summaryrefslogtreecommitdiff
path: root/battstat/battstat-upower.c
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-11-26 14:28:51 +0100
committerinfirit <[email protected]>2014-11-26 18:13:43 +0100
commit1499d577a67f2dd0f99e6707f29ebd9ba8f9b940 (patch)
tree6257bb38e41553ec62bbd5b18eb0f68c506b9a3a /battstat/battstat-upower.c
parentf98f9fe0e6d52144d99f2e92c6f4f060f67b8073 (diff)
downloadmate-applets-1499d577a67f2dd0f99e6707f29ebd9ba8f9b940.tar.bz2
mate-applets-1499d577a67f2dd0f99e6707f29ebd9ba8f9b940.tar.xz
batstat: sync upower code with gnome-applets.
Largely taken from: gnome-applets commit: 95ff3ab8dfb5f595263dce6857b7d5935042e336 From: Dmitry Shachnev <[email protected]>
Diffstat (limited to 'battstat/battstat-upower.c')
-rw-r--r--battstat/battstat-upower.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/battstat/battstat-upower.c b/battstat/battstat-upower.c
index 1326a9cc..f879a95f 100644
--- a/battstat/battstat-upower.c
+++ b/battstat/battstat-upower.c
@@ -67,6 +67,13 @@ device_cb (UpClient *client, UpDevice *device, gpointer user_data) {
schedule_status_callback();
}
+#if UP_CHECK_VERSION (0, 99, 0)
+static void
+device_removed_cb (UpClient *client, const gchar *object_path, gpointer user_data) {
+ schedule_status_callback();
+}
+#endif
+
/* ---- public functions ---- */
char *
@@ -76,6 +83,9 @@ battstat_upower_initialise (void (*callback) (void))
int i, num;
status_updated_callback = callback;
+#if UP_CHECK_VERSION (0, 99, 0)
+ GPtrArray *devices;
+#endif
if( upc != NULL )
return g_strdup( "Already initialised!" );
@@ -86,19 +96,26 @@ battstat_upower_initialise (void (*callback) (void))
GCancellable *cancellable = g_cancellable_new();
GError *gerror;
-#if !UP_CHECK_VERSION(0, 99, 0)
+#if UP_CHECK_VERSION(0, 99, 0)
+ devices = up_client_get_devices(upc);
+ if (!devices) {
+ goto error_shutdownclient;
+ }
+ g_ptr_array_unref(devices);
+#else
if (! up_client_enumerate_devices_sync( upc, cancellable, &gerror ) ) {
sprintf(error_str, "Unable to enumerate upower devices: %s\n", gerror->message);
goto error_shutdownclient;
}
#endif
+
+ g_signal_connect_after( upc, "device-added", device_cb, NULL );
#if UP_CHECK_VERSION(0, 99, 0)
- g_signal_connect_after( upc, "notify", device_cb, NULL );
+ g_signal_connect_after( upc, "device-removed", device_removed_cb, NULL );
#else
g_signal_connect_after( upc, "device-changed", device_cb, NULL );
-#endif
- g_signal_connect_after( upc, "device-added", device_cb, NULL );
g_signal_connect_after( upc, "device-removed", device_cb, NULL );
+#endif
return NULL;