diff options
author | mathieui <mathieui@mathieui.net> | 2014-10-31 19:15:57 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2014-10-31 19:16:44 +0100 |
commit | 1c1ab3cb839e5509db52770e10c7190f844eb2e5 (patch) | |
tree | b331060b3dc42651e61e4ccb2dfe6af5e2e97752 /src/core | |
parent | cedc5a6ec80a46437f42464415fd1806049c593d (diff) | |
parent | ea2b703bfd07d293ba9fdd85ac657275d43da2a7 (diff) | |
download | poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.gz poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.bz2 poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.tar.xz poezio-1c1ab3cb839e5509db52770e10c7190f844eb2e5.zip |
Merge branch 'master' of git.poez.io:poezio into slix
Conflicts:
src/bookmark.py
src/config.py
src/connection.py
src/core/commands.py
src/core/core.py
src/core/handlers.py
src/windows/info_bar.py
src/windows/muc.py
src/windows/roster_win.py
src/windows/text_win.py
src/xhtml.py
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/commands.py | 69 | ||||
-rw-r--r-- | src/core/completions.py | 16 | ||||
-rw-r--r-- | src/core/core.py | 72 | ||||
-rw-r--r-- | src/core/handlers.py | 124 |
4 files changed, 164 insertions, 117 deletions
diff --git a/src/core/commands.py b/src/core/commands.py index c27263e2..4a8f7f19 100644 --- a/src/core/commands.py +++ b/src/core/commands.py @@ -7,6 +7,7 @@ import logging log = logging.getLogger(__name__) import functools +import os import sys from datetime import datetime from gettext import gettext as _ @@ -24,6 +25,7 @@ import tabs from common import safeJID from config import config, options as config_opts import multiuserchat as muc +from plugin import PluginConfig from roster import roster from theming import dump_tuple, get_theme @@ -369,16 +371,13 @@ def command_join(self, arg, histo_length=None): room = room[1:] current_status = self.get_status() if not histo_length: - histo_length = config.get('muc_history_length', 20) + histo_length = config.get('muc_history_length') if histo_length == -1: histo_length = None if histo_length is not None: histo_length = str(histo_length) if password is None: # try to use a saved password - password = config.get_by_tabname('password', - None, - room, - fallback=False) + password = config.get_by_tabname('password', room, fallback=False) if tab and not tab.joined: if tab.last_connection: if tab.last_connection is not None: @@ -476,7 +475,7 @@ def command_bookmark(self, arg=''): /bookmark [room][/nick] [autojoin] [password] """ - if not config.get('use_remote_bookmarks', True): + if not config.get('use_remote_bookmarks'): self.command_bookmark_local(arg) return args = common.shell_split(arg) @@ -537,7 +536,7 @@ def command_bookmark(self, arg=''): if not bm: bm = bookmark.Bookmark(roomname) bookmark.bookmarks.append(bm) - bm.method = config.get('use_bookmarks_method', 'pep') + bm.method = config.get('use_bookmarks_method') if nick: bm.nick = nick if password: @@ -592,17 +591,39 @@ def command_remove_bookmark(self, arg=''): def command_set(self, arg): """ - /set [module|][section] <option> <value> + /set [module|][section] <option> [value] """ args = common.shell_split(arg) - if len(args) != 2 and len(args) != 3: - self.command_help('set') - return - if len(args) == 2: + if len(args) == 1: option = args[0] - value = args[1] - info = config.set_and_save(option, value) - self.trigger_configuration_change(option, value) + value = config.get(option) + info = ('%s=%s' % (option, value), 'Info') + elif len(args) == 2: + if '|' in args[0]: + plugin_name, section = args[0].split('|')[:2] + if not section: + section = plugin_name + option = args[1] + if not plugin_name in self.plugin_manager.plugins: + file_name = self.plugin_manager.plugins_conf_dir + file_name = os.path.join(file_name, plugin_name + '.cfg') + plugin_config = PluginConfig(file_name, plugin_name) + else: + plugin_config = self.plugin_manager.plugins[plugin_name].config + value = plugin_config.get(option, default='', section=section) + info = ('%s=%s' % (option, value), 'Info') + else: + possible_section = args[0] + if config.has_section(possible_section): + section = possible_section + option = args[1] + value = config.get(option, section=section) + info = ('%s=%s' % (option, value), 'Info') + else: + option = args[0] + value = args[1] + info = config.set_and_save(option, value) + self.trigger_configuration_change(option, value) elif len(args) == 3: if '|' in args[0]: plugin_name, section = args[0].split('|')[:2] @@ -611,15 +632,21 @@ def command_set(self, arg): option = args[1] value = args[2] if not plugin_name in self.plugin_manager.plugins: - return - plugin = self.plugin_manager.plugins[plugin_name] - info = plugin.config.set_and_save(option, value, section) + file_name = self.plugin_manager.plugins_conf_dir + file_name = os.path.join(file_name, plugin_name + '.cfg') + plugin_config = PluginConfig(file_name, plugin_name) + else: + plugin_config = self.plugin_manager.plugins[plugin_name].config + info = plugin_config.set_and_save(option, value, section) else: section = args[0] option = args[1] value = args[2] info = config.set_and_save(option, value, section) self.trigger_configuration_change(option, value) + else: + self.command_help('set') + return self.call_for_resize() self.information(*info) @@ -813,11 +840,11 @@ def command_quit(self, arg=''): msg = arg else: msg = None - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.xmpp.plugin['xep_0107'].stop() - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.xmpp.plugin['xep_0108'].stop() - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.xmpp.plugin['xep_0196'].stop() self.save_config() self.plugin_manager.disable_plugins() diff --git a/src/core/completions.py b/src/core/completions.py index 7acddef9..7d95321b 100644 --- a/src/core/completions.py +++ b/src/core/completions.py @@ -46,7 +46,7 @@ def completion_presence(self, the_input): def completion_theme(self, the_input): """ Completion for /theme""" - themes_dir = config.get('themes_dir', '') + themes_dir = config.get('themes_dir') themes_dir = themes_dir or\ os.path.join(os.environ.get('XDG_DATA_HOME') or\ os.path.join(os.environ.get('HOME'), '.local', 'share'), @@ -175,7 +175,7 @@ def completion_bookmark(self, the_input): tab = self.get_tab_by_name(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get('USER') else 'poezio' - nick = config.get('default_nick', '') + nick = config.get('default_nick') if not nick: if not default in nicks: nicks.append(default) @@ -309,7 +309,7 @@ def completion_set(self, the_input): if '|' in args[1]: plugin_name, section = args[1].split('|')[:2] if not plugin_name in self.plugin_manager.plugins: - return the_input.auto_completion([''], n, quotify=True) + return the_input.new_completion([''], n, quotify=True) plugin = self.plugin_manager.plugins[plugin_name] end_list = plugin.config.options(section or plugin_name) elif not config.has_option('Poezio', args[1]): @@ -319,19 +319,19 @@ def completion_set(self, the_input): else: end_list = [] else: - end_list = [config.get(args[1], ''), ''] + end_list = [str(config.get(args[1], '')), ''] elif n == 3: if '|' in args[1]: plugin_name, section = args[1].split('|')[:2] if not plugin_name in self.plugin_manager.plugins: - return the_input.auto_completion([''], n, quotify=True) + return the_input.new_completion([''], n, quotify=True) plugin = self.plugin_manager.plugins[plugin_name] - end_list = [plugin.config.get(args[2], '', section or plugin_name), ''] + end_list = [str(plugin.config.get(args[2], '', section or plugin_name)), ''] else: if not config.has_section(args[1]): end_list = [''] else: - end_list = [config.get(args[2], '', args[1]), ''] + end_list = [str(config.get(args[2], '', args[1])), ''] else: return return the_input.new_completion(end_list, n, quotify=True) @@ -356,7 +356,7 @@ def completion_bookmark_local(self, the_input): tab = self.get_tab_by_name(jid.bare, tabs.MucTab) nicks = [tab.own_nick] if tab else [] default = os.environ.get('USER') if os.environ.get('USER') else 'poezio' - nick = config.get('default_nick', '') + nick = config.get('default_nick') if not nick: if not default in nicks: nicks.append(default) diff --git a/src/core/core.py b/src/core/core.py index eeb25c83..70136250 100644 --- a/src/core/core.py +++ b/src/core/core.py @@ -65,10 +65,10 @@ class Core(object): sys.excepthook = self.on_exception self.connection_time = time.time() self.stdscr = None - status = config.get('status', None) + status = config.get('status') status = possible_show.get(status, None) self.status = Status(show=status, - message=config.get('status_message', '')) + message=config.get('status_message')) self.running = True self.xmpp = singleton.Singleton(connection.Connection) self.xmpp.core = self @@ -83,7 +83,7 @@ class Core(object): # that are displayed in almost all tabs, in an # information window. self.information_buffer = TextBuffer() - self.information_win_size = config.get('info_win_height', 2, 'var') + self.information_win_size = config.get('info_win_height', section='var') self.information_win = windows.TextWin(300) self.information_buffer.add_window(self.information_win) self.left_tab_win = None @@ -97,7 +97,7 @@ class Core(object): self._current_tab_nb = 0 self.previous_tab_nb = 0 - own_nick = config.get('default_nick', '') + own_nick = config.get('default_nick') own_nick = own_nick or self.xmpp.boundjid.user own_nick = own_nick or os.environ.get('USER') own_nick = own_nick or 'poezio' @@ -127,7 +127,7 @@ class Core(object): self.register_initial_commands() # We are invisible - if not config.get('send_initial_presence', True): + if not config.get('send_initial_presence'): del self.commands['status'] del self.commands['show'] @@ -256,19 +256,19 @@ class Core(object): connection.MatchAll(None), self.incoming_stanza) self.xmpp.register_handler(self.all_stanzas) - if config.get('enable_user_tune', True): + if config.get('enable_user_tune'): self.xmpp.add_event_handler("user_tune_publish", self.on_tune_event) - if config.get('enable_user_nick', True): + if config.get('enable_user_nick'): self.xmpp.add_event_handler("user_nick_publish", self.on_nick_received) - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.xmpp.add_event_handler("user_mood_publish", self.on_mood_event) - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.xmpp.add_event_handler("user_activity_publish", self.on_activity_event) - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.xmpp.add_event_handler("user_gaming_publish", self.on_gaming_event) @@ -357,13 +357,14 @@ class Core(object): """ Called when the request_message_receipts option changes """ - self.xmpp.plugin['xep_0184'].auto_request = config.get(option, True) + self.xmpp.plugin['xep_0184'].auto_request = config.get(option, + default=True) def on_ack_receipts_config_change(self, option, value): """ Called when the ack_message_receipts option changes """ - self.xmpp.plugin['xep_0184'].auto_ack = config.get(option, True) + self.xmpp.plugin['xep_0184'].auto_ack = config.get(option, default=True) def on_plugins_dir_config_change(self, option, value): """ @@ -419,7 +420,7 @@ class Core(object): old_section = old_config.get(section, {}) for option in config.options(section): old_value = old_section.get(option) - new_value = config.get(option, "", section) + new_value = config.get(option, default="", section=section) if new_value != old_value: self.trigger_configuration_change(option, new_value) log.debug("Config reloaded.") @@ -441,11 +442,11 @@ class Core(object): } log.error("%s received. Exiting…", signals[sig]) - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.xmpp.plugin['xep_0107'].stop() - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.xmpp.plugin['xep_0108'].stop() - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.xmpp.plugin['xep_0196'].stop() self.plugin_manager.disable_plugins() self.disconnect('%s received' % signals.get(sig)) @@ -455,7 +456,7 @@ class Core(object): """ Load the plugins on startup. """ - plugins = config.get('plugins_autoload', '') + plugins = config.get('plugins_autoload') if ':' in plugins: for plugin in plugins.split(':'): self.plugin_manager.load(plugin) @@ -704,9 +705,9 @@ class Core(object): work. If you try to do anything else, your |, [, <<, etc will be interpreted as normal command arguments, not shell special tokens. """ - if config.get('exec_remote', False): + if config.get('exec_remote'): # We just write the command in the fifo - fifo_path = config.get('remote_fifo_path', './') + fifo_path = config.get('remote_fifo_path') if not self.remote_fifo: try: self.remote_fifo = Fifo(os.path.join(fifo_path, @@ -802,7 +803,7 @@ class Core(object): or to use it when joining a new muc) """ self.status = Status(show=pres, message=msg) - if config.get('save_status', True): + if config.get('save_status'): ok = config.silent_set('status', pres if pres else '') msg = msg.replace('\n', '|') if msg else '' ok = ok and config.silent_set('status_message', msg) @@ -1043,7 +1044,7 @@ class Core(object): return False elif not self.tabs[old_pos]: return False - if config.get('create_gaps', False): + if config.get('create_gaps'): return self.insert_tab_gaps(old_pos, new_pos) return self.insert_tab_nogaps(old_pos, new_pos) @@ -1294,7 +1295,7 @@ class Core(object): if self.previous_tab_nb != nb: self.current_tab_nb = self.previous_tab_nb self.previous_tab_nb = 0 - if config.get('create_gaps', False): + if config.get('create_gaps'): if nb >= len(self.tabs) - 1: self.tabs.remove(tab) nb -= 1 @@ -1345,7 +1346,7 @@ class Core(object): """ Displays an informational message in the "Info" buffer """ - filter_messages = config.get('filter_info_messages', '').split(':') + filter_messages = config.get('filter_info_messages').split(':') for words in filter_messages: if words and words in msg: log.debug('Did not show the message:\n\t%s> %s', typ, msg) @@ -1355,12 +1356,11 @@ class Core(object): nb_lines = self.information_buffer.add_message(msg, nickname=typ, nick_color=color) - popup_on = config.get('information_buffer_popup_on', - 'error roster warning help info').split() + popup_on = config.get('information_buffer_popup_on').split() if isinstance(self.current_tab(), tabs.RosterInfoTab): self.refresh_window() elif typ != '' and typ.lower() in popup_on: - popup_time = config.get('popup_time', 4) + (nb_lines - 1) * 2 + popup_time = config.get('popup_time') + (nb_lines - 1) * 2 self.pop_information_win_up(nb_lines, popup_time) else: if self.information_win_size != 0: @@ -1553,7 +1553,7 @@ class Core(object): """ Enable/disable the left panel. """ - enabled = config.get('enable_vertical_tab_list', False) + enabled = config.get('enable_vertical_tab_list') if not config.silent_set('enable_vertical_tab_list', str(not enabled)): self.information(_('Unable to write in the config file'), 'Error') self.call_for_resize() @@ -1578,14 +1578,14 @@ class Core(object): Resize the GlobalInfoBar only once at each resize """ height, width = self.stdscr.getmaxyx() - if config.get('enable_vertical_tab_list', False): + if config.get('enable_vertical_tab_list'): if self.size.core_degrade_x: return try: height, _ = self.stdscr.getmaxyx() truncated_win = self.stdscr.subwin(height, - config.get('vertical_tab_list_size', 20), + config.get('vertical_tab_list_size'), 0, 0) except: log.error('Curses error on infobar resize', exc_info=True) @@ -1623,11 +1623,11 @@ class Core(object): # the screen that they can occupy, and we draw the tab list on the # remaining space, on the left height, width = self.stdscr.getmaxyx() - if (config.get('enable_vertical_tab_list', False) and + if (config.get('enable_vertical_tab_list') and not self.size.core_degrade_x): try: scr = self.stdscr.subwin(0, - config.get('vertical_tab_list_size', 20)) + config.get('vertical_tab_list_size')) except: log.error('Curses error on resize', exc_info=True) return @@ -1637,7 +1637,7 @@ class Core(object): self.resize_global_info_bar() self.resize_global_information_win() for tab in self.tabs: - if config.get('lazy_resize', True): + if config.get('lazy_resize'): tab.need_resize = True else: tab.resize() @@ -1865,7 +1865,7 @@ class Core(object): usage='<jid>', shortdesc=_('List available ad-hoc commands on the given jid')) - if config.get('enable_user_activity', True): + if config.get('enable_user_activity'): self.register_command('activity', self.command_activity, usage='[<general> [specific] [text]]', desc=_('Send your current activity to your contacts ' @@ -1873,7 +1873,7 @@ class Core(object): '"stop broadcasting an activity".'), shortdesc=_('Send your activity.'), completion=self.completion_activity) - if config.get('enable_user_mood', True): + if config.get('enable_user_mood'): self.register_command('mood', self.command_mood, usage='[<mood> [text]]', desc=_('Send your current mood to your contacts ' @@ -1881,7 +1881,7 @@ class Core(object): '"stop broadcasting a mood".'), shortdesc=_('Send your mood.'), completion=self.completion_mood) - if config.get('enable_user_gaming', True): + if config.get('enable_user_gaming'): self.register_command('gaming', self.command_gaming, usage='[<game name> [server address]]', desc=_('Send your current gaming activity to ' @@ -2025,7 +2025,7 @@ def replace_key_with_bound(key): Replace an inputted key with the one defined as its replacement in the config """ - bind = config.get(key, key, 'bindings') + bind = config.get(key, default=key, section='bindings') if not bind: bind = key return bind diff --git a/src/core/handlers.py b/src/core/handlers.py index 4e2fcfd3..648c3e4d 100644 --- a/src/core/handlers.py +++ b/src/core/handlers.py @@ -13,6 +13,7 @@ import sys import time from hashlib import sha1, sha512 from gettext import gettext as _ +from os import path from slixmpp import InvalidJID from slixmpp.stanza import Message @@ -27,7 +28,7 @@ import windows import xhtml import multiuserchat as muc from common import safeJID -from config import config +from config import config, CACHE_DIR from contact import Resource from logger import logger from roster import roster @@ -46,7 +47,7 @@ def on_session_start_features(self, _): features = iq['disco_info']['features'] rostertab = self.get_tab_by_name('Roster', tabs.RosterInfoTab) rostertab.check_blocking(features) - if (config.get('enable_carbons', True) and + if (config.get('enable_carbons') and 'urn:xmpp:carbons:2' in features): self.xmpp.plugin['xep_0280'].enable() self.xmpp.add_event_handler('carbon_received', self.on_carbon_received) @@ -120,7 +121,7 @@ def on_groupchat_invitation(self, message): if password: msg += ". The password is \"%s\"." % password self.information(msg, 'Info') - if 'invite' in config.get('beep_on', 'invite').split(): + if 'invite' in config.get('beep_on').split(): curses.beep() logger.log_roster_change(inviter.full, 'invited you to %s' % jid.full) self.pending_invites[jid.bare] = inviter.full @@ -151,7 +152,7 @@ def on_groupchat_direct_invitation(self, message): msg += "\nreason: %s" % reason self.information(msg, 'Info') - if 'invite' in config.get('beep_on', 'invite').split(): + if 'invite' in config.get('beep_on').split(): curses.beep() self.pending_invites[room.bare] = inviter.full @@ -188,8 +189,12 @@ def on_normal_message(self, message): elif message['type'] == 'headline' and message['body']: return self.information('%s says: %s' % (message['from'], message['body']), 'Headline') - use_xhtml = config.get('enable_xhtml_im', True) - body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml) + use_xhtml = config.get('enable_xhtml_im') + tmp_dir = config.get('tmp_image_dir') or path.join(CACHE_DIR, 'images') + extract_images = config.get('extract_inline_images') + body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml, + tmp_dir=tmp_dir, + extract_images=extract_images) if not body: return @@ -203,7 +208,7 @@ def on_normal_message(self, message): if conv_jid.bare in roster: remote_nick = roster[conv_jid.bare].name # check for a received nick - if not remote_nick and config.get('enable_user_nick', True): + if not remote_nick and config.get('enable_user_nick'): if message.xml.find('{http://jabber.org/protocol/nick}nick') is not None: remote_nick = message['nick']['nick'] if not remote_nick: @@ -234,13 +239,15 @@ def on_normal_message(self, message): self.events.trigger('conversation_msg', message, conversation) if not message['body']: return - body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml) + body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml, + tmp_dir=tmp_dir, + extract_images=extract_images) delayed, date = common.find_delayed_tag(message) def try_modify(): replaced_id = message['replace']['id'] - if replaced_id and (config.get_by_tabname('group_corrections', - True, conv_jid.bare)): + if replaced_id and config.get_by_tabname('group_corrections', + conv_jid.bare): try: conversation.modify_message(body, replaced_id, message['id'], jid=jid, nickname=remote_nick) @@ -263,8 +270,8 @@ def on_normal_message(self, message): conversation.remote_wants_chatstates = True else: conversation.remote_wants_chatstates = False - if 'private' in config.get('beep_on', 'highlight private').split(): - if not config.get_by_tabname('disable_beep', False, conv_jid.bare, False): + if 'private' in config.get('beep_on').split(): + if not config.get_by_tabname('disable_beep', conv_jid.bare): curses.beep() if self.current_tab() is not conversation: conversation.state = 'private' @@ -314,7 +321,7 @@ def on_gaming_event(self, message): if contact.gaming: logger.log_roster_change(contact.bare_jid, 'is playing %s' % (common.format_gaming_string(contact.gaming))) - if old_gaming != contact.gaming and config.get_by_tabname('display_gaming_notifications', False, contact.bare_jid): + if old_gaming != contact.gaming and config.get_by_tabname('display_gaming_notifications', contact.bare_jid): if contact.gaming: self.information('%s is playing %s' % (contact.bare_jid, common.format_gaming_string(contact.gaming)), 'Gaming') else: @@ -347,7 +354,7 @@ def on_mood_event(self, message): if contact.mood: logger.log_roster_change(contact.bare_jid, 'has now the mood: %s' % contact.mood) - if old_mood != contact.mood and config.get_by_tabname('display_mood_notifications', False, contact.bare_jid): + if old_mood != contact.mood and config.get_by_tabname('display_mood_notifications', contact.bare_jid): if contact.mood: self.information('Mood from '+ contact.bare_jid + ': ' + contact.mood, 'Mood') else: @@ -386,7 +393,7 @@ def on_activity_event(self, message): if contact.activity: logger.log_roster_change(contact.bare_jid, 'has now the activity %s' % contact.activity) - if old_activity != contact.activity and config.get_by_tabname('display_activity_notifications', False, contact.bare_jid): + if old_activity != contact.activity and config.get_by_tabname('display_activity_notifications', contact.bare_jid): if contact.activity: self.information('Activity from '+ contact.bare_jid + ': ' + contact.activity, 'Activity') else: @@ -420,7 +427,7 @@ def on_tune_event(self, message): if contact.tune: logger.log_roster_change(message['from'].bare, 'is now listening to %s' % common.format_tune_string(contact.tune)) - if old_tune != contact.tune and config.get_by_tabname('display_tune_notifications', False, contact.bare_jid): + if old_tune != contact.tune and config.get_by_tabname('display_tune_notifications', contact.bare_jid): if contact.tune: self.information( 'Tune from '+ message['from'].bare + ': ' + common.format_tune_string(contact.tune), @@ -451,8 +458,12 @@ def on_groupchat_message(self, message): return self.events.trigger('muc_msg', message, tab) - use_xhtml = config.get('enable_xhtml_im', True) - body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml) + use_xhtml = config.get('enable_xhtml_im') + tmp_dir = config.get('tmp_image_dir') or path.join(CACHE_DIR, 'images') + extract_images = config.get('extract_inline_images') + body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml, + tmp_dir=tmp_dir, + extract_images=extract_images) if not body: return @@ -460,8 +471,8 @@ def on_groupchat_message(self, message): delayed, date = common.find_delayed_tag(message) replaced_id = message['replace']['id'] replaced = False - if replaced_id is not '' and (config.get_by_tabname( - 'group_corrections', True, message['from'].bare)): + if replaced_id is not '' and config.get_by_tabname('group_corrections', + message['from'].bare): try: if tab.modify_message(body, replaced_id, message['id'], time=date, nickname=nick_from, user=user): @@ -487,8 +498,8 @@ def on_groupchat_message(self, message): current.input.refresh() self.doupdate() - if 'message' in config.get('beep_on', 'highlight private').split(): - if (not config.get_by_tabname('disable_beep', False, room_from, False) + if 'message' in config.get('beep_on').split(): + if (not config.get_by_tabname('disable_beep', room_from) and self.own_nick != message['from'].resource): curses.beep() @@ -508,28 +519,34 @@ def on_groupchat_private_message(self, message): return self.on_groupchat_message(message) room_from = jid.bare - use_xhtml = config.get('enable_xhtml_im', True) - body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml) + use_xhtml = config.get('enable_xhtml_im') + tmp_dir = config.get('tmp_image_dir') or path.join(CACHE_DIR, 'images') + extract_images = config.get('extract_inline_images') + body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml, + tmp_dir=tmp_dir, + extract_images=extract_images) tab = self.get_tab_by_name(jid.full, tabs.PrivateTab) # get the tab with the private conversation - ignore = config.get_by_tabname('ignore_private', False, room_from) + ignore = config.get_by_tabname('ignore_private', room_from) if not tab: # It's the first message we receive: create the tab if body and not ignore: tab = self.open_private_window(room_from, nick_from, False) if ignore: self.events.trigger('ignored_private', message, tab) - msg = config.get_by_tabname('private_auto_response', None, room_from) + msg = config.get_by_tabname('private_auto_response', room_from) if msg and body: self.xmpp.send_message(mto=jid.full, mbody=msg, mtype='chat') return self.events.trigger('private_msg', message, tab) - body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml) + body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml, + tmp_dir=tmp_dir, + extract_images=extract_images) if not body or not tab: return replaced_id = message['replace']['id'] replaced = False user = tab.parent_muc.get_user_by_name(nick_from) - if replaced_id is not '' and (config.get_by_tabname( - 'group_corrections', True, room_from)): + if replaced_id is not '' and config.get_by_tabname('group_corrections', + room_from): try: tab.modify_message(body, replaced_id, message['id'], user=user, jid=message['from'], nickname=nick_from) @@ -548,8 +565,8 @@ def on_groupchat_private_message(self, message): tab.remote_wants_chatstates = True else: tab.remote_wants_chatstates = False - if 'private' in config.get('beep_on', 'highlight private').split(): - if not config.get_by_tabname('disable_beep', False, jid.full, False): + if 'private' in config.get('beep_on').split(): + if not config.get_by_tabname('disable_beep', jid.full): curses.beep() if tab is self.current_tab(): self.refresh_window() @@ -883,7 +900,7 @@ def on_session_start(self, event): # request the roster self.xmpp.get_roster() # send initial presence - if config.get('send_initial_presence', True): + if config.get('send_initial_presence'): pres = self.xmpp.make_presence() pres['show'] = self.status.show pres['status'] = self.status.message @@ -893,13 +910,13 @@ def on_session_start(self, event): def _join_initial_rooms(bookmarks): """Join all rooms given in the iterator `bookmarks`""" for bm in bookmarks: - if bm.autojoin or config.get('open_all_bookmarks', False): + if bm.autojoin or config.get('open_all_bookmarks'): tab = self.get_tab_by_name(bm.jid, tabs.MucTab) nick = bm.nick if bm.nick else self.own_nick if not tab: self.open_new_room(bm.jid, nick, False) self.initial_joins.append(bm.jid) - histo_length = config.get('muc_history_length', 20) + histo_length = config.get('muc_history_length') if histo_length == -1: histo_length = None if histo_length is not None: @@ -915,13 +932,13 @@ def on_session_start(self, event): def _join_remote_only(): remote_bookmarks = (bm for bm in bookmark.bookmarks if (bm.method in ("pep", "privatexml"))) _join_initial_rooms(remote_bookmarks) - if not self.xmpp.anon and config.get('use_remote_bookmarks', True): + if not self.xmpp.anon and config.get('use_remote_bookmarks'): bookmark.get_remote(self.xmpp, _join_remote_only) # join all the available bookmarks. As of yet, this is just the local # ones _join_initial_rooms(bookmark.bookmarks) - if config.get('enable_user_nick', True): + if config.get('enable_user_nick'): self.xmpp.plugin['xep_0172'].publish_nick(nick=self.own_nick, callback=dumb_callback) self.xmpp.plugin['xep_0115'].update_caps() # Start the ping's plugin regular event @@ -994,18 +1011,21 @@ def on_groupchat_subject(self, message): room_from = message.get_mucroom() tab = self.get_tab_by_name(room_from, tabs.MucTab) subject = message['subject'] - if not subject or not tab: + if subject is None or not tab: return - if nick_from: - tab.add_message(_("\x19%(info_col)s}%(nick)s set the subject to: %(subject)s") % - {'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT), 'nick':nick_from, 'subject':subject}, - time=None, - typ=2) - else: - tab.add_message(_("\x19%(info_col)s}The subject is: %(subject)s") % - {'subject':subject, 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)}, - time=None, - typ=2) + if subject != tab.topic: + # Do not display the message if the subject did not change or if we + # receive an empty topic when joining the room. + if nick_from: + tab.add_message(_("\x19%(info_col)s}%(nick)s set the subject to: %(subject)s") % + {'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT), 'nick':nick_from, 'subject':subject}, + time=None, + typ=2) + else: + tab.add_message(_("\x19%(info_col)s}The subject is: %(subject)s") % + {'subject':subject, 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)}, + time=None, + typ=2) tab.topic = subject tab.topic_from = nick_from if self.get_tab_by_name(room_from, tabs.MucTab) is self.current_tab(): @@ -1064,8 +1084,8 @@ def room_error(self, error, room_name): msg = _('To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)') tab.add_message(msg, typ=2) if code == '409': - if config.get('alternative_nickname', '') != '': - self.command_join('%s/%s'% (tab.name, tab.own_nick+config.get('alternative_nickname', ''))) + if config.get('alternative_nickname') != '': + self.command_join('%s/%s'% (tab.name, tab.own_nick+config.get('alternative_nickname'))) else: if not tab.joined: tab.add_message(_('You can join the room with an other nick, by typing "/join /other_nick"'), typ=2) @@ -1095,9 +1115,9 @@ def validate_ssl(self, pem): """ Check the server certificate using the slixmpp ssl_cert event """ - if config.get('ignore_certificate', False): + if config.get('ignore_certificate'): return - cert = config.get('certificate', '') + cert = config.get('certificate') # update the cert representation when it uses the old one if cert and not ':' in cert: cert = ':'.join(i + j for i, j in zip(cert[::2], cert[1::2])).upper() @@ -1173,7 +1193,7 @@ def _composing_tab_state(tab, state): else: return # should not happen - show = config.get('show_composing_tabs', 'direct') + show = config.get('show_composing_tabs') show = show in values if tab.state != 'composing' and state == 'composing': |