mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Send tracks via context menu.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@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
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -39,12 +40,14 @@ using namespace Tomahawk;
|
|||||||
|
|
||||||
ContextMenu::ContextMenu( QWidget* parent )
|
ContextMenu::ContextMenu( QWidget* parent )
|
||||||
: QMenu( parent )
|
: QMenu( parent )
|
||||||
|
, m_playlists_sigmap( 0 )
|
||||||
|
, m_sources_sigmap( 0 )
|
||||||
, m_loveAction( 0 )
|
, m_loveAction( 0 )
|
||||||
{
|
{
|
||||||
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 | 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
|
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();
|
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
|
void
|
||||||
ContextMenu::setQueries( const QList<Tomahawk::query_ptr>& queries )
|
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.
|
// Get the current list of all playlists.
|
||||||
m_playlists = QList< Tomahawk::playlist_ptr >( SourceList::instance()->getLocal()->dbCollection()->playlists() );
|
m_playlists = QList< Tomahawk::playlist_ptr >( SourceList::instance()->getLocal()->dbCollection()->playlists() );
|
||||||
// Sort the playlist
|
// 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 );
|
m_playlists_sigmap = new QSignalMapper( this );
|
||||||
|
|
||||||
// Build the menu listing all available playlists
|
// Build the menu listing all available playlists
|
||||||
QMenu* playlistMenu = addMenu( tr( "Add to &Playlist" ) );
|
QMenu* playlistMenu = addMenu( tr( "Add to &Playlist" ) );
|
||||||
for ( int i = 0; i < m_playlists.length(); ++i )
|
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);
|
playlistMenu->addAction(action);
|
||||||
m_playlists_sigmap->setMapping( action, i );
|
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 ) ) );
|
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 ( m_supportedActions & ActionStopAfter && itemCount() == 1 )
|
||||||
{
|
{
|
||||||
if ( AudioEngine::instance()->stopAfterTrack() == queries.first() )
|
if ( AudioEngine::instance()->stopAfterTrack() == queries.first() )
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||||
* Copyright 2010-2011, Jeff Mitchell <jeff@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
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -36,18 +37,19 @@ Q_OBJECT
|
|||||||
public:
|
public:
|
||||||
enum MenuActions
|
enum MenuActions
|
||||||
{
|
{
|
||||||
ActionPlay = 1,
|
ActionPlay = 1,
|
||||||
ActionQueue = 2,
|
ActionQueue = 2,
|
||||||
ActionDelete = 4,
|
ActionDelete = 4,
|
||||||
ActionCopyLink = 8,
|
ActionCopyLink = 8,
|
||||||
ActionLove = 16,
|
ActionLove = 16,
|
||||||
ActionStopAfter = 32,
|
ActionStopAfter = 32,
|
||||||
ActionPage = 64,
|
ActionPage = 64,
|
||||||
ActionTrackPage = 65,
|
ActionTrackPage = 65,
|
||||||
ActionArtistPage = 66,
|
ActionArtistPage = 66,
|
||||||
ActionAlbumPage = 67,
|
ActionAlbumPage = 67,
|
||||||
ActionEditMetadata = 128,
|
ActionEditMetadata = 128,
|
||||||
ActionPlaylist = 256
|
ActionPlaylist = 256,
|
||||||
|
ActionSend = 512
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit ContextMenu( QWidget* parent = 0 );
|
explicit ContextMenu( QWidget* parent = 0 );
|
||||||
@@ -80,12 +82,14 @@ private slots:
|
|||||||
void openPage( MenuActions action );
|
void openPage( MenuActions action );
|
||||||
void addToQueue();
|
void addToQueue();
|
||||||
void addToPlaylist( int playlistIdx );
|
void addToPlaylist( int playlistIdx );
|
||||||
|
void sendToSource( int sourceIdx );
|
||||||
|
|
||||||
void onSocialActionsLoaded();
|
void onSocialActionsLoaded();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSignalMapper* m_sigmap;
|
QSignalMapper* m_sigmap;
|
||||||
QSignalMapper* m_playlists_sigmap;
|
QSignalMapper* m_playlists_sigmap;
|
||||||
|
QSignalMapper* m_sources_sigmap;
|
||||||
int m_supportedActions;
|
int m_supportedActions;
|
||||||
|
|
||||||
QAction* m_loveAction;
|
QAction* m_loveAction;
|
||||||
@@ -94,6 +98,7 @@ private:
|
|||||||
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;
|
||||||
|
QList< Tomahawk::source_ptr > m_sources;
|
||||||
|
|
||||||
Tomahawk::playlistinterface_ptr m_interface;
|
Tomahawk::playlistinterface_ptr m_interface;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user