[accounts-dialog] Factor out login options



commit 843c20428bfe8504bc50edf7ed4482f4ad33729a
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jan 19 19:34:13 2010 -0500

    Factor out login options

 src/Makefile.am        |    2 +
 src/main.c             |  121 +-------------------------
 src/um-login-options.c |  228 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/um-login-options.h |   34 +++++++
 4 files changed, 267 insertions(+), 118 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 01e996c..d05d2ad 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -34,6 +34,8 @@ accounts_dialog_SOURCES = \
 	um-language-dialog.c		\
 	um-location-dialog.h		\
 	um-location-dialog.c		\
+	um-login-options.h		\
+	um-login-options.c		\
 	um-names-dialog.h		\
 	um-names-dialog.c		\
 	um-password-dialog.h		\
diff --git a/src/main.c b/src/main.c
index ab8d571..43db271 100644
--- a/src/main.c
+++ b/src/main.c
@@ -49,6 +49,7 @@
 #include "um-names-dialog.h"
 #include "um-language-dialog.h"
 #include "um-location-dialog.h"
+#include "um-login-options.h"
 #include "um-password-dialog.h"
 #include "um-photo-dialog.h"
 #include "um-email-dialog.h"
@@ -69,6 +70,7 @@ typedef struct {
         UmPhotoDialog *photo_dialog;
         UmLanguageDialog *language_dialog;
         UmLocationDialog *location_dialog;
+        UmLoginOptions *login_options;
         UmEmailDialog *email_dialog;
 
         PolkitAuthority *authority;
@@ -91,12 +93,6 @@ enum {
         NUM_USER_LIST_COLS
 };
 
-enum {
-        AUTOLOGIN_NAME_COL,
-        AUTOLOGIN_USER_COL,
-        NUM_AUTOLOGIN_COLS
-};
-
 static UmUser *
 get_selected_user (UserAccountDialog *d)
 {
@@ -125,7 +121,6 @@ user_added (UmUserManager *um, UmUser *user, UserAccountDialog *d)
         GtkWidget *widget;
         GtkTreeModel *model;
         GtkListStore *store;
-        GtkListStore *list_store;
         GtkTreeIter iter;
         GtkTreeIter dummy;
         GdkPixbuf *pixbuf;
@@ -168,15 +163,6 @@ user_added (UmUserManager *um, UmUser *user, UserAccountDialog *d)
             !gtk_tree_selection_get_selected (selection, &model, &dummy)) {
                 gtk_tree_selection_select_iter (selection, &iter);
         }
-
-        /* add the user to the automatic login list */
-        widget = get_widget (d, "dm-automatic-login-combobox");
-        list_store = (GtkListStore*)gtk_combo_box_get_model (GTK_COMBO_BOX (widget));
-        gtk_list_store_append (list_store, &iter);
-        gtk_list_store_set (list_store, &iter,
-                            AUTOLOGIN_NAME_COL, um_user_get_real_name (user),
-                            AUTOLOGIN_USER_COL, user,
-                            -1);
 }
 
 static void
@@ -197,9 +183,7 @@ user_removed (UmUserManager *um, UmUser *user, UserAccountDialog *d)
         GtkTreeModel *model;
         GtkTreeSelection *selection;
         GtkListStore *store;
-        GtkListStore *list_store;
         GtkTreeIter iter, next;
-        GtkComboBox *combo;
         UmUser *u;
 
         g_debug ("user removed: %s\n", um_user_get_user_name (user));
@@ -225,37 +209,6 @@ user_removed (UmUserManager *um, UmUser *user, UserAccountDialog *d)
                         }
                 } while (gtk_tree_model_iter_next (model, &iter));
         }
-
-        /* remove the user from the automatic login list */
-        combo = GTK_COMBO_BOX (get_widget (d, "dm-automatic-login-combobox"));
-        model = gtk_combo_box_get_model (combo);
-        list_store = (GtkListStore*)model;
-        gtk_combo_box_get_active_iter (combo, &iter);
-        gtk_tree_model_get (model, &iter, AUTOLOGIN_USER_COL, &u, -1);
-        if (u != NULL) {
-                if (um_user_get_uid (user) == um_user_get_uid (u)) {
-                        /* autologin user got removed, set back to Disabled */
-                        gtk_list_store_remove (list_store, &iter);
-                        gtk_combo_box_set_active (combo, 0);
-                        g_object_unref (u);
-                        return;
-                }
-                g_object_unref (u);
-        }
-        if (gtk_tree_model_get_iter_first (model, &iter)) {
-                do {
-                        gtk_tree_model_get (model, &iter, AUTOLOGIN_USER_COL, &u, -1);
-
-                        if (u != NULL) {
-                                if (um_user_get_uid (user) == um_user_get_uid (u)) {
-                                        gtk_list_store_remove (list_store, &iter);
-                                        g_object_unref (u);
-                                        return;
-                                }
-                                g_object_unref (u);
-                        }
-                } while (gtk_tree_model_iter_next (model, &iter));
-        }
 }
 
 static void show_user (UmUser *user, UserAccountDialog *d);
@@ -1077,74 +1030,6 @@ setup_main_window (UserAccountDialog *d)
 }
 
 static void
-update_login_options (UserAccountDialog *d)
-{
-}
-
-static gint
-sort_login_users (GtkTreeModel *model,
-                  GtkTreeIter  *a,
-                  GtkTreeIter  *b,
-                  gpointer      data)
-{
-        UmUser *ua, *ub;
-        gint result;
-
-        gtk_tree_model_get (model, a, AUTOLOGIN_USER_COL, &ua, -1);
-        gtk_tree_model_get (model, b, AUTOLOGIN_USER_COL, &ub, -1);
-
-        if (ua == NULL)
-                result = -1;
-        else if (ub == NULL)
-                result = 1;
-        else if (um_user_get_uid (ua) == getuid ())
-                result = -1;
-        else if (um_user_get_uid (ub) == getuid ())
-                result = 1;
-        else
-                result = um_user_collate (ua, ub);
-
-        if (ua)
-                g_object_unref (ua);
-
-        if (ub)
-                g_object_unref (ub);
-
-        return result;
-}
-
-static void
-setup_login_options (UserAccountDialog *d)
-{
-        GtkWidget *widget;
-        GtkListStore *store;
-        GtkTreeIter iter;
-
-        /* TOOD: get actual login screen options */
-        widget = get_widget (d, "dm-automatic-login-combobox");
-        store = gtk_list_store_new (2, G_TYPE_STRING, UM_TYPE_USER);
-        gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
-        gtk_list_store_append (store, &iter);
-        gtk_list_store_set (store, &iter, 0, _("Disabled"), 1, NULL, -1);
-
-        gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
-
-        gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store), sort_login_users, NULL, NULL);
-        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
-
-        g_signal_connect_swapped (widget, "changed", G_CALLBACK (update_login_options), d);
-
-        widget = get_widget (d, "dm-show-user-list-checkbutton");
-        g_signal_connect_swapped (widget, "toggled", G_CALLBACK (update_login_options), d);
-
-        widget = get_widget (d, "dm-show-power-buttons-checkbutton");
-        g_signal_connect_swapped (widget, "toggled", G_CALLBACK (update_login_options), d);
-
-        widget = get_widget (d, "dm-show-password-hints-checkbutton");
-        g_signal_connect_swapped (widget, "toggled", G_CALLBACK (update_login_options), d);
-}
-
-static void
 eat_my_logs (const gchar    *log_domain,
              GLogLevelFlags  log_level,
              const gchar    *message,
@@ -1245,8 +1130,8 @@ main (int argc, char *argv[])
 
         d->authority = polkit_authority_get ();
 
-        setup_login_options (d);
         setup_main_window (d);
+        d->login_options = um_login_options_new (d->builder);
         d->account_type_dialog = um_account_type_dialog_new ();
         d->account_dialog = um_account_dialog_new ();
         d->names_dialog = um_names_dialog_new ();
diff --git a/src/um-login-options.c b/src/um-login-options.c
new file mode 100644
index 0000000..42a19fc
--- /dev/null
+++ b/src/um-login-options.c
@@ -0,0 +1,228 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2009-2010  Red Hat, Inc,
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Written by: Matthias Clasen <mclasen redhat com>
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "um-login-options.h"
+#include "um-user-manager.h"
+#include "um-user.h"
+
+struct _UmLoginOptions {
+	GtkWidget *autologin_combo;
+	GtkWidget *userlist_check;
+	GtkWidget *power_check;
+	GtkWidget *hints_check;
+	GtkWidget *guest_check;
+
+	UmUserManager *manager;
+};
+
+enum {
+        AUTOLOGIN_NAME_COL,
+        AUTOLOGIN_USER_COL,
+        NUM_AUTOLOGIN_COLS
+};
+
+static gint
+sort_login_users (GtkTreeModel *model,
+                  GtkTreeIter  *a,
+                  GtkTreeIter  *b,
+                  gpointer      data)
+{
+        UmUser *ua, *ub;
+        gint result;
+
+        gtk_tree_model_get (model, a, AUTOLOGIN_USER_COL, &ua, -1);
+        gtk_tree_model_get (model, b, AUTOLOGIN_USER_COL, &ub, -1);
+
+        if (ua == NULL)
+                result = -1;
+        else if (ub == NULL)
+                result = 1;
+        else if (um_user_get_uid (ua) == getuid ())
+                result = -1;
+        else if (um_user_get_uid (ub) == getuid ())
+                result = 1;
+        else
+                result = um_user_collate (ua, ub);
+
+        if (ua)
+                g_object_unref (ua);
+
+        if (ub)
+                g_object_unref (ub);
+
+        return result;
+}
+
+static void
+user_added (UmUserManager *um, UmUser *user, UmLoginOptions *d)
+{
+	GtkComboBox *combo;
+	GtkListStore *store;
+	GtkTreeIter iter;
+
+	combo = GTK_COMBO_BOX (d->autologin_combo);
+        store = (GtkListStore*)gtk_combo_box_get_model (combo);
+        gtk_list_store_append (store, &iter);
+        gtk_list_store_set (store, &iter,
+                            AUTOLOGIN_NAME_COL, um_user_get_real_name (user),
+                            AUTOLOGIN_USER_COL, user,
+                            -1);
+}
+
+static void
+user_removed (UmUserManager *um, UmUser *user, UmLoginOptions *d)
+{
+	GtkComboBox *combo;
+	GtkTreeModel *model;
+	GtkListStore *store;
+	GtkTreeIter iter;
+	UmUser *u;
+
+	combo = GTK_COMBO_BOX (d->autologin_combo);
+        model = gtk_combo_box_get_model (combo);
+        store = (GtkListStore*)model;
+        gtk_combo_box_get_active_iter (combo, &iter);
+        gtk_tree_model_get (model, &iter, AUTOLOGIN_USER_COL, &u, -1);
+        if (u != NULL) {
+                if (um_user_get_uid (user) == um_user_get_uid (u)) {
+                        /* autologin user got removed, set back to Disabled */
+                        gtk_list_store_remove (store, &iter);
+                        gtk_combo_box_set_active (combo, 0);
+                        g_object_unref (u);
+                        return;
+                }
+                g_object_unref (u);
+        }
+        if (gtk_tree_model_get_iter_first (model, &iter)) {
+                do {
+                        gtk_tree_model_get (model, &iter, AUTOLOGIN_USER_COL, &u, -1);
+
+                        if (u != NULL) {
+                                if (um_user_get_uid (user) == um_user_get_uid (u)) {
+                                        gtk_list_store_remove (store, &iter);
+                                        g_object_unref (u);
+                                        return;
+                                }
+                                g_object_unref (u);
+                        }
+                } while (gtk_tree_model_iter_next (model, &iter));
+        }
+}
+
+static void
+user_changed (UmUserManager  *manager,
+              UmUser         *user,
+              UmLoginOptions *d)
+{
+	/* FIXME */
+}
+
+static void
+users_loaded (UmUserManager  *manager,
+              UmLoginOptions *d)
+{
+	GSList *list, *l;
+	UmUser *user;
+
+        list = um_user_manager_list_users (manager);
+        for (l = list; l; l = l->next) {
+                user = l->data;
+                user_added (manager, user, d);
+        }
+        g_slist_free (list);
+
+        g_signal_connect (manager, "user-added", G_CALLBACK (user_added), d);
+        g_signal_connect (manager, "user-removed", G_CALLBACK (user_removed), d);
+        g_signal_connect (manager, "user-changed", G_CALLBACK (user_changed), d);
+}
+
+static void
+update_login_options (GtkWidget      *widget,
+                      UmLoginOptions *d)
+{
+}
+
+UmLoginOptions *
+um_login_options_new (GtkBuilder *builder)
+{
+        GtkWidget *widget;
+        GtkListStore *store;
+        GtkTreeIter iter;
+	gchar *filename;
+	GError *error;
+	UmLoginOptions *um;
+
+        /* TODO: get actual login screen options */
+
+	um = g_new0 (UmLoginOptions, 1);
+
+	um->manager = um_user_manager_ref_default ();
+	g_signal_connect (um->manager, "users-loaded",
+                          G_CALLBACK (users_loaded), um);
+
+	widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-automatic-login-combobox");
+	um->autologin_combo = widget;
+
+        store = gtk_list_store_new (2, G_TYPE_STRING, UM_TYPE_USER);
+        gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
+        gtk_list_store_append (store, &iter);
+        gtk_list_store_set (store, &iter, 0, _("Disabled"), 1, NULL, -1);
+
+        gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0);
+
+        gtk_tree_sortable_set_default_sort_func (GTK_TREE_SORTABLE (store), sort_login_users, NULL, NULL);
+        gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
+
+        g_signal_connect (widget, "changed",
+                          G_CALLBACK (update_login_options), um);
+
+	widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-show-user-list-checkbutton");
+	um->userlist_check = widget;
+        g_signal_connect (widget, "toggled",
+                          G_CALLBACK (update_login_options), um);
+
+	widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-show-power-buttons-checkbutton");
+	um->power_check = widget;
+        g_signal_connect(widget, "toggled",
+                         G_CALLBACK (update_login_options), um);
+
+	widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-show-password-hints-checkbutton");
+	um->hints_check = widget;
+        g_signal_connect (widget, "toggled",
+                          G_CALLBACK (update_login_options), um);
+
+	widget = (GtkWidget *) gtk_builder_get_object (builder, "dm-allow-guest-login-checkbutton");
+	um->guest_check = widget;
+        g_signal_connect (widget, "toggled",
+                          G_CALLBACK (update_login_options), um);
+}
+
diff --git a/src/um-login-options.h b/src/um-login-options.h
new file mode 100644
index 0000000..949e0c4
--- /dev/null
+++ b/src/um-login-options.h
@@ -0,0 +1,34 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2009-2010  Red Hat, Inc,
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Written by: Matthias Clasen <mclasen redhat com>
+ */
+
+#ifndef __UM_LOGIN_OPTIONS_H__
+#define __UM_LOGIN_OPTIONS_H__
+
+G_BEGIN_DECLS
+
+typedef struct _UmLoginOptions UmLoginOptions;
+
+UmLoginOptions *um_login_options_new      (GtkBuilder *builder);
+void            um_login_options_free     (UmLoginOptions *options);
+
+G_END_DECLS
+
+#endif



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