poezio/core/core: Prepare for global config removal

Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
Maxime “pep” Buquet 2022-08-31 15:52:25 +02:00
parent 76b3f30dd4
commit 52322cf09d
Signed by: pep
GPG key ID: DEDA74AEECA9D0F2

View file

@ -133,6 +133,7 @@ class Core:
left_tab_win: Optional[windows.VerticalGlobalInfoBar]
def __init__(self, custom_version: str, firstrun: bool):
self.config = config
self.completion = CompletionCore(self)
self.command = CommandCore(self)
self.handler = HandlerCore(self)
@ -143,9 +144,9 @@ class Core:
self.connection_time = time.time()
self.last_stream_error = None
self.stdscr = None
status = config.getstr('status')
status = self.config.getstr('status')
status = POSSIBLE_SHOW.get(status) or ''
self.status = Status(show=status, message=config.getstr('status_message'))
self.status = Status(show=status, message=self.config.getstr('status_message'))
self.custom_version = custom_version
self.xmpp = connection.Connection(custom_version)
self.xmpp.core = self
@ -160,7 +161,7 @@ class Core:
# that are displayed in almost all tabs, in an
# information window.
self.information_buffer = TextBuffer()
self.information_win_size = config.getint('info_win_height', section='var')
self.information_win_size = self.config.getint('info_win_height', section='var')
# Whether the XML tab is opened
self.xml_tab = None
@ -175,7 +176,7 @@ class Core:
self.previous_tab_nb = 0
self.own_nick: str = (
config.getstr('default_nick') or self.xmpp.boundjid.user or
self.config.getstr('default_nick') or self.xmpp.boundjid.user or
os.environ.get('USER') or 'poezio_user'
)
@ -199,7 +200,7 @@ class Core:
self.register_initial_commands()
# We are invisible
if not config.get('send_initial_presence'):
if not self.config.get('send_initial_presence'):
del self.commands['status']
del self.commands['show']
@ -331,12 +332,12 @@ class Core:
for name, handler in xmpp_event_handlers:
self.xmpp.add_event_handler(name, handler)
if config.getbool('enable_avatars'):
if self.config.getbool('enable_avatars'):
self.xmpp.add_event_handler("vcard_avatar_update",
self.handler.on_vcard_avatar)
self.xmpp.add_event_handler("avatar_metadata_publish",
self.handler.on_0084_avatar)
if config.getbool('enable_user_nick'):
if self.config.getbool('enable_user_nick'):
self.xmpp.add_event_handler("user_nick_publish",
self.handler.on_nick_received)
all_stanzas = Callback('custom matcher', connection.MatchAll(None),
@ -462,14 +463,14 @@ class Core:
"""
Called when the request_message_receipts option changes
"""
self.xmpp.plugin['xep_0184'].auto_request = config.get(
self.xmpp.plugin['xep_0184'].auto_request = self.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(
self.xmpp.plugin['xep_0184'].auto_ack = self.config.get(
option, default=True)
def on_vertical_tab_list_config_change(self, option, value):
@ -515,15 +516,15 @@ class Core:
# reload the config from the disk
log.debug("Reloading the config…")
# Copy the old config in a dict
old_config = config.to_dict()
config.read_file()
old_config = self.config.to_dict()
self.config.read_file()
# Compare old and current config, to trigger the callbacks of all
# modified options
for section in config.sections():
old_section = old_config.get(section, {})
for option in config.options(section):
for option in self.config.options(section):
old_value = old_section.get(option)
new_value = config.get(option, default="", section=section)
new_value = self.config.get(option, default="", section=section)
if new_value != old_value:
self.trigger_configuration_change(option, new_value)
log.debug("Config reloaded.")
@ -564,7 +565,7 @@ class Core:
"""
Load the plugins on startup.
"""
plugins = config.getstr('plugins_autoload')
plugins = self.config.getstr('plugins_autoload')
if ':' in plugins:
for plugin in plugins.split(':'):
self.plugin_manager.load(plugin, unload_first=False)
@ -647,8 +648,10 @@ class Core:
"""
log.debug("Input is readable.")
big_char_list = [replace_key_with_bound(key)\
for key in self.read_keyboard()]
big_char_list = [
self.config.get(key, default=key, section='bindings') or key \
for key in self.read_keyboard()
]
log.debug("Got from keyboard: %s", (big_char_list, ))
# whether to refresh after ALL keys have been handled
@ -662,7 +665,7 @@ class Core:
except ValueError:
pass
else:
if self.tabs.current_tab.nb == nb and config.getbool(
if self.tabs.current_tab.nb == nb and self.config.getbool(
'go_to_previous_tab_on_alt_number'):
self.go_to_previous_tab()
else:
@ -702,7 +705,7 @@ class Core:
Save config in the file just before exit
"""
ok = roster.save_to_config_file()
ok = ok and config.silent_set('info_win_height',
ok = ok and self.config.silent_set('info_win_height',
self.information_win_size, 'var')
if not ok:
self.information(
@ -793,7 +796,7 @@ class Core:
"""
if config.getbool('exec_remote'):
# We just write the command in the fifo
fifo_path = config.getstr('remote_fifo_path')
fifo_path = self.config.getstr('remote_fifo_path')
filename = os.path.join(fifo_path, 'poezio.fifo')
if not self.remote_fifo:
try:
@ -890,9 +893,9 @@ class Core:
"""
self.status = Status(show=pres, message=msg)
if config.getbool('save_status'):
ok = config.silent_set('status', pres if pres else '')
ok = self.config.silent_set('status', pres if pres else '')
msg = msg.replace('\n', '|') if msg else ''
ok = ok and config.silent_set('status_message', msg)
ok = ok and self.config.silent_set('status_message', msg)
if not ok:
self.information(
'Unable to save the status in '
@ -1019,7 +1022,7 @@ class Core:
# Use config.default_muc_service as muc component if available,
# otherwise find muc component by disco#items-ing the user domain.
# If not, give up
default_muc = config.get('default_muc_service', muc_from_identity)
default_muc = self.config.get('default_muc_service', muc_from_identity)
if not default_muc:
self.information(
"Error finding a MUC service to join. If your server does not "
@ -1149,7 +1152,7 @@ class Core:
returns False if it could not move the tab, True otherwise
"""
return self.tabs.insert_tab(old_pos, new_pos,
config.getbool('create_gaps'))
self.config.getbool('create_gaps'))
### Move actions (e.g. go to next room) ###
@ -1418,7 +1421,7 @@ class Core:
tab.on_close()
del tab.key_func # Remove self references
del tab.commands # and make the object collectable
self.tabs.delete(tab, gap=config.getbool('create_gaps'))
self.tabs.delete(tab, gap=self.config.getbool('create_gaps'))
logger.close(tab.name)
if was_current:
self.tabs.current_tab.on_gain_focus()
@ -1450,13 +1453,13 @@ class Core:
"""
Displays an informational message in the "Info" buffer
"""
filter_types = config.getlist('information_buffer_type_filter')
filter_types = self.config.getlist('information_buffer_type_filter')
if typ.lower() in filter_types:
log.debug(
'Did not show the message:\n\t%s> %s \n\tdue to '
'information_buffer_type_filter configuration', typ, msg)
return False
filter_messages = config.getlist('filter_info_messages')
filter_messages = self.config.getlist('filter_info_messages')
for words in filter_messages:
if words and words in msg:
log.debug(
@ -1469,11 +1472,11 @@ class Core:
level=typ,
)
)
popup_on = config.getlist('information_buffer_popup_on')
popup_on = self.config.getlist('information_buffer_popup_on')
if isinstance(self.tabs.current_tab, RosterInfoTab):
self.refresh_window()
elif typ != '' and typ.lower() in popup_on:
popup_time = config.getint('popup_time') + (nb_lines - 1) * 2
popup_time = self.config.getint('popup_time') + (nb_lines - 1) * 2
self._pop_information_win_up(nb_lines, popup_time)
else:
if self.information_win_size != 0:
@ -1658,8 +1661,8 @@ class Core:
"""
Enable/disable the left panel.
"""
enabled = config.getbool('enable_vertical_tab_list')
if not config.silent_set('enable_vertical_tab_list', str(not enabled)):
enabled = self.config.getbool('enable_vertical_tab_list')
if not self.config.silent_set('enable_vertical_tab_list', str(not enabled)):
self.information('Unable to write in the config file', 'Error')
self.call_for_resize()
@ -1682,14 +1685,14 @@ class Core:
Resize the GlobalInfoBar only once at each resize
"""
height, width = self.stdscr.getmaxyx()
if config.getbool('enable_vertical_tab_list'):
if self.config.getbool('enable_vertical_tab_list'):
if self.size.core_degrade_x:
return
try:
height, _ = self.stdscr.getmaxyx()
truncated_win = self.stdscr.subwin(
height, config.getint('vertical_tab_list_size'), 0, 0)
height, self.config.getint('vertical_tab_list_size'), 0, 0)
except:
log.error('Curses error on infobar resize', exc_info=True)
return
@ -1717,12 +1720,12 @@ class Core:
if self.stdscr is None:
raise ValueError('No output available')
height, width = self.stdscr.getmaxyx()
if (config.getbool('enable_vertical_tab_list')
if (self.config.getbool('enable_vertical_tab_list')
and not self.size.core_degrade_x):
try:
scr = self.stdscr.subwin(
0,
config.getint('vertical_tab_list_size')
self.config.getint('vertical_tab_list_size')
)
except:
log.error('Curses error on resize', exc_info=True)
@ -1734,7 +1737,7 @@ class Core:
self.resize_global_information_win(ui_config_changed)
for tab in self.tabs:
tab.ui_config_changed = True
if config.getbool('lazy_resize'):
if self.config.getbool('lazy_resize'):
tab.need_resize = True
else:
tab.resize()
@ -1802,7 +1805,7 @@ class Core:
def join_initial_rooms(self, bookmarks: List[Bookmark]):
"""Join all rooms given in the iterator `bookmarks`"""
for bm in bookmarks:
if not (bm.autojoin or config.getbool('open_all_bookmarks')):
if not (bm.autojoin or self.config.getbool('open_all_bookmarks')):
continue
tab = self.tabs.by_name_and_class(bm.jid, MucTab)
nick = bm.nick if bm.nick else self.own_nick
@ -1821,7 +1824,7 @@ class Core:
self.bookmarks.available_storage['private'] = private
self.bookmarks.available_storage['pep'] = pep_
if not self.xmpp.anon and config.getbool('use_remote_bookmarks'):
if not self.xmpp.anon and self.config.getbool('use_remote_bookmarks'):
try:
await self.bookmarks.get_remote(self.xmpp, self.information)
except IqError as error:
@ -1854,9 +1857,9 @@ class Core:
msg = 'To provide a password in order to join the room, type "/join / password" (replace "password" by the real password)'
tab.add_message(PersistentInfoMessage(msg))
if code == '409':
if config.getstr('alternative_nickname') != '':
if self.config.getstr('alternative_nickname') != '':
if not tab.joined:
tab.own_nick += config.getstr('alternative_nickname')
tab.own_nick += self.config.getstr('alternative_nickname')
tab.join()
else:
if not tab.joined: