def online(self): global logger if self.status is not self.OFFLINE: return self._error("Not currently offline.") st = self.settings logger.debug("Going online...") entries = [entry for userName, keyId, entry in listProfiles()] if not st.getInt("Settings/RememberKey", 0): return self._error("No key found.") entry = st.getString("Settings/SavedProfile") password = st.getString("Settings/SavedPassword") if not (entry and password and (entry in entries)): return self._error("No profile or password.") profile = loadProfile(entry, password) if not profile: return self._error("Profile couldn't be loaded.") self.profile = profile logger.debug("Going online as %s keyID=%s ..." % (profile.name, profile.keyId)) self.session.goOnline(self.profile) self.reconnector = Reconnector(self.profile, self._onReconnectTimer, self.reactor) return True
def _doCheckSettings( self ) : st = localSettings() windowWidth = st.getInt( 'Settings/WindowWidth', 0 ) windowHeight = st.getInt( 'Settings/WindowHeight', 0 ) if (windowWidth > 0) and (windowHeight > 0) : windowWidth = max( windowWidth, 100 ) windowHeight = max( windowHeight, 100 ) self.resize( QSize(windowWidth,windowHeight).expandedTo(self.minimumSizeHint()) ) profiles = listProfiles() entries = [entry for userName,keyId,entry in profiles] if st.getInt('Settings/RememberKey',0) : entry = st.getString('Settings/SavedProfile') password = st.getString('Settings/SavedPassword') if entry and password and (entry in entries) : profile = loadProfile( entry, password ) if profile : self._doGoOnline( profile )
def on_goOnlineButton_clicked( self ) : entryIndex = self.ui.keys.currentIndex() if entryIndex < 0 : return entry = self.profiles[entryIndex][2] password = unicode(self.ui.password.text()).encode('utf8') profile = loadProfile( entry, password ) if profile is None : QMessageBox.critical( self, 'Error', 'Invalid Password.' ) self.ui.password.setFocus() self.ui.password.selectAll() return self.profile = profile st = localSettings() if self.ui.rememberKey.isChecked() : st.setInt( 'Settings/RememberKey', 1 ) st.setString( 'Settings/SavedProfile', profile.storeEntry ) st.setString( 'Settings/SavedPassword', password ) else : st.setInt( 'Settings/RememberKey', 0 ) st.remove( 'Settings/SavedProfile' ) st.remove( 'Settings/SavedPassword' ) self.accept()
def on_goOnlineButton_clicked(self): entryIndex = self.ui.keys.currentIndex() if entryIndex < 0: return entry = self.profiles[entryIndex][2] password = unicode(self.ui.password.text()).encode('utf8') profile = loadProfile(entry, password) if profile is None: QMessageBox.critical(self, 'Error', 'Invalid Password.') self.ui.password.setFocus() self.ui.password.selectAll() return self.profile = profile st = localSettings() if self.ui.rememberKey.isChecked(): st.setInt('Settings/RememberKey', 1) st.setString('Settings/SavedProfile', profile.storeEntry) st.setString('Settings/SavedPassword', password) else: st.setInt('Settings/RememberKey', 0) st.remove('Settings/SavedProfile') st.remove('Settings/SavedPassword') self.accept()
def switch(self, profile, password): if self.status is not self.OFFLINE: return self._error("Not currently offline.") st = self.settings logger.debug("Changing profile...") profiles = [userName for userName, keyId, entry in listProfiles()] if not st.getInt("Settings/RememberKey", 0): return self._error("No key found.") if not profile in entries: return self._error("No profile %s found.") profile = loadProfile(profile, password) if not profile: return self._error("Profile couldn't be loaded.") st.setString("Settings/SavedProfile", profile.name) st.setString("Settings/SavedPassword", password) saveLocalSettings() self.dispatcher.trigger("profile.switch", profile) return True