[Xfce4-commits] <xfce4-power-manager:nick/upower-session> Work on more stuff.
Nick Schermer
noreply at xfce.org
Wed Mar 7 22:06:01 CET 2012
Updating branch refs/heads/nick/upower-session
to 0533c5e4c61313e6550b75c2e14271432b394704 (commit)
from 761ce4d2e78facafbf907759869eb9421a213154 (commit)
commit 0533c5e4c61313e6550b75c2e14271432b394704
Author: Nick Schermer <nick at xfce.org>
Date: Wed Mar 7 22:05:04 2012 +0100
Work on more stuff.
configure.ac.in | 2 +-
settings/Makefile.am | 4 +-
settings/xfpm-settings-main.c | 6 +-
src/Makefile.am | 132 ++--
src/org.xfce.Power.Manager.xml | 27 -
src/xfpm-backlight.c | 4 +-
src/xfpm-battery.c | 24 +-
src/xfpm-dbus-service.c | 232 -----
src/xfpm-dbus-service.h | 43 -
src/xfpm-disks.c | 4 +-
src/xfpm-dpms.c | 8 +-
src/xfpm-inhibit-service-infos.xml | 31 +
src/xfpm-inhibit.c | 8 +-
src/xfpm-inhibit.h | 2 +
src/xfpm-main.c | 8 +-
src/xfpm-manager-service-infos.xml | 57 ++
src/xfpm-manager.c | 216 +++++-
src/xfpm-manager.h | 6 +-
...vice-infos.xml => xfpm-power-service-infos.xml} | 29 +-
src/xfpm-power.c | 896 ++++++++------------
src/xfpm-power.h | 18 +-
21 files changed, 767 insertions(+), 990 deletions(-)
diff --git a/configure.ac.in b/configure.ac.in
index 52313f1..dc86e7a 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -66,7 +66,7 @@ m4_define([libxfce4panel_minimum_version],[4.6.0])
m4_define([libnotify_minimum_version], [0.4.1])
m4_define([xrandr_minimum_version], [1.2.0])
m4_define([x11_minimum_version], [1.0.0])
-m4_define([upower_minimum_version], [0.9.0])
+m4_define([upower_minimum_version], [0.9.2])
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [gtk_minimum_version])
XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [glib_minimum_version])
diff --git a/settings/Makefile.am b/settings/Makefile.am
index 7d80680..c99e2db 100644
--- a/settings/Makefile.am
+++ b/settings/Makefile.am
@@ -52,8 +52,8 @@ if MAINTAINER_MODE
BUILT_SOURCES = \
xfce-power-manager-dbus-client.h
-xfce-power-manager-dbus-client.h: $(top_srcdir)/src/org.xfce.Power.Manager.xml
- dbus-binding-tool --mode=glib-client --prefix=xfpm_manager $< >$@
+xfce-power-manager-dbus-client.h: $(top_srcdir)/src/xfpm-manager-service-infos.xml
+ dbus-binding-tool --mode=glib-client --prefix=xfpm_dbus_client $< >$@
endif
diff --git a/settings/xfpm-settings-main.c b/settings/xfpm-settings-main.c
index 0986c0b..af94f6d 100644
--- a/settings/xfpm-settings-main.c
+++ b/settings/xfpm-settings-main.c
@@ -104,7 +104,7 @@ int main (int argc, char **argv)
g_error ("%s\n",error->message);
}
- if ( xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus), "org.xfce.PowerManager") )
+ if ( xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus), "org.xfce.PowerManagement") )
{
GtkWidget *dialog;
XfpmUnique *unique;
@@ -138,9 +138,7 @@ int main (int argc, char **argv)
"/org/xfce/PowerManager",
"org.xfce.Power.Manager");
- xfpm_manager_dbus_client_get_config (proxy,
- &config_hash,
- &error);
+ xfpm_dbus_client_get_config (proxy, &config_hash, &error);
if ( error )
{
diff --git a/src/Makefile.am b/src/Makefile.am
index e4e2cea..60de01d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,12 +1,10 @@
bin_PROGRAMS = xfce4-power-manager \
xfce4-power-information
-xfce4_power_manager_SOURCES = \
+xfce4_power_manager_SOURCES = \
$(BUILT_SOURCES) \
xfpm-enum.h \
xfpm-enum-glib.h \
- xfpm-dbus-service.c \
- xfpm-dbus-service.h \
xfpm-main.c \
xfpm-manager.c \
xfpm-manager.h \
@@ -16,6 +14,8 @@ xfce4_power_manager_SOURCES = \
xfpm-power-common.h \
xfpm-battery.c \
xfpm-battery.h \
+ xfpm-inhibit.c \
+ xfpm-inhibit.h \
xfpm-xfconf.c \
xfpm-xfconf.h \
xfpm-disks.c \
@@ -41,21 +41,21 @@ xfce4_power_manager_SOURCES = \
gsd-media-keys-window.c \
gsd-media-keys-window.h
-xfce4_power_manager_CFLAGS = \
- -I$(top_srcdir) \
- -I$(top_srcdir)/common \
- -I$(top_srcdir)/libdbus \
- -DLOCALEDIR=\"$(localedir)\" \
- -DG_LOG_DOMAIN=\"xfce4-power-manager\" \
+xfce4_power_manager_CFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/common \
+ -I$(top_srcdir)/libdbus \
+ -DLOCALEDIR=\"$(localedir)\" \
+ -DG_LOG_DOMAIN=\"xfce4-power-manager\" \
-DSYSCONFDIR=\"$(sysconfdir)\" \
- $(GOBJECT_CFLAGS) \
- $(GTHREAD_CFLAGS) \
- $(DBUS_GLIB_CFLAGS) \
- $(LIBXFCE4UI_CFLAGS) \
- $(XFCONF_CFLAGS) \
- $(LIBNOTIFY_CFLAGS) \
+ $(GOBJECT_CFLAGS) \
+ $(GTHREAD_CFLAGS) \
+ $(DBUS_GLIB_CFLAGS) \
+ $(LIBXFCE4UI_CFLAGS) \
+ $(XFCONF_CFLAGS) \
+ $(LIBNOTIFY_CFLAGS) \
$(XRANDR_CFLAGS) \
- $(DPMS_CFLAGS) \
+ $(DPMS_CFLAGS) \
$(UPOWER_GLIB_CFLAGS) \
$(PLATFORM_CPPFLAGS) \
$(PLATFORM_CFLAGS)
@@ -64,15 +64,15 @@ xfce4_power_manager_LDFLAGS = \
-no-undefined \
$(PLATFORM_LDFLAGS)
-xfce4_power_manager_LDADD = \
- $(top_builddir)/common/libxfpmcommon.la \
- $(top_builddir)/libdbus/libxfpmdbus.la \
- $(GOBJECT_LIBS) \
- $(GTHREAD_LIBS) \
- $(DBUS_GLIB_LIBS) \
- $(LIBXFCE4UI_LIBS) \
- $(XFCONF_LIBS) \
- $(LIBNOTIFY_LIBS) \
+xfce4_power_manager_LDADD = \
+ $(top_builddir)/common/libxfpmcommon.la \
+ $(top_builddir)/libdbus/libxfpmdbus.la \
+ $(GOBJECT_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(DBUS_GLIB_LIBS) \
+ $(LIBXFCE4UI_LIBS) \
+ $(XFCONF_LIBS) \
+ $(LIBNOTIFY_LIBS) \
$(XRANDR_LIBS) \
$(UPOWER_GLIB_LIBS) \
$(DPMS_LIBS)
@@ -83,13 +83,13 @@ xfce4_power_information_SOURCES = \
xfpm-power-common.h
xfce4_power_information_CFLAGS = \
- -I$(top_srcdir) \
- -I$(top_srcdir)/common \
- -I$(top_srcdir)/libdbus \
- -DLOCALEDIR=\"$(localedir)\" \
- -DG_LOG_DOMAIN=\"xfce4-power-information\"\
- $(GOBJECT_CFLAGS) \
- $(DBUS_GLIB_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/common \
+ -I$(top_srcdir)/libdbus \
+ -DLOCALEDIR=\"$(localedir)\" \
+ -DG_LOG_DOMAIN=\"xfce4-power-information\" \
+ $(GOBJECT_CFLAGS) \
+ $(DBUS_GLIB_CFLAGS) \
$(LIBXFCE4UI_CFLAGS) \
$(UPOWER_GLIB_CFLAGS) \
$(PLATFORM_CPPFLAGS) \
@@ -100,8 +100,8 @@ xfce4_power_information_LDFLAGS = \
$(PLATFORM_LDFLAGS)
xfce4_power_information_LDADD = \
- $(GOBJECT_LIBS) \
- $(DBUS_GLIB_LIBS) \
+ $(GOBJECT_LIBS) \
+ $(DBUS_GLIB_LIBS) \
$(LIBXFCE4UI_LIBS) \
$(UPOWER_GLIB_LIBS) \
$(top_builddir)/libdbus/libxfpmdbus.la
@@ -110,20 +110,20 @@ if ENABLE_POLKIT
sbin_PROGRAMS = xfpm-power-backlight-helper
-xfpm_power_backlight_helper_SOURCES = \
+xfpm_power_backlight_helper_SOURCES = \
xfpm-backlight-helper.c
-xfpm_power_backlight_helper_LDADD = \
- $(GLIB_LIBS) \
+xfpm_power_backlight_helper_LDADD = \
+ $(GLIB_LIBS) \
-lm
-xfpm_power_backlight_helper_CFLAGS = \
- $(GLIB_CFLAGS) \
+xfpm_power_backlight_helper_CFLAGS = \
+ $(GLIB_CFLAGS) \
$(PLATFORM_CPPFLAGS) \
$(PLATFORM_CFLAGS)
polkit_policydir = $(datadir)/polkit-1/actions
-polkit_policy_DATA = \
+polkit_policy_DATA = \
org.xfce.power.policy
# You will need a recent intltool or the patch from this bug
@@ -139,20 +139,22 @@ manpagedir = $(mandir)/man1
manpage_DATA = xfce4-power-manager.1
-xfpm_glib_headers = \
- $(srcdir)/xfpm-enum-glib.h
+xfpm_glib_headers = \
+ $(srcdir)/xfpm-enum-glib.h
BUILT_SOURCES = \
- xfpm-dbus-service-infos.h \
- xfpm-enum-types.c \
+ xfpm-power-service-infos.h \
+ xfpm-manager-service-infos.h \
+ xfpm-inhibit-service-infos.h \
+ xfpm-enum-types.c \
xfpm-enum-types.h \
- xfpm-marshal.c \
- xfpm-marshal.h
+ xfpm-marshal.c \
+ xfpm-marshal.h
if MAINTAINER_MODE
xfpm-enum-types.h: $(xfpm_glib_headers)
- ( cd $(srcdir) && glib-mkenums \
+ $(AM_V_GEN) ( cd $(srcdir) && glib-mkenums \
--fhead "#ifndef _XFPM_ENUM_TYPES_H\n#define _XFPM_ENUM_TYPES_H\n#include <glib-object.h>\nG_BEGIN_DECLS\n" \
--fprod "/* enumerations from \"@filename@\" */\n" \
--vhead "GType @enum_name at _get_type (void);\n#define XFPM_TYPE_ at ENUMSHORT@ (@enum_name at _get_type())\n" \
@@ -162,7 +164,7 @@ xfpm-enum-types.h: $(xfpm_glib_headers)
&& rm -f xgen xgen~
xfpm-enum-types.c: xfpm-enum-types.h
- ( cd $(srcdir) && glib-mkenums \
+ $(AM_V_GEN) ( cd $(srcdir) && glib-mkenums \
--fhead "#include <xfpm-enum-types.h>\n" \
--fhead "#include \"xfpm-enum-glib.h\"\n\n" \
--fprod "\n/* enumerations from \"@filename@\" */\n" \
@@ -174,14 +176,20 @@ xfpm-enum-types.c: xfpm-enum-types.h
&& rm -f xgen xgen~
xfpm-marshal.c: xfpm-marshal.list
- echo "#include \"xfpm-marshal.h\"" > $@ && \
+ $(AM_V_GEN) echo "#include \"xfpm-marshal.h\"" > $@ && \
glib-genmarshal $< --prefix=_xfpm_marshal --body >> $@
xfpm-marshal.h: xfpm-marshal.list
- glib-genmarshal $< --prefix=_xfpm_marshal --header > $@
+ $(AM_V_GEN) glib-genmarshal $< --prefix=_xfpm_marshal --header > $@
+
+xfpm-power-service-infos.h: $(srcdir)/xfpm-power-service-infos.xml Makefile
+ $(AM_V_GEN) dbus-binding-tool --prefix=xfpm_power_dbus --mode=glib-server $< >$@
-xfpm-dbus-service-infos.h: $(srcdir)/xfpm-dbus-service-infos.xml Makefile
- $(AM_V_GEN) dbus-binding-tool --prefix=xfpm_dbus_service --mode=glib-server $< >$@
+xfpm-manager-service-infos.h: $(srcdir)/xfpm-manager-service-infos.xml Makefile
+ $(AM_V_GEN) dbus-binding-tool --prefix=xfpm_manager_dbus --mode=glib-server $< >$@
+
+xfpm-inhibit-service-infos.h: $(srcdir)/xfpm-inhibit-service-infos.xml Makefile
+ $(AM_V_GEN) dbus-binding-tool --prefix=xfpm_inhibit --mode=glib-server $< >$@
endif
@@ -190,14 +198,14 @@ autostartdir = $(sysconfdir)/xdg/autostart
autostart_in_files = xfce4-power-manager.desktop.in
autostart_DATA = $(autostart_in_files:.desktop.in=.desktop)
-EXTRA_DIST = \
+EXTRA_DIST = \
xfpm-marshal.list \
- $(autostart_in_files) \
- org.xfce.power.policy.in2 \
- $(manpage_DATA)
-
-DISTCLEANFILES = \
- $(BUILT_SOURCES) \
- xfce4-power-manager.desktop \
- org.xfce.power.policy \
- org.xfce.power.policy.in
+ $(autostart_in_files) \
+ org.xfce.power.policy.in2 \
+ $(manpage_DATA)
+
+DISTCLEANFILES = \
+ $(BUILT_SOURCES) \
+ xfce4-power-manager.desktop \
+ org.xfce.power.policy \
+ org.xfce.power.policy.in
diff --git a/src/org.xfce.Power.Manager.xml b/src/org.xfce.Power.Manager.xml
deleted file mode 100644
index 485fdde..0000000
--- a/src/org.xfce.Power.Manager.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<node name="/org/xfce/PowerManager">
- <interface name="org.xfce.Power.Manager">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol"
- value="xfpm_manager_dbus"/>
- <annotation name="org.freedesktop.DBus.GLib.ClientCSymbol"
- value="xfpm_manager_dbus_client"/>
-
- <method name="Quit">
- </method>
-
- <method name="Restart">
- </method>
-
- <method name="GetConfig">
- <arg direction="out" name="config" type="a{ss}"/>
- </method>
-
- <method name="GetInfo">
- <arg direction="out" name="name" type="s"/>
- <arg direction="out" name="version" type="s"/>
- <arg direction="out" name="vendor" type="s"/>
- </method>
-
- </interface>
-</node>
diff --git a/src/xfpm-backlight.c b/src/xfpm-backlight.c
index 73bd5f6..ca9c261 100644
--- a/src/xfpm-backlight.c
+++ b/src/xfpm-backlight.c
@@ -426,9 +426,7 @@ xfpm_backlight_init (XfpmBacklight *backlight)
g_signal_connect (backlight->priv->power, "on-battery-changed",
G_CALLBACK (xfpm_backlight_on_battery_changed_cb), backlight);
- g_object_get (G_OBJECT (backlight->priv->power),
- "on-battery", &backlight->priv->on_battery,
- NULL);
+ backlight->priv->on_battery = xfpm_power_get_on_battery (backlight->priv->power);
xfpm_brightness_get_level (backlight->priv->brightness, &backlight->priv->last_level);
xfpm_backlight_set_timeouts (backlight);
}
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 026fb55..0c8e1ab 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -111,26 +111,26 @@ xfpm_battery_get_icon_index (UpDeviceKind kind, gdouble percentage)
{
if (KIND_IS_BATTERY_OR_UPS (kind))
{
- if (percentage < 20)
+ if (percentage < 10)
return "000";
- else if (percentage < 40)
+ else if (percentage < 30)
return "020";
- else if (percentage < 60)
+ else if (percentage < 50)
return "040";
- else if (percentage < 80)
+ else if (percentage < 70)
return "060";
- else if (percentage < 100)
+ else if (percentage < 90)
return "080";
else
return "100";
}
else
{
- if (percentage < 30)
+ if (percentage < 10)
return "000";
- else if (percentage < 60)
+ else if (percentage < 30)
return "030";
- else if (percentage < 100)
+ else if (percentage < 60)
return "060";
else
return "100";
@@ -659,9 +659,7 @@ static void xfpm_battery_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- XfpmBattery *battery;
-
- battery = XFPM_BATTERY (object);
+ XfpmBattery *battery = XFPM_BATTERY (object);
switch (prop_id)
{
@@ -682,9 +680,7 @@ static void xfpm_battery_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- XfpmBattery *battery;
-
- battery = XFPM_BATTERY (object);
+ XfpmBattery *battery = XFPM_BATTERY (object);
switch (prop_id)
{
diff --git a/src/xfpm-dbus-service.c b/src/xfpm-dbus-service.c
deleted file mode 100644
index 810015b..0000000
--- a/src/xfpm-dbus-service.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
- * Copyright (C) 2011 Nick Schermer <nick at xfce.org>
- *
- * 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
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#ifdef HAVE_MEMORY_H
-#include <memory.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#include <dbus/dbus-glib-lowlevel.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus.h>
-#include <gtk/gtk.h>
-
-#include <libxfce4util/libxfce4util.h>
-
-#include "xfpm-dbus-service.h"
-#include "xfpm-dbus.h"
-#include "xfpm-power.h"
-
-
-
-static void xfpm_dbus_service_finalize (GObject *object);
-static gboolean xfpm_dbus_service_suspend (XfpmDBusService *dbus_service,
- GError **error);
-static gboolean xfpm_dbus_service_hibernate (XfpmDBusService *dbus_service,
- GError **error);
-static gboolean xfpm_dbus_service_can_suspend (XfpmDBusService *dbus_service,
- gboolean *OUT_can_suspend,
- GError **error);
-static gboolean xfpm_dbus_service_can_hibernate (XfpmDBusService *dbus_service,
- gboolean *OUT_can_hibernate,
- GError **error);
-static gboolean xfpm_dbus_service_get_on_battery (XfpmDBusService *dbus_service,
- gboolean *OUT_on_battery,
- GError **error);
-static gboolean xfpm_dbus_service_get_low_battery (XfpmDBusService *dbus_service,
- gboolean *OUT_low_battery,
- GError **error);
-static gboolean xfpm_dbus_service_terminate (XfpmDBusService *dbus_service,
- gboolean restart,
- GError **error);
-
-
-
-/* include generate dbus infos */
-#include "xfpm-dbus-service-infos.h"
-
-
-
-struct _XfpmDBusServiceClass
-{
- GObjectClass __parent__;
-};
-
-struct _XfpmDBusService
-{
- GObject __parent__;
-
- DBusGConnection *connection;
-
- XfpmPower *power;
-};
-
-
-
-G_DEFINE_TYPE (XfpmDBusService, xfpm_dbus_service, G_TYPE_OBJECT)
-
-
-
-static void
-xfpm_dbus_service_class_init (XfpmDBusServiceClass *klass)
-{
- GObjectClass *gobject_class;
-
- gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->finalize = xfpm_dbus_service_finalize;
-
- /* install the D-BUS info for our class */
- dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
- &dbus_glib_xfpm_dbus_service_object_info);
-}
-
-
-
-static void
-xfpm_dbus_service_init (XfpmDBusService *dbus_service)
-{
- GError *error = NULL;
-
- /* try to connect to the session bus */
- dbus_service->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (G_LIKELY (dbus_service->connection != NULL))
- {
- /* register the /org/xfce/PowerManager object */
- dbus_g_connection_register_g_object (dbus_service->connection,
- "/org/xfce/PowerManager",
- G_OBJECT (dbus_service));
-
- xfpm_dbus_register_name (dbus_g_connection_get_connection (dbus_service->connection),
- "org.xfce.PowerManager");
-
- xfpm_dbus_register_name (dbus_g_connection_get_connection (dbus_service->connection),
- "org.xfce.PowerManager.Priv");
- }
- else
- {
- /* notify the user that D-BUS service won't be available */
- g_printerr ("%s: Failed to connect to the D-BUS session bus: %s\n",
- PACKAGE_NAME, error->message);
- g_error_free (error);
- }
-
- dbus_service->power = xfpm_power_get ();
-}
-
-
-
-static void
-xfpm_dbus_service_finalize (GObject *object)
-{
- XfpmDBusService *dbus_service = XFPM_DBUS_SERVICE (object);
-
- /* release the D-BUS connection object */
- if (G_LIKELY (dbus_service->connection != NULL))
- dbus_g_connection_unref (dbus_service->connection);
-
- g_object_unref (dbus_service->power);
-
- (*G_OBJECT_CLASS (xfpm_dbus_service_parent_class)->finalize) (object);
-}
-
-
-
-static gboolean
-xfpm_dbus_service_suspend (XfpmDBusService *dbus_service,
- GError **error)
-{
- xfpm_power_suspend (dbus_service->power, FALSE);
- return TRUE;
-}
-
-
-
-static gboolean
-xfpm_dbus_service_hibernate (XfpmDBusService *dbus_service,
- GError **error)
-{
- xfpm_power_hibernate (dbus_service->power, FALSE);
- return TRUE;
-}
-
-
-
-static gboolean
-xfpm_dbus_service_can_suspend (XfpmDBusService *dbus_service,
- gboolean *OUT_can_suspend,
- GError **error)
-{
- return xfpm_power_can_suspend (dbus_service->power, OUT_can_suspend, error);
-}
-
-
-
-static gboolean
-xfpm_dbus_service_can_hibernate (XfpmDBusService *dbus_service,
- gboolean *OUT_can_hibernate,
- GError **error)
-{
- return xfpm_power_can_hibernate (dbus_service->power, OUT_can_hibernate, error);
-}
-
-
-
-static gboolean
-xfpm_dbus_service_get_on_battery (XfpmDBusService *dbus_service,
- gboolean *OUT_on_battery,
- GError **error)
-{
- return xfpm_power_get_on_battery (dbus_service->power, OUT_on_battery, error);
-}
-
-
-
-static gboolean
-xfpm_dbus_service_get_low_battery (XfpmDBusService *dbus_service,
- gboolean *OUT_low_battery,
- GError **error)
-{
- return xfpm_power_get_low_battery (dbus_service->power, OUT_low_battery, error);
-}
-
-
-
-static gboolean
-xfpm_dbus_service_terminate (XfpmDBusService *dbus_service,
- gboolean restart,
- GError **error)
-{
- gtk_main_quit ();
- //TODO restart
- return TRUE;
-}
-
-
-
-XfpmDBusService *
-xfpm_dbus_service_new (void)
-{
- return g_object_new (XFPM_TYPE_DBUS_SERVICE, NULL);
-}
diff --git a/src/xfpm-dbus-service.h b/src/xfpm-dbus-service.h
deleted file mode 100644
index 96c6e7e..0000000
--- a/src/xfpm-dbus-service.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
- * Copyright (C) 2011 Nick Schermer <nick at xfce.org>
- *
- * 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 __XFPM_DBUS_SERVICE_H__
-#define __XFPM_DBUS_SERVICE_H__
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-typedef struct _XfpmDBusServiceClass XfpmDBusServiceClass;
-typedef struct _XfpmDBusService XfpmDBusService;
-
-#define XFPM_TYPE_DBUS_SERVICE (xfpm_dbus_service_get_type ())
-#define XFPM_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFPM_TYPE_DBUS_SERVICE, XfpmDBusService))
-#define XFPM_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFPM_TYPE_DBUS_SERVICE, XfpmDBusServiceClass))
-#define XFPM_IS_DBUS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFPM_TYPE_DBUS_SERVICE))
-#define XFPM_IS_DBUS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFPM_TYPE_DBUS_BRIGDE))
-#define XFPM_DBUS_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFPM_TYPE_DBUS_SERVICE, XfpmDBusServicetClass))
-
-GType xfpm_dbus_service_get_type (void) G_GNUC_CONST;
-
-XfpmDBusService *xfpm_dbus_service_new (void);
-
-G_END_DECLS
-
-#endif /* !__XFPM_DBUS_SERVICE_H__ */
diff --git a/src/xfpm-disks.c b/src/xfpm-disks.c
index e32cbf3..d179539 100644
--- a/src/xfpm-disks.c
+++ b/src/xfpm-disks.c
@@ -125,9 +125,7 @@ xfpm_disks_set_spin_timeouts (XfpmDisks *disks)
if (!disks->priv->can_spin )
return;
- g_object_get (G_OBJECT (disks->priv->power),
- "on-battery", &on_battery,
- NULL);
+ on_battery = xfpm_power_get_on_battery (disks->priv->power);
if ( !on_battery )
{
diff --git a/src/xfpm-dpms.c b/src/xfpm-dpms.c
index 8c87fc4..13c7087 100644
--- a/src/xfpm-dpms.c
+++ b/src/xfpm-dpms.c
@@ -234,8 +234,8 @@ xfpm_dpms_init(XfpmDpms *dpms)
if ( dpms->priv->dpms_capable )
{
- dpms->priv->power = xfpm_power_get ();
- dpms->priv->conf = xfpm_xfconf_new ();
+ dpms->priv->power = xfpm_power_get ();
+ dpms->priv->conf = xfpm_xfconf_new ();
g_signal_connect (dpms->priv->power, "on-battery-changed",
G_CALLBACK(xfpm_dpms_on_battery_changed_cb), dpms);
@@ -243,9 +243,7 @@ xfpm_dpms_init(XfpmDpms *dpms)
g_signal_connect (dpms->priv->conf, "notify",
G_CALLBACK (xfpm_dpms_settings_changed_cb), dpms);
- g_object_get (G_OBJECT (dpms->priv->power),
- "on-battery", &dpms->priv->on_battery,
- NULL);
+ dpms->priv->on_battery = xfpm_power_get_on_battery (dpms->priv->power);
xfpm_dpms_refresh (dpms);
}
diff --git a/src/xfpm-inhibit-service-infos.xml b/src/xfpm-inhibit-service-infos.xml
new file mode 100644
index 0000000..ec2d0e6
--- /dev/null
+++ b/src/xfpm-inhibit-service-infos.xml
@@ -0,0 +1,31 @@
+<?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">
+ <arg type="b" name="has_inhibit_changed" direction="out"/>
+ </signal>
+
+ <!--*** NOT STANDARD ***-->
+ <method name="GetInhibitors">
+ <arg type="as" name="inhibitors" direction="out"/>
+ </method>
+
+ </interface>
+
+</node>
diff --git a/src/xfpm-inhibit.c b/src/xfpm-inhibit.c
index 0f842a3..b1dd605 100644
--- a/src/xfpm-inhibit.c
+++ b/src/xfpm-inhibit.c
@@ -277,6 +277,12 @@ xfpm_inhibit_new(void)
return XFPM_INHIBIT (xfpm_inhibit_object);
}
+gboolean
+xfpm_inhibit_get_inhibited (XfpmInhibit *inhibit)
+{
+ return inhibit->priv->inhibited;
+}
+
/*
*
* DBus server implementation for org.freedesktop.PowerManagement.Inhibit
@@ -299,7 +305,7 @@ static gboolean xfpm_inhibit_get_inhibitors (XfpmInhibit *inhibit,
gchar ***OUT_inhibitor,
GError **error);
-#include "org.freedesktop.PowerManagement.Inhibit.h"
+#include "xfpm-inhibit-service-infos.h"
static void xfpm_inhibit_dbus_class_init (XfpmInhibitClass *klass)
{
diff --git a/src/xfpm-inhibit.h b/src/xfpm-inhibit.h
index 5b66fc0..20e812e 100644
--- a/src/xfpm-inhibit.h
+++ b/src/xfpm-inhibit.h
@@ -53,6 +53,8 @@ GQuark xfpm_inhibit_get_error_quark ();
XfpmInhibit *xfpm_inhibit_new (void);
+gboolean xfpm_inhibit_get_inhibited (XfpmInhibit *inhibit);
+
G_END_DECLS
#endif /* __XFPM_INHIBIT_H */
diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index b8e81cb..2e446b0 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -194,14 +194,14 @@ xfpm_dump_remote (DBusGConnection *bus)
}
static void G_GNUC_NORETURN
-xfpm_start (DBusGConnection *bus, const gchar *client_id, gboolean dump)
+xfpm_start (const gchar *client_id, gboolean dump)
{
XfpmManager *manager;
GError *error = NULL;
XFPM_DEBUG ("Starting the power manager");
- manager = xfpm_manager_new (bus, client_id);
+ manager = xfpm_manager_new (client_id);
if ( xfce_posix_signal_handler_init (&error))
{
@@ -369,7 +369,7 @@ int main (int argc, char **argv)
!xfpm_dbus_name_has_owner (dbus_g_connection_get_connection (bus), "org.freedesktop.PowerManagement"))
{
g_print ("Xfce power manager is not running\n");
- xfpm_start (bus, client_id, dump);
+ xfpm_start (client_id, dump);
}
proxy = dbus_g_proxy_new_for_name (bus,
@@ -419,7 +419,7 @@ int main (int argc, char **argv)
}
else
{
- xfpm_start (bus, client_id, dump);
+ xfpm_start (client_id, dump);
}
return EXIT_SUCCESS;
diff --git a/src/xfpm-manager-service-infos.xml b/src/xfpm-manager-service-infos.xml
new file mode 100644
index 0000000..a73f6ac
--- /dev/null
+++ b/src/xfpm-manager-service-infos.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ Copyright (c) 2011-2012 Nick Schermer <nick at xfce.org>
+
+ 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.
+-->
+
+<node name="/org/xfce/PowerManager">
+ <!--
+ org.xfce.Power.Manager
+
+ Private things for the xfce power manager
+ -->
+ <interface name="org.xfce.Power.Manager">
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="xfpm_manager_dbus" />
+ <annotation name="org.freedesktop.DBus.GLib.ClientCSymbol" value="xfpm_dbus_client" />
+
+ <!--
+ Terminate (restart : BOOLEAN)
+
+ Tells a running Xfpm instance to terminate immediately. If @restart is
+ TRUE, a new instance will be spawned.
+ -->
+ <method name="Terminate">
+ <arg type="b" name="restart" direction="in"/>
+ </method>
+
+ <!--
+ GetConfig (config : HASH TABLE)
+
+ Return the status information of the running power manager
+ -->
+ <method name="GetConfig">
+ <arg direction="out" name="config" type="a{ss}"/>
+ </method>
+
+ <method name="GetInfo">
+ <arg direction="out" name="name" type="s"/>
+ <arg direction="out" name="version" type="s"/>
+ <arg direction="out" name="vendor" type="s"/>
+ </method>
+ </interface>
+</node>
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index 71c9c0d..8f4b2c2 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -55,10 +55,12 @@
#include "xfpm-enum-glib.h"
#include "xfpm-enum-types.h"
#include "xfpm-dbus-monitor.h"
-#include "xfpm-dbus-service.h"
static void xfpm_manager_finalize (GObject *object);
+static void xfpm_manager_dbus_class_init (XfpmManagerClass *klass);
+static void xfpm_manager_dbus_init (XfpmManager *manager);
+
static gboolean xfpm_manager_quit (XfpmManager *manager);
#define XFPM_MANAGER_GET_PRIVATE(o) \
@@ -78,7 +80,6 @@ struct XfpmManagerPrivate
XfpmBacklight *backlight;
XfpmDBusMonitor *monitor;
XfpmDisks *disks;
- XfpmDBusService *dbus_service;
EggIdletime *idle;
#ifdef HAVE_DPMS
XfpmDpms *dpms;
@@ -99,6 +100,9 @@ xfpm_manager_class_init (XfpmManagerClass *klass)
object_class->finalize = xfpm_manager_finalize;
g_type_class_add_private (klass, sizeof (XfpmManagerPrivate));
+
+ /* install the D-BUS info for our class */
+ xfpm_manager_dbus_class_init (klass);
}
static void
@@ -107,8 +111,11 @@ xfpm_manager_init (XfpmManager *manager)
manager->priv = XFPM_MANAGER_GET_PRIVATE (manager);
manager->priv->timer = g_timer_new ();
+ manager->priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
notify_init ("xfce4-power-manager");
+
+ xfpm_manager_dbus_init (manager);
}
static void
@@ -120,8 +127,7 @@ xfpm_manager_finalize (GObject *object)
if ( manager->priv->session_bus )
dbus_g_connection_unref (manager->priv->session_bus);
-
- g_object_unref (manager->priv->dbus_service);
+
g_object_unref (manager->priv->power);
g_object_unref (manager->priv->button);
g_object_unref (manager->priv->conf);
@@ -141,12 +147,35 @@ xfpm_manager_finalize (GObject *object)
G_OBJECT_CLASS (xfpm_manager_parent_class)->finalize (object);
}
+static void
+xfpm_manager_release_names (XfpmManager *manager)
+{
+ xfpm_dbus_release_name (dbus_g_connection_get_connection(manager->priv->session_bus),
+ "org.xfce.PowerManager");
+}
+
+static gboolean
+xfpm_manager_reserve_names (XfpmManager *manager)
+{
+ if (!xfpm_dbus_register_name (dbus_g_connection_get_connection (manager->priv->session_bus),
+ "org.xfce.PowerManager"))
+ {
+ g_warning ("Unable to reserve bus name: Maybe any already running instance?\n");
+
+ g_object_unref (G_OBJECT (manager));
+ gtk_main_quit ();
+
+ return FALSE;
+ }
+ return TRUE;
+}
static gboolean
xfpm_manager_quit (XfpmManager *manager)
{
XFPM_DEBUG ("Exiting");
+ xfpm_manager_release_names (manager);
gtk_main_quit ();
return TRUE;
}
@@ -184,10 +213,10 @@ xfpm_manager_sleep_request (XfpmManager *manager, XfpmShutdownRequest req, gbool
case XFPM_DO_NOTHING:
break;
case XFPM_DO_SUSPEND:
- xfpm_power_suspend (manager->priv->power, force);
+ xfpm_power_suspend (manager->priv->power, force, NULL);
break;
case XFPM_DO_HIBERNATE:
- xfpm_power_hibernate (manager->priv->power, force);
+ xfpm_power_hibernate (manager->priv->power, force, NULL);
break;
case XFPM_DO_SHUTDOWN:
xfpm_manager_shutdown (manager);
@@ -258,11 +287,9 @@ static void
xfpm_manager_lid_changed_cb (XfpmPower *power, gboolean lid_is_closed, XfpmManager *manager)
{
XfpmLidTriggerAction action;
- gboolean on_battery = FALSE;
+ gboolean on_battery;
- /*TODOg_object_get (G_OBJECT (power),
- "on-battery", &on_battery,
- NULL);*/
+ on_battery = xfpm_power_get_on_battery (manager->priv->power);
g_object_get (G_OBJECT (manager->priv->conf),
on_battery ? LID_SWITCH_ON_BATTERY_CFG : LID_SWITCH_ON_AC_CFG, &action,
@@ -303,6 +330,10 @@ xfpm_manager_lid_changed_cb (XfpmPower *power, gboolean lid_is_closed, XfpmManag
static void
xfpm_manager_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmManager *manager)
{
+ XfpmShutdownRequest req = XFPM_DO_NOTHING;
+ gchar *sleep_mode;
+ gboolean on_battery;
+
if (xfpm_power_get_mode (manager->priv->power) == XFPM_POWER_MODE_PRESENTATION)
return;
@@ -310,17 +341,11 @@ xfpm_manager_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmManager *manager
if ( id == TIMEOUT_INACTIVITY_ON_AC || id == TIMEOUT_INACTIVITY_ON_BATTERY )
{
- XfpmShutdownRequest req = XFPM_DO_NOTHING;
- gchar *sleep_mode;
- gboolean on_battery = FALSE;
-
g_object_get (G_OBJECT (manager->priv->conf),
INACTIVITY_SLEEP_MODE, &sleep_mode,
NULL);
- /* TODO g_object_get (G_OBJECT (manager->priv->power),
- "on-battery", &on_battery,
- NULL); */
+ on_battery = xfpm_power_get_on_battery (manager->priv->power);
if ( !g_strcmp0 (sleep_mode, "Suspend") )
req = XFPM_DO_SUSPEND;
@@ -403,7 +428,7 @@ xfpm_manager_set_idle_alarm (XfpmManager *manager)
}
XfpmManager *
-xfpm_manager_new (DBusGConnection *bus, const gchar *client_id)
+xfpm_manager_new (const gchar *client_id)
{
XfpmManager *manager = NULL;
GError *error = NULL;
@@ -417,8 +442,6 @@ xfpm_manager_new (DBusGConnection *bus, const gchar *client_id)
};
manager = g_object_new (XFPM_TYPE_MANAGER, NULL);
-
- manager->priv->session_bus = bus;
current_dir = g_get_current_dir ();
manager->priv->client = xfce_sm_client_get_full (XFCE_SM_CLIENT_RESTART_NORMAL,
@@ -448,12 +471,13 @@ xfpm_manager_new (DBusGConnection *bus, const gchar *client_id)
void xfpm_manager_start (XfpmManager *manager)
{
-
+ if ( !xfpm_manager_reserve_names (manager) )
+ return;
+
dbus_g_error_domain_register (XFPM_ERROR,
NULL,
XFPM_TYPE_ERROR);
- manager->priv->dbus_service = xfpm_dbus_service_new ();
manager->priv->power = xfpm_power_get ();
manager->priv->button = xfpm_button_new ();
manager->priv->conf = xfpm_xfconf_new ();
@@ -490,17 +514,17 @@ void xfpm_manager_start (XfpmManager *manager)
g_signal_connect (manager->priv->power, "on-battery-changed",
G_CALLBACK (xfpm_manager_on_battery_changed_cb), manager);
- g_signal_connect_swapped (manager->priv->power, "waking-up",
+ g_signal_connect_swapped (manager->priv->power, "notify-sleep",
G_CALLBACK (xfpm_manager_reset_sleep_timer), manager);
- g_signal_connect_swapped (manager->priv->power, "sleeping",
+ g_signal_connect_swapped (manager->priv->power, "notify-resume",
G_CALLBACK (xfpm_manager_reset_sleep_timer), manager);
- g_signal_connect_swapped (manager->priv->power, "ask-shutdown",
+ /*TODOg_signal_connect_swapped (manager->priv->power, "ask-shutdown",
G_CALLBACK (xfpm_manager_ask_shutdown), manager);
g_signal_connect_swapped (manager->priv->power, "shutdown",
- G_CALLBACK (xfpm_manager_shutdown), manager);
+ G_CALLBACK (xfpm_manager_shutdown), manager);*/
}
@@ -510,3 +534,143 @@ void xfpm_manager_stop (XfpmManager *manager)
g_return_if_fail (XFPM_IS_MANAGER (manager));
xfpm_manager_quit (manager);
}
+
+GHashTable *xfpm_manager_get_config (XfpmManager *manager)
+{
+ GHashTable *hash;
+/*
+ guint8 mapped_buttons;
+ gboolean auth_hibernate = FALSE;
+ gboolean auth_suspend = FALSE;
+ gboolean can_suspend = FALSE;
+ gboolean can_hibernate = FALSE;
+ gboolean has_sleep_button = FALSE;
+ gboolean has_hibernate_button = FALSE;
+ gboolean has_power_button = FALSE;
+ gboolean has_battery = TRUE;
+ gboolean has_lcd_brightness = TRUE;
+ gboolean can_shutdown = TRUE;
+ gboolean has_lid = FALSE;
+ gboolean can_spin = FALSE;
+ gboolean devkit_disk = FALSE;
+ */
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ /*
+ g_object_get (G_OBJECT (manager->priv->console),
+ "can-shutdown", &can_shutdown,
+ NULL);
+
+ g_object_get (G_OBJECT (manager->priv->power),
+ "auth-suspend", &auth_suspend,
+ "auth-hibernate", &auth_hibernate,
+ "can-suspend", &can_suspend,
+ "can-hibernate", &can_hibernate,
+ "has-lid", &has_lid,
+ NULL);
+
+ can_spin = xfpm_disks_get_can_spin (manager->priv->disks);
+ devkit_disk = xfpm_disks_kit_is_running (manager->priv->disks);
+
+ has_battery = xfpm_power_has_battery (manager->priv->power);
+ has_lcd_brightness = xfpm_backlight_has_hw (manager->priv->backlight);
+
+ mapped_buttons = xfpm_button_get_mapped (manager->priv->button);
+
+ if ( mapped_buttons & SLEEP_KEY )
+ has_sleep_button = TRUE;
+ if ( mapped_buttons & HIBERNATE_KEY )
+ has_hibernate_button = TRUE;
+ if ( mapped_buttons & POWER_KEY )
+ has_power_button = TRUE;
+
+ g_hash_table_insert (hash, g_strdup ("sleep-button"), g_strdup (xfpm_bool_to_string (has_sleep_button)));
+ g_hash_table_insert (hash, g_strdup ("power-button"), g_strdup (xfpm_bool_to_string (has_power_button)));
+ g_hash_table_insert (hash, g_strdup ("hibernate-button"), g_strdup (xfpm_bool_to_string (has_hibernate_button)));
+ g_hash_table_insert (hash, g_strdup ("auth-suspend"), g_strdup (xfpm_bool_to_string (auth_suspend)));
+ g_hash_table_insert (hash, g_strdup ("auth-hibernate"), g_strdup (xfpm_bool_to_string (auth_hibernate)));
+ g_hash_table_insert (hash, g_strdup ("can-suspend"), g_strdup (xfpm_bool_to_string (can_suspend)));
+ g_hash_table_insert (hash, g_strdup ("can-hibernate"), g_strdup (xfpm_bool_to_string (can_hibernate)));
+ g_hash_table_insert (hash, g_strdup ("can-shutdown"), g_strdup (xfpm_bool_to_string (can_shutdown)));
+
+ g_hash_table_insert (hash, g_strdup ("has-battery"), g_strdup (xfpm_bool_to_string (has_battery)));
+ g_hash_table_insert (hash, g_strdup ("has-lid"), g_strdup (xfpm_bool_to_string (has_lid)));
+ g_hash_table_insert (hash, g_strdup ("can-spin"), g_strdup (xfpm_bool_to_string (can_spin)));
+ g_hash_table_insert (hash, g_strdup ("devkit-disk"), g_strdup (xfpm_bool_to_string (devkit_disk)));
+
+ g_hash_table_insert (hash, g_strdup ("has-brightness"), g_strdup (xfpm_bool_to_string (has_lcd_brightness)));
+ */
+ return hash;
+}
+
+/*
+ *
+ * DBus server implementation
+ *
+ */
+static gboolean xfpm_manager_dbus_terminate (XfpmManager *manager,
+ gboolean restart,
+ GError **error);
+
+static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
+ GHashTable **OUT_config,
+ GError **error);
+
+static gboolean xfpm_manager_dbus_get_info (XfpmManager *manager,
+ gchar **OUT_name,
+ gchar **OUT_version,
+ gchar **OUT_vendor,
+ GError **error);
+
+#include "xfpm-manager-service-infos.h"
+
+static void
+xfpm_manager_dbus_class_init (XfpmManagerClass *klass)
+{
+ dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
+ &dbus_glib_xfpm_manager_dbus_object_info);
+}
+
+static void
+xfpm_manager_dbus_init (XfpmManager *manager)
+{
+ dbus_g_connection_register_g_object (manager->priv->session_bus,
+ "/org/xfce/PowerManager",
+ G_OBJECT (manager));
+}
+
+static gboolean
+xfpm_manager_dbus_terminate (XfpmManager *manager, gboolean restart, GError **error)
+{
+ XFPM_DEBUG("Terminate message received\n");
+
+ xfpm_manager_quit (manager);
+
+ if (restart)
+ g_spawn_command_line_async ("xfce4-power-manager", NULL);
+
+ return TRUE;
+}
+
+static gboolean xfpm_manager_dbus_get_config (XfpmManager *manager,
+ GHashTable **OUT_config,
+ GError **error)
+{
+
+ *OUT_config = xfpm_manager_get_config (manager);
+ return TRUE;
+}
+
+static gboolean
+xfpm_manager_dbus_get_info (XfpmManager *manager,
+ gchar **OUT_name,
+ gchar **OUT_version,
+ gchar **OUT_vendor,
+ GError **error)
+{
+
+ *OUT_name = g_strdup(PACKAGE);
+ *OUT_version = g_strdup(VERSION);
+ *OUT_vendor = g_strdup("Xfce");
+
+ return TRUE;
+}
diff --git a/src/xfpm-manager.h b/src/xfpm-manager.h
index 73fab6e..edd726a 100644
--- a/src/xfpm-manager.h
+++ b/src/xfpm-manager.h
@@ -22,7 +22,6 @@
#define __XFPM_MANAGER_H
#include <glib-object.h>
-#include <dbus/dbus-glib.h>
G_BEGIN_DECLS
@@ -48,13 +47,14 @@ typedef struct
GType xfpm_manager_get_type (void) G_GNUC_CONST;
-XfpmManager *xfpm_manager_new (DBusGConnection *bus,
- const gchar *client_id);
+XfpmManager *xfpm_manager_new (const gchar *client_id);
void xfpm_manager_start (XfpmManager *manager);
void xfpm_manager_stop (XfpmManager *manager);
+GHashTable *xfpm_manager_get_config (XfpmManager *manager);
+
G_END_DECLS
#endif /* __XFPM_MANAGER_H */
diff --git a/src/xfpm-dbus-service-infos.xml b/src/xfpm-power-service-infos.xml
similarity index 80%
rename from src/xfpm-dbus-service-infos.xml
rename to src/xfpm-power-service-infos.xml
index d3cee21..f0b388b 100644
--- a/src/xfpm-dbus-service-infos.xml
+++ b/src/xfpm-power-service-infos.xml
@@ -2,7 +2,7 @@
<!--
Copyright (C) 2009-2011 Ali <aliov at xfce.org>
- Copyright (c) 2011 Nick Schermer <nick at xfce.org>
+ Copyright (c) 2011-2012 Nick Schermer <nick at xfce.org>
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
@@ -19,14 +19,14 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-->
-<node name="/org/xfce/PowerManager">
+<node name="/org/xfce/PowerManagement">
<!--
- org.xfce.PowerManager
+ org.xfce.PowerManagement
The public power management interface.
-->
- <interface name="org.xfce.PowerManager">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="xfpm_dbus_service" />
+ <interface name="org.xfce.PowerManagement">
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="xfpm_power_dbus" />
<!--
Suspend () : VOID
@@ -106,23 +106,4 @@
<arg type="b" name="low_battery" direction="out"/>
</signal>
</interface>
-
- <!--
- org.xfce.Power
-
- The private Xfce4-power-manager interface.
- -->
- <interface name="org.xfce.PowerManager.Priv">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="xfpm_dbus_service" />
-
- <!--
- Terminate (restart : BOOLEAN)
-
- Tells a running Xfpm instance to terminate immediately. If @restart is
- TRUE, a new instance will be spawned.
- -->
- <method name="Terminate">
- <arg type="b" name="restart" direction="in"/>
- </method>
- </interface>
</node>
diff --git a/src/xfpm-power.c b/src/xfpm-power.c
index 553e444..e9a94f6 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -46,12 +46,35 @@
#include "xfpm-power-common.h"
#include "xfpm-config.h"
#include "xfpm-debug.h"
+#include "xfpm-inhibit.h"
#include "xfpm-enum-types.h"
#include "egg-idletime.h"
-static void xfpm_power_finalize (GObject *object);
+static void xfpm_power_finalize (GObject *object);
+
+static gboolean xfpm_power_dbus_suspend (XfpmPower *power,
+ GError **error);
+static gboolean xfpm_power_dbus_hibernate (XfpmPower *power,
+ GError **error);
+static gboolean xfpm_power_dbus_can_suspend (XfpmPower *power,
+ gboolean *OUT_can_suspend,
+ GError **error);
+static gboolean xfpm_power_dbus_can_hibernate (XfpmPower *power,
+ gboolean *OUT_can_hibernate,
+ GError **error);
+static gboolean xfpm_power_dbus_get_on_battery (XfpmPower *power,
+ gboolean *OUT_on_battery,
+ GError **error);
+static gboolean xfpm_power_dbus_get_low_battery (XfpmPower *power,
+ gboolean *OUT_low_battery,
+ GError **error);
+
+static void xfpm_power_refresh_adaptor_visible (XfpmPower *power);
+
+
+/* include generate dbus infos */
+#include "xfpm-power-service-infos.h"
-static void xfpm_power_refresh_adaptor_visible (XfpmPower *power);
struct _XfpmPowerClass
{
@@ -62,26 +85,31 @@ struct _XfpmPower
{
GObjectClass __parent__;
+ XfpmXfconf *conf;
+ XfpmInhibit *inhibit;
+ XfpmNotify *notify;
+
+ DBusGConnection *connection;
+
+ /* UPower client */
UpClient *up_client;
-
- GSList *devices;
- XfpmXfconf *conf;
- GtkStatusIcon *adapter_icon;
-
+ /* XfpmBattery items */
+ GSList *devices;
+
+ /* last known lid state */
+ gboolean lid_closed;
+
+ /* last know on-battery state */
+ gboolean on_battery;
+
+ /* ac-adapter icon */
+ GtkStatusIcon *adapter_icon;
+
XfpmBatteryCharge overall_state;
gboolean critical_action_done;
-
+
XfpmPowerMode power_mode;
- EggIdletime *idletime;
-
- XfpmNotify *notify;
-
- /**
- * Warning dialog to use when notification daemon
- * doesn't support actions.
- **/
- GtkWidget *dialog;
};
enum
@@ -89,14 +117,12 @@ enum
ON_BATTERY_CHANGED,
LOW_BATTERY_CHANGED,
LID_CHANGED,
- WAKING_UP,
- SLEEPING,
- ASK_SHUTDOWN,
- SHUTDOWN,
+ NOTIFY_SLEEP,
+ NOTIFY_RESUME,
LAST_SIGNAL
};
-static guint signals [LAST_SIGNAL] = { 0 };
+static guint signals [LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (XfpmPower, xfpm_power, G_TYPE_OBJECT)
@@ -104,130 +130,27 @@ G_DEFINE_TYPE (XfpmPower, xfpm_power, G_TYPE_OBJECT)
static void
-xfpm_power_report_error (XfpmPower *power, const gchar *error, const gchar *icon_name)
-{
- GtkStatusIcon *battery = NULL;
- UpDeviceKind kind;
- GSList *li;
-
- for (li = power->devices; li != NULL; li = li->next)
- {
- kind = xfpm_battery_get_kind (XFPM_BATTERY (li->data));
- if (kind == UP_DEVICE_KIND_BATTERY
- || kind == UP_DEVICE_KIND_UPS)
- {
- battery = GTK_STATUS_ICON (li->data);
- break;
- }
- }
-
- xfpm_notify_show_notification (power->notify,
- _("Power Manager"),
- error,
- icon_name,
- 10000,
- FALSE,
- XFPM_NOTIFY_CRITICAL,
- battery);
-
-}
-
-static void
-xfpm_power_sleep (XfpmPower *power, const gchar *sleep_time, gboolean force)
+xfpm_power_hibernate_clicked (XfpmPower *power)
{
GError *error = NULL;
- gboolean lock_screen;
-
- if (!force)
- {
- gboolean ret;
-
- ret = xfce_dialog_confirm (NULL,
- GTK_STOCK_YES,
- "Yes",
- _("An application is currently disabling the automatic sleep,"
- " doing this action now may damage the working state of this application,"
- " are you sure you want to hibernate the system?"),
- NULL);
-
- if ( !ret )
- return;
- }
-
- g_signal_emit (G_OBJECT (power), signals [SLEEPING], 0);
- xfpm_network_manager_sleep (TRUE);
-
- g_object_get (G_OBJECT (power->conf),
- LOCK_SCREEN_ON_SLEEP, &lock_screen,
- NULL);
-
- if ( lock_screen )
- {
- g_usleep (2000000); /* 2 seconds */
- xfpm_lock_screen ();
- }
-
- /*TODO dbus_g_proxy_call (power->proxy, sleep_time, &error,
- G_TYPE_INVALID,
- G_TYPE_INVALID);*/
-
- if ( error )
+
+ if (!xfpm_power_hibernate (power, TRUE, &error))
{
- if ( g_error_matches (error, DBUS_GERROR, DBUS_GERROR_NO_REPLY) )
- {
- XFPM_DEBUG ("D-Bus time out, but should be harmless");
- }
- else
- {
- const gchar *icon_name;
- if ( !g_strcmp0 (sleep_time, "Hibernate") )
- icon_name = XFPM_HIBERNATE_ICON;
- else
- icon_name = XFPM_SUSPEND_ICON;
-
- xfpm_power_report_error (power, error->message, icon_name);
- g_error_free (error);
- }
+ xfce_dialog_show_error (NULL, error, _("Failed to hibernate the system"));
+ g_error_free (error);
}
-
- g_signal_emit (G_OBJECT (power), signals [WAKING_UP], 0);
- xfpm_network_manager_sleep (FALSE);
-}
-
-static void
-xfpm_power_hibernate_cb (XfpmPower *power)
-{
- xfpm_power_sleep (power, "Hibernate", FALSE);
-}
-
-static void
-xfpm_power_suspend_cb (XfpmPower *power)
-{
- xfpm_power_sleep (power, "Suspend", FALSE);
-}
-
-static void
-xfpm_power_hibernate_clicked (XfpmPower *power)
-{
- gtk_widget_destroy (power->dialog );
- power->dialog = NULL;
- xfpm_power_sleep (power, "Hibernate", TRUE);
}
static void
xfpm_power_suspend_clicked (XfpmPower *power)
{
- gtk_widget_destroy (power->dialog );
- power->dialog = NULL;
- xfpm_power_sleep (power, "Suspend", TRUE);
-}
+ GError *error = NULL;
-static void
-xfpm_power_shutdown_clicked (XfpmPower *power)
-{
- gtk_widget_destroy (power->dialog );
- power->dialog = NULL;
- g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
+ if (!xfpm_power_suspend (power, TRUE, &error))
+ {
+ xfce_dialog_show_error (NULL, error, _("Failed to suspend the system"));
+ g_error_free (error);
+ }
}
static void
@@ -240,9 +163,9 @@ static void
xfpm_power_tray_exit_activated_cb (gpointer data)
{
gboolean ret;
-
- ret = xfce_dialog_confirm (NULL,
- GTK_STOCK_YES,
+
+ ret = xfce_dialog_confirm (NULL,
+ GTK_STOCK_YES,
_("Quit"),
_("All running instances of the power manager will exit"),
"%s",
@@ -253,24 +176,23 @@ xfpm_power_tray_exit_activated_cb (gpointer data)
}
}
-
static void
xfpm_power_change_mode (XfpmPower *power, XfpmPowerMode mode)
{
XfpmDpms *dpms;
-
+
power->power_mode = mode;
-
+
dpms = xfpm_dpms_new ();
xfpm_dpms_refresh (dpms);
g_object_unref (dpms);
-
+
if (mode == XFPM_POWER_MODE_NORMAL)
{
EggIdletime *idletime;
idletime = egg_idletime_new ();
egg_idletime_alarm_reset_all (idletime);
-
+
g_object_unref (idletime);
}
}
@@ -288,47 +210,48 @@ xfpm_power_presentation_mode_cb (XfpmPower *power)
}
static void
-xfpm_power_show_tray_menu (XfpmPower *power,
- GtkStatusIcon *icon,
- guint button,
+xfpm_power_show_tray_menu (XfpmPower *power,
+ GtkStatusIcon *icon,
+ guint button,
guint activate_time,
gboolean show_info_item)
{
GtkWidget *menu, *mi, *img, *subm;
+ gboolean can_hibernate = FALSE;
+ gboolean can_suspend = FALSE;
menu = gtk_menu_new();
- // Hibernate menu option
+ /* Hibernate */
mi = gtk_image_menu_item_new_with_label (_("Hibernate"));
img = gtk_image_new_from_icon_name (XFPM_HIBERNATE_ICON, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img);
- gtk_widget_set_sensitive (mi, FALSE);
-
- //TODOif ( power->can_hibernate && power->auth_hibernate)
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ gtk_widget_show (mi);
+
+ if (xfpm_power_can_hibernate (power, &can_hibernate, NULL))
{
- gtk_widget_set_sensitive (mi, TRUE);
g_signal_connect_swapped (G_OBJECT (mi), "activate",
- G_CALLBACK (xfpm_power_hibernate_cb), power);
+ G_CALLBACK (xfpm_power_hibernate_clicked),
+ power);
}
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-
- // Suspend menu option
+ gtk_widget_set_sensitive (mi, can_hibernate);
+
+ /* Suspend */
mi = gtk_image_menu_item_new_with_label (_("Suspend"));
img = gtk_image_new_from_icon_name (XFPM_SUSPEND_ICON, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img);
-
- gtk_widget_set_sensitive (mi, FALSE);
-
- //TODOif ( power->can_suspend && power->auth_hibernate)
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ gtk_widget_show (mi);
+
+ if (xfpm_power_can_suspend (power, &can_suspend, NULL))
{
- gtk_widget_set_sensitive (mi, TRUE);
- g_signal_connect_swapped (mi, "activate",
- G_CALLBACK (xfpm_power_suspend_cb), power);
+ g_signal_connect_swapped (G_OBJECT (mi), "activate",
+ G_CALLBACK (xfpm_power_suspend_clicked),
+ power);
}
-
- gtk_widget_show (mi);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+ gtk_widget_set_sensitive (mi, can_suspend);
+
/*
saver_inhibited = xfpm_screen_saver_get_inhibit (tray->srv);
mi = gtk_check_menu_item_new_with_label (_("Monitor power control"));
@@ -336,32 +259,32 @@ xfpm_power_show_tray_menu (XfpmPower *power,
gtk_widget_set_tooltip_text (mi, _("Disable or enable monitor power control, "\
"for example you could disable the screen power "\
"control to avoid screen blanking when watching a movie."));
-
+
g_signal_connect (G_OBJECT (mi), "activate",
G_CALLBACK (xfpm_tray_icon_inhibit_active_cb), tray);
gtk_widget_set_sensitive (mi, TRUE);
gtk_widget_show(mi);
gtk_menu_shell_append(GTK_MENU_SHELL(menu),mi);
*/
-
+
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
- // Power information
+ /* Power information */
mi = gtk_image_menu_item_new_with_label (_("Power Information"));
img = gtk_image_new_from_stock (GTK_STOCK_INFO, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img);
gtk_widget_set_sensitive (mi,TRUE);
-
+
g_signal_connect_swapped (mi, "activate",
G_CALLBACK (xfpm_power_power_info_cb), icon);
-
+
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-
- /**
+
+ /**
* Power Mode
**/
/* TRANSLATOR: Mode here is the power profile (presentation, power save, normal) */
@@ -370,55 +293,51 @@ xfpm_power_show_tray_menu (XfpmPower *power,
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img);
gtk_widget_set_sensitive (mi,TRUE);
gtk_widget_show (mi);
-
+
subm = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (mi), subm);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-
+
/* Normal*/
mi = gtk_check_menu_item_new_with_label (_("Normal"));
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), power->power_mode == XFPM_POWER_MODE_NORMAL);
gtk_widget_set_sensitive (mi,TRUE);
-
+
g_signal_connect_swapped (mi, "activate",
G_CALLBACK (xfpm_power_normal_mode_cb), power);
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (subm), mi);
-
+
/* Normal*/
mi = gtk_check_menu_item_new_with_label (_("Presentation"));
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), power->power_mode == XFPM_POWER_MODE_PRESENTATION);
gtk_widget_set_sensitive (mi, TRUE);
-
+
g_signal_connect_swapped (mi, "activate",
G_CALLBACK (xfpm_power_presentation_mode_cb), power);
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (subm), mi);
-
-
+
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-
+
mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_HELP, NULL);
gtk_widget_set_sensitive (mi, TRUE);
gtk_widget_show (mi);
g_signal_connect (mi, "activate", G_CALLBACK (xfpm_help), NULL);
-
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
-
+
mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_ABOUT, NULL);
gtk_widget_set_sensitive (mi, TRUE);
gtk_widget_show (mi);
g_signal_connect (mi, "activate", G_CALLBACK (xfpm_about), _("Power Manager"));
-
gtk_menu_shell_append (GTK_MENU_SHELL(menu), mi);
-
+
mi = gtk_image_menu_item_new_from_stock (GTK_STOCK_PREFERENCES, NULL);
gtk_widget_set_sensitive (mi, TRUE);
gtk_widget_show (mi);
g_signal_connect (mi, "activate",G_CALLBACK (xfpm_preferences), NULL);
-
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
mi = gtk_separator_menu_item_new ();
@@ -434,22 +353,22 @@ xfpm_power_show_tray_menu (XfpmPower *power,
g_signal_connect (menu, "selection-done",
G_CALLBACK (gtk_widget_destroy), NULL);
- // Popup the menu
+ /* Popup the menu */
gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
- gtk_status_icon_position_menu,
+ gtk_status_icon_position_menu,
icon, button, activate_time);
-
+
}
-static void
-xfpm_power_show_tray_menu_battery (GtkStatusIcon *icon, guint button,
- guint activate_time, XfpmPower *power)
+static void
+xfpm_power_show_tray_menu_battery (GtkStatusIcon *icon, guint button,
+ guint activate_time, XfpmPower *power)
{
xfpm_power_show_tray_menu (power, icon, button, activate_time, TRUE);
}
-static void
-xfpm_power_show_tray_menu_adaptor (GtkStatusIcon *icon, guint button,
+static void
+xfpm_power_show_tray_menu_adaptor (GtkStatusIcon *icon, guint button,
guint activate_time, XfpmPower *power)
{
xfpm_power_show_tray_menu (power, icon, button, activate_time, FALSE);
@@ -462,9 +381,9 @@ xfpm_power_get_current_charge_state (XfpmPower *power)
UpDeviceKind kind;
GSList *li;
XfpmBatteryCharge max_charge, charge;
-
+
max_charge = XFPM_BATTERY_CHARGE_UNKNOWN;
-
+
for (li = power->devices; li != NULL; li = li->next)
{
battery = XFPM_BATTERY (li->data);
@@ -480,193 +399,11 @@ xfpm_power_get_current_charge_state (XfpmPower *power)
}
static void
-xfpm_power_notify_action_callback (NotifyNotification *n, gchar *action, XfpmPower *power)
-{
- if ( !g_strcmp0 (action, "Shutdown") )
- g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
- else
- xfpm_power_sleep (power, action, TRUE);
-}
-
-static void
-xfpm_power_add_actions_to_notification (XfpmPower *power, NotifyNotification *n)
-{
- gboolean can_shutdown = FALSE;
-
- //TODO if ( power->can_hibernate && power->auth_hibernate )
- {
- xfpm_notify_add_action_to_notification(
- power->notify,
- n,
- "Hibernate",
- _("Hibernate the system"),
- (NotifyActionCallback)xfpm_power_notify_action_callback,
- power);
- }
-
- //TODO if ( power->can_suspend && power->auth_suspend )
- {
- xfpm_notify_add_action_to_notification(
- power->notify,
- n,
- "Suspend",
- _("Suspend the system"),
- (NotifyActionCallback)xfpm_power_notify_action_callback,
- power);
- }
-
- if (can_shutdown )
- xfpm_notify_add_action_to_notification(
- power->notify,
- n,
- "Shutdown",
- _("Shutdown the system"),
- (NotifyActionCallback)xfpm_power_notify_action_callback,
- power);
-}
-
-static void
-xfpm_power_show_critical_action_notification (XfpmPower *power, XfpmBattery *battery)
-{
- const gchar *message;
- NotifyNotification *n;
-
- message = _("System is running on low power. "\
- "Save your work to avoid losing data");
-
- n =
- xfpm_notify_new_notification (power->notify,
- _("Power Manager"),
- message,
- gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
- 20000,
- XFPM_NOTIFY_CRITICAL,
- GTK_STATUS_ICON (battery));
-
- xfpm_power_add_actions_to_notification (power, n);
- xfpm_notify_critical (power->notify, n);
-
-}
-
-static void
-xfpm_power_close_critical_dialog (XfpmPower *power)
-{
- gtk_widget_destroy (power->dialog);
- power->dialog = NULL;
-}
-
-static void
-xfpm_power_show_critical_action_gtk (XfpmPower *power)
-{
- GtkWidget *dialog;
- GtkWidget *content_area;
- GtkWidget *img;
- GtkWidget *cancel;
- const gchar *message;
- gboolean can_shutdown = FALSE; /* TODO */
-
- message = _("System is running on low power. "\
- "Save your work to avoid losing data");
-
- dialog = gtk_dialog_new_with_buttons (_("Power Manager"), NULL, GTK_DIALOG_MODAL,
- NULL);
-
- gtk_dialog_set_default_response (GTK_DIALOG (dialog),
- GTK_RESPONSE_CANCEL);
-
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
-
- gtk_box_pack_start_defaults (GTK_BOX (content_area), gtk_label_new (message));
-
- //TODO if ( power->can_hibernate && power->auth_hibernate )
- {
- GtkWidget *hibernate;
- hibernate = gtk_button_new_with_label (_("Hibernate"));
- img = gtk_image_new_from_icon_name (XFPM_HIBERNATE_ICON, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (hibernate), img);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), hibernate, GTK_RESPONSE_NONE);
-
- g_signal_connect_swapped (hibernate, "clicked",
- G_CALLBACK (xfpm_power_hibernate_clicked), power);
- }
-
- //TODO if ( power->can_suspend && power->auth_suspend )
- {
- GtkWidget *suspend;
-
- suspend = gtk_button_new_with_label (_("Suspend"));
- img = gtk_image_new_from_icon_name (XFPM_SUSPEND_ICON, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (suspend), img);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), suspend, GTK_RESPONSE_NONE);
-
- g_signal_connect_swapped (suspend, "clicked",
- G_CALLBACK (xfpm_power_suspend_clicked), power);
- }
-
- if ( can_shutdown )
- {
- GtkWidget *shutdown;
-
- shutdown = gtk_button_new_with_label (_("Shutdown"));
- img = gtk_image_new_from_icon_name (XFPM_SUSPEND_ICON, GTK_ICON_SIZE_BUTTON);
- gtk_button_set_image (GTK_BUTTON (shutdown), img);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), shutdown, GTK_RESPONSE_NONE);
-
- g_signal_connect_swapped (shutdown, "clicked",
- G_CALLBACK (xfpm_power_shutdown_clicked), power);
- }
-
- cancel = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog), cancel, GTK_RESPONSE_NONE);
-
- g_signal_connect_swapped (cancel, "clicked",
- G_CALLBACK (xfpm_power_close_critical_dialog), power);
-
- g_signal_connect_swapped (dialog, "destroy",
- G_CALLBACK (xfpm_power_close_critical_dialog), power);
- if ( power->dialog )
- {
- gtk_widget_destroy (power->dialog);
- power->dialog = NULL;
-
- }
- power->dialog = dialog;
- gtk_widget_show_all (dialog);
-}
-
-static void
-xfpm_power_show_critical_action (XfpmPower *power, XfpmBattery *battery)
-{
- gboolean supports_actions;
-
- g_object_get (G_OBJECT (power->notify),
- "actions", &supports_actions,
- NULL);
-
- if ( supports_actions )
- xfpm_power_show_critical_action_notification (power, battery);
- else
- xfpm_power_show_critical_action_gtk (power);
-}
-
-static void
-xfpm_power_process_critical_action (XfpmPower *power, XfpmShutdownRequest req)
-{
- if ( req == XFPM_ASK )
- g_signal_emit (G_OBJECT (power), signals [ASK_SHUTDOWN], 0);
- else if ( req == XFPM_DO_SUSPEND )
- xfpm_power_sleep (power, "Suspend", TRUE);
- else if ( req == XFPM_DO_HIBERNATE )
- xfpm_power_sleep (power, "Hibernate", TRUE);
- else if ( req == XFPM_DO_SHUTDOWN )
- g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
-}
-
-static void
xfpm_power_system_on_critical_power (XfpmPower *power, XfpmBattery *battery)
{
+ /*TODO
XfpmShutdownRequest critical_action;
-
+
g_object_get (G_OBJECT (power->conf),
CRITICAL_BATT_ACTION_CFG, &critical_action,
NULL);
@@ -690,6 +427,7 @@ xfpm_power_system_on_critical_power (XfpmPower *power, XfpmBattery *battery)
xfpm_power_show_critical_action (power, battery);
}
}
+ * */
}
static void
@@ -698,53 +436,53 @@ xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
gboolean notify;
XfpmBatteryCharge battery_charge;
XfpmBatteryCharge current_charge;
-
+
battery_charge = xfpm_battery_get_charge (battery);
current_charge = xfpm_power_get_current_charge_state (power);
-
+
XFPM_DEBUG_ENUM (current_charge, XFPM_TYPE_BATTERY_CHARGE, "Current system charge status");
-
+
if (current_charge == power->overall_state)
return;
-
+
if (current_charge >= XFPM_BATTERY_CHARGE_LOW)
power->critical_action_done = FALSE;
-
+
power->overall_state = current_charge;
-
+
//TODO if ( current_charge == XFPM_BATTERY_CHARGE_CRITICAL && power->on_battery)
{
xfpm_power_system_on_critical_power (power, battery);
-
+
//TODO power->on_low_battery = TRUE;
//TODOg_signal_emit (G_OBJECT (power), signals [LOW_BATTERY_CHANGED], 0, power->on_low_battery);
return;
}
-
+
//TODO if ( power->on_low_battery )
{
//TODO power->on_low_battery = FALSE;
//TODOg_signal_emit (G_OBJECT (power), signals [LOW_BATTERY_CHANGED], 0, power->on_low_battery);
}
-
+
g_object_get (G_OBJECT (power->conf),
GENERAL_NOTIFICATION_CFG, ¬ify,
NULL);
-
+
//TODO if ( power->on_battery )
{
if ( current_charge == XFPM_BATTERY_CHARGE_LOW )
{
if ( notify )
- xfpm_notify_show_notification (power->notify,
- _("Power Manager"),
- _("System is running on low power"),
+ xfpm_notify_show_notification (power->notify,
+ _("Power Manager"),
+ _("System is running on low power"),
gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
10000,
FALSE,
XFPM_NOTIFY_NORMAL,
GTK_STATUS_ICON (battery));
-
+
}
else if ( battery_charge == XFPM_BATTERY_CHARGE_LOW )
{
@@ -752,17 +490,17 @@ xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
{
gchar *msg;
gchar *time_str;
-
+
const gchar *battery_name = xfpm_battery_get_name (battery);
-
+
time_str = xfpm_battery_get_time_left (battery);
-
+
msg = g_strdup_printf (_("Your %s charge level is low\nEstimated time left %s"), battery_name, time_str);
-
-
- xfpm_notify_show_notification (power->notify,
- _("Power Manager"),
- msg,
+
+
+ xfpm_notify_show_notification (power->notify,
+ _("Power Manager"),
+ msg,
gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
10000,
FALSE,
@@ -773,13 +511,6 @@ xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
}
}
}
-
- /*Current charge is okay now, then close the dialog*/
- if ( power->dialog )
- {
- gtk_widget_destroy (power->dialog);
- power->dialog = NULL;
- }
}
static void
@@ -787,14 +518,14 @@ xfpm_power_add_device (XfpmPower *power, UpDevice *device)
{
UpDeviceKind kind;
GtkStatusIcon *battery;
-
+
g_return_if_fail (UP_IS_DEVICE (device));
g_return_if_fail (XFPM_IS_POWER (power));
-
+
g_object_get (device, "kind", &kind, NULL);
-
+
XFPM_DEBUG (" device added");
-
+
switch (kind)
{
case UP_DEVICE_KIND_BATTERY:
@@ -808,17 +539,15 @@ xfpm_power_add_device (XfpmPower *power, UpDevice *device)
G_CALLBACK (xfpm_power_show_tray_menu_battery), power);
g_signal_connect (battery, "battery-charge-changed",
G_CALLBACK (xfpm_power_battery_charge_changed_cb), power);
-
- power->devices = g_slist_prepend (power->devices, device);
- xfpm_power_refresh_adaptor_visible (power);
+ power->devices = g_slist_prepend (power->devices, device);
break;
-
+
case UP_DEVICE_KIND_LINE_POWER:
g_warning ("Unable to monitor unkown power device: %s", "TODO");
break;
-
+
default:
/* other devices types we don't care about */
break;
@@ -831,16 +560,25 @@ xfpm_power_get_power_devices (XfpmPower *power)
GPtrArray *array;
guint i;
UpDevice *device;
-
+ GError *error = NULL;
+
+ if (!up_client_enumerate_devices_sync (power->up_client, NULL, &error))
+ {
+ g_critical ("Failed to enumerate devices: %s", error->message);
+ g_error_free (error);
+
+ return;
+ }
+
array = up_client_get_devices (power->up_client);
-
+
if ( array )
{
for ( i = 0; i < array->len; i++)
{
device = g_ptr_array_index (array, i);
g_return_if_fail (UP_IS_DEVICE (device));
-
+
xfpm_power_add_device (power, device);
}
g_ptr_array_unref (array);
@@ -854,11 +592,47 @@ xfpm_power_remove_device (XfpmPower *power, UpDevice *device)
xfpm_power_refresh_adaptor_visible (power);
}
-
static void
xfpm_power_changed_cb (UpClient *up_client, XfpmPower *power)
{
+ gboolean lid_closed;
+ gboolean on_battery;
+ GSList *li;
+
g_return_if_fail (power->up_client == up_client);
+
+ if (up_client_get_lid_is_present (power->up_client))
+ {
+ lid_closed = up_client_get_lid_is_closed (power->up_client);
+
+ if (power->lid_closed != lid_closed)
+ {
+ /* notify the manager the lid state changed */
+ power->lid_closed = lid_closed;
+ g_signal_emit (G_OBJECT (power),
+ signals [LID_CHANGED],
+ 0, lid_closed);
+ }
+ }
+
+ on_battery = up_client_get_on_battery (power->up_client);
+ if (power->on_battery != on_battery)
+ {
+ /* notify the system about the battery change */
+ power->on_battery = on_battery;
+ g_signal_emit (G_OBJECT (power),
+ signals [ON_BATTERY_CHANGED],
+ 0, on_battery);
+
+ /* tell all batteries the ac-power changed */
+ for (li = power->devices; li != NULL; li = li->next)
+ {
+ g_object_set (G_OBJECT (li->data),
+ "ac-online", !on_battery,
+ NULL);
+ }
+ }
+
xfpm_power_refresh_adaptor_visible (power);
}
@@ -867,6 +641,7 @@ xfpm_power_device_added_cb (UpClient *up_client, UpDevice *device, XfpmPower *po
{
g_return_if_fail (power->up_client == up_client);
xfpm_power_add_device (power, device);
+ xfpm_power_refresh_adaptor_visible (power);
}
static void
@@ -887,7 +662,7 @@ static void
xfpm_power_hide_adapter_icon (XfpmPower *power)
{
XFPM_DEBUG ("Hide adaptor icon");
-
+
if ( power->adapter_icon )
{
g_object_unref (power->adapter_icon);
@@ -899,15 +674,15 @@ static void
xfpm_power_show_adapter_icon (XfpmPower *power)
{
g_return_if_fail (power->adapter_icon == NULL);
-
+
power->adapter_icon = gtk_status_icon_new ();
-
+
XFPM_DEBUG ("Showing adaptor icon");
-
+
gtk_status_icon_set_from_icon_name (power->adapter_icon, XFPM_AC_ADAPTER_ICON);
-
+
gtk_status_icon_set_visible (power->adapter_icon, TRUE);
-
+
g_signal_connect (power->adapter_icon, "popup-menu",
G_CALLBACK (xfpm_power_show_tray_menu_adaptor), power);
}
@@ -916,21 +691,21 @@ static void
xfpm_power_refresh_adaptor_visible (XfpmPower *power)
{
XfpmShowIcon show_icon;
-
+
g_object_get (G_OBJECT (power->conf),
SHOW_TRAY_ICON_CFG, &show_icon,
NULL);
-
+
XFPM_DEBUG_ENUM (show_icon, XFPM_TYPE_SHOW_ICON, "Tray icon configuration: ");
-
+
if ( show_icon == SHOW_ICON_ALWAYS )
{
-
+
if (power->devices == NULL)
{
xfpm_power_show_adapter_icon (power);
- gtk_status_icon_set_tooltip_text (power->adapter_icon,
- TRUE ? //power->on_battery ?
+ gtk_status_icon_set_tooltip_text (power->adapter_icon,
+ power->on_battery ?
_("Adaptor is offline") :
_("Adaptor is online") );
}
@@ -952,80 +727,90 @@ xfpm_power_class_init (XfpmPowerClass *klass)
object_class->finalize = xfpm_power_finalize;
- signals [ON_BATTERY_CHANGED] =
- g_signal_new ("on-battery-changed",
- XFPM_TYPE_POWER,
+ signals [ON_BATTERY_CHANGED] =
+ g_signal_new (g_intern_static_string ("on-battery-changed"),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals [LOW_BATTERY_CHANGED] =
- g_signal_new ("low-battery-changed",
- XFPM_TYPE_POWER,
+ signals [LOW_BATTERY_CHANGED] =
+ g_signal_new (g_intern_static_string ("low-battery-changed"),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals [LID_CHANGED] =
- g_signal_new ("lid-changed",
- XFPM_TYPE_POWER,
+ signals [LID_CHANGED] =
+ g_signal_new (g_intern_static_string ("lid-changed"),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- signals [WAKING_UP] =
- g_signal_new ("waking-up",
- XFPM_TYPE_POWER,
+ signals [NOTIFY_RESUME] =
+ g_signal_new (g_intern_static_string ("notify-resume"),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
- signals [SLEEPING] =
- g_signal_new ("sleeping",
- XFPM_TYPE_POWER,
+ signals [NOTIFY_SLEEP] =
+ g_signal_new (g_intern_static_string ("notify-sleep"),
+ G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
- signals [ASK_SHUTDOWN] =
- g_signal_new ("ask-shutdown",
- XFPM_TYPE_POWER,
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0, G_TYPE_NONE);
-
- signals [SHUTDOWN] =
- g_signal_new ("shutdown",
- XFPM_TYPE_POWER,
- G_SIGNAL_RUN_LAST,
- 0, NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0, G_TYPE_NONE);
+ /* install the D-BUS info for our class */
+ dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
+ &dbus_glib_xfpm_power_dbus_object_info);
}
static void
xfpm_power_init (XfpmPower *power)
{
GError *error = NULL;
- gboolean on_battery;
- power->dialog = NULL;
- power->adapter_icon = NULL;
- power->overall_state = XFPM_BATTERY_CHARGE_OK;
+ power->adapter_icon = NULL;
+ power->overall_state = XFPM_BATTERY_CHARGE_OK;
power->critical_action_done = FALSE;
- power->power_mode = XFPM_POWER_MODE_NORMAL;
- power->notify = xfpm_notify_new ();
-
+ power->power_mode = XFPM_POWER_MODE_NORMAL;
+ power->notify = xfpm_notify_new ();
+ power->inhibit = xfpm_inhibit_new ();
+
+ /* try to connect to the session bus */
+ power->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ if (G_LIKELY (power->connection))
+ {
+ /* register the /org/xfce/PowerManager object */
+ dbus_g_connection_register_g_object (power->connection,
+ "/org/xfce/PowerManagement",
+ G_OBJECT (power));
+
+ xfpm_dbus_register_name (dbus_g_connection_get_connection (power->connection),
+ "org.xfce.PowerManagement");
+ }
+ else
+ {
+ /* notify the user that D-BUS service won't be available */
+ g_printerr ("%s: Failed to connect to the D-BUS session bus: %s\n",
+ PACKAGE_NAME, error->message);
+ g_error_free (error);
+ }
+
power->up_client = up_client_new ();
-
+
+ power->lid_closed = up_client_get_lid_is_closed (power->up_client);
+ power->on_battery = up_client_get_on_battery (power->up_client);
+
xfpm_power_get_power_devices (power);
-
+
g_signal_connect (power->up_client, "changed",
G_CALLBACK (xfpm_power_changed_cb), power);
g_signal_connect (power->up_client, "device-removed",
@@ -1034,45 +819,103 @@ xfpm_power_init (XfpmPower *power)
G_CALLBACK (xfpm_power_device_added_cb), power);
g_signal_connect (power->up_client, "device-changed",
G_CALLBACK (xfpm_power_device_changed_cb), power);
-
-
+
power->conf = xfpm_xfconf_new ();
g_signal_connect_swapped (power->conf, "notify::" SHOW_TRAY_ICON_CFG,
G_CALLBACK (xfpm_power_refresh_adaptor_visible), power);
xfpm_power_refresh_adaptor_visible (power);
- if (xfpm_power_get_on_battery (power, &on_battery, &error))
- {
- g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, on_battery);
- }
- else
+ if (power->on_battery)
{
- g_critical ("Failed to get on-battery: %s", error->message);
- g_error_free (error);
+ g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, power->on_battery);
}
}
static void
xfpm_power_finalize (GObject *object)
{
- XfpmPower *power;
+ XfpmPower *power = XFPM_POWER (object);
- power = XFPM_POWER (object);
+ if (G_LIKELY (power->connection != NULL))
+ dbus_g_connection_unref (power->connection);
g_object_unref (power->conf);
g_object_unref (power->up_client);
-
+ g_object_unref (power->inhibit);
+
xfpm_power_hide_adapter_icon (power);
G_OBJECT_CLASS (xfpm_power_parent_class)->finalize (object);
}
+static gboolean
+xfpm_power_check_inhibited (XfpmPower *power,
+ const gchar *label)
+{
+ if (!xfpm_inhibit_get_inhibited (power->inhibit))
+ return FALSE;
+
+ return !xfce_dialog_confirm (NULL, GTK_STOCK_YES, label,
+ _("An application is currently disabling the automatic sleep,"
+ " doing this action now may damage the working state of this application,"
+ " are you sure you want to hibernate the system?"),
+ NULL);
+}
+
+static gboolean
+xfpm_power_dbus_suspend (XfpmPower *power,
+ GError **error)
+{
+ return xfpm_power_suspend (power, FALSE, error);
+}
+
+static gboolean
+xfpm_power_dbus_hibernate (XfpmPower *power,
+ GError **error)
+{
+ return xfpm_power_hibernate (power, FALSE, error);
+}
+
+static gboolean
+xfpm_power_dbus_can_suspend (XfpmPower *power,
+ gboolean *OUT_can_suspend,
+ GError **error)
+{
+ return xfpm_power_can_suspend (power, OUT_can_suspend, error);
+}
+
+static gboolean
+xfpm_power_dbus_can_hibernate (XfpmPower *power,
+ gboolean *OUT_can_hibernate,
+ GError **error)
+{
+ return xfpm_power_can_hibernate (power, OUT_can_hibernate, error);
+}
+
+static gboolean
+xfpm_power_dbus_get_on_battery (XfpmPower *power,
+ gboolean *OUT_on_battery,
+ GError **error)
+{
+ *OUT_on_battery = xfpm_power_get_on_battery (power);
+ return TRUE;
+}
+
+static gboolean
+xfpm_power_dbus_get_low_battery (XfpmPower *power,
+ gboolean *OUT_low_battery,
+ GError **error)
+{
+ *OUT_low_battery = xfpm_power_get_low_battery (power);
+ return TRUE;
+}
+
XfpmPower *
xfpm_power_get (void)
{
static gpointer xfpm_power_object = NULL;
-
+
if ( G_LIKELY (xfpm_power_object != NULL ) )
{
g_object_ref (xfpm_power_object);
@@ -1082,74 +925,75 @@ xfpm_power_get (void)
xfpm_power_object = g_object_new (XFPM_TYPE_POWER, NULL);
g_object_add_weak_pointer (xfpm_power_object, &xfpm_power_object);
}
-
+
return XFPM_POWER (xfpm_power_object);
}
-void
-xfpm_power_suspend (XfpmPower *power, gboolean force)
+gboolean
+xfpm_power_suspend (XfpmPower *power,
+ gboolean force,
+ GError **error)
{
- xfpm_power_sleep (power, "Suspend", force);
+ if (!force && xfpm_power_check_inhibited (power, _("Suspend")))
+ return TRUE;
+
+ return up_client_suspend_sync (power->up_client, NULL, error);
}
-void
-xfpm_power_hibernate (XfpmPower *power, gboolean force)
+gboolean
+xfpm_power_hibernate (XfpmPower *power,
+ gboolean force,
+ GError **error)
{
- xfpm_power_sleep (power, "Hibernate", force);
+
+ if (!force && xfpm_power_check_inhibited (power, _("Hibernate")))
+ return TRUE;
+
+ return up_client_hibernate_sync (power->up_client, NULL, error);
}
-gboolean
-xfpm_power_can_suspend (XfpmPower *power,
+gboolean
+xfpm_power_can_suspend (XfpmPower *power,
gboolean *can_suspend,
GError **error)
{
- if (!up_client_get_properties_sync (power->up_client, NULL, error))
- return FALSE;
+ if (!up_client_get_properties_sync (power->up_client, NULL, error))
+ return FALSE;
- *can_suspend = up_client_get_can_suspend (power->up_client);
- return TRUE;
+ *can_suspend = up_client_get_can_suspend (power->up_client);
+ return TRUE;
}
-gboolean
-xfpm_power_can_hibernate (XfpmPower *power,
+gboolean
+xfpm_power_can_hibernate (XfpmPower *power,
gboolean *can_hibernate,
GError **error)
{
- if (!up_client_get_properties_sync (power->up_client, NULL, error))
- return FALSE;
+ if (!up_client_get_properties_sync (power->up_client, NULL, error))
+ return FALSE;
- *can_hibernate = up_client_get_can_hibernate (power->up_client);
- return TRUE;
+ *can_hibernate = up_client_get_can_hibernate (power->up_client);
+ return TRUE;
}
-gboolean
-xfpm_power_get_on_battery (XfpmPower *power,
- gboolean *on_battery,
- GError **error)
+gboolean
+xfpm_power_get_on_battery (XfpmPower *power)
{
- if (!up_client_get_properties_sync (power->up_client, NULL, error))
- return FALSE;
-
- *on_battery = up_client_get_on_battery (power->up_client);
- return TRUE;
+ g_return_val_if_fail (XFPM_IS_POWER (power), FALSE);
+ return power->on_battery;
}
-gboolean
-xfpm_power_get_low_battery (XfpmPower *power,
- gboolean *low_battery,
- GError **error)
+gboolean
+xfpm_power_get_low_battery (XfpmPower *power)
{
- if (!up_client_get_properties_sync (power->up_client, NULL, error))
- return FALSE;
-
- *low_battery = up_client_get_on_low_battery (power->up_client);
- return TRUE;
+ g_return_val_if_fail (XFPM_IS_POWER (power), FALSE);
+ return FALSE /*TODO */;
}
-XfpmPowerMode xfpm_power_get_mode (XfpmPower *power)
+XfpmPowerMode
+xfpm_power_get_mode (XfpmPower *power)
{
g_return_val_if_fail (XFPM_IS_POWER (power), XFPM_POWER_MODE_NORMAL);
-
return power->power_mode;
}
diff --git a/src/xfpm-power.h b/src/xfpm-power.h
index 820f608..b89b120 100644
--- a/src/xfpm-power.h
+++ b/src/xfpm-power.h
@@ -40,11 +40,13 @@ GType xfpm_power_get_type (void) G_GNUC_CONST;
XfpmPower *xfpm_power_get (void);
-void xfpm_power_suspend (XfpmPower *power,
- gboolean force);
+gboolean xfpm_power_suspend (XfpmPower *power,
+ gboolean force,
+ GError **error);
-void xfpm_power_hibernate (XfpmPower *power,
- gboolean force);
+gboolean xfpm_power_hibernate (XfpmPower *power,
+ gboolean force,
+ GError **error);
gboolean xfpm_power_can_suspend (XfpmPower *power,
gboolean *can_suspend,
@@ -54,13 +56,9 @@ gboolean xfpm_power_can_hibernate (XfpmPower *power,
gboolean *can_hibernate,
GError **error);
-gboolean xfpm_power_get_on_battery (XfpmPower *power,
- gboolean *on_battery,
- GError **error);
+gboolean xfpm_power_get_on_battery (XfpmPower *power);
-gboolean xfpm_power_get_low_battery (XfpmPower *power,
- gboolean *low_battery,
- GError **error);
+gboolean xfpm_power_get_low_battery (XfpmPower *power);
XfpmPowerMode xfpm_power_get_mode (XfpmPower *power);
More information about the Xfce4-commits
mailing list