1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-01 03:40:16 +02:00

Make Tomahawk link handling cleaner and less hackish (lfranchi++). Move openLinkFromHash to GlobalActionManager, to keep Tomahawk link handling simple.

This commit is contained in:
Alejandro Wainzinger
2011-06-07 18:12:38 -07:00
parent 3ec9308916
commit b392151c56
5 changed files with 33 additions and 36 deletions

View File

@@ -60,7 +60,6 @@ GlobalActionManager::~GlobalActionManager()
QUrl QUrl
GlobalActionManager::openLinkFromQuery( const Tomahawk::query_ptr& query ) const GlobalActionManager::openLinkFromQuery( const Tomahawk::query_ptr& query ) const
{ {
QUrl link( "tomahawk://open/track/" );
QString title, artist, album; QString title, artist, album;
if( !query->results().isEmpty() && !query->results().first().isNull() ) if( !query->results().isEmpty() && !query->results().first().isNull() )
@@ -75,6 +74,30 @@ GlobalActionManager::openLinkFromQuery( const Tomahawk::query_ptr& query ) const
album = query->album(); album = query->album();
} }
return openLink( title, artist, album );
}
QUrl
GlobalActionManager::openLinkFromHash( const Tomahawk::InfoSystem::InfoCriteriaHash& hash ) const
{
QString title, artist, album;
if( !hash.isEmpty() && hash.contains( "title" ) && hash.contains( "artist" ) )
{
title = hash["title"];
artist = hash["artist"];
if( hash.contains( "album" ) )
album = hash["album"];
}
return openLink( title, artist, album );
}
QUrl
GlobalActionManager::openLink( const QString& title, const QString& artist, const QString& album ) const
{
QUrl link( "tomahawk://open/track/" );
if( !title.isEmpty() ) if( !title.isEmpty() )
link.addQueryItem( "title", title ); link.addQueryItem( "title", title );
if( !artist.isEmpty() ) if( !artist.isEmpty() )
@@ -165,13 +188,12 @@ GlobalActionManager::copyToClipboard( const Tomahawk::query_ptr& query ) const
bool bool
GlobalActionManager::parseTomahawkLink( const QString& url ) GlobalActionManager::parseTomahawkLink( const QString& url )
{ {
QString decodedUrl = QString::fromUtf8( QByteArray::fromPercentEncoding( url.toAscii() ).data() ); if( url.contains( "tomahawk://" ) ) {
if( decodedUrl.contains( "tomahawk://" ) ) { QString cmd = url.mid( 11 );
QString cmd = decodedUrl.mid( 11 );
qDebug() << "Parsing tomahawk link command" << cmd; qDebug() << "Parsing tomahawk link command" << cmd;
QString cmdType = cmd.split( "/" ).first(); QString cmdType = cmd.split( "/" ).first();
QUrl u( cmd ); QUrl u = QUrl::fromEncoded( cmd.toUtf8() );
// for backwards compatibility // for backwards compatibility
if( cmdType == "load" ) { if( cmdType == "load" ) {

View File

@@ -23,6 +23,7 @@
#include "playlist.h" #include "playlist.h"
#include "query.h" #include "query.h"
#include "playlist/dynamic/DynamicPlaylist.h" #include "playlist/dynamic/DynamicPlaylist.h"
#include "infosystem/infosystem.h"
#include "dllmacro.h" #include "dllmacro.h"
#include <QObject> #include <QObject>
@@ -36,6 +37,7 @@ public:
virtual ~GlobalActionManager(); virtual ~GlobalActionManager();
QUrl openLinkFromQuery( const Tomahawk::query_ptr& query ) const; QUrl openLinkFromQuery( const Tomahawk::query_ptr& query ) const;
QUrl openLinkFromHash( const Tomahawk::InfoSystem::InfoCriteriaHash& hash ) const;
void copyToClipboard( const Tomahawk::query_ptr& query ) const; void copyToClipboard( const Tomahawk::query_ptr& query ) const;
QString copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist ); QString copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist );
@@ -68,6 +70,8 @@ private:
bool doQueueAdd( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems ); bool doQueueAdd( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems );
QUrl openLink( const QString& title, const QString& artist, const QString& album ) const;
Tomahawk::playlist_ptr m_toShow; Tomahawk::playlist_ptr m_toShow;
Tomahawk::query_ptr m_waitingToBookmark; Tomahawk::query_ptr m_waitingToBookmark;
Tomahawk::query_ptr m_waitingToPlay; Tomahawk::query_ptr m_waitingToPlay;

View File

@@ -22,6 +22,7 @@
#include "artist.h" #include "artist.h"
#include "result.h" #include "result.h"
#include "tomahawksettings.h" #include "tomahawksettings.h"
#include "globalactionmanager.h"
#include "adiumplugin.h" #include "adiumplugin.h"
#include "adium.h" #include "adium.h"
@@ -139,7 +140,7 @@ AdiumPlugin::audioStarted( const QVariant &input )
nowPlaying.append(" - "); nowPlaying.append(" - ");
nowPlaying.append( hash["artist"] ); nowPlaying.append( hash["artist"] );
nowPlaying.append( " " ); nowPlaying.append( " " );
nowPlaying.append( openLinkFromHash( hash ).toString() ); nowPlaying.append( GlobalActionManager::instance()->openLinkFromHash( hash ).toEncoded() );
setStatus( nowPlaying ); setStatus( nowPlaying );
} }

View File

@@ -44,34 +44,6 @@ InfoPlugin::~InfoPlugin()
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
} }
QUrl
InfoPlugin::openLinkFromHash( const InfoCriteriaHash& hash ) const
{
QUrl link( "tomahawk://open/track/" );
QString title, artist, album;
if( !hash.isEmpty() && hash.contains( "title" ) && hash.contains( "artist" ) )
{
title = hash["title"];
artist = hash["artist"];
if( hash.contains( "album" ) )
qDebug() << "Album is: " << album;
album = hash["album"];
}
if( !title.isEmpty() )
link.addEncodedQueryItem( "title", QUrl::toPercentEncoding( title ) );
if( !artist.isEmpty() )
link.addEncodedQueryItem( "artist", QUrl::toPercentEncoding( artist ) );
if( !album.isEmpty() )
link.addEncodedQueryItem( "album", QUrl::toPercentEncoding( album ) );
// Add encoding for spaces, since QUrl does not
QUrl encodedLink( link.toString().replace(" ", "%20"), QUrl::StrictMode );
return encodedLink;
}
InfoSystem* InfoSystem::s_instance = 0; InfoSystem* InfoSystem::s_instance = 0;
InfoSystem* InfoSystem*

View File

@@ -134,8 +134,6 @@ protected slots:
virtual void namChangedSlot( QNetworkAccessManager *nam ) = 0; virtual void namChangedSlot( QNetworkAccessManager *nam ) = 0;
protected: protected:
QUrl openLinkFromHash( const InfoCriteriaHash& hash ) const;
InfoType m_type; InfoType m_type;
QSet< InfoType > m_supportedGetTypes; QSet< InfoType > m_supportedGetTypes;
QSet< InfoType > m_supportedPushTypes; QSet< InfoType > m_supportedPushTypes;