1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-12 00:54:20 +02:00

Add a 'Add to Playlist' entry to the ContextMenu

This commit is contained in:
Uwe L. Korn
2013-03-24 02:35:46 +01:00
parent f3b04a01e2
commit e29fa20cf4
2 changed files with 32 additions and 2 deletions

View File

@@ -27,6 +27,7 @@
#include "Result.h" #include "Result.h"
#include "collection/Collection.h" #include "collection/Collection.h"
#include "Source.h" #include "Source.h"
#include "SourceList.h"
#include "Artist.h" #include "Artist.h"
#include "Album.h" #include "Album.h"
@@ -43,7 +44,7 @@ ContextMenu::ContextMenu( QWidget* parent )
m_sigmap = new QSignalMapper( this ); m_sigmap = new QSignalMapper( this );
connect( m_sigmap, SIGNAL( mapped( int ) ), SLOT( onTriggered( int ) ) ); 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 void
ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries ) ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries )
{ {
@@ -86,6 +95,23 @@ ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries )
if ( m_supportedActions & ActionQueue ) if ( m_supportedActions & ActionQueue )
m_sigmap->setMapping( addAction( tr( "Add to &Queue" ) ), 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 ( m_supportedActions & ActionStopAfter && itemCount() == 1 )
{ {
if ( AudioEngine::instance()->stopAfterTrack() == queries.first() ) if ( AudioEngine::instance()->stopAfterTrack() == queries.first() )

View File

@@ -46,7 +46,8 @@ public:
ActionTrackPage = 65, ActionTrackPage = 65,
ActionArtistPage = 66, ActionArtistPage = 66,
ActionAlbumPage = 67, ActionAlbumPage = 67,
ActionEditMetadata = 128 ActionEditMetadata = 128,
ActionPlaylist = 256
}; };
explicit ContextMenu( QWidget* parent = 0 ); explicit ContextMenu( QWidget* parent = 0 );
@@ -78,15 +79,18 @@ private slots:
void copyLink(); void copyLink();
void openPage( MenuActions action ); void openPage( MenuActions action );
void addToQueue(); void addToQueue();
void addToPlaylist( int playlistIdx );
void onSocialActionsLoaded(); void onSocialActionsLoaded();
private: private:
QSignalMapper* m_sigmap; QSignalMapper* m_sigmap;
QSignalMapper* m_playlists_sigmap;
int m_supportedActions; int m_supportedActions;
QAction* m_loveAction; QAction* m_loveAction;
QList< Tomahawk::playlist_ptr > m_playlists;
QList< Tomahawk::query_ptr > m_queries; QList< Tomahawk::query_ptr > m_queries;
QList< Tomahawk::artist_ptr > m_artists; QList< Tomahawk::artist_ptr > m_artists;
QList< Tomahawk::album_ptr > m_albums; QList< Tomahawk::album_ptr > m_albums;