Make user password dialog real async working.

This commit is contained in:
Klaas Freitag 2013-02-11 14:18:45 +01:00
parent 424b3a9dfc
commit aa983e4966
2 changed files with 42 additions and 11 deletions

View file

@ -12,6 +12,7 @@
*/
#include <QtGui>
#include <QInputDialog>
#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;
}

View file

@ -16,6 +16,7 @@
#include "config.h"
#include <QObject>
#include <QInputDialog>
#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;
};
}