[glade/multiple-toplevels] * src/main.c, src/glade-window.c: Make Glade use GtkApplication, now Glade is a single instance



commit caf94be4e7f9d7c40cbe28c7eb65a8ca797747cb
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Sat Jan 29 21:58:42 2011 +0900

    	* src/main.c, src/glade-window.c: Make Glade use GtkApplication, now Glade is
    	  a single instance app.
    
    	* data/icons/Makefile.am, data/desktop.in.in: Rename the 'glade-3' icon to 'glade'

 ChangeLog                             |    5 +
 data/glade.desktop.in.in              |    2 +-
 data/icons/Makefile.am                |    2 +-
 data/icons/{glade-3.ico => glade.ico} |  Bin 15086 -> 15086 bytes
 src/glade-window.c                    |    5 +-
 src/glade-window.h                    |    2 +-
 src/main.c                            |  201 ++++++++++++++++++++++-----------
 7 files changed, 144 insertions(+), 73 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4242e0e..ab4e489 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,11 @@
 	  this out by just using the "parent" xml attribute and deriving GtkWindow and
 	  disabling all the irrelevant GtkWindow properties.
 
+	* src/main.c, src/glade-window.c: Make Glade use GtkApplication, now Glade is
+	  a single instance app.
+
+	* data/icons/Makefile.am, data/desktop.in.in: Rename the 'glade-3' icon to 'glade'
+
 2011-01-28  Tristan Van Berkom <tristanvb openismus com>
 
 	* gladeui/glade-xml-utils.h, gladeui/glade-widget-adaptor.[ch], gladeui/glade-widget.[ch]:
diff --git a/data/glade.desktop.in.in b/data/glade.desktop.in.in
index 6c74df7..fe4d8d9 100644
--- a/data/glade.desktop.in.in
+++ b/data/glade.desktop.in.in
@@ -7,7 +7,7 @@ Exec=glade %F
 Terminal=false
 StartupNotify=true
 Type=Application
-Icon=glade-3
+Icon=glade
 Categories=GNOME;GTK;Development;GUIDesigner;
 MimeType=application/x-glade;
 X-GNOME-DocPath=glade/glade.xml
diff --git a/data/icons/Makefile.am b/data/icons/Makefile.am
index a737fe7..7122c17 100644
--- a/data/icons/Makefile.am
+++ b/data/icons/Makefile.am
@@ -20,4 +20,4 @@ pixmapsdir = $(pkgdatadir)/pixmaps
 pixmaps_DATA = selector.png devhelp.png plus.png atk.png drag-resize.png fixed-bg.png placeholder.png
 
 
-EXTRA_DIST = $(pixmaps_DATA) glade-3.ico
+EXTRA_DIST = $(pixmaps_DATA) glade.ico
diff --git a/data/icons/glade-3.ico b/data/icons/glade.ico
similarity index 100%
rename from data/icons/glade-3.ico
rename to data/icons/glade.ico
diff --git a/src/glade-window.c b/src/glade-window.c
index da1d13c..4ed5f50 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -149,6 +149,7 @@ static void check_reload_project (GladeWindow * window, GladeProject * project);
 
 static void glade_window_config_save (GladeWindow * window);
 
+static void glade_window_check_devhelp (GladeWindow * window);
 
 G_DEFINE_TYPE (GladeWindow, glade_window, GTK_TYPE_WINDOW)
 
@@ -3559,7 +3560,7 @@ glade_window_init (GladeWindow * window)
   }
 #endif
 
-
+  glade_window_check_devhelp (window);
 }
 
 static void
@@ -3601,7 +3602,7 @@ glade_window_new (void)
   return g_object_new (GLADE_TYPE_WINDOW, NULL);
 }
 
-void
+static void
 glade_window_check_devhelp (GladeWindow * window)
 {
   g_return_if_fail (GLADE_IS_WINDOW (window));
diff --git a/src/glade-window.h b/src/glade-window.h
index d3fae18..88c4c57 100644
--- a/src/glade-window.h
+++ b/src/glade-window.h
@@ -56,7 +56,7 @@ void        glade_window_new_project   (GladeWindow *window);
 gboolean    glade_window_open_project  (GladeWindow *window,
 					const gchar *path);
 
-void        glade_window_check_devhelp (GladeWindow *window);
+
 
 G_END_DECLS
 
diff --git a/src/main.c b/src/main.c
index 048ebc6..a2d4042 100644
--- a/src/main.c
+++ b/src/main.c
@@ -41,39 +41,147 @@
 #define APPLICATION_NAME (_("Glade"))
 
 
-/* Application arguments */
-static gboolean version = FALSE, without_devhelp = FALSE;
-static gchar **files = NULL;
+#define TYPE_GLADE            (glade_get_type())
+#define GLADE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GLADE, Glade))
 
-static GOptionEntry option_entries[] = {
-  {"version", '\0', 0, G_OPTION_ARG_NONE, &version,
-   N_("Output version information and exit"), NULL},
+typedef struct _Glade      Glade;
+typedef struct _GladeClass GladeClass;
 
-  {"without-devhelp", '\0', 0, G_OPTION_ARG_NONE, &without_devhelp,
-   N_("Disable Devhelp integration"), NULL},
+struct _Glade {
+  GtkApplication application;
 
-  {G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
-   NULL, N_("[FILE...]")},
+  GladeWindow *window;
+};
 
-  {NULL}
+struct _GladeClass {
+  GtkApplicationClass application_class;
 };
 
-/* Debugging arguments */
-static gboolean verbose = FALSE;
 
-static GOptionEntry debug_option_entries[] = {
-  {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, N_("be verbose"), NULL},
+static GType  glade_get_type        (void) G_GNUC_CONST;
+static void   glade_finalize        (GObject       *object);
+static void   glade_open            (GApplication  *application,
+				     GFile        **files,
+				     gint           n_files,
+				     const gchar   *hint);
+static void   glade_startup         (GApplication  *application);
+static void   glade_activate        (GApplication  *application);
+
+G_DEFINE_TYPE (Glade, glade, GTK_TYPE_APPLICATION)
+
+static gboolean
+open_new_project (Glade *glade)
+{
+  if (!glade_app_get_projects ())
+    glade_window_new_project (glade->window);
+
+  return FALSE;
+}
+
+static void
+glade_init (Glade *glade)
+{
+
+}
+
+static void
+glade_class_init (GladeClass *glade_class)
+{
+  GObjectClass      *object_class      = G_OBJECT_CLASS (glade_class);
+  GApplicationClass *application_class = G_APPLICATION_CLASS (glade_class);
+
+  object_class->finalize      = glade_finalize;
+
+  application_class->open     = glade_open;
+  application_class->startup  = glade_startup;
+  application_class->activate = glade_activate;
+}
+
+static void
+glade_finalize (GObject *object)
+{
+  G_OBJECT_CLASS (glade_parent_class)->finalize (object);
+}
+
+static void
+glade_open (GApplication  *application,
+	    GFile        **files,
+	    gint           n_files,
+	    const gchar   *hint)
+{
+  Glade *glade = GLADE (application);
+  gint i;
+  gchar *path;
+
+  for (i = 0; i < n_files; i++)
+    {
+      if ((path = g_file_get_path (files[i])) != NULL)
+	{
+	  glade_window_open_project (glade->window, path);
+
+	  g_free (path);
+	}
+    }
+}
+
+static void
+glade_startup (GApplication *application)
+{
+  Glade *glade = GLADE (application);
+
+  glade_setup_log_handlers ();
+
+  glade->window = GLADE_WINDOW (glade_window_new ());
+  gtk_window_set_application (GTK_WINDOW (glade->window), GTK_APPLICATION (application));
+
+  gtk_widget_show (GTK_WIDGET (glade->window));
+
+  g_idle_add ((GSourceFunc)open_new_project, glade);
+
+  g_print ("Glade starting up\n");
+
+  G_APPLICATION_CLASS (glade_parent_class)->startup (application);
+}
+
+static void
+glade_activate (GApplication *application)
+{
+  g_print ("Who knows what the GApplication:activate is for anyway\n");
+}
+
+
+static Glade *
+glade_new (void)
+{
+  Glade *glade =
+    g_object_new (TYPE_GLADE, 
+		  "application-id", "org.gnome.Glade",
+		  "flags", G_APPLICATION_HANDLES_OPEN,
+		  NULL);
+
+  return glade;
+}
+
+/* Version argument parsing */
+static gboolean version = FALSE;
+
+static GOptionEntry option_entries[] = {
+  {"version", '\0', 0, G_OPTION_ARG_NONE, &version,
+   N_("Output version information and exit"), NULL},
+
   {NULL}
 };
 
 int
 main (int argc, char *argv[])
 {
-  GladeWindow *window;
   GOptionContext *option_context;
   GOptionGroup *option_group;
   GError *error = NULL;
-  gboolean opened_project = FALSE;
+  Glade *glade;
+  gint status;
+
+  g_type_init ();
 
   if (!g_thread_supported ())
     g_thread_init (NULL);
@@ -99,17 +207,6 @@ main (int argc, char *argv[])
   g_option_context_set_main_group (option_context, option_group);
   g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE);
 
-  option_group = g_option_group_new ("debug",
-                                     N_("Glade debug options"),
-                                     N_("Show Glade debug options"),
-                                     NULL, NULL);
-  g_option_group_add_entries (option_group, debug_option_entries);
-  g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE);
-  g_option_context_add_group (option_context, option_group);
-
-  /* Add Gtk option group */
-  g_option_context_add_group (option_context, gtk_get_option_group (FALSE));
-
   /* Parse command line */
   if (!g_option_context_parse (option_context, &argc, &argv, &error))
     {
@@ -136,11 +233,6 @@ main (int argc, char *argv[])
       return 0;
     }
 
-  /* Pass NULL here since we parsed the gtk+ args already...
-   * from this point on we need a DISPLAY variable to be set.
-   */
-  gtk_init (NULL, NULL);
-
   /* Check for gmodule support */
   if (!g_module_supported ())
     {
@@ -149,44 +241,17 @@ main (int argc, char *argv[])
       return -1;
     }
 
-  g_set_application_name (APPLICATION_NAME);
-  gtk_window_set_default_icon_name ("glade-3");
-
-  glade_setup_log_handlers ();
-
-
-  window = GLADE_WINDOW (glade_window_new ());
+  gtk_init (&argc, &argv);
 
-  if (without_devhelp == FALSE)
-    glade_window_check_devhelp (window);
-
-  gtk_widget_show (GTK_WIDGET (window));
-
-  /* load files specified on commandline */
-  if (files != NULL)
-    {
-      guint i;
-
-      for (i = 0; files[i]; ++i)
-        {
-          if (g_file_test (files[i], G_FILE_TEST_EXISTS) != FALSE)
-	    {
-	      if (glade_window_open_project (window, files[i]))
-		opened_project = TRUE;
-	    }
-          else
-            g_warning (_("Unable to open '%s', the file does not exist.\n"),
-                       files[i]);
-        }
-      g_strfreev (files);
-    }
-
-  if (!opened_project)
-    glade_window_new_project (window);
+  g_set_application_name (APPLICATION_NAME);
+  gtk_window_set_default_icon_name ("glade");
 
-  gtk_main ();
+  /* Fire it up */
+  glade = glade_new ();
+  status = g_application_run (G_APPLICATION (glade), argc, argv);
+  g_object_unref (glade);
 
-  return 0;
+  return status;
 }
 
 #ifdef G_OS_WIN32



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