[gucharmap] main: Port to GtkApplication



commit ae0abb2114c7423c9c63f933812d31915baee3cd
Author: Florian MÃllner <fmuellner gnome org>
Date:   Tue May 8 23:44:02 2012 +0200

    main: Port to GtkApplication
    
    Make gucharmap a non-unique GtkApplication; this is a
    prerequisite for recent desktop integration features.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=674952

 gucharmap/gucharmap-window.c |    5 +++--
 gucharmap/gucharmap-window.h |    2 +-
 gucharmap/main.c             |   24 +++++++++++++++++++-----
 3 files changed, 23 insertions(+), 8 deletions(-)
---
diff --git a/gucharmap/gucharmap-window.c b/gucharmap/gucharmap-window.c
index 88cf729..26b08e3 100644
--- a/gucharmap/gucharmap-window.c
+++ b/gucharmap/gucharmap-window.c
@@ -994,9 +994,10 @@ gucharmap_window_class_init (GucharmapWindowClass *klass)
 /* Public API */
 
 GtkWidget *
-gucharmap_window_new (void)
+gucharmap_window_new (GtkApplication *application)
 {
-  return GTK_WIDGET (g_object_new (gucharmap_window_get_type (), NULL));
+  return GTK_WIDGET (g_object_new (gucharmap_window_get_type (),
+                     "application", application, NULL));
 }
 
 void
diff --git a/gucharmap/gucharmap-window.h b/gucharmap/gucharmap-window.h
index e75f2eb..b24f10d 100644
--- a/gucharmap/gucharmap-window.h
+++ b/gucharmap/gucharmap-window.h
@@ -70,7 +70,7 @@ struct _GucharmapWindowClass
 
 GType       gucharmap_window_get_type  (void);
 
-GtkWidget * gucharmap_window_new       (void);
+GtkWidget * gucharmap_window_new       (GtkApplication *application);
 
 void        gucharmap_window_set_font  (GucharmapWindow *guw,
                                         const char *font);
diff --git a/gucharmap/main.c b/gucharmap/main.c
index 71e5b91..eecc024 100644
--- a/gucharmap/main.c
+++ b/gucharmap/main.c
@@ -39,6 +39,14 @@ option_version_cb (const gchar *option_name,
   return FALSE;
 }
 
+static void
+gucharmap_activate (GApplication *application,
+                    gpointer      unused)
+{
+  GList *windows = gtk_application_get_windows (GTK_APPLICATION (application));
+  gtk_window_present (GTK_WINDOW (windows->data));
+}
+
 int
 main (int argc, char **argv)
 {
@@ -48,6 +56,8 @@ main (int argc, char **argv)
   GdkRectangle rect;
   GError *error = NULL;
   char *font = NULL;
+  GtkApplication *application;
+  guint status;
   GOptionEntry goptions[] =
   {
     { "font", 0, 0, G_OPTION_ARG_STRING, &font,
@@ -80,9 +90,12 @@ main (int argc, char **argv)
   g_set_application_name (_("Character Map"));
   gtk_window_set_default_icon_name (GUCHARMAP_ICON_NAME);
 
-  window = gucharmap_window_new ();
-  g_signal_connect (window, "destroy",
-                    G_CALLBACK (gtk_main_quit), NULL);
+  application = gtk_application_new ("org.gnome.Charmap",
+                                     G_APPLICATION_NON_UNIQUE);
+  g_signal_connect (application, "activate",
+                    G_CALLBACK (gucharmap_activate), NULL);
+
+  window = gucharmap_window_new (application);
 
   screen = gtk_window_get_screen (GTK_WINDOW (window));
   monitor = gdk_screen_get_monitor_at_point (screen, 0, 0);
@@ -101,7 +114,8 @@ main (int argc, char **argv)
 
   gtk_window_present (GTK_WINDOW (window));
 
-  gtk_main ();
+  status = g_application_run (G_APPLICATION (application), argc, argv);
+  g_object_unref (application);
 
-  return 0;
+  return status;
 }



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