[gnome-power-manager] Remove the inhibit interface, and rely on gnome-session
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-power-manager] Remove the inhibit interface, and rely on gnome-session
- Date: Wed, 6 May 2009 11:36:56 -0400 (EDT)
commit 52a8304359d35f9614663bd5be1e8f269d1cf98e
Author: Richard Hughes <richard hughsie com>
Date: Wed May 6 15:59:22 2009 +0100
Remove the inhibit interface, and rely on gnome-session
---
po/POTFILES.in | 27 -
src/Makefile.am | 13 -
src/gpm-inhibit.c | 745 -----------------------
src/gpm-inhibit.h | 80 ---
src/gpm-manager.c | 117 +----
src/gpm-self-test.c | 5 -
src/org.freedesktop.PowerManagement.Inhibit.xml | 19 -
7 files changed, 1 insertions(+), 1005 deletions(-)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 48e0f11..4881478 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,7 +1,6 @@
[encoding: UTF-8]
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
-
applets/brightness/brightness-applet.c
applets/brightness/GNOME_BrightnessApplet.server.in.in
applets/inhibit/inhibit-applet.c
@@ -14,55 +13,29 @@ data/gpm-feedback-widget.glade
data/gpm-statistics.glade
data/gpm-inhibit-test.glade
data/gpm-prefs.glade
-src/gpm-ac-adapter.c
-src/gpm-ac-adapter.h
-src/gpm-backlight.h
src/gpm-backlight.c
src/gpm-brightness-kbd.c
-src/gpm-brightness-kbd.h
src/gpm-brightness-hal.c
-src/gpm-brightness-hal.h
src/gpm-brightness-xrandr.c
-src/gpm-brightness-xrandr.h
src/gpm-button.c
-src/gpm-button.h
src/gpm-control.c
-src/gpm-control.h
src/gpm-common.c
-src/gpm-common.h
src/gpm-devicekit.c
-src/gpm-dpms.h
src/gpm-dpms.c
src/gpm-engine.c
src/gpm-feedback-widget.c
-src/gpm-feedback-widget.h
src/gpm-graph-widget.c
-src/gpm-graph-widget.h
src/gpm-idle.c
-src/gpm-idle.h
src/gpm-load.c
-src/gpm-load.h
-src/gpm-inhibit.c
-src/gpm-inhibit.h
src/gpm-main.c
src/gpm-manager.c
-src/gpm-manager.h
src/gpm-networkmanager.c
-src/gpm-networkmanager.h
src/gpm-notify.c
-src/gpm-notify.h
src/gpm-prefs.c
src/gpm-prefs-core.c
-src/gpm-prefs-core.h
-src/gpm-prefs.h
src/gpm-screensaver.c
-src/gpm-screensaver.h
src/gpm-statistics.c
-src/gpm-stock-icons.h
src/gpm-tray-icon.c
-src/gpm-tray-icon.h
-src/gpm-refcount.c
-src/gpm-refcount.h
applets/brightness/GNOME_BrightnessApplet.xml
applets/inhibit/GNOME_InhibitApplet.xml
test/gpm-inhibit-test.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 2d1370c..815cda3 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,7 +5,6 @@ NULL =
EXTRA_DIST = \
org.freedesktop.PowerManagement.xml \
- org.freedesktop.PowerManagement.Inhibit.xml \
org.freedesktop.PowerManagement.Backlight.xml \
gpm-marshal.list \
$(NULL)
@@ -193,8 +192,6 @@ gnome_power_manager_SOURCES = \
gpm-networkmanager.h \
gpm-networkmanager.c \
gpm-stock-icons.h \
- gpm-inhibit.h \
- gpm-inhibit.c \
gpm-feedback-widget.h \
gpm-feedback-widget.c \
$(NULL)
@@ -275,8 +272,6 @@ gnome_power_self_test_SOURCES = \
gpm-marshal.c \
gpm-common.h \
gpm-common.c \
- gpm-inhibit.h \
- gpm-inhibit.c \
gpm-devicekit.h \
gpm-devicekit.c \
$(NULL)
@@ -297,7 +292,6 @@ gnome_power_self_test_CFLAGS = -DEGG_TEST $(AM_CFLAGS) $(WARNINGFLAGS)
BUILT_SOURCES = \
org.freedesktop.PowerManagement.h \
- org.freedesktop.PowerManagement.Inhibit.h \
org.freedesktop.PowerManagement.Backlight.h \
gpm-marshal.c \
gpm-marshal.h \
@@ -317,13 +311,6 @@ org.freedesktop.PowerManagement.h: org.freedesktop.PowerManagement.xml
--output=org.freedesktop.PowerManagement.h \
$(srcdir)/org.freedesktop.PowerManagement.xml
-org.freedesktop.PowerManagement.Inhibit.h: org.freedesktop.PowerManagement.Inhibit.xml
- libtool --mode=execute dbus-binding-tool \
- --prefix=gpm_inhibit \
- --mode=glib-server \
- --output=org.freedesktop.PowerManagement.Inhibit.h \
- $(srcdir)/org.freedesktop.PowerManagement.Inhibit.xml
-
org.freedesktop.PowerManagement.Backlight.h: org.freedesktop.PowerManagement.Backlight.xml
libtool --mode=execute dbus-binding-tool \
--prefix=gpm_backlight \
diff --git a/src/gpm-inhibit.c b/src/gpm-inhibit.c
deleted file mode 100644
index acca213..0000000
--- a/src/gpm-inhibit.c
+++ /dev/null
@@ -1,745 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2006-2009 Richard Hughes <richard hughsie com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <glib/gi18n.h>
-#include <string.h>
-#include <gconf/gconf-client.h>
-
-#include "egg-debug.h"
-#include "gpm-common.h"
-#include "gpm-inhibit.h"
-
-static void gpm_inhibit_finalize (GObject *object);
-
-#define GPM_INHIBIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_INHIBIT, GpmInhibitPrivate))
-#define GPM_SESSION_MANAGER_SERVICE "org.gnome.SessionManager"
-#define GPM_SESSION_MANAGER_PATH "/org/gnome/SessionManager"
-#define GPM_SESSION_MANAGER_INTERFACE "org.gnome.SessionManager"
-
-typedef struct
-{
- gchar *application;
- gchar *reason;
- gchar *connection;
- guint32 cookie;
-} GpmInhibitData;
-
-struct GpmInhibitPrivate
-{
- GSList *list;
- DBusGProxy *proxy;
- DBusGProxy *proxy_session;
- GConfClient *conf;
- gboolean ignore_inhibits;
-};
-
-enum {
- HAS_INHIBIT_CHANGED,
- LAST_SIGNAL
-};
-
-static guint signals [LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (GpmInhibit, gpm_inhibit, G_TYPE_OBJECT)
-
-/**
- * gpm_inhibit_error_quark:
- * Return value: Our personal error quark.
- **/
-GQuark
-gpm_inhibit_error_quark (void)
-{
- static GQuark quark = 0;
- if (!quark)
- quark = g_quark_from_static_string ("gpm_inhibit_error");
- return quark;
-}
-
-/**
- * gpm_inhibit_cookie_compare_func
- * @a: Pointer to the data to test
- * @b: Pointer to a cookie to compare
- *
- * A GCompareFunc for comparing a cookie to a list.
- *
- * Return value: 0 if cookie matches
- **/
-static gint
-gpm_inhibit_cookie_compare_func (gconstpointer a, gconstpointer b)
-{
- GpmInhibitData *data;
- guint32 cookie;
- data = (GpmInhibitData*) a;
- cookie = *((guint32*) b);
- if (cookie == data->cookie)
- return 0;
- return 1;
-}
-
-/**
- * gpm_inhibit_find_cookie:
- * @inhibit: This inhibit instance
- * @cookie: The cookie we are looking for
- *
- * Finds the data in the cookie list.
- *
- * Return value: The cookie data, or NULL if not found
- **/
-static GpmInhibitData *
-gpm_inhibit_find_cookie (GpmInhibit *inhibit, guint32 cookie)
-{
- GpmInhibitData *data;
- GSList *ret;
- /* search list */
- ret = g_slist_find_custom (inhibit->priv->list, &cookie,
- gpm_inhibit_cookie_compare_func);
- if (ret == NULL)
- return NULL;
- data = (GpmInhibitData *) ret->data;
- return data;
-}
-
-/**
- * gpm_inhibit_inhibit:
- * @application: Application name, e.g. "Nautilus"
- * @reason: Reason for inhibiting, e.g. "Copying files"
- *
- * Allocates a random cookie used to identify the connection, as multiple
- * inhibit requests can come from one caller sharing a dbus connection.
- * We need to refcount internally, and data is saved in the GpmInhibitData
- * struct.
- *
- * Return value: a new random cookie.
- **/
-void
-gpm_inhibit_inhibit (GpmInhibit *inhibit, const gchar *application, const gchar *reason, DBusGMethodInvocation *context)
-{
- gboolean ret;
- GError *error = NULL;
- const gchar *connection;
- GpmInhibitData *data;
- guint inhibit_cookie = 0;
-
- /* as we are async, we can get the sender */
- connection = dbus_g_method_get_sender (context);
-
- /* handle where the application does not add required data */
- if (application == NULL || reason == NULL) {
- egg_warning ("Recieved Inhibit, but application "
- "did not set the parameters correctly");
- dbus_g_method_return (context, -1);
- return;
- }
-
- /* if there's no gnome-session, this will be NULL */
- if (inhibit->priv->proxy_session == NULL)
- goto skip;
-
- /* proxy to gnome-session */
- ret = dbus_g_proxy_call (inhibit->priv->proxy_session, "Inhibit", &error,
- G_TYPE_STRING, application, /* app_id */
- G_TYPE_UINT, 0, /* toplevel_xid */
- G_TYPE_STRING, reason, /* reason*/
- G_TYPE_UINT, 8, /* flags */
- G_TYPE_INVALID,
- G_TYPE_UINT, &inhibit_cookie,
- G_TYPE_INVALID);
- if (!ret) {
- egg_warning ("failed to proxy: %s", error->message);
- dbus_g_method_return_error (context, error);
- return;
- }
-
-skip:
- /* seems okay, add to list */
- data = g_new (GpmInhibitData, 1);
- data->cookie = inhibit_cookie;
- data->application = g_strdup (application);
- data->connection = g_strdup (connection);
- data->reason = g_strdup (reason);
-
- inhibit->priv->list = g_slist_append (inhibit->priv->list, (gpointer) data);
-
- egg_debug ("Recieved Inhibit from '%s' (%s) because '%s' saving as #%i",
- data->application, data->connection, data->reason, data->cookie);
-
- /* only emit event on the first one */
- if (g_slist_length (inhibit->priv->list) == 1)
- g_signal_emit (inhibit, signals [HAS_INHIBIT_CHANGED], 0, TRUE);
-
- dbus_g_method_return (context, data->cookie);
-}
-
-/* free one element in GpmInhibitData struct */
-static void
-gpm_inhibit_free_data_object (GpmInhibitData *data)
-{
- g_free (data->application);
- g_free (data->reason);
- g_free (data->connection);
- g_free (data);
-}
-
-/**
- * gpm_inhibit_un_inhibit:
- * @application: Application name
- * @cookie: The cookie that we used to register
- *
- * Removes a cookie and associated data from the GpmInhibitData struct.
- **/
-gboolean
-gpm_inhibit_un_inhibit (GpmInhibit *inhibit, guint32 cookie, GError **error)
-{
- gboolean ret;
- GpmInhibitData *data;
-
- /* Only remove the correct cookie */
- data = gpm_inhibit_find_cookie (inhibit, cookie);
- if (data == NULL) {
- *error = g_error_new (gpm_inhibit_error_quark (),
- GPM_INHIBIT_ERROR_GENERAL,
- "Cannot find registered program for #%i, so "
- "cannot do UnInhibit!", cookie);
- return FALSE;
- }
- egg_debug ("UnInhibit okay #%i", cookie);
-
- /* if there's no gnome-session, this will be NULL */
- if (inhibit->priv->proxy_session == NULL)
- goto skip;
-
- /* proxy to gnome-session */
- ret = dbus_g_proxy_call (inhibit->priv->proxy_session, "Uninhibit", error,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (!ret) {
- egg_warning ("failed to proxy: %s", (*error)->message);
- return FALSE;
- }
-
-skip:
- gpm_inhibit_free_data_object (data);
-
- /* remove it from the list */
- inhibit->priv->list = g_slist_remove (inhibit->priv->list, (gconstpointer) data);
-
- /* only emit event on the last one */
- if (g_slist_length (inhibit->priv->list) == 0)
- g_signal_emit (inhibit, signals [HAS_INHIBIT_CHANGED], 0, FALSE);
-
- return TRUE;
-}
-
-/**
- * gpm_inhibit_remove_dbus:
- * @connection: Connection name
- * @application: Application name
- * @cookie: The cookie that we used to register
- *
- * Checks to see if the dbus closed session is registered, in which case
- * unregister it.
- **/
-static void
-gpm_inhibit_remove_dbus (GpmInhibit *inhibit, const gchar *connection)
-{
- guint a;
- GpmInhibitData *data;
- gboolean ret;
- GError *error = NULL;
-
- /* Remove *any* connections that match the connection */
- for (a=0; a<g_slist_length (inhibit->priv->list); a++) {
- data = (GpmInhibitData *) g_slist_nth_data (inhibit->priv->list, a);
- if (strcmp (data->connection, connection) == 0) {
- egg_debug ("Auto-revoked idle inhibit on '%s'.", data->application);
-
- /* if there's no gnome-session, this will be NULL */
- if (inhibit->priv->proxy_session == NULL)
- goto skip;
-
- /* proxy to gnome-session */
- ret = dbus_g_proxy_call (inhibit->priv->proxy_session, "Uninhibit", &error,
- G_TYPE_UINT, data->cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (!ret) {
- egg_warning ("failed to proxy: %s", error->message);
- g_error_free (error);
- }
-skip:
- gpm_inhibit_free_data_object (data);
- /* remove it from the list */
- inhibit->priv->list = g_slist_remove (inhibit->priv->list, (gconstpointer) data);
- }
- }
-}
-
-/**
- * gpm_inhibit_name_owner_changed_cb:
- **/
-static void
-gpm_inhibit_name_owner_changed_cb (DBusGProxy *proxy, const gchar *name,
- const gchar *prev, const gchar *new,
- GpmInhibit *inhibit)
-{
- if (strlen (new) == 0)
- gpm_inhibit_remove_dbus (inhibit, name);
-}
-
-/**
- * gpm_inhibit_has_inhibit
- *
- * Checks to see if we are being stopped from performing an action.
- *
- * TRUE if the action is OK, i.e. we have *not* been inhibited.
- **/
-gboolean
-gpm_inhibit_has_inhibit (GpmInhibit *inhibit, gboolean *has_inihibit, GError **error)
-{
- guint length;
-
- length = g_slist_length (inhibit->priv->list);
-
- if (inhibit->priv->ignore_inhibits) {
- egg_debug ("Inhibit ignored through gconf policy!");
- *has_inihibit = FALSE;
- }
-
- /* An inhibit can stop the action */
- if (length == 0) {
- egg_debug ("Valid as no inhibitors");
- *has_inihibit = FALSE;
- } else {
- /* we have at least one application blocking the action */
- egg_debug ("We have %i valid inhibitors", length);
- *has_inihibit = TRUE;
- }
-
- /* we always return successful for DBUS */
- return TRUE;
-}
-
-/**
- * gpm_inhibit_get_message:
- *
- * @message: Description string, e.g. "Nautilus because 'copying files'"
- * @action: Action we wanted to do, e.g. "suspend"
- *
- * Returns a localised message text describing what application has inhibited
- * the action, and why.
- *
- **/
-void
-gpm_inhibit_get_message (GpmInhibit *inhibit, GString *message, const gchar *action)
-{
- guint a;
- GpmInhibitData *data;
- gchar *boldstr;
- gchar *italicstr;
-
- if (g_slist_length (inhibit->priv->list) == 1) {
- data = (GpmInhibitData *) g_slist_nth_data (inhibit->priv->list, 0);
- boldstr = g_strdup_printf ("<b>%s</b>", data->application);
- italicstr = g_strdup_printf ("<b>%s</b>", data->reason);
-
- if (strcmp (action, "suspend") == 0) {
- /*Translators: first %s is an application name, second %s is the reason*/
- g_string_append_printf (message, _("%s has stopped the suspend from taking place: %s."),
- boldstr, italicstr);
-
- } else if (strcmp (action, "hibernate") == 0) {
- /*Translators: first %s is an application name, second %s is the reason*/
- g_string_append_printf (message, _("%s has stopped the hibernate from taking place: %s."),
- boldstr, italicstr);
-
- } else if (strcmp (action, "policy action") == 0) {
- /*Translators: first %s is an application name, second %s is the reason*/
- g_string_append_printf (message, _("%s has stopped the policy action from taking place: %s."),
- boldstr, italicstr);
-
- } else if (strcmp (action, "reboot") == 0) {
- /*Translators: first %s is an application name, second %s is the reason*/
- g_string_append_printf (message, _("%s has stopped the reboot from taking place: %s."),
- boldstr, italicstr);
-
- } else if (strcmp (action, "shutdown") == 0) {
- /*Translators: first %s is an application name, second %s is the reason*/
- g_string_append_printf (message, _("%s has stopped the shutdown from taking place: %s."),
- boldstr, italicstr);
-
- } else if (strcmp (action, "timeout action") == 0) {
- /*Translators: first %s is an application name, second %s is the reason*/
- g_string_append_printf (message, _("%s has stopped the timeout action from taking place: %s."),
- boldstr, italicstr);
- }
-
- g_free (boldstr);
- g_free (italicstr);
-
- } else {
- if (strcmp (action, "suspend") == 0) {
- g_string_append (message, _("Multiple applications have stopped the suspend from taking place."));
-
- } else if (strcmp (action, "hibernate") == 0) {
- g_string_append (message, _("Multiple applications have stopped the hibernate from taking place."));
-
- } else if (strcmp (action, "policy action") == 0) {
- g_string_append (message, _("Multiple applications have stopped the policy action from taking place."));
-
- } else if (strcmp (action, "reboot") == 0) {
- g_string_append (message, _("Multiple applications have stopped the reboot from taking place."));
-
- } else if (strcmp (action, "shutdown") == 0) {
- g_string_append (message, _("Multiple applications have stopped the shutdown from taking place."));
-
- } else if (strcmp (action, "timeout action") == 0) {
- g_string_append (message, _("Multiple applications have stopped the suspend from taking place."));
- }
-
- for (a=0; a<g_slist_length (inhibit->priv->list); a++) {
- data = (GpmInhibitData *) g_slist_nth_data (inhibit->priv->list, a);
- g_string_append_printf (message,
- "\n<b>%s</b> : <i>%s</i>",
- data->application, data->reason);
- }
- }
-}
-
-/** intialise the class */
-static void
-gpm_inhibit_class_init (GpmInhibitClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = gpm_inhibit_finalize;
-
- signals [HAS_INHIBIT_CHANGED] =
- g_signal_new ("has-inhibit-changed",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmInhibitClass, has_inhibit_changed),
- NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- g_type_class_add_private (klass, sizeof (GpmInhibitPrivate));
-}
-
-/** intialise the object */
-static void
-gpm_inhibit_init (GpmInhibit *inhibit)
-{
- DBusGConnection *connection;
- GError *error = NULL;
-
- inhibit->priv = GPM_INHIBIT_GET_PRIVATE (inhibit);
- inhibit->priv->list = NULL;
- inhibit->priv->conf = gconf_client_get_default ();
-
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (error != NULL) {
- egg_warning ("Cannot connect to bus: %s", error->message);
- g_error_free (error);
- }
- inhibit->priv->proxy = dbus_g_proxy_new_for_name_owner (connection,
- DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS, &error);
- if (inhibit->priv->proxy == NULL) {
- egg_warning ("failed to get proxy: %s", error->message);
- g_error_free (error);
- return;
- }
- dbus_g_proxy_add_signal (inhibit->priv->proxy, "NameOwnerChanged",
- G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (inhibit->priv->proxy, "NameOwnerChanged",
- G_CALLBACK (gpm_inhibit_name_owner_changed_cb),
- inhibit, NULL);
-
- inhibit->priv->proxy_session = dbus_g_proxy_new_for_name_owner (connection,
- GPM_SESSION_MANAGER_SERVICE, GPM_SESSION_MANAGER_PATH,
- GPM_SESSION_MANAGER_INTERFACE, &error);
- if (inhibit->priv->proxy_session == NULL) {
- egg_warning ("failed to get proxy: %s", error->message);
- g_error_free (error);
- }
-
- /* Do we ignore inhibit requests? */
- inhibit->priv->ignore_inhibits = gconf_client_get_bool (inhibit->priv->conf, GPM_CONF_IGNORE_INHIBITS, NULL);
-}
-
-/** finalise the object */
-static void
-gpm_inhibit_finalize (GObject *object)
-{
- GpmInhibit *inhibit;
- guint a;
- GpmInhibitData *data;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (GPM_IS_INHIBIT (object));
-
- inhibit = GPM_INHIBIT (object);
- inhibit->priv = GPM_INHIBIT_GET_PRIVATE (inhibit);
-
- for (a=0; a<g_slist_length (inhibit->priv->list); a++) {
- data = (GpmInhibitData *) g_slist_nth_data (inhibit->priv->list, a);
- gpm_inhibit_free_data_object (data);
- }
- g_slist_free (inhibit->priv->list);
-
- g_object_unref (inhibit->priv->conf);
- g_object_unref (inhibit->priv->proxy);
- if (inhibit->priv->proxy_session != NULL)
- g_object_unref (inhibit->priv->proxy_session);
- G_OBJECT_CLASS (gpm_inhibit_parent_class)->finalize (object);
-}
-
-/** create the object */
-GpmInhibit *
-gpm_inhibit_new (void)
-{
- GpmInhibit *inhibit;
- inhibit = g_object_new (GPM_TYPE_INHIBIT, NULL);
- return GPM_INHIBIT (inhibit);
-}
-
-/***************************************************************************
- *** MAKE CHECK TESTS ***
- ***************************************************************************/
-#ifdef EGG_TEST
-#include "egg-test.h"
-#include "egg-dbus-proxy.h"
-#include "gpm-common.h"
-
-/** cookie is returned as an unsigned integer */
-static gboolean
-inhibit (EggDbusProxy *gproxy,
- const gchar *appname,
- const gchar *reason,
- guint *cookie)
-{
- GError *error = NULL;
- gboolean ret;
- DBusGProxy *proxy;
-
- g_return_val_if_fail (cookie != NULL, FALSE);
-
- proxy = egg_dbus_proxy_get_proxy (gproxy);
- if (proxy == NULL) {
- g_warning ("not connected");
- return FALSE;
- }
-
- ret = dbus_g_proxy_call (proxy, "Inhibit", &error,
- G_TYPE_STRING, appname,
- G_TYPE_STRING, reason,
- G_TYPE_INVALID,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID);
- if (error) {
- g_debug ("ERROR: %s", error->message);
- g_error_free (error);
- *cookie = 0;
- }
- if (!ret) {
- /* abort as the DBUS method failed */
- g_warning ("Inhibit failed!");
- }
-
- return ret;
-}
-
-static gboolean
-uninhibit (EggDbusProxy *gproxy,
- guint cookie)
-{
- GError *error = NULL;
- gboolean ret;
- DBusGProxy *proxy;
-
- proxy = egg_dbus_proxy_get_proxy (gproxy);
- if (proxy == NULL) {
- g_warning ("not connected");
- return FALSE;
- }
-
- ret = dbus_g_proxy_call (proxy, "UnInhibit", &error,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (error) {
- egg_debug ("ERROR: %s", error->message);
- g_error_free (error);
- }
- return ret;
-}
-
-static gboolean
-gpm_inhibit_test_has_inhibit (EggDbusProxy *gproxy, gboolean *has_inhibit)
-{
- GError *error = NULL;
- gboolean ret;
- DBusGProxy *proxy;
-
- proxy = egg_dbus_proxy_get_proxy (gproxy);
- if (proxy == NULL) {
- g_warning ("not connected");
- return FALSE;
- }
-
- ret = dbus_g_proxy_call (proxy, "HasInhibit", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, has_inhibit,
- G_TYPE_INVALID);
- if (error) {
- g_debug ("ERROR: %s", error->message);
- g_error_free (error);
- }
- if (!ret) {
- /* abort as the DBUS method failed */
- g_warning ("HasInhibit failed!");
- }
-
- return ret;
-}
-
-void
-gpm_inhibit_test (gpointer data)
-{
- gboolean ret;
- gboolean valid;
- guint cookie1 = 0;
- guint cookie2 = 0;
- DBusGConnection *connection;
- EggDbusProxy *gproxy;
- EggTest *test = (EggTest *) data;
-
- if (egg_test_start (test, "GpmInhibit") == FALSE) {
- return;
- }
-
- gproxy = egg_dbus_proxy_new ();
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
- egg_dbus_proxy_assign (gproxy, connection, GPM_DBUS_SERVICE,
- GPM_DBUS_PATH_INHIBIT, GPM_DBUS_INTERFACE_INHIBIT);
-
- if (gproxy == NULL) {
- g_warning ("Unable to get connection to power manager");
- return;
- }
-
- /************************************************************/
- egg_test_title (test, "make sure we are not inhibited");
- ret = gpm_inhibit_test_has_inhibit (gproxy, &valid);
- if (!ret) {
- egg_test_failed (test, "Unable to test validity");
- } else if (valid) {
- egg_test_failed (test, "Already inhibited");
- } else {
- egg_test_success (test, NULL);
- }
-
- /************************************************************/
- egg_test_title (test, "clear an invalid cookie");
- ret = uninhibit (gproxy, 123456);
- if (!ret) {
- egg_test_success (test, "invalid cookie failed as expected");
- } else {
- egg_test_failed (test, "should have rejected invalid cookie");
- }
-
- /************************************************************/
- egg_test_title (test, "get auto cookie 1");
- ret = inhibit (gproxy,
- "gnome-power-self-test",
- "test inhibit",
- &cookie1);
- if (!ret) {
- egg_test_failed (test, "Unable to inhibit");
- } else if (cookie1 == 0) {
- egg_test_failed (test, "Cookie invalid (cookie: %u)", cookie1);
- } else {
- egg_test_success (test, "cookie: %u", cookie1);
- }
-
- /************************************************************/
- egg_test_title (test, "make sure we are auto inhibited");
- ret = gpm_inhibit_test_has_inhibit (gproxy, &valid);
- if (!ret) {
- egg_test_failed (test, "Unable to test validity");
- } else if (valid) {
- egg_test_success (test, "inhibited");
- } else {
- egg_test_failed (test, "inhibit failed");
- }
-
- /************************************************************/
- egg_test_title (test, "get cookie 2");
- ret = inhibit (gproxy,
- "gnome-power-self-test",
- "test inhibit",
- &cookie2);
- if (!ret) {
- egg_test_failed (test, "Unable to inhibit");
- } else if (cookie2 == 0) {
- egg_test_failed (test, "Cookie invalid (cookie: %u)", cookie2);
- } else {
- egg_test_success (test, "cookie: %u", cookie2);
- }
-
- /************************************************************/
- egg_test_title (test, "clear cookie 1");
- ret = uninhibit (gproxy, cookie1);
- if (!ret) {
- egg_test_failed (test, "cookie failed to clear");
- } else {
- egg_test_success (test, NULL);
- }
-
- /************************************************************/
- egg_test_title (test, "make sure we are still inhibited");
- ret = gpm_inhibit_test_has_inhibit (gproxy, &valid);
- if (!ret) {
- egg_test_failed (test, "Unable to test validity");
- } else if (valid) {
- egg_test_success (test, "inhibited");
- } else {
- egg_test_failed (test, "inhibit failed");
- }
-
- /************************************************************/
- egg_test_title (test, "clear cookie 2");
- ret = uninhibit (gproxy, cookie2);
- if (!ret) {
- egg_test_failed (test, "cookie failed to clear");
- } else {
- egg_test_success (test, NULL);
- }
-
- g_object_unref (gproxy);
-
- egg_test_end (test);
-}
-
-#endif
-
diff --git a/src/gpm-inhibit.h b/src/gpm-inhibit.h
deleted file mode 100644
index 61ab609..0000000
--- a/src/gpm-inhibit.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2005-2007 Richard Hughes <richard hughsie com>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __GPMINHIBIT_H
-#define __GPMINHIBIT_H
-
-#include <glib-object.h>
-#include <dbus/dbus-glib.h>
-
-G_BEGIN_DECLS
-
-#define GPM_TYPE_INHIBIT (gpm_inhibit_get_type ())
-#define GPM_INHIBIT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_TYPE_INHIBIT, GpmInhibit))
-#define GPM_INHIBIT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GPM_TYPE_INHIBIT, GpmInhibitClass))
-#define GPM_IS_INHIBIT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_TYPE_INHIBIT))
-#define GPM_IS_INHIBIT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GPM_TYPE_INHIBIT))
-#define GPM_INHIBIT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GPM_TYPE_INHIBIT, GpmInhibitClass))
-
-typedef struct GpmInhibitPrivate GpmInhibitPrivate;
-
-typedef struct
-{
- GObject parent;
- GpmInhibitPrivate *priv;
-} GpmInhibit;
-
-typedef struct
-{
- GObjectClass parent_class;
- void (* has_inhibit_changed) (GpmInhibit *inhibit,
- gboolean has_inhibit);
-} GpmInhibitClass;
-
-typedef enum
-{
- GPM_INHIBIT_ERROR_GENERAL
-} GpmInhibitError;
-
-GpmInhibit *gpm_inhibit_new (void);
-GType gpm_inhibit_get_type (void);
-GQuark gpm_inhibit_error_quark (void);
-gboolean gpm_inhibit_has_inhibit (GpmInhibit *inhibit,
- gboolean *valid,
- GError **error);
-void gpm_inhibit_get_message (GpmInhibit *inhibit,
- GString *message,
- const gchar *action);
-
-void gpm_inhibit_inhibit (GpmInhibit *inhibit,
- const gchar *application,
- const gchar *reason,
- DBusGMethodInvocation *context);
-gboolean gpm_inhibit_un_inhibit (GpmInhibit *inhibit,
- guint32 cookie,
- GError **error);
-#ifdef EGG_TEST
-void gpm_inhibit_test (gpointer data);
-#endif
-
-G_END_DECLS
-
-#endif /* __GPMINHIBIT_H */
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index fad0ad5..edcb747 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -50,7 +50,6 @@
#include "gpm-common.h"
#include "gpm-dpms.h"
#include "gpm-idle.h"
-#include "gpm-inhibit.h"
#include "gpm-manager.h"
#include "gpm-notify.h"
#include "gpm-prefs.h"
@@ -66,7 +65,6 @@
#include "gpm-devicekit.h"
#include "gpm-feedback-widget.h"
-#include "org.freedesktop.PowerManagement.Inhibit.h"
#include "org.freedesktop.PowerManagement.Backlight.h"
static void gpm_manager_finalize (GObject *object);
@@ -81,7 +79,6 @@ struct GpmManagerPrivate
GpmDpms *dpms;
GpmIdle *idle;
GpmPrefsServer *prefs_server;
- GpmInhibit *inhibit;
GpmNotify *notify;
GpmControl *control;
GpmScreensaver *screensaver;
@@ -225,47 +222,13 @@ gpm_manager_play (GpmManager *manager, GpmManagerSound action, gboolean force)
* @action: The action we want to do, e.g. "suspend"
*
* Checks to see if the specific action has been inhibited by a program.
- * If so, displays a warning libnotify dialogue for the user explaining
- * the situation.
*
* Return value: TRUE if we can perform the action.
**/
static gboolean
gpm_manager_is_inhibit_valid (GpmManager *manager, gboolean user_action, const char *action)
{
- gboolean has_inhibit;
- gchar *title = NULL;
-
- /* We have to decide on whether this is a idle action or a user keypress */
- gpm_inhibit_has_inhibit (manager->priv->inhibit, &has_inhibit, NULL);
-
- if (has_inhibit) {
- GString *message = g_string_new ("");
- const char *msg;
-
- /*Compose message for each possible action*/
- if (strcmp (action, "suspend") == 0)
- title = g_strdup (_("Request to suspend"));
- else if (strcmp (action, "hibernate") == 0)
- title = g_strdup (_("Request to hibernate"));
- else if (strcmp (action, "policy action") == 0)
- title = g_strdup (_("Request to do policy action"));
- else if (strcmp (action, "timeout action") == 0)
- title = g_strdup (_("Request to do timeout action"));
-
- gpm_inhibit_get_message (manager->priv->inhibit, message, action);
- gpm_notify_display (manager->priv->notify,
- title,
- message->str,
- GPM_NOTIFY_TIMEOUT_LONG,
- GTK_STOCK_DIALOG_WARNING,
- GPM_NOTIFY_URGENCY_NORMAL);
- /* I want this translated */
- msg = _("Perform action anyway");
- g_string_free (message, TRUE);
- g_free (title);
- }
- return !has_inhibit;
+ return TRUE;
}
/**
@@ -680,10 +643,6 @@ idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmManager *manager)
static void
lid_button_pressed (GpmManager *manager, gboolean pressed)
{
- gboolean has_inhibit;
- gboolean do_policy;
- gchar *action;
-
if (pressed)
gpm_manager_play (manager, GPM_MANAGER_SOUND_LID_CLOSE, FALSE);
else
@@ -702,29 +661,6 @@ lid_button_pressed (GpmManager *manager, gboolean pressed)
return;
}
- /* default */
- do_policy = TRUE;
-
- /* are we inhibited? */
- gpm_inhibit_has_inhibit (manager->priv->inhibit, &has_inhibit, NULL);
-
- /* do not do lid close action if suspend (or hibernate) */
- if (has_inhibit) {
- /* get the policy action for battery */
- action = gconf_client_get_string (manager->priv->conf, GPM_CONF_BUTTON_LID_BATT, NULL);
-
- /* if we are trying to suspend or hibernate then don't do action */
- if ((strcmp (action, ACTION_SUSPEND) == 0) ||
- (strcmp (action, ACTION_HIBERNATE) == 0))
- do_policy = FALSE;
- g_free (action);
- }
-
- if (do_policy == FALSE) {
- egg_debug ("Not doing lid policy action as inhibited as set to sleep");
- return;
- }
-
egg_debug ("Performing battery policy");
manager_policy_do (manager, GPM_CONF_BUTTON_LID_BATT,
_("The lid has been closed on battery power."));
@@ -1433,46 +1369,6 @@ out:
}
/**
- * has_inhibit_changed_cb:
- **/
-static void
-has_inhibit_changed_cb (GpmInhibit *inhibit, gboolean has_inhibit, GpmManager *manager)
-{
- gboolean is_laptop = FALSE;
- gboolean show_inhibit_lid;
- gchar *action = NULL;
-
- /* we don't care about uninhibits */
- if (has_inhibit == FALSE)
- return;
-
- /* only show this if specified in gconf */
- show_inhibit_lid = gconf_client_get_bool (manager->priv->conf, GPM_CONF_NOTIFY_INHIBIT_LID, NULL);
-
- /* we've already shown the UI and been clicked */
- if (show_inhibit_lid == FALSE)
- return;
-
-/* FIXME: detect if laptop */
-
- /* we don't warn for desktops, as they do not have a lid... */
- if (is_laptop == FALSE)
- return;
-
- /* get the policy action for battery */
- action = gconf_client_get_string (manager->priv->conf, GPM_CONF_BUTTON_LID_BATT, NULL);
- if (action == NULL)
- return;
-
- /* if the policy on lid close is sleep then show a warning */
- if ((strcmp (action, ACTION_SUSPEND) == 0) ||
- (strcmp (action, ACTION_HIBERNATE) == 0))
- gpm_notify_inhibit_lid (manager->priv->notify);
-
- g_free (action);
-}
-
-/**
* brightness_kbd_changed_cb:
* @brightness: The GpmBrightnessKbd class instance
* @percentage: The new percentage brightness
@@ -1639,16 +1535,6 @@ gpm_manager_init (GpmManager *manager)
g_signal_connect (manager->priv->dpms, "mode-changed",
G_CALLBACK (dpms_mode_changed_cb), manager);
- /* use a class to handle the complex stuff */
- egg_debug ("creating new inhibit instance");
- manager->priv->inhibit = gpm_inhibit_new ();
- g_signal_connect (manager->priv->inhibit, "has-inhibit-changed",
- G_CALLBACK (has_inhibit_changed_cb), manager);
- /* add the interface */
- dbus_g_object_type_install_info (GPM_TYPE_INHIBIT, &dbus_glib_gpm_inhibit_object_info);
- dbus_g_connection_register_g_object (connection, GPM_DBUS_PATH_INHIBIT,
- G_OBJECT (manager->priv->inhibit));
-
/* use the control object */
egg_debug ("creating new control instance");
manager->priv->control = gpm_control_new ();
@@ -1713,7 +1599,6 @@ gpm_manager_finalize (GObject *object)
g_object_unref (manager->priv->idle);
g_object_unref (manager->priv->engine);
g_object_unref (manager->priv->tray_icon);
- g_object_unref (manager->priv->inhibit);
g_object_unref (manager->priv->screensaver);
g_object_unref (manager->priv->notify);
g_object_unref (manager->priv->prefs_server);
diff --git a/src/gpm-self-test.c b/src/gpm-self-test.c
index 4b4ef06..2610ce7 100644
--- a/src/gpm-self-test.c
+++ b/src/gpm-self-test.c
@@ -35,10 +35,6 @@ void egg_array_float_test (EggTest *test);
void egg_idletime_test (EggTest *test);
void gpm_common_test (EggTest *test);
-void gpm_cell_unit_test (EggTest *test);
-void gpm_cell_test (EggTest *test);
-void gpm_cell_test_array (EggTest *test);
-void gpm_inhibit_test (EggTest *test);
void gpm_phone_test (EggTest *test);
void gpm_dpms_test (EggTest *test);
void gpm_graph_widget_test (EggTest *test);
@@ -67,7 +63,6 @@ main (int argc, char **argv)
// egg_idletime_test (test);
gpm_common_test (test);
- gpm_inhibit_test (test);
gpm_phone_test (test);
// gpm_dpms_test (test);
// gpm_graph_widget_test (test);
diff --git a/src/org.freedesktop.PowerManagement.Inhibit.xml b/src/org.freedesktop.PowerManagement.Inhibit.xml
deleted file mode 100644
index f78552c..0000000
--- a/src/org.freedesktop.PowerManagement.Inhibit.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<node name="/">
- <interface name="org.freedesktop.PowerManagement.Inhibit">
- <method name="Inhibit">
- <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
- <arg type="s" name="application" direction="in"/>
- <arg type="s" name="reason" direction="in"/>
- <arg type="u" name="cookie" direction="out"/>
- </method>
- <method name="UnInhibit">
- <arg type="u" name="cookie" direction="in"/>
- </method>
- <method name="HasInhibit">
- <arg type="b" name="has_inhibit" direction="out"/>
- </method>
- <signal name="HasInhibitChanged"/>
- </interface>
-</node>
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]