From c9740f3aadb2588584e0a891f26f642fda55a8f3 Mon Sep 17 00:00:00 2001
From: Nico Alt <nicoalt@posteo.org>
Date: Thu, 17 Dec 2020 21:05:49 +0100
Subject: [PATCH] Use name view instead of container in Window

---
 briar-gtk/briar_gtk/actions/window.py     | 18 +++++-----
 briar-gtk/briar_gtk/views/add_contact.py  |  2 +-
 briar-gtk/briar_gtk/views/login.py        |  2 +-
 briar-gtk/briar_gtk/views/registration.py |  2 +-
 briar-gtk/briar_gtk/window.py             | 40 ++++++++++++-----------
 briar-gtk/tests/briar_gtk/test_window.py  | 18 +++++-----
 6 files changed, 42 insertions(+), 40 deletions(-)

diff --git a/briar-gtk/briar_gtk/actions/window.py b/briar-gtk/briar_gtk/actions/window.py
index 10e2e49..c6908c4 100644
--- a/briar-gtk/briar_gtk/actions/window.py
+++ b/briar-gtk/briar_gtk/actions/window.py
@@ -64,34 +64,34 @@ class WindowActions(Actions):
 
     # pylint: disable=unused-argument
     def _back_to_sidebar(self, action, parameter):
-        if isinstance(self.widget.current_controller, MainWindowController):
-            self.widget.current_controller.close_private_chat()
+        if isinstance(self.widget.main_window_controller, MainWindowController):
+            self.widget.main_window_controller.close_private_chat()
 
     # pylint: disable=unused-argument
     def _delete_all_messages_dialog(self, action, parameter):
-        self.widget.current_controller.open_delete_all_messages_dialog()
+        self.widget.main_window_controller.open_delete_all_messages_dialog()
 
     # pylint: disable=unused-argument
     def _delete_contact_dialog(self, action, parameter):
-        self.widget.current_controller.open_delete_contact_dialog()
+        self.widget.main_window_controller.open_delete_contact_dialog()
 
     # pylint: disable=unused-argument
     def _change_alias_contact_dialog(self, action, parameter):
-        self.widget.current_controller.open_change_contact_alias_dialog()
+        self.widget.main_window_controller.open_change_contact_alias_dialog()
 
     # pylint: disable=unused-argument
     def _open_about_page(self, action, parameter):
-        self.widget.current_controller.open_about_page()
+        self.widget.main_window_controller.open_about_page()
 
     # pylint: disable=unused-argument
     def _open_add_contact(self, action, parameter):
-        self.widget.show_add_contact_container()
+        self.widget.show_add_contact_view()
 
     # pylint: disable=unused-argument
     def _open_main_window(self, action, parameter):
-        self.widget.show_main_container()
+        self.widget.show_main_window_view()
 
     # pylint: disable=unused-argument
     def _open_private_chat(self, action, contact_id):
-        self.widget.current_controller.open_private_chat(
+        self.widget.main_window_controller.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 8486f4f..f4cce01 100644
--- a/briar-gtk/briar_gtk/views/add_contact.py
+++ b/briar-gtk/briar_gtk/views/add_contact.py
@@ -63,7 +63,7 @@ class AddContactView(Gtk.Overlay):
             return
         alias_error_label.hide()
         self._add_contact()
-        APP().window.show_main_container()
+        APP().window.show_main_window_view()
 
     def _setup_view(self):
         self._add_from_resource(self.ADD_CONTACT_UI)
diff --git a/briar-gtk/briar_gtk/views/login.py b/briar-gtk/briar_gtk/views/login.py
index 94b5c98..980bf9f 100644
--- a/briar-gtk/briar_gtk/views/login.py
+++ b/briar-gtk/briar_gtk/views/login.py
@@ -80,7 +80,7 @@ class LoginView(Gtk.Overlay):
     def _login_completed(self, succeeded):
         function = self._login_failed
         if succeeded:
-            function = self._window.show_main_container
+            function = self._window.show_main_window_view
         GLib.idle_add(function)
 
     def _login_failed(self):
diff --git a/briar-gtk/briar_gtk/views/registration.py b/briar-gtk/briar_gtk/views/registration.py
index b9f4208..63aa300 100644
--- a/briar-gtk/briar_gtk/views/registration.py
+++ b/briar-gtk/briar_gtk/views/registration.py
@@ -142,7 +142,7 @@ class RegistrationView(Gtk.Overlay):
     def _registration_completed(self, succeeded):
         function = self._registration_failed
         if succeeded:
-            function = self._window.show_main_container
+            function = self._window.show_main_window_view
         GLib.idle_add(function)
 
     def _registration_failed(self):
diff --git a/briar-gtk/briar_gtk/window.py b/briar-gtk/briar_gtk/window.py
index 776aba6..3358249 100644
--- a/briar-gtk/briar_gtk/window.py
+++ b/briar-gtk/briar_gtk/window.py
@@ -22,18 +22,21 @@ class Window(Gtk.ApplicationWindow):
     DEFAULT_WINDOW_SIZE = (900, 600)
 
     def __init__(self):
+        self.main_window_controller = None
         self._initialize_gtk_application_window()
         WindowActions(self)
         self._setup_content()
         self._setup_focus_listener()
 
-    def show_main_container(self):
-        self.current_container.destroy()
-        self._setup_main_container()
+    def show_main_window_view(self):
+        self._current_view.destroy()
+        self._setup_main_window_view()
 
-    def show_add_contact_container(self):
-        self.current_container.destroy()
-        self._setup_add_contact_container()
+    def show_add_contact_view(self):
+        self._current_view.destroy()
+        if self.main_window_controller is not None:
+            self.main_window_controller = None
+        self._setup_add_contact_view()
 
     # pylint: disable=arguments-differ,unused-argument
     def do_delete_event(self, event):
@@ -70,7 +73,7 @@ class Window(Gtk.ApplicationWindow):
 
     def _setup_content(self):
         self._resize_window(self.DEFAULT_WINDOW_SIZE)
-        self._setup_startup_container()
+        self._setup_startup_view()
 
     def _setup_focus_listener(self):
         self.connect("focus-in-event", self._on_focus_change)
@@ -93,25 +96,24 @@ class Window(Gtk.ApplicationWindow):
                isinstance(size[0], int) and\
                isinstance(size[1], int)
 
-    def _setup_container(self, container):
-        self.current_container = container
-        self.current_container.show_all()
-        self.add(self.current_container)
+    def _setup_view(self, view):
+        self._current_view = view
+        self._current_view.show_all()
+        self.add(self._current_view)
 
-    def _setup_startup_container(self):
-        self._setup_container(StartupView(self))
+    def _setup_startup_view(self):
+        self._setup_view(StartupView(self))
 
-    def _setup_main_container(self):
+    def _setup_main_window_view(self):
         builder = self._setup_builder()
         main_window_view = MainWindowView(builder, self)
-        main_window_controller = MainWindowController(
+        self.main_window_controller = MainWindowController(
             main_window_view, builder)
-        self._setup_container(main_window_view)
+        self._setup_view(main_window_view)
         builder.get_object("chat_menu_button").hide()  # TODO: Make default
-        self.current_controller = main_window_controller
 
-    def _setup_add_contact_container(self):
-        self._setup_container(AddContactView())
+    def _setup_add_contact_view(self):
+        self._setup_view(AddContactView())
 
     def _setup_builder(self):
         builder = Gtk.Builder.new()
diff --git a/briar-gtk/tests/briar_gtk/test_window.py b/briar-gtk/tests/briar_gtk/test_window.py
index 157ca23..821c9b7 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_container.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,13 +35,13 @@ 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_container)
+    window_add.assert_called_once_with(window._current_view)
 
 
 def test_show_main_container(main_window_container, mocker,
                              startup_container, window_actions,
                              window_add, window_resize):
-    Window().show_main_container()
+    Window().show_main_window_view()
 
     main_window_container.assert_called_once()
 
@@ -51,9 +51,9 @@ def test_show_main_shown(main_window_container, mocker,
                          window_add, window_resize):
     window = Window()
 
-    window.show_main_container()
+    window.show_main_window_view()
 
-    window.current_container.show_all.assert_called_once()
+    window._current_view.show_all.assert_called_once()
 
 
 def test_show_main_add(main_window_container, mocker,
@@ -62,9 +62,9 @@ def test_show_main_add(main_window_container, mocker,
     window = Window()
     window_add = mocker.patch(MODULE % "Window.add")
 
-    window.show_main_container()
+    window.show_main_window_view()
 
-    window_add.assert_called_once_with(window.current_container)
+    window_add.assert_called_once_with(window._current_view)
 
 
 def test_show_main_destroy_old(main_window_container, mocker,
@@ -72,9 +72,9 @@ def test_show_main_destroy_old(main_window_container, mocker,
                                window_add, window_resize):
     window = Window()
     current_container_mock = mocker.MagicMock()
-    window.current_container = current_container_mock
+    window._current_view = current_container_mock
 
-    window.show_main_container()
+    window.show_main_window_view()
 
     current_container_mock.destroy.assert_called_once()
 
-- 
GitLab