diff options
author | Ken VanDine <ken.vandine@canonical.com> | 2011-07-14 11:04:21 -0400 |
---|---|---|
committer | Ken VanDine <ken.vandine@canonical.com> | 2011-07-14 11:04:21 -0400 |
commit | b891e8ba2224e1c554d6076a7f6df3536204db07 (patch) | |
tree | 213393b8b477481682540bc55b1d00be5993cb59 | |
parent | 502f3f9dc58ddbe9ccae645d5e29fb0e7c09a65d (diff) | |
parent | 74a0c13692f0f030a212dc56ac3e90cb6dda510d (diff) | |
download | ayatana-indicator-power-b891e8ba2224e1c554d6076a7f6df3536204db07.tar.gz ayatana-indicator-power-b891e8ba2224e1c554d6076a7f6df3536204db07.tar.bz2 ayatana-indicator-power-b891e8ba2224e1c554d6076a7f6df3536204db07.zip |
Import upstream version 0.3
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | ChangeLog | 49 | ||||
-rwxr-xr-x | configure | 20 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/indicator-power.c | 165 |
5 files changed, 175 insertions, 62 deletions
@@ -4,4 +4,5 @@ Javier Jardón Ken VanDine ken.vandine@canonical.com + Michael Terry Ted Gould @@ -1,8 +1,53 @@ # Generated by Makefile. Do not edit. -2011-07-08 Javier Jardón <javier.jardon@codethink.co.uk> +2011-07-14 Javier Jardón <javier.jardon@codethink.co.uk> + + Do not show the device name in the menu title + +2011-07-14 Javier Jardón <javier.jardon@codethink.co.uk> + + Release 0.3 + +2011-07-14 Javier Jardón <javier.jardon@codethink.co.uk> + + Show "X (charged)" if it is fully charged and not discharging + +2011-07-14 Javier Jardón <javier.jardon@codethink.co.uk> + + Only show the remaining time if it is discharging with less than 12 hours left + +2011-07-14 Javier Jardón <javier.jardon@codethink.co.uk> + + Refine the text of the items in the menu to follow the specification + + - "X (H:MM to charge)" if it is charging, with the accessible name + "X: MM minutes to charge" or "X: H hours MM minutes to charge" + + - "X (H:MM left)" if it is discharging with less than 12 hours left,x + with the accessible name "X: MM minutes left" or "X: H hours MM minutes left". + +2011-07-14 Michael Terry <michael.terry@canonical.com> + + Draw option checkbox as check, not radio + +2011-07-13 Michael Terry <michael.terry@canonical.com> + + draw option checkbox as check, not radio + +2011-07-14 Javier Jardón <javier.jardon@codethink.co.uk> + + Show the apropiate icon depending of the status of the devices + + Follow https://wiki.ubuntu.com/BatteryStatusMenu : + + - If anything is discharging, the menu title should represent the thing + that is estimated to lose power first. + - If no devices are discharging, the menu title should represent the device + that is estimated to take longest to charge. + +2011-07-13 Javier Jardón <javier.jardon@codethink.co.uk> - Release version 0.2 + Create new function to store the logic to put the primary device 2011-07-08 Javier Jardón <javier.jardon@codethink.co.uk> @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.68 for indicator-power 0.2. +# Generated by GNU Autoconf 2.68 for indicator-power 0.3. # # Report bugs to <http://bugs.launchpad.net/indicator-power>. # @@ -570,8 +570,8 @@ MAKEFLAGS= # Identity of this package. PACKAGE_NAME='indicator-power' PACKAGE_TARNAME='indicator-power' -PACKAGE_VERSION='0.2' -PACKAGE_STRING='indicator-power 0.2' +PACKAGE_VERSION='0.3' +PACKAGE_STRING='indicator-power 0.3' PACKAGE_BUGREPORT='http://bugs.launchpad.net/indicator-power' PACKAGE_URL='http://launchpad.net/indicator-power' @@ -1358,7 +1358,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures indicator-power 0.2 to adapt to many kinds of systems. +\`configure' configures indicator-power 0.3 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1428,7 +1428,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of indicator-power 0.2:";; + short | recursive ) echo "Configuration of indicator-power 0.3:";; esac cat <<\_ACEOF @@ -1555,7 +1555,7 @@ fi test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -indicator-power configure 0.2 +indicator-power configure 0.3 generated by GNU Autoconf 2.68 Copyright (C) 2010 Free Software Foundation, Inc. @@ -1833,7 +1833,7 @@ cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by indicator-power $as_me 0.2, which was +It was created by indicator-power $as_me 0.3, which was generated by GNU Autoconf 2.68. Invocation command line was $ $0 $@ @@ -2657,7 +2657,7 @@ fi # Define the identity of the package. PACKAGE='indicator-power' - VERSION='0.2' + VERSION='0.3' cat >>confdefs.h <<_ACEOF @@ -14769,7 +14769,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1 # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by indicator-power $as_me 0.2, which was +This file was extended by indicator-power $as_me 0.3, which was generated by GNU Autoconf 2.68. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -14836,7 +14836,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -indicator-power config.status 0.2 +indicator-power config.status 0.3 configured by $0, generated by GNU Autoconf 2.68, with options \\"\$ac_cs_config\\" diff --git a/configure.ac b/configure.ac index b8724b0..99780b6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_INIT([indicator-power], - [0.2], + [0.3], [http://bugs.launchpad.net/indicator-power], [indicator-power], [http://launchpad.net/indicator-power]) diff --git a/src/indicator-power.c b/src/indicator-power.c index 48d85a6..a81b791 100644 --- a/src/indicator-power.c +++ b/src/indicator-power.c @@ -262,7 +262,8 @@ build_device_time_details (const gchar *device_name, UpDeviceState state, gdouble percentage, gchar **short_details, - gchar **details) + gchar **details, + gchar **accesible_name) { gchar *short_timestring = NULL; gchar *detailed_timestring = NULL; @@ -279,24 +280,46 @@ build_device_time_details (const gchar *device_name, if (state == UP_DEVICE_STATE_CHARGING) { /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ - *details = g_strdup_printf (_("%s (%s until charged (%.0lf%%))"), - device_name, detailed_timestring, percentage); + *accesible_name = g_strdup_printf (_("%s (%s to charge (%.0lf%%))"), + device_name, detailed_timestring, percentage); + *details = g_strdup_printf (_("%s (%s to charge)"), + device_name, short_timestring); } else if (state == UP_DEVICE_STATE_DISCHARGING) { - /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ - *details = g_strdup_printf (_("%s (%s until empty (%.0lf%%))"), - device_name, detailed_timestring, percentage); + if (time > 43200) /* 12 hours */ + { + *accesible_name = g_strdup_printf (_("%s"), device_name); + *details = g_strdup_printf (_("%s"), device_name); + } + else + { + /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ + *accesible_name = g_strdup_printf (_("%s (%s left (%.0lf%%))"), + device_name, detailed_timestring, percentage); + *details = g_strdup_printf (_("%s (%s left)"), + device_name, short_timestring); + } } } else { - /* TRANSLATORS: %2 is a percentage value. Note: this string is only - * used when we don't have a time value */ - *details = g_strdup_printf (_("%s (%.0lf%%)"), - device_name, percentage); - *short_details = g_strdup_printf (_("(%.0lf%%)"), - percentage); + if (state == UP_DEVICE_STATE_FULLY_CHARGED) + { + *details = g_strdup_printf (_("%s (charged)"), device_name); + *accesible_name = g_strdup (*details); + *short_details = g_strdup (_("(charged)")); + } + else + { + /* TRANSLATORS: %2 is a percentage value. Note: this string is only + * used when we don't have a time value */ + *details = g_strdup_printf (_("%s (%.0lf%%)"), + device_name, percentage); + *accesible_name = g_strdup (*details); + *short_details = g_strdup_printf (_("(%.0lf%%)"), + percentage); + } } } @@ -330,6 +353,7 @@ menu_add_device (GtkMenu *menu, const gchar *device_name; gchar *short_details = NULL; gchar *details = NULL; + gchar *accesible_name = NULL; if (device == NULL) return; @@ -355,7 +379,7 @@ menu_add_device (GtkMenu *menu, device_name = device_kind_to_localised_string (kind); - build_device_time_details (device_name, time, state, percentage, &short_details, &details); + build_device_time_details (device_name, time, state, percentage, &short_details, &details, &accesible_name); /* Create menu item */ item = gtk_image_menu_item_new (); @@ -417,7 +441,6 @@ build_menu (IndicatorPower *self) /* options */ item = gtk_check_menu_item_new_with_label (_("Show Time Remaining")); - g_object_set (item, "draw-as-radio", TRUE, NULL); g_signal_connect (G_OBJECT (item), "toggled", G_CALLBACK (option_toggled_cb), self); gtk_menu_shell_append (GTK_MENU_SHELL (priv->menu), item); @@ -443,11 +466,18 @@ get_primary_device (GVariant *devices) { UpDeviceKind kind; UpDeviceState state; + GVariant *device; + GVariant *primary_device_charging = NULL; + GVariant *primary_device_discharging = NULL; GVariant *primary_device = NULL; + gboolean charging = FALSE; + gboolean discharging = FALSE; gchar *object_path; gchar *device_icon; gdouble percentage; guint64 time; + guint64 min_discharging_time = G_MAXUINT64; + guint64 max_charging_time = 0; gsize n_devices; guint i; @@ -456,8 +486,8 @@ get_primary_device (GVariant *devices) for (i = 0; i < n_devices; i++) { - primary_device = g_variant_get_child_value (devices, i); - g_variant_get (primary_device, + device = g_variant_get_child_value (devices, i); + g_variant_get (device, "(susdut)", &object_path, &kind, @@ -467,53 +497,61 @@ get_primary_device (GVariant *devices) &time); g_debug ("%s: got data from object %s", G_STRFUNC, object_path); + + if (primary_device == NULL && kind == UP_DEVICE_KIND_BATTERY) + primary_device = device; + + if (state == UP_DEVICE_STATE_DISCHARGING) + { + discharging = TRUE; + if (time < min_discharging_time) + { + min_discharging_time = time; + primary_device_discharging = device; + } + } + else if (state == UP_DEVICE_STATE_CHARGING) + { + charging = TRUE; + if (time > max_charging_time) + { + max_charging_time = time; + primary_device_charging = device; + } + } + } + + if (discharging) + { + primary_device = primary_device_discharging; + } + else if (charging) + { + primary_device = primary_device_charging; } return primary_device; } static void -get_devices_cb (GObject *source_object, - GAsyncResult *res, - gpointer user_data) +put_primary_device (IndicatorPower *self, + GVariant *device) { - IndicatorPower *self = INDICATOR_POWER (user_data); IndicatorPowerPrivate *priv = self->priv; UpDeviceKind kind; UpDeviceState state; GIcon *device_gicons; - GVariant *devices_container; - GError *error = NULL; gchar *short_details = NULL; gchar *details = NULL; + gchar *accesible_name = NULL; gchar *device_icon = NULL; gchar *object_path = NULL; gdouble percentage; guint64 time; const gchar *device_name; - gchar *short_timestring = NULL; - gchar *detailed_timestring = NULL; - - devices_container = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); - if (devices_container == NULL) - { - g_printerr ("Error getting devices: %s\n", error->message); - g_error_free (error); - - return; - } - priv->devices = g_variant_get_child_value (devices_container, 0); - - priv->device = get_primary_device (priv->devices); - if (priv->device == NULL) - { - g_printerr ("Error getting primary device"); - - return; - } /* set the icon and text */ - g_variant_get (priv->device, + g_variant_get (device, "(susdut)", &object_path, &kind, @@ -536,23 +574,52 @@ get_devices_cb (GObject *source_object, device_name = device_kind_to_localised_string (kind); /* get the description */ - build_device_time_details (device_name, time, state, percentage, &short_details, &details); + build_device_time_details (device_name, time, state, percentage, &short_details, &details, &accesible_name); gtk_label_set_label (GTK_LABEL (priv->label), short_details); - set_accessible_desc (self, details); - - build_menu (self); + set_accessible_desc (self, accesible_name); g_free (short_details); g_free (details); g_free (device_icon); - g_free (short_timestring); - g_free (detailed_timestring); g_free (object_path); } static void +get_devices_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + IndicatorPower *self = INDICATOR_POWER (user_data); + IndicatorPowerPrivate *priv = self->priv; + GVariant *devices_container; + GError *error = NULL; + + devices_container = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error); + if (devices_container == NULL) + { + g_printerr ("Error getting devices: %s\n", error->message); + g_error_free (error); + + return; + } + priv->devices = g_variant_get_child_value (devices_container, 0); + + priv->device = get_primary_device (priv->devices); + if (priv->device == NULL) + { + g_printerr ("Error getting primary device"); + + return; + } + + put_primary_device (self, priv->device); + + build_menu (self); +} + +static void receive_signal (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, |