[Xfce4-commits] [xfce/xfce4-power-manager] 48/63: Settings: Port to GtkApplication

noreply at xfce.org noreply at xfce.org
Sun Mar 22 13:02:43 CET 2015


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit 6eedcd26121fc99abe09d37f2c5d562450d485d0
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Mon Mar 16 19:30:24 2015 +0300

    Settings: Port to GtkApplication
    
    This changes the settings app to use GtkApplication to handle
    process uniqueness rather than our custom version. Currently,
    the command line doesn't get handeled properly so it doesn't plug
    and the plugin doesn't popup the correct device item.
---
 libdbus/Makefile.am           |    2 -
 libdbus/xfpm-unique.c         |  241 -----------------------------------------
 libdbus/xfpm-unique.h         |   57 ----------
 settings/Makefile.am          |    5 +-
 settings/xfpm-settings-app.c  |  206 +++++++++++++++++++++++++++++++++++
 settings/xfpm-settings-app.h  |   61 +++++++++++
 settings/xfpm-settings-main.c |  170 +----------------------------
 settings/xfpm-settings.h      |    1 +
 8 files changed, 276 insertions(+), 467 deletions(-)

diff --git a/libdbus/Makefile.am b/libdbus/Makefile.am
index a7e1e98..83911b3 100644
--- a/libdbus/Makefile.am
+++ b/libdbus/Makefile.am
@@ -6,8 +6,6 @@ libxfpmdbus_la_SOURCES =		\
 	xfpm-dbus.h			\
 	xfpm-dbus-monitor.c		\
 	xfpm-dbus-monitor.h		\
-	xfpm-unique.c			\
-	xfpm-unique.h			\
 	xfpm-dbus-marshal.c		\
 	xfpm-dbus-marshal.h		\
 	org.xfce.unique.h
diff --git a/libdbus/xfpm-unique.c b/libdbus/xfpm-unique.c
deleted file mode 100644
index 971bae0..0000000
--- a/libdbus/xfpm-unique.c
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * * Copyright (C) 2010-2011 Ali <aliov at xfce.org>
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "xfpm-unique.h"
-#include "xfpm-dbus.h"
-
-static void xfpm_unique_dbus_class_init 	(XfpmUniqueClass *klass);
-static void xfpm_unique_dbus_init		(XfpmUnique *unique);
-
-static void xfpm_unique_finalize   		(GObject *object);
-
-#define XFPM_UNIQUE_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_UNIQUE, XfpmUniquePrivate))
-
-struct XfpmUniquePrivate
-{
-    DBusGConnection *bus;
-    
-    gchar *name;
-};
-
-enum
-{
-    PROP_0,
-    PROP_NAME
-};
-
-enum
-{
-    PING_RECEIVED,
-    LAST_SIGNAL
-};
-
-static guint signals [LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (XfpmUnique, xfpm_unique, G_TYPE_OBJECT)
-
-static void xfpm_unique_get_property (GObject *object,
-				      guint prop_id,
-                                      GValue *value,
-                                      GParamSpec *pspec)
-{
-    XfpmUnique *unique;
-    unique = XFPM_UNIQUE (object);
-    
-    switch (prop_id)
-    {
-	case PROP_NAME:
-	    g_value_set_string (value, unique->priv->name);
-	    break;
-	default:
-            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-    }
-
-}
-
-static void xfpm_unique_set_property (GObject *object,
-				      guint prop_id,
-                                      const GValue *value,
-                                      GParamSpec *pspec)
-{
-    
-    XfpmUnique *unique;
-    unique = XFPM_UNIQUE (object);
-    
-    switch (prop_id)
-    {
-	case PROP_NAME:
-	    unique->priv->name = g_value_dup_string (value);
-	    break;
-	default:
-            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-    }
-}
-
-static void
-xfpm_unique_class_init (XfpmUniqueClass *klass)
-{
-    GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
-    object_class->finalize = xfpm_unique_finalize;
-    
-    object_class->set_property = xfpm_unique_set_property;
-    object_class->get_property = xfpm_unique_get_property;
-
-    signals [PING_RECEIVED] = 
-        g_signal_new ("ping-received",
-                      XFPM_TYPE_UNIQUE,
-                      G_SIGNAL_RUN_LAST,
-                      G_STRUCT_OFFSET (XfpmUniqueClass, ping_received),
-                      NULL, NULL,
-                      g_cclosure_marshal_VOID__VOID,
-                      G_TYPE_NONE, 0, G_TYPE_NONE);
-
-    g_object_class_install_property (object_class,
-                                     PROP_NAME,
-                                     g_param_spec_string  ("name",
-                                                           NULL, NULL,
-                                                           NULL,
-                                                           G_PARAM_READWRITE|
-							   G_PARAM_CONSTRUCT_ONLY));
-
-    g_type_class_add_private (klass, sizeof (XfpmUniquePrivate));
-    
-    xfpm_unique_dbus_class_init (klass);
-}
-
-static void
-xfpm_unique_init (XfpmUnique *unique)
-{
-    GError *error = NULL;
-    
-    unique->priv = XFPM_UNIQUE_GET_PRIVATE (unique);
-    
-    unique->priv->name = NULL;
-    
-    unique->priv->bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-    
-    if ( error )
-	g_error ("Failed to connect to the session bus : %s", error->message);
-	
-    xfpm_unique_dbus_init (unique);
-}
-
-static void
-xfpm_unique_finalize (GObject *object)
-{
-    XfpmUnique *unique;
-
-    unique = XFPM_UNIQUE (object);
-    
-    xfpm_dbus_release_name (dbus_g_connection_get_connection (unique->priv->bus),
-			    unique->priv->name);
-    
-    dbus_g_connection_unref (unique->priv->bus);
-    g_free (unique->priv->name);
-
-    G_OBJECT_CLASS (xfpm_unique_parent_class)->finalize (object);
-}
-
-XfpmUnique *
-xfpm_unique_new (const gchar *name)
-{
-    XfpmUnique *unique = NULL;
-    
-    unique = g_object_new (XFPM_TYPE_UNIQUE, "name", name, NULL);
-    
-    return unique;
-}
-
-gboolean xfpm_unique_app_is_running (XfpmUnique *unique)
-{
-    g_return_val_if_fail (XFPM_IS_UNIQUE (unique), FALSE);
-    
-    if (xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (unique->priv->bus),
-				  unique->priv->name))
-    {
-	DBusGProxy *proxy;
-	GError *error = NULL;
-	
-	proxy = dbus_g_proxy_new_for_name (unique->priv->bus,
-					   unique->priv->name,
-					   "/org/xfce/unique",
-					   "org.xfce.unique");
-	
-	/*Shoudln't happen, but check anyway*/
-	if ( !proxy )
-	{
-	    g_critical ("Unable to create proxy for %s", unique->priv->name);
-	    return FALSE;
-	}
-	
-	dbus_g_proxy_call (proxy, "Ping", &error,
-			   G_TYPE_INVALID,
-			   G_TYPE_INVALID);
-			   
-	if ( error )
-	{
-	    g_warning ("Failed to 'Ping' %s", unique->priv->name);
-	    
-	}
-	
-	g_object_unref (proxy);
-	return TRUE;
-    }
-    
-    xfpm_dbus_register_name (dbus_g_connection_get_connection (unique->priv->bus),
-			     unique->priv->name);
-    
-    return FALSE;
-}
-
-static gboolean xfce_unique_ping (XfpmUnique *unique,
-				  GError *error);	
-
-#include "org.xfce.unique.h"
-
-static void xfpm_unique_dbus_class_init (XfpmUniqueClass *klass)
-{
-    dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
-                                     &dbus_glib_xfce_unique_object_info);
-}
-
-static void xfpm_unique_dbus_init (XfpmUnique *unique)
-{
-    dbus_g_connection_register_g_object (unique->priv->bus,
-                                         "/org/xfce/unique",
-                                         G_OBJECT (unique));
-}
-
-static gboolean xfce_unique_ping (XfpmUnique *unique,
-				  GError *error)
-{
-    g_signal_emit (unique, signals[PING_RECEIVED], 0);
-    return TRUE;
-}
diff --git a/libdbus/xfpm-unique.h b/libdbus/xfpm-unique.h
deleted file mode 100644
index 5cc6c2f..0000000
--- a/libdbus/xfpm-unique.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * * Copyright (C) 2010-2011 Ali <aliov at xfce.org>
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef __XFPM_UNIQUE_H
-#define __XFPM_UNIQUE_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_UNIQUE        (xfpm_unique_get_type () )
-#define XFPM_UNIQUE(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), XFPM_TYPE_UNIQUE, XfpmUnique))
-#define XFPM_IS_UNIQUE(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), XFPM_TYPE_UNIQUE))
-
-typedef struct XfpmUniquePrivate XfpmUniquePrivate;
-
-typedef struct
-{
-    GObject         	   parent;
-    XfpmUniquePrivate     *priv;
-    
-} XfpmUnique;
-
-typedef struct
-{
-    GObjectClass	   parent_class;
-    
-    void		  (*ping_received)	       (XfpmUnique *unique);
-    
-} XfpmUniqueClass;
-
-GType        		   xfpm_unique_get_type        (void) G_GNUC_CONST;
-
-XfpmUnique                *xfpm_unique_new             (const gchar *name);
-
-gboolean		   xfpm_unique_app_is_running  (XfpmUnique *unique);
-
-G_END_DECLS
-
-#endif /* __XFPM_UNIQUE_H */
diff --git a/settings/Makefile.am b/settings/Makefile.am
index 8116b07..8efa681 100644
--- a/settings/Makefile.am
+++ b/settings/Makefile.am
@@ -1,8 +1,11 @@
 bin_PROGRAMS = xfce4-power-manager-settings
 
 xfce4_power_manager_settings_SOURCES = 				\
-	xfce-power-manager-dbus-client.h			\
+	xfce-power-manager-dbus.h			\
+	xfce-power-manager-dbus.c			\
 	xfpm-settings-main.c					\
+	xfpm-settings-app.c					\
+	xfpm-settings-app.h					\
 	xfpm-settings.c						\
 	xfpm-settings.h						\
 	$(top_srcdir)/common/xfpm-config.h				\
diff --git a/settings/xfpm-settings-app.c b/settings/xfpm-settings-app.c
new file mode 100644
index 0000000..1bc7c80
--- /dev/null
+++ b/settings/xfpm-settings-app.c
@@ -0,0 +1,206 @@
+/* -*- c-basic-offset: 4 -*- vi:set ts=4 sts=4 sw=4:
+ * * Copyright (C) 2015 Xfce Development Team <xfce4-dev at xfce.org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <gtk/gtkx.h>
+#include <glib.h>
+#include <gio/gio.h>
+
+#include <xfconf/xfconf.h>
+#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
+
+#include "xfpm-settings-app.h"
+#include "xfpm-settings.h"
+#include "xfpm-debug.h"
+#include "xfpm-config.h"
+
+
+struct _XfpmSettingsAppPrivate
+{
+    XfpmPowerManager *manager;
+    XfconfChannel    *channel;
+    gboolean          debug;
+    Window            socket_id;
+    gchar            *device_id;
+};
+
+static void xfpm_settings_app_class_init (XfpmSettingsAppClass *class);
+static void xfpm_settings_app_init       (XfpmSettingsApp *app);
+static void xfpm_settings_app_activate   (GApplication *app);
+
+
+G_DEFINE_TYPE(XfpmSettingsApp, xfpm_settings_app, GTK_TYPE_APPLICATION);
+
+
+#define XFPM_SETTINGS_APP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_SETTINGS_APP, XfpmSettingsAppPrivate))
+
+
+static void
+xfpm_settings_app_init (XfpmSettingsApp *app)
+{
+    XfpmSettingsAppPrivate *priv = XFPM_SETTINGS_APP_GET_PRIVATE (app);
+
+    const GOptionEntry option_entries[] = {
+      { "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &priv->socket_id, N_("Settings manager socket"), N_("SOCKET ID") },
+      { "device-id", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &priv->device_id, N_("Display a specific device by UpDevice object path"), N_("UpDevice object path") },
+      { "debug",    '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &priv->debug, N_("Enable debugging"), NULL },
+      { NULL, },
+    };
+
+    g_application_add_main_option_entries (G_APPLICATION (app), option_entries);
+}
+
+static void
+xfpm_settings_app_activate (GApplication *app)
+{
+    XfpmSettingsAppPrivate *priv = XFPM_SETTINGS_APP_GET_PRIVATE (app);
+
+    GError           *error = NULL;
+    GtkWidget        *dialog;
+    GHashTable       *hash;
+    GVariant         *config;
+    GVariantIter     *iter;
+    gchar            *key, *value;
+
+    gboolean has_battery;
+    gboolean auth_suspend;
+    gboolean auth_hibernate;
+    gboolean can_suspend;
+    gboolean can_hibernate;
+    gboolean can_shutdown;
+    gboolean has_lcd_brightness;
+    gboolean has_sleep_button;
+    gboolean has_hibernate_button;
+    gboolean has_power_button;
+    gboolean has_lid;
+    gboolean start_xfpm_if_not_running;
+
+    priv->manager = xfpm_power_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+                                                               G_BUS_NAME_OWNER_FLAGS_NONE,
+                                                               "org.xfce.PowerManager",
+                                                               "/org/xfce/PowerManager",
+                                                               NULL,
+                                                               &error);
+
+    if (error != NULL)
+    {
+        g_critical("xfpm_power_manager_proxy_new_sync failed: %s\n", error->message);
+        xfce_dialog_show_warning (NULL,
+                                 _("Xfce Power Manager"),
+                                 "%s",
+                                 _("Failed to connect to power manager"));
+        g_clear_error (&error);
+        return;
+    }
+
+
+    while ( !xfpm_power_manager_call_get_config_sync (priv->manager, &config, NULL, NULL) )
+    {
+        GtkWidget *startw;
+
+        startw = gtk_message_dialog_new (NULL,
+                                         GTK_DIALOG_MODAL,
+                                         GTK_MESSAGE_QUESTION,
+                                         GTK_BUTTONS_YES_NO,
+                                         _("Xfce4 Power Manager is not running, do you want to launch it now?"));
+        start_xfpm_if_not_running = gtk_dialog_run (GTK_DIALOG (startw));
+        gtk_widget_destroy (startw);
+
+        if ( start_xfpm_if_not_running ) 
+        {
+            g_spawn_command_line_async("xfce4-power-manager",NULL);
+            /* wait 2 seconds for xfpm to startup */
+            g_usleep ( 2 * 1000000 );
+        }
+        else
+        {
+            /* continue without starting xfpm, this will probably error out */
+            break;
+        }
+    }
+
+    if ( !xfconf_init(&error) )
+    {
+        g_critical("xfconf init failed: %s using default settings\n", error->message);
+        xfce_dialog_show_warning (NULL,
+                                  _("Xfce Power Manager"),
+                                  "%s",
+                                  _("Failed to load power manager configuration, using defaults"));
+        g_clear_error (&error);
+    }
+
+
+    priv->channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
+
+    xfpm_debug_init (priv->debug);
+
+    hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+    g_variant_get (config, "a{ss}", &iter);
+    while (g_variant_iter_next (iter, "{ss}", &key, &value))
+    {
+        g_hash_table_insert (hash, key, value);
+    }
+    g_variant_iter_free (iter);
+    g_variant_unref (config);
+
+
+    has_battery = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-battery"));
+    has_lid = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-lid"));
+    can_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-suspend"));
+    can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-hibernate"));
+    auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-suspend"));
+    auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (hash, "auth-hibernate"));
+    has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (hash, "has-brightness"));
+    has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "sleep-button"));
+    has_power_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "power-button"));
+    has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (hash, "hibernate-button"));
+    can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (hash, "can-shutdown"));
+
+    dialog = xfpm_settings_dialog_new (priv->channel, auth_suspend, auth_hibernate,
+                                       can_suspend, can_hibernate, can_shutdown, has_battery, has_lcd_brightness,
+                                       has_lid, has_sleep_button, has_hibernate_button, has_power_button,
+                                       priv->socket_id, priv->device_id);
+
+    g_hash_table_destroy (hash);
+
+    gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (dialog));
+}
+
+static void
+xfpm_settings_app_class_init (XfpmSettingsAppClass *class)
+{
+    G_APPLICATION_CLASS (class)->activate = xfpm_settings_app_activate;
+
+    g_type_class_add_private (class, sizeof (XfpmSettingsAppPrivate));
+}
+
+XfpmSettingsApp *
+xfpm_settings_app_new ()
+{
+    return g_object_new (XFPM_TYPE_SETTINGS_APP,
+                         "application-id", "org.xfce.PowerManager.Settings",
+                         "flags", G_APPLICATION_FLAGS_NONE,
+                         NULL);
+}
diff --git a/settings/xfpm-settings-app.h b/settings/xfpm-settings-app.h
new file mode 100644
index 0000000..b6517d3
--- /dev/null
+++ b/settings/xfpm-settings-app.h
@@ -0,0 +1,61 @@
+/* -*- c-basic-offset: 4 -*- vi:set ts=4 sts=4 sw=4:
+ * * Copyright (C) 2015 Xfce Development Team <xfce4-dev at xfce.org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <gtk/gtk.h>
+
+#include "xfce-power-manager-dbus.h"
+
+
+#ifndef __XFPM_SETTINGS_APP_H
+#define __XFPM_SETTINGS_APP_H
+
+G_BEGIN_DECLS
+
+
+#define XFPM_TYPE_SETTINGS_APP            (xfpm_settings_app_get_type())
+#define XFPM_SETTINGS_APP(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), XFPM_TYPE_SETTINGS_APP, XfpmSettingsApp))
+#define XFPM_SETTINGS_APP_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), XFPM_TYPE_SETTINGS_APP, XfpmSettingsAppClass))
+#define XFPM_IS_SETTINGS_APP(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), XFPM_TYPE_SETTINGS_APP))
+#define XFPM_SETTINGS_APP_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), XFPM_TYPE_SETTINGS_APP, XfpmSettingsAppClass))
+
+typedef struct _XfpmSettingsApp         XfpmSettingsApp;
+typedef struct _XfpmSettingsAppClass    XfpmSettingsAppClass;
+typedef struct _XfpmSettingsAppPrivate  XfpmSettingsAppPrivate;
+
+struct _XfpmSettingsApp
+{
+    GtkApplication               parent;
+    XfpmSettingsAppPrivate      *priv;
+};
+
+struct _XfpmSettingsAppClass
+{
+    GtkApplicationClass    parent_class;
+};
+
+
+GType                xfpm_settings_app_get_type        (void) G_GNUC_CONST;
+
+XfpmSettingsApp     *xfpm_settings_app_new             (void);
+
+
+G_END_DECLS
+
+#endif /* __XFPM_SETTINGS_APP_H */
diff --git a/settings/xfpm-settings-main.c b/settings/xfpm-settings-main.c
index 70f379f..88c71c8 100644
--- a/settings/xfpm-settings-main.c
+++ b/settings/xfpm-settings-main.c
@@ -1,5 +1,6 @@
-/*
+/* -*- c-basic-offset: 4 -*- vi:set ts=4 sts=4 sw=4:
  * * Copyright (C) 2008-2011 Ali <aliov at xfce.org>
+ * * Copyright (C) 2015 Xfce Development Team <xfce4-dev at xfce.org>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -33,175 +34,12 @@
 #include <libxfce4util/libxfce4util.h>
 #include <libxfce4ui/libxfce4ui.h>
 
-#include <xfconf/xfconf.h>
-
-#include "common/xfpm-common.h"
-
-#include "xfce-power-manager-dbus-client.h"
-#include "xfpm-settings.h"
-#include "xfpm-config.h"
-#include "xfpm-dbus.h"
-#include "xfpm-debug.h"
-#include "xfpm-unique.h"
+#include "xfpm-settings-app.h"
 
 int main (int argc, char **argv)
 {
-    GtkWidget *dialog;
-    XfpmUnique *unique;
-
-    GError *error = NULL;
-    DBusGConnection *bus;
-    GHashTable *config_hash;
-    
-    gboolean has_battery;
-    gboolean auth_suspend;
-    gboolean auth_hibernate;
-    gboolean can_suspend;
-    gboolean can_hibernate;
-    gboolean can_shutdown;
-    gboolean has_lcd_brightness;
-    gboolean has_sleep_button;
-    gboolean has_hibernate_button;
-    gboolean has_power_button;
-    gboolean has_lid;
-    gboolean start_xfpm_if_not_running;
-    gboolean debug = FALSE;
-
-    Window socket_id = 0;
-    gchar *device_id = NULL;
-
-    XfconfChannel *channel;
-    DBusGProxy *proxy;
-    
-    GOptionEntry option_entries[] = 
-    {
-	{ "socket-id", 's', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_INT, &socket_id, N_("Settings manager socket"), N_("SOCKET ID") },
-	{ "device-id", 'd', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_STRING, &device_id, N_("Display a specific device by UpDevice object path"), N_("UpDevice object path") },
-	{ "debug",    '\0', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &debug, N_("Enable debugging"), NULL },
-	{ NULL, },
-    };
 
     xfce_textdomain(GETTEXT_PACKAGE, LOCALEDIR, "UTF-8");
-    
-    if( !gtk_init_with_args (&argc, &argv, (gchar *)"", option_entries, (gchar *)PACKAGE, &error)) 
-    {
-        if( error) 
-        {
-            g_printerr("%s: %s.\n", G_LOG_DOMAIN, error->message);
-            g_printerr(_("Type '%s --help' for usage."), G_LOG_DOMAIN);
-            g_printerr("\n");
-            g_error_free(error);
-        }
-        else
-        {
-            g_error("Unable to open display.");
-	}
-        return EXIT_FAILURE;
-    }
-    
-    bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
-    
-    if ( error )
-    {
-	g_error ("%s\n",error->message);
-    }
-
-    while ( !xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus), "org.xfce.PowerManager") )
-    {
-	GtkWidget *startw;
-
-	startw = gtk_message_dialog_new (NULL,
-                                         GTK_DIALOG_MODAL,
-                                         GTK_MESSAGE_QUESTION,
-                                         GTK_BUTTONS_YES_NO,
-                                         _("Xfce4 Power Manager is not running, do you want to launch it now?"));
-	start_xfpm_if_not_running = gtk_dialog_run (GTK_DIALOG (startw));
-	gtk_widget_destroy (startw);
-
-	if ( start_xfpm_if_not_running ) 
-	{
-	    g_spawn_command_line_async("xfce4-power-manager",NULL);
-	    /* wait 2 seconds for xfpm to startup */
-	    g_usleep ( 2 * 1000000 );
-	}
-	else
-	{
-	    /* continue without starting xfpm, this will probably error out */
-	    break;
-	}
-    }
-
-    unique = xfpm_unique_new ("org.xfce.PowerManager.Config");
-
-    if ( !xfpm_unique_app_is_running (unique) )
-    {
-	if ( !xfconf_init(&error) )
-	{
-	    g_critical("xfconf init failed: %s using default settings\n", error->message);
-	    xfce_dialog_show_warning (NULL,
-				      _("Xfce Power Manager"),
-				      "%s",
-				      _("Failed to load power manager configuration, using defaults"));
-	    g_error_free (error);
-	    error = NULL;
-	    return EXIT_FAILURE;
-	}
-
-	dbus_g_thread_init ();
-
-	channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
-
-	proxy = dbus_g_proxy_new_for_name(bus,
-					   "org.xfce.PowerManager",
-					   "/org/xfce/PowerManager",
-					   "org.xfce.Power.Manager");
-
-	xfpm_manager_dbus_client_get_config (proxy,
-					     &config_hash,
-					     &error);
-
-	if ( error )
-	{
-	    g_critical ("Unable to get configuration information from xfce power manager: %s", error->message);
-	    xfce_dialog_show_error (NULL, error, "%s", _("Unable to connect to Xfce Power Manager"));
-	    g_error_free (error);
-	    return EXIT_FAILURE;
-	}
-
-	xfpm_debug_init (debug);
-
-	has_battery = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-battery"));
-	has_lid = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-lid"));
-	can_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-suspend"));
-	can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-hibernate"));
-	auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-suspend"));
-	auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-hibernate"));
-	has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-brightness"));
-	has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "sleep-button"));
-	has_power_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "power-button"));
-	has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "hibernate-button"));
-	can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-shutdown"));
-
-	g_hash_table_destroy (config_hash);
-
-	dialog = xfpm_settings_dialog_new (channel, auth_suspend, auth_hibernate,
-					   can_suspend, can_hibernate, can_shutdown, has_battery, has_lcd_brightness,
-					   has_lid, has_sleep_button, has_hibernate_button, has_power_button,
-					   socket_id, device_id);
-
-	g_signal_connect_swapped (unique, "ping-received",
-				  G_CALLBACK (gtk_window_present), dialog);
-
-	gtk_main();
-
-	xfpm_dbus_release_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
-	dbus_g_connection_unref (bus);
-	g_object_unref (proxy);
-
-	g_object_unref (unique);
 
-	return EXIT_SUCCESS;
-    }
-    
-    return EXIT_SUCCESS;
+    return g_application_run (G_APPLICATION (xfpm_settings_app_new ()), argc, argv);
 }
diff --git a/settings/xfpm-settings.h b/settings/xfpm-settings.h
index 2b54c16..b063b8c 100644
--- a/settings/xfpm-settings.h
+++ b/settings/xfpm-settings.h
@@ -22,6 +22,7 @@
 #define __XFPM_SETTINGS_H
 
 #include <gtk/gtkx.h>
+#include <xfconf/xfconf.h>
 
 GtkWidget *xfpm_settings_dialog_new (XfconfChannel *channel,
                                      gboolean auth_suspend,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list