Skip to content
Snippets Groups Projects
Commit 100ae021 authored by Philipp Hörist's avatar Philipp Hörist
Browse files

Refactor ChatList

parent fc365a29
No related branches found
No related tags found
No related merge requests found
...@@ -44,16 +44,17 @@ class ChatListStack(Gtk.Stack): ...@@ -44,16 +44,17 @@ class ChatListStack(Gtk.Stack):
'chat-unselected': (GObject.SignalFlags.RUN_LAST, 'chat-unselected': (GObject.SignalFlags.RUN_LAST,
None, None,
()), ()),
'chat-removed': (GObject.SignalFlags.RUN_LAST,
None,
(str, str, str)),
} }
def __init__(self, main_window, ui, chat_stack): def __init__(self, main_window, search_entry):
Gtk.Stack.__init__(self) Gtk.Stack.__init__(self)
self.set_hexpand(True) self.set_hexpand(True)
self.set_vexpand(True) self.set_vexpand(True)
self.set_vhomogeneous(False) self.set_vhomogeneous(False)
self._ui = ui
self._chat_stack = chat_stack
self._chat_lists = {} self._chat_lists = {}
self._last_visible_child_name = 'default' self._last_visible_child_name = 'default'
...@@ -61,9 +62,7 @@ def __init__(self, main_window, ui, chat_stack): ...@@ -61,9 +62,7 @@ def __init__(self, main_window, ui, chat_stack):
self.add_named(Gtk.Box(), 'default') self.add_named(Gtk.Box(), 'default')
self.connect('notify::visible-child-name', self._on_visible_child_name) self.connect('notify::visible-child-name', self._on_visible_child_name)
self._ui.search_entry.connect( search_entry.connect('search-changed', self._on_search_changed)
'search-changed', self._on_search_changed)
main_window.connect('notify::is-active', self._on_window_active) main_window.connect('notify::is-active', self._on_window_active)
self._add_actions() self._add_actions()
...@@ -94,7 +93,6 @@ def _on_visible_child_name(self, _stack, _param): ...@@ -94,7 +93,6 @@ def _on_visible_child_name(self, _stack, _param):
if self._last_visible_child_name == self.get_visible_child_name(): if self._last_visible_child_name == self.get_visible_child_name():
return return
self._ui.search_entry.set_text('')
if self._last_visible_child_name != 'default': if self._last_visible_child_name != 'default':
child = self.get_child_by_name(self._last_visible_child_name) child = self.get_child_by_name(self._last_visible_child_name)
child.set_filter_text('') child.set_filter_text('')
...@@ -157,8 +155,6 @@ def show_chat_list(self, workspace_id): ...@@ -157,8 +155,6 @@ def show_chat_list(self, workspace_id):
if current_workspace_id != 'default': if current_workspace_id != 'default':
self._chat_lists[current_workspace_id].unselect_all() self._chat_lists[current_workspace_id].unselect_all()
self._ui.workspace_label.set_text(
app.settings.get_workspace_setting(workspace_id, 'name'))
self.set_visible_child_name(workspace_id) self.set_visible_child_name(workspace_id)
def add_chat(self, workspace_id, account, jid, type_, pinned=False): def add_chat(self, workspace_id, account, jid, type_, pinned=False):
...@@ -204,12 +200,7 @@ def remove_chat(self, workspace_id, account, jid): ...@@ -204,12 +200,7 @@ def remove_chat(self, workspace_id, account, jid):
type_ = chat_list.get_chat_type(account, jid) type_ = chat_list.get_chat_type(account, jid)
chat_list.remove_chat(account, jid) chat_list.remove_chat(account, jid)
self.store_open_chats(workspace_id) self.store_open_chats(workspace_id)
self.emit('chat-removed', account, jid, type_)
if not self.contains_chat(account, jid):
self._chat_stack.remove_chat(account, jid)
if type_ == 'groupchat':
client = app.get_client(account)
client.get_module('MUC').leave(jid)
def _find_chat(self, account, jid): def _find_chat(self, account, jid):
for chat_list in self._chat_lists.values(): for chat_list in self._chat_lists.values():
......
...@@ -59,10 +59,13 @@ def __init__(self): ...@@ -59,10 +59,13 @@ def __init__(self):
self._search_revealer.add(self._search_view) self._search_revealer.add(self._search_view)
self._ui.right_grid_overlay.add_overlay(self._search_revealer) self._ui.right_grid_overlay.add_overlay(self._search_revealer)
self._chat_list_stack = ChatListStack(self, self._ui, self._chat_stack) self._chat_list_stack = ChatListStack(app.window, self._ui.search_entry)
self._chat_list_stack.connect('chat-selected', self._on_chat_selected) self._chat_list_stack.connect('chat-selected', self._on_chat_selected)
self._chat_list_stack.connect('chat-unselected', self._chat_list_stack.connect('chat-unselected',
self._on_chat_unselected) self._on_chat_unselected)
self._chat_list_stack.connect('chat-removed', self._on_chat_removed)
self._chat_list_stack.connect('notify::visible-child-name',
self._on_chat_list_changed)
self._ui.chat_list_scrolled.add(self._chat_list_stack) self._ui.chat_list_scrolled.add(self._chat_list_stack)
self._ui.start_chat_button.connect('clicked', self._ui.start_chat_button.connect('clicked',
...@@ -120,6 +123,10 @@ def _on_button_release(paned, event): ...@@ -120,6 +123,10 @@ def _on_button_release(paned, event):
def _on_chat_selected(self, _chat_list_stack, workspace_id, account, jid): def _on_chat_selected(self, _chat_list_stack, workspace_id, account, jid):
self._chat_stack.show_chat(account, jid) self._chat_stack.show_chat(account, jid)
self._search_view.set_context(account, jid) self._search_view.set_context(account, jid)
self._ui.workspace_label.set_text(
app.settings.get_workspace_setting(workspace_id, 'name'))
self.emit('chat-selected', workspace_id, account, jid) self.emit('chat-selected', workspace_id, account, jid)
def _on_chat_unselected(self, _chat_list_stack): def _on_chat_unselected(self, _chat_list_stack):
...@@ -136,6 +143,9 @@ def _on_search_history(self, _action, _param): ...@@ -136,6 +143,9 @@ def _on_search_history(self, _action, _param):
def _on_search_hide(self, *args): def _on_search_hide(self, *args):
self._search_revealer.hide() self._search_revealer.hide()
def _on_chat_list_changed(self, *args):
self._ui.search_entry.set_text('')
def process_event(self, event): def process_event(self, event):
self._chat_stack.process_event(event) self._chat_stack.process_event(event)
self._chat_list_stack.process_event(event) self._chat_list_stack.process_event(event)
...@@ -219,6 +229,12 @@ def remove_chat(self, account, jid): ...@@ -219,6 +229,12 @@ def remove_chat(self, account, jid):
self._chat_list_stack.remove_chat(workspace_id, account, jid) self._chat_list_stack.remove_chat(workspace_id, account, jid)
return return
def _on_chat_removed(self, _chat_list, account, jid, type_):
self._chat_stack.remove_chat(account, jid)
if type_ == 'groupchat':
client = app.get_client(account)
client.get_module('MUC').leave(jid)
def get_control(self, account, jid): def get_control(self, account, jid):
return self._chat_stack.get_control(account, jid) return self._chat_stack.get_control(account, jid)
...@@ -230,3 +246,7 @@ def get_active_control(self): ...@@ -230,3 +246,7 @@ def get_active_control(self):
def get_controls(self, account=None): def get_controls(self, account=None):
return self._chat_stack.get_controls(account) return self._chat_stack.get_controls(account)
def hide_search(self):
if self._search_revealer.get_reveal_child():
self._search_revealer.hide()
...@@ -173,8 +173,7 @@ def _on_action(self, action, _param): ...@@ -173,8 +173,7 @@ def _on_action(self, action, _param):
return res return res
if action == 'escape': if action == 'escape':
if self._search_revealer.get_reveal_child(): self._chat_page.hide_search()
self._search_revealer.hide()
# if action == 'escape' and app.settings.get('escape_key_closes'): # if action == 'escape' and app.settings.get('escape_key_closes'):
# self.remove_tab(control, self.CLOSE_ESC) # self.remove_tab(control, self.CLOSE_ESC)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment