From 7518a29dce9a54c538a4803052cf7c9a83b2cca1 Mon Sep 17 00:00:00 2001
From: Daniel Drake <dsd@laptop.org>
Date: Thu, 24 Dec 2009 14:57:54 +0000
Subject: [PATCH 1/2] 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.
---
extensions/deviceicon/network.py | 22 ++++++++++++++++++++--
1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index dd1a70c..686ca96 100644
a
|
b
|
import logging |
21 | 21 | import hashlib |
22 | 22 | import socket |
23 | 23 | import struct |
| 24 | import re |
24 | 25 | |
25 | 26 | import gtk |
26 | 27 | import gobject |
… |
… |
class WirelessDeviceView(ToolButton): |
409 | 410 | break |
410 | 411 | |
411 | 412 | def __create_connection_cb(self, palette, data=None): |
| 413 | """Create an 802.11 IBSS network. |
| 414 | |
| 415 | The user's color is encoded at the end of the network name. The network |
| 416 | name is truncated so that it does not exceed the 32 byte SSID limit. |
| 417 | """ |
412 | 418 | client = gconf.client_get_default() |
413 | | nick = client.get_string('/desktop/sugar/user/nick') |
| 419 | nick = client.get_string('/desktop/sugar/user/nick').decode('utf-8') |
414 | 420 | color = client.get_string('/desktop/sugar/user/color') |
415 | | connection_name = _('%s\'s network %s') % (nick, color) |
| 421 | color_suffix = ' %s' % color |
| 422 | |
| 423 | fmt = _('%s\'s network').encode('utf-8') |
| 424 | extra_len = (len(fmt) - len('%s')) + len(color_suffix) |
| 425 | name_limit = 32 - extra_len |
| 426 | |
| 427 | # truncate the nick and use a regex to drop any partial characters |
| 428 | # at the end |
| 429 | nick = nick.encode('utf-8')[:name_limit] |
| 430 | nick = re.sub("([\xf6-\xf7][\x80-\xbf]{0,2}|[\xe0-\xef][\x80-\xbf]{0,1}|[\xc0-\xdf])$", '', nick) |
| 431 | |
| 432 | connection_name = fmt % nick |
| 433 | connection_name += color_suffix |
416 | 434 | |
417 | 435 | connection = network.find_connection(connection_name) |
418 | 436 | if connection is None: |