From e6b7cbc589555f66a9b9eb1bcadf35c319e101da Mon Sep 17 00:00:00 2001
From: Daniel Drake <dsd@laptop.org>
Date: Thu, 24 Dec 2009 15:08:09 +0000
Subject: [PATCH 2/2] Only parse colors from ad-hoc network names that contain them (#1604)
---
extensions/deviceicon/network.py | 10 ++++++++--
src/jarabe/desktop/meshbox.py | 10 ++++++++--
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 686ca96..3c17253 100644
a
|
b
|
class WirelessDeviceView(ToolButton): |
309 | 309 | def __ap_properties_changed_cb(self, properties): |
310 | 310 | self._update_properties(properties) |
311 | 311 | |
| 312 | def _name_encodes_colors(self): |
| 313 | """Match #XXXXXX,#YYYYYY at the end of the network name""" |
| 314 | return self._name[-7] == '#' and self._name[-8] == ',' \ |
| 315 | and self._name[-15] == '#' |
| 316 | |
312 | 317 | def _update_properties(self, properties): |
313 | 318 | if 'Mode' in properties: |
314 | 319 | self._mode = properties['Mode'] |
… |
… |
class WirelessDeviceView(ToolButton): |
324 | 329 | self._frequency = properties['Frequency'] |
325 | 330 | |
326 | 331 | if self._color == None: |
327 | | if self._mode == network.NM_802_11_MODE_ADHOC: |
| 332 | if self._mode == network.NM_802_11_MODE_ADHOC \ |
| 333 | and self._name_encodes_colors(): |
328 | 334 | encoded_color = self._name.split("#", 1) |
329 | 335 | if len(encoded_color) == 2: |
330 | 336 | self._color = xocolor.XoColor('#' + encoded_color[1]) |
331 | | if self._mode == network.NM_802_11_MODE_INFRA: |
| 337 | else: |
332 | 338 | sha_hash = hashlib.sha1() |
333 | 339 | data = self._name + hex(self._flags) |
334 | 340 | sha_hash.update(data) |
diff --git a/src/jarabe/desktop/meshbox.py b/src/jarabe/desktop/meshbox.py
index 2c58fe6..76880b8 100644
a
|
b
|
class WirelessNetworkView(CanvasPulsingIcon): |
86 | 86 | self._connection = None |
87 | 87 | self._color = None |
88 | 88 | |
89 | | if self._mode == network.NM_802_11_MODE_ADHOC: |
| 89 | if self._mode == network.NM_802_11_MODE_ADHOC \ |
| 90 | and self._name_encodes_colors(): |
90 | 91 | encoded_color = self._name.split("#", 1) |
91 | 92 | if len(encoded_color) == 2: |
92 | 93 | self._color = xocolor.XoColor('#' + encoded_color[1]) |
93 | | if self._mode == network.NM_802_11_MODE_INFRA: |
| 94 | else: |
94 | 95 | sha_hash = hashlib.sha1() |
95 | 96 | data = self._name + hex(self._flags) |
96 | 97 | sha_hash.update(data) |
… |
… |
class WirelessNetworkView(CanvasPulsingIcon): |
142 | 143 | path=self._device.object_path, |
143 | 144 | dbus_interface=_NM_WIRELESS_IFACE) |
144 | 145 | |
| 146 | def _name_encodes_colors(self): |
| 147 | """Match #XXXXXX,#YYYYYY at the end of the network name""" |
| 148 | return self._name[-7] == '#' and self._name[-8] == ',' \ |
| 149 | and self._name[-15] == '#' |
| 150 | |
145 | 151 | def _create_palette(self): |
146 | 152 | icon_name = get_icon_state(_ICON_NAME, self._strength) |
147 | 153 | self._palette_icon = Icon(icon_name=icon_name, |