From 7734a94158eb033654d76f52d2324a8d59065c21 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Sun, 19 May 2019 23:49:30 +0200 Subject: [PATCH] Use correctly working otp accounts for switching views --- src/Authenticator/application.py.in | 6 +----- src/Authenticator/models/accounts_manager.py | 7 +++++++ src/Authenticator/widgets/window.py | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Authenticator/application.py.in b/src/Authenticator/application.py.in index 2b80fea..5ebd3db 100644 --- a/src/Authenticator/application.py.in +++ b/src/Authenticator/application.py.in @@ -45,11 +45,7 @@ class Application(Gtk.Application): if self.is_locked: Window.get_default().view = WindowView.LOCKED else: - count = Database.get_default().accounts_count - if count == 0: - Window.get_default().view = WindowView.EMPTY - else: - Window.get_default().view = WindowView.NORMAL + Window.get_default().refresh_view() @staticmethod def get_default(): if Application.instance is None: diff --git a/src/Authenticator/models/accounts_manager.py b/src/Authenticator/models/accounts_manager.py index 43e46f8..ba08942 100644 --- a/src/Authenticator/models/accounts_manager.py +++ b/src/Authenticator/models/accounts_manager.py @@ -54,6 +54,13 @@ class AccountsManager(GObject.GObject): def accounts(self): return self._accounts + @property + def accounts_count(self): + count = 0 + for _, accounts in self._accounts: + count += len(accounts) + return count + def clear(self): self._accounts = [] diff --git a/src/Authenticator/widgets/window.py b/src/Authenticator/widgets/window.py index 1c9cb8d..d599ea5 100644 --- a/src/Authenticator/widgets/window.py +++ b/src/Authenticator/widgets/window.py @@ -135,16 +135,16 @@ class Window(Gtk.ApplicationWindow, GObject.GObject): # Set up accounts Widget accounts_widget = AccountsWidget.get_default() - accounts_widget.connect("account-removed", self.__on_accounts_changed) - accounts_widget.connect("account-added", self.__on_accounts_changed) + accounts_widget.connect("account-removed", self.refresh_view) + accounts_widget.connect("account-added", self.refresh_view) self.accounts_viewport.add(accounts_widget) self.search_bar.bind_property("search-mode-enabled", self.search_btn, "active", GObject.BindingFlags.BIDIRECTIONAL) - def __on_accounts_changed(self, *_): - if Database.get_default().accounts_count == 0: + def refresh_view(self, *_): + if AccountsManager.get_default().accounts_count == 0: self.props.view = WindowView.EMPTY else: self.props.view = WindowView.NORMAL