1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-02-24 11:53:09 +01:00

Merge branch 'master' of github.com:tomahawk-player/tomahawk

This commit is contained in:
Alejandro Wainzinger 2011-08-16 22:36:07 +02:00
commit c1498bbae0
15 changed files with 472 additions and 203 deletions

View File

@ -35,6 +35,7 @@
#include "utils/tomahawkutils.h"
#include "utils/logger.h"
#include <globalactionmanager.h>
#include "dropjob.h"
using namespace Tomahawk;
@ -521,7 +522,7 @@ AudioControls::onTrackClicked()
void
AudioControls::dragEnterEvent( QDragEnterEvent* e )
{
if ( GlobalActionManager::instance()->acceptsMimeData( e->mimeData() ) )
if ( DropJob::acceptsMimeData( e->mimeData() ) )
e->acceptProposedAction();
}
@ -538,10 +539,11 @@ void
AudioControls::dropEvent( QDropEvent* e )
{
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> ) ) );
GlobalActionManager::instance()->tracksFromMimeData( e->mimeData() );
DropJob *dj = new DropJob();
connect( dj, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( droppedTracks( QList<Tomahawk::query_ptr> ) ) );
dj->tracksFromMimeData( e->mimeData() );
e->accept();
}
@ -551,8 +553,6 @@ AudioControls::dropEvent( QDropEvent* e )
void
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() )
{
// queue and play the first if nothign is playing

View File

@ -31,6 +31,7 @@ set( libSources
viewmanager.cpp
globalactionmanager.cpp
contextmenu.cpp
dropjob.cpp
sip/SipPlugin.cpp
sip/SipHandler.cpp
@ -208,6 +209,7 @@ set( libHeaders
viewmanager.h
globalactionmanager.h
contextmenu.h
dropjob.h
artist.h
album.h

313
src/libtomahawk/dropjob.cpp Normal file
View 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
View 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

View File

@ -64,7 +64,6 @@ GlobalActionManager::instance()
GlobalActionManager::GlobalActionManager( QObject* parent )
: QObject( parent )
{
m_mimeTypes << "application/tomahawk.query.list" << "application/tomahawk.plentry.list" << "application/tomahawk.result.list" << "text/plain";
}
GlobalActionManager::~GlobalActionManager()
@ -779,149 +778,6 @@ GlobalActionManager::hostname() const
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

View File

@ -51,18 +51,6 @@ public:
QString copyPlaylistToClipboard( const Tomahawk::dynplaylist_ptr& playlist );
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:
bool parseTomahawkLink( const QString& link );
void waitingForResolved( bool );
@ -70,16 +58,12 @@ public slots:
Tomahawk::dynplaylist_ptr loadDynamicPlaylist( const QUrl& url, bool station );
void handleOpenTrack( const Tomahawk::query_ptr& qry );
signals:
/// QMimeData parsing results
void tracks( const QList< Tomahawk::query_ptr >& tracks );
private slots:
void bookmarkPlaylistCreated( const Tomahawk::playlist_ptr& pl );
void showPlaylist();
void xspfCreated( const QByteArray& xspf );
void expandedUrls( QStringList );
void spotifyToPlay( const Tomahawk::query_ptr& );
private:
@ -101,18 +85,12 @@ private:
bool playSpotify( const QUrl& url );
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;
Tomahawk::playlist_ptr m_toShow;
Tomahawk::query_ptr m_waitingToBookmark;
Tomahawk::query_ptr m_waitingToPlay;
QStringList m_mimeTypes;
static GlobalActionManager* s_instance;
};

View File

@ -27,7 +27,7 @@
#include "database/databasecommand_playbackhistory.h"
#include "dynamic/GeneratorInterface.h"
#include "utils/logger.h"
#include "globalactionmanager.h"
#include "dropjob.h"
using namespace Tomahawk;
@ -358,14 +358,15 @@ PlaylistModel::dropMimeData( const QMimeData* data, Qt::DropAction action, int r
if ( action == Qt::IgnoreAction || isReadOnly() )
return true;
if ( !GlobalActionManager::instance()->acceptsMimeData( data ) )
if ( !DropJob::acceptsMimeData( data ) )
return false;
m_dropStorage.row = row;
m_dropStorage.parent = QPersistentModelIndex( parent );
m_dropStorage.action = action;
connect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
GlobalActionManager::instance()->tracksFromMimeData( data );
DropJob *dj = new DropJob();
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
dj->tracksFromMimeData( data );
return true;
}
@ -377,8 +378,6 @@ PlaylistModel::parsedDroppedTracks( QList< query_ptr > tracks )
if ( m_dropStorage.row == -10 ) // nope
return;
disconnect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
int beginRow;
if ( m_dropStorage.row != -1 )
beginRow = m_dropStorage.row;

View File

@ -33,7 +33,7 @@
#include "dynamic/widgets/LoadingSpinner.h"
#include "utils/tomahawkutils.h"
#include "utils/logger.h"
#include <globalactionmanager.h>
#include "dropjob.h"
using namespace Tomahawk;
@ -214,7 +214,7 @@ TrackView::dragEnterEvent( QDragEnterEvent* event )
qDebug() << Q_FUNC_INFO;
QTreeView::dragEnterEvent( event );
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
if ( DropJob::acceptsMimeData( event->mimeData() ) )
{
m_dragging = true;
m_dropRect = QRect();
@ -236,7 +236,7 @@ TrackView::dragMoveEvent( QDragMoveEvent* event )
return;
}
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
if ( DropJob::acceptsMimeData( event->mimeData() ) )
{
setDirtyRegion( m_dropRect );
const QPoint pos = event->pos();
@ -278,7 +278,7 @@ TrackView::dropEvent( QDropEvent* event )
}
else
{
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
if ( DropJob::acceptsMimeData( event->mimeData() ) )
{
const QPoint pos = event->pos();
const QModelIndex index = indexAt( pos );

View File

@ -293,6 +293,8 @@ TreeModel::flags( const QModelIndex& index ) const
TreeModelItem* item = itemFromIndex( index );
if ( item && !item->result().isNull() )
return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags;
if ( item && ( !item->album().isNull() || !item->artist().isNull() ) )
return Qt::ItemIsDragEnabled | defaultFlags;
}
return defaultFlags;
@ -303,7 +305,7 @@ QStringList
TreeModel::mimeTypes() const
{
QStringList types;
types << "application/tomahawk.result.list";
types << "application/tomahawk.mixed";
return types;
}
@ -318,21 +320,32 @@ TreeModel::mimeData( const QModelIndexList &indexes ) const
foreach ( const QModelIndex& i, indexes )
{
if ( i.column() > 0 )
if ( i.column() > 0 || indexes.contains( i.parent() ) )
continue;
QModelIndex idx = index( i.row(), 0, i.parent() );
TreeModelItem* item = itemFromIndex( idx );
if ( item && !item->result().isNull() )
TreeModelItem* item = itemFromIndex( i );
if ( !item )
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();
resultStream << qlonglong( &result );
resultStream << QString( "application/tomahawk.result.list" ) << qlonglong( &result );
}
}
QMimeData* mimeData = new QMimeData();
mimeData->setData( "application/tomahawk.result.list", resultData );
mimeData->setData( "application/tomahawk.mixed", resultData );
return mimeData;
}

View File

@ -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 "utils/logger.h"

View File

@ -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
#define SETTINGSLISTDELEGATE_H

View File

@ -28,7 +28,7 @@
#include "widgets/playlisttypeselectordlg.h"
#include <playlist/dynamic/GeneratorInterface.h>
#include "utils/logger.h"
#include <globalactionmanager.h>
#include "dropjob.h"
using namespace Tomahawk;
@ -122,7 +122,7 @@ CategoryAddItem::icon() const
bool
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;
}
@ -134,8 +134,9 @@ bool
CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
{
// Create a new playlist seeded with these items
connect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
GlobalActionManager::instance()->tracksFromMimeData( data );
DropJob *dj = new DropJob();
connect( dj, SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
dj->tracksFromMimeData( data );
return true;
}
@ -143,7 +144,6 @@ CategoryAddItem::dropMimeData( const QMimeData* data, Qt::DropAction )
void
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 ) {
playlist_ptr newpl = Playlist::create( SourceList::instance()->getLocal(), uuid(), "New Playlist", "", SourceList::instance()->getLocal()->friendlyName(), false, tracks );

View File

@ -28,7 +28,7 @@
#include "collectionitem.h"
#include "utils/tomahawkutils.h"
#include "utils/logger.h"
#include "globalactionmanager.h"
#include "dropjob.h"
using namespace Tomahawk;
@ -142,8 +142,9 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
data->data( "application/tomahawk.playlist.id" ) == m_playlist->guid() )
return false; // don't allow dropping on ourselves
connect( GlobalActionManager::instance(), SIGNAL( tracks( QList< Tomahawk::query_ptr > ) ), this, SLOT( parsedDroppedTracks( QList< Tomahawk::query_ptr > ) ) );
GlobalActionManager::instance()->tracksFromMimeData( data );
DropJob *dj = new DropJob();
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...
return true;
@ -152,7 +153,6 @@ PlaylistItem::dropMimeData( const QMimeData* data, Qt::DropAction action )
void
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() )
{
qDebug() << "on playlist:" << m_playlist->title() << m_playlist->guid() << m_playlist->currentrevision();

View File

@ -33,6 +33,7 @@
#include "utils/logger.h"
#include "globalactionmanager.h"
#include "dropjob.h"
#include "items/playlistitems.h"
using namespace Tomahawk;
@ -175,7 +176,7 @@ SourcesModel::setData( const QModelIndex& index, const QVariant& value, int role
QStringList
SourcesModel::mimeTypes() const
{
return GlobalActionManager::instance()->mimeTypes();
return DropJob::mimeTypes();
}

View File

@ -37,7 +37,8 @@
#include "audio/audioengine.h"
#include "sourceplaylistinterface.h"
#include "tomahawksettings.h"
#include <globalactionmanager.h>
#include "globalactionmanager.h"
#include "dropjob.h"
#include "utils/logger.h"
@ -439,7 +440,7 @@ SourceTreeView::dragEnterEvent( QDragEnterEvent* event )
qDebug() << Q_FUNC_INFO;
QTreeView::dragEnterEvent( event );
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
if ( DropJob::acceptsMimeData( event->mimeData() ) )
{
m_dragging = true;
m_dropRect = QRect();
@ -470,7 +471,7 @@ SourceTreeView::dragMoveEvent( QDragMoveEvent* event )
bool accept = false;
QTreeView::dragMoveEvent( event );
if ( GlobalActionManager::instance()->acceptsMimeData( event->mimeData() ) )
if ( DropJob::acceptsMimeData( event->mimeData() ) )
{
setDirtyRegion( m_dropRect );
const QPoint pos = event->pos();