diff options
Diffstat (limited to 'src/tabs/basetabs.py')
-rw-r--r-- | src/tabs/basetabs.py | 124 |
1 files changed, 87 insertions, 37 deletions
diff --git a/src/tabs/basetabs.py b/src/tabs/basetabs.py index 0a55640c..30ddf239 100644 --- a/src/tabs/basetabs.py +++ b/src/tabs/basetabs.py @@ -13,8 +13,6 @@ This module also defines ChatTabs, the parent class for all tabs revolving around chats. """ -from gettext import gettext as _ - import logging log = logging.getLogger(__name__) @@ -35,7 +33,7 @@ from decorators import refresh_wrapper from logger import logger from text_buffer import TextBuffer from theming import get_theme, dump_tuple - +from decorators import command_args_parser # getters for tab colors (lambdas, so that they are dynamic) STATE_COLORS = { @@ -254,7 +252,6 @@ class Tab(object): return False # There's no completion function else: return command[2](the_input) - return True return False def execute_command(self, provided_text): @@ -282,14 +279,15 @@ class Tab(object): if self.missing_command_callback is not None: error_handled = self.missing_command_callback(low) if not error_handled: - self.core.information(_("Unknown command (%s)") % - (command), - _('Error')) + self.core.information("Unknown command (%s)" % + (command), + 'Error') if command in ('correct', 'say'): # hack arg = xhtml.convert_simple_to_full_colors(arg) else: arg = xhtml.clean_text_simple(arg) if func: + self.input.reset_completion() func(arg) return True else: @@ -455,16 +453,16 @@ class ChatTab(Tab): self.key_func['M-/'] = self.last_words_completion self.key_func['^M'] = self.on_enter self.register_command('say', self.command_say, - usage=_('<message>'), - shortdesc=_('Send the message.')) + usage='<message>', + shortdesc='Send the message.') self.register_command('xhtml', self.command_xhtml, - usage=_('<custom xhtml>'), - shortdesc=_('Send custom XHTML.')) + usage='<custom xhtml>', + shortdesc='Send custom XHTML.') self.register_command('clear', self.command_clear, - shortdesc=_('Clear the current buffer.')) + shortdesc='Clear the current buffer.') self.register_command('correct', self.command_correct, - desc=_('Fix the last message with whatever you want.'), - shortdesc=_('Correct the last message.'), + desc='Fix the last message with whatever you want.', + shortdesc='Correct the last message.', completion=self.completion_correct) self.chat_state = None self.update_commands() @@ -492,7 +490,7 @@ class ChatTab(Tab): """ name = safeJID(self.name).bare if not logger.log_message(name, nickname, txt, date=time, typ=typ): - self.core.information(_('Unable to write in the log file'), 'Error') + self.core.information('Unable to write in the log file', 'Error') def add_message(self, txt, time=None, nickname=None, forced_user=None, nick_color=None, identifier=None, jid=None, history=None, @@ -544,11 +542,12 @@ class ChatTab(Tab): self.command_say(xhtml.convert_simple_to_full_colors(txt)) self.cancel_paused_delay() - def command_xhtml(self, arg): + @command_args_parser.raw + def command_xhtml(self, xhtml): """" /xhtml <custom xhtml> """ - message = self.generate_xhtml_message(arg) + message = self.generate_xhtml_message(xhtml) if message: message.send() @@ -573,7 +572,7 @@ class ChatTab(Tab): return self.name @refresh_wrapper.always - def command_clear(self, args): + def command_clear(self, ignored): """ /clear """ @@ -637,6 +636,7 @@ class ChatTab(Tab): self.core.remove_timed_event(self.timed_event_paused) self.timed_event_paused = None + @command_args_parser.raw def command_correct(self, line): """ /correct <fixed message> @@ -645,7 +645,7 @@ class ChatTab(Tab): self.core.command_help('correct') return if not self.last_sent_message: - self.core.information(_('There is no message to correct.')) + self.core.information('There is no message to correct.') return self.command_say(line, correct=True) @@ -672,6 +672,7 @@ class ChatTab(Tab): if self.text_win.pos != 0: self.state = 'scrolled' + @command_args_parser.raw def command_say(self, line, correct=False): pass @@ -707,20 +708,67 @@ class OneToOneTab(ChatTab): # 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 - self.remote_wants_chatstates = None + self._remote_wants_chatstates = None self.remote_supports_attention = True self.remote_supports_receipts = True self.check_features() - def ack_message(self, msg_id): + @property + def remote_wants_chatstates(self): + return self._remote_wants_chatstates + + @remote_wants_chatstates.setter + def remote_wants_chatstates(self, value): + old_value = self._remote_wants_chatstates + self._remote_wants_chatstates = value + if (old_value is None and value != None) or \ + (old_value != value and value != None): + ok = get_theme().CHAR_OK + nope = get_theme().CHAR_EMPTY + support = ok if value else nope + if value: + msg = '\x19%s}Contact supports chat states [%s].' + else: + msg = '\x19%s}Contact does not support chat states [%s].' + color = dump_tuple(get_theme().COLOR_INFORMATION_TEXT) + msg = msg % (color, support) + self.add_message(msg, typ=0) + self.core.refresh_window() + + def ack_message(self, msg_id, msg_jid): """ Ack a message """ - new_msg = self._text_buffer.ack_message(msg_id) + new_msg = self._text_buffer.ack_message(msg_id, msg_jid) if new_msg: self.text_win.modify_message(msg_id, new_msg) self.core.refresh_window() + def nack_message(self, error, msg_id, msg_jid): + """ + Ack a message + """ + new_msg = self._text_buffer.nack_message(error, msg_id, msg_jid) + if new_msg: + self.text_win.modify_message(msg_id, new_msg) + self.core.refresh_window() + return True + return False + + @command_args_parser.raw + def command_xhtml(self, xhtml_data): + message = self.generate_xhtml_message(xhtml_data) + if message: + if self.remote_supports_receipts: + message._add_receipt = True + if self.remote_wants_chatstates: + message['chat_sate'] = 'active' + message.send() + body = xhtml.xhtml_to_poezio_colors(xhtml_data, force=True) + self._text_buffer.add_message(body, nickname=self.core.own_nick, + identifier=message['id'],) + self.refresh() + def check_features(self): "check the features supported by the other party" if safeJID(self.get_dest_jid()).resource: @@ -728,8 +776,9 @@ class OneToOneTab(ChatTab): jid=self.get_dest_jid(), timeout=5, callback=self.features_checked) - def command_attention(self, message=''): - "/attention [message]" + @command_args_parser.raw + def command_attention(self, message): + """/attention [message]""" if message is not '': self.command_say(message, attention=True) else: @@ -738,6 +787,7 @@ class OneToOneTab(ChatTab): msg['attention'] = True msg.send() + @command_args_parser.raw def command_say(self, line, correct=False, attention=False): pass @@ -746,11 +796,11 @@ class OneToOneTab(ChatTab): return False if command_name == 'correct': - feature = _('message correction') + feature = 'message correction' elif command_name == 'attention': - feature = _('attention requests') - msg = _('%s does not support %s, therefore the /%s ' - 'command is currently disabled in this tab.') + feature = 'attention requests' + msg = ('%s does not support %s, therefore the /%s ' + 'command is currently disabled in this tab.') msg = msg % (self.name, feature, command_name) self.core.information(msg, 'Info') return True @@ -760,11 +810,11 @@ class OneToOneTab(ChatTab): if 'urn:xmpp:attention:0' in features: self.remote_supports_attention = True self.register_command('attention', self.command_attention, - usage=_('[message]'), - shortdesc=_('Request the attention.'), - desc=_('Attention: Request the attention of ' - 'the contact. Can also send a message' - ' along with the attention.')) + usage='[message]', + shortdesc='Request the attention.', + desc='Attention: Request the attention of ' + 'the contact. Can also send a message' + ' along with the attention.') else: self.remote_supports_attention = False return self.remote_supports_attention @@ -776,8 +826,8 @@ class OneToOneTab(ChatTab): del self.commands['correct'] elif not 'correct' in self.commands: self.register_command('correct', self.command_correct, - desc=_('Fix the last message with whatever you want.'), - shortdesc=_('Correct the last message.'), + desc='Fix the last message with whatever you want.', + shortdesc='Correct the last message.', completion=self.completion_correct) return 'correct' in self.commands @@ -814,8 +864,8 @@ class OneToOneTab(ChatTab): attention = ok if attention else nope receipts = ok if receipts else nope - msg = _('\x19%s}Contact supports: correction [%s], ' - 'attention [%s], receipts [%s].') + msg = ('\x19%s}Contact supports: correction [%s], ' + 'attention [%s], receipts [%s].') color = dump_tuple(get_theme().COLOR_INFORMATION_TEXT) msg = msg % (color, correct, attention, receipts) self.add_message(msg, typ=0) |