mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 15:59:42 +01:00
Send tracks via context menu.
This commit is contained in:
parent
f66f3b94af
commit
3ba9ee9779
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -39,12 +40,14 @@ using namespace Tomahawk;
|
||||
|
||||
ContextMenu::ContextMenu( QWidget* parent )
|
||||
: QMenu( parent )
|
||||
, m_playlists_sigmap( 0 )
|
||||
, m_sources_sigmap( 0 )
|
||||
, m_loveAction( 0 )
|
||||
{
|
||||
m_sigmap = new QSignalMapper( this );
|
||||
connect( m_sigmap, SIGNAL( mapped( int ) ), SLOT( onTriggered( int ) ) );
|
||||
|
||||
m_supportedActions = ActionPlay | ActionQueue | ActionPlaylist | ActionCopyLink | ActionLove | ActionStopAfter | ActionPage | ActionEditMetadata;
|
||||
m_supportedActions = ActionPlay | ActionQueue | ActionPlaylist | ActionCopyLink | ActionLove | ActionStopAfter | ActionPage | ActionEditMetadata | ActionSend;
|
||||
}
|
||||
|
||||
|
||||
@ -79,13 +82,31 @@ ContextMenu::addToPlaylist( int playlistIdx )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::sendToSource( int sourceIdx )
|
||||
{
|
||||
const Tomahawk::source_ptr &src = m_sources.at( sourceIdx );
|
||||
foreach ( Tomahawk::query_ptr query, m_queries )
|
||||
{
|
||||
query->queryTrack()->share( src );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
caseInsensitiveLessThan( Tomahawk::playlist_ptr &s1, Tomahawk::playlist_ptr &s2 )
|
||||
playlistsLessThan( const Tomahawk::playlist_ptr& s1, const Tomahawk::playlist_ptr& s2 )
|
||||
{
|
||||
return s1->title().toLower() < s2->title().toLower();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
sourcesLessThan( const Tomahawk::source_ptr& s1, const Tomahawk::source_ptr& s2 )
|
||||
{
|
||||
return s1->friendlyName().toLower() < s2->friendlyName().toLower();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries )
|
||||
{
|
||||
@ -107,21 +128,44 @@ ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries )
|
||||
// Get the current list of all playlists.
|
||||
m_playlists = QList< Tomahawk::playlist_ptr >( SourceList::instance()->getLocal()->dbCollection()->playlists() );
|
||||
// Sort the playlist
|
||||
qSort( m_playlists.begin(), m_playlists.end(), caseInsensitiveLessThan );
|
||||
qSort( m_playlists.begin(), m_playlists.end(), playlistsLessThan );
|
||||
if ( m_playlists_sigmap != 0 )
|
||||
m_playlists_sigmap->deleteLater();
|
||||
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 );
|
||||
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( action, SIGNAL( triggered() ), m_playlists_sigmap, SLOT( map() ) );
|
||||
}
|
||||
connect( m_playlists_sigmap, SIGNAL( mapped( int ) ), this, SLOT( addToPlaylist( int ) ) );
|
||||
}
|
||||
|
||||
if ( m_supportedActions & ActionSend ) //Send to someone's Inbox!
|
||||
{
|
||||
// Get the buddies list
|
||||
m_sources = SourceList::instance()->sources( true );
|
||||
qSort( m_sources.begin(), m_sources.end(), sourcesLessThan );
|
||||
|
||||
if ( m_sources_sigmap != 0 )
|
||||
m_sources_sigmap->deleteLater();
|
||||
m_sources_sigmap = new QSignalMapper( this );
|
||||
|
||||
QMenu* sourcesMenu = addMenu( tr( "Send to &Friend" ) );
|
||||
for ( int i = 0; i < m_sources.length(); ++i )
|
||||
{
|
||||
QAction* action = new QAction( m_sources.at( i )->friendlyName(), this );
|
||||
sourcesMenu->addAction( action );
|
||||
m_sources_sigmap->setMapping( action, i );
|
||||
connect( action, SIGNAL( triggered() ), m_sources_sigmap, SLOT( map() ) );
|
||||
}
|
||||
connect( m_sources_sigmap, SIGNAL( mapped( int ) ), this, SLOT( sendToSource( int ) ) );
|
||||
}
|
||||
|
||||
if ( m_supportedActions & ActionStopAfter && itemCount() == 1 )
|
||||
{
|
||||
if ( AudioEngine::instance()->stopAfterTrack() == queries.first() )
|
||||
|
@ -2,6 +2,7 @@
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -36,18 +37,19 @@ Q_OBJECT
|
||||
public:
|
||||
enum MenuActions
|
||||
{
|
||||
ActionPlay = 1,
|
||||
ActionQueue = 2,
|
||||
ActionDelete = 4,
|
||||
ActionCopyLink = 8,
|
||||
ActionLove = 16,
|
||||
ActionStopAfter = 32,
|
||||
ActionPage = 64,
|
||||
ActionTrackPage = 65,
|
||||
ActionArtistPage = 66,
|
||||
ActionAlbumPage = 67,
|
||||
ActionEditMetadata = 128,
|
||||
ActionPlaylist = 256
|
||||
ActionPlay = 1,
|
||||
ActionQueue = 2,
|
||||
ActionDelete = 4,
|
||||
ActionCopyLink = 8,
|
||||
ActionLove = 16,
|
||||
ActionStopAfter = 32,
|
||||
ActionPage = 64,
|
||||
ActionTrackPage = 65,
|
||||
ActionArtistPage = 66,
|
||||
ActionAlbumPage = 67,
|
||||
ActionEditMetadata = 128,
|
||||
ActionPlaylist = 256,
|
||||
ActionSend = 512
|
||||
};
|
||||
|
||||
explicit ContextMenu( QWidget* parent = 0 );
|
||||
@ -80,12 +82,14 @@ private slots:
|
||||
void openPage( MenuActions action );
|
||||
void addToQueue();
|
||||
void addToPlaylist( int playlistIdx );
|
||||
void sendToSource( int sourceIdx );
|
||||
|
||||
void onSocialActionsLoaded();
|
||||
|
||||
private:
|
||||
QSignalMapper* m_sigmap;
|
||||
QSignalMapper* m_playlists_sigmap;
|
||||
QSignalMapper* m_sources_sigmap;
|
||||
int m_supportedActions;
|
||||
|
||||
QAction* m_loveAction;
|
||||
@ -94,6 +98,7 @@ private:
|
||||
QList< Tomahawk::query_ptr > m_queries;
|
||||
QList< Tomahawk::artist_ptr > m_artists;
|
||||
QList< Tomahawk::album_ptr > m_albums;
|
||||
QList< Tomahawk::source_ptr > m_sources;
|
||||
|
||||
Tomahawk::playlistinterface_ptr m_interface;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user