1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

Spotify: Sync Starred tracks to Loved tracks

This commit is contained in:
Hugo Lindström 2012-12-21 11:22:13 +01:00
parent 027123ae5d
commit ec85e91825
5 changed files with 63 additions and 6 deletions

View File

@ -902,6 +902,19 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg
updater->spotifyTracksMoved( tracksList, newStartPos, newRev, oldRev );
}
else if ( msgType == "starredChanged" )
{
if( loveSync() )
{
const QVariantList tracksList = msg.value( "tracks" ).toList();
const bool love = msg.value( "starred" ).toBool();
QList<query_ptr> qs = SpotifyPlaylistUpdater::variantToQueries( tracksList );
foreach( const query_ptr& query, qs )
{
query->setLoved( love );
}
}
}
else if ( msgType == "playlistMetadataChanged" )
{
const QString plid = msg.value( "id" ).toString();
@ -1114,6 +1127,7 @@ SpotifyAccount::saveConfig()
QVariantHash config = configuration();
config[ "deleteOnUnsync" ] = m_configWidget.data()->deleteOnUnsync();
config[ "loveSync" ] = m_configWidget.data()->loveSync();
setConfiguration( config );
m_configWidget.data()->saveSettings();
@ -1123,7 +1137,15 @@ SpotifyAccount::saveConfig()
if ( pl->changed )
{
pl->changed = false;
if ( pl->sync )
if( !pl->sync && pl->loveSync )
{
QVariantMap msg;
msg[ "_msgtype" ] = "setSync";
msg[ "playlistid" ] = pl->plid;
msg[ "sync" ] = pl->loveSync;
sendMessage( msg );
}
else if ( pl->sync )
{
// Fetch full playlist contents, then begin the sync
startPlaylistSync( pl );
@ -1355,6 +1377,14 @@ SpotifyAccount::deleteOnUnsync() const
return configuration().value( "deleteOnUnsync", false ).toBool();
}
bool
SpotifyAccount::loveSync() const
{
return configuration().value( "loveSync", false ).toBool();
}
void
SpotifyAccount::stopPlaylistSync( SpotifyPlaylistInfo* playlist, bool forceDontDelete )
{

View File

@ -51,13 +51,13 @@ class SpotifyAccountConfig;
// metadata for a playlist
struct SpotifyPlaylistInfo {
QString name, plid, revid;
bool sync, subscribed, changed, isOwner;
bool sync, subscribed, changed, isOwner, loveSync;
SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync, bool ssubscribed, bool isowner = false )
: name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), subscribed( ssubscribed ), changed( false ), isOwner( isowner ) {}
SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync, bool ssubscribed, bool isowner = false, bool lovesync = false )
: name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), subscribed( ssubscribed ), changed( false ), isOwner( isowner ), loveSync( lovesync ) {}
SpotifyPlaylistInfo() : sync( false ), changed( false ) {}
SpotifyPlaylistInfo() : sync( false ), changed( false ), loveSync( false ) {}
};
@ -109,7 +109,7 @@ public:
void unregisterUpdater( const QString& plid );
bool deleteOnUnsync() const;
bool loveSync() const;
void setManualResolverPath( const QString& resolverPath );
bool loggedIn() const;

View File

@ -77,6 +77,7 @@ SpotifyAccountConfig::loadFromConfig()
m_ui->passwordEdit->setText( m_account->credentials().value( "password" ).toString() );
m_ui->streamingCheckbox->setChecked( m_account->credentials().value( "highQuality" ).toBool() );
m_ui->deleteOnUnsync->setChecked( m_account->deleteOnUnsync() );
m_ui->loveSync->setChecked( m_account->loveSync() );
if ( m_account->loggedIn() )
{
@ -103,6 +104,11 @@ SpotifyAccountConfig::saveSettings()
pl->changed = true;
pl->sync = toSync;
}
if ( pl->name == "Starred Tracks" && pl->loveSync != loveSync() )
{
pl->loveSync = loveSync();
pl->changed = true;
}
}
}
@ -133,6 +139,13 @@ SpotifyAccountConfig::deleteOnUnsync() const
}
bool
SpotifyAccountConfig::loveSync() const
{
return m_ui->loveSync->isChecked();
}
void
SpotifyAccountConfig::setPlaylists( const QList<SpotifyPlaylistInfo *>& playlists )
{

View File

@ -50,6 +50,7 @@ public:
QString password() const;
bool highQuality() const;
bool deleteOnUnsync() const;
bool loveSync() const;
void setPlaylists( const QList< SpotifyPlaylistInfo* >& playlists );

View File

@ -145,6 +145,19 @@
<item>
<widget class="QListWidget" name="playlistList"/>
</item>
<item>
<widget class="QCheckBox" name="loveSync">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Sync Starred tracks to Loved tracks</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="streamingCheckbox">
<property name="layoutDirection">