From 5be9204db288c59e5d1f32fa05ab8a685ed67f4e Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 16 Jul 2013 16:13:43 +0200 Subject: [PATCH] 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 );