aboutsummaryrefslogtreecommitdiff
path: root/src/indicator-power.c
diff options
context:
space:
mode:
authorJavier Jardón <javier.jardon@codethink.co.uk>2011-07-04 16:48:53 +0100
committerJavier Jardón <javier.jardon@codethink.co.uk>2011-07-04 16:48:53 +0100
commit453148a27b6bf3b85e378b227250a63cc0aaadd4 (patch)
tree2137a40fd7591af366b2b77d813dae75c24bdcfb /src/indicator-power.c
parent40b045d4735aed72da6bc6cb2125b6b922ad181e (diff)
downloadayatana-indicator-power-453148a27b6bf3b85e378b227250a63cc0aaadd4.tar.gz
ayatana-indicator-power-453148a27b6bf3b85e378b227250a63cc0aaadd4.tar.bz2
ayatana-indicator-power-453148a27b6bf3b85e378b227250a63cc0aaadd4.zip
Add real info in the menu item
Diffstat (limited to 'src/indicator-power.c')
-rw-r--r--src/indicator-power.c71
1 files changed, 61 insertions, 10 deletions
diff --git a/src/indicator-power.c b/src/indicator-power.c
index 32a93b1..f93c797 100644
--- a/src/indicator-power.c
+++ b/src/indicator-power.c
@@ -75,6 +75,8 @@ struct _IndicatorPowerPrivate
GCancellable *proxy_cancel;
GDBusProxy *proxy;
+
+ GVariant *device;
};
/* Prototypes */
@@ -312,28 +314,75 @@ set_accessible_desc (IndicatorPower *self,
priv->accessible_desc = g_strdup (desc);
}
-static void
-build_menu (IndicatorPower *self)
+static guint
+menu_add_device (GtkMenu *menu,
+ GVariant *device)
{
- IndicatorPowerPrivate *priv = self->priv;
+ UpDeviceKind kind;
+ UpDeviceState state;
GtkWidget *icon;
GtkWidget *item;
- GtkWidget *image;
- guint n_devices = 1; /*TODO*/
+ gchar *device_icon = NULL;
+ gchar *object_path = NULL;
+ gdouble percentage;
+ guint64 time;
+ const gchar *device_name;
+ gchar *short_details = NULL;
+ gchar *details = NULL;
+ guint n_devices = 0;
- priv->menu = GTK_MENU (gtk_menu_new ());
+ if (device == NULL)
+ return n_devices;
+
+ g_variant_get (device,
+ "((susdut))",
+ &object_path,
+ &kind,
+ &device_icon,
+ &percentage,
+ &state,
+ &time);
- icon = gtk_image_new_from_icon_name ("battery", GTK_ICON_SIZE_MENU);
+ g_debug ("%s: got data from object %s", G_STRFUNC, object_path);
+
+ n_devices++;
+
+ icon = gtk_image_new_from_icon_name (device_icon, GTK_ICON_SIZE_MENU);
+ device_name = device_kind_to_localised_string (kind);
+
+ g_print ("Device: %s\n", device_name);
+
+ build_device_time_details (device_name, time, state, percentage, &short_details, &details);
+
+ g_print ("Details: %s\n", details);
item = gtk_image_menu_item_new ();
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), icon);
- gtk_menu_item_set_label (GTK_MENU_ITEM (item), "Battery Remaining: 0:45s"); /*TODO*/
+ gtk_menu_item_set_label (GTK_MENU_ITEM (item), details);
gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (item), TRUE);
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (show_info_cb), NULL);
- gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+
+ return n_devices;
+}
+
+static void
+build_menu (IndicatorPower *self)
+{
+ IndicatorPowerPrivate *priv = self->priv;
+ GtkWidget *item;
+ GtkWidget *image;
+ guint n_devices = 0;
- /* only do the seporator if we have at least one device */
+ priv->menu = GTK_MENU (gtk_menu_new ());
+
+ /* devices */
+ n_devices += menu_add_device (priv->menu, priv->device);
+
+ g_print ("Num devices: %d\n", n_devices);
+
+ /* only do the separator if we have at least one device */
if (n_devices != 0)
{
item = gtk_separator_menu_item_new ();
@@ -394,6 +443,8 @@ get_primary_device_cb (GObject *source_object,
return;
}
+ priv->device = result;
+
/* set the icon and text */
g_variant_get (result,
"((susdut))",