Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorDaniel Drake <dsd@laptop.org>2009-12-24 14:57:54 (GMT)
committer Daniel Drake <dsd@laptop.org>2010-01-03 11:49:40 (GMT)
commit839970e6bad870e5c00bb065d949019c7fffccda (patch)
treea23b354a93c33992b3d4d22af664c05393575202 /extensions
parente71649661e7e7ba4acb9cc526c2ecd15d1e22afe (diff)
Truncate ad-hoc network name to not exceed the SSID limit (#1604)
Fixes breakage where you could not create an ad-hoc network if your sugar name is longer than 6 characters.
Diffstat (limited to 'extensions')
-rw-r--r--extensions/deviceicon/network.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index dd1a70c..2776f0a 100644
--- a/extensions/deviceicon/network.py
+++ b/extensions/deviceicon/network.py
@@ -21,6 +21,7 @@ import logging
import hashlib
import socket
import struct
+import re
import gtk
import gobject
@@ -409,10 +410,27 @@ class WirelessDeviceView(ToolButton):
break
def __create_connection_cb(self, palette, data=None):
+ """Create an 802.11 IBSS network.
+
+ The user's color is encoded at the end of the network name. The network
+ name is truncated so that it does not exceed the 32 byte SSID limit.
+ """
client = gconf.client_get_default()
- nick = client.get_string('/desktop/sugar/user/nick')
+ nick = client.get_string('/desktop/sugar/user/nick').decode('utf-8')
color = client.get_string('/desktop/sugar/user/color')
- connection_name = _('%s\'s network %s') % (nick, color)
+ color_suffix = ' %s' % color
+
+ format = _('%s\'s network').encode('utf-8')
+ extra_length = (len(format) - len('%s')) + len(color_suffix)
+ name_limit = 32 - extra_length
+
+ # truncate the nick and use a regex to drop any partial characters
+ # at the end
+ nick = nick.encode('utf-8')[:name_limit]
+ nick = re.sub("([\xf6-\xf7][\x80-\xbf]{0,2}|[\xe0-\xef][\x80-\xbf]{0,1}|[\xc0-\xdf])$", '', nick)
+
+ connection_name = format % nick
+ connection_name += color_suffix
connection = network.find_connection(connection_name)
if connection is None: