Ejemplo n.º 1
0
void
TreeProxyModel::onFilterArtists( const QList<Tomahawk::artist_ptr>& artists )
{
    bool finished = true;
    m_artistsFilter = artists;
    m_artistsFilterCmd = 0;

    foreach ( const Tomahawk::artist_ptr& artist, artists )
    {
        const QModelIndex idx = m_model->indexFromArtist( artist );
        if ( m_model->rowCount( idx ) )
        {
            finished = false;

            Tomahawk::AlbumsRequest* cmd = m_model->collection()->requestAlbums( artist );
            cmd->setFilter( m_filter );

            connect( dynamic_cast< QObject* >( cmd ), SIGNAL( albums( QList<Tomahawk::album_ptr> ) ),
                     SLOT( onFilterAlbums( QList<Tomahawk::album_ptr> ) ) );

            cmd->enqueue();
        }
    }

    if ( finished )
        filterFinished();
}
Ejemplo n.º 2
0
void
TreeProxyModel::setFilter( const QString& pattern )
{
    emit filteringStarted();

    m_filter = pattern;
    m_albumsFilter.clear();

    if ( m_artistsFilterCmd )
    {
        disconnect( dynamic_cast< QObject* >( m_artistsFilterCmd ), SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
                    this, SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );

        m_artistsFilterCmd = 0;
    }

    if ( m_filter.isEmpty() )
    {
        filterFinished();
    }
    else
    {
        Tomahawk::ArtistsRequest* cmd = m_model->collection()->requestArtists();

        cmd->setFilter( pattern );
        m_artistsFilterCmd = cmd;

        connect( dynamic_cast< QObject* >( cmd ), SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
                 SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );

        cmd->enqueue();
    }
}
Ejemplo n.º 3
0
void
TreeProxyModel::newFilterFromPlaylistInterface( const QString &pattern )
{
    emit filteringStarted();

    m_filter = pattern;
    m_albumsFilter.clear();

    if ( m_artistsFilterCmd )
    {
        disconnect( m_artistsFilterCmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
                    this,                 SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );

        m_artistsFilterCmd = 0;
    }

    if ( m_filter.isEmpty() )
    {
        filterFinished();
    }
    else
    {
        DatabaseCommand_AllArtists* cmd = new DatabaseCommand_AllArtists( m_model->collection() );
        cmd->setFilter( pattern );
        m_artistsFilterCmd = cmd;

        connect( cmd, SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
                        SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );

        Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
    }
}
Ejemplo n.º 4
0
void
TreeProxyModel::onFilterAlbums( const QList<Tomahawk::album_ptr>& albums )
{
    foreach ( const Tomahawk::album_ptr& album, albums )
    {
        m_albumsFilter << album;
    }

    filterFinished();
}
Ejemplo n.º 5
0
void
TreeProxyModel::setFilter( const QString& pattern )
{
    emit filteringStarted();

    m_filter = pattern;

    beginResetModel();
    m_albumsFilter.clear();
    endResetModel();

    if ( m_artistsFilterCmd )
    {
        disconnect( dynamic_cast< QObject* >( m_artistsFilterCmd ), SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
                    this, SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );

        delete m_artistsFilterCmd;
        m_artistsFilterCmd = 0;
    }

    if ( m_filter.isEmpty() )
    {
        filterFinished();
    }
    else
    {
        Tomahawk::ArtistsRequest* cmd = 0;
        if ( !m_model->collection().isNull() )
            cmd = m_model->collection()->requestArtists();
        else
            cmd = new Tomahawk::DatabaseCommand_AllArtists(); //for SuperCollection, TODO: replace with a proper proxy-ArtistsRequest

        cmd->setFilter( pattern );
        m_artistsFilterCmd = cmd;

        connect( dynamic_cast< QObject* >( cmd ), SIGNAL( artists( QList<Tomahawk::artist_ptr> ) ),
                 SLOT( onFilterArtists( QList<Tomahawk::artist_ptr> ) ) );

        cmd->enqueue();
    }
}