mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-01-19 15:37:01 +01:00
* DRY: Added RecentlyAddedModel.
This commit is contained in:
parent
8495c6397a
commit
d2b719b61c
@ -77,6 +77,7 @@ set( libGuiSources
|
|||||||
playlist/artistview.cpp
|
playlist/artistview.cpp
|
||||||
playlist/customplaylistview.cpp
|
playlist/customplaylistview.cpp
|
||||||
playlist/ViewHeader.cpp
|
playlist/ViewHeader.cpp
|
||||||
|
playlist/RecentlyAddedModel.cpp
|
||||||
playlist/RecentlyPlayedModel.cpp
|
playlist/RecentlyPlayedModel.cpp
|
||||||
|
|
||||||
playlist/dynamic/DynamicPlaylist.cpp
|
playlist/dynamic/DynamicPlaylist.cpp
|
||||||
|
102
src/libtomahawk/playlist/RecentlyAddedModel.cpp
Normal file
102
src/libtomahawk/playlist/RecentlyAddedModel.cpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2012, Christian Muehlhaeuser <muesli@tomahawk-player.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "RecentlyAddedModel.h"
|
||||||
|
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QTreeView>
|
||||||
|
|
||||||
|
#include "source.h"
|
||||||
|
#include "sourcelist.h"
|
||||||
|
#include "database/database.h"
|
||||||
|
#include "database/databasecommand_alltracks.h"
|
||||||
|
#include "utils/tomahawkutils.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
|
||||||
|
#define LATEST_TRACK_ITEMS 250
|
||||||
|
|
||||||
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
|
RecentlyAddedModel::RecentlyAddedModel( const source_ptr& source, QObject* parent )
|
||||||
|
: TrackModel( parent )
|
||||||
|
, m_source( source )
|
||||||
|
, m_limit( LATEST_TRACK_ITEMS )
|
||||||
|
{
|
||||||
|
if ( source.isNull() )
|
||||||
|
{
|
||||||
|
connect( SourceList::instance(), SIGNAL( ready() ), SLOT( onSourcesReady() ) );
|
||||||
|
connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
onSourceAdded( source );
|
||||||
|
loadHistory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
RecentlyAddedModel::~RecentlyAddedModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
RecentlyAddedModel::loadHistory()
|
||||||
|
{
|
||||||
|
if ( rowCount( QModelIndex() ) )
|
||||||
|
{
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_source->collection() );
|
||||||
|
cmd->setLimit( m_limit );
|
||||||
|
cmd->setSortOrder( DatabaseCommand_AllTracks::ModificationTime );
|
||||||
|
cmd->setSortDescending( true );
|
||||||
|
|
||||||
|
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
|
||||||
|
SLOT( append( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
||||||
|
|
||||||
|
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
RecentlyAddedModel::onSourcesReady()
|
||||||
|
{
|
||||||
|
Q_ASSERT( m_source.isNull() );
|
||||||
|
|
||||||
|
loadHistory();
|
||||||
|
|
||||||
|
foreach ( const source_ptr& source, SourceList::instance()->sources() )
|
||||||
|
onSourceAdded( source );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
RecentlyAddedModel::onSourceAdded( const Tomahawk::source_ptr& source )
|
||||||
|
{
|
||||||
|
connect( source->collection().data(), SIGNAL( changed() ), SLOT( loadHistory() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
RecentlyAddedModel::isTemporary() const
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
54
src/libtomahawk/playlist/RecentlyAddedModel.h
Normal file
54
src/libtomahawk/playlist/RecentlyAddedModel.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.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 RECENTLYADDEDMODEL_H
|
||||||
|
#define RECENTLYADDEDMODEL_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
|
#include "typedefs.h"
|
||||||
|
#include "trackmodel.h"
|
||||||
|
|
||||||
|
#include "dllmacro.h"
|
||||||
|
|
||||||
|
class DLLEXPORT RecentlyAddedModel : public TrackModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit RecentlyAddedModel( const Tomahawk::source_ptr& source, QObject* parent = 0 );
|
||||||
|
~RecentlyAddedModel();
|
||||||
|
|
||||||
|
unsigned int limit() const { return m_limit; }
|
||||||
|
void setLimit( unsigned int limit ) { m_limit = limit; }
|
||||||
|
|
||||||
|
bool isTemporary() const;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onSourcesReady();
|
||||||
|
void onSourceAdded( const Tomahawk::source_ptr& source );
|
||||||
|
|
||||||
|
void loadHistory();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Tomahawk::source_ptr m_source;
|
||||||
|
unsigned int m_limit;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RECENTLYADDEDMODEL_H
|
@ -138,13 +138,3 @@ CollectionFlatModel::onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
CollectionFlatModel::onDataChanged()
|
|
||||||
{
|
|
||||||
TrackModelItem* p = (TrackModelItem*)sender();
|
|
||||||
|
|
||||||
if ( p )
|
|
||||||
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount( QModelIndex() ) - 1 ) );
|
|
||||||
}
|
|
||||||
|
@ -58,8 +58,6 @@ signals:
|
|||||||
void trackCountChanged( unsigned int tracks );
|
void trackCountChanged( unsigned int tracks );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDataChanged();
|
|
||||||
|
|
||||||
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks );
|
||||||
void onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks );
|
void onTracksRemoved( const QList<Tomahawk::query_ptr>& tracks );
|
||||||
|
|
||||||
|
@ -257,15 +257,6 @@ PlaylistModel::trackResolved( bool )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
PlaylistModel::onDataChanged()
|
|
||||||
{
|
|
||||||
TrackModelItem* p = (TrackModelItem*)sender();
|
|
||||||
if ( p && p->index.isValid() )
|
|
||||||
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount() - 1 ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistModel::onRevisionLoaded( Tomahawk::PlaylistRevision revision )
|
PlaylistModel::onRevisionLoaded( Tomahawk::PlaylistRevision revision )
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,6 @@ protected:
|
|||||||
void removeFromWaitList( const QString& revisionguid ) { m_waitForRevision.removeAll( revisionguid ); }
|
void removeFromWaitList( const QString& revisionguid ) { m_waitForRevision.removeAll( revisionguid ); }
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDataChanged();
|
|
||||||
void onRevisionLoaded( Tomahawk::PlaylistRevision revision );
|
void onRevisionLoaded( Tomahawk::PlaylistRevision revision );
|
||||||
void parsedDroppedTracks( QList<Tomahawk::query_ptr> );
|
void parsedDroppedTracks( QList<Tomahawk::query_ptr> );
|
||||||
void trackResolved( bool );
|
void trackResolved( bool );
|
||||||
|
@ -584,3 +584,12 @@ TrackModel::columnAlignment( int column ) const
|
|||||||
return Qt::AlignLeft;
|
return Qt::AlignLeft;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TrackModel::onDataChanged()
|
||||||
|
{
|
||||||
|
TrackModelItem* p = (TrackModelItem*)sender();
|
||||||
|
if ( p && p->index.isValid() )
|
||||||
|
emit dataChanged( p->index, p->index.sibling( p->index.row(), columnCount() - 1 ) );
|
||||||
|
}
|
||||||
|
@ -134,6 +134,8 @@ protected:
|
|||||||
TrackModelItem* rootItem() const { return m_rootItem; }
|
TrackModelItem* rootItem() const { return m_rootItem; }
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void onDataChanged();
|
||||||
|
|
||||||
void onPlaybackStarted( const Tomahawk::result_ptr& result );
|
void onPlaybackStarted( const Tomahawk::result_ptr& result );
|
||||||
void onPlaybackStopped();
|
void onPlaybackStopped();
|
||||||
|
|
||||||
|
@ -24,10 +24,10 @@
|
|||||||
|
|
||||||
#include "playlist/albummodel.h"
|
#include "playlist/albummodel.h"
|
||||||
#include "playlist/collectionflatmodel.h"
|
#include "playlist/collectionflatmodel.h"
|
||||||
|
#include "playlist/RecentlyAddedModel.h"
|
||||||
#include "playlist/RecentlyPlayedModel.h"
|
#include "playlist/RecentlyPlayedModel.h"
|
||||||
|
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
#include "database/databasecommand_alltracks.h"
|
|
||||||
#include "database/databasecommand_allalbums.h"
|
#include "database/databasecommand_allalbums.h"
|
||||||
|
|
||||||
#include "utils/tomahawkutils.h"
|
#include "utils/tomahawkutils.h"
|
||||||
@ -61,9 +61,9 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
|
|||||||
|
|
||||||
ui->historyView->overlay()->setEnabled( false );
|
ui->historyView->overlay()->setEnabled( false );
|
||||||
|
|
||||||
m_recentCollectionModel = new CollectionFlatModel( ui->recentCollectionView );
|
m_recentTracksModel = new RecentlyAddedModel( source, ui->recentCollectionView );
|
||||||
m_recentCollectionModel->setStyle( TrackModel::Short );
|
m_recentTracksModel->setStyle( TrackModel::Short );
|
||||||
ui->recentCollectionView->setTrackModel( m_recentCollectionModel );
|
ui->recentCollectionView->setTrackModel( m_recentTracksModel );
|
||||||
ui->recentCollectionView->sortByColumn( TrackModel::Age, Qt::DescendingOrder );
|
ui->recentCollectionView->sortByColumn( TrackModel::Age, Qt::DescendingOrder );
|
||||||
|
|
||||||
m_historyModel = new RecentlyPlayedModel( source, ui->historyView );
|
m_historyModel = new RecentlyPlayedModel( source, ui->historyView );
|
||||||
@ -75,7 +75,6 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget*
|
|||||||
ui->recentAlbumView->proxyModel()->sort( -1 );
|
ui->recentAlbumView->proxyModel()->sort( -1 );
|
||||||
|
|
||||||
onCollectionChanged();
|
onCollectionChanged();
|
||||||
|
|
||||||
connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) );
|
connect( source->collection().data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ) );
|
||||||
|
|
||||||
m_title = tr( "New Additions" );
|
m_title = tr( "New Additions" );
|
||||||
@ -101,7 +100,6 @@ SourceInfoWidget::~SourceInfoWidget()
|
|||||||
void
|
void
|
||||||
SourceInfoWidget::onCollectionChanged()
|
SourceInfoWidget::onCollectionChanged()
|
||||||
{
|
{
|
||||||
loadTracks();
|
|
||||||
loadRecentAdditions();
|
loadRecentAdditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,29 +111,6 @@ SourceInfoWidget::loadRecentAdditions()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SourceInfoWidget::loadTracks()
|
|
||||||
{
|
|
||||||
DatabaseCommand_AllTracks* cmd = new DatabaseCommand_AllTracks( m_source->collection() );
|
|
||||||
cmd->setLimit( 250 );
|
|
||||||
cmd->setSortOrder( DatabaseCommand_AllTracks::ModificationTime );
|
|
||||||
cmd->setSortDescending( true );
|
|
||||||
|
|
||||||
connect( cmd, SIGNAL( tracks( QList<Tomahawk::query_ptr>, QVariant ) ),
|
|
||||||
SLOT( onLoadedTrackHistory( QList<Tomahawk::query_ptr> ) ), Qt::QueuedConnection );
|
|
||||||
|
|
||||||
Database::instance()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
SourceInfoWidget::onLoadedTrackHistory( const QList<Tomahawk::query_ptr>& queries )
|
|
||||||
{
|
|
||||||
m_recentCollectionModel->clear();
|
|
||||||
m_recentCollectionModel->append( queries );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceInfoWidget::changeEvent( QEvent* e )
|
SourceInfoWidget::changeEvent( QEvent* e )
|
||||||
{
|
{
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
class AlbumModel;
|
class AlbumModel;
|
||||||
class CollectionFlatModel;
|
class CollectionFlatModel;
|
||||||
|
class RecentlyAddedModel;
|
||||||
class RecentlyPlayedModel;
|
class RecentlyPlayedModel;
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
@ -58,16 +59,14 @@ protected:
|
|||||||
void changeEvent( QEvent* e );
|
void changeEvent( QEvent* e );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void loadTracks();
|
|
||||||
void loadRecentAdditions();
|
void loadRecentAdditions();
|
||||||
|
|
||||||
void onCollectionChanged();
|
void onCollectionChanged();
|
||||||
void onLoadedTrackHistory( const QList<Tomahawk::query_ptr>& queries );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::SourceInfoWidget *ui;
|
Ui::SourceInfoWidget *ui;
|
||||||
|
|
||||||
CollectionFlatModel* m_recentCollectionModel;
|
RecentlyAddedModel* m_recentTracksModel;
|
||||||
RecentlyPlayedModel* m_historyModel;
|
RecentlyPlayedModel* m_historyModel;
|
||||||
AlbumModel* m_recentAlbumModel;
|
AlbumModel* m_recentAlbumModel;
|
||||||
|
|
||||||
|
@ -95,7 +95,6 @@ WelcomeWidget::~WelcomeWidget()
|
|||||||
void
|
void
|
||||||
WelcomeWidget::loadData()
|
WelcomeWidget::loadData()
|
||||||
{
|
{
|
||||||
|
|
||||||
m_recentAlbumsModel->addFilteredCollection( collection_ptr(), 20, DatabaseCommand_AllAlbums::ModificationTime, true );
|
m_recentAlbumsModel->addFilteredCollection( collection_ptr(), 20, DatabaseCommand_AllAlbums::ModificationTime, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user