summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/gui/mainwindow.py
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2014-04-24 12:12:17 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2014-04-25 13:23:40 -0300
commit477f57876be9bdc8b90cb0a031dc2c7d691a8574 (patch)
tree81fa49f28c82a3a28b5d6e5755e21298fc0546eb /src/leap/bitmask/gui/mainwindow.py
parentb74620fd45d56a7a9a193572010068efa6be681f (diff)
Improve action/widget/menu display conditions.
* Hide services that the current logged in provider does not have. * If we don't have a provider supporting that service we hide the actions along with the widgets. * Use more significative method naming. * Keep track of ui component groups visibility.
Diffstat (limited to 'src/leap/bitmask/gui/mainwindow.py')
-rw-r--r--src/leap/bitmask/gui/mainwindow.py49
1 files changed, 43 insertions, 6 deletions
diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py
index 73cf9419..a5c81983 100644
--- a/src/leap/bitmask/gui/mainwindow.py
+++ b/src/leap/bitmask/gui/mainwindow.py
@@ -256,6 +256,8 @@ class MainWindow(QtGui.QMainWindow):
# self.ui.btnEIPPreferences.clicked.connect(self._show_eip_preferences)
self._enabled_services = []
+ self._ui_mx_visible = True
+ self._ui_eip_visible = True
# last minute UI manipulations
@@ -723,7 +725,7 @@ class MainWindow(QtGui.QMainWindow):
if IS_MAC:
self.raise_()
- self._hide_unsupported_services()
+ self._show_hide_unsupported_services()
if self._wizard:
possible_username = self._wizard.get_username()
@@ -765,7 +767,7 @@ class MainWindow(QtGui.QMainWindow):
if self._login_widget.load_user_from_keyring(saved_user):
self._login()
- def _hide_unsupported_services(self):
+ def _show_hide_unsupported_services(self):
"""
Given a set of configured providers, it creates a set of
available services among all of them and displays the service
@@ -786,8 +788,38 @@ class MainWindow(QtGui.QMainWindow):
for service in provider_config.get_services():
services.add(service)
- self.ui.eipWidget.setVisible(EIP_SERVICE in services)
- self.ui.mailWidget.setVisible(MX_SERVICE in services)
+ self._set_eip_visible(EIP_SERVICE in services)
+ self._set_mx_visible(MX_SERVICE in services)
+
+ def _set_mx_visible(self, visible):
+ """
+ Change the visibility of MX_SERVICE related UI components.
+
+ :param visible: whether the components should be visible or not.
+ :type visible: bool
+ """
+ # only update visibility if it is something to change
+ if self._ui_mx_visible ^ visible:
+ self.ui.mailWidget.setVisible(visible)
+ self.ui.lineUnderEmail.setVisible(visible)
+ self._action_mail_status.setVisible(visible)
+ self._ui_mx_visible = visible
+
+ def _set_eip_visible(self, visible):
+ """
+ Change the visibility of EIP_SERVICE related UI components.
+
+ :param visible: whether the components should be visible or not.
+ :type visible: bool
+ """
+ # NOTE: we use xor to avoid the code being run if the visibility hasn't
+ # changed. This is meant to avoid the eip menu being displayed floating
+ # around at start because the systray isn't rendered yet.
+ if self._ui_eip_visible ^ visible:
+ self.ui.eipWidget.setVisible(visible)
+ self.ui.lineUnderEIP.setVisible(visible)
+ self._eip_menu.setVisible(visible)
+ self._ui_eip_visible = visible
def _set_label_offline(self):
"""
@@ -824,7 +856,7 @@ class MainWindow(QtGui.QMainWindow):
systrayMenu.addSeparator()
eip_status_label = "{0}: {1}".format(self._eip_name, self.tr("OFF"))
- eip_menu = systrayMenu.addMenu(eip_status_label)
+ self._eip_menu = eip_menu = systrayMenu.addMenu(eip_status_label)
eip_menu.addAction(self._action_eip_startstop)
self._eip_status.set_eip_status_menu(eip_menu)
systrayMenu.addSeparator()
@@ -1186,7 +1218,7 @@ class MainWindow(QtGui.QMainWindow):
username = self._login_widget.get_user()
password = self._login_widget.get_password()
- self._hide_unsupported_services()
+ self._show_hide_unsupported_services()
domain = self._provider_config.get_domain()
self._backend.login(domain, username, password)
@@ -1221,6 +1253,9 @@ class MainWindow(QtGui.QMainWindow):
self._soledad_bootstrapper.soledad_failed.connect(
lambda: btn_enabled(True))
+ if not self._get_best_provider_config().provides_mx():
+ self._set_mx_visible(False)
+
def _start_eip_bootstrap(self):
"""
Changes the stackedWidget index to the EIP status one and
@@ -1950,6 +1985,8 @@ class MainWindow(QtGui.QMainWindow):
self._login_widget.logged_out()
self._mail_status.mail_state_disabled()
+ self._show_hide_unsupported_services()
+
@QtCore.Slot(dict)
def _intermediate_stage(self, data):
# TODO this method name is confusing as hell.