diff --git a/src/chat_control.py b/src/chat_control.py index d9607c4b5..9c491b9e1 100644 --- a/src/chat_control.py +++ b/src/chat_control.py @@ -1430,12 +1430,14 @@ class ChatControl(ChatControlBase): self._convert_to_gc_button.set_sensitive(False) def update_all_pep_types(self): - for pep_type in ('tune', 'mood', 'activity'): + for pep_type in self._pep_images: self.update_pep(pep_type) def update_pep(self, pep_type): if isinstance(self.contact, GC_Contact): return + if pep_type not in self._pep_images: + return pep = self.contact.pep img = self._pep_images[pep_type] if pep_type in pep: diff --git a/src/common/pep.py b/src/common/pep.py index e0394ce61..85e72d8ea 100644 --- a/src/common/pep.py +++ b/src/common/pep.py @@ -584,9 +584,7 @@ def delete_pep(jid, name): if jid == common.gajim.get_jid_from_account(name): common.gajim.interface.roster.draw_account(name) - common.gajim.interface.roster.draw_activity(user, name) - common.gajim.interface.roster.draw_tune(user, name) - common.gajim.interface.roster.draw_mood(user, name) + common.gajim.interface.roster.draw_all_pep_types(jid, name) ctrl = common.gajim.interface.msg_win_mgr.get_control(user, name) if ctrl: ctrl.update_all_pep_types() diff --git a/src/gui_interface.py b/src/gui_interface.py index ec093b03b..f33e769e3 100644 --- a/src/gui_interface.py +++ b/src/gui_interface.py @@ -1998,25 +1998,17 @@ class Interface: if jid == common.gajim.get_jid_from_account(account): self.roster.draw_account(account) - if pep_type == 'mood': - self.roster.draw_mood(jid, account) - if ctrl: - ctrl.update_pep(pep_type) - elif pep_type == 'tune': - self.roster.draw_tune(jid, account) - if ctrl: - ctrl.update_pep(pep_type) - elif pep_type == 'activity': - self.roster.draw_activity(jid, account) - if ctrl: - ctrl.update_pep(pep_type) - elif pep_type == 'nickname': + if pep_type == 'nickname': self.roster.draw_contact(jid, account) if ctrl: ctrl.update_ui() win = ctrl.parent_win win.redraw_tab(ctrl) win.show_title() + else: + self.roster.draw_pep(jid, account, pep_type) + if ctrl: + ctrl.update_pep(pep_type) def register_handler(self, event, handler): if event not in self.handlers: diff --git a/src/roster_window.py b/src/roster_window.py index 046684b57..2745a3365 100644 --- a/src/roster_window.py +++ b/src/roster_window.py @@ -1242,19 +1242,27 @@ class RosterWindow: return False - def draw_mood(self, jid, account): - if gajim.config.get('show_mood_in_roster'): - self._draw_pep(jid, account, 'mood', C_MOOD_PIXBUF) - - def draw_activity(self, jid, account): - if gajim.config.get('show_activity_in_roster'): - self._draw_pep(jid, account, 'activity', C_ACTIVITY_PIXBUF) - - def draw_tune(self, jid, account): - if gajim.config.get('show_tunes_in_roster'): - self._draw_pep(jid, account, 'tune', C_TUNE_PIXBUF) + def _is_pep_shown_in_roster(self, pep_type): + if pep_type == 'mood': + return gajim.config.get('show_mood_in_roster') + elif pep_type == 'activity': + return gajim.config.get('show_activity_in_roster') + elif pep_type == 'tune': + return gajim.config.get('show_tunes_in_roster') + else: + return False + + def draw_all_pep_types(self, jid, account): + for pep_type in self._pep_type_to_model_column: + self.draw_pep(jid, account, pep_type) - def _draw_pep(self, jid, account, pep_type, model_column): + def draw_pep(self, jid, account, pep_type): + if pep_type not in self._pep_type_to_model_column: + return + if not self._is_pep_shown_in_roster(pep_type): + return + + model_column = self._pep_type_to_model_column[pep_type] iters = self._get_contact_iter(jid, account, model=self.model) if not iters: return @@ -1285,9 +1293,7 @@ class RosterWindow: def draw_completely(self, jid, account): self.draw_contact(jid, account) - self.draw_mood(jid, account) - self.draw_activity(jid, account) - self.draw_tune(jid, account) + self.draw_all_pep_types(jid, account) self.draw_avatar(jid, account) def adjust_and_draw_contact_context(self, jid, account): @@ -5753,6 +5759,10 @@ class RosterWindow: col.add_attribute(render_pixbuf, 'pixbuf', C_TUNE_PIXBUF) col.set_cell_data_func(render_pixbuf, self._fill_pep_pixbuf_renderer, C_TUNE_PIXBUF) + + self._pep_type_to_model_column = {'mood': C_MOOD_PIXBUF, + 'activity': C_ACTIVITY_PIXBUF, + 'tune': C_ACTIVITY_PIXBUF} if gajim.config.get('avatar_position_in_roster') == 'right': add_avatar_renderer()