mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-22 16:59:58 +01:00
Add context menu item to create track links
This commit is contained in:
parent
aff34374cb
commit
aec8c97eac
@ -39,7 +39,6 @@ SET( tomahawkSources ${tomahawkSources}
|
||||
|
||||
musicscanner.cpp
|
||||
shortcuthandler.cpp
|
||||
globalactionmanager.cpp
|
||||
scanmanager.cpp
|
||||
tomahawkapp.cpp
|
||||
main.cpp
|
||||
@ -82,7 +81,6 @@ SET( tomahawkHeaders ${tomahawkHeaders}
|
||||
musicscanner.h
|
||||
scanmanager.h
|
||||
shortcuthandler.h
|
||||
globalactionmanager.h
|
||||
)
|
||||
|
||||
IF(LIBLASTFM_FOUND)
|
||||
|
@ -29,6 +29,7 @@ set( libSources
|
||||
source.cpp
|
||||
viewpage.cpp
|
||||
viewmanager.cpp
|
||||
globalactionmanager.cpp
|
||||
|
||||
sip/SipPlugin.cpp
|
||||
sip/SipHandler.cpp
|
||||
@ -183,6 +184,7 @@ set( libHeaders
|
||||
source.h
|
||||
viewpage.h
|
||||
viewmanager.h
|
||||
globalactionmanager.h
|
||||
|
||||
artist.h
|
||||
album.h
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
#include <QUrl>
|
||||
#include <Playlist.h>
|
||||
#include <qclipboard.h>
|
||||
#include <qapplication.h>
|
||||
|
||||
GlobalActionManager* GlobalActionManager::s_instance = 0;
|
||||
|
||||
@ -53,6 +55,28 @@ GlobalActionManager::GlobalActionManager( QObject* parent )
|
||||
GlobalActionManager::~GlobalActionManager()
|
||||
{}
|
||||
|
||||
QUrl
|
||||
GlobalActionManager::openLinkFromQuery( const Tomahawk::query_ptr& query ) const
|
||||
{
|
||||
QUrl link( "tomahawk://open/track/" );
|
||||
if( !query->track().isEmpty() )
|
||||
link.addQueryItem( "title", query->track() );
|
||||
if( !query->artist().isEmpty() )
|
||||
link.addQueryItem( "artist", query->artist() );
|
||||
if( !query->album().isEmpty() )
|
||||
link.addQueryItem( "album", query->album() );
|
||||
|
||||
return link;
|
||||
}
|
||||
|
||||
void
|
||||
GlobalActionManager::copyToClipboard( const Tomahawk::query_ptr& query ) const
|
||||
{
|
||||
QClipboard* cb = QApplication::clipboard();
|
||||
cb->setText( openLinkFromQuery( query ).toEncoded() );
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GlobalActionManager::parseTomahawkLink( const QString& url )
|
||||
{
|
@ -21,17 +21,21 @@
|
||||
#define GLOBALACTIONMANAGER_H
|
||||
|
||||
#include "playlist.h"
|
||||
#include "dllmacro.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QUrl>
|
||||
|
||||
class GlobalActionManager : public QObject
|
||||
class DLLEXPORT GlobalActionManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static GlobalActionManager* instance();
|
||||
virtual ~GlobalActionManager();
|
||||
|
||||
QUrl openLinkFromQuery( const Tomahawk::query_ptr& query ) const;
|
||||
void copyToClipboard( const Tomahawk::query_ptr& query ) const;
|
||||
|
||||
public slots:
|
||||
bool parseTomahawkLink( const QString& link );
|
||||
void waitingForResolved( bool );
|
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
@ -83,7 +83,10 @@ CollectionView::setupMenus()
|
||||
|
||||
m_playItemAction = m_itemMenu.addAction( tr( "&Play" ) );
|
||||
m_addItemsToQueueAction = m_itemMenu.addAction( tr( "Add to &Queue" ) );
|
||||
// m_itemMenu.addSeparator();
|
||||
m_itemMenu.addSeparator();
|
||||
|
||||
foreach( QAction* a, actions() )
|
||||
m_itemMenu.addAction( a );
|
||||
// m_addItemsToPlaylistAction = m_itemMenu.addAction( tr( "&Add to Playlist" ) );
|
||||
|
||||
connect( m_playItemAction, SIGNAL( triggered() ), SLOT( playItem() ) );
|
||||
|
@ -30,6 +30,12 @@ using namespace Tomahawk;
|
||||
|
||||
PlaylistView::PlaylistView( QWidget* parent )
|
||||
: TrackView( parent )
|
||||
, m_model( 0 )
|
||||
, m_itemMenu( 0 )
|
||||
, m_playItemAction( 0 )
|
||||
, m_addItemsToQueueAction( 0 )
|
||||
, m_addItemsToPlaylistAction( 0 )
|
||||
, m_deleteItemsAction( 0 )
|
||||
{
|
||||
setProxyModel( new PlaylistProxyModel( this ) );
|
||||
|
||||
@ -84,6 +90,9 @@ PlaylistView::setupMenus()
|
||||
m_playItemAction = m_itemMenu.addAction( tr( "&Play" ) );
|
||||
m_addItemsToQueueAction = m_itemMenu.addAction( tr( "Add to &Queue" ) );
|
||||
m_itemMenu.addSeparator();
|
||||
|
||||
foreach( QAction* a, actions() )
|
||||
m_itemMenu.addAction( a );
|
||||
// m_addItemsToPlaylistAction = m_itemMenu.addAction( tr( "&Add to Playlist" ) );
|
||||
// m_itemMenu.addSeparator();
|
||||
m_deleteItemsAction = m_itemMenu.addAction( i > 1 ? tr( "&Delete Items" ) : tr( "&Delete Item" ) );
|
||||
@ -144,7 +153,6 @@ PlaylistView::deleteItems()
|
||||
proxyModel()->removeIndexes( selectedIndexes() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistView::onTrackCountChanged( unsigned int tracks )
|
||||
{
|
||||
|
@ -65,7 +65,6 @@ private slots:
|
||||
void deleteItems();
|
||||
|
||||
void onDeleted();
|
||||
|
||||
private:
|
||||
void setupMenus();
|
||||
|
||||
|
@ -33,7 +33,8 @@
|
||||
#include "queueview.h"
|
||||
#include "trackmodel.h"
|
||||
#include "trackproxymodel.h"
|
||||
#include <track.h>
|
||||
#include "track.h"
|
||||
#include "globalactionmanager.h"
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -77,6 +78,10 @@ TrackView::TrackView( QWidget* parent )
|
||||
setFont( f );
|
||||
#endif
|
||||
|
||||
QAction* createLinkAction = new QAction( tr( "Copy track link" ), this );
|
||||
connect( createLinkAction, SIGNAL( triggered( bool ) ), this, SLOT( copyLink() ) );
|
||||
addAction( createLinkAction );
|
||||
|
||||
connect( this, SIGNAL( doubleClicked( QModelIndex ) ), SLOT( onItemActivated( QModelIndex ) ) );
|
||||
}
|
||||
|
||||
@ -173,7 +178,6 @@ TrackView::onItemResized( const QModelIndex& index )
|
||||
m_delegate->updateRowSize( index );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackView::playItem()
|
||||
{
|
||||
@ -341,6 +345,16 @@ TrackView::onFilterChanged( const QString& )
|
||||
m_overlay->hide();
|
||||
}
|
||||
|
||||
void
|
||||
TrackView::copyLink()
|
||||
{
|
||||
TrackModelItem* item = model()->itemFromIndex( proxyModel()->mapToSource( contextMenuIndex() ) );
|
||||
if ( item && !item->query().isNull() )
|
||||
{
|
||||
GlobalActionManager::instance()->copyToClipboard( item->query() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TrackView::startDrag( Qt::DropActions supportedActions )
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
*
|
||||
* Tomahawk is free software: you can redistribute it and/or modify
|
||||
@ -26,6 +26,7 @@
|
||||
|
||||
#include "dllmacro.h"
|
||||
|
||||
class QAction;
|
||||
class LoadingSpinner;
|
||||
class PlaylistInterface;
|
||||
class TrackHeader;
|
||||
@ -80,6 +81,7 @@ private slots:
|
||||
|
||||
void onFilterChanged( const QString& filter );
|
||||
|
||||
void copyLink();
|
||||
private:
|
||||
QString m_guid;
|
||||
TrackModel* m_model;
|
||||
|
Loading…
x
Reference in New Issue
Block a user