gnome-power-manager r2793 - in trunk: . libunique src
- From: rhughes svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-power-manager r2793 - in trunk: . libunique src
- Date: Wed, 14 May 2008 12:56:40 +0100 (BST)
Author: rhughes
Date: Wed May 14 11:56:39 2008
New Revision: 2793
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=2793&view=rev
Log:
2008-05-14 Richard Hughes <richard hughsie com>
* Makefile.am:
* configure.ac:
* libunique/Makefile.am:
* libunique/libunique.c: (libunique_message_cb),
(libunique_assign), (libunique_class_init), (libunique_init),
(libunique_finalize), (libunique_new):
* libunique/libunique.h:
Add a simple GObject that can optionally use Unique to give single instance capability
to the client tools. This removes a lot of HAVE_GTK_UNIQUE and random complexity from
source files also.
* src/Makefile.am:
* src/gpm-prefs.c: (gpm_prefs_close_cb), (gpm_prefs_activated_cb),
(main):
* src/gpm-statistics-core.c: (gpm_statistics_activate_window):
* src/gpm-statistics.c: (gpm_statistics_close_cb),
(gpm_statistics_activated_cb), (main):
Use LibUnique to make g-p-p and g-p-s single instance. GtkUnique is now obsolete.
Added:
trunk/libunique/
trunk/libunique/Makefile.am
trunk/libunique/libunique.c
trunk/libunique/libunique.h
Modified:
trunk/ChangeLog
trunk/Makefile.am
trunk/configure.ac
trunk/src/Makefile.am
trunk/src/gpm-prefs.c
trunk/src/gpm-statistics-core.c
trunk/src/gpm-statistics.c
Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am (original)
+++ trunk/Makefile.am Wed May 14 11:56:39 2008
@@ -2,6 +2,7 @@
libdbus-glib \
libhal-glib \
libidletime \
+ libunique \
src \
po \
docs \
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Wed May 14 11:56:39 2008
@@ -59,7 +59,7 @@
LIBNOTIFY_REQUIRED=0.4.3
LIBWNCK_REQUIRED=2.10.0
CAIRO_REQUIRED=1.0.0
-GTKUNIQUE_REQUIRED=0.9.1
+UNIQUE_REQUIRED=0.9.1
LIBPANEL_REQUIRED=2.0.0
GSTREAMER_REQUIRED=0.10
XRANDR_REQUIRED=1.2.0
@@ -79,7 +79,7 @@
AC_SUBST(LIBNOTIFY_REQUIRED)
AC_SUBST(LIBWNCK_REQUIRED)
AC_SUBST(CAIRO_REQUIRED)
-AC_SUBST(GTKUNIQUE_REQUIRED)
+AC_SUBST(UNIQUE_REQUIRED)
AC_SUBST(LIBPANEL_REQUIRED)
AC_SUBST(GSTREAMER_REQUIRED)
AC_SUBST(XRANDR_REQUIRED)
@@ -310,19 +310,19 @@
AM_CONDITIONAL([HAVE_LIBNOTIFY], [test $have_libnotify = yes])
dnl ---------------------------------------------------------------------------
-dnl - Is gtkunique available?
+dnl - Is unique available?
dnl ---------------------------------------------------------------------------
-if $PKG_CONFIG --atleast-version $GTKUNIQUE_REQUIRED gtkunique-1.0; then
- have_gtkunique=yes
- PKG_CHECK_MODULES(GTKUNIQUE, gtkunique-1.0 >= $GTKUNIQUE_REQUIRED)
- AC_SUBST(GTKUNIQUE_CFLAGS)
- AC_SUBST(GTKUNIQUE_LIBS)
- AC_DEFINE(HAVE_GTKUNIQUE, 1, [Building with gtkunique support])
+if $PKG_CONFIG --atleast-version $UNIQUE_REQUIRED unique-1.0; then
+ have_unique=yes
+ PKG_CHECK_MODULES(UNIQUE, unique-1.0 >= $UNIQUE_REQUIRED)
+ AC_SUBST(UNIQUE_CFLAGS)
+ AC_SUBST(UNIQUE_LIBS)
+ AC_DEFINE(HAVE_UNIQUE, 1, [Building with unique support])
else
- have_gtkunique=no
- AC_DEFINE(HAVE_GTKUNIQUE, 0, [Not building with gtkunique support])
+ have_unique=no
+ AC_DEFINE(HAVE_UNIQUE, 0, [Not building with unique support])
fi
-AM_CONDITIONAL([HAVE_GTKUNIQUE], [test $have_gtkunique = yes])
+AM_CONDITIONAL([HAVE_UNIQUE], [test $have_unique = yes])
dnl ---------------------------------------------------------------------------
dnl - Some utility functions to make checking for X things easier.
@@ -547,6 +547,7 @@
libhal-glib/Makefile
libdbus-glib/Makefile
libidletime/Makefile
+libunique/Makefile
docs/Makefile
man/Makefile
help/Makefile
@@ -591,7 +592,7 @@
compiler: ${CC}
cflags: ${CFLAGS}
libnotify support: ${have_libnotify}
- gtkunique support: ${have_gtkunique}
+ unique support: ${have_unique}
Building extra applets: ${enable_applets}
DPMS support: ${have_dpms}
PolicyKit support: ${have_polkit}
Added: trunk/libunique/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/libunique/Makefile.am Wed May 14 11:56:39 2008
@@ -0,0 +1,22 @@
+INCLUDES = \
+ $(GLIB_CFLAGS) \
+ $(UNIQUE_CFLAGS) \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+
+noinst_LTLIBRARIES = \
+ libunique.la
+
+libunique_la_SOURCES = \
+ libunique.c \
+ libunique.h
+libunique_la_LIBADD = $(DBUS_LIBS) $(INTLLIBS) $(GLIB_LIBS)
+
+if HAVE_UNIQUE
+libunique_la_LIBADD += \
+ $(UNIQUE_LIBS)
+endif
+
+clean-local:
+ rm -f *~
+
Added: trunk/libunique/libunique.c
==============================================================================
--- (empty file)
+++ trunk/libunique/libunique.c Wed May 14 11:56:39 2008
@@ -0,0 +1,177 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <string.h>
+#include <glib.h>
+
+#if HAVE_UNIQUE
+#include <unique/unique.h>
+#endif
+
+#include "libunique.h"
+
+static void libunique_class_init (LibUniqueClass *klass);
+static void libunique_init (LibUnique *unique);
+static void libunique_finalize (GObject *object);
+
+#define LIBUNIQUE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), LIBUNIQUE_TYPE, LibUniquePrivate))
+
+struct LibUniquePrivate
+{
+ gboolean dummy;
+#if HAVE_UNIQUE
+ UniqueApp *uniqueapp;
+#endif
+};
+
+enum {
+ ACTIVATED,
+ LAST_SIGNAL
+};
+
+static guint signals [LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (LibUnique, libunique, G_TYPE_OBJECT)
+
+#if HAVE_UNIQUE
+/**
+ * libunique_message_cb:
+ **/
+static void
+libunique_message_cb (UniqueApp *app, UniqueCommand command, UniqueMessageData *message_data,
+ guint time, LibUnique *libunique)
+{
+ g_return_if_fail (IS_LIBUNIQUE (libunique));
+ if (command == UNIQUE_ACTIVATE) {
+ g_signal_emit (libunique, signals [ACTIVATED], 0);
+ }
+}
+
+/**
+ * libunique_assign:
+ * @libunique: This class instance
+ * @service: The service name
+ * Return value: %FALSE if we should exit as another instance is running
+ **/
+gboolean
+libunique_assign (LibUnique *libunique, const gchar *service)
+{
+ g_return_val_if_fail (IS_LIBUNIQUE (libunique), FALSE);
+ g_return_val_if_fail (service != NULL, FALSE);
+
+ if (libunique->priv->uniqueapp != NULL) {
+ g_warning ("already assigned!");
+ return FALSE;
+ }
+
+ /* check to see if the user has another instance open */
+ libunique->priv->uniqueapp = unique_app_new (service, NULL);
+ if (unique_app_is_running (libunique->priv->uniqueapp)) {
+ g_warning ("You have another instance running. This program will now close");
+ unique_app_send_message (libunique->priv->uniqueapp, UNIQUE_ACTIVATE, NULL);
+ return FALSE;
+ }
+
+ /* Listen for messages from another instances */
+ g_signal_connect (G_OBJECT (libunique->priv->uniqueapp), "message-received",
+ G_CALLBACK (libunique_message_cb), libunique);
+ return TRUE;
+}
+#else
+
+/**
+ * libunique_assign:
+ * @libunique: This class instance
+ * @service: The service name
+ * Return value: always %TRUE
+ **/
+gboolean
+libunique_assign (LibUnique *libunique, const gchar *service)
+{
+ g_return_val_if_fail (IS_LIBUNIQUE (libunique), FALSE);
+ return TRUE;
+}
+#endif
+
+/**
+ * libunique_class_init:
+ * @libunique: This class instance
+ **/
+static void
+libunique_class_init (LibUniqueClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = libunique_finalize;
+ g_type_class_add_private (klass, sizeof (LibUniquePrivate));
+
+ signals [ACTIVATED] =
+ g_signal_new ("activated",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (LibUniqueClass, activated),
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+/**
+ * libunique_init:
+ * @libunique: This class instance
+ **/
+static void
+libunique_init (LibUnique *libunique)
+{
+ libunique->priv = LIBUNIQUE_GET_PRIVATE (libunique);
+ libunique->priv->uniqueapp = NULL;
+}
+
+/**
+ * libunique_finalize:
+ * @object: This class instance
+ **/
+static void
+libunique_finalize (GObject *object)
+{
+ LibUnique *libunique;
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (IS_LIBUNIQUE (object));
+
+ libunique = LIBUNIQUE_OBJECT (object);
+ libunique->priv = LIBUNIQUE_GET_PRIVATE (libunique);
+
+ if (libunique->priv->uniqueapp != NULL) {
+ g_object_unref (libunique->priv->uniqueapp);
+ }
+ G_OBJECT_CLASS (libunique_parent_class)->finalize (object);
+}
+
+/**
+ * libunique_new:
+ * Return value: new class instance.
+ **/
+LibUnique *
+libunique_new (void)
+{
+ LibUnique *libunique;
+ libunique = g_object_new (LIBUNIQUE_TYPE, NULL);
+ return LIBUNIQUE_OBJECT (libunique);
+}
+
Added: trunk/libunique/libunique.h
==============================================================================
--- (empty file)
+++ trunk/libunique/libunique.h Wed May 14 11:56:39 2008
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __LIBUNIQUE_H
+#define __LIBUNIQUE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define LIBUNIQUE_TYPE (libunique_get_type ())
+#define LIBUNIQUE_OBJECT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), LIBUNIQUE_TYPE, LibUnique))
+#define LIBUNIQUE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), LIBUNIQUE_TYPE, LibUniqueClass))
+#define IS_LIBUNIQUE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), LIBUNIQUE_TYPE))
+#define IS_LIBUNIQUE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), LIBUNIQUE_TYPE))
+#define LIBUNIQUE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), LIBUNIQUE_TYPE, LibUniqueClass))
+
+typedef struct LibUniquePrivate LibUniquePrivate;
+
+typedef struct
+{
+ GObject parent;
+ LibUniquePrivate *priv;
+} LibUnique;
+
+typedef struct
+{
+ GObjectClass parent_class;
+ void (* activated) (LibUnique *unique);
+} LibUniqueClass;
+
+GType libunique_get_type (void);
+LibUnique *libunique_new (void);
+
+gboolean libunique_assign (LibUnique *libunique,
+ const gchar *service);
+
+G_END_DECLS
+
+#endif /* __LIBUNIQUE_H */
+
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Wed May 14 11:56:39 2008
@@ -16,7 +16,7 @@
$(GNOME_CFLAGS) \
$(XRANDR_CFLAGS) \
$(LIBNOTIFY_CFLAGS) \
- $(GTKUNIQUE_CFLAGS) \
+ $(UNIQUE_CFLAGS) \
$(GSTREAMER_CFLAGS) \
$(POLKIT_GNOME_CFLAGS) \
-DBINDIR=\"$(bindir)\" \
@@ -28,6 +28,7 @@
-DVERSION="\"$(VERSION)\"" \
-DGPM_DATA=\"$(pkgdatadir)\" \
-I$(top_srcdir) \
+ -I$(top_srcdir)/libunique \
-I$(top_srcdir)/libhal-glib \
-I$(top_srcdir)/libdbus-glib \
$(NULL)
@@ -44,6 +45,9 @@
$(top_builddir)/libdbus-glib/libdbus-watch.la \
$(top_builddir)/libdbus-glib/libdbus-proxy.la
+LOCAL_LIBUNIQUE_LIBS = \
+ $(top_builddir)/libunique/libunique.la
+
bin_PROGRAMS = \
gnome-power-manager \
gnome-power-preferences \
@@ -78,11 +82,12 @@
$(GNOME_LIBS) \
$(DBUS_LIBS) \
$(LOCAL_LIBDBUS_LIBS) \
+ $(LOCAL_LIBUNIQUE_LIBS) \
$(NULL)
-if HAVE_GTKUNIQUE
+if HAVE_UNIQUE
gnome_power_statistics_LDADD += \
- $(GTKUNIQUE_LIBS)
+ $(UNIQUE_LIBS)
endif
gnome_power_preferences_SOURCES = \
@@ -117,11 +122,12 @@
$(GPM_EXTRA_LIBS) \
$(LOCAL_LIBHAL_LIBS) \
$(LOCAL_LIBDBUS_LIBS) \
+ $(LOCAL_LIBUNIQUE_LIBS) \
$(NULL)
-if HAVE_GTKUNIQUE
+if HAVE_UNIQUE
gnome_power_preferences_LDADD += \
- $(GTKUNIQUE_LIBS)
+ $(UNIQUE_LIBS)
endif
gnome_power_manager_SOURCES = \
Modified: trunk/src/gpm-prefs.c
==============================================================================
--- trunk/src/gpm-prefs.c (original)
+++ trunk/src/gpm-prefs.c Wed May 14 11:56:39 2008
@@ -2,7 +2,7 @@
*
* Copyright (C) 2005 Jaap Haitsma <jaap haitsma org>
* Copyright (C) 2005 William Jon McCann <mccann jhu edu>
- * Copyright (C) 2005-2007 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2005-2008 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -30,9 +30,8 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#if HAVE_GTKUNIQUE
-#include <gtkunique/gtkunique.h>
-#endif
+/* local .la */
+#include <libunique.h>
#include "gpm-common.h"
#include "gpm-prefs.h"
@@ -60,32 +59,20 @@
static void
gpm_prefs_close_cb (GpmPrefs *prefs)
{
- g_object_unref (prefs);
- exit (0);
+ gtk_main_quit ();
}
-#if HAVE_GTKUNIQUE
/**
- * gtkuniqueapp_command_cb:
+ * gpm_prefs_activated_cb
+ * @prefs: This prefs class instance
+ *
+ * We have been asked to show the window
**/
static void
-gtkuniqueapp_command_cb (GtkUniqueApp *app,
- GtkUniqueCommand command,
- const gchar *data,
- const gchar *startup_id,
- GdkScreen *screen,
- guint workspace,
- gpointer user_data)
+gpm_prefs_activated_cb (LibUnique *libunique, GpmPrefs *prefs)
{
- GpmPrefs *prefs;
-
- gpm_debug ("GtkUnique message %i", command);
- prefs = GPM_PREFS (user_data);
- if (command == GTK_UNIQUE_ACTIVATE) {
- gpm_prefs_activate_window (prefs);
- }
+ gpm_prefs_activate_window (prefs);
}
-#endif
/**
* main:
@@ -96,11 +83,8 @@
gboolean verbose = FALSE;
GOptionContext *context;
GpmPrefs *prefs = NULL;
- GMainLoop *loop;
-#if HAVE_GTKUNIQUE
- GtkUniqueApp *uniqueapp;
- const gchar *startup_id = NULL;
-#endif
+ gboolean ret;
+ LibUnique *libunique;
const GOptionEntry options[] = {
{ "verbose", '\0', 0, G_OPTION_ARG_NONE, &verbose,
@@ -115,15 +99,6 @@
textdomain (GETTEXT_PACKAGE);
g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
-
-#if HAVE_GTKUNIQUE
- /* FIXME: We don't need to get the startup id once we can
- * depend on gtk+-2.12. Until then we must get it BEFORE
- * gtk_init() is called, otherwise gtk_init() will clear it
- * and GtkUnique has to use racy workarounds.
- */
- startup_id = g_getenv ("DESKTOP_STARTUP_ID");
-#endif
g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
g_option_context_add_group (context, gtk_get_option_group (FALSE));
g_option_context_parse (context, &argc, &argv, NULL);
@@ -131,53 +106,28 @@
gtk_init (&argc, &argv);
gpm_debug_init (verbose);
-#if HAVE_GTKUNIQUE
- gpm_debug ("Using GtkUnique support.");
-
- /* Arrr! Until we depend on gtk+2 2.12 we can't just use gtk_unique_app_new */
- uniqueapp = gtk_unique_app_new_with_id ("org.freedesktop.PowerManagement.Preferences", startup_id);
- /* check to see if the user has another prefs window open */
- if (gtk_unique_app_is_running (uniqueapp)) {
- gpm_warning ("You have another instance running. "
- "This program will now close");
- gtk_unique_app_activate (uniqueapp);
-
- /* FIXME: This next line should be removed once we can depend
- * upon gtk+-2.12. This causes the busy cursor and temporary
- * task in the tasklist to go away too soon (though that's
- * better than having them be stuck until the 30-second-or-so
- * timeout ends).
- */
- gdk_notify_startup_complete ();
- } else {
-#else
- gpm_warning ("No GtkUnique support. Cannot signal other instances");
- /* we always assume we have no other running instance */
- if (1) {
-#endif
- /* create a new instance of the window */
- prefs = gpm_prefs_new ();
+ /* are we already activated? */
+ libunique = libunique_new ();
+ ret = libunique_assign (libunique, "org.freedesktop.PowerManagement.Preferences");
+ if (!ret) {
+ goto unique_out;
+ }
- g_signal_connect (prefs, "action-help",
- G_CALLBACK (gpm_prefs_help_cb), prefs);
- g_signal_connect (prefs, "action-close",
- G_CALLBACK (gpm_prefs_close_cb), prefs);
-#if HAVE_GTKUNIQUE
- /* Listen for messages from another instances */
- g_signal_connect (G_OBJECT (uniqueapp), "message",
- G_CALLBACK (gtkuniqueapp_command_cb), prefs);
-#endif
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
+ prefs = gpm_prefs_new ();
- g_object_unref (prefs);
- }
+ g_signal_connect (libunique, "activated",
+ G_CALLBACK (gpm_prefs_activated_cb), prefs);
+ g_signal_connect (prefs, "action-help",
+ G_CALLBACK (gpm_prefs_help_cb), prefs);
+ g_signal_connect (prefs, "action-close",
+ G_CALLBACK (gpm_prefs_close_cb), prefs);
+ gtk_main ();
+ g_object_unref (prefs);
+unique_out:
gpm_debug_shutdown ();
+ g_object_unref (libunique);
-#if HAVE_GTKUNIQUE
- g_object_unref (uniqueapp);
-#endif
/* seems to not work...
g_option_context_free (context); */
Modified: trunk/src/gpm-statistics-core.c
==============================================================================
--- trunk/src/gpm-statistics-core.c (original)
+++ trunk/src/gpm-statistics-core.c Wed May 14 11:56:39 2008
@@ -775,6 +775,9 @@
gpm_statistics_activate_window (GpmStatistics *statistics)
{
GtkWidget *widget;
+
+ g_return_if_fail (GPM_IS_STATISTICS (statistics));
+
widget = glade_xml_get_widget (statistics->priv->glade_xml, "window_graph");
gtk_window_present (GTK_WINDOW (widget));
}
Modified: trunk/src/gpm-statistics.c
==============================================================================
--- trunk/src/gpm-statistics.c (original)
+++ trunk/src/gpm-statistics.c Wed May 14 11:56:39 2008
@@ -2,7 +2,7 @@
*
* Copyright (C) 2005 Jaap Haitsma <jaap haitsma org>
* Copyright (C) 2005 William Jon McCann <mccann jhu edu>
- * Copyright (C) 2005-2007 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2005-2008 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -21,16 +21,17 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
#include <stdlib.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#if HAVE_GTKUNIQUE
-#include <gtkunique/gtkunique.h>
-#endif
+/* local .la */
+#include <libunique.h>
#include "gpm-common.h"
#include "gpm-conf.h"
@@ -58,32 +59,20 @@
static void
gpm_statistics_close_cb (GpmStatistics *statistics)
{
- g_object_unref (statistics);
- exit (0);
+ gtk_main_quit ();
}
-#if HAVE_GTKUNIQUE
/**
- * gtkuniqueapp_command_cb:
+ * gpm_statistics_activated_cb
+ * @statistics: This statistics class instance
+ *
+ * We have been asked to show the window
**/
static void
-gtkuniqueapp_command_cb (GtkUniqueApp *app,
- GtkUniqueCommand command,
- const gchar *data,
- const gchar *startup_id,
- GdkScreen *screen,
- guint workspace,
- gpointer user_data)
+gpm_statistics_activated_cb (LibUnique *libunique, GpmStatistics *statistics)
{
- GpmStatistics *statistics;
-
- gpm_debug ("GtkUnique message %i", command);
- statistics = GPM_STATISTICS (user_data);
- if (command == GTK_UNIQUE_ACTIVATE) {
- gpm_statistics_activate_window (statistics);
- }
+ gpm_statistics_activate_window (statistics);
}
-#endif
/**
* main:
@@ -91,14 +80,11 @@
int
main (int argc, char **argv)
{
- gboolean verbose = FALSE;
- GOptionContext *context;
- GpmStatistics *statistics = NULL;
- GMainLoop *loop;
-#if HAVE_GTKUNIQUE
- GtkUniqueApp *uniqueapp;
- const gchar *startup_id = NULL;
-#endif
+ gboolean verbose = FALSE;
+ GOptionContext *context;
+ GpmStatistics *statistics = NULL;
+ gboolean ret;
+ LibUnique *libunique;
const GOptionEntry options[] = {
{ "verbose", '\0', 0, G_OPTION_ARG_NONE, &verbose,
@@ -113,68 +99,33 @@
textdomain (GETTEXT_PACKAGE);
g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);
-
-#if HAVE_GTKUNIQUE
- /* FIXME: We don't need to get the startup id once we can
- * depend on gtk+-2.12. Until then we must get it BEFORE
- * gtk_init() is called, otherwise gtk_init() will clear it
- * and GtkUnique has to use racy workarounds.
- */
- startup_id = g_getenv ("DESKTOP_STARTUP_ID");
-#endif
g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
g_option_context_add_group (context, gtk_get_option_group (FALSE));
g_option_context_parse (context, &argc, &argv, NULL);
- gtk_init (&argc, &argv);
+ gtk_init (&argc, &argv);
gpm_debug_init (verbose);
-#if HAVE_GTKUNIQUE
- gpm_debug ("Using GtkUnique support.");
-
- /* Arrr! Until we depend on gtk+2 2.12 we can't just use gtk_unique_app_new */
- uniqueapp = gtk_unique_app_new_with_id ("org.freedesktop.PowerManagement.Statistics", startup_id);
- /* check to see if the user has another prefs window open */
- if (gtk_unique_app_is_running (uniqueapp)) {
- gpm_warning ("You have another instance running. "
- "This program will now close");
- gtk_unique_app_activate (uniqueapp);
-
- /* FIXME: This next line should be removed once we can depend
- * upon gtk+-2.12. This causes the busy cursor and temporary
- * task in the tasklist to go away too soon (though that's
- * better than having them be stuck until the 30-second-or-so
- * timeout ends).
- */
- gdk_notify_startup_complete ();
- } else {
-#else
- gpm_warning ("No GtkUnique support. Cannot signal other instances");
- /* we always assume we have no other running instance */
- if (1) {
-#endif
- statistics = gpm_statistics_new ();
-
- g_signal_connect (statistics, "action-help",
- G_CALLBACK (gpm_statistics_help_cb), NULL);
- g_signal_connect (statistics, "action-close",
- G_CALLBACK (gpm_statistics_close_cb), NULL);
-#if HAVE_GTKUNIQUE
- /* Listen for messages from another instances */
- g_signal_connect (G_OBJECT (uniqueapp), "message",
- G_CALLBACK (gtkuniqueapp_command_cb), statistics);
-#endif
- loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (loop);
-
- g_object_unref (statistics);
+ /* are we already activated? */
+ libunique = libunique_new ();
+ ret = libunique_assign (libunique, "org.freedesktop.PowerManagement.Statistics");
+ if (!ret) {
+ goto unique_out;
}
- gpm_debug_shutdown ();
+ statistics = gpm_statistics_new ();
+ g_signal_connect (libunique, "activated",
+ G_CALLBACK (gpm_statistics_activated_cb), statistics);
+ g_signal_connect (statistics, "action-help",
+ G_CALLBACK (gpm_statistics_help_cb), statistics);
+ g_signal_connect (statistics, "action-close",
+ G_CALLBACK (gpm_statistics_close_cb), statistics);
+ gtk_main ();
+ g_object_unref (statistics);
-#if HAVE_GTKUNIQUE
- g_object_unref (uniqueapp);
-#endif
+unique_out:
+ gpm_debug_shutdown ();
+ g_object_unref (libunique);
/* seems to not work...
g_option_context_free (context); */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]