[gnome-control-center] user-accounts: Convert UmPasswordDialog to GtkTemplate



commit ad44ad43674f410d11b4416ed35a9a1723e82c59
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue Nov 6 15:42:06 2018 +1300

    user-accounts: Convert UmPasswordDialog to GtkTemplate

 panels/user-accounts/cc-user-panel.c               |  14 +-
 panels/user-accounts/meson.build                   |   2 +-
 panels/user-accounts/um-password-dialog.c          | 431 ++++++++-------------
 panels/user-accounts/um-password-dialog.h          |  10 +-
 .../password-dialog.ui => um-password-dialog.ui}   |  63 +--
 panels/user-accounts/user-accounts.gresource.xml   |   2 +-
 po/POTFILES.in                                     |   2 +-
 7 files changed, 222 insertions(+), 302 deletions(-)
---
diff --git a/panels/user-accounts/cc-user-panel.c b/panels/user-accounts/cc-user-panel.c
index 50442cbff..d14751d9d 100644
--- a/panels/user-accounts/cc-user-panel.c
+++ b/panels/user-accounts/cc-user-panel.c
@@ -99,7 +99,6 @@ struct _CcUserPanel {
         GPermission *permission;
         CcLanguageChooser *language_chooser;
 
-        UmPasswordDialog *password_dialog;
         UmPhotoDialog *photo_dialog;
         UmHistoryDialog *history_dialog;
 
@@ -1044,12 +1043,17 @@ static void
 change_password (CcUserPanel *self)
 {
         ActUser *user;
+        UmPasswordDialog *dialog;
+        GtkWindow *parent;
 
         user = get_selected_user (self);
+        dialog = um_password_dialog_new (user);
 
-        um_password_dialog_set_user (self->password_dialog, user);
-        um_password_dialog_show (self->password_dialog,
-                                  GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))));
+        parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
+        gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+
+        gtk_dialog_run (GTK_DIALOG (dialog));
+        gtk_widget_destroy (GTK_WIDGET (dialog));
 }
 
 static void
@@ -1372,7 +1376,6 @@ cc_user_panel_init (CcUserPanel *self)
 
         self->login_screen_settings = settings_or_null ("org.gnome.login-screen");
 
-        self->password_dialog = um_password_dialog_new ();
         self->photo_dialog = um_photo_dialog_new (GTK_WIDGET (self->user_icon_button));
         self->history_dialog = um_history_dialog_new ();
         setup_main_window (self);
@@ -1388,7 +1391,6 @@ cc_user_panel_dispose (GObject *object)
 
         g_clear_object (&self->login_screen_settings);
 
-        g_clear_pointer (&self->password_dialog, um_password_dialog_free);
         g_clear_pointer (&self->history_dialog, um_history_dialog_free);
         if (self->account_dialog) {
                 gtk_dialog_response (GTK_DIALOG (self->account_dialog), GTK_RESPONSE_DELETE_EVENT);
diff --git a/panels/user-accounts/meson.build b/panels/user-accounts/meson.build
index 41300d84c..213516899 100644
--- a/panels/user-accounts/meson.build
+++ b/panels/user-accounts/meson.build
@@ -120,8 +120,8 @@ resource_data = files(
   'data/carousel.ui',
   'data/history-dialog.ui',
   'data/join-dialog.ui',
-  'data/password-dialog.ui',
   'data/user-accounts-dialog.css',
+  'um-password-dialog.ui',
 )
 
 common_sources += gnome.compile_resources(
diff --git a/panels/user-accounts/um-password-dialog.c b/panels/user-accounts/um-password-dialog.c
index 310259c37..b005fba92 100644
--- a/panels/user-accounts/um-password-dialog.c
+++ b/panels/user-accounts/um-password-dialog.c
@@ -31,36 +31,42 @@
 #include <act/act.h>
 
 #include "um-password-dialog.h"
+#include "um-resources.h"
 #include "um-utils.h"
 #include "run-passwd.h"
 #include "pw-utils.h"
 
 #define PASSWORD_CHECK_TIMEOUT 600
 
-struct _UmPasswordDialog {
-        GtkWidget *dialog;
-        GtkWidget *action_radio_box;
-        GtkWidget *action_now_radio;
-        GtkWidget *action_login_radio;
-        GtkWidget *password_entry;
-        GtkWidget *verify_entry;
-        gint       password_entry_timeout_id;
-        GtkWidget *strength_indicator;
-        GtkWidget *ok_button;
-        GtkWidget *password_hint;
-        GtkWidget *verify_hint;
-
-        ActUser *user;
+struct _UmPasswordDialog
+{
+        GtkDialog           parent_instance;
+
+        GtkBox             *action_radio_box;
+        GtkRadioButton     *action_now_radio;
+        GtkRadioButton     *action_login_radio;
+        GtkButton          *ok_button;
+        GtkLabel           *old_password_label;
+        GtkEntry           *old_password_entry;
+        GtkEntry           *password_entry;
+        GtkLabel           *password_hint_label;
+        GtkLevelBar        *strength_indicator;
+        GtkEntry           *verify_entry;
+        GtkLabel           *verify_hint_label;
+
+        gint                password_entry_timeout_id;
+
+        ActUser            *user;
         ActUserPasswordMode password_mode;
 
-        GtkWidget *old_password_label;
-        GtkWidget *old_password_entry;
-        gboolean   old_password_ok;
-        gint       old_password_entry_timeout_id;
+        gboolean            old_password_ok;
+        gint                old_password_entry_timeout_id;
 
-        PasswdHandler *passwd_handler;
+        PasswdHandler      *passwd_handler;
 };
 
+G_DEFINE_TYPE (UmPasswordDialog, um_password_dialog, GTK_TYPE_DIALOG)
+
 static gint
 update_password_strength (UmPasswordDialog *um)
 {
@@ -71,63 +77,32 @@ update_password_strength (UmPasswordDialog *um)
         const gchar *hint;
         const gchar *verify;
 
-        if (um->user == NULL) {
-                return 0;
-        }
-
-        password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
-        old_password = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry));
+        password = gtk_entry_get_text (um->password_entry);
+        old_password = gtk_entry_get_text (um->old_password_entry);
         username = act_user_get_user_name (um->user);
 
         pw_strength (password, old_password, username,
                      &hint, &strength_level);
 
-        gtk_level_bar_set_value (GTK_LEVEL_BAR (um->strength_indicator), strength_level);
-        gtk_label_set_label (GTK_LABEL (um->password_hint), hint);
+        gtk_level_bar_set_value (um->strength_indicator, strength_level);
+        gtk_label_set_label (um->password_hint_label, hint);
 
         if (strength_level > 1) {
-                set_entry_validation_checkmark (GTK_ENTRY (um->password_entry));
+                set_entry_validation_checkmark (um->password_entry);
         } else if (strlen (password) == 0) {
-                set_entry_generation_icon (GTK_ENTRY (um->password_entry));
+                set_entry_generation_icon (um->password_entry);
         } else {
-                clear_entry_validation_error (GTK_ENTRY (um->password_entry));
+                clear_entry_validation_error (um->password_entry);
         }
 
-        verify = gtk_entry_get_text (GTK_ENTRY (um->verify_entry));
+        verify = gtk_entry_get_text (um->verify_entry);
         if (strlen (verify) == 0) {
-                gtk_widget_set_sensitive (um->verify_entry, strength_level > 1);
+                gtk_widget_set_sensitive (GTK_WIDGET (um->verify_entry), strength_level > 1);
         }
 
         return strength_level;
 }
 
-static void
-finish_password_change (UmPasswordDialog *um)
-{
-        gtk_widget_hide (um->dialog);
-
-        gtk_entry_set_text (GTK_ENTRY (um->password_entry), " ");
-        gtk_entry_set_text (GTK_ENTRY (um->verify_entry), "");
-        gtk_entry_set_text (GTK_ENTRY (um->old_password_entry), "");
-
-        um_password_dialog_set_user (um, NULL);
-}
-
-static void
-cancel_password_dialog (GtkButton        *button,
-                        UmPasswordDialog *um)
-{
-        finish_password_change (um);
-}
-
-static void
-dialog_closed (GtkWidget        *dialog,
-               gint              response_id,
-               UmPasswordDialog *um)
-{
-        gtk_widget_destroy (dialog);
-}
-
 static void
 password_changed_cb (PasswdHandler    *handler,
                      GError           *error,
@@ -137,11 +112,11 @@ password_changed_cb (PasswdHandler    *handler,
         const gchar *primary_text;
         const gchar *secondary_text;
 
-        gtk_widget_set_sensitive (um->dialog, TRUE);
-        gdk_window_set_cursor (gtk_widget_get_window (um->dialog), NULL);
+        gtk_widget_set_sensitive (GTK_WIDGET (um), TRUE);
+        gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (um)), NULL);
 
         if (!error) {
-                finish_password_change (um);
+                gtk_dialog_response (GTK_DIALOG (um), GTK_RESPONSE_ACCEPT);
                 return;
         }
 
@@ -149,43 +124,40 @@ password_changed_cb (PasswdHandler    *handler,
                 primary_text = error->message;
                 secondary_text = _("Please choose another password.");
 
-                gtk_entry_set_text (GTK_ENTRY (um->password_entry), "");
-                gtk_widget_grab_focus (um->password_entry);
+                gtk_entry_set_text (um->password_entry, "");
+                gtk_widget_grab_focus (GTK_WIDGET (um->password_entry));
 
-                gtk_entry_set_text (GTK_ENTRY (um->verify_entry), "");
+                gtk_entry_set_text (um->verify_entry, "");
         }
         else if (error->code == PASSWD_ERROR_AUTH_FAILED) {
                 primary_text = error->message;
                 secondary_text = _("Please type your current password again.");
 
-                gtk_entry_set_text (GTK_ENTRY (um->old_password_entry), "");
-                gtk_widget_grab_focus (um->old_password_entry);
+                gtk_entry_set_text (um->old_password_entry, "");
+                gtk_widget_grab_focus (GTK_WIDGET (um->old_password_entry));
         }
         else {
                 primary_text = _("Password could not be changed");
                 secondary_text = error->message;
         }
 
-        dialog = gtk_message_dialog_new (GTK_WINDOW (um->dialog),
+        dialog = gtk_message_dialog_new (GTK_WINDOW (um),
                                          GTK_DIALOG_MODAL,
                                          GTK_MESSAGE_ERROR,
                                          GTK_BUTTONS_CLOSE,
                                          "%s", primary_text);
         gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
                                                   "%s", secondary_text);
-        g_signal_connect (dialog, "response",
-                          G_CALLBACK (dialog_closed), um);
-        gtk_window_present (GTK_WINDOW (dialog));
-
+        gtk_dialog_run (GTK_DIALOG (dialog));
+        gtk_widget_destroy (dialog);
 }
 
 static void
-accept_password_dialog (GtkButton        *button,
-                        UmPasswordDialog *um)
+ok_button_clicked_cb (UmPasswordDialog *um)
 {
         const gchar *password;
 
-        password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
+        password = gtk_entry_get_text (um->password_entry);
 
         switch (um->password_mode) {
                 case ACT_USER_PASSWORD_MODE_REGULAR:
@@ -199,10 +171,10 @@ accept_password_dialog (GtkButton        *button,
                                  */
                                 passwd_change_password (um->passwd_handler, password,
                                                         (PasswdCallback) password_changed_cb, um);
-                                gtk_widget_set_sensitive (um->dialog, FALSE);
-                                display = gtk_widget_get_display (um->dialog);
+                                gtk_widget_set_sensitive (GTK_WIDGET (um), FALSE);
+                                display = gtk_widget_get_display (GTK_WIDGET (um));
                                 cursor = gdk_cursor_new_for_display (display, GDK_WATCH);
-                                gdk_window_set_cursor (gtk_widget_get_window (um->dialog), cursor);
+                                gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (um)), cursor);
                                 gdk_display_flush (display);
                                 g_object_unref (cursor);
                                 return;
@@ -221,7 +193,7 @@ accept_password_dialog (GtkButton        *button,
                         g_assert_not_reached ();
         }
 
-        finish_password_change (um);
+        gtk_dialog_response (GTK_DIALOG (um), GTK_RESPONSE_ACCEPT);
 }
 
 static void
@@ -231,19 +203,19 @@ update_sensitivity (UmPasswordDialog *um)
         gboolean can_change;
         int strength;
 
-        password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
-        verify = gtk_entry_get_text (GTK_ENTRY (um->verify_entry));
+        password = gtk_entry_get_text (um->password_entry);
+        verify = gtk_entry_get_text (um->verify_entry);
 
         if (um->password_mode == ACT_USER_PASSWORD_MODE_REGULAR) {
                 strength = update_password_strength (um);
                 can_change = strength > 1 && strcmp (password, verify) == 0 &&
-                             (um->old_password_ok || !gtk_widget_get_visible (um->old_password_entry));
+                             (um->old_password_ok || !gtk_widget_get_visible (GTK_WIDGET 
(um->old_password_entry)));
         }
         else {
                 can_change = TRUE;
         }
 
-        gtk_widget_set_sensitive (um->ok_button, can_change);
+        gtk_widget_set_sensitive (GTK_WIDGET (um->ok_button), can_change);
 }
 
 static void
@@ -253,10 +225,10 @@ mode_change (UmPasswordDialog *um,
         gboolean active;
 
         active = (mode == ACT_USER_PASSWORD_MODE_REGULAR);
-        gtk_widget_set_sensitive (um->password_entry, active);
-        gtk_widget_set_sensitive (um->verify_entry, active);
-        gtk_widget_set_sensitive (um->old_password_entry, active);
-        gtk_widget_set_sensitive (um->password_hint, active);
+        gtk_widget_set_sensitive (GTK_WIDGET (um->password_entry), active);
+        gtk_widget_set_sensitive (GTK_WIDGET (um->verify_entry), active);
+        gtk_widget_set_sensitive (GTK_WIDGET (um->old_password_entry), active);
+        gtk_widget_set_sensitive (GTK_WIDGET (um->password_hint_label), active);
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->action_now_radio), active);
         gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (um->action_login_radio), !active);
 
@@ -265,13 +237,12 @@ mode_change (UmPasswordDialog *um,
 }
 
 static void
-action_changed (GtkRadioButton   *radio,
-                UmPasswordDialog *um)
+action_now_radio_toggled_cb (UmPasswordDialog *um)
 {
         gint active;
         ActUserPasswordMode mode;
 
-        active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio));
+        active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (um->action_now_radio));
         mode = active ? ACT_USER_PASSWORD_MODE_REGULAR : ACT_USER_PASSWORD_MODE_SET_AT_LOGIN;
         mode_change (um, mode);
 }
@@ -283,18 +254,18 @@ update_password_match (UmPasswordDialog *um)
         const char *verify;
         const char *message = "";
 
-        password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
-        verify = gtk_entry_get_text (GTK_ENTRY (um->verify_entry));
+        password = gtk_entry_get_text (um->password_entry);
+        verify = gtk_entry_get_text (um->verify_entry);
 
         if (strlen (verify) > 0) {
                 if (strcmp (password, verify) != 0) {
                         message = _("The passwords do not match.");
                 }
                 else {
-                        set_entry_validation_checkmark (GTK_ENTRY (um->verify_entry));
+                        set_entry_validation_checkmark (um->verify_entry);
                 }
         }
-        gtk_label_set_label (GTK_LABEL (um->verify_hint), message);
+        gtk_label_set_label (um->verify_hint_label, message);
 }
 
 static gboolean
@@ -310,9 +281,9 @@ password_entry_timeout (UmPasswordDialog *um)
 }
 
 static void
-password_entry_changed (GtkEntry         *entry,
-                      GParamSpec       *pspec,
-                      UmPasswordDialog *um)
+password_entry_changed (UmPasswordDialog *um,
+                        GParamSpec       *pspec,
+                        GtkEntry         *entry)
 {
         const char *password;
 
@@ -321,24 +292,22 @@ password_entry_changed (GtkEntry         *entry,
                 um->password_entry_timeout_id = 0;
         }
 
-        clear_entry_validation_error (GTK_ENTRY (entry));
-        clear_entry_validation_error (GTK_ENTRY (um->verify_entry));
-        gtk_widget_set_sensitive (um->ok_button, FALSE);
+        clear_entry_validation_error (entry);
+        clear_entry_validation_error (um->verify_entry);
+        gtk_widget_set_sensitive (GTK_WIDGET (um->ok_button), FALSE);
 
-        password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
+        password = gtk_entry_get_text (um->password_entry);
         if (strlen (password) == 0) {
-                gtk_entry_set_visibility (GTK_ENTRY (um->password_entry), FALSE);
+                gtk_entry_set_visibility (um->password_entry, FALSE);
         }
 
         um->password_entry_timeout_id = g_timeout_add (PASSWORD_CHECK_TIMEOUT,
-                                                     (GSourceFunc) password_entry_timeout,
-                                                     um);
+                                                       (GSourceFunc) password_entry_timeout,
+                                                       um);
 }
 
 static gboolean
-password_entry_focus_out (GtkWidget        *entry,
-                        GdkEventFocus    *event,
-                        UmPasswordDialog *um)
+password_entry_focus_out_cb (UmPasswordDialog *um)
 {
         if (um->password_entry_timeout_id != 0) {
                 g_source_remove (um->password_entry_timeout_id);
@@ -351,9 +320,8 @@ password_entry_focus_out (GtkWidget        *entry,
 }
 
 static gboolean
-password_key_press (GtkEntry         *entry,
-                    GdkEvent         *event,
-                    UmPasswordDialog *um)
+password_entry_key_press_cb (UmPasswordDialog *um,
+                             GdkEvent         *event)
 {
         GdkEventKey *key = (GdkEventKey *)event;
 
@@ -373,7 +341,7 @@ auth_cb (PasswdHandler    *handler,
         }
         else {
                 um->old_password_ok = TRUE;
-                set_entry_validation_checkmark (GTK_ENTRY (um->old_password_entry));
+                set_entry_validation_checkmark (um->old_password_entry);
         }
 
         update_sensitivity (um);
@@ -386,7 +354,7 @@ old_password_entry_timeout (UmPasswordDialog *um)
 
         update_sensitivity (um);
 
-        text = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry));
+        text = gtk_entry_get_text (um->old_password_entry);
         if (!um->old_password_ok) {
                 passwd_authenticate (um->passwd_handler, text, (PasswdCallback)auth_cb, um);
         }
@@ -397,9 +365,7 @@ old_password_entry_timeout (UmPasswordDialog *um)
 }
 
 static gboolean
-old_password_entry_focus_out (GtkWidget        *entry,
-                              GdkEventFocus    *event,
-                              UmPasswordDialog *um)
+old_password_entry_focus_out_cb (UmPasswordDialog *um)
 {
         if (um->old_password_entry_timeout_id != 0) {
                 g_source_remove (um->old_password_entry_timeout_id);
@@ -412,17 +378,15 @@ old_password_entry_focus_out (GtkWidget        *entry,
 }
 
 static void
-old_password_entry_changed (GtkEntry         *entry,
-                            GParamSpec       *pspec,
-                            UmPasswordDialog *um)
+old_password_entry_changed (UmPasswordDialog *um)
 {
         if (um->old_password_entry_timeout_id != 0) {
                 g_source_remove (um->old_password_entry_timeout_id);
                 um->old_password_entry_timeout_id = 0;
         }
 
-        clear_entry_validation_error (GTK_ENTRY (entry));
-        gtk_widget_set_sensitive (um->ok_button, FALSE);
+        clear_entry_validation_error (um->old_password_entry);
+        gtk_widget_set_sensitive (GTK_WIDGET (um->ok_button), FALSE);
 
         um->old_password_ok = FALSE;
         um->old_password_entry_timeout_id = g_timeout_add (PASSWORD_CHECK_TIMEOUT,
@@ -431,10 +395,7 @@ old_password_entry_changed (GtkEntry         *entry,
 }
 
 static void
-on_generate (GtkEntry             *entry,
-             GtkEntryIconPosition  pos,
-             GdkEventButton       *event,
-             UmPasswordDialog     *um)
+password_entry_icon_press_cb (UmPasswordDialog *um)
 {
         gchar *pwd;
 
@@ -442,107 +403,25 @@ on_generate (GtkEntry             *entry,
         if (pwd == NULL)
                 return;
 
-        gtk_entry_set_text (GTK_ENTRY (um->password_entry), pwd);
-        gtk_entry_set_text (GTK_ENTRY (um->verify_entry), pwd);
-        gtk_entry_set_visibility (GTK_ENTRY (um->password_entry), TRUE);
-        gtk_widget_set_sensitive (um->verify_entry, TRUE);
+        gtk_entry_set_text (um->password_entry, pwd);
+        gtk_entry_set_text (um->verify_entry, pwd);
+        gtk_entry_set_visibility (um->password_entry, TRUE);
+        gtk_widget_set_sensitive (GTK_WIDGET (um->verify_entry), TRUE);
 
         g_free (pwd);
 }
 
-UmPasswordDialog *
-um_password_dialog_new (void)
-{
-        GtkBuilder *builder;
-        GError *error;
-        UmPasswordDialog *um;
-        GtkWidget *widget;
-
-        builder = gtk_builder_new ();
-
-        error = NULL;
-        if (!gtk_builder_add_from_resource (builder,
-                                            "/org/gnome/control-center/user-accounts/password-dialog.ui",
-                                            &error)) {
-                g_error ("%s", error->message);
-                g_error_free (error);
-                return NULL;
-        }
-
-        um = g_new0 (UmPasswordDialog, 1);
-
-        um->action_radio_box = (GtkWidget *) gtk_builder_get_object (builder, "action-radio-box");
-        widget = (GtkWidget *) gtk_builder_get_object (builder, "action-now-radio");
-        g_signal_connect (widget, "toggled", G_CALLBACK (action_changed), um);
-        um->action_now_radio = widget;
-        um->action_login_radio = (GtkWidget *) gtk_builder_get_object (builder, "action-login-radio");
-
-        widget = (GtkWidget *) gtk_builder_get_object (builder, "dialog");
-        g_signal_connect (widget, "delete-event",
-                          G_CALLBACK (gtk_widget_hide_on_delete), NULL);
-        um->dialog = widget;
-
-        widget = (GtkWidget *) gtk_builder_get_object (builder, "cancel-button");
-        g_signal_connect (widget, "clicked",
-                          G_CALLBACK (cancel_password_dialog), um);
-
-        widget = (GtkWidget *) gtk_builder_get_object (builder, "ok-button");
-        g_signal_connect (widget, "clicked",
-                          G_CALLBACK (accept_password_dialog), um);
-        gtk_widget_grab_default (widget);
-        um->ok_button = widget;
-
-        widget = (GtkWidget *) gtk_builder_get_object (builder, "password-entry");
-        g_signal_connect (widget, "notify::text",
-                          G_CALLBACK (password_entry_changed), um);
-        g_signal_connect_after (widget, "focus-out-event",
-                                G_CALLBACK (password_entry_focus_out), um);
-        g_signal_connect (widget, "key-press-event",
-                          G_CALLBACK (password_key_press), um);
-        g_signal_connect_swapped (widget, "activate", G_CALLBACK (password_entry_timeout), um);
-        gtk_entry_set_visibility (GTK_ENTRY (widget), FALSE);
-        um->password_entry = widget;
-        g_signal_connect (widget, "icon-press", G_CALLBACK (on_generate), um);
-
-        widget = (GtkWidget *) gtk_builder_get_object (builder, "old-password-entry");
-        g_signal_connect_after (widget, "focus-out-event",
-                                G_CALLBACK (old_password_entry_focus_out), um);
-        g_signal_connect (widget, "notify::text",
-                          G_CALLBACK (old_password_entry_changed), um);
-        g_signal_connect_swapped (widget, "activate", G_CALLBACK (password_entry_timeout), um);
-        um->old_password_entry = widget;
-        um->old_password_label = (GtkWidget *) gtk_builder_get_object (builder, "old-password-label");
-
-        widget = (GtkWidget *) gtk_builder_get_object (builder, "verify-entry");
-        g_signal_connect (widget, "notify::text",
-                          G_CALLBACK (password_entry_changed), um);
-        g_signal_connect_after (widget, "focus-out-event",
-                                G_CALLBACK (password_entry_focus_out), um);
-        g_signal_connect_swapped (widget, "activate", G_CALLBACK (password_entry_timeout), um);
-        um->verify_entry = widget;
-
-        um->strength_indicator = (GtkWidget *) gtk_builder_get_object (builder, "strength-indicator");
-
-        widget = (GtkWidget *)gtk_builder_get_object (builder, "password-hint");
-        um->password_hint = widget;
-
-        widget = (GtkWidget *)gtk_builder_get_object (builder, "verify-hint");
-        um->verify_hint = widget;
-
-        g_object_unref (builder);
-
-        return um;
-}
-
-void
-um_password_dialog_free (UmPasswordDialog *um)
+static void
+um_password_dialog_dispose (GObject *object)
 {
-        gtk_widget_destroy (um->dialog);
+        UmPasswordDialog *um = UM_PASSWORD_DIALOG (object);
 
         g_clear_object (&um->user);
 
-        if (um->passwd_handler)
+        if (um->passwd_handler) {
                 passwd_destroy (um->passwd_handler);
+                um->passwd_handler = NULL;
+        }
 
         if (um->old_password_entry_timeout_id != 0) {
                 g_source_remove (um->old_password_entry_timeout_id);
@@ -554,63 +433,91 @@ um_password_dialog_free (UmPasswordDialog *um)
                 um->password_entry_timeout_id = 0;
         }
 
-        g_free (um);
+        G_OBJECT_CLASS (um_password_dialog_parent_class)->dispose (object);
 }
 
-void
-um_password_dialog_set_user (UmPasswordDialog *um,
-                             ActUser          *user)
+static void
+um_password_dialog_class_init (UmPasswordDialogClass *klass)
 {
-        gboolean visible;
+        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+        object_class->dispose = um_password_dialog_dispose;
+
+        gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/user-accounts/um-password-dialog.ui");
+
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, action_radio_box);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, action_now_radio);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, action_login_radio);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, ok_button);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, old_password_label);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, old_password_entry);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, password_entry);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, password_hint_label);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, strength_indicator);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, verify_entry);
+        gtk_widget_class_bind_template_child (widget_class, UmPasswordDialog, verify_hint_label);
+
+        gtk_widget_class_bind_template_callback (widget_class, action_now_radio_toggled_cb);
+        gtk_widget_class_bind_template_callback (widget_class, old_password_entry_changed);
+        gtk_widget_class_bind_template_callback (widget_class, old_password_entry_focus_out_cb);
+        gtk_widget_class_bind_template_callback (widget_class, ok_button_clicked_cb);
+        gtk_widget_class_bind_template_callback (widget_class, password_entry_changed);
+        gtk_widget_class_bind_template_callback (widget_class, password_entry_focus_out_cb);
+        gtk_widget_class_bind_template_callback (widget_class, password_entry_icon_press_cb);
+        gtk_widget_class_bind_template_callback (widget_class, password_entry_key_press_cb);
+        gtk_widget_class_bind_template_callback (widget_class, password_entry_timeout);
+}
 
-        if (um->user) {
-                g_object_unref (um->user);
-                um->user = NULL;
-        }
-        if (user) {
-                um->user = g_object_ref (user);
+static void
+um_password_dialog_init (UmPasswordDialog *um)
+{
+        g_resources_register (um_get_resource ());
 
-                gtk_entry_set_text (GTK_ENTRY (um->password_entry), "");
-                gtk_entry_set_text (GTK_ENTRY (um->verify_entry), "");
-                gtk_entry_set_text (GTK_ENTRY (um->old_password_entry), "");
+        gtk_widget_init_template (GTK_WIDGET (um));
+}
 
-                gtk_entry_set_visibility (GTK_ENTRY (um->password_entry), FALSE);
-                gtk_entry_set_visibility (GTK_ENTRY (um->verify_entry), FALSE);
+UmPasswordDialog *
+um_password_dialog_new (ActUser *user)
+{
+        UmPasswordDialog *um;
 
-                if (act_user_get_uid (um->user) == getuid ()) {
-                        mode_change (um, ACT_USER_PASSWORD_MODE_REGULAR);
-                        gtk_widget_hide (um->action_radio_box);
+        g_return_val_if_fail (ACT_IS_USER (user), NULL);
 
-                        visible = (act_user_get_password_mode (user) != ACT_USER_PASSWORD_MODE_NONE);
-                        gtk_widget_set_visible (um->old_password_label, visible);
-                        gtk_widget_set_visible (um->old_password_entry, visible);
-                        um->old_password_ok = !visible;
-                }
-                else {
-                        mode_change (um, ACT_USER_PASSWORD_MODE_SET_AT_LOGIN);
-                        gtk_widget_show (um->action_radio_box);
+        um = g_object_new (UM_TYPE_PASSWORD_DIALOG,
+                           "use-header-bar", 1,
+                           NULL);
 
-                        gtk_widget_hide (um->old_password_label);
-                        gtk_widget_hide (um->old_password_entry);
-                        um->old_password_ok = TRUE;
-                }
-                if (act_user_get_uid (um->user) == getuid()) {
-                        if (um->passwd_handler != NULL)
-                                passwd_destroy (um->passwd_handler);
-                        um->passwd_handler = passwd_init ();
-                }
+        um->user = g_object_ref (user);
+
+        if (act_user_get_uid (um->user) == getuid ()) {
+                gboolean visible;
+
+                mode_change (um, ACT_USER_PASSWORD_MODE_REGULAR);
+                gtk_widget_hide (GTK_WIDGET (um->action_radio_box));
+
+                visible = (act_user_get_password_mode (user) != ACT_USER_PASSWORD_MODE_NONE);
+                gtk_widget_set_visible (GTK_WIDGET (um->old_password_label), visible);
+                gtk_widget_set_visible (GTK_WIDGET (um->old_password_entry), visible);
+                um->old_password_ok = !visible;
+
+                um->passwd_handler = passwd_init ();
+        }
+        else {
+                mode_change (um, ACT_USER_PASSWORD_MODE_SET_AT_LOGIN);
+                gtk_widget_show (GTK_WIDGET (um->action_radio_box));
+
+                gtk_widget_hide (GTK_WIDGET (um->old_password_label));
+                gtk_widget_hide (GTK_WIDGET (um->old_password_entry));
+                um->old_password_ok = TRUE;
         }
-}
 
-void
-um_password_dialog_show (UmPasswordDialog *um,
-                         GtkWindow        *parent)
-{
-        gtk_window_set_transient_for (GTK_WINDOW (um->dialog), parent);
-        gtk_window_present (GTK_WINDOW (um->dialog));
         if (um->old_password_ok == FALSE)
-                gtk_widget_grab_focus (um->old_password_entry);
+                gtk_widget_grab_focus (GTK_WIDGET (um->old_password_entry));
         else
-                gtk_widget_grab_focus (um->password_entry);
-}
+                gtk_widget_grab_focus (GTK_WIDGET (um->password_entry));
 
+        gtk_widget_grab_default (GTK_WIDGET (um->ok_button));
+
+        return um;
+}
diff --git a/panels/user-accounts/um-password-dialog.h b/panels/user-accounts/um-password-dialog.h
index f6fca5e81..d89086965 100644
--- a/panels/user-accounts/um-password-dialog.h
+++ b/panels/user-accounts/um-password-dialog.h
@@ -25,13 +25,9 @@
 
 G_BEGIN_DECLS
 
-typedef struct _UmPasswordDialog UmPasswordDialog;
+#define UM_TYPE_PASSWORD_DIALOG (um_password_dialog_get_type ())
+G_DECLARE_FINAL_TYPE (UmPasswordDialog, um_password_dialog, UM, PASSWORD_DIALOG, GtkDialog)
 
-UmPasswordDialog *um_password_dialog_new      (void);
-void              um_password_dialog_free     (UmPasswordDialog *dialog);
-void              um_password_dialog_set_user (UmPasswordDialog *dialog,
-                                               ActUser          *user);
-void              um_password_dialog_show     (UmPasswordDialog *dialog,
-                                               GtkWindow        *parent);
+UmPasswordDialog *um_password_dialog_new (ActUser *user);
 
 G_END_DECLS
diff --git a/panels/user-accounts/data/password-dialog.ui b/panels/user-accounts/um-password-dialog.ui
similarity index 80%
rename from panels/user-accounts/data/password-dialog.ui
rename to panels/user-accounts/um-password-dialog.ui
index 6d8c26e00..eb3664236 100644
--- a/panels/user-accounts/data/password-dialog.ui
+++ b/panels/user-accounts/um-password-dialog.ui
@@ -2,7 +2,7 @@
 <interface>
   <!-- interface-requires gtk+ 2.12 -->
   <!-- interface-naming-policy toplevel-contextual -->
-  <object class="GtkDialog" id="dialog">
+  <template class="UmPasswordDialog" parent="GtkDialog">
     <property name="border_width">6</property>
     <property name="title" translatable="yes">Change Password</property>
     <property name="resizable">False</property>
@@ -10,14 +10,13 @@
     <property name="window_position">center-on-parent</property>
     <property name="icon_name">system-users</property>
     <property name="type_hint">dialog</property>
-    <property name="use_header_bar">1</property>
     <child internal-child="headerbar">
       <object class="GtkHeaderBar" id="dialog-header-bar">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="show_close_button">False</property>
         <child>
-          <object class="GtkButton" id="cancel-button">
+          <object class="GtkButton" id="cancel_button">
             <property name="label" translatable="yes">_Cancel</property>
             <property name="visible">True</property>
             <property name="visible">True</property>
@@ -34,7 +33,7 @@
           </packing>
         </child>
         <child>
-          <object class="GtkButton" id="ok-button">
+          <object class="GtkButton" id="ok_button">
             <property name="label" translatable="yes">Ch_ange</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
@@ -42,6 +41,7 @@
             <property name="receives_default">True</property>
             <property name="use_underline">True</property>
             <property name="valign">center</property>
+            <signal name="clicked" handler="ok_button_clicked_cb" object="UmPasswordDialog" swapped="yes"/>
             <style>
               <class name="text-button"/>
               <class name="suggested-action"/>
@@ -54,32 +54,35 @@
       </object>
     </child>
     <child internal-child="vbox">
-      <object class="GtkBox" id="dialog-vbox1">
+      <object class="GtkBox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
         <property name="spacing">6</property>
         <child>
-          <object class="GtkBox" id="vbox7">
+          <object class="GtkBox">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
             <property name="border_width">6</property>
             <property name="orientation">vertical</property>
             <property name="spacing">6</property>
             <child>
-              <object class="GtkGrid" id="table4">
+              <object class="GtkGrid">
                 <property name="visible">True</property>
                 <property name="column_spacing">6</property>
                 <property name="row_spacing">6</property>
                 <property name="hexpand">True</property>
                 <child>
-                  <object class="GtkEntry" id="verify-entry">
+                  <object class="GtkEntry" id="verify_entry">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="visibility">False</property>
                     <property name="hexpand">True</property>
                     <property name="activates_default">True</property>
                     <property name="input_purpose">password</property>
+                    <signal name="notify::text" handler="password_entry_changed" object="UmPasswordDialog" 
swapped="yes"/>
+                    <signal name="activate" handler="password_entry_timeout" object="UmPasswordDialog" 
swapped="yes"/>
+                    <signal name="focus-out-event" handler="password_entry_focus_out_cb" after="yes" 
object="UmPasswordDialog" swapped="yes"/>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -87,7 +90,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="password-hint">
+                  <object class="GtkLabel" id="password_hint_label">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
@@ -112,7 +115,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="verify-hint">
+                  <object class="GtkLabel" id="verify_hint_label">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
@@ -136,12 +139,12 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="password-normal-verify-label">
+                  <object class="GtkLabel">
                     <property name="visible">True</property>
                     <property name="xalign">1</property>
                     <property name="label" translatable="yes">_Confirm New Password</property>
                     <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">verify-entry</property>
+                    <property name="mnemonic_widget">verify_entry</property>
                     <property name="margin_start">25</property>
                     <style>
                       <class name="dim-label"/>
@@ -153,12 +156,12 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="password-normal-password-label">
+                  <object class="GtkLabel">
                     <property name="visible">True</property>
                     <property name="xalign">1</property>
                     <property name="label" translatable="yes">_New Password</property>
                     <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">password-entry</property>
+                    <property name="mnemonic_widget">password_entry</property>
                     <property name="margin_start">25</property>
                     <style>
                       <class name="dim-label"/>
@@ -170,13 +173,18 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkEntry" id="password-entry">
+                  <object class="GtkEntry" id="password_entry">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="visibility">False</property>
                     <property name="hexpand">True</property>
                     <property name="activates_default">True</property>
                     <property name="input_purpose">password</property>
+                    <signal name="notify::text" handler="password_entry_changed" object="UmPasswordDialog" 
swapped="yes"/>
+                    <signal name="activate" handler="password_entry_timeout" object="UmPasswordDialog" 
swapped="yes"/>
+                    <signal name="focus-out-event" handler="password_entry_focus_out_cb" after="yes" 
object="UmPasswordDialog" swapped="yes"/>
+                    <signal name="key-press-event" handler="password_entry_key_press_cb" 
object="UmPasswordDialog" swapped="yes"/>
+                    <signal name="icon-press" handler="password_entry_icon_press_cb" 
object="UmPasswordDialog" swapped="yes"/>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -184,7 +192,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLevelBar" id="strength-indicator">
+                  <object class="GtkLevelBar" id="strength_indicator">
                     <property name="visible">True</property>
                     <property name="mode">discrete</property>
                     <property name="max-value">5</property>
@@ -202,12 +210,12 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="old-password-label">
+                  <object class="GtkLabel" id="old_password_label">
                     <property name="visible">True</property>
                     <property name="xalign">1</property>
                     <property name="label" translatable="yes">Current _Password</property>
                     <property name="use_underline">True</property>
-                    <property name="mnemonic_widget">old-password-entry</property>
+                    <property name="mnemonic_widget">old_password_entry</property>
                     <property name="margin_start">25</property>
                     <property name="margin_bottom">12</property>
                     <style>
@@ -220,7 +228,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkEntry" id="old-password-entry">
+                  <object class="GtkEntry" id="old_password_entry">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="visibility">False</property>
@@ -228,6 +236,9 @@
                     <property name="activates_default">True</property>
                     <property name="margin_bottom">12</property>
                     <property name="input_purpose">password</property>
+                    <signal name="notify::text" handler="old_password_entry_changed" 
object="UmPasswordDialog" swapped="yes"/>
+                    <signal name="activate" handler="password_entry_timeout" object="UmPasswordDialog" 
swapped="yes"/>
+                    <signal name="focus-out-event" handler="old_password_entry_focus_out_cb" after="yes" 
object="UmPasswordDialog" swapped="yes"/>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -235,11 +246,11 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkBox" id="action-radio-box">
+                  <object class="GtkBox" id="action_radio_box">
                     <property name="visible">True</property>
                     <property name="orientation">vertical</property>
                     <child>
-                      <object class="GtkRadioButton" id="action-login-radio">
+                      <object class="GtkRadioButton" id="action_login_radio">
                         <property name="label" translatable="yes">Allow user to change their password on 
next login</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
@@ -252,14 +263,15 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkRadioButton" id="action-now-radio">
+                      <object class="GtkRadioButton" id="action_now_radio">
                         <property name="label" translatable="yes">Set a password now</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
                         <property name="active">True</property>
                         <property name="draw_indicator">True</property>
-                        <property name="group">action-login-radio</property>
+                        <property name="group">action_login_radio</property>
+                        <signal name="toggled" handler="action_now_radio_toggled_cb" 
object="UmPasswordDialog" swapped="yes"/>
                       </object>
                       <packing>
                         <property name="position">1</property>
@@ -286,5 +298,8 @@
         </child>
       </object>
     </child>
-  </object>
+    <action-widgets>
+      <action-widget response="0">cancel_button</action-widget>
+    </action-widgets>
+  </template>
 </interface>
diff --git a/panels/user-accounts/user-accounts.gresource.xml 
b/panels/user-accounts/user-accounts.gresource.xml
index b37da5319..8b0fc5c4b 100644
--- a/panels/user-accounts/user-accounts.gresource.xml
+++ b/panels/user-accounts/user-accounts.gresource.xml
@@ -6,7 +6,6 @@
     <file alias="avatar-chooser.ui" preprocess="xml-stripblanks">data/avatar-chooser.ui</file>
     <file alias="join-dialog.ui" preprocess="xml-stripblanks">data/join-dialog.ui</file>
     <file alias="account-fingerprint.ui" preprocess="xml-stripblanks">data/account-fingerprint.ui</file>
-    <file alias="password-dialog.ui" preprocess="xml-stripblanks">data/password-dialog.ui</file>
     <file alias="history-dialog.ui" preprocess="xml-stripblanks">data/history-dialog.ui</file>
     <file alias="user-accounts-dialog.css">data/user-accounts-dialog.css</file>
     <file alias="carousel.ui" preprocess="xml-stripblanks">data/carousel.ui</file>
@@ -23,5 +22,6 @@
     <file alias="right-little-finger.png">data/icons/right-little-finger.png</file>
     <file alias="right-ring-finger.png">data/icons/right-ring-finger.png</file>
     <file alias="right-thumb.png">data/icons/right-thumb.png</file>
+    <file preprocess="xml-stripblanks">um-password-dialog.ui</file>
   </gresource>
 </gresources>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e5480f84b..37dce974c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -201,7 +201,6 @@ panels/user-accounts/data/avatar-chooser.ui
 panels/user-accounts/data/gnome-user-accounts-panel.desktop.in.in
 panels/user-accounts/data/history-dialog.ui
 panels/user-accounts/data/join-dialog.ui
-panels/user-accounts/data/password-dialog.ui
 panels/user-accounts/org.gnome.controlcenter.user-accounts.policy.in
 panels/user-accounts/pw-utils.c
 panels/user-accounts/run-passwd.c
@@ -210,6 +209,7 @@ panels/user-accounts/um-account-type.c
 panels/user-accounts/um-fingerprint-dialog.c
 panels/user-accounts/um-history-dialog.c
 panels/user-accounts/um-password-dialog.c
+panels/user-accounts/um-password-dialog.ui
 panels/user-accounts/um-photo-dialog.c
 panels/user-accounts/um-realm-manager.c
 panels/user-accounts/um-utils.c



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]