1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-21 00:09:47 +01:00

Added ScriptCommand_AllAlbums.

This commit is contained in:
Teo Mrnjavac 2013-02-03 20:01:25 +01:00
parent 3da3969ad2
commit 48c56e81f7
18 changed files with 237 additions and 50 deletions

View File

@ -178,10 +178,16 @@ Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) con
}
else
{
//collection is *surely* not null
connect( collection.data(), SIGNAL( albumsResult( QList< Tomahawk::album_ptr > ) ),
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr> ) ), Qt::UniqueConnection );
collection->albums( artist );
//collection is *surely* not null, and might be a ScriptCollection
Tomahawk::AlbumsRequest* cmd = collection->requestAlbums( artist );
// There is also a signal albums( QList, QVariant ).
// The QVariant might carry a bool that says whether the dbcmd was executed for a null collection
// but here we know for a fact that the collection is not null, so we'll happily ignore it
connect( dynamic_cast< QObject* >( cmd ), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ),
this, SLOT( onAlbumsFound( QList<Tomahawk::album_ptr> ) ) );
cmd->enqueue();
}
}

View File

@ -304,6 +304,7 @@ list(APPEND libSources
resolvers/Resolver.cpp
resolvers/ScriptCollection.cpp
resolvers/ScriptCommand_AllArtists.cpp
resolvers/ScriptCommand_AllAlbums.cpp
resolvers/ScriptCommandQueue.cpp
sip/SipPlugin.cpp

View 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 ALBUMSREQUEST_H
#define ALBUMSREQUEST_H
#include "Typedefs.h"
#include "DllMacro.h"
#include <QList>
namespace Tomahawk
{
class DLLEXPORT AlbumsRequest
{
public:
virtual ~AlbumsRequest() {}
virtual void enqueue() = 0;
protected: //signals
virtual void albums( const QList< Tomahawk::album_ptr >& ) = 0;
};
} //ns
#endif // ALBUMSREQUEST_H

View File

@ -35,6 +35,7 @@
#include "Playlist.h"
#include "playlist/dynamic/DynamicPlaylist.h"
#include "collection/ArtistsRequest.h"
#include "collection/AlbumsRequest.h"
#include "DllMacro.h"
@ -82,7 +83,7 @@ public:
// Async requests. Emit artists/albums/tracksResult in subclasses when finished.
virtual Tomahawk::ArtistsRequest* requestArtists() = 0;
virtual void albums( const Tomahawk::artist_ptr& artist ) = 0;
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist ) = 0;
virtual void tracks( const Tomahawk::album_ptr& album ) = 0;
const source_ptr& source() const;

View File

@ -147,30 +147,17 @@ DatabaseCollection::requestArtists()
}
void
DatabaseCollection::albums( const Tomahawk::artist_ptr& artist )
Tomahawk::AlbumsRequest*
DatabaseCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
{
//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_AllAlbums* cmd = new DatabaseCommand_AllAlbums( thisCollection, artist );
Tomahawk::AlbumsRequest* cmd = new DatabaseCommand_AllAlbums( thisCollection, artist );
// The QVariant might carry a bool that says whether the dbcmd was executed for a null collection
// but here we know for a fact that the collection is not null, so we'll happily ignore it
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
SLOT( onAlbumsFetched( QList<Tomahawk::album_ptr>, QVariant ) ) );
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
void
DatabaseCollection::onAlbumsFetched( const QList< album_ptr >& albums, const QVariant& data )
{
Q_UNUSED( data );
emit albumsResult( albums );
return cmd;
}

View File

@ -51,7 +51,7 @@ public:
virtual QList< Tomahawk::dynplaylist_ptr > stations();
virtual Tomahawk::ArtistsRequest* requestArtists();
virtual void albums( const Tomahawk::artist_ptr& artist );
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
virtual void tracks( const Tomahawk::album_ptr& album );
public slots:
@ -59,7 +59,6 @@ public slots:
virtual void removeTracks( const QDir& dir );
private slots:
void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums, const QVariant& data );
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
void stationCreated( const Tomahawk::source_ptr& source, const QVariantList& data );

View File

@ -34,7 +34,8 @@ DatabaseCommand_AllAlbums::DatabaseCommand_AllAlbums( const Tomahawk::collection
, m_amount( 0 )
, m_sortOrder( DatabaseCommand_AllAlbums::None )
, m_sortDescending( false )
{}
{
}
DatabaseCommand_AllAlbums::~DatabaseCommand_AllAlbums()
@ -114,6 +115,7 @@ DatabaseCommand_AllAlbums::execForArtist( DatabaseImpl* dbi )
}
emit albums( al, data() );
emit albums( al );
emit done();
}
@ -162,6 +164,7 @@ DatabaseCommand_AllAlbums::execForCollection( DatabaseImpl* dbi )
}
emit albums( al, data() );
emit albums( al );
emit done();
}

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@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
@ -25,12 +26,15 @@
#include "Album.h"
#include "Artist.h"
#include "collection/Collection.h"
#include "collection/AlbumsRequest.h"
#include "Typedefs.h"
#include "DatabaseCommand.h"
#include "Database.h"
#include "DllMacro.h"
class DLLEXPORT DatabaseCommand_AllAlbums : public DatabaseCommand
, public Tomahawk::AlbumsRequest
{
Q_OBJECT
public:
@ -39,7 +43,9 @@ public:
ModificationTime = 1
};
explicit DatabaseCommand_AllAlbums( const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr(), const Tomahawk::artist_ptr& artist = Tomahawk::artist_ptr(), QObject* parent = 0 );
explicit DatabaseCommand_AllAlbums( const Tomahawk::collection_ptr& collection = Tomahawk::collection_ptr(),
const Tomahawk::artist_ptr& artist = Tomahawk::artist_ptr(),
QObject* parent = 0 );
virtual ~DatabaseCommand_AllAlbums();
virtual void exec( DatabaseImpl* );
@ -47,6 +53,8 @@ public:
virtual bool doesMutates() const { return false; }
virtual QString commandname() const { return "allalbums"; }
virtual void enqueue() { Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( this ) ); }
Tomahawk::collection_ptr collection() const { return m_collection; }
void execForCollection( DatabaseImpl* );
@ -60,6 +68,7 @@ public:
signals:
void albums( const QList<Tomahawk::album_ptr>&, const QVariant& data );
void albums( const QList<Tomahawk::album_ptr>& );
void done();
private:

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@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

View File

@ -27,6 +27,7 @@
#include "Resolver.h"
#include "ScriptCommandQueue.h"
#include "ScriptCommand_AllArtists.h"
#include "ScriptCommand_AllAlbums.h"
#include <boost/function.hpp>
@ -49,6 +50,7 @@ Q_OBJECT
friend class ::ScriptCommandQueue;
friend class ::ScriptCommand_AllArtists;
friend class ::ScriptCommand_AllAlbums;
public:
enum ErrorState {

View File

@ -187,8 +187,8 @@ QtScriptResolverHelper::addAlbumResults( const QVariantMap& results )
tDebug() << Q_FUNC_INFO << "about to push" << albums.count() << "albums";
foreach( const Tomahawk::album_ptr& album, albums)
tDebug() << album->name();
QMetaObject::invokeMethod( collection.data(), "onAlbumsFetched", Qt::QueuedConnection,
Q_ARG( QList< Tomahawk::album_ptr >, albums ) );
emit m_resolver->albumsFound( albums );
}
@ -535,8 +535,7 @@ QtScriptResolver::albums( 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(), "onAlbumsFetched", Qt::QueuedConnection,
Q_ARG( QList< Tomahawk::album_ptr >, QList< Tomahawk::album_ptr >() ) );
emit albumsFound( QList< Tomahawk::album_ptr >() );
return;
}

View File

@ -24,6 +24,7 @@
#include "utils/TomahawkUtilsGui.h"
#include "utils/Logger.h"
#include "resolvers/ScriptCommand_AllArtists.h"
#include "resolvers/ScriptCommand_AllAlbums.h"
#include <QIcon>
#include <QPainter>
@ -122,10 +123,16 @@ ScriptCollection::requestArtists()
}
void
ScriptCollection::albums( const Tomahawk::artist_ptr& artist )
Tomahawk::AlbumsRequest*
ScriptCollection::requestAlbums( const Tomahawk::artist_ptr& artist )
{
//m_resolver->albums( m_resolver->collections().value( name() ), artist );
Tomahawk::collection_ptr thisCollection = m_resolver->collections().value( name() );
if ( thisCollection->name() != this->name() )
return 0;
Tomahawk::AlbumsRequest* cmd = new ScriptCommand_AllAlbums( thisCollection, artist );
return cmd;
}
@ -136,13 +143,6 @@ ScriptCollection::tracks( const Tomahawk::album_ptr& album )
}
void
ScriptCollection::onAlbumsFetched( const QList<album_ptr>& albums )
{
emit albumsResult( albums );
}
void
ScriptCollection::onTracksFetched( const QList<query_ptr>& tracks )
{

View File

@ -23,6 +23,7 @@
#include "ExternalResolver.h"
#include "collection/Collection.h"
#include "collection/ArtistsRequest.h"
#include "collection/AlbumsRequest.h"
#include "Typedefs.h"
#include "DllMacro.h"
@ -50,11 +51,10 @@ public:
virtual ExternalResolver* resolver() { return m_resolver; }
virtual Tomahawk::ArtistsRequest* requestArtists();
virtual void albums( const Tomahawk::artist_ptr& artist );
virtual Tomahawk::AlbumsRequest* requestAlbums( const Tomahawk::artist_ptr& artist );
virtual void tracks( const Tomahawk::album_ptr& album );
private slots:
void onAlbumsFetched( const QList< Tomahawk::album_ptr >& albums );
void onTracksFetched( const QList< Tomahawk::query_ptr >& tracks );
private:

View File

@ -53,7 +53,7 @@ ScriptCommandQueue::nextCommand()
NewClosure( m_timer, SIGNAL( timeout() ),
this, SLOT( onTimeout( QSharedPointer< ScriptCommand > ) ), req );
m_timer->start( 2000 );
m_timer->start( 5000 );
req->exec();
}
@ -66,7 +66,6 @@ ScriptCommandQueue::onCommandDone( const QSharedPointer< ScriptCommand >& req )
m_timer->stop();
m_queue.removeAll( req );
req->deleteLater();
if ( m_queue.count() > 0 )
nextCommand();
@ -80,9 +79,8 @@ ScriptCommandQueue::onTimeout( const QSharedPointer< ScriptCommand >& req )
m_timer->stop();
m_queue.removeAll( req );
req->reportFailure();
req->deleteLater();
m_queue.removeAll( req );
if ( m_queue.count() > 0 )
nextCommand();

View File

@ -0,0 +1,86 @@
/* === 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_AllAlbums.h"
#include "ExternalResolver.h"
#include "ScriptCollection.h"
#include "utils/Logger.h"
ScriptCommand_AllAlbums::ScriptCommand_AllAlbums( const Tomahawk::collection_ptr& collection,
const Tomahawk::artist_ptr& artist,
QObject* parent )
: ScriptCommand( parent )
, m_collection( collection )
, m_artist( artist )
{
}
void
ScriptCommand_AllAlbums::enqueue()
{
Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
if ( collection == 0 )
{
emit albums( QList< Tomahawk::album_ptr >() );
return;
}
collection->resolver()->enqueue( QSharedPointer< ScriptCommand >( this ) );
}
void
ScriptCommand_AllAlbums::exec()
{
Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
if ( collection == 0 )
{
reportFailure();
return;
}
if ( m_artist.isNull() )
{
reportFailure();
return;
}
connect( collection->resolver(), SIGNAL( albumsFound( QList< Tomahawk::album_ptr > ) ),
this, SLOT( onResolverDone( QList< Tomahawk::album_ptr > ) ) );
collection->resolver()->albums( m_collection, m_artist );
}
void
ScriptCommand_AllAlbums::reportFailure()
{
emit albums( QList< Tomahawk::album_ptr >() );
emit done();
}
void
ScriptCommand_AllAlbums::onResolverDone( const QList< Tomahawk::album_ptr >& a )
{
emit albums( a );
emit done();
}

View 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_ALLALBUMS_H
#define SCRIPTCOMMAND_ALLALBUMS_H
#include "collection/AlbumsRequest.h"
#include "collection/Collection.h"
#include "resolvers/ScriptCommand.h"
class ScriptCommand_AllAlbums : public ScriptCommand
, public Tomahawk::AlbumsRequest
{
Q_OBJECT
public:
explicit ScriptCommand_AllAlbums( const Tomahawk::collection_ptr& collection,
const Tomahawk::artist_ptr& artist,
QObject* parent = 0 );
virtual ~ScriptCommand_AllAlbums() {}
virtual void enqueue();
signals:
void albums( const QList< Tomahawk::album_ptr >& );
void done();
protected:
virtual void exec();
virtual void reportFailure();
private slots:
void onResolverDone( const QList< Tomahawk::album_ptr >& );
private:
Tomahawk::collection_ptr m_collection;
Tomahawk::artist_ptr m_artist;
};
#endif // SCRIPTCOMMAND_ALLALBUMS_H

View File

@ -35,7 +35,7 @@ ScriptCommand_AllArtists::enqueue()
Tomahawk::ScriptCollection* collection = qobject_cast< Tomahawk::ScriptCollection* >( m_collection.data() );
if ( collection == 0 )
{
emit artists( QList< Tomahawk::artist_ptr >() );
reportFailure();
return;
}

View File

@ -23,8 +23,6 @@
#include "collection/Collection.h"
#include "resolvers/ScriptCommand.h"
#include <QObject>
class ScriptCommand_AllArtists : public ScriptCommand
, public Tomahawk::ArtistsRequest
{