diff --git a/src/accounts/spotify/SpotifyAccount.cpp b/src/accounts/spotify/SpotifyAccount.cpp index 4d0f20e4b..ddcad7da8 100644 --- a/src/accounts/spotify/SpotifyAccount.cpp +++ b/src/accounts/spotify/SpotifyAccount.cpp @@ -95,9 +95,6 @@ SpotifyAccount::init() msg[ "_msgtype" ] = "getCredentials"; m_spotifyResolver.data()->sendMessage( msg ); } - - // TODO add caching - loadPlaylists(); } @@ -144,7 +141,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg const QString name = plMap.value( "name" ).toString(); const QString plid = plMap.value( "id" ).toString(); const QString revid = plMap.value( "revid" ).toString(); - const bool sync = plMap.value( "map" ).toBool(); + const bool sync = plMap.value( "sync" ).toBool(); if ( name.isNull() || plid.isNull() || revid.isNull() ) { @@ -216,24 +213,6 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg updater->spotifyTracksMoved( tracksList, newRev, oldRev ); } - else if ( msgType == "playlists" ) - { -// QList< Tomahawk::query_ptr > tracks; -// const QString qid = m.value( "qid" ).toString(); -// const QString title = m.value( "identifier" ).toString(); -// const QVariantList reslist = m.value( "playlist" ).toList(); - -// if( !reslist.isEmpty() ) -// { -// foreach( const QVariant& rv, reslist ) -// { -// QVariantMap m = rv.toMap(); -// qDebug() << "Found playlist result:" << m; -// Tomahawk::query_ptr q = Tomahawk::Query::get( m.value( "artist" ).toString() , m.value( "track" ).toString() , QString(), uuid(), false ); -// tracks << q; -// } -// } - } } @@ -293,6 +272,7 @@ SpotifyAccount::saveConfig() m_configWidget.data()->saveSettings(); foreach ( SpotifyPlaylistInfo* pl, m_allSpotifyPlaylists ) { + qDebug() << "Checking changed state:" << pl->changed << pl->name << pl->sync; if ( pl->changed ) { pl->changed = false; @@ -359,59 +339,6 @@ SpotifyAccount::startPlaylistSyncWithPlaylist( const QString& msgType, const QVa } -void -SpotifyAccount::addPlaylist( const QString &qid, const QString& title, QList< Tomahawk::query_ptr > tracks ) -{ -/* Sync sync; - sync.id_ = qid; - int index = m_syncPlaylists.indexOf( sync ); - - if( !m_syncPlaylists.contains( sync ) ) - { - qDebug() << Q_FUNC_INFO << "Adding playlist to sync" << qid; - playlist_ptr pl; - pl = Tomahawk::Playlist::create( SourceList::instance()->getLocal(), - uuid(), - title, - QString(), - QString(), - false, - tracks ); - sync.playlist = pl; - sync.uuid = pl->guid(); - m_syncPlaylists.append( sync ); - } - else - { - - qDebug() << Q_FUNC_INFO << "Found playlist"; - - if ( index != -1 && !tracks.isEmpty()) - { - - qDebug() << Q_FUNC_INFO << "Got pl" << m_syncPlaylists[ index ].playlist->guid(); - - QList< query_ptr > currTracks; - foreach ( const plentry_ptr ple, m_syncPlaylists[ index ].playlist->entries() ) - currTracks << ple->query(); - - qDebug() << Q_FUNC_INFO << "tracks" << currTracks; - - bool changed = false; - QList< query_ptr > mergedTracks = TomahawkUtils::mergePlaylistChanges( currTracks, tracks, changed ); - - if ( changed ) - { - QList el = m_syncPlaylists[ index ].playlist->entriesFromQueries( mergedTracks, true ); - m_syncPlaylists[ index ].playlist->createNewRevision( uuid(), m_syncPlaylists[ index ].playlist->currentrevision(), el ); - } - } - } - - */ -} - - void SpotifyAccount::sendMessage( const QVariantMap &m, QObject* obj, const QString& slot ) { @@ -442,7 +369,11 @@ SpotifyAccount::fetchFullPlaylist( SpotifyPlaylistInfo* playlist ) void SpotifyAccount::stopPlaylistSync( SpotifyPlaylistInfo* playlist ) { + QVariantMap msg; + msg[ "_msgtype" ] = "removeFromSyncList"; + msg[ "playlistid" ] = playlist->plid; + m_spotifyResolver.data()->sendMessage( msg ); } diff --git a/src/accounts/spotify/SpotifyAccount.h b/src/accounts/spotify/SpotifyAccount.h index d33512aa8..4ea89818e 100644 --- a/src/accounts/spotify/SpotifyAccount.h +++ b/src/accounts/spotify/SpotifyAccount.h @@ -84,8 +84,6 @@ public: virtual QWidget* aclWidget() { return 0; } virtual InfoSystem::InfoPlugin* infoPlugin() { return 0; } virtual SipPlugin* sipPlugin() { return 0; } - - void addPlaylist( const QString &qid, const QString& title, QList< Tomahawk::query_ptr > tracks ); /* struct Sync { QString id_; diff --git a/src/accounts/spotify/SpotifyAccountConfig.cpp b/src/accounts/spotify/SpotifyAccountConfig.cpp index 2b2ffbd2f..5bfb3ddd6 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.cpp +++ b/src/accounts/spotify/SpotifyAccountConfig.cpp @@ -60,7 +60,8 @@ SpotifyAccountConfig::saveSettings() { for( int i = 0; i < m_ui->playlistList->count(); i++ ) { - const QListWidgetItem* item = m_ui->playlistList->itemAt( i, 0 ); + const QListWidgetItem* item = m_ui->playlistList->item( i ); + SpotifyPlaylistInfo* pl = item->data( Qt::UserRole ).value< SpotifyPlaylistInfo* >(); const bool toSync = ( item->checkState() == Qt::Checked ); if ( pl->sync != toSync ) diff --git a/src/accounts/spotify/SpotifyAccountConfig.ui b/src/accounts/spotify/SpotifyAccountConfig.ui index d8b99d9cb..d01df823f 100644 --- a/src/accounts/spotify/SpotifyAccountConfig.ui +++ b/src/accounts/spotify/SpotifyAccountConfig.ui @@ -171,6 +171,13 @@ + + + + Delete Tomahawk playlist when removing Spotify sync + + + diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp index 96c75e140..909eae163 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp @@ -238,6 +238,7 @@ SpotifyPlaylistUpdater::tomahawkTracksRemoved( const QList< query_ptr >& tracks qDebug() << Q_FUNC_INFO << "updating spotify resolver with removed tracks:" << tracks; QVariantMap msg; msg[ "_msgtype" ] = "removeTracksFromPlaylist"; + msg[ "playlistid" ] = m_spotifyId; msg[ "oldrev" ] = m_latestRev; msg[ "tracks" ] = queriesToVariant( tracks ); diff --git a/src/libtomahawk/playlist/playlistmodel.cpp b/src/libtomahawk/playlist/playlistmodel.cpp index 06f4ed58a..97264accc 100644 --- a/src/libtomahawk/playlist/playlistmodel.cpp +++ b/src/libtomahawk/playlist/playlistmodel.cpp @@ -41,6 +41,7 @@ PlaylistModel::PlaylistModel( QObject* parent ) : TrackModel( parent ) , m_isTemporary( false ) , m_changesOngoing( false ) + , m_isLoading( false ) , m_savedInsertPos( -1 ) { m_dropStorage.parent = QPersistentModelIndex(); @@ -65,6 +66,8 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEn disconnect( m_playlist.data(), SIGNAL( changed() ), this, SIGNAL( playlistChanged() ) ); } + m_isLoading = true; + if ( loadEntries ) clear(); @@ -80,11 +83,17 @@ PlaylistModel::loadPlaylist( const Tomahawk::playlist_ptr& playlist, bool loadEn .arg( TomahawkUtils::ageToString( QDateTime::fromTime_t( playlist->createdOn() ), true ) ) ); m_isTemporary = false; + if ( !loadEntries ) + { + m_isLoading = false; return; + } QList entries = playlist->entries(); append( entries ); + + m_isLoading = false; } @@ -204,8 +213,11 @@ PlaylistModel::insert( const QList< Tomahawk::plentry_ptr >& entries, int row ) crows.first = c; crows.second = c + entries.count() - 1; - m_savedInsertPos = row; - m_savedInsertTracks = entries; + if ( !m_isLoading ) + { + m_savedInsertPos = row; + m_savedInsertTracks = entries; + } emit beginInsertRows( QModelIndex(), crows.first, crows.second ); @@ -463,7 +475,7 @@ PlaylistModel::remove( const QModelIndex& index, bool moreToCome ) if ( !m_changesOngoing ) beginPlaylistChanges(); - if ( item ) + if ( item && !m_isLoading ) m_savedRemoveTracks << item->query(); TrackModel::remove( index, moreToCome ); diff --git a/src/libtomahawk/playlist/playlistmodel.h b/src/libtomahawk/playlist/playlistmodel.h index aca54fcc3..37a201858 100644 --- a/src/libtomahawk/playlist/playlistmodel.h +++ b/src/libtomahawk/playlist/playlistmodel.h @@ -97,6 +97,7 @@ private: Tomahawk::playlist_ptr m_playlist; bool m_isTemporary; bool m_changesOngoing; + bool m_isLoading; QList< Tomahawk::Query* > m_waitingForResolved; QStringList m_waitForRevision; diff --git a/src/libtomahawk/utils/xspfloader.cpp b/src/libtomahawk/utils/xspfloader.cpp index 0dd5da753..9ddff2779 100644 --- a/src/libtomahawk/utils/xspfloader.cpp +++ b/src/libtomahawk/utils/xspfloader.cpp @@ -262,7 +262,6 @@ XSPFLoader::gotBody() m_entries ); // 10 minute default---for now, no way to change it - connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) ); new Tomahawk::XspfUpdater( m_playlist, 6000000, m_autoUpdate, m_url.toString() ); emit ok( m_playlist ); }