[gdm/wip/initial-setup] Use ActUserManager api to create the user



commit bdc0b5bcc4e2777a6c84ed6724296061841a50cd
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed May 18 23:50:40 2011 -0400

    Use ActUserManager api to create the user
    
    Adding a dependency on 2 minutes old accountsservice release...
    thats gotta be some kind of record.

 configure.ac                          |    2 +-
 gui/initial-setup/gdm-initial-setup.c |  106 ++++++++++++++++++---------------
 2 files changed, 58 insertions(+), 50 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 6fece68..36dbcfd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -51,7 +51,7 @@ LIBCANBERRA_GTK_REQUIRED_VERSION=0.4
 #FONTCONFIG_REQUIRED_VERSION=2.6.0
 FONTCONFIG_REQUIRED_VERSION=2.5.0
 UPOWER_REQUIRED_VERSION=0.9.0
-ACCOUNTS_SERVICE_REQUIRED_VERSION=0.6.5
+ACCOUNTS_SERVICE_REQUIRED_VERSION=0.6.11
 
 EXTRA_COMPILE_WARNINGS(yes)
 
diff --git a/gui/initial-setup/gdm-initial-setup.c b/gui/initial-setup/gdm-initial-setup.c
index 3d45e92..b2818f8 100644
--- a/gui/initial-setup/gdm-initial-setup.c
+++ b/gui/initial-setup/gdm-initial-setup.c
@@ -962,47 +962,17 @@ confirm_entry_focus_out (GtkWidget     *entry,
         return FALSE;
 }
 
-/* FIXME: ActUserManager should have this */
 static void
 create_user (SetupData *setup)
 {
-        GDBusConnection *connection;
-        GVariant *result;
         const gchar *username;
         const gchar *fullname;
-        GError *error;
 
         username = gtk_combo_box_text_get_active_text (OBJ(GtkComboBoxText*, "account-username-combo"));
         fullname = gtk_entry_get_text (OBJ(GtkEntry*, "account-fullname-entry"));
-        connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, NULL);
-
-        error = NULL;
-        result = g_dbus_connection_call_sync (connection,
-                                              "org.freedesktop.Accounts",
-                                              "/org/freedesktop/Accounts",
-                                              "org.freedesktop.Accounts",
-                                              "CreateUser",
-                                              g_variant_new ("(ssi)",
-                                                             username,
-                                                             fullname,
-                                                             setup->account_type),
-                                              NULL,
-                                              G_DBUS_CALL_FLAGS_NONE,
-                                              -1,
-                                              NULL,
-                                              &error);
-        if (result == NULL) {
-                g_warning ("Failed to create user: %s", error->message);
-                g_error_free (error);
-                goto out;
-        }
-
-        g_variant_unref (result);
 
+        act_user_manager_create_user (setup->act_client, username, fullname, setup->account_type);
         setup->act_user = act_user_manager_get_user (setup->act_client, username);
-
-out:
-        g_object_unref (connection);
 }
 
 static void save_account_data (SetupData *setup);
@@ -1019,6 +989,44 @@ save_when_loaded (ActUser *user, GParamSpec *pspec, SetupData *setup)
 }
 
 static void
+clear_account_page (SetupData *setup)
+{
+        GtkWidget *fullname_entry;
+        GtkWidget *username_combo;
+        GtkWidget *password_check;
+        GtkWidget *admin_check;
+        GtkWidget *password_entry;
+        GtkWidget *confirm_entry;
+        gboolean need_password;
+
+        fullname_entry = WID("account-fullname-entry");
+        username_combo = WID("account-username-combo");
+        password_check = WID("account-password-check");
+        admin_check = WID("account-admin-check");
+        password_entry = WID("account-password-entry");
+        confirm_entry = WID("account-confirm-entry");
+
+        setup->valid_name = FALSE;
+        setup->valid_username = FALSE;
+        setup->valid_password = TRUE;
+        setup->password_mode = ACT_USER_PASSWORD_MODE_NONE;
+        setup->account_type = ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR;
+        setup->user_data_unsaved = FALSE;
+
+        need_password = setup->password_mode != ACT_USER_PASSWORD_MODE_NONE;
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_check), need_password);
+        gtk_widget_set_sensitive (password_entry, need_password);
+        gtk_widget_set_sensitive (confirm_entry, need_password);
+
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (admin_check), setup->account_type == ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR);
+
+        gtk_entry_set_text (GTK_ENTRY (fullname_entry), "");
+        gtk_list_store_clear (GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (username_combo))));
+        gtk_entry_set_text (GTK_ENTRY (password_entry), "");
+        gtk_entry_set_text (GTK_ENTRY (confirm_entry), "");
+}
+
+static void
 save_account_data (SetupData *setup)
 {
         if (!setup->user_data_unsaved) {
@@ -1036,7 +1044,11 @@ save_account_data (SetupData *setup)
                 create_user (setup);
         }
 
-        g_assert (setup->act_user);
+        if (setup->act_user == NULL) {
+                g_warning ("User creation failed");
+                clear_account_page (setup);
+                return;
+        }
 
         if (!act_user_is_loaded (setup->act_user)) {
                 if (when_loaded == 0)
@@ -1071,7 +1083,6 @@ prepare_account_page (SetupData *setup)
         GtkWidget *admin_check;
         GtkWidget *password_entry;
         GtkWidget *confirm_entry;
-        gboolean need_password;
 
         fullname_entry = WID("account-fullname-entry");
         username_combo = WID("account-username-combo");
@@ -1080,22 +1091,6 @@ prepare_account_page (SetupData *setup)
         password_entry = WID("account-password-entry");
         confirm_entry = WID("account-confirm-entry");
 
-        setup->act_client = act_user_manager_get_default ();
-
-        setup->valid_name = FALSE;
-        setup->valid_username = FALSE;
-        setup->valid_password = TRUE;
-        setup->password_mode = ACT_USER_PASSWORD_MODE_NONE;
-        setup->account_type = ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR;
-        setup->user_data_unsaved = FALSE;
-
-        need_password = setup->password_mode != ACT_USER_PASSWORD_MODE_NONE;
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (password_check), need_password);
-        gtk_widget_set_sensitive (password_entry, need_password);
-        gtk_widget_set_sensitive (confirm_entry, need_password);
-
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (admin_check), setup->account_type == ACT_USER_ACCOUNT_TYPE_ADMINISTRATOR);
-
         g_signal_connect (fullname_entry, "notify::text",
                           G_CALLBACK (fullname_changed), setup);
         g_signal_connect (username_combo, "changed",
@@ -1111,6 +1106,9 @@ prepare_account_page (SetupData *setup)
         g_signal_connect_after (confirm_entry, "focus-out-event",
                                 G_CALLBACK (confirm_entry_focus_out), setup);
 
+        setup->act_client = act_user_manager_get_default ();
+
+        clear_account_page (setup);
         update_account_page_status (setup);
 }
 
@@ -1367,6 +1365,16 @@ begin_autologin (SetupData *setup)
         const gchar *username;
         GVariant *ret;
 
+        if (setup->slave_connection == NULL) {
+                g_warning ("No slave connection; not initiating autologin");
+                return;
+        }
+
+        if (setup->act_user == NULL) {
+                g_warning ("No username; not initiating autologin");
+                return;
+        }
+
         username = act_user_get_user_name (setup->act_user);
 
         ret = g_dbus_connection_call_sync (setup->slave_connection,



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