mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-04 13:17:34 +02:00
Merge branch 'master' of github.com:tomahawk-player/tomahawk
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include <globalactionmanager.h>
|
#include <globalactionmanager.h>
|
||||||
|
#include "dropjob.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -521,7 +522,7 @@ AudioControls::onTrackClicked()
|
|||||||
void
|
void
|
||||||
AudioControls::dragEnterEvent( QDragEnterEvent* e )
|
AudioControls::dragEnterEvent( QDragEnterEvent* e )
|
||||||
{
|
{
|
||||||
if ( GlobalActionManager::instance()->acceptsMimeData( e->mimeData() ) )
|
if ( DropJob::acceptsMimeData( e->mimeData() ) )
|
||||||
e->acceptProposedAction();
|
e->acceptProposedAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,10 +539,11 @@ void
|
|||||||
AudioControls::dropEvent( QDropEvent* e )
|
AudioControls::dropEvent( QDropEvent* e )
|
||||||
{
|
{
|
||||||
tDebug() << "AudioControls got drop:" << e->mimeData()->formats();
|
tDebug() << "AudioControls got drop:" << e->mimeData()->formats();
|
||||||
if ( GlobalActionManager::instance()->acceptsMimeData( e->mimeData() ) )
|
if ( DropJob::acceptsMimeData( e->mimeData() ) )
|
||||||
{
|
{
|
||||||
connect( GlobalActionManager::instance(), SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( droppedTracks( QList<Tomahawk::query_ptr> ) ) );
|
DropJob *dj = new DropJob();
|
||||||
GlobalActionManager::instance()->tracksFromMimeData( e->mimeData() );
|
connect( dj, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( droppedTracks( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
dj->tracksFromMimeData( e->mimeData() );
|
||||||
|
|
||||||
e->accept();
|
e->accept();
|
||||||
}
|
}
|
||||||
@@ -551,8 +553,6 @@ AudioControls::dropEvent( QDropEvent* e )
|
|||||||
void
|
void
|
||||||
AudioControls::droppedTracks( QList< query_ptr > tracks )
|
AudioControls::droppedTracks( QList< query_ptr > tracks )
|
||||||
{
|
{
|
||||||
disconnect( GlobalActionManager::instance(), SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( droppedTracks( QList<Tomahawk::query_ptr> ) ) );
|
|
||||||
|
|
||||||
if ( !tracks.isEmpty() )
|
if ( !tracks.isEmpty() )
|
||||||
{
|
{
|
||||||
// queue and play the first if nothign is playing
|
// queue and play the first if nothign is playing
|
||||||
|
@@ -31,6 +31,7 @@ set( libSources
|
|||||||
viewmanager.cpp
|
viewmanager.cpp
|
||||||
globalactionmanager.cpp
|
globalactionmanager.cpp
|
||||||
contextmenu.cpp
|
contextmenu.cpp
|
||||||
|
dropjob.cpp
|
||||||
|
|
||||||
sip/SipPlugin.cpp
|
sip/SipPlugin.cpp
|
||||||
sip/SipHandler.cpp
|
sip/SipHandler.cpp
|
||||||
@@ -208,6 +209,7 @@ set( libHeaders
|
|||||||
viewmanager.h
|
viewmanager.h
|
||||||
globalactionmanager.h
|
globalactionmanager.h
|
||||||
contextmenu.h
|
contextmenu.h
|
||||||
|
dropjob.h
|
||||||
|
|
||||||
artist.h
|
artist.h
|
||||||
album.h
|
album.h
|
||||||
|
313
src/libtomahawk/dropjob.cpp
Normal file
313
src/libtomahawk/dropjob.cpp
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2011, Michael Zanetti <mzanetti@kde.org>
|
||||||
|
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "dropjob.h"
|
||||||
|
|
||||||
|
#include "artist.h"
|
||||||
|
#include "album.h"
|
||||||
|
|
||||||
|
#include "utils/spotifyparser.h"
|
||||||
|
#include "utils/rdioparser.h"
|
||||||
|
#include "utils/shortenedlinkparser.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
#include "globalactionmanager.h"
|
||||||
|
|
||||||
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
DropJob::DropJob( QObject *parent )
|
||||||
|
: QObject( parent )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DropJob::~DropJob()
|
||||||
|
{
|
||||||
|
qDebug() << "destryong DropJob";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// QMIMEDATA HANDLING
|
||||||
|
|
||||||
|
QStringList
|
||||||
|
DropJob::mimeTypes()
|
||||||
|
{
|
||||||
|
QStringList mimeTypes;
|
||||||
|
mimeTypes << "application/tomahawk.query.list"
|
||||||
|
<< "application/tomahawk.plentry.list"
|
||||||
|
<< "application/tomahawk.result.list"
|
||||||
|
<< "application/tomahawk.result"
|
||||||
|
<< "application/tomahawk.metadata.artist"
|
||||||
|
<< "application/tomahawk.metadata.album"
|
||||||
|
<< "application/tomahawk.mixed"
|
||||||
|
<< "text/plain";
|
||||||
|
return mimeTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
DropJob::acceptsMimeData( const QMimeData* data, bool tracksOnly )
|
||||||
|
{
|
||||||
|
if ( data->hasFormat( "application/tomahawk.query.list" )
|
||||||
|
|| data->hasFormat( "application/tomahawk.plentry.list" )
|
||||||
|
|| data->hasFormat( "application/tomahawk.result.list" )
|
||||||
|
|| data->hasFormat( "application/tomahawk.result" )
|
||||||
|
|| data->hasFormat( "application/tomahawk.mixed" )
|
||||||
|
|| data->hasFormat( "application/tomahawk.metadata.album" )
|
||||||
|
|| data->hasFormat( "application/tomahawk.metadata.artist" ) )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// crude check for spotify tracks
|
||||||
|
if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "spotify" ) &&
|
||||||
|
( tracksOnly ? data->data( "text/plain" ).contains( "track" ) : true ) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// crude check for rdio tracks
|
||||||
|
if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "rdio.com" ) &&
|
||||||
|
( tracksOnly ? data->data( "text/plain" ).contains( "track" ) : true ) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// We whitelist t.co and bit.ly (and j.mp) since they do some link checking. Often playable (e.g. spotify..) links hide behind them,
|
||||||
|
// so we do an extra level of lookup
|
||||||
|
if ( ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "bit.ly" ) ) ||
|
||||||
|
( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "j.mp" ) ) ||
|
||||||
|
( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "t.co" ) ) ||
|
||||||
|
( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "rd.io" ) ) )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DropJob::tracksFromMimeData( const QMimeData* data )
|
||||||
|
{
|
||||||
|
QList< query_ptr > results;
|
||||||
|
if ( data->hasFormat( "application/tomahawk.query.list" ) )
|
||||||
|
results = tracksFromQueryList( data );
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.result.list" ) )
|
||||||
|
results = tracksFromResultList( data );
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.metadata.album" ) )
|
||||||
|
results = tracksFromAlbumMetaData( data );
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.metadata.artist" ) )
|
||||||
|
results = tracksFromArtistMetaData( data );
|
||||||
|
else if ( data->hasFormat( "application/tomahawk.mixed" ) )
|
||||||
|
tracksFromMixedData( data );
|
||||||
|
else if ( data->hasFormat( "text/plain" ) )
|
||||||
|
{
|
||||||
|
QString plainData = QString::fromUtf8( data->data( "text/plain" ).constData() );
|
||||||
|
tDebug() << "Got text/plain mime data:" << data->data( "text/plain" ) << "decoded to:" << plainData;
|
||||||
|
handleTrackUrls ( plainData );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !results.isEmpty() )
|
||||||
|
{
|
||||||
|
emit tracks( results );
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< query_ptr >
|
||||||
|
DropJob::tracksFromQueryList( const QMimeData* data )
|
||||||
|
{
|
||||||
|
QList< query_ptr > queries;
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.query.list" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
qlonglong qptr;
|
||||||
|
stream >> qptr;
|
||||||
|
|
||||||
|
query_ptr* query = reinterpret_cast<query_ptr*>(qptr);
|
||||||
|
if ( query && !query->isNull() )
|
||||||
|
{
|
||||||
|
tDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track();
|
||||||
|
queries << *query;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< query_ptr >
|
||||||
|
DropJob::tracksFromResultList( const QMimeData* data )
|
||||||
|
{
|
||||||
|
QList< query_ptr > queries;
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.result.list" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
qlonglong qptr;
|
||||||
|
stream >> qptr;
|
||||||
|
|
||||||
|
result_ptr* result = reinterpret_cast<result_ptr*>(qptr);
|
||||||
|
if ( result && !result->isNull() )
|
||||||
|
{
|
||||||
|
tDebug() << "Dropped result item:" << result->data()->artist()->name() << "-" << result->data()->track();
|
||||||
|
query_ptr q = result->data()->toQuery();
|
||||||
|
q->addResults( QList< result_ptr >() << *result );
|
||||||
|
queries << q;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< query_ptr >
|
||||||
|
DropJob::tracksFromAlbumMetaData( const QMimeData *data )
|
||||||
|
{
|
||||||
|
QList<query_ptr> queries;
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.metadata.album" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
QString artist;
|
||||||
|
stream >> artist;
|
||||||
|
QString album;
|
||||||
|
stream >> album;
|
||||||
|
|
||||||
|
artist_ptr artistPtr = Artist::get( artist );
|
||||||
|
album_ptr albumPtr = Album::get( artistPtr, album );
|
||||||
|
if ( albumPtr->tracks().isEmpty() )
|
||||||
|
connect( albumPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||||
|
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
else
|
||||||
|
queries << albumPtr->tracks();
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< query_ptr >
|
||||||
|
DropJob::tracksFromArtistMetaData( const QMimeData *data )
|
||||||
|
{
|
||||||
|
QList<query_ptr> queries;
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.metadata.artist" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
QString artist;
|
||||||
|
stream >> artist;
|
||||||
|
|
||||||
|
artist_ptr artistPtr = Artist::get( artist );
|
||||||
|
if ( artistPtr->tracks().isEmpty() )
|
||||||
|
connect( artistPtr.data(), SIGNAL( tracksAdded( QList<Tomahawk::query_ptr> ) ),
|
||||||
|
SLOT( onTracksAdded( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
else
|
||||||
|
queries << artistPtr->tracks();
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList< query_ptr >
|
||||||
|
DropJob::tracksFromMixedData( const QMimeData *data )
|
||||||
|
{
|
||||||
|
QList< query_ptr > queries;
|
||||||
|
QByteArray itemData = data->data( "application/tomahawk.mixed" );
|
||||||
|
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
||||||
|
|
||||||
|
QString mimeType;
|
||||||
|
|
||||||
|
while ( !stream.atEnd() )
|
||||||
|
{
|
||||||
|
stream >> mimeType;
|
||||||
|
qDebug() << "mimetype is" << mimeType;
|
||||||
|
|
||||||
|
QByteArray singleData;
|
||||||
|
QDataStream singleStream( &singleData, QIODevice::WriteOnly );
|
||||||
|
|
||||||
|
QMimeData singleMimeData;
|
||||||
|
if ( mimeType == "application/tomahawk.query.list" || mimeType == "application/tomahawk.result.list" )
|
||||||
|
{
|
||||||
|
qlonglong query;
|
||||||
|
stream >> query;
|
||||||
|
singleStream << query;
|
||||||
|
}
|
||||||
|
else if ( mimeType == "application/tomahawk.metadata.album" )
|
||||||
|
{
|
||||||
|
QString artist;
|
||||||
|
stream >> artist;
|
||||||
|
singleStream << artist;
|
||||||
|
QString album;
|
||||||
|
stream >> album;
|
||||||
|
singleStream << album;
|
||||||
|
qDebug() << "got artist" << artist << "and album" << album;
|
||||||
|
}
|
||||||
|
else if ( mimeType == "application/tomahawk.metadata.artist" )
|
||||||
|
{
|
||||||
|
QString artist;
|
||||||
|
stream >> artist;
|
||||||
|
singleStream << artist;
|
||||||
|
qDebug() << "got artist" << artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
singleMimeData.setData( mimeType, singleData );
|
||||||
|
tracksFromMimeData( &singleMimeData );
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DropJob::handleTrackUrls( const QString& urls )
|
||||||
|
{
|
||||||
|
if ( urls.contains( "open.spotify.com/track") ||
|
||||||
|
urls.contains( "spotify:track" ) )
|
||||||
|
{
|
||||||
|
QStringList tracks = urls.split( "\n" );
|
||||||
|
|
||||||
|
tDebug() << "Got a list of spotify urls!" << tracks;
|
||||||
|
SpotifyParser* spot = new SpotifyParser( tracks, this );
|
||||||
|
connect( spot, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
} else if ( urls.contains( "rdio.com" ) )
|
||||||
|
{
|
||||||
|
QStringList tracks = urls.split( "\n" );
|
||||||
|
|
||||||
|
tDebug() << "Got a list of rdio urls!" << tracks;
|
||||||
|
RdioParser* rdio = new RdioParser( this );
|
||||||
|
connect( rdio, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ) );
|
||||||
|
rdio->parse( tracks );
|
||||||
|
} else if ( urls.contains( "bit.ly" ) ||
|
||||||
|
urls.contains( "j.mp" ) ||
|
||||||
|
urls.contains( "t.co" ) ||
|
||||||
|
urls.contains( "rd.io" ) )
|
||||||
|
{
|
||||||
|
QStringList tracks = urls.split( "\n" );
|
||||||
|
|
||||||
|
tDebug() << "Got a list of shortened urls!" << tracks;
|
||||||
|
ShortenedLinkParser* parser = new ShortenedLinkParser( tracks, this );
|
||||||
|
connect( parser, SIGNAL( urls( QStringList ) ), this, SLOT( expandedUrls( QStringList ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DropJob::expandedUrls( QStringList urls )
|
||||||
|
{
|
||||||
|
handleTrackUrls( urls.join( "\n" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DropJob::onTracksAdded( const QList<Tomahawk::query_ptr>& tracksList )
|
||||||
|
{
|
||||||
|
qDebug() << "here i am with" << tracksList.count() << "tracks";
|
||||||
|
emit tracks( tracksList );
|
||||||
|
deleteLater();
|
||||||
|
}
|
68
src/libtomahawk/dropjob.h
Normal file
68
src/libtomahawk/dropjob.h
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2011, Michael Zanetti <mzanetti@kde.org>
|
||||||
|
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef DROPJOB_H
|
||||||
|
#define DROPJOB_H
|
||||||
|
|
||||||
|
#include "query.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QMimeData>
|
||||||
|
|
||||||
|
class DLLEXPORT DropJob : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DropJob( QObject *parent = 0 );
|
||||||
|
~DropJob();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* QMimeData helpers
|
||||||
|
*
|
||||||
|
* Call this to parse the tracks in a QMimeData object to query_ptrs. This will parse internal tomahawk
|
||||||
|
* data as well as all other formats supported (spotify, etc).
|
||||||
|
*
|
||||||
|
* Connect to tracks( QList< query_ptr> ); for the extracted tracks.
|
||||||
|
*/
|
||||||
|
static bool acceptsMimeData( const QMimeData* data, bool tracksOnly = true );
|
||||||
|
static QStringList mimeTypes();
|
||||||
|
void tracksFromMimeData( const QMimeData* data );
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/// QMimeData parsing results
|
||||||
|
void tracks( const QList< Tomahawk::query_ptr >& tracks );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void expandedUrls( QStringList );
|
||||||
|
|
||||||
|
void onTracksAdded( const QList<Tomahawk::query_ptr>& );
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// handle parsing mime data
|
||||||
|
void handleTrackUrls( const QString& urls );
|
||||||
|
QList< Tomahawk::query_ptr > tracksFromQueryList( const QMimeData* d );
|
||||||
|
QList< Tomahawk::query_ptr > tracksFromResultList( const QMimeData* d );
|
||||||
|
QList< Tomahawk::query_ptr > tracksFromArtistMetaData( const QMimeData* d );
|
||||||
|
QList< Tomahawk::query_ptr > tracksFromAlbumMetaData( const QMimeData* d );
|
||||||
|
QList< Tomahawk::query_ptr > tracksFromMixedData( const QMimeData* d );
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DROPJOB_H
|
@@ -64,7 +64,6 @@ GlobalActionManager::instance()
|
|||||||
GlobalActionManager::GlobalActionManager( QObject* parent )
|
GlobalActionManager::GlobalActionManager( QObject* parent )
|
||||||
: QObject( parent )
|
: QObject( parent )
|
||||||
{
|
{
|
||||||
m_mimeTypes << "application/tomahawk.query.list" << "application/tomahawk.plentry.list" << "application/tomahawk.result.list" << "text/plain";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalActionManager::~GlobalActionManager()
|
GlobalActionManager::~GlobalActionManager()
|
||||||
@@ -779,149 +778,6 @@ GlobalActionManager::hostname() const
|
|||||||
return QString( "http://toma.hk" );
|
return QString( "http://toma.hk" );
|
||||||
}
|
}
|
||||||
|
|
||||||
/// QMIMEDATA HANDLING
|
|
||||||
|
|
||||||
QStringList
|
|
||||||
GlobalActionManager::mimeTypes() const
|
|
||||||
{
|
|
||||||
return m_mimeTypes;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
GlobalActionManager::acceptsMimeData( const QMimeData* data, bool tracksOnly )
|
|
||||||
{
|
|
||||||
if ( data->hasFormat( "application/tomahawk.query.list" )
|
|
||||||
|| data->hasFormat( "application/tomahawk.plentry.list" )
|
|
||||||
|| data->hasFormat( "application/tomahawk.result.list" ) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// crude check for spotify tracks
|
|
||||||
if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "spotify" ) &&
|
|
||||||
( tracksOnly ? data->data( "text/plain" ).contains( "track" ) : true ) )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// crude check for rdio tracks
|
|
||||||
if ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "rdio.com" ) &&
|
|
||||||
( tracksOnly ? data->data( "text/plain" ).contains( "track" ) : true ) )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// We whitelist t.co and bit.ly (and j.mp) since they do some link checking. Often playable (e.g. spotify..) links hide behind them,
|
|
||||||
// so we do an extra level of lookup
|
|
||||||
if ( ( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "bit.ly" ) ) ||
|
|
||||||
( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "j.mp" ) ) ||
|
|
||||||
( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "t.co" ) ) ||
|
|
||||||
( data->hasFormat( "text/plain" ) && data->data( "text/plain" ).contains( "rd.io" ) ) )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
GlobalActionManager::tracksFromMimeData( const QMimeData* data )
|
|
||||||
{
|
|
||||||
if ( data->hasFormat( "application/tomahawk.query.list" ) )
|
|
||||||
emit tracks( tracksFromQueryList( data ) );
|
|
||||||
else if ( data->hasFormat( "application/tomahawk.result.list" ) )
|
|
||||||
emit tracks( tracksFromResultList( data ) );
|
|
||||||
else if ( data->hasFormat( "text/plain" ) )
|
|
||||||
{
|
|
||||||
QString plainData = QString::fromUtf8( data->data( "text/plain" ).constData() );
|
|
||||||
tDebug() << "Got text/plain mime data:" << data->data( "text/plain" ) << "decoded to:" << plainData;
|
|
||||||
handleTrackUrls ( plainData );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
GlobalActionManager::handleTrackUrls( const QString& urls )
|
|
||||||
{
|
|
||||||
if ( urls.contains( "open.spotify.com/track") ||
|
|
||||||
urls.contains( "spotify:track" ) )
|
|
||||||
{
|
|
||||||
QStringList tracks = urls.split( "\n" );
|
|
||||||
|
|
||||||
tDebug() << "Got a list of spotify urls!" << tracks;
|
|
||||||
SpotifyParser* spot = new SpotifyParser( tracks, this );
|
|
||||||
connect( spot, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ) );
|
|
||||||
} else if ( urls.contains( "rdio.com" ) )
|
|
||||||
{
|
|
||||||
QStringList tracks = urls.split( "\n" );
|
|
||||||
|
|
||||||
tDebug() << "Got a list of rdio urls!" << tracks;
|
|
||||||
RdioParser* rdio = new RdioParser( this );
|
|
||||||
connect( rdio, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ) );
|
|
||||||
rdio->parse( tracks );
|
|
||||||
} else if ( urls.contains( "bit.ly" ) ||
|
|
||||||
urls.contains( "j.mp" ) ||
|
|
||||||
urls.contains( "t.co" ) ||
|
|
||||||
urls.contains( "rd.io" ) )
|
|
||||||
{
|
|
||||||
QStringList tracks = urls.split( "\n" );
|
|
||||||
|
|
||||||
tDebug() << "Got a list of shortened urls!" << tracks;
|
|
||||||
ShortenedLinkParser* parser = new ShortenedLinkParser( tracks, this );
|
|
||||||
connect( parser, SIGNAL( urls( QStringList ) ), this, SLOT( expandedUrls( QStringList ) ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
GlobalActionManager::expandedUrls( QStringList urls )
|
|
||||||
{
|
|
||||||
handleTrackUrls( urls.join( "\n" ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QList< query_ptr >
|
|
||||||
GlobalActionManager::tracksFromQueryList( const QMimeData* data )
|
|
||||||
{
|
|
||||||
QList< query_ptr > queries;
|
|
||||||
QByteArray itemData = data->data( "application/tomahawk.query.list" );
|
|
||||||
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
|
||||||
|
|
||||||
while ( !stream.atEnd() )
|
|
||||||
{
|
|
||||||
qlonglong qptr;
|
|
||||||
stream >> qptr;
|
|
||||||
|
|
||||||
query_ptr* query = reinterpret_cast<query_ptr*>(qptr);
|
|
||||||
if ( query && !query->isNull() )
|
|
||||||
{
|
|
||||||
tDebug() << "Dropped query item:" << query->data()->artist() << "-" << query->data()->track();
|
|
||||||
queries << *query;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return queries;
|
|
||||||
}
|
|
||||||
|
|
||||||
QList< query_ptr >
|
|
||||||
GlobalActionManager::tracksFromResultList( const QMimeData* data )
|
|
||||||
{
|
|
||||||
QList< query_ptr > queries;
|
|
||||||
QByteArray itemData = data->data( "application/tomahawk.result.list" );
|
|
||||||
QDataStream stream( &itemData, QIODevice::ReadOnly );
|
|
||||||
|
|
||||||
while ( !stream.atEnd() )
|
|
||||||
{
|
|
||||||
qlonglong qptr;
|
|
||||||
stream >> qptr;
|
|
||||||
|
|
||||||
result_ptr* result = reinterpret_cast<result_ptr*>(qptr);
|
|
||||||
if ( result && !result->isNull() )
|
|
||||||
{
|
|
||||||
tDebug() << "Dropped result item:" << result->data()->artist()->name() << "-" << result->data()->track();
|
|
||||||
query_ptr q = result->data()->toQuery();
|
|
||||||
q->addResults( QList< result_ptr >() << *result );
|
|
||||||
queries << q;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return queries;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// SPOTIFY URL HANDLING
|
/// SPOTIFY URL HANDLING
|
||||||
|
|
||||||
|
@@ -51,18 +51,6 @@ public:
|
|||||||
QString copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist );
|
QString copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist );
|
||||||
void savePlaylistToFile( const Tomahawk::playlist_ptr& playlist, const QString& filename );
|
void savePlaylistToFile( const Tomahawk::playlist_ptr& playlist, const QString& filename );
|
||||||
|
|
||||||
/**
|
|
||||||
* QMimeData helpers
|
|
||||||
*
|
|
||||||
* Call this to parse the tracks in a QMimeData object to query_ptrs. This will parse internal tomahawk
|
|
||||||
* data as well as all other formats supported (spotify, etc).
|
|
||||||
*
|
|
||||||
* Connect to tracks( QList< query_ptr> ); for the extracted tracks.
|
|
||||||
*/
|
|
||||||
bool acceptsMimeData( const QMimeData* data, bool tracksOnly = true );
|
|
||||||
void tracksFromMimeData( const QMimeData* data );
|
|
||||||
QStringList mimeTypes() const;
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool parseTomahawkLink( const QString& link );
|
bool parseTomahawkLink( const QString& link );
|
||||||
void waitingForResolved( bool );
|
void waitingForResolved( bool );
|
||||||
@@ -70,16 +58,12 @@ public slots:
|
|||||||
Tomahawk::dynplaylist_ptr loadDynamicPlaylist( const QUrl& url, bool station );
|
Tomahawk::dynplaylist_ptr loadDynamicPlaylist( const QUrl& url, bool station );
|
||||||
|
|
||||||
void handleOpenTrack( const Tomahawk::query_ptr& qry );
|
void handleOpenTrack( const Tomahawk::query_ptr& qry );
|
||||||
signals:
|
|
||||||
/// QMimeData parsing results
|
|
||||||
void tracks( const QList< Tomahawk::query_ptr >& tracks );
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void bookmarkPlaylistCreated( const Tomahawk::playlist_ptr& pl );
|
void bookmarkPlaylistCreated( const Tomahawk::playlist_ptr& pl );
|
||||||
void showPlaylist();
|
void showPlaylist();
|
||||||
|
|
||||||
void xspfCreated( const QByteArray& xspf );
|
void xspfCreated( const QByteArray& xspf );
|
||||||
void expandedUrls( QStringList );
|
|
||||||
|
|
||||||
void spotifyToPlay( const Tomahawk::query_ptr& );
|
void spotifyToPlay( const Tomahawk::query_ptr& );
|
||||||
private:
|
private:
|
||||||
@@ -101,18 +85,12 @@ private:
|
|||||||
bool playSpotify( const QUrl& url );
|
bool playSpotify( const QUrl& url );
|
||||||
bool queueSpotify( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems );
|
bool queueSpotify( const QStringList& parts, const QList< QPair< QString, QString > >& queryItems );
|
||||||
|
|
||||||
/// handle parsing mime data
|
|
||||||
void handleTrackUrls( const QString& urls );
|
|
||||||
QList< Tomahawk::query_ptr > tracksFromQueryList( const QMimeData* d );
|
|
||||||
QList< Tomahawk::query_ptr > tracksFromResultList( const QMimeData* d );
|
|
||||||
|
|
||||||
QString hostname() const;
|
QString hostname() const;
|
||||||
|
|
||||||
Tomahawk::playlist_ptr m_toShow;
|
Tomahawk::playlist_ptr m_toShow;
|
||||||
Tomahawk::query_ptr m_waitingToBookmark;
|
Tomahawk::query_ptr m_waitingToBookmark;
|
||||||
Tomahawk::query_ptr m_waitingToPlay;
|
Tomahawk::query_ptr m_waitingToPlay;
|
||||||
|
|
||||||
QStringList m_mimeTypes;
|
|
||||||
static GlobalActionManager* s_instance;
|
static GlobalActionManager* s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
#include "database/databasecommand_playbackhistory.h"
|
#include "database/databasecommand_playbackhistory.h"
|
||||||
#include "dynamic/GeneratorInterface.h"
|
#include "dynamic/GeneratorInterface.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "globalactionmanager.h"
|
#include "dropjob.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -358,14 +358,15 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r
|
|||||||
if ( action == Qt::IgnoreAction || isReadOnly() )
|
if ( action == Qt::IgnoreAction || isReadOnly() )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if ( !GlobalActionManager::instance()->acceptsMimeData( data ) )
|
if ( !DropJob::acceptsMimeData( data ) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_dropStorage.row = row;
|
m_dropStorage.row = row;
|
||||||
m_dropStorage.parent = QPersistentModelIndex( parent );
|
m_dropStorage.parent = QPersistentModelIndex( parent );
|
||||||
m_dropStorage.action = action;
|
m_dropStorage.action = action;
|
||||||
connect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
DropJob *dj = new DropJob();
|
||||||
GlobalActionManager::instance()->tracksFromMimeData( data );
|
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
||||||
|
dj->tracksFromMimeData( data );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -377,8 +378,6 @@ PlaylistModel::parsedDroppedTracks( QList< query_ptr > tracks )
|
|||||||
if ( m_dropStorage.row == -10 ) // nope
|
if ( m_dropStorage.row == -10 ) // nope
|
||||||
return;
|
return;
|
||||||
|
|
||||||
disconnect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
|
||||||
|
|
||||||
int beginRow;
|
int beginRow;
|
||||||
if ( m_dropStorage.row != -1 )
|
if ( m_dropStorage.row != -1 )
|
||||||
beginRow = m_dropStorage.row;
|
beginRow = m_dropStorage.row;
|
||||||
|
@@ -33,7 +33,7 @@
|
|||||||
#include "dynamic/widgets/LoadingSpinner.h"
|
#include "dynamic/widgets/LoadingSpinner.h"
|
||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include <globalactionmanager.h>
|
#include "dropjob.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ TrackView::dragEnterEvent( QDragEnterEvent* event )
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
QTreeView::dragEnterEvent( event );
|
QTreeView::dragEnterEvent( event );
|
||||||
|
|
||||||
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
|
if ( DropJob::acceptsMimeData( event->mimeData() ) )
|
||||||
{
|
{
|
||||||
m_dragging = true;
|
m_dragging = true;
|
||||||
m_dropRect = QRect();
|
m_dropRect = QRect();
|
||||||
@@ -236,7 +236,7 @@ TrackView::dragMoveEvent( QDragMoveEvent* event )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
|
if ( DropJob::acceptsMimeData( event->mimeData() ) )
|
||||||
{
|
{
|
||||||
setDirtyRegion( m_dropRect );
|
setDirtyRegion( m_dropRect );
|
||||||
const QPoint pos = event->pos();
|
const QPoint pos = event->pos();
|
||||||
@@ -278,7 +278,7 @@ TrackView::dropEvent( QDropEvent* event )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
|
if ( DropJob::acceptsMimeData( event->mimeData() ) )
|
||||||
{
|
{
|
||||||
const QPoint pos = event->pos();
|
const QPoint pos = event->pos();
|
||||||
const QModelIndex index = indexAt( pos );
|
const QModelIndex index = indexAt( pos );
|
||||||
|
@@ -293,6 +293,8 @@ TreeModel::flags( const QModelIndex& index ) const
|
|||||||
TreeModelItem* item = itemFromIndex( index );
|
TreeModelItem* item = itemFromIndex( index );
|
||||||
if ( item && !item->result().isNull() )
|
if ( item && !item->result().isNull() )
|
||||||
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
|
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
|
||||||
|
if ( item && ( !item->album().isNull() || !item->artist().isNull() ) )
|
||||||
|
return Qt::ItemIsDragEnabled | defaultFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
return defaultFlags;
|
return defaultFlags;
|
||||||
@@ -303,7 +305,7 @@ QStringList
|
|||||||
TreeModel::mimeTypes() const
|
TreeModel::mimeTypes() const
|
||||||
{
|
{
|
||||||
QStringList types;
|
QStringList types;
|
||||||
types << "application/tomahawk.result.list";
|
types << "application/tomahawk.mixed";
|
||||||
return types;
|
return types;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,21 +320,32 @@ TreeModel::mimeData( const QModelIndexList &indexes ) const
|
|||||||
|
|
||||||
foreach ( const QModelIndex& i, indexes )
|
foreach ( const QModelIndex& i, indexes )
|
||||||
{
|
{
|
||||||
if ( i.column() > 0 )
|
if ( i.column() > 0 || indexes.contains( i.parent() ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
QModelIndex idx = index( i.row(), 0, i.parent() );
|
TreeModelItem* item = itemFromIndex( i );
|
||||||
TreeModelItem* item = itemFromIndex( idx );
|
if ( !item )
|
||||||
if ( item && !item->result().isNull() )
|
continue;
|
||||||
|
|
||||||
|
if ( !item->artist().isNull() )
|
||||||
|
{
|
||||||
|
const artist_ptr& artist = item->artist();
|
||||||
|
resultStream << QString( "application/tomahawk.metadata.artist" ) << artist->name();
|
||||||
|
}
|
||||||
|
else if ( !item->album().isNull() )
|
||||||
|
{
|
||||||
|
const album_ptr& album = item->album();
|
||||||
|
resultStream << QString( "application/tomahawk.metadata.album" ) << album->artist()->name() << album->name();
|
||||||
|
}
|
||||||
|
else if ( !item->result().isNull() )
|
||||||
{
|
{
|
||||||
const result_ptr& result = item->result();
|
const result_ptr& result = item->result();
|
||||||
resultStream << qlonglong( &result );
|
resultStream << QString( "application/tomahawk.result.list" ) << qlonglong( &result );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QMimeData* mimeData = new QMimeData();
|
QMimeData* mimeData = new QMimeData();
|
||||||
mimeData->setData( "application/tomahawk.result.list", resultData );
|
mimeData->setData( "application/tomahawk.mixed", resultData );
|
||||||
|
|
||||||
return mimeData;
|
return mimeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,3 +1,22 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2011, Michael Zanetti <mzanetti@kde.org>
|
||||||
|
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "settingslistdelegate.h"
|
#include "settingslistdelegate.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
|
@@ -1,3 +1,22 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2011, Michael Zanetti <mzanetti@kde.org>
|
||||||
|
* Copyright 2011, Leo Franchi <lfranchi@kde.org>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef SETTINGSLISTDELEGATE_H
|
#ifndef SETTINGSLISTDELEGATE_H
|
||||||
#define SETTINGSLISTDELEGATE_H
|
#define SETTINGSLISTDELEGATE_H
|
||||||
|
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "widgets/playlisttypeselectordlg.h"
|
#include "widgets/playlisttypeselectordlg.h"
|
||||||
#include <playlist/dynamic/GeneratorInterface.h>
|
#include <playlist/dynamic/GeneratorInterface.h>
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include <globalactionmanager.h>
|
#include "dropjob.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ CategoryAddItem::icon() const
|
|||||||
bool
|
bool
|
||||||
CategoryAddItem::willAcceptDrag( const QMimeData* data ) const
|
CategoryAddItem::willAcceptDrag( const QMimeData* data ) const
|
||||||
{
|
{
|
||||||
if ( ( m_categoryType == SourcesModel::PlaylistsCategory || m_categoryType == SourcesModel::StationsCategory ) && GlobalActionManager::instance()->acceptsMimeData( data ) )
|
if ( ( m_categoryType == SourcesModel::PlaylistsCategory || m_categoryType == SourcesModel::StationsCategory ) && DropJob::acceptsMimeData( data ) )
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -134,8 +134,9 @@ bool
|
|||||||
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
|
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
|
||||||
{
|
{
|
||||||
// Create a new playlist seeded with these items
|
// Create a new playlist seeded with these items
|
||||||
connect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
DropJob *dj = new DropJob();
|
||||||
GlobalActionManager::instance()->tracksFromMimeData( data );
|
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
||||||
|
dj->tracksFromMimeData( data );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -143,7 +144,6 @@ CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
|
|||||||
void
|
void
|
||||||
CategoryAddItem::parsedDroppedTracks( const QList< query_ptr >& tracks )
|
CategoryAddItem::parsedDroppedTracks( const QList< query_ptr >& tracks )
|
||||||
{
|
{
|
||||||
disconnect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
|
||||||
if( m_categoryType == SourcesModel::PlaylistsCategory ) {
|
if( m_categoryType == SourcesModel::PlaylistsCategory ) {
|
||||||
|
|
||||||
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false, tracks );
|
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false, tracks );
|
||||||
|
@@ -28,7 +28,7 @@
|
|||||||
#include "collectionitem.h"
|
#include "collectionitem.h"
|
||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "globalactionmanager.h"
|
#include "dropjob.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
@@ -142,8 +142,9 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
|||||||
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
|
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
|
||||||
return false; // don't allow dropping on ourselves
|
return false; // don't allow dropping on ourselves
|
||||||
|
|
||||||
connect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
DropJob *dj = new DropJob();
|
||||||
GlobalActionManager::instance()->tracksFromMimeData( data );
|
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
||||||
|
dj->tracksFromMimeData( data );
|
||||||
|
|
||||||
// TODO cant' know if it works or not yet...
|
// TODO cant' know if it works or not yet...
|
||||||
return true;
|
return true;
|
||||||
@@ -152,7 +153,6 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
|
|||||||
void
|
void
|
||||||
PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks)
|
PlaylistItem::parsedDroppedTracks( const QList< query_ptr >& tracks)
|
||||||
{
|
{
|
||||||
disconnect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
|
|
||||||
if ( tracks.count() && !m_playlist.isNull() && m_playlist->author()->isLocal() )
|
if ( tracks.count() && !m_playlist.isNull() && m_playlist->author()->isLocal() )
|
||||||
{
|
{
|
||||||
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();
|
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include "globalactionmanager.h"
|
#include "globalactionmanager.h"
|
||||||
|
#include "dropjob.h"
|
||||||
#include "items/playlistitems.h"
|
#include "items/playlistitems.h"
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
@@ -175,7 +176,7 @@ SourcesModel::setData( const QModelIndex& index, const QVariant& value, int role
|
|||||||
QStringList
|
QStringList
|
||||||
SourcesModel::mimeTypes() const
|
SourcesModel::mimeTypes() const
|
||||||
{
|
{
|
||||||
return GlobalActionManager::instance()->mimeTypes();
|
return DropJob::mimeTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -37,7 +37,8 @@
|
|||||||
#include "audio/audioengine.h"
|
#include "audio/audioengine.h"
|
||||||
#include "sourceplaylistinterface.h"
|
#include "sourceplaylistinterface.h"
|
||||||
#include "tomahawksettings.h"
|
#include "tomahawksettings.h"
|
||||||
#include <globalactionmanager.h>
|
#include "globalactionmanager.h"
|
||||||
|
#include "dropjob.h"
|
||||||
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
|
||||||
@@ -439,7 +440,7 @@ SourceTreeView::dragEnterEvent( QDragEnterEvent* event )
|
|||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
QTreeView::dragEnterEvent( event );
|
QTreeView::dragEnterEvent( event );
|
||||||
|
|
||||||
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
|
if ( DropJob::acceptsMimeData( event->mimeData() ) )
|
||||||
{
|
{
|
||||||
m_dragging = true;
|
m_dragging = true;
|
||||||
m_dropRect = QRect();
|
m_dropRect = QRect();
|
||||||
@@ -470,7 +471,7 @@ SourceTreeView::dragMoveEvent( QDragMoveEvent* event )
|
|||||||
bool accept = false;
|
bool accept = false;
|
||||||
QTreeView::dragMoveEvent( event );
|
QTreeView::dragMoveEvent( event );
|
||||||
|
|
||||||
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
|
if ( DropJob::acceptsMimeData( event->mimeData() ) )
|
||||||
{
|
{
|
||||||
setDirtyRegion( m_dropRect );
|
setDirtyRegion( m_dropRect );
|
||||||
const QPoint pos = event->pos();
|
const QPoint pos = event->pos();
|
||||||
|
Reference in New Issue
Block a user