mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-24 09:49:42 +01:00
Route (almost) all artists/albums/tracks requests through Collections.
This commit is contained in:
parent
fb0de1d998
commit
65741c3658
@ -2,6 +2,7 @@
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2012, Jeff Mitchell <jeff@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
|
||||
@ -132,14 +133,23 @@ AlbumPlaylistInterface::tracks() const
|
||||
}
|
||||
else if ( m_mode == DatabaseMode && !m_databaseLoaded )
|
||||
{
|
||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection );
|
||||
cmd->setAlbum( m_album->weakRef() );
|
||||
cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition );
|
||||
if ( m_collection.isNull() ) //we do a dbcmd directly, for the SuperCollection I guess?
|
||||
{
|
||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection );
|
||||
cmd->setAlbum( m_album->weakRef() );
|
||||
cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition );
|
||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
|
||||
SLOT( onTracksLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
connect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ),
|
||||
SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ), Qt::UniqueConnection );
|
||||
|
||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
|
||||
SLOT( onTracksLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
Tomahawk::album_ptr ap = Album::get( m_album->id(), m_album->name(), m_album->artist() );
|
||||
m_collection->tracks( ap );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,15 +228,23 @@ AlbumPlaylistInterface::infoSystemFinished( const QString& infoId )
|
||||
|
||||
if ( m_queries.isEmpty() && m_mode == Mixed )
|
||||
{
|
||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection );
|
||||
cmd->setAlbum( m_album->weakRef() );
|
||||
//this takes discnumber into account as well
|
||||
cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition );
|
||||
if ( m_collection.isNull() ) //we do a dbcmd directly, for the SuperCollection I guess?
|
||||
{
|
||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_collection );
|
||||
cmd->setAlbum( m_album->weakRef() );
|
||||
cmd->setSortOrder( DatabaseCommand_AllTracks::AlbumPosition );
|
||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
|
||||
SLOT( onTracksLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
connect( m_collection.data(), SIGNAL( tracksResult( QList< Tomahawk::query_ptr > ) ),
|
||||
SLOT( onTracksLoaded( QList< Tomahawk::query_ptr > ) ), Qt::UniqueConnection );
|
||||
|
||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
|
||||
SLOT( onTracksLoaded( QList<Tomahawk::query_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
Tomahawk::album_ptr ap = Album::get( m_album->id(), m_album->name(), m_album->artist() );
|
||||
m_collection->tracks( ap );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2012, Jeff Mitchell <jeff@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
|
||||
@ -165,13 +166,23 @@ Artist::albums( ModelMode mode, const Tomahawk::collection_ptr& collection ) con
|
||||
|
||||
if ( ( mode == DatabaseMode || mode == Mixed ) && !dbLoaded )
|
||||
{
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection, artist );
|
||||
cmd->setData( QVariant( collection.isNull() ) );
|
||||
if ( collection.isNull() )
|
||||
{
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection, artist );
|
||||
cmd->setData( QVariant( collection.isNull() ) );
|
||||
|
||||
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
|
||||
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, QVariant ) ) );
|
||||
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
|
||||
SLOT( onAlbumsFound( QList<Tomahawk::album_ptr>, QVariant ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ( mode == InfoSystemMode || mode == Mixed ) && !infoLoaded )
|
||||
@ -376,9 +387,9 @@ Artist::playbackCount( const source_ptr& source )
|
||||
|
||||
|
||||
void
|
||||
Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& data )
|
||||
Artist::onAlbumsFound( const QList< album_ptr >& albums, const QVariant& collectionIsNull )
|
||||
{
|
||||
if ( data.toBool() )
|
||||
if ( collectionIsNull.toBool() )
|
||||
{
|
||||
m_databaseAlbums << albums;
|
||||
m_albumsLoaded.insert( DatabaseMode, true );
|
||||
|
@ -89,8 +89,7 @@ signals:
|
||||
void statsLoaded();
|
||||
|
||||
private slots:
|
||||
void onTracksLoaded( Tomahawk::ModelMode mode, const Tomahawk::collection_ptr& collection );
|
||||
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, const QVariant& data );
|
||||
void onAlbumsFound( const QList<Tomahawk::album_ptr>& albums, const QVariant& collectionIsNull = QVariant( false ) );
|
||||
|
||||
void infoSystemInfo( Tomahawk::InfoSystem::InfoRequestData requestData, QVariant output );
|
||||
void infoSystemFinished( QString target );
|
||||
|
@ -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
|
||||
@ -75,14 +76,19 @@ public:
|
||||
virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists() { return m_autoplaylists.values(); }
|
||||
virtual QList< Tomahawk::dynplaylist_ptr > stations() { return m_stations.values(); }
|
||||
|
||||
// Async requests. Emit artists/albums/tracksResult in subclasses when finished.
|
||||
virtual void artists() = 0;
|
||||
virtual void albums( const Tomahawk::artist_ptr& artist ) = 0;
|
||||
virtual void tracks( const Tomahawk::artist_ptr& artist, const Tomahawk::album_ptr& album ) = 0;
|
||||
virtual void tracks( const Tomahawk::album_ptr& album ) = 0;
|
||||
|
||||
const source_ptr& source() const;
|
||||
unsigned int lastmodified() const { return m_lastmodified; }
|
||||
|
||||
signals:
|
||||
void artistsResult( const QList< Tomahawk::artist_ptr >& artists );
|
||||
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 );
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.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
|
||||
@ -20,6 +21,8 @@
|
||||
#include "DatabaseCollection.h"
|
||||
|
||||
#include "database/Database.h"
|
||||
#include "DatabaseCommand_AllArtists.h"
|
||||
#include "DatabaseCommand_AllAlbums.h"
|
||||
#include "DatabaseCommand_AllTracks.h"
|
||||
#include "DatabaseCommand_AddFiles.h"
|
||||
#include "DatabaseCommand_DeleteFiles.h"
|
||||
@ -130,6 +133,83 @@ DatabaseCollection::stations()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCollection::artists()
|
||||
{
|
||||
//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_AllArtists* cmd = new DatabaseCommand_AllArtists( thisCollection );
|
||||
|
||||
connect( cmd, SIGNAL( artists( QList< Tomahawk::artist_ptr > ) ),
|
||||
SLOT( onArtistsFetched( QList< Tomahawk::artist_ptr > ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCollection::onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists )
|
||||
{
|
||||
emit artistsResult( artists );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCollection::albums( 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 ) );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCollection::onAlbumsFetched( const QList< album_ptr >& albums, const QVariant& data )
|
||||
{
|
||||
Q_UNUSED( data );
|
||||
emit albumsResult( albums );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCollection::tracks( 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;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DatabaseCollection::autoPlaylistCreated( const source_ptr& source, const QVariantList& data )
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
*
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.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
|
||||
@ -49,11 +50,19 @@ public:
|
||||
virtual QList< Tomahawk::dynplaylist_ptr > autoPlaylists();
|
||||
virtual QList< Tomahawk::dynplaylist_ptr > stations();
|
||||
|
||||
virtual void artists();
|
||||
virtual void albums( 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 onArtistsFetched( const QList< Tomahawk::artist_ptr >& artists );
|
||||
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 );
|
||||
void autoPlaylistCreated( const Tomahawk::source_ptr& source, const QVariantList& data );
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
||||
* Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org>
|
||||
* Copyright 2012, Leo Franchi <lfranchi@kde.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
|
||||
@ -251,12 +252,10 @@ TreeModel::addCollection( const collection_ptr& collection )
|
||||
startLoading();
|
||||
|
||||
m_collection = collection;
|
||||
DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( collection );
|
||||
|
||||
connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||
SLOT( onArtistsAdded( QList<Tomahawk::artist_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
connect( m_collection.data(), SIGNAL( artistsResult( QList<Tomahawk::artist_ptr> ) ),
|
||||
SLOT( onArtistsAdded( QList<Tomahawk::artist_ptr> ) ), Qt::UniqueConnection );
|
||||
m_collection->artists();
|
||||
|
||||
connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection );
|
||||
|
||||
@ -270,29 +269,28 @@ TreeModel::addCollection( const collection_ptr& collection )
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TreeModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << collection->name()
|
||||
<< collection->source()->id()
|
||||
<< collection->source()->nodeId()
|
||||
<< amount << order;
|
||||
//void
|
||||
//TreeModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order )
|
||||
//{
|
||||
// qDebug() << Q_FUNC_INFO << collection->name()
|
||||
// << collection->source()->id()
|
||||
// << collection->source()->nodeId()
|
||||
// << amount << order;
|
||||
// DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( collection );
|
||||
// cmd->setLimit( amount );
|
||||
// cmd->setSortOrder( order );
|
||||
// cmd->setSortDescending( true );
|
||||
|
||||
DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( collection );
|
||||
cmd->setLimit( amount );
|
||||
cmd->setSortOrder( order );
|
||||
cmd->setSortDescending( true );
|
||||
// connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr>, Tomahawk::collection_ptr ) ),
|
||||
// SLOT( onArtistsAdded( QList<Tomahawk::artist_ptr>, Tomahawk::collection_ptr ) ) );
|
||||
|
||||
connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr>, Tomahawk::collection_ptr ) ),
|
||||
SLOT( onArtistsAdded( QList<Tomahawk::artist_ptr>, Tomahawk::collection_ptr ) ) );
|
||||
// Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
|
||||
if ( collection->source()->isLocal() )
|
||||
setTitle( tr( "My Collection" ) );
|
||||
else
|
||||
setTitle( tr( "Collection of %1" ).arg( collection->source()->friendlyName() ) );
|
||||
}
|
||||
// if ( collection->source()->isLocal() )
|
||||
// setTitle( tr( "My Collection" ) );
|
||||
// else
|
||||
// setTitle( tr( "Collection of %1" ).arg( collection->source()->friendlyName() ) );
|
||||
//}
|
||||
|
||||
|
||||
void
|
||||
|
@ -53,7 +53,8 @@ public:
|
||||
|
||||
void addAllCollections();
|
||||
void addCollection( const Tomahawk::collection_ptr& collection );
|
||||
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order );
|
||||
//TODO: Unused, but will be useful for supporting filtered queries. - Teo 1/2013
|
||||
//void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllArtists::SortOrder order );
|
||||
|
||||
void addArtists( const Tomahawk::artist_ptr& artist );
|
||||
void addTracks( const Tomahawk::album_ptr& album, const QModelIndex& parent, bool autoRefetch = false );
|
||||
|
@ -64,3 +64,25 @@ ScriptCollection::icon() const
|
||||
}
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCollection::artists()
|
||||
{
|
||||
//TODO: implement!
|
||||
emit artistsResult( QList< Tomahawk::artist_ptr >() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCollection::albums( const Tomahawk::artist_ptr& artist )
|
||||
{
|
||||
emit albumsResult( QList< Tomahawk::album_ptr >() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCollection::tracks( const Tomahawk::album_ptr& album )
|
||||
{
|
||||
emit tracksResult( QList< Tomahawk::query_ptr >() );
|
||||
}
|
||||
|
@ -46,6 +46,10 @@ public:
|
||||
|
||||
virtual ExternalResolver* resolver() { return m_resolver; }
|
||||
|
||||
virtual void artists();
|
||||
virtual void albums( const Tomahawk::artist_ptr& artist );
|
||||
virtual void tracks( const Tomahawk::album_ptr& album );
|
||||
|
||||
private:
|
||||
ExternalResolver* m_resolver;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user