1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-17 11:30:49 +02:00

Added ConfigStorage priority and account deduplication.

This commit is contained in:
Teo Mrnjavac
2013-07-16 16:13:43 +02:00
parent b08cc64a88
commit 5be9204db2
7 changed files with 41 additions and 3 deletions

View File

@@ -311,7 +311,25 @@ AccountManager::loadPlugin( const QString& accountId )
void void
AccountManager::addAccount( Account* account ) 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 ); m_accounts.append( account );
if ( account->types() & Accounts::SipType ) if ( account->types() & Accounts::SipType )

View File

@@ -151,8 +151,8 @@ private:
static AccountManager* s_instance; static AccountManager* s_instance;
}; };
}; }
}; }
#endif #endif

View File

@@ -49,6 +49,8 @@ public:
virtual QStringList accountIds() const = 0; 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 save( const QString& accountId, const Account::Configuration& cfg ) = 0;
virtual void load( const QString& accountId, Account::Configuration& cfg ) = 0; virtual void load( const QString& accountId, Account::Configuration& cfg ) = 0;
virtual void remove( const QString& accountId ) = 0; virtual void remove( const QString& accountId ) = 0;

View File

@@ -80,6 +80,13 @@ LocalConfigStorage::accountIds() const
} }
unsigned int
LocalConfigStorage::priority() const
{
return 0;
}
void void
LocalConfigStorage::save( const QString& accountId, const Account::Configuration& cfg ) LocalConfigStorage::save( const QString& accountId, const Account::Configuration& cfg )
{ {

View File

@@ -39,6 +39,8 @@ public:
QStringList accountIds() const; QStringList accountIds() const;
unsigned int priority() const;
virtual void save( const QString& accountId, const Account::Configuration& cfg ); virtual void save( const QString& accountId, const Account::Configuration& cfg );
virtual void load( const QString& accountId, Account::Configuration& cfg ); virtual void load( const QString& accountId, Account::Configuration& cfg );
virtual void remove( const QString& accountId ); virtual void remove( const QString& accountId );

View File

@@ -201,6 +201,13 @@ Tomahawk::Accounts::TelepathyConfigStorage::accountIds() const
} }
unsigned int
Tomahawk::Accounts::TelepathyConfigStorage::priority() const
{
return 30;
}
void void
Tomahawk::Accounts::TelepathyConfigStorage::save( const QString& accountId, const Account::Configuration& cfg ) Tomahawk::Accounts::TelepathyConfigStorage::save( const QString& accountId, const Account::Configuration& cfg )
{ {

View File

@@ -55,6 +55,8 @@ public:
QStringList accountIds() const; QStringList accountIds() const;
unsigned int priority() const;
virtual void save( const QString& accountId, const Account::Configuration& cfg ); virtual void save( const QString& accountId, const Account::Configuration& cfg );
virtual void load( const QString& accountId, Account::Configuration& cfg ); virtual void load( const QString& accountId, Account::Configuration& cfg );
virtual void remove( const QString& accountId ); virtual void remove( const QString& accountId );