diff --git a/briar-gtk/briar_gtk/actions/window.py b/briar-gtk/briar_gtk/actions/window.py index 58e071d70641bffe10b1141e832a9e9550089818..d2beb9b5f49b6cb8df496a0609ad6559de027ce1 100644 --- a/briar-gtk/briar_gtk/actions/window.py +++ b/briar-gtk/briar_gtk/actions/window.py @@ -10,8 +10,8 @@ from gi.repository import GLib from briar_gtk.actions.actions import Actions from briar_gtk.actions.prefixes import WINDOW_PREFIX -from briar_gtk.presenters.main_window import MainWindowPresenter from briar_gtk.define import APP +from briar_gtk.views.main_window import MainWindowView class WindowActions(Actions): @@ -64,25 +64,33 @@ class WindowActions(Actions): # pylint: disable=unused-argument def _back_to_sidebar(self, action, parameter): - if isinstance(self.widget.main_window_presenter, - MainWindowPresenter): - self.widget.main_window_presenter.close_private_chat() + if not isinstance(self.widget.current_view, MainWindowView): + return # No Exception thrown because shortcut may come from other view + self.widget.current_view.presenter.close_private_chat() # pylint: disable=unused-argument def _delete_all_messages_dialog(self, action, parameter): - self.widget.main_window_presenter.open_delete_all_messages_dialog() + if not isinstance(self.widget.current_view, MainWindowView): + raise Exception("Should delete all messages only from MainWindowView") + self.widget.current_view.presenter.open_delete_all_messages_dialog() # pylint: disable=unused-argument def _delete_contact_dialog(self, action, parameter): - self.widget.main_window_presenter.open_delete_contact_dialog() + if not isinstance(self.widget.current_view, MainWindowView): + raise Exception("Should delete contact only from MainWindowView") + self.widget.current_view.presenter.open_delete_contact_dialog() # pylint: disable=unused-argument def _change_alias_contact_dialog(self, action, parameter): - self.widget.main_window_presenter.open_change_contact_alias_dialog() + if not isinstance(self.widget.current_view, MainWindowView): + raise Exception("Should change alias only from MainWindowView") + self.widget.current_view.presenter.open_change_contact_alias_dialog() # pylint: disable=unused-argument def _open_about_page(self, action, parameter): - self.widget.main_window_presenter.open_about_page() + if not isinstance(self.widget.current_view, MainWindowView): + raise Exception("Should open about page only from MainWindowView") + self.widget.current_view.presenter.open_about_page() # pylint: disable=unused-argument def _open_add_contact(self, action, parameter): @@ -94,5 +102,6 @@ class WindowActions(Actions): # pylint: disable=unused-argument def _open_private_chat(self, action, contact_id): - self.widget.main_window_presenter.open_private_chat( - contact_id.get_int32()) + if not isinstance(self.widget.current_view, MainWindowView): + raise Exception("Should open private chat only from MainWindowView") + self.widget.current_view.presenter.open_private_chat(contact_id.get_int32()) diff --git a/briar-gtk/briar_gtk/views/add_contact.py b/briar-gtk/briar_gtk/views/add_contact.py index 5e6cfb4e33d47d8273740314feeb02ae847a628e..063a36c629efdd25d64ed769b33b656b987c5983 100644 --- a/briar-gtk/briar_gtk/views/add_contact.py +++ b/briar-gtk/briar_gtk/views/add_contact.py @@ -26,6 +26,7 @@ class AddContactView(Gtk.Overlay): AddContactActions(self) self._setup_view() self._load_content() + self.show_all() @property def alias_entry(self): diff --git a/briar-gtk/briar_gtk/views/main_window.py b/briar-gtk/briar_gtk/views/main_window.py index 8ee40405b406c720cb7c0cddb74e346c14e607db..3a46d6ddc08109073c5e8fa0ae64cf9cf9217467 100644 --- a/briar-gtk/briar_gtk/views/main_window.py +++ b/briar-gtk/briar_gtk/views/main_window.py @@ -5,14 +5,37 @@ # Initial version based on GNOME Fractal # https://gitlab.gnome.org/GNOME/fractal/-/tags/4.2.2 +import os + from gi.repository import Gtk +from briar_gtk.define import RESOURCES_DIR +from briar_gtk.presenters.main_window import MainWindowPresenter + class MainWindowView(Gtk.Overlay): - def __init__(self, builder, window): + def __init__(self, window): super().__init__() + builder = self._setup_builder() + self.presenter = MainWindowPresenter(self, builder) self._setup_view(builder, window) + self.show_all() + builder.get_object("chat_menu_button").hide() # TODO: Make default + + def _setup_builder(self): + builder = Gtk.Builder.new() + builder.add_from_resource( + os.path.join(RESOURCES_DIR, "main_menu.ui") + ) + builder.add_from_resource( + os.path.join(RESOURCES_DIR, "chat_menu.ui") + ) + builder.add_from_resource( + os.path.join(RESOURCES_DIR, "main_window.ui") + ) + builder.connect_signals(self) + return builder def _setup_view(self, builder, window): self._setup_main_window_stack(builder) diff --git a/briar-gtk/briar_gtk/views/private_chat.py b/briar-gtk/briar_gtk/views/private_chat.py index 27ec4aed665864e79b5269dc8e7acd6d8b8c7062..5833b26739802c497cd84fe3e465773a460e5208 100644 --- a/briar-gtk/briar_gtk/views/private_chat.py +++ b/briar-gtk/briar_gtk/views/private_chat.py @@ -36,6 +36,7 @@ class PrivateChatView(Gtk.Overlay): private_chat = PrivateChat(APP().api, self._contact_id) private_chat.send(message) + # TODO: Doesn't work after Ctrl + W self._add_message( { "text": message, diff --git a/briar-gtk/briar_gtk/views/startup.py b/briar-gtk/briar_gtk/views/startup.py index 264ef2a92008f6b736d5e226d314b7a912a08dd3..958e523ab8a39513d03a102de60515675ad441ee 100644 --- a/briar-gtk/briar_gtk/views/startup.py +++ b/briar-gtk/briar_gtk/views/startup.py @@ -14,6 +14,7 @@ class StartupView(Gtk.Overlay): def __init__(self, window): super().__init__() self._setup_view(window) + self.show_all() def _setup_view(self, window): container = RegistrationView(window) diff --git a/briar-gtk/briar_gtk/window.py b/briar-gtk/briar_gtk/window.py index cd4fa4ded5cb37a80842a24175bba859100fd43a..6401f152c7dd3f133d59cb7aacac1363f5ed4afa 100644 --- a/briar-gtk/briar_gtk/window.py +++ b/briar-gtk/briar_gtk/window.py @@ -9,12 +9,11 @@ from gi.repository import Gio, Gtk from briar_gtk.actions.window import WindowActions from briar_gtk.views.add_contact import AddContactView -from briar_gtk.presenters.main_window import MainWindowPresenter from briar_gtk.views.main_window import MainWindowView from briar_gtk.views.startup import StartupView from briar_gtk.define import APP, APPLICATION_ID, APPLICATION_NAME from briar_gtk.define import NOTIFICATION_CONTACT_ADDED -from briar_gtk.define import NOTIFICATION_PRIVATE_MESSAGE, RESOURCES_DIR +from briar_gtk.define import NOTIFICATION_PRIVATE_MESSAGE class Window(Gtk.ApplicationWindow): @@ -22,20 +21,16 @@ class Window(Gtk.ApplicationWindow): DEFAULT_WINDOW_SIZE = (900, 600) def __init__(self): - self.main_window_presenter = None + self.current_view = None self._initialize_gtk_application_window() WindowActions(self) self._setup_content() self._setup_focus_listener() def show_main_window_view(self): - self._current_view.destroy() self._setup_main_window_view() def show_add_contact_view(self): - self._current_view.destroy() - if self.main_window_presenter is not None: - self.main_window_presenter = None self._setup_add_contact_view() # pylint: disable=arguments-differ,unused-argument @@ -97,34 +92,16 @@ class Window(Gtk.ApplicationWindow): isinstance(size[1], int) def _setup_view(self, view): - self._current_view = view - self._current_view.show_all() - self.add(self._current_view) + if isinstance(self.current_view, Gtk.Overlay): + self.current_view.destroy() + self.current_view = view + self.add(self.current_view) def _setup_startup_view(self): self._setup_view(StartupView(self)) def _setup_main_window_view(self): - builder = self._setup_builder() - main_window_view = MainWindowView(builder, self) - self.main_window_presenter = MainWindowPresenter( - main_window_view, builder) - self._setup_view(main_window_view) - builder.get_object("chat_menu_button").hide() # TODO: Make default + self._setup_view(MainWindowView(self)) def _setup_add_contact_view(self): self._setup_view(AddContactView()) - - def _setup_builder(self): - builder = Gtk.Builder.new() - builder.add_from_resource( - os.path.join(RESOURCES_DIR, "main_menu.ui") - ) - builder.add_from_resource( - os.path.join(RESOURCES_DIR, "chat_menu.ui") - ) - builder.add_from_resource( - os.path.join(RESOURCES_DIR, "main_window.ui") - ) - builder.connect_signals(self) - return builder diff --git a/briar-gtk/tests/briar_gtk/test_window.py b/briar-gtk/tests/briar_gtk/test_window.py index 821c9b77e421de9af104db2613a85e71d872c117..e6c40da4b398bed1f32c8e171f0a418c458a6ef3 100644 --- a/briar-gtk/tests/briar_gtk/test_window.py +++ b/briar-gtk/tests/briar_gtk/test_window.py @@ -21,7 +21,7 @@ def test_startup_container_at_init(mocker, startup_container, window_actions, window = Window() startup_container.assert_called_once_with(window) - window._current_view.show_all.assert_called_once() + window.current_view.show_all.assert_called_once() def test_window_actions_at_init(mocker, startup_container, window_actions, @@ -35,7 +35,7 @@ def test_window_add_at_init(mocker, startup_container, window_actions, window_add, window_resize): window = Window() - window_add.assert_called_once_with(window._current_view) + window_add.assert_called_once_with(window.current_view) def test_show_main_container(main_window_container, mocker, @@ -53,7 +53,7 @@ def test_show_main_shown(main_window_container, mocker, window.show_main_window_view() - window._current_view.show_all.assert_called_once() + window.current_view.show_all.assert_called_once() def test_show_main_add(main_window_container, mocker, @@ -64,7 +64,7 @@ def test_show_main_add(main_window_container, mocker, window.show_main_window_view() - window_add.assert_called_once_with(window._current_view) + window_add.assert_called_once_with(window.current_view) def test_show_main_destroy_old(main_window_container, mocker, @@ -72,7 +72,7 @@ def test_show_main_destroy_old(main_window_container, mocker, window_add, window_resize): window = Window() current_container_mock = mocker.MagicMock() - window._current_view = current_container_mock + window.current_view = current_container_mock window.show_main_window_view()