mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-21 21:25:52 +02:00
Fetch serviceName from LocalConfigStorage.
This commit is contained in:
@@ -18,6 +18,10 @@
|
|||||||
|
|
||||||
#include "CredentialsManager.h"
|
#include "CredentialsManager.h"
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
#include "LocalConfigStorage.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
#include <qtkeychain/keychain.h>
|
#include <qtkeychain/keychain.h>
|
||||||
@@ -94,7 +98,7 @@ CredentialsManager::loadCredentials( const QString &service )
|
|||||||
// Therefore, we make sure that our LocalConfigStorage stores everything
|
// Therefore, we make sure that our LocalConfigStorage stores everything
|
||||||
// into a single key.
|
// into a single key.
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
if ( service == "Tomahawk" ) //LocalConfigStorage::m_credentialsServiceName
|
if ( service == LocalConfigStorage::credentialsServiceName() )
|
||||||
{
|
{
|
||||||
QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( service, this );
|
QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( service, this );
|
||||||
j->setKey( OSX_SINGLE_KEY );
|
j->setKey( OSX_SINGLE_KEY );
|
||||||
@@ -184,7 +188,7 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV
|
|||||||
m_credentials.remove( csKey );
|
m_credentials.remove( csKey );
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
if ( csKey.service() == "Tomahawk" )
|
if ( csKey.service() == LocalConfigStorage::credentialsServiceName() )
|
||||||
{
|
{
|
||||||
rewriteCredentialsOsx( csKey.service() );
|
rewriteCredentialsOsx( csKey.service() );
|
||||||
return;
|
return;
|
||||||
@@ -207,7 +211,7 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV
|
|||||||
m_credentials.insert( csKey, value );
|
m_credentials.insert( csKey, value );
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
if ( csKey.service() == "Tomahawk" )
|
if ( csKey.service() == LocalConfigStorage::credentialsServiceName() )
|
||||||
{
|
{
|
||||||
rewriteCredentialsOsx( csKey.service() );
|
rewriteCredentialsOsx( csKey.service() );
|
||||||
return;
|
return;
|
||||||
@@ -262,7 +266,7 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV
|
|||||||
void
|
void
|
||||||
CredentialsManager::rewriteCredentialsOsx( const QString& service )
|
CredentialsManager::rewriteCredentialsOsx( const QString& service )
|
||||||
{
|
{
|
||||||
if ( service != "Tomahawk" ) //always LocalConfigStorage::m_credentialsServiceName
|
if ( service != LocalConfigStorage::credentialsServiceName() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QVariantMap everythingMap;
|
QVariantMap everythingMap;
|
||||||
|
@@ -29,10 +29,18 @@ namespace Tomahawk
|
|||||||
namespace Accounts
|
namespace Accounts
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const QString LocalConfigStorage::s_credentialsServiceName = "Tomahawk";
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
QString
|
||||||
|
LocalConfigStorage::credentialsServiceName()
|
||||||
|
{
|
||||||
|
return s_credentialsServiceName;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
LocalConfigStorage::LocalConfigStorage( QObject* parent )
|
LocalConfigStorage::LocalConfigStorage( QObject* parent )
|
||||||
: ConfigStorage( parent )
|
: ConfigStorage( parent )
|
||||||
, m_credentialsServiceName( "Tomahawk" )
|
|
||||||
{
|
{
|
||||||
m_accountIds = TomahawkSettings::instance()->accounts();
|
m_accountIds = TomahawkSettings::instance()->accounts();
|
||||||
}
|
}
|
||||||
@@ -46,10 +54,10 @@ LocalConfigStorage::init()
|
|||||||
CredentialsManager* cm = AccountManager::instance()->credentialsManager();
|
CredentialsManager* cm = AccountManager::instance()->credentialsManager();
|
||||||
connect( cm, SIGNAL( serviceReady( QString ) ),
|
connect( cm, SIGNAL( serviceReady( QString ) ),
|
||||||
this, SLOT( onCredentialsManagerReady( QString ) ) );
|
this, SLOT( onCredentialsManagerReady( QString ) ) );
|
||||||
AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName,
|
AccountManager::instance()->credentialsManager()->addService( s_credentialsServiceName,
|
||||||
m_accountIds );
|
m_accountIds );
|
||||||
|
|
||||||
tDebug() << Q_FUNC_INFO << "LOADING ALL CREDENTIALS FOR SERVICE" << m_credentialsServiceName << m_accountIds;
|
tDebug() << Q_FUNC_INFO << "LOADING ALL CREDENTIALS FOR SERVICE" << s_credentialsServiceName << m_accountIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -63,7 +71,7 @@ LocalConfigStorage::id() const
|
|||||||
void
|
void
|
||||||
LocalConfigStorage::onCredentialsManagerReady( const QString& service )
|
LocalConfigStorage::onCredentialsManagerReady( const QString& service )
|
||||||
{
|
{
|
||||||
if ( service != m_credentialsServiceName )
|
if ( service != s_credentialsServiceName )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//no need to listen for it any more
|
//no need to listen for it any more
|
||||||
@@ -109,7 +117,7 @@ LocalConfigStorage::save( const QString& accountId, const Account::Configuration
|
|||||||
s->sync();
|
s->sync();
|
||||||
|
|
||||||
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
||||||
c->setCredentials( m_credentialsServiceName, accountId, cfg.credentials );
|
c->setCredentials( s_credentialsServiceName, accountId, cfg.credentials );
|
||||||
|
|
||||||
if ( !m_accountIds.contains( accountId ) )
|
if ( !m_accountIds.contains( accountId ) )
|
||||||
m_accountIds.append( accountId );
|
m_accountIds.append( accountId );
|
||||||
@@ -129,7 +137,7 @@ LocalConfigStorage::load( const QString& accountId, Account::Configuration& cfg
|
|||||||
s->endGroup();
|
s->endGroup();
|
||||||
|
|
||||||
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
||||||
QVariant credentials = c->credentials( m_credentialsServiceName, accountId );
|
QVariant credentials = c->credentials( s_credentialsServiceName, accountId );
|
||||||
if ( credentials.type() == QVariant::Hash )
|
if ( credentials.type() == QVariant::Hash )
|
||||||
cfg.credentials = credentials.toHash();
|
cfg.credentials = credentials.toHash();
|
||||||
}
|
}
|
||||||
@@ -149,7 +157,7 @@ LocalConfigStorage::remove( const QString& accountId )
|
|||||||
s->remove( "accounts/" + accountId );
|
s->remove( "accounts/" + accountId );
|
||||||
|
|
||||||
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
||||||
c->setCredentials( m_credentialsServiceName, accountId, QVariantHash() );
|
c->setCredentials( s_credentialsServiceName, accountId, QVariantHash() );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -47,12 +47,15 @@ public:
|
|||||||
virtual void load( const QString& accountId, Account::Configuration& cfg ) const;
|
virtual void load( const QString& accountId, Account::Configuration& cfg ) const;
|
||||||
virtual void remove( const QString& accountId );
|
virtual void remove( const QString& accountId );
|
||||||
|
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
static QString credentialsServiceName();
|
||||||
|
#endif
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onCredentialsManagerReady( const QString& service );
|
void onCredentialsManagerReady( const QString& service );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString m_credentialsServiceName;
|
static const QString s_credentialsServiceName;
|
||||||
QStringList m_accountIds;
|
QStringList m_accountIds;
|
||||||
|
|
||||||
static LocalConfigStorage* s_instance;
|
static LocalConfigStorage* s_instance;
|
||||||
|
Reference in New Issue
Block a user