File indexing completed on 2025-01-05 04:26:04
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Andrew Coder <andrew.coder@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "ProxyResolver.h" 0018 0019 #include "Controller.h" 0020 #include "../PlaydarCollection.h" 0021 #include "../PlaydarMeta.h" 0022 #include "core-impl/meta/proxy/MetaProxy.h" 0023 0024 #include <QObject> 0025 #include <QUrl> 0026 #include <QUrlQuery> 0027 0028 Playdar::ProxyResolver::ProxyResolver( Collections::PlaydarCollection *collection, 0029 const QUrl &url, const MetaProxy::TrackPtr &track ) 0030 : m_collection( collection ) 0031 , m_proxyTrack( track ) 0032 , m_controller( new Playdar::Controller( true ) ) 0033 , m_query() 0034 { 0035 connect( m_controller, &Playdar::Controller::playdarError, 0036 this, &Playdar::ProxyResolver::slotPlaydarError ); 0037 connect( m_controller, &Playdar::Controller::queryReady, 0038 this, &Playdar::ProxyResolver::collectQuery ); 0039 m_controller->resolve( QUrlQuery(url).queryItemValue( "artist" ), 0040 QUrlQuery(url).queryItemValue( "album" ), 0041 QUrlQuery(url).queryItemValue( "title" ) ); 0042 } 0043 0044 Playdar::ProxyResolver::~ProxyResolver() 0045 { 0046 delete m_query; 0047 delete m_controller; 0048 } 0049 0050 void 0051 Playdar::ProxyResolver::slotPlaydarError( Playdar::Controller::ErrorState error ) 0052 { 0053 Q_EMIT playdarError( error ); 0054 this->deleteLater(); 0055 } 0056 0057 void 0058 Playdar::ProxyResolver::collectQuery( Playdar::Query *query ) 0059 { 0060 m_query = query; 0061 connect( m_query, &Playdar::Query::querySolved, 0062 this, &Playdar::ProxyResolver::collectSolution ); 0063 connect( m_query, &Playdar::Query::queryDone, 0064 this, &Playdar::ProxyResolver::slotQueryDone ); 0065 } 0066 0067 void 0068 Playdar::ProxyResolver::collectSolution( Meta::PlaydarTrackPtr track ) 0069 { 0070 if( !m_proxyTrack->isPlayable() ) 0071 { 0072 Meta::TrackPtr realTrack; 0073 0074 if( !m_collection.isNull() ) 0075 { 0076 track->addToCollection( m_collection ); 0077 realTrack = m_collection->trackForUrl( QUrl(track->uidUrl()) ); 0078 } 0079 else 0080 realTrack = Meta::TrackPtr::staticCast( track ); 0081 0082 m_proxyTrack->updateTrack( realTrack ); 0083 } 0084 } 0085 0086 void 0087 Playdar::ProxyResolver::slotQueryDone( Playdar::Query* query, const Meta::PlaydarTrackList& tracks ) 0088 { 0089 Q_UNUSED( query ); 0090 Q_UNUSED( tracks ); 0091 this->deleteLater(); 0092 } 0093