Merge branch 'muc-info-win-additional-info' into 'master'

Allow additional information elements in MucInfoWin same as ConversationInfoWin

See merge request poezio/poezio!17
This commit is contained in:
Maxime Buquet 2018-12-15 22:02:31 +01:00
commit 167920a9d0
2 changed files with 35 additions and 5 deletions

View file

@ -52,6 +52,7 @@ class MucTab(ChatTab):
message_type = 'groupchat' message_type = 'groupchat'
plugin_commands = {} # type: Dict[str, Command] plugin_commands = {} # type: Dict[str, Command]
plugin_keys = {} # type: Dict[str, Callable] plugin_keys = {} # type: Dict[str, Callable]
additional_information = {} # type: Dict[str, Callable[[str], str]]
def __init__(self, core, jid, nick, password=None): def __init__(self, core, jid, nick, password=None):
ChatTab.__init__(self, core, jid) ChatTab.__init__(self, core, jid)
@ -106,6 +107,20 @@ class MucTab(ChatTab):
return last_message.time return last_message.time
return None return None
@staticmethod
def add_information_element(plugin_name: str, callback: Callable[[str], str]) -> None:
"""
Lets a plugin add its own information to the MucInfoWin
"""
MucTab.additional_information[plugin_name] = callback
@staticmethod
def remove_information_element(plugin_name: str) -> None:
"""
Lets a plugin add its own information to the MucInfoWin
"""
del MucTab.additional_information[plugin_name]
def cancel_config(self, form): def cancel_config(self, form):
""" """
The user do not want to send his/her config, send an iq cancel The user do not want to send his/her config, send an iq cancel
@ -440,7 +455,9 @@ class MucTab(ChatTab):
if self.core.tabs.current_tab is self: if self.core.tabs.current_tab is self:
self.text_win.refresh() self.text_win.refresh()
self.user_win.refresh_if_changed(self.users) self.user_win.refresh_if_changed(self.users)
self.info_header.refresh(self, self.text_win, user=self.own_user) self.info_header.refresh(
self, self.text_win, user=self.own_user,
information=MucTab.additional_information)
self.input.refresh() self.input.refresh()
self.core.doupdate() self.core.doupdate()
@ -1225,7 +1242,9 @@ class MucTab(ChatTab):
if display_user_list: if display_user_list:
self.v_separator.refresh() self.v_separator.refresh()
self.user_win.refresh(self.users) self.user_win.refresh(self.users)
self.info_header.refresh(self, self.text_win, user=self.own_user) self.info_header.refresh(
self, self.text_win, user=self.own_user,
information=MucTab.additional_information)
self.refresh_tab_win() self.refresh_tab_win()
if display_info_win: if display_info_win:
self.info_win.refresh() self.info_win.refresh()

View file

@ -87,8 +87,8 @@ class PrivateInfoWin(InfoWin):
Write all information added by plugins by getting the Write all information added by plugins by getting the
value returned by the callbacks. value returned by the callbacks.
""" """
for key in information: for plugin in information.values():
self.addstr(information[key](jid), self.addstr(plugin(jid),
to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
def write_room_name(self, name): def write_room_name(self, name):
@ -257,7 +257,7 @@ class MucInfoWin(InfoWin):
def __init__(self): def __init__(self):
InfoWin.__init__(self) InfoWin.__init__(self)
def refresh(self, room, window=None, user=None): def refresh(self, room, window=None, user=None, information=None):
log.debug('Refresh: %s', self.__class__.__name__) log.debug('Refresh: %s', self.__class__.__name__)
self._win.erase() self._win.erase()
self.write_room_name(room) self.write_room_name(room)
@ -265,11 +265,22 @@ class MucInfoWin(InfoWin):
self.write_own_nick(room) self.write_own_nick(room)
self.write_disconnected(room) self.write_disconnected(room)
self.write_role(room, user) self.write_role(room, user)
if information:
self.write_additional_information(information, room)
if window: if window:
self.print_scroll_position(window) self.print_scroll_position(window)
self.finish_line(get_theme().COLOR_INFORMATION_BAR) self.finish_line(get_theme().COLOR_INFORMATION_BAR)
self._refresh() self._refresh()
def write_additional_information(self, information, jid):
"""
Write all information added by plugins by getting the
value returned by the callbacks.
"""
for plugin in information.values():
self.addstr(plugin(jid),
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
def write_room_name(self, room): def write_room_name(self, room):
self.addstr('[', to_curses_attr(get_theme().COLOR_INFORMATION_BAR)) self.addstr('[', to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
self.addstr(room.name, self.addstr(room.name,