diff --git a/src/libtomahawk-playdarapi/Api_v1_5.cpp b/src/libtomahawk-playdarapi/Api_v1_5.cpp index b3803f210..d7bff50ae 100644 --- a/src/libtomahawk-playdarapi/Api_v1_5.cpp +++ b/src/libtomahawk-playdarapi/Api_v1_5.cpp @@ -99,7 +99,7 @@ Api_v1_5::playback( QxtWebRequestEvent* event, const QString& command ) trackInfo.insert( "paused", AudioEngine::instance()->isPaused() ); trackInfo.insert( "position", AudioEngine::instance()->currentTime() / 1000 ); trackInfo.insert( "bitrate", currentTrack->bitrate() ); - if ( !currentTrack->resolvedBy().isNull() ) { + if ( currentTrack->resolvedBy() ) { QString resolverName = currentTrack->resolvedBy()->name(); trackInfo.insert( "resolvedBy", resolverName ); } else { diff --git a/src/libtomahawk/DropJob.cpp b/src/libtomahawk/DropJob.cpp index f27edca25..3df245313 100644 --- a/src/libtomahawk/DropJob.cpp +++ b/src/libtomahawk/DropJob.cpp @@ -975,8 +975,8 @@ DropJob::removeRemoteSources() foreach ( const Tomahawk::result_ptr& result, item->results() ) { - if ( !result->collection().isNull() && !result->collection()->source().isNull() - && result->collection()->source()->isLocal() ) + if ( !result->resolvedByCollection().isNull() && !result->resolvedByCollection()->source().isNull() + && result->resolvedByCollection()->source()->isLocal() ) { list.append( item ); break; diff --git a/src/libtomahawk/Pipeline.cpp b/src/libtomahawk/Pipeline.cpp index 162fb3d01..fd7f5235b 100644 --- a/src/libtomahawk/Pipeline.cpp +++ b/src/libtomahawk/Pipeline.cpp @@ -335,13 +335,18 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results ) return; if ( !d->qids.contains( qid ) ) { - if ( results.length() > 0 && !results[0]->resolvedBy().isNull() ) - { - tDebug() << "Result arrived too late for:" << qid << "by" << results[0]->resolvedBy()->name(); - } - else + if ( results.length() > 0 ) { + ResultProvider* resolvedBy = results[0]->resolvedBy(); + + if ( resolvedBy ) + { + tDebug() << "Result arrived too late for:" << qid << "by" << resolvedBy->name(); + } + else + { tDebug() << "Result arrived too late for:" << qid; + } } return; } diff --git a/src/libtomahawk/Query.cpp b/src/libtomahawk/Query.cpp index fab1d01f0..8dd9b4d9d 100644 --- a/src/libtomahawk/Query.cpp +++ b/src/libtomahawk/Query.cpp @@ -413,7 +413,7 @@ Query::resultSorter( const result_ptr& left, const result_ptr& right ) { return true; }*/ - if ( right->collection() && right->collection()->source()->isLocal() ) + if ( right->resolvedByCollection() && right->resolvedByCollection()->source()->isLocal() ) { return false; } diff --git a/src/libtomahawk/Result.cpp b/src/libtomahawk/Result.cpp index c658b8b92..c5f62f0e3 100644 --- a/src/libtomahawk/Result.cpp +++ b/src/libtomahawk/Result.cpp @@ -34,6 +34,7 @@ #include "PlaylistInterface.h" #include "Source.h" #include "Track.h" +#include "Typedefs.h" using namespace Tomahawk; @@ -132,16 +133,16 @@ Result::deleteLater() void Result::onResolverRemoved( Tomahawk::Resolver* resolver ) { - if ( m_resolvedBy.data() == resolver ) + if ( m_resolver.data() == resolver ) { - m_resolvedBy = 0; + m_resolver = 0; emit statusChanged(); } } collection_ptr -Result::collection() const +Result::resolvedByCollection() const { return m_collection; } @@ -188,13 +189,13 @@ Result::id() const bool Result::isOnline() const { - if ( !collection().isNull() ) + if ( !resolvedByCollection().isNull() ) { - return collection()->source()->isOnline(); + return resolvedByCollection()->source()->isOnline(); } else { - return !m_resolvedBy.isNull(); + return !m_resolver.isNull(); } } @@ -202,9 +203,9 @@ Result::isOnline() const bool Result::playable() const { - if ( collection() ) + if ( resolvedByCollection() ) { - return collection()->source()->isOnline(); + return resolvedByCollection()->source()->isOnline(); } else { @@ -297,17 +298,19 @@ Result::onOffline() void -Result::setCollection( const Tomahawk::collection_ptr& collection , bool emitOnlineEvents ) +Result::setResolvedByCollection( const Tomahawk::collection_ptr& collection , bool emitOnlineEvents ) { m_collection = collection; if ( emitOnlineEvents ) { - connect( m_collection->source().data(), SIGNAL( online() ), SLOT( onOnline() ), Qt::QueuedConnection ); - connect( m_collection->source().data(), SIGNAL( offline() ), SLOT( onOffline() ), Qt::QueuedConnection ); + connect( collection->source().data(), SIGNAL( online() ), SLOT( onOnline() ), Qt::QueuedConnection ); + connect( collection->source().data(), SIGNAL( offline() ), SLOT( onOffline() ), Qt::QueuedConnection ); } } + + void Result::setFriendlySource(const QString& s) { @@ -381,12 +384,12 @@ Result::fileId() const QString Result::friendlySource() const { - if ( collection().isNull() ) + if ( resolvedByCollection().isNull() ) { return m_friendlySource; } else - return collection()->source()->friendlyName(); + return resolvedByCollection()->source()->friendlyName(); } @@ -407,9 +410,9 @@ Result::linkUrl() const QPixmap Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) const { - if ( collection().isNull() ) + if ( resolvedByCollection().isNull() ) { - const ExternalResolver* resolver = qobject_cast< ExternalResolver* >( m_resolvedBy.data() ); + const ExternalResolver* resolver = qobject_cast< ExternalResolver* >( m_resolver.data() ); if ( !resolver ) { return QPixmap(); @@ -418,7 +421,7 @@ Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) c { QMutexLocker l( &s_sourceIconMutex ); - const QString key = sourceCacheKey( m_resolvedBy.data(), desiredSize, style ); + const QString key = sourceCacheKey( m_resolver.data(), desiredSize, style ); if ( !sourceIconCache()->contains( key ) ) { QPixmap pixmap = resolver->icon( desiredSize ); @@ -448,7 +451,7 @@ Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) c } else { - QPixmap avatar = collection()->source()->avatar( TomahawkUtils::RoundedCorners, desiredSize, true ); + QPixmap avatar = resolvedByCollection()->source()->avatar( TomahawkUtils::RoundedCorners, desiredSize, true ); return avatar; } } @@ -489,17 +492,20 @@ Result::setFileId( unsigned int id ) } -QPointer +Tomahawk::ResultProvider* Result::resolvedBy() const { - return m_resolvedBy; + if ( !m_collection.isNull() ) + return m_collection.data(); + + return m_resolver.data(); } void -Result::setResolvedBy( Tomahawk::Resolver* resolver ) +Result::setResolvedByResolver( Tomahawk::Resolver* resolver ) { - m_resolvedBy = QPointer< Tomahawk::Resolver >( resolver ); + m_resolver = QPointer< Tomahawk::Resolver >( resolver ); } diff --git a/src/libtomahawk/Result.h b/src/libtomahawk/Result.h index 5471c7916..eac71a99d 100644 --- a/src/libtomahawk/Result.h +++ b/src/libtomahawk/Result.h @@ -20,16 +20,17 @@ #ifndef RESULT_H #define RESULT_H -#include -#include -#include -#include - +#include "ResultProvider.h" #include "utils/TomahawkUtils.h" #include "Typedefs.h" #include "DllMacro.h" +#include +#include +#include +#include + class MetadataEditor; namespace Tomahawk @@ -71,15 +72,27 @@ public: QString toString() const; Tomahawk::query_ptr toQuery(); - QPointer resolvedBy() const; - void setResolvedBy( Tomahawk::Resolver* resolver ); + /** + * Associate the used collection for this result. + * + * @param emitOnlineEvents disableing this will not emit statusChanged anymore thus the query will not update (use with care!, only when this is the sole result) + */ + void setResolvedByCollection( const Tomahawk::collection_ptr& collection, bool emitOnlineEvents = true ); + collection_ptr resolvedByCollection() const; + + QPointer< Tomahawk::Resolver > resolvedByResolver() const; + void setResolvedByResolver( Tomahawk::Resolver* resolver ); + + /** + * This is very bad. ResultProvider is not a QObject and thus can not be tracked by a qt smart pointer ... :-( + */ + ResultProvider* resolvedBy() const; float score() const; RID id() const; bool isOnline() const; bool playable() const; - collection_ptr collection() const; QString url() const; /** * Has the given url been checked that it is accessible/valid. @@ -101,12 +114,7 @@ public: void setScore( float score ); void setFileId( unsigned int id ); void setRID( RID id ) { m_rid = id; } - /** - * Associate the used collection for this result. - * - * @param emitOnlineEvents disableing this will not emit statusChanged anymore thus the query will not update (use with care!, only when this is the sole result) - */ - void setCollection( const Tomahawk::collection_ptr& collection, bool emitOnlineEvents = true ); + void setFriendlySource( const QString& s ); void setPurchaseUrl( const QString& u ); void setLinkUrl( const QString& u ); @@ -143,8 +151,8 @@ private: explicit Result(); mutable RID m_rid; - collection_ptr m_collection; - QPointer< Tomahawk::Resolver > m_resolvedBy; + collection_wptr m_collection; + QPointer< Tomahawk::Resolver > m_resolver; QString m_url; QString m_purchaseUrl; diff --git a/src/libtomahawk/audio/AudioEngine.cpp b/src/libtomahawk/audio/AudioEngine.cpp index 7f4faef75..f2ccf0167 100644 --- a/src/libtomahawk/audio/AudioEngine.cpp +++ b/src/libtomahawk/audio/AudioEngine.cpp @@ -867,7 +867,7 @@ AudioEngine::play( const QUrl& url ) } result->setScore( 1.0 ); - result->setCollection( SourceList::instance()->getLocal()->collections().first(), false ); + result->setResolvedByCollection( SourceList::instance()->getLocal()->collections().first(), false ); // Tomahawk::query_ptr qry = Tomahawk::Query::get( t ); playItem( playlistinterface_ptr(), result, query_ptr() ); diff --git a/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp b/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp index bff5c06c3..866f5153a 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp +++ b/src/libtomahawk/database/DatabaseCommand_AllTracks.cpp @@ -162,7 +162,7 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi ) result->setModificationTime( modificationTime ); result->setMimetype( mimetype ); result->setScore( 1.0f ); - result->setCollection( s->dbCollection(), false ); + result->setResolvedByCollection( s->dbCollection(), false ); ql << Tomahawk::Query::getFixed( t, result ); } diff --git a/src/libtomahawk/database/DatabaseCommand_Resolve.cpp b/src/libtomahawk/database/DatabaseCommand_Resolve.cpp index e001227af..89de13781 100644 --- a/src/libtomahawk/database/DatabaseCommand_Resolve.cpp +++ b/src/libtomahawk/database/DatabaseCommand_Resolve.cpp @@ -59,7 +59,7 @@ DatabaseCommand_Resolve::exec( DatabaseImpl* lib ) tDebug() << "Using result-hint to speed up resolving:" << m_query->resultHint(); Tomahawk::result_ptr result = lib->resultFromHint( m_query ); - if ( result && ( !result->collection() || result->collection()->source()->isOnline() ) ) + if ( result && ( !result->resolvedByCollection() || result->resolvedByCollection()->source()->isOnline() ) ) { QList res; res << result; @@ -164,7 +164,7 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib ) result->setMimetype( files_query.value( 4 ).toString() ); result->setBitrate( files_query.value( 6 ).toUInt() ); result->setRID( uuid() ); - result->setCollection( s->dbCollection() ); + result->setResolvedByCollection( s->dbCollection() ); res << result; } @@ -277,7 +277,7 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib ) result->setMimetype( files_query.value( 4 ).toString() ); result->setBitrate( files_query.value( 6 ).toUInt() ); result->setRID( uuid() ); - result->setCollection( s->dbCollection() ); + result->setResolvedByCollection( s->dbCollection() ); for ( int k = 0; k < trackPairs.count(); k++ ) { diff --git a/src/libtomahawk/database/DatabaseImpl.cpp b/src/libtomahawk/database/DatabaseImpl.cpp index 323af70ea..1ca1de283 100644 --- a/src/libtomahawk/database/DatabaseImpl.cpp +++ b/src/libtomahawk/database/DatabaseImpl.cpp @@ -322,7 +322,7 @@ Tomahawk::DatabaseImpl::file( int fid ) r->setSize( query.value( 2 ).toUInt() ); r->setMimetype( query.value( 4 ).toString() ); r->setBitrate( query.value( 6 ).toUInt() ); - r->setCollection( s->dbCollection() ); + r->setResolvedByCollection( s->dbCollection() ); r->setScore( 1.0 ); r->setFileId( fid ); } @@ -724,7 +724,7 @@ Tomahawk::DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery ) res->setBitrate( query.value( 6 ).toInt() ); res->setScore( 1.0 ); res->setRID( uuid() ); - res->setCollection( s->dbCollection() ); + res->setResolvedByCollection( s->dbCollection() ); } return res; diff --git a/src/libtomahawk/database/DatabaseResolver.cpp b/src/libtomahawk/database/DatabaseResolver.cpp index 7dd9f5828..4204f13b3 100644 --- a/src/libtomahawk/database/DatabaseResolver.cpp +++ b/src/libtomahawk/database/DatabaseResolver.cpp @@ -57,7 +57,7 @@ DatabaseResolver::gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_p tDebug( LOGVERBOSE ) << Q_FUNC_INFO << qid << results.length(); foreach ( const Tomahawk::result_ptr& r, results ) - r->setResolvedBy( this ); + r->setResolvedByResolver( this ); Tomahawk::Pipeline::instance()->reportResults( qid, results ); } diff --git a/src/libtomahawk/filemetadata/MetadataEditor.cpp b/src/libtomahawk/filemetadata/MetadataEditor.cpp index 963323112..6ae49d499 100644 --- a/src/libtomahawk/filemetadata/MetadataEditor.cpp +++ b/src/libtomahawk/filemetadata/MetadataEditor.cpp @@ -240,7 +240,7 @@ MetadataEditor::loadResult( const Tomahawk::result_ptr& result ) return; m_result = result; - setEditable( result->collection() && result->collection()->source()->isLocal() ); + setEditable( result->resolvedByCollection() && result->resolvedByCollection()->source()->isLocal() ); setTitle( result->track()->track() ); setArtist( result->track()->artist() ); @@ -250,7 +250,7 @@ MetadataEditor::loadResult( const Tomahawk::result_ptr& result ) setYear( result->track()->year() ); setBitrate( result->bitrate() ); - if ( result->collection() && result->collection()->source()->isLocal() ) + if ( result->resolvedByCollection() && result->resolvedByCollection()->source()->isLocal() ) { QString furl = m_result->url(); if ( furl.startsWith( "file://" ) ) diff --git a/src/libtomahawk/playlist/TreeProxyModel.cpp b/src/libtomahawk/playlist/TreeProxyModel.cpp index 21ae669af..75541bf63 100644 --- a/src/libtomahawk/playlist/TreeProxyModel.cpp +++ b/src/libtomahawk/playlist/TreeProxyModel.cpp @@ -238,8 +238,8 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent if ( !item->result()->isOnline() && ti->result()->isOnline() ) return false; - if ( ( item->result()->collection().isNull() || !item->result()->collection()->source()->isLocal() ) && - !ti->result()->collection().isNull() && ti->result()->collection()->source()->isLocal() ) + if ( ( item->result()->resolvedByCollection().isNull() || !item->result()->resolvedByCollection()->source()->isLocal() ) && + !ti->result()->resolvedByCollection().isNull() && ti->result()->resolvedByCollection()->source()->isLocal() ) { return false; } diff --git a/src/libtomahawk/resolvers/JSResolver.cpp b/src/libtomahawk/resolvers/JSResolver.cpp index 4d6dd43d3..ae1dd13b4 100644 --- a/src/libtomahawk/resolvers/JSResolver.cpp +++ b/src/libtomahawk/resolvers/JSResolver.cpp @@ -594,7 +594,7 @@ JSResolver::parseResultVariantList( const QVariantList& reslist ) Q_ASSERT( !rp->mimetype().isEmpty() ); } - rp->setResolvedBy( this ); + rp->setResolvedByResolver( this ); // find collection @@ -613,7 +613,7 @@ JSResolver::parseResultVariantList( const QVariantList& reslist ) } if ( !collection.isNull() ) { - rp->setCollection( collection ); + rp->setResolvedByCollection( collection ); } } diff --git a/src/libtomahawk/resolvers/JSResolverHelper.cpp b/src/libtomahawk/resolvers/JSResolverHelper.cpp index 3f7e02b3d..5eb5e155e 100644 --- a/src/libtomahawk/resolvers/JSResolverHelper.cpp +++ b/src/libtomahawk/resolvers/JSResolverHelper.cpp @@ -233,7 +233,7 @@ JSResolverHelper::addAlbumTrackResults( const QVariantMap& results ) foreach ( const Tomahawk::result_ptr& result, tracks ) { result->setScore( 1.0 ); - result->setCollection( collection ); + result->setResolvedByCollection( collection ); queries.append( result->toQuery() ); } diff --git a/src/libtomahawk/resolvers/ScriptResolver.cpp b/src/libtomahawk/resolvers/ScriptResolver.cpp index 718ea906c..f7a153078 100644 --- a/src/libtomahawk/resolvers/ScriptResolver.cpp +++ b/src/libtomahawk/resolvers/ScriptResolver.cpp @@ -327,7 +327,7 @@ ScriptResolver::handleMsg( const QByteArray& msg ) Q_ASSERT( !rp->mimetype().isEmpty() ); } - rp->setResolvedBy( this ); + rp->setResolvedByResolver( this ); results << rp; } diff --git a/src/libtomahawk/viewpages/SearchViewPage.cpp b/src/libtomahawk/viewpages/SearchViewPage.cpp index 4b9401d62..d1247eb53 100644 --- a/src/libtomahawk/viewpages/SearchViewPage.cpp +++ b/src/libtomahawk/viewpages/SearchViewPage.cpp @@ -302,7 +302,7 @@ SearchWidget::onResultsFound( const QList& results ) foreach( const Tomahawk::result_ptr& result, results ) { - if ( !result->collection().isNull() && !result->isOnline() ) + if ( !result->resolvedByCollection().isNull() && !result->isOnline() ) continue; QList< Tomahawk::result_ptr > rl; diff --git a/src/tomahawk/AudioControls.cpp b/src/tomahawk/AudioControls.cpp index e35a6bee6..ed6dc7df0 100644 --- a/src/tomahawk/AudioControls.cpp +++ b/src/tomahawk/AudioControls.cpp @@ -360,7 +360,7 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr result ) ui->ownerButton->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultResolver, TomahawkUtils::Original, QSize( 34, 34 ) ) ); } - if ( QUrl( result->linkUrl() ).isValid() || !result->collection().isNull() ) + if ( QUrl( result->linkUrl() ).isValid() || !result->resolvedByCollection().isNull() ) ui->ownerButton->setCursor( Qt::PointingHandCursor ); else ui->ownerButton->setCursor( Qt::ArrowCursor ); @@ -791,12 +791,12 @@ AudioControls::onLoveButtonClicked( bool checked ) void AudioControls::onOwnerButtonClicked() { - if ( m_currentTrack->collection().isNull() ) + if ( m_currentTrack->resolvedByCollection().isNull() ) { QUrl url = QUrl( m_currentTrack->linkUrl() ); if ( url.isValid() ) QDesktopServices::openUrl( url ); } else - ViewManager::instance()->show( m_currentTrack->collection() ); + ViewManager::instance()->show( m_currentTrack->resolvedByCollection() ); }