mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 15:16:34 +02:00
Experimenting with ScriptCommands, added ScriptCommand_AllArtists.
This commit is contained in:
@@ -89,7 +89,6 @@ set( libGuiSources
|
|||||||
resolvers/ExternalResolverGui.cpp
|
resolvers/ExternalResolverGui.cpp
|
||||||
resolvers/ScriptResolver.cpp
|
resolvers/ScriptResolver.cpp
|
||||||
resolvers/QtScriptResolver.cpp
|
resolvers/QtScriptResolver.cpp
|
||||||
resolvers/ScriptCollection.cpp
|
|
||||||
|
|
||||||
utils/ImageRegistry.cpp
|
utils/ImageRegistry.cpp
|
||||||
utils/WidgetDragFilter.cpp
|
utils/WidgetDragFilter.cpp
|
||||||
@@ -301,8 +300,11 @@ list(APPEND libSources
|
|||||||
playlist/dynamic/database/DatabaseControl.cpp
|
playlist/dynamic/database/DatabaseControl.cpp
|
||||||
playlist/dynamic/DynamicControl.cpp
|
playlist/dynamic/DynamicControl.cpp
|
||||||
|
|
||||||
resolvers/Resolver.cpp
|
|
||||||
resolvers/ExternalResolver.cpp
|
resolvers/ExternalResolver.cpp
|
||||||
|
resolvers/Resolver.cpp
|
||||||
|
resolvers/ScriptCollection.cpp
|
||||||
|
resolvers/ScriptCommand_AllArtists.cpp
|
||||||
|
resolvers/ScriptCommandQueue.cpp
|
||||||
|
|
||||||
sip/SipPlugin.cpp
|
sip/SipPlugin.cpp
|
||||||
sip/SipInfo.cpp
|
sip/SipInfo.cpp
|
||||||
|
43
src/libtomahawk/collection/ArtistsRequest.h
Normal file
43
src/libtomahawk/collection/ArtistsRequest.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 ARTISTSREQUEST_H
|
||||||
|
#define ARTISTSREQUEST_H
|
||||||
|
|
||||||
|
#include "Typedefs.h"
|
||||||
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
class DLLEXPORT ArtistsRequest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~ArtistsRequest() {}
|
||||||
|
|
||||||
|
virtual void enqueue() = 0;
|
||||||
|
|
||||||
|
protected: //signals
|
||||||
|
virtual void artists( const QList< Tomahawk::artist_ptr >& ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //ns
|
||||||
|
|
||||||
|
#endif // ARTISTSREQUEST_H
|
@@ -34,6 +34,7 @@
|
|||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "Playlist.h"
|
#include "Playlist.h"
|
||||||
#include "playlist/dynamic/DynamicPlaylist.h"
|
#include "playlist/dynamic/DynamicPlaylist.h"
|
||||||
|
#include "collection/ArtistsRequest.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ public:
|
|||||||
virtual QList< Tomahawk::dynplaylist_ptr > stations() { return m_stations.values(); }
|
virtual QList< Tomahawk::dynplaylist_ptr > stations() { return m_stations.values(); }
|
||||||
|
|
||||||
// Async requests. Emit artists/albums/tracksResult in subclasses when finished.
|
// Async requests. Emit artists/albums/tracksResult in subclasses when finished.
|
||||||
virtual void artists() = 0;
|
virtual Tomahawk::ArtistsRequest* requestArtists() = 0;
|
||||||
virtual void albums( const Tomahawk::artist_ptr& artist ) = 0;
|
virtual void albums( const Tomahawk::artist_ptr& artist ) = 0;
|
||||||
virtual void tracks( const Tomahawk::album_ptr& album ) = 0;
|
virtual void tracks( const Tomahawk::album_ptr& album ) = 0;
|
||||||
|
|
||||||
@@ -88,7 +89,6 @@ public:
|
|||||||
unsigned int lastmodified() const { return m_lastmodified; }
|
unsigned int lastmodified() const { return m_lastmodified; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void artistsResult( const QList< Tomahawk::artist_ptr >& artists );
|
|
||||||
void albumsResult( const QList< Tomahawk::album_ptr >& albums );
|
void albumsResult( const QList< Tomahawk::album_ptr >& albums );
|
||||||
void tracksResult( const QList< Tomahawk::query_ptr >& queries );
|
void tracksResult( const QList< Tomahawk::query_ptr >& queries );
|
||||||
|
|
||||||
|
@@ -133,27 +133,17 @@ DatabaseCollection::stations()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
Tomahawk::ArtistsRequest*
|
||||||
DatabaseCollection::artists()
|
DatabaseCollection::requestArtists()
|
||||||
{
|
{
|
||||||
//FIXME: assuming there's only one dbcollection per source, and that this is the one
|
//FIXME: assuming there's only one dbcollection per source, and that this is the one
|
||||||
Tomahawk::collection_ptr thisCollection = source()->dbCollection();
|
Tomahawk::collection_ptr thisCollection = source()->dbCollection();
|
||||||
if ( thisCollection->name() != this->name() )
|
if ( thisCollection->name() != this->name() )
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( thisCollection );
|
Tomahawk::ArtistsRequest* cmd = new DatabaseCommand_AllArtists( thisCollection );
|
||||||
|
|
||||||
connect( cmd, SIGNAL( artists( QList< Tomahawk::artist_ptr > ) ),
|
return cmd;
|
||||||
SLOT( onArtistsFetched( QList< Tomahawk::artist_ptr > ) ) );
|
|
||||||
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
DatabaseCollection::onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists )
|
|
||||||
{
|
|
||||||
emit artistsResult( artists );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -50,7 +50,7 @@ public:
|
|||||||
virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists();
|
virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists();
|
||||||
virtual QList< Tomahawk::dynplaylist_ptr > stations();
|
virtual QList< Tomahawk::dynplaylist_ptr > stations();
|
||||||
|
|
||||||
virtual void artists();
|
virtual Tomahawk::ArtistsRequest* requestArtists();
|
||||||
virtual void albums( const Tomahawk::artist_ptr& artist );
|
virtual void albums( const Tomahawk::artist_ptr& artist );
|
||||||
virtual void tracks( const Tomahawk::album_ptr& album );
|
virtual void tracks( const Tomahawk::album_ptr& album );
|
||||||
|
|
||||||
@@ -59,7 +59,6 @@ public slots:
|
|||||||
virtual void removeTracks( const QDir& dir );
|
virtual void removeTracks( const QDir& dir );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists );
|
|
||||||
void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums, const QVariant& data );
|
void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums, const QVariant& data );
|
||||||
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
|
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
|
||||||
|
|
||||||
|
@@ -23,13 +23,16 @@
|
|||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
|
||||||
#include "Artist.h"
|
#include "Artist.h"
|
||||||
|
#include "collection/ArtistsRequest.h"
|
||||||
#include "collection/Collection.h"
|
#include "collection/Collection.h"
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "DatabaseCommand.h"
|
#include "DatabaseCommand.h"
|
||||||
|
#include "Database.h"
|
||||||
|
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
class DLLEXPORT DatabaseCommand_AllArtists : public DatabaseCommand
|
class DLLEXPORT DatabaseCommand_AllArtists : public DatabaseCommand
|
||||||
|
, public Tomahawk::ArtistsRequest
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
@@ -47,6 +50,8 @@ public:
|
|||||||
virtual bool doesMutates() const { return false; }
|
virtual bool doesMutates() const { return false; }
|
||||||
virtual QString commandname() const { return "allartists"; }
|
virtual QString commandname() const { return "allartists"; }
|
||||||
|
|
||||||
|
virtual void enqueue() { Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( this ) ); }
|
||||||
|
|
||||||
void setLimit( unsigned int amount ) { m_amount = amount; }
|
void setLimit( unsigned int amount ) { m_amount = amount; }
|
||||||
void setSortOrder( DatabaseCommand_AllArtists::SortOrder order ) { m_sortOrder = order; }
|
void setSortOrder( DatabaseCommand_AllArtists::SortOrder order ) { m_sortOrder = order; }
|
||||||
void setSortDescending( bool descending ) { m_sortDescending = descending; }
|
void setSortDescending( bool descending ) { m_sortDescending = descending; }
|
||||||
|
@@ -253,9 +253,10 @@ TreeModel::addCollection( const collection_ptr& collection )
|
|||||||
|
|
||||||
m_collection = collection;
|
m_collection = collection;
|
||||||
|
|
||||||
connect( m_collection.data(), SIGNAL( artistsResult( QList<Tomahawk::artist_ptr> ) ),
|
Tomahawk::ArtistsRequest* req = m_collection->requestArtists();
|
||||||
SLOT( onArtistsAdded( QList<Tomahawk::artist_ptr> ) ), Qt::UniqueConnection );
|
connect( dynamic_cast< QObject* >( req ), SIGNAL( artists( QList< Tomahawk::artist_ptr > ) ),
|
||||||
m_collection->artists();
|
this, SLOT( onArtistsAdded( QList< Tomahawk::artist_ptr > ) ), Qt::UniqueConnection );
|
||||||
|
req->enqueue();
|
||||||
|
|
||||||
connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection );
|
connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection );
|
||||||
|
|
||||||
|
@@ -25,6 +25,8 @@
|
|||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
#include "Resolver.h"
|
#include "Resolver.h"
|
||||||
|
#include "ScriptCommandQueue.h"
|
||||||
|
#include "ScriptCommand_AllArtists.h"
|
||||||
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
@@ -45,6 +47,9 @@ class DLLEXPORT ExternalResolver : public Resolver
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
friend class ::ScriptCommandQueue;
|
||||||
|
friend class ::ScriptCommand_AllArtists;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum ErrorState {
|
enum ErrorState {
|
||||||
NoError,
|
NoError,
|
||||||
@@ -62,7 +67,9 @@ public:
|
|||||||
Q_DECLARE_FLAGS( Capabilities, Capability )
|
Q_DECLARE_FLAGS( Capabilities, Capability )
|
||||||
Q_FLAGS( Capabilities )
|
Q_FLAGS( Capabilities )
|
||||||
|
|
||||||
ExternalResolver( const QString& filePath ) { m_filePath = filePath; }
|
ExternalResolver( const QString& filePath )
|
||||||
|
: m_commandQueue( new ScriptCommandQueue( this ) )
|
||||||
|
{ m_filePath = filePath; }
|
||||||
|
|
||||||
virtual QString filePath() const { return m_filePath; }
|
virtual QString filePath() const { return m_filePath; }
|
||||||
|
|
||||||
@@ -74,23 +81,31 @@ public:
|
|||||||
virtual Capabilities capabilities() const = 0;
|
virtual Capabilities capabilities() const = 0;
|
||||||
virtual QMap< QString, Tomahawk::collection_ptr > collections() { return m_collections; }
|
virtual QMap< QString, Tomahawk::collection_ptr > collections() { return m_collections; }
|
||||||
|
|
||||||
|
virtual void enqueue( const QSharedPointer< ScriptCommand >& req )
|
||||||
|
{ m_commandQueue->enqueue( req ); }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void start() = 0;
|
virtual void start() = 0;
|
||||||
virtual void stop() = 0;
|
virtual void stop() = 0;
|
||||||
|
|
||||||
// For ScriptCollection
|
|
||||||
virtual void artists( const Tomahawk::collection_ptr& collection ) = 0;
|
|
||||||
virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) = 0;
|
|
||||||
virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) = 0;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed(); // if config widget was added/removed, name changed, etc
|
void changed(); // if config widget was added/removed, name changed, etc
|
||||||
void collectionAdded( const Tomahawk::collection_ptr& collection );
|
void collectionAdded( const Tomahawk::collection_ptr& collection );
|
||||||
void collectionRemoved( const Tomahawk::collection_ptr& collection );
|
void collectionRemoved( const Tomahawk::collection_ptr& collection );
|
||||||
|
|
||||||
|
void artistsFound( const QList< Tomahawk::artist_ptr >& );
|
||||||
|
void albumsFound( const QList< Tomahawk::album_ptr >& );
|
||||||
|
void tracksFound( const QList< Tomahawk::query_ptr >& );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setFilePath( const QString& path ) { m_filePath = path; }
|
void setFilePath( const QString& path ) { m_filePath = path; }
|
||||||
QMap< QString, Tomahawk::collection_ptr > m_collections;
|
QMap< QString, Tomahawk::collection_ptr > m_collections;
|
||||||
|
ScriptCommandQueue* m_commandQueue;
|
||||||
|
|
||||||
|
// Should only be called by ScriptCommands
|
||||||
|
virtual void artists( const Tomahawk::collection_ptr& collection ) = 0;
|
||||||
|
virtual void albums( const Tomahawk::collection_ptr& collection, const Tomahawk::artist_ptr& artist ) = 0;
|
||||||
|
virtual void tracks( const Tomahawk::collection_ptr& collection, const Tomahawk::album_ptr& album ) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_filePath;
|
QString m_filePath;
|
||||||
|
@@ -156,8 +156,8 @@ QtScriptResolverHelper::addArtistResults( const QVariantMap& results )
|
|||||||
tDebug() << Q_FUNC_INFO << "about to push" << artists.count() << "artists";
|
tDebug() << Q_FUNC_INFO << "about to push" << artists.count() << "artists";
|
||||||
foreach( const Tomahawk::artist_ptr& artist, artists)
|
foreach( const Tomahawk::artist_ptr& artist, artists)
|
||||||
tDebug() << artist->name();
|
tDebug() << artist->name();
|
||||||
QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection,
|
|
||||||
Q_ARG( QList< Tomahawk::artist_ptr >, artists ) );
|
emit m_resolver->artistsFound( artists );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -502,8 +502,7 @@ QtScriptResolver::artists( const Tomahawk::collection_ptr& collection )
|
|||||||
if ( !m_collections.contains( collection->name() ) || //if the collection doesn't belong to this resolver
|
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
|
!capabilities().testFlag( Browsable ) ) //or this resolver doesn't even support collections
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod( collection.data(), "onArtistsFetched", Qt::QueuedConnection,
|
emit artistsFound( QList< Tomahawk::artist_ptr >() );
|
||||||
Q_ARG( QList< Tomahawk::artist_ptr >, QList< Tomahawk::artist_ptr >() ) );
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
#include "ExternalResolverGui.h"
|
#include "ExternalResolverGui.h"
|
||||||
#include "utils/TomahawkUtilsGui.h"
|
#include "utils/TomahawkUtilsGui.h"
|
||||||
#include "utils/Logger.h"
|
#include "utils/Logger.h"
|
||||||
|
#include "resolvers/ScriptCommand_AllArtists.h"
|
||||||
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@@ -108,31 +109,30 @@ ScriptCollection::bigIcon() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
Tomahawk::ArtistsRequest*
|
||||||
ScriptCollection::artists()
|
ScriptCollection::requestArtists()
|
||||||
{
|
{
|
||||||
m_resolver->artists( m_resolver->collections().value( name() ) );
|
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
|
||||||
|
if ( thisCollection->name() != this->name() )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Tomahawk::ArtistsRequest* cmd = new ScriptCommand_AllArtists( thisCollection );
|
||||||
|
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScriptCollection::albums( const Tomahawk::artist_ptr& artist )
|
ScriptCollection::albums( const Tomahawk::artist_ptr& artist )
|
||||||
{
|
{
|
||||||
m_resolver->albums( m_resolver->collections().value( name() ), artist );
|
//m_resolver->albums( m_resolver->collections().value( name() ), artist );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ScriptCollection::tracks( const Tomahawk::album_ptr& album )
|
ScriptCollection::tracks( const Tomahawk::album_ptr& album )
|
||||||
{
|
{
|
||||||
m_resolver->tracks( m_resolver->collections().value( name() ), album );
|
//m_resolver->tracks( m_resolver->collections().value( name() ), album );
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ScriptCollection::onArtistsFetched( const QList<artist_ptr>& artists )
|
|
||||||
{
|
|
||||||
emit artistsResult( artists );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "ExternalResolver.h"
|
#include "ExternalResolver.h"
|
||||||
#include "collection/Collection.h"
|
#include "collection/Collection.h"
|
||||||
|
#include "collection/ArtistsRequest.h"
|
||||||
|
|
||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
@@ -48,12 +49,11 @@ public:
|
|||||||
|
|
||||||
virtual ExternalResolver* resolver() { return m_resolver; }
|
virtual ExternalResolver* resolver() { return m_resolver; }
|
||||||
|
|
||||||
virtual void artists();
|
virtual Tomahawk::ArtistsRequest* requestArtists();
|
||||||
virtual void albums( const Tomahawk::artist_ptr& artist );
|
virtual void albums( const Tomahawk::artist_ptr& artist );
|
||||||
virtual void tracks( const Tomahawk::album_ptr& album );
|
virtual void tracks( const Tomahawk::album_ptr& album );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists );
|
|
||||||
void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums );
|
void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums );
|
||||||
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
|
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
|
||||||
|
|
||||||
|
38
src/libtomahawk/resolvers/ScriptCommand.h
Normal file
38
src/libtomahawk/resolvers/ScriptCommand.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* === 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_H
|
||||||
|
#define SCRIPTCOMMAND_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ScriptCommand : public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ScriptCommand( QObject* parent = 0 ) : QObject( parent ) {}
|
||||||
|
virtual ~ScriptCommand() {}
|
||||||
|
|
||||||
|
signals:
|
||||||
|
virtual void done() = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend class ScriptCommandQueue;
|
||||||
|
virtual void exec() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SCRIPTCOMMAND_H
|
65
src/libtomahawk/resolvers/ScriptCommandQueue.cpp
Normal file
65
src/libtomahawk/resolvers/ScriptCommandQueue.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/* === 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 "ScriptCommandQueue.h"
|
||||||
|
|
||||||
|
#include "utils/Closure.h"
|
||||||
|
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
|
ScriptCommandQueue::ScriptCommandQueue( QObject* parent )
|
||||||
|
: QObject( parent )
|
||||||
|
, m_timer( new QTimer( this ) )
|
||||||
|
{
|
||||||
|
m_timer->setSingleShot( true );
|
||||||
|
connect( m_timer, SIGNAL( timeout() ), SLOT( onTimeout() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCommandQueue::enqueue( const QSharedPointer< ScriptCommand >& req )
|
||||||
|
{
|
||||||
|
m_queue.append( req );
|
||||||
|
if ( m_queue.count() == 1 )
|
||||||
|
nextCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCommandQueue::nextCommand()
|
||||||
|
{
|
||||||
|
if ( m_queue.isEmpty() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QSharedPointer< ScriptCommand > req = m_queue.first();
|
||||||
|
|
||||||
|
NewClosure( req.data(), SIGNAL( done() ),
|
||||||
|
this, SLOT( onCommandDone( QSharedPointer< ScriptCommand > ) ), req );
|
||||||
|
|
||||||
|
req->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req )
|
||||||
|
{
|
||||||
|
m_queue.removeAll( req );
|
||||||
|
req->deleteLater();
|
||||||
|
if ( m_queue.count() > 0 )
|
||||||
|
nextCommand();
|
||||||
|
}
|
48
src/libtomahawk/resolvers/ScriptCommandQueue.h
Normal file
48
src/libtomahawk/resolvers/ScriptCommandQueue.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/* === 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 SCRIPTCOMMANDQUEUE_H
|
||||||
|
#define SCRIPTCOMMANDQUEUE_H
|
||||||
|
|
||||||
|
#include "ScriptCommand.h"
|
||||||
|
|
||||||
|
#include <QQueue>
|
||||||
|
#include <QSharedPointer>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QMetaType>
|
||||||
|
|
||||||
|
class ScriptCommandQueue : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ScriptCommandQueue( QObject* parent = 0 );
|
||||||
|
|
||||||
|
void enqueue( const QSharedPointer< ScriptCommand >& req );
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void nextCommand();
|
||||||
|
void onCommandDone( const QSharedPointer< ScriptCommand >& req );
|
||||||
|
|
||||||
|
private:
|
||||||
|
QQueue< QSharedPointer< ScriptCommand > > m_queue;
|
||||||
|
QTimer* m_timer;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE( QSharedPointer< ScriptCommand > )
|
||||||
|
|
||||||
|
#endif // SCRIPTCOMMANDQUEUE_H
|
67
src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp
Normal file
67
src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
/* === 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_AllArtists.h"
|
||||||
|
|
||||||
|
#include "ExternalResolver.h"
|
||||||
|
#include "ScriptCollection.h"
|
||||||
|
|
||||||
|
ScriptCommand_AllArtists::ScriptCommand_AllArtists( const Tomahawk::collection_ptr& collection,
|
||||||
|
QObject* parent )
|
||||||
|
: ScriptCommand( parent )
|
||||||
|
, m_collection( collection )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCommand_AllArtists::enqueue()
|
||||||
|
{
|
||||||
|
Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
|
||||||
|
if ( collection == 0 )
|
||||||
|
{
|
||||||
|
emit artists( QList< Tomahawk::artist_ptr >() );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
collection->resolver()->enqueue( QSharedPointer< ScriptCommand >( this ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCommand_AllArtists::exec()
|
||||||
|
{
|
||||||
|
Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
|
||||||
|
if ( collection == 0 )
|
||||||
|
{
|
||||||
|
emit artists( QList< Tomahawk::artist_ptr >() );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
connect( collection->resolver(), SIGNAL( artistsFound( QList< Tomahawk::artist_ptr > ) ),
|
||||||
|
this, SLOT( onResolverDone( QList< Tomahawk::artist_ptr > ) ) );
|
||||||
|
|
||||||
|
collection->resolver()->artists( m_collection );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ScriptCommand_AllArtists::onResolverDone( const QList< Tomahawk::artist_ptr >& a )
|
||||||
|
{
|
||||||
|
emit artists( a );
|
||||||
|
emit done();
|
||||||
|
}
|
53
src/libtomahawk/resolvers/ScriptCommand_AllArtists.h
Normal file
53
src/libtomahawk/resolvers/ScriptCommand_AllArtists.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/* === 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_ALLARTISTS_H
|
||||||
|
#define SCRIPTCOMMAND_ALLARTISTS_H
|
||||||
|
|
||||||
|
#include "collection/ArtistsRequest.h"
|
||||||
|
#include "collection/Collection.h"
|
||||||
|
#include "resolvers/ScriptCommand.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
class ScriptCommand_AllArtists : public ScriptCommand
|
||||||
|
, public Tomahawk::ArtistsRequest
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ScriptCommand_AllArtists( const Tomahawk::collection_ptr& collection,
|
||||||
|
QObject* parent = 0 );
|
||||||
|
virtual ~ScriptCommand_AllArtists() {}
|
||||||
|
|
||||||
|
virtual void enqueue();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void artists( const QList< Tomahawk::artist_ptr >& );
|
||||||
|
void done();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void exec();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onResolverDone( const QList< Tomahawk::artist_ptr >& );
|
||||||
|
|
||||||
|
private:
|
||||||
|
Tomahawk::collection_ptr m_collection;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SCRIPTCOMMAND_ALLARTISTS_H
|
Reference in New Issue
Block a user