From 647f68bd2289c245bd722a8af2db2cd34869f996 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Fri, 18 May 2012 12:46:11 -0400 Subject: [PATCH] Ensure we have lastfm and spotify accounts --- src/accounts/spotify/SpotifyAccount.cpp | 6 +-- src/libtomahawk/TomahawkSettings.cpp | 56 +++++++++++++++++++---- src/libtomahawk/TomahawkSettings.h | 2 + src/libtomahawk/accounts/AccountModel.cpp | 2 +- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/accounts/spotify/SpotifyAccount.cpp b/src/accounts/spotify/SpotifyAccount.cpp index e2d0a86e0..3a740f551 100644 --- a/src/accounts/spotify/SpotifyAccount.cpp +++ b/src/accounts/spotify/SpotifyAccount.cpp @@ -90,6 +90,9 @@ SpotifyAccount::~SpotifyAccount() void SpotifyAccount::init() { + setAccountFriendlyName( "Spotify" ); + setAccountServiceName( "spotify" ); + if ( !AtticaManager::instance()->resolversLoaded() ) { // If we're still waiting to load, wait for the attica resolvers to come down the pipe @@ -99,9 +102,6 @@ SpotifyAccount::init() qRegisterMetaType< Tomahawk::Accounts::SpotifyPlaylistInfo* >( "Tomahawk::Accounts::SpotifyPlaylist*" ); - setAccountFriendlyName( "Spotify" ); - setAccountServiceName( "spotify" ); - AtticaManager::instance()->registerCustomAccount( s_resolverId, this ); connect( AtticaManager::instance(), SIGNAL( resolverInstalled( QString ) ), this, SLOT( resolverInstalled( QString ) ) ); diff --git a/src/libtomahawk/TomahawkSettings.cpp b/src/libtomahawk/TomahawkSettings.cpp index bf4619865..cb563ec7a 100644 --- a/src/libtomahawk/TomahawkSettings.cpp +++ b/src/libtomahawk/TomahawkSettings.cpp @@ -127,6 +127,21 @@ TomahawkSettings::TomahawkSettings( QObject* parent ) // insert upgrade code here as required setValue( "configversion", TOMAHAWK_SETTINGS_VERSION ); } + + // Ensure last.fm and spotify accounts always exist + QString spotifyAcct, lastfmAcct; + foreach ( const QString& acct, value( "accounts/allaccounts" ).toStringList() ) + { + if ( acct.startsWith( "lastfmaccount_" ) ) + lastfmAcct = acct; + else if ( acct.startsWith( "spotifyaccount_" ) ) + spotifyAcct = acct; + } + + if ( spotifyAcct.isEmpty() ) + createSpotifyAccount(); + if ( lastfmAcct.isEmpty() ) + createLastFmAccount(); } @@ -142,6 +157,15 @@ TomahawkSettings::doInitialSetup() // by default we add a local network resolver addAccount( "sipzeroconf_autocreated" ); + + createLastFmAccount(); + createSpotifyAccount(); +} + + +void +TomahawkSettings::createLastFmAccount() +{ // Add a last.fm account for scrobbling and infosystem const QString accountKey = QString( "lastfmaccount_%1" ).arg( QUuid::createUuid().toString().mid( 1, 8 ) ); addAccount( accountKey ); @@ -151,6 +175,27 @@ TomahawkSettings::doInitialSetup() setValue( "autoconnect", true ); setValue( "types", QStringList() << "ResolverType" << "StatusPushType" ); endGroup(); + + QStringList allAccounts = value( "accounts/allaccounts" ).toStringList(); + allAccounts << accountKey; + setValue( "accounts/allaccounts", allAccounts ); +} + + +void +TomahawkSettings::createSpotifyAccount() +{ + const QString accountKey = QString( "spotifyaccount_%1" ).arg( QUuid::createUuid().toString().mid( 1, 8 ) ); + beginGroup( "accounts/" + accountKey ); + setValue( "enabled", false ); + setValue( "types", QStringList() << "ResolverType" ); + setValue( "credentials", QVariantHash() ); + setValue( "configuration", QVariantHash() ); + endGroup(); + + QStringList allAccounts = value( "accounts/allaccounts" ).toStringList(); + allAccounts << accountKey; + setValue( "accounts/allaccounts", allAccounts ); } @@ -541,16 +586,7 @@ TomahawkSettings::doUpgrade( int oldVersion, int newVersion ) } else { - const QString accountKey = QString( "spotifyaccount_%1" ).arg( QUuid::createUuid().toString().mid( 1, 8 ) ); - beginGroup( "accounts/" + accountKey ); - setValue( "enabled", false ); - setValue( "types", QStringList() << "ResolverType" ); - setValue( "credentials", QVariantHash() ); - setValue( "configuration", QVariantHash() ); - endGroup(); - - allAccounts << accountKey; - setValue( "accounts/allaccounts", allAccounts ); + createSpotifyAccount(); } } } diff --git a/src/libtomahawk/TomahawkSettings.h b/src/libtomahawk/TomahawkSettings.h index 421a6480c..717da384d 100644 --- a/src/libtomahawk/TomahawkSettings.h +++ b/src/libtomahawk/TomahawkSettings.h @@ -214,6 +214,8 @@ private slots: private: void doInitialSetup(); + void createLastFmAccount(); + void createSpotifyAccount(); void doUpgrade( int oldVersion, int newVersion ); static TomahawkSettings* s_instance; diff --git a/src/libtomahawk/accounts/AccountModel.cpp b/src/libtomahawk/accounts/AccountModel.cpp index b462e7673..677e9c3c6 100644 --- a/src/libtomahawk/accounts/AccountModel.cpp +++ b/src/libtomahawk/accounts/AccountModel.cpp @@ -505,7 +505,7 @@ AccountModel::setData( const QModelIndex& index, const QVariant& value, int role box.setWindowTitle( tr( "Manual Install Required" ) ); box.setTextFormat( Qt::RichText ); box.setIcon( QMessageBox::Information ); - box.setText( tr( "Unfortunately, automatic installation of the this resolver is not yet available on Linux.

" + box.setText( tr( "Unfortunately, automatic installation of this resolver is not yet available on Linux.

" "Please use \"Install from file\" above, by fetching it from your distribution or compiling it yourself. Further instructions can be found here:

http://www.tomahawk-player.org/resolvers/%1" ).arg( acct->accountServiceName() ) ); box.setStandardButtons( QMessageBox::Ok ); box.exec();