From 90019362eaba824a8977241aece203c75805675d Mon Sep 17 00:00:00 2001
From: Simon Schampijer <simon@schampijer.de>
Date: Thu, 26 Aug 2010 17:53:12 +0200
Subject: [PATCH] AP: signal strength update not seperate from state change

---
 src/jarabe/desktop/networkviews.py |   67 +++++++++++++++++------------------
 1 files changed, 33 insertions(+), 34 deletions(-)

diff --git a/src/jarabe/desktop/networkviews.py b/src/jarabe/desktop/networkviews.py
index 121c817..48d8747 100644
--- a/src/jarabe/desktop/networkviews.py
+++ b/src/jarabe/desktop/networkviews.py
@@ -159,6 +159,7 @@ class WirelessNetworkView(CanvasPulsingIcon):
     def __device_state_changed_cb(self, new_state, old_state, reason):
         self._device_state = new_state
         self._update_state()
+        self._update_icon()
 
     def __update_active_ap(self, ap_path):
         if ap_path in self._access_points:
@@ -166,12 +167,10 @@ class WirelessNetworkView(CanvasPulsingIcon):
             # strength of that one
             self._active_ap = self._access_points[ap_path]
             self.update_strength()
-            self._update_state()
         elif self._active_ap is not None:
             # revert to showing state of strongest AP again
             self._active_ap = None
             self.update_strength()
-            self._update_state()
 
     def __wireless_properties_changed_cb(self, properties):
         if 'ActiveAccessPoint' in properties:
@@ -191,26 +190,19 @@ class WirelessNetworkView(CanvasPulsingIcon):
 
     def __get_device_state_reply_cb(self, state):
         self._device_state = state
-        self._update()
-
-    def __get_device_state_error_cb(self, err):
-        logging.error('Error getting the device state: %s', err)
-
-    def _update(self):
         self._update_state()
         self._update_color()
 
-    def _update_state(self):
-        if self._active_ap is not None:
-            state = self._device_state
-        else:
-            state = network.DEVICE_STATE_UNKNOWN
+    def __get_device_state_error_cb(self, err):
+        logging.error('Error getting the device state: %s', err)
 
+    def _update_icon(self):
         if self._mode == network.NM_802_11_MODE_ADHOC and \
                 network.is_sugar_adhoc_network(self._name):
             channel = max([1] + [ap.channel for ap in
                                  self._access_points.values()])
-            if state == network.DEVICE_STATE_ACTIVATED:
+            if self._device_state == network.DEVICE_STATE_ACTIVATED and \
+                    self._active_ap is not None:
                 icon_name = 'network-adhoc-%s-connected' % channel
             else:
                 icon_name = 'network-adhoc-%s' % channel
@@ -218,11 +210,8 @@ class WirelessNetworkView(CanvasPulsingIcon):
             icon = self._palette.props.icon
             icon.props.icon_name = icon_name
         else:
-            if state == network.DEVICE_STATE_ACTIVATED:
-                connection = network.find_connection_by_ssid(self._name)
-                if connection is not None:
-                    if self._mode == network.NM_802_11_MODE_INFRA:
-                        connection.set_connected()
+            if self._device_state == network.DEVICE_STATE_ACTIVATED and \
+                    self._active_ap is not None:
                 icon_name = '%s-connected' % _AP_ICON_NAME
             else:
                 icon_name = _AP_ICON_NAME
@@ -233,6 +222,12 @@ class WirelessNetworkView(CanvasPulsingIcon):
                 icon = self._palette.props.icon
                 icon.props.icon_name = icon_name
 
+    def _update_state(self):
+        if self._active_ap is not None:
+            state = self._device_state
+        else:
+            state = network.DEVICE_STATE_UNKNOWN
+
         if state == network.DEVICE_STATE_PREPARE or \
            state == network.DEVICE_STATE_CONFIG or \
            state == network.DEVICE_STATE_NEED_AUTH or \
@@ -243,6 +238,10 @@ class WirelessNetworkView(CanvasPulsingIcon):
             self._palette.props.secondary_text = _('Connecting...')
             self.props.pulsing = True
         elif state == network.DEVICE_STATE_ACTIVATED:
+            connection = network.find_connection_by_ssid(self._name)
+            if connection is not None:
+                if self._mode == network.NM_802_11_MODE_INFRA:
+                    connection.set_connected()
             if self._disconnect_item:
                 self._disconnect_item.show()
             self._connect_item.hide()
@@ -262,6 +261,20 @@ class WirelessNetworkView(CanvasPulsingIcon):
         else:
             self.props.base_color = self._color
 
+    def update_strength(self):
+        if self._active_ap is not None:
+            # display strength of AP that we are connected to
+            new_strength = self._active_ap.strength
+        else:
+            # display the strength of the strongest AP that makes up this
+            # network, also considering that there may be no APs
+            new_strength = max([0] + [ap.strength for ap in
+                                      self._access_points.values()])
+
+        if new_strength != self._strength:
+            self._strength = new_strength
+            self._update_icon()
+
     def _disconnect_activate_cb(self, item):
         pass
 
@@ -376,27 +389,13 @@ class WirelessNetworkView(CanvasPulsingIcon):
 
     def set_filter(self, query):
         self._greyed_out = self._name.lower().find(query) == -1
-        self._update_state()
+        self._update_icon()
         self._update_color()
 
     def create_keydialog(self, settings, response):
         keydialog.create(self._name, self._flags, self._wpa_flags,
                          self._rsn_flags, self._device_caps, settings, response)
 
-    def update_strength(self):
-        if self._active_ap is not None:
-            # display strength of AP that we are connected to
-            new_strength = self._active_ap.strength
-        else:
-            # display the strength of the strongest AP that makes up this
-            # network, also considering that there may be no APs
-            new_strength = max([0] + [ap.strength for ap in
-                                      self._access_points.values()])
-
-        if new_strength != self._strength:
-            self._strength = new_strength
-            self._update_state()
-
     def add_ap(self, ap):
         self._access_points[ap.model.object_path] = ap
         self.update_strength()
-- 
1.7.2.2

