diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp index b648fd4dc..bf300eb99 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.cpp @@ -838,6 +838,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg const bool isOwner = plMap.value( "owner" ).toBool(); const bool sync = plMap.value( "sync" ).toBool(); const bool subscribed = plMap.value( "subscribed" ).toBool(); + const bool starContainer = plMap.value( "starContainer" ).toBool(); if ( name.isNull() || plid.isNull() || revid.isNull() ) { @@ -845,7 +846,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg continue; } - registerPlaylistInfo( new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed, isOwner ) ); + registerPlaylistInfo( new SpotifyPlaylistInfo( name, plid, revid, sync, subscribed, isOwner, starContainer ) ); } if ( !m_configWidget.isNull() ) @@ -862,8 +863,14 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg if ( !m_updaters.contains( plid ) ) return; - SpotifyPlaylistUpdater* updater = m_updaters[ plid ]; + SpotifyPlaylistInfo* info = m_allSpotifyPlaylists[ plid ]; + if( (info && info->starContainer ) && loveSync() ) + { + qDebug() << Q_FUNC_INFO << "SKIPPING" << msgType; + return; + } + SpotifyPlaylistUpdater* updater = m_updaters[ plid ]; // We have previously sycned starred container, but not anymore. // If we added loveSync, its synced in the background if( !updater->sync() && m_configWidget.data()->loveSync() ) @@ -887,6 +894,12 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg if ( !m_updaters.contains( plid ) ) return; + SpotifyPlaylistInfo* info = m_allSpotifyPlaylists[ plid ]; + if( (info && info->starContainer ) && loveSync() ) + { + qDebug() << Q_FUNC_INFO << "SKIPPING" << msgType; + return; + } SpotifyPlaylistUpdater* updater = m_updaters[ plid ]; // If we're not syncing with this, the resolver is quite misinformed. @@ -898,7 +911,6 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg const QString newRev = msg.value( "revid" ).toString(); const QString oldRev = msg.value( "oldRev" ).toString(); - updater->spotifyTracksRemoved( tracksList, newRev, oldRev ); } else if ( msgType == "tracksMoved" ) @@ -910,6 +922,12 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg if ( !m_updaters.contains( plid ) ) return; + SpotifyPlaylistInfo* info = m_allSpotifyPlaylists[ plid ]; + if( (info && info->starContainer ) && loveSync() ) + { + qDebug() << Q_FUNC_INFO << "SKIPPING" << msgType; + return; + } SpotifyPlaylistUpdater* updater = m_updaters[ plid ]; Q_ASSERT( updater->sync() ); @@ -926,6 +944,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg { const QVariantList tracksList = msg.value( "tracks" ).toList(); const bool love = msg.value( "starred" ).toBool(); + QList qs = SpotifyPlaylistUpdater::variantToQueries( tracksList ); foreach ( const query_ptr& query, qs ) { @@ -943,6 +962,12 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg if ( !m_updaters.contains( plid ) ) return; + SpotifyPlaylistInfo* info = m_allSpotifyPlaylists[ plid ]; + if( (info && info->starContainer ) && loveSync() ) + { + qDebug() << Q_FUNC_INFO << "SKIPPING" << msgType; + return; + } SpotifyPlaylistUpdater* updater = m_updaters[ plid ]; Q_ASSERT( updater->sync() ); @@ -952,7 +977,6 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg const bool collaborative = msg.value( "collaborative" ).toBool(); const int subscribers = msg.value( "subscribers" ).toInt(); - SpotifyPlaylistInfo* info = m_allSpotifyPlaylists[ plid ]; if( info && info->name != title ) { qDebug() << "Playlist renamed fetched in tomahawk"; @@ -1156,17 +1180,7 @@ SpotifyAccount::saveConfig() { pl->changed = false; - if ( !pl->sync && pl->loveSync ) - { - QVariantMap msg; - msg[ "_msgtype" ] = "setSync"; - msg[ "playlistid" ] = pl->plid; - msg[ "sync" ] = pl->loveSync; - sendMessage( msg ); - - } - - if ( pl->sync ) + if ( pl->sync || ( pl->starContainer && loveSync() ) ) { // Fetch full playlist contents, then begin the sync startPlaylistSync( pl ); @@ -1216,11 +1230,22 @@ SpotifyAccount::startPlaylistSync( SpotifyPlaylistInfo* playlist ) return; QVariantMap msg; - msg[ "_msgtype" ] = "getPlaylist"; msg[ "playlistid" ] = playlist->plid; - msg[ "sync" ] = playlist->sync; + msg[ "sync" ] = true; + + if( playlist->loveSync ) + { + msg[ "_msgtype" ] = "setSync"; + sendMessage( msg ); + if( playlist->sync && m_updaters.contains( playlist->plid ) ) + stopPlaylistSync(playlist, true); + } + else if( playlist->sync ) + { + msg[ "_msgtype" ] = "getPlaylist"; + sendMessage( msg, this, "startPlaylistSyncWithPlaylist" ); + } - sendMessage( msg, this, "startPlaylistSyncWithPlaylist" ); } @@ -1240,7 +1265,6 @@ SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVa // create a list of query/plentries directly QList< query_ptr > queries = SpotifyPlaylistUpdater::variantToQueries( tracks ); - /** * Begin syncing a playlist. Two options: * 1) This is a playlist that has never been synced to tomahawk. Create a new one @@ -1253,12 +1277,22 @@ SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVa { //Q_ASSERT( m_updaters[ id ]->sync() == false ); /// Should have been unchecked/off before, but might not be if the user // changed spotify resolver meanwhile, so allow it for now - m_updaters[ id ]->setSync( true ); -// m_updaters[ id ]-> - // TODO + SpotifyPlaylistInfo* info = m_allSpotifyPlaylists[ id ]; + if ( loveSync() && ( info && info->starContainer ) ) + { + qDebug() << "Stopping playlist sync in favour for Love Sync"; + stopPlaylistSync( info, true ); + } + else + { + m_updaters[ id ]->setSync( true ); +// m_updaters[ id ]-> + // TODO + } } else { + playlist_ptr plPtr = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), uuid(), name, @@ -1412,15 +1446,21 @@ SpotifyAccount::stopPlaylistSync( SpotifyPlaylistInfo* playlist, bool forceDontD if ( !playlist ) return; - QVariantMap msg; - msg[ "_msgtype" ] = "removeFromSyncList"; - msg[ "playlistid" ] = playlist->plid; + if ( loveSync() && playlist->starContainer ) + { + qDebug() << "LoveSync in action, wont remove playlist " << playlist->name; + } + else if( !loveSync() ) + { + QVariantMap msg; + msg[ "_msgtype" ] = "removeFromSyncList"; + msg[ "playlistid" ] = playlist->plid; - m_spotifyResolver.data()->sendMessage( msg ); + m_spotifyResolver.data()->sendMessage( msg ); + } if ( m_updaters.contains( playlist->plid ) ) { - SpotifyPlaylistUpdater* updater = m_updaters[ playlist->plid ]; updater->setSync( false ); diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccount.h b/src/libtomahawk/accounts/spotify/SpotifyAccount.h index 4e252f3c7..59527afe2 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccount.h +++ b/src/libtomahawk/accounts/spotify/SpotifyAccount.h @@ -51,13 +51,14 @@ class SpotifyAccountConfig; // metadata for a playlist struct SpotifyPlaylistInfo { QString name, plid, revid; - bool sync, subscribed, changed, isOwner, loveSync; + bool sync, subscribed, changed, isOwner, starContainer; + bool loveSync; + SpotifyPlaylistInfo( const QString& nname, const QString& pid, const QString& rrevid, bool ssync, bool ssubscribed, bool isowner = false, bool star = false ) + : name( nname ), plid( pid ), revid( rrevid ), sync( ssync ), subscribed( ssubscribed ) + , changed( false ), isOwner( isowner ), starContainer( star ), loveSync( false ) {} - 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 ), loveSync( false ) {} + SpotifyPlaylistInfo() : sync( false ), changed( false ), starContainer( false ), loveSync( false ) {} }; diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.cpp b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.cpp index 5ff1ea278..1fe35b289 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.cpp +++ b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.cpp @@ -49,7 +49,7 @@ SpotifyAccountConfig::SpotifyAccountConfig( SpotifyAccount *account ) m_ui->loginButton->setDefault( true ); connect( m_ui->loginButton, SIGNAL( clicked( bool ) ), this, SLOT( doLogin() ) ); - + connect( m_ui->loveSync, SIGNAL( toggled(bool) ), this, SLOT( showStarredPlaylist(bool) ) ); connect( m_ui->usernameEdit, SIGNAL( textEdited( QString ) ), this, SLOT( resetLoginButton() ) ); connect( m_ui->passwordEdit, SIGNAL( textEdited( QString ) ), this, SLOT( resetLoginButton() ) ); connect( m_ui->selectAllCheckbox, SIGNAL( stateChanged( int ) ), this, SLOT( selectAllPlaylists() ) ); @@ -104,7 +104,8 @@ SpotifyAccountConfig::saveSettings() pl->changed = true; pl->sync = toSync; } - if ( pl->name == "Starred Tracks" && pl->loveSync != loveSync() ) + + if ( ( pl->starContainer && loveSync() ) && ( pl->loveSync != loveSync() ) ) { pl->loveSync = loveSync(); pl->changed = true; @@ -162,6 +163,9 @@ SpotifyAccountConfig::setPlaylists( const QList& playlist { QListWidgetItem* item = new QListWidgetItem( pl->name, m_ui->playlistList ); item->setData( Qt::UserRole, QVariant::fromValue< SpotifyPlaylistInfo* >( pl ) ); + item->setData( Qt::UserRole+2, pl->starContainer ); + if( loveSync() && pl->starContainer ) + item->setHidden(true); item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsSelectable | Qt::ItemIsEnabled ); item->setCheckState( pl->sync ? Qt::Checked : Qt::Unchecked ); } @@ -216,6 +220,16 @@ SpotifyAccountConfig::loginResponse( bool success, const QString& msg, const QSt } +void +SpotifyAccountConfig::showStarredPlaylist( bool hide ) +{ + for ( int i = 0; i < m_ui->playlistList->count(); i++ ) + { + QListWidgetItem* item = m_ui->playlistList->item( i ); + if ( item->data( Qt::UserRole+2 ).toBool() ) + item->setHidden( hide ); + } +} void SpotifyAccountConfig::selectAllPlaylists() { diff --git a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.h b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.h index c3eeb2267..8afedd69f 100644 --- a/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.h +++ b/src/libtomahawk/accounts/spotify/SpotifyAccountConfig.h @@ -72,6 +72,7 @@ private slots: void doLogin(); void resetLoginButton(); void selectAllPlaylists(); + void showStarredPlaylist(bool); private: void showLoggedIn();