From 28ce49dcaaa1f7e958e09aff2af7d1e956796ad9 Mon Sep 17 00:00:00 2001 From: mathieui Date: Fri, 29 Jun 2018 21:18:09 +0200 Subject: Update poezio for the new tabs module --- poezio/core/commands.py | 123 +++++++++--------- poezio/core/completions.py | 17 +-- poezio/core/core.py | 302 +++++++++++++-------------------------------- poezio/core/handlers.py | 144 +++++++++++---------- 4 files changed, 230 insertions(+), 356 deletions(-) (limited to 'poezio/core') diff --git a/poezio/core/commands.py b/poezio/core/commands.py index 7d503fff..6e17c32c 100644 --- a/poezio/core/commands.py +++ b/poezio/core/commands.py @@ -53,7 +53,7 @@ class CommandCore: buff.extend(acc) acc = [] buff.append('Tab-specific commands:') - tab_commands = self.core.current_tab().commands + tab_commands = self.core.tabs.current_tab.commands for name, command in tab_commands.items(): if isinstance(command, Command): acc.append(' \x19%s}%s\x19o - %s' % (color, name, @@ -68,7 +68,7 @@ class CommandCore: else: command = args[0].lstrip('/').strip() - tab_commands = self.core.current_tab().commands + tab_commands = self.core.tabs.current_tab.commands if command in tab_commands: tup = tab_commands[command] elif command in self.core.commands: @@ -126,7 +126,7 @@ class CommandCore: pres['type'] = show self.core.events.trigger('send_normal_presence', pres) pres.send() - current = self.core.current_tab() + current = self.core.tabs.current_tab is_muctab = isinstance(current, tabs.MucTab) if is_muctab and current.joined and show in ('away', 'xa'): current.send_chat_state('inactive') @@ -149,8 +149,8 @@ class CommandCore: return self.help('presence') jid, ptype, status = args[0], args[1], args[2] - if jid == '.' and isinstance(self.core.current_tab(), tabs.ChatTab): - jid = self.core.current_tab().name + if jid == '.' and isinstance(self.core.tabs.current_tab, tabs.ChatTab): + jid = self.core.tabs.current_tab.name if ptype == 'available': ptype = None try: @@ -163,7 +163,7 @@ class CommandCore: log.debug( 'Could not send directed presence to %s', jid, exc_info=True) return - tab = self.core.get_tab_by_name(jid) + tab = self.core.tabs.by_name_and_class(jid) if tab: if ptype in ('xa', 'away'): tab.directed_presence = False @@ -171,13 +171,13 @@ class CommandCore: else: tab.directed_presence = True chatstate = 'active' - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: tab.send_chat_state(chatstate, True) if isinstance(tab, tabs.MucTab): for private in tab.privates: private.directed_presence = tab.directed_presence - if self.core.current_tab() in tab.privates: - self.core.current_tab().send_chat_state(chatstate, True) + if self.core.tabs.current_tab in tab.privates: + self.core.tabs.current_tab.send_chat_state(chatstate, True) @command_args_parser.quoted(1) def theme(self, args=None): @@ -200,33 +200,23 @@ class CommandCore: except ValueError: number = -1 name = name.lower() - if number != -1 and self.core.current_tab_nb == number: + if number != -1 and self.core.tabs.current_tab == number: return prev_nb = self.core.previous_tab_nb - self.core.previous_tab_nb = self.core.current_tab_nb - old_tab = self.core.current_tab() + self.core.previous_tab_nb = self.core.tabs.current_tab + old_tab = self.core.tabs.current_tab if 0 <= number < len(self.core.tabs): if not self.core.tabs[number]: self.core.previous_tab_nb = prev_nb return - self.core.current_tab_nb = number + self.core.tabs.set_current_index(number) else: - match = None - target_tabs = self.core.tabs[self.core.current_tab_nb+1:] \ - + self.core.tabs[:self.core.current_tab_nb] - for tab in target_tabs: - for tab_name in tab.matching_names(): - if tab_name[1] and name in tab_name[1].lower(): - match = tab - break - if match: - break + match = self.core.tabs.find_match(name) if match is None: - self.core.previous_tab_nb = prev_nb return - self.core.current_tab_nb = match.nb + self.core.tabs.set_current_tab(match) old_tab.on_lose_focus() - self.core.current_tab().on_gain_focus() + self.core.tabs.current_tab.on_gain_focus() self.core.refresh_window() @command_args_parser.quoted(2) @@ -237,7 +227,7 @@ class CommandCore: if args is None: return self.help('move_tab') - current_tab = self.core.current_tab() + current_tab = self.core.tabs.current_tab if args[0] == '.': args[0] = current_tab.nb if args[1] == '.': @@ -267,8 +257,6 @@ class CommandCore: result = self.core.insert_tab(old, new) if not result: self.core.information('Unable to move the tab.', 'Info') - else: - self.core.current_tab_nb = self.core.tabs.index(current_tab) self.core.refresh_window() @command_args_parser.quoted(0, 1) @@ -282,10 +270,10 @@ class CommandCore: elif args: jid = safeJID(args[0]) else: - if not isinstance(self.core.current_tab(), tabs.MucTab): + if not isinstance(self.core.tabs.current_tab, tabs.MucTab): return self.core.information('Please provide a server', 'Error') - jid = safeJID(self.core.current_tab().name) + jid = safeJID(self.core.tabs.current_tab.name) list_tab = tabs.MucListTab(self.core, jid) self.core.add_tab(list_tab, True) cb = list_tab.on_muc_list_item_received @@ -308,7 +296,7 @@ class CommandCore: resource.jid, callback=self.core.handler.on_version_result) def _empty_join(self): - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if not isinstance(tab, (tabs.MucTab, tabs.PrivateTab)): return (None, None) room = safeJID(tab.name).bare @@ -332,7 +320,7 @@ class CommandCore: # happens with /join /nickname, which is OK if info.bare == '': - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if not isinstance(tab, tabs.MucTab): room, set_nick = (None, None) else: @@ -345,7 +333,7 @@ class CommandCore: # use the server of the current room if available # check if the current room's name has a server if room.find('@') == -1 and not server_root: - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if isinstance(tab, tabs.MucTab): if tab.name.find('@') != -1: domain = safeJID(tab.name).domain @@ -377,13 +365,13 @@ class CommandCore: if room in self.core.pending_invites: del self.core.pending_invites[room] - tab = self.core.get_tab_by_name(room, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room, tabs.MucTab) # New tab if tab is None: tab = self.core.open_new_room(room, nick, password=password) tab.join() else: - self.core.focus_tab_named(tab.name) + self.core.focus_tab(tab) if tab.own_nick == nick and tab.joined: self.core.information('/join: Nothing to do.', 'Info') else: @@ -397,7 +385,7 @@ class CommandCore: 'use_remote_bookmarks') else 'local' self._add_bookmark('%s/%s' % (room, nick), True, password, method) - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: tab.refresh() self.core.doupdate() @@ -406,7 +394,8 @@ class CommandCore: """ /bookmark_local [room][/nick] [password] """ - if not args and not isinstance(self.core.current_tab(), tabs.MucTab): + if not args and not isinstance(self.core.tabs.current_tab, + tabs.MucTab): return password = args[1] if len(args) > 1 else None jid = args[0] if args else None @@ -418,7 +407,8 @@ class CommandCore: """ /bookmark [room][/nick] [autojoin] [password] """ - if not args and not isinstance(self.core.current_tab(), tabs.MucTab): + if not args and not isinstance(self.core.tabs.current_tab, + tabs.MucTab): return jid = args[0] if args else '' password = args[2] if len(args) > 2 else None @@ -436,7 +426,7 @@ class CommandCore: def _add_bookmark(self, jid, autojoin, password, method): nick = None if not jid: - tab = self.core.current_tab() + tab = self.core.tabs.current_tab roomname = tab.name if tab.joined and tab.own_nick != self.core.own_nick: nick = tab.own_nick @@ -448,7 +438,7 @@ class CommandCore: info = safeJID(jid) roomname, nick = info.bare, info.resource if roomname == '': - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if not isinstance(tab, tabs.MucTab): return roomname = tab.name @@ -499,14 +489,14 @@ class CommandCore: @command_args_parser.ignored def bookmarks(self): """/bookmarks""" - tab = self.core.get_tab_by_name('Bookmarks', tabs.BookmarksTab) - old_tab = self.core.current_tab() + tab = self.core.tabs.by_name_and_class('Bookmarks', tabs.BookmarksTab) + old_tab = self.core.tabs.current_tab if tab: - self.core.current_tab_nb = tab.nb + self.core.tabs.set_current_tab(tab) else: tab = tabs.BookmarksTab(self.core, self.core.bookmarks) self.core.tabs.append(tab) - self.core.current_tab_nb = tab.nb + self.core.tabs.set_current_tab(tab) old_tab.on_lose_focus() tab.on_gain_focus() self.core.refresh_window() @@ -523,7 +513,7 @@ class CommandCore: 'Error') if not args: - tab = self.core.current_tab() + tab = self.core.tabs.current_tab if isinstance(tab, tabs.MucTab) and self.core.bookmarks[tab.name]: self.core.bookmarks.remove(tab.name) self.core.bookmarks.save(self.core.xmpp, callback=cb) @@ -553,10 +543,10 @@ class CommandCore: theme.COLOR_INFORMATION_TEXT), }) for option_name, option_value in section.items(): - lines.append('%s\x19%s}=\x19o%s' % - (option_name, - dump_tuple(theme.COLOR_REVISIONS_MESSAGE), - option_value)) + lines.append( + '%s\x19%s}=\x19o%s' % + (option_name, dump_tuple( + theme.COLOR_REVISIONS_MESSAGE), option_value)) info = ('Current options:\n%s' % '\n'.join(lines), 'Info') elif len(args) == 1: option = args[0] @@ -608,7 +598,7 @@ class CommandCore: info = plugin_config.set_and_save(option, value, section) else: if args[0] == '.': - name = safeJID(self.core.current_tab().name).bare + name = safeJID(self.core.tabs.current_tab.name).bare if not name: self.core.information( 'Invalid tab to use the "." argument.', 'Error') @@ -662,7 +652,7 @@ class CommandCore: Do a /cycle on each room of the given server. If none, do it on the current tab """ - tab = self.core.current_tab() + tab = self.core.tabs.current_tab message = "" if args: domain = args[0] @@ -688,8 +678,9 @@ class CommandCore: "Callback for the last activity" if iq['type'] != 'result': if iq['error']['type'] == 'auth': - self.core.information('You are not allowed to see the ' - 'activity of this contact.', 'Error') + self.core.information( + 'You are not allowed to see the ' + 'activity of this contact.', 'Error') else: self.core.information('Error retrieving the activity', 'Error') @@ -756,8 +747,9 @@ class CommandCore: specific = args[1] text = args[2] if specific and specific not in pep.ACTIVITIES[general]: - return self.core.information('%s is not a correct value ' - 'for an activity' % specific, 'Error') + return self.core.information( + '%s is not a correct value ' + 'for an activity' % specific, 'Error') self.core.xmpp.plugin['xep_0108'].publish_activity( general, specific, text, callback=dumb_callback) @@ -849,9 +841,10 @@ class CommandCore: room = safeJID(args[0]).bare if room: muc.destroy_room(self.core.xmpp, room) - elif isinstance(self.core.current_tab(), tabs.MucTab) and not args[0]: + elif isinstance(self.core.tabs.current_tab, + tabs.MucTab) and not args[0]: muc.destroy_room(self.core.xmpp, - self.core.current_tab().general_jid) + self.core.tabs.current_tab.general_jid) else: self.core.information('Invalid JID: "%s"' % args[0], 'Error') @@ -931,8 +924,9 @@ class CommandCore: """ /plugins """ - self.core.information("Plugins currently in use: %s" % repr( - list(self.core.plugin_manager.plugins.keys())), 'Info') + self.core.information( + "Plugins currently in use: %s" % repr( + list(self.core.plugin_manager.plugins.keys())), 'Info') @command_args_parser.quoted(1, 1) def message(self, args): @@ -946,20 +940,21 @@ class CommandCore: return self.core.information('Invalid JID.', 'Error') tab = self.core.get_conversation_by_jid( jid.full, False, fallback_barejid=False) - muc = self.core.get_tab_by_name(jid.bare, typ=tabs.MucTab) + muc = self.core.tabs.by_name_and_class(jid.bare, typ=tabs.MucTab) if not tab and not muc: tab = self.core.open_conversation_window(jid.full, focus=True) elif muc: if jid.resource: - tab = self.core.get_tab_by_name(jid.full, typ=tabs.PrivateTab) + tab = self.core.tabs.by_name_and_class( + jid.full, typ=tabs.PrivateTab) if tab: - self.core.focus_tab_named(tab.name) + self.core.focus_tab(tab) else: tab = self.core.open_private_window(jid.bare, jid.resource) else: tab = muc else: - self.core.focus_tab_named(tab.name) + self.core.focus_tab(tab) if len(args) == 2: tab.command_say(args[1]) diff --git a/poezio/core/completions.py b/poezio/core/completions.py index c86e3514..331ab553 100644 --- a/poezio/core/completions.py +++ b/poezio/core/completions.py @@ -25,7 +25,7 @@ class CompletionCore: def help(self, the_input): """Completion for /help.""" commands = sorted(self.core.commands.keys()) + sorted( - self.core.current_tab().commands.keys()) + self.core.tabs.current_tab.commands.keys()) return Completion(the_input.new_completion, commands, 1, quotify=False) def status(self, the_input): @@ -47,7 +47,8 @@ class CompletionCore: if arg == 1: to_suggest = [] for bookmark in self.core.bookmarks: - tab = self.core.get_tab_by_name(bookmark.jid, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(bookmark.jid, + tabs.MucTab) if tab is not None and tab.joined: to_suggest.append(bookmark.jid) return Completion( @@ -121,7 +122,7 @@ class CompletionCore: for elem in self.core.bookmarks] to_suggest = [] for bookmark in bookmarks: - tab = self.core.get_tab_by_name(bookmark, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(bookmark, tabs.MucTab) if not tab or (tab and not tab.joined): to_suggest.append(bookmark) relevant_rooms.extend(sorted(to_suggest)) @@ -134,8 +135,8 @@ class CompletionCore: serv_list = [] for tab in self.core.get_tabs(tabs.MucTab): if tab.joined: - serv_list.append('%s@%s' % (jid.user, - safeJID(tab.name).host)) + serv_list.append( + '%s@%s' % (jid.user, safeJID(tab.name).host)) serv_list.extend(relevant_rooms) return Completion( the_input.new_completion, serv_list, 1, quotify=True) @@ -183,7 +184,7 @@ class CompletionCore: """ list_ = [] list_.extend(self.core.key_func.keys()) - list_.extend(self.core.current_tab().key_func.keys()) + list_.extend(self.core.tabs.current_tab.key_func.keys()) return Completion(the_input.new_completion, list_, 1, quotify=False) def bookmark(self, the_input): @@ -202,7 +203,7 @@ class CompletionCore: jid = safeJID(args[1]) if jid.server and (jid.resource or jid.full.endswith('/')): - tab = self.core.get_tab_by_name(jid.bare, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get( 'USER') else 'poezio' @@ -434,7 +435,7 @@ class CompletionCore: jid = safeJID(args[1]) if jid.server and (jid.resource or jid.full.endswith('/')): - tab = self.core.get_tab_by_name(jid.bare, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get( 'USER') else 'poezio' diff --git a/poezio/core/core.py b/poezio/core/core.py index b708e2cf..814f7813 100644 --- a/poezio/core/core.py +++ b/poezio/core/core.py @@ -44,6 +44,7 @@ from poezio.theming import get_theme from poezio import keyboard from poezio.core.completions import CompletionCore +from poezio.core.tabs import Tabs from poezio.core.commands import CommandCore from poezio.core.handlers import HandlerCore from poezio.core.structs import POSSIBLE_SHOW, DEPRECATED_ERRORS, \ @@ -77,7 +78,8 @@ class Core(object): self.bookmarks = BookmarkList() self.debug = False self.remote_fifo = None - self.avatar_cache = FileSystemPerJidCache(CACHE_DIR, 'avatars', binary=True) + self.avatar_cache = FileSystemPerJidCache( + CACHE_DIR, 'avatars', binary=True) # a unique buffer used to store global information # that are displayed in almost all tabs, in an # information window. @@ -93,8 +95,7 @@ class Core(object): self.xml_tab = None self.xml_buffer = TextBuffer() - self.tabs = [] - self._current_tab_nb = 0 + self.tabs = Tabs() self.previous_tab_nb = 0 own_nick = config.get('default_nick') @@ -397,8 +398,7 @@ class Core(object): Called when the option create_gaps is changed. Remove all gaptabs if switching from gaps to nogaps. """ - if value.lower() == "false": - self.tabs = [tab for tab in self.tabs if tab] + self.tabs.update_gaps(value.lower() == "false") def on_request_receipts_config_change(self, option, value): """ @@ -662,7 +662,7 @@ class Core(object): except ValueError: pass else: - if self.current_tab().nb == nb and config.get( + if self.tabs.current_tab.nb == nb and config.get( 'go_to_previous_tab_on_alt_number'): self.go_to_previous_tab() else: @@ -687,8 +687,9 @@ class Core(object): ok = ok and config.silent_set('info_win_height', self.information_win_size, 'var') if not ok: - self.information('Unable to save runtime preferences' - ' in the config file', 'Error') + self.information( + 'Unable to save runtime preferences' + ' in the config file', 'Error') def on_roster_enter_key(self, roster_row): """ @@ -715,9 +716,9 @@ class Core(object): Messages are namedtuples of the form ('txt nick_color time str_time nickname user') """ - if not isinstance(self.current_tab(), tabs.ChatTab): + if not isinstance(self.tabs.current_tab, tabs.ChatTab): return None - return self.current_tab().get_conversation_messages() + return self.tabs.current_tab.get_conversation_messages() def insert_input_text(self, text): """ @@ -784,8 +785,9 @@ class Core(object): 'Could not open the fifo for writing (%s)', os.path.join(fifo_path, './', 'poezio.fifo'), exc_info=True) - self.information('Could not open the fifo ' - 'file for writing: %s' % exc, 'Error') + self.information( + 'Could not open the fifo ' + 'file for writing: %s' % exc, 'Error') return args = (pipes.quote(arg.replace('\n', ' ')) for arg in command) @@ -829,7 +831,7 @@ class Core(object): keyboard.continuation_keys_callback = None cb(key) else: - self.current_tab().on_input(key, raw) + self.tabs.current_tab.on_input(key, raw) def try_execute(self, line): """ @@ -837,7 +839,7 @@ class Core(object): """ line = '/' + line try: - self.current_tab().execute_command(line) + self.tabs.current_tab.execute_command(line) except: log.error('Execute failed (%s)', line, exc_info=True) @@ -872,8 +874,9 @@ class Core(object): msg = msg.replace('\n', '|') if msg else '' ok = ok and config.silent_set('status_message', msg) if not ok: - self.information('Unable to save the status in ' - 'the config file', 'Error') + self.information( + 'Unable to save the status in ' + 'the config file', 'Error') def get_bookmark_nickname(self, room_name): """ @@ -909,9 +912,9 @@ class Core(object): conversation. Returns False if the current tab is not a conversation tab """ - if not isinstance(self.current_tab(), tabs.ChatTab): + if not isinstance(self.tabs.current_tab, tabs.ChatTab): return False - self.current_tab().command_say(msg) + self.tabs.current_tab.command_say(msg) return True def invite(self, jid, room, reason=None): @@ -977,15 +980,8 @@ class Core(object): def get_tabs(self, cls=None): "Get all the tabs of a type" if cls is None: - cls = tabs.Tab - return [tab for tab in self.tabs if isinstance(tab, cls)] - - def current_tab(self): - """ - returns the current room, the one we are viewing - """ - self.current_tab_nb = self.current_tab_nb - return self.tabs[self.current_tab_nb] + return self.tabs.get_tabs() + return self.tabs.by_class(cls) def get_conversation_by_jid(self, jid, create=True, fallback_barejid=True): """ @@ -999,16 +995,16 @@ class Core(object): jid = safeJID(jid) # We first check if we have a static conversation opened # with this precise resource - conversation = self.get_tab_by_name(jid.full, - tabs.StaticConversationTab) + conversation = self.tabs.by_name_and_class(jid.full, + tabs.StaticConversationTab) if jid.bare == jid.full and not conversation: - conversation = self.get_tab_by_name(jid.full, - tabs.DynamicConversationTab) + conversation = self.tabs.by_name_and_class( + jid.full, tabs.DynamicConversationTab) if not conversation and fallback_barejid: # If not, we search for a conversation with the bare jid - conversation = self.get_tab_by_name(jid.bare, - tabs.DynamicConversationTab) + conversation = self.tabs.by_name_and_class( + jid.bare, tabs.DynamicConversationTab) if not conversation: if create: # We create a dynamic conversation with the bare Jid if @@ -1020,23 +1016,6 @@ class Core(object): conversation = None return conversation - def get_tab_by_name(self, name, typ=None): - """ - Get the tab with the given name. - If typ is provided, return a tab of this type only - """ - for tab in self.tabs: - if tab.name == name: - if (typ and isinstance(tab, typ)) or\ - not typ: - return tab - return None - - def get_tab_by_number(self, number): - if 0 <= number < len(self.tabs): - return self.tabs[number] - return None - def add_tab(self, new_tab, focus=False): """ Appends the new_tab in the tab list and @@ -1046,82 +1025,12 @@ class Core(object): if focus: self.command.win("%s" % new_tab.nb) - def insert_tab_nogaps(self, old_pos, new_pos): - """ - Move tabs without creating gaps - old_pos: old position of the tab - new_pos: desired position of the tab - """ - tab = self.tabs[old_pos] - if new_pos < old_pos: - self.tabs.pop(old_pos) - self.tabs.insert(new_pos, tab) - elif new_pos > old_pos: - self.tabs.insert(new_pos, tab) - self.tabs.remove(tab) - else: - return False - return True - - def insert_tab_gaps(self, old_pos, new_pos): - """ - Move tabs and create gaps in the eventual remaining space - old_pos: old position of the tab - new_pos: desired position of the tab - """ - tab = self.tabs[old_pos] - target = None if new_pos >= len(self.tabs) else self.tabs[new_pos] - if not target: - if new_pos < len(self.tabs): - old_tab = self.tabs[old_pos] - self.tabs[new_pos], self.tabs[old_pos] = old_tab, tabs.GapTab( - self) - else: - self.tabs.append(self.tabs[old_pos]) - self.tabs[old_pos] = tabs.GapTab(self) - else: - if new_pos > old_pos: - self.tabs.insert(new_pos, tab) - self.tabs[old_pos] = tabs.GapTab(self) - elif new_pos < old_pos: - self.tabs[old_pos] = tabs.GapTab(self) - self.tabs.insert(new_pos, tab) - else: - return False - i = self.tabs.index(tab) - done = False - # Remove the first Gap on the right in the list - # in order to prevent global shifts when there is empty space - while not done: - i += 1 - if i >= len(self.tabs): - done = True - elif not self.tabs[i]: - self.tabs.pop(i) - done = True - # Remove the trailing gaps - i = len(self.tabs) - 1 - while isinstance(self.tabs[i], tabs.GapTab): - self.tabs.pop() - i -= 1 - return True - def insert_tab(self, old_pos, new_pos=99999): """ Insert a tab at a position, changing the number of the following tabs returns False if it could not move the tab, True otherwise """ - if old_pos <= 0 or old_pos >= len(self.tabs): - return False - elif new_pos <= 0: - return False - elif new_pos == old_pos: - return False - elif not self.tabs[old_pos]: - return False - if config.get('create_gaps'): - return self.insert_tab_gaps(old_pos, new_pos) - return self.insert_tab_nogaps(old_pos, new_pos) + self.tabs.insert_tab(old_pos, new_pos, config.get('create_gaps')) ### Move actions (e.g. go to next room) ### @@ -1129,22 +1038,18 @@ class Core(object): """ rotate the rooms list to the right """ - self.current_tab().on_lose_focus() - self.current_tab_nb += 1 - while not self.tabs[self.current_tab_nb]: - self.current_tab_nb += 1 - self.current_tab().on_gain_focus() + self.tabs.current_tab.on_lose_focus() + self.tabs.next() + self.tabs.current_tab.on_gain_focus() self.refresh_window() def rotate_rooms_left(self, args=None): """ rotate the rooms list to the right """ - self.current_tab().on_lose_focus() - self.current_tab_nb -= 1 - while not self.tabs[self.current_tab_nb]: - self.current_tab_nb -= 1 - self.current_tab().on_gain_focus() + self.tabs.current_tab.on_lose_focus() + self.tabs.prev() + self.tabs.current_tab.on_gain_focus() self.refresh_window() def go_to_room_number(self): @@ -1190,7 +1095,7 @@ class Core(object): priority = tabs.STATE_PRIORITY tab_refs = {} # put all the active tabs in a dict of lists by state - for tab in self.tabs: + for tab in self.tabs.get_tabs(): if not tab: continue if tab.state not in tab_refs: @@ -1204,8 +1109,8 @@ class Core(object): for state in states: for tab in tab_refs[state]: - if (tab.nb < self.current_tab_nb - and tab_refs[state][-1].nb > self.current_tab_nb): + if (tab.nb < self.tabs.current_tab_intex and + tab_refs[state][-1].nb > self.tabs.current_tab_index): continue self.command.win(str(tab.nb)) return @@ -1213,33 +1118,14 @@ class Core(object): def focus_tab_named(self, tab_name, type_=None): """Returns True if it found a tab to focus on""" - for tab in self.tabs: - if tab.name == tab_name: - if (type_ and (isinstance(tab, type_))) or not type_: - self.command.win(str(tab.nb)) - return True - return False - - @property - def current_tab_nb(self): - """Wrapper for the current tab number""" - return self._current_tab_nb - - @current_tab_nb.setter - def current_tab_nb(self, value): - """ - Prevents the tab number from going over the total number of opened - tabs, or under 0 - """ - old = self._current_tab_nb - if value >= len(self.tabs): - self._current_tab_nb = 0 - elif value < 0: - self._current_tab_nb = len(self.tabs) - 1 + if type_ is None: + tab = self.tabs.by_name(tab_name) else: - self._current_tab_nb = value - if old != self._current_tab_nb and self.tabs[self._current_tab_nb]: - self.events.trigger('tab_change', old, self._current_tab_nb) + tab = self.tabs.by_name_and_class(tab_name, type_) + if tab: + self.command_win(str(tab.nb)) + return True + return False ### Opening actions ### @@ -1270,7 +1156,7 @@ class Core(object): self.command.win(str(tab.nb)) return tab # create the new tab - tab = self.get_tab_by_name(room_name, tabs.MucTab) + tab = self.tabs.by_name_and_class(room_name, tabs.MucTab) if not tab: return None new_tab = tabs.PrivateTab(self, complete_jid, tab.own_nick) @@ -1310,8 +1196,8 @@ class Core(object): this updates the name of all the opened private conversations with him/her """ - tab = self.get_tab_by_name('%s/%s' % (room_name, old_nick), - tabs.PrivateTab) + tab = self.tabs.by_name_and_class('%s/%s' % (room_name, old_nick), + tabs.PrivateTab) if tab: tab.rename_user(old_nick, user) @@ -1321,8 +1207,8 @@ class Core(object): The user left the MUC: add a message in the associated private conversation """ - tab = self.get_tab_by_name('%s/%s' % (room_name, user.nick), - tabs.PrivateTab) + tab = self.tabs.by_name_and_class('%s/%s' % (room_name, user.nick), + tabs.PrivateTab) if tab: tab.user_left(status_message, user) @@ -1331,8 +1217,8 @@ class Core(object): The user joined a MUC: add a message in the associated private conversation """ - tab = self.get_tab_by_name('%s/%s' % (room_name, nick), - tabs.PrivateTab) + tab = self.tabs.by_name_and_class('%s/%s' % (room_name, nick), + tabs.PrivateTab) if tab: tab.user_rejoined(nick) @@ -1357,7 +1243,7 @@ class Core(object): tab.activate(reason=reason) def on_user_changed_status_in_private(self, jid, status): - tab = self.get_tab_by_name(jid, tabs.ChatTab) + tab = self.tabs.by_name_and_class(jid, tabs.ChatTab) if tab is not None: # display the message in private tab.update_status(status) @@ -1367,35 +1253,16 @@ class Core(object): """ was_current = tab is None if tab is None: - tab = self.current_tab() + tab = self.tabs.current_tab if isinstance(tab, tabs.RosterInfoTab): return # The tab 0 should NEVER be closed tab.on_close() del tab.key_func # Remove self references del tab.commands # and make the object collectable - nb = tab.nb - if was_current: - if self.previous_tab_nb != nb: - self.current_tab_nb = self.previous_tab_nb - self.previous_tab_nb = 0 - if config.get('create_gaps'): - if nb >= len(self.tabs) - 1: - self.tabs.remove(tab) - nb -= 1 - while not self.tabs[nb]: # remove the trailing gaps - self.tabs.pop() - nb -= 1 - else: - self.tabs[nb] = tabs.GapTab(self) - else: - self.tabs.remove(tab) + self.tabs.delete(tab, gap=config.get('create_gaps')) logger.close(tab.name) - if self.current_tab_nb >= len(self.tabs): - self.current_tab_nb = len(self.tabs) - 1 - while not self.tabs[self.current_tab_nb]: - self.current_tab_nb -= 1 if was_current: - self.current_tab().on_gain_focus() + self.tabs.current_tab.on_gain_focus() self.refresh_window() import gc gc.collect() @@ -1408,10 +1275,10 @@ class Core(object): Search for a ConversationTab with the given jid (full or bare), if yes, add the given message to it """ - tab = self.get_tab_by_name(jid, tabs.ConversationTab) + tab = self.tabs.by_name_and_class(jid, tabs.ConversationTab) if tab is not None: tab.add_message(msg, typ=2) - if self.current_tab() is tab: + if self.tabs.current_tab is tab: self.refresh_window() ####################### Curses and ui-related stuff ########################### @@ -1444,7 +1311,7 @@ class Core(object): nb_lines = self.information_buffer.add_message( msg, nickname=typ, nick_color=color) popup_on = config.get('information_buffer_popup_on').split() - if isinstance(self.current_tab(), tabs.RosterInfoTab): + if isinstance(self.tabs.current_tab, tabs.RosterInfoTab): self.refresh_window() elif typ != '' and typ.lower() in popup_on: popup_time = config.get('popup_time') + (nb_lines - 1) * 2 @@ -1452,7 +1319,7 @@ class Core(object): else: if self.information_win_size != 0: self.information_win.refresh() - self.current_tab().refresh_input() + self.tabs.current_tab.refresh_input() return True def _init_curses(self, stdscr): @@ -1486,8 +1353,8 @@ class Core(object): Refresh everything """ nocursor = curses.curs_set(0) - self.current_tab().state = 'current' - self.current_tab().refresh() + self.tabs.current_tab.state = 'current' + self.tabs.current_tab.refresh() self.doupdate() curses.curs_set(nocursor) @@ -1495,7 +1362,7 @@ class Core(object): """ Refresh the window containing the tab list """ - self.current_tab().refresh_tab_win() + self.tabs.current_tab.refresh_tab_win() self.refresh_input() self.doupdate() @@ -1503,8 +1370,8 @@ class Core(object): """ Refresh the input if it exists """ - if self.current_tab().input: - self.current_tab().input.refresh() + if self.tabs.current_tab.input: + self.tabs.current_tab.input.refresh() self.doupdate() def scroll_page_down(self): @@ -1512,7 +1379,7 @@ class Core(object): Scroll a page down, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_scroll_down(): + if self.tabs.current_tab.on_scroll_down(): self.refresh_window() return True @@ -1521,7 +1388,7 @@ class Core(object): Scroll a page up, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_scroll_up(): + if self.tabs.current_tab.on_scroll_up(): self.refresh_window() return True @@ -1530,7 +1397,7 @@ class Core(object): Scroll a line up, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_line_up(): + if self.tabs.current_tab.on_line_up(): self.refresh_window() return True @@ -1539,7 +1406,7 @@ class Core(object): Scroll a line down, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_line_down(): + if self.tabs.current_tab.on_line_down(): self.refresh_window() return True @@ -1548,7 +1415,7 @@ class Core(object): Scroll half a screen down, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_half_scroll_up(): + if self.tabs.current_tab.on_half_scroll_up(): self.refresh_window() return True @@ -1557,7 +1424,7 @@ class Core(object): Scroll half a screen down, if possible. Returns True on success, None on failure. """ - if self.current_tab().on_half_scroll_down(): + if self.tabs.current_tab.on_half_scroll_down(): self.refresh_window() return True @@ -1565,8 +1432,8 @@ class Core(object): """ Expand the information win a number of lines """ - if self.information_win_size >= self.current_tab().height -5 or \ - self.information_win_size+nb >= self.current_tab().height-4 or\ + if self.information_win_size >= self.tabs.current_tab.height -5 or \ + self.information_win_size+nb >= self.tabs.current_tab.height-4 or\ self.size.core_degrade_y: return 0 self.information_win_size += nb @@ -1595,10 +1462,10 @@ class Core(object): Scroll the information buffer up """ self.information_win.scroll_up(self.information_win.height) - if not isinstance(self.current_tab(), tabs.RosterInfoTab): + if not isinstance(self.tabs.current_tab, tabs.RosterInfoTab): self.information_win.refresh() else: - info = self.current_tab().information_win + info = self.tabs.current_tab.information_win info.scroll_up(info.height) self.refresh_window() @@ -1607,10 +1474,10 @@ class Core(object): Scroll the information buffer down """ self.information_win.scroll_down(self.information_win.height) - if not isinstance(self.current_tab(), tabs.RosterInfoTab): + if not isinstance(self.tabs.current_tab, tabs.RosterInfoTab): self.information_win.refresh() else: - info = self.current_tab().information_win + info = self.tabs.current_tab.information_win info.scroll_down(info.height) self.refresh_window() @@ -1717,7 +1584,8 @@ class Core(object): tab.need_resize = True else: tab.resize() - if self.tabs: + + if len(self.tabs): self.full_screen_redraw() def read_keyboard(self): @@ -2057,7 +1925,7 @@ class Core(object): for bm in bookmarks: if not (bm.autojoin or config.get('open_all_bookmarks')): continue - tab = self.get_tab_by_name(bm.jid, tabs.MucTab) + tab = self.tabs.by_name_and_class(bm.jid, tabs.MucTab) nick = bm.nick if bm.nick else self.own_nick if not tab: self.open_new_room( @@ -2085,9 +1953,9 @@ class Core(object): type_ = iq['error']['type'] condition = iq['error']['condition'] if not (type_ == 'cancel' and condition == 'item-not-found'): - self.information('Unable to fetch the remote' - ' bookmarks; %s: %s' % (type_, condition), - 'Error') + self.information( + 'Unable to fetch the remote' + ' bookmarks; %s: %s' % (type_, condition), 'Error') return remote_bookmarks = self.bookmarks.remote() self.join_initial_rooms(remote_bookmarks) @@ -2100,7 +1968,7 @@ class Core(object): """ Display the error in the tab """ - tab = self.get_tab_by_name(room_name, tabs.MucTab) + tab = self.tabs.by_name_and_class(room_name, tabs.MucTab) if not tab: return error_message = self.get_error_message(error) diff --git a/poezio/core/handlers.py b/poezio/core/handlers.py index d34534d0..0f84e69c 100644 --- a/poezio/core/handlers.py +++ b/poezio/core/handlers.py @@ -85,7 +85,8 @@ class HandlerCore: if not iq: return features = iq['disco_info']['features'] - rostertab = self.core.get_tab_by_name('Roster', tabs.RosterInfoTab) + rostertab = self.core.tabs.by_name_and_class( + 'Roster', tabs.RosterInfoTab) rostertab.check_blocking(features) rostertab.check_saslexternal(features) if (config.get('enable_carbons') @@ -138,8 +139,9 @@ class HandlerCore: sent = message['carbon_sent'] # todo: implement proper MUC detection logic - if (sent['to'].resource and (sent['to'].bare not in roster - or roster[sent['to'].bare].subscription == 'none')): + if (sent['to'].resource + and (sent['to'].bare not in roster + or roster[sent['to'].bare].subscription == 'none')): fixes.has_identity( self.core.xmpp, sent['to'].server, @@ -243,8 +245,8 @@ class HandlerCore: self.core.room_error(message, jid_from.bare) else: text = self.core.get_error_message(message) - p_tab = self.core.get_tab_by_name(jid_from.full, - tabs.PrivateTab) + p_tab = self.core.tabs.by_name_and_class( + jid_from.full, tabs.PrivateTab) if p_tab: p_tab.add_error(text) else: @@ -372,7 +374,7 @@ class HandlerCore: if not own and 'private' in config.get('beep_on').split(): if not config.get_by_tabname('disable_beep', conv_jid.bare): curses.beep() - if self.core.current_tab() is not conversation: + if self.core.tabs.current_tab is not conversation: if not own: conversation.state = 'private' self.core.refresh_tab_win() @@ -399,7 +401,8 @@ class HandlerCore: avatar_hash = info['id'] # First check whether we have it in cache. - cached_avatar = self.core.avatar_cache.retrieve_by_jid(jid, avatar_hash) + cached_avatar = self.core.avatar_cache.retrieve_by_jid( + jid, avatar_hash) if cached_avatar: contact.avatar = cached_avatar log.debug('Using cached avatar for %s', jid) @@ -425,7 +428,8 @@ class HandlerCore: log.debug('Received %s avatar: %s', jid, info['type']) # Now we save the data on the file system to not have to request it again. - if not self.core.avatar_cache.store_by_jid(jid, avatar_hash, contact.avatar): + if not self.core.avatar_cache.store_by_jid( + jid, avatar_hash, contact.avatar): log.debug( 'Failed writing %s’s avatar to cache:', jid, @@ -442,7 +446,8 @@ class HandlerCore: log.debug('Received vCard avatar update from %s: %s', jid, avatar_hash) # First check whether we have it in cache. - cached_avatar = self.core.avatar_cache.retrieve_by_jid(jid, avatar_hash) + cached_avatar = self.core.avatar_cache.retrieve_by_jid( + jid, avatar_hash) if cached_avatar: contact.avatar = cached_avatar log.debug('Using cached avatar for %s', jid) @@ -463,8 +468,10 @@ class HandlerCore: log.debug('Received %s avatar: %s', jid, avatar['TYPE']) # Now we save the data on the file system to not have to request it again. - if not self.core.avatar_cache.store_by_jid(jid, avatar_hash, contact.avatar): - log.debug('Failed writing %s’s avatar to cache:', jid, exc_info=True) + if not self.core.avatar_cache.store_by_jid(jid, avatar_hash, + contact.avatar): + log.debug( + 'Failed writing %s’s avatar to cache:', jid, exc_info=True) def on_nick_received(self, message): """ @@ -514,9 +521,9 @@ class HandlerCore: 'display_gaming_notifications', contact.bare_jid): if contact.gaming: self.core.information( - '%s is playing %s' % - (contact.bare_jid, - common.format_gaming_string(contact.gaming)), 'Gaming') + '%s is playing %s' % (contact.bare_jid, + common.format_gaming_string( + contact.gaming)), 'Gaming') else: self.core.information(contact.bare_jid + ' stopped playing.', 'Gaming') @@ -597,8 +604,9 @@ class HandlerCore: if old_activity != contact.activity and config.get_by_tabname( 'display_activity_notifications', contact.bare_jid): if contact.activity: - self.core.information('Activity from ' + contact.bare_jid + - ': ' + contact.activity, 'Activity') + self.core.information( + 'Activity from ' + contact.bare_jid + ': ' + + contact.activity, 'Activity') else: self.core.information( contact.bare_jid + ' stopped doing his/her activity.', @@ -630,9 +638,9 @@ class HandlerCore: contact.tune = {} if contact.tune: - logger.log_roster_change(message['from'].bare, - 'is now listening to %s' % - common.format_tune_string(contact.tune)) + logger.log_roster_change( + message['from'].bare, 'is now listening to %s' % + common.format_tune_string(contact.tune)) if old_tune != contact.tune and config.get_by_tabname( 'display_tune_notifications', contact.bare_jid): @@ -656,7 +664,7 @@ class HandlerCore: self.core.room_error(message, room_from) return - tab = self.core.get_tab_by_name(room_from, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room_from, tabs.MucTab) if not tab: self.core.information( "message received for a non-existing room: %s" % (room_from)) @@ -714,14 +722,14 @@ class HandlerCore: if message['from'].resource == tab.own_nick: tab.last_sent_message = message - if tab is self.core.current_tab(): + if tab is self.core.tabs.current_tab: tab.text_win.refresh() tab.info_header.refresh(tab, tab.text_win, user=tab.own_user) tab.input.refresh() self.core.doupdate() elif tab.state != old_state: self.core.refresh_tab_win() - current = self.core.current_tab() + current = self.core.tabs.current_tab if hasattr(current, 'input') and current.input: current.input.refresh() self.core.doupdate() @@ -756,7 +764,7 @@ class HandlerCore: use_xhtml=use_xhtml, tmp_dir=tmp_dir, extract_images=extract_images) - tab = self.core.get_tab_by_name( + tab = self.core.tabs.by_name_and_class( jid.full, tabs.PrivateTab) # get the tab with the private conversation ignore = config.get_by_tabname('ignore_private', room_from) @@ -764,7 +772,8 @@ class HandlerCore: if body and not ignore: tab = self.core.open_private_window(room_from, with_nick, False) - sender_nick = (tab.own_nick or self.core.own_nick) if sent else with_nick + sender_nick = (tab.own_nick + or self.core.own_nick) if sent else with_nick if ignore and not sent: self.core.events.trigger('ignored_private', message, tab) msg = config.get_by_tabname('private_auto_response', room_from) @@ -815,7 +824,7 @@ class HandlerCore: if not sent and 'private' in config.get('beep_on').split(): if not config.get_by_tabname('disable_beep', jid.full): curses.beep() - if tab is self.core.current_tab(): + if tab is self.core.tabs.current_tab: self.core.refresh_window() else: tab.state = 'normal' if sent else 'private' @@ -841,8 +850,8 @@ class HandlerCore: def _on_chatstate(self, message, state): if message['type'] == 'chat': if not self._on_chatstate_normal_conversation(message, state): - tab = self.core.get_tab_by_name(message['from'].full, - tabs.PrivateTab) + tab = self.core.tabs.by_name_and_class(message['from'].full, + tabs.PrivateTab) if not tab: return self._on_chatstate_private_conversation(message, state) @@ -857,7 +866,7 @@ class HandlerCore: tab.chatstate = state if state == 'gone' and isinstance(tab, tabs.DynamicConversationTab): tab.unlock() - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: tab.refresh_info_header() self.core.doupdate() else: @@ -869,12 +878,13 @@ class HandlerCore: """ Chatstate received in a private conversation from a MUC """ - tab = self.core.get_tab_by_name(message['from'].full, tabs.PrivateTab) + tab = self.core.tabs.by_name_and_class(message['from'].full, + tabs.PrivateTab) if not tab: return self.core.events.trigger('private_chatstate', message, tab) tab.chatstate = state - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: tab.refresh_info_header() self.core.doupdate() else: @@ -887,11 +897,11 @@ class HandlerCore: """ nick = message['mucnick'] room_from = message.get_mucroom() - tab = self.core.get_tab_by_name(room_from, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room_from, tabs.MucTab) if tab and tab.get_user_by_name(nick): self.core.events.trigger('muc_chatstate', message, tab) tab.get_user_by_name(nick).chatstate = state - if tab == self.core.current_tab(): + if tab == self.core.tabs.current_tab: if not self.core.size.tab_degrade_x: tab.user_win.refresh(tab.users) tab.input.refresh() @@ -908,15 +918,16 @@ class HandlerCore: if iq['type'] == 'error': error_condition = iq['error']['condition'] error_text = iq['error']['text'] - reply = '%s: %s' % (error_condition, error_text) if error_text else error_condition - return self.core.information('Could not get the software ' - 'version from %s: %s' % (jid, reply), - 'Warning') + reply = '%s: %s' % (error_condition, + error_text) if error_text else error_condition + return self.core.information( + 'Could not get the software ' + 'version from %s: %s' % (jid, reply), 'Warning') res = iq['software_version'] version = '%s is running %s version %s on %s' % ( jid, res.get('name', 'an unknown software'), - res.get('version', 'unknown'), - res.get('os', 'an unknown platform')) + res.get('version', 'unknown'), res.get('os', + 'an unknown platform')) self.core.information(version, 'Info') ### subscription-related handlers ### @@ -937,7 +948,7 @@ class HandlerCore: else: roster.update_contact_groups(jid) roster.update_size() - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_subscription_request(self, presence): @@ -960,7 +971,7 @@ class HandlerCore: 'tab to accept or reject the query.' % jid, 'Roster') self.core.get_tab_by_number(0).state = 'highlight' roster.modified() - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_subscription_authorized(self, presence): @@ -975,7 +986,7 @@ class HandlerCore: roster.modified() - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_subscription_remove(self, presence): @@ -988,7 +999,7 @@ class HandlerCore: self.core.information( '%s does not want to receive your status anymore.' % jid, 'Roster') self.core.get_tab_by_number(0).state = 'highlight' - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_subscription_removed(self, presence): @@ -1007,7 +1018,7 @@ class HandlerCore: '%s does not want you to receive his/her/its status anymore.' % jid, 'Roster') self.core.get_tab_by_number(0).state = 'highlight' - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() ### Presence-related handlers ### @@ -1034,9 +1045,9 @@ class HandlerCore: if tab: tab.update_status( Status(show=presence['show'], message=presence['status'])) - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() - elif self.core.current_tab() == tab: + elif self.core.tabs.current_tab == tab: tab.refresh() self.core.doupdate() @@ -1047,8 +1058,7 @@ class HandlerCore: return roster.modified() contact.error = presence['error']['type'] + ': ' + presence['error']['condition'] - # reset chat states status on presence error - tab = self.core.get_tab_by_name(jid.full, tabs.ConversationTab) + # TODO: reset chat states status on presence error def on_got_offline(self, presence): """ @@ -1076,7 +1086,7 @@ class HandlerCore: self.core.information('\x193}%s \x195}is \x191}offline' % name, 'Roster') roster.modified() - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_got_online(self, presence): @@ -1116,7 +1126,7 @@ class HandlerCore: "\x193}%s \x195}is \x194}online\x195}" % name, "Roster") self.core.add_information_message_to_conversation_tab( jid.bare, '\x195}%s is \x194}online' % name) - if isinstance(self.core.current_tab(), tabs.RosterInfoTab): + if isinstance(self.core.tabs.current_tab, tabs.RosterInfoTab): self.core.refresh_window() def on_groupchat_presence(self, presence): @@ -1126,7 +1136,7 @@ class HandlerCore: presence information of the concerned user """ from_room = presence['from'].bare - tab = self.core.get_tab_by_name(from_room, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(from_room, tabs.MucTab) if tab: self.core.events.trigger('muc_presence', presence, tab) tab.handle_presence(presence) @@ -1137,8 +1147,8 @@ class HandlerCore: """ We cannot contact the remote server """ - self.core.information("Connection to remote server failed: %s" % - (error, ), 'Error') + self.core.information( + "Connection to remote server failed: %s" % (error, ), 'Error') @asyncio.coroutine def on_disconnected(self, event): @@ -1238,11 +1248,11 @@ class HandlerCore: Those are received when a room configuration change occurs. """ room_from = message['from'] - tab = self.core.get_tab_by_name(room_from, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room_from, tabs.MucTab) status_codes = { s.attrib['code'] - for s in message.xml.findall('{%s}x/{%s}status' % ( - tabs.NS_MUC_USER, tabs.NS_MUC_USER)) + for s in message.xml.findall('{%s}x/{%s}status' % + (tabs.NS_MUC_USER, tabs.NS_MUC_USER)) } if '101' in status_codes: self.core.information( @@ -1332,7 +1342,7 @@ class HandlerCore: """ nick_from = message['mucnick'] room_from = message.get_mucroom() - tab = self.core.get_tab_by_name(room_from, tabs.MucTab) + tab = self.core.tabs.by_name_and_class(room_from, tabs.MucTab) subject = message['subject'] if subject is None or not tab: return @@ -1353,9 +1363,8 @@ class HandlerCore: after = '' if user: user_col = dump_tuple(user.color) - user_string = '\x19%s}%s\x19%s}%s' % (user_col, nick_from, - fmt['info_col'], - after) + user_string = '\x19%s}%s\x19%s}%s' % ( + user_col, nick_from, fmt['info_col'], after) else: user_string = '\x19%s}%s%s' % (fmt['info_col'], nick_from, after) @@ -1375,8 +1384,8 @@ class HandlerCore: typ=2) tab.topic = subject tab.topic_from = nick_from - if self.core.get_tab_by_name(room_from, - tabs.MucTab) is self.core.current_tab(): + if self.core.tabs.by_name_and_class( + room_from, tabs.MucTab) is self.core.tabs.current_tab: self.core.refresh_window() def on_receipt(self, message): @@ -1388,8 +1397,9 @@ class HandlerCore: if not msg_id: return - conversation = self.core.get_tab_by_name(jid.full, tabs.OneToOneTab) - conversation = conversation or self.core.get_tab_by_name( + conversation = self.core.tabs.by_name_and_class( + jid.full, tabs.OneToOneTab) + conversation = conversation or self.core.tabs.by_name_and_class( jid.bare, tabs.OneToOneTab) if not conversation: log.error("Received ack from non-existing chat tab: %s", jid) @@ -1449,8 +1459,8 @@ class HandlerCore: except: log.debug('', exc_info=True) - if isinstance(self.core.current_tab(), tabs.XMLTab): - self.core.current_tab().refresh() + if isinstance(self.core.tabs.current_tab, tabs.XMLTab): + self.core.tabs.current_tab.refresh() self.core.doupdate() def incoming_stanza(self, stanza): @@ -1476,8 +1486,8 @@ class HandlerCore: nickname=get_theme().CHAR_XML_IN) except: log.debug('', exc_info=True) - if isinstance(self.core.current_tab(), tabs.XMLTab): - self.core.current_tab().refresh() + if isinstance(self.core.tabs.current_tab, tabs.XMLTab): + self.core.tabs.current_tab.refresh() self.core.doupdate() def ssl_invalid_chain(self, tb): -- cgit v1.2.3