summaryrefslogtreecommitdiff
path: root/src/gpm-engine.c
diff options
context:
space:
mode:
authorStefano Karapetsas <[email protected]>2014-04-22 18:00:55 +0200
committerStefano Karapetsas <[email protected]>2014-04-22 18:00:55 +0200
commitd96bb779e9d88d83ba2bf54e8610bf966dcdf1c9 (patch)
treebb895796d71a346eff190714b865928d82980422 /src/gpm-engine.c
parent8cb168b752f4130e88daefa400bb9bf07cf18227 (diff)
parentd59f4b8bd38e1628af3a992ae8e96b8e069ab738 (diff)
downloadmate-power-manager-d96bb779e9d88d83ba2bf54e8610bf966dcdf1c9.tar.bz2
mate-power-manager-d96bb779e9d88d83ba2bf54e8610bf966dcdf1c9.tar.xz
Merge pull request #98 from seife/master
make m-p-m work with current upower-0.99
Diffstat (limited to 'src/gpm-engine.c')
-rw-r--r--src/gpm-engine.c102
1 files changed, 51 insertions, 51 deletions
diff --git a/src/gpm-engine.c b/src/gpm-engine.c
index 0f9d0c1..e6c6bf2 100644
--- a/src/gpm-engine.c
+++ b/src/gpm-engine.c
@@ -72,7 +72,6 @@ enum {
CHARGE_ACTION,
DISCHARGING,
LOW_CAPACITY,
- PERHAPS_RECALL,
LAST_SIGNAL
};
@@ -761,42 +760,6 @@ gpm_engine_device_add (GpmEngine *engine, UpDevice *device)
}
/**
- * gpm_engine_check_recall:
- **/
-static gboolean
-gpm_engine_check_recall (GpmEngine *engine, UpDevice *device)
-{
- UpDeviceKind kind;
- gboolean recall_notice = FALSE;
- gchar *recall_vendor = NULL;
- gchar *recall_url = NULL;
-
- /* get device properties */
- g_object_get (device,
- "kind", &kind,
- "recall-notice", &recall_notice,
- "recall-vendor", &recall_vendor,
- "recall-url", &recall_url,
- NULL);
-
- /* not battery */
- if (kind != UP_DEVICE_KIND_BATTERY)
- goto out;
-
- /* no recall data */
- if (!recall_notice)
- goto out;
-
- /* emit signal for manager */
- egg_debug ("** EMIT: perhaps-recall");
- g_signal_emit (engine, signals [PERHAPS_RECALL], 0, device, recall_vendor, recall_url);
-out:
- g_free (recall_vendor);
- g_free (recall_url);
- return recall_notice;
-}
-
-/**
* gpm_engine_coldplug_idle_cb:
**/
static gboolean
@@ -805,12 +768,14 @@ gpm_engine_coldplug_idle_cb (GpmEngine *engine)
guint i;
GPtrArray *array = NULL;
UpDevice *device;
+#if !UP_CHECK_VERSION(0, 99, 0)
gboolean ret;
GError *error = NULL;
+#endif
g_return_val_if_fail (engine != NULL, FALSE);
g_return_val_if_fail (GPM_IS_ENGINE (engine), FALSE);
-
+#if !UP_CHECK_VERSION(0, 99, 0)
/* get devices from UPower */
ret = up_client_enumerate_devices_sync (engine->priv->client, NULL, &error);
if (!ret) {
@@ -818,7 +783,7 @@ gpm_engine_coldplug_idle_cb (GpmEngine *engine)
g_error_free (error);
goto out;
}
-
+#endif
/* connected mobile phones */
gpm_phone_coldplug (engine->priv->phone);
@@ -829,9 +794,10 @@ gpm_engine_coldplug_idle_cb (GpmEngine *engine)
for (i=0;i<array->len;i++) {
device = g_ptr_array_index (array, i);
gpm_engine_device_add (engine, device);
- gpm_engine_check_recall (engine, device);
}
+#if !UP_CHECK_VERSION(0, 99, 0)
out:
+#endif
if (array != NULL)
g_ptr_array_unref (array);
/* never repeat */
@@ -846,7 +812,6 @@ gpm_engine_device_added_cb (UpClient *client, UpDevice *device, GpmEngine *engin
{
/* add to list */
g_ptr_array_add (engine->priv->array, g_object_ref (device));
- gpm_engine_check_recall (engine, device);
gpm_engine_recalculate_state (engine);
}
@@ -855,6 +820,22 @@ gpm_engine_device_added_cb (UpClient *client, UpDevice *device, GpmEngine *engin
* gpm_engine_device_removed_cb:
**/
static void
+#if UP_CHECK_VERSION(0, 99, 0)
+gpm_engine_device_removed_cb (UpClient *client, const char *object_path, GpmEngine *engine)
+{
+ guint i;
+
+ for (i = 0; i < engine->priv->array->len; i++) {
+ UpDevice *device = g_ptr_array_index (engine->priv->array, i);
+
+ if (g_strcmp0 (object_path, up_device_get_object_path (device)) == 0) {
+ g_ptr_array_remove_index (engine->priv->array, i);
+ break;
+ }
+ }
+ gpm_engine_recalculate_state (engine);
+}
+#else
gpm_engine_device_removed_cb (UpClient *client, UpDevice *device, GpmEngine *engine)
{
gboolean ret;
@@ -863,12 +844,18 @@ gpm_engine_device_removed_cb (UpClient *client, UpDevice *device, GpmEngine *eng
return;
gpm_engine_recalculate_state (engine);
}
-
+#endif
/**
* gpm_engine_device_changed_cb:
**/
static void
+#if UP_CHECK_VERSION(0, 99, 0)
+gpm_engine_device_changed_cb (UpClient *client, GParamSpec *pspec, GpmEngine *engine)
+{
+ gpm_engine_recalculate_state (engine);
+}
+#else
gpm_engine_device_changed_cb (UpClient *client, UpDevice *device, GpmEngine *engine)
{
UpDeviceKind kind;
@@ -930,6 +917,7 @@ gpm_engine_device_changed_cb (UpClient *client, UpDevice *device, GpmEngine *eng
gpm_engine_recalculate_state (engine);
}
+#endif
/**
* gpm_engine_get_devices:
@@ -1042,7 +1030,10 @@ phone_device_refresh_cb (GpmPhone *phone, guint idx, GpmEngine *engine)
static void
gpm_engine_init (GpmEngine *engine)
{
-
+#if UP_CHECK_VERSION(0, 99, 0)
+ GPtrArray *array = NULL;
+ guint i;
+#endif
engine->priv = GPM_ENGINE_GET_PRIVATE (engine);
engine->priv->array = g_ptr_array_new_with_free_func (g_object_unref);
@@ -1051,8 +1042,13 @@ gpm_engine_init (GpmEngine *engine)
G_CALLBACK (gpm_engine_device_added_cb), engine);
g_signal_connect (engine->priv->client, "device-removed",
G_CALLBACK (gpm_engine_device_removed_cb), engine);
+#if UP_CHECK_VERSION(0, 99, 0)
+ g_signal_connect (engine->priv->client, "notify",
+ G_CALLBACK (gpm_engine_device_changed_cb), engine);
+#else
g_signal_connect (engine->priv->client, "device-changed",
G_CALLBACK (gpm_engine_device_changed_cb), engine);
+#endif
engine->priv->settings = g_settings_new (GPM_SETTINGS_SCHEMA);
g_signal_connect (engine->priv->settings, "changed",
@@ -1066,6 +1062,18 @@ gpm_engine_init (GpmEngine *engine)
g_signal_connect (engine->priv->phone, "device-refresh",
G_CALLBACK (phone_device_refresh_cb), engine);
+#if UP_CHECK_VERSION(0, 99, 0)
+ /* coldplug */
+ array = up_client_get_devices(engine->priv->client);
+ if (array) {
+ for (i = 0; i < array->len; i++) {
+ UpDevice *device = g_ptr_array_index (array, i);
+ gpm_engine_device_added_cb(engine->priv->client, device, engine);
+ }
+ g_ptr_array_free (array, TRUE);
+ }
+#endif
+
/* create a fake virtual composite battery */
engine->priv->battery_composite = up_device_new ();
g_object_set (engine->priv->battery_composite,
@@ -1134,14 +1142,6 @@ gpm_engine_class_init (GpmEngineClass *klass)
G_STRUCT_OFFSET (GpmEngineClass, low_capacity),
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals [PERHAPS_RECALL] =
- g_signal_new ("perhaps-recall",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, perhaps_recall),
- NULL, NULL, gpm_marshal_VOID__POINTER_STRING_STRING,
- G_TYPE_NONE,
- 3, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
signals [FULLY_CHARGED] =
g_signal_new ("fully-charged",
G_TYPE_FROM_CLASS (object_class),