From 9ee74a367606a4dd6779b0448bef237dd9e2797e Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 26 May 2012 15:19:38 -0500 Subject: separate the dbus org.gnome.SettingsDaemon.Power logic into a separate class --- src/indicator-power.c | 155 +++----------------------------------------------- 1 file changed, 9 insertions(+), 146 deletions(-) (limited to 'src/indicator-power.c') diff --git a/src/indicator-power.c b/src/indicator-power.c index 6eb6904..dc95aae 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -20,7 +20,7 @@ with this program. If not, see . */ #ifdef HAVE_CONFIG_H -#include "config.h" + #include "config.h" #endif /* GStuff */ @@ -28,9 +28,7 @@ with this program. If not, see . #include #include -/* upower */ -#include - +#include "dbus-listener.h" #include "device.h" #include "indicator-power.h" @@ -38,11 +36,6 @@ with this program. If not, see . #define DEFAULT_ICON "gpm-battery-missing" -#define DBUS_SERVICE "org.gnome.SettingsDaemon" -#define DBUS_PATH "/org/gnome/SettingsDaemon" -#define POWER_DBUS_PATH DBUS_PATH "/Power" -#define POWER_DBUS_INTERFACE "org.gnome.SettingsDaemon.Power" - enum { POWER_INDICATOR_ICON_POLICY_PRESENT, POWER_INDICATOR_ICON_POLICY_CHARGE, @@ -57,9 +50,7 @@ struct _IndicatorPowerPrivate GtkImage *status_image; gchar *accessible_desc; - GCancellable *proxy_cancel; - GDBusProxy *proxy; - guint watcher_id; + IndicatorPowerDbusListener * dbus_listener; GSList * devices; IndicatorPowerDevice * device; @@ -86,7 +77,9 @@ static gboolean should_be_visible (IndicatorPower * self); static void on_entry_added (IndicatorObject * io, IndicatorObjectEntry * entry, gpointer user_data); +/* static void gsd_appeared_callback (GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data); +*/ G_DEFINE_TYPE (IndicatorPower, indicator_power, INDICATOR_OBJECT_TYPE); @@ -119,14 +112,9 @@ indicator_power_init (IndicatorPower *self) priv->accessible_desc = NULL; - priv->watcher_id = g_bus_watch_name (G_BUS_TYPE_SESSION, - DBUS_SERVICE, - G_BUS_NAME_WATCHER_FLAGS_NONE, - gsd_appeared_callback, - NULL, - self, - NULL); - + priv->dbus_listener = g_object_new (INDICATOR_POWER_DBUS_LISTENER_TYPE, + INDICATOR_POWER_DBUS_LISTENER_INDICATOR, self, + NULL); priv->settings = g_settings_new ("com.canonical.indicator.power"); g_signal_connect_swapped (priv->settings, "changed::" ICON_POLICY_KEY, G_CALLBACK(update_visibility), self); @@ -157,9 +145,7 @@ indicator_power_dispose (GObject *object) dispose_devices (self); - g_clear_object (&priv->proxy); - g_clear_object (&priv->proxy_cancel); - + g_clear_object (&priv->dbus_listener); g_clear_object (&priv->settings); G_OBJECT_CLASS (indicator_power_parent_class)->dispose (object); @@ -806,47 +792,6 @@ indicator_power_set_devices (IndicatorPower * self, update_visibility (self); } -static void -get_devices_cb (GObject * source_object, - GAsyncResult * res, - gpointer user_data) -{ - GError *error; - int device_count = 0; - GVariant * devices_container; - IndicatorPowerDevice ** devices = NULL; - IndicatorPower *self = INDICATOR_POWER (user_data); - - /* build an array of IndicatorPowerDevices from the DBus response */ - error = NULL; - devices_container = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); - if (devices_container == NULL) - { - g_message ("Couldn't get devices: %s\n", error->message); - g_error_free (error); - } - else - { - gsize i; - GVariant * devices_variant = g_variant_get_child_value (devices_container, 0); - device_count = devices_variant ? g_variant_n_children (devices_variant) : 0; - devices = g_new0 (IndicatorPowerDevice*, device_count); - - for (i=0; ipriv; - - /* it's time to refresh our device list */ - g_dbus_proxy_call (priv->proxy, - "GetDevices", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->proxy_cancel, - get_devices_cb, - user_data); -} - -static void -service_proxy_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate * priv = self->priv; - GError *error = NULL; - - priv->proxy = g_dbus_proxy_new_for_bus_finish (res, &error); - - g_clear_object (&priv->proxy_cancel); - - if (error != NULL) - { - g_error ("Error creating proxy: %s", error->message); - g_error_free (error); - - return; - } - - /* we want to change the primary device changes */ - g_signal_connect (priv->proxy, - "g-properties-changed", - G_CALLBACK (receive_properties_changed), - user_data); - - /* get the initial state */ - g_dbus_proxy_call (priv->proxy, - "GetDevices", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - priv->proxy_cancel, - get_devices_cb, - user_data); -} - -static void -gsd_appeared_callback (GDBusConnection *connection, - const gchar *name, - const gchar *name_owner, - gpointer user_data) -{ - IndicatorPower *self = INDICATOR_POWER (user_data); - IndicatorPowerPrivate * priv = self->priv; - - priv->proxy_cancel = g_cancellable_new (); - - g_dbus_proxy_new (connection, - G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, - NULL, - name, - POWER_DBUS_PATH, - POWER_DBUS_INTERFACE, - priv->proxy_cancel, - service_proxy_cb, - self); -} - - - /* Grabs the label. Creates it if it doesn't exist already */ -- cgit v1.2.3