[Xfce4-commits] <xfce4-power-manager:devkit-power> Expose device_type and battery_charge_status as enum properties.
Ali Abdallah
noreply at xfce.org
Wed Nov 11 10:16:03 CET 2009
Updating branch refs/heads/devkit-power
to 4f6383677fc989431b893f5d7a28e1a45235de15 (commit)
from 4e3974f46b3c4b2e8112596a07fec40f99e8b244 (commit)
commit 4f6383677fc989431b893f5d7a28e1a45235de15
Author: Ali Abdallah <ali at ali-xfce.org>
Date: Wed Nov 11 09:08:27 2009 +0100
Expose device_type and battery_charge_status as enum properties.
src/xfpm-battery-info.c | 2 +-
src/xfpm-battery.c | 26 +++++++++++++++++++++++++-
src/xfpm-battery.h | 15 ++-------------
src/xfpm-dkp.c | 22 ++++++++++++++++++----
src/xfpm-dkp.h | 26 --------------------------
src/xfpm-enum-glib.h | 39 ++++++++++++++++++++++++++++++++++++++-
6 files changed, 84 insertions(+), 46 deletions(-)
diff --git a/src/xfpm-battery-info.c b/src/xfpm-battery-info.c
index 7dbf894..508a3d4 100644
--- a/src/xfpm-battery-info.c
+++ b/src/xfpm-battery-info.c
@@ -26,7 +26,7 @@
#include <libxfce4ui/libxfce4ui.h>
#include "xfpm-battery-info.h"
-#include "xfpm-dkp.h"
+#include "xfpm-enum-glib.h"
static const gchar *
xfpm_battery_info_get_device_tech (GHashTable *props)
diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 04705c1..9df5b36 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -71,7 +71,9 @@ struct XfpmBatteryPrivate
enum
{
PROP_0,
- PROP_AC_ONLINE
+ PROP_AC_ONLINE,
+ PROP_CHARGE_STATUS,
+ PROP_DEVICE_TYPE
};
enum
@@ -555,6 +557,12 @@ static void xfpm_battery_get_property (GObject *object,
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;
@@ -611,6 +619,22 @@ xfpm_battery_class_init (XfpmBatteryClass *klass)
FALSE,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_DEVICE_TYPE,
+ g_param_spec_enum ("device-type",
+ NULL, NULL,
+ XFPM_TYPE_DKP_DEVICE_TYPE,
+ XFPM_DKP_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,
+ G_PARAM_READABLE));
+
g_type_class_add_private (klass, sizeof (XfpmBatteryPrivate));
}
diff --git a/src/xfpm-battery.h b/src/xfpm-battery.h
index 9364511..02ff781 100644
--- a/src/xfpm-battery.h
+++ b/src/xfpm-battery.h
@@ -26,6 +26,7 @@
#include <dbus/dbus-glib.h>
#include "xfpm-dkp.h"
+#include "xfpm-enum-glib.h"
G_BEGIN_DECLS
@@ -33,18 +34,6 @@ G_BEGIN_DECLS
#define XFPM_BATTERY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XFPM_TYPE_BATTERY, XfpmBattery))
#define XFPM_IS_BATTERY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XFPM_TYPE_BATTERY))
-/*
- * Order matters
- */
-typedef enum
-{
- XFPM_BATTERY_CHARGE_UNKNOWN,
- XFPM_BATTERY_CHARGE_CRITICAL,
- XFPM_BATTERY_CHARGE_LOW,
- XFPM_BATTERY_CHARGE_OK
-
-} XfpmBatteryCharge;
-
typedef struct XfpmBatteryPrivate XfpmBatteryPrivate;
typedef struct
@@ -71,7 +60,7 @@ void xfpm_battery_monitor_device (XfpmBattery *battery,
DBusGProxy *proxy,
DBusGProxy *proxy_prop,
XfpmDkpDeviceType device_type);
-//FIXME, make these as properties
+
XfpmDkpDeviceType xfpm_battery_get_device_type (XfpmBattery *battery);
XfpmBatteryCharge xfpm_battery_get_charge (XfpmBattery *battery);
diff --git a/src/xfpm-dkp.c b/src/xfpm-dkp.c
index 8cf1949..507912f 100644
--- a/src/xfpm-dkp.c
+++ b/src/xfpm-dkp.c
@@ -629,18 +629,29 @@ static XfpmBatteryCharge
xfpm_dkp_get_current_charge_state (XfpmDkp *dkp)
{
GList *list;
- XfpmBatteryCharge charge = XFPM_BATTERY_CHARGE_UNKNOWN;
guint len, i;
+ XfpmBatteryCharge max_charge_status = XFPM_BATTERY_CHARGE_UNKNOWN;
list = g_hash_table_get_values (dkp->priv->hash);
len = g_list_length (list);
for ( i = 0; i < len; i++)
{
- charge = MAX (charge, xfpm_battery_get_charge (XFPM_BATTERY (g_list_nth_data (list, i))));
+ XfpmBatteryCharge battery_charge;
+ XfpmDkpDeviceType type;
+
+ g_object_get (G_OBJECT (g_list_nth_data (list, i)),
+ "charge-status", &battery_charge,
+ "device-type", &type,
+ NULL);
+ if ( type != XFPM_DKP_DEVICE_TYPE_BATTERY &&
+ type != XFPM_DKP_DEVICE_TYPE_UPS )
+ continue;
+
+ max_charge_status = MAX (max_charge_status, battery_charge);
}
- return charge;
+ return max_charge_status;
}
static void
@@ -866,6 +877,8 @@ xfpm_dkp_battery_charge_changed_cb (XfpmBattery *battery, XfpmDkp *dkp)
battery_charge = xfpm_battery_get_charge (battery);
current_charge = xfpm_dkp_get_current_charge_state (dkp);
+ XFPM_DEBUG_ENUM (current_charge, XFPM_TYPE_BATTERY_CHARGE, "Current system charge status");
+
if ( current_charge == XFPM_BATTERY_CHARGE_CRITICAL && dkp->priv->on_battery)
{
xfpm_dkp_system_on_low_power (dkp, battery);
@@ -953,7 +966,8 @@ xfpm_dkp_add_device (XfpmDkp *dkp, const gchar *object_path)
{
GtkStatusIcon *battery;
DBusGProxy *proxy;
- XFPM_DEBUG ("Battery device detected at : %s", object_path);
+ XFPM_DEBUG_ENUM (device_type, XFPM_TYPE_DKP_DEVICE_TYPE,
+ "Battery device detected at : %s", object_path);
proxy = dbus_g_proxy_new_for_name (dkp->priv->bus,
DKP_NAME,
object_path,
diff --git a/src/xfpm-dkp.h b/src/xfpm-dkp.h
index 8c5714b..609a9c7 100644
--- a/src/xfpm-dkp.h
+++ b/src/xfpm-dkp.h
@@ -34,32 +34,6 @@ G_BEGIN_DECLS
#define DKP_IFACE "org.freedesktop.DeviceKit.Power"
#define DKP_IFACE_DEVICE "org.freedesktop.DeviceKit.Power.Device"
-typedef enum
-{
- XFPM_DKP_DEVICE_TYPE_UNKNOWN,
- XFPM_DKP_DEVICE_TYPE_LINE_POWER,
- XFPM_DKP_DEVICE_TYPE_BATTERY,
- XFPM_DKP_DEVICE_TYPE_UPS,
- XFPM_DKP_DEVICE_TYPE_MONITOR,
- XFPM_DKP_DEVICE_TYPE_MOUSE,
- XFPM_DKP_DEVICE_TYPE_KBD,
- XFPM_DKP_DEVICE_TYPE_PDA,
- XFPM_DKP_DEVICE_TYPE_PHONE
-
-} XfpmDkpDeviceType;
-
-typedef enum
-{
- XFPM_DKP_DEVICE_STATE_UNKNOWN,
- XFPM_DKP_DEVICE_STATE_CHARGING,
- XFPM_DKP_DEVICE_STATE_DISCHARGING,
- XFPM_DKP_DEVICE_STATE_EMPTY,
- XFPM_DKP_DEVICE_STATE_FULLY_CHARGED,
- XFPM_DKP_DEVICE_STATE_PENDING_CHARGING,
- XFPM_DKP_DEVICE_STATE_PENDING_DISCHARGING
-
-} XfpmDkpDeviceState;
-
typedef struct XfpmDkpPrivate XfpmDkpPrivate;
typedef struct
diff --git a/src/xfpm-enum-glib.h b/src/xfpm-enum-glib.h
index 263a7e1..3116752 100644
--- a/src/xfpm-enum-glib.h
+++ b/src/xfpm-enum-glib.h
@@ -29,6 +29,44 @@ G_BEGIN_DECLS
typedef enum
{
+ XFPM_DKP_DEVICE_TYPE_UNKNOWN,
+ XFPM_DKP_DEVICE_TYPE_LINE_POWER,
+ XFPM_DKP_DEVICE_TYPE_BATTERY,
+ XFPM_DKP_DEVICE_TYPE_UPS,
+ XFPM_DKP_DEVICE_TYPE_MONITOR,
+ XFPM_DKP_DEVICE_TYPE_MOUSE,
+ XFPM_DKP_DEVICE_TYPE_KBD,
+ XFPM_DKP_DEVICE_TYPE_PDA,
+ XFPM_DKP_DEVICE_TYPE_PHONE
+
+} XfpmDkpDeviceType;
+
+typedef enum
+{
+ XFPM_DKP_DEVICE_STATE_UNKNOWN,
+ XFPM_DKP_DEVICE_STATE_CHARGING,
+ XFPM_DKP_DEVICE_STATE_DISCHARGING,
+ XFPM_DKP_DEVICE_STATE_EMPTY,
+ XFPM_DKP_DEVICE_STATE_FULLY_CHARGED,
+ XFPM_DKP_DEVICE_STATE_PENDING_CHARGING,
+ XFPM_DKP_DEVICE_STATE_PENDING_DISCHARGING
+
+} XfpmDkpDeviceState;
+
+/*
+ * Order matters
+ */
+typedef enum
+{
+ XFPM_BATTERY_CHARGE_UNKNOWN,
+ XFPM_BATTERY_CHARGE_CRITICAL,
+ XFPM_BATTERY_CHARGE_LOW,
+ XFPM_BATTERY_CHARGE_OK
+
+} XfpmBatteryCharge;
+
+typedef enum
+{
XFPM_DO_NOTHING,
XFPM_DO_SUSPEND,
XFPM_DO_HIBERNATE,
@@ -68,7 +106,6 @@ typedef enum
} XfpmShowIcon;
-
G_END_DECLS
#endif /* __XFPM_ENUM_GLIB_H */
More information about the Xfce4-commits
mailing list