diff options
author | mathieui <mathieui@mathieui.net> | 2014-03-24 23:25:06 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2014-03-24 23:25:06 +0100 |
commit | 8d4202501d68e165ef85f720e72cb83ce384eab8 (patch) | |
tree | 7145f62740f7e3176bd845a103e012d4effe4cc7 /src | |
parent | 6b1e3dd4ac03b14a4af23cf3e0060f4c3d1de328 (diff) | |
download | poezio-8d4202501d68e165ef85f720e72cb83ce384eab8.tar.gz poezio-8d4202501d68e165ef85f720e72cb83ce384eab8.tar.bz2 poezio-8d4202501d68e165ef85f720e72cb83ce384eab8.tar.xz poezio-8d4202501d68e165ef85f720e72cb83ce384eab8.zip |
Use RawConfigParser.get{int,bool,float} whenever possible
config.get('option', 'value').lower() == 'value' is just ugly and
stupid, especially for bool.
One if in basetabs:556 was also missing a comparison, leading to True
whenever the option was set.
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmark.py | 2 | ||||
-rw-r--r-- | src/config.py | 43 | ||||
-rw-r--r-- | src/connection.py | 20 | ||||
-rw-r--r-- | src/core.py | 91 | ||||
-rw-r--r-- | src/logger.py | 8 | ||||
-rw-r--r-- | src/tabs/basetabs.py | 8 | ||||
-rw-r--r-- | src/tabs/conversationtab.py | 10 | ||||
-rw-r--r-- | src/tabs/muctab.py | 40 | ||||
-rw-r--r-- | src/tabs/privatetab.py | 12 | ||||
-rw-r--r-- | src/tabs/rostertab.py | 6 | ||||
-rw-r--r-- | src/text_buffer.py | 2 | ||||
-rw-r--r-- | src/windows.py | 34 |
12 files changed, 137 insertions, 139 deletions
diff --git a/src/bookmark.py b/src/bookmark.py index a68cc27a..98bfecc4 100644 --- a/src/bookmark.py +++ b/src/bookmark.py @@ -157,7 +157,7 @@ def save_local(): def save(xmpp, core=None): """Save all the bookmarks.""" save_local() - if config.get('use_remote_bookmarks', 'true').lower() != 'false': + if config.get('use_remote_bookmarks', True): preferred = config.get('use_bookmarks_method', 'privatexml') if not save_remote(xmpp, method=preferred) and core: core.information('Could not save bookmarks.', 'Error') diff --git a/src/config.py b/src/config.py index a51637bb..79a70bb5 100644 --- a/src/config.py +++ b/src/config.py @@ -24,7 +24,6 @@ from os import environ, makedirs, path, remove from shutil import copy2 from args import parse_args - class Config(RawConfigParser): """ load/save the config to a file @@ -62,16 +61,12 @@ class Config(RawConfigParser): res = self.getboolean(option, section) else: res = self.getstr(option, section) - except (NoOptionError, NoSectionError): + except (NoOptionError, NoSectionError, ValueError, AttributeError) as e: + return default + if res is None: return default return res - def getl(self, option, default, section=DEFSECTION): - """ - get a value and return it lowercase - """ - return self.get(option, default, section).lower() - def get_by_tabname(self, option, default, tabname, fallback=True, fallback_server=True): """ Try to get the value for the option. First we look in @@ -104,11 +99,17 @@ class Config(RawConfigParser): return default - def __get(self, option, section=DEFSECTION): + def __get(self, option, section=DEFSECTION, **kwargs): """ facility for RawConfigParser.get """ - return RawConfigParser.get(self, section, option) + return RawConfigParser.get(self, section, option, **kwargs) + + def _get(self, section, conv, option, **kwargs): + """ + Redirects RawConfigParser._get + """ + return conv(self.__get(option, section, **kwargs)) def getstr(self, option, section=DEFSECTION): """ @@ -120,16 +121,13 @@ class Config(RawConfigParser): """ get a value and returns it as an int """ - try: - return int(self.__get(option, section)) - except ValueError: - return -1 + RawConfigParser.getint(self, section, option) def getfloat(self, option, section=DEFSECTION): """ get a value and returns it as a float """ - return float(self.__get(option, section)) + return RawConfigParser.getfloat(self, section, option) def getboolean(self, option, section=DEFSECTION): """ @@ -209,12 +207,15 @@ class Config(RawConfigParser): # or it is not a bool. if value == "toggle": current = self.get(option, "", section) - if current.lower() == "false": - value = "true" - elif current.lower() == "true": - value = "false" + if isinstance(current, bool): + value = str(not current) else: - return (_("Could not toggle option: %s. Current value is %s.") % (option, current or _("empty")), 'Warning') + if current.lower() == "false": + value = "true" + elif current.lower() == "true": + value = "false" + else: + return (_("Could not toggle option: %s. Current value is %s.") % (option, current or _("empty")), 'Warning') if self.has_section(section): RawConfigParser.set(self, section, option, value) else: @@ -313,7 +314,7 @@ LOGGING_CONFIG = { 'level': 'DEBUG', } } -if config.get('log_errors', 'true').lower() != 'false': +if config.get('log_errors', True): LOGGING_CONFIG['root']['handlers'].append('error') LOGGING_CONFIG['handlers']['error'] = { 'level': 'ERROR', diff --git a/src/connection.py b/src/connection.py index fed43d88..3010a9fe 100644 --- a/src/connection.py +++ b/src/connection.py @@ -50,7 +50,7 @@ class Connection(sleekxmpp.ClientXMPP): # TODO: use the system language sleekxmpp.ClientXMPP.__init__(self, jid, password, lang=config.get('lang', 'en')) - force_encryption = config.get('force_encryption', 'true').lower() != 'false' + force_encryption = config.get('force_encryption', True) if force_encryption: self['feature_mechanisms'].unencrypted_plain = False self['feature_mechanisms'].unencrypted_digest = False @@ -58,7 +58,7 @@ class Connection(sleekxmpp.ClientXMPP): self['feature_mechanisms'].unencrypted_scram = False self.core = None - self.auto_reconnect = True if config.get('auto_reconnect', 'false').lower() in ('true', '1') else False + self.auto_reconnect = config.get('auto_reconnect', False) self.reconnect_max_attempts = 0 self.auto_authorize = None # prosody defaults, lowest is AES128-SHA, it should be a minimum @@ -88,32 +88,32 @@ class Connection(sleekxmpp.ClientXMPP): self.register_plugin('xep_0199') self.set_keepalive_values() - if config.get('enable_user_tune', 'true') != 'false': + if config.get('enable_user_tune', True): self.register_plugin('xep_0118') - if config.get('enable_user_nick', 'true') != 'false': + if config.get('enable_user_nick', True): self.register_plugin('xep_0172') - if config.get('enable_user_mood', 'true') != 'false': + if config.get('enable_user_mood', True): self.register_plugin('xep_0107') - if config.get('enable_user_activity', 'true') != 'false': + if config.get('enable_user_activity', True): self.register_plugin('xep_0108') - if config.get('enable_user_gaming', 'true') != 'false': + if config.get('enable_user_gaming', True): self.register_plugin('xep_0196') - if config.get('send_poezio_info', 'true') == 'true': + if config.get('send_poezio_info', True): info = {'name':'poezio', 'version': options.version} - if config.get('send_os_info', 'true') == 'true': + if config.get('send_os_info', True): info['os'] = common.get_os_info() self.plugin['xep_0030'].set_identities(identities=set([('client', 'pc', None,'Poezio')])) else: info = {'name': '', 'version': ''} self.plugin['xep_0030'].set_identities(identities=set([('client', 'pc', None,'')])) self.register_plugin('xep_0092', pconfig=info) - if config.get('send_time', 'true') == 'true': + if config.get('send_time', True): self.register_plugin('xep_0202') self.register_plugin('xep_0224') self.register_plugin('xep_0280') diff --git a/src/core.py b/src/core.py index ddf2c3a1..c3ae2ef8 100644 --- a/src/core.py +++ b/src/core.py @@ -165,7 +165,7 @@ class Core(object): self.register_initial_commands() # We are invisible - if config.get('send_initial_presence', 'true').lower() == 'false': + if not config.get('send_initial_presence', True): del self.commands['status'] del self.commands['show'] @@ -266,15 +266,15 @@ class Core(object): self.xmpp.add_event_handler("ssl_cert", self.validate_ssl) self.all_stanzas = Callback('custom matcher', connection.MatchAll(None), self.incoming_stanza) self.xmpp.register_handler(self.all_stanzas) - if config.get('enable_user_tune', 'true') != 'false': + if config.get('enable_user_tune', True): self.xmpp.add_event_handler("user_tune_publish", self.on_tune_event) - if config.get('enable_user_nick', 'true') != 'false': + if config.get('enable_user_nick', True): self.xmpp.add_event_handler("user_nick_publish", self.on_nick_received) - if config.get('enable_user_mood', 'true') != 'false': + if config.get('enable_user_mood', True): self.xmpp.add_event_handler("user_mood_publish", self.on_mood_event) - if config.get('enable_user_activity', 'true') != 'false': + if config.get('enable_user_activity', True): self.xmpp.add_event_handler("user_activity_publish", self.on_activity_event) - if config.get('enable_user_gaming', 'true') != 'false': + if config.get('enable_user_gaming', True): self.xmpp.add_event_handler("user_gaming_publish", self.on_gaming_event) self.initial_joins = [] @@ -399,11 +399,11 @@ class Core(object): (and only roster UI things are not yet saved) """ log.debug("Either SIGHUP or SIGTERM received. Exiting…") - if config.get('enable_user_mood', 'true') != 'false': + if config.get('enable_user_mood', True): self.xmpp.plugin['xep_0107'].stop(block=False) - if config.get('enable_user_activity', 'true') != 'false': + if config.get('enable_user_activity', True): self.xmpp.plugin['xep_0108'].stop(block=False) - if config.get('enable_user_gaming', 'true') != 'false': + if config.get('enable_user_gaming', True): self.xmpp.plugin['xep_0196'].stop(block=False) self.plugin_manager.disable_plugins() self.disconnect('') @@ -627,7 +627,7 @@ 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') == 'true': + if config.get('exec_remote', False): # We just write the command in the fifo if not self.remote_fifo: try: @@ -711,7 +711,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').lower() != 'false': + if config.get('save_status', True): if not config.silent_set('status', pres if pres else '') or \ not config.silent_set('status_message', msg.replace('\n', '|') if msg else ''): self.information(_('Unable to write in the config file'), 'Error') @@ -916,7 +916,7 @@ class Core(object): return False elif not self.tabs[old_pos]: return False - if config.get('create_gaps', 'false').lower() == 'true': + if config.get('create_gaps', False): return self.insert_tab_gaps(old_pos, new_pos) return self.insert_tab_nogaps(old_pos, new_pos) @@ -1136,7 +1136,7 @@ class Core(object): del tab.commands # and make the object collectable tab.on_close() nb = tab.nb - if config.get('create_gaps', 'false').lower() == 'true': + if config.get('create_gaps', False): if nb >= len(self.tabs) - 1: self.tabs.remove(tab) nb -= 1 @@ -1370,8 +1370,8 @@ class Core(object): """ Enable/disable the left panel. """ - enabled = config.get('enable_vertical_tab_list', 'false') - if not config.silent_set('enable_vertical_tab_list', 'false' if enabled == 'true' else 'true'): + enabled = config.get('enable_vertical_tab_list', False) + 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() @@ -1389,7 +1389,7 @@ class Core(object): """ with g_lock: self.tab_win.resize(1, tabs.Tab.width, tabs.Tab.height - 2, 0) - if config.get('enable_vertical_tab_list', 'false') == 'true': + if config.get('enable_vertical_tab_list', False): height, width = self.stdscr.getmaxyx() truncated_win = self.stdscr.subwin(height, config.get('vertical_tab_list_size', 20), 0, 0) self.left_tab_win = windows.VerticalGlobalInfoBar(truncated_win) @@ -1421,7 +1421,7 @@ class Core(object): # window to each Tab class, so the draw themself in the portion # of the screen that the can occupy, and we draw the tab list # on the left remaining space - if config.get('enable_vertical_tab_list', 'false') == 'true': + if config.get('enable_vertical_tab_list', False): with g_lock: scr = self.stdscr.subwin(0, config.get('vertical_tab_list_size', 20)) else: @@ -1431,7 +1431,7 @@ class Core(object): self.resize_global_information_win() with g_lock: for tab in self.tabs: - if config.get('lazy_resize', 'true') == 'true': + if config.get('lazy_resize', True): tab.need_resize = True else: tab.resize() @@ -2053,7 +2053,7 @@ class Core(object): /bookmark [room][/nick] [autojoin] [password] """ - if config.get('use_remote_bookmarks', 'true').lower() == 'false': + if not config.get('use_remote_bookmarks', True): self.command_bookmark_local(arg) return args = common.shell_split(arg) @@ -2464,11 +2464,11 @@ class Core(object): msg = arg else: msg = None - if config.get('enable_user_mood', 'true') != 'false': + if config.get('enable_user_mood', True): self.xmpp.plugin['xep_0107'].stop(block=False) - if config.get('enable_user_activity', 'true') != 'false': + if config.get('enable_user_activity', True): self.xmpp.plugin['xep_0108'].stop(block=False) - if config.get('enable_user_gaming', 'true') != 'false': + if config.get('enable_user_gaming', True): self.xmpp.plugin['xep_0196'].stop(block=False) self.save_config() self.plugin_manager.disable_plugins() @@ -2817,21 +2817,21 @@ class Core(object): shortdesc=_('Get the activity of someone.'), completion=self.completion_last_activity) - if config.get('enable_user_mood', 'true') != 'false': + if config.get('enable_user_mood', True): self.register_command('activity', self.command_activity, usage='[<general> [specific] [text]]', desc=_('Send your current activity to your contacts (use the completion).' ' Nothing means "stop broadcasting an activity".'), shortdesc=_('Send your activity.'), completion=self.completion_activity) - if config.get('enable_user_activity', 'true') != 'false': + if config.get('enable_user_activity', True): self.register_command('mood', self.command_mood, usage='[<mood> [text]]', desc=_('Send your current mood to your contacts (use the completion).' ' Nothing means "stop broadcasting a mood".'), shortdesc=_('Send your mood.'), completion=self.completion_mood) - if config.get('enable_user_gaming', 'true') != 'false': + if config.get('enable_user_gaming', True): self.register_command('gaming', self.command_gaming, usage='[<game name> [server address]]', desc=_('Send your current gaming activity to your contacts.' @@ -2851,7 +2851,7 @@ class Core(object): features = iq['disco_info']['features'] rostertab = self.get_tab_by_name('Roster') rostertab.check_blocking(features) - if (config.get('enable_carbons', 'true').lower() != 'false' and + if (config.get('enable_carbons', True) and 'urn:xmpp:carbons:2' in features): self.xmpp.plugin['xep_0280'].enable() self.xmpp.add_event_handler('carbon_received', self.on_carbon_received) @@ -2939,7 +2939,7 @@ class Core(object): 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') == 'true' + use_xhtml = config.get('enable_xhtml_im', True) body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml) if not body: return @@ -2954,7 +2954,7 @@ class Core(object): 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') != 'false': + if not remote_nick and config.get('enable_user_nick', True): if message.xml.find('{http://jabber.org/protocol/nick}nick') is not None: remote_nick = message['nick']['nick'] own = False @@ -2988,7 +2988,7 @@ class Core(object): def try_modify(): replaced_id = message['replace']['id'] if replaced_id and (config.get_by_tabname('group_corrections', - 'true', conv_jid.bare).lower() != 'false'): + True, conv_jid.bare)): try: conversation.modify_message(body, replaced_id, message['id'], jid=jid, nickname=remote_nick) @@ -3012,7 +3012,7 @@ class Core(object): else: conversation.remote_wants_chatstates = False if 'private' in config.get('beep_on', 'highlight private').split(): - if config.get_by_tabname('disable_beep', 'false', conv_jid.bare, False).lower() != 'true': + if not config.get_by_tabname('disable_beep', False, conv_jid.bare, False): curses.beep() if self.current_tab() is not conversation: conversation.state = 'private' @@ -3062,7 +3062,7 @@ class Core(object): 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) == 'true': + if old_gaming != contact.gaming and config.get_by_tabname('display_gaming_notifications', False, contact.bare_jid): if contact.gaming: self.information('%s is playing %s' % (contact.bare_jid, common.format_gaming_string(contact.gaming)), 'Gaming') else: @@ -3095,7 +3095,7 @@ class Core(object): 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) == 'true': + if old_mood != contact.mood and config.get_by_tabname('display_mood_notifications', False, contact.bare_jid): if contact.mood: self.information('Mood from '+ contact.bare_jid + ': ' + contact.mood, 'Mood') else: @@ -3134,7 +3134,7 @@ class Core(object): 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) == 'true': + if old_activity != contact.activity and config.get_by_tabname('display_activity_notifications', False, contact.bare_jid): if contact.activity: self.information('Activity from '+ contact.bare_jid + ': ' + contact.activity, 'Activity') else: @@ -3168,7 +3168,7 @@ class Core(object): 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) == 'true': + if old_tune != contact.tune and config.get_by_tabname('display_tune_notifications', False, contact.bare_jid): if contact.tune: self.information( 'Tune from '+ message['from'].bare + ': ' + common.format_tune_string(contact.tune), @@ -3198,7 +3198,7 @@ class Core(object): return self.events.trigger('muc_msg', message, tab) - use_xhtml = config.get('enable_xhtml_im', 'true') == 'true' + use_xhtml = config.get('enable_xhtml_im', True) body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml) if not body: return @@ -3208,7 +3208,7 @@ class Core(object): replaced_id = message['replace']['id'] replaced = False if replaced_id is not '' and (config.get_by_tabname( - 'group_corrections', 'true', message['from'].bare).lower() != 'false'): + 'group_corrections', True, message['from'].bare)): try: if tab.modify_message(body, replaced_id, message['id'], time=date, nickname=nick_from, user=user): @@ -3233,7 +3233,7 @@ class Core(object): self.doupdate() if 'message' in config.get('beep_on', 'highlight private').split(): - if config.get_by_tabname('disable_beep', 'false', room_from, False).lower() != 'true': + if not config.get_by_tabname('disable_beep', False, room_from, False): curses.beep() def on_muc_own_nickchange(self, muc): @@ -3252,11 +3252,10 @@ class Core(object): return self.on_groupchat_message(message) room_from = jid.bare - use_xhtml = config.get('enable_xhtml_im', 'true') == 'true' + use_xhtml = config.get('enable_xhtml_im', True) body = xhtml.get_body_from_message_stanza(message, use_xhtml=use_xhtml) 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).lower() == 'true' + ignore = config.get_by_tabname('ignore_private', False, 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) @@ -3274,7 +3273,7 @@ class Core(object): 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).lower() != 'false'): + 'group_corrections', True, room_from)): try: tab.modify_message(body, replaced_id, message['id'], user=user, jid=message['from'], nickname=nick_from) @@ -3294,7 +3293,7 @@ class Core(object): else: tab.remote_wants_chatstates = False if 'private' in config.get('beep_on', 'highlight private').split(): - if config.get_by_tabname('disable_beep', 'false', jid.full, False).lower() != 'true': + if not config.get_by_tabname('disable_beep', False, jid.full, False): curses.beep() if tab is self.current_tab(): self.refresh_window() @@ -3591,14 +3590,14 @@ class Core(object): # request the roster self.xmpp.get_roster() # send initial presence - if config.get('send_initial_presence', 'true').lower() != 'false': + if config.get('send_initial_presence', True): pres = self.xmpp.make_presence() pres['show'] = self.status.show pres['status'] = self.status.message self.events.trigger('send_normal_presence', pres) pres.send() bookmark.get_local() - if not self.xmpp.anon and not config.get('use_remote_bookmarks', 'true').lower() == 'false': + if not self.xmpp.anon and config.get('use_remote_bookmarks', True): bookmark.get_remote(self.xmpp) for bm in bookmark.bookmarks: tab = self.get_tab_by_name(bm.jid, tabs.MucTab) @@ -3620,7 +3619,7 @@ class Core(object): status=self.status.message, show=self.status.show) - if config.get('enable_user_nick', 'true') != 'false': + if config.get('enable_user_nick', True): self.xmpp.plugin['xep_0172'].publish_nick(nick=self.own_nick, callback=dumb_callback, block=False) self.xmpp.plugin['xep_0115'].update_caps() @@ -3774,7 +3773,7 @@ class Core(object): """ Check the server certificate using the sleekxmpp ssl_cert event """ - if config.get('ignore_certificate', 'false').lower() == 'true': + if config.get('ignore_certificate', False): return cert = config.get('certificate', '') # update the cert representation when it uses the old one diff --git a/src/logger.py b/src/logger.py index 7db34932..c05cc4a6 100644 --- a/src/logger.py +++ b/src/logger.py @@ -67,7 +67,7 @@ class Logger(object): Check that the directory where we want to log the messages exists. if not, create it """ - if config.get_by_tabname('use_log', 'true', room) == 'false': + if not config.get_by_tabname('use_log', True, room): return try: makedirs(log_dir) @@ -98,7 +98,7 @@ class Logger(object): if config.get_by_tabname('load_log', 10, jid) <= 0: return - if config.get_by_tabname('use_log', 'true', jid) == 'false': + if not config.get_by_tabname('use_log', True, jid): return if nb <= 0: @@ -184,7 +184,7 @@ class Logger(object): return True jid = str(jid).replace('/', '\\') - if config.get_by_tabname('use_log', 'false', jid) != 'true': + if not config.get_by_tabname('use_log', False, jid): return True if jid in self.fds.keys(): fd = self.fds[jid] @@ -232,7 +232,7 @@ class Logger(object): """ Log a roster change """ - if config.get_by_tabname('use_log', 'false', jid) != 'true': + if not config.get_by_tabname('use_log', False, jid): return True self.check_and_create_log_dir('', open_fd=False) if not self.roster_logfile: diff --git a/src/tabs/basetabs.py b/src/tabs/basetabs.py index 5e38775b..00f924b0 100644 --- a/src/tabs/basetabs.py +++ b/src/tabs/basetabs.py @@ -126,7 +126,7 @@ class Tab(object): Returns 1 or 0, depending on if we are using the vertical tab list or not. """ - if config.get('enable_vertical_tab_list', 'false') == 'true': + if config.get('enable_vertical_tab_list', False): return 0 return 1 @@ -556,7 +556,7 @@ class ChatTab(Tab): if not self.is_muc or self.joined: if state in ('active', 'inactive', 'gone') and self.inactive and not always_send: return - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) and \ + if config.get_by_tabname('send_chat_states', True, self.general_jid, True) and \ self.remote_wants_chatstates is not False: msg = self.core.xmpp.make_message(self.get_dest_jid()) msg['type'] = self.message_type @@ -570,7 +570,7 @@ class ChatTab(Tab): on the the current status of the input """ name = self.general_jid - if config.get_by_tabname('send_chat_states', 'true', name, True) == 'true' and self.remote_wants_chatstates: + if config.get_by_tabname('send_chat_states', True, name, True) and self.remote_wants_chatstates: needed = 'inactive' if self.inactive else 'active' self.cancel_paused_delay() if not empty_after: @@ -585,7 +585,7 @@ class ChatTab(Tab): we create a timed event that will put us to paused in a few seconds """ - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) != 'true': + if not config.get_by_tabname('send_chat_states', True, self.general_jid, True): return if self.timed_event_paused: # check the weakref diff --git a/src/tabs/conversationtab.py b/src/tabs/conversationtab.py index 5e9734d5..6c0bf2e0 100644 --- a/src/tabs/conversationtab.py +++ b/src/tabs/conversationtab.py @@ -109,7 +109,7 @@ class ConversationTab(ChatTab): replaced = False if correct or msg['replace']['id']: msg['replace']['id'] = self.last_sent_message['id'] - if config.get_by_tabname('group_corrections', 'true', self.get_name()).lower() != 'false': + if config.get_by_tabname('group_corrections', True, self.get_name()): try: self.modify_message(msg['body'], self.last_sent_message['id'], msg['id'], jid=self.core.xmpp.boundjid, nickname=self.core.own_nick) @@ -122,7 +122,7 @@ class ConversationTab(ChatTab): msg.enable('html') msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body']) msg['body'] = xhtml.clean_text(msg['body']) - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False: + if config.get_by_tabname('send_chat_states', True, self.general_jid, True) and self.remote_wants_chatstates is not False: needed = 'inactive' if self.inactive else 'active' msg['chat_state'] = needed if attention and self.remote_supports_attention: @@ -318,7 +318,7 @@ class ConversationTab(ChatTab): self.state = 'normal' self.text_win.remove_line_separator() self.text_win.add_line_separator(self._text_buffer) - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and (not self.input.get_text() or not self.input.get_text().startswith('//')): + if config.get_by_tabname('send_chat_states', True, self.general_jid, True) and (not self.input.get_text() or not self.input.get_text().startswith('//')): if resource: self.send_chat_state('inactive') self.check_scrolled() @@ -336,7 +336,7 @@ class ConversationTab(ChatTab): self.state = 'current' curses.curs_set(1) - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and (not self.input.get_text() or not self.input.get_text().startswith('//')): + if config.get_by_tabname('send_chat_states', True, self.general_jid, True) and (not self.input.get_text() or not self.input.get_text().startswith('//')): if resource: self.send_chat_state('active') @@ -351,7 +351,7 @@ class ConversationTab(ChatTab): def on_close(self): Tab.on_close(self) - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true': + if config.get_by_tabname('send_chat_states', True, self.general_jid, True): self.send_chat_state('gone') def matching_names(self): diff --git a/src/tabs/muctab.py b/src/tabs/muctab.py index 0b56df35..b80903d4 100644 --- a/src/tabs/muctab.py +++ b/src/tabs/muctab.py @@ -632,7 +632,7 @@ class MucTab(ChatTab): msg.enable('html') msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body']) msg['body'] = xhtml.clean_text(msg['body']) - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False: + if config.get_by_tabname('send_chat_states', True, self.general_jid, True) and self.remote_wants_chatstates is not False: msg['chat_state'] = needed if correct: msg['replace']['id'] = self.last_sent_message['id'] @@ -698,7 +698,7 @@ class MucTab(ChatTab): if not self.visible: return self.need_resize = False - if config.get("hide_user_list", "false") == "true": + if config.get("hide_user_list", False): text_width = self.width else: text_width = (self.width//10)*9 @@ -716,7 +716,7 @@ class MucTab(ChatTab): log.debug(' TAB Refresh: %s', self.__class__.__name__) self.topic_win.refresh(self.get_single_line_topic()) self.text_win.refresh() - if config.get("hide_user_list", "false") == "false": + if not config.get("hide_user_list", False): self.v_separator.refresh() self.user_win.refresh(self.users) self.info_header.refresh(self, self.text_win) @@ -750,7 +750,7 @@ class MucTab(ChatTab): self.input.get_text()[:input_pos] == self.input.last_completion + after): add_after = after else: - add_after = '' if config.get('add_space_after_completion', 'true') == 'false' else ' ' + add_after = '' if not config.get('add_space_after_completion', True) else ' ' self.input.auto_completion(word_list, add_after, quotify=False) 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) @@ -759,7 +759,7 @@ class MucTab(ChatTab): return self.name def get_nick(self): - if config.getl('show_muc_jid', 'true') == 'false': + if not config.get('show_muc_jid', True): return safeJID(self.name).user return self.name @@ -773,22 +773,22 @@ class MucTab(ChatTab): self.state = 'disconnected' self.text_win.remove_line_separator() self.text_win.add_line_separator(self._text_buffer) - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and not self.input.get_text(): + if config.get_by_tabname('send_chat_states', True, self.general_jid, True) and not self.input.get_text(): self.send_chat_state('inactive') self.check_scrolled() def on_gain_focus(self): self.state = 'current' - if self.text_win.built_lines and self.text_win.built_lines[-1] is None and config.getl('show_useless_separator', 'false') != 'true': + if self.text_win.built_lines and self.text_win.built_lines[-1] is None and not config.get('show_useless_separator', False): self.text_win.remove_line_separator() curses.curs_set(1) - if self.joined and config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and not self.input.get_text(): + if self.joined and config.get_by_tabname('send_chat_states', True, self.general_jid, True) and not self.input.get_text(): self.send_chat_state('active') def on_info_win_size_changed(self): if self.core.information_win_size >= self.height-3: return - if config.get("hide_user_list", "false") == "true": + if config.get("hide_user_list", False): text_width = self.width else: text_width = (self.width//10)*9 @@ -917,7 +917,7 @@ class MucTab(ChatTab): self.users.append(user) hide_exit_join = config.get_by_tabname('hide_exit_join', -1, self.general_jid, True) if hide_exit_join != 0: - color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', '', self.general_jid, True) == 'true' else 3 + color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', True, self.general_jid, True) else 3 if not jid.full: msg = '\x194}%(spec)s \x19%(color)s}%(nick)s\x19%(info_col)s} joined the room' % { 'nick':from_nick, 'color':color, 'spec':get_theme().CHAR_JOIN, @@ -937,7 +937,7 @@ class MucTab(ChatTab): # also change our nick in all private discussions of this room self.core.on_muc_own_nickchange(self) user.change_nick(new_nick) - color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', '', self.general_jid, True) == 'true' else 3 + color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', True, self.general_jid, True) else 3 self.add_message('\x19%(color)s}%(old)s\x19%(info_col)s} is now known as \x19%(color)s}%(new)s' % { 'old':from_nick, 'new':new_nick, 'color':color, 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)}, @@ -967,7 +967,7 @@ class MucTab(ChatTab): self.refresh_tab_win() self.core.current_tab().input.refresh() self.core.doupdate() - if config.get_by_tabname('autorejoin', 'false', self.general_jid, True) == 'true': + if config.get_by_tabname('autorejoin', False, self.general_jid, True): delay = config.get_by_tabname('autorejoin_delay', "5", self.general_jid, True) delay = common.parse_str_to_secs(delay) if delay <= 0: @@ -981,7 +981,7 @@ class MucTab(ChatTab): self.own_nick)) else: - color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', '', self.general_jid, True) == 'true' else 3 + color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', True, self.general_jid, True) else 3 if by: kick_msg = _('\x191}%(spec)s \x19%(color)s}%(nick)s\x19%(info_col)s} has been banned by \x194}%(by)s') % { 'spec':get_theme().CHAR_KICK, 'nick':from_nick, 'color':color, 'by':by, @@ -1018,7 +1018,7 @@ class MucTab(ChatTab): self.core.current_tab().input.refresh() self.core.doupdate() # try to auto-rejoin - if config.get_by_tabname('autorejoin', 'false', self.general_jid, True) == 'true': + if config.get_by_tabname('autorejoin', False, self.general_jid, True): delay = config.get_by_tabname('autorejoin_delay', "5", self.general_jid, True) delay = common.parse_str_to_secs(delay) if delay <= 0: @@ -1031,7 +1031,7 @@ class MucTab(ChatTab): self.name, self.own_nick)) else: - color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', '', self.general_jid, True) == 'true' else 3 + color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', True, self.general_jid, True) else 3 if by: kick_msg = _('\x191}%(spec)s \x19%(color)s}%(nick)s\x19%(info_col)s} has been kicked by \x193}%(by)s') % {'spec': get_theme().CHAR_KICK, 'nick':from_nick, 'color':color, 'by':by, 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)} else: @@ -1052,9 +1052,9 @@ class MucTab(ChatTab): self.refresh_tab_win() self.core.current_tab().input.refresh() self.core.doupdate() - hide_exit_join = config.get_by_tabname('hide_exit_join', -1, self.general_jid, True) if config.get_by_tabname('hide_exit_join', -1, self.general_jid, True) >= -1 else -1 + hide_exit_join = max(config.get_by_tabname('hide_exit_join', -1, self.general_jid, True), -1) if hide_exit_join == -1 or user.has_talked_since(hide_exit_join): - color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', '', self.general_jid, True) == 'true' else 3 + color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', True, self.general_jid, True) else 3 if not jid.full: leave_msg = _('\x191}%(spec)s \x19%(color)s}%(nick)s\x19%(info_col)s} has left the room') % {'nick':from_nick, 'color':color, 'spec':get_theme().CHAR_QUIT, 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)} else: @@ -1071,7 +1071,7 @@ class MucTab(ChatTab): # build the message display_message = False # flag to know if something significant enough # to be displayed has changed - color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', '', self.general_jid, True) == 'true' else 3 + color = dump_tuple(user.color) if config.get_by_tabname('display_user_color_in_join_part', True, self.general_jid, True) else 3 if from_nick == self.own_nick: msg = _('\x193}You\x19%(info_col)s} changed: ') % {'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)} else: @@ -1165,7 +1165,7 @@ class MucTab(ChatTab): if highlighted: beep_on = config.get('beep_on', 'highlight private').split() if 'highlight' in beep_on and 'message' not in beep_on: - if config.get_by_tabname('disable_beep', 'false', self.name, False).lower() != 'true': + if not config.get_by_tabname('disable_beep', False, self.name, False): curses.beep() return highlighted @@ -1197,7 +1197,7 @@ class MucTab(ChatTab): nickname != self.own_nick and\ self.state != 'current': if self.state != 'highlight' and\ - config.get_by_tabname('notify_messages', 'true', self.get_name()) == 'true': + config.get_by_tabname('notify_messages', True, self.get_name()): self.state = 'message' if (not nickname or time) and not txt.startswith('/me '): txt = '\x19%(info_col)s}%(txt)s' % {'txt':txt, 'info_col': dump_tuple(get_theme().COLOR_INFORMATION_TEXT)} diff --git a/src/tabs/privatetab.py b/src/tabs/privatetab.py index 6adbf878..b1c11ae2 100644 --- a/src/tabs/privatetab.py +++ b/src/tabs/privatetab.py @@ -138,7 +138,7 @@ class PrivateTab(ChatTab): replaced = False if correct or msg['replace']['id']: msg['replace']['id'] = self.last_sent_message['id'] - if config.get_by_tabname('group_corrections', 'true', self.get_name()).lower() != 'false': + if config.get_by_tabname('group_corrections', True, self.get_name()): try: self.modify_message(msg['body'], self.last_sent_message['id'], msg['id'], user=user, jid=self.core.xmpp.boundjid, nickname=self.own_nick) @@ -152,7 +152,7 @@ class PrivateTab(ChatTab): msg.enable('html') msg['html']['body'] = xhtml.poezio_colors_to_html(msg['body']) msg['body'] = xhtml.clean_text(msg['body']) - if config.get_by_tabname('send_chat_states', 'true', self.general_jid, True) == 'true' and self.remote_wants_chatstates is not False: + if config.get_by_tabname('send_chat_states', True, self.general_jid, True) and self.remote_wants_chatstates is not False: needed = 'inactive' if self.inactive else 'active' msg['chat_state'] = needed if attention and self.remote_supports_attention: @@ -285,8 +285,8 @@ class PrivateTab(ChatTab): self.text_win.add_line_separator(self._text_buffer) tab = self.core.get_tab_by_name(safeJID(self.name).bare, MucTab) if tab and tab.joined and config.get_by_tabname( - 'send_chat_states', 'true', self.general_jid, True) == 'true'\ - and not self.input.get_text() and self.on: + 'send_chat_states', True, self.general_jid, True) and\ + not self.input.get_text() and self.on: self.send_chat_state('inactive') self.check_scrolled() @@ -295,8 +295,8 @@ class PrivateTab(ChatTab): curses.curs_set(1) tab = self.core.get_tab_by_name(safeJID(self.name).bare, MucTab) if tab and tab.joined and config.get_by_tabname( - 'send_chat_states', 'true', self.general_jid, True) == 'true'\ - and not self.input.get_text() and self.on: + 'send_chat_states', True, self.general_jid, True) and\ + not self.input.get_text() and self.on: self.send_chat_state('active') def on_info_win_size_changed(self): diff --git a/src/tabs/rostertab.py b/src/tabs/rostertab.py index 22cad8b9..199be8f7 100644 --- a/src/tabs/rostertab.py +++ b/src/tabs/rostertab.py @@ -728,10 +728,8 @@ class RosterInfoTab(Tab): Show or hide offline contacts """ option = 'roster_show_offline' - if config.get(option, 'false') == 'false': - success = config.silent_set(option, 'true') - else: - success = config.silent_set(option, 'false') + value = config.get(option, False) + success = config.silent_set(option, not value) roster.modified() if not success: self.core.information(_('Unable to write in the config file'), 'Error') diff --git a/src/text_buffer.py b/src/text_buffer.py index 2254fa62..919fbe8c 100644 --- a/src/text_buffer.py +++ b/src/text_buffer.py @@ -99,7 +99,7 @@ class TextBuffer(object): 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, history=history, highlight=highlight, timestamp=config.get("show_timestamps", "true") != 'false') + nb = window.build_new_message(msg, history=history, highlight=highlight, timestamp=config.get("show_timestamps", True)) if ret_val is None: ret_val = nb if window.pos != 0: diff --git a/src/windows.py b/src/windows.py index 7e9951a6..fd66d475 100644 --- a/src/windows.py +++ b/src/windows.py @@ -238,7 +238,7 @@ class UserList(Win): def refresh(self, users): log.debug('Refresh: %s',self.__class__.__name__) - if config.get("hide_user_list", "false") == "true": + if config.get("hide_user_list", False): return # do not refresh if this win is hidden. with g_lock: self._win.erase() @@ -336,16 +336,16 @@ class GlobalInfoBar(Win): self._win.erase() self.addstr(0, 0, "[", to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) - create_gaps = config.getl('create_gaps', 'false') == 'true' - show_names = config.getl('show_tab_names', 'false') == 'true' - show_nums = config.getl('show_tab_numbers', 'true') != 'false' - use_nicks = config.getl('use_tab_nicks', 'true') != 'false' + create_gaps = config.get('create_gaps', False) + show_names = config.get('show_tab_names', False) + show_nums = config.get('show_tab_numbers', True) + use_nicks = config.get('use_tab_nicks', True) # ignore any remaining gap tabs if the feature is not enabled sorted_tabs = [tab for tab in self.core.tabs if tab] if not create_gaps else self.core.tabs[:] for nb, tab in enumerate(sorted_tabs): if not tab: continue color = tab.color - if config.get('show_inactive_tabs', 'true') == 'false' and\ + if not config.get('show_inactive_tabs', True) and\ color is get_theme().COLOR_TAB_NORMAL: continue try: @@ -379,11 +379,11 @@ class VerticalGlobalInfoBar(Win): height, width = self._win.getmaxyx() self._win.erase() sorted_tabs = [tab for tab in self.core.tabs if tab] - if config.get('show_inactive_tabs', 'true') == 'false': + if not config.get('show_inactive_tabs', True): sorted_tabs = [tab for tab in sorted_tabs if\ tab.vertical_color != get_theme().COLOR_VERTICAL_TAB_NORMAL] nb_tabs = len(sorted_tabs) - use_nicks = config.getl('use_tab_nicks', 'true') != 'false' + use_nicks = config.get('use_tab_nicks', True) if nb_tabs >= height: for y, tab in enumerate(sorted_tabs): if tab.vertical_color == get_theme().COLOR_VERTICAL_TAB_CURRENT: @@ -926,7 +926,7 @@ class TextWin(Win): lines = self.built_lines[-self.height:] else: lines = self.built_lines[-self.height-self.pos:-self.pos] - with_timestamps = config.get("show_timestamps", 'true') != 'false' + with_timestamps = config.get("show_timestamps", True) with g_lock: self._win.move(0, 0) self._win.erase() @@ -1030,7 +1030,7 @@ class TextWin(Win): def rebuild_everything(self, room): self.built_lines = [] - with_timestamps = config.get("show_timestamps", 'true') != 'false' + with_timestamps = config.get("show_timestamps", True) for message in room.messages: self.build_new_message(message, clean=False, timestamp=with_timestamps) if self.separator_after is message: @@ -1043,7 +1043,7 @@ class TextWin(Win): Find a message, and replace it with a new one (instead of rebuilding everything in order to correct a message) """ - with_timestamps = config.get("show_timestamps", 'true') != 'false' + with_timestamps = config.get("show_timestamps", True) for i in range(len(self.built_lines)-1, -1, -1): if self.built_lines[i] and self.built_lines[i].msg.identifier == old_id: index = i @@ -1664,7 +1664,7 @@ class HistoryInput(Input): self.current_completed = '' self.key_func['^R'] = self.toggle_search self.search = False - if config.get('separate_history', 'false') == 'true': + if config.get('separate_history', False): self.history = list() def toggle_search(self): @@ -1960,7 +1960,7 @@ class RosterWin(Win): for contact in roster.get_contacts_sorted_filtered(sort): self.roster_cache.append(contact) else: - show_offline = config.get('roster_show_offline', 'false') == 'true' or roster.contact_filter + show_offline = config.get('roster_show_offline', False) or roster.contact_filter sort = config.get('roster_sort', 'jid:show') or 'jid:show' group_sort = config.get('roster_group_sort', 'name') or 'name' self.roster_cache = [] @@ -2091,7 +2091,7 @@ class RosterWin(Win): self.addstr(y, 0, ' ') self.addstr(theme.CHAR_STATUS, to_curses_attr(color)) - show_roster_sub = config.getl('show_roster_subscriptions', '') + show_roster_sub = config.get('show_roster_subscriptions', '') self.addstr(' ') if resource: @@ -2099,7 +2099,7 @@ class RosterWin(Win): added += 4 if contact.ask: added += len(get_theme().CHAR_ROSTER_ASKED) - if config.get('show_s2s_errors', 'true').lower() == 'true' and contact.error: + if config.get('show_s2s_errors', True) and contact.error: added += len(get_theme().CHAR_ROSTER_ERROR) if contact.tune: added += len(get_theme().CHAR_ROSTER_TUNE) @@ -2112,7 +2112,7 @@ class RosterWin(Win): if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both', 'none'): added += len(theme.char_subscription(contact.subscription, keep=show_roster_sub)) - if config.getl('show_roster_jids', 'true') == 'false' and contact.name: + if not config.get('show_roster_jids', True) and contact.name: display_name = '%s' % contact.name elif contact.name and contact.name != contact.bare_jid: display_name = '%s (%s)' % (contact.name, contact.bare_jid) @@ -2130,7 +2130,7 @@ class RosterWin(Win): self.addstr(theme.char_subscription(contact.subscription, keep=show_roster_sub), to_curses_attr(theme.COLOR_ROSTER_SUBSCRIPTION)) if contact.ask: self.addstr(get_theme().CHAR_ROSTER_ASKED, to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT)) - if config.get('show_s2s_errors', 'true').lower() == 'true' and contact.error: + if config.get('show_s2s_errors', True) and contact.error: self.addstr(get_theme().CHAR_ROSTER_ERROR, to_curses_attr(get_theme().COLOR_ROSTER_ERROR)) if contact.tune: self.addstr(get_theme().CHAR_ROSTER_TUNE, to_curses_attr(get_theme().COLOR_ROSTER_TUNE)) |