diff --git a/src/libtomahawk/ContextMenu.cpp b/src/libtomahawk/ContextMenu.cpp index c67a63c51..668426cec 100644 --- a/src/libtomahawk/ContextMenu.cpp +++ b/src/libtomahawk/ContextMenu.cpp @@ -27,6 +27,7 @@ #include "Result.h" #include "collection/Collection.h" #include "Source.h" +#include "SourceList.h" #include "Artist.h" #include "Album.h" @@ -43,7 +44,7 @@ ContextMenu::ContextMenu( QWidget* parent ) m_sigmap = new QSignalMapper( this ); connect( m_sigmap, SIGNAL( mapped( int ) ), SLOT( onTriggered( int ) ) ); - m_supportedActions = ActionPlay | ActionQueue | ActionCopyLink | ActionLove | ActionStopAfter | ActionPage | ActionEditMetadata; + m_supportedActions = ActionPlay | ActionQueue | ActionPlaylist | ActionCopyLink | ActionLove | ActionStopAfter | ActionPage | ActionEditMetadata; } @@ -70,6 +71,14 @@ ContextMenu::itemCount() const } +void +ContextMenu::addToPlaylist( int playlistIdx ) +{ + Tomahawk::playlist_ptr playlist = m_playlists.at( playlistIdx ); + playlist->addEntries( m_queries, playlist->currentrevision() ); +} + + void ContextMenu::setQueries( const QList& queries ) { @@ -86,6 +95,23 @@ ContextMenu::setQueries( const QList& queries ) if ( m_supportedActions & ActionQueue ) m_sigmap->setMapping( addAction( tr( "Add to &Queue" ) ), ActionQueue ); + if ( m_supportedActions & ActionPlaylist ) { + // Get the current list of all playlists. + m_playlists = SourceList::instance()->getLocal()->dbCollection()->playlists(); + m_playlists_sigmap = new QSignalMapper( this ); + + // Build the menu listing all available playlists + QMenu* playlistMenu = addMenu( tr( "Add to &Playlist" ) ); + for ( int i = 0; i < m_playlists.length(); ++i ) + { + QAction* action = new QAction( m_playlists.at(i)->title() , this ); + playlistMenu->addAction(action); + m_playlists_sigmap->setMapping( action, i ); + connect( action, SIGNAL( triggered() ), m_playlists_sigmap, SLOT( map() )); + } + connect( m_playlists_sigmap, SIGNAL( mapped( int ) ), this, SLOT( addToPlaylist( int ) ) ); + } + if ( m_supportedActions & ActionStopAfter && itemCount() == 1 ) { if ( AudioEngine::instance()->stopAfterTrack() == queries.first() ) diff --git a/src/libtomahawk/ContextMenu.h b/src/libtomahawk/ContextMenu.h index 6844f04ee..19484669d 100644 --- a/src/libtomahawk/ContextMenu.h +++ b/src/libtomahawk/ContextMenu.h @@ -46,7 +46,8 @@ public: ActionTrackPage = 65, ActionArtistPage = 66, ActionAlbumPage = 67, - ActionEditMetadata = 128 + ActionEditMetadata = 128, + ActionPlaylist = 256 }; explicit ContextMenu( QWidget* parent = 0 ); @@ -78,15 +79,18 @@ private slots: void copyLink(); void openPage( MenuActions action ); void addToQueue(); + void addToPlaylist( int playlistIdx ); void onSocialActionsLoaded(); private: QSignalMapper* m_sigmap; + QSignalMapper* m_playlists_sigmap; int m_supportedActions; QAction* m_loveAction; + QList< Tomahawk::playlist_ptr > m_playlists; QList< Tomahawk::query_ptr > m_queries; QList< Tomahawk::artist_ptr > m_artists; QList< Tomahawk::album_ptr > m_albums;