[Xfce4-commits] <xfce4-power-manager:nick/upower-session> Work.
Nick Schermer
noreply at xfce.org
Mon Mar 5 23:22:02 CET 2012
Updating branch refs/heads/nick/upower-session
to 7ee6d2c47b41338219b9a64722be8020df5b4a8f (commit)
from 1f3bb60a769b2a50a732150cba89a649a630e381 (commit)
commit 7ee6d2c47b41338219b9a64722be8020df5b4a8f
Author: Nick Schermer <nick at xfce.org>
Date: Fri Jan 27 21:34:10 2012 +0100
Work.
configure.ac.in | 2 +
settings/xfce4-power-manager-settings.desktop.in | 2 +-
src/Makefile.am | 30 +-
src/org.freedesktop.PowerManagement.Inhibit.xml | 31 -
src/org.freedesktop.PowerManagement.xml | 59 -
src/xfpm-battery.c | 1051 ++++++++--------
src/xfpm-battery.h | 7 +-
src/xfpm-console-kit.c | 236 ----
src/xfpm-console-kit.h | 59 -
src/xfpm-dbus-service-infos.xml | 128 ++
src/xfpm-dbus-service.c | 232 ++++
src/xfpm-dbus-service.h | 43 +
src/xfpm-dpms.c | 3 +-
src/xfpm-enum-glib.h | 26 -
src/xfpm-main.c | 20 +-
src/xfpm-manager.c | 242 +----
src/xfpm-manager.h | 2 -
src/xfpm-power.c | 1457 +++++++---------------
src/xfpm-power.h | 87 +-
src/xfpm-sm-client.c | 133 ++
src/xfpm-sm-client.h | 58 +
21 files changed, 1657 insertions(+), 2251 deletions(-)
diff --git a/configure.ac.in b/configure.ac.in
index b925ec1..eb7ba40 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -66,6 +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])
XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [gtk_minimum_version])
XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [glib_minimum_version])
@@ -80,6 +81,7 @@ XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0],[libxfce4util_minimum_versi
XDT_CHECK_PACKAGE([LIBNOTIFY],[libnotify], [libnotify_minimum_version])
XDT_CHECK_PACKAGE([XRANDR],[xrandr], [xrandr_minimum_version])
XDT_CHECK_PACKAGE([X11], [x11], [x11_minimum_version])
+XDT_CHECK_PACKAGE([UPOWER_GLIB], [upower-glib], [upower_minimum_version])
#=======================================================#
# Polkit? #
diff --git a/settings/xfce4-power-manager-settings.desktop.in b/settings/xfce4-power-manager-settings.desktop.in
index 7cbd09f..ee9d4fb 100644
--- a/settings/xfce4-power-manager-settings.desktop.in
+++ b/settings/xfce4-power-manager-settings.desktop.in
@@ -7,7 +7,7 @@ Exec=xfce4-power-manager-settings
Icon=xfpm-ac-adapter
Terminal=false
Type=Application
-Categories=X-XFCE;Settings;DesktopSettings;X-XfceSettingsDialog;
+Categories=XFCE;GTK;Settings;DesktopSettings;X-XFCE-SettingsDialog;X-XFCE-PersonalSettings;
OnlyShowIn=XFCE;
StartupNotify=true
X-XfcePluggable=true
diff --git a/src/Makefile.am b/src/Makefile.am
index eaca181..e6ce147 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -5,6 +5,8 @@ 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 \
@@ -18,8 +20,8 @@ xfce4_power_manager_SOURCES = \
xfpm-xfconf.h \
xfpm-disks.c \
xfpm-disks.h \
- xfpm-console-kit.c \
- xfpm-console-kit.h \
+ xfpm-sm-client.c \
+ xfpm-sm-client.h \
egg-idletime.c \
egg-idletime.h \
xfpm-backlight.c \
@@ -30,8 +32,6 @@ xfce4_power_manager_SOURCES = \
xfpm-button.h \
xfpm-network-manager.c \
xfpm-network-manager.h \
- xfpm-inhibit.c \
- xfpm-inhibit.h \
xfpm-notify.c \
xfpm-notify.h \
xfpm-polkit.c \
@@ -56,6 +56,7 @@ xfce4_power_manager_CFLAGS = \
$(LIBNOTIFY_CFLAGS) \
$(XRANDR_CFLAGS) \
$(DPMS_CFLAGS) \
+ $(UPOWER_GLIB_CFLAGS) \
$(PLATFORM_CPPFLAGS) \
$(PLATFORM_CFLAGS)
@@ -73,6 +74,7 @@ xfce4_power_manager_LDADD = \
$(XFCONF_LIBS) \
$(LIBNOTIFY_LIBS) \
$(XRANDR_LIBS) \
+ $(UPOWER_GLIB_LIBS) \
$(DPMS_LIBS)
xfce4_power_information_SOURCES = \
@@ -139,14 +141,11 @@ xfpm_glib_headers = \
$(srcdir)/xfpm-enum-glib.h
BUILT_SOURCES = \
- xfce-power-manager-dbus-server.h \
- xfce-power-manager-dbus-client.h \
+ xfpm-dbus-service-infos.h \
xfpm-enum-types.c \
xfpm-enum-types.h \
xfpm-marshal.c \
- xfpm-marshal.h \
- org.freedesktop.PowerManagement.h \
- org.freedesktop.PowerManagement.Inhibit.h
+ xfpm-marshal.h
if MAINTAINER_MODE
@@ -179,17 +178,8 @@ xfpm-marshal.c: xfpm-marshal.list
xfpm-marshal.h: xfpm-marshal.list
glib-genmarshal $< --prefix=_xfpm_marshal --header > $@
-xfce-power-manager-dbus-server.h: $(srcdir)/org.xfce.Power.Manager.xml
- dbus-binding-tool --mode=glib-server --prefix=xfpm_manager $< >$@
-
-xfce-power-manager-dbus-client.h: $(srcdir)/org.xfce.Power.Manager.xml
- dbus-binding-tool --mode=glib-client --prefix=xfpm_manager $< >$@
-
-org.freedesktop.PowerManagement.h: $(srcdir)/org.freedesktop.PowerManagement.xml
- dbus-binding-tool --mode=glib-server --prefix=xfpm_power $< >$@
-
-org.freedesktop.PowerManagement.Inhibit.h: $(srcdir)/org.freedesktop.PowerManagement.Inhibit.xml
- dbus-binding-tool --mode=glib-server --prefix=xfpm_inhibit $< >$@
+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 $< >$@
endif
diff --git a/src/org.freedesktop.PowerManagement.Inhibit.xml b/src/org.freedesktop.PowerManagement.Inhibit.xml
deleted file mode 100644
index ec2d0e6..0000000
--- a/src/org.freedesktop.PowerManagement.Inhibit.xml
+++ /dev/null
@@ -1,31 +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">
- <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/org.freedesktop.PowerManagement.xml b/src/org.freedesktop.PowerManagement.xml
deleted file mode 100644
index ae00d7a..0000000
--- a/src/org.freedesktop.PowerManagement.xml
+++ /dev/null
@@ -1,59 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<node name="/org/freedesktop/PowerManagement">
- <interface name="org.freedesktop.PowerManagement">
- <annotation name="org.freedesktop.DBus.GLib.CSymbol"
- value="xfpm_power_dbus"/>
- <annotation name="org.freedesktop.DBus.GLib.ClientCSymbol"
- value="xfpm_power_dbus_client"/>
-
- <method name="Shutdown">
- </method>
-
- <method name="Reboot">
- </method>
-
- <method name="Hibernate">
- </method>
-
- <method name="Suspend">
- </method>
-
- <method name="CanShutdown">
- <arg type="b" name="can_shutdown" direction="out"/>
- </method>
-
- <method name="CanReboot">
- <arg type="b" name="can_reboot" direction="out"/>
- </method>
-
- <method name="CanSuspend">
- <arg type="b" name="can_suspend" direction="out"/>
- </method>
-
- <method name="CanHibernate">
- <arg type="b" name="can_hibernate" direction="out"/>
- </method>
-
- <method name="GetPowerSaveStatus">
- <arg type="b" name="save_power" direction="out"/>
- </method>
-
- <method name="GetOnBattery">
- <arg type="b" name="on_battery" direction="out"/>
- </method>
-
- <method name="GetLowBattery">
- <arg type="b" name="low_battery" direction="out"/>
- </method>
-
- <signal name="OnBatteryChanged">
- <arg type="b" name="on_battery" direction="out"/>
- </signal>
-
- <signal name="LowBatteryChanged">
- <arg type="b" name="low_battery" direction="out"/>
- </signal>
-
- </interface>
-</node>
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 763b014..bd3a0db 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -50,27 +50,25 @@ static void xfpm_battery_finalize (GObject *object);
struct XfpmBatteryPrivate
{
+ UpDevice *device;
+
XfpmXfconf *conf;
- XfpmNotify *notify;
+ XfpmNotify *notify;
XfpmButton *button;
- DBusGProxy *proxy;
- DBusGProxy *proxy_prop;
-
- gchar *icon_prefix;
-
+
+ gchar *icon_prefix;
+
XfpmBatteryCharge charge;
- XfpmDeviceState state;
XfpmDeviceType type;
- gboolean ac_online;
- gboolean present;
- guint percentage;
- gint64 time_to_full;
- gint64 time_to_empty;
+ gboolean ac_online;
+ guint percentage;
+ gint64 time_to_full;
+ gint64 time_to_empty;
const gchar *battery_name;
-
- gulong sig;
- gulong sig_bt;
+
+ gulong sig;
+ gulong sig_bt;
};
enum
@@ -80,73 +78,84 @@ enum
PROP_CHARGE_STATUS,
PROP_DEVICE_TYPE
};
-
+
enum
{
BATTERY_CHARGE_CHANGED,
LAST_SIGNAL
};
+
+
static guint signals [LAST_SIGNAL] = { 0 };
+
+
G_DEFINE_TYPE (XfpmBattery, xfpm_battery, GTK_TYPE_STATUS_ICON)
-static const gchar * G_GNUC_CONST
-xfpm_battery_get_icon_index (XfpmDeviceType type, guint percent)
+
+
+static const gchar *
+xfpm_battery_get_icon_index (UpDeviceKind kind;, gdouble percentage)
{
- if (percent < 10)
- {
- return "000";
- }
- else if (percent < 30)
- {
- return ( (type == XFPM_DEVICE_TYPE_BATTERY || type == XFPM_DEVICE_TYPE_UPS) ? "020" : "030");
- }
- else if (percent < 50)
- {
- return ( (type == XFPM_DEVICE_TYPE_BATTERY || type == XFPM_DEVICE_TYPE_UPS ) ? "040" : "030");
- }
- else if (percent < 70)
- {
- return "060";
- }
- else if (percent < 90)
+ if (kind == UP_DEVICE_KIND_BATTERY || kind == UP_DEVICE_KIND_UPS)
+ {
+ if (percentage < 20)
+ return "000";
+ else if (percentage < 40)
+ return "020";
+ else if (percentage < 60)
+ return "040");
+ else if (percentage < 80)
+ return "060";
+ else if (percentage < 100)
+ return "080");
+ else
+ return "100";
+ }
+ else
{
- return ((type == XFPM_DEVICE_TYPE_BATTERY || type == XFPM_DEVICE_TYPE_UPS) ? "080" : "060");
+ if (percentage < 30)
+ return "000";
+ else if (percentage < 60)
+ return "030";
+ else if (percentage < 100)
+ return "060");
+ else
+ return "100";
}
-
- return "100";
}
static void
xfpm_battery_refresh_visible (XfpmBattery *battery)
{
XfpmShowIcon show_icon;
- gboolean visible = TRUE;
-
+ gboolean visible;
+ gboolean is_present;
+ UpDeviceState state;
+
+ g_object_get (battery->device,
+ "is-present", &is_present,
+ "state", state.
+ NULL);
+
g_object_get (G_OBJECT (battery->priv->conf),
- SHOW_TRAY_ICON_CFG, &show_icon,
- NULL);
-
+ SHOW_TRAY_ICON_CFG, &show_icon,
+ NULL);
+
if ( show_icon == SHOW_ICON_ALWAYS )
- visible = TRUE;
+ visible = TRUE;
else if ( show_icon == NEVER_SHOW_ICON )
- visible = FALSE;
+ visible = FALSE;
else if ( show_icon == SHOW_ICON_WHEN_BATTERY_PRESENT )
- {
- if ( battery->priv->present )
- visible = TRUE;
- else visible = FALSE;
- }
+ visible = is_present;
else if ( show_icon == SHOW_ICON_WHEN_BATTERY_CHARGING_DISCHARGING )
- {
- if ( battery->priv->state == XFPM_DEVICE_STATE_FULLY_CHARGED )
- visible = FALSE;
- else visible = TRUE;
- }
+ visible = state != UP_DEVICE_STATE_FULLY_CHARGED;
+ else
+ visible = FALSE;
XFPM_DEBUG_ENUM (show_icon, XFPM_TYPE_SHOW_ICON, "visible=%s", xfpm_bool_to_string (visible));
-
+
gtk_status_icon_set_visible (GTK_STATUS_ICON (battery), visible);
}
@@ -155,124 +164,120 @@ xfpm_battery_refresh_visible (XfpmBattery *battery)
* Taken from gpm
*/
static gchar *
-xfpm_battery_get_time_string (guint seconds)
+xfpm_battery_get_time_string (gint64 seconds)
{
- char* timestring = NULL;
- gint hours;
- gint minutes;
+ gint hours;
+ gint minutes;
/* Add 0.5 to do rounding */
minutes = (int) ( ( seconds / 60.0 ) + 0.5 );
- if (minutes == 0)
+ if (minutes == 0)
{
- timestring = g_strdup (_("Unknown time"));
- return timestring;
+ return g_strdup (_("Unknown time"));
}
- if (minutes < 60)
+ if (minutes < 60)
{
- timestring = g_strdup_printf (ngettext ("%i minute",
- "%i minutes",
- minutes), minutes);
- return timestring;
+ return g_strdup_printf (ngettext ("%i minute",
+ "%i minutes",
+ minutes), minutes);
}
hours = minutes / 60;
minutes = minutes % 60;
if (minutes == 0)
- timestring = g_strdup_printf (ngettext (
- "%i hour",
- "%i hours",
- hours), hours);
+ {
+ return = g_strdup_printf (ngettext ("%i hour", "%i hours", hours), hours);
+ }
else
- /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes"
- * Swap order with "%2$s %2$i %1$s %1$i if needed */
- timestring = g_strdup_printf (_("%i %s %i %s"),
- hours, ngettext ("hour", "hours", hours),
- minutes, ngettext ("minute", "minutes", minutes));
- return timestring;
+ {
+ /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes"
+ * Swap order with "%2$s %2$i %1$s %1$i if needed */
+ return g_strdup_printf (_("%i %s %i %s"),
+ hours, ngettext ("hour", "hours", hours),
+ minutes, ngettext ("minute", "minutes", minutes));
+ }
}
static gchar *
xfpm_battery_get_message_from_battery_state (XfpmBattery *battery)
{
gchar *msg = NULL;
-
-
+
if (battery->priv->type == XFPM_DEVICE_TYPE_BATTERY || battery->priv->type == XFPM_DEVICE_TYPE_UPS)
{
- switch (battery->priv->state)
- {
- case XFPM_DEVICE_STATE_FULLY_CHARGED:
- msg = g_strdup_printf (_("Your %s is fully charged"), battery->priv->battery_name);
- break;
- case XFPM_DEVICE_STATE_CHARGING:
- msg = g_strdup_printf (_("Your %s is charging"), battery->priv->battery_name);
-
- if ( battery->priv->time_to_full != 0 )
- {
- gchar *tmp, *est_time_str;
- tmp = g_strdup (msg);
- g_free (msg);
-
- est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_full);
-
- msg = g_strdup_printf (_("%s (%i%%)\n%s until is fully charged."), tmp, battery->priv->percentage, est_time_str);
- g_free (est_time_str);
- g_free (tmp);
- }
-
- break;
- case XFPM_DEVICE_STATE_DISCHARGING:
- if (battery->priv->ac_online)
- msg = g_strdup_printf (_("Your %s is discharging"), battery->priv->battery_name);
- else
- msg = g_strdup_printf (_("System is running on %s power"), battery->priv->battery_name);
-
- if ( battery->priv->time_to_empty != 0 )
- {
- gchar *tmp, *est_time_str;
- tmp = g_strdup (msg);
- g_free (msg);
-
- est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_empty);
-
- msg = g_strdup_printf (_("%s (%i%%)\nEstimated time left is %s."), tmp, battery->priv->percentage, est_time_str);
- g_free (tmp);
- g_free (est_time_str);
- }
- break;
- case XFPM_DEVICE_STATE_EMPTY:
- msg = g_strdup_printf (_("Your %s is empty"), battery->priv->battery_name);
- break;
- default:
- break;
- }
-
+ switch (battery->priv->state)
+ {
+ case XFPM_DEVICE_STATE_FULLY_CHARGED:
+ msg = g_strdup_printf (_("Your %s is fully charged"), battery->priv->battery_name);
+ break;
+ case XFPM_DEVICE_STATE_CHARGING:
+ msg = g_strdup_printf (_("Your %s is charging"), battery->priv->battery_name);
+
+ if ( battery->priv->time_to_full != 0 )
+ {
+ gchar *tmp, *est_time_str;
+ tmp = g_strdup (msg);
+ g_free (msg);
+
+ est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_full);
+
+ msg = g_strdup_printf (_("%s (%i%%)\n%s until is fully charged."), tmp, battery->priv->percentage, est_time_str);
+ g_free (est_time_str);
+ g_free (tmp);
+ }
+
+ break;
+ case XFPM_DEVICE_STATE_DISCHARGING:
+ if (battery->priv->ac_online)
+ msg = g_strdup_printf (_("Your %s is discharging"), battery->priv->battery_name);
+ else
+ msg = g_strdup_printf (_("System is running on %s power"), battery->priv->battery_name);
+
+ if ( battery->priv->time_to_empty != 0 )
+ {
+ gchar *tmp, *est_time_str;
+ tmp = g_strdup (msg);
+ g_free (msg);
+
+ est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_empty);
+
+ msg = g_strdup_printf (_("%s (%i%%)\nEstimated time left is %s."), tmp, battery->priv->percentage, est_time_str);
+ g_free (tmp);
+ g_free (est_time_str);
+ }
+ break;
+ case XFPM_DEVICE_STATE_EMPTY:
+ msg = g_strdup_printf (_("Your %s is empty"), battery->priv->battery_name);
+ break;
+ default:
+ break;
+ }
+
}
else if (battery->priv->type >= XFPM_DEVICE_TYPE_MONITOR)
{
- switch (battery->priv->state)
- {
- case XFPM_DEVICE_STATE_FULLY_CHARGED:
- msg = g_strdup_printf (_("Your %s is fully charged"), battery->priv->battery_name);
- break;
- case XFPM_DEVICE_STATE_CHARGING:
- msg = g_strdup_printf (_("Your %s is charging"), battery->priv->battery_name);
- break;
- case XFPM_DEVICE_STATE_DISCHARGING:
- msg = g_strdup_printf (_("Your %s is discharging"), battery->priv->battery_name);
- break;
- case XFPM_DEVICE_STATE_EMPTY:
- msg = g_strdup_printf (_("Your %s is empty"), battery->priv->battery_name);
- break;
- default:
- break;
- }
+ switch (battery->priv->state)
+ {
+ case XFPM_DEVICE_STATE_FULLY_CHARGED:
+ msg = g_strdup_printf (_("Your %s is fully charged"), battery->priv->battery_name);
+ break;
+ case XFPM_DEVICE_STATE_CHARGING:
+ msg = g_strdup_printf (_("Your %s is charging"), battery->priv->battery_name);
+ break;
+ case XFPM_DEVICE_STATE_DISCHARGING:
+ msg = g_strdup_printf (_("Your %s is discharging"), battery->priv->battery_name);
+ break;
+ case XFPM_DEVICE_STATE_EMPTY:
+ msg = g_strdup_printf (_("Your %s is empty"), battery->priv->battery_name);
+ break;
+ default:
+ break;
+ }
}
-
+
return msg;
}
@@ -280,58 +285,86 @@ static void
xfpm_battery_refresh_icon (XfpmBattery *battery)
{
gchar icon_name[128];
-
+ gboolean is_present;
+ UpDeviceState state;
+ UpDeviceKind kind;
+ gdouble percentage;
+
XFPM_DEBUG ("Battery state %d", battery->priv->state);
-
- if ( battery->priv->type == XFPM_DEVICE_TYPE_BATTERY ||
- battery->priv->type == XFPM_DEVICE_TYPE_UPS )
- {
- if (!battery->priv->present)
- {
- g_snprintf (icon_name, 128, "%s%s", battery->priv->icon_prefix, "missing");
- }
- else if (battery->priv->state == XFPM_DEVICE_STATE_FULLY_CHARGED )
- {
- g_snprintf (icon_name, 128, "%s%s", battery->priv->icon_prefix, battery->priv->ac_online ? "charged" : "100");
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_CHARGING ||
- battery->priv->state == XFPM_DEVICE_STATE_PENDING_CHARGING)
- {
- g_snprintf (icon_name, 128, "%s%s-%s",
- battery->priv->icon_prefix,
- xfpm_battery_get_icon_index (battery->priv->type, battery->priv->percentage),
- "charging");
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_DISCHARGING ||
- battery->priv->state == XFPM_DEVICE_STATE_PENDING_DISCHARGING)
- {
- g_snprintf (icon_name, 128, "%s%s",
- battery->priv->icon_prefix,
- xfpm_battery_get_icon_index (battery->priv->type, battery->priv->percentage));
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_EMPTY)
- {
- g_snprintf (icon_name, 128, "%s%s", battery->priv->icon_prefix, battery->priv->ac_online ? "000-charging" : "000");
- }
+
+ g_snprintf (icon_name, sizeof (icon_name), GTK_STOCK_MISSING_IMAGE);
+
+ g_object_get (battery->device,
+ "is-present", &is_present,
+ "state", &state,
+ "kind", &kind,
+ "percentage", &percentage,
+ NULL);
+
+ if ( kind == UP_DEVICE_KIND_BATTERY || kind == UP_DEVICE_KIND_UPS )
+ {
+ if (!is_present)
+ {
+ g_snprintf (icon_name, sizeof (icon_name), "%s%s",
+ battery->priv->icon_prefix, "missing");
+ }
+ else
+ {
+ switch (state)
+ {
+ case UP_DEVICE_STATE_FULLY_CHARGED:
+ g_snprintf (icon_name, sizeof (icon_name), "%s%s",
+ battery->priv->icon_prefix,
+ battery->priv->ac_online ? "charged" : "100");
+ break;
+
+ case UP_DEVICE_STATE_CHARGING:
+ case UP_DEVICE_STATE_PENDING_CHARGE:
+ g_snprintf (icon_name, sizeof (icon_name), "%s%s-%s",
+ battery->priv->icon_prefix,
+ xfpm_battery_get_icon_index (kind, percentage),
+ "charging");
+ break;
+
+ case UP_DEVICE_STATE_DISCHARGING:
+ case UP_DEVICE_STATE_PENDING_DISCHARGE:
+ g_snprintf (icon_name, sizeof (icon_name), "%s%s",
+ battery->priv->icon_prefix,
+ xfpm_battery_get_icon_index (kind, percentage));
+ break;
+
+ case UP_DEVICE_STATE_EMPTY:
+ g_snprintf (icon_name, sizeof (icon_name), "%s%s",
+ battery->priv->icon_prefix,
+ battery->priv->ac_online ? "000-charging" : "000");
+ break;
+
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ }
}
else
{
- if ( !battery->priv->present || battery->priv->state == XFPM_DEVICE_STATE_EMPTY )
- {
- g_snprintf (icon_name, 128, "%s-000", battery->priv->icon_prefix);
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_FULLY_CHARGED )
- {
- g_snprintf (icon_name, 128, "%s-100", battery->priv->icon_prefix);
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_DISCHARGING )
- {
- g_snprintf (icon_name, 128, "%s-%s",
- battery->priv->icon_prefix,
- xfpm_battery_get_icon_index (battery->priv->type, battery->priv->percentage));
- }
+ if (!present || state == UP_DEVICE_STATE_EMPTY)
+ {
+ g_snprintf (icon_name, sizeof (icon_name), "%s-000",
+ battery->priv->icon_prefix);
+ }
+ else if (state == XFPM_DEVICE_STATE_FULLY_CHARGED)
+ {
+ g_snprintf (icon_name, sizeof (icon_name), "%s-100",
+ battery->priv->icon_prefix);
+ }
+ else if (state == XFPM_DEVICE_STATE_DISCHARGING)
+ {
+ g_snprintf (icon_name, sizeof (icon_name), "%s-%s",
+ battery->priv->icon_prefix,
+ xfpm_battery_get_icon_index (kind, percentage));
+ }
}
-
+
gtk_status_icon_set_from_icon_name (GTK_STATUS_ICON (battery), icon_name);
}
@@ -339,30 +372,31 @@ static void
xfpm_battery_notify (XfpmBattery *battery)
{
gchar *message = NULL;
-
+
message = xfpm_battery_get_message_from_battery_state (battery);
-
+
if ( !message )
- return;
-
- xfpm_notify_show_notification (battery->priv->notify,
- _("Power Manager"),
- message,
- gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
- 8000,
- FALSE,
- XFPM_NOTIFY_NORMAL,
- GTK_STATUS_ICON (battery));
-
+ return;
+
+ xfpm_notify_show_notification (battery->priv->notify,
+ _("Power Manager"),
+ message,
+ gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
+ 8000,
+ FALSE,
+ XFPM_NOTIFY_NORMAL,
+ GTK_STATUS_ICON (battery));
+
g_free (message);
}
static gboolean
xfpm_battery_notify_idle (gpointer data)
{
- XfpmBattery *battery;
- battery = XFPM_BATTERY (data);
+ XfpmBattery *battery = XFPM_BATTERY (data);
+
xfpm_battery_notify (battery);
+
return FALSE;
}
@@ -371,27 +405,30 @@ xfpm_battery_notify_state (XfpmBattery *battery)
{
gboolean notify;
static gboolean starting_up = TRUE;
-
+ UpDeviceKind kind;
+
if ( !gtk_status_icon_get_visible (GTK_STATUS_ICON (battery)) )
- return;
+ return;
- if ( battery->priv->type == XFPM_DEVICE_TYPE_BATTERY ||
- battery->priv->type == XFPM_DEVICE_TYPE_UPS )
+ if ( starting_up )
{
- if ( starting_up )
- {
- starting_up = FALSE;
- return;
- }
+ starting_up = FALSE;
+ return;
+ }
- g_object_get (G_OBJECT (battery->priv->conf),
- GENERAL_NOTIFICATION_CFG, ¬ify,
- NULL);
-
- if ( notify )
- {
- g_idle_add ((GSourceFunc) xfpm_battery_notify_idle, battery);
- }
+ g_object_get (battery->device, "kind", &kind, NULL);
+
+ if ( kind == XFPM_DEVICE_TYPE_BATTERY || kind == XFPM_DEVICE_TYPE_UPS )
+ {
+
+ g_object_get (G_OBJECT (battery->priv->conf),
+ GENERAL_NOTIFICATION_CFG, ¬ify,
+ NULL);
+
+ if ( notify )
+ {
+ g_idle_add ((GSourceFunc) xfpm_battery_notify_idle, battery);
+ }
}
}
@@ -402,87 +439,108 @@ static void
xfpm_battery_set_tooltip_primary (XfpmBattery *battery, GtkTooltip *tooltip)
{
gchar *tip;
- gchar *est_time_str = NULL;
- gchar *power_status = NULL;
-
- power_status = g_strdup_printf (battery->priv->ac_online ? _("Adaptor is online") : _("System is running on battery power"));
-
- if ( battery->priv->state == XFPM_DEVICE_STATE_FULLY_CHARGED )
- {
- if ( battery->priv->time_to_empty > 0 )
- {
- est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_empty);
- tip = g_strdup_printf (_("%s\nYour %s is fully charged (%i%%).\nProvides %s runtime"),
- power_status,
- battery->priv->battery_name,
- battery->priv->percentage,
- est_time_str);
- g_free (est_time_str);
- }
- else
- {
- tip = g_strdup_printf (_("%s\nYour %s is fully charged (%i%%)."),
- power_status,
- battery->priv->battery_name,
- battery->priv->percentage);
- }
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_CHARGING )
- {
- if ( battery->priv->time_to_full != 0 )
- {
- est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_full);
- tip = g_strdup_printf (_("%s\nYour %s is charging (%i%%)\n%s until is fully charged."),
- power_status,
- battery->priv->battery_name,
- battery->priv->percentage,
- est_time_str);
- g_free (est_time_str);
- }
- else
- {
- tip = g_strdup_printf (_("%s\nYour %s is charging (%i%%)."),
- power_status,
- battery->priv->battery_name,
- battery->priv->percentage);
- }
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_DISCHARGING )
- {
- if ( battery->priv->time_to_empty != 0 )
- {
- est_time_str = xfpm_battery_get_time_string (battery->priv->time_to_empty);
- tip = g_strdup_printf (_("%s\nYour %s is discharging (%i%%)\nEstimated time left is %s."),
- power_status,
- battery->priv->battery_name,
- battery->priv->percentage,
- est_time_str);
- g_free (est_time_str);
- }
- else
- {
- tip = g_strdup_printf (_("%s\nYour %s is discharging (%i%%)."),
- power_status,
- battery->priv->battery_name,
- battery->priv->percentage);
- }
-
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_PENDING_CHARGING )
- {
- tip = g_strdup_printf (_("%s\n%s waiting to discharge (%i%%)."), power_status, battery->priv->battery_name, battery->priv->percentage);
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_PENDING_DISCHARGING )
- {
- tip = g_strdup_printf (_("%s\n%s waiting to charge (%i%%)."), power_status, battery->priv->battery_name, battery->priv->percentage);
- }
- else if ( battery->priv->state == XFPM_DEVICE_STATE_EMPTY )
- {
- tip = g_strdup_printf (_("%s\nYour %s is empty"), power_status, battery->priv->battery_name);
+ gchar *est_time_str;
+ const gchar *power_status;
+ UpDeviceState state;
+ gdouble percentage;
+ gint64 time_to_empty;
+ gint64 time_to_full;
+
+ g_object_get (battery->device,
+ "state", &state,
+ "percentage", &percentage,
+ "time-to-empty", &time_to_empty,
+ "time-to-full", &time_to_full,
+ NULL);
+
+ if ( battery->priv->ac_online )
+ power_status = _("Adaptor is online");
+ else
+ power_status = _("System is running on battery power");
+
+ if ( state == UP_DEVICE_STATE_FULLY_CHARGED )
+ {
+ if ( time_to_empty > 0 )
+ {
+ est_time_str = xfpm_battery_get_time_string (time_to_empty);
+ tip = g_strdup_printf (_("%s\nYour %s is fully charged (%i%%).\nProvides %s runtime"),
+ power_status,
+ battery->priv->battery_name,
+ percentage,
+ est_time_str);
+ g_free (est_time_str);
+ }
+ else
+ {
+ tip = g_strdup_printf (_("%s\nYour %s is fully charged (%i%%)."),
+ power_status,
+ battery->priv->battery_name,
+ percentage);
+ }
}
-
+ else if ( state == UP_DEVICE_STATE_CHARGING )
+ {
+ if ( time_to_full > 0 )
+ {
+ est_time_str = xfpm_battery_get_time_string (time_to_full);
+ tip = g_strdup_printf (_("%s\nYour %s is charging (%i%%)\n%s until is fully charged."),
+ power_status,
+ battery->priv->battery_name,
+ percentage,
+ est_time_str);
+ g_free (est_time_str);
+ }
+ else
+ {
+ tip = g_strdup_printf (_("%s\nYour %s is charging (%i%%)."),
+ power_status,
+ battery->priv->battery_name,
+ percentage);
+ }
+ }
+ else if ( state == UP_DEVICE_STATE_DISCHARGING )
+ {
+ if ( time_to_empty > 0 )
+ {
+ est_time_str = xfpm_battery_get_time_string (time_to_empty);
+ tip = g_strdup_printf (_("%s\nYour %s is discharging (%i%%)\nEstimated time left is %s."),
+ power_status,
+ battery->priv->battery_name,
+ percentage,
+ est_time_str);
+ g_free (est_time_str);
+ }
+ else
+ {
+ tip = g_strdup_printf (_("%s\nYour %s is discharging (%i%%)."),
+ power_status,
+ battery->priv->battery_name,
+ percentage);
+ }
+
+ }
+ else if ( state == UP_DEVICE_STATE_PENDING_CHARGING )
+ {
+ tip = g_strdup_printf (_("%s\n%s waiting to discharge (%i%%)."),
+ power_status, battery->priv->battery_name,
+ percentage);
+ }
+ else if ( state == UP_DEVICE_STATE_PENDING_DISCHARGING )
+ {
+ tip = g_strdup_printf (_("%s\n%s waiting to charge (%i%%)."),
+ power_status,
+ battery->priv->battery_name,
+ percentage);
+ }
+ else
+ {
+ tip = g_strdup_printf (_("%s\nYour %s is empty"),
+ power_status,
+ battery->priv->battery_name);
+ }
+
gtk_tooltip_set_text (tooltip, tip);
- g_free (power_status);
+
g_free (tip);
}
@@ -491,142 +549,133 @@ xfpm_battery_check_charge (XfpmBattery *battery)
{
XfpmBatteryCharge charge;
guint critical_level, low_level;
-
+
g_object_get (G_OBJECT (battery->priv->conf),
- CRITICAL_POWER_LEVEL, &critical_level,
- NULL);
-
+ CRITICAL_POWER_LEVEL, &critical_level,
+ NULL);
+
low_level = critical_level + 10;
-
+
if ( battery->priv->percentage > low_level )
- charge = XFPM_BATTERY_CHARGE_OK;
+ charge = XFPM_BATTERY_CHARGE_OK;
else if ( battery->priv->percentage <= low_level && battery->priv->percentage > critical_level )
- charge = XFPM_BATTERY_CHARGE_LOW;
+ charge = XFPM_BATTERY_CHARGE_LOW;
else if ( battery->priv->percentage <= critical_level )
- charge = XFPM_BATTERY_CHARGE_CRITICAL;
-
+ charge = XFPM_BATTERY_CHARGE_CRITICAL;
+
if ( charge != battery->priv->charge)
{
- battery->priv->charge = charge;
- /*
- * only emit signal when when battery charge changes from ok->low->critical
- * and not the other way round.
- */
- if ( battery->priv->charge != XFPM_BATTERY_CHARGE_CRITICAL || charge != XFPM_BATTERY_CHARGE_LOW )
- g_signal_emit (G_OBJECT (battery), signals [BATTERY_CHARGE_CHANGED], 0);
+ battery->priv->charge = charge;
+ /*
+ * only emit signal when when battery charge changes from ok->low->critical
+ * and not the other way round.
+ */
+ if ( battery->priv->charge != XFPM_BATTERY_CHARGE_CRITICAL || charge != XFPM_BATTERY_CHARGE_LOW )
+ g_signal_emit (G_OBJECT (battery), signals [BATTERY_CHARGE_CHANGED], 0);
}
}
static void
-xfpm_battery_refresh (XfpmBattery *battery, GHashTable *props)
+xfpm_battery_button_pressed_cb (XfpmButton *button, XfpmButtonKey type, XfpmBattery *battery)
{
- GValue *value;
- guint state;
-
+ if (type == BUTTON_BATTERY)
+ xfpm_battery_notify (battery);
+}
+
+static void
+xfpm_battery_changed_cb (UpDevice *device, XfpmBattery *battery)
+{
+ gboolean is_present;
+
+
+ g_return_if_fail (battery->device == device);
+
+ g_object_get (battery->device,
+ "is-present", &is_present,
+ NULL);
+
value = g_hash_table_lookup (props, "IsPresent");
-
+
if ( value == NULL )
{
- g_warning ("No 'IsPresent' property found");
- goto out;
+ g_warning ("No 'IsPresent' property found");
+ goto out;
}
-
- battery->priv->present = g_value_get_boolean (value);
-
+
+ battery->priv->present = is_present;
+
value = g_hash_table_lookup (props, "State");
-
+
if ( value == NULL )
{
- g_warning ("No 'State' property found");
+ g_warning ("No 'State' property found");
}
-
+
state = g_value_get_uint (value);
if ( state != battery->priv->state )
{
- battery->priv->state = state;
- xfpm_battery_refresh_visible (battery);
- xfpm_battery_notify_state (battery);
+ battery->priv->state = state;
+ xfpm_battery_refresh_visible (battery);
+ xfpm_battery_notify_state (battery);
}
-
+
value = g_hash_table_lookup (props, "Percentage");
-
+
if ( value == NULL )
{
- g_warning ("No 'Percentage' property found on battery device");
- goto out;
+ g_warning ("No 'Percentage' property found on battery device");
+ goto out;
}
-
+
battery->priv->percentage = (guint) g_value_get_double (value);
-
+
xfpm_battery_check_charge (battery);
-
+
xfpm_battery_refresh_icon (battery);
-
+
if ( battery->priv->type == XFPM_DEVICE_TYPE_BATTERY ||
- battery->priv->type == XFPM_DEVICE_TYPE_UPS )
- {
- value = g_hash_table_lookup (props, "TimeToEmpty");
-
- if ( value == NULL )
- {
- g_warning ("No 'TimeToEmpty' property found on battery device");
- goto out;
- }
-
- battery->priv->time_to_empty = g_value_get_int64 (value);
-
- value = g_hash_table_lookup (props, "TimeToFull");
-
- if ( value == NULL )
- {
- g_warning ("No 'TimeToFull' property found on battery device");
- goto out;
- }
-
- battery->priv->time_to_full = g_value_get_int64 (value);
- }
-
- out:
- g_hash_table_destroy (props);
-}
+ battery->priv->type == XFPM_DEVICE_TYPE_UPS )
+ {
+ value = g_hash_table_lookup (props, "TimeToEmpty");
-static void
-xfpm_battery_button_pressed_cb (XfpmButton *button, XfpmButtonKey type, XfpmBattery *battery)
-{
- if (type == BUTTON_BATTERY)
- xfpm_battery_notify (battery);
-}
+ if ( value == NULL )
+ {
+ g_warning ("No 'TimeToEmpty' property found on battery device");
+ goto out;
+ }
-static void
-xfpm_battery_changed_cb (DBusGProxy *proxy, XfpmBattery *battery)
-{
- GHashTable *props;
-
- props = xfpm_power_get_interface_properties (battery->priv->proxy_prop,
- UPOWER_IFACE_DEVICE);
-
- if ( props )
- xfpm_battery_refresh (battery, props);
+ battery->priv->time_to_empty = g_value_get_int64 (value);
+
+ value = g_hash_table_lookup (props, "TimeToFull");
+
+ if ( value == NULL )
+ {
+ g_warning ("No 'TimeToFull' property found on battery device");
+ goto out;
+ }
+
+ battery->priv->time_to_full = g_value_get_int64 (value);
+ }
}
static gboolean
-xfpm_battery_query_tooltip (GtkStatusIcon *icon,
- gint x,
- gint y,
- gboolean keyboard_mode,
- GtkTooltip *tooltip)
+xfpm_battery_query_tooltip (GtkStatusIcon *icon,
+ gint x,
+ gint y,
+ gboolean keyboard_mode,
+ GtkTooltip *tooltip)
{
XfpmBattery *battery;
-
+
battery = XFPM_BATTERY (icon);
if ( battery->priv->type == XFPM_DEVICE_TYPE_BATTERY ||
- battery->priv->type == XFPM_DEVICE_TYPE_UPS )
+ battery->priv->type == XFPM_DEVICE_TYPE_UPS )
{
- xfpm_battery_set_tooltip_primary (battery, tooltip);
- return TRUE;
+ xfpm_battery_set_tooltip_primary (battery, tooltip);
+ return TRUE;
}
-
+
return FALSE;
}
@@ -637,48 +686,48 @@ xfpm_battery_tray_icon_settings_changed (GObject *obj, GParamSpec *spec, XfpmBat
}
static void xfpm_battery_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
XfpmBattery *battery;
-
+
battery = XFPM_BATTERY (object);
-
+
switch (prop_id)
{
- case PROP_AC_ONLINE:
- g_value_set_boolean (value, battery->priv->ac_online);
- break;
- case PROP_DEVICE_TYPE:
- g_value_set_enum (value, battery->priv->type);
- break;
- case PROP_CHARGE_STATUS:
- g_value_set_enum (value, battery->priv->charge);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ case PROP_AC_ONLINE:
+ g_value_set_boolean (value, battery->priv->ac_online);
+ break;
+ case PROP_DEVICE_TYPE:
+ g_value_set_enum (value, battery->priv->type);
+ break;
+ case PROP_CHARGE_STATUS:
+ g_value_set_enum (value, battery->priv->charge);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void xfpm_battery_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
XfpmBattery *battery;
-
+
battery = XFPM_BATTERY (object);
-
+
switch (prop_id)
{
- case PROP_AC_ONLINE:
- battery->priv->ac_online = g_value_get_boolean (value);
- xfpm_battery_refresh_icon (battery);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ case PROP_AC_ONLINE:
+ battery->priv->ac_online = g_value_get_boolean (value);
+ xfpm_battery_refresh_icon (battery);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
@@ -695,8 +744,8 @@ xfpm_battery_class_init (XfpmBatteryClass *klass)
object_class->set_property = xfpm_battery_set_property;
status_icon_class->query_tooltip = xfpm_battery_query_tooltip;
-
- signals [BATTERY_CHARGE_CHANGED] =
+
+ signals [BATTERY_CHARGE_CHANGED] =
g_signal_new ("battery-charge-changed",
XFPM_TYPE_BATTERY,
G_SIGNAL_RUN_LAST,
@@ -704,7 +753,7 @@ xfpm_battery_class_init (XfpmBatteryClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
-
+
g_object_class_install_property (object_class,
PROP_AC_ONLINE,
g_param_spec_boolean("ac-online",
@@ -716,16 +765,16 @@ xfpm_battery_class_init (XfpmBatteryClass *klass)
PROP_DEVICE_TYPE,
g_param_spec_enum ("device-type",
NULL, NULL,
- XFPM_TYPE_DEVICE_TYPE,
- XFPM_DEVICE_TYPE_UNKNOWN,
+ XFPM_TYPE_DEVICE_TYPE,
+ XFPM_DEVICE_TYPE_UNKNOWN,
G_PARAM_READABLE));
g_object_class_install_property (object_class,
PROP_CHARGE_STATUS,
g_param_spec_enum ("charge-status",
NULL, NULL,
- XFPM_TYPE_BATTERY_CHARGE,
- XFPM_BATTERY_CHARGE_UNKNOWN,
+ XFPM_TYPE_BATTERY_CHARGE,
+ XFPM_BATTERY_CHARGE_UNKNOWN,
G_PARAM_READABLE));
g_type_class_add_private (klass, sizeof (XfpmBatteryPrivate));
@@ -735,10 +784,9 @@ static void
xfpm_battery_init (XfpmBattery *battery)
{
battery->priv = XFPM_BATTERY_GET_PRIVATE (battery);
-
+
battery->priv->conf = xfpm_xfconf_new ();
battery->priv->notify = xfpm_notify_new ();
- battery->priv->proxy_prop = NULL;
battery->priv->state = XFPM_DEVICE_STATE_UNKNOWN;
battery->priv->type = XFPM_DEVICE_TYPE_UNKNOWN;
battery->priv->charge = XFPM_BATTERY_CHARGE_UNKNOWN;
@@ -747,38 +795,33 @@ xfpm_battery_init (XfpmBattery *battery)
battery->priv->time_to_empty = 0;
battery->priv->button = xfpm_button_new ();
battery->priv->ac_online = TRUE;
-
+
battery->priv->sig = g_signal_connect (G_OBJECT (battery->priv->conf), "notify::" SHOW_TRAY_ICON_CFG,
- G_CALLBACK (xfpm_battery_tray_icon_settings_changed), battery);
-
-
+ G_CALLBACK (xfpm_battery_tray_icon_settings_changed), battery);
+
+
battery->priv->sig_bt = g_signal_connect (G_OBJECT (battery->priv->button), "button-pressed",
- G_CALLBACK (xfpm_battery_button_pressed_cb), battery);
+ G_CALLBACK (xfpm_battery_button_pressed_cb), battery);
}
static void
xfpm_battery_finalize (GObject *object)
{
- XfpmBattery *battery;
+ XfpmBattery *battery = XFPM_BATTERY (object);
+
+ g_signal_handlers_disconnect_by_func (battery->priv->device,
+ G_CALLBACK (xfpm_battery_changed_cb), battery);
- battery = XFPM_BATTERY (object);
-
- g_free (battery->priv->icon_prefix);
-
- dbus_g_proxy_disconnect_signal (battery->priv->proxy, "Changed",
- G_CALLBACK (xfpm_battery_changed_cb), battery);
-
if ( g_signal_handler_is_connected (battery->priv->conf, battery->priv->sig ) )
- g_signal_handler_disconnect (G_OBJECT (battery->priv->conf), battery->priv->sig);
-
+ g_signal_handler_disconnect (G_OBJECT (battery->priv->conf), battery->priv->sig);
+
if ( g_signal_handler_is_connected (battery->priv->button, battery->priv->sig_bt ) )
- g_signal_handler_disconnect (G_OBJECT (battery->priv->button), battery->priv->sig_bt);
-
- g_object_unref (battery->priv->proxy);
- g_object_unref (battery->priv->proxy_prop);
+ g_signal_handler_disconnect (G_OBJECT (battery->priv->button), battery->priv->sig_bt);
+
g_object_unref (battery->priv->conf);
g_object_unref (battery->priv->notify);
g_object_unref (battery->priv->button);
+ g_object_unref (battery->priv->device);
G_OBJECT_CLASS (xfpm_battery_parent_class)->finalize (object);
}
@@ -788,25 +831,25 @@ xfpm_battery_get_icon_prefix_device_enum_type (XfpmDeviceType type)
{
if ( type == XFPM_DEVICE_TYPE_BATTERY )
{
- return g_strdup (XFPM_PRIMARY_ICON_PREFIX);
+ return g_strdup (XFPM_PRIMARY_ICON_PREFIX);
}
- else if ( type == XFPM_DEVICE_TYPE_UPS )
+ else if ( type == XFPM_DEVICE_TYPE_UPS )
{
- return g_strdup (XFPM_UPS_ICON_PREFIX);
+ return g_strdup (XFPM_UPS_ICON_PREFIX);
}
- else if ( type == XFPM_DEVICE_TYPE_MOUSE )
+ else if ( type == XFPM_DEVICE_TYPE_MOUSE )
{
- return g_strdup (XFPM_MOUSE_ICON_PREFIX);
+ return g_strdup (XFPM_MOUSE_ICON_PREFIX);
}
- else if ( type == XFPM_DEVICE_TYPE_KBD )
+ else if ( type == XFPM_DEVICE_TYPE_KBD )
{
- return g_strdup (XFPM_KBD_ICON_PREFIX);
+ return g_strdup (XFPM_KBD_ICON_PREFIX);
}
- else if ( type == XFPM_DEVICE_TYPE_PHONE )
+ else if ( type == XFPM_DEVICE_TYPE_PHONE )
{
- return g_strdup (XFPM_PHONE_ICON_PREFIX);
+ return g_strdup (XFPM_PHONE_ICON_PREFIX);
}
-
+
return g_strdup (XFPM_PRIMARY_ICON_PREFIX);
}
@@ -814,67 +857,67 @@ static const gchar *
xfpm_battery_get_name (XfpmDeviceType type)
{
const gchar *name = NULL;
-
+
switch (type)
{
- case XFPM_DEVICE_TYPE_BATTERY:
- name = _("battery");
- break;
- case XFPM_DEVICE_TYPE_UPS:
- name = _("UPS");
- break;
- case XFPM_DEVICE_TYPE_MONITOR:
- name = _("monitor battery");
- break;
- case XFPM_DEVICE_TYPE_MOUSE:
- name = _("mouse battery");
- break;
- case XFPM_DEVICE_TYPE_KBD:
- name = _("keyboard battery");
- break;
- case XFPM_DEVICE_TYPE_PDA:
- name = _("PDA battery");
- break;
- case XFPM_DEVICE_TYPE_PHONE:
- name = _("Phone battery");
- break;
- default:
- name = _("Unknown");
- break;
+ case XFPM_DEVICE_TYPE_BATTERY:
+ name = _("battery");
+ break;
+ case XFPM_DEVICE_TYPE_UPS:
+ name = _("UPS");
+ break;
+ case XFPM_DEVICE_TYPE_MONITOR:
+ name = _("monitor battery");
+ break;
+ case XFPM_DEVICE_TYPE_MOUSE:
+ name = _("mouse battery");
+ break;
+ case XFPM_DEVICE_TYPE_KBD:
+ name = _("keyboard battery");
+ break;
+ case XFPM_DEVICE_TYPE_PDA:
+ name = _("PDA battery");
+ break;
+ case XFPM_DEVICE_TYPE_PHONE:
+ name = _("Phone battery");
+ break;
+ default:
+ name = _("Unknown");
+ break;
}
-
+
return name;
}
GtkStatusIcon *
-xfpm_battery_new (void)
+xfpm_battery_new (UpDevice *device)
{
XfpmBattery *battery = NULL;
-
+
battery = g_object_new (XFPM_TYPE_BATTERY, NULL);
-
+
+ battery->device = g_object_ref (device);
+ g_signal_connect (device, "changed",
+ G_CALLBACK (xfpm_battery_changed_cb), battery);
+
return GTK_STATUS_ICON (battery);
}
void xfpm_battery_monitor_device (XfpmBattery *battery,
- DBusGProxy *proxy,
- DBusGProxy *proxy_prop,
- XfpmDeviceType device_type)
+ DBusGProxy *proxy,
+ DBusGProxy *proxy_prop,
+ XfpmDeviceType device_type)
{
battery->priv->type = device_type;
battery->priv->proxy_prop = proxy_prop;
battery->priv->proxy = proxy;
battery->priv->icon_prefix = xfpm_battery_get_icon_prefix_device_enum_type (device_type);
battery->priv->battery_name = xfpm_battery_get_name (device_type);
-
-
- dbus_g_proxy_add_signal (proxy, "Changed", G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (proxy, "Changed",
- G_CALLBACK (xfpm_battery_changed_cb), battery, NULL);
+
g_object_set (G_OBJECT (battery),
- "has-tooltip", TRUE,
- NULL);
+ "has-tooltip", TRUE,
+ NULL);
xfpm_battery_changed_cb (proxy, battery);
}
@@ -882,27 +925,27 @@ void xfpm_battery_monitor_device (XfpmBattery *battery,
XfpmDeviceType xfpm_battery_get_device_type (XfpmBattery *battery)
{
g_return_val_if_fail (XFPM_IS_BATTERY (battery), XFPM_DEVICE_TYPE_UNKNOWN );
-
+
return battery->priv->type;
}
XfpmBatteryCharge xfpm_battery_get_charge (XfpmBattery *battery)
{
g_return_val_if_fail (XFPM_IS_BATTERY (battery), XFPM_BATTERY_CHARGE_UNKNOWN);
-
+
return battery->priv->charge;
}
const gchar *xfpm_battery_get_battery_name (XfpmBattery *battery)
{
g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
-
+
return battery->priv->battery_name;
}
gchar *xfpm_battery_get_time_left (XfpmBattery *battery)
{
g_return_val_if_fail (XFPM_IS_BATTERY (battery), NULL);
-
+
return xfpm_battery_get_time_string (battery->priv->time_to_empty);
}
diff --git a/src/xfpm-battery.h b/src/xfpm-battery.h
index 4d4ca34..fdc5f04 100644
--- a/src/xfpm-battery.h
+++ b/src/xfpm-battery.h
@@ -53,12 +53,9 @@ typedef struct
GType xfpm_battery_get_type (void) G_GNUC_CONST;
-GtkStatusIcon *xfpm_battery_new (void);
+GtkStatusIcon *xfpm_battery_new (UpDevice *device);
-void xfpm_battery_monitor_device (XfpmBattery *battery,
- DBusGProxy *proxy,
- DBusGProxy *proxy_prop,
- XfpmDeviceType device_type);
+void xfpm_battery_monitor_device (XfpmBattery *battery);
XfpmDeviceType xfpm_battery_get_device_type (XfpmBattery *battery);
diff --git a/src/xfpm-console-kit.c b/src/xfpm-console-kit.c
deleted file mode 100644
index cbf9784..0000000
--- a/src/xfpm-console-kit.c
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <dbus/dbus-glib.h>
-
-#include "xfpm-console-kit.h"
-#include "xfpm-dbus-monitor.h"
-
-
-static void xfpm_console_kit_finalize (GObject *object);
-
-static void xfpm_console_kit_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-#define XFPM_CONSOLE_KIT_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_CONSOLE_KIT, XfpmConsoleKitPrivate))
-
-struct XfpmConsoleKitPrivate
-{
- DBusGConnection *bus;
- DBusGProxy *proxy;
-
- XfpmDBusMonitor *monitor;
-
- gboolean can_shutdown;
- gboolean can_restart;
-};
-
-enum
-{
- PROP_0,
- PROP_CAN_RESTART,
- PROP_CAN_SHUTDOWN
-};
-
-G_DEFINE_TYPE (XfpmConsoleKit, xfpm_console_kit, G_TYPE_OBJECT)
-
-static void
-xfpm_console_kit_get_info (XfpmConsoleKit *console)
-{
- GError *error = NULL;
-
- dbus_g_proxy_call (console->priv->proxy, "CanStop", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &console->priv->can_shutdown,
- G_TYPE_INVALID);
-
- if ( error )
- {
- g_warning ("'CanStop' method failed : %s", error->message);
- g_error_free (error);
- error = NULL;
- }
-
- dbus_g_proxy_call (console->priv->proxy, "CanRestart", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &console->priv->can_restart,
- G_TYPE_INVALID);
-
- if ( error )
- {
- g_warning ("'CanRestart' method failed : %s", error->message);
- g_error_free (error);
- error = NULL;
- }
-
-}
-
-static void
-xfpm_console_kit_class_init (XfpmConsoleKitClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = xfpm_console_kit_finalize;
-
- object_class->get_property = xfpm_console_kit_get_property;
-
- g_object_class_install_property (object_class,
- PROP_CAN_RESTART,
- g_param_spec_boolean ("can-restart",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CAN_SHUTDOWN,
- g_param_spec_boolean ("can-shutdown",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_type_class_add_private (klass, sizeof (XfpmConsoleKitPrivate));
-}
-
-static void
-xfpm_console_kit_init (XfpmConsoleKit *console)
-{
- GError *error = NULL;
-
- console->priv = XFPM_CONSOLE_KIT_GET_PRIVATE (console);
- console->priv->can_shutdown = FALSE;
- console->priv->can_restart = FALSE;
-
- console->priv->bus = NULL;
- console->priv->proxy = NULL;
-
- console->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
-
- if ( error )
- {
- g_critical ("Unable to get system bus connection : %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- console->priv->proxy = dbus_g_proxy_new_for_name_owner (console->priv->bus,
- "org.freedesktop.ConsoleKit",
- "/org/freedesktop/ConsoleKit/Manager",
- "org.freedesktop.ConsoleKit.Manager",
- NULL);
-
- if ( !console->priv->proxy )
- {
- g_warning ("Unable to create proxy for 'org.freedesktop.ConsoleKit'");
- goto out;
- }
-
- xfpm_console_kit_get_info (console);
-
-out:
- ;
-}
-
-static void xfpm_console_kit_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- XfpmConsoleKit *console;
- console = XFPM_CONSOLE_KIT (object);
-
- switch (prop_id)
- {
- case PROP_CAN_SHUTDOWN:
- g_value_set_boolean (value, console->priv->can_shutdown);
- break;
- case PROP_CAN_RESTART:
- g_value_set_boolean (value, console->priv->can_restart);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-xfpm_console_kit_finalize (GObject *object)
-{
- XfpmConsoleKit *console;
-
- console = XFPM_CONSOLE_KIT (object);
-
- if ( console->priv->bus )
- dbus_g_connection_unref (console->priv->bus);
-
- if ( console->priv->proxy )
- g_object_unref (console->priv->proxy);
-
- G_OBJECT_CLASS (xfpm_console_kit_parent_class)->finalize (object);
-}
-
-XfpmConsoleKit *
-xfpm_console_kit_new (void)
-{
- static gpointer console_obj = NULL;
-
- if ( G_LIKELY (console_obj != NULL ) )
- {
- g_object_ref (console_obj);
- }
- else
- {
- console_obj = g_object_new (XFPM_TYPE_CONSOLE_KIT, NULL);
- g_object_add_weak_pointer (console_obj, &console_obj);
- }
-
- return XFPM_CONSOLE_KIT (console_obj);
-}
-
-void xfpm_console_kit_shutdown (XfpmConsoleKit *console, GError **error)
-{
- g_return_if_fail (console->priv->proxy != NULL );
-
- dbus_g_proxy_call (console->priv->proxy, "Stop", error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &console->priv->can_shutdown,
- G_TYPE_INVALID);
-}
-
-void xfpm_console_kit_reboot (XfpmConsoleKit *console, GError **error)
-{
- g_return_if_fail (console->priv->proxy != NULL );
-
- dbus_g_proxy_call (console->priv->proxy, "Restart", error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &console->priv->can_shutdown,
- G_TYPE_INVALID);
-
-}
diff --git a/src/xfpm-console-kit.h b/src/xfpm-console-kit.h
deleted file mode 100644
index 42bf420..0000000
--- a/src/xfpm-console-kit.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef __XFPM_CONSOLE_KIT_H
-#define __XFPM_CONSOLE_KIT_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define XFPM_TYPE_CONSOLE_KIT (xfpm_console_kit_get_type () )
-#define XFPM_CONSOLE_KIT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XFPM_TYPE_CONSOLE_KIT, XfpmConsoleKit))
-#define XFPM_IS_CONSOLE_KIT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XFPM_TYPE_CONSOLE_KIT))
-
-typedef struct XfpmConsoleKitPrivate XfpmConsoleKitPrivate;
-
-typedef struct
-{
- GObject parent;
- XfpmConsoleKitPrivate *priv;
-
-} XfpmConsoleKit;
-
-typedef struct
-{
- GObjectClass parent_class;
-
-} XfpmConsoleKitClass;
-
-GType xfpm_console_kit_get_type (void) G_GNUC_CONST;
-
-XfpmConsoleKit *xfpm_console_kit_new (void);
-
-void xfpm_console_kit_shutdown (XfpmConsoleKit *console,
- GError **error);
-
-void xfpm_console_kit_reboot (XfpmConsoleKit *console,
- GError **error);
-
-G_END_DECLS
-
-#endif /* __XFPM_CONSOLE_KIT_H */
diff --git a/src/xfpm-dbus-service-infos.xml b/src/xfpm-dbus-service-infos.xml
new file mode 100644
index 0000000..d3cee21
--- /dev/null
+++ b/src/xfpm-dbus-service-infos.xml
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+-->
+
+<node name="/org/xfce/PowerManager">
+ <!--
+ org.xfce.PowerManager
+
+ The public power management interface.
+ -->
+ <interface name="org.xfce.PowerManager">
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="xfpm_dbus_service" />
+
+ <!--
+ Suspend () : VOID
+
+ Try to suspend the system.
+ -->
+ <method name="Suspend">
+ </method>
+
+ <!--
+ Hibernate () : VOID
+
+ Try to hibernate the system.
+ -->
+ <method name="Hibernate">
+ </method>
+
+ <!--
+ CanSuspend () : BOOLEAN
+
+ Queries if the system has support for suspend and the
+ user has enough permissions to do so.
+
+ Return TRUE if the user can suspend the system, FALSE otherwise.
+ -->
+ <method name="CanSuspend">
+ <arg type="b" name="can_suspend" direction="out"/>
+ </method>
+
+ <!--
+ CanHibernate () : BOOLEAN
+
+ Queries if the system has support for hibernation and the
+ user has enough permissions to do so.
+
+ Return TRUE if the user can hibernate the system, FALSE otherwise.
+ -->
+ <method name="CanHibernate">
+ <arg type="b" name="can_hibernate" direction="out"/>
+ </method>
+
+ <!--
+ GetOnBattery () : BOOLEAN
+
+ Queries if the system is running on a battery.
+
+ Return TRUE if the system is battery powered, FALSE otherwise.
+ -->
+ <method name="GetOnBattery">
+ <arg type="b" name="on_battery" direction="out"/>
+ </method>
+
+ <!--
+ GetLowBattery () : BOOLEAN
+
+ Queries if the battery percentage is low.
+ -->
+ <method name="GetLowBattery">
+ <arg type="b" name="low_battery" direction="out"/>
+ </method>
+
+ <!--
+ OnBatteryChanged (on_battery : BOOLEAN)
+
+ Signal that is triggered if the state changes.
+ -->
+ <signal name="OnBatteryChanged">
+ <arg type="b" name="on_battery" direction="out"/>
+ </signal>
+
+ <!--
+ LowBatteryChanged (low_battery : BOOLEAN)
+
+ Signal that is triggered if the battery capacity is low.
+ -->
+ <signal name="LowBatteryChanged">
+ <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-dbus-service.c b/src/xfpm-dbus-service.c
new file mode 100644
index 0000000..810015b
--- /dev/null
+++ b/src/xfpm-dbus-service.c
@@ -0,0 +1,232 @@
+/*
+ * 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
new file mode 100644
index 0000000..96c6e7e
--- /dev/null
+++ b/src/xfpm-dbus-service.h
@@ -0,0 +1,43 @@
+/*
+ * 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-dpms.c b/src/xfpm-dpms.c
index 53f3721..8c87fc4 100644
--- a/src/xfpm-dpms.c
+++ b/src/xfpm-dpms.c
@@ -52,7 +52,6 @@ struct XfpmDpmsPrivate
XfpmPower *power;
gboolean dpms_capable;
- gboolean inhibited;
gboolean on_battery;
@@ -160,7 +159,7 @@ xfpm_dpms_refresh (XfpmDpms *dpms)
presentation_mode = (xfpm_power_get_mode (dpms->priv->power) == XFPM_POWER_MODE_PRESENTATION);
- if ( dpms->priv->inhibited || presentation_mode)
+ if (presentation_mode)
{
xfpm_dpms_disable (dpms);
return;
diff --git a/src/xfpm-enum-glib.h b/src/xfpm-enum-glib.h
index b047eb4..a6c4218 100644
--- a/src/xfpm-enum-glib.h
+++ b/src/xfpm-enum-glib.h
@@ -27,32 +27,6 @@
G_BEGIN_DECLS
-typedef enum
-{
- XFPM_DEVICE_TYPE_UNKNOWN,
- XFPM_DEVICE_TYPE_LINE_POWER,
- XFPM_DEVICE_TYPE_BATTERY,
- XFPM_DEVICE_TYPE_UPS,
- XFPM_DEVICE_TYPE_MONITOR,
- XFPM_DEVICE_TYPE_MOUSE,
- XFPM_DEVICE_TYPE_KBD,
- XFPM_DEVICE_TYPE_PDA,
- XFPM_DEVICE_TYPE_PHONE
-
-} XfpmDeviceType;
-
-typedef enum
-{
- XFPM_DEVICE_STATE_UNKNOWN,
- XFPM_DEVICE_STATE_CHARGING,
- XFPM_DEVICE_STATE_DISCHARGING,
- XFPM_DEVICE_STATE_EMPTY,
- XFPM_DEVICE_STATE_FULLY_CHARGED,
- XFPM_DEVICE_STATE_PENDING_CHARGING,
- XFPM_DEVICE_STATE_PENDING_DISCHARGING
-
-} XfpmDeviceState;
-
/*
* Order matters
*/
diff --git a/src/xfpm-main.c b/src/xfpm-main.c
index a98583b..b8e81cb 100644
--- a/src/xfpm-main.c
+++ b/src/xfpm-main.c
@@ -44,7 +44,6 @@
#include "xfpm-debug.h"
#include "xfpm-common.h"
-#include "xfce-power-manager-dbus-client.h"
#include "xfpm-manager.h"
static void G_GNUC_NORETURN
@@ -69,7 +68,7 @@ xfpm_quit_signal (gint sig, gpointer data)
if ( sig != SIGHUP )
xfpm_manager_stop (manager);
}
-
+/*
static const gchar *
xfpm_bool_to_local_string (gboolean value)
{
@@ -165,11 +164,11 @@ xfpm_dump (GHashTable *hash)
_("Has LID"),
xfpm_bool_to_local_string (has_lid));
}
-
+*/
static void
xfpm_dump_remote (DBusGConnection *bus)
{
- DBusGProxy *proxy;
+ /*DBusGProxy *proxy;
GError *error = NULL;
GHashTable *hash;
@@ -191,7 +190,7 @@ xfpm_dump_remote (DBusGConnection *bus)
}
xfpm_dump (hash);
- g_hash_table_destroy (hash);
+ g_hash_table_destroy (hash);*/
}
static void G_GNUC_NORETURN
@@ -228,10 +227,7 @@ xfpm_start (DBusGConnection *bus, const gchar *client_id, gboolean dump)
if ( dump )
{
- GHashTable *hash;
- hash = xfpm_manager_get_config (manager);
- xfpm_dump (hash);
- g_hash_table_destroy (hash);
+ //TODO
}
@@ -342,7 +338,7 @@ int main (int argc, char **argv)
dbus_g_connection_unref(bus);
return EXIT_FAILURE;
}
- xfpm_manager_dbus_client_quit (proxy , &error);
+ //xfpm_manager_dbus_client_quit (proxy , &error);
g_object_unref (proxy);
if ( error)
@@ -387,13 +383,13 @@ int main (int argc, char **argv)
return EXIT_FAILURE;
}
- if ( !xfpm_manager_dbus_client_restart (proxy, NULL) )
+ /*if ( !xfpm_manager_dbus_client_restart (proxy, NULL) )
{
g_critical ("Unable to send reload message");
g_object_unref (proxy);
dbus_g_connection_unref (bus);
return EXIT_SUCCESS;
- }
+ }*/
return EXIT_SUCCESS;
}
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index f2a4cc2..b13d49c 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -43,10 +43,8 @@
#include "xfpm-disks.h"
#include "xfpm-dpms.h"
#include "xfpm-manager.h"
-#include "xfpm-console-kit.h"
#include "xfpm-button.h"
#include "xfpm-backlight.h"
-#include "xfpm-inhibit.h"
#include "egg-idletime.h"
#include "xfpm-config.h"
#include "xfpm-debug.h"
@@ -57,12 +55,10 @@
#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) \
@@ -80,18 +76,16 @@ struct XfpmManagerPrivate
XfpmButton *button;
XfpmXfconf *conf;
XfpmBacklight *backlight;
- XfpmConsoleKit *console;
XfpmDBusMonitor *monitor;
XfpmDisks *disks;
- XfpmInhibit *inhibit;
+ XfpmDBusService *dbus_service;
EggIdletime *idle;
#ifdef HAVE_DPMS
XfpmDpms *dpms;
#endif
GTimer *timer;
-
- gboolean inhibited;
+
gboolean session_managed;
};
@@ -127,14 +121,13 @@ 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);
g_object_unref (manager->priv->client);
- g_object_unref (manager->priv->console);
g_object_unref (manager->priv->monitor);
g_object_unref (manager->priv->disks);
- g_object_unref (manager->priv->inhibit);
g_object_unref (manager->priv->idle);
g_timer_destroy (manager->priv->timer);
@@ -148,22 +141,12 @@ 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");
-
- xfpm_dbus_release_name (dbus_g_connection_get_connection(manager->priv->session_bus),
- "org.freedesktop.PowerManagement");
-}
static gboolean
xfpm_manager_quit (XfpmManager *manager)
{
XFPM_DEBUG ("Exiting");
- xfpm_manager_release_names (manager);
gtk_main_quit ();
return TRUE;
}
@@ -179,38 +162,11 @@ xfpm_manager_system_bus_connection_changed_cb (XfpmDBusMonitor *monitor, gboolea
}
}
-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") ||
- !xfpm_dbus_register_name (dbus_g_connection_get_connection (manager->priv->session_bus),
- "org.freedesktop.PowerManagement") )
- {
- 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 void
xfpm_manager_shutdown (XfpmManager *manager)
{
- GError *error = NULL;
- xfpm_console_kit_shutdown (manager->priv->console, &error );
-
- if ( error )
- {
- g_warning ("Failed to shutdown the system : %s", error->message);
- g_error_free (error);
- /* Try with the session then */
- if ( manager->priv->session_managed )
- xfce_sm_client_request_shutdown (manager->priv->client, XFCE_SM_CLIENT_SHUTDOWN_HINT_HALT);
- }
+ /* TODO */
}
static void
@@ -302,11 +258,11 @@ static void
xfpm_manager_lid_changed_cb (XfpmPower *power, gboolean lid_is_closed, XfpmManager *manager)
{
XfpmLidTriggerAction action;
- gboolean on_battery;
+ gboolean on_battery = FALSE;
- g_object_get (G_OBJECT (power),
+ /*TODOg_object_get (G_OBJECT (power),
"on-battery", &on_battery,
- NULL);
+ NULL);*/
g_object_get (G_OBJECT (manager->priv->conf),
on_battery ? LID_SWITCH_ON_BATTERY_CFG : LID_SWITCH_ON_AC_CFG, &action,
@@ -345,12 +301,6 @@ xfpm_manager_lid_changed_cb (XfpmPower *power, gboolean lid_is_closed, XfpmManag
}
static void
-xfpm_manager_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean inhibited, XfpmManager *manager)
-{
- manager->priv->inhibited = inhibited;
-}
-
-static void
xfpm_manager_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmManager *manager)
{
if (xfpm_power_get_mode (manager->priv->power) == XFPM_POWER_MODE_PRESENTATION)
@@ -363,20 +313,14 @@ xfpm_manager_alarm_timeout_cb (EggIdletime *idle, guint id, XfpmManager *manager
XfpmShutdownRequest req = XFPM_DO_NOTHING;
gchar *sleep_mode;
gboolean on_battery;
-
- if ( manager->priv->inhibited )
- {
- XFPM_DEBUG ("Idle sleep alarm timeout, but power manager is currently inhibited, action ignored");
- return;
- }
g_object_get (G_OBJECT (manager->priv->conf),
INACTIVITY_SLEEP_MODE, &sleep_mode,
NULL);
- g_object_get (G_OBJECT (manager->priv->power),
+ /* TODO g_object_get (G_OBJECT (manager->priv->power),
"on-battery", &on_battery,
- NULL);
+ NULL); */
if ( !g_strcmp0 (sleep_mode, "Suspend") )
req = XFPM_DO_SUSPEND;
@@ -499,28 +443,22 @@ xfpm_manager_new (DBusGConnection *bus, const gchar *client_id)
G_CALLBACK (xfpm_manager_quit), manager);
}
- xfpm_manager_dbus_class_init (XFPM_MANAGER_GET_CLASS (manager));
- xfpm_manager_dbus_init (manager);
-
return manager;
}
void xfpm_manager_start (XfpmManager *manager)
{
- if ( !xfpm_manager_reserve_names (manager) )
- goto out;
-
+
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 ();
- manager->priv->console = xfpm_console_kit_new ();
manager->priv->monitor = xfpm_dbus_monitor_new ();
manager->priv->disks = xfpm_disks_new ();
- manager->priv->inhibit = xfpm_inhibit_new ();
manager->priv->idle = egg_idletime_new ();
g_signal_connect (manager->priv->idle, "alarm-expired",
@@ -534,9 +472,6 @@ void xfpm_manager_start (XfpmManager *manager)
xfpm_manager_set_idle_alarm (manager);
- g_signal_connect (manager->priv->inhibit, "has-inhibit-changed",
- G_CALLBACK (xfpm_manager_inhibit_changed_cb), manager);
-
g_signal_connect (manager->priv->monitor, "system-bus-connection-changed",
G_CALLBACK (xfpm_manager_system_bus_connection_changed_cb), manager);
@@ -567,8 +502,6 @@ void xfpm_manager_start (XfpmManager *manager)
g_signal_connect_swapped (manager->priv->power, "shutdown",
G_CALLBACK (xfpm_manager_shutdown), manager);
-out:
- ;
}
void xfpm_manager_stop (XfpmManager *manager)
@@ -577,154 +510,3 @@ 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_quit (XfpmManager *manager,
- GError **error);
-
-static gboolean xfpm_manager_dbus_restart (XfpmManager *manager,
- 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 "xfce-power-manager-dbus-server.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_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_quit (XfpmManager *manager, GError **error)
-{
- XFPM_DEBUG("Quit message received\n");
-
- xfpm_manager_quit (manager);
-
- return TRUE;
-}
-
-static gboolean xfpm_manager_dbus_restart (XfpmManager *manager,
- GError **error)
-{
- XFPM_DEBUG("Restart message received");
-
- xfpm_manager_quit (manager);
-
- 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-goodies");
-
- return TRUE;
-}
diff --git a/src/xfpm-manager.h b/src/xfpm-manager.h
index fcbceb3..73fab6e 100644
--- a/src/xfpm-manager.h
+++ b/src/xfpm-manager.h
@@ -55,8 +55,6 @@ 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-power.c b/src/xfpm-power.c
index 45ad928..9eca8e2 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -31,6 +31,7 @@
#include <libxfce4util/libxfce4util.h>
#include <libxfce4ui/libxfce4ui.h>
+#include <libupower-glib/upower.h>
#include "xfpm-power.h"
#include "xfpm-dbus.h"
@@ -39,9 +40,6 @@
#include "xfpm-xfconf.h"
#include "xfpm-notify.h"
#include "xfpm-errors.h"
-#include "xfpm-console-kit.h"
-#include "xfpm-inhibit.h"
-#include "xfpm-polkit.h"
#include "xfpm-network-manager.h"
#include "xfpm-icons.h"
#include "xfpm-common.h"
@@ -53,74 +51,37 @@
static void xfpm_power_finalize (GObject *object);
-static void xfpm_power_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static void xfpm_power_dbus_class_init (XfpmPowerClass * klass);
-static void xfpm_power_dbus_init (XfpmPower *power);
-
static void xfpm_power_refresh_adaptor_visible (XfpmPower *power);
-#define XFPM_POWER_GET_PRIVATE(o) \
-(G_TYPE_INSTANCE_GET_PRIVATE ((o), XFPM_TYPE_POWER, XfpmPowerPrivate))
+struct _XfpmPowerClass
+{
+ GObjectClass __parent__;
+};
-struct XfpmPowerPrivate
+struct _XfpmPower
{
- DBusGConnection *bus;
+ GObjectClass __parent__;
- DBusGProxy *proxy;
- DBusGProxy *proxy_prop;
+ UpClient *up_client;
- GHashTable *hash;
-
- XfpmConsoleKit *console;
- XfpmInhibit *inhibit;
+ GSList *devices;
+
XfpmXfconf *conf;
GtkStatusIcon *adapter_icon;
XfpmBatteryCharge overall_state;
- gboolean critical_action_done;
+ gboolean critical_action_done;
XfpmPowerMode power_mode;
EggIdletime *idletime;
- gboolean inhibited;
-
- XfpmNotify *notify;
-#ifdef ENABLE_POLKIT
- XfpmPolkit *polkit;
-#endif
- gboolean auth_suspend;
- gboolean auth_hibernate;
-
- /* Properties */
- gboolean on_low_battery;
- gboolean lid_is_present;
- gboolean lid_is_closed;
- gboolean on_battery;
- gchar *daemon_version;
- gboolean can_suspend;
- gboolean can_hibernate;
+ XfpmNotify *notify;
/**
* Warning dialog to use when notification daemon
* doesn't support actions.
**/
- GtkWidget *dialog;
-};
-
-enum
-{
- PROP_0,
- PROP_ON_LOW_BATTERY,
- PROP_ON_BATTERY,
- PROP_AUTH_SUSPEND,
- PROP_AUTH_HIBERNATE,
- PROP_CAN_SUSPEND,
- PROP_CAN_HIBERNATE,
- PROP_HAS_LID
+ GtkWidget *dialog;
};
enum
@@ -140,148 +101,7 @@ static guint signals [LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (XfpmPower, xfpm_power, G_TYPE_OBJECT)
-#ifdef ENABLE_POLKIT
-static void
-xfpm_power_check_polkit_auth (XfpmPower *power)
-{
- power->priv->auth_suspend = xfpm_polkit_check_auth (power->priv->polkit,
- POLKIT_AUTH_SUSPEND);
-
- power->priv->auth_hibernate = xfpm_polkit_check_auth (power->priv->polkit,
- POLKIT_AUTH_HIBERNATE);
-
-}
-#endif
-
-static void
-xfpm_power_check_pm (XfpmPower *power, GHashTable *props)
-{
- GValue *value;
- gboolean ret;
-
- value = g_hash_table_lookup (props, "CanSuspend");
-
- if (value == NULL)
- {
- g_warning ("No 'CanSuspend' property");
- }
- ret = g_value_get_boolean (value);
-
- if (ret != power->priv->can_suspend)
- {
- power->priv->can_suspend = ret;
- }
-
- value = g_hash_table_lookup (props, "CanHibernate");
-
- if (value == NULL)
- {
- g_warning ("No 'CanHibernate' property");
- }
-
- ret = g_value_get_boolean (value);
-
- if (ret != power->priv->can_hibernate)
- {
- power->priv->can_hibernate = ret;
- }
-}
-
-static void
-xfpm_power_check_power (XfpmPower *power, GHashTable *props)
-{
- GValue *value;
- gboolean on_battery;
-
- value = g_hash_table_lookup (props, "OnBattery");
-
- if (G_LIKELY (value))
- {
- on_battery = g_value_get_boolean (value);
-
- if (on_battery != power->priv->on_battery )
- {
- GList *list;
- guint len, i;
- g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, on_battery);
- power->priv->on_battery = on_battery;
- list = g_hash_table_get_values (power->priv->hash);
- len = g_list_length (list);
- for ( i = 0; i < len; i++)
- {
- g_object_set (G_OBJECT (g_list_nth_data (list, i)),
- "ac-online", !on_battery,
- NULL);
- }
- }
- }
- else
- {
- g_warning ("No 'OnBattery' property");
- }
-}
-
-static void
-xfpm_power_check_lid (XfpmPower *power, GHashTable *props)
-{
- GValue *value;
-
- value = g_hash_table_lookup (props, "LidIsPresent");
-
- if (value == NULL)
- {
- g_warning ("No 'LidIsPresent' property");
- return;
- }
-
- power->priv->lid_is_present = g_value_get_boolean (value);
- if (power->priv->lid_is_present)
- {
- gboolean closed;
-
- value = g_hash_table_lookup (props, "LidIsClosed");
-
- if (value == NULL)
- {
- g_warning ("No 'LidIsClosed' property");
- return;
- }
-
- closed = g_value_get_boolean (value);
-
- if (closed != power->priv->lid_is_closed )
- {
- power->priv->lid_is_closed = closed;
- g_signal_emit (G_OBJECT (power), signals [LID_CHANGED], 0, power->priv->lid_is_closed);
- }
- }
-}
-
-/*
- * Get the properties on org.freedesktop.DeviceKit.Power
- *
- * DaemonVersion 's'
- * CanSuspend' 'b'
- * CanHibernate' 'b'
- * OnBattery' 'b'
- * OnLowBattery' 'b'
- * LidIsClosed' 'b'
- * LidIsPresent' 'b'
- */
-static void
-xfpm_power_get_properties (XfpmPower *power)
-{
- GHashTable *props;
-
- props = xfpm_power_get_interface_properties (power->priv->proxy_prop, UPOWER_IFACE);
-
- xfpm_power_check_pm (power, props);
- xfpm_power_check_lid (power, props);
- xfpm_power_check_power (power, props);
-
- g_hash_table_destroy (props);
-}
static void
xfpm_power_report_error (XfpmPower *power, const gchar *error, const gchar *icon_name)
@@ -290,27 +110,27 @@ xfpm_power_report_error (XfpmPower *power, const gchar *error, const gchar *icon
guint i, len;
GList *list;
- list = g_hash_table_get_values (power->priv->hash);
+ list = g_hash_table_get_values (power->hash);
len = g_list_length (list);
for ( i = 0; i < len; i++)
{
- XfpmDeviceType type;
- battery = g_list_nth_data (list, i);
- type = xfpm_battery_get_device_type (XFPM_BATTERY (battery));
- if ( type == XFPM_DEVICE_TYPE_BATTERY ||
- type == XFPM_DEVICE_TYPE_UPS )
- break;
+ XfpmDeviceType type;
+ battery = g_list_nth_data (list, i);
+ type = xfpm_battery_get_device_type (XFPM_BATTERY (battery));
+ if ( type == XFPM_DEVICE_TYPE_BATTERY ||
+ type == XFPM_DEVICE_TYPE_UPS )
+ break;
}
- xfpm_notify_show_notification (power->priv->notify,
- _("Power Manager"),
- error,
- icon_name,
- 10000,
- FALSE,
- XFPM_NOTIFY_CRITICAL,
- battery);
+ xfpm_notify_show_notification (power->notify,
+ _("Power Manager"),
+ error,
+ icon_name,
+ 10000,
+ FALSE,
+ XFPM_NOTIFY_CRITICAL,
+ battery);
}
@@ -320,56 +140,56 @@ xfpm_power_sleep (XfpmPower *power, const gchar *sleep_time, gboolean force)
GError *error = NULL;
gboolean lock_screen;
- if ( power->priv->inhibited && force == FALSE)
+ 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;
+ 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->priv->conf),
- LOCK_SCREEN_ON_SLEEP, &lock_screen,
- NULL);
+ 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 ();
+ g_usleep (2000000); /* 2 seconds */
+ xfpm_lock_screen ();
}
- dbus_g_proxy_call (power->priv->proxy, sleep_time, &error,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ dbus_g_proxy_call (power->proxy, sleep_time, &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
if ( 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);
- }
+ 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);
+ }
}
g_signal_emit (G_OBJECT (power), signals [WAKING_UP], 0);
@@ -391,24 +211,24 @@ xfpm_power_suspend_cb (XfpmPower *power)
static void
xfpm_power_hibernate_clicked (XfpmPower *power)
{
- gtk_widget_destroy (power->priv->dialog );
- power->priv->dialog = NULL;
+ 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->priv->dialog );
- power->priv->dialog = NULL;
+ gtk_widget_destroy (power->dialog );
+ power->dialog = NULL;
xfpm_power_sleep (power, "Suspend", TRUE);
}
static void
xfpm_power_shutdown_clicked (XfpmPower *power)
{
- gtk_widget_destroy (power->priv->dialog );
- power->priv->dialog = NULL;
+ gtk_widget_destroy (power->dialog );
+ power->dialog = NULL;
g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
}
@@ -424,14 +244,14 @@ xfpm_power_tray_exit_activated_cb (gpointer data)
gboolean ret;
ret = xfce_dialog_confirm (NULL,
- GTK_STOCK_YES,
- _("Quit"),
- _("All running instances of the power manager will exit"),
- "%s",
- _("Quit the power manager?"));
+ GTK_STOCK_YES,
+ _("Quit"),
+ _("All running instances of the power manager will exit"),
+ "%s",
+ _("Quit the power manager?"));
if ( ret )
{
- xfpm_quit ();
+ xfpm_quit ();
}
}
@@ -441,7 +261,7 @@ xfpm_power_change_mode (XfpmPower *power, XfpmPowerMode mode)
{
XfpmDpms *dpms;
- power->priv->power_mode = mode;
+ power->power_mode = mode;
dpms = xfpm_dpms_new ();
xfpm_dpms_refresh (dpms);
@@ -449,11 +269,11 @@ xfpm_power_change_mode (XfpmPower *power, XfpmPowerMode mode)
if (mode == XFPM_POWER_MODE_NORMAL)
{
- EggIdletime *idletime;
- idletime = egg_idletime_new ();
- egg_idletime_alarm_reset_all (idletime);
+ EggIdletime *idletime;
+ idletime = egg_idletime_new ();
+ egg_idletime_alarm_reset_all (idletime);
- g_object_unref (idletime);
+ g_object_unref (idletime);
}
}
@@ -471,10 +291,10 @@ xfpm_power_presentation_mode_cb (XfpmPower *power)
static void
xfpm_power_show_tray_menu (XfpmPower *power,
- GtkStatusIcon *icon,
- guint button,
- guint activate_time,
- gboolean show_info_item)
+ GtkStatusIcon *icon,
+ guint button,
+ guint activate_time,
+ gboolean show_info_item)
{
GtkWidget *menu, *mi, *img, *subm;
@@ -486,11 +306,11 @@ xfpm_power_show_tray_menu (XfpmPower *power,
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (mi), img);
gtk_widget_set_sensitive (mi, FALSE);
- if ( power->priv->can_hibernate && power->priv->auth_hibernate)
+ //TODOif ( power->can_hibernate && power->auth_hibernate)
{
- gtk_widget_set_sensitive (mi, TRUE);
- g_signal_connect_swapped (G_OBJECT (mi), "activate",
- G_CALLBACK (xfpm_power_hibernate_cb), power);
+ gtk_widget_set_sensitive (mi, TRUE);
+ g_signal_connect_swapped (G_OBJECT (mi), "activate",
+ G_CALLBACK (xfpm_power_hibernate_cb), power);
}
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
@@ -502,25 +322,25 @@ xfpm_power_show_tray_menu (XfpmPower *power,
gtk_widget_set_sensitive (mi, FALSE);
- if ( power->priv->can_suspend && power->priv->auth_hibernate)
+ //TODOif ( power->can_suspend && power->auth_hibernate)
{
- gtk_widget_set_sensitive (mi, TRUE);
- g_signal_connect_swapped (mi, "activate",
- G_CALLBACK (xfpm_power_suspend_cb), power);
+ gtk_widget_set_sensitive (mi, TRUE);
+ g_signal_connect_swapped (mi, "activate",
+ G_CALLBACK (xfpm_power_suspend_cb), power);
}
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
/*
- saver_inhibited = xfpm_screen_saver_get_inhibit (tray->priv->srv);
+ saver_inhibited = xfpm_screen_saver_get_inhibit (tray->srv);
mi = gtk_check_menu_item_new_with_label (_("Monitor power control"));
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), !saver_inhibited);
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."));
+ "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);
+ 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);
@@ -538,8 +358,8 @@ xfpm_power_show_tray_menu (XfpmPower *power,
gtk_widget_set_sensitive (mi,TRUE);
g_signal_connect_swapped (mi, "activate",
- G_CALLBACK (xfpm_power_power_info_cb), icon);
-
+ G_CALLBACK (xfpm_power_power_info_cb), icon);
+
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
@@ -559,21 +379,21 @@ xfpm_power_show_tray_menu (XfpmPower *power,
/* Normal*/
mi = gtk_check_menu_item_new_with_label (_("Normal"));
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mi), power->priv->power_mode == XFPM_POWER_MODE_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);
+ 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->priv->power_mode == XFPM_POWER_MODE_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);
+ G_CALLBACK (xfpm_power_presentation_mode_cb), power);
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (subm), mi);
@@ -581,12 +401,12 @@ xfpm_power_show_tray_menu (XfpmPower *power,
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);
@@ -614,25 +434,25 @@ xfpm_power_show_tray_menu (XfpmPower *power,
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
g_signal_connect (menu, "selection-done",
- G_CALLBACK (gtk_widget_destroy), NULL);
+ G_CALLBACK (gtk_widget_destroy), NULL);
// Popup the menu
gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
- gtk_status_icon_position_menu,
- icon, button, activate_time);
+ 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)
+ 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,
- guint activate_time, XfpmPower *power)
+ guint activate_time, XfpmPower *power)
{
xfpm_power_show_tray_menu (power, icon, button, activate_time, FALSE);
}
@@ -644,23 +464,23 @@ xfpm_power_get_current_charge_state (XfpmPower *power)
guint len, i;
XfpmBatteryCharge max_charge_status = XFPM_BATTERY_CHARGE_UNKNOWN;
- list = g_hash_table_get_values (power->priv->hash);
+ list = g_hash_table_get_values (power->hash);
len = g_list_length (list);
for ( i = 0; i < len; i++)
{
- XfpmBatteryCharge battery_charge;
- XfpmDeviceType type;
-
- g_object_get (G_OBJECT (g_list_nth_data (list, i)),
- "charge-status", &battery_charge,
- "device-type", &type,
- NULL);
- if ( type != XFPM_DEVICE_TYPE_BATTERY &&
- type != XFPM_DEVICE_TYPE_UPS )
- continue;
-
- max_charge_status = MAX (max_charge_status, battery_charge);
+ XfpmBatteryCharge battery_charge;
+ XfpmDeviceType type;
+
+ g_object_get (G_OBJECT (g_list_nth_data (list, i)),
+ "charge-status", &battery_charge,
+ "device-type", &type,
+ NULL);
+ if ( type != XFPM_DEVICE_TYPE_BATTERY &&
+ type != XFPM_DEVICE_TYPE_UPS )
+ continue;
+
+ max_charge_status = MAX (max_charge_status, battery_charge);
}
return max_charge_status;
@@ -670,36 +490,32 @@ 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);
+ g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
else
- xfpm_power_sleep (power, action, TRUE);
+ xfpm_power_sleep (power, action, TRUE);
}
static void
xfpm_power_add_actions_to_notification (XfpmPower *power, NotifyNotification *n)
{
- gboolean can_shutdown;
-
- g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", &can_shutdown,
- NULL);
-
- if ( power->priv->can_hibernate && power->priv->auth_hibernate )
+ gboolean can_shutdown = FALSE;
+
+ //TODO if ( power->can_hibernate && power->auth_hibernate )
{
xfpm_notify_add_action_to_notification(
- power->priv->notify,
- n,
+ power->notify,
+ n,
"Hibernate",
_("Hibernate the system"),
(NotifyActionCallback)xfpm_power_notify_action_callback,
power);
}
- if ( power->priv->can_suspend && power->priv->auth_suspend )
+ //TODO if ( power->can_suspend && power->auth_suspend )
{
xfpm_notify_add_action_to_notification(
- power->priv->notify,
- n,
+ power->notify,
+ n,
"Suspend",
_("Suspend the system"),
(NotifyActionCallback)xfpm_power_notify_action_callback,
@@ -707,13 +523,13 @@ xfpm_power_add_actions_to_notification (XfpmPower *power, NotifyNotification *n)
}
if (can_shutdown )
- xfpm_notify_add_action_to_notification(
- power->priv->notify,
- n,
- "Shutdown",
- _("Shutdown the system"),
- (NotifyActionCallback)xfpm_power_notify_action_callback,
- power);
+ xfpm_notify_add_action_to_notification(
+ power->notify,
+ n,
+ "Shutdown",
+ _("Shutdown the system"),
+ (NotifyActionCallback)xfpm_power_notify_action_callback,
+ power);
}
static void
@@ -724,26 +540,26 @@ xfpm_power_show_critical_action_notification (XfpmPower *power, XfpmBattery *bat
message = _("System is running on low power. "\
"Save your work to avoid losing data");
-
+
n =
- xfpm_notify_new_notification (power->priv->notify,
- _("Power Manager"),
- message,
- gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
- 20000,
- XFPM_NOTIFY_CRITICAL,
- GTK_STATUS_ICON (battery));
+ 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->priv->notify, n);
+ xfpm_notify_critical (power->notify, n);
}
static void
xfpm_power_close_critical_dialog (XfpmPower *power)
{
- gtk_widget_destroy (power->priv->dialog);
- power->priv->dialog = NULL;
+ gtk_widget_destroy (power->dialog);
+ power->dialog = NULL;
}
static void
@@ -754,11 +570,7 @@ xfpm_power_show_critical_action_gtk (XfpmPower *power)
GtkWidget *img;
GtkWidget *cancel;
const gchar *message;
- gboolean can_shutdown;
-
- g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", &can_shutdown,
- NULL);
+ gboolean can_shutdown = FALSE; /* TODO */
message = _("System is running on low power. "\
"Save your work to avoid losing data");
@@ -773,59 +585,59 @@ xfpm_power_show_critical_action_gtk (XfpmPower *power)
gtk_box_pack_start_defaults (GTK_BOX (content_area), gtk_label_new (message));
- if ( power->priv->can_hibernate && power->priv->auth_hibernate )
+ //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);
+ 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);
}
- if ( power->priv->can_suspend && power->priv->auth_suspend )
+ //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);
+ 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);
+ 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_CALLBACK (xfpm_power_close_critical_dialog), power);
g_signal_connect_swapped (dialog, "destroy",
- G_CALLBACK (xfpm_power_close_critical_dialog), power);
- if ( power->priv->dialog )
+ G_CALLBACK (xfpm_power_close_critical_dialog), power);
+ if ( power->dialog )
{
- gtk_widget_destroy (power->priv->dialog);
- power->priv->dialog = NULL;
-
+ gtk_widget_destroy (power->dialog);
+ power->dialog = NULL;
+
}
- power->priv->dialog = dialog;
+ power->dialog = dialog;
gtk_widget_show_all (dialog);
}
@@ -834,27 +646,27 @@ xfpm_power_show_critical_action (XfpmPower *power, XfpmBattery *battery)
{
gboolean supports_actions;
- g_object_get (G_OBJECT (power->priv->notify),
- "actions", &supports_actions,
- NULL);
-
+ g_object_get (G_OBJECT (power->notify),
+ "actions", &supports_actions,
+ NULL);
+
if ( supports_actions )
- xfpm_power_show_critical_action_notification (power, battery);
+ xfpm_power_show_critical_action_notification (power, battery);
else
- xfpm_power_show_critical_action_gtk (power);
+ 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);
+ g_signal_emit (G_OBJECT (power), signals [ASK_SHUTDOWN], 0);
else if ( req == XFPM_DO_SUSPEND )
- xfpm_power_sleep (power, "Suspend", TRUE);
+ xfpm_power_sleep (power, "Suspend", TRUE);
else if ( req == XFPM_DO_HIBERNATE )
- xfpm_power_sleep (power, "Hibernate", TRUE);
+ xfpm_power_sleep (power, "Hibernate", TRUE);
else if ( req == XFPM_DO_SHUTDOWN )
- g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
+ g_signal_emit (G_OBJECT (power), signals [SHUTDOWN], 0);
}
static void
@@ -862,28 +674,28 @@ xfpm_power_system_on_critical_power (XfpmPower *power, XfpmBattery *battery)
{
XfpmShutdownRequest critical_action;
- g_object_get (G_OBJECT (power->priv->conf),
- CRITICAL_BATT_ACTION_CFG, &critical_action,
- NULL);
+ g_object_get (G_OBJECT (power->conf),
+ CRITICAL_BATT_ACTION_CFG, &critical_action,
+ NULL);
XFPM_DEBUG ("System is running on low power");
XFPM_DEBUG_ENUM (critical_action, XFPM_TYPE_SHUTDOWN_REQUEST, "Critical battery action");
if ( critical_action == XFPM_DO_NOTHING )
{
- xfpm_power_show_critical_action (power, battery);
+ xfpm_power_show_critical_action (power, battery);
}
else
{
- if (power->priv->critical_action_done == FALSE)
- {
- power->priv->critical_action_done = TRUE;
- xfpm_power_process_critical_action (power, critical_action);
- }
- else
- {
- xfpm_power_show_critical_action (power, battery);
- }
+ if (power->critical_action_done == FALSE)
+ {
+ power->critical_action_done = TRUE;
+ xfpm_power_process_critical_action (power, critical_action);
+ }
+ else
+ {
+ xfpm_power_show_critical_action (power, battery);
+ }
}
}
@@ -899,143 +711,121 @@ xfpm_power_battery_charge_changed_cb (XfpmBattery *battery, XfpmPower *power)
XFPM_DEBUG_ENUM (current_charge, XFPM_TYPE_BATTERY_CHARGE, "Current system charge status");
- if (current_charge == power->priv->overall_state)
- return;
+ if (current_charge == power->overall_state)
+ return;
if (current_charge >= XFPM_BATTERY_CHARGE_LOW)
- power->priv->critical_action_done = FALSE;
+ power->critical_action_done = FALSE;
- power->priv->overall_state = current_charge;
+ power->overall_state = current_charge;
- if ( current_charge == XFPM_BATTERY_CHARGE_CRITICAL && power->priv->on_battery)
+ //TODO if ( current_charge == XFPM_BATTERY_CHARGE_CRITICAL && power->on_battery)
{
- xfpm_power_system_on_critical_power (power, battery);
-
- power->priv->on_low_battery = TRUE;
- g_signal_emit (G_OBJECT (power), signals [LOW_BATTERY_CHANGED], 0, power->priv->on_low_battery);
- return;
+ 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;
}
- if ( power->priv->on_low_battery )
+ //TODO if ( power->on_low_battery )
{
- power->priv->on_low_battery = FALSE;
- g_signal_emit (G_OBJECT (power), signals [LOW_BATTERY_CHANGED], 0, power->priv->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->priv->conf),
- GENERAL_NOTIFICATION_CFG, ¬ify,
- NULL);
+ g_object_get (G_OBJECT (power->conf),
+ GENERAL_NOTIFICATION_CFG, ¬ify,
+ NULL);
- if ( power->priv->on_battery )
+ //TODO if ( power->on_battery )
{
- if ( current_charge == XFPM_BATTERY_CHARGE_LOW )
- {
- if ( notify )
- xfpm_notify_show_notification (power->priv->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 )
- {
- if ( notify )
- {
- gchar *msg;
- gchar *time_str;
-
- const gchar *battery_name = xfpm_battery_get_battery_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->priv->notify,
- _("Power Manager"),
- msg,
- gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
- 10000,
- FALSE,
- XFPM_NOTIFY_NORMAL,
- GTK_STATUS_ICON (battery));
- g_free (msg);
- g_free (time_str);
- }
- }
+ if ( current_charge == XFPM_BATTERY_CHARGE_LOW )
+ {
+ if ( notify )
+ 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 )
+ {
+ if ( notify )
+ {
+ gchar *msg;
+ gchar *time_str;
+
+ const gchar *battery_name = xfpm_battery_get_battery_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,
+ gtk_status_icon_get_icon_name (GTK_STATUS_ICON (battery)),
+ 10000,
+ FALSE,
+ XFPM_NOTIFY_NORMAL,
+ GTK_STATUS_ICON (battery));
+ g_free (msg);
+ g_free (time_str);
+ }
+ }
}
/*Current charge is okay now, then close the dialog*/
- if ( power->priv->dialog )
+ if ( power->dialog )
{
- gtk_widget_destroy (power->priv->dialog);
- power->priv->dialog = NULL;
+ gtk_widget_destroy (power->dialog);
+ power->dialog = NULL;
}
}
static void
-xfpm_power_add_device (XfpmPower *power, const gchar *object_path)
+xfpm_power_add_device (XfpmPower *power, UpDevice *device)
{
- DBusGProxy *proxy_prop;
- guint device_type = XFPM_DEVICE_TYPE_UNKNOWN;
- GValue value;
-
- proxy_prop = dbus_g_proxy_new_for_name (power->priv->bus,
- UPOWER_NAME,
- object_path,
- DBUS_INTERFACE_PROPERTIES);
-
- if ( !proxy_prop )
- {
- g_warning ("Unable to create proxy for : %s", object_path);
- return;
- }
-
- value = xfpm_power_get_interface_property (proxy_prop, UPOWER_IFACE_DEVICE, "Type");
+ UpDeviceKind device_kind;
+ GtkStatusIcon *battery;
- device_type = g_value_get_uint (&value);
+ g_object_get (device, "kind", &kind, NULL);
XFPM_DEBUG_ENUM (device_type, XFPM_TYPE_DEVICE_TYPE, " device added");
-
- if ( device_type == XFPM_DEVICE_TYPE_BATTERY ||
- device_type == XFPM_DEVICE_TYPE_UPS ||
- device_type == XFPM_DEVICE_TYPE_MOUSE ||
- device_type == XFPM_DEVICE_TYPE_KBD ||
- device_type == XFPM_DEVICE_TYPE_PHONE)
+
+ switch (kind)
{
- GtkStatusIcon *battery;
- DBusGProxy *proxy;
- XFPM_DEBUG_ENUM (device_type, XFPM_TYPE_DEVICE_TYPE,
- "Battery device detected at : %s", object_path);
- proxy = dbus_g_proxy_new_for_name (power->priv->bus,
- UPOWER_NAME,
- object_path,
- UPOWER_IFACE_DEVICE);
- battery = xfpm_battery_new ();
- gtk_status_icon_set_visible (battery, FALSE);
- xfpm_battery_monitor_device (XFPM_BATTERY (battery),
- proxy,
- proxy_prop,
- device_type);
-
- g_hash_table_insert (power->priv->hash, g_strdup (object_path), battery);
-
- g_signal_connect (battery, "popup-menu",
- 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);
-
- xfpm_power_refresh_adaptor_visible (power);
- }
- else if ( device_type != XFPM_DEVICE_TYPE_LINE_POWER )
- {
- g_warning ("Unable to monitor unkown power device with object_path : %s", object_path);
- g_object_unref (proxy_prop);
+ case UP_DEVICE_KIND_BATTERY:
+ case UP_DEVICE_KIND_UPS:
+ case UP_DEVICE_KIND_MOUSE:
+ case UP_DEVICE_KIND_KEYBOARD:
+ case UP_DEVICE_KIND_PHONE:
+ battery = xfpm_battery_new (device);
+ gtk_status_icon_set_visible (battery, FALSE);
+ g_signal_connect (battery, "popup-menu",
+ 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);
+
+ break;
+
+ case UP_DEVICE_KIND_LINE_POWER:
+ g_warning ("Unable to monitor unkown power device with object_path : %s", object_path);
+ break;
+
+ default:
+ /* other devices types we don't care about */
+ break;
}
}
@@ -1045,95 +835,84 @@ xfpm_power_get_power_devices (XfpmPower *power)
GPtrArray *array = NULL;
guint i;
- array = xfpm_power_enumerate_devices (power->priv->proxy);
+ array = xfpm_power_enumerate_devices (power->proxy);
if ( array )
{
- for ( i = 0; i < array->len; i++)
- {
- const gchar *object_path = ( const gchar *) g_ptr_array_index (array, i);
- XFPM_DEBUG ("Power device detected at : %s", object_path);
- xfpm_power_add_device (power, object_path);
- }
- g_ptr_array_free (array, TRUE);
+ for ( i = 0; i < array->len; i++)
+ {
+ const gchar *object_path = ( const gchar *) g_ptr_array_index (array, i);
+ XFPM_DEBUG ("Power device detected at : %s", object_path);
+ xfpm_power_add_device (power, object_path);
+ }
+ g_ptr_array_free (array, TRUE);
}
}
static void
-xfpm_power_remove_device (XfpmPower *power, const gchar *object_path)
+xfpm_power_remove_device (XfpmPower *power, UpDevice *device)
{
- g_hash_table_remove (power->priv->hash, object_path);
+ power->devices = g_slist_remove (power->devices, device);
xfpm_power_refresh_adaptor_visible (power);
}
-static void
-xfpm_power_inhibit_changed_cb (XfpmInhibit *inhibit, gboolean is_inhibit, XfpmPower *power)
-{
- power->priv->inhibited = is_inhibit;
-}
static void
-xfpm_power_changed_cb (DBusGProxy *proxy, XfpmPower *power)
+xfpm_power_changed_cb (UpClient *up_client, XfpmPower *power)
{
- xfpm_power_get_properties (power);
+ g_return_if_fail (power->up_client == up_client);
xfpm_power_refresh_adaptor_visible (power);
}
static void
-xfpm_power_device_added_cb (DBusGProxy *proxy, const gchar *object_path, XfpmPower *power)
+xfpm_power_device_added_cb (UpClient *up_client, UpDevice *device, XfpmPower *power)
{
- xfpm_power_add_device (power, object_path);
+ g_return_if_fail (power->up_client == up_client);
+ xfpm_power_add_device (power, device);
}
static void
-xfpm_power_device_removed_cb (DBusGProxy *proxy, const gchar *object_path, XfpmPower *power)
+xfpm_power_device_removed_cb (UpClient *up_client, UpDevice *device, XfpmPower *power)
{
- xfpm_power_remove_device (power, object_path);
+ g_return_if_fail (power->up_client == up_client);
+ xfpm_power_remove_device (power, device);
}
static void
-xfpm_power_device_changed_cb (DBusGProxy *proxy, const gchar *object_path, XfpmPower *power)
+xfpm_power_device_changed_cb (UpClient *up_client, UpDevice *device, XfpmPower *power)
{
+ g_return_if_fail (power->up_client == up_client);
xfpm_power_refresh_adaptor_visible (power);
}
-#ifdef ENABLE_POLKIT
-static void
-xfpm_power_polkit_auth_changed_cb (XfpmPower *power)
-{
- XFPM_DEBUG ("Auth configuration changed");
- xfpm_power_check_polkit_auth (power);
-}
-#endif
-
static void
xfpm_power_hide_adapter_icon (XfpmPower *power)
{
XFPM_DEBUG ("Hide adaptor icon");
- if ( power->priv->adapter_icon )
+ if ( power->adapter_icon )
{
- g_object_unref (power->priv->adapter_icon);
- power->priv->adapter_icon = NULL;
+ g_object_unref (power->adapter_icon);
+ power->adapter_icon = NULL;
}
}
static void
xfpm_power_show_adapter_icon (XfpmPower *power)
{
- g_return_if_fail (power->priv->adapter_icon == NULL);
+ g_return_if_fail (power->adapter_icon == NULL);
- power->priv->adapter_icon = gtk_status_icon_new ();
+ power->adapter_icon = gtk_status_icon_new ();
XFPM_DEBUG ("Showing adaptor icon");
- gtk_status_icon_set_from_icon_name (power->priv->adapter_icon, XFPM_AC_ADAPTER_ICON);
+ gtk_status_icon_set_from_icon_name (power->adapter_icon, XFPM_AC_ADAPTER_ICON);
- gtk_status_icon_set_visible (power->priv->adapter_icon, TRUE);
+ gtk_status_icon_set_visible (power->adapter_icon, TRUE);
- g_signal_connect (power->priv->adapter_icon, "popup-menu",
- G_CALLBACK (xfpm_power_show_tray_menu_adaptor), power);
+ g_signal_connect (power->adapter_icon, "popup-menu",
+ G_CALLBACK (xfpm_power_show_tray_menu_adaptor), power);
}
static void
@@ -1141,37 +920,37 @@ xfpm_power_refresh_adaptor_visible (XfpmPower *power)
{
XfpmShowIcon show_icon;
- g_object_get (G_OBJECT (power->priv->conf),
- SHOW_TRAY_ICON_CFG, &show_icon,
- NULL);
-
+ 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 ( g_hash_table_size (power->priv->hash) == 0 )
- {
- xfpm_power_show_adapter_icon (power);
+ if ( g_hash_table_size (power->hash) == 0 )
+ {
+ xfpm_power_show_adapter_icon (power);
#if GTK_CHECK_VERSION (2, 16, 0)
- gtk_status_icon_set_tooltip_text (power->priv->adapter_icon,
- power->priv->on_battery ?
- _("Adaptor is offline") :
- _("Adaptor is online") );
+ gtk_status_icon_set_tooltip_text (power->adapter_icon,
+ TRUE ? //power->on_battery ?
+ _("Adaptor is offline") :
+ _("Adaptor is online") );
#else
- gtk_status_icon_set_tooltip (power->priv->adapter_icon,
- power->priv->on_battery ?
- _("Adaptor is offline") :
- _("Adaptor is online") );
+ gtk_status_icon_set_tooltip (power->adapter_icon,
+ TRUE ?//power->on_battery ?
+ _("Adaptor is offline") :
+ _("Adaptor is online") );
#endif
- }
- else
- {
- xfpm_power_hide_adapter_icon (power);
- }
+ }
+ else
+ {
+ xfpm_power_hide_adapter_icon (power);
+ }
}
else
{
- xfpm_power_hide_adapter_icon (power);
+ xfpm_power_hide_adapter_icon (power);
}
}
@@ -1182,14 +961,11 @@ xfpm_power_class_init (XfpmPowerClass *klass)
object_class->finalize = xfpm_power_finalize;
- object_class->get_property = xfpm_power_get_property;
-
signals [ON_BATTERY_CHANGED] =
g_signal_new ("on-battery-changed",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmPowerClass, on_battery_changed),
- NULL, NULL,
+ 0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
@@ -1197,8 +973,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_signal_new ("low-battery-changed",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmPowerClass, low_battery_changed),
- NULL, NULL,
+ 0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
@@ -1206,8 +981,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_signal_new ("lid-changed",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmPowerClass, lid_changed),
- NULL, NULL,
+ 0, NULL, NULL,
g_cclosure_marshal_VOID__BOOLEAN,
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
@@ -1215,8 +989,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_signal_new ("waking-up",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmPowerClass, waking_up),
- NULL, NULL,
+ 0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
@@ -1224,8 +997,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_signal_new ("sleeping",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmPowerClass, sleeping),
- NULL, NULL,
+ 0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
@@ -1233,8 +1005,7 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_signal_new ("ask-shutdown",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmPowerClass, ask_shutdown),
- NULL, NULL,
+ 0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
@@ -1242,194 +1013,53 @@ xfpm_power_class_init (XfpmPowerClass *klass)
g_signal_new ("shutdown",
XFPM_TYPE_POWER,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(XfpmPowerClass, shutdown),
- NULL, NULL,
+ 0, NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
-
- g_object_class_install_property (object_class,
- PROP_ON_BATTERY,
- g_param_spec_boolean ("on-battery",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_ON_LOW_BATTERY,
- g_param_spec_boolean ("on-low-battery",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_AUTH_SUSPEND,
- g_param_spec_boolean ("auth-suspend",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_AUTH_HIBERNATE,
- g_param_spec_boolean ("auth-hibernate",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CAN_HIBERNATE,
- g_param_spec_boolean ("can-hibernate",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_CAN_SUSPEND,
- g_param_spec_boolean ("can-suspend",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_object_class_install_property (object_class,
- PROP_HAS_LID,
- g_param_spec_boolean ("has-lid",
- NULL, NULL,
- FALSE,
- G_PARAM_READABLE));
-
- g_type_class_add_private (klass, sizeof (XfpmPowerPrivate));
-
- xfpm_power_dbus_class_init (klass);
}
static void
xfpm_power_init (XfpmPower *power)
{
GError *error = NULL;
-
- power->priv = XFPM_POWER_GET_PRIVATE (power);
-
- power->priv->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- power->priv->lid_is_present = FALSE;
- power->priv->lid_is_closed = FALSE;
- power->priv->on_battery = FALSE;
- power->priv->on_low_battery = FALSE;
- power->priv->daemon_version = NULL;
- power->priv->can_suspend = FALSE;
- power->priv->can_hibernate = FALSE;
- power->priv->auth_hibernate = TRUE;
- power->priv->auth_suspend = TRUE;
- power->priv->dialog = NULL;
- power->priv->adapter_icon = NULL;
- power->priv->overall_state = XFPM_BATTERY_CHARGE_OK;
- power->priv->critical_action_done = FALSE;
- power->priv->power_mode = XFPM_POWER_MODE_NORMAL;
-
- power->priv->inhibit = xfpm_inhibit_new ();
- power->priv->notify = xfpm_notify_new ();
- power->priv->conf = xfpm_xfconf_new ();
- power->priv->console = xfpm_console_kit_new ();
-
- g_signal_connect_swapped (power->priv->conf, "notify::" SHOW_TRAY_ICON_CFG,
- G_CALLBACK (xfpm_power_refresh_adaptor_visible), power);
-
-#ifdef ENABLE_POLKIT
- power->priv->polkit = xfpm_polkit_get ();
- g_signal_connect_swapped (power->priv->polkit, "auth-changed",
- G_CALLBACK (xfpm_power_polkit_auth_changed_cb), power);
-#endif
-
- g_signal_connect (power->priv->inhibit, "has-inhibit-changed",
- G_CALLBACK (xfpm_power_inhibit_changed_cb), power);
-
- power->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
-
- if ( error )
- {
- g_critical ("Unable to connect to the system bus : %s", error->message);
- g_error_free (error);
- goto out;
- }
+ gboolean on_battery;
- power->priv->proxy = dbus_g_proxy_new_for_name (power->priv->bus,
- UPOWER_NAME,
- UPOWER_PATH,
- UPOWER_IFACE);
-
+ power->hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ power->dialog = NULL;
+ 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->priv->proxy_prop = dbus_g_proxy_new_for_name (power->priv->bus,
- UPOWER_NAME,
- UPOWER_PATH,
- DBUS_INTERFACE_PROPERTIES);
- if (power->priv->proxy_prop == NULL)
- {
- g_critical ("Unable to create proxy for %s", UPOWER_NAME);
- goto out;
- }
+ power->up_client = up_client_new ();
xfpm_power_get_power_devices (power);
- xfpm_power_get_properties (power);
-#ifdef ENABLE_POLKIT
- xfpm_power_check_polkit_auth (power);
-#endif
-
- dbus_g_proxy_add_signal (power->priv->proxy, "Changed", G_TYPE_INVALID);
- dbus_g_proxy_add_signal (power->priv->proxy, "DeviceAdded", G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_add_signal (power->priv->proxy, "DeviceRemoved", G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_add_signal (power->priv->proxy, "DeviceChanged", G_TYPE_STRING, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (power->priv->proxy, "Changed",
- G_CALLBACK (xfpm_power_changed_cb), power, NULL);
- dbus_g_proxy_connect_signal (power->priv->proxy, "DeviceRemoved",
- G_CALLBACK (xfpm_power_device_removed_cb), power, NULL);
- dbus_g_proxy_connect_signal (power->priv->proxy, "DeviceAdded",
- G_CALLBACK (xfpm_power_device_added_cb), power, NULL);
-
- dbus_g_proxy_connect_signal (power->priv->proxy, "DeviceChanged",
- G_CALLBACK (xfpm_power_device_changed_cb), power, NULL);
-
+ g_signal_connect (power->up_client, "changed",
+ G_CALLBACK (xfpm_power_changed_cb), power);
+ g_signal_connect (power->up_client, "device-removed",
+ G_CALLBACK (xfpm_power_device_removed_cb), power);
+ g_signal_connect (power->up_client, "device-added",
+ G_CALLBACK (xfpm_power_device_added_cb), power);
+ g_signal_connect (power->up_client, "device-changed",
+ G_CALLBACK (xfpm_power_device_changed_cb), power);
-out:
- xfpm_power_refresh_adaptor_visible (power);
-
- xfpm_power_dbus_init (power);
-
- /*
- * Emit org.freedesktop.PowerManagement session signals on startup
- */
- g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, power->priv->on_battery);
-}
+
+ power->conf = xfpm_xfconf_new ();
+ g_signal_connect_swapped (power->conf, "notify::" SHOW_TRAY_ICON_CFG,
+ G_CALLBACK (xfpm_power_refresh_adaptor_visible), power);
-static void xfpm_power_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- XfpmPower *power;
- power = XFPM_POWER (object);
+ xfpm_power_refresh_adaptor_visible (power);
- switch (prop_id)
+ if (xfpm_power_get_on_battery (power, &on_battery, &error))
{
- case PROP_ON_BATTERY:
- g_value_set_boolean (value, power->priv->on_battery);
- break;
- case PROP_AUTH_HIBERNATE:
- g_value_set_boolean (value, power->priv->auth_hibernate);
- break;
- case PROP_AUTH_SUSPEND:
- g_value_set_boolean (value, power->priv->auth_suspend);
- break;
- case PROP_CAN_SUSPEND:
- g_value_set_boolean (value, power->priv->can_suspend);
- break;
- case PROP_CAN_HIBERNATE:
- g_value_set_boolean (value, power->priv->can_hibernate);
- break;
- case PROP_HAS_LID:
- g_value_set_boolean (value, power->priv->lid_is_present);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ g_signal_emit (G_OBJECT (power), signals [ON_BATTERY_CHANGED], 0, on_battery);
+ }
+ else
+ {
+ g_critical ("Failed to get on-battery: %s", error->message);
+ g_error_free (error);
}
}
@@ -1439,39 +1069,30 @@ xfpm_power_finalize (GObject *object)
XfpmPower *power;
power = XFPM_POWER (object);
-
- g_free (power->priv->daemon_version);
-
- g_object_unref (power->priv->inhibit);
- g_object_unref (power->priv->notify);
- g_object_unref (power->priv->conf);
- g_object_unref (power->priv->console);
+
+ g_object_unref (power->conf);
xfpm_power_hide_adapter_icon (power);
- dbus_g_connection_unref (power->priv->bus);
+ dbus_g_connection_unref (power->bus);
- if ( power->priv->proxy )
+ if ( power->proxy )
{
- dbus_g_proxy_disconnect_signal (power->priv->proxy, "Changed",
- G_CALLBACK (xfpm_power_changed_cb), power);
- dbus_g_proxy_disconnect_signal (power->priv->proxy, "DeviceRemoved",
- G_CALLBACK (xfpm_power_device_removed_cb), power);
- dbus_g_proxy_disconnect_signal (power->priv->proxy, "DeviceAdded",
- G_CALLBACK (xfpm_power_device_added_cb), power);
- dbus_g_proxy_disconnect_signal (power->priv->proxy, "DeviceChanged",
- G_CALLBACK (xfpm_power_device_changed_cb), power);
- g_object_unref (power->priv->proxy);
+ dbus_g_proxy_disconnect_signal (power->proxy, "Changed",
+ G_CALLBACK (xfpm_power_changed_cb), power);
+ dbus_g_proxy_disconnect_signal (power->proxy, "DeviceRemoved",
+ G_CALLBACK (xfpm_power_device_removed_cb), power);
+ dbus_g_proxy_disconnect_signal (power->proxy, "DeviceAdded",
+ G_CALLBACK (xfpm_power_device_added_cb), power);
+ dbus_g_proxy_disconnect_signal (power->proxy, "DeviceChanged",
+ G_CALLBACK (xfpm_power_device_changed_cb), power);
+ g_object_unref (power->proxy);
}
- if ( power->priv->proxy_prop )
- g_object_unref (power->priv->proxy_prop);
+ if ( power->proxy_prop )
+ g_object_unref (power->proxy_prop);
- g_hash_table_destroy (power->priv->hash);
-
-#ifdef ENABLE_POLKIT
- g_object_unref (power->priv->polkit);
-#endif
+ g_hash_table_destroy (power->hash);
G_OBJECT_CLASS (xfpm_power_parent_class)->finalize (object);
}
@@ -1483,273 +1104,81 @@ xfpm_power_get (void)
if ( G_LIKELY (xfpm_power_object != NULL ) )
{
- g_object_ref (xfpm_power_object);
+ g_object_ref (xfpm_power_object);
}
else
{
- xfpm_power_object = g_object_new (XFPM_TYPE_POWER, NULL);
- g_object_add_weak_pointer (xfpm_power_object, &xfpm_power_object);
+ 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)
+void
+xfpm_power_suspend (XfpmPower *power, gboolean force)
{
xfpm_power_sleep (power, "Suspend", force);
}
-void xfpm_power_hibernate (XfpmPower *power, gboolean force)
+void
+xfpm_power_hibernate (XfpmPower *power, gboolean force)
{
xfpm_power_sleep (power, "Hibernate", force);
}
-gboolean xfpm_power_has_battery (XfpmPower *power)
-{
- GtkStatusIcon *battery = NULL;
- guint i, len;
- GList *list;
-
- gboolean ret = FALSE;
-
- list = g_hash_table_get_values (power->priv->hash);
- len = g_list_length (list);
-
- for ( i = 0; i < len; i++)
- {
- XfpmDeviceType type;
- battery = g_list_nth_data (list, i);
- type = xfpm_battery_get_device_type (XFPM_BATTERY (battery));
- if ( type == XFPM_DEVICE_TYPE_BATTERY ||
- type == XFPM_DEVICE_TYPE_UPS )
- {
- ret = TRUE;
- break;
- }
- }
-
- return ret;
-}
-
-XfpmPowerMode xfpm_power_get_mode (XfpmPower *power)
-{
- g_return_val_if_fail (XFPM_IS_POWER (power), XFPM_POWER_MODE_NORMAL);
-
- return power->priv->power_mode;
-}
-
-/*
- *
- * DBus server implementation for org.freedesktop.PowerManagement
- *
- */
-static gboolean xfpm_power_dbus_shutdown (XfpmPower *power,
- GError **error);
-
-static gboolean xfpm_power_dbus_reboot (XfpmPower *power,
- GError **error);
-
-static gboolean xfpm_power_dbus_hibernate (XfpmPower * power,
- GError **error);
-
-static gboolean xfpm_power_dbus_suspend (XfpmPower * power,
- GError ** error);
-
-static gboolean xfpm_power_dbus_can_reboot (XfpmPower * power,
- gboolean * OUT_can_reboot,
- GError ** error);
-
-static gboolean xfpm_power_dbus_can_shutdown (XfpmPower * power,
- gboolean * OUT_can_reboot,
- GError ** error);
-
-static gboolean xfpm_power_dbus_can_hibernate (XfpmPower * power,
- gboolean * OUT_can_hibernate,
- GError ** error);
-
-static gboolean xfpm_power_dbus_can_suspend (XfpmPower * power,
- gboolean * OUT_can_suspend,
- GError ** error);
-
-static gboolean xfpm_power_dbus_get_power_save_status (XfpmPower * power,
- gboolean * OUT_save_power,
- 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);
-
-#include "org.freedesktop.PowerManagement.h"
-
-static void
-xfpm_power_dbus_class_init (XfpmPowerClass * klass)
-{
- dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (klass),
- &dbus_glib_xfpm_power_object_info);
-}
-
-static void
-xfpm_power_dbus_init (XfpmPower *power)
+gboolean
+xfpm_power_can_suspend (XfpmPower *power,
+ gboolean *can_suspend,
+ GError **error)
{
- DBusGConnection *bus = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+ if (!up_client_get_properties_sync (power->up_client, NULL, error))
+ return FALSE;
- dbus_g_connection_register_g_object (bus,
- "/org/freedesktop/PowerManagement",
- G_OBJECT (power));
+ *can_suspend = up_client_get_can_suspend (power->up_client);
+ return TRUE;
}
-static gboolean xfpm_power_dbus_shutdown (XfpmPower *power,
- GError **error)
+gboolean
+xfpm_power_can_hibernate (XfpmPower *power,
+ gboolean *can_hibernate,
+ GError **error)
{
- gboolean can_reboot;
-
- g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", &can_reboot,
- NULL);
-
- if ( !can_reboot)
- {
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return FALSE;
- }
-
- xfpm_console_kit_shutdown (power->priv->console, error);
-
- return TRUE;
-}
+ if (!up_client_get_properties_sync (power->up_client, NULL, error))
+ return FALSE;
-static gboolean xfpm_power_dbus_reboot (XfpmPower *power,
- GError **error)
-{
- gboolean can_reboot;
-
- g_object_get (G_OBJECT (power->priv->console),
- "can-restart", &can_reboot,
- NULL);
-
- if ( !can_reboot)
- {
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return FALSE;
- }
-
- xfpm_console_kit_reboot (power->priv->console, error);
-
- return TRUE;
-}
-
-static gboolean xfpm_power_dbus_hibernate (XfpmPower * power,
- GError **error)
-{
- if ( !power->priv->auth_suspend )
- {
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return FALSE;
-
- }
-
- if (!power->priv->can_hibernate )
- {
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_NO_HARDWARE_SUPPORT,
- _("Suspend not supported"));
- return FALSE;
- }
-
- xfpm_power_sleep (power, "Hibernate", FALSE);
-
- return TRUE;
-}
-
-static gboolean xfpm_power_dbus_suspend (XfpmPower * power,
- GError ** error)
-{
- if ( !power->priv->auth_suspend )
- {
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_PERMISSION_DENIED,
- _("Permission denied"));
- return FALSE;
-
- }
-
- if (!power->priv->can_suspend )
- {
- g_set_error (error, XFPM_ERROR, XFPM_ERROR_NO_HARDWARE_SUPPORT,
- _("Suspend not supported"));
- return FALSE;
- }
-
- xfpm_power_sleep (power, "Suspend", FALSE);
-
- return TRUE;
+ *can_hibernate = up_client_get_can_hibernate (power->up_client);
+ return TRUE;
}
-static gboolean xfpm_power_dbus_can_reboot (XfpmPower * power,
- gboolean * OUT_can_reboot,
- GError ** error)
+gboolean
+xfpm_power_get_on_battery (XfpmPower *power,
+ gboolean *on_battery,
+ GError **error)
{
- g_object_get (G_OBJECT (power->priv->console),
- "can-reboot", OUT_can_reboot,
- NULL);
-
- return TRUE;
-}
+ if (!up_client_get_properties_sync (power->up_client, NULL, error))
+ return FALSE;
-static gboolean xfpm_power_dbus_can_shutdown (XfpmPower * power,
- gboolean * OUT_can_shutdown,
- GError ** error)
-{
- g_object_get (G_OBJECT (power->priv->console),
- "can-shutdown", OUT_can_shutdown,
- NULL);
- return TRUE;
+ *on_battery = up_client_get_on_battery (power->up_client);
+ return TRUE;
}
-static gboolean xfpm_power_dbus_can_hibernate (XfpmPower * power,
- gboolean * OUT_can_hibernate,
- GError ** error)
+gboolean
+xfpm_power_get_low_battery (XfpmPower *power,
+ gboolean *low_battery,
+ GError **error)
{
- *OUT_can_hibernate = power->priv->can_hibernate;
- return TRUE;
-}
-
-static gboolean xfpm_power_dbus_can_suspend (XfpmPower * power,
- gboolean * OUT_can_suspend,
- GError ** error)
-{
- *OUT_can_suspend = power->priv->can_suspend;
-
- return TRUE;
-}
+ if (!up_client_get_properties_sync (power->up_client, NULL, error))
+ return FALSE;
-static gboolean xfpm_power_dbus_get_power_save_status (XfpmPower * power,
- gboolean * OUT_save_power,
- GError ** error)
-{
- //FIXME
- return TRUE;
+ *low_battery = up_client_get_on_low_battery (power->up_client);
+ return TRUE;
}
-static gboolean xfpm_power_dbus_get_on_battery (XfpmPower * power,
- gboolean * OUT_on_battery,
- GError ** error)
+XfpmPowerMode xfpm_power_get_mode (XfpmPower *power)
{
- *OUT_on_battery = power->priv->on_battery;
+ g_return_val_if_fail (XFPM_IS_POWER (power), XFPM_POWER_MODE_NORMAL);
- return TRUE;
+ return power->power_mode;
}
-static gboolean xfpm_power_dbus_get_low_battery (XfpmPower * power,
- gboolean * OUT_low_battery,
- GError ** error)
-{
- *OUT_low_battery = power->priv->on_low_battery;
-
- return TRUE;
-}
diff --git a/src/xfpm-power.h b/src/xfpm-power.h
index d9798b0..c138080 100644
--- a/src/xfpm-power.h
+++ b/src/xfpm-power.h
@@ -26,56 +26,43 @@
G_BEGIN_DECLS
-#define XFPM_TYPE_POWER (xfpm_power_get_type () )
-#define XFPM_POWER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XFPM_TYPE_POWER, XfpmPower))
-#define XFPM_IS_POWER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XFPM_TYPE_POWER))
-
-typedef struct XfpmPowerPrivate XfpmPowerPrivate;
-
-typedef struct
-{
- GObject parent;
-
- XfpmPowerPrivate *priv;
-
-} XfpmPower;
-
-typedef struct
-{
- GObjectClass parent_class;
-
- void (*on_battery_changed) (XfpmPower *power,
- gboolean on_battery);
-
- void (*low_battery_changed) (XfpmPower *power,
- gboolean low_battery);
-
- void (*lid_changed) (XfpmPower *power,
- gboolean lid_is_closed);
-
- void (*waking_up) (XfpmPower *power);
-
- void (*sleeping) (XfpmPower *power);
-
- void (*ask_shutdown) (XfpmPower *power);
-
- void (*shutdown) (XfpmPower *power);
-
-} XfpmPowerClass;
-
-GType xfpm_power_get_type (void) G_GNUC_CONST;
-
-XfpmPower *xfpm_power_get (void);
-
-void xfpm_power_suspend (XfpmPower *power,
- gboolean force);
-
-void xfpm_power_hibernate (XfpmPower *power,
- gboolean force);
-
-gboolean xfpm_power_has_battery (XfpmPower *power);
-
-XfpmPowerMode xfpm_power_get_mode (XfpmPower *power);
+typedef struct _XfpmPowerClass XfpmPowerClass;
+typedef struct _XfpmPower XfpmPower;
+
+#define XFPM_TYPE_POWER (xfpm_power_get_type ())
+#define XFPM_POWER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFPM_TYPE_POWER, XfpmPower))
+#define XFPM_POWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFPM_TYPE_POWER, XfpmPowerClass))
+#define XFPM_IS_POWER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFPM_TYPE_POWER))
+#define XFPM_IS_POWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFPM_TYPE_POWER))
+#define XFPM_POWER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFPM_TYPE_POWER, XfpmPowerClass))
+
+GType xfpm_power_get_type (void) G_GNUC_CONST;
+
+XfpmPower *xfpm_power_get (void);
+
+void xfpm_power_suspend (XfpmPower *power,
+ gboolean force);
+
+void xfpm_power_hibernate (XfpmPower *power,
+ gboolean force);
+
+gboolean xfpm_power_can_suspend (XfpmPower *power,
+ gboolean *can_suspend,
+ GError **error);
+
+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_low_battery (XfpmPower *power,
+ gboolean *low_battery,
+ GError **error);
+
+XfpmPowerMode xfpm_power_get_mode (XfpmPower *power);
G_END_DECLS
diff --git a/src/xfpm-sm-client.c b/src/xfpm-sm-client.c
new file mode 100644
index 0000000..ed588bf
--- /dev/null
+++ b/src/xfpm-sm-client.c
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2012 Nick Schermer <nick at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dbus/dbus-glib.h>
+
+#include "xfpm-sm-client.h"
+#include "xfpm-dbus-monitor.h"
+
+
+
+static void xfpm_sm_client_finalize (GObject *object);
+
+
+
+struct _XfpmSMClientClass
+{
+ GObjectClass __parent__;
+};
+
+struct _XfpmSMClient
+{
+ GObject __parent__;
+};
+
+
+
+G_DEFINE_TYPE (XfpmSMClient, xfpm_sm_client, G_TYPE_OBJECT)
+
+
+
+static void
+xfpm_sm_client_class_init (XfpmSMClientClass *klass)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = xfpm_sm_client_finalize;
+}
+
+static void
+xfpm_sm_client_init (XfpmSMClient *sm_client)
+{
+
+}
+
+static void
+xfpm_sm_client_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (xfpm_sm_client_parent_class)->finalize (object);
+}
+
+XfpmSMClient *
+xfpm_sm_client_new (void)
+{
+ static gpointer sm_client = NULL;
+
+ if (G_LIKELY (sm_client != NULL))
+ {
+ g_object_ref (sm_client);
+ }
+ else
+ {
+ sm_client = g_object_new (XFPM_TYPE_SM_CLIENT, NULL);
+ g_object_add_weak_pointer (sm_client, &sm_client);
+ }
+
+ return XFPM_SM_CLIENT (sm_client);
+}
+
+gboolean
+xfpm_sm_client_can_shutdown (XfpmSMClient *sm_client,
+ gboolean *can_shutdown,
+ GError **error)
+{
+ g_return_val_if_fail (XFPM_IS_SM_CLIENT (sm_client), FALSE);
+ g_return_val_if_fail (can_shutdown != NULL, FALSE);
+
+ return TRUE;
+}
+
+gboolean
+xfpm_sm_client_can_restart (XfpmSMClient *sm_client,
+ gboolean *can_restart,
+ GError **error)
+{
+ g_return_val_if_fail (XFPM_IS_SM_CLIENT (sm_client), FALSE);
+ g_return_val_if_fail (can_restart != NULL, FALSE);
+
+ return TRUE;
+}
+
+gboolean
+xfpm_sm_client_shutdown (XfpmSMClient *sm_client,
+ GError **error)
+{
+ g_return_val_if_fail (XFPM_IS_SM_CLIENT (sm_client), FALSE);
+
+ return TRUE;
+}
+
+gboolean
+xfpm_sm_client_restart (XfpmSMClient *sm_client,
+ GError **error)
+{
+ g_return_val_if_fail (XFPM_IS_SM_CLIENT (sm_client), FALSE);
+
+ return TRUE;
+}
diff --git a/src/xfpm-sm-client.h b/src/xfpm-sm-client.h
new file mode 100644
index 0000000..c044c10
--- /dev/null
+++ b/src/xfpm-sm-client.h
@@ -0,0 +1,58 @@
+/*
+ * * Copyright (C) 2009-2011 Ali <aliov at xfce.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef __XFPM_CONSOLE_KIT_H
+#define __XFPM_CONSOLE_KIT_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _XfpmSMClientClass XfpmSMClientClass;
+typedef struct _XfpmSMClient XfpmSMClient;
+
+#define XFPM_TYPE_SM_CLIENT (xfpm_sm_client_get_type ())
+#define XFPM_SM_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFPM_TYPE_SM_CLIENT, XfpmSMClient))
+#define XFPM_SM_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFPM_TYPE_SM_CLIENT, XfpmSMClientClass))
+#define XFPM_IS_SM_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFPM_TYPE_SM_CLIENT))
+#define XFPM_IS_SM_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFPM_TYPE_SM_CLIENT))
+#define XFPM_SM_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFPM_TYPE_SM_CLIENT, XfpmSMClientClass))
+
+GType xfpm_sm_client_get_type (void) G_GNUC_CONST;
+
+XfpmSMClient *xfpm_sm_client_new (void);
+
+gboolean xfpm_sm_client_can_shutdown (XfpmSMClient *sm_client,
+ gboolean *can_shutdown,
+ GError **error);
+
+gboolean xfpm_sm_client_can_restart (XfpmSMClient *sm_client,
+ gboolean *can_restart,
+ GError **error);
+
+gboolean xfpm_sm_client_shutdown (XfpmSMClient *sm_client,
+ GError **error);
+
+gboolean xfpm_sm_client_restart (XfpmSMClient *sm_client,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __XFPM_CONSOLE_KIT_H */
More information about the Xfce4-commits
mailing list