gnome-power-manager r3327 - in trunk: . libdevkit-power



Author: rhughes
Date: Wed Mar  4 12:55:45 2009
New Revision: 3327
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=3327&view=rev

Log:
2009-03-04  Richard Hughes  <richard hughsie com>

* libdevkit-power/dkp-device.c: (dkp_device_get_history):
* libdevkit-power/dkp-enum.h:
* libdevkit-power/dkp-object.c: (dkp_object_collect_props):
Add in a check for the enum type, as upstream DeviceKit-power will
soon move to sending uint based enums, rather than strings.
For now, bodge in some checking code, so that 2-26 can work with
either version of DeviceKit-power.


Modified:
   trunk/ChangeLog
   trunk/libdevkit-power/dkp-device.c
   trunk/libdevkit-power/dkp-enum.h
   trunk/libdevkit-power/dkp-object.c

Modified: trunk/libdevkit-power/dkp-device.c
==============================================================================
--- trunk/libdevkit-power/dkp-device.c	(original)
+++ trunk/libdevkit-power/dkp-device.c	Wed Mar  4 12:55:45 2009
@@ -329,7 +329,10 @@
 		g_value_unset (gv);
 		/* 2 */
 		gv = g_value_array_get_nth (gva, 2);
-		obj->state = dkp_device_state_from_text (g_value_get_string (gv));
+		if (G_VALUE_HOLDS_STRING(gv))
+			obj->state = dkp_device_state_from_text (g_value_get_string (gv));
+		else
+			obj->state = g_value_get_uint (gv);
 		g_value_unset (gv);
 		egg_obj_list_add (array, obj);
 		dkp_history_obj_free (obj);

Modified: trunk/libdevkit-power/dkp-enum.h
==============================================================================
--- trunk/libdevkit-power/dkp-enum.h	(original)
+++ trunk/libdevkit-power/dkp-enum.h	Wed Mar  4 12:55:45 2009
@@ -27,6 +27,7 @@
 G_BEGIN_DECLS
 
 typedef enum {
+	DKP_DEVICE_TYPE_UNKNOWN,
 	DKP_DEVICE_TYPE_LINE_POWER,
 	DKP_DEVICE_TYPE_BATTERY,
 	DKP_DEVICE_TYPE_UPS,
@@ -35,25 +36,27 @@
 	DKP_DEVICE_TYPE_KEYBOARD,
 	DKP_DEVICE_TYPE_PDA,
 	DKP_DEVICE_TYPE_PHONE,
-	DKP_DEVICE_TYPE_UNKNOWN
+	DKP_DEVICE_TYPE_LAST
 } DkpDeviceType;
 
 typedef enum {
+	DKP_DEVICE_STATE_UNKNOWN,
 	DKP_DEVICE_STATE_CHARGING,
 	DKP_DEVICE_STATE_DISCHARGING,
 	DKP_DEVICE_STATE_EMPTY,
 	DKP_DEVICE_STATE_FULLY_CHARGED,
-	DKP_DEVICE_STATE_UNKNOWN
+	DKP_DEVICE_STATE_LAST
 } DkpDeviceState;
 
 typedef enum {
+	DKP_DEVICE_TECHNOLGY_UNKNOWN,
 	DKP_DEVICE_TECHNOLGY_LITHIUM_ION,
 	DKP_DEVICE_TECHNOLGY_LITHIUM_POLYMER,
 	DKP_DEVICE_TECHNOLGY_LITHIUM_IRON_PHOSPHATE,
 	DKP_DEVICE_TECHNOLGY_LEAD_ACID,
 	DKP_DEVICE_TECHNOLGY_NICKEL_CADMIUM,
 	DKP_DEVICE_TECHNOLGY_NICKEL_METAL_HYDRIDE,
-	DKP_DEVICE_TECHNOLGY_UNKNOWN
+	DKP_DEVICE_TECHNOLGY_LAST
 } DkpDeviceTechnology;
 
 const gchar	*dkp_device_type_to_text	(DkpDeviceType		 type_enum);

Modified: trunk/libdevkit-power/dkp-object.c
==============================================================================
--- trunk/libdevkit-power/dkp-object.c	(original)
+++ trunk/libdevkit-power/dkp-object.c	Wed Mar  4 12:55:45 2009
@@ -77,9 +77,12 @@
 		obj->serial = g_strdup (g_value_get_string (value));
 	else if (g_strcmp0 (key, "update-time") == 0)
 		obj->update_time = g_value_get_uint64 (value);
-	else if (g_strcmp0 (key, "type") == 0)
-		obj->type = dkp_device_type_from_text (g_value_get_string (value));
-	else if (g_strcmp0 (key, "online") == 0)
+	else if (g_strcmp0 (key, "type") == 0) {
+		if (G_VALUE_HOLDS_STRING(value))
+			obj->type = dkp_device_type_from_text (g_value_get_string (value));
+		else
+			obj->type = g_value_get_uint (value);
+	} else if (g_strcmp0 (key, "online") == 0)
 		obj->online = g_value_get_boolean (value);
 	else if (g_strcmp0 (key, "has-history") == 0)
 		obj->has_history = g_value_get_boolean (value);
@@ -103,9 +106,12 @@
 		obj->time_to_empty = g_value_get_int64 (value);
 	else if (g_strcmp0 (key, "percentage") == 0)
 		obj->percentage = g_value_get_double (value);
-	else if (g_strcmp0 (key, "technology") == 0)
-		obj->technology = dkp_device_technology_from_text (g_value_get_string (value));
-	else if (g_strcmp0 (key, "is-present") == 0)
+	else if (g_strcmp0 (key, "technology") == 0) {
+		if (G_VALUE_HOLDS_STRING(value))
+			obj->technology = dkp_device_technology_from_text (g_value_get_string (value));
+		else
+			obj->technology = g_value_get_uint (value);
+	} else if (g_strcmp0 (key, "is-present") == 0)
 		obj->is_present = g_value_get_boolean (value);
 	else if (g_strcmp0 (key, "is-rechargeable") == 0)
 		obj->is_rechargeable = g_value_get_boolean (value);
@@ -113,9 +119,12 @@
 		obj->power_supply = g_value_get_boolean (value);
 	else if (g_strcmp0 (key, "capacity") == 0)
 		obj->capacity = g_value_get_double (value);
-	else if (g_strcmp0 (key, "state") == 0)
-		obj->state = dkp_device_state_from_text (g_value_get_string (value));
-	else
+	else if (g_strcmp0 (key, "state") == 0) {
+		if (G_VALUE_HOLDS_STRING(value))
+			obj->state = dkp_device_state_from_text (g_value_get_string (value));
+		else
+			obj->state = g_value_get_uint (value);
+	} else
 		handled = FALSE;
 
 	if (!handled)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]