From 60d6ec378975e9bf006b12464ddd6eb301d3976e Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 19 Dec 2013 13:26:49 +0100 Subject: [PATCH] Add support for tomahawk://love links. --- src/libtomahawk/GlobalActionManager.cpp | 36 +++++++++++++++++++++++++ src/libtomahawk/GlobalActionManager.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/libtomahawk/GlobalActionManager.cpp b/src/libtomahawk/GlobalActionManager.cpp index f33cfb3ca..810ca97f4 100644 --- a/src/libtomahawk/GlobalActionManager.cpp +++ b/src/libtomahawk/GlobalActionManager.cpp @@ -360,6 +360,10 @@ GlobalActionManager::parseTomahawkLink( const QString& urlIn ) { return handleImportCommand( u ); } + else if ( cmdType == "love" ) + { + return handleLoveCommand( u ); + } else { tLog() << "Tomahawk link not supported, command not known!" << cmdType << u.path(); @@ -526,6 +530,38 @@ GlobalActionManager::handleOpenCommand( const QUrl& url ) } +bool +GlobalActionManager::handleLoveCommand( const QUrl& url ) +{ + QStringList parts = url.path().split( "/" ).mid( 1 ); // get the rest of the command + if ( parts.isEmpty() ) + { + tLog() << "No specific love command:" << url.toString(); + return false; + } + + QPair< QString, QString > pair; + QString title, artist, album; + foreach ( pair, urlQueryItems( url ) ) + { + if ( pair.first == "title" ) + title = pair.second; + else if ( pair.first == "artist" ) + artist = pair.second; + else if ( pair.first == "album" ) + album = pair.second; + } + + track_ptr t = Track::get( artist, title, album ); + if ( t.isNull() ) + return false; + + t->setLoved( true ); + + return true; +} + + void GlobalActionManager::handleOpenTrack( const query_ptr& q ) { diff --git a/src/libtomahawk/GlobalActionManager.h b/src/libtomahawk/GlobalActionManager.h index 869d02f86..c7864d88a 100644 --- a/src/libtomahawk/GlobalActionManager.h +++ b/src/libtomahawk/GlobalActionManager.h @@ -118,6 +118,7 @@ private: bool handleCollectionCommand( const QUrl& url ); bool handlePlayCommand( const QUrl& url ); bool handleOpenCommand( const QUrl& url ); + bool handleLoveCommand( const QUrl& url ); void createPlaylistFromUrl( const QString& type, const QString& url, const QString& title );