From f1fcf461752f164b6f697dcf86c86c7ddde644bf Mon Sep 17 00:00:00 2001
From: Daniel Drake <dsd@laptop.org>
Date: Fri, 4 Dec 2009 17:07:55 +0000
Subject: [PATCH 2/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 long.
---
extensions/deviceicon/network.py | 19 +++++++++++++++++--
1 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 75bc467..fd5c9b1 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): |
398 | 399 | |
399 | 400 | def __create_connection_cb(self, palette, data=None): |
400 | 401 | client = gconf.client_get_default() |
401 | | nick = client.get_string('/desktop/sugar/user/nick') |
402 | | connection_name = _('%s\'s network') % nick |
| 402 | nick = client.get_string('/desktop/sugar/user/nick').decode('utf-8') |
| 403 | |
| 404 | # there is a 32 character SSID limit, and we use some of that with |
| 405 | # our "'s network" label. truncate the name accordingly, being careful |
| 406 | # not to truncate in the middle of multi-byte characters |
| 407 | |
| 408 | fmt = _('%s\'s network').encode('utf-8') |
| 409 | extra_len = len(fmt) - len('%s') |
| 410 | name_limit = 32 - extra_len |
| 411 | |
| 412 | # truncate the nick and use a regex to drop any partial characters |
| 413 | # at the end |
| 414 | nick = nick.encode('utf-8')[:name_limit] |
| 415 | nick = re.sub("([\xf6-\xf7][\x80-\xbf]{0,2}|[\xe0-\xef][\x80-\xbf]{0,1}|[\xc0-\xdf])$", '', nick) |
| 416 | |
| 417 | connection_name = fmt % nick |
403 | 418 | |
404 | 419 | connection = network.find_connection(connection_name) |
405 | 420 | if connection is None: |