mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-22 13:43:11 +02:00
Added ConfigStorage and LocalConfigStorage, preparation for Telepathy.
This commit is contained in:
@@ -52,7 +52,7 @@ public:
|
|||||||
QString description() const { return tr( "Log on to your Jabber/XMPP account to connect to your friends" ); }
|
QString description() const { return tr( "Log on to your Jabber/XMPP account to connect to your friends" ); }
|
||||||
QString factoryId() const { return "xmppaccount"; }
|
QString factoryId() const { return "xmppaccount"; }
|
||||||
QPixmap icon() const { return QPixmap( ":/xmpp-account/xmpp-icon.png" ); }
|
QPixmap icon() const { return QPixmap( ":/xmpp-account/xmpp-icon.png" ); }
|
||||||
AccountTypes types() const { return AccountTypes( SipType | StatusPushType ); };
|
AccountTypes types() const { return AccountTypes( SipType | StatusPushType ); }
|
||||||
Account* createAccount( const QString& pluginId = QString() );
|
Account* createAccount( const QString& pluginId = QString() );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -219,6 +219,7 @@ list(APPEND libSources
|
|||||||
accounts/AccountFactoryWrapper.cpp
|
accounts/AccountFactoryWrapper.cpp
|
||||||
accounts/AccountFactoryWrapperDelegate.cpp
|
accounts/AccountFactoryWrapperDelegate.cpp
|
||||||
accounts/AccountConfigWidget.cpp
|
accounts/AccountConfigWidget.cpp
|
||||||
|
accounts/LocalConfigStorage.cpp
|
||||||
|
|
||||||
accounts/spotify/SpotifyAccount.cpp
|
accounts/spotify/SpotifyAccount.cpp
|
||||||
accounts/spotify/SpotifyAccountConfig.cpp
|
accounts/spotify/SpotifyAccountConfig.cpp
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,9 +20,9 @@
|
|||||||
|
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
|
|
||||||
#include "TomahawkSettings.h"
|
|
||||||
#include "AccountManager.h"
|
#include "AccountManager.h"
|
||||||
#include "CredentialsManager.h"
|
#include "CredentialsManager.h"
|
||||||
|
#include "ConfigStorage.h"
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
@@ -51,9 +52,10 @@ accountTypeToString( AccountType type )
|
|||||||
|
|
||||||
Account::Account( const QString& accountId )
|
Account::Account( const QString& accountId )
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_enabled( false )
|
|
||||||
, m_accountId( accountId )
|
, m_accountId( accountId )
|
||||||
{
|
{
|
||||||
|
m_cfg.enabled = false;
|
||||||
|
|
||||||
connect( this, SIGNAL( error( int, QString ) ), this, SLOT( onError( int, QString ) ) );
|
connect( this, SIGNAL( error( int, QString ) ), this, SLOT( onError( int, QString ) ) );
|
||||||
connect( this, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) , this, SLOT( onConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) );
|
connect( this, SIGNAL( connectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) , this, SLOT( onConnectionStateChanged( Tomahawk::Accounts::Account::ConnectionState ) ) );
|
||||||
|
|
||||||
@@ -132,18 +134,7 @@ Account::onConnectionStateChanged( Account::ConnectionState )
|
|||||||
void
|
void
|
||||||
Account::syncConfig()
|
Account::syncConfig()
|
||||||
{
|
{
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
AccountManager::instance()->configStorageForAccount( m_accountId )->save( m_accountId, m_cfg );
|
||||||
s->beginGroup( "accounts/" + m_accountId );
|
|
||||||
s->setValue( "accountfriendlyname", m_accountFriendlyName );
|
|
||||||
s->setValue( "enabled", m_enabled );
|
|
||||||
s->setValue( "configuration", m_configuration );
|
|
||||||
s->setValue( "acl", m_acl );
|
|
||||||
s->setValue( "types", m_types );
|
|
||||||
s->endGroup();
|
|
||||||
s->sync();
|
|
||||||
|
|
||||||
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
|
||||||
c->setCredentials( "Tomahawk", m_accountId, m_credentials );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -151,35 +142,15 @@ void
|
|||||||
Account::loadFromConfig( const QString& accountId )
|
Account::loadFromConfig( const QString& accountId )
|
||||||
{
|
{
|
||||||
m_accountId = accountId;
|
m_accountId = accountId;
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
|
||||||
s->beginGroup( "accounts/" + m_accountId );
|
|
||||||
m_accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString();
|
|
||||||
m_enabled = s->value( "enabled", false ).toBool();
|
|
||||||
m_configuration = s->value( "configuration", QVariantHash() ).toHash();
|
|
||||||
m_acl = s->value( "acl", QVariantMap() ).toMap();
|
|
||||||
m_types = s->value( "types", QStringList() ).toStringList();
|
|
||||||
s->endGroup();
|
|
||||||
|
|
||||||
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
AccountManager::instance()->configStorageForAccount( m_accountId )->load( m_accountId, m_cfg );
|
||||||
m_credentials = c->credentials( "Tomahawk", m_accountId );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Account::removeFromConfig()
|
Account::removeFromConfig()
|
||||||
{
|
{
|
||||||
TomahawkSettings* s = TomahawkSettings::instance();
|
AccountManager::instance()->configStorageForAccount( m_accountId )->remove( m_accountId );
|
||||||
s->beginGroup( "accounts/" + m_accountId );
|
|
||||||
s->remove( "accountfriendlyname" );
|
|
||||||
s->remove( "enabled" );
|
|
||||||
s->remove( "configuration" );
|
|
||||||
s->remove( "acl" );
|
|
||||||
s->remove( "types" );
|
|
||||||
s->endGroup();
|
|
||||||
s->remove( "accounts/" + m_accountId );
|
|
||||||
|
|
||||||
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
|
||||||
c->setCredentials( "Tomahawk", m_accountId, QVariantHash() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -187,15 +158,15 @@ void
|
|||||||
Account::setTypes( AccountTypes types )
|
Account::setTypes( AccountTypes types )
|
||||||
{
|
{
|
||||||
QMutexLocker locker( &m_mutex );
|
QMutexLocker locker( &m_mutex );
|
||||||
m_types = QStringList();
|
m_cfg.types = QStringList();
|
||||||
if ( types & InfoType )
|
if ( types & InfoType )
|
||||||
m_types << "InfoType";
|
m_cfg.types << "InfoType";
|
||||||
if ( types & SipType )
|
if ( types & SipType )
|
||||||
m_types << "SipType";
|
m_cfg.types << "SipType";
|
||||||
if ( types & ResolverType )
|
if ( types & ResolverType )
|
||||||
m_types << "ResolverType";
|
m_cfg.types << "ResolverType";
|
||||||
if ( types & StatusPushType )
|
if ( types & StatusPushType )
|
||||||
m_types << "StatusPushType";
|
m_cfg.types << "StatusPushType";
|
||||||
syncConfig();
|
syncConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,13 +176,13 @@ Account::types() const
|
|||||||
{
|
{
|
||||||
QMutexLocker locker( &m_mutex );
|
QMutexLocker locker( &m_mutex );
|
||||||
AccountTypes types;
|
AccountTypes types;
|
||||||
if ( m_types.contains( "InfoType" ) )
|
if ( m_cfg.types.contains( "InfoType" ) )
|
||||||
types |= InfoType;
|
types |= InfoType;
|
||||||
if ( m_types.contains( "SipType" ) )
|
if ( m_cfg.types.contains( "SipType" ) )
|
||||||
types |= SipType;
|
types |= SipType;
|
||||||
if ( m_types.contains( "ResolverType" ) )
|
if ( m_cfg.types.contains( "ResolverType" ) )
|
||||||
types |= ResolverType;
|
types |= ResolverType;
|
||||||
if ( m_types.contains( "StatusPushType" ) )
|
if ( m_cfg.types.contains( "StatusPushType" ) )
|
||||||
types |= StatusPushType;
|
types |= StatusPushType;
|
||||||
|
|
||||||
return types;
|
return types;
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
*
|
*
|
||||||
* Tomahawk is free software: you can redistribute it and/or modify
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -41,6 +42,8 @@ namespace Tomahawk
|
|||||||
namespace Accounts
|
namespace Accounts
|
||||||
{
|
{
|
||||||
|
|
||||||
|
class ConfigStorage;
|
||||||
|
|
||||||
enum AccountType
|
enum AccountType
|
||||||
{
|
{
|
||||||
NoType = 0x00,
|
NoType = 0x00,
|
||||||
@@ -66,6 +69,16 @@ class DLLEXPORT Account : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
struct Configuration
|
||||||
|
{
|
||||||
|
QString accountFriendlyName;
|
||||||
|
bool enabled;
|
||||||
|
QVariantHash configuration;
|
||||||
|
QVariantMap acl;
|
||||||
|
QStringList types;
|
||||||
|
QVariantHash credentials;
|
||||||
|
};
|
||||||
|
|
||||||
enum AuthErrorCode { AuthError, ConnectionError };
|
enum AuthErrorCode { AuthError, ConnectionError };
|
||||||
enum ConnectionState { Disconnected, Connecting, Connected, Disconnecting };
|
enum ConnectionState { Disconnected, Connecting, Connected, Disconnecting };
|
||||||
|
|
||||||
@@ -73,11 +86,11 @@ public:
|
|||||||
virtual ~Account();
|
virtual ~Account();
|
||||||
|
|
||||||
QString accountServiceName() const { QMutexLocker locker( &m_mutex ); return m_accountServiceName; } // e.g. "Twitter", "Last.fm"
|
QString accountServiceName() const { QMutexLocker locker( &m_mutex ); return m_accountServiceName; } // e.g. "Twitter", "Last.fm"
|
||||||
QString accountFriendlyName() const { QMutexLocker locker( &m_mutex ); return m_accountFriendlyName; } // e.g. screen name on the service, JID, etc.
|
QString accountFriendlyName() const { QMutexLocker locker( &m_mutex ); return m_cfg.accountFriendlyName; } // e.g. screen name on the service, JID, etc.
|
||||||
bool enabled() const { QMutexLocker locker( &m_mutex ); return m_enabled; }
|
bool enabled() const { QMutexLocker locker( &m_mutex ); return m_cfg.enabled; }
|
||||||
QString accountId() const { QMutexLocker locker( &m_mutex ); return m_accountId; }
|
QString accountId() const { QMutexLocker locker( &m_mutex ); return m_accountId; }
|
||||||
|
|
||||||
QVariantHash configuration() const { QMutexLocker locker( &m_mutex ); return m_configuration; }
|
QVariantHash configuration() const { QMutexLocker locker( &m_mutex ); return m_cfg.configuration; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration widgets can have a "dataError( bool )" signal to enable/disable the OK button in their wrapper dialogs.
|
* Configuration widgets can have a "dataError( bool )" signal to enable/disable the OK button in their wrapper dialogs.
|
||||||
@@ -94,9 +107,9 @@ public:
|
|||||||
|
|
||||||
virtual void saveConfig() {} // called when the widget has been edited. save values from config widget, call sync() to write to disk account generic settings
|
virtual void saveConfig() {} // called when the widget has been edited. save values from config widget, call sync() to write to disk account generic settings
|
||||||
|
|
||||||
QVariantHash credentials() const { QMutexLocker locker( &m_mutex ); return m_credentials; }
|
QVariantHash credentials() const { QMutexLocker locker( &m_mutex ); return m_cfg.credentials; }
|
||||||
|
|
||||||
QVariantMap acl() const { QMutexLocker locker( &m_mutex ); return m_acl; }
|
QVariantMap acl() const { QMutexLocker locker( &m_mutex ); return m_cfg.acl; }
|
||||||
|
|
||||||
virtual ConnectionState connectionState() const = 0;
|
virtual ConnectionState connectionState() const = 0;
|
||||||
virtual bool isAuthenticated() const = 0;
|
virtual bool isAuthenticated() const = 0;
|
||||||
@@ -113,15 +126,16 @@ public:
|
|||||||
AccountTypes types() const;
|
AccountTypes types() const;
|
||||||
|
|
||||||
void setAccountServiceName( const QString &serviceName ) { QMutexLocker locker( &m_mutex ); m_accountServiceName = serviceName; }
|
void setAccountServiceName( const QString &serviceName ) { QMutexLocker locker( &m_mutex ); m_accountServiceName = serviceName; }
|
||||||
void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_accountFriendlyName = friendlyName; }
|
void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_cfg.accountFriendlyName = friendlyName; }
|
||||||
void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_enabled = enabled; }
|
void setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_cfg.enabled = enabled; }
|
||||||
void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; }
|
void setAccountId( const QString &accountId ) { QMutexLocker locker( &m_mutex ); m_accountId = accountId; }
|
||||||
void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_credentials = credentialHash; }
|
void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_cfg.credentials = credentialHash; }
|
||||||
void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_configuration = configuration; }
|
void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_cfg.configuration = configuration; }
|
||||||
void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; }
|
void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_cfg.acl = acl; }
|
||||||
|
|
||||||
void setTypes( AccountTypes types );
|
void setTypes( AccountTypes types );
|
||||||
|
|
||||||
void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); };
|
void sync() { QMutexLocker locker( &m_mutex ); syncConfig(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all the settings held in the config file for this account instance
|
* Removes all the settings held in the config file for this account instance
|
||||||
@@ -150,15 +164,12 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_accountServiceName;
|
QString m_accountServiceName;
|
||||||
QString m_accountFriendlyName;
|
|
||||||
QString m_cachedError;
|
QString m_cachedError;
|
||||||
bool m_enabled;
|
|
||||||
QString m_accountId;
|
QString m_accountId;
|
||||||
QVariantHash m_credentials;
|
|
||||||
QVariantHash m_configuration;
|
|
||||||
QVariantMap m_acl;
|
|
||||||
QStringList m_types;
|
|
||||||
mutable QMutex m_mutex;
|
mutable QMutex m_mutex;
|
||||||
|
|
||||||
|
Account::Configuration m_cfg;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLLEXPORT AccountFactory : public QObject
|
class DLLEXPORT AccountFactory : public QObject
|
||||||
|
@@ -32,6 +32,7 @@
|
|||||||
#include "ResolverAccount.h"
|
#include "ResolverAccount.h"
|
||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
#include "TomahawkSettings.h"
|
#include "TomahawkSettings.h"
|
||||||
|
#include "LocalConfigStorage.h"
|
||||||
|
|
||||||
#include <QtCore/QLibrary>
|
#include <QtCore/QLibrary>
|
||||||
#include <QtCore/QDir>
|
#include <QtCore/QDir>
|
||||||
@@ -284,27 +285,31 @@ AccountManager::toggleAccountsConnected()
|
|||||||
void
|
void
|
||||||
AccountManager::loadFromConfig()
|
AccountManager::loadFromConfig()
|
||||||
{
|
{
|
||||||
QStringList accountIds = TomahawkSettings::instance()->accounts();
|
m_creds = new CredentialsManager( this );
|
||||||
|
ConfigStorage* configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor
|
||||||
|
m_configStorageById.insert( configStorage->id(), configStorage );
|
||||||
|
|
||||||
|
|
||||||
|
QStringList accountIds;
|
||||||
|
foreach ( ConfigStorage* cs, m_configStorageById )
|
||||||
|
accountIds << cs->accountIds();
|
||||||
qDebug() << "LOADING ALL CREDENTIALS" << accountIds;
|
qDebug() << "LOADING ALL CREDENTIALS" << accountIds;
|
||||||
|
|
||||||
m_creds = new CredentialsManager( this );
|
|
||||||
NewClosure( m_creds, SIGNAL( ready() ),
|
NewClosure( m_creds, SIGNAL( ready() ),
|
||||||
this, SLOT( finishLoadingFromConfig( QStringList ) ), accountIds );
|
this, SLOT( finishLoadingFromConfig() ) );
|
||||||
|
m_creds->loadCredentials();
|
||||||
CredentialsManager::Service tomahawkSvc;
|
|
||||||
tomahawkSvc.name = "Tomahawk"; //the string where we store in QtKeychain
|
|
||||||
tomahawkSvc.keys = accountIds;
|
|
||||||
QList< CredentialsManager::Service > svcs;
|
|
||||||
svcs << tomahawkSvc;
|
|
||||||
m_creds->loadCredentials( svcs );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountManager::finishLoadingFromConfig( const QStringList& accountIds )
|
AccountManager::finishLoadingFromConfig()
|
||||||
{
|
{
|
||||||
qDebug() << "LOADING ALL ACCOUNTS" << accountIds;
|
foreach ( ConfigStorage* cs, m_configStorageById )
|
||||||
|
{
|
||||||
|
QStringList accountIds = cs->accountIds();
|
||||||
|
|
||||||
|
qDebug() << "LOADING ALL ACCOUNTS FOR STORAGE" << cs->metaObject()->className()
|
||||||
|
<< ":" << accountIds;
|
||||||
|
|
||||||
foreach ( const QString& accountId, accountIds )
|
foreach ( const QString& accountId, accountIds )
|
||||||
{
|
{
|
||||||
@@ -315,7 +320,7 @@ AccountManager::finishLoadingFromConfig( const QStringList& accountIds )
|
|||||||
addAccount( account );
|
addAccount( account );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
m_readyForSip = true;
|
m_readyForSip = true;
|
||||||
emit readyForSip(); //we have to yield to TomahawkApp because we don't know if Servent is ready
|
emit readyForSip(); //we have to yield to TomahawkApp because we don't know if Servent is ready
|
||||||
}
|
}
|
||||||
@@ -453,6 +458,18 @@ AccountManager::zeroconfAccount() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ConfigStorage*
|
||||||
|
AccountManager::configStorageForAccount( const QString& accountId )
|
||||||
|
{
|
||||||
|
foreach ( ConfigStorage* cs, m_configStorageById )
|
||||||
|
{
|
||||||
|
if ( cs->accountIds().contains( accountId ) )
|
||||||
|
return cs;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AccountManager::hookupAccount( Account* account ) const
|
AccountManager::hookupAccount( Account* account ) const
|
||||||
{
|
{
|
||||||
|
@@ -95,6 +95,7 @@ public:
|
|||||||
bool isReady() const { return m_completelyReady; }
|
bool isReady() const { return m_completelyReady; }
|
||||||
|
|
||||||
CredentialsManager* credentialsManager() const { return m_creds; }
|
CredentialsManager* credentialsManager() const { return m_creds; }
|
||||||
|
ConfigStorage* configStorageForAccount( const QString& accountId );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void connectAll();
|
void connectAll();
|
||||||
@@ -119,7 +120,7 @@ private slots:
|
|||||||
void init();
|
void init();
|
||||||
void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
|
void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state );
|
||||||
void onError( int code, const QString& msg );
|
void onError( int code, const QString& msg );
|
||||||
void finishLoadingFromConfig( const QStringList& accountIds );
|
void finishLoadingFromConfig();
|
||||||
|
|
||||||
void onSettingsChanged();
|
void onSettingsChanged();
|
||||||
|
|
||||||
@@ -145,6 +146,8 @@ private:
|
|||||||
QHash< QString, AccountFactory* > m_accountFactories;
|
QHash< QString, AccountFactory* > m_accountFactories;
|
||||||
QList< AccountFactory* > m_factoriesForFilesytem;
|
QList< AccountFactory* > m_factoriesForFilesytem;
|
||||||
|
|
||||||
|
QMap< QString, ConfigStorage* > m_configStorageById;
|
||||||
|
|
||||||
static AccountManager* s_instance;
|
static AccountManager* s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
54
src/libtomahawk/accounts/ConfigStorage.h
Normal file
54
src/libtomahawk/accounts/ConfigStorage.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONFIGSTORAGE_H
|
||||||
|
#define CONFIGSTORAGE_H
|
||||||
|
|
||||||
|
#include "TomahawkSettings.h"
|
||||||
|
#include "Account.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Accounts
|
||||||
|
{
|
||||||
|
|
||||||
|
class ConfigStorage : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ConfigStorage( QObject* parent )
|
||||||
|
: QObject( parent )
|
||||||
|
{}
|
||||||
|
|
||||||
|
virtual ~ConfigStorage() {}
|
||||||
|
|
||||||
|
virtual QString id() const = 0;
|
||||||
|
|
||||||
|
virtual QStringList accountIds() const = 0;
|
||||||
|
|
||||||
|
virtual void save( const QString& accountId, const Account::Configuration& cfg ) = 0;
|
||||||
|
virtual void load( const QString& accountId, Account::Configuration& cfg ) = 0;
|
||||||
|
virtual void remove( const QString& accountId ) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace Accounts
|
||||||
|
} //namespace Tomahawk
|
||||||
|
|
||||||
|
#endif // CONFIGSTORAGE_H
|
@@ -66,14 +66,26 @@ CredentialsManager::CredentialsManager( QObject* parent )
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
CredentialsManager::loadCredentials( QList< Service > keysByService )
|
CredentialsManager::addService( const QString& service , const QStringList& accountIds )
|
||||||
{
|
{
|
||||||
foreach ( const Service svc, keysByService )
|
if ( m_services.contains( service ) )
|
||||||
|
m_services.remove( service );
|
||||||
|
m_services.insert( service, accountIds );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
CredentialsManager::loadCredentials()
|
||||||
{
|
{
|
||||||
tDebug() << Q_FUNC_INFO << "keys for service" << svc.name << ":" << svc.keys;
|
for ( QHash< QString, QStringList >::const_iterator it = m_services.constBegin();
|
||||||
foreach ( QString key, svc.keys )
|
it != m_services.constEnd(); ++it )
|
||||||
{
|
{
|
||||||
QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( svc.name, this );
|
const QString& svcName = it.key();
|
||||||
|
const QStringList& accountIds = it.value();
|
||||||
|
tDebug() << Q_FUNC_INFO << "keys for service" << svcName << ":" << accountIds;
|
||||||
|
foreach ( QString key, accountIds )
|
||||||
|
{
|
||||||
|
QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( svcName, this );
|
||||||
j->setKey( key );
|
j->setKey( key );
|
||||||
j->setAutoDelete( false );
|
j->setAutoDelete( false );
|
||||||
#if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC )
|
#if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC )
|
||||||
|
@@ -64,15 +64,11 @@ class CredentialsManager : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
struct Service
|
|
||||||
{
|
|
||||||
QString name;
|
|
||||||
QStringList keys;
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit CredentialsManager( QObject* parent = 0 );
|
explicit CredentialsManager( QObject* parent = 0 );
|
||||||
|
|
||||||
void loadCredentials( QList< Service > keysByService );
|
void addService( const QString& service, const QStringList& accountIds );
|
||||||
|
|
||||||
|
void loadCredentials();
|
||||||
|
|
||||||
QList< CredentialsStorageKey > keys() const;
|
QList< CredentialsStorageKey > keys() const;
|
||||||
|
|
||||||
@@ -88,6 +84,7 @@ private slots:
|
|||||||
void keychainJobFinished( QKeychain::Job* );
|
void keychainJobFinished( QKeychain::Job* );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QHash< QString, QStringList > m_services;
|
||||||
QHash< CredentialsStorageKey, QVariantHash > m_credentials;
|
QHash< CredentialsStorageKey, QVariantHash > m_credentials;
|
||||||
QList< QKeychain::ReadPasswordJob* > m_readJobs;
|
QList< QKeychain::ReadPasswordJob* > m_readJobs;
|
||||||
QMutex m_mutex;
|
QMutex m_mutex;
|
||||||
|
108
src/libtomahawk/accounts/LocalConfigStorage.cpp
Normal file
108
src/libtomahawk/accounts/LocalConfigStorage.cpp
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "LocalConfigStorage.h"
|
||||||
|
|
||||||
|
#include "Account.h"
|
||||||
|
#include "AccountManager.h"
|
||||||
|
#include "CredentialsManager.h"
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Accounts
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
LocalConfigStorage::LocalConfigStorage( QObject* parent )
|
||||||
|
: ConfigStorage( parent )
|
||||||
|
, m_credentialsServiceName( "Tomahawk" )
|
||||||
|
{
|
||||||
|
m_accountIds = TomahawkSettings::instance()->accounts();
|
||||||
|
|
||||||
|
// tell CredentialsManager which account ids it will be writing credentials for and in which svc
|
||||||
|
// so it can preload them when we call CM::loadCredentials()
|
||||||
|
AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName,
|
||||||
|
m_accountIds );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
LocalConfigStorage::accountIds() const
|
||||||
|
{
|
||||||
|
return m_accountIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalConfigStorage::save( const QString& accountId, const Account::Configuration& cfg )
|
||||||
|
{
|
||||||
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
|
s->beginGroup( "accounts/" + accountId );
|
||||||
|
s->setValue( "accountfriendlyname", cfg.accountFriendlyName );
|
||||||
|
s->setValue( "enabled", cfg.enabled );
|
||||||
|
s->setValue( "configuration", cfg.configuration );
|
||||||
|
s->setValue( "acl", cfg.acl );
|
||||||
|
s->setValue( "types", cfg.types );
|
||||||
|
s->endGroup();
|
||||||
|
s->sync();
|
||||||
|
|
||||||
|
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
||||||
|
c->setCredentials( m_credentialsServiceName, accountId, cfg.credentials );
|
||||||
|
|
||||||
|
if ( !m_accountIds.contains( accountId ) )
|
||||||
|
m_accountIds.append( accountId );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalConfigStorage::load( const QString& accountId, Account::Configuration& cfg )
|
||||||
|
{
|
||||||
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
|
s->beginGroup( "accounts/" + accountId );
|
||||||
|
cfg.accountFriendlyName = s->value( "accountfriendlyname", QString() ).toString();
|
||||||
|
cfg.enabled = s->value( "enabled", false ).toBool();
|
||||||
|
cfg.configuration = s->value( "configuration", QVariantHash() ).toHash();
|
||||||
|
cfg.acl = s->value( "acl", QVariantMap() ).toMap();
|
||||||
|
cfg.types = s->value( "types", QStringList() ).toStringList();
|
||||||
|
s->endGroup();
|
||||||
|
|
||||||
|
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
||||||
|
cfg.credentials = c->credentials( m_credentialsServiceName, accountId );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
LocalConfigStorage::remove( const QString& accountId )
|
||||||
|
{
|
||||||
|
TomahawkSettings* s = TomahawkSettings::instance();
|
||||||
|
s->beginGroup( "accounts/" + accountId );
|
||||||
|
s->remove( "accountfriendlyname" );
|
||||||
|
s->remove( "enabled" );
|
||||||
|
s->remove( "configuration" );
|
||||||
|
s->remove( "acl" );
|
||||||
|
s->remove( "types" );
|
||||||
|
s->endGroup();
|
||||||
|
s->remove( "accounts/" + accountId );
|
||||||
|
|
||||||
|
CredentialsManager* c = AccountManager::instance()->credentialsManager();
|
||||||
|
c->setCredentials( m_credentialsServiceName, accountId, QVariantHash() );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
55
src/libtomahawk/accounts/LocalConfigStorage.h
Normal file
55
src/libtomahawk/accounts/LocalConfigStorage.h
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LOCALCONFIGSTORAGE_H
|
||||||
|
#define LOCALCONFIGSTORAGE_H
|
||||||
|
|
||||||
|
#include "ConfigStorage.h"
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace Accounts
|
||||||
|
{
|
||||||
|
|
||||||
|
class LocalConfigStorage : public ConfigStorage
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit LocalConfigStorage( QObject* parent = 0 );
|
||||||
|
|
||||||
|
QString id() const { return "localconfigstorage"; }
|
||||||
|
|
||||||
|
QStringList accountIds() const;
|
||||||
|
|
||||||
|
virtual void save( const QString& accountId, const Account::Configuration& cfg );
|
||||||
|
virtual void load( const QString& accountId, Account::Configuration& cfg );
|
||||||
|
virtual void remove( const QString& accountId );
|
||||||
|
|
||||||
|
private:
|
||||||
|
const QString m_credentialsServiceName;
|
||||||
|
QStringList m_accountIds;
|
||||||
|
|
||||||
|
static LocalConfigStorage* s_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace Accounts
|
||||||
|
|
||||||
|
} //namespace Tomahawk
|
||||||
|
|
||||||
|
#endif // LOCALCONFIGSTORAGE_H
|
Reference in New Issue
Block a user