summaryrefslogtreecommitdiff
path: root/src/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/core.py')
-rw-r--r--src/core.py58
1 files changed, 46 insertions, 12 deletions
diff --git a/src/core.py b/src/core.py
index f5980af1..8e0d56ce 100644
--- a/src/core.py
+++ b/src/core.py
@@ -128,6 +128,7 @@ class Core(object):
'message': (self.command_message, _('Usage: /message <jid> [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 <jid>\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),
+ 'server_cycle': (self.command_server_cycle, _('Usage: /server_cycle [domain] [message]\nServer Cycle: disconnect and reconnects in all the rooms in domain.'), None),
}
self.key_func = {
@@ -682,7 +683,7 @@ class Core(object):
else:
self.command_win('%d' % nb)
# search for keyboard shortcut
- if char in list(self.key_func.keys()):
+ if char in self.key_func:
self.key_func[char]()
else:
self.do_command(char)
@@ -853,7 +854,7 @@ class Core(object):
code = error['error']['code']
body = error['error']['text']
if not body:
- if code in list(ERROR_AND_STATUS_CODES.keys()):
+ if code in ERROR_AND_STATUS_CODES:
body = ERROR_AND_STATUS_CODES[code]
else:
body = condition or _('Unknown error')
@@ -877,6 +878,11 @@ class Core(object):
"""
open a new conversation tab and focus it if needed
"""
+ for tab in self.tabs: # if the room exists, focus it and return
+ if isinstance(tab, tabs.ConversationTab):
+ if tab.get_name() == jid:
+ self.command_win('%s' % tab.nb)
+ return tab
new_tab = tabs.ConversationTab(jid)
# insert it in the rooms
self.add_tab(new_tab, focus)
@@ -945,8 +951,6 @@ class Core(object):
room_from = message.getMucroom()
if message['type'] == 'error': # Check if it's an error
return self.room_error(message, from_room)
- if nick_from == room_from:
- nick_from = None
room = self.get_room_by_name(room_from)
tab = self.get_tab_by_name(room_from, tabs.MucTab)
if tab and tab.get_room() and tab.get_room().get_user_by_name(nick_from) and\
@@ -980,15 +984,15 @@ class Core(object):
args = arg.split()
if len(args) == 0:
msg = _('Available commands are: ')
- for command in list(self.commands.keys()):
+ for command in self.commands:
msg += "%s " % command
- for command in list(self.current_tab().commands.keys()):
+ for command in self.current_tab().commands:
msg += "%s " % command
msg += _("\nType /help <command_name> to know what each command does")
if len(args) >= 1:
- if args[0] in list(self.commands.keys()):
+ if args[0] in self.commands:
msg = self.commands[args[0]][1]
- elif args[0] in list(self.current_tab().commands.keys()):
+ elif args[0] in self.current_tab().commands:
msg = self.current_tab().commands[args[0]][1]
else:
msg = _('Unknown command: %s') % args[0]
@@ -1024,7 +1028,7 @@ class Core(object):
self.set_status(show, msg)
def completion_status(self, the_input):
- return the_input.auto_completion([status for status in list(possible_show.keys())], ' ')
+ return the_input.auto_completion([status for status in possible_show], ' ')
def command_message(self, arg):
"""
@@ -1322,6 +1326,31 @@ class Core(object):
del tab
self.refresh_window()
+ def command_server_cycle(self, arg):
+ """
+ Do a /cycle on each room of the given server. If none, do it on the current tab
+ """
+ args = common.shell_split(arg)
+ tab = self.current_tab()
+ message = ""
+
+ if len(args):
+ domain = args[0]
+ if len(args) > 1:
+ message = args[1]
+ else:
+ if isinstance(tab, tabs.MucTab):
+ domain = JID(tab.get_name()).domain
+ else:
+ self.information(_("No server specified"), "Error")
+ return
+ for tab in self.tabs:
+ if isinstance(tab, tabs.MucTab) and JID(tab.get_name()).domain == domain:
+ if tab.get_room().joined:
+ muc.leave_groupchat(tab.core.xmpp, tab.get_name(), tab.get_room().own_nick, message)
+ tab.get_room().joined = False
+ self.command_join(tab.get_name())
+
def go_to_room_number(self):
"""
Read 2 more chars and go to the tab
@@ -1358,7 +1387,12 @@ class Core(object):
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)
+ # Ugly fix thanks to gmail servers
+ try:
+ sys.stderr = None
+ self.xmpp.disconnect(False)
+ except:
+ pass
def command_quit(self, arg):
"""
@@ -1430,12 +1464,12 @@ class Core(object):
command = line.strip()[:].split()[0][1:]
arg = line[2+len(command):] # jump the '/' and the ' '
# example. on "/link 0 open", command = "link" and arg = "0 open"
- if command in list(self.commands.keys()):
+ if command in self.commands:
func = self.commands[command][0]
func(arg)
return
else:
- self.information(_("unknown command (%s)") % (command), _('Error'))
+ self.information(_("Unknown command (%s)") % (command), _('Error'))
def doupdate(self):
if not self.running: