1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-22 16:59:58 +01:00

Ensure we have lastfm and spotify accounts

This commit is contained in:
Leo Franchi 2012-05-18 12:46:11 -04:00
parent 4f947b893f
commit 647f68bd22
4 changed files with 52 additions and 14 deletions

View File

@ -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 ) ) );

View File

@ -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();
}
}
}

View File

@ -214,6 +214,8 @@ private slots:
private:
void doInitialSetup();
void createLastFmAccount();
void createSpotifyAccount();
void doUpgrade( int oldVersion, int newVersion );
static TomahawkSettings* s_instance;

View File

@ -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.<br /><br />"
box.setText( tr( "Unfortunately, automatic installation of this resolver is not yet available on Linux.<br /><br />"
"Please use \"Install from file\" above, by fetching it from your distribution or compiling it yourself. Further instructions can be found here:<br /><br />http://www.tomahawk-player.org/resolvers/%1" ).arg( acct->accountServiceName() ) );
box.setStandardButtons( QMessageBox::Ok );
box.exec();