summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/bitmask/gui')
-rw-r--r--src/leap/bitmask/gui/account.py4
-rw-r--r--src/leap/bitmask/gui/app.py2
-rw-r--r--src/leap/bitmask/gui/eip_status.py3
-rw-r--r--src/leap/bitmask/gui/login.py6
-rw-r--r--src/leap/bitmask/gui/mail_status.py44
-rw-r--r--src/leap/bitmask/gui/mainwindow.py48
-rw-r--r--src/leap/bitmask/gui/passwordwindow.py13
-rw-r--r--src/leap/bitmask/gui/preferenceswindow.py2
8 files changed, 94 insertions, 28 deletions
diff --git a/src/leap/bitmask/gui/account.py b/src/leap/bitmask/gui/account.py
index c941c3fa..81f96389 100644
--- a/src/leap/bitmask/gui/account.py
+++ b/src/leap/bitmask/gui/account.py
@@ -43,7 +43,7 @@ class Account():
return self._settings.get_enabled_services(self.domain)
def is_email_enabled(self):
- MX_SERVICE in self.services()
+ return MX_SERVICE in self.services()
def is_eip_enabled(self):
- EIP_SERVICE in self.services()
+ return EIP_SERVICE in self.services()
diff --git a/src/leap/bitmask/gui/app.py b/src/leap/bitmask/gui/app.py
index 02357b2b..97fd0549 100644
--- a/src/leap/bitmask/gui/app.py
+++ b/src/leap/bitmask/gui/app.py
@@ -43,6 +43,8 @@ class App(QtGui.QWidget):
self.signaler = LeapSignaler()
self.signaler.start()
+ self.soledad_started = False
+
# periodically check if the backend is alive
self._backend_checker = QtCore.QTimer(self)
self._backend_checker.timeout.connect(self._check_backend_status)
diff --git a/src/leap/bitmask/gui/eip_status.py b/src/leap/bitmask/gui/eip_status.py
index 8334c2ee..64a408c4 100644
--- a/src/leap/bitmask/gui/eip_status.py
+++ b/src/leap/bitmask/gui/eip_status.py
@@ -96,7 +96,8 @@ class EIPStatusWidget(QtGui.QWidget):
# Action for the systray
self._eip_disabled_action = QtGui.QAction(
- u"{0} is {1}".format(self._service_name, self.tr("disabled")), self)
+ u"{0} is {1}".format(
+ self._service_name, self.tr("disabled")), self)
def connect_backend_signals(self):
"""
diff --git a/src/leap/bitmask/gui/login.py b/src/leap/bitmask/gui/login.py
index 756dd63c..4c2bd9c5 100644
--- a/src/leap/bitmask/gui/login.py
+++ b/src/leap/bitmask/gui/login.py
@@ -19,10 +19,12 @@ Login widget implementation
The login sequence is the following:
- _do_login
- - backend.provider_setup (check_name_resolution, check_https, download_provider_info)
+ - backend.provider_setup (
+ check_name_resolution, check_https, download_provider_info)
- on error: _provider_setup_intermediate
- on success: _load_provider_config
- - backend.provider_bootstrap (download_ca_cert, check_ca_fingerprint, check_api_certificate)
+ - backend.provider_bootstrap (
+ download_ca_cert, check_ca_fingerprint, check_api_certificate)
- on error: _provider_setup_intermediate
- on success: _provider_config_loaded
- backend.user_login
diff --git a/src/leap/bitmask/gui/mail_status.py b/src/leap/bitmask/gui/mail_status.py
index 1a38c8cf..eebae49b 100644
--- a/src/leap/bitmask/gui/mail_status.py
+++ b/src/leap/bitmask/gui/mail_status.py
@@ -53,6 +53,8 @@ class MailStatusWidget(QtGui.QWidget):
self._disabled = True
self._started = False
+ self._unread_mails = 0
+
self.ui = Ui_MailStatusWidget()
self.ui.setupUi(self)
@@ -92,6 +94,8 @@ class MailStatusWidget(QtGui.QWidget):
callback=self._mail_handle_soledad_events)
register(event=catalog.SOLEDAD_INVALID_AUTH_TOKEN,
callback=self.set_soledad_invalid_auth_token)
+ register(event=catalog.SOLEDAD_DONE_DATA_SYNC,
+ callback=self._mail_handle_soledad_events)
register(event=catalog.MAIL_UNREAD_MESSAGES,
callback=self._mail_handle_imap_events)
@@ -277,6 +281,14 @@ class MailStatusWidget(QtGui.QWidget):
ext_status = self.tr("Sync: upload complete.")
ready = 2
+ elif event == catalog.SOLEDAD_DONE_DATA_SYNC:
+ if self._unread_mails > 0:
+ self._show_unread_mails()
+ return
+ else:
+ ext_status = self.tr("Sync: completed.")
+
+ ready = 2
else:
leap_assert(False,
"Don't know how to handle this state: %s"
@@ -395,21 +407,33 @@ class MailStatusWidget(QtGui.QWidget):
# We could make this configurable to include all unread mail
# or all unread mail in subscribed folders.
if self._started:
- count = content
- if count != "0":
- status = self.tr("{0} Unread Emails "
- "in your Inbox").format(count)
- if count == "1":
- status = self.tr("1 Unread Email in your Inbox")
-
- self._set_mail_status(status, ready=2)
- else:
- self._set_mail_status("", ready=2)
+ try:
+ self._unread_mails = int(content)
+ except:
+ self._unread_mails = 0
+
+ self._show_unread_mails()
elif event == catalog.IMAP_SERVICE_STARTED:
self._imap_started = True
if ext_status is not None:
self._set_mail_status(ext_status, ready=1)
+ def _show_unread_mails(self):
+ """
+ Show the user the amount of unread emails.
+ """
+ count = self._unread_mails
+
+ if count > 0:
+ status = self.tr("{0} Unread Emails "
+ "in your Inbox").format(count)
+ if count == 1:
+ status = self.tr("1 Unread Email in your Inbox")
+
+ self._set_mail_status(status, ready=2)
+ else:
+ self._set_mail_status("", ready=2)
+
def about_to_start(self):
"""
Display the correct UI for the point where mail components
diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py
index 312048ba..387c6283 100644
--- a/src/leap/bitmask/gui/mainwindow.py
+++ b/src/leap/bitmask/gui/mainwindow.py
@@ -17,8 +17,11 @@
"""
Main window for Bitmask.
"""
+import os
import time
+import ConfigParser
+
from datetime import datetime
import psutil
@@ -198,8 +201,6 @@ class MainWindow(QtGui.QMainWindow, SignalTracker):
self._login_widget.login_offline_finished.connect(
self._maybe_run_soledad_setup_checks)
- self._soledad_started = False
-
# This is created once we have a valid provider config
self._logged_in_offline = False
@@ -541,7 +542,7 @@ class MainWindow(QtGui.QMainWindow, SignalTracker):
# XXX: handle differently not logged in user?
akm = AdvancedKeyManagement(self, mx_provided, logged_user,
- self._backend, self._soledad_started)
+ self._backend, self.app.soledad_started)
akm.show()
def _show_preferences(self):
@@ -781,6 +782,10 @@ class MainWindow(QtGui.QMainWindow, SignalTracker):
if self._wizard:
self._load_from_wizard()
else:
+ if self._load_credentials_from_env():
+ self._login()
+ return
+
domain = self._settings.get_provider()
if domain is not None:
self._providers.select_provider_by_name(domain)
@@ -796,6 +801,35 @@ class MainWindow(QtGui.QMainWindow, SignalTracker):
if self._login_widget.load_user_from_keyring(saved_user):
self._login()
+ def _load_credentials_from_env(self):
+ """
+ Load username and password into the login widget from a file specified
+ in an environment variable. This is useful for test purposes.
+
+ :return: True if credentials were loaded, False otherwise
+ :rtype: bool
+ """
+ credentials = os.environ.get("BITMASK_CREDENTIALS")
+
+ if credentials is None:
+ return False
+
+ try:
+ config = ConfigParser.ConfigParser()
+ config.read(credentials)
+ username, domain = config.get('Credentials', 'username').split('@')
+ password = config.get('Credentials', 'password')
+ except Exception, e:
+ print "Error reading credentials file: {0}".format(e)
+ return False
+
+ self._providers.select_provider_by_name(domain)
+ self._login_widget.set_provider(domain)
+ self._login_widget.set_user(username)
+ self._login_widget.set_password(password)
+
+ return True
+
def _show_hide_unsupported_services(self):
"""
Given a set of configured providers, it creates a set of
@@ -1202,7 +1236,7 @@ class MainWindow(QtGui.QMainWindow, SignalTracker):
self._backend.soledad_cancel_bootstrap()
self._backend.soledad_close()
- self._soledad_started = False
+ self.app.soledad_started = True
def _on_user_logged_in(self):
"""
@@ -1378,7 +1412,7 @@ class MainWindow(QtGui.QMainWindow, SignalTracker):
"""
logger.debug("Done bootstrapping Soledad")
- self._soledad_started = True
+ self.app.soledad_started = True
self.soledad_ready.emit()
###################################################################
@@ -1604,14 +1638,12 @@ class MainWindow(QtGui.QMainWindow, SignalTracker):
# window handling methods
#
- def _on_raise_window_event(self, event, content):
+ def _on_raise_window_event(self, event):
"""
Callback for the raise window event
:param event: The event that triggered the callback.
:type event: str
- :param content: The content of the event.
- :type content: list
"""
if IS_WIN:
locks.raise_window_ack()
diff --git a/src/leap/bitmask/gui/passwordwindow.py b/src/leap/bitmask/gui/passwordwindow.py
index 94cf25da..dedfcb10 100644
--- a/src/leap/bitmask/gui/passwordwindow.py
+++ b/src/leap/bitmask/gui/passwordwindow.py
@@ -71,9 +71,10 @@ class PasswordWindow(QtGui.QDialog, Flashable):
self.ui.cancel_button.setEnabled(True)
self.flash_error(self.tr("Please log in to change your password."))
- if self.is_soledad_needed() and not self._soledad_ready:
+ if self.is_soledad_needed() and not self.app.soledad_started:
self._enable_password_widgets(False)
self.ui.cancel_button.setEnabled(True)
+
self.flash_message(
self.tr("Please wait for data storage to be ready."))
@@ -146,7 +147,6 @@ class PasswordWindow(QtGui.QDialog, Flashable):
sig.soledad_password_change_error.connect(
self._soledad_change_password_problem)
- self._soledad_ready = False
sig.soledad_bootstrap_finished.connect(self._on_soledad_ready)
def _change_password(self):
@@ -203,8 +203,14 @@ class PasswordWindow(QtGui.QDialog, Flashable):
new_password = self.ui.new_password_lineedit.text()
logger.debug("SRP password changed successfully.")
+ # FIXME ---- both changes need to be made atomically!
+ # if there is some problem changing password in soledad (for instance,
+ # it checks for length), any exception raised will be lost and we will
+ # have an inconsistent state between soledad and srp passwords.
+ # We need to implement rollaback.
+
if self.is_soledad_needed():
- self._backend.soledad_change_password(new_password=new_password)
+ self.app.backend.soledad_change_password(new_password=new_password)
else:
self._change_password_success()
@@ -263,4 +269,3 @@ class PasswordWindow(QtGui.QDialog, Flashable):
Signaler.soledad_bootstrap_finished
"""
self._enable_password_widgets(True)
- self._soledad_ready = True
diff --git a/src/leap/bitmask/gui/preferenceswindow.py b/src/leap/bitmask/gui/preferenceswindow.py
index baa71252..44c4641c 100644
--- a/src/leap/bitmask/gui/preferenceswindow.py
+++ b/src/leap/bitmask/gui/preferenceswindow.py
@@ -70,7 +70,7 @@ class PreferencesWindow(QtGui.QDialog):
# only allow a single preferences window at a time.
if PreferencesWindow._current_window is not None:
- PreferencesWindow._current_window.close_window()
+ PreferencesWindow._current_window.close()
PreferencesWindow._current_window = self
def _add_icons(self):