1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-04 21:27:58 +02:00

* Robustified and cleaned up the PlaylistManager class.

* artist_ptr caching.
* Added basic AlbumView. (click the cloud icon in mainwindow's toolbar for now)
This commit is contained in:
Christian Muehlhaeuser
2010-12-07 08:10:12 +01:00
parent e2f6d2891d
commit fdc5db522d
27 changed files with 251 additions and 141 deletions

View File

@@ -29,6 +29,7 @@ public:
Tomahawk::collection_ptr collection() const { return m_collection; } Tomahawk::collection_ptr collection() const { return m_collection; }
QList<Tomahawk::query_ptr> tracks(); QList<Tomahawk::query_ptr> tracks();
virtual int unfilteredTrackCount() const { return m_queries.count(); }
virtual int trackCount() const { return m_queries.count(); } virtual int trackCount() const { return m_queries.count(); }
virtual Tomahawk::result_ptr siblingItem( int itemsAway ); virtual Tomahawk::result_ptr siblingItem( int itemsAway );
@@ -38,12 +39,15 @@ public:
virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {} virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {}
virtual void setShuffled( bool ) {} virtual void setShuffled( bool ) {}
virtual void setFilter( const QString& pattern ) {}
signals: signals:
void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void repeatModeChanged( PlaylistInterface::RepeatMode mode );
void shuffleModeChanged( bool enabled ); void shuffleModeChanged( bool enabled );
void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& ); void tracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& );
void trackCountChanged( unsigned int tracks ); void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
private slots: private slots:
void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection ); void onTracksAdded( const QList<Tomahawk::query_ptr>& tracks, const Tomahawk::collection_ptr& collection );

View File

@@ -4,6 +4,8 @@
#include <QObject> #include <QObject>
#include <QSharedPointer> #include <QSharedPointer>
#include "tomahawk/typedefs.h"
namespace Tomahawk namespace Tomahawk
{ {
@@ -12,14 +14,23 @@ class Artist : public QObject
Q_OBJECT Q_OBJECT
public: public:
Artist( const QString& name ) static artist_ptr get( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection );
: m_name( name )
{};
Artist( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection );
unsigned int id() const { return m_id; }
QString name() const { return m_name; } QString name() const { return m_name; }
Tomahawk::collection_ptr collection() const { return m_collection; }
// QList<Tomahawk::query_ptr> tracks();
// virtual int trackCount() const { return 0; }
private: private:
unsigned int m_id;
QString m_name; QString m_name;
Tomahawk::collection_ptr m_collection;
}; };
}; // ns }; // ns

View File

@@ -2,6 +2,7 @@
#define PLAYLISTINTERFACE_H #define PLAYLISTINTERFACE_H
#include <QModelIndex> #include <QModelIndex>
#include <QWidget>
#include "tomahawk/typedefs.h" #include "tomahawk/typedefs.h"
@@ -10,9 +11,10 @@ class PlaylistInterface
public: public:
enum RepeatMode { NoRepeat, RepeatOne, RepeatAll }; enum RepeatMode { NoRepeat, RepeatOne, RepeatAll };
PlaylistInterface() {} PlaylistInterface( QObject* parent ) : m_widget( 0 ), m_object( parent ) {}
virtual ~PlaylistInterface() {} virtual ~PlaylistInterface() {}
virtual int unfilteredTrackCount() const = 0;
virtual int trackCount() const = 0; virtual int trackCount() const = 0;
virtual Tomahawk::result_ptr previousItem() { return siblingItem( -1 ); } virtual Tomahawk::result_ptr previousItem() { return siblingItem( -1 ); }
@@ -22,6 +24,13 @@ public:
virtual PlaylistInterface::RepeatMode repeatMode() const = 0; virtual PlaylistInterface::RepeatMode repeatMode() const = 0;
virtual bool shuffled() const = 0; virtual bool shuffled() const = 0;
virtual void setFilter( const QString& pattern ) = 0;
QWidget* widget() const { return m_widget; }
void setWidget( QWidget* widget ) { m_widget = widget; }
QObject* object() const { return m_object; }
public slots: public slots:
virtual void setRepeatMode( RepeatMode mode ) = 0; virtual void setRepeatMode( RepeatMode mode ) = 0;
virtual void setShuffled( bool enabled ) = 0; virtual void setShuffled( bool enabled ) = 0;
@@ -30,6 +39,11 @@ signals:
virtual void repeatModeChanged( PlaylistInterface::RepeatMode mode ) = 0; virtual void repeatModeChanged( PlaylistInterface::RepeatMode mode ) = 0;
virtual void shuffleModeChanged( bool enabled ) = 0; virtual void shuffleModeChanged( bool enabled ) = 0;
virtual void trackCountChanged( unsigned int tracks ) = 0; virtual void trackCountChanged( unsigned int tracks ) = 0;
virtual void sourceTrackCountChanged( unsigned int tracks ) = 0;
private:
QWidget* m_widget;
QObject* m_object;
}; };
#endif // PLAYLISTINTERFACE_H #endif // PLAYLISTINTERFACE_H

View File

@@ -27,6 +27,7 @@ SET( TOMAHAWK_INC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../include/" )
#ENDFOREACH( moddir ) #ENDFOREACH( moddir )
SET( tomahawkSources ${tomahawkSources} SET( tomahawkSources ${tomahawkSources}
artist.cpp
album.cpp album.cpp
pipeline.cpp pipeline.cpp
playlist.cpp playlist.cpp

View File

@@ -28,7 +28,8 @@ Album::get( unsigned int id, const QString& name, const Tomahawk::artist_ptr& ar
Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist, const Tomahawk::collection_ptr& collection ) Album::Album( unsigned int id, const QString& name, const Tomahawk::artist_ptr& artist, const Tomahawk::collection_ptr& collection )
: m_id( id ) : PlaylistInterface( this )
, m_id( id )
, m_name( name ) , m_name( name )
, m_artist( artist ) , m_artist( artist )
, m_collection( collection ) , m_collection( collection )

35
src/artist.cpp Normal file
View File

@@ -0,0 +1,35 @@
#include "tomahawk/artist.h"
#include <QDebug>
#include "tomahawk/collection.h"
#include "tomahawk/tomahawkapp.h"
#include "database/database.h"
#include "database/databasecommand_alltracks.h"
using namespace Tomahawk;
artist_ptr
Artist::get( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection )
{
static QHash< unsigned int, artist_ptr > s_artists;
if ( s_artists.contains( id ) )
{
return s_artists.value( id );
}
artist_ptr a = artist_ptr( new Artist( id, name, collection ) );
s_artists.insert( id, a );
return a;
}
Artist::Artist( unsigned int id, const QString& name, const Tomahawk::collection_ptr& collection )
: m_id( id )
, m_name( name )
, m_collection( collection )
{
}

View File

@@ -41,7 +41,7 @@ DatabaseCommand_AllAlbums::exec( DatabaseImpl* dbi )
while( query.next() ) while( query.next() )
{ {
Tomahawk::artist_ptr artist = Tomahawk::artist_ptr( new Tomahawk::Artist( query.value( 3 ).toString() ) ); Tomahawk::artist_ptr artist = Tomahawk::Artist::get( query.value( 2 ).toUInt(), query.value( 3 ).toString(), m_collection );
Tomahawk::album_ptr album = Tomahawk::Album::get( query.value( 0 ).toUInt(), query.value( 1 ).toString(), artist, m_collection ); Tomahawk::album_ptr album = Tomahawk::Album::get( query.value( 0 ).toUInt(), query.value( 1 ).toString(), artist, m_collection );
al << album; al << album;

View File

@@ -170,6 +170,9 @@ DatabaseImpl::file( int fid )
m["mimetype"] = query.value( 4 ).toString(); m["mimetype"] = query.value( 4 ).toString();
m["duration"] = query.value( 5 ).toInt(); m["duration"] = query.value( 5 ).toInt();
m["bitrate"] = query.value( 6 ).toInt(); m["bitrate"] = query.value( 6 ).toInt();
m["artistid"] = query.value( 7 ).toInt();
m["albumid"] = query.value( 8 ).toInt();
m["trackid"] = query.value( 8 ).toInt();
m["artist"] = query.value( 10 ).toString(); m["artist"] = query.value( 10 ).toString();
m["album"] = query.value( 11 ).toString(); m["album"] = query.value( 11 ).toString();
m["track"] = query.value( 12 ).toString(); m["track"] = query.value( 12 ).toString();

View File

@@ -211,6 +211,22 @@ AlbumModel::removeIndexes( const QList<QModelIndex>& indexes )
} }
void
AlbumModel::addCollection( const collection_ptr& collection )
{
qDebug() << Q_FUNC_INFO << collection->name()
<< collection->source()->id()
<< collection->source()->userName();
DatabaseCommand_AllAlbums* cmd = new DatabaseCommand_AllAlbums( collection );
connect( cmd, SIGNAL( albums( QList<Tomahawk::album_ptr>, Tomahawk::collection_ptr ) ),
SLOT( onAlbumsAdded( QList<Tomahawk::album_ptr>, Tomahawk::collection_ptr ) ) );
TomahawkApp::instance()->database()->enqueue( QSharedPointer<DatabaseCommand>( cmd ) );
}
void void
AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order ) AlbumModel::addFilteredCollection( const collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order )
{ {

View File

@@ -13,7 +13,7 @@
class QMetaData; class QMetaData;
class AlbumModel : public QAbstractItemModel, public PlaylistInterface class AlbumModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
@@ -38,8 +38,6 @@ public:
virtual void removeIndex( const QModelIndex& index ); virtual void removeIndex( const QModelIndex& index );
virtual void removeIndexes( const QList<QModelIndex>& indexes ); virtual void removeIndexes( const QList<QModelIndex>& indexes );
virtual Tomahawk::result_ptr siblingItem( int direction ) { return Tomahawk::result_ptr(); }
virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; } virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; }
virtual bool shuffled() const { return false; } virtual bool shuffled() const { return false; }
@@ -47,6 +45,7 @@ public:
virtual QStringList mimeTypes() const; virtual QStringList mimeTypes() const;
virtual Qt::ItemFlags flags( const QModelIndex& index ) const; virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
void addCollection( const Tomahawk::collection_ptr& collection );
void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order ); void addFilteredCollection( const Tomahawk::collection_ptr& collection, unsigned int amount, DatabaseCommand_AllAlbums::SortOrder order );
AlbumItem* itemFromIndex( const QModelIndex& index ) const AlbumItem* itemFromIndex( const QModelIndex& index ) const

View File

@@ -9,6 +9,7 @@
AlbumProxyModel::AlbumProxyModel( QObject* parent ) AlbumProxyModel::AlbumProxyModel( QObject* parent )
: QSortFilterProxyModel( parent ) : QSortFilterProxyModel( parent )
, PlaylistInterface( this )
, m_model( 0 ) , m_model( 0 )
{ {
qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) ); qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );
@@ -26,15 +27,18 @@ AlbumProxyModel::setSourceModel( AlbumModel* sourceModel )
{ {
m_model = sourceModel; m_model = sourceModel;
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ),
SIGNAL( sourceTrackCountChanged( unsigned int ) ) );
QSortFilterProxyModel::setSourceModel( sourceModel ); QSortFilterProxyModel::setSourceModel( sourceModel );
} }
void void
AlbumProxyModel::setFilterRegExp( const QString& pattern ) AlbumProxyModel::setFilter( const QString& pattern )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QSortFilterProxyModel::setFilterRegExp( pattern ); setFilterRegExp( pattern );
emit filterChanged( pattern ); emit filterChanged( pattern );
} }
@@ -53,11 +57,11 @@ AlbumProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParen
const Tomahawk::album_ptr& q = pi->album(); const Tomahawk::album_ptr& q = pi->album();
QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts ); QStringList sl = filterRegExp().pattern().split( " ", QString::SkipEmptyParts );
bool found = true;
bool found = true;
foreach( const QString& s, sl ) foreach( const QString& s, sl )
{ {
if ( !q->name().contains( s, Qt::CaseInsensitive ) ) if ( !q->name().contains( s, Qt::CaseInsensitive ) && !q->artist()->name().contains( s, Qt::CaseInsensitive ) )
{ {
found = false; found = false;
} }
@@ -98,5 +102,5 @@ Tomahawk::result_ptr
AlbumProxyModel::siblingItem( int itemsAway ) AlbumProxyModel::siblingItem( int itemsAway )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
return Tomahawk::result_ptr(); return Tomahawk::result_ptr( 0 );
} }

View File

@@ -16,6 +16,7 @@ public:
virtual AlbumModel* sourceModel() const { return m_model; } virtual AlbumModel* sourceModel() const { return m_model; }
virtual void setSourceModel( AlbumModel* sourceModel ); virtual void setSourceModel( AlbumModel* sourceModel );
virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); }
virtual int trackCount() const { return rowCount( QModelIndex() ); } virtual int trackCount() const { return rowCount( QModelIndex() ); }
virtual int albumCount() const { return rowCount( QModelIndex() ); } virtual int albumCount() const { return rowCount( QModelIndex() ); }
@@ -24,7 +25,7 @@ public:
virtual Tomahawk::result_ptr siblingItem( int direction ); virtual Tomahawk::result_ptr siblingItem( int direction );
void setFilterRegExp( const QString& pattern ); virtual void setFilter( const QString& pattern );
virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; } virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; } virtual bool shuffled() const { return m_shuffled; }
@@ -34,6 +35,7 @@ signals:
void shuffleModeChanged( bool enabled ); void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks ); void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void filterChanged( const QString& filter ); void filterChanged( const QString& filter );

View File

@@ -51,6 +51,8 @@ void
AlbumView::setProxyModel( AlbumProxyModel* model ) AlbumView::setProxyModel( AlbumProxyModel* model )
{ {
m_proxyModel = model; m_proxyModel = model;
qDebug() << "NOOOOOOOOOOOOOOW CUUUUUUUUUUUUUUUUUR:" << m_proxyModel << (PlaylistInterface*)m_proxyModel;
setItemDelegate( new AlbumItemDelegate( this, m_proxyModel ) ); setItemDelegate( new AlbumItemDelegate( this, m_proxyModel ) );
QListView::setModel( m_proxyModel ); QListView::setModel( m_proxyModel );

View File

@@ -18,7 +18,7 @@ public:
void setProxyModel( AlbumProxyModel* model ); void setProxyModel( AlbumProxyModel* model );
AlbumModel* model() { return m_model; } AlbumModel* model() { return m_model; }
AlbumProxyModel* proxyModel() { return (AlbumProxyModel*)m_proxyModel; } AlbumProxyModel* proxyModel() { return m_proxyModel; }
// PlaylistItemDelegate* delegate() { return m_delegate; } // PlaylistItemDelegate* delegate() { return m_delegate; }
void setModel( AlbumModel* model ); void setModel( AlbumModel* model );

View File

@@ -15,7 +15,7 @@
class QMetaData; class QMetaData;
class CollectionModel : public QAbstractItemModel, public PlaylistInterface class CollectionModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
@@ -37,12 +37,6 @@ public:
void addCollection( const Tomahawk::collection_ptr& collection ); void addCollection( const Tomahawk::collection_ptr& collection );
void removeCollection( const Tomahawk::collection_ptr& collection ); void removeCollection( const Tomahawk::collection_ptr& collection );
virtual Tomahawk::result_ptr previousItem() { return Tomahawk::result_ptr(); }
virtual Tomahawk::result_ptr nextItem() { return Tomahawk::result_ptr(); }
virtual Tomahawk::result_ptr siblingItem( int direction ) { return Tomahawk::result_ptr(); }
virtual void setCurrentItem( const QModelIndex& index ) {}
virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; } virtual PlaylistInterface::RepeatMode repeatMode() const { return PlaylistInterface::NoRepeat; }
virtual bool shuffled() const { return false; } virtual bool shuffled() const { return false; }

View File

@@ -77,7 +77,7 @@ PlaylistItemDelegate::paint( QPainter* painter, const QStyleOptionViewItem& opti
if ( index.column() == index.model()->columnCount() - 1 ) if ( index.column() == index.model()->columnCount() - 1 )
{ {
QRect r = QRect( 3, option.rect.y() + 1, m_view->contentsRect().width() - 6, option.rect.height() - 2 ); QRect r = QRect( 3, option.rect.y() + 1, m_view->viewport()->width() - 6, option.rect.height() - 2 );
painter->setPen( option.palette.highlight().color() ); painter->setPen( option.palette.highlight().color() );
QPen pen = painter->pen(); QPen pen = painter->pen();
pen.setWidth( 1.0 ); pen.setWidth( 1.0 );

View File

@@ -13,6 +13,9 @@
#include "queueview.h" #include "queueview.h"
#include "trackproxymodel.h" #include "trackproxymodel.h"
#include "trackmodel.h" #include "trackmodel.h"
#include "albumview.h"
#include "albumproxymodel.h"
#include "albummodel.h"
#include "infowidgets/sourceinfowidget.h" #include "infowidgets/sourceinfowidget.h"
@@ -22,9 +25,7 @@
PlaylistManager::PlaylistManager( QObject* parent ) PlaylistManager::PlaylistManager( QObject* parent )
: QObject( parent ) : QObject( parent )
, m_widget( new QWidget() ) , m_widget( new QWidget() )
, m_currentProxyModel( 0 ) , m_currentInterface( 0 )
, m_currentModel( 0 )
, m_currentView( 0 )
, m_currentMode( 0 ) , m_currentMode( 0 )
, m_superCollectionVisible( true ) , m_superCollectionVisible( true )
{ {
@@ -54,7 +55,7 @@ PlaylistManager::PlaylistManager( QObject* parent )
m_superCollectionView->setModel( m_superCollectionFlatModel ); m_superCollectionView->setModel( m_superCollectionFlatModel );
m_stack->addWidget( m_superCollectionView ); m_stack->addWidget( m_superCollectionView );
m_currentView = m_superCollectionView; m_currentInterface = m_superCollectionView->proxyModel();
connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) ); connect( &m_filterTimer, SIGNAL( timeout() ), SLOT( applyFilter() ) );
} }
@@ -84,26 +85,20 @@ PlaylistManager::show( const Tomahawk::playlist_ptr& playlist )
PlaylistModel* model = new PlaylistModel(); PlaylistModel* model = new PlaylistModel();
view->setModel( model ); view->setModel( model );
m_currentProxyModel = view->proxyModel();
m_currentModel = view->model();
model->loadPlaylist( playlist ); model->loadPlaylist( playlist );
playlist->resolve(); playlist->resolve();
m_currentInterface = view->proxyModel();
m_playlistViews.insert( playlist, view ); m_playlistViews.insert( playlist, view );
m_views.insert( (PlaylistInterface*)m_currentProxyModel, view );
m_stack->addWidget( view ); m_stack->addWidget( view );
m_stack->setCurrentWidget( view ); m_stack->setCurrentWidget( view );
m_currentView = view;
} }
else else
{ {
PlaylistView* view = m_playlistViews.value( playlist ); PlaylistView* view = m_playlistViews.value( playlist );
m_stack->setCurrentWidget( view ); m_stack->setCurrentWidget( view );
m_currentProxyModel = view->proxyModel(); m_currentInterface = view->proxyModel();
m_currentModel = view->model();
m_currentView = view;
} }
m_superCollectionVisible = false; m_superCollectionVisible = false;
@@ -125,26 +120,19 @@ PlaylistManager::show( const Tomahawk::album_ptr& album )
PlaylistView* view = new PlaylistView(); PlaylistView* view = new PlaylistView();
PlaylistModel* model = new PlaylistModel(); PlaylistModel* model = new PlaylistModel();
view->setModel( model ); view->setModel( model );
m_currentProxyModel = view->proxyModel();
m_currentModel = view->model();
model->loadAlbum( album ); model->loadAlbum( album );
m_currentInterface = view->proxyModel();
m_albumViews.insert( album, view ); m_albumViews.insert( album, view );
m_views.insert( (PlaylistInterface*)m_currentProxyModel, view );
m_stack->addWidget( view ); m_stack->addWidget( view );
m_stack->setCurrentWidget( view ); m_stack->setCurrentWidget( view );
m_currentView = view;
} }
else else
{ {
PlaylistView* view = m_albumViews.value( album ); PlaylistView* view = m_albumViews.value( album );
m_stack->setCurrentWidget( view ); m_stack->setCurrentWidget( view );
m_currentProxyModel = view->proxyModel(); m_currentInterface = view->proxyModel();
m_currentModel = view->model();
m_currentView = view;
} }
m_superCollectionVisible = false; m_superCollectionVisible = false;
@@ -160,31 +148,50 @@ PlaylistManager::show( const Tomahawk::collection_ptr& collection )
{ {
unlinkPlaylist(); unlinkPlaylist();
if ( !m_collectionViews.contains( collection ) ) if ( m_currentMode == 0 )
{ {
CollectionView* view = new CollectionView(); if ( !m_collectionViews.contains( collection ) )
CollectionFlatModel* model = new CollectionFlatModel(); {
view->setModel( model ); CollectionView* view = new CollectionView();
CollectionFlatModel* model = new CollectionFlatModel();
view->setModel( model );
model->addCollection( collection );
m_currentProxyModel = view->proxyModel(); m_currentInterface = view->proxyModel();
m_currentModel = view->model(); m_collectionViews.insert( collection, view );
model->addCollection( collection ); m_stack->addWidget( view );
m_stack->setCurrentWidget( view );
m_collectionViews.insert( collection, view ); }
m_views.insert( (PlaylistInterface*)m_currentProxyModel, view ); else
{
m_stack->addWidget( view ); CollectionView* view = m_collectionViews.value( collection );
m_stack->setCurrentWidget( view ); m_stack->setCurrentWidget( view );
m_currentView = view; m_currentInterface = view->proxyModel();
}
} }
else
if ( m_currentMode == 2 )
{ {
CollectionView* view = m_collectionViews.value( collection ); if ( !m_collectionAlbumViews.contains( collection ) )
m_stack->setCurrentWidget( view ); {
m_currentProxyModel = view->proxyModel(); AlbumView* aview = new AlbumView();
m_currentModel = view->model(); AlbumModel* amodel = new AlbumModel( aview );
m_currentView = view; aview->setModel( amodel );
amodel->addCollection( collection );
m_currentInterface = aview->proxyModel();
m_collectionAlbumViews.insert( collection, aview );
m_stack->addWidget( aview );
m_stack->setCurrentWidget( aview );
}
else
{
AlbumView* view = m_collectionAlbumViews.value( collection );
m_stack->setCurrentWidget( view );
m_currentInterface = view->proxyModel();
}
} }
m_superCollectionVisible = false; m_superCollectionVisible = false;
@@ -200,9 +207,7 @@ PlaylistManager::show( const Tomahawk::source_ptr& source )
{ {
unlinkPlaylist(); unlinkPlaylist();
m_currentProxyModel = 0; m_currentInterface = 0;
m_currentModel = 0;
m_currentView = 0;
if ( !m_sourceViews.contains( source ) ) if ( !m_sourceViews.contains( source ) )
{ {
@@ -237,10 +242,7 @@ PlaylistManager::showSuperCollection()
} }
m_stack->setCurrentWidget( m_superCollectionView ); m_stack->setCurrentWidget( m_superCollectionView );
m_currentProxyModel = m_superCollectionView->proxyModel(); m_currentInterface = m_superCollectionView->proxyModel();
m_currentModel = m_superCollectionView->model();
m_currentView = m_superCollectionView;
m_views.insert( (PlaylistInterface*)m_currentProxyModel, m_superCollectionView );
m_superCollectionVisible = true; m_superCollectionVisible = true;
linkPlaylist(); linkPlaylist();
@@ -250,6 +252,16 @@ PlaylistManager::showSuperCollection()
} }
void
PlaylistManager::setTableMode()
{
qDebug() << Q_FUNC_INFO;
m_currentMode = 0;
m_stack->setCurrentWidget( m_superCollectionView );
}
void void
PlaylistManager::setTreeMode() PlaylistManager::setTreeMode()
{ {
@@ -263,11 +275,11 @@ PlaylistManager::setTreeMode()
void void
PlaylistManager::setTableMode() PlaylistManager::setAlbumMode()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
m_currentMode = 0; m_currentMode = 2;
m_stack->setCurrentWidget( m_superCollectionView ); m_stack->setCurrentWidget( m_superCollectionView );
} }
@@ -319,30 +331,27 @@ PlaylistManager::applyFilter()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
if ( m_currentProxyModel ) if ( m_currentInterface )
m_currentProxyModel->setFilterRegExp( m_filter ); m_currentInterface->setFilter( m_filter );
} }
void void
PlaylistManager::unlinkPlaylist() PlaylistManager::unlinkPlaylist()
{ {
if ( m_currentModel ) if ( m_currentInterface )
{ {
disconnect( m_currentModel, SIGNAL( trackCountChanged( unsigned int ) ), disconnect( m_currentInterface->object(), SIGNAL( sourceTrackCountChanged( unsigned int ) ),
this, SLOT( onTrackCountChanged( unsigned int ) ) ); this, SIGNAL( numTracksChanged( unsigned int ) ) );
}
if ( m_currentProxyModel ) disconnect( m_currentInterface->object(), SIGNAL( trackCountChanged( unsigned int ) ),
{ this, SIGNAL( numShownChanged( unsigned int ) ) );
disconnect( m_currentProxyModel, SIGNAL( trackCountChanged( unsigned int ) ),
this, SLOT( onTrackCountChanged( unsigned int ) ) );
disconnect( m_currentProxyModel, SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ), disconnect( m_currentInterface->object(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ),
this, SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ) ); this, SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ) );
disconnect( m_currentProxyModel, SIGNAL( shuffleModeChanged( bool ) ), disconnect( m_currentInterface->object(), SIGNAL( shuffleModeChanged( bool ) ),
this, SIGNAL( shuffleModeChanged( bool ) ) ); this, SIGNAL( shuffleModeChanged( bool ) ) );
} }
} }
@@ -350,68 +359,62 @@ PlaylistManager::unlinkPlaylist()
void void
PlaylistManager::linkPlaylist() PlaylistManager::linkPlaylist()
{ {
connect( m_currentModel, SIGNAL( trackCountChanged( unsigned int ) ), if ( m_currentInterface )
this, SLOT( onTrackCountChanged( unsigned int ) ) ); {
connect( m_currentInterface->object(), SIGNAL( sourceTrackCountChanged( unsigned int ) ),
this, SIGNAL( numTracksChanged( unsigned int ) ) );
connect( m_currentProxyModel, SIGNAL( trackCountChanged( unsigned int ) ), connect( m_currentInterface->object(), SIGNAL( trackCountChanged( unsigned int ) ),
this, SLOT( onTrackCountChanged( unsigned int ) ) ); this, SIGNAL( numShownChanged( unsigned int ) ) );
connect( m_currentProxyModel, SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ), connect( m_currentInterface->object(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ),
this, SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ) ); this, SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ) );
connect( m_currentProxyModel, SIGNAL( shuffleModeChanged( bool ) ), connect( m_currentInterface->object(), SIGNAL( shuffleModeChanged( bool ) ),
this, SIGNAL( shuffleModeChanged( bool ) ) ); this, SIGNAL( shuffleModeChanged( bool ) ) );
}
applyFilter(); applyFilter();
APP->audioEngine()->setPlaylist( (PlaylistInterface*)m_currentProxyModel ); APP->audioEngine()->setPlaylist( m_currentInterface );
emit numTracksChanged( m_currentModel->trackCount() ); if ( m_currentInterface )
emit repeatModeChanged( m_currentProxyModel->repeatMode() ); {
emit shuffleModeChanged( m_currentProxyModel->shuffled() ); emit numTracksChanged( m_currentInterface->unfilteredTrackCount() );
} emit numShownChanged( m_currentInterface->trackCount() );
emit repeatModeChanged( m_currentInterface->repeatMode() );
emit shuffleModeChanged( m_currentInterface->shuffled() );
void }
PlaylistManager::onTrackCountChanged( unsigned int )
{
emit numTracksChanged( m_currentModel->trackCount() );
emit numShownChanged( m_currentProxyModel->trackCount() );
} }
void void
PlaylistManager::setRepeatMode( PlaylistInterface::RepeatMode mode ) PlaylistManager::setRepeatMode( PlaylistInterface::RepeatMode mode )
{ {
if ( m_currentProxyModel ) if ( m_currentInterface )
m_currentProxyModel->setRepeatMode( mode ); m_currentInterface->setRepeatMode( mode );
} }
void void
PlaylistManager::setShuffled( bool enabled ) PlaylistManager::setShuffled( bool enabled )
{ {
if ( m_currentProxyModel ) if ( m_currentInterface )
m_currentProxyModel->setShuffled( enabled ); m_currentInterface->setShuffled( enabled );
} }
void void
PlaylistManager::showCurrentTrack() PlaylistManager::showCurrentTrack()
{ {
PlaylistInterface* playlist = APP->audioEngine()->currentTrackPlaylist(); m_currentInterface = APP->audioEngine()->currentTrackPlaylist();
if ( m_views.contains( playlist ) ) unlinkPlaylist();
{
unlinkPlaylist();
m_currentView = m_views.value( playlist ); if ( m_currentInterface->widget() )
m_currentProxyModel = m_currentView->proxyModel(); m_stack->setCurrentWidget( m_currentInterface->widget() );
m_currentModel = m_currentView->model();
m_stack->setCurrentWidget( m_currentView ); linkPlaylist();
linkPlaylist();
}
if ( m_currentView && m_currentProxyModel ) /* if ( m_currentView && m_currentProxyModel )
m_currentView->scrollTo( m_currentProxyModel->currentItem(), QAbstractItemView::PositionAtCenter ); m_currentView->scrollTo( m_currentProxyModel->currentItem(), QAbstractItemView::PositionAtCenter );*/
} }

View File

@@ -9,6 +9,7 @@
#include "tomahawk/playlistinterface.h" #include "tomahawk/playlistinterface.h"
class AnimatedSplitter; class AnimatedSplitter;
class AlbumView;
class CollectionModel; class CollectionModel;
class CollectionFlatModel; class CollectionFlatModel;
class CollectionView; class CollectionView;
@@ -53,6 +54,7 @@ signals:
public slots: public slots:
void setTreeMode(); void setTreeMode();
void setTableMode(); void setTableMode();
void setAlbumMode();
void showQueue(); void showQueue();
void hideQueue(); void hideQueue();
@@ -64,7 +66,6 @@ public slots:
private slots: private slots:
void applyFilter(); void applyFilter();
void onTrackCountChanged( unsigned int );
private: private:
void unlinkPlaylist(); void unlinkPlaylist();
@@ -82,15 +83,19 @@ private:
QList< Tomahawk::collection_ptr > m_superCollections; QList< Tomahawk::collection_ptr > m_superCollections;
QHash< PlaylistInterface*, TrackView* > m_views;
QHash< Tomahawk::collection_ptr, CollectionView* > m_collectionViews; QHash< Tomahawk::collection_ptr, CollectionView* > m_collectionViews;
QHash< Tomahawk::collection_ptr, AlbumView* > m_collectionAlbumViews;
QHash< Tomahawk::playlist_ptr, PlaylistView* > m_playlistViews; QHash< Tomahawk::playlist_ptr, PlaylistView* > m_playlistViews;
QHash< Tomahawk::album_ptr, PlaylistView* > m_albumViews; QHash< Tomahawk::album_ptr, PlaylistView* > m_albumViews;
QHash< Tomahawk::source_ptr, SourceInfoWidget* > m_sourceViews; QHash< Tomahawk::source_ptr, SourceInfoWidget* > m_sourceViews;
TrackProxyModel* m_currentProxyModel; /*TrackProxyModel* m_currentProxyModel;
TrackModel* m_currentModel; TrackModel* m_currentModel;
TrackView* m_currentView; TrackView* m_currentView;*/
// QWidget* m_currentView;
PlaylistInterface* m_currentInterface;
QWidget* m_currentInfoWidget; QWidget* m_currentInfoWidget;

View File

@@ -8,7 +8,7 @@
class QMetaData; class QMetaData;
class TrackModel : public QAbstractItemModel, public PlaylistInterface class TrackModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
@@ -41,8 +41,6 @@ public:
virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const; virtual QVariant data( const QModelIndex& index, int role = Qt::DisplayRole ) const;
virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const; virtual QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
virtual Tomahawk::result_ptr siblingItem( int direction ) { return Tomahawk::result_ptr(); }
virtual QMimeData* mimeData( const QModelIndexList& indexes ) const; virtual QMimeData* mimeData( const QModelIndexList& indexes ) const;
virtual QStringList mimeTypes() const; virtual QStringList mimeTypes() const;
virtual Qt::DropActions supportedDropActions() const; virtual Qt::DropActions supportedDropActions() const;

View File

@@ -10,6 +10,7 @@
TrackProxyModel::TrackProxyModel( QObject* parent ) TrackProxyModel::TrackProxyModel( QObject* parent )
: QSortFilterProxyModel( parent ) : QSortFilterProxyModel( parent )
, PlaylistInterface( this )
, m_model( 0 ) , m_model( 0 )
, m_repeatMode( PlaylistInterface::NoRepeat ) , m_repeatMode( PlaylistInterface::NoRepeat )
, m_shuffled( false ) , m_shuffled( false )
@@ -29,15 +30,19 @@ TrackProxyModel::setSourceModel( TrackModel* sourceModel )
{ {
m_model = sourceModel; m_model = sourceModel;
if ( m_model )
connect( m_model, SIGNAL( trackCountChanged( unsigned int ) ),
SIGNAL( sourceTrackCountChanged( unsigned int ) ) );
QSortFilterProxyModel::setSourceModel( sourceModel ); QSortFilterProxyModel::setSourceModel( sourceModel );
} }
void void
TrackProxyModel::setFilterRegExp( const QString& pattern ) TrackProxyModel::setFilter( const QString& pattern )
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
QSortFilterProxyModel::setFilterRegExp( pattern ); setFilterRegExp( pattern );
emit filterChanged( pattern ); emit filterChanged( pattern );
emit trackCountChanged( trackCount() ); emit trackCountChanged( trackCount() );

View File

@@ -19,6 +19,7 @@ public:
virtual QPersistentModelIndex currentItem() const { return mapFromSource( m_model->currentItem() ); } virtual QPersistentModelIndex currentItem() const { return mapFromSource( m_model->currentItem() ); }
virtual void setCurrentItem( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); } virtual void setCurrentItem( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); }
virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); }
virtual int trackCount() const { return rowCount( QModelIndex() ); } virtual int trackCount() const { return rowCount( QModelIndex() ); }
virtual void removeIndex( const QModelIndex& index ); virtual void removeIndex( const QModelIndex& index );
@@ -27,7 +28,7 @@ public:
virtual Tomahawk::result_ptr siblingItem( int itemsAway ); virtual Tomahawk::result_ptr siblingItem( int itemsAway );
void setFilterRegExp( const QString& pattern ); virtual void setFilter( const QString& pattern );
virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; } virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; }
virtual bool shuffled() const { return m_shuffled; } virtual bool shuffled() const { return m_shuffled; }
@@ -39,6 +40,7 @@ signals:
void shuffleModeChanged( bool enabled ); void shuffleModeChanged( bool enabled );
void trackCountChanged( unsigned int tracks ); void trackCountChanged( unsigned int tracks );
void sourceTrackCountChanged( unsigned int tracks );
void filterChanged( const QString& filter ); void filterChanged( const QString& filter );

View File

@@ -34,6 +34,8 @@ TrackView::TrackView( QWidget* parent )
setDragDropOverwriteMode( false ); setDragDropOverwriteMode( false );
setAllColumnsShowFocus( true ); setAllColumnsShowFocus( true );
setVerticalScrollMode( QAbstractItemView::ScrollPerPixel ); setVerticalScrollMode( QAbstractItemView::ScrollPerPixel );
setRootIsDecorated( false );
setUniformRowHeights( true );
setMinimumWidth( 700 ); setMinimumWidth( 700 );
setHeader( m_header ); setHeader( m_header );
@@ -58,6 +60,8 @@ void
TrackView::setProxyModel( TrackProxyModel* model ) TrackView::setProxyModel( TrackProxyModel* model )
{ {
m_proxyModel = model; m_proxyModel = model;
m_proxyModel->setWidget( this );
m_delegate = new PlaylistItemDelegate( this, m_proxyModel ); m_delegate = new PlaylistItemDelegate( this, m_proxyModel );
setItemDelegate( m_delegate ); setItemDelegate( m_delegate );
@@ -69,17 +73,16 @@ void
TrackView::setModel( TrackModel* model ) TrackView::setModel( TrackModel* model )
{ {
m_model = model; m_model = model;
m_modelInterface = (PlaylistInterface*)model;
if ( m_proxyModel ) if ( m_proxyModel )
{
m_proxyModel->setSourceModel( model ); m_proxyModel->setSourceModel( model );
}
connect( m_model, SIGNAL( itemSizeChanged( QModelIndex ) ), SLOT( onItemResized( QModelIndex ) ) ); connect( m_model, SIGNAL( itemSizeChanged( QModelIndex ) ), SLOT( onItemResized( QModelIndex ) ) );
connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) ); connect( m_proxyModel, SIGNAL( filterChanged( QString ) ), SLOT( onFilterChanged( QString ) ) );
setAcceptDrops( true ); setAcceptDrops( true );
setRootIsDecorated( false );
setUniformRowHeights( true );
} }

View File

@@ -22,7 +22,7 @@ public:
void setProxyModel( TrackProxyModel* model ); void setProxyModel( TrackProxyModel* model );
TrackModel* model() { return m_model; } TrackModel* model() { return m_model; }
TrackProxyModel* proxyModel() { return (TrackProxyModel*)m_proxyModel; } TrackProxyModel* proxyModel() { return m_proxyModel; }
PlaylistItemDelegate* delegate() { return m_delegate; } PlaylistItemDelegate* delegate() { return m_delegate; }
TrackHeader* header() { return m_header; } TrackHeader* header() { return m_header; }
@@ -59,7 +59,6 @@ private:
TrackModel* m_model; TrackModel* m_model;
TrackProxyModel* m_proxyModel; TrackProxyModel* m_proxyModel;
PlaylistInterface* m_modelInterface;
PlaylistItemDelegate* m_delegate; PlaylistItemDelegate* m_delegate;
TrackHeader* m_header; TrackHeader* m_header;

View File

@@ -11,7 +11,7 @@ Result::Result( const QVariant& v, const collection_ptr& collection )
{ {
QVariantMap m = m_v.toMap(); QVariantMap m = m_v.toMap();
m_artist = artist_ptr( new Artist( m.value( "artist" ).toString() ) ); m_artist = Artist::get( m.value( "artistid" ).toUInt(), m.value( "artist" ).toString(), collection );
m_album = Album::get( m.value( "albumid" ).toUInt(), m.value( "album" ).toString(), m_artist, collection ); m_album = Album::get( m.value( "albumid" ).toUInt(), m.value( "album" ).toString(), m_artist, collection );
m_track = m.value( "track" ).toString(); m_track = m.value( "track" ).toString();
m_url = m.value( "url" ).toString(); m_url = m.value( "url" ).toString();

View File

@@ -139,6 +139,9 @@ TomahawkWindow::setupSignals()
connect( m_topbar, SIGNAL( artistMode() ), connect( m_topbar, SIGNAL( artistMode() ),
playlistManager(), SLOT( setTreeMode() ) ); playlistManager(), SLOT( setTreeMode() ) );
connect( m_topbar, SIGNAL( albumMode() ),
playlistManager(), SLOT( setAlbumMode() ) );
// <From PlaylistManager> // <From PlaylistManager>
connect( playlistManager(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ), connect( playlistManager(), SIGNAL( repeatModeChanged( PlaylistInterface::RepeatMode ) ),
m_audioControls, SLOT( onRepeatModeChanged( PlaylistInterface::RepeatMode ) ) ); m_audioControls, SLOT( onRepeatModeChanged( PlaylistInterface::RepeatMode ) ) );

View File

@@ -56,10 +56,13 @@ TopBar::TopBar( QWidget* parent )
ui->radioDetailed->setFocusPolicy( Qt::NoFocus ); ui->radioDetailed->setFocusPolicy( Qt::NoFocus );
ui->radioCloud->setFocusPolicy( Qt::NoFocus ); ui->radioCloud->setFocusPolicy( Qt::NoFocus );
ui->radioDetailed->setEnabled( false );
connect( ui->radioNormal, SIGNAL( clicked() ), SIGNAL( flatMode() ) ); connect( ui->radioNormal, SIGNAL( clicked() ), SIGNAL( flatMode() ) );
connect( ui->radioDetailed, SIGNAL( clicked() ), SIGNAL( artistMode() ) ); connect( ui->radioDetailed, SIGNAL( clicked() ), SIGNAL( artistMode() ) );
connect( ui->radioCloud, SIGNAL( clicked() ), SIGNAL( albumMode() ) );
ui->widgetRadio->hide(); // FIXME // ui->widgetRadio->hide(); // FIXME
setNumSources( 0 ); setNumSources( 0 );
setNumTracks( 0 ); setNumTracks( 0 );
@@ -168,6 +171,7 @@ void
TopBar::setNumTracks( unsigned int i ) TopBar::setNumTracks( unsigned int i )
{ {
m_tracks = i; m_tracks = i;
ui->statsLabelNumTracks->setVisible( m_tracks > 0 );
ui->statsLabelNumTracks->setVal( i ); ui->statsLabelNumTracks->setVal( i );
} }

View File

@@ -22,8 +22,10 @@ public:
signals: signals:
void filterTextChanged( const QString& newtext ); void filterTextChanged( const QString& newtext );
void flatMode(); void flatMode();
void artistMode(); void artistMode();
void albumMode();
public slots: public slots:
void setNumSources( unsigned int ); void setNumSources( unsigned int );