mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-23 01:09:42 +01:00
* Make results singletons, based on its url. Now we can call Result's toQuery() without re-resolving. Much nicer.
This commit is contained in:
parent
efaa1eb18f
commit
b9087ad7b7
@ -193,7 +193,7 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi )
|
||||
|
||||
Tomahawk::artist_ptr artistptr = Tomahawk::Artist::get( artistid, artist );
|
||||
Tomahawk::album_ptr albumptr = Tomahawk::Album::get( albumid, album, artistptr );
|
||||
Tomahawk::result_ptr result = Tomahawk::result_ptr( new Tomahawk::Result() );
|
||||
Tomahawk::result_ptr result = Tomahawk::Result::get( url );
|
||||
result->setModificationTime( mtime );
|
||||
result->setSize( size );
|
||||
result->setMimetype( mimetype );
|
||||
@ -206,7 +206,6 @@ DatabaseCommand_AddFiles::exec( DatabaseImpl* dbi )
|
||||
result->setAttributes( attr );
|
||||
result->setCollection( source()->collection() );
|
||||
result->setScore( 1.0 );
|
||||
result->setUrl( url );
|
||||
result->setId( trackid );
|
||||
|
||||
QList<Tomahawk::result_ptr> results;
|
||||
|
@ -91,24 +91,23 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
|
||||
|
||||
while( query.next() )
|
||||
{
|
||||
Tomahawk::result_ptr result = Tomahawk::result_ptr( new Tomahawk::Result() );
|
||||
Tomahawk::source_ptr s;
|
||||
QString url = query.value( 7 ).toString();
|
||||
|
||||
if( query.value( 8 ).toUInt() == 0 )
|
||||
if ( query.value( 8 ).toUInt() == 0 )
|
||||
{
|
||||
s = SourceList::instance()->getLocal();
|
||||
result->setUrl( query.value( 7 ).toString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SourceList::instance()->get( query.value( 8 ).toUInt() );
|
||||
if( s.isNull() )
|
||||
if ( s.isNull() )
|
||||
{
|
||||
Q_ASSERT( false );
|
||||
continue;
|
||||
}
|
||||
|
||||
result->setUrl( QString( "servent://%1\t%2" ).arg( s->userName() ).arg( query.value( 7 ).toString() ) );
|
||||
url = QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url );
|
||||
}
|
||||
|
||||
QString artist, track, album;
|
||||
@ -116,6 +115,7 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
|
||||
album = query.value( 2 ).toString();
|
||||
track = query.value( 3 ).toString();
|
||||
|
||||
Tomahawk::result_ptr result = Tomahawk::Result::get( url );
|
||||
Tomahawk::query_ptr qry = Tomahawk::Query::get( artist, track, album );
|
||||
Tomahawk::artist_ptr artistptr = Tomahawk::Artist::get( query.value( 12 ).toUInt(), artist );
|
||||
Tomahawk::album_ptr albumptr = Tomahawk::Album::get( query.value( 13 ).toUInt(), album, artistptr );
|
||||
|
@ -39,8 +39,16 @@ DatabaseCommand_LogPlayback::postCommitHook()
|
||||
connect( this, SIGNAL( trackPlayed( Tomahawk::query_ptr ) ),
|
||||
source().data(), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ), Qt::QueuedConnection );
|
||||
|
||||
// do not auto resolve this track
|
||||
Tomahawk::query_ptr q = Tomahawk::Query::get( m_artist, m_track, QString() );
|
||||
Tomahawk::query_ptr q;
|
||||
if ( !m_result.isNull() )
|
||||
{
|
||||
q = m_result->toQuery();
|
||||
}
|
||||
else
|
||||
{
|
||||
// do not auto resolve this track
|
||||
q = Tomahawk::Query::get( m_artist, m_track, QString() );
|
||||
}
|
||||
q->setPlayedBy( source(), m_playtime );
|
||||
|
||||
if ( m_action == Finished )
|
||||
|
@ -118,29 +118,28 @@ DatabaseCommand_Resolve::resolve( DatabaseImpl* lib )
|
||||
files_query.prepare( sql );
|
||||
files_query.exec();
|
||||
|
||||
while( files_query.next() )
|
||||
while ( files_query.next() )
|
||||
{
|
||||
Tomahawk::result_ptr result( new Tomahawk::Result() );
|
||||
source_ptr s;
|
||||
QString url = files_query.value( 0 ).toString();
|
||||
|
||||
const QString url_str = files_query.value( 0 ).toString();
|
||||
if( files_query.value( 13 ).toUInt() == 0 )
|
||||
if ( files_query.value( 13 ).toUInt() == 0 )
|
||||
{
|
||||
s = SourceList::instance()->getLocal();
|
||||
result->setUrl( url_str );
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SourceList::instance()->get( files_query.value( 13 ).toUInt() );
|
||||
if( s.isNull() )
|
||||
{
|
||||
qDebug() << "WTF: Could not find source" << files_query.value( 13 ).toUInt();
|
||||
qDebug() << "Could not find source" << files_query.value( 13 ).toUInt();
|
||||
continue;
|
||||
}
|
||||
|
||||
result->setUrl( QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url_str ) );
|
||||
url = QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url );
|
||||
}
|
||||
|
||||
Tomahawk::result_ptr result = Tomahawk::Result::get( url );
|
||||
Tomahawk::artist_ptr artist = Tomahawk::Artist::get( files_query.value( 15 ).toUInt(), files_query.value( 10 ).toString() );
|
||||
Tomahawk::album_ptr album = Tomahawk::Album::get( files_query.value( 16 ).toUInt(), files_query.value( 11 ).toString(), artist );
|
||||
|
||||
@ -233,27 +232,26 @@ DatabaseCommand_Resolve::fullTextResolve( DatabaseImpl* lib )
|
||||
|
||||
while( files_query.next() )
|
||||
{
|
||||
Tomahawk::result_ptr result( new Tomahawk::Result() );
|
||||
source_ptr s;
|
||||
QString url = files_query.value( 0 ).toString();
|
||||
|
||||
const QString url_str = files_query.value( 0 ).toString();
|
||||
if( files_query.value( 13 ).toUInt() == 0 )
|
||||
if ( files_query.value( 13 ).toUInt() == 0 )
|
||||
{
|
||||
s = SourceList::instance()->getLocal();
|
||||
result->setUrl( url_str );
|
||||
}
|
||||
else
|
||||
{
|
||||
s = SourceList::instance()->get( files_query.value( 13 ).toUInt() );
|
||||
if( s.isNull() )
|
||||
{
|
||||
qDebug() << "WTF: Could not find source" << files_query.value( 13 ).toUInt();
|
||||
qDebug() << "Could not find source" << files_query.value( 13 ).toUInt();
|
||||
continue;
|
||||
}
|
||||
|
||||
result->setUrl( QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url_str ) );
|
||||
url = QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url );
|
||||
}
|
||||
|
||||
Tomahawk::result_ptr result = Tomahawk::Result::get( url );
|
||||
Tomahawk::artist_ptr artist = Tomahawk::Artist::get( files_query.value( 15 ).toUInt(), files_query.value( 10 ).toString() );
|
||||
Tomahawk::album_ptr album = Tomahawk::Album::get( files_query.value( 16 ).toUInt(), files_query.value( 11 ).toString(), artist );
|
||||
|
||||
|
@ -213,7 +213,7 @@ DatabaseImpl::cleanSql( const QString& sql )
|
||||
Tomahawk::result_ptr
|
||||
DatabaseImpl::file( int fid )
|
||||
{
|
||||
Tomahawk::result_ptr r = Tomahawk::result_ptr( new Tomahawk::Result() );
|
||||
Tomahawk::result_ptr r;
|
||||
TomahawkSqlQuery query = newquery();
|
||||
query.exec( QString( "SELECT url, mtime, size, md5, mimetype, duration, bitrate, "
|
||||
"file_join.artist, file_join.album, file_join.track, "
|
||||
@ -228,8 +228,8 @@ DatabaseImpl::file( int fid )
|
||||
if ( query.next() )
|
||||
{
|
||||
Tomahawk::source_ptr s;
|
||||
QString url = query.value( 0 ).toString();
|
||||
|
||||
const QString url_str = query.value( 0 ).toString();
|
||||
if ( query.value( 13 ).toUInt() == 0 )
|
||||
{
|
||||
s = SourceList::instance()->getLocal();
|
||||
@ -242,13 +242,13 @@ DatabaseImpl::file( int fid )
|
||||
return r;
|
||||
}
|
||||
|
||||
r->setUrl( QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url_str ) );
|
||||
url = QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url );
|
||||
}
|
||||
|
||||
r = Tomahawk::Result::get( url );
|
||||
Tomahawk::artist_ptr artist = Tomahawk::Artist::get( query.value( 7 ).toUInt(), query.value( 10 ).toString() );
|
||||
Tomahawk::album_ptr album = Tomahawk::Album::get( query.value( 8 ).toUInt(), query.value( 11 ).toString(), artist );
|
||||
|
||||
r->setUrl( query.value( 0 ).toString() );
|
||||
r->setModificationTime( query.value( 1 ).toUInt() );
|
||||
r->setSize( query.value( 2 ).toUInt() );
|
||||
r->setMimetype( query.value( 4 ).toString() );
|
||||
@ -556,7 +556,6 @@ DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery )
|
||||
return res;
|
||||
}
|
||||
|
||||
res = Tomahawk::result_ptr( new Tomahawk::Result() );
|
||||
bool searchlocal = s->isLocal();
|
||||
|
||||
QString sql = QString( "SELECT "
|
||||
@ -587,12 +586,11 @@ DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery )
|
||||
if( query.next() )
|
||||
{
|
||||
Tomahawk::source_ptr s;
|
||||
QString url = query.value( 0 ).toString();
|
||||
|
||||
const QString url_str = query.value( 0 ).toString();
|
||||
if ( query.value( 13 ).toUInt() == 0 )
|
||||
{
|
||||
s = SourceList::instance()->getLocal();
|
||||
res->setUrl( url_str );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -602,9 +600,10 @@ DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery )
|
||||
return res;
|
||||
}
|
||||
|
||||
res->setUrl( QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url_str ) );
|
||||
url = QString( "servent://%1\t%2" ).arg( s->userName() ).arg( url );
|
||||
}
|
||||
|
||||
res = Tomahawk::Result::get( url );
|
||||
Tomahawk::artist_ptr artist = Tomahawk::Artist::get( query.value( 15 ).toUInt(), query.value( 10 ).toString() );
|
||||
Tomahawk::album_ptr album = Tomahawk::Album::get( query.value( 16 ).toUInt(), query.value( 11 ).toString(), artist );
|
||||
|
||||
|
@ -117,6 +117,8 @@ Pipeline::resolve( const QList<query_ptr>& qlist, bool prioritized, bool tempora
|
||||
int i = 0;
|
||||
foreach( const query_ptr& q, qlist )
|
||||
{
|
||||
if ( q->resolvingFinished() )
|
||||
continue;
|
||||
if ( m_queries_pending.contains( q ) )
|
||||
continue;
|
||||
if ( m_qidsState.contains( q->id() ) )
|
||||
|
@ -393,7 +393,7 @@ TrackModel::ensureResolved()
|
||||
{
|
||||
query_ptr query = itemFromIndex( index( i, 0, QModelIndex() ) )->query();
|
||||
|
||||
if ( !query->numResults() )
|
||||
if ( !query->resolvingFinished() )
|
||||
Pipeline::instance()->resolve( query );
|
||||
}
|
||||
}
|
||||
|
@ -165,6 +165,7 @@ Query::addResults( const QList< Tomahawk::result_ptr >& newresults )
|
||||
void
|
||||
Query::refreshResults()
|
||||
{
|
||||
setResolveFinished( false );
|
||||
Pipeline::instance()->resolve( id() );
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,28 @@
|
||||
using namespace Tomahawk;
|
||||
|
||||
|
||||
Result::Result()
|
||||
Tomahawk::result_ptr
|
||||
Result::get( const QString& url )
|
||||
{
|
||||
static QHash< QString, result_ptr > s_results;
|
||||
static QMutex s_mutex;
|
||||
|
||||
QMutexLocker lock( &s_mutex );
|
||||
if ( s_results.contains( url ) )
|
||||
{
|
||||
return s_results.value( url );
|
||||
}
|
||||
|
||||
result_ptr r = result_ptr( new Result( url ) );
|
||||
s_results.insert( url, r );
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
Result::Result( const QString& url )
|
||||
: QObject()
|
||||
, m_url( url )
|
||||
, m_duration( 0 )
|
||||
, m_bitrate( 0 )
|
||||
, m_size( 0 )
|
||||
@ -142,6 +162,11 @@ Tomahawk::query_ptr
|
||||
Result::toQuery() const
|
||||
{
|
||||
Tomahawk::query_ptr query = Tomahawk::Query::get( artist()->name(), track(), album()->name() );
|
||||
QList<Tomahawk::result_ptr> rl;
|
||||
rl << Result::get( m_url );
|
||||
|
||||
query->addResults( rl );
|
||||
query->setResolveFinished( true );
|
||||
return query;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ friend class ::DatabaseCommand_AddFiles;
|
||||
friend class ::DatabaseCommand_LoadFile;
|
||||
|
||||
public:
|
||||
explicit Result();
|
||||
static Tomahawk::result_ptr get( const QString& url );
|
||||
virtual ~Result();
|
||||
|
||||
QVariant toVariant() const;
|
||||
@ -92,7 +92,6 @@ public:
|
||||
void setArtist( const Tomahawk::artist_ptr& artist );
|
||||
void setAlbum( const Tomahawk::album_ptr& album );
|
||||
void setTrack( const QString& track ) { m_track = track; }
|
||||
void setUrl( const QString& url ) { m_url = url; }
|
||||
void setMimetype( const QString& mimetype ) { m_mimetype = mimetype; }
|
||||
void setDuration( unsigned int duration ) { m_duration = duration; }
|
||||
void setBitrate( unsigned int bitrate ) { m_bitrate = bitrate; }
|
||||
@ -124,6 +123,9 @@ private slots:
|
||||
void onOnline();
|
||||
|
||||
private:
|
||||
// private constructor
|
||||
explicit Result( const QString& url );
|
||||
|
||||
void updateAttributes();
|
||||
void parseSocialActions();
|
||||
|
||||
|
@ -316,13 +316,12 @@ QtScriptResolver::parseResultVariantList( const QVariantList& reslist )
|
||||
{
|
||||
QVariantMap m = rv.toMap();
|
||||
|
||||
Tomahawk::result_ptr rp( new Tomahawk::Result() );
|
||||
Tomahawk::result_ptr rp = Tomahawk::Result::get( m.value( "url" ).toString() );
|
||||
Tomahawk::artist_ptr ap = Tomahawk::Artist::get( 0, m.value( "artist" ).toString() );
|
||||
rp->setArtist( ap );
|
||||
rp->setAlbum( Tomahawk::Album::get( 0, m.value( "album" ).toString(), ap ) );
|
||||
rp->setTrack( m.value( "track" ).toString() );
|
||||
rp->setBitrate( m.value( "bitrate" ).toUInt() );
|
||||
rp->setUrl( m.value( "url" ).toString() );
|
||||
rp->setSize( m.value( "size" ).toUInt() );
|
||||
rp->setRID( uuid() );
|
||||
rp->setFriendlySource( name() );
|
||||
|
@ -212,14 +212,13 @@ ScriptResolver::handleMsg( const QByteArray& msg )
|
||||
QVariantMap m = rv.toMap();
|
||||
qDebug() << "Found result:" << m;
|
||||
|
||||
Tomahawk::result_ptr rp( new Tomahawk::Result() );
|
||||
Tomahawk::result_ptr rp = Tomahawk::Result::get( m.value( "url" ).toString() );
|
||||
Tomahawk::artist_ptr ap = Tomahawk::Artist::get( 0, m.value( "artist" ).toString() );
|
||||
rp->setArtist( ap );
|
||||
rp->setAlbum( Tomahawk::Album::get( 0, m.value( "album" ).toString(), ap ) );
|
||||
rp->setTrack( m.value( "track" ).toString() );
|
||||
rp->setDuration( m.value( "duration" ).toUInt() );
|
||||
rp->setBitrate( m.value( "bitrate" ).toUInt() );
|
||||
rp->setUrl( m.value( "url" ).toString() );
|
||||
rp->setSize( m.value( "size" ).toUInt() );
|
||||
rp->setRID( uuid() );
|
||||
rp->setFriendlySource( m_name );
|
||||
|
@ -48,12 +48,12 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
|
||||
{
|
||||
m_lovedTracksItem = new GenericPageItem( model(), this, ( m_source.isNull() ? tr( "Top Loved Tracks" ) : tr( "Loved Tracks" ) ), QIcon( RESPATH "images/loved_playlist.png" ),
|
||||
boost::bind( &CollectionItem::lovedTracksClicked, this ),
|
||||
boost::bind( &CollectionItem::getLovedTracksPage, this )
|
||||
);
|
||||
boost::bind( &CollectionItem::getLovedTracksPage, this ) );
|
||||
m_lovedTracksItem->setSortValue( -250 );
|
||||
|
||||
|
||||
if( m_source.isNull() ) { // super collection
|
||||
if ( m_source.isNull() )
|
||||
{
|
||||
// super collection
|
||||
connect( ViewManager::instance(), SIGNAL( tempPageActivated( Tomahawk::ViewPage*) ), this, SLOT( tempPageActivated( Tomahawk::ViewPage* ) ) );
|
||||
|
||||
// add misc children of root node
|
||||
@ -84,8 +84,7 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons
|
||||
|
||||
m_sourceInfoItem = new GenericPageItem( model(), this, tr( "New Additions" ), QIcon( RESPATH "images/new-additions.png" ),
|
||||
boost::bind( &CollectionItem::sourceInfoClicked, this ),
|
||||
boost::bind( &CollectionItem::getSourceInfoPage, this )
|
||||
);
|
||||
boost::bind( &CollectionItem::getSourceInfoPage, this ) );
|
||||
m_sourceInfoItem->setSortValue( -300 );
|
||||
|
||||
// create category items if there are playlists to show, or stations to show
|
||||
@ -238,9 +237,11 @@ CollectionItem::playlistDeletedInternal( SourceTreeItem* parent, const T& p )
|
||||
{
|
||||
Q_ASSERT( parent ); // How can we delete playlists if we have none?
|
||||
int curCount = parent->children().count();
|
||||
for( int i = 0; i < curCount; i++ ) {
|
||||
for( int i = 0; i < curCount; i++ )
|
||||
{
|
||||
PlaylistItem* pl = qobject_cast< PlaylistItem* >( parent->children().at( i ) );
|
||||
if( pl && pl->playlist() == p ) {
|
||||
if( pl && pl->playlist() == p )
|
||||
{
|
||||
parent->beginRowsRemoved( i, i );
|
||||
parent->removeChild( pl );
|
||||
parent->endRowsRemoved();
|
||||
@ -324,7 +325,9 @@ CollectionItem::onAutoPlaylistsAdded( const QList< dynplaylist_ptr >& playlists
|
||||
if( playlists.isEmpty() )
|
||||
return;
|
||||
|
||||
if( !m_playlists ) { // add the category too
|
||||
if( !m_playlists )
|
||||
{
|
||||
// add the category too
|
||||
int cur = children().count();
|
||||
beginRowsAdded( cur, cur );
|
||||
m_playlists = new CategoryItem( model(), this, SourcesModel::PlaylistsCategory, source()->isLocal() );
|
||||
@ -351,7 +354,9 @@ CollectionItem::onStationsAdded( const QList< dynplaylist_ptr >& stations )
|
||||
if( stations.isEmpty() )
|
||||
return;
|
||||
|
||||
if( !m_stations ) { // add the category too
|
||||
if( !m_stations )
|
||||
{
|
||||
// add the category too
|
||||
int cur = children().count();
|
||||
beginRowsAdded( cur, cur );
|
||||
m_stations = new CategoryItem( model(), this, SourcesModel::StationsCategory, source()->isLocal() );
|
||||
@ -397,6 +402,7 @@ CollectionItem::tempPageActivated( Tomahawk::ViewPage* v )
|
||||
emit selectRequest( tempPage );
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
CollectionItem::sourceInfoClicked()
|
||||
{
|
||||
@ -414,6 +420,7 @@ CollectionItem::getSourceInfoPage() const
|
||||
return m_sourceInfoPage;
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
CollectionItem::coolPlaylistsClicked()
|
||||
{
|
||||
@ -427,12 +434,14 @@ CollectionItem::coolPlaylistsClicked()
|
||||
return m_coolPlaylistsPage;
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
CollectionItem::getCoolPlaylistsPage() const
|
||||
{
|
||||
return m_coolPlaylistsPage;
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
CollectionItem::lovedTracksClicked()
|
||||
{
|
||||
@ -443,6 +452,7 @@ CollectionItem::lovedTracksClicked()
|
||||
return m_lovedTracksPage;
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
CollectionItem::getLovedTracksPage() const
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user