[krb5-auth-dialog] Make sure we don't show multiple error dialogs
- From: Guido Günther <guidog src gnome org>
- To: svn-commits-list gnome org
- Subject: [krb5-auth-dialog] Make sure we don't show multiple error dialogs
- Date: Thu, 2 Jul 2009 13:05:10 +0000 (UTC)
commit 1a4aba5b7a71dc913d9ba215b023879766a41b91
Author: Guido Günther <agx sigxcpu org>
Date: Thu Jul 2 14:33:06 2009 +0200
Make sure we don't show multiple error dialogs
by setting proper parent for the error message dialog and destroying an
already open one if present.
src/krb5-auth-applet.h | 2 ++
src/krb5-auth-dialog.c | 33 ++++++++-------------------------
src/krb5-auth-pwdialog.c | 42 ++++++++++++++++++++++++++++++++++++------
src/krb5-auth-pwdialog.h | 7 ++++---
4 files changed, 50 insertions(+), 34 deletions(-)
---
diff --git a/src/krb5-auth-applet.h b/src/krb5-auth-applet.h
index 35679bc..06e45f9 100644
--- a/src/krb5-auth-applet.h
+++ b/src/krb5-auth-applet.h
@@ -28,6 +28,8 @@
#include "config.h"
#include "krb5-auth-pwdialog.h"
+#define KA_NAME _("Network Authentication")
+
G_BEGIN_DECLS
#define KA_TYPE_APPLET (ka_applet_get_type ())
diff --git a/src/krb5-auth-dialog.c b/src/krb5-auth-dialog.c
index f163cd7..db3dcc5 100644
--- a/src/krb5-auth-dialog.c
+++ b/src/krb5-auth-dialog.c
@@ -50,8 +50,6 @@
# include <hx509_err.h>
#endif
-#define KA_NAME _("Network Authentication")
-
static krb5_context kcontext;
static krb5_principal kprincipal;
static krb5_timestamp creds_expiry;
@@ -137,7 +135,7 @@ get_principal_realm_data(krb5_principal p)
}
static const char*
-get_error_message(krb5_context context, krb5_error_code err)
+ka_get_error_message(krb5_context context, krb5_error_code err)
{
const char *msg = NULL;
@@ -368,7 +366,7 @@ credentials_expiring (gpointer *data)
retval = grab_credentials (applet);
give_up = canceled &&
(creds_expiry == canceled_creds_expiry);
- } while ((retval != 0) &&
+ } while ((retval != 0) &&
(retval != KRB5_REALM_CANT_RESOLVE) &&
(retval != KRB5_KDC_UNREACH) &&
invalid_auth &&
@@ -655,7 +653,7 @@ grab_credentials (KaApplet* applet)
break;
default:
KA_DEBUG("Auth failed with %d: %s", retval,
- get_error_message(kcontext, retval));
+ ka_get_error_message(kcontext, retval));
break;
}
goto out;
@@ -710,12 +708,12 @@ ka_renew_credentials (KaApplet* applet)
retval = krb5_cc_initialize(kcontext, ccache, kprincipal);
if(retval) {
- g_warning("krb5_cc_initialize: %s", get_error_message(kcontext, retval));
+ g_warning("krb5_cc_initialize: %s", ka_get_error_message(kcontext, retval));
goto out;
}
retval = krb5_cc_store_cred(kcontext, ccache, &my_creds);
if (retval) {
- g_warning("krb5_cc_store_cred: %s", get_error_message(kcontext, retval));
+ g_warning("krb5_cc_store_cred: %s", ka_get_error_message(kcontext, retval));
goto out;
}
}
@@ -807,23 +805,6 @@ ka_destroy_ccache (KaApplet *applet)
}
-static void
-ka_error_dialog(int err)
-{
- const char *msg = get_error_message(kcontext, err);
- GtkWidget *dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "%s", KA_NAME);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- _("Couldn't acquire kerberos ticket: '%s'"),
- _(msg));
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-}
-
-
/*
* check if we have valid credentials for the requested principal - if not, grab them
* principal: requested principal - if empty use default
@@ -889,7 +870,9 @@ ka_grab_credentials (KaApplet* applet)
if (canceled)
break;
if (retval) {
- ka_error_dialog(retval);
+ ka_pwdialog_error(pwdialog,
+ ka_get_error_message(kcontext,
+ retval));
break;
} else {
success = TRUE;
diff --git a/src/krb5-auth-pwdialog.c b/src/krb5-auth-pwdialog.c
index dd0270a..0bfffd7 100644
--- a/src/krb5-auth-pwdialog.c
+++ b/src/krb5-auth-pwdialog.c
@@ -47,6 +47,7 @@ struct _KaPwDialogPrivate
GtkWidget* pw_entry; /* password entry field */
gboolean persist; /* don't hide the dialog when creds are still valid */
gboolean grabbed; /* keyboard grabbed? */
+ GtkWidget* error_dialog; /* error dialog */
};
@@ -121,9 +122,16 @@ window_state_changed (GtkWidget *win, GdkEventWindowState *event, gpointer data)
gint
-ka_pwdialog_run(KaPwDialog* pwdialog)
+ka_pwdialog_run(KaPwDialog* self)
{
- GtkWidget* dialog = pwdialog->priv->dialog;
+ GtkWidget *dialog = self->priv->dialog;
+
+ /* cleanup old error dialog, if present (e.g. user didn't acknowledge
+ * the error but clicked the tray icon again) */
+ if (self->priv->error_dialog) {
+ gtk_widget_destroy (self->priv->error_dialog);
+ self->priv->error_dialog = NULL;
+ }
/* make sure we pop up on top */
gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
@@ -132,15 +140,36 @@ ka_pwdialog_run(KaPwDialog* pwdialog)
* grab the keyboard so that people don't accidentally type their
* passwords in other windows.
*/
- g_signal_connect (dialog, "map-event", G_CALLBACK (grab_keyboard), pwdialog);
- g_signal_connect (dialog, "unmap-event", G_CALLBACK (ungrab_keyboard), pwdialog);
- g_signal_connect (dialog, "window-state-event", G_CALLBACK (window_state_changed), pwdialog);
+ g_signal_connect (dialog, "map-event", G_CALLBACK (grab_keyboard), self);
+ g_signal_connect (dialog, "unmap-event", G_CALLBACK (ungrab_keyboard), self);
+ g_signal_connect (dialog, "window-state-event", G_CALLBACK (window_state_changed), self);
- gtk_widget_grab_focus (pwdialog->priv->pw_entry);
+ gtk_widget_grab_focus (self->priv->pw_entry);
gtk_widget_show(dialog);
return gtk_dialog_run (GTK_DIALOG(dialog));
}
+
+void
+ka_pwdialog_error(KaPwDialog* self, const char *msg)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (
+ GTK_WINDOW(self->priv->dialog),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s", KA_NAME);
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ _("Couldn't acquire kerberos ticket: '%s'"),
+ _(msg));
+ self->priv->error_dialog = dialog;
+ gtk_dialog_run (GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+}
+
+
void
ka_pwdialog_set_persist (KaPwDialog* pwdialog, gboolean persist)
{
@@ -247,6 +276,7 @@ ka_pwdialog_create(GtkBuilder* xml)
priv->status_label = GTK_WIDGET (gtk_builder_get_object (xml, "krb5_status_label"));
priv->krb_label = GTK_WIDGET (gtk_builder_get_object (xml, "krb5_message_label"));
priv->pw_entry = GTK_WIDGET (gtk_secure_entry_new ());
+ priv->error_dialog = NULL;
entry_hbox = GTK_WIDGET (gtk_builder_get_object (xml, "entry_hbox"));
gtk_container_add (GTK_CONTAINER (entry_hbox), priv->pw_entry);
diff --git a/src/krb5-auth-pwdialog.h b/src/krb5-auth-pwdialog.h
index 1e5c93d..a02d3fb 100644
--- a/src/krb5-auth-pwdialog.h
+++ b/src/krb5-auth-pwdialog.h
@@ -52,9 +52,10 @@ KaPwDialog* ka_pwdialog_create(GtkBuilder *xml);
/* setup everything for the next prompting */
void ka_pwdialog_setup (KaPwDialog* pwdialog, const gchar *krb5prompt,
gboolean invalid_auth);
-gint ka_pwdialog_run(KaPwDialog *applet);
-void ka_pwdialog_hide(const KaPwDialog *applet, gboolean force);
-void ka_pwdialog_set_persist(KaPwDialog *applet, gboolean persist);
+gint ka_pwdialog_run(KaPwDialog *pwdialog);
+void ka_pwdialog_hide(const KaPwDialog *pwdialog, gboolean force);
+void ka_pwdialog_set_persist(KaPwDialog *pwdialog, gboolean persist);
+void ka_pwdialog_error (KaPwDialog *pwdialog, const char *msg);
/* update the expiry information in the status entry */
gboolean ka_pwdialog_status_update (KaPwDialog *pwdialog);
const gchar* ka_pwdialog_get_password(KaPwDialog *dialog);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]