[gnome-initial-setup] summary: Split out



commit 6a9337bf7f3e7637a3ff4cb6abcd35f0cd18fbe6
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Jun 22 15:10:36 2012 -0400

    summary: Split out

 gnome-initial-setup/Makefile.am           |    5 +-
 gnome-initial-setup/gis-summary-page.c    |  132 ++++++-----------------------
 gnome-initial-setup/gis-summary-page.h    |   14 +++
 gnome-initial-setup/gis-utils.c           |   83 ++++++++++++++++++
 gnome-initial-setup/gis-utils.h           |   17 ++++
 gnome-initial-setup/gnome-initial-setup.c |   36 ++++++--
 gnome-initial-setup/gnome-initial-setup.h |    3 +
 7 files changed, 173 insertions(+), 117 deletions(-)
---
diff --git a/gnome-initial-setup/Makefile.am b/gnome-initial-setup/Makefile.am
index 3743ac9..036d41e 100644
--- a/gnome-initial-setup/Makefile.am
+++ b/gnome-initial-setup/Makefile.am
@@ -38,10 +38,12 @@ gnome_initial_setup_SOURCES =	\
 	gnome-initial-setup.c gnome-initial-setup.h \
 	cc-notebook.c cc-notebook.h \
 	gis-assistant.c gis-assistant.h \
+	gis-utils.c gis-utils.h \
 	gis-welcome-page.c gis-welcome-page.h \
 	gis-eula-pages.c gis-eula-pages.h \
 	gis-location-page.c gis-location-page.h \
 	gis-network-page.c gis-network-page.h \
+	gis-summary-page.c gis-summary-page.h \
 	gis-goa-page.c gis-goa-page.h \
 	cc-online-accounts-add-account-dialog.c cc-online-accounts-add-account-dialog.h \
 	panel-cell-renderer-signal.c panel-cell-renderer-signal.h \
@@ -59,8 +61,7 @@ autostartdir = $(sysconfdir)/xdg/autostart
 autostart_DATA = welcome-tour.desktop
 
 included_source_files = \
-	gis-account-page.c \
-	gis-summary-page.c
+	gis-account-page.c
 
 EXTRA_DIST = \
 	$(sys_DATA) \
diff --git a/gnome-initial-setup/gis-summary-page.c b/gnome-initial-setup/gis-summary-page.c
index d1e7e67..97b6df0 100644
--- a/gnome-initial-setup/gis-summary-page.c
+++ b/gnome-initial-setup/gis-summary-page.c
@@ -1,115 +1,34 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 
-/* Other setup {{{1 */
+#include "config.h"
+#include "gis-summary-page.h"
 
-static void
-copy_account_file (SetupData   *setup,
-                   const gchar *relative_path)
-{
-        const gchar *username;
-        const gchar *homedir;
-        GSList *dirs = NULL, *l;
-        gchar *p, *tmp;
-        gchar *argv[20];
-        gint i;
-        gchar *from;
-        gchar *to;
-        GError *error = NULL;
+#include "gis-utils.h"
 
-        username = act_user_get_user_name (setup->act_user);
-        homedir = act_user_get_home_dir (setup->act_user);
+#include <glib/gi18n.h>
+#include <gio/gio.h>
 
-        from = g_build_filename (g_get_home_dir (), relative_path, NULL);
-        to = g_build_filename (homedir, relative_path, NULL);
+#include <gdm-greeter-client.h>
 
-        p = g_path_get_dirname (relative_path);
-        while (strcmp (p, ".") != 0) {
-                dirs = g_slist_prepend (dirs, g_build_filename (homedir, p, NULL));
-                tmp = g_path_get_dirname (p);
-                g_free (p);
-                p = tmp;
-        }
-
-        i = 0;
-        argv[i++] = "/usr/bin/pkexec";
-        argv[i++] = "install";
-        argv[i++] = "--owner";
-        argv[i++] = (gchar *)username;
-        argv[i++] = "--group";
-        argv[i++] = (gchar *)username;
-        argv[i++] = "--mode";
-        argv[i++] = "755";
-        argv[i++] = "--directory";
-        for (l = dirs; l; l = l->next) {
-                argv[i++] = l->data;
-                if (i == 20) {
-                        g_warning ("Too many subdirectories");
-                        goto out;
-                }
-        }
-        argv[i++] = NULL;
-
-        if (!g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, &error)) {
-                g_warning ("Failed to copy account data: %s", error->message);
-                g_error_free (error);
-                goto out;
-        }
-
-        i = 0;
-        argv[i++] = "/usr/bin/pkexec";
-        argv[i++] = "install";
-        argv[i++] = "--owner";
-        argv[i++] = (gchar *)username;
-        argv[i++] = "--group";
-        argv[i++] = (gchar *)username;
-        argv[i++] = "--mode";
-        argv[i++] = "755";
-        argv[i++] = from;
-        argv[i++] = to;
-        argv[i++] = NULL;
-
-        if (!g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, &error)) {
-                g_warning ("Failed to copy account data: %s", error->message);
-                g_error_free (error);
-                goto out;
-        }
-
-out:
-        g_slist_free_full (dirs, g_free);
-        g_free (to);
-        g_free (from);
-}
-
-static void
-copy_account_data (SetupData *setup)
-{
-        /* here is where we copy all the things we just
-         * configured, from the current users home dir to the
-         * account that was created in the first step
-         */
-        g_debug ("Copying account data");
-        g_settings_sync ();
-
-        copy_account_file (setup, ".config/dconf/user");
-        copy_account_file (setup, ".config/goa-1.0/accounts.conf");
-        copy_account_file (setup, ".gnome2/keyrings/Default.keyring");
-}
-
-static void
-connect_to_slave (SetupData *setup)
+static GdmGreeterClient *
+connect_to_slave (void)
 {
         GError *error = NULL;
         gboolean res;
+        GdmGreeterClient *greeter_client;
 
-        setup->greeter_client = gdm_greeter_client_new ();
+        greeter_client = gdm_greeter_client_new ();
 
-        res = gdm_greeter_client_open_connection (setup->greeter_client, &error);
+        res = gdm_greeter_client_open_connection (greeter_client, &error);
 
         if (!res) {
                 g_warning ("Failed to open connection to slave: %s", error->message);
                 g_error_free (error);
-                g_clear_object (&setup->greeter_client);
-                return;
+                g_object_unref (greeter_client);
+                return NULL;
         }
+
+        return greeter_client;
 }
 
 static void
@@ -119,7 +38,7 @@ on_ready_for_auto_login (GdmGreeterClient *client,
 {
         const gchar *username;
 
-        username = act_user_get_user_name (setup->act_user);
+        username = act_user_get_user_name (gis_get_act_user (setup));
 
         g_debug ("Initiating autologin for %s", username);
         gdm_greeter_client_call_begin_auto_login (client, username);
@@ -131,23 +50,26 @@ on_ready_for_auto_login (GdmGreeterClient *client,
 static void
 begin_autologin (SetupData *setup)
 {
-        if (setup->greeter_client == NULL) {
+        GdmGreeterClient *greeter_client = connect_to_slave ();
+        ActUser *act_user = gis_get_act_user (setup);
+
+        if (greeter_client == NULL) {
                 g_warning ("No slave connection; not initiating autologin");
                 return;
         }
 
-        if (setup->act_user == NULL) {
+        if (act_user == NULL) {
                 g_warning ("No username; not initiating autologin");
                 return;
         }
 
         g_debug ("Preparing to autologin");
 
-        g_signal_connect (setup->greeter_client,
+        g_signal_connect (greeter_client,
                           "ready",
                           G_CALLBACK (on_ready_for_auto_login),
                           setup);
-        gdm_greeter_client_call_start_conversation (setup->greeter_client, "gdm-autologin");
+        gdm_greeter_client_call_start_conversation (greeter_client, "gdm-autologin");
 }
 
 static void
@@ -164,14 +86,14 @@ tour_cb (GtkButton *button, SetupData *setup)
         /* the tour is triggered by ~/.config/run-welcome-tour */
         filename = g_build_filename (g_get_home_dir (), ".config", "run-welcome-tour", NULL);
         g_file_set_contents (filename, "yes", -1, NULL);
-        copy_account_file (setup, ".config/run-welcome-tour");
+        gis_copy_account_file (gis_get_act_user (setup), ".config/run-welcome-tour");
         g_free (filename);
 
         begin_autologin (setup);
 }
 
-static void
-prepare_summary_page (SetupData *setup)
+void
+gis_prepare_summary_page (SetupData *setup)
 {
         GtkWidget *button;
         GKeyFile *overrides = gis_get_overrides (setup);
diff --git a/gnome-initial-setup/gis-summary-page.h b/gnome-initial-setup/gis-summary-page.h
new file mode 100644
index 0000000..0f67de6
--- /dev/null
+++ b/gnome-initial-setup/gis-summary-page.h
@@ -0,0 +1,14 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+#ifndef __GIS_SUMMARY_PAGE_H__
+#define __GIS_SUMMARY_PAGE_H__
+
+#include "gnome-initial-setup.h"
+
+G_BEGIN_DECLS
+
+void gis_prepare_summary_page (SetupData *setup);
+
+G_END_DECLS
+
+#endif /* __GIS_SUMMARY_PAGE_H__ */
diff --git a/gnome-initial-setup/gis-utils.c b/gnome-initial-setup/gis-utils.c
new file mode 100644
index 0000000..a95e198
--- /dev/null
+++ b/gnome-initial-setup/gis-utils.c
@@ -0,0 +1,83 @@
+
+#include "config.h"
+#include "gis-utils.h"
+
+#include <string.h>
+
+void
+gis_copy_account_file (ActUser     *act_user,
+                       const gchar *relative_path)
+{
+        const gchar *username;
+        const gchar *homedir;
+        GSList *dirs = NULL, *l;
+        gchar *p, *tmp;
+        gchar *argv[20];
+        gint i;
+        gchar *from;
+        gchar *to;
+        GError *error = NULL;
+
+        username = act_user_get_user_name (act_user);
+        homedir = act_user_get_home_dir (act_user);
+
+        from = g_build_filename (g_get_home_dir (), relative_path, NULL);
+        to = g_build_filename (homedir, relative_path, NULL);
+
+        p = g_path_get_dirname (relative_path);
+        while (strcmp (p, ".") != 0) {
+                dirs = g_slist_prepend (dirs, g_build_filename (homedir, p, NULL));
+                tmp = g_path_get_dirname (p);
+                g_free (p);
+                p = tmp;
+        }
+
+        i = 0;
+        argv[i++] = "/usr/bin/pkexec";
+        argv[i++] = "install";
+        argv[i++] = "--owner";
+        argv[i++] = (gchar *)username;
+        argv[i++] = "--group";
+        argv[i++] = (gchar *)username;
+        argv[i++] = "--mode";
+        argv[i++] = "755";
+        argv[i++] = "--directory";
+        for (l = dirs; l; l = l->next) {
+                argv[i++] = l->data;
+                if (i == 20) {
+                        g_warning ("Too many subdirectories");
+                        goto out;
+                }
+        }
+        argv[i++] = NULL;
+
+        if (!g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, &error)) {
+                g_warning ("Failed to copy account data: %s", error->message);
+                g_error_free (error);
+                goto out;
+        }
+
+        i = 0;
+        argv[i++] = "/usr/bin/pkexec";
+        argv[i++] = "install";
+        argv[i++] = "--owner";
+        argv[i++] = (gchar *)username;
+        argv[i++] = "--group";
+        argv[i++] = (gchar *)username;
+        argv[i++] = "--mode";
+        argv[i++] = "755";
+        argv[i++] = from;
+        argv[i++] = to;
+        argv[i++] = NULL;
+
+        if (!g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, NULL, &error)) {
+                g_warning ("Failed to copy account data: %s", error->message);
+                g_error_free (error);
+                goto out;
+        }
+
+out:
+        g_slist_free_full (dirs, g_free);
+        g_free (to);
+        g_free (from);
+}
diff --git a/gnome-initial-setup/gis-utils.h b/gnome-initial-setup/gis-utils.h
new file mode 100644
index 0000000..089db71
--- /dev/null
+++ b/gnome-initial-setup/gis-utils.h
@@ -0,0 +1,17 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+
+#ifndef __GIS_UTILS_H__
+#define __GIS_UTILS_H__
+
+#include "gnome-initial-setup.h"
+
+#include <act/act-user-manager.h>
+
+G_BEGIN_DECLS
+
+void gis_copy_account_file (ActUser     *act_user,
+                            const gchar *relative_path);
+
+G_END_DECLS
+
+#endif /* __GIS_UTILS_H__ */
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index 9f61997..c4a07ce 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -12,12 +12,9 @@
 #include <gtk/gtk.h>
 #include <clutter-gtk/clutter-gtk.h>
 
-#include <act/act-user-manager.h>
-
 #include "um-utils.h"
 #include "um-photo-dialog.h"
 #include "pw-utils.h"
-#include "gdm-greeter-client.h"
 
 #ifdef HAVE_CHEESE
 #include <cheese-gtk.h>
@@ -32,6 +29,9 @@
 #include "gis-location-page.h"
 #include "gis-network-page.h"
 #include "gis-goa-page.h"
+#include "gis-summary-page.h"
+
+#include "gis-utils.h"
 
 /* Setup data {{{1 */
 struct _SetupData {
@@ -40,8 +40,6 @@ struct _SetupData {
 
         GKeyFile *overrides;
 
-        GdmGreeterClient *greeter_client;
-
         GisAssistant *assistant;
 
         /* account data */
@@ -63,7 +61,22 @@ struct _SetupData {
 };
 
 #include "gis-account-page.c"
-#include "gis-summary-page.c"
+
+static void
+copy_account_data (SetupData *setup)
+{
+        ActUser *user = setup->act_user;
+        /* here is where we copy all the things we just
+         * configured, from the current users home dir to the
+         * account that was created in the first step
+         */
+        g_debug ("Copying account data");
+        g_settings_sync ();
+
+        gis_copy_account_file (user, ".config/dconf/user");
+        gis_copy_account_file (user, ".config/goa-1.0/accounts.conf");
+        gis_copy_account_file (user, ".gnome2/keyrings/Default.keyring");
+}
 
 static void
 prepare_cb (GisAssistant *assi, GtkWidget *page, SetupData *setup)
@@ -111,16 +124,13 @@ prepare_main_window (SetupData *setup)
         g_signal_connect (setup->assistant, "prepare",
                           G_CALLBACK (prepare_cb), setup);
 
-        /* connect to gdm slave */
-        connect_to_slave (setup);
-
         gis_prepare_welcome_page (setup);
         gis_prepare_eula_pages (setup);
         gis_prepare_network_page (setup);
         prepare_account_page (setup);
         gis_prepare_location_page (setup);
         gis_prepare_online_page (setup);
-        prepare_summary_page (setup);
+        gis_prepare_summary_page (setup);
 }
 
 GKeyFile *
@@ -147,6 +157,12 @@ gis_get_assistant (SetupData *setup)
         return setup->assistant;
 }
 
+ActUser *
+gis_get_act_user (SetupData *setup)
+{
+        return setup->act_user;
+}
+
 /* main {{{1 */
 
 int
diff --git a/gnome-initial-setup/gnome-initial-setup.h b/gnome-initial-setup/gnome-initial-setup.h
index f57bd2d..9f3640f 100644
--- a/gnome-initial-setup/gnome-initial-setup.h
+++ b/gnome-initial-setup/gnome-initial-setup.h
@@ -7,6 +7,8 @@
 
 #include "gis-assistant.h"
 
+#include <act/act-user-manager.h>
+
 G_BEGIN_DECLS
 
 typedef struct _SetupData SetupData;
@@ -15,6 +17,7 @@ GtkBuilder *gis_get_builder (SetupData *setup);
 GtkWindow *gis_get_main_window (SetupData *setup);
 GKeyFile *gis_get_overrides (SetupData *setup);
 GisAssistant * gis_get_assistant (SetupData *setup);
+ActUser * gis_get_act_user (SetupData *setup);
 
 #define OBJ(type,name) ((type)gtk_builder_get_object(gis_get_builder(setup),(name)))
 #define WID(name) OBJ(GtkWidget*,name)



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