From cbb540adc1825c0e59d973c386479c66d40c6b54 Mon Sep 17 00:00:00 2001 From: Nico Alt <nicoalt@posteo.org> Date: Fri, 27 Mar 2020 12:00:18 +0000 Subject: [PATCH] Put public functions to the top --- briar-gtk/briar_gtk/containers/add_contact.py | 56 +++++++++---------- briar-gtk/briar_gtk/containers/main_window.py | 18 +++--- .../briar_gtk/containers/private_chat.py | 26 ++++----- .../briar_gtk/containers/registration.py | 48 ++++++++-------- 4 files changed, 74 insertions(+), 74 deletions(-) diff --git a/briar-gtk/briar_gtk/containers/add_contact.py b/briar-gtk/briar_gtk/containers/add_contact.py index c5b7101..107d180 100644 --- a/briar-gtk/briar_gtk/containers/add_contact.py +++ b/briar-gtk/briar_gtk/containers/add_contact.py @@ -24,6 +24,34 @@ class AddContactContainer(Container): self._setup_view() self._load_content() + def proceed_from_links(self): + link_error_label = self.builder.get_object("link_error_label") + if self._link_is_empty(): + link_error_label.set_label(_("Please enter a link")) + link_error_label.show() + return + if self._links_match(): + link_error_label.show() + link_error_label.set_label( + _("Enter your contact's link, not your own")) + return + link_error_label.hide() + self._show_alias_page() + + def show_links_page(self): + links_page = self.builder.get_object("links_page") + self.add_contact_flow_stack.set_visible_child(links_page) + + def on_add_contact_pressed(self): + alias_error_label = self.builder.get_object( + "alias_error_label") + if self._alias_is_empty(): + alias_error_label.show() + return + alias_error_label.hide() + self._add_contact() + APP().window.show_main_container() + def _setup_view(self): self._add_from_resource(self.ADD_CONTACT_UI) self.builder.connect_signals(self) @@ -58,20 +86,6 @@ class AddContactContainer(Container): def _on_link_enter(self, widget): self.proceed_from_links() - def proceed_from_links(self): - link_error_label = self.builder.get_object("link_error_label") - if self._link_is_empty(): - link_error_label.set_label(_("Please enter a link")) - link_error_label.show() - return - if self._links_match(): - link_error_label.show() - link_error_label.set_label( - _("Enter your contact's link, not your own")) - return - link_error_label.hide() - self._show_alias_page() - def _links_match(self): their_link = self.builder.get_object("their_link_entry").get_text() own_link = self.builder.get_object("own_link_entry").get_text() @@ -100,20 +114,6 @@ class AddContactContainer(Container): def _on_alias_enter(self, widget): self.on_add_contact_pressed() - def show_links_page(self): - links_page = self.builder.get_object("links_page") - self.add_contact_flow_stack.set_visible_child(links_page) - - def on_add_contact_pressed(self): - alias_error_label = self.builder.get_object( - "alias_error_label") - if self._alias_is_empty(): - alias_error_label.show() - return - alias_error_label.hide() - self._add_contact() - APP().window.show_main_container() - def _alias_is_empty(self): alias = self.builder.get_object("alias_entry").get_text() return len(alias) == 0 diff --git a/briar-gtk/briar_gtk/containers/main_window.py b/briar-gtk/briar_gtk/containers/main_window.py index a0b49c5..bf75384 100644 --- a/briar-gtk/briar_gtk/containers/main_window.py +++ b/briar-gtk/briar_gtk/containers/main_window.py @@ -72,6 +72,15 @@ class MainWindowContainer(Container): self._prepare_chat_view(contact_name) self._setup_private_chat_widget(contact_name, contact_id) + def show_sidebar(self): + self.main_window_leaflet.set_visible_child( + self.builder.get_object("sidebar_box")) + self.chat_view.hide() + self.chat_placeholder.show() + self._clear_history_container() + self.contacts_list_box.unselect_all() + self.room_name_label.set_text("") + def _prepare_chat_view(self, contact_name): if self._no_chat_opened(): self.chat_placeholder.hide() @@ -149,12 +158,3 @@ class MainWindowContainer(Container): contacts_list_box_children = self.contacts_list_box.get_children() for child in contacts_list_box_children: self.contacts_list_box.remove(child) - - def show_sidebar(self): - self.main_window_leaflet.set_visible_child( - self.builder.get_object("sidebar_box")) - self.chat_view.hide() - self.chat_placeholder.show() - self._clear_history_container() - self.contacts_list_box.unselect_all() - self.room_name_label.set_text("") diff --git a/briar-gtk/briar_gtk/containers/private_chat.py b/briar-gtk/briar_gtk/containers/private_chat.py index c5bc821..96cee01 100644 --- a/briar-gtk/briar_gtk/containers/private_chat.py +++ b/briar-gtk/briar_gtk/containers/private_chat.py @@ -30,6 +30,19 @@ class PrivateChatContainer(Container): self._setup_view() self._load_content() + def send_message(self, widget): + message = widget.get_text() + private_chat = PrivateChat(APP().api, self._contact_id) + private_chat.send(message) + + self._add_message( + { + "text": message, + "local": True, + "timestamp": int(round(time.time() * 1000)) + }) + widget.set_text("") + def _setup_view(self): self._add_from_resource(self.CONTAINER_UI) @@ -67,16 +80,3 @@ class PrivateChatContainer(Container): def _add_message_async(self, message): GLib.idle_add(self._add_message, message) - - def send_message(self, widget): - message = widget.get_text() - private_chat = PrivateChat(APP().api, self._contact_id) - private_chat.send(message) - - self._add_message( - { - "text": message, - "local": True, - "timestamp": int(round(time.time() * 1000)) - }) - widget.set_text("") diff --git a/briar-gtk/briar_gtk/containers/registration.py b/briar-gtk/briar_gtk/containers/registration.py index 0fee2a2..253875f 100644 --- a/briar-gtk/briar_gtk/containers/registration.py +++ b/briar-gtk/briar_gtk/containers/registration.py @@ -24,6 +24,30 @@ class RegistrationContainer(Container): self._window = window self._setup_view() + def proceed_from_nickname(self): + if self._nickname_is_empty(): + self._show_nickname_error_message(_("Please enter a nickname")) + return + error_label = self.builder.get_object("nickname_error_label") + error_label.hide() + self._show_passwords_page() + + def show_nickname_page(self): + nickname_page = self.builder.get_object("nickname_page") + self.registration_flow_stack.set_visible_child(nickname_page) + + def on_create_account_pressed(self): + if self._password_is_empty(): + self._show_passwords_error_message(_("Please enter a password")) + return + if not self._passwords_match(): + self._show_passwords_error_message(_("The passwords do not match")) + return + error_label = self.builder.get_object("passwords_error_label") + error_label.hide() + self._show_loading_animation() + self._register() + def _setup_view(self): self._add_from_resource(self.REGISTRATION_UI) self.builder.connect_signals(self) @@ -53,14 +77,6 @@ class RegistrationContainer(Container): def _on_nickname_enter(self, widget): self.proceed_from_nickname() - def proceed_from_nickname(self): - if self._nickname_is_empty(): - self._show_nickname_error_message(_("Please enter a nickname")) - return - error_label = self.builder.get_object("nickname_error_label") - error_label.hide() - self._show_passwords_page() - def _nickname_is_empty(self): nickname = self.builder.get_object("nickname_entry").get_text() return len(nickname) == 0 @@ -86,22 +102,6 @@ class RegistrationContainer(Container): def _on_passwords_enter(self, widget): self.on_create_account_pressed() - def show_nickname_page(self): - nickname_page = self.builder.get_object("nickname_page") - self.registration_flow_stack.set_visible_child(nickname_page) - - def on_create_account_pressed(self): - if self._password_is_empty(): - self._show_passwords_error_message(_("Please enter a password")) - return - if not self._passwords_match(): - self._show_passwords_error_message(_("The passwords do not match")) - return - error_label = self.builder.get_object("passwords_error_label") - error_label.hide() - self._show_loading_animation() - self._register() - def _password_is_empty(self): password = self.builder.get_object("password_entry").get_text() return len(password) == 0 -- GitLab