From 4a8ef778399e652c304a82cd3b326d4f604f05d6 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 5 Nov 2011 19:35:24 +0100 Subject: Partial fix to #2266 and #2255 (removes the idea of "color state" and adds state, that are computed to the current theme color) --- src/core.py | 14 +++---- src/room.py | 25 +++++------- src/tabs.py | 122 +++++++++++++++++++++++++++------------------------------ src/windows.py | 2 +- 4 files changed, 75 insertions(+), 88 deletions(-) diff --git a/src/core.py b/src/core.py index 8abaec63..d107e86c 100644 --- a/src/core.py +++ b/src/core.py @@ -614,7 +614,7 @@ class Core(object): if 'private' in config.get('beep_on', 'highlight private').split(): curses.beep() if self.current_tab() is not conversation: - conversation.set_color_state(get_theme().COLOR_TAB_PRIVATE) + conversation.state = 'private' self.refresh_tab_win() else: self.refresh_window() @@ -676,7 +676,7 @@ class Core(object): roster.add_contact(contact, jid) roster.edit_groups_of_contact(contact, []) contact.set_ask('asked') - self.get_tab_by_number(0).set_color_state(get_theme().COLOR_TAB_HIGHLIGHT) + self.get_tab_by_number(0).state = 'highlight' self.information('%s wants to subscribe to your presence'%jid, 'Roster') if isinstance(self.current_tab(), tabs.RosterInfoTab): self.refresh_window() @@ -827,7 +827,7 @@ class Core(object): """ Refresh everything """ - self.current_tab().set_color_state(get_theme().COLOR_TAB_CURRENT) + self.current_tab().state = 'current' self.current_tab().refresh() self.doupdate() @@ -875,19 +875,19 @@ class Core(object): - A Muc with any new message """ for tab in self.tabs: - if tab.get_color_state() == get_theme().COLOR_TAB_PRIVATE: + if tab.state == 'private': self.command_win('%s' % tab.nb) return for tab in self.tabs: - if tab.get_color_state() == get_theme().COLOR_TAB_HIGHLIGHT: + if tab.state == 'highlight': self.command_win('%s' % tab.nb) return for tab in self.tabs: - if tab.get_color_state() == get_theme().COLOR_TAB_NEW_MESSAGE: + if tab.state == 'message': self.command_win('%s' % tab.nb) return for tab in self.tabs: - if tab.get_color_state() == get_theme().COLOR_TAB_DISCONNECTED: + if tab.state == 'disconnected': self.command_win('%s' % tab.nb) return for tab in self.tabs: diff --git a/src/room.py b/src/room.py index b97dd0b6..ad52451c 100644 --- a/src/room.py +++ b/src/room.py @@ -24,7 +24,7 @@ class Room(TextBuffer): TextBuffer.__init__(self, messages_nb_limit) self.name = name self.own_nick = nick - self.color_state = get_theme().COLOR_TAB_NORMAL # color used in RoomInfo + self.state = 'normal' # color used in RoomInfo self.joined = False # false until self presence is receied self.users = [] # User objects self.topic = '' @@ -35,7 +35,7 @@ class Room(TextBuffer): we can know if we can join it, send messages to it, etc """ self.users = [] - self.color_state = get_theme().COLOR_TAB_DISCONNECTED + self.state = 'disconnected' self.joined = False def get_single_line_topic(self): @@ -59,15 +59,15 @@ class Room(TextBuffer): color = None if not time and nickname and nickname != self.own_nick and self.joined: if self.own_nick.lower() in txt.lower(): - if self.color_state != get_theme().COLOR_TAB_CURRENT: - self.set_color_state(get_theme().COLOR_TAB_HIGHLIGHT) + if self.state != 'current': + self.state = 'highlight' color = get_theme().COLOR_HIGHLIGHT_NICK else: highlight_words = config.get('highlight_on', '').split(':') for word in highlight_words: if word and word.lower() in txt.lower(): - if self.color_state != get_theme().COLOR_TAB_CURRENT: - self.set_color_state(get_theme().COLOR_TAB_HIGHLIGHT) + if self.state != 'current': + self.state = 'highlight' color = get_theme().COLOR_HIGHLIGHT_NICK break if color: @@ -85,13 +85,6 @@ class Room(TextBuffer): return user return None - def set_color_state(self, color): - """ - Set the color that will be used to display the room's - number in the RoomInfo window - """ - self.color_state = color - def add_message(self, txt, time=None, nickname=None, forced_user=None, nick_color=None, history=None): """ Note that user can be None even if nickname is not None. It happens @@ -110,9 +103,9 @@ class Room(TextBuffer): user = forced_user if not time and nickname and\ nickname != self.own_nick and\ - self.color_state != get_theme().COLOR_TAB_CURRENT: - if self.color_state != get_theme().COLOR_TAB_HIGHLIGHT: - self.set_color_state(get_theme().COLOR_TAB_NEW_MESSAGE) + self.state != 'current': + if self.state != 'highlight': + self.state = 'message' nick_color = nick_color or None if not nickname or time: txt = '\x195}%s' % (txt,) diff --git a/src/tabs.py b/src/tabs.py index a9709c02..f4487643 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -57,12 +57,21 @@ SHOW_NAME = { NS_MUC_USER = 'http://jabber.org/protocol/muc#user' +STATE_COLORS = { + 'disconnected': 'COLOR_TAB_DISCONNECTED', + 'message': 'COLOR_TAB_NEW_MESSAGE', + 'highlight': 'COLOR_TAB_HIGHLIGHT', + 'private': 'COLOR_TAB_PRIVATE', + 'normal': 'COLOR_TAB_NORMAL', + 'current': 'COLOR_TAB_CURRENT', + } + class Tab(object): number = 0 tab_core = None def __init__(self): self.input = None - self._color_state = get_theme().COLOR_TAB_NORMAL + self.state = 'normal' self.need_resize = False self.nb = Tab.number Tab.number += 1 @@ -87,6 +96,21 @@ class Tab(object): def info_win(self): return self.core.information_win + @property + def color(self): + return getattr(get_theme(), STATE_COLORS[self.state]) + + @property + def state(self): + return self._state + + @state.setter + def state(self, value): + if not value in STATE_COLORS: + log.debug("WARNING: invalid value for tab state") + return + self._state = value + @staticmethod def resize(scr): Tab.size = (Tab.height, Tab.width) = scr.getmaxyx() @@ -167,18 +191,6 @@ class Tab(object): """ raise NotImplementedError - def get_color_state(self): - """ - returns the color that should be used in the GlobalInfoBar - """ - return self._color_state - - def set_color_state(self, color): - """ - set the color state - """ - pass - def get_name(self): """ get the name of the tab @@ -198,13 +210,13 @@ class Tab(object): """ called when this tab loses the focus. """ - self._color_state = get_theme().COLOR_TAB_NORMAL + self.state = 'normal' def on_gain_focus(self): """ called when this tab gains the focus. """ - self._color_state = get_theme().COLOR_TAB_CURRENT + self.state = 'current' def add_message(self): """ @@ -803,12 +815,6 @@ class MucTab(ChatTab): empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//')) self.send_composing_chat_state(empty_after) - def get_color_state(self): - return self._room.color_state - - def set_color_state(self, color): - self._room.set_color_state(color) - def get_name(self): return self._room.name @@ -818,15 +824,19 @@ class MucTab(ChatTab): def get_room(self): return self._room + @property + def color(self): + return getattr(get_theme(), STATE_COLORS[self._room.state]) + def on_lose_focus(self): - self._room.set_color_state(get_theme().COLOR_TAB_NORMAL) + self._room.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('inactive') def on_gain_focus(self): - self._room.set_color_state(get_theme().COLOR_TAB_CURRENT) + self._room.state = 'current' if self.text_win.built_lines and self.text_win.built_lines[-1] is None: self.text_win.remove_line_separator() curses.curs_set(1) @@ -1167,14 +1177,12 @@ class PrivateTab(ChatTab): self.info_header.refresh(self._room, self.text_win, self.chatstate) self.input.refresh() - def get_color_state(self): - if self._room.color_state == get_theme().COLOR_TAB_NORMAL or\ - self._room.color_state == get_theme().COLOR_TAB_CURRENT: - return self._room.color_state - return get_theme().COLOR_TAB_PRIVATE - - def set_color_state(self, color): - self._room.color_state = color + @property + def color(self): + if self._room.state == 'normal' or\ + self._room.state == 'current': + return getattr(get_theme(), STATE_COLORS[self._room.state]) + return getattr(get_theme(), 'COLOR_TAB_PRIVATE') def get_name(self): return self._room.name @@ -1193,14 +1201,14 @@ class PrivateTab(ChatTab): return False def on_lose_focus(self): - self._room.set_color_state(get_theme().COLOR_TAB_NORMAL) + self._room.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if self.get_room().joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('inactive') def on_gain_focus(self): - self._room.set_color_state(get_theme().COLOR_TAB_CURRENT) + self._room.state = 'CURRENT' curses.curs_set(1) if self.get_room().joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('active') @@ -1276,7 +1284,7 @@ class RosterInfoTab(Tab): self.contact_info_win = windows.ContactInfoWin() self.default_help_message = windows.HelpText("Enter commands with “/”. “o”: toggle offline show") self.input = self.default_help_message - self.set_color_state(get_theme().COLOR_TAB_NORMAL) + self.state = 'normal' self.key_func['^I'] = self.completion self.key_func[' '] = self.on_space self.key_func["/"] = self.on_slash @@ -1590,12 +1598,6 @@ class RosterInfoTab(Tab): def get_name(self): return self.name - def get_color_state(self): - return self._color_state - - def set_color_state(self, color): - self._color_state = color - def on_input(self, key): if key == '^M': selected_row = self.roster_win.get_selected_row() @@ -1643,10 +1645,10 @@ class RosterInfoTab(Tab): return self.reset_help_message() def on_lose_focus(self): - self._color_state = get_theme().COLOR_TAB_NORMAL + self.state = 'normal' def on_gain_focus(self): - self._color_state = get_theme().COLOR_TAB_CURRENT + self.state = 'current' if isinstance(self.input, windows.HelpText): curses.curs_set(0) else: @@ -1753,7 +1755,7 @@ class ConversationTab(ChatTab): def __init__(self, jid): txt_buff = text_buffer.TextBuffer() ChatTab.__init__(self, txt_buff) - self.color_state = get_theme().COLOR_TAB_NORMAL + self.state = 'normal' self._name = jid # a conversation tab is linked to one specific full jid OR bare jid self.text_win = windows.TextWin() txt_buff.add_window(self.text_win) @@ -1816,15 +1818,13 @@ class ConversationTab(ChatTab): self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self._room, self.text_win, self.chatstate) self.input.refresh() - def get_color_state(self): - if self.color_state == get_theme().COLOR_TAB_NORMAL or\ - self.color_state == get_theme().COLOR_TAB_CURRENT: - return self.color_state + @property + def color(self): + if self.state == 'normal' or \ + self.state == 'current': + return getattr(get_theme(), STATE_COLORS[self.state]) return get_theme().COLOR_TAB_PRIVATE - def set_color_state(self, color): - self.color_state = color - def get_name(self): return self._name @@ -1838,14 +1838,14 @@ class ConversationTab(ChatTab): return False def on_lose_focus(self): - self.set_color_state(get_theme().COLOR_TAB_NORMAL) + self.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'): self.send_chat_state('inactive') def on_gain_focus(self): - self.set_color_state(get_theme().COLOR_TAB_CURRENT) + self.state = 'current' curses.curs_set(1) if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'): self.send_chat_state('active') @@ -1880,7 +1880,7 @@ class MucListTab(Tab): """ def __init__(self, server): Tab.__init__(self) - self._color_state = get_theme().COLOR_TAB_NORMAL + self.state = 'normal' self.name = server self.upper_message = windows.Topic() self.upper_message.set_message('Chatroom list on server %s (Loading)' % self.name) @@ -1994,15 +1994,12 @@ class MucListTab(Tab): return self.key_func[key]() def on_lose_focus(self): - self._color_state = get_theme().COLOR_TAB_NORMAL + self.state = 'normal' def on_gain_focus(self): - self._color_state = get_theme().COLOR_TAB_CURRENT + self.state = 'current' curses.curs_set(0) - def get_color_state(self): - return self._color_state - def on_scroll_up(self): self.listview.scroll_up() @@ -2017,7 +2014,7 @@ class SimpleTextTab(Tab): """ def __init__(self, text): Tab.__init__(self) - self._color_state = get_theme().COLOR_TAB_NORMAL + self.state = 'normal' self.text_win = windows.SimpleTextWin(text) self.default_help_message = windows.HelpText("“Ctrl+q”: close") self.input = self.default_help_message @@ -2060,15 +2057,12 @@ class SimpleTextTab(Tab): self.input.refresh() def on_lose_focus(self): - self._color_state = get_theme().COLOR_TAB_NORMAL + self.state = 'normal' def on_gain_focus(self): - self._color_state = get_theme().COLOR_TAB_CURRENT + self.state = 'current' curses.curs_set(0) - def get_color_state(self): - return self._color_state - def diffmatch(search, string): """ Use difflib and a loop to check if search_pattern can diff --git a/src/windows.py b/src/windows.py index 4f2c68c6..c2c35170 100644 --- a/src/windows.py +++ b/src/windows.py @@ -297,7 +297,7 @@ class GlobalInfoBar(Win): self.addstr(0, 0, "[", to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) sorted_tabs = sorted(self.core.tabs, key=comp) for tab in sorted_tabs: - color = tab.get_color_state() + color = tab.color if config.get('show_inactive_tabs', 'true') == 'false' and\ color == get_theme().COLOR_TAB_NORMAL: continue -- cgit v1.2.3 From 038869d2f7408d46d04dfdd7bd0cf67f731afee4 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 5 Nov 2011 19:38:03 +0100 Subject: Fix the /kick command --- src/tabs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tabs.py b/src/tabs.py index f4487643..ae20128c 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -653,7 +653,7 @@ class MucTab(ChatTab): if not len(args): self.core.command_help('kick') else: - self.command_role('none '+arg) + self.command_role(arg+ ' none') def command_role(self, arg): """ -- cgit v1.2.3 From 3f08e235a11ccc201e672e306fa7543437a589c0 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 5 Nov 2011 21:10:16 +0100 Subject: Fix some chat states problems (e.g. /dnd sending inactive) --- src/core.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core.py b/src/core.py index d107e86c..87f27e17 100644 --- a/src/core.py +++ b/src/core.py @@ -1114,12 +1114,14 @@ class Core(object): pres['type'] = show pres.send() current = self.current_tab() - if isinstance(current, tabs.MucTab) and current.get_room().joined: + if isinstance(current, tabs.MucTab) and current.get_room().joined and show in ('away', 'xa'): current.send_chat_state('inactive') for tab in self.tabs: if isinstance(tab, tabs.MucTab) and tab.get_room().joined: muc.change_show(self.xmpp, tab.get_room().name, tab.get_room().own_nick, show, msg) self.set_status(show, msg) + if isinstance(current, tabs.MucTab) and current.get_room().joined and show not in ('away', 'xa'): + current.send_chat_state('active') def completion_status(self, the_input): return the_input.auto_completion([status for status in possible_show], ' ') -- cgit v1.2.3 From a49af71f7c18eb7373423ab45cb543f2141d049b Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 5 Nov 2011 21:25:17 +0100 Subject: Fixes #2255 with some lambda fun --- src/tabs.py | 22 +++++++++++----------- src/windows.py | 30 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/tabs.py b/src/tabs.py index ae20128c..2e4a8901 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -58,12 +58,12 @@ SHOW_NAME = { NS_MUC_USER = 'http://jabber.org/protocol/muc#user' STATE_COLORS = { - 'disconnected': 'COLOR_TAB_DISCONNECTED', - 'message': 'COLOR_TAB_NEW_MESSAGE', - 'highlight': 'COLOR_TAB_HIGHLIGHT', - 'private': 'COLOR_TAB_PRIVATE', - 'normal': 'COLOR_TAB_NORMAL', - 'current': 'COLOR_TAB_CURRENT', + 'disconnected': lambda: get_theme().COLOR_TAB_DISCONNECTED, + 'message': lambda: get_theme().COLOR_TAB_NEW_MESSAGE, + 'highlight': lambda: get_theme().COLOR_TAB_HIGHLIGHT, + 'private': lambda: get_theme().COLOR_TAB_PRIVATE, + 'normal': lambda: get_theme().COLOR_TAB_NORMAL, + 'current': lambda: get_theme().COLOR_TAB_CURRENT, } class Tab(object): @@ -98,7 +98,7 @@ class Tab(object): @property def color(self): - return getattr(get_theme(), STATE_COLORS[self.state]) + return STATE_COLORS[self.state]() @property def state(self): @@ -826,7 +826,7 @@ class MucTab(ChatTab): @property def color(self): - return getattr(get_theme(), STATE_COLORS[self._room.state]) + return STATE_COLORS[self._room.state]() def on_lose_focus(self): self._room.state = 'normal' @@ -1181,8 +1181,8 @@ class PrivateTab(ChatTab): def color(self): if self._room.state == 'normal' or\ self._room.state == 'current': - return getattr(get_theme(), STATE_COLORS[self._room.state]) - return getattr(get_theme(), 'COLOR_TAB_PRIVATE') + return STATE_COLORS[self._room.state]() + return get_theme().COLOR_TAB_PRIVATE def get_name(self): return self._room.name @@ -1822,7 +1822,7 @@ class ConversationTab(ChatTab): def color(self): if self.state == 'normal' or \ self.state == 'current': - return getattr(get_theme(), STATE_COLORS[self.state]) + return STATE_COLORS[self.state]() return get_theme().COLOR_TAB_PRIVATE def get_name(self): diff --git a/src/windows.py b/src/windows.py index c2c35170..1612e416 100644 --- a/src/windows.py +++ b/src/windows.py @@ -191,19 +191,19 @@ class UserList(Win): def __init__(self): Win.__init__(self) self.pos = 0 - self.color_role = {'moderator': get_theme().COLOR_USER_MODERATOR, - 'participant':get_theme().COLOR_USER_PARTICIPANT, - 'visitor':get_theme().COLOR_USER_VISITOR, - 'none':get_theme().COLOR_USER_NONE, - '':get_theme().COLOR_USER_NONE - } - self.color_show = {'xa':get_theme().COLOR_STATUS_XA, - 'none':get_theme().COLOR_STATUS_NONE, - '':get_theme().COLOR_STATUS_NONE, - 'dnd':get_theme().COLOR_STATUS_DND, - 'away':get_theme().COLOR_STATUS_AWAY, - 'chat':get_theme().COLOR_STATUS_CHAT - } + self.color_role = {'moderator': lambda: get_theme().COLOR_USER_MODERATOR, + 'participant': lambda: get_theme().COLOR_USER_PARTICIPANT, + 'visitor': lambda: get_theme().COLOR_USER_VISITOR, + 'none': lambda: get_theme().COLOR_USER_NONE, + '': lambda: get_theme().COLOR_USER_NONE + } + self.color_show = {'xa': lambda: get_theme().COLOR_STATUS_XA, + 'none': lambda: get_theme().COLOR_STATUS_NONE, + '': lambda: get_theme().COLOR_STATUS_NONE, + 'dnd': lambda: get_theme().COLOR_STATUS_DND, + 'away': lambda: get_theme().COLOR_STATUS_AWAY, + 'chat': lambda: get_theme().COLOR_STATUS_CHAT + } def scroll_up(self): self.pos += self.height-1 @@ -228,11 +228,11 @@ class UserList(Win): if not user.role in self.color_role: role_col = get_theme().COLOR_USER_NONE else: - role_col = self.color_role[user.role] + role_col = self.color_role[user.role]() if not user.show in self.color_show: show_col = get_theme().COLOR_STATUS_NONE else: - show_col = self.color_show[user.show] + show_col = self.color_show[user.show]() if user.chatstate == 'composing': char = 'X' elif user.chatstate == 'active': -- cgit v1.2.3 From 25fb35d7e149c9d2a1ac44c9270b11780a5bfcda Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 5 Nov 2011 22:12:03 +0100 Subject: Things related to priority, fixes #2266 (imo) --- src/core.py | 4 ++++ src/tabs.py | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core.py b/src/core.py index 87f27e17..5fcdf8a3 100644 --- a/src/core.py +++ b/src/core.py @@ -971,6 +971,8 @@ class Core(object): return tab new_tab = tabs.ConversationTab(jid) # insert it in the rooms + if not focus: + new_tab.state = "private" self.add_tab(new_tab, focus) self.refresh_window() return new_tab @@ -989,6 +991,8 @@ class Core(object): own_nick = room.own_nick r = Room(complete_jid, own_nick) # PrivateRoom here new_tab = tabs.PrivateTab(r) + if not focus: + new_tab.state = "private" # insert it in the tabs self.add_tab(new_tab, focus) # self.window.new_room(r) diff --git a/src/tabs.py b/src/tabs.py index 2e4a8901..a27eeb38 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -64,6 +64,17 @@ STATE_COLORS = { 'private': lambda: get_theme().COLOR_TAB_PRIVATE, 'normal': lambda: get_theme().COLOR_TAB_NORMAL, 'current': lambda: get_theme().COLOR_TAB_CURRENT, +# 'attention': lambda: get_theme().COLOR_TAB_ATTENTION, + } + +STATE_PRIORITY = { + 'normal': -1, + 'current': -1, + 'disconnected': 0, + 'message': 1, + 'highlight': 2, + 'private': 2, +# 'attention': 3 } class Tab(object): @@ -71,7 +82,7 @@ class Tab(object): tab_core = None def __init__(self): self.input = None - self.state = 'normal' + self._state = 'normal' self.need_resize = False self.nb = Tab.number Tab.number += 1 @@ -109,6 +120,10 @@ class Tab(object): if not value in STATE_COLORS: log.debug("WARNING: invalid value for tab state") return + elif STATE_PRIORITY[value] < STATE_PRIORITY[self._state] and \ + value != 'current': + log.debug("WARNING: did not set status because of lower priority") + return self._state = value @staticmethod -- cgit v1.2.3 From af6e5345781381fbfab48552684a2c621989a24d Mon Sep 17 00:00:00 2001 From: mathieui Date: Sat, 5 Nov 2011 22:12:55 +0100 Subject: More @property magic, for transparency --- src/tabs.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/tabs.py b/src/tabs.py index a27eeb38..2297cf86 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -840,18 +840,22 @@ class MucTab(ChatTab): return self._room @property - def color(self): - return STATE_COLORS[self._room.state]() + def state(self): + return self._room.state + + @state.setter + def state(self, value): + self._room.state = value def on_lose_focus(self): - self._room.state = 'normal' + self.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('inactive') def on_gain_focus(self): - self._room.state = 'current' + self.state = 'current' if self.text_win.built_lines and self.text_win.built_lines[-1] is None: self.text_win.remove_line_separator() curses.curs_set(1) @@ -1193,11 +1197,12 @@ class PrivateTab(ChatTab): self.input.refresh() @property - def color(self): - if self._room.state == 'normal' or\ - self._room.state == 'current': - return STATE_COLORS[self._room.state]() - return get_theme().COLOR_TAB_PRIVATE + def state(self): + return self._room.state + + @state.setter + def state(self, value): + self._room.state = value def get_name(self): return self._room.name @@ -1216,14 +1221,14 @@ class PrivateTab(ChatTab): return False def on_lose_focus(self): - self._room.state = 'normal' + self.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if self.get_room().joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('inactive') def on_gain_focus(self): - self._room.state = 'CURRENT' + self.state = 'current' curses.curs_set(1) if self.get_room().joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('active') @@ -1833,13 +1838,6 @@ class ConversationTab(ChatTab): self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self._room, self.text_win, self.chatstate) self.input.refresh() - @property - def color(self): - if self.state == 'normal' or \ - self.state == 'current': - return STATE_COLORS[self.state]() - return get_theme().COLOR_TAB_PRIVATE - def get_name(self): return self._name -- cgit v1.2.3 From e6797c29a5f20b50ed35ef25922596bab047d0f6 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 6 Nov 2011 00:15:38 +0100 Subject: =?UTF-8?q?Smaller=20means=20being=20insane,=20and=20even=20then,?= =?UTF-8?q?=20it=20should=E2=80=99nt=20bug=20too=20much=20Fixes=20#2259?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.py | 3 +++ src/tabs.py | 4 ++-- src/windows.py | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core.py b/src/core.py index 5fcdf8a3..ec821cbd 100644 --- a/src/core.py +++ b/src/core.py @@ -230,6 +230,9 @@ class Core(object): return self.information_buffer def grow_information_win(self, nb=1): + if self.information_win_size >= self.current_tab().height -5 or \ + self.information_win_size+nb >= self.current_tab().height-4: + return if self.information_win_size == 14: return self.information_win_size += nb diff --git a/src/tabs.py b/src/tabs.py index 2297cf86..5c8ba962 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -13,8 +13,8 @@ Each Tab object has different refresh() and resize() methods, defining how its Windows are displayed, resized, etc """ -MIN_WIDTH = 50 -MIN_HEIGHT = 22 +MIN_WIDTH = 42 +MIN_HEIGHT = 6 import logging log = logging.getLogger(__name__) diff --git a/src/windows.py b/src/windows.py index 1612e416..1701fee7 100644 --- a/src/windows.py +++ b/src/windows.py @@ -62,9 +62,10 @@ class Win(object): self._win = None def _resize(self, height, width, y, x): - self.height, self.width, self.x, self.y = height, width, x, y if height == 0 or width == 0: + self.height, self.width = height, width return + self.height, self.width, self.x, self.y = height, width, x, y if not self._win: self._win = curses.newwin(height, width, y, x) else: -- cgit v1.2.3 From 3412c119a911319d8e28debafdc47e27eb343fd4 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 23 Oct 2011 17:19:14 +0200 Subject: =?UTF-8?q?First=20part=20of=20the=20=E2=80=9Cremove=20the=20Room?= =?UTF-8?q?=20class=E2=80=9D=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tabs.py | 189 +++++++++++++++++++++++++++++---------------------------- src/windows.py | 2 +- 2 files changed, 96 insertions(+), 95 deletions(-) diff --git a/src/tabs.py b/src/tabs.py index 5c8ba962..9fe685a3 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -41,6 +41,7 @@ from sleekxmpp.xmlstream.stanzabase import JID from config import config from roster import RosterGroup, roster from contact import Contact, Resource +from text_buffer import TextBuffer from user import User from os import getenv, path from logger import logger @@ -285,9 +286,9 @@ class ChatTab(Tab): Also, ^M is already bound to on_enter And also, add the /say command """ - def __init__(self, room): + def __init__(self): Tab.__init__(self) - self._room = room + self._text_buffer = TextBuffer() self.remote_wants_chatstates = None # change this to True or False when # we know that the remote user wants chatstates, or not. # None means we don’t know yet, and we send only "active" chatstates @@ -313,7 +314,7 @@ class ChatTab(Tab): # build the list of the recent words char_we_dont_want = string.punctuation+' ' words = list() - for msg in self._room.messages[:-40:-1]: + for msg in self.messages[:-40:-1]: if not msg: continue txt = xhtml.clean_text(msg.txt) @@ -338,7 +339,7 @@ class ChatTab(Tab): """ Send an empty chatstate message """ - if not isinstance(self, MucTab) or self.get_room().joined: + if not isinstance(self, MucTab) or self.joined: if state in ('active', 'inactive', 'gone') and self.core.status.show in ('xa', 'away') and not always_send: return msg = self.core.xmpp.make_message(self.get_name()) @@ -397,7 +398,7 @@ class ChatTab(Tab): def move_separator(self): self.text_win.remove_line_separator() self.text_win.add_line_separator() - self.text_win.refresh(self._room) + self.text_win.refresh(self._text_buffer) self.input.refresh() def command_say(self, line): @@ -450,19 +451,19 @@ class MucTab(ChatTab): def scroll_user_list_up(self): self.user_win.scroll_up() - self.user_win.refresh(self._room.users) + self.user_win.refresh(self.users) self.input.refresh() def scroll_user_list_down(self): self.user_win.scroll_down() - self.user_win.refresh(self._room.users) + self.user_win.refresh(self.users) self.input.refresh() def command_info(self, arg): args = common.shell_split(arg) if len(args) != 1: return self.core.information("Info command takes only 1 argument") - user = self.get_room().get_user_by_name(args[0]) + user = self.get_user_by_name(args[0]) if not user: return self.core.information("Unknown user: %s" % args[0]) info = '%s%s: show: %s, affiliation: %s, role: %s%s' % (args[0], @@ -497,35 +498,34 @@ class MucTab(ChatTab): """ /clear """ - self._room.messages = [] - self.text_win.rebuild_everything(self._room) + self.messages = [] + self.text_win.rebuild_everything(self._text_buffer) self.refresh() self.core.doupdate() def command_cycle(self, arg): - if self.get_room().joined: - muc.leave_groupchat(self.core.xmpp, self.get_name(), self.get_room().own_nick, arg) - self.get_room().disconnect() - self.core.disable_private_tabs(self.get_room().name) - self.core.command_join('"/%s"' % self.core.get_bookmark_nickname(self.get_room().name), '0') + if self.joined: + muc.leave_groupchat(self.core.xmpp, self.get_name(), self.own_nick, arg) + self.disconnect() + self.core.disable_private_tabs(self.name) + self.core.command_join('"/%s"' % self.core.get_bookmark_nickname(self.name), '0') self.user_win.pos = 0 def command_recolor(self, arg): """ Re-assign color to the participants of the room """ - room = self.get_room() compare_users = lambda x: x.last_talked - users = list(room.users) + users = list(self.users) # search our own user, to remove it from the room for user in users: - if user.nick == room.own_nick: + if user.nick == self.own_nick: users.remove(user) nb_color = len(get_theme().LIST_COLOR_NICKNAMES) for i, user in enumerate(sorted(users, key=compare_users, reverse=True)): user.color = get_theme().LIST_COLOR_NICKNAMES[i % nb_color] - self.text_win.rebuild_everything(self._room) - self.text_win.refresh(self._room) + self.text_win.rebuild_everything(self._text_buffer) + self.text_win.refresh() self.input.refresh() def command_version(self, arg): @@ -544,8 +544,8 @@ class MucTab(ChatTab): args = common.shell_split(arg) if len(args) < 1: return - if args[0] in [user.nick for user in self.get_room().users]: - jid = self._room.name + '/' + args[0] + if args[0] in [user.nick for user in self.users]: + jid = self.name + '/' + args[0] else: jid = args[0] self.core.xmpp.plugin['xep_0092'].get_version(jid, callback=callback) @@ -558,29 +558,27 @@ class MucTab(ChatTab): if len(args) != 1: return nick = args[0] - room = self.get_room() - if not room.joined: + if not self.joined: return current_status = self.core.get_status() - muc.change_nick(self.core.xmpp, room.name, nick, current_status.message, current_status.show) + muc.change_nick(self.core.xmpp, self.name, nick, current_status.message, current_status.show) def command_part(self, arg): """ /part [msg] """ args = arg.split() - room = self.get_room() if len(args): msg = ' '.join(args) else: msg = None - if self.get_room().joined: - muc.leave_groupchat(self.core.xmpp, room.name, room.own_nick, arg) - self.get_room().joined = False - self.get_room().add_message(_("\x195}You left the chatroom\x193}")) + if self.joined: + muc.leave_groupchat(self.core.xmpp, self.name, self.own_nick, arg) + self.joined = False + self.add_message(_("\x195}You left the chatroom\x193}")) self.refresh() self.core.doupdate() - self.core.disable_private_tabs(self.get_room().name) + self.core.disable_private_tabs(self.name) def command_close(self, arg): """ @@ -598,11 +596,10 @@ class MucTab(ChatTab): if len(args) < 1: return nick = args[0] - room = self.get_room() r = None - for user in room.users: + for user in self.users: if user.nick == nick: - r = self.core.open_private_window(room.name, user.nick) + r = self.core.open_private_window(self.name, user.nick) if r and len(args) > 1: msg = arg[len(nick)+1:] self.core.current_tab().command_say(msg) @@ -614,23 +611,22 @@ class MucTab(ChatTab): /topic [new topic] """ if not arg.strip(): - self.core.add_message_to_text_buffer(self.get_room(), - _("The subject of the room is: %s") % self.get_room().topic) - self.text_win.refresh(self.get_room()) + self._text_buffer.add_message_to_text_buffer(self, + _("The subject of the room is: %s") % self.topic) + self.text_win.refresh(self._text_buffer) self.input.refresh() return subject = arg - muc.change_subject(self.core.xmpp, self.get_room().name, subject) + muc.change_subject(self.core.xmpp, self.name, subject) def command_names(self, arg=None): """ /names """ - room = self.get_room() - if not room.joined: + if not self.joined: return users, visitors, moderators, participants, others = [], [], [], [], [] - for user in room.users: + for user in self.users: if user.role == 'visitor': visitors.append(user.nick) elif user.role == 'participant': @@ -652,12 +648,13 @@ class MucTab(ChatTab): message += '%s, ' % item message += '%s\n' % last - self.core.add_message_to_text_buffer(room, message) - self.text_win.refresh(self.get_room()) + # self.core.add_message_to_text_buffer(room, message) + self._text_buffer.add_message(message) + self.text_win.refresh() self.input.refresh() def completion_topic(self, the_input): - current_topic = self.get_room().topic + current_topic = self.topic return the_input.auto_completion([current_topic], '') def command_kick(self, arg): @@ -685,7 +682,7 @@ class MucTab(ChatTab): reason = ' '.join(args[2:]) else: reason = '' - if not self.get_room().joined or \ + if not self.joined or \ not role in ('none', 'visitor', 'participant', 'moderator'): return res = muc.set_user_role(self.core.xmpp, self.get_name(), nick, reason, role) @@ -707,7 +704,7 @@ class MucTab(ChatTab): reason = ' '.join(args[2:]) else: reason = '' - if not self.get_room().joined or \ + if not self.joined or \ not affiliation in ('none', 'member', 'admin', 'owner'): # replace this ↑ with this ↓ when the ban list support is done # not affiliation in ('outcast', 'none', 'member', 'admin', 'owner'): @@ -740,7 +737,7 @@ class MucTab(ChatTab): self.core.command_help('ignore') return nick = args[0] - user = self._room.get_user_by_name(nick) + user = self.get_user_by_name(nick) if not user: self.core.information(_('%s is not in the room') % nick) elif user in self.ignores: @@ -758,7 +755,7 @@ class MucTab(ChatTab): self.core.command_help('unignore') return nick = args[0] - user = self._room.get_user_by_name(nick) + user = self.get_user_by_name(nick) if not user: self.core.information(_('%s is not in the room') % nick) elif user not in self.ignores: @@ -781,7 +778,7 @@ class MucTab(ChatTab): self.topic_win.resize(1, self.width, 0, 0) self.v_separator.resize(self.height-3, 1, 1, 9*(self.width//10)) self.text_win.resize(self.height-4-self.core.information_win_size, text_width, 1, 0) - self.text_win.rebuild_everything(self._room) + self.text_win.rebuild_everything(self._text_buffer) self.user_win.resize(self.height-3-self.core.information_win_size-1, self.width-text_width-1, 1, text_width+1) self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0) self.input.resize(1, self.width, self.height-1, 0) @@ -790,11 +787,11 @@ class MucTab(ChatTab): if self.need_resize: self.resize() log.debug(' TAB Refresh: %s'%self.__class__.__name__) - self.topic_win.refresh(self._room.get_single_line_topic()) - self.text_win.refresh(self._room) + self.topic_win.refresh(self.get_single_line_topic()) + self.text_win.refresh() self.v_separator.refresh() - self.user_win.refresh(self._room.users) - self.info_header.refresh(self._room, self.text_win) + self.user_win.refresh(self.users) + self.info_header.refresh(self, self.text_win) self.tab_win.refresh() self.info_win.refresh(self.core.informations) self.input.refresh() @@ -817,8 +814,8 @@ class MucTab(ChatTab): # If we are not completing a command or a command's argument, complete a nick compare_users = lambda x: x.last_talked - word_list = [user.nick for user in sorted(self._room.users, key=compare_users, reverse=True)\ - if user.nick != self._room.own_nick] + word_list = [user.nick for user in sorted(self.users, key=compare_users, reverse=True)\ + if user.nick != self.own_nick] after = config.get('after_completion', ',')+" " input_pos = self.input.pos + self.input.line_pos if ' ' not in self.input.get_text()[:input_pos] or (self.input.last_completion and\ @@ -830,14 +827,20 @@ class MucTab(ChatTab): empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//')) self.send_composing_chat_state(empty_after) + def get_color_state(self): + return self.color_state + + def set_color_state(self, color): + self.set_color_state(color) + def get_name(self): - return self._room.name + return self.name def get_text_window(self): return self.text_win - def get_room(self): - return self._room + # def get_room(self): + # return self._room @property def state(self): @@ -859,7 +862,7 @@ class MucTab(ChatTab): if self.text_win.built_lines and self.text_win.built_lines[-1] is None: self.text_win.remove_line_separator() curses.curs_set(1) - if self.get_room().joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): + if self.joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('active') def on_scroll_up(self): @@ -889,90 +892,88 @@ class MucTab(ChatTab): role = presence['muc']['role'] jid = presence['muc']['jid'] typ = presence['type'] - room = self.get_room() - if not room.joined: # user in the room BEFORE us. + if not self.joined: # user in the room BEFORE us. # ignore redondant presence message, see bug #1509 - if from_nick not in [user.nick for user in room.users] and typ != "unavailable": + if from_nick not in [user.nick for user in self.users] and typ != "unavailable": new_user = User(from_nick, affiliation, show, status, role, jid) - room.users.append(new_user) - if from_nick == room.own_nick: - room.joined = True + self.users.append(new_user) + if from_nick == self.own_nick: + self.joined = True if self.core.current_tab() == self and self.core.status.show not in ('xa', 'away'): self.send_chat_state('active') new_user.color = get_theme().COLOR_OWN_NICK - room.add_message(_("\x195}Your nickname is \x193}%s") % (from_nick)) + self.add_message(_("\x195}Your nickname is \x193}%s") % (from_nick)) if '170' in status_codes: - room.add_message('\x191}Warning: \x195}this room is publicly logged') + self.add_message('\x191}Warning: \x195}this room is publicly logged') else: change_nick = '303' in status_codes kick = '307' in status_codes and typ == 'unavailable' ban = '301' in status_codes and typ == 'unavailable' - user = room.get_user_by_name(from_nick) + user = self.get_user_by_name(from_nick) # New user if not user: - self.on_user_join(room, from_nick, affiliation, show, status, role, jid) + self.on_user_join(from_nick, affiliation, show, status, role, jid) # nick change elif change_nick: - self.on_user_nick_change(room, presence, user, from_nick, from_room) + self.on_user_nick_change(presence, user, from_nick, from_room) elif ban: - self.on_user_banned(room, presence, user, from_nick) + self.on_user_banned(presence, user, from_nick) # kick elif kick: - self.on_user_kicked(room, presence, user, from_nick) + self.on_user_kicked(presence, user, from_nick) # user quit elif typ == 'unavailable': - self.on_user_leave_groupchat(room, user, jid, status, from_nick, from_room) + self.on_user_leave_groupchat(user, jid, status, from_nick, from_room) # status change else: - self.on_user_change_status(room, user, from_nick, from_room, affiliation, role, show, status) + self.on_user_change_status(user, from_nick, from_room, affiliation, role, show, status) if self.core.current_tab() is self: - self.text_win.refresh(self._room) - self.user_win.refresh(self._room.users) - self.info_header.refresh(self._room, self.text_win) + self.text_win.refresh() + self.user_win.refresh(self.users) + self.info_header.refresh(self, self.text_win) self.input.refresh() self.core.doupdate() - def on_user_join(self, room, from_nick, affiliation, show, status, role, jid): + def on_user_join(self, from_nick, affiliation, show, status, role, jid): """ When a new user joins the groupchat """ user = User(from_nick, affiliation, show, status, role, jid) - room.users.append(user) + self.users.append(user) hide_exit_join = config.get('hide_exit_join', -1) if hide_exit_join != 0: color = user.color[0] if config.get('display_user_color_in_join_part', '') == 'true' else 3 if not jid.full: - room.add_message('\x194}%(spec)s \x19%(color)d}%(nick)s\x195} joined the room' % {'nick':from_nick, 'color':color, 'spec':get_theme().CHAR_JOIN}) + self.add_message('\x194}%(spec)s \x19%(color)d}%(nick)s\x195} joined the room' % {'nick':from_nick, 'color':color, 'spec':get_theme().CHAR_JOIN}) else: - room.add_message('\x194}%(spec)s \x19%(color)d}%(nick)s \x195}(\x194}%(jid)s\x195}) joined the room' % {'spec':get_theme().CHAR_JOIN, 'nick':from_nick, 'color':color, 'jid':jid.full}) + self.add_message('\x194}%(spec)s \x19%(color)d}%(nick)s \x195}(\x194}%(jid)s\x195}) joined the room' % {'spec':get_theme().CHAR_JOIN, 'nick':from_nick, 'color':color, 'jid':jid.full}) self.core.on_user_rejoined_private_conversation(room.name, from_nick) - - def on_user_nick_change(self, room, presence, user, from_nick, from_room): + def on_user_nick_change(self, presence, user, from_nick, from_room): new_nick = presence.find('{%s}x/{%s}item' % (NS_MUC_USER, NS_MUC_USER)).attrib['nick'] - if user.nick == room.own_nick: - room.own_nick = new_nick + if user.nick == self.own_nick: + self.own_nick = new_nick # also change our nick in all private discussion of this room for _tab in self.core.tabs: - if isinstance(_tab, PrivateTab) and JID(_tab.get_name()).bare == room.name: - _tab.get_room().own_nick = new_nick + if isinstance(_tab, PrivateTab) and JID(_tab.get_name()).bare == self.name: + _tab.own_nick = new_nick user.change_nick(new_nick) color = user.color[0] if config.get('display_user_color_in_join_part', '') == 'true' else 3 - room.add_message('\x19%(color)d}%(old)s\x195} is now known as \x19%(color)d}%(new)s' % {'old':from_nick, 'new':new_nick, 'color':color}) + self.add_message('\x19%(color)d}%(old)s\x195} is now known as \x19%(color)d}%(new)s' % {'old':from_nick, 'new':new_nick, 'color':color}) # rename the private tabs if needed - self.core.rename_private_tabs(room.name, from_nick, new_nick) + self.core.rename_private_tabs(self.name, from_nick, new_nick) - def on_user_banned(self, room, presence, user, from_nick): + def on_user_banned(self, presence, user, from_nick): """ When someone is banned from a muc """ - room.users.remove(user) + self.users.remove(user) by = presence.find('{%s}x/{%s}item/{%s}actor' % (NS_MUC_USER, NS_MUC_USER, NS_MUC_USER)) reason = presence.find('{%s}x/{%s}item/{%s}reason' % (NS_MUC_USER, NS_MUC_USER, NS_MUC_USER)) by = by.attrib['jid'] if by is not None else None - if from_nick == room.own_nick: # we are banned - room.disconnect() + if from_nick == self.own_nick: # we are banned + self.disconnect() self.core.disable_private_tabs(room.name) self.tab_win.refresh() self.core.doupdate() @@ -1611,7 +1612,7 @@ class RosterInfoTab(Tab): self.v_separator.refresh() self.roster_win.refresh(roster) self.contact_info_win.refresh(self.roster_win.get_selected_row()) - self.information_win.refresh(self.core.informations) + self.information_win.refresh() self.tab_win.refresh() self.input.refresh() diff --git a/src/windows.py b/src/windows.py index 1701fee7..dfe46a14 100644 --- a/src/windows.py +++ b/src/windows.py @@ -606,7 +606,7 @@ class TextWin(Win): self.built_lines.pop(0) return len(lines) - def refresh(self, room): + def refresh(self): log.debug('Refresh: %s'%self.__class__.__name__) if self.height <= 0: return -- cgit v1.2.3 From e3477d7db88e787442cf65afce95cd48ed927f56 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 03:22:19 +0100 Subject: Remove the Room class. fixes #2122 --- src/core.py | 156 +++++++++++++++------------------- src/room.py | 132 ----------------------------- src/tabs.py | 242 ++++++++++++++++++++++++++++++++++++----------------- src/text_buffer.py | 7 +- src/windows.py | 10 +-- 5 files changed, 241 insertions(+), 306 deletions(-) delete mode 100644 src/room.py diff --git a/src/core.py b/src/core.py index ec821cbd..35cc6951 100644 --- a/src/core.py +++ b/src/core.py @@ -40,7 +40,6 @@ from data_forms import DataFormsTab from config import config, options from logger import logger from user import User -from room import Room from roster import Roster, RosterGroup, roster from contact import Contact, Resource from text_buffer import TextBuffer @@ -335,10 +334,10 @@ class Core(object): nick = message['mucnick'] room_from = message.getMucroom() 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): - tab.get_room().get_user_by_name(nick).chatstate = state + if tab and tab.get_user_by_name(nick): + tab.get_user_by_name(nick).chatstate = state if tab == self.current_tab(): - tab.user_win.refresh(tab._room.users) + tab.user_win.refresh(tab.users) tab.input.refresh() self.doupdate() @@ -357,7 +356,6 @@ class Core(object): logger.log_roster_change(jid.bare, 'got offline') if not contact: return - log.debug('on_got_offline: %s' % presence) resource = contact.get_resource_by_fulljid(jid.full) if not resource: return @@ -403,7 +401,7 @@ class Core(object): """ tab = self.get_tab_by_name(jid, tabs.ConversationTab) if tab: - self.add_message_to_text_buffer(tab.get_room(), msg) + self.add_message_to_text_buffer(tab._text_buffer, msg) def on_failed_connection(self): """ @@ -417,7 +415,7 @@ class Core(object): """ for tab in self.tabs: if isinstance(tab, tabs.MucTab): - tab.get_room().disconnect() + tab.disconnect() self.information(_("Disconnected from server.")) def on_failed_auth(self, event): @@ -518,7 +516,7 @@ class Core(object): def on_user_changed_status_in_private(self, jid, msg): tab = self.get_tab_by_name(jid) if tab: # display the message in private - tab.get_room().add_message(msg) + tab.add_message(msg) def on_message(self, message): """ @@ -544,16 +542,16 @@ class Core(object): jid = message['from'] nick_from = jid.resource room_from = jid.bare - room = self.get_room_by_name(jid.full) # get the tab with the private conversation - if not room: # It's the first message we receive: create the tab - room = self.open_private_window(room_from, nick_from, False) - if not room: + tab = self.get_tab_by_name(jid.full, tabs.PrivateTab) # get the tab with the private conversation + if not tab: # It's the first message we receive: create the tab + tab = self.open_private_window(room_from, nick_from, False) + if not tab: return body = xhtml.get_body_from_message_stanza(message) if not body: return - room.add_message(body, time=None, nickname=nick_from, - forced_user=self.get_room_by_name(room_from).get_user_by_name(nick_from)) + tab.add_message(body, time=None, nickname=nick_from, + forced_user=self.get_tab_by_name(room_from, tabs.MucTab).get_user_by_name(nick_from)) conversation = self.get_tab_by_name(jid.full, tabs.PrivateTab) if conversation and conversation.remote_wants_chatstates is None: if message['chat_state']: @@ -607,7 +605,7 @@ class Core(object): remote_nick = roster.get_contact_by_jid(jid.bare).get_name() or jid.user else: remote_nick = jid.user - conversation.get_room().add_message(body, nickname=remote_nick, nick_color=get_theme().COLOR_REMOTE_USER) + conversation._text_buffer.add_message(body, nickname=remote_nick, nick_color=get_theme().COLOR_REMOTE_USER) if conversation.remote_wants_chatstates is None: if message['chat_state']: conversation.remote_wants_chatstates = True @@ -767,7 +765,7 @@ class Core(object): for tab in self.tabs: if isinstance(tab, tabs.ConversationTab): if tab.get_name() == jid: - return tab.get_room() + return tab return None def get_tab_by_name(self, name, typ=None): @@ -788,16 +786,6 @@ class Core(object): return tab return None - def get_room_by_name(self, name): - """ - returns the room that has this name - """ - for tab in self.tabs: - if (isinstance(tab, tabs.MucTab) or - isinstance(tab, tabs.PrivateTab)) and tab.get_name() == name: - return tab.get_room() - return None - def init_curses(self, stdscr): """ ncurses initialization @@ -859,8 +847,7 @@ class Core(object): """ Open a new tab.MucTab containing a muc Room, using the specified nick """ - r = Room(room, nick) - new_tab = tabs.MucTab(r) + new_tab = tabs.MucTab(room, nick) self.add_tab(new_tab, focus) self.refresh_window() @@ -947,20 +934,20 @@ class Core(object): def room_error(self, error, room_name): """ - Display the error on the room window + Display the error in the tab """ - room = self.get_room_by_name(room_name) + tab = self.get_tab_by_name(room_name) error_message = self.get_error_message_from_error_stanza(error) - self.add_message_to_text_buffer(room, error_message) + self.add_message_to_text_buffer(tab._text_buffer, error_message) code = error['error']['code'] if code == '401': msg = _('To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)') - self.add_message_to_text_buffer(room, msg) + self.add_message_to_text_buffer(tab._text_buffer, msg) if code == '409': if config.get('alternative_nickname', '') != '': - self.command_join('%s/%s'% (room.name, room.own_nick+config.get('alternative_nickname', ''))) + self.command_join('%s/%s'% (tab.name, tab.own_nick+config.get('alternative_nickname', ''))) else: - self.add_message_to_text_buffer(room, _('You can join the room with an other nick, by typing "/join /other_nick"')) + self.add_message_to_text_buffer(tab._text_buffer, _('You can join the room with an other nick, by typing "/join /other_nick"')) self.refresh_window() def open_conversation_window(self, jid, focus=True): @@ -986,21 +973,18 @@ class Core(object): if isinstance(tab, tabs.PrivateTab): if tab.get_name() == complete_jid: self.command_win('%s' % tab.nb) - return tab.get_room() + return tab # create the new tab - room = self.get_room_by_name(room_name) - if not room: + tab = self.get_tab_by_name(room_name, tabs.MucTab) + if not tab: return None - own_nick = room.own_nick - r = Room(complete_jid, own_nick) # PrivateRoom here - new_tab = tabs.PrivateTab(r) + new_tab = tabs.PrivateTab(complete_jid, tab.own_nick) if not focus: new_tab.state = "private" # insert it in the tabs self.add_tab(new_tab, focus) - # self.window.new_room(r) self.refresh_window() - return r + return new_tab def on_groupchat_subject(self, message): """ @@ -1008,15 +992,15 @@ class Core(object): """ nick_from = message['mucnick'] room_from = message.getMucroom() - room = self.get_room_by_name(room_from) + tab = self.get_tab_by_name(room_from, tabs.MucTab) subject = message['subject'] - if not subject or not room: + if not subject or not tab: return if nick_from: - self.add_message_to_text_buffer(room, _("%(nick)s set the subject to: %(subject)s") % {'nick':nick_from, 'subject':subject}, time=None) + self.add_message_to_text_buffer(tab._text_buffer, _("%(nick)s set the subject to: %(subject)s") % {'nick':nick_from, 'subject':subject}, time=None) else: - self.add_message_to_text_buffer(room, _("The subject is: %(subject)s") % {'subject':subject}, time=None) - room.topic = subject + self.add_message_to_text_buffer(tab._text_buffer, _("The subject is: %(subject)s") % {'subject':subject}, time=None) + tab.topic = subject if self.get_tab_by_name(room_from, tabs.MucTab) is self.current_tab(): self.refresh_window() @@ -1044,34 +1028,33 @@ class Core(object): room_from = message.getMucroom() if message['type'] == 'error': # Check if it's an error return self.room_error(message, room_from) - 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\ - tab.get_room().get_user_by_name(nick_from) in tab.ignores: - return - if not room: + if not tab: self.information(_("message received for a non-existing room: %s") % (room_from)) return + if tab.get_user_by_name(nick_from) and\ + tab.get_user_by_name(nick_from) in tab.ignores: + return body = xhtml.get_body_from_message_stanza(message) if body: date = date if delayed == True else None - self.add_message_to_text_buffer(room, body, date, nick_from, history=True if date else False) + tab.add_message(body, date, nick_from, history=True if date else False) if tab is self.current_tab(): - tab.text_win.refresh(tab._room) - tab.info_header.refresh(tab._room, tab.text_win) + tab.text_win.refresh() + tab.info_header.refresh(tab, tab.text_win) self.refresh_tab_win() if 'message' in config.get('beep_on', 'highlight private').split(): curses.beep() - def add_message_to_text_buffer(self, room, txt, time=None, nickname=None, history=None): + def add_message_to_text_buffer(self, buff, txt, time=None, nickname=None, history=None): """ Add the message to the room if possible, else, add it to the Info window (in the Info tab of the info window in the RosterTab) """ - if not room: + if not buff: self.information('Trying to add a message in no room: %s' % txt, 'Error') else: - room.add_message(txt, time, nickname, history=history) + buff.add_message(txt, time, nickname, history=history) def command_help(self, arg): """ @@ -1121,13 +1104,13 @@ class Core(object): pres['type'] = show pres.send() current = self.current_tab() - if isinstance(current, tabs.MucTab) and current.get_room().joined and show in ('away', 'xa'): + if isinstance(current, tabs.MucTab) and current.joined and show in ('away', 'xa'): current.send_chat_state('inactive') for tab in self.tabs: - if isinstance(tab, tabs.MucTab) and tab.get_room().joined: - muc.change_show(self.xmpp, tab.get_room().name, tab.get_room().own_nick, show, msg) + if isinstance(tab, tabs.MucTab) and tab.joined: + muc.change_show(self.xmpp, tab.name, tab.own_nick, show, msg) self.set_status(show, msg) - if isinstance(current, tabs.MucTab) and current.get_room().joined and show not in ('away', 'xa'): + if isinstance(current, tabs.MucTab) and current.joined and show not in ('away', 'xa'): current.send_chat_state('active') def completion_status(self, the_input): @@ -1281,11 +1264,11 @@ class Core(object): args = common.shell_split(arg) password = None if len(args) == 0: - t = self.current_tab() - if not isinstance(t, tabs.MucTab) and not isinstance(t, tabs.PrivateTab): + tab = self.current_tab() + if not isinstance(tab, tabs.MucTab) and not isinstance(tab, tabs.PrivateTab): return - room = JID(t.get_name()).bare - nick = t.get_room().own_nick + room = JID(tab.get_name()).bare + nick = tab.own_nick else: info = JID(args[0]) if info.resource == '': @@ -1296,12 +1279,12 @@ class Core(object): else: nick = info.resource if info.bare == '': # happens with /join /nickname, which is OK - t = self.current_tab() - if not isinstance(t, tabs.MucTab): + tab = self.current_tab() + if not isinstance(tab, tabs.MucTab): return - room = t.get_name() + room = tab.get_name() if nick == '': - nick = t.get_room().own_nick + nick = tab.own_nick else: room = info.bare if room.find('@') == -1: # no server is provided, like "/join hello" @@ -1314,25 +1297,25 @@ class Core(object): self.information(_("You didn't specify a server for the room you want to join"), 'Error') return room = room.lower() - r = self.get_room_by_name(room) + tab = self.get_tab_by_name(room, tabs.MucTab) if len(args) == 2: # a password is provided password = args[1] - if r and r.joined: # if we are already in the room - self.focus_tab_named(r.name) + if tab and tab.joined: # if we are already in the room + self.focus_tab_named(tab.name) return if room.startswith('@'): room = room[1:] current_status = self.get_status() - if r and not r.joined: + if tab and not tab.joined: muc.join_groupchat(self.xmpp, room, nick, password, histo_length, current_status.message, current_status.show) - if not r: # if the room window exists, we don't recreate it. + if not tab: self.open_new_room(room, nick) muc.join_groupchat(self.xmpp, room, nick, password, histo_length, current_status.message, current_status.show) else: - r.own_nick = nick - r.users = [] + tab.own_nick = nick + tab.users = [] self.enable_private_tabs(room) def get_bookmark_nickname(self, room_name): @@ -1356,10 +1339,10 @@ class Core(object): if len(args) == 0 and not isinstance(self.current_tab(), tabs.MucTab): return if len(args) == 0: - room = self.current_tab().get_room() - roomname = self.current_tab().get_name() - if room.joined: - nick = room.own_nick + tab = self.current_tab() + roomname = tab.get_name() + if tab.joined: + nick = tab.own_nick else: info = JID(args[0]) if info.resource != '': @@ -1459,9 +1442,9 @@ class Core(object): 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 + if tab.joined: + muc.leave_groupchat(tab.core.xmpp, tab.get_name(), tab.own_nick, message) + tab.joined = False self.command_join(tab.get_name()) def command_bind(self, arg): @@ -1518,7 +1501,7 @@ class Core(object): self.pop_information_win_up(nb_lines, popup_time) else: if self.information_win_size != 0: - self.information_win.refresh(self.information_buffer) + self.information_win.refresh() self.current_tab().input.refresh() def disconnect(self, msg=None, reconnect=False): @@ -1528,7 +1511,7 @@ class Core(object): """ 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) + muc.leave_groupchat(self.xmpp, tab.name, tab.own_nick, msg) roster.empty() self.save_config() # Ugly fix thanks to gmail servers @@ -1577,7 +1560,6 @@ class Core(object): def remove_timed_event(self, event): if event and event in self.timed_events: - log.debug('removing event') self.timed_events.remove(event) def add_timed_event(self, event): diff --git a/src/room.py b/src/room.py deleted file mode 100644 index ad52451c..00000000 --- a/src/room.py +++ /dev/null @@ -1,132 +0,0 @@ -# Copyright 2010-2011 Florent Le Coz -# -# This file is part of Poezio. -# -# Poezio is free software: you can redistribute it and/or modify -# it under the terms of the zlib license. See the COPYING file. - -from text_buffer import TextBuffer, Message -from datetime import datetime -from random import randrange -from config import config -from logger import logger - -import common -from theming import get_theme - -import logging -import curses - -log = logging.getLogger(__name__) - -class Room(TextBuffer): - def __init__(self, name, nick, messages_nb_limit=config.get('max_messages_in_memory', 2048)): - TextBuffer.__init__(self, messages_nb_limit) - self.name = name - self.own_nick = nick - self.state = 'normal' # color used in RoomInfo - self.joined = False # false until self presence is receied - self.users = [] # User objects - self.topic = '' - - def disconnect(self): - """ - Set the state of the room as not joined, so - we can know if we can join it, send messages to it, etc - """ - self.users = [] - self.state = 'disconnected' - self.joined = False - - def get_single_line_topic(self): - """ - Return the topic as a single-line string (for the window header) - """ - return self.topic.replace('\n', '|') - - def log_message(self, txt, time, nickname): - """ - Log the messages in the archives, if it needs - to be - """ - if time is None and self.joined: # don't log the history messages - logger.log_message(self.name, nickname, txt) - - def do_highlight(self, txt, time, nickname): - """ - Set the tab color and returns the nick color - """ - color = None - if not time and nickname and nickname != self.own_nick and self.joined: - if self.own_nick.lower() in txt.lower(): - if self.state != 'current': - self.state = 'highlight' - color = get_theme().COLOR_HIGHLIGHT_NICK - else: - highlight_words = config.get('highlight_on', '').split(':') - for word in highlight_words: - if word and word.lower() in txt.lower(): - if self.state != 'current': - self.state = 'highlight' - color = get_theme().COLOR_HIGHLIGHT_NICK - break - if color: - beep_on = config.get('beep_on', 'highlight private').split() - if 'highlight' in beep_on and 'message' not in beep_on: - curses.beep() - return color - - def get_user_by_name(self, nick): - """ - Gets the user associated with the given nick, or None if not found - """ - for user in self.users: - if user.nick == nick: - return user - return None - - def add_message(self, txt, time=None, nickname=None, forced_user=None, nick_color=None, history=None): - """ - Note that user can be None even if nickname is not None. It happens - when we receive an history message said by someone who is not - in the room anymore - """ - self.log_message(txt, time, nickname) - special_message = False - if txt.startswith('/me '): - txt = "\x192}* \x195}" + nickname + ' ' + txt[4:] - special_message = True - user = self.get_user_by_name(nickname) if nickname is not None else None - if user: - user.set_last_talked(datetime.now()) - if not user and forced_user: - user = forced_user - if not time and nickname and\ - nickname != self.own_nick and\ - self.state != 'current': - if self.state != 'highlight': - self.state = 'message' - nick_color = nick_color or None - if not nickname or time: - txt = '\x195}%s' % (txt,) - else: # TODO - highlight = self.do_highlight(txt, time, nickname) - if highlight: - nick_color = highlight - if special_message: - txt = '\x195}%s' % (txt,) - nickname = None - time = time or datetime.now() - message = Message(txt='%s\x19o'%(txt.replace('\t', ' '),), nick_color=nick_color, - time=time, str_time=time.strftime("%Y-%m-%d %H:%M:%S")\ - if history else time.strftime("%H:%M:%S"),\ - nickname=nickname, user=user) - while len(self.messages) > self.messages_nb_limit: - self.messages.pop(0) - self.messages.append(message) - for window in self.windows: # make the associated windows - # build the lines from the new message - nb = window.build_new_message(message, history=history) - if window.pos != 0: - window.scroll_up(nb) - return nb diff --git a/src/tabs.py b/src/tabs.py index 9fe685a3..6afb0dd1 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -234,15 +234,6 @@ class Tab(object): """ self.state = 'current' - def add_message(self): - """ - Adds a message in the tab. - If the tab cannot add a message in itself (for example - FormTab, where text is not intented to be appened), it returns False. - If the tab can, it returns True - """ - return False - def on_scroll_down(self): """ Defines what happens when we scrol down @@ -410,15 +401,20 @@ class MucTab(ChatTab): It contains an userlist, an input, a topic, an information and a chat zone """ message_type = 'groupchat' - def __init__(self, room): - ChatTab.__init__(self, room) + def __init__(self, jid, nick): + ChatTab.__init__(self) + self.own_nick = nick + self.name = jid + self.joined = False + self.users = [] + self.topic = '' self.remote_wants_chatstates = True # We send active, composing and paused states to the MUC because # the chatstate may or may not be filtered by the MUC, # that’s not our problem. self.topic_win = windows.Topic() self.text_win = windows.TextWin() - room.add_window(self.text_win) + self._text_buffer.add_window(self.text_win) self.v_separator = windows.VerticalSeparator() self.user_win = windows.UserList() self.info_header = windows.MucInfoWin() @@ -793,7 +789,7 @@ class MucTab(ChatTab): self.user_win.refresh(self.users) self.info_header.refresh(self, self.text_win) self.tab_win.refresh() - self.info_win.refresh(self.core.informations) + self.info_win.refresh() self.input.refresh() def on_input(self, key): @@ -839,9 +835,6 @@ class MucTab(ChatTab): def get_text_window(self): return self.text_win - # def get_room(self): - # return self._room - @property def state(self): return self._room.state @@ -974,7 +967,7 @@ class MucTab(ChatTab): by = by.attrib['jid'] if by is not None else None if from_nick == self.own_nick: # we are banned self.disconnect() - self.core.disable_private_tabs(room.name) + self.core.disable_private_tabs(self.name) self.tab_win.refresh() self.core.doupdate() if by: @@ -989,19 +982,19 @@ class MucTab(ChatTab): kick_msg = _('\x191}%(spec)s \x19%(color)d}%(nick)s\x195} has been banned') % {'spec':get_theme().CHAR_KICK, 'nick':from_nick.replace('"', '\\"'), 'color':color} if reason is not None and reason.text: kick_msg += _('\x195} Reason: \x196}%(reason)s\x195}') % {'reason': reason.text} - room.add_message(kick_msg) + self._text_buffer.add_message(kick_msg) - def on_user_kicked(self, room, presence, user, from_nick): + def on_user_kicked(self, presence, user, from_nick): """ When someone is kicked from a muc """ - room.users.remove(user) + self.users.remove(user) by = presence.find('{%s}x/{%s}item/{%s}actor' % (NS_MUC_USER, NS_MUC_USER, NS_MUC_USER)) reason = presence.find('{%s}x/{%s}item/{%s}reason' % (NS_MUC_USER, NS_MUC_USER, NS_MUC_USER)) by = by.attrib['jid'] if by is not None else None - if from_nick == room.own_nick: # we are kicked - room.disconnect() - self.core.disable_private_tabs(room.name) + if from_nick == self.own_nick: # we are kicked + self.disconnect() + self.core.disable_private_tabs(self.name) self.tab_win.refresh() self.core.doupdate() if by: @@ -1010,7 +1003,7 @@ class MucTab(ChatTab): kick_msg = _('\x191}%(spec)s \x193}You\x195} have been kicked.') % {'spec':get_theme().CHAR_KICK} # try to auto-rejoin if config.get('autorejoin', 'false') == 'true': - muc.join_groupchat(self.core.xmpp, room.name, room.own_nick) + muc.join_groupchat(self.core.xmpp, self.name, self.own_nick) else: color = user.color[0] if config.get('display_user_color_in_join_part', '') == 'true' else 3 if by: @@ -1019,16 +1012,16 @@ class MucTab(ChatTab): kick_msg = _('\x191}%(spec)s \x19%(color)d}%(nick)s\x195} has been kicked') % {'spec':get_theme().CHAR_KICK, 'nick':from_nick.replace('"', '\\"'), 'color':color} if reason is not None and reason.text: kick_msg += _('\x195} Reason: \x196}%(reason)s') % {'reason': reason.text} - room.add_message(kick_msg) + self.add_message(kick_msg) - def on_user_leave_groupchat(self, room, user, jid, status, from_nick, from_room): + def on_user_leave_groupchat(self, user, jid, status, from_nick, from_room): """ When an user leaves a groupchat """ - room.users.remove(user) - if room.own_nick == user.nick: + self.users.remove(user) + if self.own_nick == user.nick: # We are now out of the room. Happens with some buggy (? not sure) servers - room.disconnect() + self.disconnect() self.core.disable_private_tabs(from_room) self.tab_win.refresh() self.core.doupdate() @@ -1042,11 +1035,11 @@ class MucTab(ChatTab): leave_msg = _('\x191}%(spec)s \x19%(color)d}%(nick)s\x195} (\x194}%(jid)s\x195}) has left the room') % {'spec':get_theme().CHAR_QUIT, 'nick':from_nick, 'color':color, 'jid':jid.full} if status: leave_msg += ' (%s)' % status - room.add_message(leave_msg) + self.add_message(leave_msg) self.core.refresh_window() self.core.on_user_left_private_conversation(from_room, from_nick, status) - def on_user_change_status(self, room, user, from_nick, from_room, affiliation, role, show, status): + def on_user_change_status(self, user, from_nick, from_room, affiliation, role, show, status): """ When an user changes her status """ @@ -1054,7 +1047,7 @@ class MucTab(ChatTab): display_message = False # flag to know if something significant enough # to be displayed has changed color = user.color[0] if config.get('display_user_color_in_join_part', '') == 'true' else 3 - if from_nick == room.own_nick: + if from_nick == self.own_nick: msg = _('\x193}You\x195} changed: ') else: msg = _('\x19%(color)d}%(nick)s\x195} changed: ') % {'nick': from_nick.replace('"', '\\"'), 'color': color} @@ -1086,27 +1079,119 @@ class MucTab(ChatTab): hide_status_change = -1 if (hide_status_change == -1 or \ user.has_talked_since(hide_status_change) or\ - user.nick == room.own_nick)\ + user.nick == self.own_nick)\ and\ (affiliation != user.affiliation or\ role != user.role or\ show != user.show or\ status != user.status): # display the message in the room - room.add_message(msg) + self._text_buffer.add_message(msg) self.core.on_user_changed_status_in_private('%s/%s' % (from_room, from_nick), msg) # finally, effectively change the user status user.update(affiliation, show, status, role) + def disconnect(self): + """ + Set the state of the room as not joined, so + we can know if we can join it, send messages to it, etc + """ + self.users = [] + self.state = 'disconnected' + self.joined = False + + def get_single_line_topic(self): + """ + Return the topic as a single-line string (for the window header) + """ + return self.topic.replace('\n', '|') + + def log_message(self, txt, time, nickname): + """ + Log the messages in the archives, if it needs + to be + """ + if time is None and self.joined: # don't log the history messages + logger.log_message(self.name, nickname, txt) + + def do_highlight(self, txt, time, nickname): + """ + Set the tab color and returns the nick color + """ + color = None + if not time and nickname and nickname != self.own_nick and self.joined: + if self.own_nick.lower() in txt.lower(): + if self.state != 'current': + self.state = 'highlight' + color = get_theme().COLOR_HIGHLIGHT_NICK + else: + highlight_words = config.get('highlight_on', '').split(':') + for word in highlight_words: + if word and word.lower() in txt.lower(): + if self.state != 'current': + self.state = 'highlight' + color = get_theme().COLOR_HIGHLIGHT_NICK + break + if color: + beep_on = config.get('beep_on', 'highlight private').split() + if 'highlight' in beep_on and 'message' not in beep_on: + curses.beep() + return color + + def get_user_by_name(self, nick): + """ + Gets the user associated with the given nick, or None if not found + """ + for user in self.users: + if user.nick == nick: + return user + return None + + def add_message(self, txt, time=None, nickname=None, forced_user=None, nick_color=None, history=None): + """ + Note that user can be None even if nickname is not None. It happens + when we receive an history message said by someone who is not + in the room anymore + """ + self.log_message(txt, time, nickname) + special_message = False + if txt.startswith('/me '): + txt = "\x192}* \x195}" + nickname + ' ' + txt[4:] + special_message = True + user = self.get_user_by_name(nickname) if nickname is not None else None + if user: + user.set_last_talked(datetime.now()) + if not user and forced_user: + user = forced_user + if not time and nickname and\ + nickname != self.own_nick and\ + self.state != 'current': + if self.state != 'highlight': + self.state = 'message' + nick_color = nick_color or None + if not nickname or time: + txt = '\x195}%s' % (txt,) + else: # TODO + highlight = self.do_highlight(txt, time, nickname) + if highlight: + nick_color = highlight + if special_message: + txt = '\x195}%s' % (txt,) + nickname = None + time = time or datetime.now() + self._text_buffer.add_message(txt, time, nickname, nick_color, history, user) + class PrivateTab(ChatTab): """ The tab containg a private conversation (someone from a MUC) """ message_type = 'chat' - def __init__(self, room): - ChatTab.__init__(self, room) + def __init__(self, name, nick): + ChatTab.__init__(self) + self.own_nick = nick + self.name = name self.text_win = windows.TextWin() - room.add_window(self.text_win) + self._text_buffer.add_window(self.text_win) self.info_header = windows.PrivateInfoWin() self.input = windows.MessageInput() # keys @@ -1117,7 +1202,7 @@ class PrivateTab(ChatTab): self.commands['close'] = (self.command_unquery, _("Usage: /close\nClose: close the tab"), None) self.commands['version'] = (self.command_version, _('Usage: /version\nVersion: get the software version of the current interlocutor (usually its XMPP client and Operating System)'), None) self.resize() - self.parent_muc = self.core.get_tab_by_name(JID(room.name).bare, MucTab) + self.parent_muc = self.core.get_tab_by_name(JID(name).bare, MucTab) self.on = True def completion(self): @@ -1137,10 +1222,9 @@ class PrivateTab(ChatTab): needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' msg['chat_state'] = needed msg.send() - self.core.add_message_to_text_buffer(self.get_room(), line, None, self.core.own_nick or self.get_room().own_nick) - logger.log_message(JID(self.get_name()).bare, self.core.own_nick, line) + self.core.add_message_to_text_buffer(self._text_buffer, line, None, self.core.own_nick or self.own_nick) self.cancel_paused_delay() - self.text_win.refresh(self._room) + self.text_win.refresh() self.input.refresh() def command_unquery(self, arg): @@ -1161,7 +1245,7 @@ class PrivateTab(ChatTab): res.get('version') or _('unknown'), res.get('os') or _('on an unknown platform')) self.core.information(version, 'Info') - jid = self.get_room().name + jid = self.name self.core.xmpp.plugin['xep_0092'].get_version(jid, callback=callback) def command_info(self, arg): @@ -1171,7 +1255,7 @@ class PrivateTab(ChatTab): if arg: self.parent_muc.command_info(arg) else: - user = JID(self.get_room().name).resource + user = JID(self.name).resource self.parent_muc.command_info(user) def resize(self): @@ -1179,7 +1263,7 @@ class PrivateTab(ChatTab): return self.need_resize = False self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0) - self.text_win.rebuild_everything(self._room) + self.text_win.rebuild_everything(self._text_buffer) self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0) self.input.resize(1, self.width, self.height-1, 0) @@ -1187,14 +1271,14 @@ class PrivateTab(ChatTab): if self.need_resize: self.resize() log.debug(' TAB Refresh: %s'%self.__class__.__name__) - self.text_win.refresh(self._room) - self.info_header.refresh(self._room, self.text_win, self.chatstate) - self.info_win.refresh(self.core.informations) + self.text_win.refresh() + self.info_header.refresh(self.name, self.text_win, self.chatstate) + self.info_win.refresh() self.tab_win.refresh() self.input.refresh() def refresh_info_header(self): - self.info_header.refresh(self._room, self.text_win, self.chatstate) + self.info_header.refresh(self.name, self.text_win, self.chatstate) self.input.refresh() @property @@ -1206,7 +1290,7 @@ class PrivateTab(ChatTab): self._room.state = value def get_name(self): - return self._room.name + return self.name def on_input(self, key): if key in self.key_func: @@ -1216,8 +1300,8 @@ class PrivateTab(ChatTab): if not self.on: return False empty_after = self.input.get_text() == '' or (self.input.get_text().startswith('/') and not self.input.get_text().startswith('//')) - tab = self.core.get_tab_by_name(JID(self.get_room().name).bare, MucTab) - if tab and tab.get_room().joined: + tab = self.core.get_tab_by_name(JID(self.name).bare, MucTab) + if tab and tab.joined: self.send_composing_chat_state(empty_after) return False @@ -1225,13 +1309,15 @@ class PrivateTab(ChatTab): self.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() - if self.get_room().joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): + tab = self.core.get_tab_by_name(JID(self.name).bare, MucTab) + if tab.joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('inactive') def on_gain_focus(self): self.state = 'current' curses.curs_set(1) - if self.get_room().joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): + tab = self.core.get_tab_by_name(JID(self.name).bare, MucTab) + if tab.joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('active') def on_scroll_up(self): @@ -1246,9 +1332,6 @@ class PrivateTab(ChatTab): self.text_win.resize(self.height-3-self.core.information_win_size, self.width, 0, 0) self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0) - def get_room(self): - return self._room - def get_text_window(self): return self.text_win @@ -1257,9 +1340,9 @@ class PrivateTab(ChatTab): The user changed her nick in the corresponding muc: update the tab’s name and display a message. """ - self.get_room().add_message(_('"[%(old_nick)s]" is now known as "[%(new_nick)s]"') % {'old_nick':old_nick.replace('"', '\\"'), 'new_nick':new_nick.replace('"', '\\"')}) - new_jid = JID(self.get_room().name).bare+'/'+new_nick - self.get_room().name = new_jid + self.add_message('\x193}%(old)s\x195} is now known as \x193}%(new)s' % {'old':old_nick, 'new':new_nick}) + new_jid = JID(self.name).bare+'/'+new_nick + self.name = new_jid def user_left(self, status_message, from_nick): """ @@ -1267,9 +1350,9 @@ class PrivateTab(ChatTab): """ self.deactivate() if not status_message: - self.get_room().add_message(_('\x191}%(spec)s \x193}%(nick)s\x195} has left the room') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT.replace('"', '\\"')}) + self.add_message(_('\x191}%(spec)s \x193}%(nick)s\x195} has left the room') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT.replace('"', '\\"')}) else: - self.get_room().add_message(_('\x191}%(spec)s \x193}%(nick)s\x195} has left the room (%(status)s)"') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT, 'status': status_message.replace('"', '\\"')}) + self.add_message(_('\x191}%(spec)s \x193}%(nick)s\x195} has left the room (%(status)s)"') % {'nick':from_nick.replace('"', '\\"'), 'spec':get_theme().CHAR_QUIT, 'status': status_message.replace('"', '\\"')}) if self.core.current_tab() is self: self.refresh() self.core.doupdate() @@ -1279,18 +1362,26 @@ class PrivateTab(ChatTab): The user (or at least someone with the same nick) came back in the MUC """ self.activate() - self.get_room().add_message('\x194}%(spec)s \x19%(color)d}%(nick)s\x195} joined the room' % {'nick':nick, 'color':user.color, 'spec':get_theme().CHAR_JOIN}) + tab = self.core.get_tab_by_name(JID(self.name).bare, MucTab) + color = None + if tab: + user = tab.get_user_by_name(nick) + if user: + color = user.color + self.add_message('\x194}%(spec)s \x19%(color)d}%(nick)s\x195} joined the room' % {'nick':nick, 'color': color or 3, 'spec':get_theme().CHAR_JOIN}) if self.core.current_tab() is self: self.refresh() self.core.doupdate() - def activate(self): self.on = True def deactivate(self): self.on = False + def add_message(self, txt, time=None, nickname=None, forced_user=None): + self._text_buffer.add_message(txt, time, nickname, None, None, forced_user) + class RosterInfoTab(Tab): """ A tab, splitted in two, containing the roster and infos @@ -1675,9 +1766,6 @@ class RosterInfoTab(Tab): else: curses.curs_set(1) - def add_message(self): - return False - def move_cursor_down(self): if isinstance(self.input, windows.CommandInput): return @@ -1774,12 +1862,11 @@ class ConversationTab(ChatTab): """ message_type = 'chat' def __init__(self, jid): - txt_buff = text_buffer.TextBuffer() - ChatTab.__init__(self, txt_buff) + ChatTab.__init__(self) self.state = 'normal' self._name = jid # a conversation tab is linked to one specific full jid OR bare jid self.text_win = windows.TextWin() - txt_buff.add_window(self.text_win) + self._text_buffer.add_window(self.text_win) self.upper_bar = windows.ConversationStatusMessageWin() self.info_header = windows.ConversationInfoWin() self.input = windows.MessageInput() @@ -1805,10 +1892,10 @@ class ConversationTab(ChatTab): needed = 'inactive' if self.core.status.show in ('xa', 'away') else 'active' msg['chat_state'] = needed msg.send() - self.core.add_message_to_text_buffer(self.get_room(), line, None, self.core.own_nick) + self.core.add_message_to_text_buffer(self._text_buffer, line, None, self.core.own_nick) logger.log_message(JID(self.get_name()).bare, self.core.own_nick, line) self.cancel_paused_delay() - self.text_win.refresh(self._room) + self.text_win.refresh() self.input.refresh() def command_unquery(self, arg): @@ -1819,7 +1906,7 @@ class ConversationTab(ChatTab): return self.need_resize = False self.text_win.resize(self.height-4-self.core.information_win_size, self.width, 1, 0) - self.text_win.rebuild_everything(self._room) + self.text_win.rebuild_everything(self._text_buffer) self.upper_bar.resize(1, self.width, 0, 0) self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0) self.input.resize(1, self.width, self.height-1, 0) @@ -1828,15 +1915,15 @@ class ConversationTab(ChatTab): if self.need_resize: self.resize() log.debug(' TAB Refresh: %s'%self.__class__.__name__) - self.text_win.refresh(self._room) + self.text_win.refresh() self.upper_bar.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name())) - self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self._room, self.text_win, self.chatstate) - self.info_win.refresh(self.core.informations) + self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self.text_win, self.chatstate) + self.info_win.refresh() self.tab_win.refresh() self.input.refresh() def refresh_info_header(self): - self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self._room, self.text_win, self.chatstate) + self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self.text_win, self.chatstate) self.input.refresh() def get_name(self): @@ -1876,9 +1963,6 @@ class ConversationTab(ChatTab): self.text_win.resize(self.height-4-self.core.information_win_size, self.width, 1, 0) self.info_header.resize(1, self.width, self.height-3-self.core.information_win_size, 0) - def get_room(self): - return self._room - def get_text_window(self): return self.text_win diff --git a/src/text_buffer.py b/src/text_buffer.py index f39f147a..eb4b7b79 100644 --- a/src/text_buffer.py +++ b/src/text_buffer.py @@ -34,19 +34,20 @@ class TextBuffer(object): def add_window(self, win): self.windows.append(win) - def add_message(self, txt, time=None, nickname=None, nick_color=None, history=None): + def add_message(self, txt, time=None, nickname=None, nick_color=None, history=None, user=None): time = time or datetime.now() msg = Message(txt='%s\x19o'%(txt.replace('\t', ' '),), nick_color=nick_color, time=time, str_time=time.strftime("%Y-%m-%d %H:%M:%S")\ if history else time.strftime("%H:%M:%S"),\ - nickname=nickname, user=None) + nickname=nickname, user=user) + log.debug('Coucou, le message ajouté : %s' % (msg,)) self.messages.append(msg) while len(self.messages) > self.messages_nb_limit: self.messages.pop(0) ret_val = None for window in self.windows: # make the associated windows # build the lines from the new message - nb = window.build_new_message(msg) + nb = window.build_new_message(msg, history=history) if ret_val is None: ret_val = nb if window.pos != 0: diff --git a/src/windows.py b/src/windows.py index dfe46a14..42c9bfa0 100644 --- a/src/windows.py +++ b/src/windows.py @@ -341,18 +341,18 @@ class PrivateInfoWin(InfoWin): def __init__(self): InfoWin.__init__(self) - def refresh(self, room, window, chatstate): + def refresh(self, name, window, chatstate): log.debug('Refresh: %s'%self.__class__.__name__) with g_lock: self._win.erase() - self.write_room_name(room) + self.write_room_name(name) self.print_scroll_position(window) self.write_chatstate(chatstate) self.finish_line(get_theme().COLOR_INFORMATION_BAR) self._refresh() - def write_room_name(self, room): - jid = JID(room.name) + def write_room_name(self, name): + jid = JID(name) room_name, nick = jid.bare, jid.resource self.addstr(nick, to_curses_attr(get_theme().COLOR_PRIVATE_NAME)) txt = ' from room %s' % room_name @@ -380,7 +380,7 @@ class ConversationInfoWin(InfoWin): def __init__(self): InfoWin.__init__(self) - def refresh(self, jid, contact, text_buffer, window, chatstate): + def refresh(self, jid, contact, window, chatstate): # contact can be None, if we receive a message # from someone not in our roster. In this case, we display # only the maximum information from the message we can get. -- cgit v1.2.3 From 9ff6380149980581bc74f33ddd0e38fb0627623b Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 03:34:39 +0100 Subject: fix variable name, and remove ALL tab._room references. --- src/tabs.py | 62 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/src/tabs.py b/src/tabs.py index 6afb0dd1..5fc9047c 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -110,7 +110,7 @@ class Tab(object): @property def color(self): - return STATE_COLORS[self.state]() + return STATE_COLORS[self._state]() @property def state(self): @@ -226,13 +226,13 @@ class Tab(object): """ called when this tab loses the focus. """ - self.state = 'normal' + self._state = 'normal' def on_gain_focus(self): """ called when this tab gains the focus. """ - self.state = 'current' + self._state = 'current' def on_scroll_down(self): """ @@ -837,21 +837,21 @@ class MucTab(ChatTab): @property def state(self): - return self._room.state + return self._state @state.setter def state(self, value): - self._room.state = value + self._state = value def on_lose_focus(self): - self.state = 'normal' + self._state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('inactive') def on_gain_focus(self): - self.state = 'current' + self._state = 'current' if self.text_win.built_lines and self.text_win.built_lines[-1] is None: self.text_win.remove_line_separator() curses.curs_set(1) @@ -1097,7 +1097,7 @@ class MucTab(ChatTab): we can know if we can join it, send messages to it, etc """ self.users = [] - self.state = 'disconnected' + self._state = 'disconnected' self.joined = False def get_single_line_topic(self): @@ -1121,15 +1121,15 @@ class MucTab(ChatTab): color = None if not time and nickname and nickname != self.own_nick and self.joined: if self.own_nick.lower() in txt.lower(): - if self.state != 'current': - self.state = 'highlight' + if self._state != 'current': + self._state = 'highlight' color = get_theme().COLOR_HIGHLIGHT_NICK else: highlight_words = config.get('highlight_on', '').split(':') for word in highlight_words: if word and word.lower() in txt.lower(): - if self.state != 'current': - self.state = 'highlight' + if self._state != 'current': + self._state = 'highlight' color = get_theme().COLOR_HIGHLIGHT_NICK break if color: @@ -1165,9 +1165,9 @@ class MucTab(ChatTab): user = forced_user if not time and nickname and\ nickname != self.own_nick and\ - self.state != 'current': - if self.state != 'highlight': - self.state = 'message' + self._state != 'current': + if self._state != 'highlight': + self._state = 'message' nick_color = nick_color or None if not nickname or time: txt = '\x195}%s' % (txt,) @@ -1283,11 +1283,11 @@ class PrivateTab(ChatTab): @property def state(self): - return self._room.state + return self._state @state.setter def state(self, value): - self._room.state = value + self._state = value def get_name(self): return self.name @@ -1306,7 +1306,7 @@ class PrivateTab(ChatTab): return False def on_lose_focus(self): - self.state = 'normal' + self._state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() tab = self.core.get_tab_by_name(JID(self.name).bare, MucTab) @@ -1314,7 +1314,7 @@ class PrivateTab(ChatTab): self.send_chat_state('inactive') def on_gain_focus(self): - self.state = 'current' + self._state = 'current' curses.curs_set(1) tab = self.core.get_tab_by_name(JID(self.name).bare, MucTab) if tab.joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): @@ -1396,7 +1396,7 @@ class RosterInfoTab(Tab): self.contact_info_win = windows.ContactInfoWin() self.default_help_message = windows.HelpText("Enter commands with “/”. “o”: toggle offline show") self.input = self.default_help_message - self.state = 'normal' + self._state = 'normal' self.key_func['^I'] = self.completion self.key_func[' '] = self.on_space self.key_func["/"] = self.on_slash @@ -1757,10 +1757,10 @@ class RosterInfoTab(Tab): return self.reset_help_message() def on_lose_focus(self): - self.state = 'normal' + self._state = 'normal' def on_gain_focus(self): - self.state = 'current' + self._state = 'current' if isinstance(self.input, windows.HelpText): curses.curs_set(0) else: @@ -1863,7 +1863,7 @@ class ConversationTab(ChatTab): message_type = 'chat' def __init__(self, jid): ChatTab.__init__(self) - self.state = 'normal' + self._state = 'normal' self._name = jid # a conversation tab is linked to one specific full jid OR bare jid self.text_win = windows.TextWin() self._text_buffer.add_window(self.text_win) @@ -1939,14 +1939,14 @@ class ConversationTab(ChatTab): return False def on_lose_focus(self): - self.state = 'normal' + self._state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'): self.send_chat_state('inactive') def on_gain_focus(self): - self.state = 'current' + self._state = 'current' curses.curs_set(1) if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'): self.send_chat_state('active') @@ -1978,7 +1978,7 @@ class MucListTab(Tab): """ def __init__(self, server): Tab.__init__(self) - self.state = 'normal' + self._state = 'normal' self.name = server self.upper_message = windows.Topic() self.upper_message.set_message('Chatroom list on server %s (Loading)' % self.name) @@ -2092,10 +2092,10 @@ class MucListTab(Tab): return self.key_func[key]() def on_lose_focus(self): - self.state = 'normal' + self._state = 'normal' def on_gain_focus(self): - self.state = 'current' + self._state = 'current' curses.curs_set(0) def on_scroll_up(self): @@ -2112,7 +2112,7 @@ class SimpleTextTab(Tab): """ def __init__(self, text): Tab.__init__(self) - self.state = 'normal' + self._state = 'normal' self.text_win = windows.SimpleTextWin(text) self.default_help_message = windows.HelpText("“Ctrl+q”: close") self.input = self.default_help_message @@ -2155,10 +2155,10 @@ class SimpleTextTab(Tab): self.input.refresh() def on_lose_focus(self): - self.state = 'normal' + self._state = 'normal' def on_gain_focus(self): - self.state = 'current' + self._state = 'current' curses.curs_set(0) def diffmatch(search, string): -- cgit v1.2.3 From 12850ed06275fa4bbe499553e8c650b9e4a3ecea Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 6 Nov 2011 03:57:43 +0100 Subject: Use Tab.state proxy everywhere, also, use the right color on private message --- src/core.py | 1 + src/tabs.py | 68 +++++++++++++++++++++++-------------------------------------- 2 files changed, 27 insertions(+), 42 deletions(-) diff --git a/src/core.py b/src/core.py index 35cc6951..70781ebf 100644 --- a/src/core.py +++ b/src/core.py @@ -564,6 +564,7 @@ class Core(object): if conversation is self.current_tab(): self.refresh_window() else: + conversation.state = 'private' self.refresh_tab_win() def focus_tab_named(self, tab_name): diff --git a/src/tabs.py b/src/tabs.py index 5fc9047c..4276e163 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -226,13 +226,13 @@ class Tab(object): """ called when this tab loses the focus. """ - self._state = 'normal' + self.state = 'normal' def on_gain_focus(self): """ called when this tab gains the focus. """ - self._state = 'current' + self.state = 'current' def on_scroll_down(self): """ @@ -835,23 +835,15 @@ class MucTab(ChatTab): def get_text_window(self): return self.text_win - @property - def state(self): - return self._state - - @state.setter - def state(self, value): - self._state = value - def on_lose_focus(self): - self._state = 'normal' + self.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): self.send_chat_state('inactive') def on_gain_focus(self): - self._state = 'current' + self.state = 'current' if self.text_win.built_lines and self.text_win.built_lines[-1] is None: self.text_win.remove_line_separator() curses.curs_set(1) @@ -1097,7 +1089,7 @@ class MucTab(ChatTab): we can know if we can join it, send messages to it, etc """ self.users = [] - self._state = 'disconnected' + self.state = 'disconnected' self.joined = False def get_single_line_topic(self): @@ -1121,15 +1113,15 @@ class MucTab(ChatTab): color = None if not time and nickname and nickname != self.own_nick and self.joined: if self.own_nick.lower() in txt.lower(): - if self._state != 'current': - self._state = 'highlight' + if self.state != 'current': + self.state = 'highlight' color = get_theme().COLOR_HIGHLIGHT_NICK else: highlight_words = config.get('highlight_on', '').split(':') for word in highlight_words: if word and word.lower() in txt.lower(): - if self._state != 'current': - self._state = 'highlight' + if self.state != 'current': + self.state = 'highlight' color = get_theme().COLOR_HIGHLIGHT_NICK break if color: @@ -1165,9 +1157,9 @@ class MucTab(ChatTab): user = forced_user if not time and nickname and\ nickname != self.own_nick and\ - self._state != 'current': - if self._state != 'highlight': - self._state = 'message' + self.state != 'current': + if self.state != 'highlight': + self.state = 'message' nick_color = nick_color or None if not nickname or time: txt = '\x195}%s' % (txt,) @@ -1281,14 +1273,6 @@ class PrivateTab(ChatTab): self.info_header.refresh(self.name, self.text_win, self.chatstate) self.input.refresh() - @property - def state(self): - return self._state - - @state.setter - def state(self, value): - self._state = value - def get_name(self): return self.name @@ -1306,7 +1290,7 @@ class PrivateTab(ChatTab): return False def on_lose_focus(self): - self._state = 'normal' + self.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() tab = self.core.get_tab_by_name(JID(self.name).bare, MucTab) @@ -1314,7 +1298,7 @@ class PrivateTab(ChatTab): self.send_chat_state('inactive') def on_gain_focus(self): - self._state = 'current' + self.state = 'current' curses.curs_set(1) tab = self.core.get_tab_by_name(JID(self.name).bare, MucTab) if tab.joined and config.get('send_chat_states', 'true') == 'true' and not self.input.get_text(): @@ -1396,7 +1380,7 @@ class RosterInfoTab(Tab): self.contact_info_win = windows.ContactInfoWin() self.default_help_message = windows.HelpText("Enter commands with “/”. “o”: toggle offline show") self.input = self.default_help_message - self._state = 'normal' + self.state = 'normal' self.key_func['^I'] = self.completion self.key_func[' '] = self.on_space self.key_func["/"] = self.on_slash @@ -1757,10 +1741,10 @@ class RosterInfoTab(Tab): return self.reset_help_message() def on_lose_focus(self): - self._state = 'normal' + self.state = 'normal' def on_gain_focus(self): - self._state = 'current' + self.state = 'current' if isinstance(self.input, windows.HelpText): curses.curs_set(0) else: @@ -1863,7 +1847,7 @@ class ConversationTab(ChatTab): message_type = 'chat' def __init__(self, jid): ChatTab.__init__(self) - self._state = 'normal' + self.state = 'normal' self._name = jid # a conversation tab is linked to one specific full jid OR bare jid self.text_win = windows.TextWin() self._text_buffer.add_window(self.text_win) @@ -1939,14 +1923,14 @@ class ConversationTab(ChatTab): return False def on_lose_focus(self): - self._state = 'normal' + self.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator() if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'): self.send_chat_state('inactive') def on_gain_focus(self): - self._state = 'current' + self.state = 'current' curses.curs_set(1) if config.get('send_chat_states', 'true') == 'true' and not self.input.get_text() or not self.input.get_text().startswith('//'): self.send_chat_state('active') @@ -1978,7 +1962,7 @@ class MucListTab(Tab): """ def __init__(self, server): Tab.__init__(self) - self._state = 'normal' + self.state = 'normal' self.name = server self.upper_message = windows.Topic() self.upper_message.set_message('Chatroom list on server %s (Loading)' % self.name) @@ -2092,10 +2076,10 @@ class MucListTab(Tab): return self.key_func[key]() def on_lose_focus(self): - self._state = 'normal' + self.state = 'normal' def on_gain_focus(self): - self._state = 'current' + self.state = 'current' curses.curs_set(0) def on_scroll_up(self): @@ -2112,7 +2096,7 @@ class SimpleTextTab(Tab): """ def __init__(self, text): Tab.__init__(self) - self._state = 'normal' + self.state = 'normal' self.text_win = windows.SimpleTextWin(text) self.default_help_message = windows.HelpText("“Ctrl+q”: close") self.input = self.default_help_message @@ -2155,10 +2139,10 @@ class SimpleTextTab(Tab): self.input.refresh() def on_lose_focus(self): - self._state = 'normal' + self.state = 'normal' def on_gain_focus(self): - self._state = 'current' + self.state = 'current' curses.curs_set(0) def diffmatch(search, string): -- cgit v1.2.3 From fbb465a092a192821fea55eae2c7a918edf9fd59 Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 6 Nov 2011 14:18:45 +0100 Subject: Fixes #2284 --- src/core.py | 7 ++++--- src/tabs.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core.py b/src/core.py index 70781ebf..05ae2cb1 100644 --- a/src/core.py +++ b/src/core.py @@ -1505,14 +1505,15 @@ class Core(object): self.information_win.refresh() self.current_tab().input.refresh() - def disconnect(self, msg=None, reconnect=False): + def disconnect(self, msg='', reconnect=False): """ Disconnect from remote server and correctly set the states of all parts of the client (for example, set the MucTabs as not joined, etc) """ + msg = msg or '' for tab in self.tabs: - if isinstance(tab, tabs.MucTab): - muc.leave_groupchat(self.xmpp, tab.name, tab.own_nick, msg) + if isinstance(tab, tabs.MucTab) and tab.joined: + tab.command_part(msg) roster.empty() self.save_config() # Ugly fix thanks to gmail servers diff --git a/src/tabs.py b/src/tabs.py index 4276e163..43dcb2b9 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -570,9 +570,9 @@ class MucTab(ChatTab): msg = None if self.joined: muc.leave_groupchat(self.core.xmpp, self.name, self.own_nick, arg) - self.joined = False self.add_message(_("\x195}You left the chatroom\x193}")) - self.refresh() + if self == self.core.current_tab(): + self.refresh() self.core.doupdate() self.core.disable_private_tabs(self.name) -- cgit v1.2.3 From fc20de76ffef3982e59bd004d1e7c9f3c6e0d4bc Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 6 Nov 2011 14:38:00 +0100 Subject: Should really fix #2284 and some other tbs --- src/multiuserchat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/multiuserchat.py b/src/multiuserchat.py index 264f0e4a..ac910837 100644 --- a/src/multiuserchat.py +++ b/src/multiuserchat.py @@ -65,7 +65,10 @@ def leave_groupchat(xmpp, jid, own_nick, msg): """ Leave the groupchat """ - xmpp.plugin['xep_0045'].leaveMUC(jid, own_nick, msg) + try: + xmpp.plugin['xep_0045'].leaveMUC(jid, own_nick, msg) + except KeyError: + log.debug("WARNING: in muc.leave_groupchat: could not leave the room") def set_user_role(xmpp, jid, nick, reason, role): """ -- cgit v1.2.3 From bf9857b782586e4d17395a3feef0fd65aac428ee Mon Sep 17 00:00:00 2001 From: mathieui Date: Sun, 6 Nov 2011 15:46:52 +0100 Subject: =?UTF-8?q?Fixes=20mostly=20#2285=20(no=20more=20crashes),=20but?= =?UTF-8?q?=20as=20for=20why=20we=20get=20an=20iqerror=20when=20trying=20t?= =?UTF-8?q?o=20get=20the=20version=20from=20a=20full=20jid=E2=80=A6?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core.py | 18 ++++++++++-------- src/tabs.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/core.py b/src/core.py index 05ae2cb1..8c4ad258 100644 --- a/src/core.py +++ b/src/core.py @@ -1134,18 +1134,20 @@ class Core(object): """ /version """ + def callback(res): + if not res: + return self.information('Could not get the software version from %s' % (jid,), 'Warning') + version = '%s is running %s version %s on %s' % (jid, + res.get('name') or _('an unknown software'), + res.get('version') or _('unknown'), + res.get('os') or _('on an unknown platform')) + self.information(version, 'Info') + args = common.shell_split(arg) if len(args) < 1: return self.command_help('version') jid = args[0] - res = self.xmpp.plugin['xep_0092'].get_version(jid) - if not res: - return self.information('Could not get the software version from %s' % (jid,), 'Warning') - version = '%s is running %s version %s on %s' % (jid, - res.get('name') or _('an unknown software'), - res.get('version') or _('unknown'), - res.get('os') or _('on an unknown platform')) - self.information(version, 'Info') + self.xmpp.plugin['xep_0092'].get_version(jid, callback=callback) def command_reconnect(self, args): """ diff --git a/src/tabs.py b/src/tabs.py index 43dcb2b9..b4d4ef44 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -1859,6 +1859,7 @@ class ConversationTab(ChatTab): # commands self.commands['unquery'] = (self.command_unquery, _("Usage: /unquery\nUnquery: close the tab"), None) self.commands['close'] = (self.command_unquery, _("Usage: /close\Close: close the tab"), None) + self.commands['version'] = (self.command_version, _('Usage: /version\nVersion: get the software version of the current interlocutor (usually its XMPP client and Operating System)'), None) self.resize() def completion(self): @@ -1885,6 +1886,21 @@ class ConversationTab(ChatTab): def command_unquery(self, arg): self.core.close_tab() + def command_version(self, arg): + """ + /version + """ + def callback(res): + if not res: + return self.core.information('Could not get the software version from %s' % (jid,), 'Warning') + version = '%s is running %s version %s on %s' % (jid, + res.get('name') or _('an unknown software'), + res.get('version') or _('unknown'), + res.get('os') or _('on an unknown platform')) + self.core.information(version, 'Info') + jid = self._name + self.core.xmpp.plugin['xep_0092'].get_version(jid, callback=callback) + def resize(self): if self.core.information_win_size >= self.height-3 or not self.visible: return -- cgit v1.2.3 From 7bf63c51e2650042932ad78207ce5366bab3e38a Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Sun, 6 Nov 2011 15:57:03 +0100 Subject: Fix a remaining crash from the Room class deletion. --- src/tabs.py | 7 +++---- src/text_buffer.py | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/tabs.py b/src/tabs.py index b4d4ef44..1209038c 100644 --- a/src/tabs.py +++ b/src/tabs.py @@ -389,7 +389,7 @@ class ChatTab(Tab): def move_separator(self): self.text_win.remove_line_separator() self.text_win.add_line_separator() - self.text_win.refresh(self._text_buffer) + self.text_win.refresh() self.input.refresh() def command_say(self, line): @@ -607,9 +607,8 @@ class MucTab(ChatTab): /topic [new topic] """ if not arg.strip(): - self._text_buffer.add_message_to_text_buffer(self, - _("The subject of the room is: %s") % self.topic) - self.text_win.refresh(self._text_buffer) + self._text_buffer.add_message(_("The subject of the room is: %s") % self.topic) + self.text_win.refresh() self.input.refresh() return subject = arg diff --git a/src/text_buffer.py b/src/text_buffer.py index eb4b7b79..94bd94b9 100644 --- a/src/text_buffer.py +++ b/src/text_buffer.py @@ -40,7 +40,6 @@ class TextBuffer(object): time=time, str_time=time.strftime("%Y-%m-%d %H:%M:%S")\ if history else time.strftime("%H:%M:%S"),\ nickname=nickname, user=user) - log.debug('Coucou, le message ajouté : %s' % (msg,)) self.messages.append(msg) while len(self.messages) > self.messages_nb_limit: self.messages.pop(0) -- cgit v1.2.3