From cba3adcced7f6fa0670ba5012bcd59974c05ea09 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 20 Mar 2011 01:46:44 +0100 Subject: Command connect, to reconnect if needed. Fixed #1149 --- src/core.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/core.py b/src/core.py index 031c4127..803cbe38 100644 --- a/src/core.py +++ b/src/core.py @@ -120,6 +120,7 @@ class Core(object): 'list': (self.command_list, _('Usage: /list\nList: get the list of public chatrooms on the specified server'), self.completion_list), 'message': (self.command_message, _('Usage: /message [optional message]\nMessage: Open a conversation with the specified JID (even if it is not in our roster), and send a message to it, if specified'), None), 'version': (self.command_version, _('Usage: /version \nVersion: get the software version of the given JID (usually its XMPP client and Operating System)'), None), + 'connect': (self.command_reconnect, _('Usage: /connect\nConnect: disconnect from the remote server if you are currently connected and then connect to it again'), None), } self.key_func = { @@ -970,6 +971,12 @@ class Core(object): res.get('os') or _('on an unknown platform')) self.information(version) + def command_reconnect(self, args): + """ + /reconnect + """ + self.disconnect(True) + def command_list(self, arg): """ /list @@ -1247,6 +1254,17 @@ class Core(object): # TODO: refresh only the correct window in the current tab self.refresh_window() + def disconnect(self, msg=None): + """ + Disconnect from remote server and correctly set the states of all + parts of the client (for example, set the MucTabs as not joined, etc) + """ + for tab in self.tabs: + if isinstance(tab, tabs.MucTab): + muc.leave_groupchat(self.xmpp, tab.get_room().name, tab.get_room().own_nick, msg) + self.save_config() + self.xmpp.disconnect(False) + def command_quit(self, arg): """ /quit @@ -1255,11 +1273,7 @@ class Core(object): msg = arg else: msg = None - for tab in self.tabs: - if isinstance(tab, tabs.MucTab): - muc.leave_groupchat(self.xmpp, tab.get_room().name, tab.get_room().own_nick, msg) - self.save_config() - self.xmpp.disconnect() + self.disconnect(msg) self.running = False self.reset_curses() sys.exit() -- cgit v1.2.3