diff --git a/src/libtomahawk/dropjob.cpp b/src/libtomahawk/dropjob.cpp index bc24408e4..04620e41d 100644 --- a/src/libtomahawk/dropjob.cpp +++ b/src/libtomahawk/dropjob.cpp @@ -28,9 +28,12 @@ #include "utils/rdioparser.h" #include "utils/shortenedlinkparser.h" #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" using namespace Tomahawk; bool DropJob::s_canParseSpotifyPlaylists = false; @@ -43,6 +46,7 @@ DropJob::DropJob( QObject *parent ) , m_getWholeAlbums( false ) , m_top10( false ) , m_dropAction( Default ) + , m_dropJob( 0 ) { } @@ -136,6 +140,24 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType return false; } +bool +DropJob::isDropType( DropJob::DropType desired, const QMimeData* data ) +{ + const QString url = data->data( "text/plain" ); + if ( desired == Playlist ) + { + if( url.contains( "xspf" ) ) + return true; + + // Not the most elegant + if ( url.contains( "spotify" ) && url.contains( "playlist" ) && s_canParseSpotifyPlaylists ) + return true; + } + + return false; +} + + void DropJob::setGetWholeArtists( bool getWholeArtists ) { @@ -490,6 +512,12 @@ DropJob::expandedUrls( QStringList urls ) void DropJob::onTracksAdded( const QList& tracksList ) { + if ( m_dropJob ) + { + m_dropJob->setFinished(); + m_dropJob = 0; + } + m_resultList.append( tracksList ); if ( --m_queryCount == 0 ) @@ -596,8 +624,11 @@ DropJob::getAlbum(const QString &artist, const QString &album) if ( albumPtr->tracks().isEmpty() ) { + m_dropJob = new DropJobNotifier( QPixmap( RESPATH "images/album-icon.png" ), Album ); connect( albumPtr.data(), SIGNAL( tracksAdded( QList ) ), SLOT( onTracksAdded( QList ) ) ); + JobStatusView::instance()->model()->addJob( m_dropJob ); + m_queryCount++; return QList< query_ptr >(); } diff --git a/src/libtomahawk/dropjob.h b/src/libtomahawk/dropjob.h index e79213938..0142ec5bb 100644 --- a/src/libtomahawk/dropjob.h +++ b/src/libtomahawk/dropjob.h @@ -27,6 +27,10 @@ #include #include +namespace Tomahawk { +class DropJobNotifier; +} + class DLLEXPORT DropJob : public QObject { @@ -70,6 +74,14 @@ public: */ static bool acceptsMimeData( const QMimeData* data, DropJob::DropTypes type = All, DropAction action = Append ); + /** + * Return if the drop is primarily of the given type. Does not auto-convert (e.g. if the drop is of type playlist, + * even thougha playlist can be converted into tracks, this will return true only for the Playlist drop type). + * + * TODO Only implemented for Playlist atm. Extend when you need it. + */ + static bool isDropType( DropJob::DropType desired, const QMimeData* data ); + static QStringList mimeTypes(); /// Set the drop types that should be extracted from this drop @@ -131,6 +143,8 @@ private: DropTypes m_dropTypes; DropAction m_dropAction; + Tomahawk::DropJobNotifier* m_dropJob; + QList< Tomahawk::query_ptr > m_resultList; static bool s_canParseSpotifyPlaylists; diff --git a/src/libtomahawk/utils/dropjobnotifier.cpp b/src/libtomahawk/utils/dropjobnotifier.cpp index 4094433fe..c104ada55 100644 --- a/src/libtomahawk/utils/dropjobnotifier.cpp +++ b/src/libtomahawk/utils/dropjobnotifier.cpp @@ -41,7 +41,29 @@ DropJobNotifier::DropJobNotifier( QPixmap servicePixmap, QString service, DropJo , m_pixmap ( servicePixmap ) , m_service ( service ) { + init( type ); + if( m_service.isEmpty() ) + m_service = "DropJob"; + + connect( job, SIGNAL( finished() ), this, SLOT( setFinished() ) ); +} + +DropJobNotifier::DropJobNotifier( QPixmap pixmap, DropJob::DropType type ) + : JobStatusItem() + , m_pixmap( pixmap ) + , m_job( 0 ) +{ + init( type ); +} + + +DropJobNotifier::~DropJobNotifier() +{} + +void +DropJobNotifier::init( DropJob::DropType type ) +{ if( type == DropJob::Playlist ) m_type = "playlist"; @@ -54,16 +76,9 @@ DropJobNotifier::DropJobNotifier( QPixmap servicePixmap, QString service, DropJo if( type == DropJob::Album ) m_type = "album"; - if( m_service.isEmpty() ) - m_service = "DropJob"; - - connect( job, SIGNAL( finished() ), this, SLOT( setFinished() ) ); } -DropJobNotifier::~DropJobNotifier() -{} - QString DropJobNotifier::rightColumnText() const { @@ -80,8 +95,15 @@ DropJobNotifier::icon() const QString DropJobNotifier::mainText() const { - return tr( "Parsing %1 %2" ).arg( m_service ) - .arg( m_type ); + if ( m_service.isEmpty() ) + { + return tr( "Fetching %1 from database" ).arg( m_type ); + } + else + { + return tr( "Parsing %1 %2" ).arg( m_service ) + .arg( m_type ); + } } void diff --git a/src/libtomahawk/utils/dropjobnotifier.h b/src/libtomahawk/utils/dropjobnotifier.h index 3d5aa9e3d..6119f0ad8 100644 --- a/src/libtomahawk/utils/dropjobnotifier.h +++ b/src/libtomahawk/utils/dropjobnotifier.h @@ -37,8 +37,10 @@ class DLLEXPORT DropJobNotifier : public JobStatusItem { Q_OBJECT public: - DropJobNotifier( QPixmap pixmap, QString service, DropJob::DropType type, QNetworkReply* job ); + + // No QNetworkReply, needs manual finished call + DropJobNotifier( QPixmap pixmap, DropJob::DropType type ); virtual ~DropJobNotifier(); virtual QString rightColumnText() const; @@ -51,6 +53,8 @@ public slots: void setFinished(); private: + void init( DropJob::DropType type ); + QString m_type; QNetworkReply* m_job; QPixmap m_pixmap; diff --git a/src/libtomahawk/utils/spotifyparser.cpp b/src/libtomahawk/utils/spotifyparser.cpp index f1e912ec2..cba486f2d 100644 --- a/src/libtomahawk/utils/spotifyparser.cpp +++ b/src/libtomahawk/utils/spotifyparser.cpp @@ -40,10 +40,10 @@ QPixmap* SpotifyParser::s_pixmap = 0; SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, QObject* parent ) : QObject ( parent ) + , m_limit ( 40 ) , m_single( false ) , m_trackMode( true ) , m_createNewPlaylist( createNewPlaylist ) - , m_limit ( 40 ) , m_browseJob( 0 ) { @@ -53,10 +53,10 @@ SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, Q SpotifyParser::SpotifyParser( const QString& Url, bool createNewPlaylist, QObject* parent ) : QObject ( parent ) + , m_limit ( 40 ) , m_single( true ) , m_trackMode( true ) , m_createNewPlaylist( createNewPlaylist ) - , m_limit ( 40 ) , m_browseJob( 0 ) { lookupUrl( Url ); diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index 762c2b74b..59e9a4d01 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -525,12 +525,15 @@ SourceTreeView::dropEvent( QDropEvent* event ) } else { - // if it's a playlist drop, accept it anywhere in the sourcetree by manually parsing it. - qDebug() << Q_FUNC_INFO << "Current Event"; - DropJob *dropThis = new DropJob; - dropThis->setDropTypes( DropJob::Playlist ); - dropThis->setDropAction( DropJob::Create ); - dropThis->parseMimeData( event->mimeData() ); + if ( DropJob::isDropType( DropJob::Playlist, event->mimeData() ) ) + { + // if it's a playlist drop, accept it anywhere in the sourcetree by manually parsing it. + qDebug() << Q_FUNC_INFO << "Current Event"; + DropJob *dropThis = new DropJob; + dropThis->setDropTypes( DropJob::Playlist ); + dropThis->setDropAction( DropJob::Create ); + dropThis->parseMimeData( event->mimeData() ); + } QTreeView::dropEvent( event ); }