mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 15:29:42 +01:00
qt5: add QUrl comp layer
This commit is contained in:
parent
a8bd444e6c
commit
29e73ad47c
@ -267,7 +267,8 @@ void
|
||||
ChartsPlugin::fetchChartSourcesList( bool fetchOnlySourceList )
|
||||
{
|
||||
QUrl url = QUrl( QString ( CHART_URL "charts" ) );
|
||||
url.addQueryItem( "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
reply->setProperty( "only_source_list", fetchOnlySourceList );
|
||||
@ -356,7 +357,8 @@ ChartsPlugin::fetchAllChartSources()
|
||||
foreach ( const Tomahawk::InfoSystem::InfoStringHash source, m_chartResources )
|
||||
{
|
||||
QUrl url = QUrl( QString( CHART_URL "charts/%1" ).arg( source[ "chart_source" ] ) );
|
||||
url.addQueryItem( "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
reply->setProperty( "chart_source", source[ "chart_source" ] );
|
||||
@ -375,7 +377,8 @@ ChartsPlugin::fetchChart( Tomahawk::InfoSystem::InfoRequestData requestData, con
|
||||
{
|
||||
/// Fetch the chart, we need source and id
|
||||
QUrl url = QUrl ( QString ( CHART_URL "charts/%1/%2" ).arg( source ).arg( chart_id ) );
|
||||
url.addQueryItem( "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetching: " << url;
|
||||
|
||||
|
@ -89,9 +89,11 @@ DiscogsPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requestD
|
||||
{
|
||||
QString requestString( "http://api.discogs.com/database/search" );
|
||||
QUrl url( requestString );
|
||||
url.addQueryItem( "type", "release" );
|
||||
url.addQueryItem( "release_title", criteria[ "album" ] );
|
||||
url.addQueryItem( "artist", criteria[ "artist" ] );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "type", "release" );
|
||||
TomahawkUtils::urlAddQueryItem( url, "release_title", criteria[ "album" ] );
|
||||
TomahawkUtils::urlAddQueryItem( url, "artist", criteria[ "artist" ] );
|
||||
|
||||
QNetworkRequest req( url );
|
||||
req.setRawHeader( "User-Agent", "TomahawkPlayer/1.0 +http://tomahawk-player.org" );
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
||||
|
@ -106,8 +106,10 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
||||
|
||||
QString requestString( "http://musicbrainz.org/ws/2/release-group" );
|
||||
QUrl url( requestString );
|
||||
url.addQueryItem( "query", querySt );
|
||||
url.addQueryItem( "limit", "100" );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "query", querySt );
|
||||
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
||||
|
||||
tDebug() << Q_FUNC_INFO << url.toString();
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||
@ -124,8 +126,10 @@ MusicBrainzPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
||||
|
||||
QString requestString( "http://musicbrainz.org/ws/2/release" );
|
||||
QUrl url( requestString );
|
||||
url.addQueryItem( "query", querySt );
|
||||
url.addQueryItem( "limit", "100" );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "query", querySt );
|
||||
TomahawkUtils::urlAddQueryItem( url, "limit", "100" );
|
||||
|
||||
tDebug() << Q_FUNC_INFO << url.toString();
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||
@ -230,7 +234,7 @@ MusicBrainzPlugin::gotReleasesSlot()
|
||||
|
||||
QString requestString = QString( "http://musicbrainz.org/ws/2/release/%1" ).arg( release_id );
|
||||
QUrl url( requestString );
|
||||
url.addQueryItem( "inc", "recordings" );
|
||||
TomahawkUtils::urlAddQueryItem( url, "inc", "recordings" );
|
||||
tDebug() << Q_FUNC_INFO << url.toString();
|
||||
|
||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
|
@ -64,9 +64,11 @@ MusixMatchPlugin::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData )
|
||||
tDebug() << "artist is " << artist << ", track is " << track;
|
||||
QString requestString( "http://api.musixmatch.com/ws/1.1/track.search?format=xml&page_size=1&f_has_lyrics=1" );
|
||||
QUrl url( requestString );
|
||||
url.addQueryItem( "apikey", m_apiKey );
|
||||
url.addQueryItem( "q_artist", artist );
|
||||
url.addQueryItem( "q_track", track );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "apikey", m_apiKey );
|
||||
TomahawkUtils::urlAddQueryItem( url, "q_artist", artist );
|
||||
TomahawkUtils::urlAddQueryItem( url, "q_track", track );
|
||||
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
reply->setProperty( "requestData", QVariant::fromValue< Tomahawk::InfoSystem::InfoRequestData >( requestData ) );
|
||||
|
||||
@ -123,8 +125,10 @@ MusixMatchPlugin::trackSearchSlot()
|
||||
QString track_id = domNodeList.at(0).toElement().text();
|
||||
QString requestString( "http://api.musixmatch.com/ws/1.1/track.lyrics.get?track_id=%1&format=xml&apikey=%2" );
|
||||
QUrl url( requestString );
|
||||
url.addQueryItem( "apikey", m_apiKey );
|
||||
url.addQueryItem( "track_id", track_id );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "apikey", m_apiKey );
|
||||
TomahawkUtils::urlAddQueryItem( url, "track_id", track_id );
|
||||
|
||||
QNetworkReply* newReply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
newReply->setProperty( "requestData", oldReply->property( "requestData" ) );
|
||||
connect( newReply, SIGNAL( finished() ), SLOT( trackLyricsSlot() ) );
|
||||
|
@ -257,7 +257,8 @@ NewReleasesPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
||||
tDebug ( LOGVERBOSE ) << Q_FUNC_INFO << "InfoChartCapabilities not in cache! Fetching..." << criteria << requestData.requestId;
|
||||
|
||||
QUrl url = QUrl( QString ( CHART_URL "newreleases" ) );
|
||||
url.addQueryItem( "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest ( url ) );
|
||||
reply->setProperty( "only_source_list", true );
|
||||
@ -389,7 +390,8 @@ NewReleasesPlugin::fetchAllNRSources()
|
||||
foreach ( const Tomahawk::InfoSystem::InfoStringHash source, m_nrSources )
|
||||
{
|
||||
QUrl url = QUrl( QString( CHART_URL "newreleases/%1" ).arg( source[ "nr_source" ] ) );
|
||||
url.addQueryItem( "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
QNetworkReply* reply = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
reply->setProperty( "nr_source", source[ "nr_source" ] );
|
||||
@ -408,7 +410,8 @@ NewReleasesPlugin::fetchNR( InfoRequestData requestData, const QString& source,
|
||||
{
|
||||
/// Fetch the chart, we need source and id
|
||||
QUrl url = QUrl ( QString ( CHART_URL "newreleases/%1/%2" ).arg( source ).arg( nr_id ) );
|
||||
url.addQueryItem( "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "version", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << "fetching: " << url;
|
||||
|
||||
|
@ -79,9 +79,10 @@ RoviPlugin::notInCacheSlot( Tomahawk::InfoSystem::InfoStringHash criteria, Tomah
|
||||
case InfoAlbumSongs:
|
||||
{
|
||||
QUrl baseUrl = QUrl( "http://api.rovicorp.com/search/v2/music/search" );
|
||||
baseUrl.addQueryItem( "query", QString( "%1 %2" ).arg( criteria[ "artist" ] ).arg( criteria[ "album" ] ) );
|
||||
baseUrl.addQueryItem( "entitytype", "album" );
|
||||
baseUrl.addQueryItem( "include", "album:tracks" );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( baseUrl, "query", QString( "%1 %2" ).arg( criteria[ "artist" ] ).arg( criteria[ "album" ] ) );
|
||||
TomahawkUtils::urlAddQueryItem( baseUrl, "entitytype", "album" );
|
||||
TomahawkUtils::urlAddQueryItem( baseUrl, "include", "album:tracks" );
|
||||
|
||||
QNetworkReply* reply = makeRequest( baseUrl );
|
||||
|
||||
@ -178,8 +179,8 @@ RoviPlugin::albumLookupFinished()
|
||||
QNetworkReply*
|
||||
RoviPlugin::makeRequest( QUrl url )
|
||||
{
|
||||
url.addQueryItem( "apikey", m_apiKey );
|
||||
url.addEncodedQueryItem( "sig", generateSig() );
|
||||
TomahawkUtils::urlAddQueryItem( url, "apikey", m_apiKey );
|
||||
TomahawkUtils::urlAddQueryItem( url, "sig", generateSig() );
|
||||
|
||||
qDebug() << "Rovi request url:" << url.toString();
|
||||
return TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
|
@ -546,7 +546,8 @@ void AtticaManager::doInstallResolver( const Content& resolver, bool autoCreate,
|
||||
|
||||
// ItemJob< DownloadItem >* job = m_resolverProvider.downloadLink( resolver.id() );
|
||||
QUrl url( QString( "%1/resolvers/v1/content/download/%2/1" ).arg( hostname() ).arg( resolver.id() ) );
|
||||
url.addQueryItem( "tomahawkversion", TomahawkUtils::appFriendlyVersion() );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "tomahawkversion", TomahawkUtils::appFriendlyVersion() );
|
||||
QNetworkReply* r = TomahawkUtils::nam()->get( QNetworkRequest( url ) );
|
||||
NewClosure( r, SIGNAL( finished() ), this, SLOT( resolverDownloadFinished( QNetworkReply* ) ), r );
|
||||
r->setProperty( "resolverId", resolver.id() );
|
||||
|
@ -62,6 +62,7 @@
|
||||
GlobalActionManager* GlobalActionManager::s_instance = 0;
|
||||
|
||||
using namespace Tomahawk;
|
||||
using namespace TomahawkUtils;
|
||||
|
||||
|
||||
GlobalActionManager*
|
||||
@ -129,11 +130,11 @@ GlobalActionManager::openLink( const QString& title, const QString& artist, cons
|
||||
QUrl link( QString( "%1/open/track/" ).arg( hostname() ) );
|
||||
|
||||
if ( !artist.isEmpty() )
|
||||
link.addQueryItem( "artist", artist );
|
||||
TomahawkUtils::urlAddQueryItem( link, "artist", artist );
|
||||
if ( !title.isEmpty() )
|
||||
link.addQueryItem( "title", title );
|
||||
TomahawkUtils::urlAddQueryItem( link, "title", title );
|
||||
if ( !album.isEmpty() )
|
||||
link.addQueryItem( "album", album );
|
||||
TomahawkUtils::urlAddQueryItem( link, "album", album );
|
||||
|
||||
return link;
|
||||
}
|
||||
@ -221,8 +222,8 @@ GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
||||
return QString();
|
||||
}
|
||||
|
||||
link.addEncodedQueryItem( "type", "echonest" );
|
||||
link.addQueryItem( "title", playlist->title() );
|
||||
TomahawkUtils::urlAddQueryItem( link, "type", "echonest" );
|
||||
TomahawkUtils::urlAddQueryItem( link, "title", playlist->title() );
|
||||
|
||||
QList< dyncontrol_ptr > controls = playlist->generator()->controls();
|
||||
foreach ( const dyncontrol_ptr& c, controls )
|
||||
@ -230,13 +231,13 @@ GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
||||
if ( c->selectedType() == "Artist" )
|
||||
{
|
||||
if ( c->match().toInt() == Echonest::DynamicPlaylist::ArtistType )
|
||||
link.addQueryItem( "artist_limitto", c->input() );
|
||||
TomahawkUtils::urlAddQueryItem( link, "artist_limitto", c->input() );
|
||||
else
|
||||
link.addQueryItem( "artist", c->input() );
|
||||
TomahawkUtils::urlAddQueryItem( link, "artist", c->input() );
|
||||
}
|
||||
else if ( c->selectedType() == "Artist Description" )
|
||||
{
|
||||
link.addQueryItem( "description", c->input() );
|
||||
TomahawkUtils::urlAddQueryItem( link, "description", c->input() );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -249,7 +250,7 @@ GlobalActionManager::copyPlaylistToClipboard( const dynplaylist_ptr& playlist )
|
||||
|| p == Echonest::DynamicPlaylist::ArtistMaxLongitude )
|
||||
name += "_max";
|
||||
|
||||
link.addQueryItem( name, c->input() );
|
||||
TomahawkUtils::urlAddQueryItem( link, name, c->input() );
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,9 +319,9 @@ GlobalActionManager::parseTomahawkLink( const QString& urlIn )
|
||||
// for backwards compatibility
|
||||
if ( cmdType == "load" )
|
||||
{
|
||||
if ( u.hasQueryItem( "xspf" ) )
|
||||
if ( urlHasQueryItem( u, "xspf" ) )
|
||||
{
|
||||
QUrl xspf = QUrl::fromUserInput( u.queryItemValue( "xspf" ) );
|
||||
QUrl xspf = QUrl::fromUserInput( urlQueryItemValue( u, "xspf" ) );
|
||||
XSPFLoader* l = new XSPFLoader( true, this );
|
||||
tDebug() << "Loading spiff:" << xspf.toString();
|
||||
l->load( xspf );
|
||||
@ -328,9 +329,9 @@ GlobalActionManager::parseTomahawkLink( const QString& urlIn )
|
||||
|
||||
return true;
|
||||
}
|
||||
else if ( u.hasQueryItem( "jspf" ) )
|
||||
else if ( urlHasQueryItem( u, "jspf" ) )
|
||||
{
|
||||
QUrl jspf = QUrl::fromUserInput( u.queryItemValue( "jspf" ) );
|
||||
QUrl jspf = QUrl::fromUserInput( urlQueryItemValue( u, "jspf" ) );
|
||||
JSPFLoader* l = new JSPFLoader( true, this );
|
||||
|
||||
tDebug() << "Loading jspiff:" << jspf.toString();
|
||||
@ -411,35 +412,35 @@ GlobalActionManager::handlePlaylistCommand( const QUrl& url )
|
||||
|
||||
if ( parts[ 0 ] == "import" )
|
||||
{
|
||||
if ( !url.hasQueryItem( "xspf" ) && !url.hasQueryItem( "jspf") )
|
||||
if ( !urlHasQueryItem( url, "xspf" ) && !urlHasQueryItem( url, "jspf" ) )
|
||||
{
|
||||
tDebug() << "No xspf or jspf to load...";
|
||||
return false;
|
||||
}
|
||||
if ( url.hasQueryItem( "xspf" ) )
|
||||
if ( urlHasQueryItem( url, "xspf" ) )
|
||||
{
|
||||
createPlaylistFromUrl( "xspf", url.queryItemValue( "xspf" ), url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString() );
|
||||
createPlaylistFromUrl( "xspf", urlQueryItemValue( url, "xspf" ), urlHasQueryItem( url, "title" ) ? urlQueryItemValue( url, "title" ) : QString() );
|
||||
return true;
|
||||
}
|
||||
else if ( url.hasQueryItem( "jspf" ) )
|
||||
else if ( urlHasQueryItem( url, "jspf" ) )
|
||||
{
|
||||
createPlaylistFromUrl( "jspf", url.queryItemValue( "jspf" ), url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString() );
|
||||
createPlaylistFromUrl( "jspf", urlQueryItemValue( url, "jspf" ), urlHasQueryItem( url, "title" ) ? urlQueryItemValue( url, "title" ) : QString() );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if ( parts [ 0 ] == "new" )
|
||||
{
|
||||
if ( !url.hasQueryItem( "title" ) )
|
||||
if ( !urlHasQueryItem( url, "title" ) )
|
||||
{
|
||||
tLog() << "New playlist command needs a title...";
|
||||
return false;
|
||||
}
|
||||
playlist_ptr pl = Playlist::create( SourceList::instance()->getLocal(), uuid(), url.queryItemValue( "title" ), QString(), QString(), false );
|
||||
playlist_ptr pl = Playlist::create( SourceList::instance()->getLocal(), uuid(), urlQueryItemValue( url, "title" ), QString(), QString(), false );
|
||||
ViewManager::instance()->show( pl );
|
||||
}
|
||||
else if ( parts[ 0 ] == "add" )
|
||||
{
|
||||
if ( !url.hasQueryItem( "playlistid" ) || !url.hasQueryItem( "title" ) || !url.hasQueryItem( "artist" ) )
|
||||
if ( !urlHasQueryItem( url, "playlistid" ) || !urlHasQueryItem( url, "title" ) || !urlHasQueryItem( url, "artist" ) )
|
||||
{
|
||||
tLog() << "Add to playlist command needs playlistid, track, and artist..." << url.toString();
|
||||
return false;
|
||||
@ -461,14 +462,14 @@ GlobalActionManager::handleImportCommand( const QUrl& url )
|
||||
|
||||
if ( parts[ 0 ] == "playlist" )
|
||||
{
|
||||
if ( url.hasQueryItem( "xspf" ) )
|
||||
if ( urlHasQueryItem( url, "xspf" ) )
|
||||
{
|
||||
createPlaylistFromUrl( "xspf", url.queryItemValue( "xspf" ), url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString() );
|
||||
createPlaylistFromUrl( "xspf", urlQueryItemValue( url, "xspf" ), urlHasQueryItem( url, "title" ) ? urlQueryItemValue( url, "title" ) : QString() );
|
||||
return true;
|
||||
}
|
||||
else if ( url.hasQueryItem( "jspf" ) )
|
||||
else if ( urlHasQueryItem( url, "jspf" ) )
|
||||
{
|
||||
createPlaylistFromUrl( "jspf", url.queryItemValue( "jspf" ), url.hasQueryItem( "title" ) ? url.queryItemValue( "title" ) : QString() );
|
||||
createPlaylistFromUrl( "jspf", urlQueryItemValue( url, "jspf" ), urlHasQueryItem( url, "title" ) ? urlQueryItemValue( url, "title" ) : QString() );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -547,7 +548,7 @@ GlobalActionManager::handleOpenCommand( const QUrl& url )
|
||||
return false;
|
||||
}
|
||||
// TODO user configurable in the UI
|
||||
return doQueueAdd( parts, url.queryItems() );
|
||||
return doQueueAdd( parts, urlQueryItems( url ) );
|
||||
}
|
||||
|
||||
|
||||
@ -601,7 +602,7 @@ GlobalActionManager::handleQueueCommand( const QUrl& url )
|
||||
|
||||
if ( parts[ 0 ] == "add" )
|
||||
{
|
||||
doQueueAdd( parts.mid( 1 ), url.queryItems() );
|
||||
doQueueAdd( parts.mid( 1 ), urlQueryItems( url ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -783,17 +784,17 @@ GlobalActionManager::handleSearchCommand( const QUrl& url )
|
||||
{
|
||||
// open the super collection and set this as the search filter
|
||||
QString queryStr;
|
||||
if ( url.hasQueryItem( "query" ) )
|
||||
queryStr = url.queryItemValue( "query" );
|
||||
if ( urlHasQueryItem( url, "query" ) )
|
||||
queryStr = urlQueryItemValue( url, "query" );
|
||||
else
|
||||
{
|
||||
QStringList query;
|
||||
if ( url.hasQueryItem( "artist" ) )
|
||||
query << url.queryItemValue( "artist" );
|
||||
if ( url.hasQueryItem( "album" ) )
|
||||
query << url.queryItemValue( "album" );
|
||||
if ( url.hasQueryItem( "title" ) )
|
||||
query << url.queryItemValue( "title" );
|
||||
if ( urlHasQueryItem( url, "artist" ) )
|
||||
query << urlQueryItemValue( url, "artist" );
|
||||
if ( urlHasQueryItem( url, "album" ) )
|
||||
query << urlQueryItemValue( url, "album" );
|
||||
if ( urlHasQueryItem( url, "title" ) )
|
||||
query << urlQueryItemValue( url, "title" );
|
||||
queryStr = query.join( " " );
|
||||
}
|
||||
|
||||
@ -817,7 +818,7 @@ GlobalActionManager::handleViewCommand( const QUrl& url )
|
||||
|
||||
if ( parts[ 0 ] == "artist" )
|
||||
{
|
||||
const QString artist = QUrl::fromPercentEncoding( url.encodedQueryItemValue( "name" ) ).replace( "+", " " );
|
||||
const QString artist = urlQueryItemValue( url, "name" );
|
||||
if ( artist.isEmpty() )
|
||||
{
|
||||
tLog() << "No artist supplied for view/artist command.";
|
||||
@ -832,8 +833,8 @@ GlobalActionManager::handleViewCommand( const QUrl& url )
|
||||
}
|
||||
else if ( parts[ 0 ] == "album" )
|
||||
{
|
||||
const QString artist = QUrl::fromPercentEncoding( url.encodedQueryItemValue( "artist" ) ).replace( "+", " " );
|
||||
const QString album = QUrl::fromPercentEncoding( url.encodedQueryItemValue( "name" ) ).replace( "+", " " );
|
||||
const QString artist = urlQueryItemValue( url, "artist" );
|
||||
const QString album = urlQueryItemValue( url, "name" );
|
||||
if ( artist.isEmpty() || album.isEmpty() )
|
||||
{
|
||||
tLog() << "No artist or album supplied for view/album command:" << url;
|
||||
@ -848,9 +849,9 @@ GlobalActionManager::handleViewCommand( const QUrl& url )
|
||||
}
|
||||
else if ( parts[ 0 ] == "track" )
|
||||
{
|
||||
const QString artist = QUrl::fromPercentEncoding( url.encodedQueryItemValue( "artist" ) ).replace( "+", " " );
|
||||
const QString album = QUrl::fromPercentEncoding( url.encodedQueryItemValue( "album" ) ).replace( "+", " " );
|
||||
const QString track = QUrl::fromPercentEncoding( url.encodedQueryItemValue( "name" ) ).replace( "+", " " );
|
||||
const QString artist = urlQueryItemValue( url, "artist" );
|
||||
const QString album = urlQueryItemValue( url, "album" );
|
||||
const QString track = urlQueryItemValue( url, "track" );
|
||||
if ( artist.isEmpty() || track.isEmpty() )
|
||||
{
|
||||
tLog() << "No artist or track supplied for view/track command:" << url;
|
||||
@ -887,13 +888,13 @@ GlobalActionManager::loadDynamicPlaylist( const QUrl& url, bool station )
|
||||
|
||||
if ( parts[ 0 ] == "create" )
|
||||
{
|
||||
if ( !url.hasQueryItem( "title" ) || !url.hasQueryItem( "type" ) )
|
||||
if ( !urlHasQueryItem( url, "title" ) || !urlHasQueryItem( url, "type" ) )
|
||||
{
|
||||
tLog() << "Station create command needs title and type..." << url.toString();
|
||||
return Tomahawk::dynplaylist_ptr();
|
||||
}
|
||||
QString title = url.queryItemValue( "title" );
|
||||
QString type = url.queryItemValue( "type" );
|
||||
QString title = urlQueryItemValue( url, "title" );
|
||||
QString type = urlQueryItemValue( url, "type" );
|
||||
GeneratorMode m = Static;
|
||||
if ( station )
|
||||
m = OnDemand;
|
||||
@ -902,7 +903,7 @@ GlobalActionManager::loadDynamicPlaylist( const QUrl& url, bool station )
|
||||
pl->setMode( m );
|
||||
QList< dyncontrol_ptr > controls;
|
||||
QPair< QString, QString > param;
|
||||
foreach ( param, url.queryItems() )
|
||||
foreach ( param, urlQueryItems( url ) )
|
||||
{
|
||||
if ( param.first == "artist" )
|
||||
{
|
||||
@ -1088,7 +1089,7 @@ GlobalActionManager::handlePlayCommand( const QUrl& url )
|
||||
|
||||
QPair< QString, QString > pair;
|
||||
QString title, artist, album, urlStr;
|
||||
foreach ( pair, url.queryItems() )
|
||||
foreach ( pair, urlQueryItems( url ) )
|
||||
{
|
||||
if ( pair.first == "title" )
|
||||
title = pair.second;
|
||||
@ -1121,10 +1122,10 @@ GlobalActionManager::handlePlayCommand( const QUrl& url )
|
||||
bool
|
||||
GlobalActionManager::playSpotify( const QUrl& url )
|
||||
{
|
||||
if ( !url.hasQueryItem( "spotifyURI" ) && !url.hasQueryItem( "spotifyURL" ) )
|
||||
if ( !urlHasQueryItem( url, "spotifyURI" ) && !urlHasQueryItem( url, "spotifyURL" ) )
|
||||
return false;
|
||||
|
||||
QString spotifyUrl = url.hasQueryItem( "spotifyURI" ) ? url.queryItemValue( "spotifyURI" ) : url.queryItemValue( "spotifyURL" );
|
||||
QString spotifyUrl = urlHasQueryItem( url, "spotifyURI" ) ? urlQueryItemValue( url, "spotifyURI" ) : urlQueryItemValue( url, "spotifyURL" );
|
||||
SpotifyParser* p = new SpotifyParser( spotifyUrl, this );
|
||||
connect( p, SIGNAL( track( Tomahawk::query_ptr ) ), this, SLOT( playOrQueueNow( Tomahawk::query_ptr ) ) );
|
||||
|
||||
@ -1156,10 +1157,10 @@ GlobalActionManager::playOrQueueNow( const query_ptr& q )
|
||||
bool
|
||||
GlobalActionManager::playRdio( const QUrl& url )
|
||||
{
|
||||
if ( !url.hasQueryItem( "rdioURI" ) && !url.hasQueryItem( "rdioURL" ) )
|
||||
if ( !urlHasQueryItem( url, "rdioURI" ) && !urlHasQueryItem( url, "rdioURL" ) )
|
||||
return false;
|
||||
|
||||
QString rdioUrl = url.hasQueryItem( "rdioURI" ) ? url.queryItemValue( "spotifyURI" ) : url.queryItemValue( "rdioURL" );
|
||||
QString rdioUrl = urlHasQueryItem( url, "rdioURI" ) ? urlQueryItemValue( url, "spotifyURI" ) : urlQueryItemValue( url, "rdioURL" );
|
||||
RdioParser* p = new RdioParser( this );
|
||||
p->parse( rdioUrl );
|
||||
connect( p, SIGNAL( track( Tomahawk::query_ptr ) ), this, SLOT( playOrQueueNow( Tomahawk::query_ptr ) ) );
|
||||
@ -1183,7 +1184,7 @@ bool GlobalActionManager::handleBookmarkCommand(const QUrl& url)
|
||||
{
|
||||
QPair< QString, QString > pair;
|
||||
QString title, artist, album, urlStr;
|
||||
foreach ( pair, url.queryItems() )
|
||||
foreach ( pair, urlQueryItems( url ) )
|
||||
{
|
||||
if ( pair.first == "title" )
|
||||
title = pair.second;
|
||||
|
@ -141,7 +141,7 @@ SpotifyInfoPlugin::notInCacheSlot( InfoStringHash criteria, InfoRequestData requ
|
||||
{
|
||||
// No running spotify account, use our webservice
|
||||
QUrl lookupUrl( "http://ws.spotify.com/search/1/album.json" );
|
||||
lookupUrl.addQueryItem( "q", QString( "%1 %2" ).arg( artist ).arg( album ) );
|
||||
TomahawkUtils::urlAddQueryItem( lookupUrl, "q", QString( "%1 %2" ).arg( artist ).arg( album ) );
|
||||
|
||||
QNetworkReply * reply = TomahawkUtils::nam()->get( QNetworkRequest( lookupUrl ) );
|
||||
NewClosure( reply, SIGNAL( finished() ), this, SLOT( albumIdLookupFinished( QNetworkReply*, Tomahawk::InfoSystem::InfoRequestData ) ), reply, requestData );
|
||||
|
@ -470,7 +470,7 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
|
||||
if ( m_currentTrack->url().contains( "?" ) )
|
||||
{
|
||||
furl = QUrl( m_currentTrack->url().left( m_currentTrack->url().indexOf( '?' ) ) );
|
||||
furl.setEncodedQuery( QString( m_currentTrack->url().mid( m_currentTrack->url().indexOf( '?' ) + 1 ) ).toLocal8Bit() );
|
||||
TomahawkUtils::urlSetQuery( furl, QString( m_currentTrack->url().mid( m_currentTrack->url().indexOf( '?' ) + 1 ) ) );
|
||||
}
|
||||
|
||||
tLog( LOGVERBOSE ) << "Passing to Phonon:" << furl;
|
||||
|
@ -256,24 +256,26 @@ RdioParser::generateRequest( const QString& method, const QString& url, const QL
|
||||
QUrl fetchUrl( "http://api.rdio.com/1/" );
|
||||
QUrl toSignUrl = fetchUrl;
|
||||
|
||||
|
||||
QPair<QByteArray, QByteArray> param;
|
||||
foreach ( param, extraParams )
|
||||
{
|
||||
toSignUrl.addEncodedQueryItem( param.first, param.second );
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, param.first, param.second );
|
||||
}
|
||||
toSignUrl.addQueryItem( "method", method );
|
||||
toSignUrl.addEncodedQueryItem("oauth_consumer_key", "gk8zmyzj5xztt8aj48csaart" );
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, "method", method );
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, "oauth_consumer_key", "gk8zmyzj5xztt8aj48csaart" );
|
||||
QString nonce;
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
nonce += QString::number( qrand() % 10 );
|
||||
toSignUrl.addQueryItem("oauth_nonce", nonce );
|
||||
toSignUrl.addEncodedQueryItem("oauth_signature_method", "HMAC-SHA1");
|
||||
toSignUrl.addQueryItem("oauth_timestamp", QString::number(QDateTime::currentMSecsSinceEpoch() / 1000 ) );
|
||||
toSignUrl.addEncodedQueryItem("oauth_version", "1.0");
|
||||
toSignUrl.addEncodedQueryItem( "url", QUrl::toPercentEncoding( url ) );
|
||||
int size = toSignUrl.encodedQueryItems().size();
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, "oauth_nonce", nonce );
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, "oauth_signature_method", "HMAC-SHA1");
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, "oauth_timestamp", QString::number(QDateTime::currentMSecsSinceEpoch() / 1000 ) );
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, "oauth_version", "1.0");
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, "url", QUrl::toPercentEncoding( url ) );
|
||||
|
||||
int size = TomahawkUtils::urlQueryItems( toSignUrl ).size();
|
||||
for( int i = 0; i < size; i++ ) {
|
||||
const QPair< QByteArray, QByteArray > item = toSignUrl.encodedQueryItems().at( i );
|
||||
const QPair< QString, QString > item = TomahawkUtils::urlQueryItems( toSignUrl ).at( i );
|
||||
data->append( item.first + "=" + item.second + "&" );
|
||||
}
|
||||
data->truncate( data->size() - 1 ); // remove extra &
|
||||
@ -281,13 +283,13 @@ RdioParser::generateRequest( const QString& method, const QString& url, const QL
|
||||
QByteArray toSign = "POST&" + QUrl::toPercentEncoding( fetchUrl.toEncoded() ) + '&' + QUrl::toPercentEncoding( *data );
|
||||
qDebug() << "Rdio" << toSign;
|
||||
|
||||
toSignUrl.addEncodedQueryItem( "oauth_signature", QUrl::toPercentEncoding( hmacSha1("yt35kakDyW&", toSign ) ) );
|
||||
TomahawkUtils::urlAddQueryItem( toSignUrl, "oauth_signature", QUrl::toPercentEncoding( hmacSha1("yt35kakDyW&", toSign ) ) );
|
||||
|
||||
data->clear();
|
||||
size = toSignUrl.encodedQueryItems().size();
|
||||
size = TomahawkUtils::urlQueryItems( toSignUrl ).size();
|
||||
for( int i = 0; i < size; i++ ) {
|
||||
const QPair< QByteArray, QByteArray > item = toSignUrl.encodedQueryItems().at( i );
|
||||
data->append( item.first + "=" + item.second + "&" );
|
||||
const QPair< QString, QString > item = TomahawkUtils::urlQueryItems( toSignUrl ).at( i );
|
||||
data->append( item.first.toLatin1() + "=" + item.second.toLatin1() + "&" );
|
||||
}
|
||||
data->truncate( data->size() - 1 ); // remove extra &
|
||||
|
||||
|
@ -119,7 +119,10 @@ SoundcloudParser::parseTrack( const QVariantMap& res )
|
||||
if ( !q.isNull() )
|
||||
{
|
||||
QUrl url = QUrl::fromUserInput( res.value( "stream_url" ).toString() );
|
||||
url.addQueryItem( "client_id", "TiNg2DRYhBnp01DA3zNag" );
|
||||
|
||||
TomahawkUtils::urlAddQueryItem( url, "client_id", "TiNg2DRYhBnp01DA3zNag" );
|
||||
|
||||
|
||||
tLog() << "Setting resulthint to " << res.value( "stream_url" ) << url.toString();
|
||||
q->setResultHint( url.toString() );
|
||||
q->setSaveHTTPResultHint( true );
|
||||
|
@ -47,6 +47,10 @@
|
||||
#include <QProcess>
|
||||
#include <QTranslator>
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
#include <QUrlQuery>
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
@ -992,6 +996,63 @@ whitelistedHttpResultHint( const QString& url )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
urlAddQueryItem( QUrl& url, const QString& key, const QString& value )
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
QUrlQuery urlQuery( url );
|
||||
urlQuery.addQueryItem( key, value );
|
||||
url.setQuery( urlQuery );
|
||||
#else
|
||||
url.addQueryItem( key, value );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
urlQueryItemValue( const QUrl& url, const QString& key )
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
return QUrlQuery( url ).queryItemValue( key ).replace( "+", " " )
|
||||
#else
|
||||
return url.queryItemValue( key ).replace( "+", " " );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
urlHasQueryItem( const QUrl& url, const QString& key )
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
return QUrlQuery( url ).hasQueryItem( key );
|
||||
#else
|
||||
return url.hasQueryItem( key );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
QList<QPair<QString, QString> >
|
||||
urlQueryItems( const QUrl& url )
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
return QUrlQuery( url ).queryItems();
|
||||
#else
|
||||
return url.queryItems();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
urlSetQuery( QUrl& url, const QString& query )
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 )
|
||||
url.setQuery( query );
|
||||
#else
|
||||
url.setEncodedQuery( query.toLocal8Bit() );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // ns
|
||||
|
||||
#include "TomahawkUtils.moc"
|
||||
|
@ -214,6 +214,19 @@ namespace TomahawkUtils
|
||||
DLLEXPORT QList< Tomahawk::query_ptr > mergePlaylistChanges( const QList< Tomahawk::query_ptr >& orig, const QList< Tomahawk::query_ptr >& newTracks, bool& changed );
|
||||
|
||||
DLLEXPORT void crash();
|
||||
|
||||
|
||||
/**
|
||||
* Qt4 / Qt5 compatibility layer
|
||||
*/
|
||||
|
||||
/* QUrl */
|
||||
DLLEXPORT void urlAddQueryItem( QUrl& url, const QString& key, const QString& value );
|
||||
DLLEXPORT QString urlQueryItemValue( const QUrl& url, const QString& key );
|
||||
DLLEXPORT bool urlHasQueryItem( const QUrl& url, const QString& key );
|
||||
DLLEXPORT QList<QPair<QString, QString> > urlQueryItems( const QUrl& url );
|
||||
DLLEXPORT void urlSetQuery( QUrl& url, const QString& query );
|
||||
|
||||
}
|
||||
|
||||
#endif // TOMAHAWKUTILS_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user