Credential Store is no longer static

It now belongs to HttpCredentials
This commit is contained in:
Daniel Molkentin 2013-10-30 16:32:34 +01:00
parent 14c2ff44f3
commit 59bc1d8966
4 changed files with 27 additions and 44 deletions

View file

@ -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;

View file

@ -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;
};
}

View file

@ -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();
}

View file

@ -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;