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 _updateUI( self ) : state = self.sm.current() online = (state == self.ONLINE) offline = (state == self.OFFLINE) connecting = (state == self.CONNECTING) disconnecting = (state == self.DISCONNECTING) self.ui.actionCreateKey.setEnabled( offline ) self.ui.actionGoOnline.setEnabled( offline ) self.ui.actionGoOffline.setEnabled( online ) self.ui.actionKeyInfo.setEnabled( online ) self.ui.actionExit.setEnabled( True ) self.ui.actionAddContact.setEnabled( online ) self.ui.actionRefreshStatus.setEnabled( online ) self.ui.actionCheckStatus.setEnabled( online ) self.ui.actionContactInfo.setEnabled( online ) self.ui.actionRemoveContact.setEnabled( online ) self.ui.actionEditPermissions.setEnabled( online ) self.ui.actionAboutCSpace.setEnabled( True ) if online : msg = 'Online' if offline : msg = 'Offline' if connecting : msg = 'Going Online...' if disconnecting : msg = 'Going Offline...' if not offline : msg = '%s - %s' % (self.profile.name,msg) self.setWindowTitle( ' - '.join([msg,self.baseTitle]) ) self.ui.createKeyButton.setEnabled( offline ) self.ui.createKeyButton1.setEnabled( offline ) self.ui.goOnlineButton.setEnabled( offline ) self.ui.connectCancelButton.setEnabled( connecting or disconnecting ) if online : self.ui.stack.setCurrentWidget( self.ui.contactsPage ) elif offline : if self.reconnector : assert self.reconnector.reconnecting self.ui.connectCancelButton.setEnabled( True ) self.ui.stack.setCurrentWidget( self.ui.connectingPage ) self.ui.connectStatus.setText('<b>%s<br/>Reconnecting in %d second(s)...</b>' % (self.reconnector.errorMsg, self.reconnector.timeLeft) ) elif listProfiles() : self.ui.stack.setCurrentWidget( self.ui.offlinePage ) else : self.ui.stack.setCurrentWidget( self.ui.offlineNoUsersPage ) elif connecting : self.ui.stack.setCurrentWidget( self.ui.connectingPage ) self.ui.connectStatus.setText( '<b>Connecting...</b>' ) elif disconnecting : self.ui.stack.setCurrentWidget( self.ui.connectingPage ) self.ui.connectStatus.setText( '<b>Disconnecting...</b>' )
def _updateUI( self ) : state = self.sm.current() online = (state == self.ONLINE) offline = (state == self.OFFLINE) connecting = (state == self.CONNECTING) disconnecting = (state == self.DISCONNECTING) self.ui.actionCreateKey.setEnabled( offline ) self.ui.actionGoOnline.setEnabled( offline ) self.ui.actionGoOffline.setEnabled( online ) self.ui.actionKeyInfo.setEnabled( online ) self.ui.actionExit.setEnabled( True ) self.ui.actionAddContact.setEnabled( online ) self.ui.actionRefreshStatus.setEnabled( online ) self.ui.actionCheckStatus.setEnabled( online ) self.ui.actionContactInfo.setEnabled( online ) self.ui.actionRemoveContact.setEnabled( online ) self.ui.actionEditPermissions.setEnabled( online ) self.ui.actionAboutCSpace.setEnabled( True ) if online : msg = 'Online' if offline : msg = 'Offline' if connecting : msg = 'Going Online...' if disconnecting : msg = 'Going Offline...' if not offline : msg = '%s - %s' % (self.profile.name,msg) self.setWindowTitle( ' - '.join([msg,self.baseTitle]) ) self.ui.createKeyButton.setEnabled( offline ) self.ui.createKeyButton1.setEnabled( offline ) self.ui.goOnlineButton.setEnabled( offline ) self.ui.connectCancelButton.setEnabled( connecting or disconnecting ) if online : self.ui.stack.setCurrentWidget( self.ui.contactsPage ) elif offline : if self.reconnector : assert self.reconnector.reconnecting self.ui.connectCancelButton.setEnabled( True ) self.ui.stack.setCurrentWidget( self.ui.connectingPage ) self.ui.connectStatus.setText('<b>%s<br/>Reconnecting in %d second(s)...</b>' % (self.reconnector.errorMsg, self.reconnector.timeLeft) ) elif listProfiles() : self.ui.stack.setCurrentWidget( self.ui.offlinePage ) else : self.ui.stack.setCurrentWidget( self.ui.offlineNoUsersPage ) elif connecting : self.ui.stack.setCurrentWidget( self.ui.connectingPage ) self.ui.connectStatus.setText( '<b>Connecting...</b>' ) elif disconnecting : self.ui.stack.setCurrentWidget( self.ui.connectingPage ) self.ui.connectStatus.setText( '<b>Disconnecting...</b>' )
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 _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 __init__( self, parent ) : QDialog.__init__( self, parent ) self.ui = Ui_GoOnlineDialog() self.ui.setupUi( self ) self.profiles = listProfiles() for userName,keyId,entry in self.profiles : text = userName if keyId : text += ' (KeyID: %s)' % keyId self.ui.keys.addItem( QString(text) ) entries = [entry for userName,keyId,entry in self.profiles] st = localSettings() if st.getInt('Settings/RememberKey',0) : self.ui.rememberKey.setChecked( True ) entry = st.getString( 'Settings/SavedProfile' ) password = st.getString( 'Settings/SavedPassword' ) if entry and password and (entry in entries) : self.ui.keys.setCurrentIndex( entries.index(entry) ) self.ui.password.setText( password ) else : self.ui.rememberKey.setChecked( False )
def __init__(self, parent): QDialog.__init__(self, parent) self.ui = Ui_GoOnlineDialog() self.ui.setupUi(self) self.profiles = listProfiles() for userName, keyId, entry in self.profiles: text = userName if keyId: text += ' (KeyID: %s)' % keyId self.ui.keys.addItem(QString(text)) entries = [entry for userName, keyId, entry in self.profiles] st = localSettings() if st.getInt('Settings/RememberKey', 0): self.ui.rememberKey.setChecked(True) entry = st.getString('Settings/SavedProfile') password = st.getString('Settings/SavedPassword') if entry and password and (entry in entries): self.ui.keys.setCurrentIndex(entries.index(entry)) self.ui.password.setText(password) else: self.ui.rememberKey.setChecked(False)
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