diff --git a/src/libtomahawk/Artist.cpp b/src/libtomahawk/Artist.cpp index 9a0f9dd25..9e34a7512 100644 --- a/src/libtomahawk/Artist.cpp +++ b/src/libtomahawk/Artist.cpp @@ -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 ) ), 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 ) ), + this, SLOT( onAlbumsFound( QList ) ) ); + + cmd->enqueue(); } } diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index d61dfe23b..c309b87ed 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -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 diff --git a/src/libtomahawk/collection/AlbumsRequest.h b/src/libtomahawk/collection/AlbumsRequest.h new file mode 100644 index 000000000..af3771135 --- /dev/null +++ b/src/libtomahawk/collection/AlbumsRequest.h @@ -0,0 +1,43 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#ifndef ALBUMSREQUEST_H +#define ALBUMSREQUEST_H + +#include "Typedefs.h" +#include "DllMacro.h" + +#include + +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 diff --git a/src/libtomahawk/collection/Collection.h b/src/libtomahawk/collection/Collection.h index 079bf1acd..d90e6c639 100644 --- a/src/libtomahawk/collection/Collection.h +++ b/src/libtomahawk/collection/Collection.h @@ -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; diff --git a/src/libtomahawk/database/DatabaseCollection.cpp b/src/libtomahawk/database/DatabaseCollection.cpp index ce443e928..fb787d033 100644 --- a/src/libtomahawk/database/DatabaseCollection.cpp +++ b/src/libtomahawk/database/DatabaseCollection.cpp @@ -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, QVariant ) ), - SLOT( onAlbumsFetched( QList, QVariant ) ) ); - - Database::instance()->enqueue( QSharedPointer( cmd ) ); -} - - -void -DatabaseCollection::onAlbumsFetched( const QList< album_ptr >& albums, const QVariant& data ) -{ - Q_UNUSED( data ); - emit albumsResult( albums ); + return cmd; } diff --git a/src/libtomahawk/database/DatabaseCollection.h b/src/libtomahawk/database/DatabaseCollection.h index 2fa3a6b49..efa60c6a7 100644 --- a/src/libtomahawk/database/DatabaseCollection.h +++ b/src/libtomahawk/database/DatabaseCollection.h @@ -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 ); diff --git a/src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp b/src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp index cfc7c9165..7077383ff 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp +++ b/src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp @@ -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(); } diff --git a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h index e0bb03b92..b015b207b 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllAlbums.h +++ b/src/libtomahawk/database/DatabaseCommand_AllAlbums.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * 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( this ) ); } + Tomahawk::collection_ptr collection() const { return m_collection; } void execForCollection( DatabaseImpl* ); @@ -60,6 +68,7 @@ public: signals: void albums( const QList&, const QVariant& data ); + void albums( const QList& ); void done(); private: diff --git a/src/libtomahawk/database/DatabaseCommand_AllArtists.h b/src/libtomahawk/database/DatabaseCommand_AllArtists.h index ac778ac4c..d9d45f4a5 100644 --- a/src/libtomahawk/database/DatabaseCommand_AllArtists.h +++ b/src/libtomahawk/database/DatabaseCommand_AllArtists.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/libtomahawk/resolvers/ExternalResolver.h b/src/libtomahawk/resolvers/ExternalResolver.h index 93468ab67..73ca4c84f 100644 --- a/src/libtomahawk/resolvers/ExternalResolver.h +++ b/src/libtomahawk/resolvers/ExternalResolver.h @@ -27,6 +27,7 @@ #include "Resolver.h" #include "ScriptCommandQueue.h" #include "ScriptCommand_AllArtists.h" +#include "ScriptCommand_AllAlbums.h" #include @@ -49,6 +50,7 @@ Q_OBJECT friend class ::ScriptCommandQueue; friend class ::ScriptCommand_AllArtists; + friend class ::ScriptCommand_AllAlbums; public: enum ErrorState { diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 6454594c8..f62e440f5 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -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; } diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index 635f5e58a..b200bac48 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -24,6 +24,7 @@ #include "utils/TomahawkUtilsGui.h" #include "utils/Logger.h" #include "resolvers/ScriptCommand_AllArtists.h" +#include "resolvers/ScriptCommand_AllAlbums.h" #include #include @@ -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& albums ) -{ - emit albumsResult( albums ); -} - - void ScriptCollection::onTracksFetched( const QList& tracks ) { diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index 5a9272b16..66ab60f6b 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -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: diff --git a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp index 6fb42ccbd..ce4662145 100644 --- a/src/libtomahawk/resolvers/ScriptCommandQueue.cpp +++ b/src/libtomahawk/resolvers/ScriptCommandQueue.cpp @@ -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(); diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.cpp new file mode 100644 index 000000000..94fa3c0f8 --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.cpp @@ -0,0 +1,86 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#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(); +} diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h new file mode 100644 index 000000000..5742a2c1e --- /dev/null +++ b/src/libtomahawk/resolvers/ScriptCommand_AllAlbums.h @@ -0,0 +1,54 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2013, Teo Mrnjavac + * + * 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 . + */ + +#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 diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp index ec90c0a09..6c9553040 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.cpp @@ -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; } diff --git a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h index d5adcb755..3193a72a2 100644 --- a/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h +++ b/src/libtomahawk/resolvers/ScriptCommand_AllArtists.h @@ -23,8 +23,6 @@ #include "collection/Collection.h" #include "resolvers/ScriptCommand.h" -#include - class ScriptCommand_AllArtists : public ScriptCommand , public Tomahawk::ArtistsRequest {