[vino: 15/17] Updated GtkApplication code.



commit 8a9d8c0ee3a4f99079091dfaff0aa6717a91c734
Author: Chris Kühl <chrisk openismus com>
Date:   Fri Feb 18 12:26:22 2011 +0100

    Updated GtkApplication code.

 capplet/vino-preferences.c |   63 +++++++++++++++++++++++--------------------
 1 files changed, 34 insertions(+), 29 deletions(-)
---
diff --git a/capplet/vino-preferences.c b/capplet/vino-preferences.c
index 8905b6a..9a035de 100644
--- a/capplet/vino-preferences.c
+++ b/capplet/vino-preferences.c
@@ -341,13 +341,14 @@ vino_preferences_connect_ui (VinoPreferences *app,
   return window;
 }
 
-static GtkWindow *
-vino_preferences_create_window (GtkApplication *gtk_app)
+static void
+vino_preferences_create_window (GApplication *g_app)
 {
-  VinoPreferences *app = (VinoPreferences *) gtk_app;
+  VinoPreferences *app = (VinoPreferences *) g_app;
   GError     *error = NULL;
   GtkBuilder *builder;
   const char *ui_file;
+  GtkWindow  *window;
 
   vino_radio_button_get_type ();
   vino_message_box_get_type ();
@@ -364,10 +365,11 @@ vino_preferences_create_window (GtkApplication *gtk_app)
     {
       g_warning ("Unable to load ui file '%s': %s", ui_file, error->message);
       g_error_free (error);
-      return NULL;
     }
 
-  return vino_preferences_connect_ui (app, builder);
+  window = vino_preferences_connect_ui (app, builder);
+  gtk_window_set_application (GTK_WINDOW (window), GTK_APPLICATION (app));
+  gtk_widget_show_all(GTK_WIDGET(window));
 }
 
 static void
@@ -377,8 +379,7 @@ vino_preferences_finalize (GObject *object)
 
   g_object_unref (app->info);
 
-  G_OBJECT_CLASS (vino_preferences_parent_class)
-    ->finalize (object);
+  G_OBJECT_CLASS (vino_preferences_parent_class)->finalize (object);
 }
 
 static void
@@ -386,50 +387,54 @@ vino_preferences_init (VinoPreferences *app)
 {
 }
 
-static void
-vino_preferences_class_init (GtkApplicationClass *class)
+static GtkApplication *
+vino_preferences_new (void)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  g_type_init();
 
-  class->create_window = vino_preferences_create_window;
-  object_class->finalize = vino_preferences_finalize;
+  return g_object_new (vino_preferences_get_type (),
+                       "application-id", "org.gnome.Vino.Preferences",
+                       "flags", G_APPLICATION_FLAGS_NONE,
+                       NULL);
 }
 
-static GtkApplication *
-vino_preferences_new (gint argc, char **argv)
+static void
+vino_preferences_activate (GApplication *app)
 {
-  GError *error = NULL;
-  GtkApplication *app;
-  const gchar **args;
+  GList *list;
 
-  args = (const gchar **) argv;
+  list = gtk_application_get_windows (GTK_APPLICATION(app));
 
-  app = g_initable_new (vino_preferences_get_type (), NULL, &error,
-                        "application-id", "org.gnome.Vino.Preferences",
-                        "argv", g_variant_new_bytestring_array (args, argc),
-                        NULL);
+  if (list)
+    gtk_window_present (GTK_WINDOW (list->data));
+  else
+    vino_preferences_create_window (app);
+}
 
-  if G_UNLIKELY (app == NULL)
-    g_error ("%s", error->message);
+static void
+vino_preferences_class_init (VinoPreferencesClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
 
-  return app;
+  G_APPLICATION_CLASS (class)->activate = vino_preferences_activate;
+  object_class->finalize                = vino_preferences_finalize;
 }
 
 int
 main (int argc, char **argv)
 {
   GtkApplication *app;
+  int status;
 
   bindtextdomain (GETTEXT_PACKAGE, VINO_LOCALEDIR);
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
   textdomain (GETTEXT_PACKAGE);
 
   gtk_init (&argc, &argv);
-  app = vino_preferences_new (argc, argv);
-  gtk_application_get_window (app);
-  gtk_application_run (app);
+  app = vino_preferences_new ();
+  status = g_application_run (G_APPLICATION(app), argc, argv);
   g_object_unref (app);
   g_settings_sync ();
 
-  return 0;
+  return status;
 }



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