From 09a20e98d1d8ec27df574e1942f3b200ad9dbf92 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 30 May 2013 15:24:13 +0200 Subject: [PATCH 01/27] CredentialsManager can now read/write under different service names. --- src/libtomahawk/accounts/Account.cpp | 6 +- src/libtomahawk/accounts/AccountManager.cpp | 8 +- .../accounts/CredentialsManager.cpp | 96 +++++++++++++------ src/libtomahawk/accounts/CredentialsManager.h | 36 +++++-- 4 files changed, 108 insertions(+), 38 deletions(-) diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 9c168c85c..8cfdd659e 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -143,7 +143,7 @@ Account::syncConfig() s->sync(); CredentialsManager* c = AccountManager::instance()->credentialsManager(); - c->setCredentials( m_accountId, m_credentials ); + c->setCredentials( "Tomahawk", m_accountId, m_credentials ); } @@ -161,7 +161,7 @@ Account::loadFromConfig( const QString& accountId ) s->endGroup(); CredentialsManager* c = AccountManager::instance()->credentialsManager(); - m_credentials = c->credentials( m_accountId ); + m_credentials = c->credentials( "Tomahawk", m_accountId ); } @@ -179,7 +179,7 @@ Account::removeFromConfig() s->remove( "accounts/" + m_accountId ); CredentialsManager* c = AccountManager::instance()->credentialsManager(); - c->setCredentials( m_accountId, QVariantHash() ); + c->setCredentials( "Tomahawk", m_accountId, QVariantHash() ); } diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 8bd948eb9..71ff0b0a9 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -291,7 +291,13 @@ AccountManager::loadFromConfig() m_creds = new CredentialsManager( this ); NewClosure( m_creds, SIGNAL( ready() ), this, SLOT( finishLoadingFromConfig( QStringList ) ), accountIds ); - m_creds->loadCredentials( accountIds ); + + 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 ); } diff --git a/src/libtomahawk/accounts/CredentialsManager.cpp b/src/libtomahawk/accounts/CredentialsManager.cpp index 38ee1f6df..b0c62d1c7 100644 --- a/src/libtomahawk/accounts/CredentialsManager.cpp +++ b/src/libtomahawk/accounts/CredentialsManager.cpp @@ -24,7 +24,6 @@ #include -#define TOMAHAWK_KEYCHAINSVC QLatin1String("Tomahawk") namespace Tomahawk { @@ -32,6 +31,32 @@ namespace Tomahawk namespace Accounts { +CredentialsStorageKey::CredentialsStorageKey( const QString& service, const QString& key ) + : m_service( service ) + , m_key( key ) +{} + +bool +CredentialsStorageKey::operator ==( const CredentialsStorageKey& other ) const +{ + return ( m_key == other.m_key ) && ( m_service == other.m_service ); +} + + +bool +CredentialsStorageKey::operator !=( const CredentialsStorageKey& other ) const +{ + return !operator ==( other ); +} + +uint +qHash( const Tomahawk::Accounts::CredentialsStorageKey& key ) +{ + return qHash( key.service() + key.key() ); +} + + +// CredentialsManager CredentialsManager::CredentialsManager( QObject* parent ) : QObject( parent ) @@ -41,65 +66,74 @@ CredentialsManager::CredentialsManager( QObject* parent ) void -CredentialsManager::loadCredentials( QStringList keys ) +CredentialsManager::loadCredentials( QList< Service > keysByService ) { - tDebug() << Q_FUNC_INFO << "keys:" << keys; - foreach ( QString key, keys ) + foreach ( const Service svc, keysByService ) { - QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( TOMAHAWK_KEYCHAINSVC, this ); - j->setKey( key ); - j->setAutoDelete( false ); + tDebug() << Q_FUNC_INFO << "keys for service" << svc.name << ":" << svc.keys; + foreach ( QString key, svc.keys ) + { + QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( svc.name, this ); + j->setKey( key ); + j->setAutoDelete( false ); #if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC ) - j->setInsecureFallback( true ); + j->setInsecureFallback( true ); #endif - connect( j, SIGNAL( finished( QKeychain::Job* ) ), - SLOT( keychainJobFinished( QKeychain::Job* ) ) ); - m_readJobs << j; - j->start(); - tDebug() << "Launching QtKeychain readJob for" << key; + connect( j, SIGNAL( finished( QKeychain::Job* ) ), + SLOT( keychainJobFinished( QKeychain::Job* ) ) ); + m_readJobs << j; + j->start(); + tDebug() << "Launching QtKeychain readJob for" << key; + } } - } -QStringList +QList< CredentialsStorageKey > CredentialsManager::keys() const { - QStringList keys = m_credentials.keys(); + QList< CredentialsStorageKey > keys = m_credentials.keys(); return keys; } QVariantHash -CredentialsManager::credentials( const QString& key ) const +CredentialsManager::credentials( const CredentialsStorageKey& key ) const { return m_credentials.value( key ); } +QVariantHash +CredentialsManager::credentials( const QString& serviceName, const QString& key ) const +{ + return credentials( CredentialsStorageKey( serviceName, key ) ); +} + + void -CredentialsManager::setCredentials( const QString& key, const QVariantHash& value ) +CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QVariantHash& value ) { QMutexLocker locker( &m_mutex ); QKeychain::Job* j; if ( value.isEmpty() ) { - if ( !m_credentials.contains( key ) ) //if we don't have any credentials for this key, we bail + if ( !m_credentials.contains( csKey ) ) //if we don't have any credentials for this key, we bail return; - m_credentials.remove( key ); + m_credentials.remove( csKey ); - QKeychain::DeletePasswordJob* dj = new QKeychain::DeletePasswordJob( TOMAHAWK_KEYCHAINSVC, this ); - dj->setKey( key ); + QKeychain::DeletePasswordJob* dj = new QKeychain::DeletePasswordJob( csKey.service(), this ); + dj->setKey( csKey.key() ); j = dj; } else { - if ( value == m_credentials.value( key ) ) //if the credentials haven't actually changed, we bail + if ( value == m_credentials.value( csKey ) ) //if the credentials haven't actually changed, we bail return; - m_credentials.insert( key, value ); + m_credentials.insert( csKey, value ); QByteArray data; { @@ -107,8 +141,8 @@ CredentialsManager::setCredentials( const QString& key, const QVariantHash& valu ds << value; } - QKeychain::WritePasswordJob* wj = new QKeychain::WritePasswordJob( TOMAHAWK_KEYCHAINSVC, this ); - wj->setKey( key ); + QKeychain::WritePasswordJob* wj = new QKeychain::WritePasswordJob( csKey.service(), this ); + wj->setKey( csKey.key() ); wj->setBinaryData( data ); j = wj; } @@ -123,6 +157,13 @@ CredentialsManager::setCredentials( const QString& key, const QVariantHash& valu } +void +CredentialsManager::setCredentials( const QString& serviceName, const QString& key, const QVariantHash& value ) +{ + setCredentials( CredentialsStorageKey( serviceName, key ), value ); +} + + void CredentialsManager::keychainJobFinished( QKeychain::Job* j ) { @@ -137,7 +178,7 @@ CredentialsManager::keychainJobFinished( QKeychain::Job* j ) QDataStream dataStream( readJob->binaryData() ); dataStream >> creds; - m_credentials.insert( readJob->key(), creds ); + m_credentials.insert( CredentialsStorageKey( readJob->service(), readJob->key() ), creds ); } else { @@ -164,7 +205,6 @@ CredentialsManager::keychainJobFinished( QKeychain::Job* j ) j->deleteLater(); } - } //namespace Accounts } //namespace Tomahawk diff --git a/src/libtomahawk/accounts/CredentialsManager.h b/src/libtomahawk/accounts/CredentialsManager.h index ec751fa6a..f450aaeff 100644 --- a/src/libtomahawk/accounts/CredentialsManager.h +++ b/src/libtomahawk/accounts/CredentialsManager.h @@ -22,6 +22,7 @@ #include #include #include +#include namespace QKeychain @@ -30,13 +31,25 @@ class Job; class ReadPasswordJob; } - namespace Tomahawk { namespace Accounts { +class CredentialsStorageKey +{ +public: + explicit CredentialsStorageKey( const QString &service, const QString &key ); + bool operator ==( const CredentialsStorageKey& other ) const; + bool operator !=( const CredentialsStorageKey& other ) const; + QString service() const { return m_service; } + QString key() const { return m_key; } +private: + QString m_service; + QString m_key; +}; + /** * @brief The CredentialsManager class holds an in-memory cache of whatever credentials are stored * in the system's QtKeychain-accessible credentials storage. @@ -51,14 +64,22 @@ class CredentialsManager : public QObject { Q_OBJECT public: + struct Service + { + QString name; + QStringList keys; + }; + explicit CredentialsManager( QObject* parent = 0 ); - void loadCredentials( QStringList keys ); + void loadCredentials( QList< Service > keysByService ); - QStringList keys() const; + QList< CredentialsStorageKey > keys() const; - QVariantHash credentials( const QString& key ) const; - void setCredentials( const QString& key, const QVariantHash& value ); + QVariantHash credentials( const CredentialsStorageKey& key ) const; + QVariantHash credentials( const QString& serviceName, const QString& key ) const; + void setCredentials( const CredentialsStorageKey& key, const QVariantHash& value ); + void setCredentials( const QString& serviceName, const QString& key, const QVariantHash& value ); signals: void ready(); @@ -67,12 +88,15 @@ private slots: void keychainJobFinished( QKeychain::Job* ); private: - QHash< QString, QVariantHash > m_credentials; + QHash< CredentialsStorageKey, QVariantHash > m_credentials; QList< QKeychain::ReadPasswordJob* > m_readJobs; QMutex m_mutex; }; +uint qHash( const Tomahawk::Accounts::CredentialsStorageKey& key ); + } //namespace Accounts } //namespace Tomahawk + #endif // CREDENTIALSMANAGER_H From 63f9168b4af7b3e639e3be8c4c48120935daa173 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 2 Jun 2013 17:41:08 +0200 Subject: [PATCH 02/27] Added ConfigStorage and LocalConfigStorage, preparation for Telepathy. --- src/accounts/xmpp/XmppAccount.h | 2 +- src/libtomahawk/CMakeLists.txt | 1 + src/libtomahawk/accounts/Account.cpp | 63 +++------- src/libtomahawk/accounts/Account.h | 47 +++++--- src/libtomahawk/accounts/AccountManager.cpp | 55 ++++++--- src/libtomahawk/accounts/AccountManager.h | 7 +- src/libtomahawk/accounts/ConfigStorage.h | 54 +++++++++ .../accounts/CredentialsManager.cpp | 22 +++- src/libtomahawk/accounts/CredentialsManager.h | 11 +- .../accounts/LocalConfigStorage.cpp | 108 ++++++++++++++++++ src/libtomahawk/accounts/LocalConfigStorage.h | 55 +++++++++ 11 files changed, 327 insertions(+), 98 deletions(-) create mode 100644 src/libtomahawk/accounts/ConfigStorage.h create mode 100644 src/libtomahawk/accounts/LocalConfigStorage.cpp create mode 100644 src/libtomahawk/accounts/LocalConfigStorage.h diff --git a/src/accounts/xmpp/XmppAccount.h b/src/accounts/xmpp/XmppAccount.h index 077cdbaf3..b0593b3c2 100644 --- a/src/accounts/xmpp/XmppAccount.h +++ b/src/accounts/xmpp/XmppAccount.h @@ -52,7 +52,7 @@ public: QString description() const { return tr( "Log on to your Jabber/XMPP account to connect to your friends" ); } QString factoryId() const { return "xmppaccount"; } 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() ); }; diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 2c8b25ab8..277e92a9d 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -219,6 +219,7 @@ list(APPEND libSources accounts/AccountFactoryWrapper.cpp accounts/AccountFactoryWrapperDelegate.cpp accounts/AccountConfigWidget.cpp + accounts/LocalConfigStorage.cpp accounts/spotify/SpotifyAccount.cpp accounts/spotify/SpotifyAccountConfig.cpp diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 8cfdd659e..0cda69122 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -2,6 +2,7 @@ * * Copyright 2011, Christian Muehlhaeuser * Copyright 2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,9 +20,9 @@ #include "Account.h" -#include "TomahawkSettings.h" #include "AccountManager.h" #include "CredentialsManager.h" +#include "ConfigStorage.h" namespace Tomahawk { @@ -51,10 +52,11 @@ accountTypeToString( AccountType type ) Account::Account( const QString& accountId ) : QObject() - , m_enabled( false ) , m_accountId( accountId ) { - connect( this, SIGNAL( error( int, QString ) ), this, SLOT( onError( int,QString ) ) ); + m_cfg.enabled = false; + + 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 ) ) ); loadFromConfig( accountId ); @@ -132,18 +134,7 @@ Account::onConnectionStateChanged( Account::ConnectionState ) void Account::syncConfig() { - TomahawkSettings* s = TomahawkSettings::instance(); - 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 ); + AccountManager::instance()->configStorageForAccount( m_accountId )->save( m_accountId, m_cfg ); } @@ -151,35 +142,15 @@ void Account::loadFromConfig( const QString& 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(); - m_credentials = c->credentials( "Tomahawk", m_accountId ); + AccountManager::instance()->configStorageForAccount( m_accountId )->load( m_accountId, m_cfg ); } void Account::removeFromConfig() { - TomahawkSettings* s = TomahawkSettings::instance(); - 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() ); + AccountManager::instance()->configStorageForAccount( m_accountId )->remove( m_accountId ); } @@ -187,15 +158,15 @@ void Account::setTypes( AccountTypes types ) { QMutexLocker locker( &m_mutex ); - m_types = QStringList(); + m_cfg.types = QStringList(); if ( types & InfoType ) - m_types << "InfoType"; + m_cfg.types << "InfoType"; if ( types & SipType ) - m_types << "SipType"; + m_cfg.types << "SipType"; if ( types & ResolverType ) - m_types << "ResolverType"; + m_cfg.types << "ResolverType"; if ( types & StatusPushType ) - m_types << "StatusPushType"; + m_cfg.types << "StatusPushType"; syncConfig(); } @@ -205,13 +176,13 @@ Account::types() const { QMutexLocker locker( &m_mutex ); AccountTypes types; - if ( m_types.contains( "InfoType" ) ) + if ( m_cfg.types.contains( "InfoType" ) ) types |= InfoType; - if ( m_types.contains( "SipType" ) ) + if ( m_cfg.types.contains( "SipType" ) ) types |= SipType; - if ( m_types.contains( "ResolverType" ) ) + if ( m_cfg.types.contains( "ResolverType" ) ) types |= ResolverType; - if ( m_types.contains( "StatusPushType" ) ) + if ( m_cfg.types.contains( "StatusPushType" ) ) types |= StatusPushType; return types; diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index d7b54d0a5..436335af7 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -2,6 +2,7 @@ * * Copyright 2011, Christian Muehlhaeuser * Copyright 2011, Leo Franchi + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -41,6 +42,8 @@ namespace Tomahawk namespace Accounts { +class ConfigStorage; + enum AccountType { NoType = 0x00, @@ -66,18 +69,28 @@ class DLLEXPORT Account : public QObject Q_OBJECT public: + struct Configuration + { + QString accountFriendlyName; + bool enabled; + QVariantHash configuration; + QVariantMap acl; + QStringList types; + QVariantHash credentials; + }; + enum AuthErrorCode { AuthError, ConnectionError }; enum ConnectionState { Disconnected, Connecting, Connected, Disconnecting }; - explicit Account( const QString &accountId ); + explicit Account(const QString &accountId); virtual ~Account(); 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. - bool enabled() const { QMutexLocker locker( &m_mutex ); return m_enabled; } + 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_cfg.enabled; } 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. @@ -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 - 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 bool isAuthenticated() const = 0; @@ -113,15 +126,16 @@ public: AccountTypes types() const; 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 setEnabled( bool enabled ) { QMutexLocker locker( &m_mutex ); m_enabled = enabled; } + void setAccountFriendlyName( const QString &friendlyName ) { QMutexLocker locker( &m_mutex ); m_cfg.accountFriendlyName = friendlyName; } + 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 setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_credentials = credentialHash; } - void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_configuration = configuration; } - void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_acl = acl; } + void setCredentials( const QVariantHash &credentialHash ) { QMutexLocker locker( &m_mutex ); m_cfg.credentials = credentialHash; } + void setConfiguration( const QVariantHash &configuration ) { QMutexLocker locker( &m_mutex ); m_cfg.configuration = configuration; } + void setAcl( const QVariantMap &acl ) { QMutexLocker locker( &m_mutex ); m_cfg.acl = acl; } + 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 @@ -150,15 +164,12 @@ private slots: private: QString m_accountServiceName; - QString m_accountFriendlyName; QString m_cachedError; - bool m_enabled; QString m_accountId; - QVariantHash m_credentials; - QVariantHash m_configuration; - QVariantMap m_acl; - QStringList m_types; + mutable QMutex m_mutex; + + Account::Configuration m_cfg; }; class DLLEXPORT AccountFactory : public QObject diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 71ff0b0a9..88ec4c4e7 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -32,6 +32,7 @@ #include "ResolverAccount.h" #include "SourceList.h" #include "TomahawkSettings.h" +#include "LocalConfigStorage.h" #include #include @@ -284,38 +285,42 @@ AccountManager::toggleAccountsConnected() void 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; - m_creds = new CredentialsManager( this ); NewClosure( m_creds, SIGNAL( ready() ), - this, SLOT( finishLoadingFromConfig( QStringList ) ), accountIds ); - - 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 ); + this, SLOT( finishLoadingFromConfig() ) ); + m_creds->loadCredentials(); } void -AccountManager::finishLoadingFromConfig( const QStringList& accountIds ) +AccountManager::finishLoadingFromConfig() { - qDebug() << "LOADING ALL ACCOUNTS" << accountIds; - - foreach ( const QString& accountId, accountIds ) + foreach ( ConfigStorage* cs, m_configStorageById ) { - QString pluginFactory = factoryFromId( accountId ); - if ( m_accountFactories.contains( pluginFactory ) ) + QStringList accountIds = cs->accountIds(); + + qDebug() << "LOADING ALL ACCOUNTS FOR STORAGE" << cs->metaObject()->className() + << ":" << accountIds; + + foreach ( const QString& accountId, accountIds ) { - Account* account = loadPlugin( accountId ); - addAccount( account ); + QString pluginFactory = factoryFromId( accountId ); + if ( m_accountFactories.contains( pluginFactory ) ) + { + Account* account = loadPlugin( accountId ); + addAccount( account ); + } } } - m_readyForSip = true; 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 AccountManager::hookupAccount( Account* account ) const { diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index 3e74802cc..0e9f5efd1 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -95,6 +95,7 @@ public: bool isReady() const { return m_completelyReady; } CredentialsManager* credentialsManager() const { return m_creds; } + ConfigStorage* configStorageForAccount( const QString& accountId ); public slots: void connectAll(); @@ -119,7 +120,7 @@ private slots: void init(); void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state ); void onError( int code, const QString& msg ); - void finishLoadingFromConfig( const QStringList& accountIds ); + void finishLoadingFromConfig(); void onSettingsChanged(); @@ -129,7 +130,7 @@ private: void loadPluginFactory( const QString &path ); QString factoryFromId( const QString& accountId ) const; - Account* loadPlugin( const QString &accountId ); + Account* loadPlugin( const QString& accountId ); void hookupAccount( Account* ) const; CredentialsManager* m_creds; @@ -145,6 +146,8 @@ private: QHash< QString, AccountFactory* > m_accountFactories; QList< AccountFactory* > m_factoriesForFilesytem; + QMap< QString, ConfigStorage* > m_configStorageById; + static AccountManager* s_instance; }; diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h new file mode 100644 index 000000000..ad95fe5a7 --- /dev/null +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -0,0 +1,54 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#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 diff --git a/src/libtomahawk/accounts/CredentialsManager.cpp b/src/libtomahawk/accounts/CredentialsManager.cpp index b0c62d1c7..3f0be86d1 100644 --- a/src/libtomahawk/accounts/CredentialsManager.cpp +++ b/src/libtomahawk/accounts/CredentialsManager.cpp @@ -66,14 +66,26 @@ CredentialsManager::CredentialsManager( QObject* parent ) 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() +{ + for ( QHash< QString, QStringList >::const_iterator it = m_services.constBegin(); + it != m_services.constEnd(); ++it ) { - tDebug() << Q_FUNC_INFO << "keys for service" << svc.name << ":" << svc.keys; - foreach ( QString key, svc.keys ) + 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( svc.name, this ); + QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( svcName, this ); j->setKey( key ); j->setAutoDelete( false ); #if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC ) diff --git a/src/libtomahawk/accounts/CredentialsManager.h b/src/libtomahawk/accounts/CredentialsManager.h index f450aaeff..aa000709e 100644 --- a/src/libtomahawk/accounts/CredentialsManager.h +++ b/src/libtomahawk/accounts/CredentialsManager.h @@ -64,15 +64,11 @@ class CredentialsManager : public QObject { Q_OBJECT public: - struct Service - { - QString name; - QStringList keys; - }; - explicit CredentialsManager( QObject* parent = 0 ); - void loadCredentials( QList< Service > keysByService ); + void addService( const QString& service, const QStringList& accountIds ); + + void loadCredentials(); QList< CredentialsStorageKey > keys() const; @@ -88,6 +84,7 @@ private slots: void keychainJobFinished( QKeychain::Job* ); private: + QHash< QString, QStringList > m_services; QHash< CredentialsStorageKey, QVariantHash > m_credentials; QList< QKeychain::ReadPasswordJob* > m_readJobs; QMutex m_mutex; diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp new file mode 100644 index 000000000..b1581b978 --- /dev/null +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -0,0 +1,108 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#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() ); +} + +} +} diff --git a/src/libtomahawk/accounts/LocalConfigStorage.h b/src/libtomahawk/accounts/LocalConfigStorage.h new file mode 100644 index 000000000..31f04d0b0 --- /dev/null +++ b/src/libtomahawk/accounts/LocalConfigStorage.h @@ -0,0 +1,55 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#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 From e4fbe9bffb0ae92783212d4431fa5a10a6e523dd Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 10 Jun 2013 19:08:51 +0200 Subject: [PATCH 03/27] Create TelepathyConfigStorage as plugin, and link against TelepathyQt. --- CMakeLists.txt | 5 + CMakeModules/FindTelepathyQt.cmake | 27 ++++ src/libtomahawk/CMakeLists.txt | 2 + src/libtomahawk/accounts/AccountManager.cpp | 5 +- .../accounts/ConfigStorageDllMacro.h | 32 +++++ src/libtomahawk/accounts/CredentialsManager.h | 4 +- .../accounts/configstorage/CMakeLists.txt | 14 +++ .../configstorage/telepathy/CMakeLists.txt | 11 ++ .../telepathy/TelepathyConfigStorage.cpp | 115 ++++++++++++++++++ .../telepathy/TelepathyConfigStorage.h | 56 +++++++++ src/tomahawk/Config.h.in | 2 +- 11 files changed, 269 insertions(+), 4 deletions(-) create mode 100644 CMakeModules/FindTelepathyQt.cmake create mode 100644 src/libtomahawk/accounts/ConfigStorageDllMacro.h create mode 100644 src/libtomahawk/accounts/configstorage/CMakeLists.txt create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 35909aafa..9c52db193 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,11 @@ macro_log_feature(LIBLASTFM_FOUND "liblastfm" "Qt library for the Last.fm webser macro_optional_find_package(QtKeychain 0.1.0) macro_log_feature(QTKEYCHAIN_FOUND "QtKeychain" "Provides support for secure credentials storage" "https://github.com/frankosterfeld/qtkeychain" TRUE "" "") +if( UNIX AND NOT APPLE ) + macro_optional_find_package(TelepathyQt 0.9.3) + macro_log_feature(TelepathyQt4_FOUND "Telepathy-Qt" "Telepathy-Qt is a Qt high-level binding for Telepathy, a D-Bus framework for unifying real time communication." FALSE "" "Telepathy-Qt is needed for sharing Jabber/GTalk accounts with Telepathy.\n") +endif() + # we need pthreads too macro_optional_find_package(Threads) macro_log_feature(THREADS_FOUND "Threads" "Threading Library" "" TRUE "" "Platform specific library for threading") diff --git a/CMakeModules/FindTelepathyQt.cmake b/CMakeModules/FindTelepathyQt.cmake new file mode 100644 index 000000000..2b286856b --- /dev/null +++ b/CMakeModules/FindTelepathyQt.cmake @@ -0,0 +1,27 @@ +# Copyright (c) 2013, Teo Mrnjavac + +include(FindPackageHandleStandardArgs) + +if( NOT BUILD_WITH_QT4 ) + find_package(TelepathyQt5 NO_MODULE) + set(TelepathyQt_FOUND ${TelepathyQt5_FOUND}) + set(TELEPATHY_QT_VERSION ${TELEPATHY_QT5_VERSION}) + set(TELEPATHY_QT_INSTALL_DIR ${TELEPATHY_QT5_INSTALL_DIR}) + set(TELEPATHY_QT_INCLUDE_DIR ${TELEPATHY_QT5_INCLUDE_DIR}) + set(TELEPATHY_QT_LIB_DIR ${TELEPATHY_QT5_LIB_DIR}) + set(TELEPATHY_QT_SHARE_DIR ${TELEPATHY_QT5_SHARE_DIR}) + set(TELEPATHY_QT_LIBRARIES ${TELEPATHY_QT5_LIBRARIES}) +else() + find_package(TelepathyQt4 NO_MODULE) + set(TelepathyQt_FOUND ${TelepathyQt4_FOUND}) + set(TELEPATHY_QT_VERSION ${TELEPATHY_QT4_VERSION}) + set(TELEPATHY_QT_INSTALL_DIR ${TELEPATHY_QT4_INSTALL_DIR}) + set(TELEPATHY_QT_INCLUDE_DIR ${TELEPATHY_QT4_INCLUDE_DIR}) + set(TELEPATHY_QT_LIB_DIR ${TELEPATHY_QT4_LIB_DIR}) + set(TELEPATHY_QT_SHARE_DIR ${TELEPATHY_QT4_SHARE_DIR}) + set(TELEPATHY_QT_LIBRARIES ${TELEPATHY_QT4_LIBRARIES}) +endif() + +set(TELEPATHY_QT_FOUND ${TelepathyQt_FOUND}) + +find_package_handle_standard_args(TelepathyQt DEFAULT_MSG TELEPATHY_QT_INSTALL_DIR ) diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 277e92a9d..8dd9992db 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -365,6 +365,8 @@ list(APPEND libSources thirdparty/kdsingleapplicationguard/kdlockedsharedmemorypointer.cpp ) +add_subdirectory( accounts/configstorage ) + IF(LIBLASTFM_FOUND) include_directories( ${LIBLASTFM_INCLUDE_DIRS} ) list(APPEND LINK_LIBRARIES ${LIBLASTFM_LIBRARIES} ) diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 88ec4c4e7..7b758e085 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -286,9 +286,10 @@ void AccountManager::loadFromConfig() { m_creds = new CredentialsManager( this ); - ConfigStorage* configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor - m_configStorageById.insert( configStorage->id(), configStorage ); + ConfigStorage* configStorage; + configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor + m_configStorageById.insert( configStorage->id(), configStorage ); QStringList accountIds; foreach ( ConfigStorage* cs, m_configStorageById ) diff --git a/src/libtomahawk/accounts/ConfigStorageDllMacro.h b/src/libtomahawk/accounts/ConfigStorageDllMacro.h new file mode 100644 index 000000000..4a1db7294 --- /dev/null +++ b/src/libtomahawk/accounts/ConfigStorageDllMacro.h @@ -0,0 +1,32 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#ifndef CONFIGSTORAGEDLLMACRO_H +#define CONFIGSTORAGEDLLMACRO_H + +#include + +#ifndef CONFIGSTORAGEDLLEXPORT +# if defined (CONFIGSTORAGEDLLEXPORT_PRO) +# define CONFIGSTORAGEDLLEXPORT Q_DECL_EXPORT +# else +# define CONFIGSTORAGEDLLEXPORT Q_DECL_IMPORT +# endif +#endif + +#endif // CONFIGSTORAGEDLLMACRO_H diff --git a/src/libtomahawk/accounts/CredentialsManager.h b/src/libtomahawk/accounts/CredentialsManager.h index aa000709e..eaf7b4f46 100644 --- a/src/libtomahawk/accounts/CredentialsManager.h +++ b/src/libtomahawk/accounts/CredentialsManager.h @@ -19,6 +19,8 @@ #ifndef CREDENTIALSMANAGER_H #define CREDENTIALSMANAGER_H +#include "DllMacro.h" + #include #include #include @@ -60,7 +62,7 @@ private: * This ensures an illusion of synchronous operations for Tomahawk's Account classes, even though all * QtKeychain jobs are async. */ -class CredentialsManager : public QObject +class DLLEXPORT CredentialsManager : public QObject { Q_OBJECT public: diff --git a/src/libtomahawk/accounts/configstorage/CMakeLists.txt b/src/libtomahawk/accounts/configstorage/CMakeLists.txt new file mode 100644 index 000000000..88ac22f2d --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/CMakeLists.txt @@ -0,0 +1,14 @@ +include( ${CMAKE_CURRENT_LIST_DIR}/../../../../TomahawkAddPlugin.cmake ) + +file(GLOB SUBDIRECTORIES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*") +foreach(SUBDIRECTORY ${SUBDIRECTORIES}) + if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUBDIRECTORY}/CMakeLists.txt") + if(SUBDIRECTORY STREQUAL "telepathy") + if( TelepathyQt_FOUND ) + add_subdirectory( telepathy ) + endif() + else() + add_subdirectory(${SUBDIRECTORY}) + endif() + endif() +endforeach() diff --git a/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt b/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt new file mode 100644 index 000000000..25f64f7ea --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt @@ -0,0 +1,11 @@ +include_directories(${TELEPATHY_QT_INCLUDE_DIR}) + +tomahawk_add_plugin(telepathy + TYPE configstorage + EXPORT_MACRO CONFIGSTORAGEDLLEXPORT_PRO + SOURCES + TelepathyConfigStorage.cpp + LINK_LIBRARIES + ${TOMAHAWK_LIBRARIES} + ${TELEPATHY_QT_LIBRARIES} +) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp new file mode 100644 index 000000000..acf2cb582 --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -0,0 +1,115 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#include "TelepathyConfigStorage.h" + +#include "accounts/Account.h" +#include "accounts/AccountManager.h" +#include "accounts/CredentialsManager.h" +#include "utils/Logger.h" + + +namespace Tomahawk +{ + +namespace Accounts +{ + + +TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent ) + : ConfigStorage( parent ) + , m_credentialsServiceName( "telepathy-kde" ) +{ + tDebug() << Q_FUNC_INFO; + + + // 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 +TelepathyConfigStorage::accountIds() const +{ + return m_accountIds; +} + + +void +TelepathyConfigStorage::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 +TelepathyConfigStorage::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(); + QString prefix( "tomahawkaccount_" ); + QString idInKeychain = accountId; + if ( idInKeychain.startsWith( prefix ) ) + idInKeychain.remove( 0, prefix.length() ); + cfg.credentials = c->credentials( m_credentialsServiceName, idInKeychain ); +} + + +void +TelepathyConfigStorage::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() ); +} + +} +} diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h new file mode 100644 index 000000000..c85df045c --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -0,0 +1,56 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#ifndef TELEPATHYCONFIGSTORAGE_H +#define TELEPATHYCONFIGSTORAGE_H + +#include "accounts/ConfigStorageDllMacro.h" +#include "accounts/ConfigStorage.h" + +namespace Tomahawk +{ + +namespace Accounts +{ + +class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorage : public ConfigStorage +{ + Q_OBJECT +public: + explicit TelepathyConfigStorage( QObject* parent = 0 ); + + QString id() const { return "telepathyconfigstorage"; } + + 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 TelepathyConfigStorage* s_instance; +}; + +} //namespace Accounts + +} //namespace Tomahawk + +#endif // TELEPATHYCONFIGSTORAGE_H diff --git a/src/tomahawk/Config.h.in b/src/tomahawk/Config.h.in index 60e0c37ec..27500df65 100644 --- a/src/tomahawk/Config.h.in +++ b/src/tomahawk/Config.h.in @@ -19,7 +19,7 @@ #cmakedefine WITH_UPOWER #cmakedefine WITH_GNOMESHORTCUTHANDLER - +#cmakedefine TELEPATHY_QT_FOUND #cmakedefine LIBLASTFM_FOUND #cmakedefine QCA2_FOUND From 08158ca405d9e9504c6e5cd2761ff6ae4e2f29dd Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 11 Jun 2013 18:08:45 +0200 Subject: [PATCH 04/27] ConfigStorage is now in charge of initializing its own account credentials in CredentialsManager. --- src/libtomahawk/CMakeLists.txt | 1 + src/libtomahawk/accounts/AccountManager.cpp | 12 +--- src/libtomahawk/accounts/ConfigStorage.cpp | 41 +++++++++++++ src/libtomahawk/accounts/ConfigStorage.h | 11 ++-- .../accounts/CredentialsManager.cpp | 57 +++++++++++-------- src/libtomahawk/accounts/CredentialsManager.h | 21 ++++--- .../accounts/LocalConfigStorage.cpp | 21 ++++++- src/libtomahawk/accounts/LocalConfigStorage.h | 4 ++ .../telepathy/TelepathyConfigStorage.cpp | 1 - 9 files changed, 118 insertions(+), 51 deletions(-) create mode 100644 src/libtomahawk/accounts/ConfigStorage.cpp diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 8dd9992db..21777479a 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -219,6 +219,7 @@ list(APPEND libSources accounts/AccountFactoryWrapper.cpp accounts/AccountFactoryWrapperDelegate.cpp accounts/AccountConfigWidget.cpp + accounts/ConfigStorage.cpp accounts/LocalConfigStorage.cpp accounts/spotify/SpotifyAccount.cpp diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 7b758e085..ec8776a13 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -286,19 +286,13 @@ void AccountManager::loadFromConfig() { m_creds = new CredentialsManager( this ); - ConfigStorage* configStorage; - configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor + 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; - - NewClosure( m_creds, SIGNAL( ready() ), + //TODO: when we get more than one CS, hook them all up to continue with account loading + NewClosure( configStorage, SIGNAL( ready() ), this, SLOT( finishLoadingFromConfig() ) ); - m_creds->loadCredentials(); } diff --git a/src/libtomahawk/accounts/ConfigStorage.cpp b/src/libtomahawk/accounts/ConfigStorage.cpp new file mode 100644 index 000000000..8ee9fee76 --- /dev/null +++ b/src/libtomahawk/accounts/ConfigStorage.cpp @@ -0,0 +1,41 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#include "ConfigStorage.h" + + + +namespace Tomahawk +{ + +namespace Accounts +{ + +ConfigStorage::ConfigStorage( QObject* parent ) + : QObject( parent ) +{ +} + + +ConfigStorage::~ConfigStorage() +{ +} + + +} //ns +} //ns diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h index ad95fe5a7..69a531186 100644 --- a/src/libtomahawk/accounts/ConfigStorage.h +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -29,14 +29,13 @@ namespace Tomahawk namespace Accounts { -class ConfigStorage : public QObject +class DLLEXPORT ConfigStorage : public QObject { + Q_OBJECT public: - explicit ConfigStorage( QObject* parent ) - : QObject( parent ) - {} + explicit ConfigStorage( QObject* parent = 0 ); - virtual ~ConfigStorage() {} + virtual ~ConfigStorage(); virtual QString id() const = 0; @@ -46,6 +45,8 @@ public: virtual void load( const QString& accountId, Account::Configuration& cfg ) = 0; virtual void remove( const QString& accountId ) = 0; +signals: + void ready(); //emit this when done with whatever it is that needs to be initialized }; } //namespace Accounts diff --git a/src/libtomahawk/accounts/CredentialsManager.cpp b/src/libtomahawk/accounts/CredentialsManager.cpp index 3f0be86d1..8daed33b7 100644 --- a/src/libtomahawk/accounts/CredentialsManager.cpp +++ b/src/libtomahawk/accounts/CredentialsManager.cpp @@ -71,44 +71,53 @@ CredentialsManager::addService( const QString& service , const QStringList& acco if ( m_services.contains( service ) ) m_services.remove( service ); m_services.insert( service, accountIds ); + loadCredentials( service ); } void -CredentialsManager::loadCredentials() +CredentialsManager::loadCredentials( const QString &service ) { - for ( QHash< QString, QStringList >::const_iterator it = m_services.constBegin(); - it != m_services.constEnd(); ++it ) + + const QStringList& accountIds = m_services.value( service ); + tDebug() << Q_FUNC_INFO << "keys for service" << service << ":" << accountIds; + foreach ( QString key, accountIds ) { - 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->setAutoDelete( false ); + QKeychain::ReadPasswordJob* j = new QKeychain::ReadPasswordJob( service, this ); + j->setKey( key ); + j->setAutoDelete( false ); #if defined( Q_OS_UNIX ) && !defined( Q_OS_MAC ) - j->setInsecureFallback( true ); + j->setInsecureFallback( true ); #endif - connect( j, SIGNAL( finished( QKeychain::Job* ) ), - SLOT( keychainJobFinished( QKeychain::Job* ) ) ); - m_readJobs << j; - j->start(); - tDebug() << "Launching QtKeychain readJob for" << key; - } + connect( j, SIGNAL( finished( QKeychain::Job* ) ), + SLOT( keychainJobFinished( QKeychain::Job* ) ) ); + m_readJobs[ service ] << j; + j->start(); + tDebug() << "Launching QtKeychain readJob for" << key; } } -QList< CredentialsStorageKey > -CredentialsManager::keys() const +QStringList +CredentialsManager::keys( const QString& service ) const { - QList< CredentialsStorageKey > keys = m_credentials.keys(); + QStringList keys; + foreach ( const CredentialsStorageKey& k, m_credentials.keys() ) + { + if ( k.service() == service ) + keys << k.key(); + } return keys; } +QStringList +CredentialsManager::services() const +{ + return m_services.keys(); +} + + QVariantHash CredentialsManager::credentials( const CredentialsStorageKey& key ) const { @@ -197,11 +206,11 @@ CredentialsManager::keychainJobFinished( QKeychain::Job* j ) tDebug() << "QtKeychain readJob for" << readJob->key() << "finished with error:" << j->error() << j->errorString(); } - m_readJobs.removeOne( readJob ); + m_readJobs[ readJob->service() ].removeOne( readJob ); - if ( m_readJobs.isEmpty() ) + if ( m_readJobs[ readJob->service() ].isEmpty() ) { - emit ready(); + emit serviceReady( readJob->service() ); } } else if ( QKeychain::WritePasswordJob* writeJob = qobject_cast< QKeychain::WritePasswordJob* >( j ) ) diff --git a/src/libtomahawk/accounts/CredentialsManager.h b/src/libtomahawk/accounts/CredentialsManager.h index eaf7b4f46..5e21b4da8 100644 --- a/src/libtomahawk/accounts/CredentialsManager.h +++ b/src/libtomahawk/accounts/CredentialsManager.h @@ -55,10 +55,6 @@ private: /** * @brief The CredentialsManager class holds an in-memory cache of whatever credentials are stored * in the system's QtKeychain-accessible credentials storage. - * After instantiating the class, loadCredentials should be called, and this is the only time a read - * operation from QtKeychain is performed. When CredentialsManager emits ready(), it can be used for - * all other operations. The only QtKeychain operations performed at any time after startup are - * write and delete. * This ensures an illusion of synchronous operations for Tomahawk's Account classes, even though all * QtKeychain jobs are async. */ @@ -70,25 +66,28 @@ public: void addService( const QString& service, const QStringList& accountIds ); - void loadCredentials(); + QStringList keys( const QString& service ) const; + QStringList services() const; - QList< CredentialsStorageKey > keys() const; - - QVariantHash credentials( const CredentialsStorageKey& key ) const; QVariantHash credentials( const QString& serviceName, const QString& key ) const; - void setCredentials( const CredentialsStorageKey& key, const QVariantHash& value ); void setCredentials( const QString& serviceName, const QString& key, const QVariantHash& value ); signals: - void ready(); + void serviceReady( const QString& service ); private slots: + void loadCredentials( const QString& service ); + void keychainJobFinished( QKeychain::Job* ); +protected: + QVariantHash credentials( const CredentialsStorageKey& key ) const; + void setCredentials( const CredentialsStorageKey& key, const QVariantHash& value ); + private: QHash< QString, QStringList > m_services; QHash< CredentialsStorageKey, QVariantHash > m_credentials; - QList< QKeychain::ReadPasswordJob* > m_readJobs; + QHash< QString, QList< QKeychain::ReadPasswordJob* > > m_readJobs; QMutex m_mutex; }; diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp index b1581b978..878e722cd 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.cpp +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -21,6 +21,7 @@ #include "Account.h" #include "AccountManager.h" #include "CredentialsManager.h" +#include "utils/Logger.h" namespace Tomahawk { @@ -36,9 +37,27 @@ LocalConfigStorage::LocalConfigStorage( QObject* parent ) 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() + + CredentialsManager* cm = AccountManager::instance()->credentialsManager(); + connect( cm, SIGNAL( serviceReady( QString ) ), + this, SLOT( onCredentialsManagerReady( QString ) ) ); AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName, m_accountIds ); + + tDebug() << Q_FUNC_INFO << "LOADING ALL CREDENTIALS FOR SERVICE" << m_credentialsServiceName << m_accountIds; +} + + +void +LocalConfigStorage::onCredentialsManagerReady( const QString& service ) +{ + if ( service != m_credentialsServiceName ) + return; + + //no need to listen for it any more + disconnect( this, SLOT( onCredentialsManagerReady( QString ) ) ); + + emit ready(); } diff --git a/src/libtomahawk/accounts/LocalConfigStorage.h b/src/libtomahawk/accounts/LocalConfigStorage.h index 31f04d0b0..3540bebd9 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.h +++ b/src/libtomahawk/accounts/LocalConfigStorage.h @@ -41,6 +41,10 @@ public: virtual void load( const QString& accountId, Account::Configuration& cfg ); virtual void remove( const QString& accountId ); + +private slots: + void onCredentialsManagerReady( const QString& service ); + private: const QString m_credentialsServiceName; QStringList m_accountIds; diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index acf2cb582..ecae779bf 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -37,7 +37,6 @@ TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent ) { tDebug() << Q_FUNC_INFO; - // 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, From ebd7091fda5cb342ee72039f27e00f00955378da Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 12 Jun 2013 16:56:37 +0200 Subject: [PATCH 05/27] Asyncify ConfigStorage loading, and allow multiple ConfigStorages. --- src/libtomahawk/accounts/AccountManager.cpp | 31 +++++++++++++------ src/libtomahawk/accounts/AccountManager.h | 7 +++-- src/libtomahawk/accounts/ConfigStorage.h | 5 +++ .../accounts/LocalConfigStorage.cpp | 5 +++ src/libtomahawk/accounts/LocalConfigStorage.h | 2 ++ .../telepathy/TelepathyConfigStorage.cpp | 6 ++++ .../telepathy/TelepathyConfigStorage.h | 2 ++ 7 files changed, 46 insertions(+), 12 deletions(-) diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index ec8776a13..3b9dcd33e 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -287,19 +288,31 @@ AccountManager::loadFromConfig() { m_creds = new CredentialsManager( this ); - ConfigStorage* configStorage = new LocalConfigStorage( this ); //registers with CredentialsManager in the ctor + QSharedPointer< ConfigStorage > configStorage; + configStorage = QSharedPointer< ConfigStorage >( new LocalConfigStorage( this ) ); m_configStorageById.insert( configStorage->id(), configStorage ); - //TODO: when we get more than one CS, hook them all up to continue with account loading - NewClosure( configStorage, SIGNAL( ready() ), - this, SLOT( finishLoadingFromConfig() ) ); + + foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) + { + m_configStorageLoading.insert( cs->id() ); + NewClosure( cs.data(), SIGNAL( ready() ), + this, SLOT( finishLoadingFromConfig( QSharedPointer< ConfigStorage > ) ), cs ); + cs->init(); + } } void -AccountManager::finishLoadingFromConfig() +AccountManager::finishLoadingFromConfig( const QSharedPointer< ConfigStorage >& cs ) { - foreach ( ConfigStorage* cs, m_configStorageById ) + if ( m_configStorageLoading.contains( cs->id() ) ) + m_configStorageLoading.remove( cs->id() ); + + if ( !m_configStorageLoading.isEmpty() ) + return; + + foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) { QStringList accountIds = cs->accountIds(); @@ -453,15 +466,15 @@ AccountManager::zeroconfAccount() const } -ConfigStorage* +QSharedPointer< ConfigStorage > AccountManager::configStorageForAccount( const QString& accountId ) { - foreach ( ConfigStorage* cs, m_configStorageById ) + foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) { if ( cs->accountIds().contains( accountId ) ) return cs; } - return 0; + return QSharedPointer< ConfigStorage >(); } diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index 0e9f5efd1..bc56f9d44 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -95,7 +95,7 @@ public: bool isReady() const { return m_completelyReady; } CredentialsManager* credentialsManager() const { return m_creds; } - ConfigStorage* configStorageForAccount( const QString& accountId ); + QSharedPointer< ConfigStorage > configStorageForAccount( const QString& accountId ); public slots: void connectAll(); @@ -120,7 +120,7 @@ private slots: void init(); void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state ); void onError( int code, const QString& msg ); - void finishLoadingFromConfig(); + void finishLoadingFromConfig( const QSharedPointer< ConfigStorage >& cs ); void onSettingsChanged(); @@ -146,7 +146,8 @@ private: QHash< QString, AccountFactory* > m_accountFactories; QList< AccountFactory* > m_factoriesForFilesytem; - QMap< QString, ConfigStorage* > m_configStorageById; + QMap< QString, QSharedPointer< ConfigStorage > > m_configStorageById; + QSet< QString > m_configStorageLoading; static AccountManager* s_instance; }; diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h index 69a531186..cbf784918 100644 --- a/src/libtomahawk/accounts/ConfigStorage.h +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -22,6 +22,7 @@ #include "TomahawkSettings.h" #include "Account.h" +#include namespace Tomahawk { @@ -37,6 +38,8 @@ public: virtual ~ConfigStorage(); + virtual void init() = 0; + virtual QString id() const = 0; virtual QStringList accountIds() const = 0; @@ -52,4 +55,6 @@ signals: } //namespace Accounts } //namespace Tomahawk +Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Accounts::ConfigStorage > ) + #endif // CONFIGSTORAGE_H diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp index 878e722cd..254ac1c79 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.cpp +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -35,7 +35,12 @@ LocalConfigStorage::LocalConfigStorage( QObject* parent ) , m_credentialsServiceName( "Tomahawk" ) { m_accountIds = TomahawkSettings::instance()->accounts(); +} + +void +LocalConfigStorage::init() +{ // tell CredentialsManager which account ids it will be writing credentials for and in which svc CredentialsManager* cm = AccountManager::instance()->credentialsManager(); diff --git a/src/libtomahawk/accounts/LocalConfigStorage.h b/src/libtomahawk/accounts/LocalConfigStorage.h index 3540bebd9..4303c463f 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.h +++ b/src/libtomahawk/accounts/LocalConfigStorage.h @@ -33,6 +33,8 @@ class LocalConfigStorage : public ConfigStorage public: explicit LocalConfigStorage( QObject* parent = 0 ); + virtual void init(); + QString id() const { return "localconfigstorage"; } QStringList accountIds() const; diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index ecae779bf..e6420230f 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -36,11 +36,17 @@ TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent ) , m_credentialsServiceName( "telepathy-kde" ) { tDebug() << Q_FUNC_INFO; +} + +void +TelepathyConfigStorage::init() +{ // 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 ); + emit ready(); } diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index c85df045c..df83532b0 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -34,6 +34,8 @@ class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorage : public ConfigStorage public: explicit TelepathyConfigStorage( QObject* parent = 0 ); + void init(); + QString id() const { return "telepathyconfigstorage"; } QStringList accountIds() const; From 2db2cdb996d780dfca220d6a4e850ed4ffcff018 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 12 Jun 2013 19:40:25 +0200 Subject: [PATCH 06/27] Load TelepathyConfigStorage plugin. --- src/libtomahawk/accounts/AccountManager.cpp | 102 ++++++++++++++---- src/libtomahawk/accounts/AccountManager.h | 10 +- src/libtomahawk/accounts/ConfigStorage.h | 2 +- .../telepathy/TelepathyConfigStorage.cpp | 6 +- .../telepathy/TelepathyConfigStorage.h | 1 + 5 files changed, 93 insertions(+), 28 deletions(-) diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 3b9dcd33e..ffd8e8513 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -34,10 +34,10 @@ #include "TomahawkSettings.h" #include "LocalConfigStorage.h" -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -101,10 +101,9 @@ AccountManager::init() } -QStringList -AccountManager::findPluginFactories() +QList< QDir > +AccountManager::findPluginDirs() const { - QStringList paths; QList< QDir > pluginDirs; QDir appDir( qApp->applicationDirPath() ); @@ -125,10 +124,21 @@ AccountManager::findPluginFactories() lib64Dir.cd( "lib64" ); pluginDirs << appDir << libDir << lib64Dir << QDir( qApp->applicationDirPath() ); - foreach ( const QDir& pluginDir, pluginDirs ) + return pluginDirs; +} + + +QStringList +AccountManager::findPluginFactories() +{ + QStringList paths; + + foreach ( const QDir& pluginDir, findPluginDirs() ) { - tDebug() << Q_FUNC_INFO << "Checking directory for plugins:" << pluginDir; - foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_account_*.so" << "*tomahawk_account_*.dylib" << "*tomahawk_account_*.dll", QDir::Files ) ) + tDebug() << Q_FUNC_INFO << "Checking directory for account plugins:" << pluginDir; + foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_account_*.so" + << "*tomahawk_account_*.dylib" + << "*tomahawk_account_*.dll", QDir::Files ) ) { if ( fileName.startsWith( "libtomahawk_account" ) ) { @@ -143,6 +153,33 @@ AccountManager::findPluginFactories() } +QStringList +AccountManager::findConfigStoragePlugins() +{ + QStringList paths; + + foreach( const QDir& pluginDir, findPluginDirs() ) + { + tDebug() << Q_FUNC_INFO << "Checking directory for ConfigStorage plugins:" << pluginDir; + foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_configstorage_*.so" + << "*tomahawk_configstorage_*.dylib" + << "*tomahawk_configstorage_*.dll", QDir::Files ) ) + { + if ( fileName.startsWith( "libtomahawk_configstorage" ) ) + { + const QString path = pluginDir.absoluteFilePath( fileName ); + if ( !paths.contains( path ) ) + paths << path; + } + } + } + + tDebug() << Q_FUNC_INFO << "ConfigStorage plugin file paths:" << paths; + + return paths; +} + + void AccountManager::loadPluginFactories( const QStringList& paths ) { @@ -288,31 +325,50 @@ AccountManager::loadFromConfig() { m_creds = new CredentialsManager( this ); - QSharedPointer< ConfigStorage > configStorage; - configStorage = QSharedPointer< ConfigStorage >( new LocalConfigStorage( this ) ); - m_configStorageById.insert( configStorage->id(), configStorage ); + ConfigStorage* localCS = new LocalConfigStorage( this ); + m_configStorageById.insert( localCS->id(), localCS ); + QStringList configStoragePlugins = findConfigStoragePlugins(); + foreach( const QString& pluginPath, configStoragePlugins ) + { + QPluginLoader loader; + if ( !QLibrary::isLibrary( pluginPath ) ) + continue; - foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) + loader.setFileName( pluginPath ); + if ( !loader.load() ) + { + tDebug() << "Error loading ConfigStorage plugin" << loader.errorString() << loader.staticInstances().count(); + continue; + } + + ConfigStorage* cs = qobject_cast< ConfigStorage* >( loader.instance() ); + if ( !cs ) + continue; + + m_configStorageById.insert( cs->id(), cs ); + } + + foreach ( ConfigStorage* cs, m_configStorageById ) { m_configStorageLoading.insert( cs->id() ); - NewClosure( cs.data(), SIGNAL( ready() ), - this, SLOT( finishLoadingFromConfig( QSharedPointer< ConfigStorage > ) ), cs ); + NewClosure( cs, SIGNAL( ready() ), + this, SLOT( finishLoadingFromConfig( QString ) ), cs->id() ); cs->init(); } } void -AccountManager::finishLoadingFromConfig( const QSharedPointer< ConfigStorage >& cs ) +AccountManager::finishLoadingFromConfig( const QString& csid ) { - if ( m_configStorageLoading.contains( cs->id() ) ) - m_configStorageLoading.remove( cs->id() ); + if ( m_configStorageLoading.contains( csid ) ) + m_configStorageLoading.remove( csid ); if ( !m_configStorageLoading.isEmpty() ) return; - foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) + foreach ( const ConfigStorage* cs, m_configStorageById ) { QStringList accountIds = cs->accountIds(); @@ -466,15 +522,15 @@ AccountManager::zeroconfAccount() const } -QSharedPointer< ConfigStorage > +ConfigStorage* AccountManager::configStorageForAccount( const QString& accountId ) { - foreach ( const QSharedPointer< ConfigStorage >& cs, m_configStorageById ) + foreach ( ConfigStorage* cs, m_configStorageById ) { if ( cs->accountIds().contains( accountId ) ) return cs; } - return QSharedPointer< ConfigStorage >(); + return 0; } diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index bc56f9d44..4a39323a3 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -95,7 +95,7 @@ public: bool isReady() const { return m_completelyReady; } CredentialsManager* credentialsManager() const { return m_creds; } - QSharedPointer< ConfigStorage > configStorageForAccount( const QString& accountId ); + ConfigStorage* configStorageForAccount( const QString& accountId ); public slots: void connectAll(); @@ -120,16 +120,20 @@ private slots: void init(); void onStateChanged( Tomahawk::Accounts::Account::ConnectionState state ); void onError( int code, const QString& msg ); - void finishLoadingFromConfig( const QSharedPointer< ConfigStorage >& cs ); + void finishLoadingFromConfig( const QString& cs ); void onSettingsChanged(); private: + QList< QDir > findPluginDirs() const; + QStringList findPluginFactories(); void loadPluginFactories( const QStringList &paths ); void loadPluginFactory( const QString &path ); QString factoryFromId( const QString& accountId ) const; + QStringList findConfigStoragePlugins(); + Account* loadPlugin( const QString& accountId ); void hookupAccount( Account* ) const; @@ -146,7 +150,7 @@ private: QHash< QString, AccountFactory* > m_accountFactories; QList< AccountFactory* > m_factoriesForFilesytem; - QMap< QString, QSharedPointer< ConfigStorage > > m_configStorageById; + QHash< QString, ConfigStorage* > m_configStorageById; QSet< QString > m_configStorageLoading; static AccountManager* s_instance; diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h index cbf784918..9f3d9e6d7 100644 --- a/src/libtomahawk/accounts/ConfigStorage.h +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -55,6 +55,6 @@ signals: } //namespace Accounts } //namespace Tomahawk -Q_DECLARE_METATYPE( QSharedPointer< Tomahawk::Accounts::ConfigStorage > ) +Q_DECLARE_INTERFACE( Tomahawk::Accounts::ConfigStorage, "tomahawk.ConfigStorage/1.0" ) #endif // CONFIGSTORAGE_H diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index e6420230f..222072fd1 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -23,6 +23,8 @@ #include "accounts/CredentialsManager.h" #include "utils/Logger.h" +#include + namespace Tomahawk { @@ -46,7 +48,7 @@ TelepathyConfigStorage::init() // so it can preload them when we call CM::loadCredentials() AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName, m_accountIds ); - emit ready(); + QTimer::singleShot( 0, this, SIGNAL( ready() ) ); } @@ -118,3 +120,5 @@ TelepathyConfigStorage::remove( const QString& accountId ) } } + +Q_EXPORT_PLUGIN2( Tomahawk::Accounts::ConfigStorage, Tomahawk::Accounts::TelepathyConfigStorage ) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index df83532b0..362ab885d 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -31,6 +31,7 @@ namespace Accounts class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorage : public ConfigStorage { Q_OBJECT + Q_INTERFACES( Tomahawk::Accounts::ConfigStorage ) public: explicit TelepathyConfigStorage( QObject* parent = 0 ); From 530a838a1f40d853297e96336e8e1f57c9961d20 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 16 Jun 2013 14:08:56 +0200 Subject: [PATCH 07/27] Add Telepathy magic to TelepathyConfigStorage --- .../accounts/CredentialsManager.cpp | 59 +++++-- src/libtomahawk/accounts/CredentialsManager.h | 9 +- .../accounts/LocalConfigStorage.cpp | 4 +- .../telepathy/TelepathyConfigStorage.cpp | 165 ++++++++++++++---- .../telepathy/TelepathyConfigStorage.h | 15 ++ 5 files changed, 197 insertions(+), 55 deletions(-) diff --git a/src/libtomahawk/accounts/CredentialsManager.cpp b/src/libtomahawk/accounts/CredentialsManager.cpp index 8daed33b7..d0f4802ed 100644 --- a/src/libtomahawk/accounts/CredentialsManager.cpp +++ b/src/libtomahawk/accounts/CredentialsManager.cpp @@ -118,14 +118,14 @@ CredentialsManager::services() const } -QVariantHash +QVariant CredentialsManager::credentials( const CredentialsStorageKey& key ) const { return m_credentials.value( key ); } -QVariantHash +QVariant CredentialsManager::credentials( const QString& serviceName, const QString& key ) const { return credentials( CredentialsStorageKey( serviceName, key ) ); @@ -133,12 +133,14 @@ CredentialsManager::credentials( const QString& serviceName, const QString& key void -CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QVariantHash& value ) +CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QVariant& value, bool tryToWriteAsString ) { QMutexLocker locker( &m_mutex ); QKeychain::Job* j; - if ( value.isEmpty() ) + if ( value.isNull() || + ( value.type() == QVariant::Hash && value.toHash().isEmpty() ) || + ( value.type() == QVariant::String && value.toString().isEmpty() ) ) { if ( !m_credentials.contains( csKey ) ) //if we don't have any credentials for this key, we bail return; @@ -156,15 +158,26 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV m_credentials.insert( csKey, value ); - QByteArray data; - { - QDataStream ds( &data, QIODevice::WriteOnly ); - ds << value; - } - QKeychain::WritePasswordJob* wj = new QKeychain::WritePasswordJob( csKey.service(), this ); wj->setKey( csKey.key() ); - wj->setBinaryData( data ); + + Q_ASSERT( value.type() == QVariant::String || value.type() == QVariant::Hash ); + + if ( tryToWriteAsString && value.type() == QVariant::String ) + { + wj->setTextData( value.toString() ); + } + else if ( value.type() == QVariant::Hash ) + { + QByteArray data; + { + QDataStream ds( &data, QIODevice::WriteOnly ); + ds << value.toHash(); + } + + wj->setBinaryData( data ); + } + j = wj; } @@ -181,7 +194,14 @@ CredentialsManager::setCredentials( const CredentialsStorageKey& csKey, const QV void CredentialsManager::setCredentials( const QString& serviceName, const QString& key, const QVariantHash& value ) { - setCredentials( CredentialsStorageKey( serviceName, key ), value ); + setCredentials( CredentialsStorageKey( serviceName, key ), QVariant( value ) ); +} + + +void +CredentialsManager::setCredentials( const QString& serviceName, const QString& key, const QString& value ) +{ + setCredentials( CredentialsStorageKey( serviceName, key ), QVariant( value ), true ); } @@ -195,9 +215,18 @@ CredentialsManager::keychainJobFinished( QKeychain::Job* j ) { tDebug() << "QtKeychain readJob for" << readJob->key() << "finished without errors"; - QVariantHash creds; - QDataStream dataStream( readJob->binaryData() ); - dataStream >> creds; + QVariant creds; + if ( !readJob->textData().isEmpty() ) + { + creds = QVariant( readJob->textData() ); + } + else //must be a QVH + { + QDataStream dataStream( readJob->binaryData() ); + QVariantHash hash; + dataStream >> hash; + creds = QVariant( hash ); + } m_credentials.insert( CredentialsStorageKey( readJob->service(), readJob->key() ), creds ); } diff --git a/src/libtomahawk/accounts/CredentialsManager.h b/src/libtomahawk/accounts/CredentialsManager.h index 5e21b4da8..851e8d9b6 100644 --- a/src/libtomahawk/accounts/CredentialsManager.h +++ b/src/libtomahawk/accounts/CredentialsManager.h @@ -69,8 +69,9 @@ public: QStringList keys( const QString& service ) const; QStringList services() const; - QVariantHash credentials( const QString& serviceName, const QString& key ) const; + QVariant credentials( const QString& serviceName, const QString& key ) const; //returns QString or QVH void setCredentials( const QString& serviceName, const QString& key, const QVariantHash& value ); + void setCredentials( const QString& serviceName, const QString& key, const QString& value ); signals: void serviceReady( const QString& service ); @@ -81,12 +82,12 @@ private slots: void keychainJobFinished( QKeychain::Job* ); protected: - QVariantHash credentials( const CredentialsStorageKey& key ) const; - void setCredentials( const CredentialsStorageKey& key, const QVariantHash& value ); + QVariant credentials( const CredentialsStorageKey& key ) const; + void setCredentials( const CredentialsStorageKey& key, const QVariant& value, bool tryToWriteAsString = false ); private: QHash< QString, QStringList > m_services; - QHash< CredentialsStorageKey, QVariantHash > m_credentials; + QHash< CredentialsStorageKey, QVariant > m_credentials; QHash< QString, QList< QKeychain::ReadPasswordJob* > > m_readJobs; QMutex m_mutex; }; diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp index 254ac1c79..51e6e8d79 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.cpp +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -107,7 +107,9 @@ LocalConfigStorage::load( const QString& accountId, Account::Configuration& cfg s->endGroup(); CredentialsManager* c = AccountManager::instance()->credentialsManager(); - cfg.credentials = c->credentials( m_credentialsServiceName, accountId ); + QVariant credentials = c->credentials( m_credentialsServiceName, accountId ); + if ( credentials.type() == QVariant::Hash ) + cfg.credentials = credentials.toHash(); } diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index 222072fd1..2e1e7b9c8 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -23,18 +23,20 @@ #include "accounts/CredentialsManager.h" #include "utils/Logger.h" +#include +#include +#include +#include + #include -namespace Tomahawk -{ -namespace Accounts -{ +//NOTE: Both Tomahawk::Accounts and Tp have class names Account and AccountManager. -TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent ) - : ConfigStorage( parent ) +Tomahawk::Accounts::TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent ) + : Tomahawk::Accounts::ConfigStorage( parent ) , m_credentialsServiceName( "telepathy-kde" ) { tDebug() << Q_FUNC_INFO; @@ -42,25 +44,92 @@ TelepathyConfigStorage::TelepathyConfigStorage( QObject* parent ) void -TelepathyConfigStorage::init() +Tomahawk::Accounts::TelepathyConfigStorage::init() { + + m_tpam = Tp::AccountManager::create(); + connect( m_tpam->becomeReady(), SIGNAL( finished( Tp::PendingOperation* ) ), + this, SLOT( onTpAccountManagerReady( Tp::PendingOperation* ) ) ); +} + + +void +Tomahawk::Accounts::TelepathyConfigStorage::onTpAccountManagerReady( Tp::PendingOperation* op ) +{ + if ( op->isError() ) + { + tDebug() << "Telepathy AccountManager cannot become ready:" + << op->errorName() << "-" << op->errorMessage(); + emit ready(); //we bail, this CS is ready to provide 0 accounts + return; + } + + QStringList keychainIds; + foreach ( const Tp::AccountPtr& acc, m_tpam->validAccounts()->accounts() ) + { + if ( acc->protocolName() == "jabber" ) + { + m_accountIds << acc->objectPath(); + keychainIds << acc->uniqueIdentifier(); + } + } + // 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 ); - QTimer::singleShot( 0, this, SIGNAL( ready() ) ); + + CredentialsManager* cm = AccountManager::instance()->credentialsManager(); + connect( cm, SIGNAL( serviceReady( QString ) ), + this, SLOT( onCredentialsManagerReady( QString ) ) ); + Tomahawk::Accounts::AccountManager::instance()->credentialsManager()->addService( m_credentialsServiceName, + keychainIds ); + tDebug() << Q_FUNC_INFO << "LOADING ALL CREDENTIALS FOR SERVICE" << m_credentialsServiceName << m_accountIds << keychainIds; +} + + +void +Tomahawk::Accounts::TelepathyConfigStorage::onCredentialsManagerReady( const QString& service ) +{ + if ( service != m_credentialsServiceName ) + return; + + //no need to listen for it any more + disconnect( this, SLOT( onCredentialsManagerReady( QString ) ) ); + + for ( int i = 0; i < m_accountIds.length(); ++i ) + { + m_accountIds[ i ] = telepathyPathToAccountId( m_accountIds[ i ] ); + } + + emit ready(); +} + + +QString +Tomahawk::Accounts::TelepathyConfigStorage::telepathyPathToAccountId( const QString& objectPath ) +{ + return QString( "xmppaccount_" ) + objectPath; +} + + +QString +Tomahawk::Accounts::TelepathyConfigStorage::accountIdToTelepathyPath( const QString& accountId ) +{ + QString prefix( "xmppaccount_" ); + QString r = accountId; + if ( r.startsWith( prefix ) ) + r.remove( 0, prefix.length() ); + return r; } QStringList -TelepathyConfigStorage::accountIds() const +Tomahawk::Accounts::TelepathyConfigStorage::accountIds() const { return m_accountIds; } void -TelepathyConfigStorage::save( const QString& accountId, const Account::Configuration& cfg ) +Tomahawk::Accounts::TelepathyConfigStorage::save( const QString& accountId, const Account::Configuration& cfg ) { // TomahawkSettings* s = TomahawkSettings::instance(); // s->beginGroup( "accounts/" + accountId ); @@ -81,7 +150,7 @@ TelepathyConfigStorage::save( const QString& accountId, const Account::Configura void -TelepathyConfigStorage::load( const QString& accountId, Account::Configuration& cfg ) +Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Account::Configuration& cfg ) { // TomahawkSettings* s = TomahawkSettings::instance(); // s->beginGroup( "accounts/" + accountId ); @@ -92,33 +161,59 @@ TelepathyConfigStorage::load( const QString& accountId, Account::Configuration& // cfg.types = s->value( "types", QStringList() ).toStringList(); // s->endGroup(); - CredentialsManager* c = AccountManager::instance()->credentialsManager(); - QString prefix( "tomahawkaccount_" ); - QString idInKeychain = accountId; - if ( idInKeychain.startsWith( prefix ) ) - idInKeychain.remove( 0, prefix.length() ); - cfg.credentials = c->credentials( m_credentialsServiceName, idInKeychain ); + Tp::AccountPtr account = m_tpam->accountForObjectPath( accountIdToTelepathyPath( accountId ) ); + + cfg.accountFriendlyName = account->normalizedName(); + + cfg.enabled = true; + cfg.acl = QVariantMap(); + + QStringList types; + types << "SipType"; + cfg.types = types; + + if ( !account->parameters()[ "port" ].isNull() ) + cfg.configuration[ "port" ] = account->parameters()[ "port" ].toString(); + else + cfg.configuration[ "port" ] = "5222"; + + if ( !account->parameters()[ "server" ].isNull() ) + cfg.configuration[ "server" ] = account->parameters()[ "server" ].toString(); + + if ( !account->parameters()[ "require-encryption" ].isNull() ) + cfg.configuration[ "enforcesecure" ] = account->parameters()[ "require-encryption" ].toBool(); + + cfg.configuration[ "publishtracks" ] = true; + + Tomahawk::Accounts::CredentialsManager* c = Tomahawk::Accounts::AccountManager::instance()->credentialsManager(); + cfg.credentials = QVariantHash(); + + if ( !account->parameters()[ "account" ].isNull() ) + cfg.credentials[ "username" ] = account->parameters()[ "account" ].toString(); + else + cfg.credentials[ "username" ] = account->normalizedName(); + + QVariant credentials = c->credentials( m_credentialsServiceName, account->uniqueIdentifier() ); + if ( credentials.type() == QVariant::String ) + cfg.credentials[ "password" ] = credentials.toString(); } void -TelepathyConfigStorage::remove( const QString& accountId ) +Tomahawk::Accounts::TelepathyConfigStorage::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 ); +// 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() ); -} - -} +// Tomahawk::Accounts::CredentialsManager* c = Tomahawk::Accounts::AccountManager::instance()->credentialsManager(); +// c->setCredentials( m_credentialsServiceName, account->uniqueIdentifier(), QVariantHash() ); } Q_EXPORT_PLUGIN2( Tomahawk::Accounts::ConfigStorage, Tomahawk::Accounts::TelepathyConfigStorage ) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index 362ab885d..3c063d43f 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -22,6 +22,13 @@ #include "accounts/ConfigStorageDllMacro.h" #include "accounts/ConfigStorage.h" +#include + +namespace Tp +{ +class PendingOperation; +} + namespace Tomahawk { @@ -45,9 +52,17 @@ public: virtual void load( const QString& accountId, Account::Configuration& cfg ); virtual void remove( const QString& accountId ); +private slots: + void onTpAccountManagerReady( Tp::PendingOperation* op ); + void onCredentialsManagerReady( const QString& service ); + private: + QString telepathyPathToAccountId( const QString& objectPath ); + QString accountIdToTelepathyPath( const QString& accountId ); + const QString m_credentialsServiceName; QStringList m_accountIds; + Tp::AccountManagerPtr m_tpam; static TelepathyConfigStorage* s_instance; }; From 1bc3bf3b0556b610358fbe8e491b9bef6751db65 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 16 Jun 2013 14:17:05 +0200 Subject: [PATCH 08/27] Don't carry Telepathy objectPaths around more than necessary. --- .../configstorage/telepathy/TelepathyConfigStorage.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index 2e1e7b9c8..b738639f6 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -69,7 +69,7 @@ Tomahawk::Accounts::TelepathyConfigStorage::onTpAccountManagerReady( Tp::Pending { if ( acc->protocolName() == "jabber" ) { - m_accountIds << acc->objectPath(); + m_accountIds << telepathyPathToAccountId( acc->objectPath() ); keychainIds << acc->uniqueIdentifier(); } } @@ -94,11 +94,6 @@ Tomahawk::Accounts::TelepathyConfigStorage::onCredentialsManagerReady( const QSt //no need to listen for it any more disconnect( this, SLOT( onCredentialsManagerReady( QString ) ) ); - for ( int i = 0; i < m_accountIds.length(); ++i ) - { - m_accountIds[ i ] = telepathyPathToAccountId( m_accountIds[ i ] ); - } - emit ready(); } From 2416de9697987b2915b929cd17e8eab2ebe17734 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 16 Jun 2013 14:35:24 +0200 Subject: [PATCH 09/27] Just say NO to implementations in headers! --- src/libtomahawk/accounts/LocalConfigStorage.cpp | 7 +++++++ src/libtomahawk/accounts/LocalConfigStorage.h | 2 +- .../configstorage/telepathy/TelepathyConfigStorage.cpp | 7 +++++++ .../configstorage/telepathy/TelepathyConfigStorage.h | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp index 51e6e8d79..a8a8c7ed4 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.cpp +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -53,6 +53,13 @@ LocalConfigStorage::init() } +QString +LocalConfigStorage::id() const +{ + return "localconfigstorage"; +} + + void LocalConfigStorage::onCredentialsManagerReady( const QString& service ) { diff --git a/src/libtomahawk/accounts/LocalConfigStorage.h b/src/libtomahawk/accounts/LocalConfigStorage.h index 4303c463f..c2aff5edd 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.h +++ b/src/libtomahawk/accounts/LocalConfigStorage.h @@ -35,7 +35,7 @@ public: virtual void init(); - QString id() const { return "localconfigstorage"; } + QString id() const; QStringList accountIds() const; diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index b738639f6..b74164d56 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -53,6 +53,13 @@ Tomahawk::Accounts::TelepathyConfigStorage::init() } +QString +Tomahawk::Accounts::TelepathyConfigStorage::id() const +{ + return "telepathyconfigstorage"; +} + + void Tomahawk::Accounts::TelepathyConfigStorage::onTpAccountManagerReady( Tp::PendingOperation* op ) { diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index 3c063d43f..872b6d268 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -44,7 +44,7 @@ public: void init(); - QString id() const { return "telepathyconfigstorage"; } + QString id() const; QStringList accountIds() const; From 99c3fb443121972594598b635cfac91c50c107d3 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sun, 16 Jun 2013 14:36:17 +0200 Subject: [PATCH 10/27] Obsolete cmakedefine is obsolete. --- src/tomahawk/Config.h.in | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tomahawk/Config.h.in b/src/tomahawk/Config.h.in index 27500df65..e1d5aedbf 100644 --- a/src/tomahawk/Config.h.in +++ b/src/tomahawk/Config.h.in @@ -19,7 +19,6 @@ #cmakedefine WITH_UPOWER #cmakedefine WITH_GNOMESHORTCUTHANDLER -#cmakedefine TELEPATHY_QT_FOUND #cmakedefine LIBLASTFM_FOUND #cmakedefine QCA2_FOUND From bec87f692d024a96049c3a4cfdd6623d143e7329 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 18 Jun 2013 18:04:06 +0200 Subject: [PATCH 11/27] Add GTalk support for Telepathy accounts. --- .../telepathy/TelepathyConfigStorage.cpp | 24 ++++++++++++------- .../telepathy/TelepathyConfigStorage.h | 2 +- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index b74164d56..3a422a47c 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -76,7 +76,7 @@ Tomahawk::Accounts::TelepathyConfigStorage::onTpAccountManagerReady( Tp::Pending { if ( acc->protocolName() == "jabber" ) { - m_accountIds << telepathyPathToAccountId( acc->objectPath() ); + m_accountIds << telepathyPathToAccountId( acc->objectPath(), acc->serviceName() ); keychainIds << acc->uniqueIdentifier(); } } @@ -106,8 +106,10 @@ Tomahawk::Accounts::TelepathyConfigStorage::onCredentialsManagerReady( const QSt QString -Tomahawk::Accounts::TelepathyConfigStorage::telepathyPathToAccountId( const QString& objectPath ) +Tomahawk::Accounts::TelepathyConfigStorage::telepathyPathToAccountId( const QString& objectPath, const QString& telepathyServiceName ) { + if ( telepathyServiceName == "google-talk" ) + return QString( "googleaccount_" ) + objectPath; return QString( "xmppaccount_" ) + objectPath; } @@ -115,10 +117,15 @@ Tomahawk::Accounts::TelepathyConfigStorage::telepathyPathToAccountId( const QStr QString Tomahawk::Accounts::TelepathyConfigStorage::accountIdToTelepathyPath( const QString& accountId ) { - QString prefix( "xmppaccount_" ); + QStringList allowedPrefixes; + allowedPrefixes << "xmppaccount_" + << "googleaccount_"; QString r = accountId; - if ( r.startsWith( prefix ) ) - r.remove( 0, prefix.length() ); + foreach ( QString prefix, allowedPrefixes ) + { + if ( r.startsWith( prefix ) ) + r.remove( 0, prefix.length() ); + } return r; } @@ -174,10 +181,11 @@ Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Acco types << "SipType"; cfg.types = types; - if ( !account->parameters()[ "port" ].isNull() ) - cfg.configuration[ "port" ] = account->parameters()[ "port" ].toString(); - else + if ( account->serviceName() == "google-talk" || + account->parameters()[ "port" ].isNull() ) cfg.configuration[ "port" ] = "5222"; + else + cfg.configuration[ "port" ] = account->parameters()[ "port" ].toString(); if ( !account->parameters()[ "server" ].isNull() ) cfg.configuration[ "server" ] = account->parameters()[ "server" ].toString(); diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index 872b6d268..a829ee7c3 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -57,7 +57,7 @@ private slots: void onCredentialsManagerReady( const QString& service ); private: - QString telepathyPathToAccountId( const QString& objectPath ); + QString telepathyPathToAccountId( const QString& objectPath, const QString& telepathyServiceName ); QString accountIdToTelepathyPath( const QString& accountId ); const QString m_credentialsServiceName; From e80a5ba2e5baabac5d0b116856b87e1c56d8a357 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 19 Jun 2013 16:45:34 +0200 Subject: [PATCH 12/27] Lock external account config UI, launch KDE Telepathy config dialog. --- src/accounts/xmpp/XmppConfigWidget.cpp | 34 ++++++ src/accounts/xmpp/XmppConfigWidget.h | 1 + src/accounts/xmpp/XmppConfigWidget.ui | 112 +++++++++++++++++- src/libtomahawk/accounts/ConfigStorage.cpp | 21 ++++ src/libtomahawk/accounts/ConfigStorage.h | 5 + .../telepathy/TelepathyConfigStorage.cpp | 36 +++++- .../telepathy/TelepathyConfigStorage.h | 4 + .../accounts/configstorage/telepathy/kde.png | Bin 0 -> 18660 bytes .../configstorage/telepathy/resources.qrc | 5 + 9 files changed, 211 insertions(+), 7 deletions(-) create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/kde.png create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/resources.qrc diff --git a/src/accounts/xmpp/XmppConfigWidget.cpp b/src/accounts/xmpp/XmppConfigWidget.cpp index 0df3cc9d2..a6001cc90 100644 --- a/src/accounts/xmpp/XmppConfigWidget.cpp +++ b/src/accounts/xmpp/XmppConfigWidget.cpp @@ -23,7 +23,9 @@ #include "accounts/AccountManager.h" +#include "accounts/ConfigStorage.h" #include "utils/Logger.h" +#include "utils/TomahawkUtilsGui.h" #include @@ -48,9 +50,41 @@ XmppConfigWidget::XmppConfigWidget( XmppAccount* account, QWidget *parent ) m_ui->xmppPublishTracksCheckbox->setChecked( account->configuration().contains( "publishtracks" ) ? account->configuration()[ "publishtracks" ].toBool() : true); m_ui->xmppEnforceSecureCheckbox->setChecked( account->configuration().contains( "enforcesecure" ) ? account->configuration()[ "enforcesecure" ].toBool() : false); m_ui->jidExistsLabel->hide(); + m_ui->xmppConfigFrame->hide(); connect( m_ui->xmppUsername, SIGNAL( textChanged( QString ) ), SLOT( onCheckJidExists( QString ) ) ); + + if ( m_account->configuration()[ "read-only" ].toBool() ) + { + m_ui->xmppUsername->setEnabled( false ); + m_ui->xmppPassword->setEnabled( false ); + m_ui->xmppServer->setEnabled( false ); + m_ui->xmppPort->setEnabled( false ); + m_ui->xmppEnforceSecureCheckbox->setEnabled( false ); + m_ui->xmppPublishTracksCheckbox->setEnabled( false ); + } + + ConfigStorage* cs = AccountManager::instance()->configStorageForAccount( m_account->accountId() ); + if ( cs->id() != "localconfigstorage" ) + { + m_ui->xmppBlurb->hide(); + m_ui->xmppConfigFrame->show(); + m_ui->xmppConfigLabel->setText( tr( "Account provided by %1." ) + .arg( cs->prettyName() ) ); + m_ui->xmppConfigIcon->setPixmap( cs->icon().scaled( TomahawkUtils::defaultIconSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation ) ); + m_ui->xmppConfigLaunchDialog->setIcon( TomahawkUtils::defaultPixmap( TomahawkUtils::Configure ) ); + connect( m_ui->xmppConfigLaunchDialog, SIGNAL( clicked() ), + this, SLOT( launchExternalConfigDialog() ) ); + } +} + + +void +XmppConfigWidget::launchExternalConfigDialog() +{ + ConfigStorage* cs = AccountManager::instance()->configStorageForAccount( m_account->accountId() ); + cs->execConfigDialog(); } diff --git a/src/accounts/xmpp/XmppConfigWidget.h b/src/accounts/xmpp/XmppConfigWidget.h index 447b5fafb..bfdaa5da8 100644 --- a/src/accounts/xmpp/XmppConfigWidget.h +++ b/src/accounts/xmpp/XmppConfigWidget.h @@ -56,6 +56,7 @@ signals: private slots: void onCheckJidExists( const QString& jid ); + void launchExternalConfigDialog(); private: Ui::XmppConfigWidget *m_ui; diff --git a/src/accounts/xmpp/XmppConfigWidget.ui b/src/accounts/xmpp/XmppConfigWidget.ui index 8e16eaced..96eacb053 100644 --- a/src/accounts/xmpp/XmppConfigWidget.ui +++ b/src/accounts/xmpp/XmppConfigWidget.ui @@ -1,15 +1,21 @@ XmppConfigWidget - + 0 0 451 - 335 + 337 + + + 451 + 0 + + Xmpp Configuration @@ -35,7 +41,7 @@ - :/xmpp-account/xmpp-icon.png + :/xmpp-account/xmpp-icon.png @@ -69,15 +75,18 @@ - + Qt::Horizontal + + QSizePolicy::Expanding + - 40 + 0 20 @@ -85,9 +94,18 @@ + + + 0 + 0 + + Enter your Xmpp login to connect with your friends using Tomahawk! + + false + @@ -95,9 +113,12 @@ Qt::Horizontal + + QSizePolicy::Expanding + - 40 + 0 20 @@ -105,6 +126,85 @@ + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + 0 + + + + 5 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + Configure + + + + + + + + + + + diff --git a/src/libtomahawk/accounts/ConfigStorage.cpp b/src/libtomahawk/accounts/ConfigStorage.cpp index 8ee9fee76..07dac2233 100644 --- a/src/libtomahawk/accounts/ConfigStorage.cpp +++ b/src/libtomahawk/accounts/ConfigStorage.cpp @@ -37,5 +37,26 @@ ConfigStorage::~ConfigStorage() } +QString +ConfigStorage::prettyName() const +{ + return QString(); +} + + +QPixmap +ConfigStorage::icon() const +{ + return QPixmap(); +} + + +bool +ConfigStorage::execConfigDialog() +{ + return false; +} + + } //ns } //ns diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h index 9f3d9e6d7..7da7a82cd 100644 --- a/src/libtomahawk/accounts/ConfigStorage.h +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -41,6 +41,11 @@ public: virtual void init() = 0; virtual QString id() const = 0; + virtual QString prettyName() const; + + virtual QPixmap icon() const; + + virtual bool execConfigDialog(); virtual QStringList accountIds() const = 0; diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index 3a422a47c..87b9241b9 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -28,6 +28,7 @@ #include #include +#include #include @@ -60,6 +61,37 @@ Tomahawk::Accounts::TelepathyConfigStorage::id() const } +QString +Tomahawk::Accounts::TelepathyConfigStorage::prettyName() const +{ + return tr( "the KDE instant messaging framework" ); +} + + +QPixmap +Tomahawk::Accounts::TelepathyConfigStorage::icon() const +{ + return QPixmap( ":/telepathy/kde.png" ); +} + + +bool +Tomahawk::Accounts::TelepathyConfigStorage::execConfigDialog() +{ + QProcess kcm; + kcm.start( "kcmshell4 kcm_ktp_accounts" ); + if ( !kcm.waitForStarted() ) + return false; + + if ( !kcm.waitForFinished( 600000 ) ) + return false; + + //TODO: this should probably be async + + return true; +} + + void Tomahawk::Accounts::TelepathyConfigStorage::onTpAccountManagerReady( Tp::PendingOperation* op ) { @@ -172,7 +204,7 @@ Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Acco Tp::AccountPtr account = m_tpam->accountForObjectPath( accountIdToTelepathyPath( accountId ) ); - cfg.accountFriendlyName = account->normalizedName(); + cfg.accountFriendlyName = "Tp:" + account->normalizedName(); cfg.enabled = true; cfg.acl = QVariantMap(); @@ -206,6 +238,8 @@ Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Acco QVariant credentials = c->credentials( m_credentialsServiceName, account->uniqueIdentifier() ); if ( credentials.type() == QVariant::String ) cfg.credentials[ "password" ] = credentials.toString(); + + cfg.configuration[ "read-only" ] = true; } diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index a829ee7c3..d88d65176 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -45,6 +45,10 @@ public: void init(); QString id() const; + QString prettyName() const; + QPixmap icon() const; + + bool execConfigDialog(); QStringList accountIds() const; diff --git a/src/libtomahawk/accounts/configstorage/telepathy/kde.png b/src/libtomahawk/accounts/configstorage/telepathy/kde.png new file mode 100644 index 0000000000000000000000000000000000000000..3efaaf80825efbdd900d30a651c3da4a9cc296a9 GIT binary patch literal 18660 zcmV(>K-j;DP)Kr%jj=1Zz>dKw$E2W09FsUzE>|2^f=w#kv11#@V2m*o$Y3xagTyYd7FHQcdU|@& zTkgB-IcK^%|NP7SyEXUT^WKv)=l1QMo|&GR{{H^AUdE-A;9R!zUiA9|@7xQ0)w|U@ ze}(t{karlWY93?ot^$gE#cA)s=|094#+-I~T=p%dYxEe!bgmqi^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0wbPQJhu|q-QbYZ@oU&SFwCPCE=rlcKf2VL&+V=1A7pru1~3xHxPZRwdJZka z)`p#EpfCWG7;%&6L8BH z_=pK$l55Q@av-uVH7RcO{9g!7kVwYnyNEzp0`&g_PP9QH+4=hl00000NkvXX Hu0mjfx@?ml literal 0 HcmV?d00001 diff --git a/src/libtomahawk/accounts/configstorage/telepathy/resources.qrc b/src/libtomahawk/accounts/configstorage/telepathy/resources.qrc new file mode 100644 index 000000000..2dd0f273e --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/resources.qrc @@ -0,0 +1,5 @@ + + + kde.png + + From 93bbf44669101b9f5ed4e255dbb448c08f6ce50f Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 23 Jun 2013 22:19:49 +0200 Subject: [PATCH 13/27] Centralize plugin finding logic in Tomahawk::Utils::PluginLoader --- src/libtomahawk/CMakeLists.txt | 2 +- src/libtomahawk/accounts/AccountManager.cpp | 84 +---------- src/libtomahawk/accounts/AccountManager.h | 4 - .../infosystem/InfoSystemWorker.cpp | 47 +----- src/libtomahawk/infosystem/InfoSystemWorker.h | 1 - src/libtomahawk/utils/PluginLoader.cpp | 136 ++++++++++++++++++ src/libtomahawk/utils/PluginLoader.h | 55 +++++++ src/libtomahawk/utils/PluginLoader_p.h | 41 ++++++ 8 files changed, 240 insertions(+), 130 deletions(-) create mode 100644 src/libtomahawk/utils/PluginLoader.cpp create mode 100644 src/libtomahawk/utils/PluginLoader.h create mode 100644 src/libtomahawk/utils/PluginLoader_p.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 21777479a..158b9dbf6 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -358,7 +358,7 @@ list(APPEND libSources utils/TomahawkCache.cpp utils/GuiHelpers.cpp utils/WeakObjectHash.cpp - + utils/PluginLoader.cpp thirdparty/kdsingleapplicationguard/kdsingleapplicationguard.cpp thirdparty/kdsingleapplicationguard/kdsharedmemorylocker.cpp diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index ffd8e8513..2654f0b19 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -26,6 +26,7 @@ #include "jobview/JobStatusModel.h" #include "utils/Closure.h" #include "utils/Logger.h" +#include "utils/PluginLoader.h" #include "CredentialsManager.h" #include "config.h" @@ -90,7 +91,7 @@ AccountManager::init() connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) ); - loadPluginFactories( findPluginFactories() ); + loadPluginFactories( Tomahawk::Utils::PluginLoader( "account" ).pluginPaths() ); // We include the resolver factory manually, not in a plugin ResolverAccountFactory* f = new ResolverAccountFactory(); @@ -101,85 +102,6 @@ AccountManager::init() } -QList< QDir > -AccountManager::findPluginDirs() const -{ - QList< QDir > pluginDirs; - - QDir appDir( qApp->applicationDirPath() ); -#ifdef Q_WS_MAC - if ( appDir.dirName() == "MacOS" ) - { - // Development convenience-hack - appDir.cdUp(); - appDir.cdUp(); - appDir.cdUp(); - } -#endif - - QDir libDir( CMAKE_INSTALL_PREFIX "/lib" ); - - QDir lib64Dir( appDir ); - lib64Dir.cdUp(); - lib64Dir.cd( "lib64" ); - - pluginDirs << appDir << libDir << lib64Dir << QDir( qApp->applicationDirPath() ); - return pluginDirs; -} - - -QStringList -AccountManager::findPluginFactories() -{ - QStringList paths; - - foreach ( const QDir& pluginDir, findPluginDirs() ) - { - tDebug() << Q_FUNC_INFO << "Checking directory for account plugins:" << pluginDir; - foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_account_*.so" - << "*tomahawk_account_*.dylib" - << "*tomahawk_account_*.dll", QDir::Files ) ) - { - if ( fileName.startsWith( "libtomahawk_account" ) ) - { - const QString path = pluginDir.absoluteFilePath( fileName ); - if ( !paths.contains( path ) ) - paths << path; - } - } - } - - return paths; -} - - -QStringList -AccountManager::findConfigStoragePlugins() -{ - QStringList paths; - - foreach( const QDir& pluginDir, findPluginDirs() ) - { - tDebug() << Q_FUNC_INFO << "Checking directory for ConfigStorage plugins:" << pluginDir; - foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_configstorage_*.so" - << "*tomahawk_configstorage_*.dylib" - << "*tomahawk_configstorage_*.dll", QDir::Files ) ) - { - if ( fileName.startsWith( "libtomahawk_configstorage" ) ) - { - const QString path = pluginDir.absoluteFilePath( fileName ); - if ( !paths.contains( path ) ) - paths << path; - } - } - } - - tDebug() << Q_FUNC_INFO << "ConfigStorage plugin file paths:" << paths; - - return paths; -} - - void AccountManager::loadPluginFactories( const QStringList& paths ) { @@ -328,7 +250,7 @@ AccountManager::loadFromConfig() ConfigStorage* localCS = new LocalConfigStorage( this ); m_configStorageById.insert( localCS->id(), localCS ); - QStringList configStoragePlugins = findConfigStoragePlugins(); + QStringList configStoragePlugins = Tomahawk::Utils::PluginLoader( "configstorage" ).pluginPaths(); foreach( const QString& pluginPath, configStoragePlugins ) { QPluginLoader loader; diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index 4a39323a3..1e24fbc93 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -125,14 +125,10 @@ private slots: void onSettingsChanged(); private: - QList< QDir > findPluginDirs() const; - - QStringList findPluginFactories(); void loadPluginFactories( const QStringList &paths ); void loadPluginFactory( const QString &path ); QString factoryFromId( const QString& accountId ) const; - QStringList findConfigStoragePlugins(); Account* loadPlugin( const QString& accountId ); void hookupAccount( Account* ) const; diff --git a/src/libtomahawk/infosystem/InfoSystemWorker.cpp b/src/libtomahawk/infosystem/InfoSystemWorker.cpp index fbe974f2e..2c0967457 100644 --- a/src/libtomahawk/infosystem/InfoSystemWorker.cpp +++ b/src/libtomahawk/infosystem/InfoSystemWorker.cpp @@ -27,6 +27,9 @@ #include "GlobalActionManager.h" #include "InfoSystemCache.h" #include "PlaylistEntry.h" +#include "utils/TomahawkUtils.h" +#include "utils/Logger.h" +#include "utils/PluginLoader.h" #include "Source.h" @@ -82,7 +85,7 @@ InfoSystemWorker::init( Tomahawk::InfoSystem::InfoSystemCache* cache ) m_shortLinksWaiting = 0; m_cache = cache; - loadInfoPlugins( findInfoPlugins() ); + loadInfoPlugins( Tomahawk::Utils::PluginLoader( "infoplugin" ).pluginPaths() ); } @@ -165,48 +168,6 @@ InfoSystemWorker::removeInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin ) } -QStringList -InfoSystemWorker::findInfoPlugins() -{ - QStringList paths; - QList< QDir > pluginDirs; - - QDir appDir( qApp->applicationDirPath() ); -#ifdef Q_WS_MAC - if ( appDir.dirName() == "MacOS" ) - { - // Development convenience-hack - appDir.cdUp(); - appDir.cdUp(); - appDir.cdUp(); - } -#endif - - QDir libDir( CMAKE_INSTALL_PREFIX "/lib" ); - - QDir lib64Dir( appDir ); - lib64Dir.cdUp(); - lib64Dir.cd( "lib64" ); - - pluginDirs << appDir << libDir << lib64Dir << QDir( qApp->applicationDirPath() ); - foreach ( const QDir& pluginDir, pluginDirs ) - { - tDebug() << Q_FUNC_INFO << "Checking directory for plugins:" << pluginDir; - foreach ( QString fileName, pluginDir.entryList( QStringList() << "*tomahawk_infoplugin_*.so" << "*tomahawk_infoplugin_*.dylib" << "*tomahawk_infoplugin_*.dll", QDir::Files ) ) - { - if ( fileName.startsWith( "libtomahawk_infoplugin" ) ) - { - const QString path = pluginDir.absoluteFilePath( fileName ); - if ( !paths.contains( path ) ) - paths << path; - } - } - } - - return paths; -} - - void InfoSystemWorker::loadInfoPlugins( const QStringList& pluginPaths ) { diff --git a/src/libtomahawk/infosystem/InfoSystemWorker.h b/src/libtomahawk/infosystem/InfoSystemWorker.h index 96a0ddb8f..65cfbd4ed 100644 --- a/src/libtomahawk/infosystem/InfoSystemWorker.h +++ b/src/libtomahawk/infosystem/InfoSystemWorker.h @@ -68,7 +68,6 @@ public slots: void addInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin ); void removeInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin ); - QStringList findInfoPlugins(); void loadInfoPlugins( const QStringList &pluginPaths ); void getShortUrl( Tomahawk::InfoSystem::InfoPushData data ); diff --git a/src/libtomahawk/utils/PluginLoader.cpp b/src/libtomahawk/utils/PluginLoader.cpp new file mode 100644 index 000000000..db66d4583 --- /dev/null +++ b/src/libtomahawk/utils/PluginLoader.cpp @@ -0,0 +1,136 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2010-2012, Leo Franchi + * Copyright 2010-2011, Jeff Mitchell + * Copyright 2013, Teo Mrnjavac + * Copyright 2013, Dominik Schmidt + * + * 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 . + */ + +#include "PluginLoader.h" +#include "PluginLoader_p.h" + +#include "config.h" + +#include "utils/Logger.h" + +#include +#include + +#include "DllMacro.h" + + +namespace Tomahawk +{ + +namespace Utils +{ + + +PluginLoader::PluginLoader( const QString& type ) + : d_ptr( new PluginLoaderPrivate( this ) ) +{ + Q_D( PluginLoader ); + + d->type = type; +} + + +PluginLoader::~PluginLoader() +{ + delete d_ptr; +} + + +const QList< QDir > +PluginLoader::pluginDirs() +{ + QList< QDir > pluginDirs; + + QDir appDir( QCoreApplication::instance()->applicationDirPath() ); +#ifdef Q_WS_MAC + if ( appDir.dirName() == "MacOS" ) + { + // Development convenience-hack + appDir.cdUp(); + appDir.cdUp(); + appDir.cdUp(); + } +#endif + + QDir libDir( CMAKE_INSTALL_PREFIX "/lib" ); + + QDir lib64Dir( appDir ); + lib64Dir.cdUp(); + lib64Dir.cd( "lib64" ); + + pluginDirs << appDir << libDir << lib64Dir << QDir( qApp->applicationDirPath() ); + return pluginDirs; +} + + +const QStringList +PluginLoader::pluginFilenames( const QString& name ) const +{ + //TODO: ifdef! + const QStringList extensions = QStringList() + << "so" + << "dll" + << "dylib"; + + + QStringList fileNames; + foreach( const QString& extension, extensions ) + { + fileNames << QString("libtomahawk_%1_%2.%3") + .arg( d_ptr->type ) + .arg( name ) + .arg( extension ); + } + + return fileNames; +} + + +const QStringList +PluginLoader::pluginPaths( const QString& name ) const +{ + const QString type = d_ptr->type; + + QSet< QString > paths; + foreach ( const QDir& pluginDir, pluginDirs() ) + { + tDebug() << Q_FUNC_INFO << "Checking directory for" << type << "plugins:" << pluginDir; + foreach ( QString fileName, pluginDir.entryList( pluginFilenames( name ), QDir::Files ) ) + { + //TODO: do we really need to check this?! + if ( fileName.startsWith( QString( "libtomahawk_%1" ).arg( type ) ) ) + { + const QString path = pluginDir.absoluteFilePath( fileName ); + paths << path; + } + } + } + + tDebug() << Q_FUNC_INFO << type << "plugin file paths:" << paths; + + return paths.toList(); +} + + +} // ns utils + +} // ns Tomahawk diff --git a/src/libtomahawk/utils/PluginLoader.h b/src/libtomahawk/utils/PluginLoader.h new file mode 100644 index 000000000..484137fae --- /dev/null +++ b/src/libtomahawk/utils/PluginLoader.h @@ -0,0 +1,55 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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 . + */ + +#ifndef LIBTOMAHAWK_UTILS_PLUGINLOADER_H +#define LIBTOMAHAWK_UTILS_PLUGINLOADER_H + +#include + +#include "DllMacro.h" + +class QDir; +class PluginLoaderPrivate; + +namespace Tomahawk +{ + +namespace Utils +{ + +class DLLEXPORT PluginLoader +{ +public: + PluginLoader( const QString& type ); + virtual ~PluginLoader(); + + const QStringList pluginFilenames( const QString& name = "*" ) const; + const QStringList pluginPaths( const QString& name = "*" ) const; + + static const QList< QDir > pluginDirs(); + +private: + Q_DECLARE_PRIVATE( PluginLoader ); + PluginLoaderPrivate* d_ptr; +}; + +} + +} + +#endif // LIBTOMAHAWK_UTILS_PLUGINLOADER_H diff --git a/src/libtomahawk/utils/PluginLoader_p.h b/src/libtomahawk/utils/PluginLoader_p.h new file mode 100644 index 000000000..ed34790f7 --- /dev/null +++ b/src/libtomahawk/utils/PluginLoader_p.h @@ -0,0 +1,41 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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 . + */ + +#include + +namespace Tomahawk +{ + namespace Utils + { + class PluginLoader; + } +} + +class PluginLoaderPrivate +{ +public: + PluginLoaderPrivate( Tomahawk::Utils::PluginLoader* q ) + : q_ptr ( q ) + { + } + + Tomahawk::Utils::PluginLoader* q_ptr; + Q_DECLARE_PUBLIC ( Tomahawk::Utils::PluginLoader ) + + QString type; +}; From d965783a5384fbc393c2bc0c00c1f318af8a8eab Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 23 Jun 2013 23:14:16 +0200 Subject: [PATCH 14/27] Centralize plugin loading logic in Tomahawk::Utils::PluginLoader --- src/libtomahawk/accounts/AccountManager.cpp | 64 +++++-------------- src/libtomahawk/accounts/AccountManager.h | 4 +- .../infosystem/InfoSystemWorker.cpp | 37 +++-------- src/libtomahawk/infosystem/InfoSystemWorker.h | 2 +- src/libtomahawk/utils/PluginLoader.cpp | 36 +++++++++++ src/libtomahawk/utils/PluginLoader.h | 4 +- 6 files changed, 66 insertions(+), 81 deletions(-) diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 2654f0b19..86a259147 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -35,9 +35,6 @@ #include "TomahawkSettings.h" #include "LocalConfigStorage.h" -#include -#include -#include #include #include #include @@ -91,7 +88,7 @@ AccountManager::init() connect( TomahawkSettings::instance(), SIGNAL( changed() ), SLOT( onSettingsChanged() ) ); - loadPluginFactories( Tomahawk::Utils::PluginLoader( "account" ).pluginPaths() ); + loadPluginFactories(); // We include the resolver factory manually, not in a plugin ResolverAccountFactory* f = new ResolverAccountFactory(); @@ -103,15 +100,20 @@ AccountManager::init() void -AccountManager::loadPluginFactories( const QStringList& paths ) +AccountManager::loadPluginFactories() { - foreach ( QString fileName, paths ) + QHash< QString, QObject* > plugins = Tomahawk::Utils::PluginLoader( "account" ).loadPlugins(); + foreach ( QObject* plugin, plugins.values() ) { - if ( !QLibrary::isLibrary( fileName ) ) - continue; - - tDebug() << Q_FUNC_INFO << "Trying to load plugin:" << fileName; - loadPluginFactory( fileName ); + AccountFactory* accountfactory = qobject_cast( plugin ); + if ( accountfactory ) + { + tDebug() << Q_FUNC_INFO << "Loaded plugin factory:" << plugins.key( plugin ) << accountfactory->factoryId() << accountfactory->prettyName(); + m_accountFactories[ accountfactory->factoryId() ] = accountfactory; + } else + { + tDebug() << Q_FUNC_INFO << "Loaded invalid plugin.." << plugins.key( plugin ); + } } } @@ -144,29 +146,6 @@ AccountManager::factoryForAccount( Account* account ) const } -void -AccountManager::loadPluginFactory( const QString& path ) -{ - QPluginLoader loader( path ); - QObject* plugin = loader.instance(); - if ( !plugin ) - { - tDebug() << Q_FUNC_INFO << "Error loading plugin:" << loader.errorString(); - } - - AccountFactory* accountfactory = qobject_cast( plugin ); - if ( accountfactory ) - { - tDebug() << Q_FUNC_INFO << "Loaded plugin factory:" << loader.fileName() << accountfactory->factoryId() << accountfactory->prettyName(); - m_accountFactories[ accountfactory->factoryId() ] = accountfactory; - } else - { - tDebug() << Q_FUNC_INFO << "Loaded invalid plugin.." << loader.fileName(); - } -} - - - void AccountManager::enableAccount( Account* account ) { @@ -250,21 +229,10 @@ AccountManager::loadFromConfig() ConfigStorage* localCS = new LocalConfigStorage( this ); m_configStorageById.insert( localCS->id(), localCS ); - QStringList configStoragePlugins = Tomahawk::Utils::PluginLoader( "configstorage" ).pluginPaths(); - foreach( const QString& pluginPath, configStoragePlugins ) + QList< QObject* > configStoragePlugins = Tomahawk::Utils::PluginLoader( "configstorage" ).loadPlugins().values(); + foreach( QObject* plugin, configStoragePlugins ) { - QPluginLoader loader; - if ( !QLibrary::isLibrary( pluginPath ) ) - continue; - - loader.setFileName( pluginPath ); - if ( !loader.load() ) - { - tDebug() << "Error loading ConfigStorage plugin" << loader.errorString() << loader.staticInstances().count(); - continue; - } - - ConfigStorage* cs = qobject_cast< ConfigStorage* >( loader.instance() ); + ConfigStorage* cs = qobject_cast< ConfigStorage* >( plugin ); if ( !cs ) continue; diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index 1e24fbc93..b219d8e81 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -125,11 +125,9 @@ private slots: void onSettingsChanged(); private: - void loadPluginFactories( const QStringList &paths ); - void loadPluginFactory( const QString &path ); + void loadPluginFactories(); QString factoryFromId( const QString& accountId ) const; - Account* loadPlugin( const QString& accountId ); void hookupAccount( Account* ) const; diff --git a/src/libtomahawk/infosystem/InfoSystemWorker.cpp b/src/libtomahawk/infosystem/InfoSystemWorker.cpp index 2c0967457..3ca764bfb 100644 --- a/src/libtomahawk/infosystem/InfoSystemWorker.cpp +++ b/src/libtomahawk/infosystem/InfoSystemWorker.cpp @@ -32,13 +32,9 @@ #include "utils/PluginLoader.h" #include "Source.h" - #include -#include -#include #include #include -#include namespace Tomahawk { @@ -85,7 +81,7 @@ InfoSystemWorker::init( Tomahawk::InfoSystem::InfoSystemCache* cache ) m_shortLinksWaiting = 0; m_cache = cache; - loadInfoPlugins( Tomahawk::Utils::PluginLoader( "infoplugin" ).pluginPaths() ); + loadInfoPlugins(); } @@ -169,37 +165,22 @@ InfoSystemWorker::removeInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin ) void -InfoSystemWorker::loadInfoPlugins( const QStringList& pluginPaths ) +InfoSystemWorker::loadInfoPlugins() { - tDebug() << Q_FUNC_INFO << "Attempting to load the following plugin paths:" << pluginPaths; - - if ( pluginPaths.isEmpty() ) - return; - - foreach ( const QString fileName, pluginPaths ) + QHash< QString, QObject* > plugins = Tomahawk::Utils::PluginLoader( "infoplugin" ).loadPlugins(); + foreach ( QObject* plugin, plugins.values() ) { - if ( !QLibrary::isLibrary( fileName ) ) - continue; - - tDebug() << Q_FUNC_INFO << "Trying to load plugin:" << fileName; - - QPluginLoader loader( fileName ); - QObject* plugin = loader.instance(); - if ( !plugin ) - { - tDebug() << Q_FUNC_INFO << "Error loading plugin:" << loader.errorString(); - continue; - } - InfoPlugin* infoPlugin = qobject_cast< InfoPlugin* >( plugin ); if ( infoPlugin ) { - tDebug() << Q_FUNC_INFO << "Loaded info plugin:" << loader.fileName(); - infoPlugin->setFriendlyName( loader.fileName() ); + tDebug() << Q_FUNC_INFO << "Loaded info plugin:" << plugins.key( plugin ); + infoPlugin->setFriendlyName( plugins.key( plugin ) ); addInfoPlugin( InfoPluginPtr( infoPlugin ) ); } else - tDebug() << Q_FUNC_INFO << "Loaded invalid plugin:" << loader.fileName(); + { + tDebug() << Q_FUNC_INFO << "Loaded invalid plugin:" << plugins.key( plugin ); + } } } diff --git a/src/libtomahawk/infosystem/InfoSystemWorker.h b/src/libtomahawk/infosystem/InfoSystemWorker.h index 65cfbd4ed..df966e064 100644 --- a/src/libtomahawk/infosystem/InfoSystemWorker.h +++ b/src/libtomahawk/infosystem/InfoSystemWorker.h @@ -68,7 +68,7 @@ public slots: void addInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin ); void removeInfoPlugin( Tomahawk::InfoSystem::InfoPluginPtr plugin ); - void loadInfoPlugins( const QStringList &pluginPaths ); + void loadInfoPlugins(); void getShortUrl( Tomahawk::InfoSystem::InfoPushData data ); void shortLinkReady( QUrl longUrl, QUrl shortUrl, QVariant callbackObj ); diff --git a/src/libtomahawk/utils/PluginLoader.cpp b/src/libtomahawk/utils/PluginLoader.cpp index db66d4583..f1a056f99 100644 --- a/src/libtomahawk/utils/PluginLoader.cpp +++ b/src/libtomahawk/utils/PluginLoader.cpp @@ -29,6 +29,8 @@ #include #include +#include +#include #include "DllMacro.h" @@ -55,6 +57,40 @@ PluginLoader::~PluginLoader() } +const QHash< QString, QObject* > PluginLoader::loadPlugins() const +{ + tLog() << "Load plugins of type" << d_ptr->type; + + const QString errorMessage("Error loading plugin: %1: %2"); + + QHash< QString, QObject* > plugins; + + foreach( const QString& pluginPath, pluginPaths() ) + { +// tDebug() << Q_FUNC_INFO << "Trying to load plugin:" << pluginPath; + + if ( !QLibrary::isLibrary( pluginPath ) ) + { + tLog() << Q_FUNC_INFO << errorMessage.arg( pluginPath, "Not a library" ); + continue; + } + + QPluginLoader loader( pluginPath ); + + QObject* plugin = loader.instance(); + if ( !plugin ) + { + tLog() << Q_FUNC_INFO << errorMessage.arg( pluginPath, loader.errorString() ); + continue; + } + + plugins.insert( loader.fileName(), plugin ); + } + + return plugins; +} + + const QList< QDir > PluginLoader::pluginDirs() { diff --git a/src/libtomahawk/utils/PluginLoader.h b/src/libtomahawk/utils/PluginLoader.h index 484137fae..2cc495eb0 100644 --- a/src/libtomahawk/utils/PluginLoader.h +++ b/src/libtomahawk/utils/PluginLoader.h @@ -38,12 +38,14 @@ public: PluginLoader( const QString& type ); virtual ~PluginLoader(); + const QHash< QString, QObject* > loadPlugins() const; + +private: const QStringList pluginFilenames( const QString& name = "*" ) const; const QStringList pluginPaths( const QString& name = "*" ) const; static const QList< QDir > pluginDirs(); -private: Q_DECLARE_PRIVATE( PluginLoader ); PluginLoaderPrivate* d_ptr; }; From b2bb0349bec4db9d7f76639ff149611a18a13e37 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 23 Jun 2013 23:37:13 +0200 Subject: [PATCH 15/27] Make building with Qt4 the default even if Qt5 was found --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c52db193..19ec4c4ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ option(BUILD_GUI "Build Tomahawk with GUI" ON) option(BUILD_RELEASE "Generate TOMAHAWK_VERSION without GIT info" OFF) option(BUILD_TESTS "Build Tomahawk with unit tests" ON) option(BUILD_HATCHET "Build the Hatchet plugin" OFF) +option(BUILD_WITH_QT4 "Build Tomahawk with Qt4 no matter if Qt5 was found" ON) option(WITH_BREAKPAD "Build with breakpad integration" ON) option(WITH_CRASHREPORTER "Build with CrashReporter" ON) From a5121f3ad158471116ce60e03878cf5919232be8 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Sun, 23 Jun 2013 23:37:28 +0200 Subject: [PATCH 16/27] Remove obsolete QPluginLoader include from TomahawkApp --- src/tomahawk/TomahawkApp.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/tomahawk/TomahawkApp.cpp b/src/tomahawk/TomahawkApp.cpp index dbb07c2e8..eae770e91 100644 --- a/src/tomahawk/TomahawkApp.cpp +++ b/src/tomahawk/TomahawkApp.cpp @@ -104,7 +104,6 @@ #include #endif -#include #include #include #include From 8f1c4aeaf060a5c1bcb72d8eeca245fadab54a16 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 24 Jun 2013 01:15:24 +0200 Subject: [PATCH 17/27] Yo dawg (teo-), I put a plugin in your plugin, so I can load another plugin for showing an in-application KDE config widget --- CMakeLists.txt | 2 +- .../configstorage/telepathy/CMakeLists.txt | 15 ++++++++ .../telepathy/KdeTelepathyConfigWidget.cpp | 35 +++++++++++++++++ .../telepathy/KdeTelepathyConfigWidget.h | 36 ++++++++++++++++++ .../telepathy/TelepathyConfigStorage.cpp | 24 ++++++++++++ .../telepathy/TelepathyConfigStorage.h | 6 +++ ...lepathyConfigStorageConfigWidgetDllMacro.h | 32 ++++++++++++++++ ...lepathyConfigStorageConfigWidgetPlugin.cpp | 23 +++++++++++ ...TelepathyConfigStorageConfigWidgetPlugin.h | 38 +++++++++++++++++++ 9 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.cpp create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.h create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetDllMacro.h create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetPlugin.cpp create mode 100644 src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetPlugin.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 19ec4c4ac..9b196ed30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -311,8 +311,8 @@ if (WITH_KDE4) endif(WITH_KDE4) # this was used before we had FindKDE4Installed, just leaving it here to keep the flags # for future kde integration +macro_log_feature(KDE4_FOUND "KDE4" "Provides support for configuring Telepathy Accounts from inside Tomahawk" "https://www.kde.org" FALSE "" "") -# macro_optional_find_package(KDE4) IF( KDE4_FOUND ) IF( CMAKE_C_FLAGS ) # KDE4 adds and removes some compiler flags that we don't like diff --git a/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt b/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt index 25f64f7ea..c303b9c4e 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt +++ b/src/libtomahawk/accounts/configstorage/telepathy/CMakeLists.txt @@ -5,7 +5,22 @@ tomahawk_add_plugin(telepathy EXPORT_MACRO CONFIGSTORAGEDLLEXPORT_PRO SOURCES TelepathyConfigStorage.cpp + TelepathyConfigStorageConfigWidgetPlugin.cpp LINK_LIBRARIES ${TOMAHAWK_LIBRARIES} ${TELEPATHY_QT_LIBRARIES} + SHARED_LIB ) + +if( KDE4_FOUND ) + include_directories( ${KDE4_INCLUDES} ) + tomahawk_add_plugin(kde + TYPE configstorage_telepathy + EXPORT_MACRO CONFIGSTORAGETELEPATHYDLLEXPORT_PRO + SOURCES + KdeTelepathyConfigWidget.cpp + LINK_LIBRARIES + tomahawk_configstorage_telepathy + ${KDE4_KCMUTILS_LIBS} + ) +endif() diff --git a/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.cpp b/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.cpp new file mode 100644 index 000000000..516760501 --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.cpp @@ -0,0 +1,35 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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 . + */ + +#include "KdeTelepathyConfigWidget.h" + +#include "utils/Logger.h" + +#include + +#include + +QWidget* +KdeTelepathyConfigWidget::configWidget() +{ + return new KCModuleProxy( "kcm_ktp_accounts" ); +} + +Q_EXPORT_PLUGIN2( TelepathyConfigStorageConfigWidgetPlugin, KdeTelepathyConfigWidget ) + + diff --git a/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.h b/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.h new file mode 100644 index 000000000..61acdbbf2 --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.h @@ -0,0 +1,36 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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 . + */ + +#ifndef KDETELEPATHYCONFIGWIDGET_H +#define KDETELEPATHYCONFIGWIDGET_H + +#include "TelepathyConfigStorageConfigWidgetPlugin.h" + +#include "TelepathyConfigStorageConfigWidgetDllMacro.h" + +class CONFIGSTORAGETELEPATHYDLLEXPORT KdeTelepathyConfigWidget : public TelepathyConfigStorageConfigWidgetPlugin +{ + Q_OBJECT + Q_INTERFACES( TelepathyConfigStorageConfigWidgetPlugin ) + +public: + virtual QWidget* configWidget(); +}; + + +#endif // KDETELEPATHYCONFIGWIDGET_H diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index 87b9241b9..c8ef9b5b0 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2013, Teo Mrnjavac + * Copyright 2013, Dominik Schmidt * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,10 +19,14 @@ #include "TelepathyConfigStorage.h" +#include "TelepathyConfigStorageConfigWidgetPlugin.h" + + #include "accounts/Account.h" #include "accounts/AccountManager.h" #include "accounts/CredentialsManager.h" #include "utils/Logger.h" +#include "utils/PluginLoader.h" #include #include @@ -41,6 +46,7 @@ Tomahawk::Accounts::TelepathyConfigStorage::TelepathyConfigStorage( QObject* par , m_credentialsServiceName( "telepathy-kde" ) { tDebug() << Q_FUNC_INFO; + loadConfigWidgetPlugins(); } @@ -137,6 +143,24 @@ Tomahawk::Accounts::TelepathyConfigStorage::onCredentialsManagerReady( const QSt } +void +Tomahawk::Accounts::TelepathyConfigStorage::loadConfigWidgetPlugins() +{ + tDebug() << Q_FUNC_INFO; + foreach( QObject* plugin, Tomahawk::Utils::PluginLoader( "configstorage_telepathy" ).loadPlugins().values() ) + { + TelepathyConfigStorageConfigWidgetPlugin* configWidgetPlugin = qobject_cast< TelepathyConfigStorageConfigWidgetPlugin* >( plugin ); + if( !configWidgetPlugin ) + { + tLog() << "Tried to load invalid TelepathyConfigStorageConfigWidgetPlugin"; + continue; + } + + m_configWidgetPlugins << configWidgetPlugin; + } +} + + QString Tomahawk::Accounts::TelepathyConfigStorage::telepathyPathToAccountId( const QString& objectPath, const QString& telepathyServiceName ) { diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index d88d65176..530d28bc9 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2013, Teo Mrnjavac + * Copyright 2013, Dominik Schmidt * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +30,8 @@ namespace Tp class PendingOperation; } +class TelepathyConfigStorageConfigWidgetPlugin; + namespace Tomahawk { @@ -61,12 +64,15 @@ private slots: void onCredentialsManagerReady( const QString& service ); private: + void loadConfigWidgetPlugins(); + QString telepathyPathToAccountId( const QString& objectPath, const QString& telepathyServiceName ); QString accountIdToTelepathyPath( const QString& accountId ); const QString m_credentialsServiceName; QStringList m_accountIds; Tp::AccountManagerPtr m_tpam; + QList< TelepathyConfigStorageConfigWidgetPlugin* > m_configWidgetPlugins; static TelepathyConfigStorage* s_instance; }; diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetDllMacro.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetDllMacro.h new file mode 100644 index 000000000..5e72f192f --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetDllMacro.h @@ -0,0 +1,32 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#ifndef TELEPATHYCONFIGSTORAGECONFIGWIDGETDLLMACRO_H +#define TELEPATHYCONFIGSTORAGECONFIGWIDGETDLLMACRO_H + +#include + +#ifndef CONFIGSTORAGETELEPATHYDLLEXPORT +# if defined (CONFIGSTORAGETELEPATHYDLLEXPORT_PRO) +# define CONFIGSTORAGETELEPATHYDLLEXPORT Q_DECL_EXPORT +# else +# define CONFIGSTORAGETELEPATHYDLLEXPORT Q_DECL_IMPORT +# endif +#endif + +#endif // TELEPATHYCONFIGSTORAGECONFIGWIDGETDLLMACRO_H diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetPlugin.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetPlugin.cpp new file mode 100644 index 000000000..860632542 --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetPlugin.cpp @@ -0,0 +1,23 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Dominik Schmidt + * + * 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 . + */ + +#include "TelepathyConfigStorageConfigWidgetPlugin.h" + +TelepathyConfigStorageConfigWidgetPlugin::~TelepathyConfigStorageConfigWidgetPlugin() +{ +} diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetPlugin.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetPlugin.h new file mode 100644 index 000000000..06a665da8 --- /dev/null +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorageConfigWidgetPlugin.h @@ -0,0 +1,38 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#ifndef TELEPATHYCONFIGSTORAGECONFIGWIDGETPLUGIN_H +#define TELEPATHYCONFIGSTORAGECONFIGWIDGETPLUGIN_H + +#include + +#include "accounts/ConfigStorageDllMacro.h" + +class CONFIGSTORAGEDLLEXPORT TelepathyConfigStorageConfigWidgetPlugin : public QObject +{ +Q_OBJECT + +public: + virtual ~TelepathyConfigStorageConfigWidgetPlugin(); + + virtual QWidget* configWidget() = 0; +}; + +Q_DECLARE_INTERFACE( TelepathyConfigStorageConfigWidgetPlugin, "tomahawk.TelepathyConfigStorageConfigWidget/1.0" ) + +#endif // TELEPATHYCONFIGSTORAGE_H From 1c61c5ae25aadf85edc9f2f5165adac1ae8b1cde Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Mon, 24 Jun 2013 02:12:51 +0200 Subject: [PATCH 18/27] Return 0 for KdeConfigWidget if kcm_ktp_accounts was not found --- .../telepathy/KdeTelepathyConfigWidget.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.cpp b/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.cpp index 516760501..a91683eca 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/KdeTelepathyConfigWidget.cpp @@ -27,7 +27,18 @@ QWidget* KdeTelepathyConfigWidget::configWidget() { - return new KCModuleProxy( "kcm_ktp_accounts" ); + KCModuleProxy* proxy = new KCModuleProxy( "kcm_ktp_accounts" ); + + if ( !proxy->aboutData() ) + { + qWarning() << "Could not load kcm_ktp_accounts... "; + + delete proxy; + + return 0; + } + + return proxy; } Q_EXPORT_PLUGIN2( TelepathyConfigStorageConfigWidgetPlugin, KdeTelepathyConfigWidget ) From e2f31fdd68a2ac24c3bed6ee1b9e0803302a1d60 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 28 Jun 2013 21:40:13 +0200 Subject: [PATCH 19/27] Show KTp KCM for KTp akkounts. --- src/accounts/xmpp/XmppConfigWidget.cpp | 2 +- src/libtomahawk/accounts/ConfigStorage.cpp | 2 +- src/libtomahawk/accounts/ConfigStorage.h | 2 +- .../telepathy/TelepathyConfigStorage.cpp | 27 ++++++++++++------- .../telepathy/TelepathyConfigStorage.h | 2 +- 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/accounts/xmpp/XmppConfigWidget.cpp b/src/accounts/xmpp/XmppConfigWidget.cpp index a6001cc90..021e6289b 100644 --- a/src/accounts/xmpp/XmppConfigWidget.cpp +++ b/src/accounts/xmpp/XmppConfigWidget.cpp @@ -84,7 +84,7 @@ void XmppConfigWidget::launchExternalConfigDialog() { ConfigStorage* cs = AccountManager::instance()->configStorageForAccount( m_account->accountId() ); - cs->execConfigDialog(); + cs->execConfigDialog( this ); } diff --git a/src/libtomahawk/accounts/ConfigStorage.cpp b/src/libtomahawk/accounts/ConfigStorage.cpp index 07dac2233..2208420d6 100644 --- a/src/libtomahawk/accounts/ConfigStorage.cpp +++ b/src/libtomahawk/accounts/ConfigStorage.cpp @@ -52,7 +52,7 @@ ConfigStorage::icon() const bool -ConfigStorage::execConfigDialog() +ConfigStorage::execConfigDialog( QWidget* parent ) { return false; } diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h index 7da7a82cd..2a56dac4d 100644 --- a/src/libtomahawk/accounts/ConfigStorage.h +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -45,7 +45,7 @@ public: virtual QPixmap icon() const; - virtual bool execConfigDialog(); + virtual bool execConfigDialog( QWidget* parent ); virtual QStringList accountIds() const = 0; diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index c8ef9b5b0..f04f41a77 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -27,14 +27,18 @@ #include "accounts/CredentialsManager.h" #include "utils/Logger.h" #include "utils/PluginLoader.h" +#include "utils/TomahawkUtilsGui.h" #include #include #include #include +#include +#include #include #include +#include @@ -82,19 +86,22 @@ Tomahawk::Accounts::TelepathyConfigStorage::icon() const bool -Tomahawk::Accounts::TelepathyConfigStorage::execConfigDialog() +Tomahawk::Accounts::TelepathyConfigStorage::execConfigDialog( QWidget* parent ) { - QProcess kcm; - kcm.start( "kcmshell4 kcm_ktp_accounts" ); - if ( !kcm.waitForStarted() ) - return false; + if ( !m_configWidgetPlugins.isEmpty() ) + { + QDialog dialog( parent ); + dialog.resize( parent->logicalDpiX() * 3.0, parent->logicalDpiY() * 2.2 ); + dialog.setLayout( new QVBoxLayout ); + dialog.layout()->addWidget( m_configWidgetPlugins.first()->configWidget() ); - if ( !kcm.waitForFinished( 600000 ) ) - return false; + QDialogButtonBox* box = new QDialogButtonBox( QDialogButtonBox::Close, Qt::Horizontal ); + dialog.layout()->addWidget( box ); + connect( box, SIGNAL( clicked( QAbstractButton* ) ), &dialog, SLOT( accept() ) ); + return dialog.exec(); + } - //TODO: this should probably be async - - return true; + return false; } diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index 530d28bc9..cc4910ebe 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -51,7 +51,7 @@ public: QString prettyName() const; QPixmap icon() const; - bool execConfigDialog(); + bool execConfigDialog( QWidget* parent ); QStringList accountIds() const; From b08ba3fe408a43c6f0bdcc4f97d556f9e9ad9af7 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sat, 29 Jun 2013 12:29:01 +0200 Subject: [PATCH 20/27] KTp KCM dialog title --- .../accounts/configstorage/telepathy/TelepathyConfigStorage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index f04f41a77..5349ad395 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -91,6 +91,7 @@ Tomahawk::Accounts::TelepathyConfigStorage::execConfigDialog( QWidget* parent ) if ( !m_configWidgetPlugins.isEmpty() ) { QDialog dialog( parent ); + dialog.setWindowTitle( tr( "KDE Instant Messaging Accounts" ) ); dialog.resize( parent->logicalDpiX() * 3.0, parent->logicalDpiY() * 2.2 ); dialog.setLayout( new QVBoxLayout ); dialog.layout()->addWidget( m_configWidgetPlugins.first()->configWidget() ); From 484b7ccb88c560bc809de86a8dfc4f13885e0f68 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sat, 29 Jun 2013 12:39:07 +0200 Subject: [PATCH 21/27] Ensure we have a string to show if a Tp account name is empty. --- .../configstorage/telepathy/TelepathyConfigStorage.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index 5349ad395..92a48af6f 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -236,7 +236,13 @@ Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Acco Tp::AccountPtr account = m_tpam->accountForObjectPath( accountIdToTelepathyPath( accountId ) ); - cfg.accountFriendlyName = "Tp:" + account->normalizedName(); + if ( !account->normalizedName().isEmpty() ) + cfg.accountFriendlyName = account->normalizedName(); + else if ( !account->parameters()[ "account" ].isNull() ) + cfg.accountFriendlyName = account->parameters()[ "account" ].toString(); + + if ( cfg.accountFriendlyName.isEmpty() ) //this should never happen + cfg.accountFriendlyName = accountId; cfg.enabled = true; cfg.acl = QVariantMap(); From af6a90f9560ffd628be340f54cfe7d586b8dfd0d Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sat, 29 Jun 2013 15:18:39 +0200 Subject: [PATCH 22/27] Remove cruft --- .../configstorage/telepathy/TelepathyConfigStorage.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index 92a48af6f..6cac3a493 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -225,15 +225,6 @@ Tomahawk::Accounts::TelepathyConfigStorage::save( const QString& accountId, cons void Tomahawk::Accounts::TelepathyConfigStorage::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(); - Tp::AccountPtr account = m_tpam->accountForObjectPath( accountIdToTelepathyPath( accountId ) ); if ( !account->normalizedName().isEmpty() ) From 2cd17362030cc8044f57532cac1f5bc4ad7642b7 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Sat, 29 Jun 2013 15:19:02 +0200 Subject: [PATCH 23/27] Store to LocalConfigStorage as fallback when installing a ResolverAccount. --- src/libtomahawk/accounts/Account.cpp | 3 ++- src/libtomahawk/accounts/AccountManager.cpp | 7 +++++++ src/libtomahawk/accounts/AccountManager.h | 1 + src/libtomahawk/accounts/ResolverAccount.cpp | 7 +++++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/accounts/Account.cpp b/src/libtomahawk/accounts/Account.cpp index 0cda69122..4fa57d2c3 100644 --- a/src/libtomahawk/accounts/Account.cpp +++ b/src/libtomahawk/accounts/Account.cpp @@ -143,7 +143,8 @@ Account::loadFromConfig( const QString& accountId ) { m_accountId = accountId; - AccountManager::instance()->configStorageForAccount( m_accountId )->load( m_accountId, m_cfg ); + if ( AccountManager::instance()->configStorageForAccount( m_accountId ) != 0 ) //could be 0 if we are installing the account right now + AccountManager::instance()->configStorageForAccount( m_accountId )->load( m_accountId, m_cfg ); } diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 86a259147..6800be04d 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -424,6 +424,13 @@ AccountManager::configStorageForAccount( const QString& accountId ) } +ConfigStorage* +AccountManager::localConfigStorage() +{ + return m_configStorageById.value( "localconfigstorage" ); +} + + void AccountManager::hookupAccount( Account* account ) const { diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index b219d8e81..a30b67d8d 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -96,6 +96,7 @@ public: CredentialsManager* credentialsManager() const { return m_creds; } ConfigStorage* configStorageForAccount( const QString& accountId ); + ConfigStorage* localConfigStorage(); public slots: void connectAll(); diff --git a/src/libtomahawk/accounts/ResolverAccount.cpp b/src/libtomahawk/accounts/ResolverAccount.cpp index 90a93a171..3d884f504 100644 --- a/src/libtomahawk/accounts/ResolverAccount.cpp +++ b/src/libtomahawk/accounts/ResolverAccount.cpp @@ -22,6 +22,9 @@ #include "jobview/JobStatusView.h" #include "jobview/JobStatusModel.h" #include "jobview/ErrorStatusMessage.h" +#include "AccountManager.h" +#include "AtticaManager.h" +#include "ConfigStorage.h" #include "resolvers/ExternalResolver.h" #include "resolvers/ExternalResolverGui.h" #include "utils/Logger.h" @@ -302,6 +305,10 @@ ResolverAccount::ResolverAccount( const QString& accountId, const QString& path, setConfiguration( configuration ); + //just init so this account is tracked by LCS, we'll sync later + if ( !AccountManager::instance()->configStorageForAccount( accountId ) ) + AccountManager::instance()->localConfigStorage()->save( accountId, Account::Configuration() ); + init( path ); sync(); From b08cc64a882730c0e0f6236807268e5f6d85514a Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 1 Jul 2013 11:26:03 +0200 Subject: [PATCH 24/27] Default to LocalConfigStorage for (new) accounts without CS. --- src/libtomahawk/accounts/AccountManager.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 6800be04d..065667a88 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -420,7 +420,8 @@ AccountManager::configStorageForAccount( const QString& accountId ) if ( cs->accountIds().contains( accountId ) ) return cs; } - return 0; + tLog() << "Warning: defaulting to LocalConfigStorage for account" << accountId; + return localConfigStorage(); } From 5be9204db288c59e5d1f32fa05ab8a685ed67f4e Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 16 Jul 2013 16:13:43 +0200 Subject: [PATCH 25/27] Added ConfigStorage priority and account deduplication. --- src/libtomahawk/accounts/AccountManager.cpp | 20 ++++++++++++++++++- src/libtomahawk/accounts/AccountManager.h | 4 ++-- src/libtomahawk/accounts/ConfigStorage.h | 2 ++ .../accounts/LocalConfigStorage.cpp | 7 +++++++ src/libtomahawk/accounts/LocalConfigStorage.h | 2 ++ .../telepathy/TelepathyConfigStorage.cpp | 7 +++++++ .../telepathy/TelepathyConfigStorage.h | 2 ++ 7 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/accounts/AccountManager.cpp b/src/libtomahawk/accounts/AccountManager.cpp index 065667a88..95376fdb6 100644 --- a/src/libtomahawk/accounts/AccountManager.cpp +++ b/src/libtomahawk/accounts/AccountManager.cpp @@ -311,7 +311,25 @@ AccountManager::loadPlugin( const QString& accountId ) void AccountManager::addAccount( Account* account ) { - tDebug() << Q_FUNC_INFO << "adding account plugin"; + tDebug() << Q_FUNC_INFO << "adding account plugin" << account->accountId(); + foreach ( Account* a, m_accounts ) + { + if ( a->credentials()["username"] == account->credentials()["username"] ) + { + ConfigStorage* configStorageForA = configStorageForAccount( a->accountId() ); + ConfigStorage* configStorageForNewAccount = configStorageForAccount( account->accountId() ); + + if ( !configStorageForA || !configStorageForNewAccount || configStorageForA->priority() > configStorageForNewAccount->priority() ) + { + removeAccount( a ); + break; + } + else + { + return; + } + } + } m_accounts.append( account ); if ( account->types() & Accounts::SipType ) diff --git a/src/libtomahawk/accounts/AccountManager.h b/src/libtomahawk/accounts/AccountManager.h index a30b67d8d..29ca2766d 100644 --- a/src/libtomahawk/accounts/AccountManager.h +++ b/src/libtomahawk/accounts/AccountManager.h @@ -151,8 +151,8 @@ private: static AccountManager* s_instance; }; -}; +} -}; +} #endif diff --git a/src/libtomahawk/accounts/ConfigStorage.h b/src/libtomahawk/accounts/ConfigStorage.h index 2a56dac4d..734bc3a4b 100644 --- a/src/libtomahawk/accounts/ConfigStorage.h +++ b/src/libtomahawk/accounts/ConfigStorage.h @@ -49,6 +49,8 @@ public: virtual QStringList accountIds() const = 0; + virtual unsigned int priority() const = 0; //LocalConfigStorage has 0, everything else comes later + 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; diff --git a/src/libtomahawk/accounts/LocalConfigStorage.cpp b/src/libtomahawk/accounts/LocalConfigStorage.cpp index a8a8c7ed4..aaf490761 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.cpp +++ b/src/libtomahawk/accounts/LocalConfigStorage.cpp @@ -80,6 +80,13 @@ LocalConfigStorage::accountIds() const } +unsigned int +LocalConfigStorage::priority() const +{ + return 0; +} + + void LocalConfigStorage::save( const QString& accountId, const Account::Configuration& cfg ) { diff --git a/src/libtomahawk/accounts/LocalConfigStorage.h b/src/libtomahawk/accounts/LocalConfigStorage.h index c2aff5edd..55347ea13 100644 --- a/src/libtomahawk/accounts/LocalConfigStorage.h +++ b/src/libtomahawk/accounts/LocalConfigStorage.h @@ -39,6 +39,8 @@ public: QStringList accountIds() const; + unsigned int priority() 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 ); diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index 6cac3a493..f88dba254 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -201,6 +201,13 @@ Tomahawk::Accounts::TelepathyConfigStorage::accountIds() const } +unsigned int +Tomahawk::Accounts::TelepathyConfigStorage::priority() const +{ + return 30; +} + + void Tomahawk::Accounts::TelepathyConfigStorage::save( const QString& accountId, const Account::Configuration& cfg ) { diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h index cc4910ebe..d21265fa7 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.h @@ -55,6 +55,8 @@ public: QStringList accountIds() const; + unsigned int priority() 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 ); From 016466bd522350c80b478ca83c50166b887d1f38 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Mon, 22 Jul 2013 13:08:10 +0200 Subject: [PATCH 26/27] Store the enabled state of external accounts --- .../telepathy/TelepathyConfigStorage.cpp | 46 ++++++++----------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp index f88dba254..6f5ececa5 100644 --- a/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp +++ b/src/libtomahawk/accounts/configstorage/telepathy/TelepathyConfigStorage.cpp @@ -211,18 +211,12 @@ Tomahawk::Accounts::TelepathyConfigStorage::priority() const void Tomahawk::Accounts::TelepathyConfigStorage::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 ); + TomahawkSettings* s = TomahawkSettings::instance(); + s->beginGroup( "externalaccounts/" + accountId ); + s->setValue( "enabled", cfg.enabled ); + s->setValue( "acl", cfg.acl ); + s->endGroup(); + s->sync(); if ( !m_accountIds.contains( accountId ) ) m_accountIds.append( accountId ); @@ -232,6 +226,13 @@ Tomahawk::Accounts::TelepathyConfigStorage::save( const QString& accountId, cons void Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Account::Configuration& cfg ) { + TomahawkSettings* s = TomahawkSettings::instance(); + s->beginGroup( "externalaccounts/" + accountId ); + cfg.enabled = s->value( "enabled", true ).toBool(); + cfg.acl = s->value( "acl", QVariantMap() ).toMap(); + s->endGroup(); + + Tp::AccountPtr account = m_tpam->accountForObjectPath( accountIdToTelepathyPath( accountId ) ); if ( !account->normalizedName().isEmpty() ) @@ -242,9 +243,6 @@ Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Acco if ( cfg.accountFriendlyName.isEmpty() ) //this should never happen cfg.accountFriendlyName = accountId; - cfg.enabled = true; - cfg.acl = QVariantMap(); - QStringList types; types << "SipType"; cfg.types = types; @@ -282,18 +280,12 @@ Tomahawk::Accounts::TelepathyConfigStorage::load( const QString& accountId, Acco void Tomahawk::Accounts::TelepathyConfigStorage::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 ); - -// Tomahawk::Accounts::CredentialsManager* c = Tomahawk::Accounts::AccountManager::instance()->credentialsManager(); -// c->setCredentials( m_credentialsServiceName, account->uniqueIdentifier(), QVariantHash() ); + TomahawkSettings* s = TomahawkSettings::instance(); + s->beginGroup( "externalaccounts/" + accountId ); + s->remove( "enabled" ); + s->remove( "acl" ); + s->endGroup(); + s->remove( "externalaccounts/" + accountId ); } Q_EXPORT_PLUGIN2( Tomahawk::Accounts::ConfigStorage, Tomahawk::Accounts::TelepathyConfigStorage ) From c5ec5bce41a967199e74d28f117e5237630273e2 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Wed, 24 Jul 2013 11:37:12 +0200 Subject: [PATCH 27/27] Fix coding style. --- src/libtomahawk/accounts/Account.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libtomahawk/accounts/Account.h b/src/libtomahawk/accounts/Account.h index 436335af7..6c2eb8767 100644 --- a/src/libtomahawk/accounts/Account.h +++ b/src/libtomahawk/accounts/Account.h @@ -82,7 +82,7 @@ public: enum AuthErrorCode { AuthError, ConnectionError }; enum ConnectionState { Disconnected, Connecting, Connected, Disconnecting }; - explicit Account(const QString &accountId); + explicit Account( const QString& accountId ); virtual ~Account(); QString accountServiceName() const { QMutexLocker locker( &m_mutex ); return m_accountServiceName; } // e.g. "Twitter", "Last.fm"