summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/gui/preferenceswindow.py
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2016-04-18 23:44:12 -0700
committerKali Kaneko <kali@leap.se>2016-04-19 12:00:23 -0400
commit229f803235ae9b9a71313d11071c7a0fbea0a681 (patch)
treefada7035628c90757b6b0cd7cf34182d1b6269fc /src/leap/bitmask/gui/preferenceswindow.py
parentc6db8a1f9ba7b6fc9dd117c0a699f4dfd339a375 (diff)
[feature] add email panel to preferences
Diffstat (limited to 'src/leap/bitmask/gui/preferenceswindow.py')
-rw-r--r--src/leap/bitmask/gui/preferenceswindow.py131
1 files changed, 93 insertions, 38 deletions
diff --git a/src/leap/bitmask/gui/preferenceswindow.py b/src/leap/bitmask/gui/preferenceswindow.py
index 44c4641c..1facba69 100644
--- a/src/leap/bitmask/gui/preferenceswindow.py
+++ b/src/leap/bitmask/gui/preferenceswindow.py
@@ -20,18 +20,15 @@ Preferences window
"""
from PySide import QtCore, QtGui
-from leap.bitmask.services import EIP_SERVICE
-from leap.bitmask._components import HAS_EIP
-
from leap.bitmask.logs.utils import get_logger
from leap.bitmask.gui.ui_preferences import Ui_Preferences
+from leap.bitmask.gui.preferences_page import PreferencesPage
from leap.bitmask.gui.preferences_account_page import PreferencesAccountPage
from leap.bitmask.gui.preferences_vpn_page import PreferencesVpnPage
from leap.bitmask.gui.preferences_email_page import PreferencesEmailPage
logger = get_logger()
-
class PreferencesWindow(QtGui.QDialog):
"""
@@ -40,39 +37,46 @@ class PreferencesWindow(QtGui.QDialog):
_current_window = None # currently visible preferences window
- def __init__(self, parent, account, app):
+ def __init__(self, parent, app):
"""
:param parent: parent object of the PreferencesWindow.
:parent type: QWidget
- :param account: the user or provider
- :type account: Account
-
:param app: the current App object
:type app: App
"""
QtGui.QDialog.__init__(self, parent)
- self.account = account
self.app = app
self.ui = Ui_Preferences()
self.ui.setupUi(self)
- self.ui.close_button.clicked.connect(self.close)
- self.ui.account_label.setText(account.address)
-
- self.app.service_selection_changed.connect(self._update_icons)
+ self._account_page = None
+ self._vpn_page = None
+ self._email_page = None
self._add_icons()
- self._add_pages()
- self._update_icons(self.account, self.account.services())
+ self._set_account(app.current_account())
+ self._setup_connections()
# only allow a single preferences window at a time.
if PreferencesWindow._current_window is not None:
PreferencesWindow._current_window.close()
PreferencesWindow._current_window = self
+ def _set_account(self, account):
+ """
+ Initially sets, or resets, the currently viewed account.
+ The account might not represent an authenticated user, but
+ just a domain.
+ """
+ self.ui.account_label.setText(account.address)
+ self._add_pages(account)
+ self._update_icons(account)
+ self.ui.pages_widget.setCurrentIndex(0)
+ self.ui.nav_widget.setCurrentRow(0)
+
def _add_icons(self):
"""
Adds all the icons for the different configuration categories.
@@ -114,22 +118,71 @@ class PreferencesWindow(QtGui.QDialog):
email_item.setSizeHint(QtCore.QSize(98, 56))
self._email_item = email_item
- self.ui.nav_widget.currentItemChanged.connect(self._change_page)
- self.ui.nav_widget.setCurrentRow(0)
-
- def _add_pages(self):
+ def _add_pages(self, account):
"""
Adds the pages for the different configuration categories.
"""
- self._account_page = PreferencesAccountPage(
- self, self.account, self.app)
- self._vpn_page = PreferencesVpnPage(self, self.account, self.app)
- self._email_page = PreferencesEmailPage(self, self.account, self.app)
-
+ self._remove_pages() # in case different account was loaded.
+
+ # load placeholder widgets if the page should not be loaded.
+ # the order of the pages is important, and must match the order
+ # of the nav_widget icons.
+ self._account_page = PreferencesAccountPage(self, account, self.app)
+ if account.has_eip():
+ self._vpn_page = PreferencesVpnPage(self, account, self.app)
+ else:
+ self._vpn_page = PreferencesPage(self)
+ if account.has_email():
+ self._email_page = PreferencesEmailPage(self, account, self.app)
+ else:
+ self._email_page = PreferencesPage(self)
self.ui.pages_widget.addWidget(self._account_page)
self.ui.pages_widget.addWidget(self._vpn_page)
self.ui.pages_widget.addWidget(self._email_page)
+ def _remove_pages(self):
+ # deleteLater does not seem to cascade to items in stackLayout
+ # (even with QtCore.Qt.WA_DeleteOnClose attribute).
+ # so, here we call deleteLater() explicitly.
+ if self._account_page is not None:
+ self.ui.pages_widget.removeWidget(self._account_page)
+ self._account_page.teardown_connections()
+ self._account_page.deleteLater()
+ if self._vpn_page is not None:
+ self.ui.pages_widget.removeWidget(self._vpn_page)
+ self._vpn_page.teardown_connections()
+ self._vpn_page.deleteLater()
+ if self._email_page is not None:
+ self.ui.pages_widget.removeWidget(self._email_page)
+ self._email_page.teardown_connections()
+ self._email_page.deleteLater()
+
+ def _setup_connections(self):
+ """
+ setup signal connections
+ """
+ self.ui.nav_widget.currentItemChanged.connect(self._change_page)
+ self.ui.close_button.clicked.connect(self.close)
+ self.app.service_selection_changed.connect(self._update_icons)
+ sig = self.app.signaler
+ sig.srp_auth_ok.connect(self._login_status_changed)
+ sig.srp_logout_ok.connect(self._login_status_changed)
+ sig.srp_status_logged_in.connect(self._update_account)
+ sig.srp_status_not_logged_in.connect(self._update_account)
+
+ def _teardown_connections(self):
+ """
+ clean up signal connections
+ """
+ self.ui.nav_widget.currentItemChanged.disconnect(self._change_page)
+ self.ui.close_button.clicked.disconnect(self.close)
+ self.app.service_selection_changed.disconnect(self._update_icons)
+ sig = self.app.signaler
+ sig.srp_auth_ok.disconnect(self._login_status_changed)
+ sig.srp_logout_ok.disconnect(self._login_status_changed)
+ sig.srp_status_logged_in.disconnect(self._update_account)
+ sig.srp_status_not_logged_in.disconnect(self._update_account)
+
#
# Slots
#
@@ -144,13 +197,8 @@ class PreferencesWindow(QtGui.QDialog):
Close this dialog and destroy it.
"""
PreferencesWindow._current_window = None
-
- # deleteLater does not seem to cascade to items in stackLayout
- # (even with QtCore.Qt.WA_DeleteOnClose attribute).
- # so, here we call deleteLater() explicitly:
- self._account_page.deleteLater()
- self._vpn_page.deleteLater()
- self._email_page.deleteLater()
+ self._teardown_connections();
+ self._remove_pages();
self.deleteLater()
def _change_page(self, current, previous):
@@ -170,17 +218,24 @@ class PreferencesWindow(QtGui.QDialog):
current = previous
self.ui.pages_widget.setCurrentIndex(self.ui.nav_widget.row(current))
- def _update_icons(self, account, services):
+ def _update_icons(self, account):
"""
TRIGGERS:
self.app.service_selection_changed
Change which icons are visible.
"""
- if account != self.account:
- return
+ self._vpn_item.setHidden(not account.has_eip())
+ self._email_item.setHidden(not account.has_email())
+
+ def _login_status_changed(self):
+ """
+ Triggered by signal srp_auth_ok, srp_logout_ok
+ """
+ self.app.backend.user_get_logged_in_status()
- if HAS_EIP:
- self._vpn_item.setHidden(EIP_SERVICE not in services)
- # self._email_item.setHidden(not MX_SERVICE in services)
- # ^^ disable email for now, there is nothing there yet.
+ def _update_account(self):
+ """
+ Triggered by get srp_status_logged_in, srp_status_not_logged_in
+ """
+ self._set_account(self.app.current_account())