[gnome-shell/wip/aggregate-menu: 46/99] network: Move the VPN indicator to getIndicatorIcon as well



commit 6724835cbb459952a3216395d865304f220c161a
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon Jun 10 15:17:30 2013 -0400

    network: Move the VPN indicator to getIndicatorIcon as well
    
    This removes the need to track the VPN connection in the main
    applet.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701954

 js/ui/status/network.js |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 101ed86..594e14d 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -1458,6 +1458,29 @@ const NMVPNSection = new Lang.Class({
         } else {
             log('Could not find connection for vpn-state-changed handler');
         }
+
+        this.emit('icon-changed');
+    },
+
+    _getIconForConnection: function(vpnConnection) {
+        if (vpnConnection) {
+            if (vpnConnection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
+                return 'network-vpn-acquiring-symbolic';
+            else
+                return 'network-vpn-symbolic';
+        } else {
+            return '';
+        }
+    },
+
+    getIndicatorIcon: function() {
+        for (let i = 0; i < this._connections.length; i++) {
+            let obj = this._connections[i];
+            let icon = this._getIconForConnection(obj.active);
+            if (icon)
+                return icon;
+        }
+        return '';
     },
 });
 
@@ -1536,7 +1559,6 @@ const NMApplet = new Lang.Class({
 
         this._mainConnection = null;
         this._mainConnectionIconChangedId = 0;
-        this._vpnConnection = null;
 
         this._nmDevices = [];
         this._devices = { };
@@ -1580,6 +1602,7 @@ const NMApplet = new Lang.Class({
 
         this._vpnSection = new NMVPNSection(this._client);
         this._vpnSection.connect('activation-failed', Lang.bind(this, this._onActivationFailed));
+        this._vpnSection.connect('icon-changed', Lang.bind(this, this._updateIcon));
         this.menu.addMenuItem(this._vpnSection.section);
         this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
         this.menu.addSettingsAction(_("Network Settings"), 'gnome-network-panel.desktop');
@@ -1829,12 +1852,10 @@ const NMApplet = new Lang.Class({
 
         this._activeConnections = newActiveConnections;
         this._mainConnection = null;
-        this._vpnConnection = null;
 
         let activating = null;
         let default_ip4 = null;
         let default_ip6 = null;
-        let active_vpn = null;
         let active_any = null;
         for (let i = 0; i < this._activeConnections.length; i++) {
             let a = this._activeConnections[i];
@@ -1871,11 +1892,6 @@ const NMApplet = new Lang.Class({
             else if (a.state == NetworkManager.ActiveConnectionState.ACTIVATED)
                 active_any = a;
 
-            if (a._type == 'vpn' &&
-                (a.state == NetworkManager.ActiveConnectionState.ACTIVATING ||
-                 a.state == NetworkManager.ActiveConnectionState.ACTIVATED))
-                active_vpn = a;
-
             if (!a._primaryDevice) {
                 if (a._type != NetworkManager.SETTING_VPN_SETTING_NAME) {
                     // This list is guaranteed to have one device in it.
@@ -1894,7 +1910,6 @@ const NMApplet = new Lang.Class({
         }
 
         this._mainConnection = activating || default_ip4 || default_ip6 || active_any || null;
-        this._vpnConnection = active_vpn;
 
         if (this._mainConnection) {
             let dev = this._mainConnection._primaryDevice;
@@ -2078,16 +2093,6 @@ const NMApplet = new Lang.Class({
             this.setIcon(dev.getIndicatorIcon());
         }
 
-        // update VPN indicator
-        if (this._vpnConnection) {
-            if (this._vpnConnection.state == NetworkManager.ActiveConnectionState.ACTIVATING)
-                this._vpnIcon.icon_name = 'network-vpn-acquiring-symbolic';
-            else
-                this._vpnIcon.icon_name = 'network-vpn-symbolic';
-
-            this._vpnIcon.show();
-        } else {
-            this._vpnIcon.hide();
-        }
+        this._vpnIcon.icon_name = this._vpnSection.getIndicatorIcon();
     }
 });


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