Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-power-manager/ChangeLog,v
retrieving revision 1.265
diff -u -r1.265 ChangeLog
--- ChangeLog	17 Jan 2006 20:14:37 -0000	1.265
+++ ChangeLog	17 Jan 2006 23:36:13 -0000
@@ -1,3 +1,10 @@
+2006-01-19  Jaap Haitsma  <jaap@haitsma.org>
+
+	* src/gpm-power.c: Make tooltip more concise
+
+	* src/gpm-common.c: return "Unknown time" if minutes <=0 for
+	get_timestring_from_minutes (). Some minor refactoring.
+
 2005-01-17  Richard Hughes  <richard@hughsie.com>
 
 	* src/gpm-manager.c (gpm_manager_init):
Index: src/gpm-common.c
===================================================================
RCS file: /cvs/gnome/gnome-power-manager/src/gpm-common.c,v
retrieving revision 1.36
diff -u -r1.36 gpm-common.c
--- src/gpm-common.c	11 Jan 2006 19:59:37 -0000	1.36
+++ src/gpm-common.c	17 Jan 2006 23:36:13 -0000
@@ -39,39 +39,36 @@
  *  @param  minutes		Minutes to convert to string
  *  @return			The timestring
  *
- *  @note	minutes == 0 is returned as "Unknown"
+ *  @note	minutes <= 0 is returned as "Unknown time"
  */
 char *
 get_timestring_from_minutes (int minutes)
 {
-	char* timestring = NULL;
 	gint   hours;
 
-	if (minutes == 0) {
-		timestring = g_strdup_printf (_("Unknown"));
-		return timestring;
+	if (minutes <= 0) {
+		return g_strdup_printf (_("Unknown time"));
 	}
 
 	if (minutes < 60) {
-		timestring = g_strdup_printf (ngettext ("%i minute",
-                                                        "%i minutes",
-                                                        minutes), minutes);
-		return timestring;
+		return g_strdup_printf (ngettext ("%i minute",
+                                                   "%i minutes",
+                                                   minutes), minutes);
 	}
 
 	hours = minutes / 60;
 	minutes = minutes % 60;
 
-	if (minutes == 0) 
-		timestring = g_strdup_printf (ngettext (
-				"%i hour",
-				"%i hours",
-				hours), hours);
-	else
+	if (minutes == 0) {
+		return g_strdup_printf (ngettext (
+					"%i hour",
+					"%i hours",
+					hours), hours);
+	} else {
 		/* TRANSLATOR: "%i %s %i %s" are "%i hours %i minutes"
 		 * Swap order with "%2$s %2$i %1$s %1$i if needed */
-		timestring = g_strdup_printf (_("%i %s, %i %s"),
-				hours, ngettext ("hour", "hours", hours),
-				minutes, ngettext ("minute", "minutes", minutes));
-	return timestring;
+		return g_strdup_printf (_("%i %s, %i %s"),
+					hours, ngettext ("hour", "hours", hours),
+					minutes, ngettext ("minute", "minutes", minutes));
+	}
 }
Index: src/gpm-power.c
===================================================================
RCS file: /cvs/gnome/gnome-power-manager/src/gpm-power.c,v
retrieving revision 1.8
diff -u -r1.8 gpm-power.c
--- src/gpm-power.c	17 Jan 2006 18:33:11 -0000	1.8
+++ src/gpm-power.c	17 Jan 2006 23:36:14 -0000
@@ -615,8 +615,7 @@
 			    GString    *summary)
 {
 	BatteryKindCacheEntry *entry;
-	const char            *kind_desc = NULL;
-	const char            *charge_state = NULL;
+	char *timestring;
 
 	entry = battery_kind_cache_find (power, kind);
 
@@ -628,8 +627,6 @@
 		return;
 	}
 
-	kind_desc = kind_for_display (entry->kind);
-
 	/* don't display all the extra stuff for keyboards and mice */
 	if (strcmp (entry->kind, "mouse") == 0
 	    || strcmp (entry->kind, "keyboard") == 0
@@ -637,53 +634,37 @@
 
 		g_string_append_printf (summary,
 					"%s (%i%%)\n",
-					kind_desc,
+					kind_for_display (entry->kind),
 					entry->percentage_charge);
 		return;
 	}
 
-	/* work out chargestate */
-	if (entry->is_charging)
-		charge_state = _("charging");
-	else if (entry->is_discharging)
-		charge_state = _("discharging");
-	else if (! entry->is_charging && !entry->is_discharging)
-		charge_state = _("charged");
-
-	g_string_append_printf (summary,
-				"%s %s (%i%%)",
-				kind_desc,
-				charge_state,
-				entry->percentage_charge);
-
-	/*
-	 * only display time remaining if remaining_time > 120
-	 * and percentage_charge < 99 to cope with some broken
-	 * batteries.
-	 */
-	if (entry->remaining_time > 120 && entry->percentage_charge < 99) {
-		char *timestring;
-
-		/* why add 0.5 ? */
-		timestring = get_timestring_from_minutes ((int)((entry->remaining_time/60)+0.5));
-
-		if (timestring) {
-			if (entry->is_charging) {
-				g_string_append_printf (summary,
-							"\n%s %s",
-							timestring,
-							_("until charged"));
-			} else {
-				g_string_append_printf (summary,
-							"\n%s %s",
-							timestring,
-							_("until empty"));
-			}
-			g_free (timestring);
-		}
+	/* Add 0.5 to do rounding */
+	timestring = get_timestring_from_minutes ((int)((entry->remaining_time/60.0)+0.5));
+
+	if (entry->is_charging) {
+		g_string_append_printf (summary,
+					"%s %s (%i%%)\n",
+					timestring,
+					_("until charged"),
+					entry->percentage_charge);
+	} else if (entry->is_discharging) {
+		g_string_append_printf (summary,
+					"%s (%i%%) %s\n",
+					timestring,
+					entry->percentage_charge,
+					_("remaining"));
+	} else if (!entry->is_discharging && !entry->is_charging && entry->percentage_charge==100){
+		g_string_append_printf (summary,
+					"%s %s\n",
+					kind_for_display (entry->kind),
+					_("fully charged"));
+	} else {
+		g_warning ("power_get_summary_for_kind (): in an undefined state we are not charging or "
+			   "discharging and the batteries are also not fully loaded");
 	}
-	g_string_append (summary, "\n");
 
+	g_free (timestring);
 }
 
 gboolean
