From 9dc21bf8a37150b2e0b8d98c50c71dd933d43e65 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Sun, 26 May 2013 13:55:23 +0200 Subject: [PATCH] Let the keychain return new creds during async save. The credentials are asynchronously saved. The credentialstore now returns the creds even if the saving has not yet finished but is running, for that the new state AsyncWriting was added. That makes the start of the sync after the password was changed more reliable. --- src/mirall/credentialstore.cpp | 28 +++++++++++++--------------- src/mirall/credentialstore.h | 1 + 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/mirall/credentialstore.cpp b/src/mirall/credentialstore.cpp index 7338a56552..a8aafe0176 100644 --- a/src/mirall/credentialstore.cpp +++ b/src/mirall/credentialstore.cpp @@ -76,23 +76,14 @@ bool CredentialStore::canTryAgain() return false; } - if( _state == NotFetched ) { + /* Since QtKeyChain is required now, it makes to only + * query once. */ + if( _state == NotFetched || _state == AsyncWriting ) { return true; + } else { + return false; } - switch( _type ) { - case CredentialStore::User: - canDoIt = true; - break; - case CredentialStore::Settings: - break; - case CredentialStore::KeyChain: - canDoIt = true; - break; - default: - break; - } - return canDoIt; } void CredentialStore::fetchCredentials() @@ -147,7 +138,7 @@ void CredentialStore::fetchCredentials() } case CredentialStore::KeyChain: { // If the credentials are here already, return. - if( _state == Ok ) { + if( _state == Ok || _state == AsyncWriting ) { emit(fetchCredentialsFinished(true)); return; } @@ -347,6 +338,7 @@ void CredentialStore::saveCredentials( ) connect( job, SIGNAL(finished(QKeychain::Job*)), this, SLOT(slotKeyChainWriteFinished(QKeychain::Job*))); + _state = AsyncWriting; job->start(); #endif break; @@ -373,15 +365,21 @@ void CredentialStore::slotKeyChainWriteFinished( QKeychain::Job *job ) pwdJob->errorString().contains(QLatin1String("Could not open wallet"))) { _type = Settings; saveCredentials(); + _state = NoKeychainBackend; + } else { + _state = Error; } } else { qDebug() << "Successfully stored password for user " << _user; // Try to remove password formerly stored in the config file. MirallConfigFile cfgFile; cfgFile.clearPasswordFromConfig(); + _state = NotFetched; + _tries = 0; } } else { qDebug() << "Error: KeyChain Write Password Job failed!"; + _state = Error; } #else (void) job; diff --git a/src/mirall/credentialstore.h b/src/mirall/credentialstore.h index 51030a2f91..364e3d1f61 100644 --- a/src/mirall/credentialstore.h +++ b/src/mirall/credentialstore.h @@ -57,6 +57,7 @@ public: AccessDenied, NoKeychainBackend, Error, + AsyncWriting, TooManyAttempts }; enum CredentialType {