From 364c6d5e9882f47ff5938f731641bc7509e32fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Tue, 12 Mar 2013 17:12:20 -0300 Subject: Make the wizard provider setup only Also: - Add a way to enable/disable services for a provider - Run EIP only if it is enabled --- src/leap/gui/mainwindow.py | 25 +++++++-- src/leap/gui/ui/mainwindow.ui | 3 +- src/leap/gui/ui/wizard.ui | 106 ++-------------------------------- src/leap/gui/wizard.py | 128 +++++++++++++++++++----------------------- 4 files changed, 88 insertions(+), 174 deletions(-) diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py index 3af87366..f8ca4c35 100644 --- a/src/leap/gui/mainwindow.py +++ b/src/leap/gui/mainwindow.py @@ -175,6 +175,8 @@ class MainWindow(QtGui.QMainWindow): self._action_visible = QtGui.QAction(self.tr("Hide"), self) self._action_visible.triggered.connect(self._toggle_visible) + self._enabled_services = [] + self._center_window() self._wizard = None self._wizard_firstrun = False @@ -214,6 +216,11 @@ class MainWindow(QtGui.QMainWindow): if self._wizard: possible_username = self._wizard.get_username() possible_password = self._wizard.get_password() + self.ui.chkRemember.setChecked(self._wizard.get_remember()) + self._enabled_services = list(self._wizard.get_services()) + settings.setValue("%s/Services" % + (self.ui.cmbProviders.currentText(),), + self._enabled_services) if possible_username is not None: self.ui.lnUser.setText(possible_username) self._focus_password() @@ -487,6 +494,11 @@ class MainWindow(QtGui.QMainWindow): password = self.ui.lnPassword.text() provider = self.ui.cmbProviders.currentText() + settings = QtCore.QSettings() + self._enabled_services = settings.value( + "%s/Services" % + (self.ui.cmbProviders.currentText(),), "").split(",") + if len(provider) == 0: self._set_status(self.tr("Please select a valid provider")) return @@ -608,15 +620,20 @@ class MainWindow(QtGui.QMainWindow): self._set_eip_status(self.tr("Checking configuration, please wait...")) - if self._provider_config.provides_eip(): + if self._provider_config.provides_eip() and \ + self._enabled_services.count("openvpn") > 0: self._eip_bootstrapper.run_eip_setup_checks( self._checker_thread, self._provider_config, download_if_needed=True) else: - self._set_eip_status(self.tr("%s does not support EIP") % - (self._provider_config.get_domain(),), - error=True) + if self._enabled_services.count("openvpn") > 0: + self._set_eip_status(self.tr("%s does not support EIP") % + (self._provider_config.get_domain(),), + error=True) + else: + self._set_eip_status(self.tr("EIP is disabled")) + self.ui.btnEipStartStop.setEnabled(False) def _set_eip_status_icon(self, status): """ diff --git a/src/leap/gui/ui/mainwindow.ui b/src/leap/gui/ui/mainwindow.ui index d723114c..a8a8aa59 100644 --- a/src/leap/gui/ui/mainwindow.ui +++ b/src/leap/gui/ui/mainwindow.ui @@ -70,7 +70,7 @@ - 0 + 1 @@ -389,6 +389,7 @@ + diff --git a/src/leap/gui/ui/wizard.ui b/src/leap/gui/ui/wizard.ui index ad4c0500..b8fed183 100644 --- a/src/leap/gui/ui/wizard.ui +++ b/src/leap/gui/ui/wizard.ui @@ -632,123 +632,29 @@ - + - EIP Setup + Service selection - Setting up Encrypted Internet + Please select the services you would like to have 5 - - - Qt::Vertical - - - - 20 - 40 - - - - - - + - Checking EIP + Services by PROVIDER - - - - Download EIP configuration - - - - - - - Download client certificate - - - - - - - - 0 - 0 - - - - - 24 - 24 - - - - - - - :/images/Emblem-question.png - - - - - - - - 0 - 0 - - - - - 24 - 24 - - - - - - - :/images/Emblem-question.png - - - - - - Qt::Horizontal - - - - 40 - 0 - - - + - - - - Qt::Vertical - - - - 20 - 40 - - - - diff --git a/src/leap/gui/wizard.py b/src/leap/gui/wizard.py index 1f0bc877..83f64020 100644 --- a/src/leap/gui/wizard.py +++ b/src/leap/gui/wizard.py @@ -27,9 +27,7 @@ from functools import partial from ui_wizard import Ui_Wizard from leap.config.providerconfig import ProviderConfig from leap.crypto.srpregister import SRPRegister -from leap.crypto.srpauth import SRPAuth from leap.services.eip.providerbootstrapper import ProviderBootstrapper -from leap.services.eip.eipbootstrapper import EIPBootstrapper logger = logging.getLogger(__name__) @@ -44,7 +42,7 @@ class Wizard(QtGui.QWizard): PRESENT_PROVIDER_PAGE = 2 SETUP_PROVIDER_PAGE = 3 REGISTER_USER_PAGE = 4 - SETUP_EIP_PAGE = 5 + SERVICES_PAGE = 5 FINISH_PAGE = 6 WEAK_PASSWORDS = ("123456", "qweasd", "qwerty", @@ -65,6 +63,16 @@ class Wizard(QtGui.QWizard): self.ERROR_ICON = QtGui.QPixmap(":/images/Dialog-error.png") self.OK_ICON = QtGui.QPixmap(":/images/Dialog-accept.png") + # Correspondence for services and their name to display + self.SERVICE_DISPLAY = [ + self.tr("Encrypted Internet") + ] + self.SERVICE_CONFIG = [ + "openvpn" + ] + + self._selected_services = set() + self._show_register = False self.ui.grpCheckProvider.setVisible(False) @@ -86,13 +94,6 @@ class Wizard(QtGui.QWizard): self._provider_bootstrapper.check_api_certificate.connect( self._check_api_certificate) - self._eip_bootstrapper = EIPBootstrapper() - - self._eip_bootstrapper.download_config.connect( - self._download_eip_config) - self._eip_bootstrapper.download_client_certificate.connect( - self._download_client_certificate) - self._domain = None self._provider_config = ProviderConfig() @@ -135,6 +136,12 @@ class Wizard(QtGui.QWizard): def get_password(self): return self._password + def get_remember(self): + return self.ui.chkRemember.isChecked() + + def get_services(self): + return self._selected_services + def _enable_check(self, text): self.ui.btnCheck.setEnabled(len(self.ui.lnProvider.text()) != 0) self._reset_provider_check() @@ -214,19 +221,11 @@ class Wizard(QtGui.QWizard): if ok: self._set_register_status(self.tr("" "User registration OK. " - "Logging in...")) + "")) self.ui.lblPassword2.clearFocus() - - srp_auth = SRPAuth(self._provider_config) - srp_auth.authentication_finished.connect( - self._authentication_finished) - - auth_partial = partial(srp_auth.authenticate, - self._username, - self._password) - self._checker_thread.add_checks([auth_partial]) - self.ui.chkRemember.setEnabled(True) + + self.page(self.REGISTER_USER_PAGE).set_completed() else: old_username = self._username self._username = None @@ -241,24 +240,6 @@ class Wizard(QtGui.QWizard): logger.error("Unknown error: %r" % (req.content,)) self.ui.btnRegister.setEnabled(True) - def _authentication_finished(self, ok, message): - """ - SLOT - TRIGGER: srp_auth.authentication_finished - - Finish the authentication process as it comes from the - register form - """ - if ok: - self._set_register_status(self.tr("" - "Login succeeded!" - "")) - self.page(self.REGISTER_USER_PAGE).set_completed() - else: - self._set_register_status(message) - self.ui.btnRegister.setEnabled(True) - self.ui.chkRemember.setEnabled(False) - def _set_register_status(self, status, error=False): """ Sets the status label in the registration page to status @@ -291,13 +272,6 @@ class Wizard(QtGui.QWizard): self.ui.lblCheckCaFpr.setPixmap(None) self.ui.lblCheckApiCert.setPixmap(None) - def _reset_eip_check(self): - """ - Resets the UI for the EIP check - """ - self.ui.lblDownloadEIPConfig.setPixmap(None) - self.ui.lblDownloadClientCert.setPixmap(None) - def _check_provider(self): """ SLOT @@ -447,28 +421,47 @@ class Wizard(QtGui.QWizard): self._complete_task(data, self.ui.lblCheckApiCert, True, self.SETUP_PROVIDER_PAGE) - def _download_eip_config(self, data): + def _service_selection_changed(self, service, state): """ SLOT - TRIGGER: self._eip_bootstrapper.download_config + TRIGGER: service_checkbox.stateChanged + Adds the service to the state if the state is checked, removes + it otherwise + + @param service: service to handle + @type service: str + @param state: state of the checkbox + @type state: int + """ + if state == QtCore.Qt.Checked: + self._selected_services = \ + self._selected_services.union({service}) + else: + self._selected_services = \ + self._selected_services.difference({service}) - Sets the status for the EIP config downloading check + def _populate_services(self): """ - self._complete_task(data, self.ui.lblDownloadEIPConfig) - self.ui.lblDownloadClientCert.setPixmap(self.QUESTION_ICON) - - def _download_client_certificate(self, data): + Loads the services that the provider provides into the UI for + the user to enable or disable """ - SLOT - TRIGGER: self._provider_bootstrapper.download_client_certificate + self.ui.grpServices.setTitle( + self.tr("Services by %s") % + (self._provider_config.get_name(),)) - Sets the status for the download client certificate check and - completes the page if passed. Also stops the eip bootstrapper - thread since it's not needed from this point on unless the - check chain is restarted - """ - self._complete_task(data, self.ui.lblDownloadClientCert, - True, self.SETUP_EIP_PAGE) + for service in self._provider_config.get_services(): + try: + checkbox = QtGui.QCheckBox(self) + service_index = self.SERVICE_CONFIG.index(service) + checkbox.setText(self.SERVICE_DISPLAY[service_index]) + self.ui.serviceListLayout.addWidget(checkbox) + checkbox.stateChanged.connect( + partial(self._service_selection_changed, service)) + checkbox.setChecked(True) + except ValueError: + logger.error( + self.tr("Something went wrong while trying to " + "load service %s" % (service,))) def _current_id_changed(self, pageId): """ @@ -492,12 +485,6 @@ class Wizard(QtGui.QWizard): run_provider_setup_checks(self._checker_thread, self._provider_config) - if pageId == self.SETUP_EIP_PAGE: - self._reset_eip_check() - self.ui.lblDownloadEIPConfig.setPixmap(self.QUESTION_ICON) - self._eip_bootstrapper.run_eip_setup_checks(self._checker_thread, - self._provider_config) - if pageId == self.PRESENT_PROVIDER_PAGE: self.page(pageId).setSubTitle(self.tr("Services offered by %s") % (self._provider_config @@ -521,6 +508,9 @@ class Wizard(QtGui.QWizard): (self._provider_config .get_name(),)) + if pageId == self.SERVICES_PAGE: + self._populate_services() + def nextId(self): """ Sets the next page id for the wizard based on wether the user @@ -533,6 +523,6 @@ class Wizard(QtGui.QWizard): if self._show_register: return self.REGISTER_USER_PAGE else: - return self.SETUP_EIP_PAGE + return self.SERVICES_PAGE return QtGui.QWizard.nextId(self) -- cgit v1.2.3