From 570171bddd311b0c39f9e5faa57367dd3355646c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Lindstr=C3=B6m?= Date: Sat, 7 Apr 2012 10:23:40 +0200 Subject: [PATCH] emit rename signal and update spotify playlistname --- src/accounts/spotify/SpotifyAccount.cpp | 2 +- src/accounts/spotify/SpotifyPlaylistUpdater.cpp | 14 ++++++++++++++ src/accounts/spotify/SpotifyPlaylistUpdater.h | 2 +- src/libtomahawk/playlist.cpp | 12 ++++++++++++ src/libtomahawk/playlist.h | 3 ++- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/accounts/spotify/SpotifyAccount.cpp b/src/accounts/spotify/SpotifyAccount.cpp index 599d33833..5389b8e28 100644 --- a/src/accounts/spotify/SpotifyAccount.cpp +++ b/src/accounts/spotify/SpotifyAccount.cpp @@ -220,7 +220,7 @@ SpotifyAccount::resolverMessage( const QString &msgType, const QVariantMap &msg { const QString plid = msg.value( "id" ).toString(); // We should already be syncing this playlist if we get updates for it - Q_ASSERT( m_updaters.contains( plid ) ); + //Q_ASSERT( m_updaters.contains( plid ) ); qDebug() << Q_FUNC_INFO; if ( !m_updaters.contains( plid ) ) diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp index 29bfbeec7..f959d49f8 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.cpp +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.cpp @@ -84,6 +84,7 @@ SpotifyPlaylistUpdater::init() connect( playlist().data(), SIGNAL( tracksInserted( QList, int ) ), this, SLOT( tomahawkTracksInserted( QList, int ) ) ); connect( playlist().data(), SIGNAL( tracksRemoved( QList ) ), this, SLOT( tomahawkTracksRemoved( QList ) ) ); + connect( playlist().data(), SIGNAL( renamed(const QString&, const QString& ) ), this, SLOT( tomahawkPlaylistRenamed( const QString&, const QString& ) ) ); // TODO reorders in a playlist } @@ -231,6 +232,19 @@ SpotifyPlaylistUpdater::spotifyPlaylistRenamed( const QString title, const QStri } +void +SpotifyPlaylistUpdater::tomahawkPlaylistRenamed(const QString &newT, const QString &oldT) +{ + qDebug() << Q_FUNC_INFO; + QVariantMap msg; + msg[ "_msgtype" ] = "playlistRenamed"; + msg[ "oldrev" ] = m_latestRev; + msg[ "newTitle" ] = newT; + msg[ "oldTitle" ] = oldT; + msg[ "playlistid" ] = m_spotifyId; + m_spotify.data()->sendMessage( msg, this, "onPlaylistRename" ); +} + void SpotifyPlaylistUpdater::spotifyTracksMoved( const QVariantList& tracks, const QString& newRev, const QString& oldRev ) { diff --git a/src/accounts/spotify/SpotifyPlaylistUpdater.h b/src/accounts/spotify/SpotifyPlaylistUpdater.h index f8cb7fb47..44012909e 100644 --- a/src/accounts/spotify/SpotifyPlaylistUpdater.h +++ b/src/accounts/spotify/SpotifyPlaylistUpdater.h @@ -61,7 +61,7 @@ protected: private slots: void tomahawkTracksInserted( const QList& ,int ); void tomahawkTracksRemoved( const QList& ); - + void tomahawkPlaylistRenamed( const QString&, const QString&); // SpotifyResolver message handlers, all take msgtype, msg as argument void onTracksInsertedReturn( const QString& msgType, const QVariantMap& msg ); void onTracksRemovedReturn( const QString& msgType, const QVariantMap& msg ); diff --git a/src/libtomahawk/playlist.cpp b/src/libtomahawk/playlist.cpp index 298f2f278..45465bac1 100644 --- a/src/libtomahawk/playlist.cpp +++ b/src/libtomahawk/playlist.cpp @@ -248,6 +248,18 @@ Playlist::rename( const QString& title ) Database::instance()->enqueue( QSharedPointer(cmd) ); } +void +Playlist::setTitle( const QString& title ) +{ + if( title == m_title ) + return; + + const QString oldTitle = m_title; + const QString newTitle = title; + m_title = title; + emit changed(); + emit renamed( newTitle, oldTitle ); +} void Playlist::reportCreated( const playlist_ptr& self ) diff --git a/src/libtomahawk/playlist.h b/src/libtomahawk/playlist.h index fb9cddd8f..f8479144a 100644 --- a/src/libtomahawk/playlist.h +++ b/src/libtomahawk/playlist.h @@ -178,12 +178,12 @@ public: // maybe friend QObjectHelper and make them private? explicit Playlist( const source_ptr& author ); void setCurrentrevision( const QString& s ) { m_currentrevision = s; } - void setTitle( const QString& s ) { m_title = s; emit changed(); } void setInfo( const QString& s ) { m_info = s; } void setCreator( const QString& s ) { m_creator = s; } void setGuid( const QString& s ) { m_guid = s; } void setShared( bool b ) { m_shared = b; } void setCreatedOn( uint createdOn ) { m_createdOn = createdOn; } + void setTitle( const QString& s ); // @@ -202,6 +202,7 @@ signals: /// renamed etc. void changed(); + void renamed( const QString&, const QString& ); /** * delete command is scheduled but not completed. Do not call remove() again once this