1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-18 20:04:00 +02:00

Make it more obvious that a result can come from a resolver or a collection

This commit is contained in:
Dominik Schmidt
2015-01-06 14:41:06 +01:00
parent 5d322c12cb
commit 8d4a6c814e
18 changed files with 85 additions and 66 deletions

View File

@@ -99,7 +99,7 @@ Api_v1_5::playback( QxtWebRequestEvent* event, const QString& command )
trackInfo.insert( "paused", AudioEngine::instance()->isPaused() ); trackInfo.insert( "paused", AudioEngine::instance()->isPaused() );
trackInfo.insert( "position", AudioEngine::instance()->currentTime() / 1000 ); trackInfo.insert( "position", AudioEngine::instance()->currentTime() / 1000 );
trackInfo.insert( "bitrate", currentTrack->bitrate() ); trackInfo.insert( "bitrate", currentTrack->bitrate() );
if ( !currentTrack->resolvedBy().isNull() ) { if ( currentTrack->resolvedBy() ) {
QString resolverName = currentTrack->resolvedBy()->name(); QString resolverName = currentTrack->resolvedBy()->name();
trackInfo.insert( "resolvedBy", resolverName ); trackInfo.insert( "resolvedBy", resolverName );
} else { } else {

View File

@@ -975,8 +975,8 @@ DropJob::removeRemoteSources()
foreach ( const Tomahawk::result_ptr& result, item->results() ) foreach ( const Tomahawk::result_ptr& result, item->results() )
{ {
if ( !result->collection().isNull() && !result->collection()->source().isNull() if ( !result->resolvedByCollection().isNull() && !result->resolvedByCollection()->source().isNull()
&& result->collection()->source()->isLocal() ) && result->resolvedByCollection()->source()->isLocal() )
{ {
list.append( item ); list.append( item );
break; break;

View File

@@ -335,13 +335,18 @@ Pipeline::reportResults( QID qid, const QList< result_ptr >& results )
return; return;
if ( !d->qids.contains( qid ) ) if ( !d->qids.contains( qid ) )
{ {
if ( results.length() > 0 && !results[0]->resolvedBy().isNull() ) if ( results.length() > 0 )
{
tDebug() << "Result arrived too late for:" << qid << "by" << results[0]->resolvedBy()->name();
}
else
{ {
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; tDebug() << "Result arrived too late for:" << qid;
}
} }
return; return;
} }

View File

@@ -413,7 +413,7 @@ Query::resultSorter( const result_ptr& left, const result_ptr& right )
{ {
return true; return true;
}*/ }*/
if ( right->collection() && right->collection()->source()->isLocal() ) if ( right->resolvedByCollection() && right->resolvedByCollection()->source()->isLocal() )
{ {
return false; return false;
} }

View File

@@ -34,6 +34,7 @@
#include "PlaylistInterface.h" #include "PlaylistInterface.h"
#include "Source.h" #include "Source.h"
#include "Track.h" #include "Track.h"
#include "Typedefs.h"
using namespace Tomahawk; using namespace Tomahawk;
@@ -132,16 +133,16 @@ Result::deleteLater()
void void
Result::onResolverRemoved( Tomahawk::Resolver* resolver ) Result::onResolverRemoved( Tomahawk::Resolver* resolver )
{ {
if ( m_resolvedBy.data() == resolver ) if ( m_resolver.data() == resolver )
{ {
m_resolvedBy = 0; m_resolver = 0;
emit statusChanged(); emit statusChanged();
} }
} }
collection_ptr collection_ptr
Result::collection() const Result::resolvedByCollection() const
{ {
return m_collection; return m_collection;
} }
@@ -188,13 +189,13 @@ Result::id() const
bool bool
Result::isOnline() const Result::isOnline() const
{ {
if ( !collection().isNull() ) if ( !resolvedByCollection().isNull() )
{ {
return collection()->source()->isOnline(); return resolvedByCollection()->source()->isOnline();
} }
else else
{ {
return !m_resolvedBy.isNull(); return !m_resolver.isNull();
} }
} }
@@ -202,9 +203,9 @@ Result::isOnline() const
bool bool
Result::playable() const Result::playable() const
{ {
if ( collection() ) if ( resolvedByCollection() )
{ {
return collection()->source()->isOnline(); return resolvedByCollection()->source()->isOnline();
} }
else else
{ {
@@ -297,17 +298,19 @@ Result::onOffline()
void void
Result::setCollection( const Tomahawk::collection_ptr& collection , bool emitOnlineEvents ) Result::setResolvedByCollection( const Tomahawk::collection_ptr& collection , bool emitOnlineEvents )
{ {
m_collection = collection; m_collection = collection;
if ( emitOnlineEvents ) if ( emitOnlineEvents )
{ {
connect( m_collection->source().data(), SIGNAL( online() ), SLOT( onOnline() ), Qt::QueuedConnection ); connect( 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( offline() ), SLOT( onOffline() ), Qt::QueuedConnection );
} }
} }
void void
Result::setFriendlySource(const QString& s) Result::setFriendlySource(const QString& s)
{ {
@@ -381,12 +384,12 @@ Result::fileId() const
QString QString
Result::friendlySource() const Result::friendlySource() const
{ {
if ( collection().isNull() ) if ( resolvedByCollection().isNull() )
{ {
return m_friendlySource; return m_friendlySource;
} }
else else
return collection()->source()->friendlyName(); return resolvedByCollection()->source()->friendlyName();
} }
@@ -407,9 +410,9 @@ Result::linkUrl() const
QPixmap QPixmap
Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) const 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 ) if ( !resolver )
{ {
return QPixmap(); return QPixmap();
@@ -418,7 +421,7 @@ Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) c
{ {
QMutexLocker l( &s_sourceIconMutex ); 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 ) ) if ( !sourceIconCache()->contains( key ) )
{ {
QPixmap pixmap = resolver->icon( desiredSize ); QPixmap pixmap = resolver->icon( desiredSize );
@@ -448,7 +451,7 @@ Result::sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize ) c
} }
else else
{ {
QPixmap avatar = collection()->source()->avatar( TomahawkUtils::RoundedCorners, desiredSize, true ); QPixmap avatar = resolvedByCollection()->source()->avatar( TomahawkUtils::RoundedCorners, desiredSize, true );
return avatar; return avatar;
} }
} }
@@ -489,17 +492,20 @@ Result::setFileId( unsigned int id )
} }
QPointer<Tomahawk::Resolver> Tomahawk::ResultProvider*
Result::resolvedBy() const Result::resolvedBy() const
{ {
return m_resolvedBy; if ( !m_collection.isNull() )
return m_collection.data();
return m_resolver.data();
} }
void void
Result::setResolvedBy( Tomahawk::Resolver* resolver ) Result::setResolvedByResolver( Tomahawk::Resolver* resolver )
{ {
m_resolvedBy = QPointer< Tomahawk::Resolver >( resolver ); m_resolver = QPointer< Tomahawk::Resolver >( resolver );
} }

View File

@@ -20,16 +20,17 @@
#ifndef RESULT_H #ifndef RESULT_H
#define RESULT_H #define RESULT_H
#include <QObject> #include "ResultProvider.h"
#include <QPixmap>
#include <QPointer>
#include <QVariant>
#include "utils/TomahawkUtils.h" #include "utils/TomahawkUtils.h"
#include "Typedefs.h" #include "Typedefs.h"
#include "DllMacro.h" #include "DllMacro.h"
#include <QObject>
#include <QPixmap>
#include <QPointer>
#include <QVariant>
class MetadataEditor; class MetadataEditor;
namespace Tomahawk namespace Tomahawk
@@ -71,15 +72,27 @@ public:
QString toString() const; QString toString() const;
Tomahawk::query_ptr toQuery(); Tomahawk::query_ptr toQuery();
QPointer<Tomahawk::Resolver> 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; float score() const;
RID id() const; RID id() const;
bool isOnline() const; bool isOnline() const;
bool playable() const; bool playable() const;
collection_ptr collection() const;
QString url() const; QString url() const;
/** /**
* Has the given url been checked that it is accessible/valid. * Has the given url been checked that it is accessible/valid.
@@ -101,12 +114,7 @@ public:
void setScore( float score ); void setScore( float score );
void setFileId( unsigned int id ); void setFileId( unsigned int id );
void setRID( RID id ) { m_rid = 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 setFriendlySource( const QString& s );
void setPurchaseUrl( const QString& u ); void setPurchaseUrl( const QString& u );
void setLinkUrl( const QString& u ); void setLinkUrl( const QString& u );
@@ -143,8 +151,8 @@ private:
explicit Result(); explicit Result();
mutable RID m_rid; mutable RID m_rid;
collection_ptr m_collection; collection_wptr m_collection;
QPointer< Tomahawk::Resolver > m_resolvedBy; QPointer< Tomahawk::Resolver > m_resolver;
QString m_url; QString m_url;
QString m_purchaseUrl; QString m_purchaseUrl;

View File

@@ -867,7 +867,7 @@ AudioEngine::play( const QUrl& url )
} }
result->setScore( 1.0 ); 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 ); // Tomahawk::query_ptr qry = Tomahawk::Query::get( t );
playItem( playlistinterface_ptr(), result, query_ptr() ); playItem( playlistinterface_ptr(), result, query_ptr() );

View File

@@ -162,7 +162,7 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
result->setModificationTime( modificationTime ); result->setModificationTime( modificationTime );
result->setMimetype( mimetype ); result->setMimetype( mimetype );
result->setScore( 1.0f ); result->setScore( 1.0f );
result->setCollection( s->dbCollection(), false ); result->setResolvedByCollection( s->dbCollection(), false );
ql << Tomahawk::Query::getFixed( t, result ); ql << Tomahawk::Query::getFixed( t, result );
} }

View File

@@ -59,7 +59,7 @@ DatabaseCommand_Resolve::exec( DatabaseImpl* lib )
tDebug() << "Using result-hint to speed up resolving:" << m_query->resultHint(); tDebug() << "Using result-hint to speed up resolving:" << m_query->resultHint();
Tomahawk::result_ptr result = lib->resultFromHint( m_query ); 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<Tomahawk::result_ptr> res; QList<Tomahawk::result_ptr> res;
res << result; res << result;
@@ -164,7 +164,7 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib )
result->setMimetype( files_query.value( 4 ).toString() ); result->setMimetype( files_query.value( 4 ).toString() );
result->setBitrate( files_query.value( 6 ).toUInt() ); result->setBitrate( files_query.value( 6 ).toUInt() );
result->setRID( uuid() ); result->setRID( uuid() );
result->setCollection( s->dbCollection() ); result->setResolvedByCollection( s->dbCollection() );
res << result; res << result;
} }
@@ -277,7 +277,7 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib )
result->setMimetype( files_query.value( 4 ).toString() ); result->setMimetype( files_query.value( 4 ).toString() );
result->setBitrate( files_query.value( 6 ).toUInt() ); result->setBitrate( files_query.value( 6 ).toUInt() );
result->setRID( uuid() ); result->setRID( uuid() );
result->setCollection( s->dbCollection() ); result->setResolvedByCollection( s->dbCollection() );
for ( int k = 0; k < trackPairs.count(); k++ ) for ( int k = 0; k < trackPairs.count(); k++ )
{ {

View File

@@ -322,7 +322,7 @@ Tomahawk::DatabaseImpl::file( int fid )
r->setSize( query.value( 2 ).toUInt() ); r->setSize( query.value( 2 ).toUInt() );
r->setMimetype( query.value( 4 ).toString() ); r->setMimetype( query.value( 4 ).toString() );
r->setBitrate( query.value( 6 ).toUInt() ); r->setBitrate( query.value( 6 ).toUInt() );
r->setCollection( s->dbCollection() ); r->setResolvedByCollection( s->dbCollection() );
r->setScore( 1.0 ); r->setScore( 1.0 );
r->setFileId( fid ); r->setFileId( fid );
} }
@@ -724,7 +724,7 @@ Tomahawk::DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery )
res->setBitrate( query.value( 6 ).toInt() ); res->setBitrate( query.value( 6 ).toInt() );
res->setScore( 1.0 ); res->setScore( 1.0 );
res->setRID( uuid() ); res->setRID( uuid() );
res->setCollection( s->dbCollection() ); res->setResolvedByCollection( s->dbCollection() );
} }
return res; return res;

View File

@@ -57,7 +57,7 @@ DatabaseResolver::gotResults( const Tomahawk::QID qid, QList< Tomahawk::result_p
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << qid << results.length(); tDebug( LOGVERBOSE ) << Q_FUNC_INFO << qid << results.length();
foreach ( const Tomahawk::result_ptr& r, results ) foreach ( const Tomahawk::result_ptr& r, results )
r->setResolvedBy( this ); r->setResolvedByResolver( this );
Tomahawk::Pipeline::instance()->reportResults( qid, results ); Tomahawk::Pipeline::instance()->reportResults( qid, results );
} }

View File

@@ -240,7 +240,7 @@ MetadataEditor::loadResult( const Tomahawk::result_ptr& result )
return; return;
m_result = result; m_result = result;
setEditable( result->collection() && result->collection()->source()->isLocal() ); setEditable( result->resolvedByCollection() && result->resolvedByCollection()->source()->isLocal() );
setTitle( result->track()->track() ); setTitle( result->track()->track() );
setArtist( result->track()->artist() ); setArtist( result->track()->artist() );
@@ -250,7 +250,7 @@ MetadataEditor::loadResult( const Tomahawk::result_ptr& result )
setYear( result->track()->year() ); setYear( result->track()->year() );
setBitrate( result->bitrate() ); setBitrate( result->bitrate() );
if ( result->collection() && result->collection()->source()->isLocal() ) if ( result->resolvedByCollection() && result->resolvedByCollection()->source()->isLocal() )
{ {
QString furl = m_result->url(); QString furl = m_result->url();
if ( furl.startsWith( "file://" ) ) if ( furl.startsWith( "file://" ) )

View File

@@ -238,8 +238,8 @@ TreeProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent
if ( !item->result()->isOnline() && ti->result()->isOnline() ) if ( !item->result()->isOnline() && ti->result()->isOnline() )
return false; return false;
if ( ( item->result()->collection().isNull() || !item->result()->collection()->source()->isLocal() ) && if ( ( item->result()->resolvedByCollection().isNull() || !item->result()->resolvedByCollection()->source()->isLocal() ) &&
!ti->result()->collection().isNull() && ti->result()->collection()->source()->isLocal() ) !ti->result()->resolvedByCollection().isNull() && ti->result()->resolvedByCollection()->source()->isLocal() )
{ {
return false; return false;
} }

View File

@@ -594,7 +594,7 @@ JSResolver::parseResultVariantList( const QVariantList& reslist )
Q_ASSERT( !rp->mimetype().isEmpty() ); Q_ASSERT( !rp->mimetype().isEmpty() );
} }
rp->setResolvedBy( this ); rp->setResolvedByResolver( this );
// find collection // find collection
@@ -613,7 +613,7 @@ JSResolver::parseResultVariantList( const QVariantList& reslist )
} }
if ( !collection.isNull() ) if ( !collection.isNull() )
{ {
rp->setCollection( collection ); rp->setResolvedByCollection( collection );
} }
} }

View File

@@ -233,7 +233,7 @@ JSResolverHelper::addAlbumTrackResults( const QVariantMap& results )
foreach ( const Tomahawk::result_ptr& result, tracks ) foreach ( const Tomahawk::result_ptr& result, tracks )
{ {
result->setScore( 1.0 ); result->setScore( 1.0 );
result->setCollection( collection ); result->setResolvedByCollection( collection );
queries.append( result->toQuery() ); queries.append( result->toQuery() );
} }

View File

@@ -327,7 +327,7 @@ ScriptResolver::handleMsg( const QByteArray& msg )
Q_ASSERT( !rp->mimetype().isEmpty() ); Q_ASSERT( !rp->mimetype().isEmpty() );
} }
rp->setResolvedBy( this ); rp->setResolvedByResolver( this );
results << rp; results << rp;
} }

View File

@@ -302,7 +302,7 @@ SearchWidget::onResultsFound( const QList<Tomahawk::result_ptr>& results )
foreach( const Tomahawk::result_ptr& result, results ) foreach( const Tomahawk::result_ptr& result, results )
{ {
if ( !result->collection().isNull() && !result->isOnline() ) if ( !result->resolvedByCollection().isNull() && !result->isOnline() )
continue; continue;
QList< Tomahawk::result_ptr > rl; QList< Tomahawk::result_ptr > rl;

View File

@@ -360,7 +360,7 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr result )
ui->ownerButton->setPixmap( TomahawkUtils::defaultPixmap( TomahawkUtils::DefaultResolver, TomahawkUtils::Original, QSize( 34, 34 ) ) ); 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 ); ui->ownerButton->setCursor( Qt::PointingHandCursor );
else else
ui->ownerButton->setCursor( Qt::ArrowCursor ); ui->ownerButton->setCursor( Qt::ArrowCursor );
@@ -791,12 +791,12 @@ AudioControls::onLoveButtonClicked( bool checked )
void void
AudioControls::onOwnerButtonClicked() AudioControls::onOwnerButtonClicked()
{ {
if ( m_currentTrack->collection().isNull() ) if ( m_currentTrack->resolvedByCollection().isNull() )
{ {
QUrl url = QUrl( m_currentTrack->linkUrl() ); QUrl url = QUrl( m_currentTrack->linkUrl() );
if ( url.isValid() ) if ( url.isValid() )
QDesktopServices::openUrl( url ); QDesktopServices::openUrl( url );
} }
else else
ViewManager::instance()->show( m_currentTrack->collection() ); ViewManager::instance()->show( m_currentTrack->resolvedByCollection() );
} }