summaryrefslogtreecommitdiff
path: root/settings
diff options
context:
space:
mode:
authorEric Koegel <eric.koegel@gmail.com>2015-03-16 19:30:24 +0300
committerEric Koegel <eric.koegel@gmail.com>2015-03-22 14:58:02 +0300
commit6eedcd26121fc99abe09d37f2c5d562450d485d0 (patch)
tree0502525c2bd363db77530664bd64e296197390b7 /settings
parentb3eb1f464c7c2d9e3c527f3d10041f8d564faa10 (diff)
downloadixfce4-power-manager-6eedcd26121fc99abe09d37f2c5d562450d485d0.tar.gz
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.
Diffstat (limited to 'settings')
-rw-r--r--settings/Makefile.am5
-rw-r--r--settings/xfpm-settings-app.c206
-rw-r--r--settings/xfpm-settings-app.h61
-rw-r--r--settings/xfpm-settings-main.c170
-rw-r--r--settings/xfpm-settings.h1
5 files changed, 276 insertions, 167 deletions
diff --git a/settings/Makefile.am b/settings/Makefile.am
index 8116b07d..8efa681b 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 00000000..1bc7c808
--- /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@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 00000000..b6517d39
--- /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@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 70f379f1..88c71c84 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@xfce.org>
+ * * Copyright (C) 2015 Xfce Development Team <xfce4-dev@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 2b54c16a..b063b8ce 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,