diff --git a/src/libtomahawk/database/databasecommand_addfiles.cpp b/src/libtomahawk/database/databasecommand_addfiles.cpp index 2a9df9c74..262189536 100644 --- a/src/libtomahawk/database/databasecommand_addfiles.cpp +++ b/src/libtomahawk/database/databasecommand_addfiles.cpp @@ -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 results; diff --git a/src/libtomahawk/database/databasecommand_alltracks.cpp b/src/libtomahawk/database/databasecommand_alltracks.cpp index b611f8b74..161c72534 100644 --- a/src/libtomahawk/database/databasecommand_alltracks.cpp +++ b/src/libtomahawk/database/databasecommand_alltracks.cpp @@ -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 ); diff --git a/src/libtomahawk/database/databasecommand_logplayback.cpp b/src/libtomahawk/database/databasecommand_logplayback.cpp index 3c1ad731c..8022227d6 100644 --- a/src/libtomahawk/database/databasecommand_logplayback.cpp +++ b/src/libtomahawk/database/databasecommand_logplayback.cpp @@ -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 ) diff --git a/src/libtomahawk/database/databasecommand_resolve.cpp b/src/libtomahawk/database/databasecommand_resolve.cpp index b2233fc45..a29aacfe3 100644 --- a/src/libtomahawk/database/databasecommand_resolve.cpp +++ b/src/libtomahawk/database/databasecommand_resolve.cpp @@ -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 ); diff --git a/src/libtomahawk/database/databaseimpl.cpp b/src/libtomahawk/database/databaseimpl.cpp index e042930ab..972f92357 100644 --- a/src/libtomahawk/database/databaseimpl.cpp +++ b/src/libtomahawk/database/databaseimpl.cpp @@ -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 ); diff --git a/src/libtomahawk/pipeline.cpp b/src/libtomahawk/pipeline.cpp index 9bd7c052c..40b78254c 100644 --- a/src/libtomahawk/pipeline.cpp +++ b/src/libtomahawk/pipeline.cpp @@ -117,6 +117,8 @@ Pipeline::resolve( const QList& 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() ) ) diff --git a/src/libtomahawk/playlist/trackmodel.cpp b/src/libtomahawk/playlist/trackmodel.cpp index 62bdd9f88..85ac47500 100644 --- a/src/libtomahawk/playlist/trackmodel.cpp +++ b/src/libtomahawk/playlist/trackmodel.cpp @@ -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 ); } } diff --git a/src/libtomahawk/query.cpp b/src/libtomahawk/query.cpp index bd4a863ce..01961adf0 100644 --- a/src/libtomahawk/query.cpp +++ b/src/libtomahawk/query.cpp @@ -165,6 +165,7 @@ Query::addResults( const QList< Tomahawk::result_ptr >& newresults ) void Query::refreshResults() { + setResolveFinished( false ); Pipeline::instance()->resolve( id() ); } diff --git a/src/libtomahawk/result.cpp b/src/libtomahawk/result.cpp index d4765d960..0c5e05f13 100644 --- a/src/libtomahawk/result.cpp +++ b/src/libtomahawk/result.cpp @@ -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 rl; + rl << Result::get( m_url ); + + query->addResults( rl ); + query->setResolveFinished( true ); return query; } diff --git a/src/libtomahawk/result.h b/src/libtomahawk/result.h index 1ef6708ad..64ee7d665 100644 --- a/src/libtomahawk/result.h +++ b/src/libtomahawk/result.h @@ -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(); diff --git a/src/resolvers/qtscriptresolver.cpp b/src/resolvers/qtscriptresolver.cpp index 905401385..ed97feaa4 100644 --- a/src/resolvers/qtscriptresolver.cpp +++ b/src/resolvers/qtscriptresolver.cpp @@ -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() ); diff --git a/src/resolvers/scriptresolver.cpp b/src/resolvers/scriptresolver.cpp index 8511c32b5..356415ee9 100644 --- a/src/resolvers/scriptresolver.cpp +++ b/src/resolvers/scriptresolver.cpp @@ -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 ); diff --git a/src/sourcetree/items/collectionitem.cpp b/src/sourcetree/items/collectionitem.cpp index 1364c7a62..7db800565 100644 --- a/src/sourcetree/items/collectionitem.cpp +++ b/src/sourcetree/items/collectionitem.cpp @@ -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 {