From 769f334a3a424612b454061f4dc3937e3e46071f Mon Sep 17 00:00:00 2001
From: Ivan Alejandro
Date: Mon, 11 Aug 2014 17:35:36 -0300
Subject: Do some pep8 fixes.
---
src/leap/bitmask/gui/mainwindow.py | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
(limited to 'src')
diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py
index 0518350e..c6fd12e1 100644
--- a/src/leap/bitmask/gui/mainwindow.py
+++ b/src/leap/bitmask/gui/mainwindow.py
@@ -1062,17 +1062,19 @@ class MainWindow(QtGui.QMainWindow):
help_url = "{0}
".format(
self.tr("bitmask.net/help"))
- lang = QtCore.QLocale.system().name().replace('_','-')
+ lang = QtCore.QLocale.system().name().replace('_', '-')
thunderbird_extension_url = \
"https://addons.mozilla.org/{0}/" \
"thunderbird/addon/bitmask/".format(lang)
email_quick_reference = self.tr("Email quick reference")
- thunderbird_text = self.tr("For Thunderbird, you can use the "
+ thunderbird_text = self.tr(
+ "For Thunderbird, you can use the "
"Bitmask extension. Search for \"Bitmask\" in the add-on "
"manager or download it from "
"addons.mozilla.org.".format(thunderbird_extension_url))
- manual_text = self.tr("Alternately, you can manually configure "
+ manual_text = self.tr(
+ "Alternately, you can manually configure "
"your mail client to use Bitmask Email with these options:")
manual_imap = self.tr("IMAP: localhost, port {0}".format(IMAP_PORT))
manual_smtp = self.tr("SMTP: localhost, port {0}".format(smtp_port))
@@ -1089,8 +1091,8 @@ class MainWindow(QtGui.QMainWindow):
" {5}"
" {6}"
"
").format(email_quick_reference, thunderbird_text,
- manual_text, manual_imap, manual_smtp,
- manual_username, manual_password)
+ manual_text, manual_imap, manual_smtp,
+ manual_username, manual_password)
QtGui.QMessageBox.about(self, self.tr("Bitmask Help"), msg)
def _needs_update(self):
@@ -1201,7 +1203,8 @@ class MainWindow(QtGui.QMainWindow):
eip_sigs = self._eip_conductor.qtsigs
eip_sigs.connected_signal.connect(self._download_provider_config)
eip_sigs.disconnected_signal.connect(self._download_provider_config)
- eip_sigs.connection_aborted_signal.connect(self._download_provider_config)
+ eip_sigs.connection_aborted_signal.connect(
+ self._download_provider_config)
eip_sigs.connection_died_signal.connect(self._download_provider_config)
def _disconnect_scheduled_login(self):
@@ -1211,18 +1214,17 @@ class MainWindow(QtGui.QMainWindow):
try:
eip_sigs = self._eip_conductor.qtsigs
eip_sigs.connected_signal.disconnect(
- self._download_provider_config)
+ self._download_provider_config)
eip_sigs.disconnected_signal.disconnect(
- self._download_provider_config)
+ self._download_provider_config)
eip_sigs.connection_aborted_signal.disconnect(
- self._download_provider_config)
+ self._download_provider_config)
eip_sigs.connection_died_signal.disconnect(
- self._download_provider_config)
+ self._download_provider_config)
except Exception:
# signal not connected
pass
-
@QtCore.Slot()
def _login(self):
"""
--
cgit v1.2.3
From 1d8fd48517a44f81d816eba2488e23fe3080f83b Mon Sep 17 00:00:00 2001
From: Ivan Alejandro
Date: Mon, 11 Aug 2014 15:48:54 -0300
Subject: Stop the services if the selected provider is changed.
Store the last 2 indexes on a deque and improve the 'select previous
provider' action.
---
src/leap/bitmask/gui/login.py | 46 +++++++++++++++++++---------
src/leap/bitmask/gui/mainwindow.py | 62 ++++++++++++++++++++++++++++++++++++--
2 files changed, 90 insertions(+), 18 deletions(-)
(limited to 'src')
diff --git a/src/leap/bitmask/gui/login.py b/src/leap/bitmask/gui/login.py
index 8e0a3a15..0e64bbcf 100644
--- a/src/leap/bitmask/gui/login.py
+++ b/src/leap/bitmask/gui/login.py
@@ -19,6 +19,8 @@ Login widget implementation
"""
import logging
+from collections import deque
+
from PySide import QtCore, QtGui
from ui_login import Ui_LoginWidget
@@ -43,9 +45,10 @@ class LoginWidget(QtGui.QWidget):
cancel_login = QtCore.Signal()
logout = QtCore.Signal()
- # Emitted when the user selects "Other..." in the provider
- # combobox or click "Create Account"
- show_wizard = 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
@@ -64,7 +67,9 @@ class LoginWidget(QtGui.QWidget):
QtGui.QWidget.__init__(self, parent)
self._settings = settings
- self._selected_provider_index = -1
+
+ self._providers_indexes = deque(maxlen=2) # previous and current
+ self._providers_indexes.append(-1)
self.ui = Ui_LoginWidget()
self.ui.setupUi(self)
@@ -132,7 +137,14 @@ class LoginWidget(QtGui.QWidget):
: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):
"""
@@ -267,17 +279,21 @@ class LoginWidget(QtGui.QWidget):
:param idx: the index of the new selected item
:type idx: int
"""
- if idx == (self.ui.cmbProviders.count() - 1):
- self.show_wizard.emit()
- # Leave the previously selected provider in the combobox
- prev_provider = 0
- if self._selected_provider_index != -1:
- prev_provider = self._selected_provider_index
- self.ui.cmbProviders.blockSignals(True)
- self.ui.cmbProviders.setCurrentIndex(prev_provider)
- self.ui.cmbProviders.blockSignals(False)
- else:
- self._selected_provider_index = idx
+ 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):
"""
diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py
index c6fd12e1..a85cb657 100644
--- a/src/leap/bitmask/gui/mainwindow.py
+++ b/src/leap/bitmask/gui/mainwindow.py
@@ -153,8 +153,8 @@ class MainWindow(QtGui.QMainWindow):
self._login_widget.login.connect(self._login)
self._login_widget.cancel_login.connect(self._cancel_login)
- self._login_widget.show_wizard.connect(self._launch_wizard)
self._login_widget.logout.connect(self._logout)
+ self._login_widget.provider_changed.connect(self._on_provider_changed)
# EIP Control redux #########################################
self._eip_conductor = eip_conductor.EIPConductor(
@@ -174,6 +174,8 @@ class MainWindow(QtGui.QMainWindow):
self._eip_conductor.connect_signals()
self._eip_conductor.qtsigs.connected_signal.connect(
self._on_eip_connection_connected)
+ self._eip_conductor.qtsigs.disconnected_signal.connect(
+ self._on_eip_connection_disconnected)
self._eip_conductor.qtsigs.connected_signal.connect(
self._maybe_run_soledad_setup_checks)
@@ -187,7 +189,6 @@ class MainWindow(QtGui.QMainWindow):
self._already_started_eip = False
self._trying_to_start_eip = False
- self._already_started_eip = False
self._soledad_started = False
# This is created once we have a valid provider config
@@ -502,7 +503,6 @@ class MainWindow(QtGui.QMainWindow):
def _launch_wizard(self):
"""
TRIGGERS:
- self._login_widget.show_wizard
self.ui.action_wizard.triggered
Also called in first run.
@@ -1225,6 +1225,52 @@ class MainWindow(QtGui.QMainWindow):
# signal not connected
pass
+ @QtCore.Slot(object)
+ def _on_provider_changed(self, wizard):
+ """
+ TRIGGERS:
+ self._login.provider_changed
+
+ Ask the user if really wants to change provider since a services stop
+ is required for that action.
+
+ :param wizard: whether the 'other...' option was picked or not.
+ :type wizard: bool
+ """
+ # TODO: we should handle the case that EIP is autostarting since we
+ # won't get a warning until EIP has fully started.
+ # TODO: we need to add a check for the mail status (smtp/imap/soledad)
+ something_runing = (self._logged_user is not None or
+ self._already_started_eip)
+ if not something_runing:
+ if wizard:
+ self._launch_wizard()
+ return
+
+ title = self.tr("Stop services")
+ text = self.tr("Do you want to stop all services?")
+ informative_text = self.tr("In order to change the provider, the "
+ "running services needs to be stopped.")
+
+ msg = QtGui.QMessageBox(self)
+ msg.setWindowTitle(title)
+ msg.setText(text)
+ msg.setInformativeText(informative_text)
+ msg.setStandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
+ msg.setDefaultButton(QtGui.QMessageBox.No)
+ msg.setIcon(QtGui.QMessageBox.Warning)
+ res = msg.exec_()
+
+ if res == QtGui.QMessageBox.Yes:
+ self._stop_services()
+ self._eip_conductor.qtsigs.do_disconnect_signal.emit()
+ if wizard:
+ self._launch_wizard()
+ else:
+ if not wizard:
+ # if wizard, the widget restores itself
+ self._login_widget.restore_previous_provider()
+
@QtCore.Slot()
def _login(self):
"""
@@ -1563,6 +1609,16 @@ class MainWindow(QtGui.QMainWindow):
# check for connectivity
self._backend.eip_check_dns(domain=domain)
+ @QtCore.Slot()
+ def _on_eip_connection_disconnected(self):
+ """
+ TRIGGERS:
+ self._eip_conductor.qtsigs.disconnected_signal
+
+ Set the eip status to not started.
+ """
+ self._already_started_eip = False
+
@QtCore.Slot()
def _set_eip_provider(self, country_code=None):
"""
--
cgit v1.2.3
From dd2097d27efc32820a25faff9236d091372f7930 Mon Sep 17 00:00:00 2001
From: Ivan Alejandro
Date: Tue, 12 Aug 2014 17:12:11 -0300
Subject: Ask for services stop when the wizard is needed.
---
src/leap/bitmask/gui/mainwindow.py | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
(limited to 'src')
diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py
index a85cb657..03f91996 100644
--- a/src/leap/bitmask/gui/mainwindow.py
+++ b/src/leap/bitmask/gui/mainwindow.py
@@ -215,8 +215,9 @@ class MainWindow(QtGui.QMainWindow):
self.ui.action_wizard.triggered.connect(self._launch_wizard)
self.ui.action_show_logs.triggered.connect(self._show_logger_window)
self.ui.action_help.triggered.connect(self._help)
+
self.ui.action_create_new_account.triggered.connect(
- self._launch_wizard)
+ self._on_provider_changed)
self.ui.action_advanced_key_management.triggered.connect(
self._show_AKM)
@@ -1226,10 +1227,11 @@ class MainWindow(QtGui.QMainWindow):
pass
@QtCore.Slot(object)
- def _on_provider_changed(self, wizard):
+ def _on_provider_changed(self, wizard=True):
"""
TRIGGERS:
self._login.provider_changed
+ self.ui.action_create_new_account.triggered
Ask the user if really wants to change provider since a services stop
is required for that action.
@@ -1251,6 +1253,9 @@ class MainWindow(QtGui.QMainWindow):
text = self.tr("Do you want to stop all services?")
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)
--
cgit v1.2.3