Skip to content

Commit

Permalink
Added ScriptCommand_AllAlbums.
Browse files Browse the repository at this point in the history
  • Loading branch information
teo committed Feb 4, 2013
1 parent 3da3969 commit 48c56e8
Show file tree
Hide file tree
Showing 18 changed files with 237 additions and 50 deletions.
14 changes: 10 additions & 4 deletions src/libtomahawk/Artist.cpp
Expand Up @@ -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();
}
}

Expand Down
1 change: 1 addition & 0 deletions src/libtomahawk/CMakeLists.txt
Expand Up @@ -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
Expand Down
43 changes: 43 additions & 0 deletions src/libtomahawk/collection/AlbumsRequest.h
@@ -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
3 changes: 2 additions & 1 deletion src/libtomahawk/collection/Collection.h
Expand Up @@ -35,6 +35,7 @@
#include "Playlist.h"
#include "playlist/dynamic/DynamicPlaylist.h"
#include "collection/ArtistsRequest.h"
#include "collection/AlbumsRequest.h"

#include "DllMacro.h"

Expand Down Expand Up @@ -82,7 +83,7 @@ Q_OBJECT

// 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;
Expand Down
23 changes: 5 additions & 18 deletions src/libtomahawk/database/DatabaseCollection.cpp
Expand Up @@ -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;

DatabaseCommand_AllAlbums* 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 ) );
}
return 0;

Tomahawk::AlbumsRequest* cmd = new DatabaseCommand_AllAlbums( thisCollection, artist );

void
DatabaseCollection::onAlbumsFetched( const QList< album_ptr >& albums, const QVariant& data )
{
Q_UNUSED( data );
emit albumsResult( albums );
return cmd;
}


Expand Down
3 changes: 1 addition & 2 deletions src/libtomahawk/database/DatabaseCollection.h
Expand Up @@ -51,15 +51,14 @@ Q_OBJECT
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:
virtual void addTracks( const QList<QVariant>& newitems );
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 );
Expand Down
5 changes: 4 additions & 1 deletion src/libtomahawk/database/DatabaseCommand_AllAlbums.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -114,6 +115,7 @@ DatabaseCommand_AllAlbums::execForArtist( DatabaseImpl* dbi )
}

emit albums( al, data() );
emit albums( al );
emit done();
}

Expand Down Expand Up @@ -162,6 +164,7 @@ DatabaseCommand_AllAlbums::execForCollection( DatabaseImpl* dbi )
}

emit albums( al, data() );
emit albums( al );
emit done();
}

Expand Down
11 changes: 10 additions & 1 deletion src/libtomahawk/database/DatabaseCommand_AllAlbums.h
@@ -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
Expand All @@ -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:
Expand All @@ -39,14 +43,18 @@ Q_OBJECT
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* );

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* );
Expand All @@ -60,6 +68,7 @@ Q_OBJECT

signals:
void albums( const QList<Tomahawk::album_ptr>&, const QVariant& data );
void albums( const QList<Tomahawk::album_ptr>& );
void done();

private:
Expand Down
1 change: 1 addition & 0 deletions src/libtomahawk/database/DatabaseCommand_AllArtists.h
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/libtomahawk/resolvers/ExternalResolver.h
Expand Up @@ -27,6 +27,7 @@
#include "Resolver.h"
#include "ScriptCommandQueue.h"
#include "ScriptCommand_AllArtists.h"
#include "ScriptCommand_AllAlbums.h"

#include <boost/function.hpp>

Expand All @@ -49,6 +50,7 @@ Q_OBJECT

friend class ::ScriptCommandQueue;
friend class ::ScriptCommand_AllArtists;
friend class ::ScriptCommand_AllAlbums;

public:
enum ErrorState {
Expand Down
7 changes: 3 additions & 4 deletions src/libtomahawk/resolvers/QtScriptResolver.cpp
Expand Up @@ -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 );
}


Expand Down Expand Up @@ -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;
}

Expand Down
20 changes: 10 additions & 10 deletions src/libtomahawk/resolvers/ScriptCollection.cpp
Expand Up @@ -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>
Expand Down Expand Up @@ -122,24 +123,23 @@ 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 );

void
ScriptCollection::tracks( const Tomahawk::album_ptr& album )
{
//m_resolver->tracks( m_resolver->collections().value( name() ), album );
return cmd;
}


void
ScriptCollection::onAlbumsFetched( const QList<album_ptr>& albums )
ScriptCollection::tracks( const Tomahawk::album_ptr& album )
{
emit albumsResult( albums );
//m_resolver->tracks( m_resolver->collections().value( name() ), album );
}


Expand Down
4 changes: 2 additions & 2 deletions src/libtomahawk/resolvers/ScriptCollection.h
Expand Up @@ -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"
Expand Down Expand Up @@ -50,11 +51,10 @@ class DLLEXPORT ScriptCollection : public Collection
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:
Expand Down
6 changes: 2 additions & 4 deletions src/libtomahawk/resolvers/ScriptCommandQueue.cpp
Expand Up @@ -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();
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 48c56e8

Please sign in to comment.