mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
* Result uses a Track object internally.
This commit is contained in:
@@ -35,14 +35,15 @@
|
|||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
static QHash< QString, QWeakPointer< Result > > s_results;
|
static QHash< QString, result_wptr > s_results;
|
||||||
static QMutex s_mutex;
|
static QMutex s_mutex;
|
||||||
|
|
||||||
typedef QMap< QString, QPixmap > SourceIconCache;
|
typedef QMap< QString, QPixmap > SourceIconCache;
|
||||||
Q_GLOBAL_STATIC( SourceIconCache, sourceIconCache );
|
Q_GLOBAL_STATIC( SourceIconCache, sourceIconCache );
|
||||||
static QMutex s_sourceIconMutex;
|
static QMutex s_sourceIconMutex;
|
||||||
|
|
||||||
inline QString sourceCacheKey( Resolver* resolver, const QSize& size, TomahawkUtils::ImageMode style )
|
inline QString
|
||||||
|
sourceCacheKey( Resolver* resolver, const QSize& size, TomahawkUtils::ImageMode style )
|
||||||
{
|
{
|
||||||
QString str;
|
QString str;
|
||||||
QTextStream stream( &str );
|
QTextStream stream( &str );
|
||||||
@@ -78,12 +79,9 @@ Result::isCached( const QString& url )
|
|||||||
Result::Result( const QString& url )
|
Result::Result( const QString& url )
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_url( url )
|
, m_url( url )
|
||||||
, m_duration( 0 )
|
|
||||||
, m_bitrate( 0 )
|
, m_bitrate( 0 )
|
||||||
, m_size( 0 )
|
, m_size( 0 )
|
||||||
, m_albumpos( 0 )
|
|
||||||
, m_modtime( 0 )
|
, m_modtime( 0 )
|
||||||
, m_discnumber( 0 )
|
|
||||||
, m_year( 0 )
|
, m_year( 0 )
|
||||||
, m_score( 0 )
|
, m_score( 0 )
|
||||||
, m_trackId( 0 )
|
, m_trackId( 0 )
|
||||||
@@ -95,6 +93,7 @@ Result::Result( const QString& url )
|
|||||||
|
|
||||||
Result::~Result()
|
Result::~Result()
|
||||||
{
|
{
|
||||||
|
tDebug( LOGVERBOSE ) << Q_FUNC_INFO << toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -112,6 +111,13 @@ Result::deleteLater()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Result::isValid() const
|
||||||
|
{
|
||||||
|
return m_track && !m_track->artist().isEmpty() && !m_track->track().isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Result::onResolverRemoved( Tomahawk::Resolver* resolver )
|
Result::onResolverRemoved( Tomahawk::Resolver* resolver )
|
||||||
{
|
{
|
||||||
@@ -123,27 +129,6 @@ Result::onResolverRemoved( Tomahawk::Resolver* resolver )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
artist_ptr
|
|
||||||
Result::artist() const
|
|
||||||
{
|
|
||||||
return m_artist;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
artist_ptr
|
|
||||||
Result::composer() const
|
|
||||||
{
|
|
||||||
return m_composer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
album_ptr
|
|
||||||
Result::album() const
|
|
||||||
{
|
|
||||||
return m_album;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
collection_ptr
|
collection_ptr
|
||||||
Result::collection() const
|
Result::collection() const
|
||||||
{
|
{
|
||||||
@@ -185,25 +170,39 @@ Result::isOnline() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Result::playable() const
|
||||||
|
{
|
||||||
|
if ( collection() )
|
||||||
|
{
|
||||||
|
return collection()->source()->isOnline();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return score() > 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariant
|
QVariant
|
||||||
Result::toVariant() const
|
Result::toVariant() const
|
||||||
{
|
{
|
||||||
QVariantMap m;
|
QVariantMap m;
|
||||||
m.insert( "artist", artist()->name() );
|
m.insert( "artist", m_track->artist() );
|
||||||
m.insert( "album", album()->name() );
|
m.insert( "album", m_track->album() );
|
||||||
m.insert( "track", track() );
|
m.insert( "track", m_track->track() );
|
||||||
m.insert( "source", friendlySource() );
|
m.insert( "source", friendlySource() );
|
||||||
m.insert( "mimetype", mimetype() );
|
m.insert( "mimetype", mimetype() );
|
||||||
m.insert( "size", size() );
|
m.insert( "size", size() );
|
||||||
m.insert( "bitrate", bitrate() );
|
m.insert( "bitrate", bitrate() );
|
||||||
m.insert( "duration", duration() );
|
m.insert( "duration", m_track->duration() );
|
||||||
m.insert( "score", score() );
|
m.insert( "score", score() );
|
||||||
m.insert( "sid", id() );
|
m.insert( "sid", id() );
|
||||||
m.insert( "discnumber", discnumber() );
|
m.insert( "discnumber", m_track->discnumber() );
|
||||||
m.insert( "albumpos", albumpos() );
|
m.insert( "albumpos", m_track->albumpos() );
|
||||||
|
|
||||||
if ( !composer().isNull() )
|
if ( !m_track->composer().isEmpty() )
|
||||||
m.insert( "composer", composer()->name() );
|
m.insert( "composer", m_track->composer() );
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@@ -215,9 +214,9 @@ Result::toString() const
|
|||||||
return QString( "Result(%1, score: %2) %3 - %4%5 (%6)" )
|
return QString( "Result(%1, score: %2) %3 - %4%5 (%6)" )
|
||||||
.arg( id() )
|
.arg( id() )
|
||||||
.arg( score() )
|
.arg( score() )
|
||||||
.arg( artist().isNull() ? QString() : artist()->name() )
|
.arg( track()->artist() )
|
||||||
.arg( track() )
|
.arg( track()->track() )
|
||||||
.arg( album().isNull() || album()->name().isEmpty() ? "" : QString( " on %1" ).arg( album()->name() ) )
|
.arg( track()->album().isEmpty() ? "" : QString( " on %1" ).arg( track()->album() ) )
|
||||||
.arg( url() );
|
.arg( url() );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,25 +226,21 @@ Result::toQuery()
|
|||||||
{
|
{
|
||||||
if ( m_query.isNull() )
|
if ( m_query.isNull() )
|
||||||
{
|
{
|
||||||
m_query = Tomahawk::Query::get( artist()->name(), track(), album()->name() );
|
query_ptr query = Tomahawk::Query::get( m_track );
|
||||||
|
if ( !query )
|
||||||
if ( m_query.isNull() )
|
|
||||||
return query_ptr();
|
return query_ptr();
|
||||||
|
|
||||||
m_query->setAlbumPos( albumpos() );
|
m_query = query->weakRef();
|
||||||
m_query->setDiscNumber( discnumber() );
|
|
||||||
m_query->setDuration( duration() );
|
|
||||||
if ( !composer().isNull() )
|
|
||||||
m_query->setComposer( composer()->name() );
|
|
||||||
|
|
||||||
QList<Tomahawk::result_ptr> rl;
|
QList<Tomahawk::result_ptr> rl;
|
||||||
rl << Result::get( m_url );
|
rl << Result::get( m_url );
|
||||||
|
|
||||||
m_query->addResults( rl );
|
query->addResults( rl );
|
||||||
m_query->setResolveFinished( true );
|
query->setResolveFinished( true );
|
||||||
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_query;
|
return m_query.toStrongRef();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -273,27 +268,6 @@ Result::onOffline()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Result::setArtist( const Tomahawk::artist_ptr& artist )
|
|
||||||
{
|
|
||||||
m_artist = artist;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Result::setComposer( const Tomahawk::artist_ptr &composer )
|
|
||||||
{
|
|
||||||
m_composer = composer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Result::setAlbum( const Tomahawk::album_ptr& album )
|
|
||||||
{
|
|
||||||
m_album = album;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Result::setCollection( const Tomahawk::collection_ptr& collection )
|
Result::setCollection( const Tomahawk::collection_ptr& collection )
|
||||||
{
|
{
|
||||||
@@ -391,6 +365,13 @@ Result::setResolvedBy( Tomahawk::Resolver* resolver )
|
|||||||
void
|
void
|
||||||
Result::doneEditing()
|
Result::doneEditing()
|
||||||
{
|
{
|
||||||
m_query.clear();
|
// m_query.clear();
|
||||||
emit updated();
|
emit updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
track_ptr
|
||||||
|
Result::track() const
|
||||||
|
{
|
||||||
|
return m_track;
|
||||||
|
}
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
#include "utils/TomahawkUtils.h"
|
#include "utils/TomahawkUtils.h"
|
||||||
|
#include "Track.h"
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
@@ -57,6 +58,8 @@ public:
|
|||||||
static bool isCached( const QString& url );
|
static bool isCached( const QString& url );
|
||||||
virtual ~Result();
|
virtual ~Result();
|
||||||
|
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
QVariant toVariant() const;
|
QVariant toVariant() const;
|
||||||
QString toString() const;
|
QString toString() const;
|
||||||
Tomahawk::query_ptr toQuery();
|
Tomahawk::query_ptr toQuery();
|
||||||
@@ -67,12 +70,9 @@ public:
|
|||||||
float score() const;
|
float score() const;
|
||||||
RID id() const;
|
RID id() const;
|
||||||
bool isOnline() const;
|
bool isOnline() const;
|
||||||
|
bool playable() const;
|
||||||
|
|
||||||
collection_ptr collection() const;
|
collection_ptr collection() const;
|
||||||
Tomahawk::artist_ptr artist() const;
|
|
||||||
Tomahawk::album_ptr album() const;
|
|
||||||
Tomahawk::artist_ptr composer() const;
|
|
||||||
QString track() const { return m_track; }
|
|
||||||
QString url() const { return m_url; }
|
QString url() const { return m_url; }
|
||||||
QString mimetype() const { return m_mimetype; }
|
QString mimetype() const { return m_mimetype; }
|
||||||
QString friendlySource() const;
|
QString friendlySource() const;
|
||||||
@@ -81,13 +81,10 @@ public:
|
|||||||
|
|
||||||
QPixmap sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize = QSize() ) const;
|
QPixmap sourceIcon( TomahawkUtils::ImageMode style, const QSize& desiredSize = QSize() ) const;
|
||||||
|
|
||||||
unsigned int duration() const { return m_duration; }
|
|
||||||
unsigned int bitrate() const { return m_bitrate; }
|
unsigned int bitrate() const { return m_bitrate; }
|
||||||
unsigned int size() const { return m_size; }
|
unsigned int size() const { return m_size; }
|
||||||
unsigned int albumpos() const { return m_albumpos; }
|
|
||||||
unsigned int modificationTime() const { return m_modtime; }
|
unsigned int modificationTime() const { return m_modtime; }
|
||||||
int year() const { return m_year; }
|
int year() const { return m_year; }
|
||||||
unsigned int discnumber() const { return m_discnumber; }
|
|
||||||
|
|
||||||
void setScore( float score ) { m_score = score; }
|
void setScore( float score ) { m_score = score; }
|
||||||
void setTrackId( unsigned int id ) { m_trackId = id; }
|
void setTrackId( unsigned int id ) { m_trackId = id; }
|
||||||
@@ -97,18 +94,13 @@ public:
|
|||||||
void setFriendlySource( const QString& s ) { m_friendlySource = s; }
|
void setFriendlySource( const QString& s ) { m_friendlySource = s; }
|
||||||
void setPurchaseUrl( const QString& u ) { m_purchaseUrl = u; }
|
void setPurchaseUrl( const QString& u ) { m_purchaseUrl = u; }
|
||||||
void setLinkUrl( const QString& u ) { m_linkUrl = u; }
|
void setLinkUrl( const QString& u ) { m_linkUrl = u; }
|
||||||
void setArtist( const Tomahawk::artist_ptr& artist );
|
|
||||||
void setAlbum( const Tomahawk::album_ptr& album );
|
|
||||||
void setComposer( const Tomahawk::artist_ptr& composer );
|
|
||||||
void setTrack( const QString& track ) { m_track = track; }
|
|
||||||
void setMimetype( const QString& mimetype ) { m_mimetype = mimetype; }
|
void setMimetype( const QString& mimetype ) { m_mimetype = mimetype; }
|
||||||
void setDuration( unsigned int duration ) { m_duration = duration; }
|
|
||||||
void setBitrate( unsigned int bitrate ) { m_bitrate = bitrate; }
|
void setBitrate( unsigned int bitrate ) { m_bitrate = bitrate; }
|
||||||
void setSize( unsigned int size ) { m_size = size; }
|
void setSize( unsigned int size ) { m_size = size; }
|
||||||
void setAlbumPos( unsigned int albumpos ) { m_albumpos = albumpos; }
|
|
||||||
void setModificationTime( unsigned int modtime ) { m_modtime = modtime; }
|
void setModificationTime( unsigned int modtime ) { m_modtime = modtime; }
|
||||||
void setYear( unsigned int year ) { m_year = year; }
|
void setYear( unsigned int year ) { m_year = year; }
|
||||||
void setDiscNumber( unsigned int discnumber ) { m_discnumber = discnumber; }
|
|
||||||
|
void setTrack( const track_ptr& track ) { m_track = track; }
|
||||||
|
|
||||||
QVariantMap attributes() const { return m_attributes; }
|
QVariantMap attributes() const { return m_attributes; }
|
||||||
void setAttributes( const QVariantMap& map ) { m_attributes = map; updateAttributes(); }
|
void setAttributes( const QVariantMap& map ) { m_attributes = map; updateAttributes(); }
|
||||||
@@ -116,6 +108,8 @@ public:
|
|||||||
unsigned int trackId() const { return m_trackId; }
|
unsigned int trackId() const { return m_trackId; }
|
||||||
unsigned int fileId() const { return m_fileId; }
|
unsigned int fileId() const { return m_fileId; }
|
||||||
|
|
||||||
|
track_ptr track() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void deleteLater();
|
void deleteLater();
|
||||||
|
|
||||||
@@ -140,30 +134,25 @@ private:
|
|||||||
|
|
||||||
mutable RID m_rid;
|
mutable RID m_rid;
|
||||||
collection_ptr m_collection;
|
collection_ptr m_collection;
|
||||||
Tomahawk::query_ptr m_query;
|
|
||||||
QPointer< Tomahawk::Resolver > m_resolvedBy;
|
QPointer< Tomahawk::Resolver > m_resolvedBy;
|
||||||
|
|
||||||
Tomahawk::artist_ptr m_artist;
|
|
||||||
Tomahawk::album_ptr m_album;
|
|
||||||
Tomahawk::artist_ptr m_composer;
|
|
||||||
QString m_track;
|
|
||||||
QString m_url;
|
QString m_url;
|
||||||
QString m_purchaseUrl;
|
QString m_purchaseUrl;
|
||||||
QString m_linkUrl;
|
QString m_linkUrl;
|
||||||
QString m_mimetype;
|
QString m_mimetype;
|
||||||
QString m_friendlySource;
|
QString m_friendlySource;
|
||||||
|
|
||||||
unsigned int m_duration;
|
|
||||||
unsigned int m_bitrate;
|
unsigned int m_bitrate;
|
||||||
unsigned int m_size;
|
unsigned int m_size;
|
||||||
unsigned int m_albumpos;
|
|
||||||
unsigned int m_modtime;
|
unsigned int m_modtime;
|
||||||
unsigned int m_discnumber;
|
|
||||||
int m_year;
|
int m_year;
|
||||||
float m_score;
|
float m_score;
|
||||||
|
|
||||||
QVariantMap m_attributes;
|
QVariantMap m_attributes;
|
||||||
unsigned int m_trackId, m_fileId;
|
unsigned int m_trackId, m_fileId;
|
||||||
|
|
||||||
|
track_ptr m_track;
|
||||||
|
query_wptr m_query;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //ns
|
} //ns
|
||||||
|
Reference in New Issue
Block a user