mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
add Open command to url handling
This commit is contained in:
@@ -89,7 +89,9 @@ GlobalActionManager::parseTomahawkLink( const QString& url )
|
|||||||
} else if( cmdType == "play" ) {
|
} else if( cmdType == "play" ) {
|
||||||
return handlePlayCommand( u );
|
return handlePlayCommand( u );
|
||||||
} else if( cmdType == "bookmark" ) {
|
} else if( cmdType == "bookmark" ) {
|
||||||
return handleBookmarkCommand( u );
|
return handlePlayCommand( u );
|
||||||
|
} else if( cmdType == "open" ) {
|
||||||
|
return handleOpenCommand( u );
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Tomahawk link not supported, command not known!" << cmdType << u.path();
|
qDebug() << "Tomahawk link not supported, command not known!" << cmdType << u.path();
|
||||||
return false;
|
return false;
|
||||||
@@ -130,7 +132,7 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
|
|||||||
pl->createNewRevision( uuid(), pl->currentrevision(), QList< Tomahawk::plentry_ptr >() );
|
pl->createNewRevision( uuid(), pl->currentrevision(), QList< Tomahawk::plentry_ptr >() );
|
||||||
ViewManager::instance()->show( pl );
|
ViewManager::instance()->show( pl );
|
||||||
} else if( parts[ 0 ] == "add" ) {
|
} else if( parts[ 0 ] == "add" ) {
|
||||||
if( !url.hasQueryItem( "playlistid" ) || !url.hasQueryItem( "track" ) || !url.hasQueryItem( "artist" ) ) {
|
if( !url.hasQueryItem( "playlistid" ) || !url.hasQueryItem( "title" ) || !url.hasQueryItem( "artist" ) ) {
|
||||||
qDebug() << "Add to playlist command needs playlistid, track, and artist..." << url.toString();
|
qDebug() << "Add to playlist command needs playlistid, track, and artist..." << url.toString();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -157,6 +159,19 @@ GlobalActionManager::handleCollectionCommand( const QUrl& url )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
GlobalActionManager::handleOpenCommand(const QUrl& url)
|
||||||
|
{
|
||||||
|
QStringList parts = url.path().split( "/" ).mid( 1 );
|
||||||
|
if( parts.isEmpty() ) {
|
||||||
|
qDebug() << "No specific type to open:" << url.toString();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// TODO user configurable in the UI
|
||||||
|
return doQueueAdd( parts, url.queryItems() );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
GlobalActionManager::handleQueueCommand( const QUrl& url )
|
GlobalActionManager::handleQueueCommand( const QUrl& url )
|
||||||
{
|
{
|
||||||
@@ -167,12 +182,24 @@ GlobalActionManager::handleQueueCommand( const QUrl& url )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( parts[ 0 ] == "add" ) {
|
if( parts[ 0 ] == "add" ) {
|
||||||
if( parts.size() > 1 && parts[ 1 ] == "track" ) {
|
doQueueAdd( parts.mid( 1 ), url.queryItems() );
|
||||||
|
} else {
|
||||||
|
qDebug() << "Only queue/add/track is support at the moment, got:" << parts;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
GlobalActionManager::doQueueAdd( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems )
|
||||||
|
{
|
||||||
|
if( parts.size() && parts[ 0 ] == "track" ) {
|
||||||
QPair< QString, QString > pair;
|
QPair< QString, QString > pair;
|
||||||
|
|
||||||
QString title, artist, album, urlStr;
|
QString title, artist, album, urlStr;
|
||||||
foreach( pair, url.queryItems() ) {
|
foreach( pair, queryItems ) {
|
||||||
if( pair.first == "track" )
|
if( pair.first == "title" )
|
||||||
title = pair.second;
|
title = pair.second;
|
||||||
else if( pair.first == "artist" )
|
else if( pair.first == "artist" )
|
||||||
artist = pair.second;
|
artist = pair.second;
|
||||||
@@ -181,12 +208,16 @@ GlobalActionManager::handleQueueCommand( const QUrl& url )
|
|||||||
else if( pair.first == "url" )
|
else if( pair.first == "url" )
|
||||||
urlStr = pair.second;
|
urlStr = pair.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !title.isEmpty() || !artist.isEmpty() || !album.isEmpty() ) { // an individual; query to add to queue
|
if( !title.isEmpty() || !artist.isEmpty() || !album.isEmpty() ) { // an individual; query to add to queue
|
||||||
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album );
|
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, title, album );
|
||||||
if( !urlStr.isEmpty() )
|
if( !urlStr.isEmpty() )
|
||||||
q->setResultHint( urlStr );
|
q->setResultHint( urlStr );
|
||||||
Tomahawk::Pipeline::instance()->resolve( q, true );
|
Tomahawk::Pipeline::instance()->resolve( q, true );
|
||||||
|
|
||||||
|
ViewManager::instance()->queue()->model()->append( q );
|
||||||
|
ViewManager::instance()->showQueue();
|
||||||
|
|
||||||
if( !AudioEngine::instance()->isPlaying() ) {
|
if( !AudioEngine::instance()->isPlaying() ) {
|
||||||
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( waitingForResolved( bool ) ) );
|
connect( q.data(), SIGNAL( resolvingFinished( bool ) ), this, SLOT( waitingForResolved( bool ) ) );
|
||||||
m_waitingToPlay = q;
|
m_waitingToPlay = q;
|
||||||
@@ -194,7 +225,7 @@ GlobalActionManager::handleQueueCommand( const QUrl& url )
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else { // a list of urls to add to the queue
|
} else { // a list of urls to add to the queue
|
||||||
foreach( pair, url.queryItems() ) {
|
foreach( pair, queryItems ) {
|
||||||
if( pair.first != "url" )
|
if( pair.first != "url" )
|
||||||
continue;
|
continue;
|
||||||
QUrl track = QUrl::fromUserInput( pair.second );
|
QUrl track = QUrl::fromUserInput( pair.second );
|
||||||
@@ -213,12 +244,7 @@ GlobalActionManager::handleQueueCommand( const QUrl& url )
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
qDebug() << "Only queue/add/track is support at the moment, got:" << parts;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,8 +257,8 @@ GlobalActionManager::handleSearchCommand( const QUrl& url )
|
|||||||
query << url.queryItemValue( "artist" );
|
query << url.queryItemValue( "artist" );
|
||||||
if( url.hasQueryItem( "album" ) )
|
if( url.hasQueryItem( "album" ) )
|
||||||
query << url.queryItemValue( "album" );
|
query << url.queryItemValue( "album" );
|
||||||
if( url.hasQueryItem( "track" ) )
|
if( url.hasQueryItem( "title" ) )
|
||||||
query << url.queryItemValue( "track" );
|
query << url.queryItemValue( "title" );
|
||||||
QString queryStr = query.join( " " );
|
QString queryStr = query.join( " " );
|
||||||
|
|
||||||
if( queryStr.isEmpty() )
|
if( queryStr.isEmpty() )
|
||||||
@@ -295,7 +321,7 @@ GlobalActionManager::handlePlayCommand( const QUrl& url )
|
|||||||
QPair< QString, QString > pair;
|
QPair< QString, QString > pair;
|
||||||
QString title, artist, album, urlStr;
|
QString title, artist, album, urlStr;
|
||||||
foreach( pair, url.queryItems() ) {
|
foreach( pair, url.queryItems() ) {
|
||||||
if( pair.first == "track" )
|
if( pair.first == "title" )
|
||||||
title = pair.second;
|
title = pair.second;
|
||||||
else if( pair.first == "artist" )
|
else if( pair.first == "artist" )
|
||||||
artist = pair.second;
|
artist = pair.second;
|
||||||
@@ -330,7 +356,7 @@ bool GlobalActionManager::handleBookmarkCommand(const QUrl& url)
|
|||||||
QPair< QString, QString > pair;
|
QPair< QString, QString > pair;
|
||||||
QString title, artist, album, urlStr;
|
QString title, artist, album, urlStr;
|
||||||
foreach( pair, url.queryItems() ) {
|
foreach( pair, url.queryItems() ) {
|
||||||
if( pair.first == "track" )
|
if( pair.first == "title" )
|
||||||
title = pair.second;
|
title = pair.second;
|
||||||
else if( pair.first == "artist" )
|
else if( pair.first == "artist" )
|
||||||
artist = pair.second;
|
artist = pair.second;
|
||||||
@@ -408,7 +434,8 @@ void
|
|||||||
GlobalActionManager::waitingForResolved( bool success )
|
GlobalActionManager::waitingForResolved( bool success )
|
||||||
{
|
{
|
||||||
if( success && !m_waitingToPlay.isNull() && !m_waitingToPlay->results().isEmpty() ) { // play it!
|
if( success && !m_waitingToPlay.isNull() && !m_waitingToPlay->results().isEmpty() ) { // play it!
|
||||||
AudioEngine::instance()->playItem( AudioEngine::instance()->playlist(), m_waitingToPlay->results().first() );
|
// AudioEngine::instance()->playItem( AudioEngine::instance()->playlist(), m_waitingToPlay->results().first() );
|
||||||
|
AudioEngine::instance()->play();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_waitingToPlay.clear();
|
m_waitingToPlay.clear();
|
||||||
|
@@ -51,6 +51,9 @@ private:
|
|||||||
bool handleSearchCommand(const QUrl& url );
|
bool handleSearchCommand(const QUrl& url );
|
||||||
bool handlePlayCommand(const QUrl& url );
|
bool handlePlayCommand(const QUrl& url );
|
||||||
bool handleBookmarkCommand(const QUrl& url );
|
bool handleBookmarkCommand(const QUrl& url );
|
||||||
|
bool handleOpenCommand(const QUrl& url );
|
||||||
|
|
||||||
|
bool doQueueAdd( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems );
|
||||||
|
|
||||||
Tomahawk::playlist_ptr m_toShow;
|
Tomahawk::playlist_ptr m_toShow;
|
||||||
Tomahawk::query_ptr m_waitingToBookmark;
|
Tomahawk::query_ptr m_waitingToBookmark;
|
||||||
|
Reference in New Issue
Block a user