Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits: 480fd92d by lovetox at 2021-01-23T08:16:03+01:00 Store chatlist on remove
- - - - -
4 changed files:
- gajim/gtk/chat_list.py - gajim/gtk/chat_list_stack.py - gajim/gtk/chat_stack.py - gajim/gtk/main.py
Changes:
===================================== gajim/gtk/chat_list.py ===================================== @@ -4,6 +4,7 @@ from gi.repository import Gdk from gi.repository import Gtk from gi.repository import Pango +from gi.repository import GObject
from gajim.common import app from gajim.common.const import AvatarSize @@ -17,11 +18,17 @@
class ChatList(Gtk.ListBox): - def __init__(self, ui, chat_stack): + + __gsignals__ = { + 'chat-closed': ( + GObject.SignalFlags.RUN_LAST, + None, + (Gtk.ListBoxRow,) + )} + + def __init__(self): Gtk.ListBox.__init__(self)
- self._ui = ui - self._chat_stack = chat_stack self._chats = {} self._current_filter_text = '' self.set_size_request(250, -1) @@ -29,7 +36,6 @@ def __init__(self, ui, chat_stack): self.show_all()
self.set_filter_func(self._filter_func) - self.connect('row-selected', self._on_row_selected)
def _filter_func(self, row): if not self._current_filter_text: @@ -41,10 +47,9 @@ def set_filter_text(self, text): self.invalidate_filter()
def add_chat(self, account, jid): - for _row_account, row_jid in self.get_open_chats(): - if row_jid == jid: - self.select_chat(account, jid) - return + if self._chats.get((account, jid)) is not None: + # Chat is already in the List + return
row = ChatRow(account, jid) self._chats[(account, jid)] = row @@ -59,11 +64,8 @@ def remove_chat(self, account, jid): self.remove(row) row.destroy()
- def _on_row_selected(self, _listbox, row): - if row is None: - self._chat_stack.clear() - return - self._chat_stack.show_chat(row.account, row.jid) + def contains_chat(self, account, jid): + return self._chats.get((account, jid)) is not None
def get_open_chats(self): return list(self._chats.keys()) @@ -199,7 +201,7 @@ def _on_state_flags_changed(self, _listboxrow, *args): self._revealer.set_reveal_child(False)
def _on_close_button_clicked(self, _button): - self.get_parent().remove_chat(self.account, self.jid) + self.get_parent().emit('chat-closed', self)
def set_unread(self, count): log.info('Set unread count: %s (%s)', self.jid, count)
===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -32,11 +32,23 @@ def _on_search_changed(self, search_entry): chat_list.set_filter_text(search_entry.get_text())
def add_chat_list(self, workspace_id): - chat_list = ChatList(self._ui, self._chat_stack) + chat_list = ChatList() + chat_list.connect('row-selected', self._on_row_selected) + chat_list.connect('chat-closed', self._on_chat_closed, workspace_id) + self._chat_lists[workspace_id] = chat_list self.add_named(chat_list, workspace_id) return chat_list
+ def _on_row_selected(self, _chat_list, row): + if row is None: + self._chat_stack.clear() + return + self._chat_stack.show_chat(row.account, row.jid) + + def _on_chat_closed(self, _chat_list, row, workspace_id): + self.remove_chat(workspace_id, row.account, row.jid) + def show_chat_list(self, workspace_id): self.set_visible_child_name(workspace_id)
@@ -60,3 +72,13 @@ def store_open_chats(self, workspace_id): def remove_chat(self, workspace_id, account, jid): chat_list = self._chat_lists[workspace_id] chat_list.remove_chat(account, jid) + self.store_open_chats(workspace_id) + + if self._find_chat(account, jid) is None: + self._chat_stack.remove_chat(account, jid) + + def _find_chat(self, account, jid): + for chat_list in self._chat_lists.values(): + if chat_list.contains_chat(account, jid): + return chat_list + return None
===================================== gajim/gtk/chat_stack.py ===================================== @@ -17,26 +17,30 @@ def __init__(self): self.add_named(Gtk.Box(), 'empty')
self.show_all() - self._controls = defaultdict(dict) + self._controls = {}
def get_control(self, account, jid): try: - return self._controls[account][jid] + return self._controls[(account, jid)] except KeyError: return None
def add_chat(self, account, jid): + if self._controls.get((account, jid)) is not None: + # Control is already in the Stack + return + mw = self.get_toplevel() contact = app.contacts.create_contact(jid, account) chat_control = ChatControl(mw, contact, account, None, None) - self._controls[account][jid] = chat_control + self._controls[(account, jid)] = chat_control self.add_named(chat_control.widget, f'{account}:{jid}') chat_control.widget.show_all()
def remove_chat(self, account, jid): - control = self._controls[account].pop(jid) + control = self._controls.pop((account, jid)) + self.remove(control.widget) control.shutdown() - self.remove(control)
def show_chat(self, account, jid): self.set_visible_child_name(f'{account}:{jid}')
===================================== gajim/gtk/main.py ===================================== @@ -80,9 +80,7 @@ def add_chat_for_workspace(self, workspace_id, account, jid): self._chat_list_stack.store_open_chats(workspace_id)
def remove_chat(self, workspace_id, account, jid): - self._chat_stack.remove_chat(account, jid) self._chat_list_stack.remove_chat(workspace_id, account, jid) - self._chat_list_stack.store_open_chats(workspace_id)
def get_control(self, account, jid): return self._chat_stack.get_control(account, jid)
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/480fd92d7bc93418e90f8fcdd11147d7c...