1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-18 11:51:44 +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( "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 {

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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::Resolver>
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 );
}

View File

@@ -20,16 +20,17 @@
#ifndef RESULT_H
#define RESULT_H
#include <QObject>
#include <QPixmap>
#include <QPointer>
#include <QVariant>
#include "ResultProvider.h"
#include "utils/TomahawkUtils.h"
#include "Typedefs.h"
#include "DllMacro.h"
#include <QObject>
#include <QPixmap>
#include <QPointer>
#include <QVariant>
class MetadataEditor;
namespace Tomahawk
@@ -71,15 +72,27 @@ public:
QString toString() const;
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;
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;

View File

@@ -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() );

View File

@@ -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 );
}

View File

@@ -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<Tomahawk::result_ptr> 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++ )
{

View File

@@ -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;

View File

@@ -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 );
}

View File

@@ -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://" ) )

View File

@@ -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;
}

View File

@@ -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 );
}
}

View File

@@ -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() );
}

View File

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

View File

@@ -302,7 +302,7 @@ SearchWidget::onResultsFound( const QList<Tomahawk::result_ptr>& 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;

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 ) ) );
}
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() );
}