2004-08-08  Danilo Šegan  <dsegan@gmx.net>

	Fix bug #149586.
	
	* battstat_applet.c (get_remaining): Add batstatus and remaining
	parameters.
	(pixmap_timeout, change_orient): Adjust calls to get_remaining().
Index: battstat/battstat_applet.c
===================================================================
RCS file: /cvs/gnome/gnome-applets/battstat/battstat_applet.c,v
retrieving revision 1.78
diff -u -r1.78 battstat_applet.c
--- battstat/battstat_applet.c	7 Aug 2004 16:16:56 -0000	1.78
+++ battstat/battstat_applet.c	8 Aug 2004 10:46:00 -0000
@@ -349,7 +349,7 @@
 
 /* } */
 
-static char *get_remaining (int time)
+static char *get_remaining (int time, int batstatus, int remaining)
 {
 	int hours = time / 60;
 	int mins  = time % 60;
@@ -362,10 +362,16 @@
 	
 	if (time == -1)
 		/* Translation Note: as in "No time remaining" or "No time till charged" */
-		return g_strdup_printf(_("No time"));
+		if (remaining)
+			return g_strdup_printf(_("No time (%d%%) remaining."), batstatus);
+		else
+			return g_strdup_printf(_("No time (%d%%) till charged."), batstatus);
 	else if (time < 0)
 		/* Translation Note: as in "Unknown time remaining" or "Unknown time till charged" */
-		return g_strdup_printf(_("Unknown time"));
+		if (remaining)
+			return g_strdup_printf(_("Unknown time (%d%%) remaining."), batstatus);
+		else
+			return g_strdup_printf(_("Unknown time (%d%%) till charged."), batstatus);
 	else
 		if (hours == 0)
 		{
@@ -383,8 +389,8 @@
 			/* Translation note:
 			 * The %s:s are the "%i hour" and "%i minute" messages translated elsewhere respectively.
 			 * Swap the order with "%2$s %1$s" if needed. */
-			return_string = g_strdup_printf(_("%s %s"),
-					hours_string, mins_string);
+			return_string = g_strdup_printf((remaining)? _("%s %s (%d%%) remaining.") : _("%s %s (%d%%) till charged."),
+							hours_string, mins_string, batstatus);
 			g_free (hours_string);
 			g_free (mins_string);
 			return return_string;
@@ -408,6 +414,7 @@
   gchar *new_label;
   gchar *new_string;
   gchar *rem_time = NULL;
+  gchar *chg_time = NULL;
   GtkWidget *hbox, *image, *label, *dialog;
   GdkPixbuf *pixbuf;
   
@@ -505,15 +512,13 @@
       if(battery->lowbattnotification) {
 	 gchar *new_label2;
 #ifdef __FreeBSD__
-	 new_string = get_remaining (apminfo.ai_batt_time);
+	 new_string = get_remaining (apminfo.ai_batt_time, batt_life, 1);
 #else
-	 new_string = get_remaining (apminfo.battery_time);
+	 new_string = get_remaining (apminfo.battery_time, batt_life, 1);
 #endif
 	 /* Translation note:
 	  * The %s will be replaced with the "1 hour 34 minutes" or "Unknown time" messages translated elsewhere. */
-	 new_label2 = g_strdup_printf (
-			 _("%s (%d%%) remaining. To avoid losing work please power off, suspend or plug your laptop in."),
-			 new_string, batt_life);
+	 new_label2 = g_strconcat ( new_string, _("To avoid losing work please power off, suspend or plug your laptop in."), NULL);
 	 new_label = g_strdup_printf (
 			 "<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s",
 			 _("Your battery is running low"),
@@ -642,18 +647,16 @@
       if(!battery->showbattery && !battery->showpercent) {
 	 gchar *new_string;
 #ifdef __FreeBSD__
-	          new_string = get_remaining (apminfo.ai_batt_time);
+		new_string = get_remaining (apminfo.ai_batt_time, batt_life, 0);
 #else
-		  new_string = get_remaining (apminfo.battery_time);
+		new_string = get_remaining (apminfo.battery_time, batt_life, 0);
 #endif
 	 if(acline_status == 0) {
 		/* Translation note: %s is time in words (translated elsewhere) */
-		new_label = g_strdup_printf (_("System is running on battery power\n%s (%d%%) remaining"),
-		     new_string, batt_life);
+		new_label = g_strconcat (_("System is running on battery power\n"), new_string, NULL );
 	 } else {
 		/* Translation note: %s is time in words (translated elsewhere) */
-		new_label = g_strdup_printf (_("System is running on AC power\n%s (%d%%) till charged"),
-		     new_string, batt_life);
+		new_label = g_strconcat (_("System is running on AC power\n"), new_string, NULL );
 	 }
 	 g_free (new_string);
       } else {
@@ -796,12 +799,14 @@
       
       if (batt_state != 3)
 #ifdef __FreeBSD__
-	      rem_time = get_remaining(apminfo.ai_batt_time);
+	      rem_time = get_remaining(apminfo.ai_batt_time, batt_life, 1);
+	      chg_time = get_remaining(apminfo.ai_batt_time, batt_life, 0);
 #else
-	      rem_time = get_remaining(apminfo.battery_time);
+	      rem_time = get_remaining(apminfo.battery_time, batt_life, 1);
+	      chg_time = get_remaining(apminfo.battery_time, batt_life, 0);
 #endif
       else
-	      rem_time = g_strdup(_(status[batt_state]));
+	      rem_time = g_strdup(_(status[batt_state])); // this might need to be changed as well?
       
       if (battery->showstatus == 0) {
 	 if (batterypresent) {
@@ -809,14 +814,12 @@
 			/* This string will display as a tooltip over the battery frame
 			 when the computer is using battery power.
 			 Translation note: %s is time in words (translated elsewhere) */
-		new_string = g_strdup_printf (_("System is running on battery power. %s (%d%%) remaining."),
-			rem_time, batt_life);
+			new_string = g_strconcat (_("System is running on battery power."), rem_time, NULL );
 	    } else {
 			/* This string will display as a tooltip over the battery frame
 			 when the computer is using AC power.
 		         Translation note: %s is time in words (translated elsewhere) */
-		new_string = g_strdup_printf (_("System is running on AC power. %s (%d%%) till charged."),
-			rem_time, batt_life);
+			new_string = g_strconcat (_("System is running on AC power."), chg_time, NULL );
 	    }
 	 } else {
 	    if(acline_status == 0) {
@@ -838,8 +841,7 @@
 		     a battery present. %d will hold the current charge and %s will
 		     contains a string of the time remaining
 		     Translation note: %s is time in words (translated elsewhere) */
-		new_string = g_strdup_printf ((_("%s (%d%%) remaining")),
-		    rem_time, batt_life);
+		new_string = g_strdup(rem_time);
 	 } else {
 		     /* Displayed as a tooltip over the battery meter when no
 		      battery is present. */
@@ -848,6 +850,7 @@
       }
       
       g_free (rem_time);
+      g_free (chg_time);
       
       gtk_tooltips_set_tip(battery->progress_tip,
 			   battery->eventbattery,
@@ -1109,7 +1112,8 @@
    guint acline_status;
    guint batt_state;
    guint batt_life;
-   gchar *time_string;
+   gchar *rem_string;
+   gchar *chg_string;
    gchar *status[]={
       /* The following four messages will be displayed as tooltips over
        the battery meter.  
@@ -1129,20 +1133,23 @@
    apm_readinfo(PANEL_APPLET (applet), battstat);
 #ifdef __FreeBSD__
    acline_status = apminfo.ai_acline ? 1 : 0;
-   time_string = get_remaining (apminfo.ai_batt_time);
    batt_life = apminfo.ai_batt_life;
+   rem_string = get_remaining (apminfo.ai_batt_time, batt_life, 1);
+   chg_string = get_remaining (apminfo.ai_batt_time, batt_life, 0);
 #elif defined(__NetBSD__) || defined(__OpenBSD__)
    acline_status = apminfo.ac_state ? 1 : 0;
-   time_string = get_remaining (apminfo.battery_time);
    batt_life = apminfo.battery_life;
+   rem_string = get_remaining (apminfo.battery_time, batt_life, 1);
+   chg_string = get_remaining (apminfo.battery_time, batt_life, 0);
 #elif __linux__
    acline_status = apminfo.ac_line_status ? 1 : 0;
-   time_string = get_remaining (apminfo.battery_time);
    batt_life = apminfo.battery_percentage;
+   rem_string = get_remaining (apminfo.battery_time, batt_life, 1);
+   chg_string = get_remaining (apminfo.battery_time, batt_life, 0);
 #else
    acline_status = 1;
-   /* Translation Note: as in "Unknown time remaining" */
-   time_string = g_strdup (_("Unknown time"));
+   rem_string = g_strdup (_("Unknown time remaining."));
+   chg_string = g_strdup (_("Unknown time till charged."));
    batt_life = 100;
 #endif
    if(batt_state > 3) batt_state = 0;
@@ -1187,22 +1194,21 @@
 		      when the computer is using battery power and the battery meter
 	  	      and percent meter is hidden by the user.
 		      Translation note: %s is time in words (translated elsewhere) */
-		new_label = g_strdup_printf (_("System is running on battery power. %s (%d%%) remaining."),
-		     time_string, batt_life);
+	        new_label = g_strconcat (_("System is running on battery power."), rem_string, NULL);
 	 } else {
 		     /* This string will display as a tooltip over the status frame
 		      when the computer is using AC power and the battery meter
 		      and percent meter is hidden by the user.
 		      Translation note: %s is time in words (translated elsewhere) */
-		new_label = g_strdup_printf (_("System is running on AC power. %s (%d%%) till charged."),
-		     time_string, batt_life);
+	        new_label = g_strconcat (_("System is running on AC power."), chg_string, NULL);
 	 }
 	 gtk_tooltips_set_tip (battstat->ac_tip,
 			       battstat->eventstatus,
 			       new_label,
 			       NULL);
 	 g_free (new_label);
-	 g_free (time_string);
+	 g_free (rem_string);
+	 g_free (chg_string);
       } else {
 	 if(acline_status == 0) {
 	    /* 0 = Battery power */
@@ -1276,16 +1282,14 @@
 		      when the computer is using battery power and the battery meter
 		      and percent meter is hidden by the user.
 		      Translation note: %s is time in words (translated elsewhere) */
-		new_label = g_strdup_printf (_("System is running on battery power\n%s (%d%%) remaining."),
-		     time_string, batt_life);
+	        new_label = g_strconcat (_("System is running on battery power"), "\n", rem_string, NULL),
 	 } else {
 	    /* 1 = AC power. I should really test it explicitly here. */
 		     /* This string will display as a tooltip over the status frame
 		      when the computer is using AC power and the battery meter
 		      and percent meter is hidden by the user.
 		      Translation note: %s is time in words (translated elsewhere) */
-		new_label = g_strdup_printf (_("System is running on AC power\n%s (%d%%) till charged."),
-		     time_string, batt_life);
+	        new_label = g_strconcat (_("System is running on AC power"), "\n", chg_string, NULL),
 	 }
 	 gtk_tooltips_set_tip (battstat->ac_tip,
 			       battstat->eventstatus,
@@ -1309,7 +1313,8 @@
 			       new_label,
 			       NULL);
 	 g_free (new_label);
-	 g_free (time_string);
+	 g_free (rem_string);
+	 g_free (chg_string);
       }
    }
    
