Philipp Hörist pushed to branch mainwindow at gajim / gajim
Commits: 69416bf4 by lovetox at 2021-02-06T10:37:49+01:00 Dont allow chats to be opened multiple times
- - - - -
6 changed files:
- gajim/gtk/chat_list.py - gajim/gtk/chat_list_stack.py - gajim/gtk/main.py - gajim/gtk/start_chat.py - gajim/gtk/workspace_side_bar.py - gajim/gui_interface.py
Changes:
===================================== gajim/gtk/chat_list.py ===================================== @@ -37,6 +37,10 @@ def __init__(self, workspace_id):
self.show_all()
+ @property + def workspace_id(self): + return self._workspace_id + def get_unread_count(self): return sum([chats.unread_count for chats in self._chats.values()])
===================================== gajim/gtk/chat_list_stack.py ===================================== @@ -20,6 +20,9 @@ class ChatListStack(Gtk.Stack): 'unread-count-changed': (GObject.SignalFlags.RUN_LAST, None, (str, int)), + 'chat-selected': (GObject.SignalFlags.RUN_LAST, + None, + (str, str, str)), }
def __init__(self, main_window, ui, chat_stack): @@ -92,6 +95,7 @@ def _on_row_selected(self, _chat_list, row): self._chat_stack.show_chat(row.account, row.jid) if row.is_active: row.reset_unread() + self.emit('chat-selected', row.workspace_id, row.account, row.jid)
def show_chat_list(self, workspace_id): current_workspace_id = self.get_visible_child_name() @@ -111,9 +115,12 @@ def add_chat(self, workspace_id, account, jid, type_): chat_list = self.add_chat_list(workspace_id) chat_list.add_chat(account, jid, type_)
- def select_chat(self, workspace_id, account, jid): - self.show_chat_list(workspace_id) - chat_list = self._chat_lists.get(workspace_id) + def select_chat(self, account, jid): + chat_list = self._find_chat(account, jid) + if chat_list is None: + return + + self.show_chat_list(chat_list.workspace_id) chat_list.select_chat(account, jid)
def store_open_chats(self, workspace_id):
===================================== gajim/gtk/main.py ===================================== @@ -205,19 +205,38 @@ def _add_group_chat(self, _action, param): account, jid = param.unpack() self.add_group_chat(account, jid)
- def add_group_chat(self, account, jid): + def add_group_chat(self, account, jid, select=False): workspace_id = self._workspace_side_bar.get_active_workspace() - self.add_chat_for_workspace(workspace_id, account, jid, 'groupchat') + self.add_chat_for_workspace(workspace_id, + account, + jid, + 'groupchat', + select=select)
def _add_chat(self, _action, param): account, jid, type_ = param.unpack() self.add_chat(account, jid, type_)
- def add_chat(self, account, jid, type_): + def add_chat(self, account, jid, type_, select=False): workspace_id = self._workspace_side_bar.get_active_workspace() - self.add_chat_for_workspace(workspace_id, account, jid, type_) + self.add_chat_for_workspace(workspace_id, + account, + jid, + type_, + select=select) + + def add_chat_for_workspace(self, + workspace_id, + account, + jid, + type_, + select=False): + + if self.chat_exists(account, jid): + if select: + self._chat_list_stack.select_chat(account, jid) + return
- def add_chat_for_workspace(self, workspace_id, account, jid, type_): if type_ == 'groupchat': self._chat_stack.add_group_chat(account, jid) else: @@ -225,7 +244,8 @@ def add_chat_for_workspace(self, workspace_id, account, jid, type_): self._chat_list_stack.add_chat(workspace_id, account, jid, type_)
if self._startup_finished: - self._chat_list_stack.select_chat(workspace_id, account, jid) + if select: + self._chat_list_stack.select_chat(account, jid) self._chat_list_stack.store_open_chats(workspace_id)
def _remove_chat(self, _action, param): @@ -242,10 +262,6 @@ def chat_exists_for_workspace(self, workspace_id, account, jid): return self._chat_list_stack.contains_chat( account, jid, workspace_id=workspace_id)
- def select_chat(self, workspace_id, account, jid): - self._workspace_side_bar.activate_workspace(workspace_id) - self._chat_list_stack.select_chat(workspace_id, account, jid) - def get_control(self, account, jid): return self._chat_stack.get_control(account, jid)
===================================== gajim/gtk/start_chat.py ===================================== @@ -295,8 +295,7 @@ def _start_new_chat(self, row): self._disco_muc(row.account, row.jid, request_vcard=row.new)
else: - # app.interface.new_chat_from_jid(row.account, row.jid) - app.window.add_chat(row.account, row.jid, 'contact') + app.window.add_chat(row.account, row.jid, 'contact', select=True) self.ready_to_destroy = True self.destroy()
===================================== gajim/gtk/workspace_side_bar.py ===================================== @@ -22,12 +22,17 @@ def __init__(self, chat_list_stack):
chat_list_stack.connect('unread-count-changed', self._on_unread_count_changed) + chat_list_stack.connect('chat-selected', + self._on_chat_selected) self._workspaces = {}
def _on_unread_count_changed(self, _chat_list_stack, workspace_id, count): workspace = self._workspaces[workspace_id] workspace.set_unread_count(count)
+ def _on_chat_selected(self, _chat_list_stack, workspace_id, *args): + self.activate_workspace(workspace_id) + @staticmethod def _sort_func(child1, child2): if child1.sort_index < child2.sort_index:
===================================== gajim/gui_interface.py ===================================== @@ -1469,16 +1469,11 @@ def create_groupchat(self, account, room_jid, config=None): app.connections[account].get_module('MUC').create(muc_data)
def show_add_join_groupchat(self, account, jid, nickname=None): - workspace_id = app.window.get_active_workspace() - if app.window.chat_exists_for_workspace(workspace_id, account, jid): - app.window.select_chat(workspace_id, account, jid) - return - if not app.window.chat_exists(account, jid): client = app.get_client(account) client.get_module('MUC').join(jid, nick=nickname)
- app.window.add_group_chat(account, str(jid)) + app.window.add_group_chat(account, str(jid), select=True)
@staticmethod def _on_muc_added(_muc_manger, _signal_name, account, jid):
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/69416bf47c898e2661687870430e16c13...