diff --git a/plugins/power/csd-power-manager.c b/plugins/power/csd-power-manager.c index 3a15985..4caf6ab 100644 --- a/plugins/power/csd-power-manager.c +++ b/plugins/power/csd-power-manager.c @@ -42,7 +42,6 @@ #include #include "gpm-common.h" -#include "gpm-phone.h" #include "gpm-idletime.h" #include "cinnamon-settings-profile.h" #include "cinnamon-settings-session.h" @@ -156,7 +155,6 @@ struct CsdPowerManagerPrivate GnomeRRScreen *x11_screen; gboolean use_time_primary; GIcon *previous_icon; - GpmPhone *phone; GPtrArray *devices_array; guint action_percentage; guint action_time; @@ -913,9 +911,6 @@ engine_coldplug (CsdPowerManager *manager) GPtrArray *array = NULL; UpDevice *device; - /* connected mobile phones */ - gpm_phone_coldplug (manager->priv->phone); - engine_recalculate_state (manager); /* add to database */ @@ -1705,90 +1700,6 @@ engine_get_primary_device (CsdPowerManager *manager) return device; } -static void -phone_device_added_cb (GpmPhone *phone, guint idx, CsdPowerManager *manager) -{ - UpDevice *device; - device = up_device_new (); - - g_debug ("phone added %i", idx); - - /* get device properties */ - g_object_set (device, - "kind", UP_DEVICE_KIND_PHONE, - "is-rechargeable", TRUE, - "native-path", g_strdup_printf ("dummy:phone_%i", idx), - "is-present", TRUE, - NULL); - - /* state changed */ - engine_device_add (manager, device); - g_ptr_array_add (manager->priv->devices_array, g_object_ref (device)); - engine_recalculate_state (manager); -} - -static void -phone_device_removed_cb (GpmPhone *phone, guint idx, CsdPowerManager *manager) -{ - guint i; - UpDevice *device; - UpDeviceKind kind; - - g_debug ("phone removed %i", idx); - - for (i=0; ipriv->devices_array->len; i++) { - device = g_ptr_array_index (manager->priv->devices_array, i); - - /* get device properties */ - g_object_get (device, - "kind", &kind, - NULL); - - if (kind == UP_DEVICE_KIND_PHONE) { - g_ptr_array_remove_index (manager->priv->devices_array, i); - break; - } - } - - /* state changed */ - engine_recalculate_state (manager); -} - -static void -phone_device_refresh_cb (GpmPhone *phone, guint idx, CsdPowerManager *manager) -{ - guint i; - UpDevice *device; - UpDeviceKind kind; - UpDeviceState state; - gboolean is_present; - gdouble percentage; - - g_debug ("phone refresh %i", idx); - - for (i=0; ipriv->devices_array->len; i++) { - device = g_ptr_array_index (manager->priv->devices_array, i); - - /* get device properties */ - g_object_get (device, - "kind", &kind, - "state", &state, - "percentage", &percentage, - "is-present", &is_present, - NULL); - - if (kind == UP_DEVICE_KIND_PHONE) { - is_present = gpm_phone_get_present (phone, idx); - state = gpm_phone_get_on_ac (phone, idx) ? UP_DEVICE_STATE_CHARGING : UP_DEVICE_STATE_DISCHARGING; - percentage = gpm_phone_get_percentage (phone, idx); - break; - } - } - - /* state changed */ - engine_recalculate_state (manager); -} - static void cinnamon_session_shutdown_cb (GObject *source_object, GAsyncResult *res, @@ -4094,14 +4005,6 @@ on_rr_screen_acquired (GObject *object, connect_screen_iface (manager); connect_keyboard_iface (manager); - manager->priv->phone = gpm_phone_new (); - g_signal_connect (manager->priv->phone, "device-added", - G_CALLBACK (phone_device_added_cb), manager); - g_signal_connect (manager->priv->phone, "device-removed", - G_CALLBACK (phone_device_removed_cb), manager); - g_signal_connect (manager->priv->phone, "device-refresh", - G_CALLBACK (phone_device_refresh_cb), manager); - /* create a fake virtual composite battery */ manager->priv->device_composite = up_device_new (); g_object_set (manager->priv->device_composite, @@ -4295,11 +4198,6 @@ csd_power_manager_stop (CsdPowerManager *manager) g_ptr_array_unref (manager->priv->devices_array); manager->priv->devices_array = NULL; - if (manager->priv->phone != NULL) { - g_object_unref (manager->priv->phone); - manager->priv->phone = NULL; - } - if (manager->priv->device_composite != NULL) { g_object_unref (manager->priv->device_composite); manager->priv->device_composite = NULL; diff --git a/plugins/power/gpm-phone.c b/plugins/power/gpm-phone.c deleted file mode 100644 index 2358147..0000000 --- a/plugins/power/gpm-phone.c +++ /dev/null @@ -1,332 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007-2011 Richard Hughes - * - * 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 "config.h" - -#include -#include -#include -#include - -#include "gpm-phone.h" - -static void gpm_phone_finalize (GObject *object); - -#define GPM_PHONE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_PHONE, GpmPhonePrivate)) - -struct GpmPhonePrivate -{ - GDBusProxy *proxy; - GDBusConnection *connection; - guint watch_id; - gboolean present; - guint percentage; - gboolean onac; -}; - -enum { - DEVICE_ADDED, - DEVICE_REMOVED, - DEVICE_REFRESH, - LAST_SIGNAL -}; - -static guint signals [LAST_SIGNAL] = { 0 }; -static gpointer gpm_phone_object = NULL; - -G_DEFINE_TYPE (GpmPhone, gpm_phone, G_TYPE_OBJECT) - -gboolean -gpm_phone_coldplug (GpmPhone *phone) -{ - GError *error = NULL; - GVariant *reply; - gboolean ret; - - g_return_val_if_fail (phone != NULL, FALSE); - g_return_val_if_fail (GPM_IS_PHONE (phone), FALSE); - - if (phone->priv->proxy == NULL) - return FALSE; - - reply = g_dbus_proxy_call_sync (phone->priv->proxy, "Coldplug", - NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error != NULL) { - g_warning ("DEBUG: ERROR: %s", error->message); - g_error_free (error); - } - - if (reply != NULL) { - ret = TRUE; - g_variant_unref (reply); - } else - ret = FALSE; - - return ret; -} - -gboolean -gpm_phone_get_present (GpmPhone *phone, guint idx) -{ - g_return_val_if_fail (phone != NULL, FALSE); - g_return_val_if_fail (GPM_IS_PHONE (phone), FALSE); - return phone->priv->present; -} - -guint -gpm_phone_get_percentage (GpmPhone *phone, guint idx) -{ - g_return_val_if_fail (phone != NULL, 0); - g_return_val_if_fail (GPM_IS_PHONE (phone), 0); - return phone->priv->percentage; -} - -gboolean -gpm_phone_get_on_ac (GpmPhone *phone, guint idx) -{ - g_return_val_if_fail (phone != NULL, FALSE); - g_return_val_if_fail (GPM_IS_PHONE (phone), FALSE); - return phone->priv->onac; -} - -guint -gpm_phone_get_num_batteries (GpmPhone *phone) -{ - g_return_val_if_fail (phone != NULL, 0); - g_return_val_if_fail (GPM_IS_PHONE (phone), 0); - if (phone->priv->present) - return 1; - return 0; -} - -static void -gpm_phone_battery_state_changed (GDBusProxy *proxy, - guint idx, - guint percentage, - gboolean on_ac, - GpmPhone *phone) -{ - g_return_if_fail (GPM_IS_PHONE (phone)); - - g_debug ("got BatteryStateChanged %i = %i (%i)", idx, percentage, on_ac); - phone->priv->percentage = percentage; - phone->priv->onac = on_ac; - phone->priv->present = TRUE; - g_debug ("emitting device-refresh : (%i)", idx); - g_signal_emit (phone, signals [DEVICE_REFRESH], 0, idx); -} - -static void -gpm_phone_num_batteries_changed (GDBusProxy *proxy, - guint number, - GpmPhone *phone) -{ - g_return_if_fail (GPM_IS_PHONE (phone)); - - g_debug ("got NumberBatteriesChanged %i", number); - if (number > 1) { - g_warning ("number not 0 or 1, not valid!"); - return; - } - - /* are we removed? */ - if (number == 0) { - phone->priv->present = FALSE; - phone->priv->percentage = 0; - phone->priv->onac = FALSE; - g_debug ("emitting device-removed : (%i)", 0); - g_signal_emit (phone, signals [DEVICE_REMOVED], 0, 0); - return; - } - - if (phone->priv->present) { - g_warning ("duplicate NumberBatteriesChanged with no change"); - return; - } - - /* reset to defaults until we get BatteryStateChanged */ - phone->priv->present = TRUE; - phone->priv->percentage = 0; - phone->priv->onac = FALSE; - g_debug ("emitting device-added : (%i)", 0); - g_signal_emit (phone, signals [DEVICE_ADDED], 0, 0); -} - -static void -gpm_phone_generic_signal_cb (GDBusProxy *proxy, - gchar *sender_name, gchar *signal_name, - GVariant *parameters, gpointer user_data) { - - GpmPhone *self = GPM_PHONE (user_data); - - if (!g_strcmp0 (signal_name, "BatteryStateChanged")) { - guint idx, percentage; - gboolean on_ac; - - g_variant_get (parameters, "(uub)", &idx, &percentage, &on_ac); - gpm_phone_battery_state_changed (proxy, idx, percentage, on_ac, self); - return; - } - - if (!g_strcmp0 (signal_name, "NumberBatteriesChanged")) { - guint number; - - g_variant_get (parameters, "(u)", &number); - gpm_phone_num_batteries_changed (proxy, number, self); - return; - } - - /* not a signal we're interested in */ -} - -static void -gpm_phone_class_init (GpmPhoneClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->finalize = gpm_phone_finalize; - g_type_class_add_private (klass, sizeof (GpmPhonePrivate)); - - signals [DEVICE_ADDED] = - g_signal_new ("device-added", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GpmPhoneClass, device_added), - NULL, NULL, g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, G_TYPE_UINT); - - signals [DEVICE_REMOVED] = - g_signal_new ("device-removed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GpmPhoneClass, device_removed), - NULL, NULL, g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, G_TYPE_UINT); - - signals [DEVICE_REFRESH] = - g_signal_new ("device-refresh", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GpmPhoneClass, device_refresh), - NULL, NULL, g_cclosure_marshal_VOID__UINT, - G_TYPE_NONE, 1, G_TYPE_UINT); -} - -static void -gpm_phone_service_appeared_cb (GDBusConnection *connection, - const gchar *name, const gchar *name_owner, - GpmPhone *phone) -{ - GError *error = NULL; - - g_return_if_fail (GPM_IS_PHONE (phone)); - - if (phone->priv->connection == NULL) { - g_debug ("get connection"); - g_clear_error (&error); - phone->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); - if (phone->priv->connection == NULL) { - g_warning ("Could not connect to DBUS daemon: %s", error->message); - g_error_free (error); - phone->priv->connection = NULL; - return; - } - } - if (phone->priv->proxy == NULL) { - g_debug ("get proxy"); - g_clear_error (&error); - phone->priv->proxy = g_dbus_proxy_new_sync (phone->priv->connection, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, - NULL, - CINNAMON_PHONE_MANAGER_DBUS_SERVICE, - CINNAMON_PHONE_MANAGER_DBUS_PATH, - CINNAMON_PHONE_MANAGER_DBUS_INTERFACE, - NULL, &error); - if (phone->priv->proxy == NULL) { - g_warning ("Cannot connect, maybe the daemon is not running: %s", error->message); - g_error_free (error); - phone->priv->proxy = NULL; - return; - } - - g_signal_connect (phone->priv->proxy, "g-signal", G_CALLBACK(gpm_phone_generic_signal_cb), phone); - } -} - -static void -gpm_phone_service_vanished_cb (GDBusConnection *connection, - const gchar *name, - GpmPhone *phone) -{ - g_return_if_fail (GPM_IS_PHONE (phone)); - - if (phone->priv->proxy == NULL) - return; - g_debug ("removing proxy"); - g_object_unref (phone->priv->proxy); - phone->priv->proxy = NULL; - if (phone->priv->present) { - phone->priv->present = FALSE; - phone->priv->percentage = 0; - g_debug ("emitting device-removed : (%i)", 0); - g_signal_emit (phone, signals [DEVICE_REMOVED], 0, 0); - } -} - -static void -gpm_phone_init (GpmPhone *phone) -{ - phone->priv = GPM_PHONE_GET_PRIVATE (phone); - phone->priv->watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION, - CINNAMON_PHONE_MANAGER_DBUS_SERVICE, - G_BUS_NAME_WATCHER_FLAGS_NONE, - (GBusNameAppearedCallback) gpm_phone_service_appeared_cb, - (GBusNameVanishedCallback) gpm_phone_service_vanished_cb, - phone, NULL); -} - -static void -gpm_phone_finalize (GObject *object) -{ - GpmPhone *phone; - g_return_if_fail (GPM_IS_PHONE (object)); - - phone = GPM_PHONE (object); - phone->priv = GPM_PHONE_GET_PRIVATE (phone); - - if (phone->priv->proxy != NULL) - g_object_unref (phone->priv->proxy); - g_bus_unwatch_name (phone->priv->watch_id); - - G_OBJECT_CLASS (gpm_phone_parent_class)->finalize (object); -} - -GpmPhone * -gpm_phone_new (void) -{ - if (gpm_phone_object != NULL) { - g_object_ref (gpm_phone_object); - } else { - gpm_phone_object = g_object_new (GPM_TYPE_PHONE, NULL); - g_object_add_weak_pointer (gpm_phone_object, &gpm_phone_object); - } - return GPM_PHONE (gpm_phone_object); -} - diff --git a/plugins/power/gpm-phone.h b/plugins/power/gpm-phone.h deleted file mode 100644 index 536c594..0000000 --- a/plugins/power/gpm-phone.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- - * - * Copyright (C) 2007-2011 Richard Hughes - * - * 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 __GPMPHONE_H -#define __GPMPHONE_H - -#include - -G_BEGIN_DECLS - -#define GPM_TYPE_PHONE (gpm_phone_get_type ()) -#define GPM_PHONE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_PHONE, GpmPhone)) -#define GPM_PHONE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_PHONE, GpmPhoneClass)) -#define GPM_IS_PHONE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_PHONE)) -#define GPM_IS_PHONE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_PHONE)) -#define GPM_PHONE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_PHONE, GpmPhoneClass)) - -#define CINNAMON_PHONE_MANAGER_DBUS_SERVICE "org.cinnamon.phone" -#define CINNAMON_PHONE_MANAGER_DBUS_PATH "/org/cinnamon/phone/Manager" -#define CINNAMON_PHONE_MANAGER_DBUS_INTERFACE "org.cinnamon.phone.Manager" - -typedef struct GpmPhonePrivate GpmPhonePrivate; - -typedef struct -{ - GObject parent; - GpmPhonePrivate *priv; -} GpmPhone; - -typedef struct -{ - GObjectClass parent_class; - void (* device_added) (GpmPhone *phone, - guint idx); - void (* device_removed) (GpmPhone *phone, - guint idx); - void (* device_refresh) (GpmPhone *phone, - guint idx); -} GpmPhoneClass; - -GType gpm_phone_get_type (void); -GpmPhone *gpm_phone_new (void); - -gboolean gpm_phone_get_present (GpmPhone *phone, - guint idx); -guint gpm_phone_get_percentage (GpmPhone *phone, - guint idx); -gboolean gpm_phone_get_on_ac (GpmPhone *phone, - guint idx); -guint gpm_phone_get_num_batteries (GpmPhone *phone); -gboolean gpm_phone_coldplug (GpmPhone *phone); - -G_END_DECLS - -#endif /* __GPMPHONE_H */ diff --git a/plugins/power/meson.build b/plugins/power/meson.build index 61c1a24..b48fca7 100644 --- a/plugins/power/meson.build +++ b/plugins/power/meson.build @@ -30,7 +30,6 @@ power_keyboard_proxy = gnome.gdbus_codegen( power_sources = [ 'csd-power-manager.c', 'gpm-common.c', - 'gpm-phone.c', 'gpm-idletime.c', 'main.c', power_proxy,