[gnome-initial-setup] initial-setup: Port to GApplication



commit 8434da0b4b8f79d71f6dbbc9c7407b6cab150b6b
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Aug 17 16:49:45 2012 -0400

    initial-setup: Port to GApplication

 gnome-initial-setup/gnome-initial-setup.c |   98 ++++++++++++++++++-----------
 1 files changed, 62 insertions(+), 36 deletions(-)
---
diff --git a/gnome-initial-setup/gnome-initial-setup.c b/gnome-initial-setup/gnome-initial-setup.c
index 94bdf83..07e3113 100644
--- a/gnome-initial-setup/gnome-initial-setup.c
+++ b/gnome-initial-setup/gnome-initial-setup.c
@@ -152,35 +152,38 @@ get_assistant_type (void)
 
 /* main {{{1 */
 
-int
-main (int argc, char *argv[])
+static void
+load_overrides (SetupData *setup)
 {
-  SetupData *setup;
   gchar *filename;
-  GError *error;
-
-  bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
-  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-  textdomain (GETTEXT_PACKAGE);
-
-  cheese_gtk_init (NULL, NULL);
+  GError *error = NULL;
 
-  setup = g_new0 (SetupData, 1);
+  setup->overrides = g_key_file_new ();
+  filename = g_build_filename (UIDIR, "overrides.ini", NULL);
+  if (!g_key_file_load_from_file (setup->overrides, filename, 0, &error)) {
+    if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
+      g_error ("%s", error->message);
+      exit (1);
+    }
+    g_error_free (error);
+  }
+  g_free (filename);
+}
 
-  gtk_init (&argc, &argv);
+static void
+activate_cb (GApplication *app,
+             gpointer      user_data)
+{
+  SetupData *setup = user_data;
 
-#if HAVE_CLUTTER
-  if (gtk_clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS) {
-    g_critical ("Clutter-GTK init failed");
-    exit (1);
-  }
-#endif
+  gtk_window_present (GTK_WINDOW (setup->main_window));
+}
 
-  error = NULL;
-  if (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error) == NULL) {
-    g_error ("Couldn't get on session bus: %s", error->message);
-    exit (1);
-  }
+static void
+startup_cb (GApplication *app,
+            gpointer      user_data)
+{
+  SetupData *setup = user_data;
 
   setup->main_window = g_object_new (GTK_TYPE_WINDOW,
                                      "type", GTK_WINDOW_TOPLEVEL,
@@ -190,30 +193,53 @@ main (int argc, char *argv[])
                                      "resizable", FALSE,
                                      "window-position", GTK_WIN_POS_CENTER_ALWAYS,
                                      NULL);
+  gtk_application_add_window (GTK_APPLICATION (app), setup->main_window);
 
   setup->assistant = g_object_new (get_assistant_type (), NULL);
   gtk_container_add (GTK_CONTAINER (setup->main_window), GTK_WIDGET (setup->assistant));
 
   gtk_widget_show (GTK_WIDGET (setup->assistant));
 
-  setup->overrides = g_key_file_new ();
-  filename = g_build_filename (UIDIR, "overrides.ini", NULL);
-  if (!g_key_file_load_from_file (setup->overrides, filename, 0, &error)) {
-    if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
-      g_error ("%s", error->message);
-      exit (1);
-    }
-    g_error_free (error);
-  }
-  g_free (filename);
+  load_overrides (setup);
 
   prepare_main_window (setup);
+}
 
-  gtk_window_present (GTK_WINDOW (setup->main_window));
+int
+main (int argc, char *argv[])
+{
+  SetupData *setup;
+  GtkApplication *application;
+  int status;
+
+  bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
+
+  cheese_gtk_init (NULL, NULL);
+
+  setup = g_new0 (SetupData, 1);
+
+  gtk_init (&argc, &argv);
+
+#if HAVE_CLUTTER
+  if (gtk_clutter_init (NULL, NULL) != CLUTTER_INIT_SUCCESS) {
+    g_critical ("Clutter-GTK init failed");
+    exit (1);
+  }
+#endif
+
+  application = gtk_application_new ("org.gnome.InitialSetup", G_APPLICATION_FLAGS_NONE);
+  g_signal_connect (application, "startup",
+                    G_CALLBACK (startup_cb), setup);
+  g_signal_connect (application, "activate",
+                    G_CALLBACK (activate_cb), setup);
+
+  status = g_application_run (G_APPLICATION (application), argc, argv);
 
-  gtk_main ();
+  g_object_unref (application);
 
-  return 0;
+  return status;
 }
 
 /* Epilogue {{{1 */



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