[accounts-dialog] Improve the handling of account locking



commit b5bdab629acad42d88a3986e37ca27e6910d3960
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Mar 25 11:55:49 2010 -0400

    Improve the handling of account locking
    
    Allow to unlock an account, and show the right text for other password modes.

 data/password-dialog.ui  |    4 ++++
 src/main.c               |    6 ++++--
 src/um-password-dialog.c |   37 +++++++++++++++++++++++++++++++++++++
 src/um-user.c            |   11 +++++++++++
 src/um-user.h            |    3 ++-
 5 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/data/password-dialog.ui b/data/password-dialog.ui
index c7f0bf9..a896474 100644
--- a/data/password-dialog.ui
+++ b/data/password-dialog.ui
@@ -26,6 +26,10 @@
         <col id="0" translatable="yes">Disable this account</col>
         <col id="1">3</col>
       </row>
+      <row>
+        <col id="0" translatable="yes">Enable this account</col>
+        <col id="1">4</col>
+      </row>
     </data>
   </object>
   <object class="GtkDialog" id="dialog">
diff --git a/src/main.c b/src/main.c
index 58ebf9a..ccd6072 100644
--- a/src/main.c
+++ b/src/main.c
@@ -500,8 +500,9 @@ show_user (UmUser *user, UserAccountDialog *d)
                 }
         }  while (gtk_tree_model_iter_next (model, &iter));
 
-        if (um_user_get_locked (user))
+        if (um_user_get_locked (user)) {
                 text = C_("Password mode", "Account disabled");
+        }
         else {
                 switch (um_user_get_password_mode (user)) {
                 case UM_PASSWORD_MODE_REGULAR:
@@ -514,7 +515,8 @@ show_user (UmUser *user, UserAccountDialog *d)
                         text = C_("Password mode", "None");
                         break;
                 default:
-                g_assert_not_reached ();
+                        g_assert_not_reached ();
+                }
         }
         label = get_widget (d, "account-password-value-label");
         gtk_label_set_text (GTK_LABEL (label), text);
diff --git a/src/um-password-dialog.c b/src/um-password-dialog.c
index 97b699d..5d96234 100644
--- a/src/um-password-dialog.c
+++ b/src/um-password-dialog.c
@@ -619,8 +619,10 @@ um_password_dialog_new (void)
         builder = gtk_builder_new ();
 
         error = NULL;
+#if 0
         filename = UIDIR "/password-dialog.ui";
         if (!g_file_test (filename, G_FILE_TEST_EXISTS))
+#endif
                 filename = "../data/password-dialog.ui";
         if (!gtk_builder_add_from_file (builder, filename, &error)) {
                 g_error ("%s", error->message);
@@ -741,11 +743,35 @@ um_password_dialog_free (UmPasswordDialog *um)
         g_free (um);
 }
 
+static gboolean
+visible_func (GtkTreeModel     *model,
+              GtkTreeIter      *iter,
+              UmPasswordDialog *um)
+{
+        if (um->user) {
+                gint mode; 
+                gboolean locked = um_user_get_locked (um->user);
+
+                gtk_tree_model_get (model, iter, 1, &mode, -1);
+
+                if (mode == 3 && locked)
+                        return FALSE;
+
+                if (mode == 4 && !locked)
+                        return FALSE;
+
+                return TRUE;
+        }
+
+        return TRUE;
+}
+
 void
 um_password_dialog_set_user (UmPasswordDialog *um,
                              UmUser           *user)
 {
         GdkPixbuf *pixbuf;
+        GtkTreeModel *model;
 
         if (um->passwd_handler) {
                 passwd_destroy (um->passwd_handler);
@@ -784,6 +810,17 @@ um_password_dialog_set_user (UmPasswordDialog *um,
                         um->old_password_ok = TRUE;
                 }
         }
+
+        model = gtk_combo_box_get_model (GTK_COMBO_BOX (um->action_combo));
+        if (!GTK_IS_TREE_MODEL_FILTER (model)) {
+                model = gtk_tree_model_filter_new (model, NULL);
+                gtk_combo_box_set_model (GTK_COMBO_BOX (um->action_combo), model);
+                gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model),
+                                                        visible_func,
+                                                        um, NULL);
+        }
+
+        gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
 }
 
 void
diff --git a/src/um-user.c b/src/um-user.c
index 99195c7..15b2e8d 100644
--- a/src/um-user.c
+++ b/src/um-user.c
@@ -969,6 +969,17 @@ um_user_set_password (UmUser      *user,
                 }
                 g_free (crypted);
         }
+        else if (password_mode == 3 || password_mode == 4) {
+                if (!dbus_g_proxy_call (user->proxy,
+                                        "SetLocked",
+                                        &error,
+                                        G_TYPE_BOOLEAN, (password_mode == 3),
+                                        G_TYPE_INVALID,
+                                        G_TYPE_INVALID)) {
+                        g_warning ("SetLocked call failed: %s", error->message);
+                        g_error_free (error);
+                }
+        }
         else {
                 if (!dbus_g_proxy_call (user->proxy,
                                         "SetPasswordMode",
diff --git a/src/um-user.h b/src/um-user.h
index c149c41..43a88b0 100644
--- a/src/um-user.h
+++ b/src/um-user.h
@@ -41,7 +41,8 @@ typedef enum {
         UM_PASSWORD_MODE_REGULAR,
         UM_PASSWORD_MODE_SET_AT_LOGIN,
         UM_PASSWORD_MODE_NONE,
-        UM_PASSWORD_MODE_DISABLED
+        UM_PASSWORD_MODE_DISABLED,
+        UM_PASSWORD_MODE_ENABLED
 } UmPasswordMode;
 
 typedef struct _UmUser UmUser;



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