From c8afb7a7c61fcbb7510cfe97eafc57f6cf1d4744 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 28 May 2012 16:12:51 +0200 Subject: [PATCH] * DropJob now uses the new API. --- src/libtomahawk/DropJob.cpp | 195 ++++++------------------------------ src/libtomahawk/DropJob.h | 13 +-- 2 files changed, 36 insertions(+), 172 deletions(-) diff --git a/src/libtomahawk/DropJob.cpp b/src/libtomahawk/DropJob.cpp index 029eb44cb..674a8840d 100644 --- a/src/libtomahawk/DropJob.cpp +++ b/src/libtomahawk/DropJob.cpp @@ -32,7 +32,6 @@ #include "utils/Logger.h" #include "utils/TomahawkUtils.h" #include "GlobalActionManager.h" -#include "infosystem/InfoSystem.h" #include "utils/XspfLoader.h" #include "jobview/JobStatusView.h" #include "jobview/JobStatusModel.h" @@ -57,7 +56,6 @@ DropJob::DropJob( QObject *parent ) , m_getWholeAlbums( false ) , m_top10( false ) , m_dropAction( Default ) - , m_dropJob( 0 ) { } @@ -294,11 +292,11 @@ DropJob::tracksFromQueryList( const QMimeData* data ) query_ptr* query = reinterpret_cast(qptr); if ( query && !query->isNull() ) { - tDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track(); + tDebug() << "Dropped query item:" << query->data()->toString(); if ( m_top10 ) { - getTopTen( query->data()->artist() ); + queries << getTopTen( query->data()->artist() ); } else if ( m_getWholeArtists ) { @@ -376,7 +374,7 @@ DropJob::tracksFromAlbumMetaData( const QMimeData *data ) stream >> album; if ( m_top10 ) - getTopTen( artist ); + queries << getTopTen( artist ); else if ( m_getWholeArtists ) queries << getArtist( artist ); else @@ -405,7 +403,7 @@ DropJob::tracksFromArtistMetaData( const QMimeData *data ) } else { - getTopTen( artist ); + queries << getTopTen( artist ); } } return queries; @@ -569,6 +567,7 @@ DropJob::handleRdioUrls( const QString& urlsRaw ) rdio->parse( urls ); } + void DropJob::handleGroovesharkUrls ( const QString& urlsRaw ) { @@ -594,7 +593,6 @@ DropJob::handleGroovesharkUrls ( const QString& urlsRaw ) } - void DropJob::handleAllUrls( const QString& urls ) { @@ -672,22 +670,28 @@ DropJob::expandedUrls( QStringList urls ) void DropJob::onTracksAdded( const QList& tracksList ) { - qDebug() << Q_FUNC_INFO; - if ( m_dropJob ) + tDebug() << Q_FUNC_INFO << tracksList.count(); + +/* if ( results.isEmpty() ) { - m_dropJob->setFinished(); - m_dropJob = 0; + const QString which = album.isEmpty() ? "artist" : "album"; + JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "No tracks found for given %1" ).arg( which ), 5 ) ); + }*/ + + if ( !m_dropJob.isEmpty() ) + { + m_dropJob.takeFirst()->setFinished(); } m_resultList.append( tracksList ); if ( --m_queryCount == 0 ) { - if ( m_onlyLocal ) +/* if ( m_onlyLocal ) removeRemoteSources(); if ( !m_allowDuplicates ) - removeDuplicates(); + removeDuplicates();*/ emit tracks( m_resultList ); deleteLater(); @@ -695,67 +699,6 @@ DropJob::onTracksAdded( const QList& tracksList ) } -void -DropJob::tracksFromDB( const QList< query_ptr >& tracks ) -{ - // Tracks that we get from databasecommand_alltracks are resolved only against the database and explicitly marked - // as finished. if the source they resolve to is offline they will not resolve against any resolver. - // explicitly resolve them if they fall in that case first - foreach( const query_ptr& track, tracks ) - { - if ( !track->playable() && !track->solved() && track->results().size() ) // we have offline results - { - track->setResolveFinished( false ); - Pipeline::instance()->resolve( track ); - } - } - - album_ptr albumPtr; - artist_ptr artistPtr; - if ( Tomahawk::Album* album = qobject_cast< Tomahawk::Album* >( sender() ) ) - { - foreach ( const album_ptr& ptr, m_albumsToKeep ) - if ( ptr.data() == album ) - { - albumPtr = ptr; - m_albumsToKeep.remove( ptr ); - } - } - else if ( Tomahawk::Artist* artist = qobject_cast< Tomahawk::Artist* >( sender() ) ) - { - foreach ( const artist_ptr& ptr, m_artistsToKeep ) - if ( ptr.data() == artist ) - { - artistPtr = ptr; - m_artistsToKeep.remove( ptr ); - } - } - - // If we have no tracks, this means no sources in our network have the give request (artist or album) - // Since we really do want to try to drop them, we ask the infosystem as well. - if ( tracks.isEmpty() ) - { - if ( !albumPtr.isNull() && !albumPtr->artist().isNull() ) - { - Q_ASSERT( artistPtr.isNull() ); - --m_queryCount; // This query is done. New query is infosystem query - getAlbumFromInfoystem( albumPtr->artist()->name(), albumPtr->name() ); - } - else if ( !artistPtr.isNull() ) - { - Q_ASSERT( albumPtr.isNull() ); - --m_queryCount; - getTopTen( artistPtr->name() ); - } - } - else - { - onTracksAdded( tracks ); - } - -} - - void DropJob::removeDuplicates() { @@ -803,41 +746,8 @@ DropJob::removeRemoteSources() } -void -DropJob::infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ) -{ - if ( requestData.caller == s_dropJobInfoId ) - { - const Tomahawk::InfoSystem::InfoStringHash info = requestData.input.value< Tomahawk::InfoSystem::InfoStringHash >(); - - const QString artist = info["artist"]; - const QString album = info["album"]; - - qDebug() << "Got requestData response for artist" << artist << "and album:" << album << output; - - QList< query_ptr > results; - - int i = 0; - foreach ( const QVariant& title, output.toMap().value( "tracks" ).toList() ) - { - results << Query::get( artist, title.toString(), QString(), uuid() ); - - if ( ++i == 10 ) // Only getting top ten for now. Would make sense to make it configurable - break; - } - - if ( results.isEmpty() ) - { - const QString which = album.isEmpty() ? "artist" : "album"; - JobStatusView::instance()->model()->addJob( new ErrorStatusMessage( tr( "No tracks found for given %1" ).arg( which ), 5 ) ); - } - onTracksAdded( results ); - } -} - - QList< query_ptr > -DropJob::getArtist( const QString &artist ) +DropJob::getArtist( const QString &artist, Tomahawk::ModelMode mode ) { artist_ptr artistPtr = Artist::get( artist ); if ( artistPtr->playlistInterface( Mixed )->tracks().isEmpty() ) @@ -845,13 +755,15 @@ DropJob::getArtist( const QString &artist ) m_artistsToKeep.insert( artistPtr ); connect( artistPtr.data(), SIGNAL( tracksAdded( QList, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ), - SLOT( tracksFromDB( QList ) ) ); + SLOT( onTracksAdded( QList ) ) ); + + m_dropJob << new DropJobNotifier( QPixmap( RESPATH "images/album-icon.png" ), Album ); + JobStatusView::instance()->model()->addJob( m_dropJob.last() ); m_queryCount++; - return QList< query_ptr >(); } - else - return artistPtr->playlistInterface( Mixed )->tracks(); + + return artistPtr->playlistInterface( Mixed )->tracks(); } @@ -872,62 +784,21 @@ DropJob::getAlbum( const QString& artist, const QString& album ) // the artist_ptr which means we never get the signal delivered. so we hold on to the album pointer till we're done m_albumsToKeep.insert( albumPtr ); - m_dropJob = new DropJobNotifier( QPixmap( RESPATH "images/album-icon.png" ), Album ); connect( albumPtr.data(), SIGNAL( tracksAdded( QList, Tomahawk::ModelMode, Tomahawk::collection_ptr ) ), - SLOT( tracksFromDB( QList ) ) ); - JobStatusView::instance()->model()->addJob( m_dropJob ); + SLOT( onTracksAdded( QList ) ) ); + + m_dropJob << new DropJobNotifier( QPixmap( RESPATH "images/album-icon.png" ), Album ); + JobStatusView::instance()->model()->addJob( m_dropJob.last() ); m_queryCount++; - return QList< query_ptr >(); } - else - return albumPtr->playlistInterface( Mixed )->tracks(); + + return albumPtr->playlistInterface( Mixed )->tracks(); } -void -DropJob::getTopTen( const QString &artist ) +QList< query_ptr > +DropJob::getTopTen( const QString& artist ) { - connect( Tomahawk::InfoSystem::InfoSystem::instance(), - SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), - SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); - - Tomahawk::InfoSystem::InfoStringHash artistInfo; - artistInfo["artist"] = artist; - - Tomahawk::InfoSystem::InfoRequestData requestData; - requestData.caller = s_dropJobInfoId; - requestData.customData = QVariantMap(); - - requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo ); - - requestData.type = Tomahawk::InfoSystem::InfoArtistSongs; - Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); - - m_queryCount++; + return getArtist( artist, Tomahawk::InfoSystemMode ); } - - -void -DropJob::getAlbumFromInfoystem( const QString& artist, const QString& album ) -{ - connect( Tomahawk::InfoSystem::InfoSystem::instance(), - SIGNAL( info( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ), - SLOT( infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData, QVariant ) ) ); - - Tomahawk::InfoSystem::InfoStringHash artistInfo; - artistInfo["artist"] = artist; - artistInfo["album"] = album; - - Tomahawk::InfoSystem::InfoRequestData requestData; - requestData.caller = s_dropJobInfoId; - requestData.customData = QVariantMap(); - - requestData.input = QVariant::fromValue< Tomahawk::InfoSystem::InfoStringHash >( artistInfo ); - - requestData.type = Tomahawk::InfoSystem::InfoAlbumSongs; - Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); - - m_queryCount++; -} - diff --git a/src/libtomahawk/DropJob.h b/src/libtomahawk/DropJob.h index 8ae990352..272a6d338 100644 --- a/src/libtomahawk/DropJob.h +++ b/src/libtomahawk/DropJob.h @@ -22,9 +22,6 @@ #include "Query.h" -#include "infosystem/InfoSystem.h" -#include "utils/XspfLoader.h" - #include #include #include @@ -120,9 +117,7 @@ signals: private slots: void expandedUrls( QStringList ); void onTracksAdded( const QList& ); - void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output ); - void tracksFromDB( const QList< Tomahawk::query_ptr >& ); private: /// handle parsing mime data void handleAllUrls( const QString& urls ); @@ -133,11 +128,9 @@ private: QList< Tomahawk::query_ptr > tracksFromAlbumMetaData( const QMimeData* d ); QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d ); - QList< Tomahawk::query_ptr > getArtist( const QString& artist ); + QList< Tomahawk::query_ptr > getArtist( const QString& artist, Tomahawk::ModelMode mode = Tomahawk::Mixed ); QList< Tomahawk::query_ptr > getAlbum( const QString& artist, const QString& album ); - - void getTopTen( const QString& artist ); - void getAlbumFromInfoystem( const QString& artist, const QString& album ); + QList< Tomahawk::query_ptr > getTopTen( const QString& artist ); void removeDuplicates(); void removeRemoteSources(); @@ -151,7 +144,7 @@ private: DropTypes m_dropTypes; DropAction m_dropAction; - Tomahawk::DropJobNotifier* m_dropJob; + QList m_dropJob; QList< Tomahawk::query_ptr > m_resultList; QSet< Tomahawk::album_ptr > m_albumsToKeep;