diff options
author | Brent Hull <[email protected]> | 2012-10-27 21:17:07 -0400 |
---|---|---|
committer | Brent Hull <[email protected]> | 2012-10-27 21:17:07 -0400 |
commit | aa88be1d4a4e545b4141b0065b094d49d3d3a81b (patch) | |
tree | 631437e0c5df2754ed31d4b5e31a1b5ca9d134e3 /src | |
parent | 543b06f44cafd70fe708fd54a82cba198a6da73b (diff) | |
download | mate-power-manager-aa88be1d4a4e545b4141b0065b094d49d3d3a81b.tar.bz2 mate-power-manager-aa88be1d4a4e545b4141b0065b094d49d3d3a81b.tar.xz |
Get device capabilities in the preferences capplet, not the daemon (GNOME fix for bug #617529 originally by Richard Hughes)
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 8 | ||||
-rw-r--r-- | src/gpm-backlight.c | 17 | ||||
-rw-r--r-- | src/gpm-engine.c | 37 | ||||
-rw-r--r-- | src/gpm-manager.c | 19 | ||||
-rw-r--r-- | src/gpm-manager.h | 3 | ||||
-rw-r--r-- | src/gpm-prefs-core.c | 97 | ||||
-rw-r--r-- | src/gpm-prefs-server.c | 138 | ||||
-rw-r--r-- | src/gpm-prefs-server.h | 67 | ||||
-rw-r--r-- | src/org.mate.PowerManager.xml | 3 |
9 files changed, 50 insertions, 339 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 9aa8cdc..2fdf9d0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -77,6 +77,8 @@ libgpmshared_a_SOURCES = \ egg-console-kit.c \ gpm-common.h \ gpm-common.c \ + gpm-brightness.h \ + gpm-brightness.c \ gpm-marshal.h \ gpm-marshal.c \ gpm-upower.c \ @@ -146,8 +148,6 @@ mate_power_manager_SOURCES = \ gpm-phone.c \ gpm-backlight.h \ gpm-backlight.c \ - gpm-prefs-server.h \ - gpm-prefs-server.c \ gpm-idle.h \ gpm-idle.c \ gpm-load.h \ @@ -158,8 +158,6 @@ mate_power_manager_SOURCES = \ gpm-control.c \ gpm-button.h \ gpm-button.c \ - gpm-brightness.h \ - gpm-brightness.c \ gpm-main.c \ gpm-manager.h \ gpm-manager.c \ @@ -218,8 +216,6 @@ mate_power_self_test_SOURCES = \ egg-array-float.c \ egg-console-kit.h \ egg-console-kit.c \ - gpm-prefs-server.h \ - gpm-prefs-server.c \ gpm-control.h \ gpm-control.c \ gpm-networkmanager.h \ diff --git a/src/gpm-backlight.c b/src/gpm-backlight.c index c0479fd..c88e220 100644 --- a/src/gpm-backlight.c +++ b/src/gpm-backlight.c @@ -53,7 +53,6 @@ #include "gpm-idle.h" #include "gpm-marshal.h" #include "gpm-stock-icons.h" -#include "gpm-prefs-server.h" #include "egg-console-kit.h" #define GPM_BACKLIGHT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_BACKLIGHT, GpmBacklightPrivate)) @@ -724,9 +723,6 @@ gpm_backlight_class_init (GpmBacklightClass *klass) static void gpm_backlight_init (GpmBacklight *backlight) { - gboolean lid_is_present = TRUE; - GpmPrefsServer *prefs_server; - backlight->priv = GPM_BACKLIGHT_GET_PRIVATE (backlight); /* record our idle time */ @@ -745,19 +741,6 @@ gpm_backlight_init (GpmBacklight *backlight) /* gets caps */ backlight->priv->can_dim = gpm_brightness_has_hw (backlight->priv->brightness); - /* we use UPower to see if we should show the lid UI */ - g_object_get (backlight->priv->client, - "lid-is-present", &lid_is_present, - NULL); - - /* expose ui in prefs program */ - prefs_server = gpm_prefs_server_new (); - if (lid_is_present) - gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_LID); - if (backlight->priv->can_dim) - gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_BACKLIGHT); - g_object_unref (prefs_server); - /* watch for dim value changes */ backlight->priv->conf = mateconf_client_get_default (); diff --git a/src/gpm-engine.c b/src/gpm-engine.c index 1ca78b8..0b1bb62 100644 --- a/src/gpm-engine.c +++ b/src/gpm-engine.c @@ -34,7 +34,6 @@ #include "gpm-marshal.h" #include "gpm-engine.h" #include "gpm-stock-icons.h" -#include "gpm-prefs-server.h" #include "gpm-phone.h" static void gpm_engine_finalize (GObject *object); @@ -816,12 +815,8 @@ static gboolean gpm_engine_coldplug_idle_cb (GpmEngine *engine) { guint i; - GPtrArray *array; - gboolean has_battery = FALSE; - gboolean has_ups = FALSE; - GpmPrefsServer *prefs_server; + GPtrArray *array = NULL; UpDevice *device; - UpDeviceKind kind; gboolean ret; GError *error = NULL; @@ -835,31 +830,6 @@ gpm_engine_coldplug_idle_cb (GpmEngine *engine) g_error_free (error); goto out; } - engine->priv->array = up_client_get_devices (engine->priv->client); - - /* do we have specific device types? */ - array = engine->priv->array; - for (i=0;i<array->len;i++) { - device = g_ptr_array_index (engine->priv->array, i); - - /* get device properties */ - g_object_get (device, - "kind", &kind, - NULL); - - if (kind == UP_DEVICE_KIND_BATTERY) - has_battery = TRUE; - else if (kind == UP_DEVICE_KIND_UPS) - has_ups = TRUE; - } - - /* only show the battery prefs section if we have batteries */ - prefs_server = gpm_prefs_server_new (); - if (has_battery) - gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_BATTERY); - if (has_ups) - gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_UPS); - g_object_unref (prefs_server); /* connected mobile phones */ gpm_phone_coldplug (engine->priv->phone); @@ -867,12 +837,15 @@ gpm_engine_coldplug_idle_cb (GpmEngine *engine) gpm_engine_recalculate_state (engine); /* add to database */ + array = up_client_get_devices (engine->priv->client); for (i=0;i<array->len;i++) { - device = g_ptr_array_index (engine->priv->array, i); + device = g_ptr_array_index (array, i); gpm_engine_device_add (engine, device); gpm_engine_check_recall (engine, device); } out: + if (array != NULL) + g_ptr_array_unref (array); /* never repeat */ return FALSE; } diff --git a/src/gpm-manager.c b/src/gpm-manager.c index ec787be..a84f338 100644 --- a/src/gpm-manager.c +++ b/src/gpm-manager.c @@ -56,7 +56,6 @@ #include "gpm-backlight.h" #include "gpm-session.h" #include "gpm-stock-icons.h" -#include "gpm-prefs-server.h" #include "gpm-tray-icon.h" #include "gpm-engine.h" #include "gpm-upower.h" @@ -81,7 +80,6 @@ struct GpmManagerPrivate GpmDisks *disks; GpmDpms *dpms; GpmIdle *idle; - GpmPrefsServer *prefs_server; GpmControl *control; GpmScreensaver *screensaver; GpmTrayIcon *tray_icon; @@ -375,7 +373,7 @@ gpm_manager_sync_policy_sleep (GpmManager *manager) * Turn off the backlight of the LCD when we shut the lid, and lock * if required. This is required because some laptops do not turn off the * LCD backlight when the lid is closed. - * See http://bugzilla.mate.org/show_bug.cgi?id=321313 + * See http://bugzilla.gnome.org/show_bug.cgi?id=321313 * * Return value: Success. **/ @@ -711,17 +709,6 @@ gpm_manager_perform_policy (GpmManager *manager, const gchar *policy_key, const } /** - * gpm_manager_get_preferences_options: - **/ -gboolean -gpm_manager_get_preferences_options (GpmManager *manager, gint *capability, GError **error) -{ - g_return_val_if_fail (manager != NULL, FALSE); - g_return_val_if_fail (GPM_IS_MANAGER (manager), FALSE); - return gpm_prefs_server_get_capability (manager->priv->prefs_server, capability); -} - -/** * gpm_manager_idle_do_sleep: * @manager: This class instance * @@ -1930,9 +1917,6 @@ gpm_manager_init (GpmManager *manager) /* don't apply policy when not active, so listen to ConsoleKit */ manager->priv->console = egg_console_kit_new (); - /* this is a singleton, so we keep a master copy open here */ - manager->priv->prefs_server = gpm_prefs_server_new (); - manager->priv->notification_general = NULL; manager->priv->notification_warning_low = NULL; manager->priv->notification_discharging = NULL; @@ -2085,7 +2069,6 @@ gpm_manager_finalize (GObject *object) g_object_unref (manager->priv->engine); g_object_unref (manager->priv->tray_icon); g_object_unref (manager->priv->screensaver); - g_object_unref (manager->priv->prefs_server); g_object_unref (manager->priv->control); g_object_unref (manager->priv->button); g_object_unref (manager->priv->backlight); diff --git a/src/gpm-manager.h b/src/gpm-manager.h index 1d31b75..a78509a 100644 --- a/src/gpm-manager.h +++ b/src/gpm-manager.h @@ -73,9 +73,6 @@ gboolean gpm_manager_can_suspend (GpmManager *manager, gboolean gpm_manager_can_hibernate (GpmManager *manager, gboolean *can_hibernate, GError **error); -gboolean gpm_manager_get_preferences_options (GpmManager *manager, - gint *capability, - GError **error); G_END_DECLS diff --git a/src/gpm-prefs-core.c b/src/gpm-prefs-core.c index a35b268..46cae73 100644 --- a/src/gpm-prefs-core.c +++ b/src/gpm-prefs-core.c @@ -40,7 +40,7 @@ #include "gpm-common.h" #include "gpm-prefs-core.h" #include "gpm-stock-icons.h" -#include "gpm-prefs-server.h" +#include "gpm-brightness.h" static void gpm_prefs_finalize (GObject *object); @@ -119,46 +119,6 @@ gpm_prefs_activate_window (GpmPrefs *prefs) } /** - * gpm_dbus_get_caps: - * @method: The g-p-m DBUS method name, e.g. "AllowedSuspend" - **/ -static gint -gpm_dbus_get_caps (GpmPrefs *prefs) -{ - DBusGConnection *connection; - DBusGProxy *proxy = NULL; - GError *error = NULL; - gboolean ret; - gint value = 0; - - connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); - if (connection == NULL) { - egg_warning ("Couldn't connect to g-p-m %s", error->message); - g_error_free (error); - goto out; - } - - proxy = dbus_g_proxy_new_for_name (connection, - GPM_DBUS_SERVICE, - GPM_DBUS_PATH, - GPM_DBUS_INTERFACE); - ret = dbus_g_proxy_call (proxy, "GetPreferencesOptions", &error, - G_TYPE_INVALID, - G_TYPE_INT, &value, - G_TYPE_INVALID); - if (!ret) { - /* abort as the DBUS method failed */ - egg_warning ("GetPreferencesOptions failed: %s", error->message); - g_error_free (error); - goto out; - } -out: - if (proxy != NULL) - g_object_unref (proxy); - return value; -} - -/** * gpm_prefs_help_cb: * @widget: The GtkWidget object * @prefs: This prefs class instance @@ -980,9 +940,14 @@ gpm_prefs_init (GpmPrefs *prefs) { GtkWidget *main_window; GtkWidget *widget; - gint caps; guint retval; GError *error = NULL; + GPtrArray *devices = NULL; + UpDevice *device; + UpDeviceKind kind; + GpmBrightness *brightness; + gboolean ret; + guint i; prefs->priv = GPM_PREFS_GET_PRIVATE (prefs); @@ -999,25 +964,47 @@ gpm_prefs_init (GpmPrefs *prefs) /* get value of delay in mate-session */ prefs->priv->idle_delay = mateconf_client_get_int (prefs->priv->conf, GPM_CONF_IDLE_DELAY, NULL); - caps = gpm_dbus_get_caps (prefs); - egg_debug ("caps=%i", caps); - - /* get properties from mate-power-manager */ - prefs->priv->has_batteries = ((caps & GPM_PREFS_SERVER_BATTERY) > 0); - prefs->priv->has_ups = ((caps & GPM_PREFS_SERVER_UPS) > 0); - prefs->priv->has_lcd = ((caps & GPM_PREFS_SERVER_BACKLIGHT) > 0); - prefs->priv->has_button_lid = ((caps & GPM_PREFS_SERVER_LID) > 0); - prefs->priv->has_button_suspend = TRUE; - /* are we allowed to shutdown? */ prefs->priv->can_shutdown = TRUE; egg_console_kit_can_stop (prefs->priv->console, &prefs->priv->can_shutdown, NULL); /* get values from UpClient */ + prefs->priv->can_suspend = up_client_get_can_suspend (prefs->priv->client); + prefs->priv->can_hibernate = up_client_get_can_hibernate (prefs->priv->client); + +#if UP_CHECK_VERSION(0,9,2) + prefs->priv->has_button_lid = up_client_get_lid_is_present (prefs->priv->client); +#else g_object_get (prefs->priv->client, - "can-suspend", &prefs->priv->can_suspend, - "can-hibernate", &prefs->priv->can_hibernate, - NULL); + "lid-is-present", &prefs->priv->has_button_lid, + NULL); +#endif + prefs->priv->has_button_suspend = TRUE; + + /* find if we have brightness hardware */ + brightness = gpm_brightness_new (); + prefs->priv->has_lcd = gpm_brightness_has_hw (brightness); + g_object_unref (brightness); + + /* get device list */ + ret = up_client_enumerate_devices_sync (prefs->priv->client, NULL, &error); + if (!ret) { + egg_warning ("failed to get device list: %s", error->message); + g_error_free (error); + } + + devices = up_client_get_devices (prefs->priv->client); + for (i=0; i<devices->len; i++) { + device = g_ptr_array_index (devices, i); + g_object_get (device, + "kind", &kind, + NULL); + if (kind == UP_DEVICE_KIND_BATTERY) + prefs->priv->has_batteries = TRUE; + if (kind == UP_DEVICE_KIND_UPS) + prefs->priv->has_ups = TRUE; + } + g_ptr_array_unref (devices); prefs->priv->builder = gtk_builder_new (); diff --git a/src/gpm-prefs-server.c b/src/gpm-prefs-server.c deleted file mode 100644 index 2ced9ff..0000000 --- a/src/gpm-prefs-server.c +++ /dev/null @@ -1,138 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 Richard Hughes <[email protected]> - * - * 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 <stdlib.h> -#include <stdio.h> -#include <time.h> -#include <errno.h> - -#include <string.h> -#include <sys/time.h> -#include <sys/types.h> -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#include <glib/gi18n.h> -#include <dbus/dbus-glib.h> - -#include "gpm-prefs-server.h" -#include "egg-debug.h" - -#define GPM_PREFS_SERVER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_PREFS_SERVER, GpmPrefsServerPrivate)) - -struct GpmPrefsServerPrivate -{ - guint capability; -}; - -enum { - CAPABILITY_CHANGED, - LAST_SIGNAL -}; - -static guint signals [LAST_SIGNAL] = { 0 }; -static gpointer gpm_prefs_server_object = NULL; - -G_DEFINE_TYPE (GpmPrefsServer, gpm_prefs_server, G_TYPE_OBJECT) - -/** - * gpm_prefs_server_get_capability: - **/ -gboolean -gpm_prefs_server_get_capability (GpmPrefsServer *server, - gint *capability) -{ - g_return_val_if_fail (server != NULL, FALSE); - g_return_val_if_fail (GPM_IS_PREFS_SERVER (server), FALSE); - *capability = server->priv->capability; - return TRUE; -} - -/** - * gpm_prefs_server_set_capability: - **/ -gboolean -gpm_prefs_server_set_capability (GpmPrefsServer *server, - gint capability) -{ - g_return_val_if_fail (server != NULL, FALSE); - g_return_val_if_fail (GPM_IS_PREFS_SERVER (server), FALSE); - server->priv->capability = server->priv->capability + capability; - egg_debug ("capability now %i", server->priv->capability); - return TRUE; -} - -/** - * gpm_prefs_server_class_init: - * @klass: This prefs class instance - **/ -static void -gpm_prefs_server_class_init (GpmPrefsServerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (klass, sizeof (GpmPrefsServerPrivate)); - signals [CAPABILITY_CHANGED] = - g_signal_new ("capability-changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (GpmPrefsServerClass, capability_changed), - NULL, - NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -/** - * gpm_prefs_server_init: - * @server: This server class instance - * - * initialises the server class. NOTE: We expect prefs_server objects - * to *NOT* be removed or added during the session. - * We only control the first prefs_server object if there are more than one. - **/ -static void -gpm_prefs_server_init (GpmPrefsServer *server) -{ - server->priv = GPM_PREFS_SERVER_GET_PRIVATE (server); - server->priv->capability = 0; -} - -/** - * gpm_prefs_server_new: - * Return value: A new server class instance. - * Can return NULL if no suitable hardware is found. - **/ -GpmPrefsServer * -gpm_prefs_server_new (void) -{ - if (gpm_prefs_server_object != NULL) { - g_object_ref (gpm_prefs_server_object); - } else { - gpm_prefs_server_object = g_object_new (GPM_TYPE_PREFS_SERVER, NULL); - g_object_add_weak_pointer (gpm_prefs_server_object, &gpm_prefs_server_object); - } - return GPM_PREFS_SERVER (gpm_prefs_server_object); -} diff --git a/src/gpm-prefs-server.h b/src/gpm-prefs-server.h deleted file mode 100644 index 62cadb6..0000000 --- a/src/gpm-prefs-server.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2007 Richard Hughes <[email protected]> - * - * 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 __GPM_PREFS_SERVER_H -#define __GPM_PREFS_SERVER_H - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define GPM_TYPE_PREFS_SERVER (gpm_prefs_server_get_type ()) -#define GPM_PREFS_SERVER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_PREFS_SERVER, GpmPrefsServer)) -#define GPM_PREFS_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_PREFS_SERVER, GpmPrefsServerClass)) -#define GPM_IS_PREFS_SERVER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_PREFS_SERVER)) -#define GPM_IS_PREFS_SERVER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_PREFS_SERVER)) -#define GPM_PREFS_SERVER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_PREFS_SERVER, GpmPrefsServerClass)) - -#define GPM_PREFS_SERVER_BACKLIGHT 1 -#define GPM_PREFS_SERVER_LID 4 -#define GPM_PREFS_SERVER_BATTERY 8 -#define GPM_PREFS_SERVER_UPS 16 -#define GPM_PREFS_SERVER_KEYLIGHT 32 - -typedef struct GpmPrefsServerPrivate GpmPrefsServerPrivate; - -typedef struct -{ - GObject parent; - GpmPrefsServerPrivate *priv; -} GpmPrefsServer; - -typedef struct -{ - GObjectClass parent_class; - void (* capability_changed) (GpmPrefsServer *server, - gint capability); -} GpmPrefsServerClass; - -GType gpm_prefs_server_get_type (void); -GpmPrefsServer *gpm_prefs_server_new (void); - -gboolean gpm_prefs_server_get_capability (GpmPrefsServer *server, - gint *capability); -gboolean gpm_prefs_server_set_capability (GpmPrefsServer *server, - gint capability); - -G_END_DECLS - -#endif /* __GPM_PREFS_SERVER_H */ diff --git a/src/org.mate.PowerManager.xml b/src/org.mate.PowerManager.xml index a5ca988..c4c73ff 100644 --- a/src/org.mate.PowerManager.xml +++ b/src/org.mate.PowerManager.xml @@ -1,9 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <node name="/"> <interface name="org.mate.PowerManager"> - <method name="GetPreferencesOptions"> - <arg type="i" name="capability" direction="out"/> - </method> </interface> </node> |