aboutsummaryrefslogtreecommitdiff
path: root/src/ka-pwdialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ka-pwdialog.c')
-rw-r--r--src/ka-pwdialog.c160
1 files changed, 99 insertions, 61 deletions
diff --git a/src/ka-pwdialog.c b/src/ka-pwdialog.c
index 7653a4d..005a833 100644
--- a/src/ka-pwdialog.c
+++ b/src/ka-pwdialog.c
@@ -27,28 +27,28 @@
#include "ka-entry-buffer.h"
struct _KaPwDialog {
- GObject parent;
+ GtkDialog parent;
KaPwDialogPrivate *priv;
};
struct _KaPwDialogClass {
- GObjectClass parent;
+ GtkDialogClass parent;
};
-G_DEFINE_TYPE (KaPwDialog, ka_pwdialog, G_TYPE_OBJECT);
-
struct _KaPwDialogPrivate {
/* The password dialog */
- GtkWidget *dialog; /* the password dialog itself */
GtkWidget *status_label; /* the wrong password/timeout label */
GtkWidget *krb_label; /* krb5 passwort prompt label */
+ GtkWidget *entry_hbox; /* hbox for the pw entry */
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 */
};
+G_DEFINE_TYPE_WITH_PRIVATE (KaPwDialog, ka_pwdialog, GTK_TYPE_DIALOG);
static void
ka_pwdialog_init (KaPwDialog *pwdialog)
@@ -56,6 +56,8 @@ ka_pwdialog_init (KaPwDialog *pwdialog)
pwdialog->priv = G_TYPE_INSTANCE_GET_PRIVATE (pwdialog,
KA_TYPE_PWDIALOG,
KaPwDialogPrivate);
+
+ gtk_widget_init_template (GTK_WIDGET (pwdialog));
}
static void
@@ -67,26 +69,106 @@ ka_pwdialog_finalize (GObject *object)
gtk_widget_destroy (pwdialog->priv->error_dialog);
pwdialog->priv->error_dialog = NULL;
- if (parent_class->finalize != NULL)
- parent_class->finalize (object);
+ parent_class->finalize (object);
}
+
+static GObject *
+ka_pwdialog_constructor (GType type,
+ guint n_construct_properties,
+ GObjectConstructParam *construct_params)
+{
+ GObject *object;
+ guint idx;
+ GParamSpec *pspec;
+ GValue *value;
+
+ for (idx = 0; idx < n_construct_properties; idx++)
+ {
+ pspec = construct_params[idx].pspec;
+ if (g_strcmp0 (pspec->name, "use-header-bar") != 0)
+ continue;
+
+ /* GtkDialog uses "-1" to imply an unset value for this property */
+ value = construct_params[idx].value;
+ if (g_value_get_int (value) == -1)
+ g_value_set_int (value, 1);
+
+ break;
+ }
+
+ object = G_OBJECT_CLASS (ka_pwdialog_parent_class)->constructor (type,
+ n_construct_properties,
+ construct_params);
+
+ return object;
+}
+
+
static void
ka_pwdialog_class_init (KaPwDialogClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = ka_pwdialog_finalize;
- g_type_class_add_private (klass, sizeof (KaPwDialogPrivate));
+ object_class->constructor = ka_pwdialog_constructor;
+
+ /* Bind class to template
+ */
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gnome/krb5-auth-dialog/ui/ka-pwdialog.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, KaPwDialog, status_label);
+ gtk_widget_class_bind_template_child_private (widget_class, KaPwDialog, krb_label);
+ gtk_widget_class_bind_template_child_private (widget_class, KaPwDialog, entry_hbox);
}
-static KaPwDialog *
+
+static void add_password_entry (KaPwDialogPrivate *priv)
+{
+ KaEntryBuffer *buffer = ka_entry_buffer_new ();
+
+ priv->pw_entry =
+ GTK_WIDGET (gtk_entry_new_with_buffer (GTK_ENTRY_BUFFER (buffer)));
+ gtk_entry_set_visibility (GTK_ENTRY (priv->pw_entry), FALSE);
+ g_object_unref (buffer);
+
+ gtk_container_add (GTK_CONTAINER (priv->entry_hbox), priv->pw_entry);
+ gtk_entry_set_activates_default (GTK_ENTRY (priv->pw_entry), TRUE);
+ gtk_widget_show (priv->pw_entry);
+}
+
+
+static GtkWidget *
+ka_error_dialog_new (void)
+{
+ GtkWidget *dialog =
+ gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+ _("%s Error"), KA_NAME);
+
+ gtk_window_set_title (GTK_WINDOW (dialog), _(KA_NAME));
+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
+ return dialog;
+}
+
+
+KaPwDialog *
ka_pwdialog_new (void)
{
- return g_object_new (KA_TYPE_PWDIALOG, NULL);
+ KaPwDialog *pwdialog;
+ gboolean use_header;
+
+ g_object_get (gtk_settings_get_default (), "gtk-dialogs-use-header", &use_header, NULL);
+ pwdialog = g_object_new (KA_TYPE_PWDIALOG, "use-header-bar", use_header, NULL);
+
+ pwdialog->priv->error_dialog = ka_error_dialog_new ();
+ add_password_entry (pwdialog->priv);
+ return pwdialog;
}
+
static GdkGrabStatus
for_each_keyboard (GdkWindow *window, GdkEvent *event,
GdkGrabStatus (*func)(GdkDevice*,
@@ -193,29 +275,27 @@ window_state_changed (GtkWidget *win, GdkEventWindowState *event,
gint
ka_pwdialog_run (KaPwDialog *self)
{
- 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_hide (self->priv->error_dialog);
/* make sure we pop up on top */
- gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
+ gtk_window_set_keep_above (GTK_WINDOW (self), TRUE);
/*
* 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), self);
- g_signal_connect (dialog, "unmap-event", G_CALLBACK (ungrab_keyboard),
+ g_signal_connect (self, "map-event", G_CALLBACK (grab_keyboard), self);
+ g_signal_connect (self, "unmap-event", G_CALLBACK (ungrab_keyboard),
self);
- g_signal_connect (dialog, "window-state-event",
+ g_signal_connect (self, "window-state-event",
G_CALLBACK (window_state_changed), self);
gtk_widget_grab_focus (self->priv->pw_entry);
- gtk_widget_show (dialog);
- return gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_show (GTK_WIDGET (self));
+ return gtk_dialog_run (GTK_DIALOG (self));
}
@@ -245,7 +325,7 @@ ka_pwdialog_hide (const KaPwDialog *pwdialog, gboolean force)
{
KA_DEBUG ("PW Dialog persist: %d", pwdialog->priv->persist);
if (!pwdialog->priv->persist || force)
- gtk_widget_hide (pwdialog->priv->dialog);
+ gtk_widget_hide (GTK_WIDGET (pwdialog));
}
const gchar *
@@ -332,45 +412,3 @@ ka_pwdialog_setup (KaPwDialog *pwdialog, const gchar *krb5prompt,
g_free (wrong_markup);
g_free (prompt);
}
-
-
-static GtkWidget *
-ka_error_dialog_new (void)
-{
- GtkWidget *dialog =
- gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
- _("%s Error"), KA_NAME);
-
- gtk_window_set_title (GTK_WINDOW (dialog), _(KA_NAME));
- gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
- return dialog;
-}
-
-
-KaPwDialog *
-ka_pwdialog_create (GtkBuilder *xml)
-{
- KaPwDialog *pwdialog = ka_pwdialog_new ();
- KaEntryBuffer *buffer = ka_entry_buffer_new ();
- KaPwDialogPrivate *priv = pwdialog->priv;
- GtkWidget *entry_hbox = NULL;
-
- priv->dialog = GTK_WIDGET (gtk_builder_get_object (xml, "krb5_dialog"));
- 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_entry_new_with_buffer (GTK_ENTRY_BUFFER (buffer)));
- gtk_entry_set_visibility (GTK_ENTRY (priv->pw_entry), FALSE);
- g_object_unref (buffer);
- priv->error_dialog = ka_error_dialog_new ();
-
- entry_hbox = GTK_WIDGET (gtk_builder_get_object (xml, "entry_hbox"));
- gtk_container_add (GTK_CONTAINER (entry_hbox), priv->pw_entry);
- gtk_entry_set_activates_default (GTK_ENTRY (priv->pw_entry), TRUE);
- gtk_widget_show (priv->pw_entry);
-
- return pwdialog;
-}
bgstack15