summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/gui/mainwindow.py
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2014-09-22 16:17:02 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2014-09-22 16:17:02 -0300
commitc1fa3959fbffb381e067dcd619d528412e235401 (patch)
tree72662a8d2102dd782d68006d69e3b3058d8bd899 /src/leap/bitmask/gui/mainwindow.py
parent30fe51fa5c90a5ec08491b6d3f8524838ec75ac2 (diff)
parent668a9f9aa327c3c055b9e0f641f8c33d59e1c452 (diff)
Merge remote-tracking branch 'elijah/feature/prefui' into develop
Diffstat (limited to 'src/leap/bitmask/gui/mainwindow.py')
-rw-r--r--src/leap/bitmask/gui/mainwindow.py112
1 files changed, 35 insertions, 77 deletions
diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py
index 916e7c1f..cc4ede09 100644
--- a/src/leap/bitmask/gui/mainwindow.py
+++ b/src/leap/bitmask/gui/mainwindow.py
@@ -37,7 +37,6 @@ from leap.bitmask.config import flags
from leap.bitmask.config.leapsettings import LeapSettings
from leap.bitmask.gui.advanced_key_management import AdvancedKeyManagement
-from leap.bitmask.gui.eip_preferenceswindow import EIPPreferencesWindow
from leap.bitmask.gui.eip_status import EIPStatusWidget
from leap.bitmask.gui.loggerwindow import LoggerWindow
from leap.bitmask.gui.login import LoginWidget
@@ -46,6 +45,8 @@ 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.gui.account import Account
+from leap.bitmask.gui.app import App
from leap.bitmask.platform_init import IS_WIN, IS_MAC, IS_LINUX
from leap.bitmask.platform_init import locks
@@ -124,19 +125,10 @@ class MainWindow(QtGui.QMainWindow):
self.ui.setupUi(self)
self.menuBar().setNativeMenuBar(not IS_LINUX)
- self._backend = BackendProxy()
-
- # periodically check if the backend is alive
- self._backend_checker = QtCore.QTimer(self)
- self._backend_checker.timeout.connect(self._check_backend_status)
- self._backend_checker.start(2000)
-
- self._leap_signaler = LeapSignaler()
- self._leap_signaler.start()
-
- self._settings = LeapSettings()
- # gateway = self._settings.get_selected_gateway(provider)
- # self._backend.settings_set_selected_gateway(provider, gateway)
+ self.app = App()
+ self._backend = self.app.backend
+ self._leap_signaler = self.app.signaler
+ self._settings = self.app.settings
# Login Widget
self._login_widget = LoginWidget(self._settings, self)
@@ -152,6 +144,7 @@ class MainWindow(QtGui.QMainWindow):
# Qt Signal Connections #####################################
# TODO separate logic from ui signals.
+ self.app.service_selection_changed.connect(self._update_eip_enabled_status)
self._login_widget.login.connect(self._login)
self._login_widget.cancel_login.connect(self._cancel_login)
self._login_widget.logout.connect(self._logout)
@@ -213,8 +206,6 @@ class MainWindow(QtGui.QMainWindow):
self._backend_connect()
self.ui.action_preferences.triggered.connect(self._show_preferences)
- self.ui.action_eip_preferences.triggered.connect(
- self._show_eip_preferences)
self.ui.action_about_leap.triggered.connect(self._about)
self.ui.action_quit.triggered.connect(self.quit)
self.ui.action_wizard.triggered.connect(self._launch_wizard)
@@ -245,10 +236,6 @@ class MainWindow(QtGui.QMainWindow):
self._action_visible = QtGui.QAction(self.tr("Show Main Window"), self)
self._action_visible.triggered.connect(self._ensure_visible)
- # disable buttons for now, may come back later.
- # self.ui.btnPreferences.clicked.connect(self._show_preferences)
- # self.ui.btnEIPPreferences.clicked.connect(self._show_eip_preferences)
-
self._enabled_services = []
self._ui_mx_visible = True
self._ui_eip_visible = True
@@ -343,23 +330,6 @@ class MainWindow(QtGui.QMainWindow):
logger.error("Bad call to the backend:")
logger.error(data)
- @QtCore.Slot()
- def _check_backend_status(self):
- """
- TRIGGERS:
- self._backend_checker.timeout
-
- Check that the backend is running. Otherwise show an error to the user.
- """
- online = self._backend.online
- if not online:
- logger.critical("Backend is not online.")
- QtGui.QMessageBox.critical(
- self, self.tr("Application error"),
- self.tr("There is a problem contacting the backend, please "
- "restart Bitmask."))
- self._backend_checker.stop()
-
def _backend_connect(self, only_tracked=False):
"""
Connect to backend signals.
@@ -599,24 +569,16 @@ class MainWindow(QtGui.QMainWindow):
Display the preferences window.
"""
- user = self._logged_user
- 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']
- preferences = PreferencesWindow(self, user, domain, self._backend,
- self._soledad_started, mx_provided,
- self._leap_signaler)
+ account = Account(self._logged_user,
+ self._providers.get_selected_provider())
+ pref_win = PreferencesWindow(self, account, self.app)
+ pref_win.show()
- self.soledad_ready.connect(preferences.set_soledad_ready)
- preferences.show()
- preferences.preferences_saved.connect(self._update_eip_enabled_status)
-
- @QtCore.Slot()
- def _update_eip_enabled_status(self):
+ @QtCore.Slot(object, list)
+ def _update_eip_enabled_status(self, account=None, services=None):
"""
TRIGGER:
- PreferencesWindow.preferences_saved
+ App.service_selection_changed
Enable or disable the EIP start/stop actions and stop EIP if the user
disabled that service.
@@ -624,24 +586,35 @@ class MainWindow(QtGui.QMainWindow):
:returns: if the eip actions were enabled or disabled
:rtype: bool
"""
- settings = self._settings
- default_provider = settings.get_defaultprovider()
+ if account is not None:
+ domain = account.domain
+ else:
+ # I am not sure why, but asking for the currently selected
+ # provider here give you the WRONG provider
+ domain = self.app.settings.get_defaultprovider()
- if default_provider is None:
+ if domain is None:
logger.warning("Trying to update eip enabled status but there's no"
" default provider. Disabling EIP for the time"
" being...")
self._backend_cannot_start_eip()
return
- self._trying_to_start_eip = settings.get_autostart_eip()
- self._backend.eip_can_start(domain=default_provider)
+ if not EIP_SERVICE in self.app.settings.get_enabled_services(domain):
+ self._eip_conductor.terminate()
+ def hide():
+ self.app.backend.eip_can_start(domain=domain)
+ QtDelayedCall(100, hide)
+ # ^^ VERY VERY Hacky, but with the simple state machine,
+ # there is no way to signal 'disconnect and then disable'
+
+ else:
+ self._trying_to_start_eip = self.app.settings.get_autostart_eip()
+ if not self._trying_to_start_eip:
+ self._backend.eip_setup(provider=domain, skip_network=True)
+ # check if EIP can start (will trigger widget update)
+ self.app.backend.eip_can_start(domain=domain)
- # If we don't want to start eip, we leave everything
- # initialized to quickly start it
- if not self._trying_to_start_eip:
- self._backend.eip_setup(provider=default_provider,
- skip_network=True)
def _backend_can_start_eip(self):
"""
@@ -661,7 +634,6 @@ class MainWindow(QtGui.QMainWindow):
enabled_services = []
if default_provider is not None:
enabled_services = settings.get_enabled_services(default_provider)
-
eip_enabled = False
if EIP_SERVICE in enabled_services:
eip_enabled = True
@@ -718,20 +690,6 @@ class MainWindow(QtGui.QMainWindow):
"""
self._eip_status.missing_helpers = True
- @QtCore.Slot()
- def _show_eip_preferences(self):
- """
- TRIGGERS:
- self.ui.btnEIPPreferences.clicked
- self.ui.action_eip_preferences (disabled for now)
-
- Display the EIP preferences window.
- """
- domain = self._providers.get_selected_provider()
- pref = EIPPreferencesWindow(self, domain,
- self._backend, self._leap_signaler)
- pref.show()
-
#
# updates
#