[Xfce4-commits] [xfce/xfce4-power-manager] 01/01: Make the devices tab label the same as the plugin

noreply at xfce.org noreply at xfce.org
Mon May 26 16:58:32 CEST 2014


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit 44f9eacbe38e11142503132f20bb4d61d8f8dd1f
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Mon May 26 17:54:45 2014 +0300

    Make the devices tab label the same as the plugin
---
 common/xfpm-power-common.c             |  137 ++++++++++++++++++++++++++++++++
 common/xfpm-power-common.h             |    2 +
 panel-plugins/battery/battery-button.c |  113 +-------------------------
 settings/xfpm-settings.c               |    8 +-
 4 files changed, 141 insertions(+), 119 deletions(-)

diff --git a/common/xfpm-power-common.c b/common/xfpm-power-common.c
index 81dd2ba..c99be8a 100644
--- a/common/xfpm-power-common.c
+++ b/common/xfpm-power-common.c
@@ -293,3 +293,140 @@ get_device_icon_name (UpClient *upower, UpDevice *device)
 
     return icon_name;
 }
+
+gchar*
+get_device_description (UpClient *upower, UpDevice *device)
+{
+    UpDevice *display_device;
+    gchar *tip = NULL;
+    gchar *est_time_str = NULL;
+    guint type = 0, state = 0;
+    gchar *model = NULL, *vendor = NULL;
+    gboolean present, online;
+    gdouble percentage;
+    guint64 time_to_empty, time_to_full;
+
+    /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
+    g_object_get (device,
+                  "kind", &type,
+                  "vendor", &vendor,
+                  "model", &model,
+                  "state", &state,
+                  "is-present", &present,
+                  "percentage", &percentage,
+                  "time-to-empty", &time_to_empty,
+                  "time-to-full", &time_to_full,
+                  "online", &online,
+                   NULL);
+
+    display_device = up_client_get_display_device (upower);
+
+    if (device == display_device)
+    {
+        g_free (vendor);
+        vendor = g_strdup (_("Computer"));
+
+        g_free (model);
+        model = NULL;
+    }
+
+    /* If we get a vendor or model we can use it, otherwise translate the
+     * device type into something readable (works for things like ac_power)
+     */
+    if (g_strcmp0(vendor, "") == 0 && g_strcmp0(model, "") == 0)
+        vendor = g_strdup_printf ("%s", xfpm_power_translate_device_type (type));
+
+    if ( state == UP_DEVICE_STATE_FULLY_CHARGED )
+    {
+        if ( time_to_empty > 0 )
+        {
+            est_time_str = xfpm_battery_get_time_string (time_to_empty);
+            tip = g_strdup_printf (_("<b>%s %s</b>\t\nFully charged (%0.0f%%, %s runtime)\t"),
+                                   vendor, model,
+                                   percentage,
+                                   est_time_str);
+            g_free (est_time_str);
+        }
+        else
+        {
+            tip = g_strdup_printf (_("<b>%s %s</b>\t\nFully charged (%0.0f%%)\t"),
+                                   vendor, model,
+                                   percentage);
+        }
+    }
+    else if ( state == UP_DEVICE_STATE_CHARGING )
+    {
+        if ( time_to_full != 0 )
+        {
+            est_time_str = xfpm_battery_get_time_string (time_to_full);
+            tip = g_strdup_printf (_("<b>%s %s</b>\t\nCharging (%0.0f%%, %s)\t"),
+                                   vendor, model,
+                                   percentage,
+                                   est_time_str);
+            g_free (est_time_str);
+        }
+        else
+        {
+            tip = g_strdup_printf (_("<b>%s %s</b>\t\nCharging (%0.0f%%)\t"),
+                                   vendor, model,
+                                   percentage);
+        }
+    }
+    else if ( state == UP_DEVICE_STATE_DISCHARGING )
+    {
+        if ( time_to_empty != 0 )
+        {
+            est_time_str = xfpm_battery_get_time_string (time_to_empty);
+            tip = g_strdup_printf (_("<b>%s %s</b>\t\nDischarging (%0.0f%%, %s)\t"),
+                                   vendor, model,
+                                   percentage,
+                                   est_time_str);
+            g_free (est_time_str);
+        }
+        else
+        {
+            tip = g_strdup_printf (_("<b>%s %s</b>\t\nDischarging (%0.0f%%)\t"),
+                                   vendor, model,
+                                   percentage);
+        }
+    }
+    else if ( state == UP_DEVICE_STATE_PENDING_CHARGE )
+    {
+        tip = g_strdup_printf (_("<b>%s %s</b>\t\nWaiting to discharge (%0.0f%%)\t"),
+                               vendor, model,
+                               percentage);
+    }
+    else if ( state == UP_DEVICE_STATE_PENDING_DISCHARGE )
+    {
+        tip = g_strdup_printf (_("<b>%s %s</b>\t\nWaiting to charge (%0.0f%%)\t"),
+                               vendor, model,
+                               percentage);
+    }
+    else if ( state == UP_DEVICE_STATE_EMPTY )
+    {
+        tip = g_strdup_printf (_("<b>%s %s</b>\t\nis empty\t"),
+                               vendor, model);
+    }
+    else
+    {
+        if (type == UP_DEVICE_KIND_LINE_POWER)
+        {
+            /* On the 2nd line we want to know if the power cord is plugged
+             * in or not */
+            tip = g_strdup_printf (_("<b>%s %s</b>\t\n%s\t"),
+                           vendor, model, online ? _("Plugged in") : _("Not plugged in"));
+        }
+        else
+        {
+            /* unknown device state, just display the percentage */
+            tip = g_strdup_printf (_("<b>%s %s</b>\t\nUnknown state\t"),
+                           vendor, model);
+        }
+    }
+
+    g_free(model);
+    g_free(vendor);
+    g_object_unref (display_device);
+
+    return tip;
+}
diff --git a/common/xfpm-power-common.h b/common/xfpm-power-common.h
index dc1bbbe..63db7ad 100644
--- a/common/xfpm-power-common.h
+++ b/common/xfpm-power-common.h
@@ -53,4 +53,6 @@ gchar *xfpm_battery_get_icon_prefix_device_enum_type (UpDeviceKind type);
 
 gchar *get_device_icon_name (UpClient *upower, UpDevice *device);
 
+gchar *get_device_description (UpClient *upower, UpDevice *device);
+
 #endif /* XFPM_UPOWER_COMMON */
diff --git a/panel-plugins/battery/battery-button.c b/panel-plugins/battery/battery-button.c
index 51f9108..9414476 100644
--- a/panel-plugins/battery/battery-button.c
+++ b/panel-plugins/battery/battery-button.c
@@ -86,7 +86,6 @@ typedef struct
 G_DEFINE_TYPE (BatteryButton, battery_button, GTK_TYPE_TOGGLE_BUTTON)
 
 static void battery_button_finalize   (GObject *object);
-static gchar* get_device_description (BatteryButton *button, UpDevice *device);
 static GList* find_device_in_list (BatteryButton *button, const gchar *object_path);
 static gboolean battery_button_set_icon (BatteryButton *button);
 static gboolean battery_button_press_event (GtkWidget *widget, GdkEventButton *event);
@@ -170,116 +169,6 @@ battery_button_set_tooltip (BatteryButton *button)
     }
 }
 
-static gchar*
-get_device_description (BatteryButton *button, UpDevice *device)
-{
-    gchar *tip = NULL;
-    gchar *est_time_str = NULL;
-    guint type = 0, state = 0;
-    gchar *model = NULL, *vendor = NULL;
-    gboolean present;
-    gdouble percentage;
-    guint64 time_to_empty, time_to_full;
-
-    /* hack, this depends on XFPM_DEVICE_TYPE_* being in sync with UP_DEVICE_KIND_* */
-    g_object_get (device,
-		  "kind", &type,
-		  "vendor", &vendor,
-		  "model", &model,
-		  "state", &state,
-		  "is-present", &present,
-		  "percentage", &percentage,
-		  "time-to-empty", &time_to_empty,
-		  "time-to-full", &time_to_full,
-		   NULL);
-
-    if (device == button->priv->display_device)
-    {
-	vendor = g_strdup (_("Computer"));
-    }
-
-    if ( state == UP_DEVICE_STATE_FULLY_CHARGED )
-    {
-	if ( time_to_empty > 0 )
-	{
-	    est_time_str = xfpm_battery_get_time_string (time_to_empty);
-	    tip = g_strdup_printf (_("<b>%s %s</b>\t\nFully charged (%0.0f%%, %s runtime)\t"),
-				   vendor, model,
-				   percentage,
-				   est_time_str);
-	    g_free (est_time_str);
-	}
-	else
-	{
-	    tip = g_strdup_printf (_("<b>%s %s</b>\t\nFully charged (%0.0f%%)\t"),
-				   vendor, model,
-				   percentage);
-	}
-    }
-    else if ( state == UP_DEVICE_STATE_CHARGING )
-    {
-	if ( time_to_full != 0 )
-	{
-	    est_time_str = xfpm_battery_get_time_string (time_to_full);
-	    tip = g_strdup_printf (_("<b>%s %s</b>\t\nCharging (%0.0f%%, %s)\t"),
-				   vendor, model,
-				   percentage,
-				   est_time_str);
-	    g_free (est_time_str);
-	}
-	else
-	{
-	    tip = g_strdup_printf (_("<b>%s %s</b>\t\nCharging (%0.0f%%)\t"),
-				   vendor, model,
-				   percentage);
-	}
-    }
-    else if ( state == UP_DEVICE_STATE_DISCHARGING )
-    {
-	if ( time_to_empty != 0 )
-	{
-	    est_time_str = xfpm_battery_get_time_string (time_to_empty);
-	    tip = g_strdup_printf (_("<b>%s %s</b>\t\nDischarging (%0.0f%%, %s)\t"),
-				   vendor, model,
-				   percentage,
-				   est_time_str);
-	    g_free (est_time_str);
-	}
-	else
-	{
-	    tip = g_strdup_printf (_("<b>%s %s</b>\t\nDischarging (%0.0f%%)\t"),
-				   vendor, model,
-				   percentage);
-	}
-
-    }
-    else if ( state == UP_DEVICE_STATE_PENDING_CHARGE )
-    {
-	tip = g_strdup_printf (_("<b>%s %s</b>\t\nWaiting to discharge (%0.0f%%)\t"),
-			       vendor, model,
-			       percentage);
-    }
-    else if ( state == UP_DEVICE_STATE_PENDING_DISCHARGE )
-    {
-	tip = g_strdup_printf (_("<b>%s %s</b>\t\nWaiting to charge (%0.0f%%)\t"),
-	                       vendor, model,
-			       percentage);
-    }
-    else if ( state == UP_DEVICE_STATE_EMPTY )
-    {
-	tip = g_strdup_printf (_("<b>%s %s</b>\t\nis empty\t"),
-	                       vendor, model);
-    }
-    else
-    {
-	/* unknown device state, just display the percentage */
-	tip = g_strdup_printf (_("<b>%s %s</b>\t\nUnknown state\t"),
-			       vendor, model);
-    }
-
-    return tip;
-}
-
 static GList*
 find_device_in_list (BatteryButton *button, const gchar *object_path)
 {
@@ -326,7 +215,7 @@ battery_button_update_device_icon_and_details (BatteryButton *button, UpDevice *
 		   NULL);
 
     icon_name = get_device_icon_name (button->priv->upower, device);
-    details = get_device_description(button, device);
+    details = get_device_description(button->priv->upower, device);
 
     pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
 				    icon_name,
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index 4a78ca0..a625747 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -1557,14 +1557,8 @@ update_sideview_icon (UpDevice *device)
                   "model", &model,
                   NULL);
 
-    /* If we get a vendor or model we can use it, otherwise translate the
-     * device type into something readable (works for things like ac_power)
-     */
-    if (g_strcmp0(vendor, "") != 0 || g_strcmp0(model, "") != 0)
-        name = g_strdup_printf ("%s %s", vendor, model);
-    else
-        name = g_strdup_printf ("%s", xfpm_power_translate_device_type (type));
 
+    name = get_device_description (upower, device);
     icon_name = get_device_icon_name (upower, device);
 
     pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list