Skip to content

Instantly share code, notes, and snippets.

@drdaxxy
Created September 9, 2013 02:37
Show Gist options
  • Save drdaxxy/6490873 to your computer and use it in GitHub Desktop.
Save drdaxxy/6490873 to your computer and use it in GitHub Desktop.
Quick hack for Ubuntu 12.04's https://launchpad.net/indicator-power showing remaining percentage of battery charge instead of time. This is already implemented in newer versions.
diff -Naur a/data/com.canonical.indicator.power.gschema.xml.in b/data/com.canonical.indicator.power.gschema.xml.in
--- a/data/com.canonical.indicator.power.gschema.xml.in 2012-04-11 16:58:56.000000000 +0200
+++ b/data/com.canonical.indicator.power.gschema.xml.in 2013-09-09 04:29:40.921738433 +0200
@@ -5,10 +5,10 @@
<value nick="never" value="2" />
</enum>
<schema gettext-domain="@GETTEXT_PACKAGE@" id="com.canonical.indicator.power" path="/com/canonical/indicator/power/">
- <key name="show-time" type="b">
+ <key name="show-percentage" type="b">
<default>false</default>
- <_summary>Show time in Menu Bar</_summary>
- <_description>Whether or not to show the time in the menu bar.</_description>
+ <_summary>Show percentage in Menu Bar</_summary>
+ <_description>Whether or not to show the percentage in the menu bar.</_description>
</key>
<key enum="icon-policy-enum" name="icon-policy">
<default>"present"</default>
diff -Naur a/src/indicator-power.c b/src/indicator-power.c
--- a/src/indicator-power.c 2012-04-11 16:58:56.000000000 +0200
+++ b/src/indicator-power.c 2013-09-09 04:29:33.009602231 +0200
@@ -339,6 +339,15 @@
gchar *short_timestring = NULL;
gchar *detailed_timestring = NULL;
+ if (percentage > 0)
+ {
+ *short_details = g_strdup_printf (_("(%.0lf%%)"), percentage);
+ }
+ else
+ {
+ *short_details = g_strdup (_("(not present)"));
+ }
+
if (time > 0)
{
get_timestring (time,
@@ -352,11 +361,9 @@
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);
}
else if (state == UP_DEVICE_STATE_DISCHARGING)
{
- *short_details = g_strdup_printf ("%s", short_timestring);
if (time > 43200) /* 12 hours */
{
@@ -382,7 +389,6 @@
{
*details = g_strdup_printf (_("%s (charged)"), device_name);
*accessible_name = g_strdup (*details);
- *short_details = g_strdup ("");
}
else if (percentage > 0)
{
@@ -391,14 +397,11 @@
*details = g_strdup_printf (_("%s (%.0lf%%)"),
device_name, percentage);
*accessible_name = g_strdup (*details);
- *short_details = g_strdup_printf (_("(%.0lf%%)"),
- percentage);
}
else
{
*details = g_strdup_printf (_("%s (not present)"), device_name);
*accessible_name = g_strdup (*details);
- *short_details = g_strdup (_("(not present)"));
}
}
}
@@ -671,9 +674,9 @@
}
/* options */
- item = gtk_check_menu_item_new_with_label (_("Show Time in Menu Bar"));
+ item = gtk_check_menu_item_new_with_label (_("Show Percentage in Menu Bar"));
g_signal_connect (item, "toggled", G_CALLBACK(option_toggled_cb), self);
- g_settings_bind (self->settings, "show-time", item, "active", G_SETTINGS_BIND_DEFAULT);
+ g_settings_bind (self->settings, "show-percentage", item, "active", G_SETTINGS_BIND_DEFAULT);
gtk_menu_shell_append (GTK_MENU_SHELL (self->menu), item);
/* preferences */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment