1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-10-05 01:52:28 +02: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

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