gnome-power-manager r3101 - in trunk: . libdevkit-power src
- From: rhughes svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-power-manager r3101 - in trunk: . libdevkit-power src
- Date: Wed, 26 Nov 2008 11:35:13 +0000 (UTC)
Author: rhughes
Date: Wed Nov 26 11:35:12 2008
New Revision: 3101
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=3101&view=rev
Log:
2008-11-26 Richard Hughes <richard hughsie com>
* configure.ac:
* libdevkit-power/Makefile.am:
* libdevkit-power/dkp-client-device.c:
* libdevkit-power/dkp-client-device.h:
* libdevkit-power/dkp-client.c: (dkp_client_get_device),
(dkp_client_enumerate_devices),
(dkp_client_enumerate_devices_private), (dkp_client_add),
(dkp_client_remove), (dkp_device_added_cb),
(dkp_device_changed_cb), (dkp_device_removed_cb),
(dkp_client_class_init), (dkp_client_init), (dkp_client_finalize):
* libdevkit-power/dkp-client.h:
* libdevkit-power/dkp-device.c: (dkp_device_get_device_properties),
(dkp_device_refresh_internal), (dkp_device_changed_cb),
(dkp_device_set_object_path), (dkp_device_get_object_path),
(dkp_device_get_object), (dkp_device_print_history),
(dkp_device_print), (dkp_device_refresh), (dkp_device_get_history),
(dkp_device_get_statistics), (dkp_device_class_init),
(dkp_device_init), (dkp_device_finalize), (dkp_device_new):
* libdevkit-power/dkp-device.h:
Rename DkpClientDevice to DkpDevice.
* src/Makefile.am:
* src/gpm-ac-adapter.c: (gpm_ac_adapter_is_present),
(gpm_ac_adapter_changed_cb), (gpm_ac_adapter_finalize),
(gpm_ac_adapter_init):
* src/gpm-devicekit.c: (gpm_devicekit_get_object_summary):
* src/gpm-devicekit.h:
* src/gpm-engine-old.c: (ac_adaptor_changed_cb),
(control_resume_cb), (gpm_engine_conf_key_changed_cb),
(gpm_engine_coldplug_idle_cb), (gpm_engine_init),
(gpm_engine_class_init):
* src/gpm-engine-old.h:
* src/gpm-engine.c:
* src/gpm-engine.h:
* src/gpm-info.c:
* src/gpm-info.h:
* src/gpm-manager.c: (gpm_engine_perhaps_recall_cb),
(gpm_engine_low_capacity_cb), (gpm_engine_icon_changed_cb),
(gpm_engine_summary_changed_cb), (gpm_engine_fully_charged_cb),
(gpm_engine_discharging_cb), (control_sleep_failure_cb),
(gpm_engine_charge_low_cb),
(gpm_manager_get_time_until_action_text),
(gpm_engine_charge_critical_cb):
* src/gpm-statistics.c: (gpm_stats_button_help_cb),
(gpm_stats_add_info_columns), (gpm_stats_add_devices_columns),
(gpm_stats_add_info_data), (gpm_stats_update_smooth_data),
(gpm_stats_time_to_text), (gpm_stats_bool_to_text),
(gpm_stats_update_info_page_details),
(gpm_stats_update_info_page_history),
(gpm_stats_update_info_page_stats),
(gpm_stats_update_info_data_page), (gpm_stats_update_info_data),
(gpm_stats_notebook_changed_cb), (gpm_stats_button_refresh_cb),
(gpm_stats_button_update_ui),
(gpm_stats_devices_treeview_clicked_cb),
(gpm_stats_create_custom_widget), (gpm_stats_window_activated_cb),
(gpm_stats_add_device), (gpm_stats_device_added_cb),
(gpm_stats_device_changed_cb), (gpm_stats_device_removed_cb),
(gpm_stats_history_type_combo_changed_cb),
(gpm_stats_type_combo_changed_cb), (gpm_stats_range_combo_changed),
(gpm_stats_smooth_checkbox_history_cb),
(gpm_stats_smooth_checkbox_stats_cb), (main):
* src/gpm-tray-icon.c: (gpm_tray_icon_set_collection_data),
(gpm_tray_icon_show_info_cb), (gpm_tray_icon_popup_cleared_cd),
(gpm_tray_icon_class_init), (gpm_tray_icon_popup_menu_cb),
(gpm_tray_icon_add_device), (gpm_tray_icon_activate_cb),
(gpm_tray_icon_init), (gpm_tray_icon_finalize):
* src/gpm-tray-icon.h:
* src/gpm-warnings.c: (gpm_warnings_get_state_csr),
(gpm_warnings_get_state_time):
Add a new engine that uses DeviceKit, not HAL.
Added:
trunk/libdevkit-power/dkp-device.c (contents, props changed)
- copied, changed from r3099, /trunk/libdevkit-power/dkp-client-device.c
trunk/libdevkit-power/dkp-device.h (contents, props changed)
- copied, changed from r3099, /trunk/libdevkit-power/dkp-client-device.h
trunk/src/gpm-engine-old.c (contents, props changed)
- copied, changed from r3097, /trunk/src/gpm-engine.c
trunk/src/gpm-engine-old.h (contents, props changed)
- copied, changed from r3097, /trunk/src/gpm-engine.h
Removed:
trunk/libdevkit-power/dkp-client-device.c
trunk/libdevkit-power/dkp-client-device.h
trunk/src/gpm-engine.c
trunk/src/gpm-engine.h
Modified:
trunk/ChangeLog
trunk/configure.ac
trunk/libdevkit-power/Makefile.am
trunk/libdevkit-power/dkp-client.c
trunk/libdevkit-power/dkp-client.h
trunk/src/Makefile.am
trunk/src/gpm-ac-adapter.c
trunk/src/gpm-cell-array.c
trunk/src/gpm-devicekit.c
trunk/src/gpm-devicekit.h
trunk/src/gpm-info.c
trunk/src/gpm-info.h
trunk/src/gpm-manager.c
trunk/src/gpm-statistics.c
trunk/src/gpm-tray-icon.c
trunk/src/gpm-tray-icon.h
trunk/src/gpm-warnings.c
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Wed Nov 26 11:35:12 2008
@@ -1,6 +1,6 @@
AC_PREREQ(2.60)
-AC_INIT(gnome-power-manager, 2.23.91)
+AC_INIT(gnome-power-manager, 2.25.1)
AC_CONFIG_SRCDIR(src)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AM_CONFIG_HEADER(config.h)
Modified: trunk/libdevkit-power/Makefile.am
==============================================================================
--- trunk/libdevkit-power/Makefile.am (original)
+++ trunk/libdevkit-power/Makefile.am Wed Nov 26 11:35:12 2008
@@ -21,8 +21,8 @@
egg-obj-list.h \
dkp-client.c \
dkp-client.h \
- dkp-client-device.c \
- dkp-client-device.h \
+ dkp-device.c \
+ dkp-device.h \
dkp-history-obj.h \
dkp-history-obj.c \
dkp-stats-obj.h \
Modified: trunk/libdevkit-power/dkp-client.c
==============================================================================
--- trunk/libdevkit-power/dkp-client.c (original)
+++ trunk/libdevkit-power/dkp-client.c Wed Nov 26 11:35:12 2008
@@ -28,7 +28,7 @@
#include "egg-debug.h"
#include "dkp-client.h"
-#include "dkp-client-device.h"
+#include "dkp-device.h"
static void dkp_client_class_init (DkpClientClass *klass);
static void dkp_client_init (DkpClient *client);
@@ -54,9 +54,9 @@
};
enum {
- DKP_CLIENT_DEVICE_ADDED,
- DKP_CLIENT_DEVICE_CHANGED,
- DKP_CLIENT_DEVICE_REMOVED,
+ DKP_DEVICE_ADDED,
+ DKP_DEVICE_CHANGED,
+ DKP_DEVICE_REMOVED,
DKP_CLIENT_CHANGED,
DKP_CLIENT_LAST_SIGNAL
};
@@ -68,19 +68,41 @@
/**
* dkp_client_get_device:
**/
-static DkpClientDevice *
+static DkpDevice *
dkp_client_get_device (DkpClient *client, const gchar *object_path)
{
- DkpClientDevice *device;
+ DkpDevice *device;
device = g_hash_table_lookup (client->priv->hash, object_path);
return device;
}
/**
* dkp_client_enumerate_devices:
+ *
+ * Return a list of devices, which need to be unref'd, and the array needs
+ * to be freed
+ **/
+GPtrArray *
+dkp_client_enumerate_devices (DkpClient *client)
+{
+ guint i;
+ GPtrArray *array;
+ DkpDevice *device;
+
+ array = g_ptr_array_new ();
+ for (i=0; i<client->priv->array->len; i++) {
+ device = g_ptr_array_index (client->priv->array, i);
+ g_object_ref (device);
+ g_ptr_array_add (array, device);
+ }
+ return array;
+}
+
+/**
+ * dkp_client_enumerate_devices_private:
**/
GPtrArray *
-dkp_client_enumerate_devices (DkpClient *client, GError **error)
+dkp_client_enumerate_devices_private (DkpClient *client, GError **error)
{
gboolean ret;
GError *error_local = NULL;
@@ -231,14 +253,14 @@
/**
* dkp_client_add:
**/
-static DkpClientDevice *
+static DkpDevice *
dkp_client_add (DkpClient *client, const gchar *object_path)
{
- DkpClientDevice *device;
+ DkpDevice *device;
/* create new device */
- device = dkp_client_device_new ();
- dkp_client_device_set_object_path (device, object_path);
+ device = dkp_device_new ();
+ dkp_device_set_object_path (device, object_path);
g_ptr_array_add (client->priv->array, device);
g_hash_table_insert (client->priv->hash, g_strdup (object_path), device);
@@ -249,7 +271,7 @@
* dkp_client_remove:
**/
static gboolean
-dkp_client_remove (DkpClient *client, DkpClientDevice *device)
+dkp_client_remove (DkpClient *client, DkpDevice *device)
{
/* deallocate it */
g_object_unref (device);
@@ -263,37 +285,37 @@
* dkp_client_added_cb:
**/
static void
-dkp_client_device_added_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
+dkp_device_added_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
{
- DkpClientDevice *device;
+ DkpDevice *device;
/* create new device */
device = dkp_client_add (client, object_path);
- g_signal_emit (client, signals [DKP_CLIENT_DEVICE_ADDED], 0, device);
+ g_signal_emit (client, signals [DKP_DEVICE_ADDED], 0, device);
}
/**
* dkp_client_changed_cb:
**/
static void
-dkp_client_device_changed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
+dkp_device_changed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
{
- DkpClientDevice *device;
+ DkpDevice *device;
device = dkp_client_get_device (client, object_path);
if (device != NULL)
- g_signal_emit (client, signals [DKP_CLIENT_DEVICE_CHANGED], 0, device);
+ g_signal_emit (client, signals [DKP_DEVICE_CHANGED], 0, device);
}
/**
* dkp_client_removed_cb:
**/
static void
-dkp_client_device_removed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
+dkp_device_removed_cb (DBusGProxy *proxy, const gchar *object_path, DkpClient *client)
{
- DkpClientDevice *device;
+ DkpDevice *device;
device = dkp_client_get_device (client, object_path);
if (device != NULL)
- g_signal_emit (client, signals [DKP_CLIENT_DEVICE_REMOVED], 0, device);
+ g_signal_emit (client, signals [DKP_DEVICE_REMOVED], 0, device);
dkp_client_remove (client, device);
}
@@ -317,19 +339,19 @@
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = dkp_client_finalize;
- signals [DKP_CLIENT_DEVICE_ADDED] =
+ signals [DKP_DEVICE_ADDED] =
g_signal_new ("device-added",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DkpClientClass, device_added),
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals [DKP_CLIENT_DEVICE_REMOVED] =
+ signals [DKP_DEVICE_REMOVED] =
g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DkpClientClass, device_removed),
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals [DKP_CLIENT_DEVICE_CHANGED] =
+ signals [DKP_DEVICE_CHANGED] =
g_signal_new ("device-changed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (DkpClientClass, device_changed),
@@ -395,16 +417,16 @@
/* all callbacks */
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceAdded",
- G_CALLBACK (dkp_client_device_added_cb), client, NULL);
+ G_CALLBACK (dkp_device_added_cb), client, NULL);
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceRemoved",
- G_CALLBACK (dkp_client_device_removed_cb), client, NULL);
+ G_CALLBACK (dkp_device_removed_cb), client, NULL);
dbus_g_proxy_connect_signal (client->priv->proxy, "DeviceChanged",
- G_CALLBACK (dkp_client_device_changed_cb), client, NULL);
+ G_CALLBACK (dkp_device_changed_cb), client, NULL);
dbus_g_proxy_connect_signal (client->priv->proxy, "Changed",
G_CALLBACK (dkp_client_changed_cb), client, NULL);
/* coldplug */
- devices = dkp_client_enumerate_devices (client, NULL);
+ devices = dkp_client_enumerate_devices_private (client, NULL);
if (devices == NULL)
goto out;
for (i=0; i<devices->len; i++) {
@@ -423,7 +445,7 @@
dkp_client_finalize (GObject *object)
{
DkpClient *client;
- DkpClientDevice *device;
+ DkpDevice *device;
guint i;
g_return_if_fail (DKP_IS_CLIENT (object));
@@ -432,7 +454,7 @@
/* free any devices */
for (i=0; i<client->priv->array->len; i++) {
- device = (DkpClientDevice *) g_ptr_array_index (client->priv->array, i);
+ device = (DkpDevice *) g_ptr_array_index (client->priv->array, i);
dkp_client_remove (client, device);
}
Modified: trunk/libdevkit-power/dkp-client.h
==============================================================================
--- trunk/libdevkit-power/dkp-client.h (original)
+++ trunk/libdevkit-power/dkp-client.h Wed Nov 26 11:35:12 2008
@@ -24,7 +24,7 @@
#include <glib-object.h>
#include <dkp-enum.h>
-#include "dkp-client-device.h"
+#include "dkp-device.h"
G_BEGIN_DECLS
@@ -49,25 +49,22 @@
{
GObjectClass parent_class;
void (*device_added) (DkpClient *client,
- const DkpClientDevice *device);
+ const DkpDevice *device);
void (*device_changed) (DkpClient *client,
- const DkpClientDevice *device);
+ const DkpDevice *device);
void (*device_removed) (DkpClient *client,
- const DkpClientDevice *device);
- void (*changed) (DkpClient *client,
- gboolean on_battery);
+ const DkpDevice *device);
+ void (*changed) (DkpClient *client);
} DkpClientClass;
GType dkp_client_get_type (void) G_GNUC_CONST;
DkpClient *dkp_client_new (void);
-GPtrArray *dkp_client_enumerate_devices (DkpClient *client,
- GError **error);
-
-const gchar *dkp_client_get_daemon_version (DkpClient *client);
-gboolean dkp_client_can_hibernate (DkpClient *client);
-gboolean dkp_client_can_suspend (DkpClient *client);
-gboolean dkp_client_on_battery (DkpClient *client);
-gboolean dkp_client_on_low_battery (DkpClient *client);
+GPtrArray *dkp_client_enumerate_devices (DkpClient *client);
+const gchar *dkp_client_get_daemon_version (DkpClient *client);
+gboolean dkp_client_can_hibernate (DkpClient *client);
+gboolean dkp_client_can_suspend (DkpClient *client);
+gboolean dkp_client_on_battery (DkpClient *client);
+gboolean dkp_client_on_low_battery (DkpClient *client);
G_END_DECLS
Copied: trunk/libdevkit-power/dkp-device.c (from r3099, /trunk/libdevkit-power/dkp-client-device.c)
==============================================================================
--- /trunk/libdevkit-power/dkp-client-device.c (original)
+++ trunk/libdevkit-power/dkp-device.c Wed Nov 26 11:35:12 2008
@@ -29,18 +29,18 @@
#include "egg-debug.h"
#include "egg-obj-list.h"
-#include "dkp-client-device.h"
+#include "dkp-device.h"
#include "dkp-object.h"
#include "dkp-stats-obj.h"
#include "dkp-history-obj.h"
-static void dkp_client_device_class_init (DkpClientDeviceClass *klass);
-static void dkp_client_device_init (DkpClientDevice *device);
-static void dkp_client_device_finalize (GObject *object);
+static void dkp_device_class_init (DkpDeviceClass *klass);
+static void dkp_device_init (DkpDevice *device);
+static void dkp_device_finalize (GObject *object);
-#define DKP_CLIENT_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_CLIENT_DEVICE, DkpClientDevicePrivate))
+#define DKP_DEVICE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), DKP_TYPE_DEVICE, DkpDevicePrivate))
-struct DkpClientDevicePrivate
+struct DkpDevicePrivate
{
gchar *object_path;
DkpObject *obj;
@@ -50,19 +50,19 @@
};
enum {
- DKP_CLIENT_DEVICE_CHANGED,
- DKP_CLIENT_DEVICE_LAST_SIGNAL
+ DKP_DEVICE_CHANGED,
+ DKP_DEVICE_LAST_SIGNAL
};
-static guint signals [DKP_CLIENT_DEVICE_LAST_SIGNAL] = { 0 };
+static guint signals [DKP_DEVICE_LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (DkpClientDevice, dkp_client_device, G_TYPE_OBJECT)
+G_DEFINE_TYPE (DkpDevice, dkp_device, G_TYPE_OBJECT)
/**
- * dkp_client_device_get_device_properties:
+ * dkp_device_get_device_properties:
**/
static GHashTable *
-dkp_client_device_get_device_properties (DkpClientDevice *device)
+dkp_device_get_device_properties (DkpDevice *device)
{
gboolean ret;
GError *error = NULL;
@@ -84,15 +84,15 @@
}
/**
- * dkp_client_device_refresh_internal:
+ * dkp_device_refresh_internal:
**/
static gboolean
-dkp_client_device_refresh_internal (DkpClientDevice *device)
+dkp_device_refresh_internal (DkpDevice *device)
{
GHashTable *hash;
/* get all the properties */
- hash = dkp_client_device_get_device_properties (device);
+ hash = dkp_device_get_device_properties (device);
if (hash == NULL) {
egg_warning ("Cannot get device properties for %s", device->priv->object_path);
return FALSE;
@@ -103,28 +103,28 @@
}
/**
- * dkp_client_device_changed_cb:
+ * dkp_device_changed_cb:
**/
static void
-dkp_client_device_changed_cb (DBusGProxy *proxy, DkpClientDevice *device)
+dkp_device_changed_cb (DBusGProxy *proxy, DkpDevice *device)
{
- g_return_if_fail (DKP_IS_CLIENT_DEVICE (device));
- dkp_client_device_refresh_internal (device);
- g_signal_emit (device, signals [DKP_CLIENT_DEVICE_CHANGED], 0, device->priv->obj);
+ g_return_if_fail (DKP_IS_DEVICE (device));
+ dkp_device_refresh_internal (device);
+ g_signal_emit (device, signals [DKP_DEVICE_CHANGED], 0, device->priv->obj);
}
/**
- * dkp_client_device_set_object_path:
+ * dkp_device_set_object_path:
**/
gboolean
-dkp_client_device_set_object_path (DkpClientDevice *device, const gchar *object_path)
+dkp_device_set_object_path (DkpDevice *device, const gchar *object_path)
{
GError *error = NULL;
gboolean ret = FALSE;
DBusGProxy *proxy_device;
DBusGProxy *proxy_props;
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
+ g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
if (device->priv->object_path != NULL)
return FALSE;
@@ -158,7 +158,7 @@
/* listen to Changed */
dbus_g_proxy_add_signal (proxy_device, "Changed", G_TYPE_INVALID);
dbus_g_proxy_connect_signal (proxy_device, "Changed",
- G_CALLBACK (dkp_client_device_changed_cb), device, NULL);
+ G_CALLBACK (dkp_device_changed_cb), device, NULL);
/* yay */
egg_debug ("using object_path: %s", object_path);
@@ -167,7 +167,7 @@
device->priv->object_path = g_strdup (object_path);
/* coldplug */
- ret = dkp_client_device_refresh_internal (device);
+ ret = dkp_device_refresh_internal (device);
if (!ret)
egg_warning ("cannot refresh");
out:
@@ -175,30 +175,30 @@
}
/**
- * dkp_client_device_get_object_path:
+ * dkp_device_get_object_path:
**/
const gchar *
-dkp_client_device_get_object_path (const DkpClientDevice *device)
+dkp_device_get_object_path (const DkpDevice *device)
{
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), NULL);
+ g_return_val_if_fail (DKP_IS_DEVICE (device), NULL);
return device->priv->object_path;
}
/**
- * dkp_client_device_get_object:
+ * dkp_device_get_object:
**/
const DkpObject *
-dkp_client_device_get_object (const DkpClientDevice *device)
+dkp_device_get_object (const DkpDevice *device)
{
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), NULL);
+ g_return_val_if_fail (DKP_IS_DEVICE (device), NULL);
return device->priv->obj;
}
/**
- * dkp_client_device_print_history:
+ * dkp_device_print_history:
**/
static gboolean
-dkp_client_device_print_history (const DkpClientDevice *device, const gchar *type)
+dkp_device_print_history (const DkpDevice *device, const gchar *type)
{
guint i;
EggObjList *array;
@@ -206,7 +206,7 @@
gboolean ret = FALSE;
/* get a fair chunk of data */
- array = dkp_client_device_get_history (device, type, 120, 10);
+ array = dkp_device_get_history (device, type, 120, 10);
if (array == NULL)
goto out;
@@ -223,33 +223,33 @@
}
/**
- * dkp_client_device_print:
+ * dkp_device_print:
**/
gboolean
-dkp_client_device_print (const DkpClientDevice *device)
+dkp_device_print (const DkpDevice *device)
{
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
+ g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
/* print to screen */
dkp_object_print (device->priv->obj);
/* if we can, get history */
- dkp_client_device_print_history (device, "charge");
- dkp_client_device_print_history (device, "rate");
+ dkp_device_print_history (device, "charge");
+ dkp_device_print_history (device, "rate");
return TRUE;
}
/**
- * dkp_client_device_refresh:
+ * dkp_device_refresh:
**/
gboolean
-dkp_client_device_refresh (DkpClientDevice *device)
+dkp_device_refresh (DkpDevice *device)
{
GError *error = NULL;
gboolean ret;
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
+ g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
/* just refresh the device */
@@ -265,12 +265,12 @@
}
/**
- * dkp_client_device_get_history:
+ * dkp_device_get_history:
*
* Returns an array of %DkpHistoryObj's
**/
EggObjList *
-dkp_client_device_get_history (const DkpClientDevice *device, const gchar *type, guint timespec, guint resolution)
+dkp_device_get_history (const DkpDevice *device, const gchar *type, guint timespec, guint resolution)
{
GError *error = NULL;
GType g_type_gvalue_array;
@@ -282,7 +282,7 @@
EggObjList *array = NULL;
gboolean ret;
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
+ g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
@@ -343,12 +343,12 @@
}
/**
- * dkp_client_device_get_statistics:
+ * dkp_device_get_statistics:
*
* Returns an array of %DkpStatsObj's
**/
EggObjList *
-dkp_client_device_get_statistics (const DkpClientDevice *device, const gchar *type)
+dkp_device_get_statistics (const DkpDevice *device, const gchar *type)
{
GError *error = NULL;
GType g_type_gvalue_array;
@@ -360,7 +360,7 @@
EggObjList *array = NULL;
gboolean ret;
- g_return_val_if_fail (DKP_IS_CLIENT_DEVICE (device), FALSE);
+ g_return_val_if_fail (DKP_IS_DEVICE (device), FALSE);
g_return_val_if_fail (device->priv->proxy_device != NULL, FALSE);
g_type_gvalue_array = dbus_g_type_get_collection ("GPtrArray",
@@ -416,40 +416,40 @@
}
/**
- * dkp_client_device_class_init:
- * @klass: The DkpClientDeviceClass
+ * dkp_device_class_init:
+ * @klass: The DkpDeviceClass
**/
static void
-dkp_client_device_class_init (DkpClientDeviceClass *klass)
+dkp_device_class_init (DkpDeviceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = dkp_client_device_finalize;
+ object_class->finalize = dkp_device_finalize;
/**
* PkClient::changed:
- * @device: the #DkpClientDevice instance that emitted the signal
+ * @device: the #DkpDevice instance that emitted the signal
* @obj: the #DkpObject that has changed
*
* The ::changed signal is emitted when the device data has changed.
**/
- signals [DKP_CLIENT_DEVICE_CHANGED] =
+ signals [DKP_DEVICE_CHANGED] =
g_signal_new ("changed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (DkpClientDeviceClass, changed),
+ G_STRUCT_OFFSET (DkpDeviceClass, changed),
NULL, NULL, g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE, 1, G_TYPE_POINTER);
- g_type_class_add_private (klass, sizeof (DkpClientDevicePrivate));
+ g_type_class_add_private (klass, sizeof (DkpDevicePrivate));
}
/**
- * dkp_client_device_init:
- * @client_device: This class instance
+ * dkp_device_init:
+ * @device: This class instance
**/
static void
-dkp_client_device_init (DkpClientDevice *device)
+dkp_device_init (DkpDevice *device)
{
- device->priv = DKP_CLIENT_DEVICE_GET_PRIVATE (device);
+ device->priv = DKP_DEVICE_GET_PRIVATE (device);
device->priv->object_path = NULL;
device->priv->proxy_device = NULL;
device->priv->proxy_props = NULL;
@@ -457,17 +457,17 @@
}
/**
- * dkp_client_device_finalize:
+ * dkp_device_finalize:
* @object: The object to finalize
**/
static void
-dkp_client_device_finalize (GObject *object)
+dkp_device_finalize (GObject *object)
{
- DkpClientDevice *device;
+ DkpDevice *device;
- g_return_if_fail (DKP_IS_CLIENT_DEVICE (object));
+ g_return_if_fail (DKP_IS_DEVICE (object));
- device = DKP_CLIENT_DEVICE (object);
+ device = DKP_DEVICE (object);
g_free (device->priv->object_path);
dkp_object_free (device->priv->obj);
@@ -477,19 +477,19 @@
g_object_unref (device->priv->proxy_props);
dbus_g_connection_unref (device->priv->bus);
- G_OBJECT_CLASS (dkp_client_device_parent_class)->finalize (object);
+ G_OBJECT_CLASS (dkp_device_parent_class)->finalize (object);
}
/**
- * dkp_client_device_new:
+ * dkp_device_new:
*
- * Return value: a new DkpClientDevice object.
+ * Return value: a new DkpDevice object.
**/
-DkpClientDevice *
-dkp_client_device_new (void)
+DkpDevice *
+dkp_device_new (void)
{
- DkpClientDevice *device;
- device = g_object_new (DKP_TYPE_CLIENT_DEVICE, NULL);
- return DKP_CLIENT_DEVICE (device);
+ DkpDevice *device;
+ device = g_object_new (DKP_TYPE_DEVICE, NULL);
+ return DKP_DEVICE (device);
}
Copied: trunk/libdevkit-power/dkp-device.h (from r3099, /trunk/libdevkit-power/dkp-client-device.h)
==============================================================================
--- /trunk/libdevkit-power/dkp-client-device.h (original)
+++ trunk/libdevkit-power/dkp-device.h Wed Nov 26 11:35:12 2008
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef __DKP_CLIENT_DEVICE_H
-#define __DKP_CLIENT_DEVICE_H
+#ifndef __DKP_DEVICE_H
+#define __DKP_DEVICE_H
#include <glib-object.h>
#include <dkp-enum.h>
@@ -29,48 +29,48 @@
G_BEGIN_DECLS
-#define DKP_TYPE_CLIENT_DEVICE (dkp_client_device_get_type ())
-#define DKP_CLIENT_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_TYPE_CLIENT_DEVICE, DkpClientDevice))
-#define DKP_CLIENT_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_TYPE_CLIENT_DEVICE, DkpClientDeviceClass))
-#define DKP_IS_CLIENT_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_TYPE_CLIENT_DEVICE))
-#define DKP_IS_CLIENT_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_TYPE_CLIENT_DEVICE))
-#define DKP_CLIENT_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_TYPE_CLIENT_DEVICE, DkpClientDeviceClass))
-#define DKP_CLIENT_DEVICE_ERROR (dkp_client_device_error_quark ())
-#define DKP_CLIENT_DEVICE_TYPE_ERROR (dkp_client_device_error_get_type ())
+#define DKP_TYPE_DEVICE (dkp_device_get_type ())
+#define DKP_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), DKP_TYPE_DEVICE, DkpDevice))
+#define DKP_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), DKP_TYPE_DEVICE, DkpDeviceClass))
+#define DKP_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), DKP_TYPE_DEVICE))
+#define DKP_IS_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), DKP_TYPE_DEVICE))
+#define DKP_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), DKP_TYPE_DEVICE, DkpDeviceClass))
+#define DKP_DEVICE_ERROR (dkp_device_error_quark ())
+#define DKP_DEVICE_TYPE_ERROR (dkp_device_error_get_type ())
-typedef struct DkpClientDevicePrivate DkpClientDevicePrivate;
+typedef struct DkpDevicePrivate DkpDevicePrivate;
typedef struct
{
GObject parent;
- DkpClientDevicePrivate *priv;
-} DkpClientDevice;
+ DkpDevicePrivate *priv;
+} DkpDevice;
typedef struct
{
GObjectClass parent_class;
- void (*changed) (DkpClientDevice *device,
+ void (*changed) (DkpDevice *device,
const DkpObject *obj);
-} DkpClientDeviceClass;
+} DkpDeviceClass;
-GType dkp_client_device_get_type (void) G_GNUC_CONST;
-DkpClientDevice *dkp_client_device_new (void);
+GType dkp_device_get_type (void) G_GNUC_CONST;
+DkpDevice *dkp_device_new (void);
-const DkpObject *dkp_client_device_get_object (const DkpClientDevice *device);
-const gchar *dkp_client_device_get_object_path (const DkpClientDevice *device);
-gboolean dkp_client_device_set_object_path (DkpClientDevice *device,
+const DkpObject *dkp_device_get_object (const DkpDevice *device);
+const gchar *dkp_device_get_object_path (const DkpDevice *device);
+gboolean dkp_device_set_object_path (DkpDevice *device,
const gchar *object_path);
-gboolean dkp_client_device_print (const DkpClientDevice *device);
-gboolean dkp_client_device_refresh (DkpClientDevice *device);
-EggObjList *dkp_client_device_get_history (const DkpClientDevice *device,
+gboolean dkp_device_print (const DkpDevice *device);
+gboolean dkp_device_refresh (DkpDevice *device);
+EggObjList *dkp_device_get_history (const DkpDevice *device,
const gchar *type,
guint timespec,
guint resolution);
-EggObjList *dkp_client_device_get_statistics (const DkpClientDevice *device,
+EggObjList *dkp_device_get_statistics (const DkpDevice *device,
const gchar *type);
G_END_DECLS
-#endif /* __DKP_CLIENT_DEVICE_H */
+#endif /* __DKP_DEVICE_H */
Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am (original)
+++ trunk/src/Makefile.am Wed Nov 26 11:35:12 2008
@@ -164,8 +164,6 @@
endif
gnome_power_manager_SOURCES = \
- egg-color.c \
- egg-color.h \
egg-debug.h \
egg-debug.c \
egg-dbus-monitor.h \
@@ -182,18 +180,8 @@
gpm-dpms.c \
gpm-notify.h \
gpm-notify.c \
- gpm-engine.h \
- gpm-engine.c \
gpm-phone.h \
gpm-phone.c \
- gpm-cell.h \
- gpm-cell.c \
- gpm-cell-unit.h \
- gpm-cell-unit.c \
- gpm-cell-array.h \
- gpm-cell-array.c \
- gpm-warnings.h \
- gpm-warnings.c \
gpm-backlight.h \
gpm-backlight.c \
gpm-prefs-server.h \
@@ -202,8 +190,6 @@
gpm-idle.c \
gpm-load.h \
gpm-load.c \
- gpm-profile.h \
- gpm-profile.c \
gpm-control.h \
gpm-control.c \
gpm-refcount.h \
@@ -236,19 +222,44 @@
gpm-networkmanager.h \
gpm-networkmanager.c \
gpm-stock-icons.h \
+ gpm-inhibit.h \
+ gpm-inhibit.c \
+ gpm-feedback-widget.h \
+ gpm-feedback-widget.c \
+ $(NULL)
+
+if HAVE_DK_POWER
+gnome_power_manager_SOURCES += \
+ gpm-engine.h \
+ gpm-engine.c \
+ gpm-devicekit.h \
+ gpm-devicekit.c \
+ $(NULL)
+else
+ egg-color.c \
+ egg-color.h \
gpm-info.h \
gpm-info.c \
+ gpm-graph-widget-old.h \
+ gpm-graph-widget-old.c \
+ gpm-profile.h \
+ gpm-profile.c \
gpm-array.h \
gpm-array.c \
gpm-array-float.h \
gpm-array-float.c \
- gpm-inhibit.h \
- gpm-inhibit.c \
- gpm-graph-widget-old.h \
- gpm-graph-widget-old.c \
- gpm-feedback-widget.h \
- gpm-feedback-widget.c \
+ gpm-engine-old.h \
+ gpm-engine-old.c \
+ gpm-cell.h \
+ gpm-cell.c \
+ gpm-cell-unit.h \
+ gpm-cell-unit.c \
+ gpm-cell-array.h \
+ gpm-cell-array.c \
+ gpm-warnings.h \
+ gpm-warnings.c \
$(NULL)
+endif
gnome_power_manager_LDADD = \
$(GLIB_LIBS) \
Modified: trunk/src/gpm-ac-adapter.c
==============================================================================
--- trunk/src/gpm-ac-adapter.c (original)
+++ trunk/src/gpm-ac-adapter.c Wed Nov 26 11:35:12 2008
@@ -40,7 +40,7 @@
#ifdef HAVE_DK_POWER
#include <dkp-client.h>
- #include <dkp-client-device.h>
+ #include <dkp-device.h>
#else
#include <hal-device.h>
#include <hal-manager.h>
@@ -56,7 +56,7 @@
{
gboolean has_hardware;
#ifdef HAVE_DK_POWER
- DkpClient *device;
+ DkpClient *client;
#else
HalDevice *device;
#endif
@@ -100,7 +100,7 @@
}
#else
gboolean on_battery;
- on_battery = dkp_client_on_battery (ac_adapter->priv->device);
+ on_battery = dkp_client_on_battery (ac_adapter->priv->client);
/* battery -> not AC */
is_on_ac = !on_battery;
#endif
@@ -136,11 +136,13 @@
}
#else
/**
- * gpm_ac_adapter_on_battery_changed_cb:
+ * gpm_ac_adapter_changed_cb:
*/
static void
-gpm_ac_adapter_on_battery_changed_cb (DkpClientDevice *device, gboolean on_battery, GpmAcAdapter *ac_adapter)
+gpm_ac_adapter_changed_cb (DkpClient *client, GpmAcAdapter *ac_adapter)
{
+ gboolean on_battery;
+ on_battery = dkp_client_on_battery (client);
g_signal_emit (ac_adapter, signals [AC_ADAPTER_CHANGED], 0, !on_battery);
}
#endif
@@ -157,7 +159,7 @@
ac_adapter = GPM_AC_ADAPTER (object);
g_return_if_fail (ac_adapter->priv != NULL);
- g_object_unref (ac_adapter->priv->device);
+ g_object_unref (ac_adapter->priv->client);
G_OBJECT_CLASS (gpm_ac_adapter_parent_class)->finalize (object);
}
@@ -196,9 +198,9 @@
{
ac_adapter->priv = GPM_AC_ADAPTER_GET_PRIVATE (ac_adapter);
#ifdef HAVE_DK_POWER
- ac_adapter->priv->device = dkp_client_new ();
- g_signal_connect (ac_adapter->priv->device, "on-battery-changed",
- G_CALLBACK (gpm_ac_adapter_on_battery_changed_cb), ac_adapter);
+ ac_adapter->priv->client = dkp_client_new ();
+ g_signal_connect (ac_adapter->priv->client, "changed",
+ G_CALLBACK (gpm_ac_adapter_changed_cb), ac_adapter);
#else
gchar **device_names;
gboolean ret;
Modified: trunk/src/gpm-cell-array.c
==============================================================================
--- trunk/src/gpm-cell-array.c (original)
+++ trunk/src/gpm-cell-array.c Wed Nov 26 11:35:12 2008
@@ -59,7 +59,7 @@
GpmCellUnit unit;
GpmAcAdapter *ac_adapter;
GpmProfile *profile;
- GConfClient *conf;
+ GConfClient *conf;
GpmPhone *phone;
GpmControl *control;
GpmWarnings *warnings;
Modified: trunk/src/gpm-devicekit.c
==============================================================================
--- trunk/src/gpm-devicekit.c (original)
+++ trunk/src/gpm-devicekit.c Wed Nov 26 11:35:12 2008
@@ -24,6 +24,8 @@
#include <glib/gi18n.h>
#include "egg-debug.h"
+#include "egg-precision.h"
+
#include "dkp-enum.h"
#include "dkp-object.h"
@@ -121,6 +123,106 @@
return filename;
}
+
+#define GPM_DKP_TIME_PRECISION 5*60
+#define GPM_DKP_TEXT_MIN_TIME 120
+
+/**
+ * gpm_devicekit_get_object_summary:
+ **/
+gchar *
+gpm_devicekit_get_object_summary (const DkpObject *obj)
+{
+ const gchar *type_desc = NULL;
+ gchar *description = NULL;
+ guint time_to_full_round;
+ guint time_to_empty_round;
+ gchar *time_to_full_str;
+ gchar *time_to_empty_str;
+
+ if (!obj->is_present)
+ return NULL;
+
+ type_desc = gpm_device_type_to_localised_text (obj->type, 1);
+
+ /* don't display all the extra stuff for keyboards and mice */
+ if (obj->type == DKP_DEVICE_TYPE_MOUSE ||
+ obj->type == DKP_DEVICE_TYPE_KEYBOARD ||
+ obj->type == DKP_DEVICE_TYPE_PDA)
+ return g_strdup_printf ("%s (%.1f%%)", type_desc, obj->percentage);
+
+ /* we care if we are on AC */
+ if (obj->type == DKP_DEVICE_TYPE_PHONE) {
+ if (obj->state == DKP_DEVICE_STATE_CHARGING || !obj->state == DKP_DEVICE_STATE_DISCHARGING)
+ return g_strdup_printf ("%s charging (%.1f%%)", type_desc, obj->percentage);
+ return g_strdup_printf ("%s (%.1f%%)", type_desc, obj->percentage);
+ }
+
+ /* precalculate so we don't get Unknown time remaining */
+ time_to_full_round = egg_precision_round_down (obj->time_to_full, GPM_DKP_TIME_PRECISION);
+ time_to_empty_round = egg_precision_round_down (obj->time_to_empty, GPM_DKP_TIME_PRECISION);
+
+ /* we always display "Laptop battery 16 minutes remaining" as we need to clarify what device we are refering to */
+ if (obj->state == DKP_DEVICE_STATE_FULLY_CHARGED) {
+
+ if (obj->type == DKP_DEVICE_TYPE_BATTERY && time_to_empty_round > GPM_DKP_TEXT_MIN_TIME) {
+ time_to_empty_str = gpm_get_timestring (time_to_empty_round);
+ description = g_strdup_printf (_("%s fully charged (%.1f%%)\nProvides %s battery runtime"),
+ type_desc, obj->percentage, time_to_empty_str);
+ g_free (time_to_empty_str);
+ } else {
+ description = g_strdup_printf (_("%s fully charged (%.1f%%)"),
+ type_desc, obj->percentage);
+ }
+
+ } else if (obj->state == DKP_DEVICE_STATE_DISCHARGING) {
+
+ if (time_to_empty_round > GPM_DKP_TEXT_MIN_TIME) {
+ time_to_empty_str = gpm_get_timestring (time_to_empty_round);
+ description = g_strdup_printf (_("%s %s remaining (%.1f%%)"),
+ type_desc, time_to_empty_str, obj->percentage);
+ g_free (time_to_empty_str);
+ } else {
+ /* don't display "Unknown remaining" */
+ description = g_strdup_printf (_("%s discharging (%.1f%%)"),
+ type_desc, obj->percentage);
+ }
+
+ } else if (obj->state == DKP_DEVICE_STATE_CHARGING) {
+
+ if (time_to_full_round > GPM_DKP_TEXT_MIN_TIME &&
+ time_to_empty_round > GPM_DKP_TEXT_MIN_TIME) {
+
+ /* display both discharge and charge time */
+ time_to_full_str = gpm_get_timestring (time_to_full_round);
+ time_to_empty_str = gpm_get_timestring (time_to_empty_round);
+ description = g_strdup_printf (_("%s %s until charged (%.1f%%)\nProvides %s battery runtime"),
+ type_desc, time_to_full_str, obj->percentage, time_to_empty_str);
+ g_free (time_to_full_str);
+ g_free (time_to_empty_str);
+
+ } else if (time_to_full_round > GPM_DKP_TEXT_MIN_TIME) {
+
+ /* display only charge time */
+ time_to_full_str = gpm_get_timestring (time_to_full_round);
+ description = g_strdup_printf (_("%s %s until charged (%.1f%%)"),
+ type_desc, time_to_full_str, obj->percentage);
+ g_free (time_to_full_str);
+ } else {
+
+ /* don't display "Unknown remaining" */
+ description = g_strdup_printf (_("%s charging (%.1f%%)"),
+ type_desc, obj->percentage);
+ }
+
+ } else {
+ egg_warning ("in an undefined state we are not charging or "
+ "discharging and the batteries are also not charged");
+ description = g_strdup (_("Device state could not be read at this time"));
+ }
+ return description;
+}
+
/**
* gpm_devicekit_get_object_description:
**/
Modified: trunk/src/gpm-devicekit.h
==============================================================================
--- trunk/src/gpm-devicekit.h (original)
+++ trunk/src/gpm-devicekit.h Wed Nov 26 11:35:12 2008
@@ -33,6 +33,7 @@
const gchar *gpm_device_type_to_icon (DkpDeviceType type);
const gchar *gpm_device_technology_to_localised_text (DkpDeviceTechnology technology_enum);
gchar *gpm_devicekit_get_object_icon (const DkpObject *obj);
+gchar *gpm_devicekit_get_object_summary (const DkpObject *obj);
gchar *gpm_devicekit_get_object_description (const DkpObject *obj);
G_END_DECLS
Copied: trunk/src/gpm-engine-old.c (from r3097, /trunk/src/gpm-engine.c)
==============================================================================
--- /trunk/src/gpm-engine.c (original)
+++ trunk/src/gpm-engine-old.c Wed Nov 26 11:35:12 2008
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2007 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2007-2008 Richard Hughes <richard hughsie com>
*
* Licensed under the GNU General Public License Version 2
*
@@ -34,7 +34,7 @@
#include "gpm-control.h"
#include "gpm-profile.h"
#include "gpm-marshal.h"
-#include "gpm-engine.h"
+#include "gpm-engine-old.h"
#include "gpm-cell-unit.h"
#include "gpm-cell-array.h"
#include "gpm-cell.h"
@@ -89,9 +89,7 @@
* ac_adaptor_changed_cb:
**/
static void
-ac_adaptor_changed_cb (GpmAcAdapter *ac_adapter,
- gboolean on_ac,
- GpmEngine *engine)
+ac_adaptor_changed_cb (GpmAcAdapter *ac_adapter, gboolean on_ac, GpmEngine *engine)
{
GpmEngineCollection *collection;
@@ -131,101 +129,13 @@
* We have to update the caches on resume
**/
static void
-control_resume_cb (GpmControl *control,
- GpmControlAction action,
- GpmEngine *engine)
+control_resume_cb (GpmControl *control, GpmControlAction action, GpmEngine *engine)
{
/* we have to delay this at resume to counteract races */
g_timeout_add (GPM_ENGINE_RESUME_DELAY, (GSourceFunc) gpm_engine_delayed_refresh, engine);
}
/**
- * gpm_engine_class_init:
- * @engine: This class instance
- **/
-static void
-gpm_engine_class_init (GpmEngineClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = gpm_engine_finalize;
- g_type_class_add_private (klass, sizeof (GpmEnginePrivate));
-
- signals [ICON_CHANGED] =
- g_signal_new ("icon-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, icon_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
- signals [SUMMARY_CHANGED] =
- g_signal_new ("summary-changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, summary_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
- signals [LOW_CAPACITY] =
- g_signal_new ("low-capacity",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, low_capacity),
- NULL, NULL,
- gpm_marshal_VOID__UINT_UINT,
- G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
- signals [PERHAPS_RECALL] =
- g_signal_new ("perhaps-recall",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, perhaps_recall),
- NULL, NULL,
- gpm_marshal_VOID__UINT_STRING_STRING,
- G_TYPE_NONE,
- 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
- signals [FULLY_CHARGED] =
- g_signal_new ("fully-charged",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, fully_charged),
- NULL, NULL,
- g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
- signals [DISCHARGING] =
- g_signal_new ("discharging",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, discharging),
- NULL, NULL,
- g_cclosure_marshal_VOID__UINT,
- G_TYPE_NONE, 1, G_TYPE_UINT);
- signals [CHARGE_ACTION] =
- g_signal_new ("charge-action",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, charge_action),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals [CHARGE_LOW] =
- g_signal_new ("charge-low",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, charge_low),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
- signals [CHARGE_CRITICAL] =
- g_signal_new ("charge-critical",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GpmEngineClass, charge_critical),
- NULL, NULL,
- g_cclosure_marshal_VOID__POINTER,
- G_TYPE_NONE, 1, G_TYPE_POINTER);
-}
-
-/**
* gpm_engine_get_collection:
* @engine: This engine class instance
* @string: The returned string
@@ -820,12 +730,10 @@
}
/**
- * conf_key_changed_cb:
+ * gpm_engine_conf_key_changed_cb:
**/
static void
-conf_key_changed_cb (GConfClient *conf,
- const gchar *key,
- GpmEngine *engine)
+gpm_engine_conf_key_changed_cb (GConfClient *conf, const gchar *key, GpmEngine *engine)
{
gchar *icon_policy;
if (strcmp (key, GPM_CONF_UI_ICON_POLICY) == 0) {
@@ -841,6 +749,44 @@
}
/**
+ * gpm_engine_coldplug_idle_cb:
+ **/
+static gboolean
+gpm_engine_coldplug_idle_cb (GpmEngine *engine)
+{
+ GpmEngineCollection *collection;
+ GpmPrefsServer *prefs_server;
+
+ g_return_val_if_fail (engine != NULL, FALSE);
+ g_return_val_if_fail (GPM_IS_ENGINE (engine), FALSE);
+
+ /* grab a reference to the collection */
+ collection = &engine->priv->collection;
+ gpm_cell_array_set_type (collection->primary, GPM_CELL_UNIT_KIND_PRIMARY);
+ gpm_cell_array_set_type (collection->ups, GPM_CELL_UNIT_KIND_UPS);
+ gpm_cell_array_set_type (collection->mouse, GPM_CELL_UNIT_KIND_MOUSE);
+ gpm_cell_array_set_type (collection->keyboard, GPM_CELL_UNIT_KIND_KEYBOARD);
+ gpm_cell_array_set_type (collection->pda, GPM_CELL_UNIT_KIND_PDA);
+ gpm_cell_array_set_type (collection->phone, GPM_CELL_UNIT_KIND_PHONE);
+
+ /* only show the battery prefs section if we have batteries */
+ prefs_server = gpm_prefs_server_new ();
+ if (gpm_cell_array_get_num_cells (collection->primary) > 0)
+ gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_BATTERY);
+ if (gpm_cell_array_get_num_cells (collection->ups) > 0)
+ gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_UPS);
+ g_object_unref (prefs_server);
+
+ /* we're done */
+ engine->priv->during_coldplug = FALSE;
+
+ gpm_engine_recalculate_state (engine);
+
+ /* never repeat */
+ return FALSE;
+}
+
+/**
* gpm_engine_init:
* @engine: This class instance
**/
@@ -854,7 +800,7 @@
engine->priv->conf = gconf_client_get_default ();
g_signal_connect (engine->priv->conf, "value-changed",
- G_CALLBACK (conf_key_changed_cb), engine);
+ G_CALLBACK (gpm_engine_conf_key_changed_cb), engine);
engine->priv->warnings = gpm_warnings_new ();
engine->priv->profile = gpm_profile_new ();
@@ -965,42 +911,85 @@
G_CALLBACK (gpm_cell_array_charge_critical_cb), engine);
g_signal_connect (collection->ups, "charge-action",
G_CALLBACK (gpm_cell_array_charge_action_cb), engine);
+
+ g_idle_add ((GSourceFunc) gpm_engine_coldplug_idle_cb, engine);
}
/**
- * gpm_engine_start:
+ * gpm_engine_class_init:
+ * @engine: This class instance
**/
-gboolean
-gpm_engine_start (GpmEngine *engine)
+static void
+gpm_engine_class_init (GpmEngineClass *klass)
{
- GpmEngineCollection *collection;
- GpmPrefsServer *prefs_server;
-
- g_return_val_if_fail (engine != NULL, FALSE);
- g_return_val_if_fail (GPM_IS_ENGINE (engine), FALSE);
-
- /* grab a reference to the collection */
- collection = &engine->priv->collection;
- gpm_cell_array_set_type (collection->primary, GPM_CELL_UNIT_KIND_PRIMARY);
- gpm_cell_array_set_type (collection->ups, GPM_CELL_UNIT_KIND_UPS);
- gpm_cell_array_set_type (collection->mouse, GPM_CELL_UNIT_KIND_MOUSE);
- gpm_cell_array_set_type (collection->keyboard, GPM_CELL_UNIT_KIND_KEYBOARD);
- gpm_cell_array_set_type (collection->pda, GPM_CELL_UNIT_KIND_PDA);
- gpm_cell_array_set_type (collection->phone, GPM_CELL_UNIT_KIND_PHONE);
-
- /* only show the battery prefs section if we have batteries */
- prefs_server = gpm_prefs_server_new ();
- if (gpm_cell_array_get_num_cells (collection->primary) > 0)
- gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_BATTERY);
- if (gpm_cell_array_get_num_cells (collection->ups) > 0)
- gpm_prefs_server_set_capability (prefs_server, GPM_PREFS_SERVER_UPS);
- g_object_unref (prefs_server);
-
- /* we're done */
- engine->priv->during_coldplug = FALSE;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gpm_engine_finalize;
+ g_type_class_add_private (klass, sizeof (GpmEnginePrivate));
- gpm_engine_recalculate_state (engine);
- return TRUE;
+ signals [ICON_CHANGED] =
+ g_signal_new ("icon-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, icon_changed),
+ NULL, NULL, g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+ signals [SUMMARY_CHANGED] =
+ g_signal_new ("summary-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, summary_changed),
+ NULL, NULL, g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+ signals [LOW_CAPACITY] =
+ g_signal_new ("low-capacity",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, low_capacity),
+ NULL, NULL, gpm_marshal_VOID__UINT_UINT,
+ G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
+ signals [PERHAPS_RECALL] =
+ g_signal_new ("perhaps-recall",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, perhaps_recall),
+ NULL, NULL, gpm_marshal_VOID__UINT_STRING_STRING,
+ G_TYPE_NONE,
+ 3, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
+ signals [FULLY_CHARGED] =
+ g_signal_new ("fully-charged",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, fully_charged),
+ NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+ signals [DISCHARGING] =
+ g_signal_new ("discharging",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, discharging),
+ NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+ signals [CHARGE_ACTION] =
+ g_signal_new ("charge-action",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, charge_action),
+ NULL, NULL, g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+ signals [CHARGE_LOW] =
+ g_signal_new ("charge-low",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, charge_low),
+ NULL, NULL, g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
+ signals [CHARGE_CRITICAL] =
+ g_signal_new ("charge-critical",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GpmEngineClass, charge_critical),
+ NULL, NULL, g_cclosure_marshal_VOID__POINTER,
+ G_TYPE_NONE, 1, G_TYPE_POINTER);
}
/**
Copied: trunk/src/gpm-engine-old.h (from r3097, /trunk/src/gpm-engine.h)
==============================================================================
--- /trunk/src/gpm-engine.h (original)
+++ trunk/src/gpm-engine-old.h Wed Nov 26 11:35:12 2008
@@ -83,7 +83,6 @@
GType gpm_engine_get_type (void);
GpmEngine *gpm_engine_new (void);
-gboolean gpm_engine_start (GpmEngine *engine);
gchar *gpm_engine_get_icon (GpmEngine *engine);
gchar *gpm_engine_get_summary (GpmEngine *engine);
Modified: trunk/src/gpm-info.c
==============================================================================
--- trunk/src/gpm-info.c (original)
+++ trunk/src/gpm-info.c Wed Nov 26 11:35:12 2008
@@ -31,13 +31,14 @@
#include <hal-manager.h>
#include "egg-color.h"
+#include "egg-debug.h"
+
#include "gpm-control.h"
#include "gpm-common.h"
-#include "egg-debug.h"
#include "gpm-info.h"
#include "gpm-profile.h"
#include "gpm-array.h"
-#include "gpm-engine.h"
+#include "gpm-engine-old.h"
#include "gpm-stock-icons.h"
#include "gpm-graph-widget-old.h"
Modified: trunk/src/gpm-info.h
==============================================================================
--- trunk/src/gpm-info.h (original)
+++ trunk/src/gpm-info.h Wed Nov 26 11:35:12 2008
@@ -24,7 +24,7 @@
#include <glib-object.h>
#include "gpm-graph-widget-old.h"
-#include "gpm-engine.h"
+#include "gpm-engine-old.h"
G_BEGIN_DECLS
Modified: trunk/src/gpm-manager.c
==============================================================================
--- trunk/src/gpm-manager.c (original)
+++ trunk/src/gpm-manager.c Wed Nov 26 11:35:12 2008
@@ -41,6 +41,10 @@
#include <gconf/gconf-client.h>
#include <canberra-gtk.h>
+#ifdef HAVE_DK_POWER
+ #include <dkp-device.h>
+#endif
+
#include <hal-device-power.h>
#include <hal-manager.h>
@@ -67,9 +71,13 @@
#include "gpm-stock-icons.h"
#include "gpm-prefs-server.h"
#include "gpm-tray-icon.h"
-#include "gpm-engine.h"
+#include "gpm-engine-old.h"
#include "gpm-feedback-widget.h"
+#ifdef HAVE_DK_POWER
+ #include "gpm-devicekit.h"
+#endif
+
#include "org.freedesktop.PowerManagement.Inhibit.h"
#include "org.freedesktop.PowerManagement.Backlight.h"
#ifndef HAVE_DK_POWER
@@ -1427,11 +1435,11 @@
* gpm_engine_perhaps_recall_cb:
*/
static void
-gpm_engine_perhaps_recall_cb (GpmEngine *engine,
- GpmCellUnitKind kind,
- gchar *oem_vendor,
- gchar *website,
- GpmManager *manager)
+#ifdef HAVE_DK_POWER
+gpm_engine_perhaps_recall_cb (GpmEngine *engine, DkpDeviceType type, gchar *oem_vendor, gchar *website, GpmManager *manager)
+#else
+gpm_engine_perhaps_recall_cb (GpmEngine *engine, GpmCellUnitKind kind, gchar *oem_vendor, gchar *website, GpmManager *manager)
+#endif
{
g_object_set_data (G_OBJECT (manager), "recall-oem-vendor", (gpointer) g_strdup (oem_vendor));
g_object_set_data (G_OBJECT (manager), "recall-oem-website", (gpointer) g_strdup (website));
@@ -1443,10 +1451,11 @@
* gpm_engine_low_capacity_cb:
*/
static void
-gpm_engine_low_capacity_cb (GpmEngine *engine,
- GpmCellUnitKind kind,
- guint capacity,
- GpmManager *manager)
+#ifdef HAVE_DK_POWER
+gpm_engine_low_capacity_cb (GpmEngine *engine, DkpDeviceType type, guint capacity, GpmManager *manager)
+#else
+gpm_engine_low_capacity_cb (GpmEngine *engine, GpmCellUnitKind kind, guint capacity, GpmManager *manager)
+#endif
{
/* We should notify the user if the battery has a low capacity,
* where capacity is the ratio of the last_full capacity with that of
@@ -1458,9 +1467,7 @@
* gpm_engine_icon_changed_cb:
*/
static void
-gpm_engine_icon_changed_cb (GpmEngine *engine,
- gchar *icon,
- GpmManager *manager)
+gpm_engine_icon_changed_cb (GpmEngine *engine, gchar *icon, GpmManager *manager)
{
gpm_tray_icon_set_icon (manager->priv->tray_icon, icon);
}
@@ -1469,9 +1476,7 @@
* gpm_engine_summary_changed_cb:
*/
static void
-gpm_engine_summary_changed_cb (GpmEngine *engine,
- gchar *summary,
- GpmManager *manager)
+gpm_engine_summary_changed_cb (GpmEngine *engine, gchar *summary, GpmManager *manager)
{
gpm_tray_icon_set_tooltip (manager->priv->tray_icon, summary);
}
@@ -1480,11 +1485,17 @@
* gpm_engine_low_capacity_cb:
*/
static void
-gpm_engine_fully_charged_cb (GpmEngine *engine,
- GpmCellUnitKind kind,
- GpmManager *manager)
+#ifdef HAVE_DK_POWER
+gpm_engine_fully_charged_cb (GpmEngine *engine, DkpDeviceType type, GpmManager *manager)
+#else
+gpm_engine_fully_charged_cb (GpmEngine *engine, GpmCellUnitKind kind, GpmManager *manager)
+#endif
{
+#ifndef HAVE_DK_POWER
if (kind == GPM_CELL_UNIT_KIND_PRIMARY)
+#else
+ if (type == DKP_DEVICE_TYPE_BATTERY)
+#endif
gpm_notify_fully_charged_primary (manager->priv->notify);
}
@@ -1492,13 +1503,23 @@
* gpm_engine_low_capacity_cb:
*/
static void
-gpm_engine_discharging_cb (GpmEngine *engine,
- GpmCellUnitKind kind,
- GpmManager *manager)
+#ifdef HAVE_DK_POWER
+gpm_engine_discharging_cb (GpmEngine *engine, DkpDeviceType type, GpmManager *manager)
+#else
+gpm_engine_discharging_cb (GpmEngine *engine, GpmCellUnitKind kind, GpmManager *manager)
+#endif
{
+#ifndef HAVE_DK_POWER
if (kind == GPM_CELL_UNIT_KIND_PRIMARY)
+#else
+ if (type == DKP_DEVICE_TYPE_BATTERY)
+#endif
gpm_notify_discharging_primary (manager->priv->notify);
+#ifndef HAVE_DK_POWER
else if (kind == GPM_CELL_UNIT_KIND_UPS)
+#else
+ else if (type == DKP_DEVICE_TYPE_UPS)
+#endif
gpm_notify_discharging_ups (manager->priv->notify);
}
@@ -1506,9 +1527,7 @@
* control_sleep_failure_cb:
**/
static void
-control_sleep_failure_cb (GpmControl *control,
- GpmControlAction action,
- GpmManager *manager)
+control_sleep_failure_cb (GpmControl *control, GpmControlAction action, GpmManager *manager)
{
gboolean show_sleep_failed;
@@ -1540,15 +1559,18 @@
* gpm_engine_charge_low_cb:
*/
static void
-gpm_engine_charge_low_cb (GpmEngine *engine,
- GpmCellUnit *unit,
- GpmManager *manager)
+#ifdef HAVE_DK_POWER
+gpm_engine_charge_low_cb (GpmEngine *engine, DkpObject *obj, GpmManager *manager)
+#else
+gpm_engine_charge_low_cb (GpmEngine *engine, GpmCellUnit *unit, GpmManager *manager)
+#endif
{
const gchar *title = NULL;
gchar *message = NULL;
gchar *remaining_text;
gchar *icon;
+#ifndef HAVE_DK_POWER
if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY) {
title = _("Laptop battery low");
remaining_text = gpm_get_timestring (unit->time_discharge);
@@ -1562,22 +1584,55 @@
} else if (unit->kind == GPM_CELL_UNIT_KIND_MOUSE) {
title = _("Mouse battery low");
message = g_strdup_printf (_("The wireless mouse attached to this computer is low in power (%.1f%%)"), unit->percentage);
+
} else if (unit->kind == GPM_CELL_UNIT_KIND_KEYBOARD) {
title = _("Keyboard battery low");
message = g_strdup_printf (_("The wireless keyboard attached to this computer is low in power (%.1f%%)"), unit->percentage);
+
} else if (unit->kind == GPM_CELL_UNIT_KIND_PDA) {
title = _("PDA battery low");
message = g_strdup_printf (_("The PDA attached to this computer is low in power (%.1f%%)"), unit->percentage);
+
} else if (unit->kind == GPM_CELL_UNIT_KIND_PHONE) {
title = _("Cell phone battery low");
message = g_strdup_printf (_("The cell phone attached to this computer is low in power (%.1f%%)"), unit->percentage);
}
+#else
+ if (obj->type == GPM_CELL_UNIT_KIND_PRIMARY) {
+ title = _("Laptop battery low");
+ remaining_text = gpm_get_timestring (obj->time_to_empty);
+ message = g_strdup_printf (_("You have approximately <b>%s</b> of remaining battery life (%.1f%%)"),
+ remaining_text, obj->percentage);
+ } else if (obj->type == GPM_CELL_UNIT_KIND_UPS) {
+ title = _("UPS low");
+ remaining_text = gpm_get_timestring (obj->time_to_empty);
+ message = g_strdup_printf (_("You have approximately <b>%s</b> of remaining UPS backup power (%.1f%%)"),
+ remaining_text, obj->percentage);
+ } else if (obj->type == GPM_CELL_UNIT_KIND_MOUSE) {
+ title = _("Mouse battery low");
+ message = g_strdup_printf (_("The wireless mouse attached to this computer is low in power (%.1f%%)"), obj->percentage);
+
+ } else if (obj->type == GPM_CELL_UNIT_KIND_KEYBOARD) {
+ title = _("Keyboard battery low");
+ message = g_strdup_printf (_("The wireless keyboard attached to this computer is low in power (%.1f%%)"), obj->percentage);
+
+ } else if (obj->type == GPM_CELL_UNIT_KIND_PDA) {
+ title = _("PDA battery low");
+ message = g_strdup_printf (_("The PDA attached to this computer is low in power (%.1f%%)"), obj->percentage);
+
+ } else if (obj->type == GPM_CELL_UNIT_KIND_PHONE) {
+ title = _("Cell phone battery low");
+ message = g_strdup_printf (_("The cell phone attached to this computer is low in power (%.1f%%)"), obj->percentage);
+ }
+#endif
/* get correct icon */
+#ifndef HAVE_DK_POWER
icon = gpm_cell_unit_get_icon (unit);
- gpm_notify_display (manager->priv->notify,
- title, message, GPM_NOTIFY_TIMEOUT_LONG,
- icon, GPM_NOTIFY_URGENCY_NORMAL);
+#else
+ icon = gpm_devicekit_get_object_icon (obj);
+#endif
+ gpm_notify_display (manager->priv->notify, title, message, GPM_NOTIFY_TIMEOUT_LONG, icon, GPM_NOTIFY_URGENCY_NORMAL);
gpm_manager_play (manager, GPM_MANAGER_SOUND_BATTERY_LOW, TRUE);
g_free (icon);
g_free (message);
@@ -1589,7 +1644,8 @@
static gchar *
gpm_manager_get_time_until_action_text (GpmManager *manager)
{
- guint time;
+ guint time = 0;
+#ifndef HAVE_DK_POWER
GpmEngineCollection *collection;
collection = gpm_engine_get_collection (manager->priv->engine);
@@ -1598,6 +1654,7 @@
time = gpm_cell_array_get_time_until_action (collection->primary);
if (time == 0)
return g_strdup (_("a short time"));
+#endif
return gpm_get_timestring (time);
}
@@ -1605,9 +1662,11 @@
* gpm_engine_charge_critical_cb:
*/
static void
-gpm_engine_charge_critical_cb (GpmEngine *engine,
- GpmCellUnit *unit,
- GpmManager *manager)
+#ifdef HAVE_DK_POWER
+gpm_engine_charge_critical_cb (GpmEngine *engine, DkpObject *obj, GpmManager *manager)
+#else
+gpm_engine_charge_critical_cb (GpmEngine *engine, GpmCellUnit *unit, GpmManager *manager)
+#endif
{
const gchar *title = NULL;
gchar *message = NULL;
@@ -1617,7 +1676,8 @@
gchar *icon;
gchar *time_text;
- if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY) {
+#ifndef HAVE_DK_POWER
+ if (obj->type == DKP_DEVICE_TYPE_BATTERY) {
title = _("Laptop battery critically low");
remaining_text = gpm_get_timestring (unit->time_discharge);
time_text = gpm_manager_get_time_until_action_text (manager);
@@ -1674,12 +1734,73 @@
"This device will soon stop functioning if not charged."),
unit->percentage);
}
+#else
+ if (obj->type == DKP_DEVICE_TYPE_BATTERY) {
+ title = _("Laptop battery critically low");
+ remaining_text = gpm_get_timestring (obj->time_to_empty);
+ time_text = gpm_manager_get_time_until_action_text (manager);
+
+ /* we have to do different warnings depending on the policy */
+ action = gconf_client_get_string (manager->priv->conf, GPM_CONF_ACTIONS_CRITICAL_BATT, NULL);
+ if (action == NULL) {
+ egg_warning ("schema invalid!");
+ action = g_strdup (ACTION_NOTHING);
+ }
+
+ /* use different text for different actions */
+ if (strcmp (action, ACTION_NOTHING) == 0)
+ action_text = g_strdup (_("Plug in your AC adapter to avoid losing data."));
+ else if (strcmp (action, ACTION_SUSPEND) == 0)
+ action_text = g_strdup_printf (_("This computer will suspend in %s if the AC is not connected."), time_text);
+ else if (strcmp (action, ACTION_HIBERNATE) == 0)
+ action_text = g_strdup_printf (_("This computer will hibernate in %s if the AC is not connected."), time_text);
+ else if (strcmp (action, ACTION_SHUTDOWN) == 0)
+ action_text = g_strdup_printf (_("This computer will shutdown in %s if the AC is not connected."), time_text);
+
+ message = g_strdup_printf (_("You have approximately <b>%s</b> of remaining battery life (%.1f%%). %s"),
+ remaining_text, obj->percentage, action_text);
+
+ g_free (action);
+ g_free (action_text);
+ g_free (remaining_text);
+ g_free (time_text);
+ } else if (obj->type == DKP_DEVICE_TYPE_UPS) {
+ title = _("UPS critically low");
+ remaining_text = gpm_get_timestring (obj->time_to_empty);
+ message = g_strdup_printf (_("You have approximately <b>%s</b> of remaining UPS power (%.1f%%). "
+ "Restore AC power to your computer to avoid losing data."),
+ remaining_text, obj->percentage);
+ g_free (remaining_text);
+ } else if (obj->type == DKP_DEVICE_TYPE_MOUSE) {
+ title = _("Mouse battery low");
+ message = g_strdup_printf (_("The wireless mouse attached to this computer is very low in power (%.1f%%). "
+ "This device will soon stop functioning if not charged."),
+ obj->percentage);
+ } else if (obj->type == DKP_DEVICE_TYPE_KEYBOARD) {
+ title = _("Keyboard battery low");
+ message = g_strdup_printf (_("The wireless keyboard attached to this computer is very low in power (%.1f%%). "
+ "This device will soon stop functioning if not charged."),
+ obj->percentage);
+ } else if (obj->type == DKP_DEVICE_TYPE_PDA) {
+ title = _("PDA battery low");
+ message = g_strdup_printf (_("The PDA attached to this computer is very low in power (%.1f%%). "
+ "This device will soon stop functioning if not charged."),
+ obj->percentage);
+ } else if (obj->type == DKP_DEVICE_TYPE_PHONE) {
+ title = _("Cell phone battery low");
+ message = g_strdup_printf (_("Your cell phone is very low in power (%.1f%%). "
+ "This device will soon stop functioning if not charged."),
+ obj->percentage);
+ }
+#endif
/* get correct icon */
+#ifndef HAVE_DK_POWER
icon = gpm_cell_unit_get_icon (unit);
- gpm_notify_display (manager->priv->notify,
- title, message, GPM_NOTIFY_TIMEOUT_LONG,
- icon, GPM_NOTIFY_URGENCY_CRITICAL);
+#else
+ icon = gpm_devicekit_get_object_icon (obj);
+#endif
+ gpm_notify_display (manager->priv->notify, title, message, GPM_NOTIFY_TIMEOUT_LONG, icon, GPM_NOTIFY_URGENCY_CRITICAL);
gpm_manager_play (manager, GPM_MANAGER_SOUND_BATTERY_LOW, TRUE);
g_free (icon);
g_free (message);
@@ -1689,14 +1810,22 @@
* gpm_engine_charge_action_cb:
*/
static void
+#ifdef HAVE_DK_POWER
+gpm_engine_charge_action_cb (GpmEngine *engine, DkpObject *obj, GpmManager *manager)
+#else
gpm_engine_charge_action_cb (GpmEngine *engine, GpmCellUnit *unit, GpmManager *manager)
+#endif
{
const gchar *title = NULL;
gchar *action;
gchar *message = NULL;
gchar *icon;
+#ifndef HAVE_DK_POWER
if (unit->kind == GPM_CELL_UNIT_KIND_PRIMARY) {
+#else
+ if (obj->type == DKP_DEVICE_TYPE_BATTERY) {
+#endif
title = _("Laptop battery critically low");
/* we have to do different warnings depending on the policy */
@@ -1728,7 +1857,11 @@
/* wait 10 seconds for user-panic */
g_timeout_add (1000*10, (GSourceFunc) manager_critical_action_do, manager);
+#ifndef HAVE_DK_POWER
} else if (unit->kind == GPM_CELL_UNIT_KIND_UPS) {
+#else
+ } else if (obj->type == DKP_DEVICE_TYPE_UPS) {
+#endif
title = _("UPS critically low");
/* we have to do different warnings depending on the policy */
@@ -1757,7 +1890,11 @@
return;
/* get correct icon */
+#ifndef HAVE_DK_POWER
icon = gpm_cell_unit_get_icon (unit);
+#else
+ icon = gpm_devicekit_get_object_icon (obj);
+#endif
gpm_notify_display (manager->priv->notify,
title, message, GPM_NOTIFY_TIMEOUT_LONG,
icon, GPM_NOTIFY_URGENCY_CRITICAL);
@@ -1870,7 +2007,9 @@
{
gboolean check_type_cpu;
DBusGConnection *connection;
+#ifndef HAVE_DK_POWER
GpmEngineCollection *collection;
+#endif
GError *error = NULL;
gboolean on_ac;
guint version;
@@ -2030,14 +2169,15 @@
g_signal_connect (manager->priv->engine, "charge-action",
G_CALLBACK (gpm_engine_charge_action_cb), manager);
- gpm_engine_start (manager->priv->engine);
-
/* update ac throttle */
on_ac = gpm_ac_adapter_is_present (manager->priv->ac_adapter);
update_ac_throttle (manager, on_ac);
+#ifndef HAVE_DK_POWER
collection = gpm_engine_get_collection (manager->priv->engine);
gpm_tray_icon_set_collection_data (manager->priv->tray_icon, collection);
+#endif
+
#ifndef HAVE_DK_POWER
gpm_info_set_collection_data (manager->priv->info, collection);
#endif
Modified: trunk/src/gpm-statistics.c
==============================================================================
--- trunk/src/gpm-statistics.c (original)
+++ trunk/src/gpm-statistics.c Wed Nov 26 11:35:12 2008
@@ -45,7 +45,7 @@
#include "dkp-client.h"
#include "dkp-history-obj.h"
#include "dkp-stats-obj.h"
-#include "dkp-client-device.h"
+#include "dkp-device.h"
static GladeXML *glade_xml = NULL;
static GtkListStore *list_store_info = NULL;
@@ -101,19 +101,19 @@
#define GPM_STATS_DISCHARGE_ACCURACY_VALUE "discharge-accuracy"
/**
- * gpm_button_help_cb:
+ * gpm_stats_button_help_cb:
**/
static void
-gpm_button_help_cb (GtkWidget *widget, gboolean data)
+gpm_stats_button_help_cb (GtkWidget *widget, gboolean data)
{
//gpm_gnome_help ("update-log");
}
/**
- * gpm_add_info_columns:
+ * gpm_stats_add_info_columns:
**/
static void
-gpm_add_info_columns (GtkTreeView *treeview)
+gpm_stats_add_info_columns (GtkTreeView *treeview)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
@@ -133,10 +133,10 @@
}
/**
- * gpm_add_devices_columns:
+ * gpm_stats_add_devices_columns:
**/
static void
-gpm_add_devices_columns (GtkTreeView *treeview)
+gpm_stats_add_devices_columns (GtkTreeView *treeview)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
@@ -158,10 +158,10 @@
}
/**
- * gpm_add_info_data:
+ * gpm_stats_add_info_data:
**/
static void
-gpm_add_info_data (const gchar *attr, const gchar *text)
+gpm_stats_add_info_data (const gchar *attr, const gchar *text)
{
GtkTreeIter iter;
gtk_list_store_append (list_store_info, &iter);
@@ -171,10 +171,10 @@
}
/**
- * gpm_update_smooth_data:
+ * gpm_stats_update_smooth_data:
**/
static void
-gpm_update_smooth_data (EggObjList *list)
+gpm_stats_update_smooth_data (EggObjList *list)
{
guint i;
GpmPointObj *point;
@@ -204,10 +204,10 @@
}
/**
- * gpm_time_to_text:
+ * gpm_stats_time_to_text:
**/
static gchar *
-gpm_time_to_text (gint seconds)
+gpm_stats_time_to_text (gint seconds)
{
gfloat value = seconds;
@@ -226,19 +226,19 @@
}
/**
- * gpm_bool_to_text:
+ * gpm_stats_bool_to_text:
**/
static const gchar *
-gpm_bool_to_text (gboolean ret)
+gpm_stats_bool_to_text (gboolean ret)
{
return ret ? _("Yes") : _("No");
}
/**
- * gpm_update_info_page_details:
+ * gpm_stats_update_info_page_details:
**/
static void
-gpm_update_info_page_details (const DkpClientDevice *device)
+gpm_stats_update_info_page_details (const DkpDevice *device)
{
const DkpObject *obj;
struct tm *time_tm;
@@ -248,77 +248,77 @@
gtk_list_store_clear (list_store_info);
- obj = dkp_client_device_get_object (device);
+ obj = dkp_device_get_object (device);
/* get a human readable time */
t = (time_t) obj->update_time;
time_tm = localtime (&t);
strftime (time_buf, sizeof time_buf, "%c", time_tm);
- gpm_add_info_data (_("Device"), dkp_client_device_get_object_path (device));
- gpm_add_info_data (_("Type"), gpm_device_type_to_localised_text (obj->type, 1));
+ gpm_stats_add_info_data (_("Device"), dkp_device_get_object_path (device));
+ gpm_stats_add_info_data (_("Type"), gpm_device_type_to_localised_text (obj->type, 1));
if (!egg_strzero (obj->vendor))
- gpm_add_info_data (_("Vendor"), obj->vendor);
+ gpm_stats_add_info_data (_("Vendor"), obj->vendor);
if (!egg_strzero (obj->model))
- gpm_add_info_data (_("Model"), obj->model);
+ gpm_stats_add_info_data (_("Model"), obj->model);
if (!egg_strzero (obj->serial))
- gpm_add_info_data (_("Serial number"), obj->serial);
- gpm_add_info_data (_("Supply"), gpm_bool_to_text (obj->power_supply));
+ gpm_stats_add_info_data (_("Serial number"), obj->serial);
+ gpm_stats_add_info_data (_("Supply"), gpm_stats_bool_to_text (obj->power_supply));
text = g_strdup_printf ("%d seconds", (int) (time (NULL) - obj->update_time));
- gpm_add_info_data (_("Refreshed"), text);
+ gpm_stats_add_info_data (_("Refreshed"), text);
g_free (text);
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_MOUSE ||
obj->type == DKP_DEVICE_TYPE_KEYBOARD ||
obj->type == DKP_DEVICE_TYPE_UPS)
- gpm_add_info_data (_("Present"), gpm_bool_to_text (obj->is_present));
+ gpm_stats_add_info_data (_("Present"), gpm_stats_bool_to_text (obj->is_present));
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_MOUSE ||
obj->type == DKP_DEVICE_TYPE_KEYBOARD)
- gpm_add_info_data (_("Rechargeable"), gpm_bool_to_text (obj->is_rechargeable));
+ gpm_stats_add_info_data (_("Rechargeable"), gpm_stats_bool_to_text (obj->is_rechargeable));
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_MOUSE ||
obj->type == DKP_DEVICE_TYPE_KEYBOARD)
- gpm_add_info_data (_("State"), dkp_device_state_to_text (obj->state));
+ gpm_stats_add_info_data (_("State"), dkp_device_state_to_text (obj->state));
if (obj->type == DKP_DEVICE_TYPE_BATTERY) {
text = g_strdup_printf ("%.1f Wh", obj->energy);
- gpm_add_info_data (_("Energy"), text);
+ gpm_stats_add_info_data (_("Energy"), text);
g_free (text);
text = g_strdup_printf ("%.1f Wh", obj->energy_empty);
- gpm_add_info_data (_("Energy when empty"), text);
+ gpm_stats_add_info_data (_("Energy when empty"), text);
g_free (text);
text = g_strdup_printf ("%.1f Wh", obj->energy_full);
- gpm_add_info_data (_("Energy when full"), text);
+ gpm_stats_add_info_data (_("Energy when full"), text);
g_free (text);
text = g_strdup_printf ("%.1f Wh", obj->energy_full_design);
- gpm_add_info_data (_("Energy (design)"), text);
+ gpm_stats_add_info_data (_("Energy (design)"), text);
g_free (text);
}
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_MONITOR) {
text = g_strdup_printf ("%.1f W", obj->energy_rate);
- gpm_add_info_data (_("Rate"), text);
+ gpm_stats_add_info_data (_("Rate"), text);
g_free (text);
}
if (obj->type == DKP_DEVICE_TYPE_UPS ||
obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_MONITOR) {
text = g_strdup_printf ("%.1f V", obj->voltage);
- gpm_add_info_data (_("Voltage"), text);
+ gpm_stats_add_info_data (_("Voltage"), text);
g_free (text);
}
if (obj->type == DKP_DEVICE_TYPE_BATTERY ||
obj->type == DKP_DEVICE_TYPE_UPS) {
if (obj->time_to_full >= 0) {
- text = gpm_time_to_text (obj->time_to_full);
- gpm_add_info_data (_("Time to full"), text);
+ text = gpm_stats_time_to_text (obj->time_to_full);
+ gpm_stats_add_info_data (_("Time to full"), text);
g_free (text);
}
if (obj->time_to_empty >= 0) {
- text = gpm_time_to_text (obj->time_to_empty);
- gpm_add_info_data (_("Time to empty"), text);
+ text = gpm_stats_time_to_text (obj->time_to_empty);
+ gpm_stats_add_info_data (_("Time to empty"), text);
g_free (text);
}
}
@@ -327,25 +327,25 @@
obj->type == DKP_DEVICE_TYPE_KEYBOARD ||
obj->type == DKP_DEVICE_TYPE_UPS) {
text = g_strdup_printf ("%.1f%%", obj->percentage);
- gpm_add_info_data (_("Percentage"), text);
+ gpm_stats_add_info_data (_("Percentage"), text);
g_free (text);
}
if (obj->type == DKP_DEVICE_TYPE_BATTERY) {
text = g_strdup_printf ("%.1f%%", obj->capacity);
- gpm_add_info_data (_("Capacity"), text);
+ gpm_stats_add_info_data (_("Capacity"), text);
g_free (text);
}
if (obj->type == DKP_DEVICE_TYPE_BATTERY)
- gpm_add_info_data (_("Technology"), gpm_device_technology_to_localised_text (obj->technology));
+ gpm_stats_add_info_data (_("Technology"), gpm_device_technology_to_localised_text (obj->technology));
if (obj->type == DKP_DEVICE_TYPE_LINE_POWER)
- gpm_add_info_data (_("Online"), gpm_bool_to_text (obj->online));
+ gpm_stats_add_info_data (_("Online"), gpm_stats_bool_to_text (obj->online));
}
/**
- * gpm_update_info_page_history:
+ * gpm_stats_update_info_page_history:
**/
static void
-gpm_update_info_page_history (const DkpClientDevice *device)
+gpm_stats_update_info_page_history (const DkpDevice *device)
{
EggObjList *array;
guint i;
@@ -370,7 +370,7 @@
else
gpm_graph_widget_set_type_y (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_TYPE_TIME);
- array = dkp_client_device_get_history (device, history_type, history_time, 150);
+ array = dkp_device_get_history (device, history_type, history_time, 150);
if (array == NULL) {
gtk_widget_hide (widget);
goto out;
@@ -409,7 +409,7 @@
/* smooth */
if (checked)
- gpm_update_smooth_data (new);
+ gpm_stats_update_smooth_data (new);
widget = glade_xml_get_widget (glade_xml, "custom_graph_history");
gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), new);
@@ -421,10 +421,10 @@
}
/**
- * gpm_update_info_page_stats:
+ * gpm_stats_update_info_page_stats:
**/
static void
-gpm_update_info_page_stats (const DkpClientDevice *device)
+gpm_stats_update_info_page_stats (const DkpDevice *device)
{
EggObjList *array;
guint i;
@@ -440,8 +440,6 @@
egg_obj_list_set_copy (new, (EggObjListCopyFunc) dkp_point_obj_copy);
egg_obj_list_set_free (new, (EggObjListFreeFunc) dkp_point_obj_free);
-// egg_debug ("history_type=%s", history_type);
-
widget = glade_xml_get_widget (glade_xml, "custom_graph_stats");
if (strcmp (stats_type, GPM_STATS_CHARGE_DATA_VALUE) == 0) {
type = "charging";
@@ -465,7 +463,7 @@
else
gpm_graph_widget_set_type_y (GPM_GRAPH_WIDGET (widget), GPM_GRAPH_WIDGET_TYPE_PERCENTAGE);
- array = dkp_client_device_get_statistics (device, type);
+ array = dkp_device_get_statistics (device, type);
if (array == NULL) {
gtk_widget_hide (widget);
goto out;
@@ -490,7 +488,7 @@
/* smooth */
if (checked)
- gpm_update_smooth_data (new);
+ gpm_stats_update_smooth_data (new);
widget = glade_xml_get_widget (glade_xml, "custom_graph_stats");
gpm_graph_widget_data_assign (GPM_GRAPH_WIDGET (widget), new);
@@ -503,24 +501,24 @@
}
/**
- * gpm_update_info_data_page:
+ * gpm_stats_update_info_data_page:
**/
static void
-gpm_update_info_data_page (const DkpClientDevice *device, gint page)
+gpm_stats_update_info_data_page (const DkpDevice *device, gint page)
{
if (page == 0)
- gpm_update_info_page_details (device);
+ gpm_stats_update_info_page_details (device);
else if (page == 1)
- gpm_update_info_page_history (device);
+ gpm_stats_update_info_page_history (device);
else if (page == 2)
- gpm_update_info_page_stats (device);
+ gpm_stats_update_info_page_stats (device);
}
/**
- * gpm_update_info_data:
+ * gpm_stats_update_info_data:
**/
static void
-gpm_update_info_data (const DkpClientDevice *device)
+gpm_stats_update_info_data (const DkpDevice *device)
{
gint page;
GtkWidget *widget;
@@ -528,7 +526,7 @@
const DkpObject *obj;
widget = glade_xml_get_widget (glade_xml, "notebook1");
- obj = dkp_client_device_get_object (device);
+ obj = dkp_device_get_object (device);
/* hide history if no support */
page_widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK(widget), 1);
@@ -545,18 +543,18 @@
gtk_widget_hide (page_widget);
page = gtk_notebook_get_current_page (GTK_NOTEBOOK (widget));
- gpm_update_info_data_page (device, page);
+ gpm_stats_update_info_data_page (device, page);
return;
}
/**
- * gpm_notebook_changed_cb:
+ * gpm_stats_notebook_changed_cb:
**/
static void
-gpm_notebook_changed_cb (GtkNotebook *notebook, GtkNotebookPage *page, gint page_num, gpointer user_data)
+gpm_stats_notebook_changed_cb (GtkNotebook *notebook, GtkNotebookPage *page, gint page_num, gpointer user_data)
{
- DkpClientDevice *device;
+ DkpDevice *device;
/* save page in gconf */
gconf_client_set_int (gconf_client, GPM_CONF_INFO_PAGE_NUMBER, page_num, NULL);
@@ -564,45 +562,45 @@
if (current_device == NULL)
return;
- device = dkp_client_device_new ();
- dkp_client_device_set_object_path (device, current_device);
- gpm_update_info_data_page (device, page_num);
- gpm_update_info_data (device);
+ device = dkp_device_new ();
+ dkp_device_set_object_path (device, current_device);
+ gpm_stats_update_info_data_page (device, page_num);
+ gpm_stats_update_info_data (device);
g_object_unref (device);
}
/**
- * gpm_button_refresh_cb:
+ * gpm_stats_button_refresh_cb:
**/
static void
-gpm_button_refresh_cb (GtkWidget *widget, gpointer data)
+gpm_stats_button_refresh_cb (GtkWidget *widget, gpointer data)
{
- DkpClientDevice *device;
- device = dkp_client_device_new ();
- dkp_client_device_set_object_path (device, current_device);
- dkp_client_device_refresh (device);
- gpm_update_info_data (device);
+ DkpDevice *device;
+ device = dkp_device_new ();
+ dkp_device_set_object_path (device, current_device);
+ dkp_device_refresh (device);
+ gpm_stats_update_info_data (device);
g_object_unref (device);
}
/**
- * gpm_button_update_ui:
+ * gpm_stats_button_update_ui:
**/
static void
-gpm_button_update_ui (void)
+gpm_stats_button_update_ui (void)
{
- DkpClientDevice *device;
- device = dkp_client_device_new ();
- dkp_client_device_set_object_path (device, current_device);
- gpm_update_info_data (device);
+ DkpDevice *device;
+ device = dkp_device_new ();
+ dkp_device_set_object_path (device, current_device);
+ gpm_stats_update_info_data (device);
g_object_unref (device);
}
/**
- * gpm_devices_treeview_clicked_cb:
+ * gpm_stats_devices_treeview_clicked_cb:
**/
static void
-gpm_devices_treeview_clicked_cb (GtkTreeSelection *selection, gboolean data)
+gpm_stats_devices_treeview_clicked_cb (GtkTreeSelection *selection, gboolean data)
{
GtkTreeModel *model;
GtkTreeIter iter;
@@ -618,10 +616,10 @@
/* show transaction_id */
egg_debug ("selected row is: %s", current_device);
- DkpClientDevice *device;
- device = dkp_client_device_new ();
- dkp_client_device_set_object_path (device, current_device);
- gpm_update_info_data (device);
+ DkpDevice *device;
+ device = dkp_device_new ();
+ dkp_device_set_object_path (device, current_device);
+ gpm_stats_update_info_data (device);
g_object_unref (device);
} else {
@@ -630,12 +628,11 @@
}
/**
- * gpm_info_create_custom_widget:
+ * gpm_stats_create_custom_widget:
**/
static GtkWidget *
-gpm_info_create_custom_widget (GladeXML *xml, gchar *func_name, gchar *name,
- gchar *string1, gchar *string2,
- gint int1, gint int2, gpointer user_data)
+gpm_stats_create_custom_widget (GladeXML *xml, gchar *func_name, gchar *name,
+ gchar *string1, gchar *string2, gint int1, gint int2, gpointer user_data)
{
GtkWidget *widget = NULL;
if (strcmp ("gpm_graph_widget_new", func_name) == 0) {
@@ -647,10 +644,10 @@
}
/**
- * gpm_gnome_activated_cb
+ * gpm_stats_window_activated_cb
**/
static void
-gpm_gnome_activated_cb (EggUnique *egg_unique, gpointer data)
+gpm_stats_window_activated_cb (EggUnique *egg_unique, gpointer data)
{
GtkWidget *widget;
widget = glade_xml_get_widget (glade_xml, "dialog_stats");
@@ -658,10 +655,10 @@
}
/**
- * gpm_add_device:
+ * gpm_stats_add_device:
**/
static void
-gpm_add_device (const DkpClientDevice *device)
+gpm_stats_add_device (const DkpDevice *device)
{
const gchar *id;
GtkTreeIter iter;
@@ -669,8 +666,8 @@
const gchar *text;
const gchar *icon;
- obj = dkp_client_device_get_object (device);
- id = dkp_client_device_get_object_path (device);
+ obj = dkp_device_get_object (device);
+ id = dkp_device_get_object_path (device);
text = gpm_device_type_to_localised_text (obj->type, 1);
icon = gpm_devicekit_get_object_icon (obj);
@@ -682,44 +679,44 @@
}
/**
- * gpm_tool_device_added_cb:
+ * gpm_stats_device_added_cb:
**/
static void
-gpm_tool_device_added_cb (DkpClient *client, const DkpClientDevice *device, gpointer user_data)
+gpm_stats_device_added_cb (DkpClient *client, const DkpDevice *device, gpointer user_data)
{
const gchar *object_path;
- object_path = dkp_client_device_get_object_path (device);
+ object_path = dkp_device_get_object_path (device);
egg_debug ("added: %s", object_path);
- gpm_add_device (device);
+ gpm_stats_add_device (device);
}
/**
- * gpm_tool_device_changed_cb:
+ * gpm_stats_device_changed_cb:
**/
static void
-gpm_tool_device_changed_cb (DkpClient *client, const DkpClientDevice *device, gpointer user_data)
+gpm_stats_device_changed_cb (DkpClient *client, const DkpDevice *device, gpointer user_data)
{
const gchar *object_path;
- object_path = dkp_client_device_get_object_path (device);
+ object_path = dkp_device_get_object_path (device);
if (object_path == NULL || current_device == NULL)
return;
egg_debug ("changed: %s", object_path);
if (strcmp (current_device, object_path) == 0)
- gpm_update_info_data (device);
+ gpm_stats_update_info_data (device);
}
/**
- * gpm_tool_device_removed_cb:
+ * gpm_stats_device_removed_cb:
**/
static void
-gpm_tool_device_removed_cb (DkpClient *client, const DkpClientDevice *device, gpointer user_data)
+gpm_stats_device_removed_cb (DkpClient *client, const DkpDevice *device, gpointer user_data)
{
const gchar *object_path;
GtkTreeIter iter;
gchar *id = NULL;
gboolean ret;
- object_path = dkp_client_device_get_object_path (device);
+ object_path = dkp_device_get_object_path (device);
egg_debug ("removed: %s", object_path);
if (strcmp (current_device, object_path) == 0) {
gtk_list_store_clear (list_store_info);
@@ -739,10 +736,10 @@
}
/**
- * gpm_history_type_combo_changed_cb:
+ * gpm_stats_history_type_combo_changed_cb:
**/
static void
-gpm_history_type_combo_changed_cb (GtkWidget *widget, gpointer data)
+gpm_stats_history_type_combo_changed_cb (GtkWidget *widget, gpointer data)
{
gchar *value;
const gchar *axis_x = NULL;
@@ -782,7 +779,7 @@
widget = glade_xml_get_widget (glade_xml, "label_axis_history_y");
gtk_label_set_label (GTK_LABEL(widget), axis_y);
- gpm_button_update_ui ();
+ gpm_stats_button_update_ui ();
g_free (value);
/* save to gconf */
@@ -833,7 +830,7 @@
widget = glade_xml_get_widget (glade_xml, "label_axis_stats_y");
gtk_label_set_label (GTK_LABEL(widget), axis_y);
- gpm_button_update_ui ();
+ gpm_stats_button_update_ui ();
g_free (value);
/* save to gconf */
@@ -841,10 +838,10 @@
}
/**
- * gpm_update_range_combo_changed:
+ * gpm_stats_range_combo_changed:
**/
static void
-gpm_update_range_combo_changed (GtkWidget *widget, gpointer data)
+gpm_stats_range_combo_changed (GtkWidget *widget, gpointer data)
{
gchar *value;
value = gtk_combo_box_get_active_text (GTK_COMBO_BOX (widget));
@@ -862,34 +859,34 @@
/* save to gconf */
gconf_client_set_int (gconf_client, GPM_CONF_INFO_HISTORY_TIME, history_time, NULL);
- gpm_button_update_ui ();
+ gpm_stats_button_update_ui ();
g_free (value);
}
/**
- * gpm_smooth_checkbox_history_cb:
+ * gpm_stats_smooth_checkbox_history_cb:
* @widget: The GtkWidget object
**/
static void
-gpm_smooth_checkbox_history_cb (GtkWidget *widget, gpointer data)
+gpm_stats_smooth_checkbox_history_cb (GtkWidget *widget, gpointer data)
{
gboolean checked;
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
gconf_client_set_bool (gconf_client, GPM_CONF_INFO_HISTORY_GRAPH_SMOOTH, checked, NULL);
- gpm_button_update_ui ();
+ gpm_stats_button_update_ui ();
}
/**
- * gpm_smooth_checkbox_stats_cb:
+ * gpm_stats_smooth_checkbox_stats_cb:
* @widget: The GtkWidget object
**/
static void
-gpm_smooth_checkbox_stats_cb (GtkWidget *widget, gpointer data)
+gpm_stats_smooth_checkbox_stats_cb (GtkWidget *widget, gpointer data)
{
gboolean checked;
checked = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
gconf_client_set_bool (gconf_client, GPM_CONF_INFO_STATS_GRAPH_SMOOTH, checked, NULL);
- gpm_button_update_ui ();
+ gpm_stats_button_update_ui ();
}
/**
@@ -906,7 +903,7 @@
gboolean ret;
DkpClient *client;
GPtrArray *devices;
- DkpClientDevice *device;
+ DkpDevice *device;
guint i;
gint page;
const gchar *object_path;
@@ -944,7 +941,7 @@
if (!ret)
goto unique_out;
g_signal_connect (egg_unique, "activated",
- G_CALLBACK (gpm_gnome_activated_cb), NULL);
+ G_CALLBACK (gpm_stats_window_activated_cb), NULL);
/* add application specific icons to search path */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
@@ -961,7 +958,7 @@
GPM_DATA G_DIR_SEPARATOR_S "icons");
/* use custom widgets */
- glade_set_custom_handler (gpm_info_create_custom_widget, NULL);
+ glade_set_custom_handler (gpm_stats_create_custom_widget, NULL);
glade_xml = glade_xml_new (GPM_DATA "/gpm-statistics.glade", NULL, NULL);
widget = glade_xml_get_widget (glade_xml, "dialog_stats");
@@ -978,29 +975,29 @@
widget = glade_xml_get_widget (glade_xml, "button_help");
g_signal_connect (widget, "clicked",
- G_CALLBACK (gpm_button_help_cb), NULL);
+ G_CALLBACK (gpm_stats_button_help_cb), NULL);
widget = glade_xml_get_widget (glade_xml, "button_refresh");
g_signal_connect (widget, "clicked",
- G_CALLBACK (gpm_button_refresh_cb), NULL);
+ G_CALLBACK (gpm_stats_button_refresh_cb), NULL);
widget = glade_xml_get_widget (glade_xml, "checkbutton_smooth_history");
checked = gconf_client_get_bool (gconf_client, GPM_CONF_INFO_HISTORY_GRAPH_SMOOTH, NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), checked);
g_signal_connect (widget, "clicked",
- G_CALLBACK (gpm_smooth_checkbox_history_cb), NULL);
+ G_CALLBACK (gpm_stats_smooth_checkbox_history_cb), NULL);
widget = glade_xml_get_widget (glade_xml, "checkbutton_smooth_stats");
checked = gconf_client_get_bool (gconf_client, GPM_CONF_INFO_STATS_GRAPH_SMOOTH, NULL);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), checked);
g_signal_connect (widget, "clicked",
- G_CALLBACK (gpm_smooth_checkbox_stats_cb), NULL);
+ G_CALLBACK (gpm_stats_smooth_checkbox_stats_cb), NULL);
widget = glade_xml_get_widget (glade_xml, "notebook1");
page = gconf_client_get_int (gconf_client, GPM_CONF_INFO_PAGE_NUMBER, NULL);
gtk_notebook_set_current_page (GTK_NOTEBOOK (widget), page);
g_signal_connect (widget, "switch-page",
- G_CALLBACK (gpm_notebook_changed_cb), NULL);
+ G_CALLBACK (gpm_stats_notebook_changed_cb), NULL);
/* create list stores */
list_store_info = gtk_list_store_new (GPM_INFO_COLUMN_LAST, G_TYPE_STRING, G_TYPE_STRING);
@@ -1013,7 +1010,7 @@
GTK_TREE_MODEL (list_store_info));
/* add columns to the tree view */
- gpm_add_info_columns (GTK_TREE_VIEW (widget));
+ gpm_stats_add_info_columns (GTK_TREE_VIEW (widget));
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)); /* show */
/* create transaction_id tree view */
@@ -1022,10 +1019,10 @@
GTK_TREE_MODEL (list_store_devices));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
g_signal_connect (selection, "changed",
- G_CALLBACK (gpm_devices_treeview_clicked_cb), NULL);
+ G_CALLBACK (gpm_stats_devices_treeview_clicked_cb), NULL);
/* add columns to the tree view */
- gpm_add_devices_columns (GTK_TREE_VIEW (widget));
+ gpm_stats_add_devices_columns (GTK_TREE_VIEW (widget));
gtk_tree_view_columns_autosize (GTK_TREE_VIEW (widget)); /* show */
history_type = gconf_client_get_string (gconf_client, GPM_CONF_INFO_HISTORY_TYPE, NULL);
@@ -1049,7 +1046,7 @@
else
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 1);
g_signal_connect (G_OBJECT (widget), "changed",
- G_CALLBACK (gpm_history_type_combo_changed_cb), NULL);
+ G_CALLBACK (gpm_stats_history_type_combo_changed_cb), NULL);
widget = glade_xml_get_widget (glade_xml, "combobox_stats_type");
gtk_combo_box_append_text (GTK_COMBO_BOX (widget), GPM_STATS_CHARGE_DATA_TEXT);
@@ -1082,7 +1079,7 @@
else
gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 2);
g_signal_connect (G_OBJECT (widget), "changed",
- G_CALLBACK (gpm_update_range_combo_changed), NULL);
+ G_CALLBACK (gpm_stats_range_combo_changed), NULL);
widget = glade_xml_get_widget (glade_xml, "custom_graph_history");
gtk_widget_set_size_request (widget, 700, 400);
@@ -1092,25 +1089,21 @@
gtk_widget_show (widget);
client = dkp_client_new ();
- g_signal_connect (client, "device-added", G_CALLBACK (gpm_tool_device_added_cb), NULL);
- g_signal_connect (client, "device-removed", G_CALLBACK (gpm_tool_device_removed_cb), NULL);
- g_signal_connect (client, "device-changed", G_CALLBACK (gpm_tool_device_changed_cb), NULL);
+ g_signal_connect (client, "device-added", G_CALLBACK (gpm_stats_device_added_cb), NULL);
+ g_signal_connect (client, "device-removed", G_CALLBACK (gpm_stats_device_removed_cb), NULL);
+ g_signal_connect (client, "device-changed", G_CALLBACK (gpm_stats_device_changed_cb), NULL);
/* coldplug */
- devices = dkp_client_enumerate_devices (client, NULL);
+ devices = dkp_client_enumerate_devices (client);
if (devices == NULL)
goto out;
for (i=0; i < devices->len; i++) {
- object_path = (const gchar *) g_ptr_array_index (devices, i);
- egg_debug ("Device: %s", object_path);
- device = dkp_client_device_new ();
- dkp_client_device_set_object_path (device, object_path);
- gpm_add_device (device);
+ device = g_ptr_array_index (devices, i);
+ gpm_stats_add_device (device);
if (i == 0) {
- gpm_update_info_data (device);
- current_device = g_strdup (object_path);
+ gpm_stats_update_info_data (device);
+ current_device = g_strdup (dkp_device_get_object_path (device));
}
- g_object_unref (device);
}
gchar *last_device;
@@ -1133,12 +1126,12 @@
}
}
- g_ptr_array_foreach (devices, (GFunc) g_free, NULL);
+ g_ptr_array_foreach (devices, (GFunc) g_object_unref, NULL);
g_ptr_array_free (devices, TRUE);
/* set axis */
widget = glade_xml_get_widget (glade_xml, "combobox_history_type");
- gpm_history_type_combo_changed_cb (widget, NULL);
+ gpm_stats_history_type_combo_changed_cb (widget, NULL);
widget = glade_xml_get_widget (glade_xml, "combobox_stats_type");
gpm_stats_type_combo_changed_cb (widget, NULL);
Modified: trunk/src/gpm-tray-icon.c
==============================================================================
--- trunk/src/gpm-tray-icon.c (original)
+++ trunk/src/gpm-tray-icon.c Wed Nov 26 11:35:12 2008
@@ -41,6 +41,15 @@
#include <gtk/gtkstatusicon.h>
#include <gconf/gconf-client.h>
+#ifdef HAVE_DK_POWER
+ #include <dkp-device.h>
+#endif
+
+#ifdef HAVE_DK_POWER
+ #include "gpm-devicekit.h"
+ #include "gpm-engine.h"
+#endif
+
#include "gpm-control.h"
#include "gpm-common.h"
#include "egg-debug.h"
@@ -62,8 +71,11 @@
GConfClient *conf;
GpmControl *control;
GpmNotify *notify;
+#ifndef HAVE_DK_POWER
GpmEngineCollection *collection;
-
+#else
+ GpmEngine *engine;
+#endif
GtkStatusIcon *status_icon;
gboolean is_visible;
gboolean show_suspend;
@@ -86,18 +98,18 @@
G_DEFINE_TYPE (GpmTrayIcon, gpm_tray_icon, G_TYPE_OBJECT)
+#ifndef HAVE_DK_POWER
/**
* gpm_tray_icon_set_collection_data:
**/
gboolean
-gpm_tray_icon_set_collection_data (GpmTrayIcon *icon,
- GpmEngineCollection *collection)
+gpm_tray_icon_set_collection_data (GpmTrayIcon *icon, GpmEngineCollection *collection)
{
g_return_val_if_fail (GPM_IS_TRAY_ICON (icon), FALSE);
-
icon->priv->collection = collection;
return TRUE;
}
+#endif
/**
* gpm_tray_icon_enable_suspend:
@@ -196,23 +208,41 @@
/**
* gpm_tray_icon_show_info_cb:
- * @action: A valid GtkAction
- * @icon: This TrayIcon class instance
**/
static void
gpm_tray_icon_show_info_cb (GtkMenuItem *item, gpointer data)
{
- GpmCell *cell;
+ gchar *icon_name = NULL;
+ gchar *description = NULL;
GtkWidget *dialog;
GtkWidget *image;
- gchar *icon_name;
- gchar *description;
+#ifndef HAVE_DK_POWER
+ GpmCell *cell;
+#else
+ const DkpObject *obj;
+ const gchar *object_path;
+ DkpDevice *device = NULL;
+ gboolean ret;
+#endif
+#ifndef HAVE_DK_POWER
cell = g_object_get_data (G_OBJECT (item), "cell");
-
- /* get long description */
description = gpm_cell_get_description (cell);
icon_name = gpm_cell_get_icon (cell);
+#else
+ object_path = g_object_get_data (G_OBJECT (item), "object-path");
+ egg_debug ("object_path=%s", object_path);
+ if (object_path == NULL)
+ goto out;
+
+ device = dkp_device_new ();
+ ret = dkp_device_set_object_path (device, object_path);
+ if (!ret)
+ goto out;
+ obj = dkp_device_get_object (device);
+ icon_name = gpm_devicekit_get_object_icon (obj);
+ description = gpm_devicekit_get_object_description (obj);
+#endif
image = gtk_image_new ();
dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -228,6 +258,11 @@
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (GTK_WIDGET (dialog));
+out:
+#ifdef HAVE_DK_POWER
+ if (device != NULL)
+ g_object_unref (device);
+#endif
g_free (description);
g_free (icon_name);
}
@@ -370,8 +405,7 @@
* We have to re-enable the tooltip when the popup is removed
**/
static void
-gpm_tray_icon_popup_cleared_cd (GtkWidget *widget,
- GpmTrayIcon *icon)
+gpm_tray_icon_popup_cleared_cd (GtkWidget *widget, GpmTrayIcon *icon)
{
g_return_if_fail (GPM_IS_TRAY_ICON (icon));
egg_debug ("clear tray (icon = %p)", icon);
@@ -383,10 +417,9 @@
static void
gpm_tray_icon_class_init (GpmTrayIconClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = gpm_tray_icon_finalize;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gpm_tray_icon_finalize;
g_type_class_add_private (klass, sizeof (GpmTrayIconPrivate));
signals [SUSPEND] =
@@ -394,9 +427,7 @@
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GpmTrayIconClass, suspend),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
signals [HIBERNATE] =
@@ -404,9 +435,7 @@
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GpmTrayIconClass, hibernate),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
+ NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
}
@@ -417,10 +446,7 @@
* Display the popup menu.
**/
static void
-gpm_tray_icon_popup_menu_cb (GtkStatusIcon *status_icon,
- guint button,
- guint32 timestamp,
- GpmTrayIcon *icon)
+gpm_tray_icon_popup_menu_cb (GtkStatusIcon *status_icon, guint button, guint32 timestamp, GpmTrayIcon *icon)
{
GtkMenu *menu = (GtkMenu*) gtk_menu_new ();
GtkWidget *item;
@@ -431,7 +457,7 @@
if (!icon->priv->show_context_menu)
return;
- /* Preferences */
+ /* preferences */
item = gtk_image_menu_item_new_with_mnemonic (_("_Preferences"));
image = gtk_image_new_from_icon_name (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
@@ -439,7 +465,7 @@
G_CALLBACK (gpm_tray_icon_show_preferences_cb), icon);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- /* Statistics */
+ /* statistics */
item = gtk_image_menu_item_new_with_mnemonic (_("Power _History"));
image = gtk_image_new_from_icon_name (GPM_STOCK_STATISTICS, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
@@ -447,11 +473,11 @@
G_CALLBACK (gpm_tray_icon_show_statistics_cb), icon);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- /* Separator for HIG? */
+ /* separator for HIG? */
item = gtk_separator_menu_item_new ();
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- /* Help */
+ /* help */
item = gtk_image_menu_item_new_with_mnemonic (_("_Help"));
image = gtk_image_new_from_icon_name (GTK_STOCK_HELP, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
@@ -459,7 +485,7 @@
G_CALLBACK (gpm_tray_icon_show_help_cb), icon);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- /* About */
+ /* about */
item = gtk_image_menu_item_new_with_mnemonic (_("_About"));
image = gtk_image_new_from_icon_name (GTK_STOCK_ABOUT, GTK_ICON_SIZE_MENU);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
@@ -472,23 +498,21 @@
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
gtk_status_icon_position_menu, status_icon,
button, timestamp);
- if (button == 0) {
+ if (button == 0)
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
- }
g_signal_connect (GTK_WIDGET (menu), "hide",
G_CALLBACK (gpm_tray_icon_popup_cleared_cd), icon);
}
+#ifndef HAVE_DK_POWER
/**
* gpm_tray_icon_add_device:
*
* Add all the selected type of devices to the menu to form "drop down" info.
**/
static guint
-gpm_tray_icon_add_device (GpmTrayIcon *icon,
- GtkMenu *menu,
- GpmCellArray *array)
+gpm_tray_icon_add_device (GpmTrayIcon *icon, GtkMenu *menu, GpmCellArray *array)
{
GtkWidget *item;
GtkWidget *image;
@@ -498,15 +522,10 @@
gchar *icon_name;
gchar *label;
const gchar *desc;
- guint max;
+ guint len;
- max = gpm_cell_array_get_num_cells (array);
- /* shortcut */
- if (max == 0) {
- return max;
- }
-
- for (i=0; i<max; i++) {
+ len = gpm_cell_array_get_num_cells (array);
+ for (i=0; i<len; i++) {
cell = gpm_cell_array_get_cell (array, i);
unit = gpm_cell_get_unit (cell);
@@ -530,8 +549,58 @@
g_object_set_data (G_OBJECT (item), "cell", (gpointer) cell);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
}
- return max;
+ return len;
}
+#else
+/**
+ * gpm_tray_icon_add_device:
+ **/
+static guint
+gpm_tray_icon_add_device (GpmTrayIcon *icon, GtkMenu *menu, const GPtrArray *array, DkpDeviceType type)
+{
+ guint i;
+ guint added = 0;
+ gchar *icon_name;
+ gchar *label;
+ GtkWidget *item;
+ GtkWidget *image;
+ const gchar *object_path;
+ const DkpObject *obj;
+ const gchar *desc;
+ const DkpDevice *device;
+
+ /* find type */
+ for (i=0;i<array->len;i++) {
+ device = g_ptr_array_index (array, i);
+ obj = dkp_device_get_object (device);
+ if (obj->type != type)
+ continue;
+
+ object_path = dkp_device_get_object_path (device);
+ egg_debug ("adding device %s", object_path);
+ added++;
+
+ /* generate the label */
+ desc = gpm_device_type_to_localised_text (type, 1);
+ label = g_strdup_printf ("%s (%.1f%%)", desc, obj->percentage);
+ item = gtk_image_menu_item_new_with_label (label);
+
+ /* generate the image */
+ icon_name = gpm_devicekit_get_object_icon (obj);
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+ gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+
+ /* callback and add the the menu */
+ g_signal_connect (G_OBJECT (item), "activate", G_CALLBACK (gpm_tray_icon_show_info_cb), icon);
+ g_object_set_data (G_OBJECT (item), "object-path", (gpointer) object_path);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ g_free (icon_name);
+ g_free (label);
+ }
+ return added;
+}
+#endif
/**
* gpm_tray_icon_activate_cb:
@@ -541,8 +610,7 @@
* Callback when the icon is clicked
**/
static void
-gpm_tray_icon_activate_cb (GtkStatusIcon *status_icon,
- GpmTrayIcon *icon)
+gpm_tray_icon_activate_cb (GtkStatusIcon *status_icon, GpmTrayIcon *icon)
{
GtkMenu *menu = (GtkMenu*) gtk_menu_new ();
GtkWidget *item;
@@ -552,19 +620,27 @@
egg_debug ("icon left clicked");
/* add all device types to the drop down menu */
+#ifndef HAVE_DK_POWER
dev_cnt += gpm_tray_icon_add_device (icon, menu, icon->priv->collection->primary);
dev_cnt += gpm_tray_icon_add_device (icon, menu, icon->priv->collection->ups);
dev_cnt += gpm_tray_icon_add_device (icon, menu, icon->priv->collection->phone);
dev_cnt += gpm_tray_icon_add_device (icon, menu, icon->priv->collection->mouse);
dev_cnt += gpm_tray_icon_add_device (icon, menu, icon->priv->collection->keyboard);
dev_cnt += gpm_tray_icon_add_device (icon, menu, icon->priv->collection->pda);
-
- if (dev_cnt == 0 &&
- icon->priv->show_suspend == FALSE &&
- icon->priv->show_hibernate == FALSE) {
- /* nothing to display! */
+#else
+ const GPtrArray *array;
+ array = gpm_engine_get_devices (icon->priv->engine);
+ dev_cnt += gpm_tray_icon_add_device (icon, menu, array, DKP_DEVICE_TYPE_BATTERY);
+ dev_cnt += gpm_tray_icon_add_device (icon, menu, array, DKP_DEVICE_TYPE_UPS);
+ dev_cnt += gpm_tray_icon_add_device (icon, menu, array, DKP_DEVICE_TYPE_MOUSE);
+ dev_cnt += gpm_tray_icon_add_device (icon, menu, array, DKP_DEVICE_TYPE_KEYBOARD);
+ dev_cnt += gpm_tray_icon_add_device (icon, menu, array, DKP_DEVICE_TYPE_PDA);
+ dev_cnt += gpm_tray_icon_add_device (icon, menu, array, DKP_DEVICE_TYPE_PHONE);
+ g_ptr_array_foreach ((GPtrArray*)array, (GFunc) g_object_unref, NULL);
+#endif
+ /* nothing to display! */
+ if (dev_cnt == 0 && !icon->priv->show_suspend && !icon->priv->show_hibernate)
return;
- }
/* only do the seporator if we have at least one device and can do an action */
if (dev_cnt != 0 && (icon->priv->show_suspend || icon->priv->show_hibernate)) {
@@ -654,8 +730,11 @@
icon->priv = GPM_TRAY_ICON_GET_PRIVATE (icon);
+#ifndef HAVE_DK_POWER
icon->priv->collection = NULL;
-
+#else
+ icon->priv->engine = gpm_engine_new ();
+#endif
/* use libnotify */
icon->priv->notify = gpm_notify_new ();
@@ -713,7 +792,9 @@
g_object_unref (tray_icon->priv->notify);
g_object_unref (tray_icon->priv->control);
g_object_unref (tray_icon->priv->status_icon);
-
+#ifndef HAVE_DK_POWER
+ g_object_unref (tray_icon->priv->engine);
+#endif
g_return_if_fail (tray_icon->priv != NULL);
G_OBJECT_CLASS (gpm_tray_icon_parent_class)->finalize (object);
Modified: trunk/src/gpm-tray-icon.h
==============================================================================
--- trunk/src/gpm-tray-icon.h (original)
+++ trunk/src/gpm-tray-icon.h Wed Nov 26 11:35:12 2008
@@ -24,7 +24,9 @@
#define __GPM_TRAY_ICON_H
#include <glib-object.h>
-#include "gpm-engine.h"
+#ifndef HAVE_DK_POWER
+#include "gpm-engine-old.h"
+#endif
G_BEGIN_DECLS
@@ -57,8 +59,10 @@
const gchar *tooltip);
gboolean gpm_tray_icon_set_icon (GpmTrayIcon *icon,
const gchar *filename);
+#ifndef HAVE_DK_POWER
gboolean gpm_tray_icon_set_collection_data (GpmTrayIcon *icon,
GpmEngineCollection *collection);
+#endif
G_END_DECLS
Modified: trunk/src/gpm-warnings.c
==============================================================================
--- trunk/src/gpm-warnings.c (original)
+++ trunk/src/gpm-warnings.c Wed Nov 26 11:35:12 2008
@@ -48,7 +48,7 @@
struct GpmWarningsPrivate
{
- GConfClient *conf;
+ GConfClient *conf;
gboolean use_time_primary;
gboolean time_is_accurate;
@@ -81,8 +81,7 @@
}
static GpmWarningsState
-gpm_warnings_get_state_csr (GpmWarnings *warnings,
- GpmCellUnit *unit)
+gpm_warnings_get_state_csr (GpmWarnings *warnings, GpmCellUnit *unit)
{
if (unit->charge_current == 2) {
return GPM_WARNINGS_LOW;
@@ -93,8 +92,7 @@
}
static GpmWarningsState
-gpm_warnings_get_state_time (GpmWarnings *warnings,
- GpmCellUnit *unit)
+gpm_warnings_get_state_time (GpmWarnings *warnings, GpmCellUnit *unit)
{
if (unit->time_discharge == 0) {
/* this is probably an error condition */
@@ -141,7 +139,7 @@
* Return value: A GpmWarnings state, e.g. GPM_WARNINGS_VERY_LOW
**/
GpmWarningsState
-gpm_warnings_get_state (GpmWarnings *warnings, GpmCellUnit *unit)
+gpm_warnings_get_state (GpmWarnings *warnings, GpmCellUnit *unit)
{
GpmWarningsState type;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]