mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 11:50:37 +02:00
Basic ScriptCollection filtering support.
This commit is contained in:
@@ -19,5 +19,6 @@
|
||||
|
||||
#include "AlbumsRequest.h"
|
||||
|
||||
|
||||
Tomahawk::AlbumsRequest::~AlbumsRequest()
|
||||
{}
|
||||
|
@@ -34,6 +34,8 @@ public:
|
||||
|
||||
virtual void enqueue() = 0;
|
||||
|
||||
virtual void setFilter( const QString& filter ) = 0;
|
||||
|
||||
protected: //signals
|
||||
virtual void albums( const QList< Tomahawk::album_ptr >& ) = 0;
|
||||
};
|
||||
|
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "ArtistsRequest.h"
|
||||
|
||||
|
||||
Tomahawk::ArtistsRequest::~ArtistsRequest()
|
||||
{}
|
||||
|
||||
|
@@ -34,6 +34,8 @@ public:
|
||||
|
||||
virtual void enqueue() = 0;
|
||||
|
||||
virtual void setFilter( const QString& filter ) = 0;
|
||||
|
||||
protected: //signals
|
||||
virtual void artists( const QList< Tomahawk::artist_ptr >& ) = 0;
|
||||
};
|
||||
|
@@ -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
|
||||
@@ -24,7 +25,8 @@
|
||||
#include "Query.h"
|
||||
#include "database/Database.h"
|
||||
#include "database/DatabaseImpl.h"
|
||||
#include "database/DatabaseCommand_AllAlbums.h"
|
||||
#include "collection/AlbumsRequest.h"
|
||||
#include "collection/ArtistsRequest.h"
|
||||
#include "PlayableItem.h"
|
||||
#include "utils/Logger.h"
|
||||
|
||||
@@ -71,14 +73,14 @@ TreeProxyModel::onRowsInserted( const QModelIndex& parent, int /* start */, int
|
||||
if ( pi->artist().isNull() )
|
||||
return;
|
||||
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( m_model->collection() );
|
||||
cmd->setArtist( pi->artist() );
|
||||
Tomahawk::AlbumsRequest* cmd = m_model->collection()->requestAlbums( pi->artist() );
|
||||
|
||||
cmd->setFilter( m_filter );
|
||||
|
||||
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
|
||||
SLOT( onFilterAlbums( QList<Tomahawk::album_ptr> ) ) );
|
||||
connect( dynamic_cast< QObject* >( cmd ), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ),
|
||||
SLOT( onFilterAlbums( QList<Tomahawk::album_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
cmd->enqueue();
|
||||
}
|
||||
|
||||
|
||||
@@ -101,8 +103,8 @@ TreeProxyModel::setFilter( const QString& pattern )
|
||||
|
||||
if ( m_artistsFilterCmd )
|
||||
{
|
||||
disconnect( m_artistsFilterCmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||
this, SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );
|
||||
disconnect( dynamic_cast< QObject* >( m_artistsFilterCmd ), SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||
this, SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );
|
||||
|
||||
m_artistsFilterCmd = 0;
|
||||
}
|
||||
@@ -113,14 +115,15 @@ TreeProxyModel::setFilter( const QString& pattern )
|
||||
}
|
||||
else
|
||||
{
|
||||
DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( m_model->collection() );
|
||||
Tomahawk::ArtistsRequest* cmd = m_model->collection()->requestArtists();
|
||||
|
||||
cmd->setFilter( pattern );
|
||||
m_artistsFilterCmd = cmd;
|
||||
|
||||
connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||
SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );
|
||||
connect( dynamic_cast< QObject* >( cmd ), SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
|
||||
SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
cmd->enqueue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,14 +149,14 @@ TreeProxyModel::onFilterArtists( const QList<Tomahawk::artist_ptr>& artists )
|
||||
{
|
||||
finished = false;
|
||||
|
||||
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( m_model->collection() );
|
||||
cmd->setArtist( artist );
|
||||
Tomahawk::AlbumsRequest* cmd = m_model->collection()->requestAlbums( artist );
|
||||
|
||||
cmd->setFilter( m_filter );
|
||||
|
||||
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, QVariant ) ),
|
||||
SLOT( onFilterAlbums( QList<Tomahawk::album_ptr> ) ) );
|
||||
connect( dynamic_cast< QObject* >( cmd ), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ),
|
||||
SLOT( onFilterAlbums( QList<Tomahawk::album_ptr> ) ) );
|
||||
|
||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||
cmd->enqueue();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -26,10 +26,9 @@
|
||||
|
||||
#include "DllMacro.h"
|
||||
|
||||
class DatabaseCommand_AllArtists;
|
||||
|
||||
namespace Tomahawk
|
||||
{
|
||||
class ArtistsRequest;
|
||||
class TreeProxyModelPlaylistInterface;
|
||||
}
|
||||
|
||||
@@ -76,7 +75,7 @@ private:
|
||||
|
||||
QList<Tomahawk::artist_ptr> m_artistsFilter;
|
||||
QList<int> m_albumsFilter;
|
||||
DatabaseCommand_AllArtists* m_artistsFilterCmd;
|
||||
Tomahawk::ArtistsRequest* m_artistsFilterCmd;
|
||||
|
||||
QString m_filter;
|
||||
TreeModel* m_model;
|
||||
|
@@ -20,6 +20,8 @@
|
||||
|
||||
#include "ExternalResolver.h"
|
||||
#include "ScriptCollection.h"
|
||||
#include "Album.h"
|
||||
#include "Artist.h"
|
||||
|
||||
#include "utils/Logger.h"
|
||||
|
||||
@@ -47,6 +49,13 @@ ScriptCommand_AllAlbums::enqueue()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCommand_AllAlbums::setFilter( const QString& filter )
|
||||
{
|
||||
m_filter = filter;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCommand_AllAlbums::exec()
|
||||
{
|
||||
@@ -81,6 +90,18 @@ ScriptCommand_AllAlbums::reportFailure()
|
||||
void
|
||||
ScriptCommand_AllAlbums::onResolverDone( const QList< Tomahawk::album_ptr >& a )
|
||||
{
|
||||
emit albums( a );
|
||||
if ( m_filter.isEmpty() )
|
||||
emit albums( a );
|
||||
else
|
||||
{
|
||||
QList< Tomahawk::album_ptr > filtered;
|
||||
foreach( const Tomahawk::album_ptr& album, a )
|
||||
{
|
||||
if( album->name().toLower().contains( m_filter.toLower() ) ||
|
||||
album->artist()->name().toLower().contains( m_filter.toLower() ) )
|
||||
filtered.append( album );
|
||||
}
|
||||
emit albums( filtered );
|
||||
}
|
||||
emit done();
|
||||
}
|
||||
|
@@ -33,6 +33,8 @@ public:
|
||||
virtual ~ScriptCommand_AllAlbums() {}
|
||||
|
||||
virtual void enqueue();
|
||||
|
||||
virtual void setFilter( const QString& filter );
|
||||
|
||||
signals:
|
||||
void albums( const QList< Tomahawk::album_ptr >& );
|
||||
@@ -48,6 +50,7 @@ private slots:
|
||||
private:
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
Tomahawk::artist_ptr m_artist;
|
||||
QString m_filter;
|
||||
};
|
||||
|
||||
#endif // SCRIPTCOMMAND_ALLALBUMS_H
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "ScriptCommand_AllArtists.h"
|
||||
|
||||
#include "Artist.h"
|
||||
#include "ExternalResolver.h"
|
||||
#include "ScriptCollection.h"
|
||||
|
||||
@@ -43,6 +44,13 @@ ScriptCommand_AllArtists::enqueue()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCommand_AllArtists::setFilter( const QString& filter )
|
||||
{
|
||||
m_filter = filter;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCommand_AllArtists::exec()
|
||||
{
|
||||
@@ -70,6 +78,17 @@ ScriptCommand_AllArtists::reportFailure()
|
||||
|
||||
void ScriptCommand_AllArtists::onResolverDone( const QList< Tomahawk::artist_ptr >& a )
|
||||
{
|
||||
emit artists( a );
|
||||
if ( m_filter.isEmpty() )
|
||||
emit artists( a );
|
||||
else
|
||||
{
|
||||
QList< Tomahawk::artist_ptr > filtered;
|
||||
foreach( const Tomahawk::artist_ptr& artist, a )
|
||||
{
|
||||
if ( artist->name().contains( m_filter ) )
|
||||
filtered.append( artist );
|
||||
}
|
||||
emit artists( filtered );
|
||||
}
|
||||
emit done();
|
||||
}
|
||||
|
@@ -32,6 +32,8 @@ public:
|
||||
virtual ~ScriptCommand_AllArtists() {}
|
||||
|
||||
virtual void enqueue();
|
||||
|
||||
void setFilter( const QString& filter );
|
||||
|
||||
signals:
|
||||
void artists( const QList< Tomahawk::artist_ptr >& );
|
||||
@@ -46,6 +48,7 @@ private slots:
|
||||
|
||||
private:
|
||||
Tomahawk::collection_ptr m_collection;
|
||||
QString m_filter;
|
||||
};
|
||||
|
||||
#endif // SCRIPTCOMMAND_ALLARTISTS_H
|
||||
|
Reference in New Issue
Block a user