[gnome-shell/wip/aggregate-menu: 15/36] power: Use the new power labels from the designs



commit 434413d02c9499a5929735ce7021bb90b4dadeb8
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed May 22 14:19:00 2013 -0400

    power: Use the new power labels from the designs

 data/theme/gnome-shell.css |    8 -----
 js/ui/status/power.js      |   71 ++++++++++++++++++++++++-------------------
 2 files changed, 40 insertions(+), 39 deletions(-)
---
diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css
index a4f72c1..6f574d2 100644
--- a/data/theme/gnome-shell.css
+++ b/data/theme/gnome-shell.css
@@ -229,10 +229,6 @@ StScrollBar StButton#vhandle:active {
     font-weight: bold;
 }
 
-.popup-device-menu-item {
-    spacing: .5em;
-}
-
 .popup-status-menu-item {
     font-weight: normal;
     color: #999;
@@ -251,10 +247,6 @@ StScrollBar StButton#vhandle:active {
     icon-size: 1.09em;
 }
 
-.popup-battery-percentage {
-    padding-left: 24px;
-}
-
 /* Switches */
 .toggle-switch {
     width: 65px;
diff --git a/js/ui/status/power.js b/js/ui/status/power.js
index 20eb545..76f3afa 100644
--- a/js/ui/status/power.js
+++ b/js/ui/status/power.js
@@ -41,47 +41,56 @@ const Indicator = new Lang.Class({
                                                 this._devicesChanged();
                                             }));
 
-        this.item = new PopupMenu.PopupMenuItem('', { reactive: false });
-        this._primaryPercentage = new St.Label({ style_class: 'popup-battery-percentage' });
-        this.item.addActor(this._primaryPercentage, { align: St.Align.END });
-        this.menu.addMenuItem(this.item);
+        this._batteryItem = new PopupMenu.PopupMenuItem(_("Battery"), { reactive: false });
+        this._status = new St.Label({ style_class: 'popup-status-menu-item' });
+        this._batteryItem.addActor(this._status, { align: St.Align.END });
+        this.menu.addMenuItem(this._batteryItem);
+    },
+
+    _statusForDevice: function(device) {
+        let [device_id, device_type, icon, percentage, state, seconds] = device;
+
+        if (state == UPower.DeviceState.FULLY_CHARGED)
+            return _("Fully Charged");
+
+        let time = Math.round(seconds / 60);
+        if (time == 0) {
+            // 0 is reported when UPower does not have enough data
+            // to estimate battery life
+            return _("Estimating…");
+        }
+
+        let minutes = time % 60;
+        let hours = Math.floor(time / 60);
+
+        if (state == UPower.DeviceState.DISCHARGING) {
+            // Translators: this is <hours>:<minutes> Remaining (<percentage>)
+            return _("%d\u2236%d Remaining (%d%%)".format(hours, minutes, percentage));
+        }
+
+        if (state == UPower.DeviceState.CHARGING) {
+            // Translators: this is <hours>:<minutes> Until Full (<percentage>)
+            return _("%d\u2236%d Until Full (%d%%)".format(hours, minutes, percentage));
+        }
+
+        // state is one of PENDING_CHARGING, PENDING_DISCHARGING
+        return _("Estimating…");
     },
 
     _readPrimaryDevice: function() {
         this._proxy.GetPrimaryDeviceRemote(Lang.bind(this, function(result, error) {
             if (error) {
-                this.item.actor.hide();
+                this._batteryItem.actor.hide();
                 return;
             }
 
-            let [[device_id, device_type, icon, percentage, state, seconds]] = result;
+            let [device] = result;
+            let [device_id, device_type] = device;
             if (device_type == UPower.DeviceKind.BATTERY) {
-                let time = Math.round(seconds / 60);
-                if (time == 0) {
-                    // 0 is reported when UPower does not have enough data
-                    // to estimate battery life
-                    this.item.label.text = _("Estimating…");
-                } else {
-                    let minutes = time % 60;
-                    let hours = Math.floor(time / 60);
-                    let timestring;
-                    if (time >= 60) {
-                        if (minutes == 0) {
-                            timestring = ngettext("%d hour remaining", "%d hours remaining", 
hours).format(hours);
-                        } else {
-                            /* TRANSLATORS: this is a time string, as in "%d hours %d minutes remaining" */
-                            let template = _("%d %s %d %s remaining");
-
-                            timestring = template.format (hours, ngettext("hour", "hours", hours), minutes, 
ngettext("minute", "minutes", minutes));
-                        }
-                    } else
-                        timestring = ngettext("%d minute remaining", "%d minutes remaining", 
minutes).format(minutes);
-                    this.item.label.text = timestring;
-                }
-                this._primaryPercentage.text = C_("percent of battery remaining", 
"%d%%").format(Math.round(percentage));
-                this.item.actor.show();
+                this._status.text = this._statusForDevice(device);
+                this._batteryItem.actor.show();
             } else {
-                this.item.actor.hide();
+                this._batteryItem.actor.hide();
             }
         }));
     },


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]