[gnome-power-manager] Port to GApplication



commit 10e86eb2f2d6b02ba92fe8ba449cf4553474dfb9
Author: Richard Hughes <richard hughsie com>
Date:   Tue Jun 8 18:00:10 2010 +0100

    Port to GApplication

 configure.ac         |    6 +--
 src/Makefile.am      |    5 --
 src/egg-unique.c     |  151 --------------------------------------------------
 src/egg-unique.h     |   59 -------------------
 src/gpm-prefs-core.c |    5 +-
 src/gpm-prefs.c      |   53 ++++++-----------
 src/gpm-statistics.c |   52 ++++++++++++------
 7 files changed, 56 insertions(+), 275 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 92a8de8..8a857c0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,7 +109,7 @@ dnl ---------------------------------------------------------------------------
 dnl - Library dependencies
 dnl ---------------------------------------------------------------------------
 GLIB_REQUIRED=2.13.0
-GIO_REQUIRED=2.25.0
+GIO_REQUIRED=2.25.8
 GTK_REQUIRED=2.17.7
 GDK_REQUIRED=2.11.0
 GCONF_REQUIRED=2.31.1
@@ -119,7 +119,6 @@ DBUS_GLIB_REQUIRED=0.70
 LIBNOTIFY_REQUIRED=0.4.3
 LIBWNCK_REQUIRED=2.10.0
 CAIRO_REQUIRED=1.0.0
-UNIQUE_REQUIRED=0.9.4
 LIBPANEL_REQUIRED=2.0.0
 XRANDR_REQUIRED=1.2.0
 CANBERRA_REQUIRED=0.10
@@ -159,9 +158,6 @@ PKG_CHECK_EXISTS(
  [AC_DEFINE(HAVE_XRANDR_13, 1, [xrandr 1.3 available])])
 
 PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED)
-
-PKG_CHECK_MODULES(UNIQUE, unique-1.0 >= $UNIQUE_REQUIRED)
-
 PKG_CHECK_MODULES(UPOWER, upower-glib >= $UPOWER_REQUIRED)
 
 dnl ---------------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 74682b0..1d52bfa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,7 +13,6 @@ INCLUDES =						\
 	$(GLIB_CFLAGS)					\
 	$(DBUS_CFLAGS)					\
 	$(GNOME_CFLAGS)					\
-	$(UNIQUE_CFLAGS)				\
 	$(X11_CFLAGS)					\
 	$(LIBNOTIFY_CFLAGS)				\
 	$(CANBERRA_CFLAGS)				\
@@ -57,8 +56,6 @@ libgpmshared_a_SOURCES =				\
 	egg-color.h					\
 	egg-debug.h					\
 	egg-debug.c					\
-	egg-unique.h					\
-	egg-unique.c					\
 	egg-precision.h					\
 	egg-precision.c					\
 	egg-array-float.c				\
@@ -112,7 +109,6 @@ gnome_power_statistics_LDADD =				\
 	$(X11_LIBS)					\
 	$(UPOWER_LIBS)					\
 	$(GNOME_LIBS)					\
-	$(UNIQUE_LIBS)					\
 	$(DBUS_LIBS)					\
 	-lm
 
@@ -132,7 +128,6 @@ gnome_power_preferences_LDADD =				\
 	$(X11_LIBS)					\
 	$(GNOME_LIBS)					\
 	$(DBUS_LIBS)					\
-	$(UNIQUE_LIBS)					\
 	$(GPM_EXTRA_LIBS)				\
 	$(UPOWER_LIBS)					\
 	-lm
diff --git a/src/gpm-prefs-core.c b/src/gpm-prefs-core.c
index f478482..2404f17 100644
--- a/src/gpm-prefs-core.c
+++ b/src/gpm-prefs-core.c
@@ -378,9 +378,6 @@ gpm_prefs_close_cb (GtkWidget *widget, GpmPrefs *prefs)
 
 /**
  * gpm_prefs_delete_event_cb:
- * @widget: The GtkWidget object
- * @event: The event type, unused.
- * @prefs: This prefs class instance
  **/
 static gboolean
 gpm_prefs_delete_event_cb (GtkWidget *widget, GdkEvent *event, GpmPrefs *prefs)
@@ -806,7 +803,7 @@ gpm_prefs_init (GpmPrefs *prefs)
 	gtk_window_set_default_icon_name (GPM_STOCK_APP_ICON);
 
 	/* Get the main window quit */
-	g_signal_connect (main_window, "delete_event",
+	g_signal_connect (main_window, "delete-event",
 			  G_CALLBACK (gpm_prefs_delete_event_cb), prefs);
 
 	widget = GTK_WIDGET (gtk_builder_get_object (prefs->priv->builder, "button_close"));
diff --git a/src/gpm-prefs.c b/src/gpm-prefs.c
index 7acc653..aea3c98 100644
--- a/src/gpm-prefs.c
+++ b/src/gpm-prefs.c
@@ -30,45 +30,35 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
-/* local .la */
-#include <egg-unique.h>
+#include "egg-debug.h"
 
 #include "gpm-common.h"
-#include "egg-debug.h"
 #include "gpm-prefs-core.h"
 
 /**
  * gpm_prefs_help_cb
- * @prefs: This prefs class instance
- *
- * What to do when help is requested
  **/
 static void
-gpm_prefs_help_cb (GpmPrefs *prefs)
+gpm_prefs_help_cb (GpmPrefs *prefs, GApplication *application)
 {
 	gpm_help_display ("preferences");
 }
 
 /**
  * gpm_prefs_close_cb
- * @prefs: This prefs class instance
- *
- * What to do when we are asked to close for whatever reason
  **/
 static void
-gpm_prefs_close_cb (GpmPrefs *prefs)
+gpm_prefs_close_cb (GpmPrefs *prefs, GApplication *application)
 {
-	gtk_main_quit ();
+	g_application_quit (application, 0);
 }
 
 /**
- * gpm_prefs_activated_cb
- * @prefs: This prefs class instance
- *
- * We have been asked to show the window
+ * gpm_prefs_application_prepare_action_cb:
  **/
 static void
-gpm_prefs_activated_cb (EggUnique *egg_unique, GpmPrefs *prefs)
+gpm_prefs_application_prepare_action_cb (GApplication *application, GVariant *arguments,
+					 GVariant *platform_data, GpmPrefs *prefs)
 {
 	gpm_prefs_activate_window (prefs);
 }
@@ -82,8 +72,7 @@ main (int argc, char **argv)
 	gboolean verbose = FALSE;
 	GOptionContext *context;
 	GpmPrefs *prefs = NULL;
-	gboolean ret;
-	EggUnique *egg_unique;
+	GApplication *application;
 
 	const GOptionEntry options[] = {
 		{ "verbose", '\0', 0, G_OPTION_ARG_NONE, &verbose,
@@ -105,26 +94,22 @@ main (int argc, char **argv)
 	gtk_init (&argc, &argv);
 	egg_debug_init (verbose);
 
-	/* are we already activated? */
-	egg_unique = egg_unique_new ();
-	ret = egg_unique_assign (egg_unique, "org.gnome.PowerManager.Preferences");
-	if (!ret) {
-		goto unique_out;
-	}
-
 	prefs = gpm_prefs_new ();
 
-	g_signal_connect (egg_unique, "activated",
-			  G_CALLBACK (gpm_prefs_activated_cb), prefs);
+	/* ensure single instance */
+	application = g_application_new_and_register ("org.gnome.PowerManager.Preferences", argc, argv);
+	g_signal_connect (application, "prepare-activation",
+			  G_CALLBACK (gpm_prefs_application_prepare_action_cb), prefs);
 	g_signal_connect (prefs, "action-help",
-			  G_CALLBACK (gpm_prefs_help_cb), prefs);
+			  G_CALLBACK (gpm_prefs_help_cb), application);
 	g_signal_connect (prefs, "action-close",
-			  G_CALLBACK (gpm_prefs_close_cb), prefs);
-	gtk_main ();
-	g_object_unref (prefs);
+			  G_CALLBACK (gpm_prefs_close_cb), application);
 
-unique_out:
-	g_object_unref (egg_unique);
+	/* run */
+	g_application_run (application);
+
+	g_object_unref (prefs);
+	g_object_unref (application);
 
 /* seems to not work...
 	g_option_context_free (context); */
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index 5815072..caaa4b5 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -34,7 +34,6 @@
 #include "egg-debug.h"
 #include "egg-color.h"
 #include "egg-array-float.h"
-#include "egg-unique.h"
 
 #include "gpm-common.h"
 #include "gpm-stock-icons.h"
@@ -115,7 +114,7 @@ enum {
  * gpm_stats_button_help_cb:
  **/
 static void
-gpm_stats_button_help_cb (GtkWidget *widget, gboolean data)
+gpm_stats_button_help_cb (GtkWidget *widget, gpointer user_data)
 {
 	gpm_help_display ("statistics");
 }
@@ -1124,7 +1123,7 @@ gpm_stats_button_update_ui (void)
  * gpm_stats_devices_treeview_clicked_cb:
  **/
 static void
-gpm_stats_devices_treeview_clicked_cb (GtkTreeSelection *selection, gboolean data)
+gpm_stats_devices_treeview_clicked_cb (GtkTreeSelection *selection, gpointer user_data)
 {
 	GtkTreeModel *model;
 	GtkTreeIter iter;
@@ -1157,10 +1156,11 @@ gpm_stats_devices_treeview_clicked_cb (GtkTreeSelection *selection, gboolean dat
 }
 
 /**
- * gpm_stats_window_activated_cb
+ * gpm_stats_application_prepare_action_cb:
  **/
 static void
-gpm_stats_window_activated_cb (EggUnique *egg_unique, gpointer data)
+gpm_stats_application_prepare_action_cb (GApplication *application, GVariant *arguments,
+					 GVariant *platform_data, gpointer user_data)
 {
 	GtkWidget *widget;
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"));
@@ -1503,6 +1503,25 @@ gpm_stats_highlight_device (const gchar *object_path)
 }
 
 /**
+ * gpm_stats_delete_event_cb:
+ **/
+static gboolean
+gpm_stats_delete_event_cb (GtkWidget *widget, GdkEvent *event, GApplication *application)
+{
+	g_application_quit (application, 0);
+	return FALSE;
+}
+
+/**
+ * gpm_stats_button_close_cb:
+ **/
+static void
+gpm_stats_button_close_cb (GtkWidget *widget, GApplication *application)
+{
+	g_application_quit (application, 0);
+}
+
+/**
  * main:
  **/
 int
@@ -1513,7 +1532,7 @@ main (int argc, char *argv[])
 	GtkBox *box;
 	GtkWidget *widget;
 	GtkTreeSelection *selection;
-	EggUnique *egg_unique;
+	GApplication *application;
 	gboolean ret;
 	UpClient *client;
 	GPtrArray *devices;
@@ -1558,12 +1577,9 @@ main (int argc, char *argv[])
 	gtk_init (&argc, &argv);
 
 	/* are we already activated? */
-	egg_unique = egg_unique_new ();
-	ret = egg_unique_assign (egg_unique, "org.gnome.PowerManager.Statistics");
-	if (!ret)
-		goto unique_out;
-	g_signal_connect (egg_unique, "activated",
-			  G_CALLBACK (gpm_stats_window_activated_cb), NULL);
+	application = g_application_new_and_register ("org.gnome.PowerManager.Statistics", argc, argv);
+	g_signal_connect (application, "prepare-activation",
+			  G_CALLBACK (gpm_stats_application_prepare_action_cb), NULL);
 
 	/* add application specific icons to search path */
 	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
@@ -1599,10 +1615,12 @@ main (int argc, char *argv[])
 	gtk_window_set_default_icon_name (GPM_STOCK_APP_ICON);
 
 	/* Get the main window quit */
-	g_signal_connect_swapped (widget, "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+	g_signal_connect (widget, "delete-event",
+			  G_CALLBACK (gpm_stats_delete_event_cb), application);
 
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
-	g_signal_connect_swapped (widget, "clicked", G_CALLBACK (gtk_main_quit), NULL);
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gpm_stats_button_close_cb), application);
 	gtk_widget_grab_default (widget);
 
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"));
@@ -1800,7 +1818,8 @@ main (int argc, char *argv[])
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_stats"));
 	gtk_widget_show (widget);
 
-	gtk_main ();
+	/* run */
+	g_application_run (application);
 
 out:
 	g_object_unref (settings);
@@ -1808,8 +1827,7 @@ out:
 	g_object_unref (wakeups);
 	g_object_unref (builder);
 	g_object_unref (list_store_info);
-unique_out:
-	g_object_unref (egg_unique);
+	g_object_unref (application);
 	g_free (last_device);
 	return 0;
 }



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