From 5535aefc758a50366851f1bc0cf382757d5f8178 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 27 Feb 2007 19:08:17 +0100 Subject: [PATCH] Add a Server section in the config file and use it to register only when needed --- services/presence2/server_plugin.py | 19 ++++++++++++++++--- shell/intro/intro.py | 5 +++++ sugar/profile.py | 27 +++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/services/presence2/server_plugin.py b/services/presence2/server_plugin.py index 613511c6..0cce49cc 100644 --- a/services/presence2/server_plugin.py +++ b/services/presence2/server_plugin.py @@ -57,9 +57,19 @@ class ServerPlugin(gobject.GObject): self._conn = self._init_connection() def _get_account_info(self): - account_info = {'server': 'olpc.collabora.co.uk'} - + account_info = {} + pubkey = profile.get_pubkey() + + server = profile.get_server() + if not server: + account_info['server'] = 'olpc.collabora.co.uk' + else: + account_info['server'] = server + + registered = profile.get_server_registered() + account_info['register'] = not registered + khash = util.printable_hash(util._sha_data(pubkey)) account_info['account'] = "%s@%s" % (khash, account_info['server']) @@ -88,7 +98,6 @@ class ServerPlugin(gobject.GObject): conn = self._find_existing_connection() if not conn: acct = self._account.copy() - acct['register'] = True # Create a new connection print acct @@ -117,6 +126,10 @@ class ServerPlugin(gobject.GObject): return channel def _connected_cb(self): + if self._account['register']: + # we successfully register this account + profile.set_server_registered() + # the group of contacts who may receive your presence publish = self._request_list_channel('publish') publish_handles, local_pending, remote_pending = publish[CHANNEL_INTERFACE_GROUP].GetAllMembers() diff --git a/shell/intro/intro.py b/shell/intro/intro.py index 0a733295..2e23dffa 100644 --- a/shell/intro/intro.py +++ b/shell/intro/intro.py @@ -239,6 +239,11 @@ class IntroBox(hippo.CanvasBox, hippo.CanvasItem): cp.set(section, 'NickName', name) cp.set(section, 'Color', color.to_string()) + secion = 'Server' + cp.add_section(section) + cp.set(section, 'Server', 'olpc.collabora.co.uk') + cp.set(Section, 'Registered', 'False') + config_path = os.path.join(env.get_profile_path(), 'config') f = open(config_path, 'w') cp.write(f) diff --git a/sugar/profile.py b/sugar/profile.py index f34e390b..526c0f9d 100644 --- a/sugar/profile.py +++ b/sugar/profile.py @@ -28,6 +28,8 @@ class _Profile(object): self.color = None self.pubkey = None self.privkey_hash = None + self.server = None + self.server_registered = False self._load() def update(self): @@ -44,6 +46,12 @@ class _Profile(object): if cp.has_option('Buddy', 'Color'): self.color = XoColor(cp.get('Buddy', 'Color')) + if cp.has_option('Server', 'Server'): + self.server = cp.get('Server', 'Server') + + if cp.has_option('Server', 'Registered'): + self.server_registered = cp.get('Server', 'Registered') + del cp self._load_pubkey() @@ -110,6 +118,25 @@ def get_pubkey(): def get_private_key_hash(): return _profile.privkey_hash +def get_server(): + return _profile.server + +def get_server_registered(): + return _profile.server_registered + +def set_server_registered(): + _profile.server_registered = True + + cp = ConfigParser() + + config_path = os.path.join(env.get_profile_path(), 'config') + cp.read([config_path]) + + if not cp.has_section('Server'): + cp.add_section('Server') + cp.set('Server', 'Registered', True) + cp.write(open(config_path, 'w')) + def update(): _profile.update()