1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-08 07:07:05 +02:00

Don't run a dropjob for any drop unless it's a playlist. Show notifications for album db fetches

This commit is contained in:
Leo Franchi
2011-10-19 22:55:11 -04:00
parent 24c7b0074a
commit 4107c01ad1
6 changed files with 92 additions and 18 deletions

View File

@@ -28,9 +28,12 @@
#include "utils/rdioparser.h" #include "utils/rdioparser.h"
#include "utils/shortenedlinkparser.h" #include "utils/shortenedlinkparser.h"
#include "utils/logger.h" #include "utils/logger.h"
#include "utils/tomahawkutils.h"
#include "globalactionmanager.h" #include "globalactionmanager.h"
#include "infosystem/infosystem.h" #include "infosystem/infosystem.h"
#include "utils/xspfloader.h" #include "utils/xspfloader.h"
#include "jobview/JobStatusView.h"
#include "jobview/JobStatusModel.h"
using namespace Tomahawk; using namespace Tomahawk;
bool DropJob::s_canParseSpotifyPlaylists = false; bool DropJob::s_canParseSpotifyPlaylists = false;
@@ -43,6 +46,7 @@ DropJob::DropJob( QObject *parent )
, m_getWholeAlbums( false ) , m_getWholeAlbums( false )
, m_top10( false ) , m_top10( false )
, m_dropAction( Default ) , m_dropAction( Default )
, m_dropJob( 0 )
{ {
} }
@@ -136,6 +140,24 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
return false; 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 void
DropJob::setGetWholeArtists( bool getWholeArtists ) DropJob::setGetWholeArtists( bool getWholeArtists )
{ {
@@ -490,6 +512,12 @@ DropJob::expandedUrls( QStringList urls )
void void
DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList ) DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
{ {
if ( m_dropJob )
{
m_dropJob->setFinished();
m_dropJob = 0;
}
m_resultList.append( tracksList ); m_resultList.append( tracksList );
if ( --m_queryCount == 0 ) if ( --m_queryCount == 0 )
@@ -596,8 +624,11 @@ DropJob::getAlbum(const QString &artist, const QString &album)
if ( albumPtr->tracks().isEmpty() ) if ( albumPtr->tracks().isEmpty() )
{ {
m_dropJob = new DropJobNotifier( QPixmap( RESPATH "images/album-icon.png" ), Album );
connect( albumPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ), connect( albumPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) ); SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
JobStatusView::instance()->model()->addJob( m_dropJob );
m_queryCount++; m_queryCount++;
return QList< query_ptr >(); return QList< query_ptr >();
} }

View File

@@ -27,6 +27,10 @@
#include <QStringList> #include <QStringList>
#include <QMimeData> #include <QMimeData>
namespace Tomahawk {
class DropJobNotifier;
}
class DLLEXPORT DropJob : public QObject class DLLEXPORT DropJob : public QObject
{ {
@@ -70,6 +74,14 @@ public:
*/ */
static bool acceptsMimeData( const QMimeData* data, DropJob::DropTypes type = All, DropAction action = Append ); 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(); static QStringList mimeTypes();
/// Set the drop types that should be extracted from this drop /// Set the drop types that should be extracted from this drop
@@ -131,6 +143,8 @@ private:
DropTypes m_dropTypes; DropTypes m_dropTypes;
DropAction m_dropAction; DropAction m_dropAction;
Tomahawk::DropJobNotifier* m_dropJob;
QList< Tomahawk::query_ptr > m_resultList; QList< Tomahawk::query_ptr > m_resultList;
static bool s_canParseSpotifyPlaylists; static bool s_canParseSpotifyPlaylists;

View File

@@ -41,7 +41,29 @@ DropJobNotifier::DropJobNotifier( QPixmap servicePixmap, QString service, DropJo
, m_pixmap ( servicePixmap ) , m_pixmap ( servicePixmap )
, m_service ( service ) , 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 ) if( type == DropJob::Playlist )
m_type = "playlist"; m_type = "playlist";
@@ -54,16 +76,9 @@ DropJobNotifier::DropJobNotifier( QPixmap servicePixmap, QString service, DropJo
if( type == DropJob::Album ) if( type == DropJob::Album )
m_type = "album"; m_type = "album";
if( m_service.isEmpty() )
m_service = "DropJob";
connect( job, SIGNAL( finished() ), this, SLOT( setFinished() ) );
} }
DropJobNotifier::~DropJobNotifier()
{}
QString QString
DropJobNotifier::rightColumnText() const DropJobNotifier::rightColumnText() const
{ {
@@ -80,8 +95,15 @@ DropJobNotifier::icon() const
QString QString
DropJobNotifier::mainText() const DropJobNotifier::mainText() const
{ {
return tr( "Parsing %1 %2" ).arg( m_service ) if ( m_service.isEmpty() )
.arg( m_type ); {
return tr( "Fetching %1 from database" ).arg( m_type );
}
else
{
return tr( "Parsing %1 %2" ).arg( m_service )
.arg( m_type );
}
} }
void void

View File

@@ -37,8 +37,10 @@ class DLLEXPORT DropJobNotifier : public JobStatusItem
{ {
Q_OBJECT Q_OBJECT
public: public:
DropJobNotifier( QPixmap pixmap, QString service, DropJob::DropType type, QNetworkReply* job ); 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 ~DropJobNotifier();
virtual QString rightColumnText() const; virtual QString rightColumnText() const;
@@ -51,6 +53,8 @@ public slots:
void setFinished(); void setFinished();
private: private:
void init( DropJob::DropType type );
QString m_type; QString m_type;
QNetworkReply* m_job; QNetworkReply* m_job;
QPixmap m_pixmap; QPixmap m_pixmap;

View File

@@ -40,10 +40,10 @@ QPixmap* SpotifyParser::s_pixmap = 0;
SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, QObject* parent ) SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, QObject* parent )
: QObject ( parent ) : QObject ( parent )
, m_limit ( 40 )
, m_single( false ) , m_single( false )
, m_trackMode( true ) , m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist ) , m_createNewPlaylist( createNewPlaylist )
, m_limit ( 40 )
, m_browseJob( 0 ) , m_browseJob( 0 )
{ {
@@ -53,10 +53,10 @@ SpotifyParser::SpotifyParser( const QStringList& Urls, bool createNewPlaylist, Q
SpotifyParser::SpotifyParser( const QString& Url, bool createNewPlaylist, QObject* parent ) SpotifyParser::SpotifyParser( const QString& Url, bool createNewPlaylist, QObject* parent )
: QObject ( parent ) : QObject ( parent )
, m_limit ( 40 )
, m_single( true ) , m_single( true )
, m_trackMode( true ) , m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist ) , m_createNewPlaylist( createNewPlaylist )
, m_limit ( 40 )
, m_browseJob( 0 ) , m_browseJob( 0 )
{ {
lookupUrl( Url ); lookupUrl( Url );

View File

@@ -525,12 +525,15 @@ SourceTreeView::dropEvent( QDropEvent* event )
} }
else else
{ {
// if it's a playlist drop, accept it anywhere in the sourcetree by manually parsing it. if ( DropJob::isDropType( DropJob::Playlist, event->mimeData() ) )
qDebug() << Q_FUNC_INFO << "Current Event"; {
DropJob *dropThis = new DropJob; // if it's a playlist drop, accept it anywhere in the sourcetree by manually parsing it.
dropThis->setDropTypes( DropJob::Playlist ); qDebug() << Q_FUNC_INFO << "Current Event";
dropThis->setDropAction( DropJob::Create ); DropJob *dropThis = new DropJob;
dropThis->parseMimeData( event->mimeData() ); dropThis->setDropTypes( DropJob::Playlist );
dropThis->setDropAction( DropJob::Create );
dropThis->parseMimeData( event->mimeData() );
}
QTreeView::dropEvent( event ); QTreeView::dropEvent( event );
} }