diff options
-rw-r--r-- | changes/provider-combo-on-top | 1 | ||||
-rw-r--r-- | src/leap/bitmask/gui/login.py | 91 | ||||
-rw-r--r-- | src/leap/bitmask/gui/mainwindow.py | 76 | ||||
-rw-r--r-- | src/leap/bitmask/gui/providers.py | 114 | ||||
-rw-r--r-- | src/leap/bitmask/gui/ui/login.ui | 25 | ||||
-rw-r--r-- | src/leap/bitmask/gui/ui/mainwindow.ui | 39 |
6 files changed, 178 insertions, 168 deletions
diff --git a/changes/provider-combo-on-top b/changes/provider-combo-on-top new file mode 100644 index 00000000..8aceb7df --- /dev/null +++ b/changes/provider-combo-on-top @@ -0,0 +1 @@ +- moved provider selection dropdown menu to be at the top of the main window
\ No newline at end of file diff --git a/src/leap/bitmask/gui/login.py b/src/leap/bitmask/gui/login.py index 0e64bbcf..2a79fafd 100644 --- a/src/leap/bitmask/gui/login.py +++ b/src/leap/bitmask/gui/login.py @@ -19,8 +19,6 @@ Login widget implementation """ import logging -from collections import deque - from PySide import QtCore, QtGui from ui_login import Ui_LoginWidget @@ -45,11 +43,6 @@ class LoginWidget(QtGui.QWidget): cancel_login = QtCore.Signal() logout = QtCore.Signal() - # Emitted when the user changes the provider combobox index. The object - # parameter is actually a boolean value that is True if "Other..." was - # selected, False otherwse - provider_changed = QtCore.Signal(object) - MAX_STATUS_WIDTH = 40 # Keyring @@ -68,9 +61,6 @@ class LoginWidget(QtGui.QWidget): self._settings = settings - self._providers_indexes = deque(maxlen=2) # previous and current - self._providers_indexes.append(-1) - self.ui = Ui_LoginWidget() self.ui.setupUi(self) @@ -85,9 +75,6 @@ class LoginWidget(QtGui.QWidget): self.ui.lnUser.returnPressed.connect(self._focus_password) - self.ui.cmbProviders.currentIndexChanged.connect( - self._current_provider_changed) - self.ui.btnLogout.clicked.connect( self.logout) @@ -116,42 +103,6 @@ class LoginWidget(QtGui.QWidget): enable = True if state == QtCore.Qt.Checked else False self._settings.set_remember(enable) - def set_providers(self, provider_list): - """ - Set the provider list to provider_list plus an "Other..." item - that triggers the wizard - - :param provider_list: list of providers - :type provider_list: list of str - """ - self.ui.cmbProviders.blockSignals(True) - self.ui.cmbProviders.clear() - self.ui.cmbProviders.addItems(provider_list + [self.tr("Other...")]) - self.ui.cmbProviders.blockSignals(False) - - def select_provider_by_name(self, name): - """ - Given a provider name/domain, it selects it in the combobox - - :param name: name or domain for the provider - :type name: str - """ - provider_index = self.ui.cmbProviders.findText(name) - self._providers_indexes.append(provider_index) - - # block the signals during a combobox change since we don't want to - # trigger the default signal that makes the UI ask the user for - # confirmation - self.ui.cmbProviders.blockSignals(True) - self.ui.cmbProviders.setCurrentIndex(provider_index) - self.ui.cmbProviders.blockSignals(False) - - def get_selected_provider(self): - """ - Returns the selected provider in the combobox - """ - return self.ui.cmbProviders.currentText() - def set_remember(self, value): """ Checks the remember user and password checkbox @@ -229,7 +180,6 @@ class LoginWidget(QtGui.QWidget): self.ui.lnUser.setEnabled(enabled) self.ui.lnPassword.setEnabled(enabled) self.ui.chkRemember.setEnabled(enabled and has_keyring()) - self.ui.cmbProviders.setEnabled(enabled) self._set_cancel(not enabled) @@ -270,45 +220,20 @@ class LoginWidget(QtGui.QWidget): """ self.ui.lnPassword.setFocus() - @QtCore.Slot(int) - def _current_provider_changed(self, idx): - """ - TRIGGERS: - self.ui.cmbProviders.currentIndexChanged - - :param idx: the index of the new selected item - :type idx: int - """ - self._providers_indexes.append(idx) - is_wizard = idx == (self.ui.cmbProviders.count() - 1) - self.provider_changed.emit(is_wizard) - if is_wizard: - self.restore_previous_provider() - - def restore_previous_provider(self): - """ - Set as selected provider the one that was selected previously. - """ - prev_provider = self._providers_indexes.popleft() - self._providers_indexes.append(prev_provider) - self.ui.cmbProviders.blockSignals(True) - self.ui.cmbProviders.setCurrentIndex(prev_provider) - self.ui.cmbProviders.blockSignals(False) - - def start_login(self): + def start_login(self, provider): """ Setups the login widgets for actually performing the login and performs some basic checks. + :param provider: the domain of the current provider + :type provider: unicode str :returns: True if everything's good to go, False otherwise :rtype: bool """ username = self.get_user() password = self.get_password() - provider = self.get_selected_provider() - self._enabled_services = self._settings.get_enabled_services( - self.get_selected_provider()) + self._enabled_services = self._settings.get_enabled_services(provider) if len(provider) == 0: self.set_status( @@ -347,14 +272,16 @@ class LoginWidget(QtGui.QWidget): % (e,)) return True - def logged_in(self): + def logged_in(self, provider): """ Sets the widgets to the logged in state + + :param provider: the domain of the current provider + :type provider: unicode str """ self.ui.login_widget.hide() self.ui.logged_widget.show() - self.ui.lblUser.setText(make_address( - self.get_user(), self.get_selected_provider())) + self.ui.lblUser.setText(make_address(self.get_user(), provider)) if flags.OFFLINE is False: self.logged_in_signal.emit() diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index 03f91996..8ce7f2fc 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -45,6 +45,7 @@ from leap.bitmask.gui.mail_status import MailStatusWidget from leap.bitmask.gui.preferenceswindow import PreferencesWindow from leap.bitmask.gui.systray import SysTray from leap.bitmask.gui.wizard import Wizard +from leap.bitmask.gui.providers import Providers from leap.bitmask.platform_init import IS_WIN, IS_MAC, IS_LINUX from leap.bitmask.platform_init.initializers import init_platform @@ -148,13 +149,17 @@ class MainWindow(QtGui.QMainWindow): self._mail_status = MailStatusWidget(self) self.ui.mailLayout.addWidget(self._mail_status) + # Provider List + self._providers = Providers(self.ui.cmbProviders) + # Qt Signal Connections ##################################### # TODO separate logic from ui signals. self._login_widget.login.connect(self._login) self._login_widget.cancel_login.connect(self._cancel_login) self._login_widget.logout.connect(self._logout) - self._login_widget.provider_changed.connect(self._on_provider_changed) + + self._providers.connect_provider_changed(self._on_provider_changed) # EIP Control redux ######################################### self._eip_conductor = eip_conductor.EIPConductor( @@ -577,7 +582,7 @@ class MainWindow(QtGui.QMainWindow): Display the Advanced Key Management dialog. """ - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() logged_user = "{0}@{1}".format(self._logged_user, domain) details = self._provider_details @@ -600,7 +605,7 @@ class MainWindow(QtGui.QMainWindow): Display the preferences window. """ user = self._logged_user - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() mx_provided = False if self._provider_details is not None: mx_provided = MX_SERVICE in self._provider_details['services'] @@ -717,7 +722,7 @@ class MainWindow(QtGui.QMainWindow): Display the EIP preferences window. """ - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() pref = EIPPreferencesWindow(self, domain, self._backend, self._leap_signaler) pref.show() @@ -794,7 +799,7 @@ class MainWindow(QtGui.QMainWindow): # XXX: May be this can be divided into two methods? providers = self._settings.get_configured_providers() - self._login_widget.set_providers(providers) + self._providers.set_providers(providers) self._show_systray() if not self._start_hidden: @@ -810,12 +815,12 @@ class MainWindow(QtGui.QMainWindow): # select the configured provider in the combo box domain = self._wizard.get_domain() - self._login_widget.select_provider_by_name(domain) + self._providers.select_provider_by_name(domain) self._login_widget.set_remember(self._wizard.get_remember()) self._enabled_services = list(self._wizard.get_services()) self._settings.set_enabled_services( - self._login_widget.get_selected_provider(), + self._providers.get_selected_provider(), self._enabled_services) if possible_username is not None: self._login_widget.set_user(possible_username) @@ -832,7 +837,7 @@ class MainWindow(QtGui.QMainWindow): domain = self._settings.get_provider() if domain is not None: - self._login_widget.select_provider_by_name(domain) + self._providers.select_provider_by_name(domain) if not self._settings.get_remember(): # nothing to do here @@ -895,11 +900,7 @@ class MainWindow(QtGui.QMainWindow): """ Set the login label to reflect offline status. """ - provider = "" - if not self._logged_in_offline: - provider = self.ui.lblLoginProvider.text() - - self.ui.lblLoginProvider.setText(provider + self.tr(" (offline mode)")) + # TODO: figure out what widget to use for this. Maybe the window title? # # systray @@ -1159,7 +1160,7 @@ class MainWindow(QtGui.QMainWindow): emit the corresponding signals inmediately """ self._disconnect_scheduled_login() - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() self._backend.provider_setup(provider=domain) @QtCore.Slot(dict) @@ -1176,7 +1177,7 @@ class MainWindow(QtGui.QMainWindow): :type data: dict """ if data[PASSED_KEY]: - selected_provider = self._login_widget.get_selected_provider() + selected_provider = self._providers.get_selected_provider() self._backend.provider_bootstrap(provider=selected_provider) else: logger.error(data[ERROR_KEY]) @@ -1230,7 +1231,7 @@ class MainWindow(QtGui.QMainWindow): def _on_provider_changed(self, wizard=True): """ TRIGGERS: - self._login.provider_changed + self._providers._provider_changed self.ui.action_create_new_account.triggered Ask the user if really wants to change provider since a services stop @@ -1250,12 +1251,9 @@ class MainWindow(QtGui.QMainWindow): return title = self.tr("Stop services") - text = self.tr("<b>Do you want to stop all services?</b>") + text = "<b>" + self.tr("Do you want to stop all services?") + "</b>" informative_text = self.tr("In order to change the provider, the " "running services needs to be stopped.") - if wizard: - informative_text = self.tr("In order to start the wizard, the " - "running services needs to be stopped.") msg = QtGui.QMessageBox(self) msg.setWindowTitle(title) @@ -1274,7 +1272,7 @@ class MainWindow(QtGui.QMainWindow): else: if not wizard: # if wizard, the widget restores itself - self._login_widget.restore_previous_provider() + self._providers.restore_previous_provider() @QtCore.Slot() def _login(self): @@ -1288,19 +1286,18 @@ class MainWindow(QtGui.QMainWindow): bootstrapping the EIP service """ # TODO most of this could ve handled by the login widget, - # but we'd have to move lblLoginProvider into the widget itself, - # instead of having it as a top-level attribute. + provider = self._providers.get_selected_provider() if flags.OFFLINE is True: logger.debug("OFFLINE mode! bypassing remote login") # TODO reminder, we're not handling logout for offline # mode. - self._login_widget.logged_in() + self._login_widget.logged_in(provider) self._logged_in_offline = True self._set_label_offline() self.offline_mode_bypass_login.emit() else: self.ui.action_create_new_account.setEnabled(False) - if self._login_widget.start_login(): + if self._login_widget.start_login(provider): if self._trying_to_start_eip: self._schedule_login() else: @@ -1380,7 +1377,7 @@ class MainWindow(QtGui.QMainWindow): self._show_hide_unsupported_services() - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() self._backend.user_login(provider=domain, username=username, password=password) else: @@ -1400,7 +1397,7 @@ class MainWindow(QtGui.QMainWindow): self._logged_user = self._login_widget.get_user() user = self._logged_user - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() full_user_id = make_address(user, domain) self._mail_conductor.userid = full_user_id self._start_eip_bootstrap() @@ -1423,9 +1420,8 @@ class MainWindow(QtGui.QMainWindow): triggers the eip bootstrapping. """ - self._login_widget.logged_in() - domain = self._login_widget.get_selected_provider() - self.ui.lblLoginProvider.setText(domain) + domain = self._providers.get_selected_provider() + self._login_widget.logged_in(domain) self._enabled_services = self._settings.get_enabled_services(domain) @@ -1447,7 +1443,7 @@ class MainWindow(QtGui.QMainWindow): and enabled. This is triggered right after the provider has been set up. """ - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() lang = QtCore.QLocale.system().name() self._backend.provider_get_details(domain=domain, lang=lang) @@ -1468,7 +1464,7 @@ class MainWindow(QtGui.QMainWindow): :returns: True if provides and is enabled, False otherwise :rtype: bool """ - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() enabled_services = self._settings.get_enabled_services(domain) mx_enabled = MX_SERVICE in enabled_services @@ -1485,7 +1481,7 @@ class MainWindow(QtGui.QMainWindow): :returns: True if provides and is enabled, False otherwise :rtype: bool """ - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() enabled_services = self._settings.get_enabled_services(domain) eip_enabled = EIP_SERVICE in enabled_services @@ -1506,7 +1502,7 @@ class MainWindow(QtGui.QMainWindow): username = self._login_widget.get_user() password = unicode(self._login_widget.get_password()) - provider_domain = self._login_widget.get_selected_provider() + provider_domain = self._providers.get_selected_provider() if flags.OFFLINE: full_user_id = make_address(username, provider_domain) @@ -1522,7 +1518,7 @@ class MainWindow(QtGui.QMainWindow): password=password, uuid=uuid) else: if self._logged_user is not None: - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() self._backend.soledad_bootstrap(username=username, domain=domain, password=password) @@ -1606,7 +1602,7 @@ class MainWindow(QtGui.QMainWindow): """ self._already_started_eip = True - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() self._settings.set_defaultprovider(domain) self._backend.eip_get_gateway_country_code(domain=domain) @@ -1633,7 +1629,7 @@ class MainWindow(QtGui.QMainWindow): Set the current provider and country code in the eip status widget. """ - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() self._eip_status.set_provider(domain, country_code) @QtCore.Slot() @@ -1641,7 +1637,7 @@ class MainWindow(QtGui.QMainWindow): """ Trigger this if we don't have a working DNS resolver. """ - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() msg = self.tr( "The server at {0} can't be found, because the DNS lookup " "failed. DNS is the network service that translates a " @@ -1705,7 +1701,7 @@ class MainWindow(QtGui.QMainWindow): self._eip_status.eip_button.hide() self._eip_status.eip_button.setEnabled(False) - domain = self._login_widget.get_selected_provider() + domain = self._providers.get_selected_provider() self._backend.eip_setup(provider=domain) self._already_started_eip = True @@ -1796,7 +1792,6 @@ class MainWindow(QtGui.QMainWindow): Inform the user about a logout error. """ self._login_widget.done_logout() - self.ui.lblLoginProvider.setText(self.tr("Login")) self._login_widget.set_status( self.tr("Something went wrong with the logout.")) @@ -1810,7 +1805,6 @@ class MainWindow(QtGui.QMainWindow): logging out """ self._login_widget.done_logout() - self.ui.lblLoginProvider.setText(self.tr("Login")) self._logged_user = None self._login_widget.logged_out() diff --git a/src/leap/bitmask/gui/providers.py b/src/leap/bitmask/gui/providers.py new file mode 100644 index 00000000..b3eb8620 --- /dev/null +++ b/src/leap/bitmask/gui/providers.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2013,2014 LEAP +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +""" +An instance of class Providers, held by mainwindow, is responsible for +managing the current provider and the combobox provider list. +""" + +from collections import deque +from PySide import QtCore + + +class Providers(QtCore.QObject): + + # Emitted when the user changes the provider combobox index. The object + # parameter is actually a boolean value that is True if "Other..." was + # selected, False otherwse + _provider_changed = QtCore.Signal(object) + + def __init__(self, providers_combo): + """ + :param providers_combo: combo widget that lists providers + :type providers_combo: QWidget + """ + QtCore.QObject.__init__(self) + self._providers_indexes = deque(maxlen=2) # previous and current + self._providers_indexes.append(-1) + self._combo = providers_combo + self._combo.currentIndexChanged.connect( + self._current_provider_changed) + + def set_providers(self, provider_list): + """ + Set the provider list to provider_list plus an "Other..." item + that triggers the wizard + + :param provider_list: list of providers + :type provider_list: list of str + """ + self._combo.blockSignals(True) + self._combo.clear() + self._combo.addItems(provider_list + [self.tr("Other...")]) + self._combo.blockSignals(False) + + def select_provider_by_name(self, name): + """ + Given a provider name/domain, it selects it in the combobox + + :param name: name or domain for the provider + :type name: unicode str + """ + provider_index = self._combo.findText(name) + self._providers_indexes.append(provider_index) + + # block the signals during a combobox change since we don't want to + # trigger the default signal that makes the UI ask the user for + # confirmation + self._combo.blockSignals(True) + self._combo.setCurrentIndex(provider_index) + self._combo.blockSignals(False) + + def get_selected_provider(self): + """ + Returns the selected provider in the combobox + + :rtype: unicode str + """ + return self._combo.currentText() + + def connect_provider_changed(self, callback): + """ + Connects callback to provider_changed signal + """ + self._provider_changed.connect(callback) + + def restore_previous_provider(self): + """ + Set as selected provider the one that was selected previously. + """ + prev_provider = self._providers_indexes.popleft() + self._providers_indexes.append(prev_provider) + self._combo.blockSignals(True) + self._combo.setCurrentIndex(prev_provider) + self._combo.blockSignals(False) + + @QtCore.Slot(int) + def _current_provider_changed(self, idx): + """ + TRIGGERS: + self._combo.currentIndexChanged + + :param idx: the index of the new selected item + :type idx: int + """ + self._providers_indexes.append(idx) + is_wizard = idx == (self._combo.count() - 1) + self._provider_changed.emit(is_wizard) + if is_wizard: + self.restore_previous_provider() diff --git a/src/leap/bitmask/gui/ui/login.ui b/src/leap/bitmask/gui/ui/login.ui index 26decc6d..bfd5f9c0 100644 --- a/src/leap/bitmask/gui/ui/login.ui +++ b/src/leap/bitmask/gui/ui/login.ui @@ -69,17 +69,7 @@ <property name="rightMargin"> <number>24</number> </property> - <item row="0" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string><b>Provider:</b></string> - </property> - <property name="alignment"> - <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> - </property> - </widget> - </item> - <item row="4" column="1"> + <item row="3" column="1"> <widget class="QPushButton" name="btnLogin"> <property name="sizePolicy"> <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> @@ -92,7 +82,7 @@ </property> </widget> </item> - <item row="3" column="1"> + <item row="2" column="1"> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QCheckBox" name="chkRemember"> @@ -116,10 +106,7 @@ </item> </layout> </item> - <item row="0" column="1"> - <widget class="QComboBox" name="cmbProviders"/> - </item> - <item row="1" column="0"> + <item row="0" column="0"> <widget class="QLabel" name="label_2"> <property name="text"> <string><b>Username:</b></string> @@ -129,10 +116,10 @@ </property> </widget> </item> - <item row="1" column="1"> + <item row="0" column="1"> <widget class="QLineEdit" name="lnUser"/> </item> - <item row="2" column="0"> + <item row="1" column="0"> <widget class="QLabel" name="label_3"> <property name="text"> <string><b>Password:</b></string> @@ -142,7 +129,7 @@ </property> </widget> </item> - <item row="2" column="1"> + <item row="1" column="1"> <widget class="QLineEdit" name="lnPassword"> <property name="inputMask"> <string/> diff --git a/src/leap/bitmask/gui/ui/mainwindow.ui b/src/leap/bitmask/gui/ui/mainwindow.ui index 5dc48f29..92c13d15 100644 --- a/src/leap/bitmask/gui/ui/mainwindow.ui +++ b/src/leap/bitmask/gui/ui/mainwindow.ui @@ -75,7 +75,7 @@ <x>0</x> <y>0</y> <width>524</width> - <height>589</height> + <height>540</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout"> @@ -86,7 +86,7 @@ <number>0</number> </property> <item> - <widget class="QFrame" name="frame"> + <widget class="QFrame" name="providerFrame"> <property name="sizePolicy"> <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> <horstretch>0</horstretch> @@ -97,29 +97,16 @@ <bool>false</bool> </property> <property name="styleSheet"> - <string notr="true">background-color: rgba(0,0,0,20); border-bottom: 1px solid rgba(0,0,0,30);</string> + <string notr="true">QFrame#providerFrame {background-color: rgba(0,0,0,20); border-bottom: 1px solid rgba(0,0,0,30);}</string> </property> <layout class="QHBoxLayout" name="horizontalLayout"> - <property name="leftMargin"> - <number>24</number> - </property> - <property name="rightMargin"> - <number>24</number> - </property> <item> - <widget class="QLabel" name="lblLoginProvider"> + <widget class="QComboBox" name="cmbProviders"> <property name="font"> <font> - <weight>75</weight> - <bold>true</bold> + <pointsize>12</pointsize> </font> </property> - <property name="styleSheet"> - <string notr="true">background-color: rgba(255, 255, 255, 0); border: none;</string> - </property> - <property name="text"> - <string>Please Log In</string> - </property> </widget> </item> </layout> @@ -186,7 +173,7 @@ <item> <layout class="QVBoxLayout" name="mailLayout"> <property name="spacing"> - <number>-1</number> + <number>6</number> </property> <property name="margin"> <number>12</number> @@ -224,18 +211,18 @@ <verstretch>0</verstretch> </sizepolicy> </property> - <property name="autoFillBackground"> - <bool>false</bool> - </property> - <property name="styleSheet"> - <string notr="true">background-color: rgba(0,0,0,20); border-top: 1px solid rgba(0,0,0,30);</string> - </property> <property name="minimumSize"> <size> <width>0</width> <height>16</height> </size> </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="styleSheet"> + <string notr="true">background-color: rgba(0,0,0,20); border-top: 1px solid rgba(0,0,0,30);</string> + </property> </widget> </item> </layout> @@ -319,7 +306,7 @@ <x>0</x> <y>0</y> <width>524</width> - <height>21</height> + <height>25</height> </rect> </property> <widget class="QMenu" name="menuFile"> |