diff options
Diffstat (limited to 'src/leap/gui')
-rwxr-xr-x | src/leap/gui/firstrunwizard.py | 347 |
1 files changed, 280 insertions, 67 deletions
diff --git a/src/leap/gui/firstrunwizard.py b/src/leap/gui/firstrunwizard.py index a76865fd..0cf46956 100755 --- a/src/leap/gui/firstrunwizard.py +++ b/src/leap/gui/firstrunwizard.py @@ -13,7 +13,16 @@ from PyQt4 import QtGui from leap.crypto import leapkeyring from leap.gui import mainwindow_rc +try: + from collections import OrderedDict +except ImportError: + # We must be in 2.6 + from leap.util.dicts import OrderedDict + +# XXX DEBUG +logging.basicConfig() logger = logging.getLogger(__name__) +logger.setLevel(logging.DEBUG) APP_LOGO = ':/images/leap-color-small.png' @@ -77,7 +86,7 @@ class LeapSRPRegister(object): def register_user(self, username, password, keep=False): """ @rtype: tuple - @rvalue: (ok, request) + @rparam: (ok, request) """ salt, vkey = self.srp.create_salted_verification_key( username, @@ -116,7 +125,7 @@ class FirstRunWizard(QtGui.QWizard): def __init__( self, parent=None, providers=None, - success_cb=None): + success_cb=None, is_provider_setup=False): super(FirstRunWizard, self).__init__( parent, QtCore.Qt.WindowStaysOnTopHint) @@ -129,12 +138,30 @@ class FirstRunWizard(QtGui.QWizard): # success callback self.success_cb = success_cb - self.addPage(IntroPage()) - self.addPage(SelectProviderPage(providers=providers)) - - self.addPage(RegisterUserPage(wizard=self)) - #self.addPage(GlobalEIPSettings()) - self.addPage(LastPage()) + # is provider setup? + self.is_provider_setup = is_provider_setup + + # FIXME remove kwargs, we can access + # wizard as self.wizard() + + # FIXME add param for previously_registered + # should start at login page. + + pages_dict = OrderedDict(( + # (name, (WizardPage, **kwargs)) + ('intro', (IntroPage, {})), + ('providerselection', ( + SelectProviderPage, + {'providers': providers})), + ('login', (LogInPage, {})), + ('providerinfo', (ProviderInfoPage, {})), + ('providersetup', (ProviderSetupPage, {})), + ('signup', ( + RegisterUserPage, {})), + ('connecting', (ConnectingPage, {})), + ('lastpage', (LastPage, {})) + )) + self.add_pages_from_dict(pages_dict) self.setPixmap( QtGui.QWizard.BannerPixmap, @@ -148,6 +175,41 @@ class FirstRunWizard(QtGui.QWizard): # TODO: set style for MAC / windows ... #self.setWizardStyle() + def add_pages_from_dict(self, pages_dict): + """ + @param pages_dict: the dictionary with pages, where + values are a tuple of InstanceofWizardPage, kwargs. + @type pages_dict: dict + """ + for name, (page, page_args) in pages_dict.items(): + self.addPage(page(**page_args)) + self.pages_dict = pages_dict + + def get_page_index(self, page_name): + """ + returns the index of the given page + @param page_name: the name of the desired page + @type page_name: str + @rparam: index of page in wizard + @rtype: int + """ + return self.pages_dict.keys().index(page_name) + + #def get_page(self, page_name): + #""" + #returns a wizard page doing a lookup for + #the page_name in the pages dictionary + #@param page_name: the page name to lookup + #@type page_name: str + #""" + #logger.debug('getting page %s' % page_name) + #page_tuple = self.pages_dict.get(page_name, None) + #if not page_tuple: + #return None + #wizard_page, args = page_tuple + #logger.debug('wizard page %s', wizard_page) + #return wizard_page + def setWindowFlags(self, flags): logger.debug('setting window flags') QtGui.QWizard.setWindowFlags(self, flags) @@ -224,14 +286,40 @@ class IntroPage(QtGui.QWizardPage): "can connect for the first time.<br><br>" "If you ever need to modify these options again, " "you can find the wizard in the '<i>Settings</i>' menu from the " - "main window of the Leap App.") - + "main window.<br><br>" + "Do you want to <b>sign up</b> for a new account, or <b>log " + "in</b> with an already existing username?<br>") label.setWordWrap(True) + self.sign_up = QtGui.QRadioButton( + "Sign up for a new account.") + self.sign_up.setChecked(True) + self.log_in = QtGui.QRadioButton( + "Log In with my credentials.") + layout = QtGui.QVBoxLayout() layout.addWidget(label) + layout.addWidget(self.sign_up) + layout.addWidget(self.log_in) self.setLayout(layout) + self.registerField('is_signup', self.sign_up) + + def validatePage(self): + return True + + def nextId(self): + """ + returns next id + in a non-linear wizard + """ + if self.sign_up.isChecked(): + next_ = 'providerselection' + if self.log_in.isChecked(): + next_ = 'login' + wizard = self.wizard() + return wizard.get_page_index(next_) + class SelectProviderPage(QtGui.QWizardPage): def __init__(self, parent=None, providers=None): @@ -263,74 +351,54 @@ class SelectProviderPage(QtGui.QWizardPage): layout.addWidget(providerNameSelect, 0, 1) self.setLayout(layout) + def validatePage(self): + # XXX just DEBUGGING ..>! + wizard = self.wizard() + if bool(wizard): + logger.debug('current: %s', wizard.currentPage()) + return True -class RegisterUserPage(QtGui.QWizardPage): - setSigningUpStatus = QtCore.pyqtSignal([]) - - def __init__(self, parent=None, wizard=None): - super(RegisterUserPage, self).__init__(parent) - - # bind wizard page signals - self.setSigningUpStatus.connect( - self.set_status_validating) - - # XXX check for no wizard pased - # getting provider from previous step - provider = wizard.get_provider() - - self.setTitle("User registration") - self.setSubTitle( - "Register a new user with provider %s." % - provider) - self.setPixmap( - QtGui.QWizard.LogoPixmap, - QtGui.QPixmap(APP_LOGO)) - - rememberPasswordCheckBox = QtGui.QCheckBox( - "&Remember password.") - rememberPasswordCheckBox.setChecked(True) - - userNameLabel = QtGui.QLabel("User &name:") - userNameLineEdit = QtGui.QLineEdit() - userNameLineEdit.cursorPositionChanged.connect( - self.reset_validation_status) - userNameLabel.setBuddy(userNameLineEdit) - - # add regex validator - usernameRe = QtCore.QRegExp(r"^[A-Za-z\d_]+$") - userNameLineEdit.setValidator( - QtGui.QRegExpValidator(usernameRe, self)) - self.userNameLineEdit = userNameLineEdit + def nextId(self): + wizard = self.wizard() + if not wizard: + return + return wizard.get_page_index('providerinfo') - userPasswordLabel = QtGui.QLabel("&Password:") - self.userPasswordLineEdit = QtGui.QLineEdit() - self.userPasswordLineEdit.setEchoMode( - QtGui.QLineEdit.Password) - userPasswordLabel.setBuddy(self.userPasswordLineEdit) +class ProviderInfoPage(QtGui.QWizardPage): + def __init__(self, parent=None): + super(ProviderInfoPage, self).__init__(parent) - self.registerField('userName', self.userNameLineEdit) - self.registerField('userPassword', self.userPasswordLineEdit) - self.registerField('rememberPassword', rememberPasswordCheckBox) + self.setTitle("Provider Info") + self.setSubTitle("Available information about chosen provider.") - layout = QtGui.QGridLayout() - layout.setColumnMinimumWidth(0, 20) + def nextId(self): + wizard = self.wizard() + if not wizard: + return + return wizard.get_page_index('providersetup') - validationMsg = QtGui.QLabel("") - validationMsg.setStyleSheet(ErrorLabelStyleSheet) - self.validationMsg = validationMsg +class ProviderSetupPage(QtGui.QWizardPage): + def __init__(self, parent=None): + super(ProviderSetupPage, self).__init__(parent) - layout.addWidget(validationMsg, 0, 3) + self.setTitle("Provider Setup") + self.setSubTitle("Setting up provider.") - layout.addWidget(userNameLabel, 1, 0) - layout.addWidget(self.userNameLineEdit, 1, 3) + def nextId(self): + wizard = self.wizard() + if not wizard: + return + is_signup = self.field('is_signup') + if is_signup is True: + next_ = 'signup' + if is_signup is False: + next_ = 'connecting' + return wizard.get_page_index(next_) - layout.addWidget(userPasswordLabel, 2, 0) - layout.addWidget(self.userPasswordLineEdit, 2, 3) - layout.addWidget(rememberPasswordCheckBox, 3, 3, 3, 4) - self.setLayout(layout) +class UserFormMixIn(object): def reset_validation_status(self): """ @@ -352,6 +420,8 @@ class RegisterUserPage(QtGui.QWizardPage): self.validationMsg.setText('registering...') # need to call update somehow??? + # XXX refactor set_status_foo + def set_status_invalid_username(self): """ set validation msg to @@ -389,6 +459,130 @@ class RegisterUserPage(QtGui.QWizardPage): """ self.validationMsg.setText("Error during signup") + +class LogInPage(QtGui.QWizardPage, UserFormMixIn): + def __init__(self, parent=None): + super(LogInPage, self).__init__(parent) + + self.setTitle("Log In") + self.setSubTitle("Log in with your credentials.") + + userNameLabel = QtGui.QLabel("User &name:") + userNameLineEdit = QtGui.QLineEdit() + userNameLineEdit.cursorPositionChanged.connect( + self.reset_validation_status) + userNameLabel.setBuddy(userNameLineEdit) + + # add regex validator + usernameRe = QtCore.QRegExp(r"^[A-Za-z\d_]+$") + userNameLineEdit.setValidator( + QtGui.QRegExpValidator(usernameRe, self)) + self.userNameLineEdit = userNameLineEdit + + userPasswordLabel = QtGui.QLabel("&Password:") + self.userPasswordLineEdit = QtGui.QLineEdit() + self.userPasswordLineEdit.setEchoMode( + QtGui.QLineEdit.Password) + userPasswordLabel.setBuddy(self.userPasswordLineEdit) + + self.registerField('log_in_userName*', self.userNameLineEdit) + self.registerField('log_in_userPassword*', self.userPasswordLineEdit) + + layout = QtGui.QGridLayout() + layout.setColumnMinimumWidth(0, 20) + + validationMsg = QtGui.QLabel("") + validationMsg.setStyleSheet(ErrorLabelStyleSheet) + + self.validationMsg = validationMsg + + layout.addWidget(validationMsg, 0, 3) + + layout.addWidget(userNameLabel, 1, 0) + layout.addWidget(self.userNameLineEdit, 1, 3) + + layout.addWidget(userPasswordLabel, 2, 0) + layout.addWidget(self.userPasswordLineEdit, 2, 3) + + self.setLayout(layout) + + def nextId(self): + wizard = self.wizard() + if not wizard: + return + if wizard.is_provider_setup is True: + next_ = 'connecting' + if wizard.is_provider_setup is False: + next_ = 'providersetup' + return wizard.get_page_index(next_) + + +class RegisterUserPage(QtGui.QWizardPage, UserFormMixIn): + setSigningUpStatus = QtCore.pyqtSignal([]) + + def __init__(self, parent=None): + super(RegisterUserPage, self).__init__(parent) + + # bind wizard page signals + self.setSigningUpStatus.connect( + self.set_status_validating) + + wizard = self.wizard() + provider = wizard.get_provider() if wizard else None + + self.setTitle("User registration") + self.setSubTitle( + "Register a new user with provider %s." % + provider) + self.setPixmap( + QtGui.QWizard.LogoPixmap, + QtGui.QPixmap(APP_LOGO)) + + userNameLabel = QtGui.QLabel("User &name:") + userNameLineEdit = QtGui.QLineEdit() + userNameLineEdit.cursorPositionChanged.connect( + self.reset_validation_status) + userNameLabel.setBuddy(userNameLineEdit) + + # add regex validator + usernameRe = QtCore.QRegExp(r"^[A-Za-z\d_]+$") + userNameLineEdit.setValidator( + QtGui.QRegExpValidator(usernameRe, self)) + self.userNameLineEdit = userNameLineEdit + + userPasswordLabel = QtGui.QLabel("&Password:") + self.userPasswordLineEdit = QtGui.QLineEdit() + self.userPasswordLineEdit.setEchoMode( + QtGui.QLineEdit.Password) + userPasswordLabel.setBuddy(self.userPasswordLineEdit) + + rememberPasswordCheckBox = QtGui.QCheckBox( + "&Remember username and password.") + rememberPasswordCheckBox.setChecked(True) + + self.registerField('userName*', self.userNameLineEdit) + self.registerField('userPassword*', self.userPasswordLineEdit) + self.registerField('rememberPassword', rememberPasswordCheckBox) + + layout = QtGui.QGridLayout() + layout.setColumnMinimumWidth(0, 20) + + validationMsg = QtGui.QLabel("") + validationMsg.setStyleSheet(ErrorLabelStyleSheet) + + self.validationMsg = validationMsg + + layout.addWidget(validationMsg, 0, 3) + + layout.addWidget(userNameLabel, 1, 0) + layout.addWidget(self.userNameLineEdit, 1, 3) + + layout.addWidget(userPasswordLabel, 2, 0) + layout.addWidget(self.userPasswordLineEdit, 2, 3) + + layout.addWidget(rememberPasswordCheckBox, 3, 3, 3, 4) + self.setLayout(layout) + # overwritten methods def initializePage(self): @@ -456,17 +650,36 @@ class RegisterUserPage(QtGui.QWizardPage): logger.debug('validation errors: %s' % validation_msgs) errors = validation_msgs.get('errors', None) if errors and errors.get('login', None): + # XXX this sometimes catch the blank username + # but we're not allowing that (soon) self.set_status_invalid_username() else: self.set_status_unknown_error() return False + def nextId(self): + wizard = self.wizard() + if not wizard: + return + return wizard.get_page_index('connecting') + class GlobalEIPSettings(QtGui.QWizardPage): + """ + not in use right now + """ def __init__(self, parent=None): super(GlobalEIPSettings, self).__init__(parent) +class ConnectingPage(QtGui.QWizardPage): + def __init__(self, parent=None): + super(ConnectingPage, self).__init__(parent) + + self.setTitle("Connecting") + self.setSubTitle('Connecting to provider.') + + class LastPage(QtGui.QWizardPage): def __init__(self, parent=None): super(LastPage, self).__init__(parent) |