[gnome-user-share] Port from libunique to GtkApplication



commit 70577007a8ecce66bf6b547bda863235bc1d6f48
Author: Javier JardÃn <jjardon gnome org>
Date:   Tue Jan 10 12:55:26 2012 +0000

    Port from libunique to GtkApplication
    
    https://bugzilla.gnome.org/show_bug.cgi?id=658399

 configure.in                |    2 +-
 src/file-share-properties.c |   83 ++++++++++++++++++++++--------------------
 2 files changed, 44 insertions(+), 41 deletions(-)
---
diff --git a/configure.in b/configure.in
index 7e96122..d1c2bbd 100644
--- a/configure.in
+++ b/configure.in
@@ -60,7 +60,7 @@ PKG_CHECK_MODULES(USER_SHARE, glib-2.0 >= 2.15.2 gio-2.0 gtk+-3.0 gconf-2.0 dbus
 AC_SUBST(USER_SHARE_CFLAGS)
 AC_SUBST(USER_SHARE_LIBS)
 
-PKG_CHECK_MODULES(USER_SHARE_CONFIG, glib-2.0 >= 2.15.2 gtk+-3.0 >= 2.12.0 gconf-2.0 unique-3.0)
+PKG_CHECK_MODULES(USER_SHARE_CONFIG, glib-2.0 >= 2.15.2 gtk+-3.0 >= 2.12.0 gconf-2.0)
 AC_SUBST(USER_SHARE_CONFIG_CFLAGS)
 AC_SUBST(USER_SHARE_CONFIG_LIBS)
 
diff --git a/src/file-share-properties.c b/src/file-share-properties.c
index 17dc9bb..4d8473d 100644
--- a/src/file-share-properties.c
+++ b/src/file-share-properties.c
@@ -29,7 +29,6 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 #include <gconf/gconf-client.h>
-#include <unique/uniqueapp.h>
 
 #include "user_share-private.h"
 
@@ -470,20 +469,8 @@ help_button_clicked (GtkButton *button, GtkWidget *window)
 	}
 }
 
-static UniqueResponse
-message_received_cb (UniqueApp         *app,
-		     int                command,
-		     UniqueMessageData *message_data,
-		     guint              time_,
-		     gpointer           user_data)
-{
-  gtk_window_present (GTK_WINDOW (user_data));
-
-  return UNIQUE_RESPONSE_OK;
-}
-
-int
-main (int argc, char *argv[])
+static GtkWidget *
+create_window (void)
 {
     GError *error = NULL;
     GConfClient *client;
@@ -500,20 +487,6 @@ main (int argc, char *argv[])
     GtkListStore *store;
     GtkCellRenderer *cell;
     GtkTreeIter iter;
-    UniqueApp *app;
-    
-    bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
-    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
-    textdomain (GETTEXT_PACKAGE);
-    
-    gtk_init (&argc, &argv);
-
-    app = unique_app_new ("org.gnome.user-share.properties", NULL);
-    if (unique_app_is_running (app)) {
-      gdk_notify_startup_complete ();
-      unique_app_send_message (app, UNIQUE_ACTIVATE, NULL);
-      return 0;
-    }
 
     builder = gtk_builder_new ();
     gtk_builder_add_from_file (builder, DATADIR"file-share-properties.ui", &error);
@@ -526,14 +499,10 @@ main (int argc, char *argv[])
       gtk_widget_destroy (dialog);
 
       g_error_free (error);
-      return 1;
+      return NULL;
     }
 
     window = GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog"));
-    g_signal_connect (G_OBJECT (window), "delete_event",
-		      G_CALLBACK (gtk_main_quit), NULL);
-    g_signal_connect (app, "message-received",
-		      G_CALLBACK (message_received_cb), window);
 
     client = gconf_client_get_default ();
     gconf_client_add_dir (client,
@@ -623,8 +592,8 @@ main (int argc, char *argv[])
     g_signal_connect (notify_received_obexpush_check,
     		      "toggled", G_CALLBACK (notify_received_obexpush_check_toggled), NULL);
 
-    g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
-		      "clicked", G_CALLBACK (gtk_main_quit), NULL);
+    g_signal_connect_swapped (GTK_WIDGET (gtk_builder_get_object (builder, "close_button")),
+                              "clicked", G_CALLBACK (gtk_widget_destroy), window);
     g_signal_connect (GTK_WIDGET (gtk_builder_get_object (builder, "help_button")),
 		      "clicked", G_CALLBACK (help_button_clicked),
 		      gtk_builder_get_object (builder, "user_share_dialog"));
@@ -680,9 +649,43 @@ main (int argc, char *argv[])
 
     g_object_unref (client);
 
-    gtk_widget_show (GTK_WIDGET (gtk_builder_get_object (builder, "user_share_dialog")));
-    
-    gtk_main ();
+    return window;
+}
+
+static void
+activate (GtkApplication *app)
+{
+    GList *list;
+    GtkWidget *window;
+
+    list = gtk_application_get_windows (app);
+
+    if (list) {
+        gtk_window_present (GTK_WINDOW (list->data));
+    } else {
+        window = create_window ();
+        gtk_window_set_application (GTK_WINDOW (window), app);
+        gtk_widget_show (window);
+    }
+}
+
+int
+main (int argc, char *argv[])
+{
+    GtkApplication *app;
+    gint status;
+
+    bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+    bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+    textdomain (GETTEXT_PACKAGE);
+
+    app = gtk_application_new ("org.gnome.user-share.properties",
+                               G_APPLICATION_FLAGS_NONE);
+    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
+
+    status = g_application_run (G_APPLICATION (app), argc, argv);
+
+    g_object_unref (app);
 
-    return 0;
+    return status;
 }



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