[PolicyKit-gnome] Handle non-standard PAM stacks like fprintd
- From: David Zeuthen <davidz src gnome org>
- To: svn-commits-list gnome org
- Subject: [PolicyKit-gnome] Handle non-standard PAM stacks like fprintd
- Date: Tue, 26 May 2009 15:49:47 -0400 (EDT)
commit 4025665790a7cb72490039a21646a62cc2cbf1d3
Author: David Zeuthen <davidz redhat com>
Date: Tue May 26 15:46:36 2009 -0400
Handle non-standard PAM stacks like fprintd
This PAM stack is a bit special insofar that it only pops up INFO and
ERROR messages, never PROMPT.
---
src/polkitgnomeauthenticationdialog.c | 42 ++++++++++++++++++----
src/polkitgnomeauthenticationdialog.h | 2 +
src/polkitgnomeauthenticator.c | 62 +++++++++++++++++++++++++++++++-
3 files changed, 97 insertions(+), 9 deletions(-)
diff --git a/src/polkitgnomeauthenticationdialog.c b/src/polkitgnomeauthenticationdialog.c
index aa2315c..99c1ff3 100644
--- a/src/polkitgnomeauthenticationdialog.c
+++ b/src/polkitgnomeauthenticationdialog.c
@@ -50,6 +50,8 @@ struct _PolkitGnomeAuthenticationDialogPrivate
GtkWidget *password_entry;
GtkWidget *auth_button;
GtkWidget *cancel_button;
+ GtkWidget *info_label;
+ GtkWidget *table_alignment;
gchar *message;
gchar *action_id;
@@ -189,8 +191,8 @@ create_user_combobox (PolkitGnomeAuthenticationDialog *dialog)
{
gchar *path;
path = g_strdup_printf ("%s/.face", passwd->pw_dir);
- /* TODO: we probably shouldn't hard-code the size to 24x24*/
- pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 24, 24, TRUE, NULL);
+ /* TODO: we probably shouldn't hard-code the size to 16x16 */
+ pixbuf = gdk_pixbuf_new_from_file_at_scale (path, 16, 16, TRUE, NULL);
g_free (path);
}
@@ -261,7 +263,7 @@ get_image (PolkitGnomeAuthenticationDialog *dialog)
copy_pixbuf = NULL;
vendor_pixbuf = NULL;
- if (dialog->priv->icon_name == NULL)
+ if (dialog->priv->icon_name == NULL || strlen (dialog->priv->icon_name) == 0)
{
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG);
goto out;
@@ -274,7 +276,7 @@ get_image (PolkitGnomeAuthenticationDialog *dialog)
NULL);
if (vendor_pixbuf == NULL)
{
- g_warning ("No icon for themed icon with name %s", dialog->priv->icon_name);
+ g_warning ("No icon for themed icon with name '%s'", dialog->priv->icon_name);
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG);
goto out;
}
@@ -595,7 +597,7 @@ polkit_gnome_authentication_dialog_constructed (GObject *object)
}
/* password entry */
- vbox = gtk_vbox_new (FALSE, 6);
+ vbox = gtk_vbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
table_alignment = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
@@ -612,6 +614,18 @@ polkit_gnome_authentication_dialog_constructed (GObject *object)
G_CALLBACK (gtk_window_activate_default),
dialog);
+ dialog->priv->table_alignment = table_alignment;
+ /* initially never show the password entry stuff; we'll toggle it on/off so it's
+ * only shown when prompting for a password */
+ gtk_widget_set_no_show_all (dialog->priv->table_alignment, TRUE);
+
+ /* A label for showing PAM_TEXT_INFO and PAM_TEXT_ERROR messages */
+ label = gtk_label_new (NULL);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+ dialog->priv->info_label = label;
+
+ /* Details */
details_expander = gtk_expander_new_with_mnemonic (_("<small><b>_Details</b></small>"));
gtk_expander_set_use_markup (GTK_EXPANDER (details_expander), TRUE);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), details_expander, FALSE, FALSE, 0);
@@ -698,6 +712,8 @@ polkit_gnome_authentication_dialog_constructed (GObject *object)
{
}
+ gtk_widget_realize (GTK_WIDGET (dialog));
+
}
static void
@@ -916,7 +932,6 @@ polkit_gnome_authentication_dialog_run_until_user_is_selected (PolkitGnomeAuthen
dialog->priv->is_running = TRUE;
- gtk_widget_show_all (GTK_WIDGET (dialog));
response = gtk_dialog_run (GTK_DIALOG (dialog));
dialog->priv->is_running = FALSE;
@@ -966,9 +981,14 @@ polkit_gnome_authentication_dialog_run_until_response_for_prompt (PolkitGnomeAut
dialog->priv->is_running = TRUE;
- gtk_widget_show_all (GTK_WIDGET (dialog));
+ gtk_widget_set_no_show_all (dialog->priv->table_alignment, FALSE);
+ gtk_widget_show_all (dialog->priv->table_alignment);
+
response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_hide_all (dialog->priv->table_alignment);
+ gtk_widget_set_no_show_all (dialog->priv->table_alignment, TRUE);
+
dialog->priv->is_running = FALSE;
if (response == GTK_RESPONSE_OK)
@@ -1003,6 +1023,14 @@ polkit_gnome_authentication_dialog_get_selected_user (PolkitGnomeAuthenticationD
return g_strdup (dialog->priv->selected_user);
}
+void
+polkit_gnome_authentication_dialog_set_info_message (PolkitGnomeAuthenticationDialog *dialog,
+ const gchar *info_markup)
+{
+ gtk_label_set_markup (GTK_LABEL (dialog->priv->info_label), info_markup);
+}
+
+
/**
* polkit_gnome_authentication_dialog_cancel:
* @dialog: A #PolkitGnomeAuthenticationDialog.
diff --git a/src/polkitgnomeauthenticationdialog.h b/src/polkitgnomeauthenticationdialog.h
index c4bcf13..70d71f0 100644
--- a/src/polkitgnomeauthenticationdialog.h
+++ b/src/polkitgnomeauthenticationdialog.h
@@ -65,6 +65,8 @@ gchar *polkit_gnome_authentication_dialog_run_until_response_for_prompt (Pol
gboolean *new_user_selected);
gboolean polkit_gnome_authentication_dialog_cancel (PolkitGnomeAuthenticationDialog *dialog);
void polkit_gnome_authentication_dialog_indicate_error (PolkitGnomeAuthenticationDialog *dialog);
+void polkit_gnome_authentication_dialog_set_info_message (PolkitGnomeAuthenticationDialog *dialog,
+ const gchar *info_markup);
G_END_DECLS
diff --git a/src/polkitgnomeauthenticator.c b/src/polkitgnomeauthenticator.c
index b346668..c7c1b15 100644
--- a/src/polkitgnomeauthenticator.c
+++ b/src/polkitgnomeauthenticator.c
@@ -174,6 +174,30 @@ get_desc_for_action (PolkitAuthority *authority,
return result;
}
+static void
+on_dialog_deleted (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer user_data)
+{
+ PolkitGnomeAuthenticator *authenticator = POLKIT_GNOME_AUTHENTICATOR (user_data);
+
+ polkit_gnome_authenticator_cancel (authenticator);
+}
+
+static void
+on_user_selected (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ PolkitGnomeAuthenticator *authenticator = POLKIT_GNOME_AUTHENTICATOR (user_data);
+
+ /* clear any previous messages */
+ polkit_gnome_authentication_dialog_set_info_message (POLKIT_GNOME_AUTHENTICATION_DIALOG (authenticator->dialog), "");
+
+ polkit_gnome_authenticator_cancel (authenticator);
+ authenticator->new_user_selected = TRUE;
+}
+
PolkitGnomeAuthenticator *
polkit_gnome_authenticator_new (const gchar *action_id,
const gchar *message,
@@ -223,6 +247,14 @@ polkit_gnome_authenticator_new (const gchar *action_id,
authenticator->message,
authenticator->details,
authenticator->users);
+ g_signal_connect (authenticator->dialog,
+ "delete-event",
+ G_CALLBACK (on_dialog_deleted),
+ authenticator);
+ g_signal_connect (authenticator->dialog,
+ "notify::selected-user",
+ G_CALLBACK (on_user_selected),
+ authenticator);
return authenticator;
@@ -262,6 +294,8 @@ session_request (PolkitAgentSession *session,
modified_request = g_strdup (request);
}
+ gtk_widget_show_all (GTK_WIDGET (authenticator->dialog));
+ gtk_window_present (GTK_WINDOW (authenticator->dialog));
password = polkit_gnome_authentication_dialog_run_until_response_for_prompt (POLKIT_GNOME_AUTHENTICATION_DIALOG (authenticator->dialog),
modified_request,
echo_on,
@@ -289,7 +323,12 @@ session_show_error (PolkitAgentSession *session,
const gchar *msg,
gpointer user_data)
{
- g_warning ("TODO: should display error_msg='%s'", msg);
+ PolkitGnomeAuthenticator *authenticator = POLKIT_GNOME_AUTHENTICATOR (user_data);
+ gchar *s;
+
+ s = g_strconcat ("<b>", msg, "</b>", NULL);
+ polkit_gnome_authentication_dialog_set_info_message (POLKIT_GNOME_AUTHENTICATION_DIALOG (authenticator->dialog), s);
+ g_free (s);
}
static void
@@ -297,7 +336,15 @@ session_show_info (PolkitAgentSession *session,
const gchar *msg,
gpointer user_data)
{
- g_warning ("TODO: should display text_info='%s'", msg);
+ PolkitGnomeAuthenticator *authenticator = POLKIT_GNOME_AUTHENTICATOR (user_data);
+ gchar *s;
+
+ s = g_strconcat ("<b>", msg, "</b>", NULL);
+ polkit_gnome_authentication_dialog_set_info_message (POLKIT_GNOME_AUTHENTICATION_DIALOG (authenticator->dialog), s);
+ g_free (s);
+
+ gtk_widget_show_all (GTK_WIDGET (authenticator->dialog));
+ gtk_window_present (GTK_WINDOW (authenticator->dialog));
}
@@ -323,6 +370,8 @@ do_initiate (gpointer user_data)
PolkitIdentity *identity;
gint num_tries;
+ gtk_widget_show_all (GTK_WIDGET (authenticator->dialog));
+ gtk_window_present (GTK_WINDOW (authenticator->dialog));
if (!polkit_gnome_authentication_dialog_run_until_user_is_selected (POLKIT_GNOME_AUTHENTICATION_DIALOG (authenticator->dialog)))
{
/* user cancelled the dialog */
@@ -391,6 +440,15 @@ do_initiate (gpointer user_data)
{
if (authenticator->dialog != NULL)
{
+ gchar *s;
+
+ s = g_strconcat ("<b>", _("Authentication Failure"), "</b>", NULL);
+ polkit_gnome_authentication_dialog_set_info_message (
+ POLKIT_GNOME_AUTHENTICATION_DIALOG (authenticator->dialog),
+ s);
+ g_free (s);
+ gtk_widget_queue_draw (authenticator->dialog);
+
/* shake the dialog to indicate error */
polkit_gnome_authentication_dialog_indicate_error (POLKIT_GNOME_AUTHENTICATION_DIALOG (authenticator->dialog));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]