From ccd2656a216023b7d1aeef2a61bdcb77ddca037a Mon Sep 17 00:00:00 2001
From: Morgan Collett <morgan.collett@gmail.com>
Date: Fri, 19 Dec 2008 14:21:34 +0200
Subject: [PATCH] #142: D-Bus method to restart the server_plugin.
Changes to ShellOwner and GenericOwner to reread the server from gconf on the fly.
---
src/buddy.py | 9 ++++-----
src/presenceservice.py | 12 ++++++++++++
src/telepathy_plugin.py | 2 ++
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/buddy.py b/src/buddy.py
index 3e8788d..68061c6 100644
a
|
b
|
class GenericOwner(Buddy): |
655 | 655 | calls Buddy.__init__ |
656 | 656 | """ |
657 | 657 | self._ps = ps |
658 | | self._server = kwargs.pop("server", None) |
659 | 658 | self._key_hash = kwargs.pop("key_hash", None) |
660 | 659 | |
661 | 660 | #: Telepathy plugin -> dict { activity ID -> room handle } |
… |
… |
class GenericOwner(Buddy): |
910 | 909 | |
911 | 910 | def get_server(self): |
912 | 911 | """Retrieve XMPP server hostname (used by the server plugin)""" |
913 | | return self._server |
| 912 | client = gconf.client_get_default() |
| 913 | server = client.get_string("/desktop/sugar/collaboration/jabber_server") |
| 914 | return server |
914 | 915 | |
915 | 916 | def get_key_hash(self): |
916 | 917 | """Retrieve the user's private-key hash (used by the server plugin |
… |
… |
class ShellOwner(GenericOwner): |
951 | 952 | client = gconf.client_get_default() |
952 | 953 | profile = get_profile() |
953 | 954 | |
954 | | server = client.get_string("/desktop/sugar/collaboration/jabber_server") |
955 | 955 | key_hash = profile.privkey_hash |
956 | 956 | key = profile.pubkey |
957 | 957 | |
… |
… |
class ShellOwner(GenericOwner): |
965 | 965 | |
966 | 966 | GenericOwner.__init__(self, ps, bus, |
967 | 967 | 'keyid/' + psutils.pubkey_to_keyid(key), |
968 | | key=key, nick=nick, color=color, icon=icon, server=server, |
969 | | key_hash=key_hash) |
| 968 | key=key, nick=nick, color=color, icon=icon, key_hash=key_hash) |
970 | 969 | |
971 | 970 | # Ask to get notifications on Owner object property changes in the |
972 | 971 | # shell. If it's not currently running, no problem - we'll get the |
diff --git a/src/presenceservice.py b/src/presenceservice.py
index e68bded..84c3cc2 100644
a
|
b
|
class PresenceService(ExportedGObject): |
857 | 857 | if self._server_plugin is not None: |
858 | 858 | self._server_plugin.sync_friends(keys) |
859 | 859 | |
| 860 | @dbus.service.method(PRESENCE_INTERFACE, in_signature="", |
| 861 | out_signature="") |
| 862 | def RestartServerConnection(self): |
| 863 | """Stop and restart the server_plugin. |
| 864 | |
| 865 | This allows changing jabber servers without restarting Sugar. |
| 866 | """ |
| 867 | if self._server_plugin: |
| 868 | if self._server_plugin.status == CONNECTION_STATUS_CONNECTED: |
| 869 | self._server_plugin.cleanup() |
| 870 | self._server_plugin.start() |
| 871 | |
860 | 872 | def main(test_num=0, randomize=False): |
861 | 873 | loop = gobject.MainLoop() |
862 | 874 | DBusGMainLoop(set_as_default=True) |
diff --git a/src/telepathy_plugin.py b/src/telepathy_plugin.py
index 982f7cc..5aca07e 100644
a
|
b
|
class TelepathyPlugin(gobject.GObject): |
591 | 591 | |
592 | 592 | # Only init connection if we have a valid IP address |
593 | 593 | if self._could_connect(): |
| 594 | # Reread account info in case the server changed |
| 595 | self._account = self._get_account_info() |
594 | 596 | self._init_connection() |
595 | 597 | else: |
596 | 598 | _logger.debug('%r: Postponing connection', self) |