From c1a7c63f036320353e22fd2dcdd0def94134fa3f Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Thu, 12 Apr 2012 09:09:09 -0400 Subject: [PATCH] Ask to delete a playlist on spotify side when deleting a synced playlist --- src/accounts/spotify/SpotifyAccount.cpp | 10 +++--- .../spotify/SpotifyPlaylistUpdater.cpp | 31 +++++++++++++++++++ src/accounts/spotify/SpotifyPlaylistUpdater.h | 2 ++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/accounts/spotify/SpotifyAccount.cpp b/src/accounts/spotify/SpotifyAccount.cpp index 66acc6ffd..989917f1c 100644 --- a/src/accounts/spotify/SpotifyAccount.cpp +++ b/src/accounts/spotify/SpotifyAccount.cpp @@ -182,14 +182,14 @@ SpotifyAccount::syncActionTriggered( bool checked ) } Q_ASSERT( info ); + if ( info ) + info->sync = !updater->sync(); + + if ( m_configWidget.data() ) + m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists ); if ( !updater->sync() ) { - if ( info ) - info->sync = true; - if ( m_configWidget.data() ) - m_configWidget.data()->setPlaylists( m_allSpotifyPlaylists ); - startPlaylistSync( info ); } else diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp index 675cb6f07..8e9dd62b0 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp @@ -22,6 +22,8 @@ #include "SpotifyAccount.h" #include "utils/tomahawkutils.h" +#include + using namespace Tomahawk; using namespace Accounts; @@ -114,9 +116,38 @@ SpotifyPlaylistUpdater::removeFromSettings( const QString& group ) const TomahawkSettings::instance()->remove( QString( "%1/latestrev" ).arg( group ) ); TomahawkSettings::instance()->remove( QString( "%1/sync" ).arg( group ) ); TomahawkSettings::instance()->remove( QString( "%1/spotifyId" ).arg( group ) ); + + if ( m_sync ) + { + if ( QThread::currentThread() != QApplication::instance()->thread() ) + QMetaObject::invokeMethod( const_cast(this), "checkDeleteDialog", Qt::BlockingQueuedConnection ); + else + checkDeleteDialog(); + } } +void +SpotifyPlaylistUpdater::checkDeleteDialog() const +{ + // Ask if we should delete the playlist on the spotify side as well + QMessageBox askDelete( QMessageBox::Question, tr( "Delete in Spotify?" ), tr( "Would you like to delete the corresponding Spotify playlist as well?" ), QMessageBox::Yes | QMessageBox::No, 0 ); + int ret = askDelete.exec(); + if ( ret == QMessageBox::Yes ) + { + if ( m_spotify.isNull() ) + return; + + // User wants to delete it! + QVariantMap msg; + msg[ "_msgtype" ] = "deletePlaylist"; + msg[ "playlistid" ] = m_spotifyId; + m_spotify.data()->sendMessage( msg ); + } +} + + + void SpotifyPlaylistUpdater::saveToSettings( const QString& group ) const { diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.h b/src/accounts/spotify/SpotifyPlaylistUpdater.h index e551fef56..211d003a5 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.h +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.h @@ -58,6 +58,7 @@ public: void spotifyTracksRemoved( const QVariantList& tracks, const QString& newRev, const QString& oldRev ); void spotifyTracksMoved( const QVariantList& tracks, const QString& newRev, const QString& oldRev ); void spotifyPlaylistRenamed( const QString& title, const QString& newRev, const QString& oldRev ); + protected: virtual void removeFromSettings(const QString& group) const; virtual void saveToSettings(const QString& group) const; @@ -70,6 +71,7 @@ private slots: void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg ); void onTracksRemovedReturn( const QString& msgType, const QVariantMap& msg ); + void checkDeleteDialog() const; private: void init();