diff --git a/src/creds/http/credentialstore.cpp b/src/creds/http/credentialstore.cpp index 19229514b..537129804 100644 --- a/src/creds/http/credentialstore.cpp +++ b/src/creds/http/credentialstore.cpp @@ -29,29 +29,17 @@ using namespace QKeychain; namespace Mirall { -CredentialStore *CredentialStore::_instance=0; -CredentialStore::CredState CredentialStore::_state = NotFetched; -QString CredentialStore::_passwd = QString::null; -QString CredentialStore::_user = QString::null; -QString CredentialStore::_url = QString::null; -QString CredentialStore::_errorMsg = QString::null; -#ifdef WITH_QTKEYCHAIN -CredentialStore::CredentialType CredentialStore::_type = KeyChain; -#else -CredentialStore::CredentialType CredentialStore::_type = Settings; -#endif - -CredentialStore::CredentialStore(QObject *parent) : - QObject(parent) +CredentialStore::CredentialStore(QObject *parent) + : QObject(parent) + , _state() + , _passwd() + , _user() + , _url() + , _errorMsg() + , _type() { } -CredentialStore *CredentialStore::instance() -{ - if( !CredentialStore::_instance ) CredentialStore::_instance = new CredentialStore; - return CredentialStore::_instance; -} - QString CredentialStore::password() const { return _passwd; diff --git a/src/creds/http/credentialstore.h b/src/creds/http/credentialstore.h index 2732e603c..836c396a3 100644 --- a/src/creds/http/credentialstore.h +++ b/src/creds/http/credentialstore.h @@ -77,12 +77,6 @@ public: */ void fetchCredentials(); - /** - * @brief instance - singleton pointer. - * @return the singleton pointer to access the object. - */ - static CredentialStore *instance(); - /** * @brief setCredentials - sets the user credentials. * @@ -119,13 +113,12 @@ private: void deleteKeyChainCredential( const QString& ); QString keyChainKey( const QString& ) const; - static CredentialStore *_instance; - static CredState _state; - static QString _passwd; - static QString _user; - static QString _url; - static QString _errorMsg; - static CredentialType _type; + CredState _state; + QString _passwd; + QString _user; + QString _url; + QString _errorMsg; + CredentialType _type; }; } diff --git a/src/creds/httpcredentials.cpp b/src/creds/httpcredentials.cpp index 25c8fb708..08f7e2226 100644 --- a/src/creds/httpcredentials.cpp +++ b/src/creds/httpcredentials.cpp @@ -93,7 +93,11 @@ HttpCredentials::HttpCredentials(const QString& user, const QString& password) : _user(user), _password(password), _ready(true) -{} +{ + _store = new CredentialStore(this); + connect(store, SIGNAL(fetchCredentialsFinished(bool)), + this, SLOT(slotCredentialsFetched(bool))); +} void HttpCredentials::syncContextPreInit (CSYNC* ctx) { @@ -168,27 +172,22 @@ void HttpCredentials::fetch() Q_EMIT fetched(); } else { // TODO: merge CredentialStore into HttpCredentials? - CredentialStore* store(CredentialStore::instance()); - connect(store, SIGNAL(fetchCredentialsFinished(bool)), - this, SLOT(slotCredentialsFetched(bool))); - store->fetchCredentials(); + _store->fetchCredentials(); } } void HttpCredentials::persistForUrl(const QString& url) { - CredentialStore* store(CredentialStore::instance()); - store->setCredentials(url, _user, _password); - store->saveCredentials(); + _store->setCredentials(url, _user, _password); + _store->saveCredentials(); } void HttpCredentials::slotCredentialsFetched(bool ok) { _ready = ok; if (_ready) { - CredentialStore* store(CredentialStore::instance()); - _user = store->user(); - _password = store->password(); + _user = _store->user(); + _password = _store->password(); } Q_EMIT fetched(); } diff --git a/src/creds/httpcredentials.h b/src/creds/httpcredentials.h index 3a2aadab7..0b348803f 100644 --- a/src/creds/httpcredentials.h +++ b/src/creds/httpcredentials.h @@ -27,6 +27,8 @@ class QAuthenticator; namespace Mirall { +class CredentialStore; + class HttpCredentials : public AbstractCredentials { Q_OBJECT @@ -53,6 +55,7 @@ private Q_SLOTS: void slotReplyFinished(); private: + CredentialStore *_store; QString _user; QString _password; bool _ready;