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