From aa983e496610ee71b601ce322139e50102d274b7 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Mon, 11 Feb 2013 14:18:45 +0100 Subject: [PATCH] Make user password dialog real async working. --- src/mirall/credentialstore.cpp | 48 +++++++++++++++++++++++++++------- src/mirall/credentialstore.h | 5 +++- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/mirall/credentialstore.cpp b/src/mirall/credentialstore.cpp index 694bd32f9..99403baa8 100644 --- a/src/mirall/credentialstore.cpp +++ b/src/mirall/credentialstore.cpp @@ -12,6 +12,7 @@ */ #include +#include #include "config.h" @@ -103,6 +104,9 @@ void CredentialStore::fetchCredentials() QString pwd; _user = cfgFile.ownCloudUser(); _url = cfgFile.ownCloudUrl(); + if( !cfgFile.passwordStorageAllowed() ) { + _type = CredentialStore::User; + } QString key = keyChainKey(_url); @@ -117,15 +121,16 @@ void CredentialStore::fetchCredentials() case CredentialStore::User: { /* Ask the user for the password */ /* Fixme: Move user interaction out here. */ - _state = Fetching; - pwd = QInputDialog::getText(0, QApplication::translate("MirallConfigFile","Password Required"), - QApplication::translate("MirallConfigFile","Please enter your %1 password:") - .arg(Theme::instance()->appName()), - QLineEdit::Password, - QString::null, &ok); - if( !ok ) { - _state = UserCanceled; - } + _state = AsyncFetching; + _inputDialog = new QInputDialog; + _inputDialog->setWindowTitle(QApplication::translate("MirallConfigFile","Password Required") ); + _inputDialog->setLabelText( QApplication::translate("MirallConfigFile","Please enter your %1 password:") + .arg(Theme::instance()->appName())); + _inputDialog->setInputMode( QInputDialog::TextInput ); + _inputDialog->setTextEchoMode( QLineEdit::Password ); + + connect(_inputDialog, SIGNAL(finished(int)), SLOT(slotUserDialogDone(int))); + _inputDialog->exec(); break; } case CredentialStore::Settings: { @@ -179,6 +184,19 @@ void CredentialStore::fetchCredentials() } } +void CredentialStore::slotUserDialogDone( int result ) +{ + if( result == QDialog::Accepted ) { + _passwd = _inputDialog->textValue(); + _state = Ok; + } else { + _state = UserCanceled; + _passwd = QString::null; + } + _inputDialog->deleteLater(); + emit(fetchCredentialsFinished(_state == Ok)); +} + void CredentialStore::reset() { _state = NotFetched; @@ -281,10 +299,20 @@ QString CredentialStore::errorMessage() return _errorMsg; } -void CredentialStore::setCredentials( const QString& url, const QString& user, const QString& pwd ) +void CredentialStore::setCredentials( const QString& url, const QString& user, + const QString& pwd, bool allowToStore ) { _passwd = pwd; _user = user; + if( allowToStore ) { +#ifdef WITH_QTKEYCHAIN + _type = KeyChain; +#else + _type = Settings; +#endif + } else { + _type = User; + } _url = url; _state = Ok; } diff --git a/src/mirall/credentialstore.h b/src/mirall/credentialstore.h index d361d2f40..0179c04f4 100644 --- a/src/mirall/credentialstore.h +++ b/src/mirall/credentialstore.h @@ -16,6 +16,7 @@ #include "config.h" #include +#include #ifdef WITH_QTKEYCHAIN #include "qtkeychain/keychain.h" @@ -107,7 +108,7 @@ public: * @param user - the user name * @param password - the password. */ - void setCredentials( const QString&, const QString&, const QString& ); + void setCredentials( const QString&, const QString&, const QString&, bool ); void saveCredentials( ); @@ -133,6 +134,7 @@ signals: protected slots: void slotKeyChainReadFinished( QKeychain::Job* ); void slotKeyChainWriteFinished( QKeychain::Job* ); + void slotUserDialogDone(int); private: explicit CredentialStore(QObject *parent = 0); @@ -147,6 +149,7 @@ private: static QString _errorMsg; static int _tries; static CredentialType _type; + QInputDialog *_inputDialog; }; }