From 3c2e7c88bd24441d87a52e702e2e1e985f9abcef Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 22 Aug 2013 18:36:37 -0500 Subject: add schema changes from hloeung's branch --- src/service.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/service.c b/src/service.c index b59bce3..4aaca3f 100644 --- a/src/service.c +++ b/src/service.c @@ -33,6 +33,7 @@ #define SETTINGS_SHOW_TIME_S "show-time" #define SETTINGS_ICON_POLICY_S "icon-policy" +#define SETTINGS_SHOW_PERCENTAGE_S "show-percentage" G_DEFINE_TYPE (IndicatorPowerService, indicator_power_service, -- cgit v1.2.3 From c15ff1e02ea0a7ae1f68a66a31dc6ce7d8955575 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 22 Aug 2013 23:51:20 -0500 Subject: add show-percentage feature, basing off Haw Loeung's patch. --- src/device.c | 173 +++++++++++++++++++++++++++++++++++++++------------------- src/device.h | 31 ++++++----- src/service.c | 145 +++++++++++++++++++++++------------------------- 3 files changed, 201 insertions(+), 148 deletions(-) (limited to 'src') diff --git a/src/device.c b/src/device.c index 02c9e65..69336eb 100644 --- a/src/device.c +++ b/src/device.c @@ -451,8 +451,8 @@ indicator_power_device_get_gicon (const IndicatorPowerDevice * device) static void get_timestring (guint64 time_secs, - gchar **short_timestring, - gchar **detailed_timestring) + gchar **readable_timestring, + gchar **accessible_timestring) { gint hours; gint minutes; @@ -462,16 +462,16 @@ get_timestring (guint64 time_secs, if (minutes == 0) { - *short_timestring = g_strdup (_("Unknown time")); - *detailed_timestring = g_strdup (_("Unknown time")); + *readable_timestring = g_strdup (_("Unknown time")); + *accessible_timestring = g_strdup (_("Unknown time")); return; } if (minutes < 60) { - *short_timestring = g_strdup_printf ("0:%.2i", minutes); - *detailed_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%i minute", + *readable_timestring = g_strdup_printf ("0:%.2i", minutes); + *accessible_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%i minute", "%i minutes", minutes), minutes); return; @@ -480,11 +480,11 @@ get_timestring (guint64 time_secs, hours = minutes / 60; minutes = minutes % 60; - *short_timestring = g_strdup_printf ("%i:%.2i", hours, minutes); + *readable_timestring = g_strdup_printf ("%i:%.2i", hours, minutes); if (minutes == 0) { - *detailed_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, + *accessible_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%i hour", "%i hours", hours), hours); @@ -493,7 +493,7 @@ get_timestring (guint64 time_secs, { /* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes" * Swap order with "%2$s %2$i %1$s %1$i if needed */ - *detailed_timestring = g_strdup_printf (_("%i %s %i %s"), + *accessible_timestring = g_strdup_printf (_("%i %s %i %s"), hours, g_dngettext (GETTEXT_PACKAGE, "hour", "hours", hours), minutes, g_dngettext (GETTEXT_PACKAGE, "minute", "minutes", minutes)); } @@ -561,86 +561,145 @@ device_kind_to_localised_string (UpDeviceKind kind) return text; } -void +static char * +join_strings (const char * name, const char * time, const char * percent) +{ + char * str; + const gboolean have_name = name && *name; + const gboolean have_time = time && *time; + const gboolean have_percent = percent && *percent; + + if (have_name && have_time && have_percent) + str = g_strdup_printf (_("%s (%s, %s)"), name, time, percent); + else if (have_name && have_time) + str = g_strdup_printf (_("%s (%s)"), name, time); + else if (have_name && have_percent) + str = g_strdup_printf (_("%s (%s)"), name, percent); + else if (have_name) + str = g_strdup (name); + else if (have_time && have_percent) + str = g_strdup_printf (_("(%s, %s)"), time, percent); + else if (have_time) + str = g_strdup_printf (_("(%s)"), time); + else if (have_percent) + str = g_strdup_printf (_("(%s)"), percent); + else + str = g_strdup (""); + + return str; +} + +static void indicator_power_device_get_time_details (const IndicatorPowerDevice * device, - gchar ** short_details, - gchar ** details, - gchar ** accessible_name) + gboolean show_time_in_header, + gboolean show_percentage_in_header, + gchar ** header, + gchar ** label, + gchar ** a11y) { if (!INDICATOR_IS_POWER_DEVICE(device)) { - *short_details = NULL; - *details = NULL; - *accessible_name = NULL; + if (a11y != NULL) *a11y = NULL; + if (label != NULL) *label = NULL; + if (header != NULL) *header = NULL; g_warning ("%s: %p is not an IndicatorPowerDevice", G_STRFUNC, device); return; } const time_t time = indicator_power_device_get_time (device); const UpDeviceState state = indicator_power_device_get_state (device); - const gdouble percentage = indicator_power_device_get_percentage (device); const UpDeviceKind kind = indicator_power_device_get_kind (device); const gchar * device_name = device_kind_to_localised_string (kind); + const gdouble percentage = indicator_power_device_get_percentage (device); + char pctstr[32] = { '\0' }; + g_snprintf (pctstr, sizeof(pctstr), "%.0lf%%", percentage); + + GString * terse_time = g_string_new (NULL); + GString * verbose_time = g_string_new (NULL); + GString * accessible_time = g_string_new (NULL); if (time > 0) { - gchar *short_timestring = NULL; - gchar *detailed_timestring = NULL; - - get_timestring (time, - &short_timestring, - &detailed_timestring); + char * readable_timestr = NULL; + char * accessible_timestr = NULL; + get_timestring (time, &readable_timestr, &accessible_timestr); if (state == UP_DEVICE_STATE_CHARGING) { - /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ - *accessible_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); - *short_details = g_strdup_printf ("(%s)", short_timestring); + g_string_assign (terse_time, readable_timestr); + g_string_printf (verbose_time, _("%s to charge"), readable_timestr); + g_string_printf (accessible_time, _("%s to charge"), accessible_timestr); } - else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time > (60*60*12))) + else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time < (60*60*12))) { - *accessible_name = g_strdup_printf (_("%s"), device_name); - *details = g_strdup_printf (_("%s"), device_name); - *short_details = g_strdup (short_timestring); - } - else - { - /* TRANSLATORS: %2 is a time string, e.g. "1 hour 5 minutes" */ - *accessible_name = g_strdup_printf (_("%s (%s left (%.0lf%%))"), device_name, detailed_timestring, percentage); - *details = g_strdup_printf (_("%s (%s left)"), device_name, short_timestring); - *short_details = g_strdup (short_timestring); + g_string_assign (terse_time, readable_timestr); + g_string_printf (verbose_time, _("%s left"), readable_timestr); + g_string_printf (accessible_time, _("%s left"), accessible_timestr); } - g_free (short_timestring); - g_free (detailed_timestring); + g_free (readable_timestr); + g_free (accessible_timestr); } else if (state == UP_DEVICE_STATE_FULLY_CHARGED) { - *details = g_strdup_printf (_("%s (charged)"), device_name); - *accessible_name = g_strdup (*details); - *short_details = g_strdup (""); + g_string_assign (verbose_time, _("charged")); + g_string_assign (accessible_time, _("charged")); } else if (percentage > 0) { - /* 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); - *accessible_name = g_strdup (*details); - *short_details = g_strdup_printf (_("(%.0lf%%)"), percentage); - } - else if (kind == UP_DEVICE_KIND_LINE_POWER) - { - *details = g_strdup (device_name); - *accessible_name = g_strdup (device_name); - *short_details = g_strdup (""); + g_string_assign (terse_time, _("estimating…")); + g_string_assign (verbose_time, _("estimating…")); + g_string_assign (accessible_time, _("estimating…")); } else { - *details = g_strdup_printf (_("%s (not present)"), device_name); - *accessible_name = g_strdup (*details); - *short_details = g_strdup (_("(not present)")); + *pctstr = '\0'; + + if (kind != UP_DEVICE_KIND_LINE_POWER) + { + g_string_assign (verbose_time, _("not present")); + g_string_assign (accessible_time, _("not present")); + } } + + if (header != NULL) + *header = join_strings (NULL, + show_time_in_header ? terse_time->str : "", + show_percentage_in_header ? pctstr : ""); + + if (label != NULL) + *label = join_strings (device_name, + verbose_time->str, + NULL); + + if (a11y != NULL) + *a11y = join_strings (device_name, + accessible_time->str, + pctstr); + + g_string_free (terse_time, TRUE); + g_string_free (verbose_time, TRUE); + g_string_free (accessible_time, TRUE); +} + +gchar * +indicator_power_device_get_label (const IndicatorPowerDevice * device) +{ + gchar * label = NULL; + indicator_power_device_get_time_details (device, FALSE, FALSE, + NULL, &label, NULL); + return label; +} + +void +indicator_power_device_get_header (const IndicatorPowerDevice * device, + gboolean show_time, + gboolean show_percentage, + gchar ** header, + gchar ** a11y) +{ + indicator_power_device_get_time_details (device, show_time, show_percentage, + header, NULL, a11y); } /*** diff --git a/src/device.h b/src/device.h index ffbb5da..1f395a1 100644 --- a/src/device.h +++ b/src/device.h @@ -116,21 +116,22 @@ IndicatorPowerDevice* indicator_power_device_new (const gchar * object_path, IndicatorPowerDevice* indicator_power_device_new_from_variant (GVariant * variant); -UpDeviceKind indicator_power_device_get_kind (const IndicatorPowerDevice * device); -UpDeviceState indicator_power_device_get_state (const IndicatorPowerDevice * device); -const gchar * indicator_power_device_get_object_path (const IndicatorPowerDevice * device); -gdouble indicator_power_device_get_percentage (const IndicatorPowerDevice * device); -time_t indicator_power_device_get_time (const IndicatorPowerDevice * device); - -GStrv indicator_power_device_get_icon_names (const IndicatorPowerDevice * device); -GIcon * indicator_power_device_get_gicon (const IndicatorPowerDevice * device); - -void indicator_power_device_get_time_details (const IndicatorPowerDevice * device, - gchar ** short_details, - gchar ** details, - gchar ** accessible_name); - - +UpDeviceKind indicator_power_device_get_kind (const IndicatorPowerDevice * device); +UpDeviceState indicator_power_device_get_state (const IndicatorPowerDevice * device); +const gchar * indicator_power_device_get_object_path (const IndicatorPowerDevice * device); +gdouble indicator_power_device_get_percentage (const IndicatorPowerDevice * device); +time_t indicator_power_device_get_time (const IndicatorPowerDevice * device); + +GStrv indicator_power_device_get_icon_names (const IndicatorPowerDevice * device); +GIcon * indicator_power_device_get_gicon (const IndicatorPowerDevice * device); + +gchar * indicator_power_device_get_label (const IndicatorPowerDevice * device); + +void indicator_power_device_get_header (const IndicatorPowerDevice * device, + gboolean show_time, + gboolean show_percentage, + gchar ** header, + gchar ** a11y); G_END_DECLS diff --git a/src/service.c b/src/service.c index 4aaca3f..81a70d5 100644 --- a/src/service.c +++ b/src/service.c @@ -113,6 +113,7 @@ struct _IndicatorPowerServicePrivate GSimpleActionGroup * actions; GSimpleAction * header_action; GSimpleAction * show_time_action; + GSimpleAction * show_percentage_action; GSimpleAction * battery_level_action; GSimpleAction * brightness_action; @@ -319,16 +320,13 @@ create_header_state (IndicatorPowerService * self) if (p->primary_device != NULL) { - gchar * details; - - indicator_power_device_get_time_details (p->primary_device, - &label, - &details, - &a11y); + indicator_power_device_get_header (p->primary_device, + g_settings_get_boolean (p->settings, SETTINGS_SHOW_TIME_S), + g_settings_get_boolean (p->settings, SETTINGS_SHOW_PERCENTAGE_S), + &label, + &a11y); icon = indicator_power_device_get_gicon (p->primary_device); - - g_free (details); } g_variant_builder_init (&b, G_VARIANT_TYPE("a{sv}")); @@ -338,9 +336,7 @@ create_header_state (IndicatorPowerService * self) if (label != NULL) { - if (g_settings_get_boolean (p->settings, SETTINGS_SHOW_TIME_S)) - g_variant_builder_add (&b, "{sv}", "label", - g_variant_new_string (label)); + g_variant_builder_add (&b, "{sv}", "label", g_variant_new_string (label)); g_free (label); } @@ -377,33 +373,24 @@ append_device_to_menu (GMenu * menu, const IndicatorPowerDevice * device) if (kind != UP_DEVICE_KIND_LINE_POWER) { - char * brief; + GIcon * icon; char * label; - char * a11y; GMenuItem * menu_item; - GIcon * icon = indicator_power_device_get_gicon (device); - - indicator_power_device_get_time_details (device, - &brief, - &label, - &a11y); + icon = indicator_power_device_get_gicon (device); + label = indicator_power_device_get_label (device); menu_item = g_menu_item_new (label, "indicator.activate-statistics"); if (icon != NULL) - { - g_menu_item_set_attribute_value (menu_item, - G_MENU_ATTRIBUTE_ICON, - g_icon_serialize (icon)); - } + g_menu_item_set_attribute_value (menu_item, + G_MENU_ATTRIBUTE_ICON, + g_icon_serialize (icon)); g_menu_append_item (menu, menu_item); g_object_unref (menu_item); g_clear_object (&icon); - g_free (brief); g_free (label); - g_free (a11y); } } @@ -521,6 +508,10 @@ create_desktop_settings_section (IndicatorPowerService * self G_GNUC_UNUSED) _("Show Time in Menu Bar"), "indicator.show-time"); + g_menu_append (menu, + _("Show Percentage in Menu Bar"), + "indicator.show-percentage"); + g_menu_append (menu, _("Power Settings…"), "indicator.activate-settings"); @@ -707,61 +698,43 @@ on_statistics_activated (GSimpleAction * a G_GNUC_UNUSED, execute_command ("gnome-power-statistics"); } -/* FIXME: use a GBinding to tie the gaction's state and the GSetting together? */ +/*** +**** +***/ +/* toggles the state */ static void -set_show_time_flag (IndicatorPowerService * self, gboolean b) +on_toggle_action_activated (GSimpleAction * simple, + GVariant * parameter G_GNUC_UNUSED, + gpointer unused G_GNUC_UNUSED) { - GVariant * v; - priv_t * p = self->priv; - - /* update the settings */ - if (b != g_settings_get_boolean (p->settings, SETTINGS_SHOW_TIME_S)) - g_settings_set_boolean (p->settings, SETTINGS_SHOW_TIME_S, b); - - /* update the action state */ - v = g_action_get_state (G_ACTION(p->show_time_action)); - if (b != g_variant_get_boolean (v)) - g_simple_action_set_state (p->show_time_action, g_variant_new_boolean (b)); + GVariant * v = g_action_get_state (G_ACTION (simple)); + gboolean flag = g_variant_get_boolean (v); + g_simple_action_set_state (simple, g_variant_new_boolean (!flag)); g_variant_unref (v); - - rebuild_header_now (self); -} -static void -on_show_time_setting_changed (GSettings * settings, gchar * key, gpointer gself) -{ - set_show_time_flag (INDICATOR_POWER_SERVICE(gself), - g_settings_get_boolean (settings, key)); } -static void -on_show_time_action_state_changed (GAction * action, - GParamSpec * pspec G_GNUC_UNUSED, - gpointer gself) +static gboolean +settings_to_action_state (GValue * value, + GVariant * variant, + gpointer user_data G_GNUC_UNUSED) { - GVariant * v = g_action_get_state (action); - set_show_time_flag (INDICATOR_POWER_SERVICE(gself), - g_variant_get_boolean (v)); - g_variant_unref (v); + g_value_set_variant (value, variant); + return TRUE; } -/* toggles the state */ -static void -on_show_time_action_activated (GSimpleAction * simple, - GVariant * parameter G_GNUC_UNUSED, - gpointer unused G_GNUC_UNUSED) +static GVariant * +action_state_to_settings (const GValue * value, + const GVariantType * expected_type G_GNUC_UNUSED, + gpointer user_data G_GNUC_UNUSED) { - GVariant * v = g_action_get_state (G_ACTION (simple)); - gboolean flag = g_variant_get_boolean (v); - g_simple_action_set_state (simple, g_variant_new_boolean (!flag)); - g_variant_unref (v); + return g_value_dup_variant (value); } static void init_gactions (IndicatorPowerService * self) { GSimpleAction * a; - gboolean show_time; priv_t * p = self->priv; GActionEntry entries[] = { @@ -794,17 +767,31 @@ init_gactions (IndicatorPowerService * self) p->brightness_action = a; /* add the show-time action */ - show_time = g_settings_get_boolean (p->settings, SETTINGS_SHOW_TIME_S); - a = g_simple_action_new_stateful ("show-time", - NULL, - g_variant_new_boolean(show_time)); - g_signal_connect (a, "activate", - G_CALLBACK(on_show_time_action_activated), self); - g_signal_connect (a, "notify", - G_CALLBACK(on_show_time_action_state_changed), self); + a = g_simple_action_new ("show-time", NULL); + g_settings_bind_with_mapping (p->settings, SETTINGS_SHOW_TIME_S, + a, "state", + G_SETTINGS_BIND_DEFAULT, + settings_to_action_state, + action_state_to_settings, + NULL, NULL); + g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self); + g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self); g_simple_action_group_insert (p->actions, G_ACTION(a)); p->show_time_action = a; + /* add the show-percentage action */ + a = g_simple_action_new ("show-percentage", NULL); + g_settings_bind_with_mapping (p->settings, SETTINGS_SHOW_PERCENTAGE_S, + a, "state", + G_SETTINGS_BIND_DEFAULT, + settings_to_action_state, + action_state_to_settings, + NULL, NULL); + g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self); + g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self); + g_simple_action_group_insert (p->actions, G_ACTION(a)); + p->show_percentage_action = a; + rebuild_header_now (self); } @@ -1015,10 +1002,16 @@ my_dispose (GObject * o) g_clear_object (&p->show_time_action); } + if (p->show_percentage_action != NULL) + { + g_signal_handlers_disconnect_by_data (p->show_percentage_action, self); + + g_clear_object (&p->show_percentage_action); + } + g_clear_object (&p->brightness_action); g_clear_object (&p->battery_level_action); g_clear_object (&p->header_action); - g_clear_object (&p->show_time_action); g_clear_object (&p->actions); g_clear_object (&p->conn); @@ -1052,8 +1045,8 @@ indicator_power_service_init (IndicatorPowerService * self) g_signal_connect_swapped (p->settings, "changed::" SETTINGS_ICON_POLICY_S, G_CALLBACK(rebuild_header_now), self); - g_signal_connect (p->settings, "changed::" SETTINGS_SHOW_TIME_S, - G_CALLBACK(on_show_time_setting_changed), self); + //g_signal_connect (p->settings, "changed::" SETTINGS_SHOW_TIME_S, + // G_CALLBACK(on_show_time_setting_changed), self); p->own_id = g_bus_own_name (G_BUS_TYPE_SESSION, BUS_NAME, -- cgit v1.2.3 From 65b6f061fe4f003eae25d423bbf2f3aa8aca1471 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 22 Aug 2013 23:52:27 -0500 Subject: don't use deprecated GSimpleActionGroup APIs --- src/service.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/service.c b/src/service.c index 81a70d5..8269448 100644 --- a/src/service.c +++ b/src/service.c @@ -751,18 +751,18 @@ init_gactions (IndicatorPowerService * self) /* add the header action */ a = g_simple_action_new_stateful ("_header", NULL, create_header_state (self)); - g_simple_action_group_insert (p->actions, G_ACTION(a)); + g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); p->header_action = a; /* add the power-level action */ a = g_simple_action_new_stateful ("battery-level", NULL, g_variant_new_uint32(0)); g_simple_action_set_enabled (a, FALSE); - g_simple_action_group_insert (p->actions, G_ACTION(a)); + g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); p->battery_level_action = a; /* add the brightness action */ a = g_simple_action_new_stateful ("brightness", NULL, action_state_for_brightness (self)); - g_simple_action_group_insert (p->actions, G_ACTION(a)); + g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); g_signal_connect (a, "change-state", G_CALLBACK(on_brightness_change_requested), self); p->brightness_action = a; @@ -776,7 +776,7 @@ init_gactions (IndicatorPowerService * self) NULL, NULL); g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self); g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self); - g_simple_action_group_insert (p->actions, G_ACTION(a)); + g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); p->show_time_action = a; /* add the show-percentage action */ @@ -789,7 +789,7 @@ init_gactions (IndicatorPowerService * self) NULL, NULL); g_signal_connect (a, "activate", G_CALLBACK(on_toggle_action_activated), self); g_signal_connect_swapped (a, "notify", G_CALLBACK(rebuild_header_now), self); - g_simple_action_group_insert (p->actions, G_ACTION(a)); + g_action_map_add_action (G_ACTION_MAP(p->actions), G_ACTION(a)); p->show_percentage_action = a; rebuild_header_now (self); -- cgit v1.2.3 From cfda45be70c9d7877d23f3bfdc70672be1fa71f2 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 22 Aug 2013 23:58:00 -0500 Subject: copyediting: remove trailing spaces in source code --- src/device-provider.c | 2 +- src/device.c | 2 +- src/service.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/device-provider.c b/src/device-provider.c index 5ccf588..81a8eec 100644 --- a/src/device-provider.c +++ b/src/device-provider.c @@ -54,7 +54,7 @@ indicator_power_device_provider_default_init (IndicatorPowerDeviceProviderInterf * An easy way to free the list properly in one step is as follows: * * g_slist_free_full (list, (GDestroyNotify)g_object_unref); - * + * * Return value: (element-type IndicatorPowerDevice) * (transfer full): * list of devices diff --git a/src/device.c b/src/device.c index 69336eb..4777675 100644 --- a/src/device.c +++ b/src/device.c @@ -484,7 +484,7 @@ get_timestring (guint64 time_secs, if (minutes == 0) { - *accessible_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, + *accessible_timestring = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "%i hour", "%i hours", hours), hours); diff --git a/src/service.c b/src/service.c index 8269448..9484e65 100644 --- a/src/service.c +++ b/src/service.c @@ -937,7 +937,7 @@ my_get_property (GObject * o, { IndicatorPowerService * self = INDICATOR_POWER_SERVICE (o); priv_t * p = self->priv; - + switch (property_id) { case PROP_DEVICE_PROVIDER: -- cgit v1.2.3 From b84432b9493a1b0680a93c9199d6cbbd938e95b4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 23 Aug 2013 08:57:22 -0500 Subject: copyediting: more descriptive comments when building label/header/a11y text --- src/device.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/device.c b/src/device.c index 4777675..26b4c04 100644 --- a/src/device.c +++ b/src/device.c @@ -449,6 +449,7 @@ indicator_power_device_get_gicon (const IndicatorPowerDevice * device) **** ***/ +/* Format time remaining for reading ("H:MM") and speech ("H hours, MM minutes") */ static void get_timestring (guint64 time_secs, gchar **readable_timestring, @@ -590,12 +591,12 @@ join_strings (const char * name, const char * time, const char * percent) } static void -indicator_power_device_get_time_details (const IndicatorPowerDevice * device, - gboolean show_time_in_header, - gboolean show_percentage_in_header, - gchar ** header, - gchar ** label, - gchar ** a11y) +indicator_power_device_get_text (const IndicatorPowerDevice * device, + gboolean show_time_in_header, + gboolean show_percentage_in_header, + gchar ** header, + gchar ** label, + gchar ** a11y) { if (!INDICATOR_IS_POWER_DEVICE(device)) { @@ -630,12 +631,16 @@ indicator_power_device_get_time_details (const IndicatorPowerDevice * device, g_string_printf (verbose_time, _("%s to charge"), readable_timestr); g_string_printf (accessible_time, _("%s to charge"), accessible_timestr); } - else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time < (60*60*12))) + else if ((state == UP_DEVICE_STATE_DISCHARGING) && (time <= (60*60*12))) { g_string_assign (terse_time, readable_timestr); g_string_printf (verbose_time, _("%s left"), readable_timestr); g_string_printf (accessible_time, _("%s left"), accessible_timestr); } + else + { + /* if there's more than 12 hours remaining, we don't show it */ + } g_free (readable_timestr); g_free (accessible_timestr); @@ -686,8 +691,8 @@ gchar * indicator_power_device_get_label (const IndicatorPowerDevice * device) { gchar * label = NULL; - indicator_power_device_get_time_details (device, FALSE, FALSE, - NULL, &label, NULL); + indicator_power_device_get_text (device, FALSE, FALSE, + NULL, &label, NULL); return label; } @@ -698,8 +703,8 @@ indicator_power_device_get_header (const IndicatorPowerDevice * device, gchar ** header, gchar ** a11y) { - indicator_power_device_get_time_details (device, show_time, show_percentage, - header, NULL, a11y); + indicator_power_device_get_text (device, show_time, show_percentage, + header, NULL, a11y); } /*** -- cgit v1.2.3 From ad28ae2fdfa5e803031dc5d41a83f033c924f4e9 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Fri, 23 Aug 2013 08:57:47 -0500 Subject: copyediting: some newly-dead code should have been removed instead of just commented out --- src/service.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/service.c b/src/service.c index 9484e65..1976332 100644 --- a/src/service.c +++ b/src/service.c @@ -1045,8 +1045,6 @@ indicator_power_service_init (IndicatorPowerService * self) g_signal_connect_swapped (p->settings, "changed::" SETTINGS_ICON_POLICY_S, G_CALLBACK(rebuild_header_now), self); - //g_signal_connect (p->settings, "changed::" SETTINGS_SHOW_TIME_S, - // G_CALLBACK(on_show_time_setting_changed), self); p->own_id = g_bus_own_name (G_BUS_TYPE_SESSION, BUS_NAME, -- cgit v1.2.3