From 7363fc1f72ee74d2da534eb16de608634e1b7398 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Tue, 18 Aug 2009 05:59:30 +0000 Subject: Transmit the color of the ad-hoc network creator The color is encoded in the essid --- (limited to 'extensions') diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py index 5016943..0803936 100644 --- a/extensions/deviceicon/network.py +++ b/extensions/deviceicon/network.py @@ -215,6 +215,7 @@ class WirelessDeviceView(ToolButton): self._device_props = None self._flags = 0 self._name = '' + self._mode = network.NM_802_11_MODE_UNKNOWN self._strength = 0 self._frequency = 0 self._device_state = None @@ -308,8 +309,12 @@ class WirelessDeviceView(ToolButton): self._update_properties(properties) def _update_properties(self, properties): + if 'Mode' in properties: + self._mode = properties['Mode'] + self._color = None if 'Ssid' in properties: self._name = properties['Ssid'] + self._color = None if 'Strength' in properties: self._strength = properties['Strength'] if 'Flags' in properties: @@ -317,14 +322,21 @@ class WirelessDeviceView(ToolButton): if 'Frequency' in properties: self._frequency = properties['Frequency'] - sh = hashlib.sha1() - data = self._name + hex(self._flags) - sh.update(data) - h = hash(sh.digest()) - idx = h % len(xocolor.colors) - - self._color = xocolor.XoColor('%s,%s' % (xocolor.colors[idx][0], - xocolor.colors[idx][1])) + if self._color == None: + if self._mode == network.NM_802_11_MODE_ADHOC: + encoded_color = self._name.split("#", 1) + if len(encoded_color) == 2: + self._color = xocolor.XoColor('#' + encoded_color[1]) + if self._mode == network.NM_802_11_MODE_INFRA: + sha_hash = hashlib.sha1() + data = self._name + hex(self._flags) + sha_hash.update(data) + digest = hash(sha_hash.digest()) + index = digest % len(xocolor.colors) + + self._color = xocolor.XoColor('%s,%s' % + (xocolor.colors[index][0], + xocolor.colors[index][1])) self._update() def __get_all_ap_props_reply_cb(self, properties): @@ -399,7 +411,8 @@ class WirelessDeviceView(ToolButton): def __create_connection_cb(self, palette, data=None): client = gconf.client_get_default() nick = client.get_string('/desktop/sugar/user/nick') - connection_name = _('%s\'s network') % nick + color = client.get_string('/desktop/sugar/user/color') + connection_name = _('%s\'s network %s') % (nick, color) connection = network.find_connection(connection_name) if connection is None: -- cgit v0.9.1