mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
Added ScriptCommand_AllTracks.
This commit is contained in:
parent
48c56e81f7
commit
6c5ad05d27
@ -21,6 +21,7 @@
|
||||
#include "AlbumPlaylistInterface.h"
|
||||
|
||||
#include "Artist.h"
|
||||
#include "collection/TracksRequest.h"
|
||||
#include "database/Database.h"
|
||||
#include "database/DatabaseImpl.h"
|
||||
#include "database/DatabaseCommand_AllTracks.h"
|
||||
@ -144,11 +145,13 @@ AlbumPlaylistInterface::tracks() const
|
||||
}
|
||||
else
|
||||
{
|
||||
connect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ),
|
||||
SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ), Qt::UniqueConnection );
|
||||
|
||||
Tomahawk::album_ptr ap = Album::get( m_album->id(), m_album->name(), m_album->artist() );
|
||||
m_collection->tracks( ap );
|
||||
|
||||
Tomahawk::TracksRequest* cmd = m_collection->requestTracks( ap );
|
||||
connect( dynamic_cast< QObject* >( cmd ), SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ),
|
||||
this, SLOT( onTracksLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
cmd->enqueue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -239,11 +242,13 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId )
|
||||
}
|
||||
else
|
||||
{
|
||||
connect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ),
|
||||
SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ), Qt::UniqueConnection );
|
||||
|
||||
Tomahawk::album_ptr ap = Album::get( m_album->id(), m_album->name(), m_album->artist() );
|
||||
m_collection->tracks( ap );
|
||||
|
||||
Tomahawk::TracksRequest* cmd = m_collection->requestTracks( ap );
|
||||
connect( dynamic_cast< QObject* >( cmd ), SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ),
|
||||
this, SLOT( onTracksLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
cmd->enqueue();
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -257,9 +262,6 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId )
|
||||
void
|
||||
AlbumPlaylistInterface::onTracksLoaded( const QList< query_ptr >& tracks )
|
||||
{
|
||||
disconnect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ),
|
||||
this, SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ) );
|
||||
|
||||
if ( m_collection.isNull() )
|
||||
{
|
||||
m_databaseLoaded = true;
|
||||
|
@ -305,6 +305,7 @@ list(APPEND libSources
|
||||
resolvers/ScriptCollection.cpp
|
||||
resolvers/ScriptCommand_AllArtists.cpp
|
||||
resolvers/ScriptCommand_AllAlbums.cpp
|
||||
resolvers/ScriptCommand_AllTracks.cpp
|
||||
resolvers/ScriptCommandQueue.cpp
|
||||
|
||||
sip/SipPlugin.cpp
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "playlist/dynamic/DynamicPlaylist.h"
|
||||
#include "collection/ArtistsRequest.h"
|
||||
#include "collection/AlbumsRequest.h"
|
||||
#include "collection/TracksRequest.h"
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
@ -84,15 +85,12 @@ public:
|
||||
// Async requests. Emit artists/albums/tracksResult in subclasses when finished.
|
||||
virtual Tomahawk::ArtistsRequest* requestArtists() = 0;
|
||||
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ) = 0;
|
||||
virtual void tracks( const Tomahawk::album_ptr& album ) = 0;
|
||||
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album ) = 0;
|
||||
|
||||
const source_ptr& source() const;
|
||||
unsigned int lastmodified() const { return m_lastmodified; }
|
||||
|
||||
signals:
|
||||
void albumsResult( const QList< Tomahawk::album_ptr >& albums );
|
||||
void tracksResult( const QList< Tomahawk::query_ptr >& queries );
|
||||
|
||||
void tracksAdded( const QList<unsigned int>& fileids );
|
||||
void tracksRemoved( const QList<unsigned int>& fileids );
|
||||
|
||||
|
43
src/libtomahawk/collection/TracksRequest.h
Normal file
43
src/libtomahawk/collection/TracksRequest.h
Normal file
@ -0,0 +1,43 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Teo Mrnjavac <teo@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 TRACKSREQUEST_H
|
||||
#define TRACKSREQUEST_H
|
||||
|
||||
#include "Typedefs.h"
|
||||
#include "DllMacro.h"
|
||||
|
||||
#include <QList>
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
|
||||
class DLLEXPORT TracksRequest
|
||||
{
|
||||
public:
|
||||
virtual ~TracksRequest() {}
|
||||
|
||||
virtual void enqueue() = 0;
|
||||
|
||||
protected: //signals
|
||||
virtual void tracks( const QList< Tomahawk::query_ptr >& ) = 0;
|
||||
};
|
||||
|
||||
} //ns
|
||||
|
||||
#endif // TRACKSREQUEST_H
|
@ -161,29 +161,19 @@ DatabaseCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCollection::tracks( const Tomahawk::album_ptr& album )
|
||||
Tomahawk::TracksRequest*
|
||||
DatabaseCollection::requestTracks( const Tomahawk::album_ptr& album )
|
||||
{
|
||||
//FIXME: assuming there's only one dbcollection per source, and that this is the one
|
||||
Tomahawk::collection_ptr thisCollection = source()->dbCollection();
|
||||
if ( thisCollection->name() != this->name() )
|
||||
return;
|
||||
return 0;
|
||||
|
||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( thisCollection );
|
||||
cmd->setAlbum( album->weakRef() );
|
||||
cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition );
|
||||
|
||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
|
||||
SLOT( onTracksFetched( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCollection::onTracksFetched( const QList< query_ptr >& tracks )
|
||||
{
|
||||
emit tracksResult( tracks );
|
||||
return cmd;
|
||||
}
|
||||
|
||||
|
||||
|
@ -52,15 +52,13 @@ public:
|
||||
|
||||
virtual Tomahawk::ArtistsRequest* requestArtists();
|
||||
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
|
||||
virtual void tracks( const Tomahawk::album_ptr& album );
|
||||
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album );
|
||||
|
||||
public slots:
|
||||
virtual void addTracks( const QList<QVariant>& newitems );
|
||||
virtual void removeTracks( const QDir& dir );
|
||||
|
||||
private slots:
|
||||
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
|
||||
|
||||
void stationCreated( const Tomahawk::source_ptr& source, const QVariantList& data );
|
||||
void autoPlaylistCreated( const Tomahawk::source_ptr& source, const QVariantList& data );
|
||||
};
|
||||
|
@ -164,5 +164,6 @@ DatabaseCommand_AllTracks::exec( DatabaseImpl* dbi )
|
||||
}
|
||||
|
||||
emit tracks( ql, data() );
|
||||
emit tracks( ql );
|
||||
emit done( m_collection );
|
||||
}
|
||||
|
@ -23,7 +23,9 @@
|
||||
#include <QVariantMap>
|
||||
|
||||
#include "DatabaseCommand.h"
|
||||
#include "Database.h"
|
||||
#include "collection/Collection.h"
|
||||
#include "collection/TracksRequest.h"
|
||||
#include "Typedefs.h"
|
||||
#include "Query.h"
|
||||
#include "Artist.h"
|
||||
@ -32,6 +34,7 @@
|
||||
#include "DllMacro.h"
|
||||
|
||||
class DLLEXPORT DatabaseCommand_AllTracks : public DatabaseCommand
|
||||
, public Tomahawk::TracksRequest
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
@ -57,6 +60,8 @@ public:
|
||||
virtual bool doesMutates() const { return false; }
|
||||
virtual QString commandname() const { return "alltracks"; }
|
||||
|
||||
virtual void enqueue() { Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( this ) ); }
|
||||
|
||||
void setArtist( const Tomahawk::artist_ptr& artist ) { m_artist = artist; }
|
||||
void setAlbum( const Tomahawk::album_ptr& album ) { m_album = album; }
|
||||
|
||||
@ -66,6 +71,7 @@ public:
|
||||
|
||||
signals:
|
||||
void tracks( const QList<Tomahawk::query_ptr>&, const QVariant& data );
|
||||
void tracks( const QList<Tomahawk::query_ptr>& );
|
||||
void done( const Tomahawk::collection_ptr& );
|
||||
|
||||
private:
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "ScriptCommandQueue.h"
|
||||
#include "ScriptCommand_AllArtists.h"
|
||||
#include "ScriptCommand_AllAlbums.h"
|
||||
#include "ScriptCommand_AllTracks.h"
|
||||
|
||||
#include <boost/function.hpp>
|
||||
|
||||
@ -51,6 +52,7 @@ Q_OBJECT
|
||||
friend class ::ScriptCommandQueue;
|
||||
friend class ::ScriptCommand_AllArtists;
|
||||
friend class ::ScriptCommand_AllAlbums;
|
||||
friend class ::ScriptCommand_AllTracks;
|
||||
|
||||
public:
|
||||
enum ErrorState {
|
||||
|
@ -230,8 +230,7 @@ QtScriptResolverHelper::addAlbumTrackResults( const QVariantMap& results )
|
||||
|
||||
tDebug() << Q_FUNC_INFO << "about to push" << tracks.count() << "tracks";
|
||||
|
||||
QMetaObject::invokeMethod( collection.data(), "onTracksFetched", Qt::QueuedConnection,
|
||||
Q_ARG( QList< Tomahawk::query_ptr >, queries ) );
|
||||
emit m_resolver->tracksFound( queries );
|
||||
}
|
||||
|
||||
|
||||
@ -570,8 +569,7 @@ QtScriptResolver::tracks( const Tomahawk::collection_ptr& collection, const Toma
|
||||
if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver
|
||||
!capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
||||
{
|
||||
QMetaObject::invokeMethod( collection.data(), "onTracksFetched", Qt::QueuedConnection,
|
||||
Q_ARG( QList< Tomahawk::query_ptr >, QList< Tomahawk::query_ptr >() ) );
|
||||
emit tracksFound( QList< Tomahawk::query_ptr >() );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "utils/Logger.h"
|
||||
#include "resolvers/ScriptCommand_AllArtists.h"
|
||||
#include "resolvers/ScriptCommand_AllAlbums.h"
|
||||
#include "resolvers/ScriptCommand_AllTracks.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
@ -136,15 +137,14 @@ ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCollection::tracks( const Tomahawk::album_ptr& album )
|
||||
Tomahawk::TracksRequest*
|
||||
ScriptCollection::requestTracks( const Tomahawk::album_ptr& album )
|
||||
{
|
||||
//m_resolver->tracks( m_resolver->collections().value( name() ), album );
|
||||
}
|
||||
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
|
||||
if ( thisCollection->name() != this->name() )
|
||||
return 0;
|
||||
|
||||
Tomahawk::TracksRequest* cmd = new ScriptCommand_AllTracks( thisCollection, album );
|
||||
|
||||
void
|
||||
ScriptCollection::onTracksFetched( const QList<query_ptr>& tracks )
|
||||
{
|
||||
emit tracksResult( tracks );
|
||||
return cmd;
|
||||
}
|
||||
|
@ -52,10 +52,7 @@ public:
|
||||
|
||||
virtual Tomahawk::ArtistsRequest* requestArtists();
|
||||
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
|
||||
virtual void tracks( const Tomahawk::album_ptr& album );
|
||||
|
||||
private slots:
|
||||
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
|
||||
virtual Tomahawk::TracksRequest* requestTracks( const Tomahawk::album_ptr& album );
|
||||
|
||||
private:
|
||||
ExternalResolver* m_resolver;
|
||||
|
84
src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp
Normal file
84
src/libtomahawk/resolvers/ScriptCommand_AllTracks.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Teo Mrnjavac <teo@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 "ScriptCommand_AllTracks.h"
|
||||
|
||||
#include "ExternalResolver.h"
|
||||
#include "ScriptCollection.h"
|
||||
|
||||
ScriptCommand_AllTracks::ScriptCommand_AllTracks( const Tomahawk::collection_ptr& collection,
|
||||
const Tomahawk::album_ptr& album,
|
||||
QObject* parent )
|
||||
: ScriptCommand( parent )
|
||||
, m_collection( collection )
|
||||
, m_album( album )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCommand_AllTracks::enqueue()
|
||||
{
|
||||
Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
|
||||
if ( collection == 0 )
|
||||
{
|
||||
emit tracks( QList< Tomahawk::query_ptr >() );
|
||||
return;
|
||||
}
|
||||
|
||||
collection->resolver()->enqueue( QSharedPointer< ScriptCommand >( this ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCommand_AllTracks::exec()
|
||||
{
|
||||
Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
|
||||
if ( collection == 0 )
|
||||
{
|
||||
reportFailure();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( m_album.isNull() )
|
||||
{
|
||||
reportFailure();
|
||||
return;
|
||||
}
|
||||
|
||||
connect( collection->resolver(), SIGNAL( tracksFound( QList< Tomahawk::query_ptr > ) ),
|
||||
this, SLOT( onResolverDone( QList< Tomahawk::query_ptr > ) ) );
|
||||
|
||||
collection->resolver()->tracks( m_collection, m_album );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCommand_AllTracks::reportFailure()
|
||||
{
|
||||
emit tracks( QList< Tomahawk::query_ptr >() );
|
||||
emit done();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCommand_AllTracks::onResolverDone( const QList< Tomahawk::query_ptr >& q )
|
||||
{
|
||||
emit tracks( q );
|
||||
emit done();
|
||||
}
|
54
src/libtomahawk/resolvers/ScriptCommand_AllTracks.h
Normal file
54
src/libtomahawk/resolvers/ScriptCommand_AllTracks.h
Normal file
@ -0,0 +1,54 @@
|
||||
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||
*
|
||||
* Copyright 2013, Teo Mrnjavac <teo@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 SCRIPTCOMMAND_ALLTRACKS_H
|
||||
#define SCRIPTCOMMAND_ALLTRACKS_H
|
||||
|
||||
#include "collection/TracksRequest.h"
|
||||
#include "collection/Collection.h"
|
||||
#include "resolvers/ScriptCommand.h"
|
||||
|
||||
class ScriptCommand_AllTracks : public ScriptCommand
|
||||
, public Tomahawk::TracksRequest
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScriptCommand_AllTracks( const Tomahawk::collection_ptr& collection,
|
||||
const Tomahawk::album_ptr& album,
|
||||
QObject *parent = 0 );
|
||||
virtual ~ScriptCommand_AllTracks() {}
|
||||
|
||||
virtual void enqueue();
|
||||
|
||||
signals:
|
||||
void tracks( const QList< Tomahawk::query_ptr >& );
|
||||
void done();
|
||||
|
||||
protected:
|
||||
virtual void exec();
|
||||
virtual void reportFailure();
|
||||
|
||||
private slots:
|
||||
void onResolverDone( const QList< Tomahawk::query_ptr >& );
|
||||
|
||||
private:
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
Tomahawk::album_ptr m_album;
|
||||
};
|
||||
|
||||
#endif // SCRIPTCOMMAND_ALLTRACKS_H
|
Loading…
x
Reference in New Issue
Block a user