mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-20 07:49:42 +01: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:
parent
24c7b0074a
commit
4107c01ad1
@ -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<Tomahawk::query_ptr>& 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<Tomahawk::query_ptr> ) ),
|
||||
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||
JobStatusView::instance()->model()->addJob( m_dropJob );
|
||||
|
||||
m_queryCount++;
|
||||
return QList< query_ptr >();
|
||||
}
|
||||
|
@ -27,6 +27,10 @@
|
||||
#include <QStringList>
|
||||
#include <QMimeData>
|
||||
|
||||
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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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 );
|
||||
|
@ -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 );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user