diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 36efed296..ee8d41f4b 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -43,26 +43,32 @@ set( libGuiSources playlist/treemodel.cpp playlist/treeproxymodel.cpp + playlist/treeproxymodelplaylistinterface.cpp playlist/treeheader.cpp playlist/treeitemdelegate.cpp playlist/collectionproxymodel.cpp + playlist/collectionproxymodelplaylistinterface.cpp playlist/collectionflatmodel.cpp playlist/collectionview.cpp playlist/playlistmodel.cpp playlist/playlistproxymodel.cpp + playlist/playlistproxymodelplaylistinterface.cpp playlist/playlistview.cpp playlist/playlistitemdelegate.cpp playlist/queueproxymodel.cpp + playlist/queueproxymodelplaylistinterface.cpp playlist/queueview.cpp playlist/trackmodel.cpp playlist/trackmodelitem.cpp playlist/trackproxymodel.cpp + playlist/trackproxymodelplaylistinterface.cpp playlist/trackview.cpp playlist/trackheader.cpp playlist/treemodelitem.cpp playlist/albumitem.cpp playlist/albummodel.cpp playlist/albumproxymodel.cpp + playlist/albumproxymodelplaylistinterface.cpp playlist/albumitemdelegate.cpp playlist/albumview.cpp playlist/artistview.cpp @@ -170,26 +176,32 @@ set( libGuiHeaders playlist/treemodel.h playlist/treeproxymodel.h + playlist/treeproxymodelplaylistinterface.h playlist/treeheader.h playlist/treeitemdelegate.h playlist/collectionproxymodel.h + playlist/collectionproxymodelplaylistinterface.h playlist/collectionflatmodel.h playlist/collectionview.h playlist/playlistmodel.h playlist/playlistproxymodel.h + playlist/playlistproxymodelplaylistinterface.h playlist/playlistview.h playlist/playlistitemdelegate.h playlist/queueproxymodel.h + playlist/queueproxymodelplaylistinterface.h playlist/queueview.h playlist/trackmodel.h playlist/trackmodelitem.h playlist/trackproxymodel.h + playlist/trackproxymodelplaylistinterface.h playlist/trackview.h playlist/trackheader.h playlist/treemodelitem.h playlist/albumitem.h playlist/albummodel.h playlist/albumproxymodel.h + playlist/albumproxymodelplaylistinterface.h playlist/albumitemdelegate.h playlist/albumview.h playlist/artistview.h @@ -406,6 +418,8 @@ set( libHeaders pipeline.h functimeout.h + playlistinterface.h + aclsystem.h collection.h query.h diff --git a/src/libtomahawk/album.h b/src/libtomahawk/album.h index 14fb9d749..6b1d4c8da 100644 --- a/src/libtomahawk/album.h +++ b/src/libtomahawk/album.h @@ -64,6 +64,6 @@ private: Tomahawk::playlistinterface_ptr m_playlistInterface; }; -}; // ns +} // ns #endif diff --git a/src/libtomahawk/albumplaylistinterface.cpp b/src/libtomahawk/albumplaylistinterface.cpp index a72723653..791aecafd 100644 --- a/src/libtomahawk/albumplaylistinterface.cpp +++ b/src/libtomahawk/albumplaylistinterface.cpp @@ -31,7 +31,7 @@ using namespace Tomahawk; AlbumPlaylistInterface::AlbumPlaylistInterface() {} AlbumPlaylistInterface::AlbumPlaylistInterface( Tomahawk::Album *album ) - : Tomahawk::PlaylistInterface( this ) + : Tomahawk::PlaylistInterface() , m_currentItem( 0 ) , m_currentTrack( 0 ) , m_album( QWeakPointer< Tomahawk::Album >( album ) ) diff --git a/src/libtomahawk/albumplaylistinterface.h b/src/libtomahawk/albumplaylistinterface.h index 9fd9eaa48..e852a6f68 100644 --- a/src/libtomahawk/albumplaylistinterface.h +++ b/src/libtomahawk/albumplaylistinterface.h @@ -32,7 +32,7 @@ namespace Tomahawk class Album; -class DLLEXPORT AlbumPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +class DLLEXPORT AlbumPlaylistInterface : public Tomahawk::PlaylistInterface { Q_OBJECT @@ -60,8 +60,6 @@ public: virtual void addQueries( const QList& tracks ); - virtual void findMoreIfaces() {} - signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); diff --git a/src/libtomahawk/artistplaylistinterface.h b/src/libtomahawk/artistplaylistinterface.h index 04e75e908..567f4ae7d 100644 --- a/src/libtomahawk/artistplaylistinterface.h +++ b/src/libtomahawk/artistplaylistinterface.h @@ -31,7 +31,7 @@ namespace Tomahawk class Artist; -class DLLEXPORT ArtistPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +class DLLEXPORT ArtistPlaylistInterface : public Tomahawk::PlaylistInterface { Q_OBJECT @@ -59,8 +59,6 @@ public: virtual void addQueries( const QList& tracks ); - virtual void findMoreIfaces() {} - signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); diff --git a/src/libtomahawk/audio/audioengine.cpp b/src/libtomahawk/audio/audioengine.cpp index 73e9a732c..9be1cf518 100644 --- a/src/libtomahawk/audio/audioengine.cpp +++ b/src/libtomahawk/audio/audioengine.cpp @@ -562,7 +562,7 @@ AudioEngine::playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk: m_playlist.data()->reset(); setPlaylist( playlist ); - m_currentTrackPlaylist = playlist->getSharedPointer(); + m_currentTrackPlaylist = playlist; if ( !result.isNull() ) loadTrack( result ); @@ -682,8 +682,8 @@ AudioEngine::setPlaylist( Tomahawk::playlistinterface_ptr playlist ) { if ( !m_playlist.isNull() ) { - if ( m_playlist.data()->object() && m_playlist.data()->retryMode() == PlaylistInterface::Retry ) - disconnect( m_playlist.data()->object(), SIGNAL( nextTrackReady() ) ); + if ( m_playlist.data() && m_playlist.data()->retryMode() == PlaylistInterface::Retry ) + disconnect( m_playlist.data(), SIGNAL( nextTrackReady() ) ); m_playlist.data()->reset(); } @@ -694,10 +694,10 @@ AudioEngine::setPlaylist( Tomahawk::playlistinterface_ptr playlist ) return; } - m_playlist = playlist.data()->getSharedPointer(); + m_playlist = playlist; - if ( m_playlist.data()->object() && m_playlist.data()->retryMode() == PlaylistInterface::Retry ) - connect( m_playlist.data()->object(), SIGNAL( nextTrackReady() ), SLOT( playlistNextTrackReady() ) ); + if ( !m_playlist.isNull() && m_playlist.data() && m_playlist.data()->retryMode() == PlaylistInterface::Retry ) + connect( m_playlist.data(), SIGNAL( nextTrackReady() ), SLOT( playlistNextTrackReady() ) ); emit playlistChanged( playlist ); } diff --git a/src/libtomahawk/audio/audioengine.h b/src/libtomahawk/audio/audioengine.h index c65ae3e5e..4b19a8c02 100644 --- a/src/libtomahawk/audio/audioengine.h +++ b/src/libtomahawk/audio/audioengine.h @@ -92,7 +92,7 @@ public slots: void playItem( Tomahawk::playlistinterface_ptr playlist, const Tomahawk::result_ptr& result ); void setPlaylist( Tomahawk::playlistinterface_ptr playlist ); - void setQueue( Tomahawk::playlistinterface_ptr queue ) { m_queue = queue.data()->getSharedPointer(); } + void setQueue( Tomahawk::playlistinterface_ptr queue ) { m_queue = queue; } void playlistNextTrackReady(); diff --git a/src/libtomahawk/playlist/albumproxymodel.cpp b/src/libtomahawk/playlist/albumproxymodel.cpp index e687a693c..125a81672 100644 --- a/src/libtomahawk/playlist/albumproxymodel.cpp +++ b/src/libtomahawk/playlist/albumproxymodel.cpp @@ -20,6 +20,7 @@ #include +#include "albumproxymodelplaylistinterface.h" #include "artist.h" #include "albumitem.h" #include "query.h" @@ -28,10 +29,7 @@ AlbumProxyModel::AlbumProxyModel( QObject* parent ) : QSortFilterProxyModel( parent ) - , PlaylistInterface( this ) , m_model( 0 ) - , m_repeatMode( PlaylistInterface::NoRepeat ) - , m_shuffled( false ) { setFilterCaseSensitivity( Qt::CaseInsensitive ); setSortCaseSensitivity( Qt::CaseInsensitive ); @@ -61,29 +59,6 @@ AlbumProxyModel::setSourceAlbumModel( AlbumModel* sourceModel ) QSortFilterProxyModel::setSourceModel( sourceModel ); } -QList< Tomahawk::query_ptr > -AlbumProxyModel::tracks() -{ - Q_ASSERT( FALSE ); - QList queries; - return queries; -} - -Tomahawk::result_ptr -AlbumProxyModel::currentItem() const -{ - return Tomahawk::result_ptr(); -} - -void -AlbumProxyModel::setFilter( const QString& pattern ) -{ - qDebug() << Q_FUNC_INFO; - setFilterRegExp( pattern ); - - emit filterChanged( pattern ); -} - bool AlbumProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const @@ -165,10 +140,13 @@ AlbumProxyModel::removeIndexes( const QList& indexes ) } -Tomahawk::result_ptr -AlbumProxyModel::siblingItem( int itemsAway ) +Tomahawk::playlistinterface_ptr +AlbumProxyModel::getPlaylistInterface() { - Q_UNUSED( itemsAway ); - qDebug() << Q_FUNC_INFO; - return Tomahawk::result_ptr( 0 ); + if ( m_playlistInterface.isNull() ) + { + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::AlbumProxyModelPlaylistInterface( this ) ); + } + + return m_playlistInterface; } diff --git a/src/libtomahawk/playlist/albumproxymodel.h b/src/libtomahawk/playlist/albumproxymodel.h index 17c9383fb..9e8cc566d 100644 --- a/src/libtomahawk/playlist/albumproxymodel.h +++ b/src/libtomahawk/playlist/albumproxymodel.h @@ -26,7 +26,7 @@ #include "dllmacro.h" -class DLLEXPORT AlbumProxyModel : public QSortFilterProxyModel, public Tomahawk::PlaylistInterface +class DLLEXPORT AlbumProxyModel : public QSortFilterProxyModel { Q_OBJECT @@ -38,48 +38,26 @@ public: virtual void setSourceAlbumModel( AlbumModel* sourceModel ); virtual void setSourceModel( QAbstractItemModel* sourceModel ); - virtual QList tracks(); - - virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); } - virtual int trackCount() const { return rowCount( QModelIndex() ); } virtual int albumCount() const { return rowCount( QModelIndex() ); } virtual void removeIndex( const QModelIndex& index ); virtual void removeIndexes( const QList& indexes ); - virtual bool hasNextItem() { return true; } - virtual Tomahawk::result_ptr currentItem() const; - virtual Tomahawk::result_ptr siblingItem( int direction ); + virtual void emitFilterChanged( const QString &pattern ) { emit filterChanged( pattern ); } - virtual void setFilter( const QString& pattern ); - - virtual Tomahawk::PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; } - virtual bool shuffled() const { return m_shuffled; } - virtual Tomahawk::PlaylistInterface::ViewMode viewMode() const { return Tomahawk::PlaylistInterface::Album; } + virtual Tomahawk::playlistinterface_ptr getPlaylistInterface(); signals: - void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); - void shuffleModeChanged( bool enabled ); - - void trackCountChanged( unsigned int tracks ); - void sourceTrackCountChanged( unsigned int tracks ); - void filterChanged( const QString& filter ); - void nextTrackReady(); - -public slots: - virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); } - virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); } - protected: bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; bool lessThan( const QModelIndex& left, const QModelIndex& right ) const; private: AlbumModel* m_model; - RepeatMode m_repeatMode; - bool m_shuffled; + + Tomahawk::playlistinterface_ptr m_playlistInterface; }; #endif // ALBUMPROXYMODEL_H diff --git a/src/libtomahawk/playlist/albumproxymodelplaylistinterface.cpp b/src/libtomahawk/playlist/albumproxymodelplaylistinterface.cpp new file mode 100644 index 000000000..892abb3fc --- /dev/null +++ b/src/libtomahawk/playlist/albumproxymodelplaylistinterface.cpp @@ -0,0 +1,100 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "albumproxymodelplaylistinterface.h" + +#include "albumproxymodel.h" +#include "artist.h" +#include "albumitem.h" +#include "query.h" +#include "utils/logger.h" + +using namespace Tomahawk; + +AlbumProxyModelPlaylistInterface::AlbumProxyModelPlaylistInterface( AlbumProxyModel *proxyModel ) + : Tomahawk::PlaylistInterface() + , m_proxyModel( proxyModel ) + , m_repeatMode( PlaylistInterface::NoRepeat ) + , m_shuffled( false ) +{ +} + + +AlbumProxyModelPlaylistInterface::~AlbumProxyModelPlaylistInterface() +{ + m_proxyModel.clear(); +} + + +QList< Tomahawk::query_ptr > +AlbumProxyModelPlaylistInterface::tracks() +{ + Q_ASSERT( FALSE ); + QList queries; + return queries; +} + + +int +AlbumProxyModelPlaylistInterface::unfilteredTrackCount() const +{ + return ( m_proxyModel.isNull() ? 0 : m_proxyModel.data()->sourceModel()->rowCount( QModelIndex() ) ); +} + + +int +AlbumProxyModelPlaylistInterface::trackCount() const +{ + return ( m_proxyModel.isNull() ? 0 : m_proxyModel.data()->rowCount( QModelIndex() ) ); +} + + +Tomahawk::result_ptr +AlbumProxyModelPlaylistInterface::currentItem() const +{ + return Tomahawk::result_ptr(); +} + + +QString +AlbumProxyModelPlaylistInterface::filter() const +{ + return ( m_proxyModel.isNull() ? QString() : m_proxyModel.data()->filterRegExp().pattern() ); +} + + +void +AlbumProxyModelPlaylistInterface::setFilter( const QString& pattern ) +{ + qDebug() << Q_FUNC_INFO; + + if ( m_proxyModel.isNull() ) + return; + + m_proxyModel.data()->setFilterRegExp( pattern ); + m_proxyModel.data()->emitFilterChanged( pattern ); +} + + +Tomahawk::result_ptr +AlbumProxyModelPlaylistInterface::siblingItem( int itemsAway ) +{ + Q_UNUSED( itemsAway ); + qDebug() << Q_FUNC_INFO; + return Tomahawk::result_ptr( 0 ); +} diff --git a/src/libtomahawk/playlist/albumproxymodelplaylistinterface.h b/src/libtomahawk/playlist/albumproxymodelplaylistinterface.h new file mode 100644 index 000000000..01e34cdc4 --- /dev/null +++ b/src/libtomahawk/playlist/albumproxymodelplaylistinterface.h @@ -0,0 +1,77 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef ALBUMPROXYMODELPLAYLISTINTERFACE_H +#define ALBUMPROXYMODELPLAYLISTINTERFACE_H + +#include "playlistinterface.h" +#include "playlist/albummodel.h" + +#include "dllmacro.h" + +class AlbumProxyModel; + +namespace Tomahawk +{ + +class DLLEXPORT AlbumProxyModelPlaylistInterface : public Tomahawk::PlaylistInterface +{ +Q_OBJECT + +public: + explicit AlbumProxyModelPlaylistInterface( AlbumProxyModel *proxyModel ); + virtual ~AlbumProxyModelPlaylistInterface(); + + virtual QList tracks(); + + virtual int unfilteredTrackCount() const; + virtual int trackCount() const; + + virtual bool hasNextItem() { return true; } + virtual Tomahawk::result_ptr currentItem() const; + virtual Tomahawk::result_ptr siblingItem( int direction ); + + virtual QString filter() const; + virtual void setFilter( const QString& pattern ); + + virtual Tomahawk::PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; } + virtual bool shuffled() const { return m_shuffled; } + virtual Tomahawk::PlaylistInterface::ViewMode viewMode() const { return Tomahawk::PlaylistInterface::Album; } + +signals: + void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + + void nextTrackReady(); + +public slots: + virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); } + virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); } + +private: + QWeakPointer< AlbumProxyModel > m_proxyModel; + RepeatMode m_repeatMode; + bool m_shuffled; +}; + +} //ns + +#endif // ALBUMPROXYMODELPLAYLISTINTERFACE_H diff --git a/src/libtomahawk/playlist/albumview.h b/src/libtomahawk/playlist/albumview.h index 84ad7d1f2..993a2fea7 100644 --- a/src/libtomahawk/playlist/albumview.h +++ b/src/libtomahawk/playlist/albumview.h @@ -53,7 +53,7 @@ public: void setModel( QAbstractItemModel* model ); virtual QWidget* widget() { return this; } - virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getSharedPointer(); } + virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getPlaylistInterface(); } virtual QString title() const { return m_model->title(); } virtual QString description() const { return m_model->description(); } diff --git a/src/libtomahawk/playlist/artistview.cpp b/src/libtomahawk/playlist/artistview.cpp index 029de502f..929905f39 100644 --- a/src/libtomahawk/playlist/artistview.cpp +++ b/src/libtomahawk/playlist/artistview.cpp @@ -188,7 +188,7 @@ ArtistView::onItemActivated( const QModelIndex& index ) else if ( !item->result().isNull() && item->result()->isOnline() ) { m_model->setCurrentItem( item->index ); - AudioEngine::instance()->playItem( m_proxyModel->getSharedPointer(), item->result() ); + AudioEngine::instance()->playItem( m_proxyModel->getPlaylistInterface(), item->result() ); } } } @@ -248,9 +248,9 @@ ArtistView::onFilterChanged( const QString& ) if ( selectedIndexes().count() ) scrollTo( selectedIndexes().at( 0 ), QAbstractItemView::PositionAtCenter ); - if ( !proxyModel()->filter().isEmpty() && !proxyModel()->trackCount() && model()->trackCount() ) + if ( !proxyModel()->getPlaylistInterface()->filter().isEmpty() && !proxyModel()->getPlaylistInterface()->trackCount() && model()->trackCount() ) { - m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->filter() ) ); + m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->getPlaylistInterface()->filter() ) ); m_overlay->show(); } else @@ -332,7 +332,7 @@ ArtistView::onScrollTimeout() while ( right.isValid() && right.parent().isValid() ) right = right.parent(); - int max = m_proxyModel->trackCount(); + int max = m_proxyModel->getPlaylistInterface()->trackCount(); if ( right.isValid() ) max = right.row() + 1; diff --git a/src/libtomahawk/playlist/artistview.h b/src/libtomahawk/playlist/artistview.h index 65fb145e8..e67ef37c3 100644 --- a/src/libtomahawk/playlist/artistview.h +++ b/src/libtomahawk/playlist/artistview.h @@ -62,7 +62,7 @@ public: void setTreeModel( TreeModel* model ); virtual QWidget* widget() { return this; } - virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getSharedPointer(); } + virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getPlaylistInterface(); } virtual QString title() const { return m_model->title(); } virtual QString description() const { return m_model->description(); } diff --git a/src/libtomahawk/playlist/collectionproxymodel.cpp b/src/libtomahawk/playlist/collectionproxymodel.cpp index dc050511c..1f5df9c7d 100644 --- a/src/libtomahawk/playlist/collectionproxymodel.cpp +++ b/src/libtomahawk/playlist/collectionproxymodel.cpp @@ -18,6 +18,8 @@ #include "collectionproxymodel.h" +#include "collectionproxymodelplaylistinterface.h" + #include #include "album.h" @@ -29,3 +31,14 @@ CollectionProxyModel::CollectionProxyModel( QObject* parent ) : TrackProxyModel( parent ) { } + +Tomahawk::playlistinterface_ptr +CollectionProxyModel::getPlaylistInterface() +{ + if ( m_playlistInterface.isNull() ) + { + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::CollectionProxyModelPlaylistInterface( this ) ); + } + + return m_playlistInterface; +} diff --git a/src/libtomahawk/playlist/collectionproxymodel.h b/src/libtomahawk/playlist/collectionproxymodel.h index 61abd3df4..898f05095 100644 --- a/src/libtomahawk/playlist/collectionproxymodel.h +++ b/src/libtomahawk/playlist/collectionproxymodel.h @@ -20,6 +20,7 @@ #define COLLECTIONPROXYMODEL_H #include "trackproxymodel.h" +#include "trackproxymodelplaylistinterface.h" #include "dllmacro.h" @@ -29,8 +30,10 @@ Q_OBJECT public: explicit CollectionProxyModel( QObject* parent = 0 ); + virtual ~CollectionProxyModel() {} + + virtual Tomahawk::playlistinterface_ptr getPlaylistInterface(); - virtual PlaylistInterface::ViewMode viewMode() const { return PlaylistInterface::Flat; } }; #endif // COLLECTIONPROXYMODEL_H diff --git a/src/libtomahawk/playlist/collectionproxymodelplaylistinterface.cpp b/src/libtomahawk/playlist/collectionproxymodelplaylistinterface.cpp new file mode 100644 index 000000000..d2e67c9f1 --- /dev/null +++ b/src/libtomahawk/playlist/collectionproxymodelplaylistinterface.cpp @@ -0,0 +1,36 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "collectionproxymodelplaylistinterface.h" + +#include "collectionproxymodel.h" +#include "album.h" +#include "query.h" +#include "utils/logger.h" + +using namespace Tomahawk; + +CollectionProxyModelPlaylistInterface::CollectionProxyModelPlaylistInterface( CollectionProxyModel *proxyModel ) + : TrackProxyModelPlaylistInterface( proxyModel ) +{ +} + +CollectionProxyModelPlaylistInterface::~CollectionProxyModelPlaylistInterface() +{ + m_proxyModel.clear(); +} diff --git a/src/libtomahawk/playlist/collectionproxymodelplaylistinterface.h b/src/libtomahawk/playlist/collectionproxymodelplaylistinterface.h new file mode 100644 index 000000000..008373867 --- /dev/null +++ b/src/libtomahawk/playlist/collectionproxymodelplaylistinterface.h @@ -0,0 +1,45 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef COLLECTIONPROXYMODELPLAYLISTINTERFACE_H +#define COLLECTIONPROXYMODELPLAYLISTINTERFACE_H + +#include "trackproxymodel.h" +#include "trackproxymodelplaylistinterface.h" + +#include "dllmacro.h" + +class CollectionProxyModel; + +namespace Tomahawk +{ + +class DLLEXPORT CollectionProxyModelPlaylistInterface : public TrackProxyModelPlaylistInterface +{ +Q_OBJECT + +public: + explicit CollectionProxyModelPlaylistInterface( CollectionProxyModel* proxyModel ); + virtual ~CollectionProxyModelPlaylistInterface(); + + virtual PlaylistInterface::ViewMode viewMode() const { return PlaylistInterface::Flat; } +}; + +} //ns + +#endif // COLLECTIONPROXYMODELPLAYLISTINTERFACE_H diff --git a/src/libtomahawk/playlist/collectionview.h b/src/libtomahawk/playlist/collectionview.h index 867fb7431..ff7471e97 100644 --- a/src/libtomahawk/playlist/collectionview.h +++ b/src/libtomahawk/playlist/collectionview.h @@ -39,7 +39,7 @@ public: virtual void setModel( QAbstractItemModel* model ); virtual QWidget* widget() { return this; } - virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getSharedPointer(); } + virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getPlaylistInterface(); } virtual QString title() const { return model()->title(); } virtual QString description() const { return model()->description(); } diff --git a/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.cpp b/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.cpp index d9381d096..2cf47020f 100644 --- a/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.cpp +++ b/src/libtomahawk/playlist/dynamic/widgets/DynamicWidget.cpp @@ -203,7 +203,7 @@ DynamicWidget::onRevisionLoaded( const Tomahawk::DynamicPlaylistRevision& rev ) Tomahawk::playlistinterface_ptr DynamicWidget::playlistInterface() const { - return m_view->proxyModel()->getSharedPointer(); + return m_view->proxyModel()->getPlaylistInterface(); } @@ -243,7 +243,7 @@ DynamicWidget::layoutFloatingWidgets() void DynamicWidget::playlistChanged( Tomahawk::playlistinterface_ptr pl ) { - if( pl == m_view->proxyModel()->getSharedPointer() ) { // same playlist + if( pl == m_view->proxyModel()->getPlaylistInterface() ) { // same playlist m_activePlaylist = true; } else { m_activePlaylist = false; diff --git a/src/libtomahawk/playlist/playlistproxymodel.cpp b/src/libtomahawk/playlist/playlistproxymodel.cpp index 45c234980..ded13bd95 100644 --- a/src/libtomahawk/playlist/playlistproxymodel.cpp +++ b/src/libtomahawk/playlist/playlistproxymodel.cpp @@ -18,6 +18,7 @@ #include "playlistproxymodel.h" +#include "playlistproxymodelplaylistinterface.h" #include "utils/logger.h" @@ -25,3 +26,14 @@ PlaylistProxyModel::PlaylistProxyModel( QObject* parent ) : TrackProxyModel( parent ) { } + +Tomahawk::playlistinterface_ptr +PlaylistProxyModel::getPlaylistInterface() +{ + if ( m_playlistInterface.isNull() ) + { + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::PlaylistProxyModelPlaylistInterface( this ) ); + } + + return m_playlistInterface; +} diff --git a/src/libtomahawk/playlist/playlistproxymodel.h b/src/libtomahawk/playlist/playlistproxymodel.h index 01660d388..b7e1610db 100644 --- a/src/libtomahawk/playlist/playlistproxymodel.h +++ b/src/libtomahawk/playlist/playlistproxymodel.h @@ -1,5 +1,5 @@ /* === This file is part of Tomahawk Player - === - * + * * Copyright 2010-2011, Christian Muehlhaeuser * * Tomahawk is free software: you can redistribute it and/or modify @@ -30,6 +30,8 @@ Q_OBJECT public: explicit PlaylistProxyModel( QObject* parent = 0 ); virtual ~PlaylistProxyModel() {} + + virtual Tomahawk::playlistinterface_ptr getPlaylistInterface(); }; #endif // PLAYLISTPROXYMODEL_H diff --git a/src/libtomahawk/playlist/playlistproxymodelplaylistinterface.cpp b/src/libtomahawk/playlist/playlistproxymodelplaylistinterface.cpp new file mode 100644 index 000000000..e3b165a7f --- /dev/null +++ b/src/libtomahawk/playlist/playlistproxymodelplaylistinterface.cpp @@ -0,0 +1,34 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "playlistproxymodelplaylistinterface.h" + +#include "playlistproxymodel.h" +#include "utils/logger.h" + +using namespace Tomahawk; + +PlaylistProxyModelPlaylistInterface::PlaylistProxyModelPlaylistInterface( PlaylistProxyModel *proxyModel ) + : TrackProxyModelPlaylistInterface( proxyModel ) +{ +} + +PlaylistProxyModelPlaylistInterface::~PlaylistProxyModelPlaylistInterface() +{ + m_proxyModel.clear(); +} diff --git a/src/libtomahawk/playlist/playlistproxymodelplaylistinterface.h b/src/libtomahawk/playlist/playlistproxymodelplaylistinterface.h new file mode 100644 index 000000000..4f10c155a --- /dev/null +++ b/src/libtomahawk/playlist/playlistproxymodelplaylistinterface.h @@ -0,0 +1,42 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef PLAYLISTPROXYMODELPLAYLISTINTERFACE_H +#define PLAYLISTPROXYMODELPLAYLISTINTERFACE_H + +#include "trackproxymodelplaylistinterface.h" + +#include "dllmacro.h" + +class PlaylistProxyModel; + +namespace Tomahawk +{ + +class DLLEXPORT PlaylistProxyModelPlaylistInterface : public TrackProxyModelPlaylistInterface +{ +Q_OBJECT + +public: + explicit PlaylistProxyModelPlaylistInterface( PlaylistProxyModel *proxyModel ); + virtual ~PlaylistProxyModelPlaylistInterface(); +}; + +} //ns + +#endif // PLAYLISTPROXYMODELPLAYLISTINTERFACE_H diff --git a/src/libtomahawk/playlist/playlistview.h b/src/libtomahawk/playlist/playlistview.h index f9d76e00a..f89836fc3 100644 --- a/src/libtomahawk/playlist/playlistview.h +++ b/src/libtomahawk/playlist/playlistview.h @@ -38,7 +38,7 @@ public: virtual void setModel( QAbstractItemModel* model ); virtual QWidget* widget() { return this; } - virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getSharedPointer(); } + virtual Tomahawk::playlistinterface_ptr playlistInterface() const { return proxyModel()->getPlaylistInterface(); } virtual bool showFilter() const { return true; } diff --git a/src/libtomahawk/playlist/queueproxymodel.cpp b/src/libtomahawk/playlist/queueproxymodel.cpp index 88129a57b..8deab2696 100644 --- a/src/libtomahawk/playlist/queueproxymodel.cpp +++ b/src/libtomahawk/playlist/queueproxymodel.cpp @@ -18,6 +18,7 @@ #include "queueproxymodel.h" +#include "queueproxymodelplaylistinterface.h" #include "playlist/trackview.h" #include "viewmanager.h" #include "utils/logger.h" @@ -48,21 +49,21 @@ QueueProxyModel::onIndexActivated( const QModelIndex& index ) } -Tomahawk::result_ptr -QueueProxyModel::siblingItem( int itemsAway ) -{ - setCurrentIndex( QModelIndex() ); - Tomahawk::result_ptr res = PlaylistProxyModel::siblingItem( itemsAway ); - - remove( currentIndex() ); - - return res; -} - - void QueueProxyModel::onTrackCountChanged( unsigned int count ) { if ( count == 0 ) ViewManager::instance()->hideQueue(); } + + +Tomahawk::playlistinterface_ptr +QueueProxyModel::getPlaylistInterface() +{ + if ( m_playlistInterface.isNull() ) + { + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::QueueProxyModelPlaylistInterface( this ) ); + } + + return m_playlistInterface; +} diff --git a/src/libtomahawk/playlist/queueproxymodel.h b/src/libtomahawk/playlist/queueproxymodel.h index d9368648d..5197d443a 100644 --- a/src/libtomahawk/playlist/queueproxymodel.h +++ b/src/libtomahawk/playlist/queueproxymodel.h @@ -32,11 +32,9 @@ Q_OBJECT public: explicit QueueProxyModel( TrackView* parent = 0 ); - ~QueueProxyModel(); + virtual ~QueueProxyModel(); - virtual Tomahawk::result_ptr siblingItem( int itemsAway ); - - using PlaylistProxyModel::siblingItem; + virtual Tomahawk::playlistinterface_ptr getPlaylistInterface(); private slots: void onIndexActivated( const QModelIndex& index ); diff --git a/src/libtomahawk/playlist/queueproxymodelplaylistinterface.cpp b/src/libtomahawk/playlist/queueproxymodelplaylistinterface.cpp new file mode 100644 index 000000000..6b1c86cf8 --- /dev/null +++ b/src/libtomahawk/playlist/queueproxymodelplaylistinterface.cpp @@ -0,0 +1,50 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "queueproxymodelplaylistinterface.h" + +#include "queueproxymodel.h" +#include "utils/logger.h" + +using namespace Tomahawk; + +QueueProxyModelPlaylistInterface::QueueProxyModelPlaylistInterface( QueueProxyModel *proxyModel ) + : PlaylistProxyModelPlaylistInterface( proxyModel ) +{ +} + + +QueueProxyModelPlaylistInterface::~QueueProxyModelPlaylistInterface() +{ + m_proxyModel.clear(); +} + + +Tomahawk::result_ptr +QueueProxyModelPlaylistInterface::siblingItem( int itemsAway ) +{ + if ( m_proxyModel.isNull() ) + return Tomahawk::result_ptr(); + + m_proxyModel.data()->setCurrentIndex( QModelIndex() ); + Tomahawk::result_ptr res = PlaylistProxyModelPlaylistInterface::siblingItem( itemsAway ); + + m_proxyModel.data()->remove( m_proxyModel.data()->currentIndex() ); + + return res; +} diff --git a/src/libtomahawk/playlist/queueproxymodelplaylistinterface.h b/src/libtomahawk/playlist/queueproxymodelplaylistinterface.h new file mode 100644 index 000000000..85c9101c6 --- /dev/null +++ b/src/libtomahawk/playlist/queueproxymodelplaylistinterface.h @@ -0,0 +1,44 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef QUEUEPROXYMODELPLAYLISTINTERFACE_H +#define QUEUEPROXYMODELPLAYLISTINTERFACE_H + +#include "playlistproxymodelplaylistinterface.h" + +#include "dllmacro.h" + +class QueueProxyModel; + +namespace Tomahawk +{ + +class DLLEXPORT QueueProxyModelPlaylistInterface : public PlaylistProxyModelPlaylistInterface +{ +Q_OBJECT + +public: + explicit QueueProxyModelPlaylistInterface( QueueProxyModel *proxyModel ); + virtual ~QueueProxyModelPlaylistInterface(); + + virtual Tomahawk::result_ptr siblingItem( int itemsAway ); +}; + +} //ns + +#endif // QUEUEPROXYMODELPLAYLISTINTERFACE_H diff --git a/src/libtomahawk/playlist/trackproxymodel.cpp b/src/libtomahawk/playlist/trackproxymodel.cpp index e2753a04f..ed3ba8354 100644 --- a/src/libtomahawk/playlist/trackproxymodel.cpp +++ b/src/libtomahawk/playlist/trackproxymodel.cpp @@ -20,6 +20,7 @@ #include +#include "trackproxymodelplaylistinterface.h" #include "artist.h" #include "album.h" #include "query.h" @@ -28,10 +29,7 @@ TrackProxyModel::TrackProxyModel( QObject* parent ) : QSortFilterProxyModel( parent ) - , PlaylistInterface( this ) , m_model( 0 ) - , m_repeatMode( PlaylistInterface::NoRepeat ) - , m_shuffled( false ) , m_showOfflineResults( true ) { setFilterCaseSensitivity( Qt::CaseInsensitive ); @@ -63,120 +61,6 @@ TrackProxyModel::setSourceTrackModel( TrackModel* sourceModel ) } -void -TrackProxyModel::setFilter( const QString& pattern ) -{ - PlaylistInterface::setFilter( pattern ); - setFilterRegExp( pattern ); - - emit filterChanged( pattern ); - emit trackCountChanged( trackCount() ); -} - - -QList< Tomahawk::query_ptr > -TrackProxyModel::tracks() -{ - QList queries; - - for ( int i = 0; i < rowCount( QModelIndex() ); i++ ) - { - TrackModelItem* item = itemFromIndex( mapToSource( index( i, 0 ) ) ); - if ( item ) - queries << item->query(); - } - - return queries; -} - - -Tomahawk::result_ptr -TrackProxyModel::siblingItem( int itemsAway ) -{ - return siblingItem( itemsAway, false ); -} - - -bool -TrackProxyModel::hasNextItem() -{ - return !( siblingItem( 1, true ).isNull() ); -} - - -Tomahawk::result_ptr -TrackProxyModel::siblingItem( int itemsAway, bool readOnly ) -{ - qDebug() << Q_FUNC_INFO; - - QModelIndex idx = index( 0, 0 ); - if ( rowCount() ) - { - if ( m_shuffled ) - { - // random mode is enabled - // TODO come up with a clever random logic, that keeps track of previously played items - idx = index( qrand() % rowCount(), 0 ); - } - else if ( currentIndex().isValid() ) - { - idx = currentIndex(); - - // random mode is disabled - if ( m_repeatMode != PlaylistInterface::RepeatOne ) - { - // keep progressing through the playlist normally - idx = index( idx.row() + itemsAway, 0 ); - } - } - } - - if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll ) - { - // repeat all tracks - if ( itemsAway > 0 ) - { - // reset to first item - idx = index( 0, 0 ); - } - else - { - // reset to last item - idx = index( rowCount() - 1, 0 ); - } - } - - // Try to find the next available PlaylistItem (with results) - while ( idx.isValid() ) - { - TrackModelItem* item = itemFromIndex( mapToSource( idx ) ); - if ( item && item->query()->playable() ) - { - qDebug() << "Next PlaylistItem found:" << item->query()->toString() << item->query()->results().at( 0 )->url(); - if ( !readOnly ) - setCurrentIndex( idx ); - return item->query()->results().at( 0 ); - } - - idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0 ); - } - - if ( !readOnly ) - setCurrentIndex( QModelIndex() ); - return Tomahawk::result_ptr(); -} - - -Tomahawk::result_ptr -TrackProxyModel::currentItem() const -{ - TrackModelItem* item = itemFromIndex( mapToSource( currentIndex() ) ); - if ( item && !item->query().isNull() && item->query()->playable() ) - return item->query()->results().at( 0 ); - return Tomahawk::result_ptr(); -} - - bool TrackProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const { @@ -388,3 +272,15 @@ TrackProxyModel::lessThan( const QModelIndex& left, const QModelIndex& right ) c return QString::localeAwareCompare( lefts, rights ) < 0; } + + +Tomahawk::playlistinterface_ptr +TrackProxyModel::getPlaylistInterface() +{ + if ( m_playlistInterface.isNull() ) + { + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::TrackProxyModelPlaylistInterface( this ) ); + } + + return m_playlistInterface; +} diff --git a/src/libtomahawk/playlist/trackproxymodel.h b/src/libtomahawk/playlist/trackproxymodel.h index bf592c5ee..18f3a127a 100644 --- a/src/libtomahawk/playlist/trackproxymodel.h +++ b/src/libtomahawk/playlist/trackproxymodel.h @@ -26,14 +26,14 @@ #include "dllmacro.h" -class DLLEXPORT TrackProxyModel : public QSortFilterProxyModel, public Tomahawk::PlaylistInterface +class DLLEXPORT TrackProxyModel : public QSortFilterProxyModel { Q_OBJECT public: explicit TrackProxyModel ( QObject* parent = 0 ); virtual ~TrackProxyModel() {} - + virtual TrackModel* sourceModel() const { return m_model; } virtual void setSourceTrackModel( TrackModel* sourceModel ); virtual void setSourceModel( QAbstractItemModel* model ); @@ -41,55 +41,29 @@ public: virtual QPersistentModelIndex currentIndex() const { return mapFromSource( m_model->currentItem() ); } virtual void setCurrentIndex( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); } - virtual QList tracks(); - - virtual int unfilteredTrackCount() const { return sourceModel()->trackCount(); } - virtual int trackCount() const { return rowCount( QModelIndex() ); } - virtual void remove( const QModelIndex& index ); virtual void remove( const QModelIndexList& indexes ); virtual void remove( const QList< QPersistentModelIndex >& indexes ); - virtual Tomahawk::result_ptr currentItem() const; - virtual Tomahawk::result_ptr siblingItem( int itemsAway ); - virtual Tomahawk::result_ptr siblingItem( int itemsAway, bool readOnly ); - virtual bool hasNextItem(); + virtual bool showOfflineResults() const { return m_showOfflineResults; } + virtual void setShowOfflineResults( bool b ) { m_showOfflineResults = b; } - virtual QString filter() const { return filterRegExp().pattern(); } - virtual void setFilter( const QString& pattern ); + virtual void emitFilterChanged( const QString &pattern ) { emit filterChanged( pattern ); } - virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; } - virtual bool shuffled() const { return m_shuffled; } + virtual TrackModelItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); } - bool showOfflineResults() const { return m_showOfflineResults; } - void setShowOfflineResults( bool b ) { m_showOfflineResults = b; } - - TrackModelItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); } + virtual Tomahawk::playlistinterface_ptr getPlaylistInterface(); signals: - void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); - void shuffleModeChanged( bool enabled ); - - void trackCountChanged( unsigned int tracks ); - void sourceTrackCountChanged( unsigned int tracks ); - void filterChanged( const QString& filter ); - void nextTrackReady(); - -public slots: - virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); } - virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); } - protected: - bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; - bool lessThan( const QModelIndex& left, const QModelIndex& right ) const; + virtual bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; + virtual bool lessThan( const QModelIndex& left, const QModelIndex& right ) const; -private: TrackModel* m_model; - RepeatMode m_repeatMode; - bool m_shuffled; bool m_showOfflineResults; + Tomahawk::playlistinterface_ptr m_playlistInterface; }; #endif // TRACKPROXYMODEL_H diff --git a/src/libtomahawk/playlist/trackproxymodelplaylistinterface.cpp b/src/libtomahawk/playlist/trackproxymodelplaylistinterface.cpp new file mode 100644 index 000000000..cceb60ed1 --- /dev/null +++ b/src/libtomahawk/playlist/trackproxymodelplaylistinterface.cpp @@ -0,0 +1,193 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "trackproxymodelplaylistinterface.h" + +#include "trackproxymodel.h" +#include "artist.h" +#include "album.h" +#include "query.h" +#include "utils/logger.h" + +using namespace Tomahawk; + +TrackProxyModelPlaylistInterface::TrackProxyModelPlaylistInterface( TrackProxyModel* proxyModel ) + : PlaylistInterface() + , m_proxyModel( proxyModel ) + , m_repeatMode( PlaylistInterface::NoRepeat ) + , m_shuffled( false ) +{ +} + + +TrackProxyModelPlaylistInterface::~TrackProxyModelPlaylistInterface() +{ + m_proxyModel.clear(); +} + + +int +TrackProxyModelPlaylistInterface::unfilteredTrackCount() const +{ + return ( m_proxyModel.isNull() ? 0 : m_proxyModel.data()->sourceModel()->trackCount() ); +} + + +int +TrackProxyModelPlaylistInterface::trackCount() const +{ + return ( m_proxyModel.isNull() ? 0 : m_proxyModel.data()->rowCount( QModelIndex() ) ); +} + + +QString +TrackProxyModelPlaylistInterface::filter() const +{ + return ( m_proxyModel.isNull() ? QString() : m_proxyModel.data()->filterRegExp().pattern() ); +} + + +void +TrackProxyModelPlaylistInterface::setFilter( const QString& pattern ) +{ + if ( m_proxyModel.isNull() ) + return; + + m_proxyModel.data()->setFilterRegExp( pattern ); + m_proxyModel.data()->emitFilterChanged( pattern ); + + emit trackCountChanged( trackCount() ); +} + + +QList< Tomahawk::query_ptr > +TrackProxyModelPlaylistInterface::tracks() +{ + if ( m_proxyModel.isNull() ) + return QList< Tomahawk::query_ptr >(); + + TrackProxyModel* proxyModel = m_proxyModel.data(); + QList queries; + + for ( int i = 0; i < proxyModel->rowCount( QModelIndex() ); i++ ) + { + TrackModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->index( i, 0 ) ) ); + if ( item ) + queries << item->query(); + } + + return queries; +} + + +Tomahawk::result_ptr +TrackProxyModelPlaylistInterface::siblingItem( int itemsAway ) +{ + return siblingItem( itemsAway, false ); +} + + +bool +TrackProxyModelPlaylistInterface::hasNextItem() +{ + return !( siblingItem( 1, true ).isNull() ); +} + + +Tomahawk::result_ptr +TrackProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly ) +{ + qDebug() << Q_FUNC_INFO; + + if ( m_proxyModel.isNull() ) + return Tomahawk::result_ptr(); + + TrackProxyModel* proxyModel = m_proxyModel.data(); + + QModelIndex idx = proxyModel->index( 0, 0 ); + if ( proxyModel->rowCount() ) + { + if ( m_shuffled ) + { + // random mode is enabled + // TODO come up with a clever random logic, that keeps track of previously played items + idx = proxyModel->index( qrand() % proxyModel->rowCount(), 0 ); + } + else if ( proxyModel->currentIndex().isValid() ) + { + idx = proxyModel->currentIndex(); + + // random mode is disabled + if ( m_repeatMode != PlaylistInterface::RepeatOne ) + { + // keep progressing through the playlist normally + idx = proxyModel->index( idx.row() + itemsAway, 0 ); + } + } + } + + if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll ) + { + // repeat all tracks + if ( itemsAway > 0 ) + { + // reset to first item + idx = proxyModel->index( 0, 0 ); + } + else + { + // reset to last item + idx = proxyModel->index( proxyModel->rowCount() - 1, 0 ); + } + } + + // Try to find the next available PlaylistItem (with results) + while ( idx.isValid() ) + { + TrackModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) ); + if ( item && item->query()->playable() ) + { + qDebug() << "Next PlaylistItem found:" << item->query()->toString() << item->query()->results().at( 0 )->url(); + if ( !readOnly ) + proxyModel->setCurrentIndex( idx ); + return item->query()->results().at( 0 ); + } + + idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0 ); + } + + if ( !readOnly ) + proxyModel->setCurrentIndex( QModelIndex() ); + return Tomahawk::result_ptr(); +} + + +Tomahawk::result_ptr +TrackProxyModelPlaylistInterface::currentItem() const +{ + if ( m_proxyModel.isNull() ) + return Tomahawk::result_ptr(); + + TrackProxyModel* proxyModel = m_proxyModel.data(); + + TrackModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->currentIndex() ) ); + if ( item && !item->query().isNull() && item->query()->playable() ) + return item->query()->results().at( 0 ); + return Tomahawk::result_ptr(); +} + diff --git a/src/libtomahawk/playlist/trackproxymodelplaylistinterface.h b/src/libtomahawk/playlist/trackproxymodelplaylistinterface.h new file mode 100644 index 000000000..37cc4effe --- /dev/null +++ b/src/libtomahawk/playlist/trackproxymodelplaylistinterface.h @@ -0,0 +1,78 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef TRACKPROXYMODELPLAYLISTINTERFACE_H +#define TRACKPROXYMODELPLAYLISTINTERFACE_H + +#include + +#include "playlistinterface.h" +#include "playlist/trackmodel.h" + +#include "dllmacro.h" + +class TrackProxyModel; + +namespace Tomahawk { + +class DLLEXPORT TrackProxyModelPlaylistInterface : public Tomahawk::PlaylistInterface +{ +Q_OBJECT + +public: + explicit TrackProxyModelPlaylistInterface( TrackProxyModel* proxyModel ); + virtual ~TrackProxyModelPlaylistInterface(); + + virtual QList tracks(); + + virtual int unfilteredTrackCount() const; + virtual int trackCount() const; + + virtual Tomahawk::result_ptr currentItem() const; + virtual Tomahawk::result_ptr siblingItem( int itemsAway ); + virtual Tomahawk::result_ptr siblingItem( int itemsAway, bool readOnly ); + virtual bool hasNextItem(); + + virtual QString filter() const; + virtual void setFilter( const QString& pattern ); + + virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; } + virtual bool shuffled() const { return m_shuffled; } + +signals: + void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + + void nextTrackReady(); + +public slots: + virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); } + virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); } + +protected: + QWeakPointer< TrackProxyModel > m_proxyModel; + RepeatMode m_repeatMode; + bool m_shuffled; +}; + +} //ns + +#endif // TRACKPROXYMODELPLAYLISTINTERFACE_H diff --git a/src/libtomahawk/playlist/trackview.cpp b/src/libtomahawk/playlist/trackview.cpp index 4b5a028b0..0bbdcd5fe 100644 --- a/src/libtomahawk/playlist/trackview.cpp +++ b/src/libtomahawk/playlist/trackview.cpp @@ -182,7 +182,7 @@ TrackView::onItemActivated( const QModelIndex& index ) { tDebug() << "Result activated:" << item->query()->toString() << item->query()->results().first()->url(); m_proxyModel->setCurrentIndex( index ); - AudioEngine::instance()->playItem( m_proxyModel->getSharedPointer(), item->query()->results().first() ); + AudioEngine::instance()->playItem( m_proxyModel->getPlaylistInterface(), item->query()->results().first() ); } emit itemActivated( index ); @@ -369,9 +369,9 @@ TrackView::onFilterChanged( const QString& ) if ( selectedIndexes().count() ) scrollTo( selectedIndexes().at( 0 ), QAbstractItemView::PositionAtCenter ); - if ( !proxyModel()->filter().isEmpty() && !proxyModel()->trackCount() && model()->trackCount() ) + if ( !proxyModel()->getPlaylistInterface()->filter().isEmpty() && !proxyModel()->getPlaylistInterface()->trackCount() && model()->trackCount() ) { - m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->filter() ) ); + m_overlay->setText( tr( "Sorry, your filter '%1' did not match any results." ).arg( proxyModel()->getPlaylistInterface()->filter() ) ); m_overlay->show(); } else diff --git a/src/libtomahawk/playlist/treeproxymodel.cpp b/src/libtomahawk/playlist/treeproxymodel.cpp index 7bd956e4b..10ef415fb 100644 --- a/src/libtomahawk/playlist/treeproxymodel.cpp +++ b/src/libtomahawk/playlist/treeproxymodel.cpp @@ -18,8 +18,9 @@ #include "treeproxymodel.h" -#include +#include +#include "treeproxymodelplaylistinterface.h" #include "source.h" #include "query.h" #include "database/database.h" @@ -30,11 +31,8 @@ TreeProxyModel::TreeProxyModel( QObject* parent ) : QSortFilterProxyModel( parent ) - , PlaylistInterface( this ) , m_artistsFilterCmd( 0 ) , m_model( 0 ) - , m_repeatMode( PlaylistInterface::NoRepeat ) - , m_shuffled( false ) { setFilterCaseSensitivity( Qt::CaseInsensitive ); setSortCaseSensitivity( Qt::CaseInsensitive ); @@ -111,9 +109,8 @@ TreeProxyModel::onModelReset() m_albumsFilter.clear(); } - void -TreeProxyModel::setFilter( const QString& pattern ) +TreeProxyModel::newFilterFromPlaylistInterface( const QString &pattern ) { emit filteringStarted(); @@ -145,7 +142,6 @@ TreeProxyModel::setFilter( const QString& pattern ) } } - void TreeProxyModel::onFilterArtists( const QList& artists ) { @@ -191,15 +187,16 @@ TreeProxyModel::filterFinished() { m_artistsFilterCmd = 0; - if ( PlaylistInterface::filter() != m_filter ) + if ( qobject_cast< Tomahawk::TreeProxyModelPlaylistInterface* >( m_playlistInterface.data() )->vanillaFilter() != m_filter ) { emit filterChanged( m_filter ); } - PlaylistInterface::setFilter( m_filter ); + qobject_cast< Tomahawk::TreeProxyModelPlaylistInterface* >( m_playlistInterface )->setVanillaFilter( m_filter ); setFilterRegExp( m_filter ); - emit trackCountChanged( trackCount() ); + qobject_cast< Tomahawk::TreeProxyModelPlaylistInterface* >( m_playlistInterface )->sendTrackCount(); + emit filteringFinished(); } @@ -338,82 +335,6 @@ TreeProxyModel::removeIndexes( const QList& indexes ) } -bool -TreeProxyModel::hasNextItem() -{ - return !( siblingItem( 1, true ).isNull() ); -} - - -Tomahawk::result_ptr -TreeProxyModel::siblingItem( int itemsAway ) -{ - return siblingItem( itemsAway, false ); -} - - -Tomahawk::result_ptr -TreeProxyModel::siblingItem( int itemsAway, bool readOnly ) -{ - QModelIndex idx = currentIndex(); - if ( !idx.isValid() ) - return Tomahawk::result_ptr(); - - if ( m_shuffled ) - { - idx = index( qrand() % rowCount( idx.parent() ), 0, idx.parent() ); - } - else - { - if ( m_repeatMode != PlaylistInterface::RepeatOne ) - idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); - } - - if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll ) - { - if ( itemsAway > 0 ) - { - // reset to first item - idx = index( 0, 0, currentIndex().parent() ); - } - else - { - // reset to last item - idx = index( rowCount( currentIndex().parent() ) - 1, 0, currentIndex().parent() ); - } - } - - // Try to find the next available PlaylistItem (with results) - while ( idx.isValid() ) - { - TreeModelItem* item = itemFromIndex( mapToSource( idx ) ); - if ( item && !item->result().isNull() && item->result()->isOnline() ) - { - qDebug() << "Next PlaylistItem found:" << item->result()->url(); - if ( !readOnly ) - setCurrentIndex( idx ); - return item->result(); - } - - idx = index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); - } - - if ( !readOnly ) - setCurrentIndex( QModelIndex() ); - return Tomahawk::result_ptr(); -} - - -Tomahawk::result_ptr -TreeProxyModel::currentItem() const -{ - TreeModelItem* item = itemFromIndex( mapToSource( currentIndex() ) ); - if ( item && !item->result().isNull() && item->result()->isOnline() ) - return item->result(); - return Tomahawk::result_ptr(); -} - - QString TreeProxyModel::textForItem( TreeModelItem* item ) const { @@ -439,3 +360,15 @@ TreeProxyModel::textForItem( TreeModelItem* item ) const return QString(); } + + +Tomahawk::playlistinterface_ptr +TreeProxyModel::getPlaylistInterface() +{ + if ( m_playlistInterface.isNull() ) + { + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::TreeProxyModelPlaylistInterface( this ) ); + } + + return m_playlistInterface; +} diff --git a/src/libtomahawk/playlist/treeproxymodel.h b/src/libtomahawk/playlist/treeproxymodel.h index 6e4da857a..6ce52785a 100644 --- a/src/libtomahawk/playlist/treeproxymodel.h +++ b/src/libtomahawk/playlist/treeproxymodel.h @@ -28,7 +28,12 @@ class DatabaseCommand_AllArtists; -class DLLEXPORT TreeProxyModel : public QSortFilterProxyModel, public Tomahawk::PlaylistInterface +namespace Tomahawk +{ + class TreeProxyModelPlaylistInterface; +} + +class DLLEXPORT TreeProxyModel : public QSortFilterProxyModel { Q_OBJECT @@ -43,46 +48,22 @@ public: virtual QPersistentModelIndex currentIndex() const; virtual void setCurrentIndex( const QModelIndex& index ) { m_model->setCurrentItem( mapToSource( index ) ); } - virtual QList tracks() { Q_ASSERT( FALSE ); QList queries; return queries; } - - virtual int unfilteredTrackCount() const { return sourceModel()->rowCount( QModelIndex() ); } - virtual int trackCount() const { return rowCount( QModelIndex() ); } - virtual int albumCount() const { return rowCount( QModelIndex() ); } + virtual void newFilterFromPlaylistInterface( const QString &pattern ); virtual void removeIndex( const QModelIndex& index ); virtual void removeIndexes( const QList& indexes ); - virtual bool hasNextItem(); - virtual Tomahawk::result_ptr currentItem() const; - virtual Tomahawk::result_ptr siblingItem( int direction ); - virtual Tomahawk::result_ptr siblingItem( int direction, bool readOnly ); + virtual int albumCount() const { return rowCount( QModelIndex() ); } - virtual QString filter() const { return filterRegExp().pattern(); } - virtual void setFilter( const QString& pattern ); + virtual TreeModelItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); } - virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; } - virtual bool shuffled() const { return m_shuffled; } - virtual PlaylistInterface::ViewMode viewMode() const { return PlaylistInterface::Tree; } - - TreeModelItem* itemFromIndex( const QModelIndex& index ) const { return sourceModel()->itemFromIndex( index ); } + virtual Tomahawk::playlistinterface_ptr getPlaylistInterface(); signals: - void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); - void shuffleModeChanged( bool enabled ); - - void trackCountChanged( unsigned int tracks ); - void sourceTrackCountChanged( unsigned int tracks ); - void filterChanged( const QString& filter ); void filteringStarted(); void filteringFinished(); - void nextTrackReady(); - -public slots: - virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); } - virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); } - protected: bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; bool lessThan( const QModelIndex& left, const QModelIndex& right ) const; @@ -105,11 +86,11 @@ private: QList m_albumsFilter; DatabaseCommand_AllArtists* m_artistsFilterCmd; - QString m_filter; + QString m_filter; TreeModel* m_model; - RepeatMode m_repeatMode; - bool m_shuffled; + + Tomahawk::playlistinterface_ptr m_playlistInterface; }; #endif // TREEPROXYMODEL_H diff --git a/src/libtomahawk/playlist/treeproxymodelplaylistinterface.cpp b/src/libtomahawk/playlist/treeproxymodelplaylistinterface.cpp new file mode 100644 index 000000000..0521ad42b --- /dev/null +++ b/src/libtomahawk/playlist/treeproxymodelplaylistinterface.cpp @@ -0,0 +1,167 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#include "treeproxymodelplaylistinterface.h" + +#include "treeproxymodel.h" + +#include "source.h" +#include "query.h" +#include "database/database.h" +#include "database/databaseimpl.h" +#include "database/databasecommand_allalbums.h" +#include "utils/logger.h" + +using namespace Tomahawk; + +TreeProxyModelPlaylistInterface::TreeProxyModelPlaylistInterface( TreeProxyModel *proxyModel ) + : PlaylistInterface() + , m_proxyModel( proxyModel ) + , m_repeatMode( PlaylistInterface::NoRepeat ) + , m_shuffled( false ) +{ +} + + +TreeProxyModelPlaylistInterface::~TreeProxyModelPlaylistInterface() +{ + m_proxyModel.clear(); +} + + +QString +TreeProxyModelPlaylistInterface::filter() const +{ + if ( m_proxyModel.isNull() ) + return 0; + TreeProxyModel* proxyModel = m_proxyModel.data(); + return proxyModel->filterRegExp().pattern(); +} + + +void +TreeProxyModelPlaylistInterface::setFilter( const QString& pattern ) +{ + if ( m_proxyModel.isNull() ) + return; + m_proxyModel.data()->newFilterFromPlaylistInterface( pattern ); +} + + +int +TreeProxyModelPlaylistInterface::unfilteredTrackCount() const +{ + if ( m_proxyModel.isNull() ) + return 0; + TreeProxyModel* proxyModel = m_proxyModel.data(); + return proxyModel->sourceModel()->rowCount( QModelIndex() ); +} + + +int +TreeProxyModelPlaylistInterface::trackCount() const +{ + if ( m_proxyModel.isNull() ) + return 0; + TreeProxyModel* proxyModel = m_proxyModel.data(); + return proxyModel->rowCount( QModelIndex() ); +} + + +bool +TreeProxyModelPlaylistInterface::hasNextItem() +{ + return !( siblingItem( 1, true ).isNull() ); +} + + +Tomahawk::result_ptr +TreeProxyModelPlaylistInterface::siblingItem( int itemsAway ) +{ + return siblingItem( itemsAway, false ); +} + + +Tomahawk::result_ptr +TreeProxyModelPlaylistInterface::siblingItem( int itemsAway, bool readOnly ) +{ + if ( m_proxyModel.isNull() ) + return Tomahawk::result_ptr(); + TreeProxyModel* proxyModel = m_proxyModel.data(); + + QModelIndex idx = proxyModel->currentIndex(); + if ( !idx.isValid() ) + return Tomahawk::result_ptr(); + + if ( m_shuffled ) + { + idx = proxyModel->index( qrand() % proxyModel->rowCount( idx.parent() ), 0, idx.parent() ); + } + else + { + if ( m_repeatMode != PlaylistInterface::RepeatOne ) + idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); + } + + if ( !idx.isValid() && m_repeatMode == PlaylistInterface::RepeatAll ) + { + if ( itemsAway > 0 ) + { + // reset to first item + idx = proxyModel->index( 0, 0, proxyModel->currentIndex().parent() ); + } + else + { + // reset to last item + idx = proxyModel->index( proxyModel->rowCount( proxyModel->currentIndex().parent() ) - 1, 0, proxyModel->currentIndex().parent() ); + } + } + + // Try to find the next available PlaylistItem (with results) + while ( idx.isValid() ) + { + TreeModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( idx ) ); + if ( item && !item->result().isNull() && item->result()->isOnline() ) + { + qDebug() << "Next PlaylistItem found:" << item->result()->url(); + if ( !readOnly ) + proxyModel->setCurrentIndex( idx ); + return item->result(); + } + + idx = proxyModel->index( idx.row() + ( itemsAway > 0 ? 1 : -1 ), 0, idx.parent() ); + } + + if ( !readOnly ) + proxyModel->setCurrentIndex( QModelIndex() ); + return Tomahawk::result_ptr(); +} + + +Tomahawk::result_ptr +TreeProxyModelPlaylistInterface::currentItem() const +{ + if ( m_proxyModel.isNull() ) + return Tomahawk::result_ptr(); + TreeProxyModel* proxyModel = m_proxyModel.data(); + + TreeModelItem* item = proxyModel->itemFromIndex( proxyModel->mapToSource( proxyModel->currentIndex() ) ); + if ( item && !item->result().isNull() && item->result()->isOnline() ) + return item->result(); + return Tomahawk::result_ptr(); +} diff --git a/src/libtomahawk/playlist/treeproxymodelplaylistinterface.h b/src/libtomahawk/playlist/treeproxymodelplaylistinterface.h new file mode 100644 index 000000000..f38654981 --- /dev/null +++ b/src/libtomahawk/playlist/treeproxymodelplaylistinterface.h @@ -0,0 +1,89 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Christian Muehlhaeuser + * + * 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 . + */ + +#ifndef TREEPROXYMODELPLAYLISTINTERFACE_H +#define TREEPROXYMODELPLAYLISTINTERFACE_H + +#include "playlistinterface.h" +#include "treemodel.h" + +#include "dllmacro.h" + +class DatabaseCommand_AllArtists; +class TreeProxyModel; + +namespace Tomahawk +{ + +class DLLEXPORT TreeProxyModelPlaylistInterface : public Tomahawk::PlaylistInterface +{ +Q_OBJECT + +public: + explicit TreeProxyModelPlaylistInterface( TreeProxyModel *proxyModel ); + virtual ~TreeProxyModelPlaylistInterface(); + + virtual QList< Tomahawk::query_ptr > tracks() { Q_ASSERT( FALSE ); QList< Tomahawk::query_ptr > queries; return queries; } + + virtual int unfilteredTrackCount() const; + virtual int trackCount() const; + + virtual bool hasNextItem(); + virtual Tomahawk::result_ptr currentItem() const; + virtual Tomahawk::result_ptr siblingItem( int direction ); + virtual Tomahawk::result_ptr siblingItem( int direction, bool readOnly ); + + virtual QString filter() const; + virtual void setFilter( const QString& pattern ); + + virtual QString vanillaFilter() const { return PlaylistInterface::filter(); } + virtual void setVanillaFilter( const QString &filter ) { PlaylistInterface::setFilter( filter ); } + + virtual void sendTrackCount() { emit trackCountChanged( trackCount() ); } + + virtual PlaylistInterface::RepeatMode repeatMode() const { return m_repeatMode; } + virtual bool shuffled() const { return m_shuffled; } + virtual PlaylistInterface::ViewMode viewMode() const { return PlaylistInterface::Tree; } + +signals: + void repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + + void filterChanged( const QString& filter ); + void filteringStarted(); + void filteringFinished(); + + void nextTrackReady(); + +public slots: + virtual void setRepeatMode( RepeatMode mode ) { m_repeatMode = mode; emit repeatModeChanged( mode ); } + virtual void setShuffled( bool enabled ) { m_shuffled = enabled; emit shuffleModeChanged( enabled ); } + +private: + QWeakPointer< TreeProxyModel > m_proxyModel; + + RepeatMode m_repeatMode; + bool m_shuffled; +}; + +} //ns + +#endif // TREEPROXYMODELPLAYLISTINTERFACE_H diff --git a/src/libtomahawk/playlistinterface.cpp b/src/libtomahawk/playlistinterface.cpp index 7e381a90d..63fb86996 100644 --- a/src/libtomahawk/playlistinterface.cpp +++ b/src/libtomahawk/playlistinterface.cpp @@ -22,8 +22,7 @@ using namespace Tomahawk; -PlaylistInterface::PlaylistInterface ( QObject *parent ) - : m_object( parent ) +PlaylistInterface::PlaylistInterface () { qRegisterMetaType( "Tomahawk::PlaylistInterface::RepeatMode" ); } diff --git a/src/libtomahawk/playlistinterface.h b/src/libtomahawk/playlistinterface.h index 88b7058e8..e161608ed 100644 --- a/src/libtomahawk/playlistinterface.h +++ b/src/libtomahawk/playlistinterface.h @@ -28,8 +28,9 @@ namespace Tomahawk { -class DLLEXPORT PlaylistInterface +class DLLEXPORT PlaylistInterface : public QObject { +Q_OBJECT public: enum RepeatMode { NoRepeat, RepeatOne, RepeatAll }; @@ -39,7 +40,7 @@ public: enum SkipRestrictions { NoSkipRestrictions, NoSkipForwards, NoSkipBackwards, NoSkip }; enum RetryMode { NoRetry, Retry }; - explicit PlaylistInterface( QObject* parent = 0 ); + explicit PlaylistInterface(); virtual ~PlaylistInterface(); virtual QList< Tomahawk::query_ptr > tracks() = 0; @@ -67,39 +68,25 @@ public: virtual void reset() {} + //TODO: Get rid of the next two functions once all playlsitinterfaces are factored out // Some playlist interfaces can wrap other interfaces. When checking for top-level // equality (say, to compare the currently playing interface) this might be needed virtual bool hasChildInterface( Tomahawk::playlistinterface_ptr ) { return false; } - QObject* object() const { return m_object; } - - virtual Tomahawk::playlistinterface_ptr getSharedPointer() - { - if ( m_sharedPtr.isNull() ) - { - m_sharedPtr = Tomahawk::playlistinterface_ptr( this ); - } - - return m_sharedPtr; - } - - //virtual void findMoreIfaces() = 0; - public slots: virtual void setRepeatMode( RepeatMode mode ) = 0; virtual void setShuffled( bool enabled ) = 0; signals: - virtual void repeatModeChanged( PlaylistInterface::RepeatMode mode ) = 0; - virtual void shuffleModeChanged( bool enabled ) = 0; - virtual void trackCountChanged( unsigned int tracks ) = 0; - virtual void sourceTrackCountChanged( unsigned int tracks ) = 0; - virtual void nextTrackReady() = 0; + void repeatModeChanged( PlaylistInterface::RepeatMode mode ); + void shuffleModeChanged( bool enabled ); + void trackCountChanged( unsigned int tracks ); + void sourceTrackCountChanged( unsigned int tracks ); + void nextTrackReady(); private: Q_DISABLE_COPY( PlaylistInterface ) - QObject* m_object; Tomahawk::playlistinterface_ptr m_sharedPtr; QString m_filter; diff --git a/src/libtomahawk/playlistplaylistinterface.cpp b/src/libtomahawk/playlistplaylistinterface.cpp index 3f7984e44..30049fc0b 100644 --- a/src/libtomahawk/playlistplaylistinterface.cpp +++ b/src/libtomahawk/playlistplaylistinterface.cpp @@ -27,7 +27,7 @@ using namespace Tomahawk; PlaylistPlaylistInterface::PlaylistPlaylistInterface( Tomahawk::Playlist* playlist ) - : QObject() + : Tomahawk::PlaylistInterface() , m_playlist( playlist ) { } diff --git a/src/libtomahawk/playlistplaylistinterface.h b/src/libtomahawk/playlistplaylistinterface.h index 6beae26bb..94dcacd08 100644 --- a/src/libtomahawk/playlistplaylistinterface.h +++ b/src/libtomahawk/playlistplaylistinterface.h @@ -33,7 +33,7 @@ namespace Tomahawk { -class DLLEXPORT PlaylistPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +class DLLEXPORT PlaylistPlaylistInterface : public Tomahawk::PlaylistInterface { Q_OBJECT @@ -56,8 +56,6 @@ public: virtual void setFilter( const QString& /*pattern*/ ) {} - virtual void findMoreIfaces() {} - signals: void repeatModeChanged( PlaylistInterface::RepeatMode mode ); void shuffleModeChanged( bool enabled ); diff --git a/src/libtomahawk/source.cpp b/src/libtomahawk/source.cpp index 6f0e6d540..45db8297e 100644 --- a/src/libtomahawk/source.cpp +++ b/src/libtomahawk/source.cpp @@ -307,7 +307,7 @@ Source::getPlaylistInterface() if ( m_playlistInterface.isNull() ) { Tomahawk::source_ptr source = SourceList::instance()->get( id() ); - m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::SourcePlaylistInterface( source ) ); + m_playlistInterface = Tomahawk::playlistinterface_ptr( new Tomahawk::SourcePlaylistInterface( source.data() ) ); } return m_playlistInterface; diff --git a/src/libtomahawk/sourceplaylistinterface.cpp b/src/libtomahawk/sourceplaylistinterface.cpp index 9dcce89e4..b1ee26ef6 100644 --- a/src/libtomahawk/sourceplaylistinterface.cpp +++ b/src/libtomahawk/sourceplaylistinterface.cpp @@ -26,13 +26,14 @@ using namespace Tomahawk; -SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::source_ptr& source ) - : PlaylistInterface( this ) - , m_source( source.data() ) +SourcePlaylistInterface::SourcePlaylistInterface( Tomahawk::Source *source ) + : PlaylistInterface() + , m_source( source ) , m_currentItem( 0 ) , m_gotNextItem( false ) { - connect( source.data(), SIGNAL( playbackStarted( const Tomahawk::query_ptr& ) ), SLOT( onSourcePlaybackStarted( const Tomahawk::query_ptr& ) ) ); + if ( !m_source.isNull() ) + connect( m_source.data(), SIGNAL( playbackStarted( const Tomahawk::query_ptr& ) ), SLOT( onSourcePlaybackStarted( const Tomahawk::query_ptr& ) ) ); } diff --git a/src/libtomahawk/sourceplaylistinterface.h b/src/libtomahawk/sourceplaylistinterface.h index 7e4e5c73e..ce03f3c63 100644 --- a/src/libtomahawk/sourceplaylistinterface.h +++ b/src/libtomahawk/sourceplaylistinterface.h @@ -30,12 +30,12 @@ namespace Tomahawk { -class DLLEXPORT SourcePlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +class DLLEXPORT SourcePlaylistInterface : public Tomahawk::PlaylistInterface { Q_OBJECT public: - SourcePlaylistInterface( Tomahawk::source_ptr& source ); + SourcePlaylistInterface( Tomahawk::Source *source ); virtual ~SourcePlaylistInterface(); QList tracks(); @@ -61,8 +61,6 @@ public: virtual void reset(); - virtual void findMoreIfaces() {} - public slots: virtual void setRepeatMode( PlaylistInterface::RepeatMode ) {} virtual void setShuffled( bool ) {} diff --git a/src/libtomahawk/viewmanager.cpp b/src/libtomahawk/viewmanager.cpp index 069391424..209855da1 100644 --- a/src/libtomahawk/viewmanager.cpp +++ b/src/libtomahawk/viewmanager.cpp @@ -605,16 +605,16 @@ ViewManager::unlinkPlaylist() { if ( currentPlaylistInterface() ) { - disconnect( currentPlaylistInterface()->object(), SIGNAL( sourceTrackCountChanged( unsigned int ) ), + disconnect( currentPlaylistInterface().data(), SIGNAL( sourceTrackCountChanged( unsigned int ) ), this, SIGNAL( numTracksChanged( unsigned int ) ) ); - disconnect( currentPlaylistInterface()->object(), SIGNAL( trackCountChanged( unsigned int ) ), + disconnect( currentPlaylistInterface().data(), SIGNAL( trackCountChanged( unsigned int ) ), this, SIGNAL( numShownChanged( unsigned int ) ) ); - disconnect( currentPlaylistInterface()->object(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), + disconnect( currentPlaylistInterface().data(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), this, SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) ); - disconnect( currentPlaylistInterface()->object(), SIGNAL( shuffleModeChanged( bool ) ), + disconnect( currentPlaylistInterface().data(), SIGNAL( shuffleModeChanged( bool ) ), this, SIGNAL( shuffleModeChanged( bool ) ) ); } } @@ -644,16 +644,16 @@ ViewManager::updateView() { if ( currentPlaylistInterface() ) { - connect( currentPlaylistInterface()->object(), SIGNAL( sourceTrackCountChanged( unsigned int ) ), + connect( currentPlaylistInterface().data(), SIGNAL( sourceTrackCountChanged( unsigned int ) ), SIGNAL( numTracksChanged( unsigned int ) ) ); - connect( currentPlaylistInterface()->object(), SIGNAL( trackCountChanged( unsigned int ) ), + connect( currentPlaylistInterface().data(), SIGNAL( trackCountChanged( unsigned int ) ), SIGNAL( numShownChanged( unsigned int ) ) ); - connect( currentPlaylistInterface()->object(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), + connect( currentPlaylistInterface().data(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ) ); - connect( currentPlaylistInterface()->object(), SIGNAL( shuffleModeChanged( bool ) ), + connect( currentPlaylistInterface().data(), SIGNAL( shuffleModeChanged( bool ) ), SIGNAL( shuffleModeChanged( bool ) ) ); m_infobar->setFilter( currentPlaylistInterface()->filter() ); diff --git a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp index 54b98d0b2..0b70bb809 100644 --- a/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/AlbumInfoWidget.cpp @@ -102,7 +102,7 @@ AlbumInfoWidget::~AlbumInfoWidget() Tomahawk::playlistinterface_ptr AlbumInfoWidget::playlistInterface() const { - return ui->tracksView->playlistInterface()->getSharedPointer(); + return ui->tracksView->playlistInterface(); } diff --git a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h index b4bd3c270..a50bb1a31 100644 --- a/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h +++ b/src/libtomahawk/widgets/infowidgets/ArtistInfoWidget_p.h @@ -27,12 +27,12 @@ #include -class MetaPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +class MetaPlaylistInterface : public Tomahawk::PlaylistInterface { Q_OBJECT public: explicit MetaPlaylistInterface( ArtistInfoWidget* w ) - : PlaylistInterface( this ) + : PlaylistInterface() , m_w( w ) { connect( m_w->ui->albums->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), @@ -53,9 +53,9 @@ public: // Any one is fine, we keep them all synched - virtual RepeatMode repeatMode() const { return m_w->ui->albums->proxyModel()->repeatMode(); } + virtual RepeatMode repeatMode() const { return m_w->ui->albums->proxyModel()->getPlaylistInterface()->repeatMode(); } - virtual bool shuffled() const { return m_w->ui->albums->proxyModel()->shuffled(); } + virtual bool shuffled() const { return m_w->ui->albums->proxyModel()->getPlaylistInterface()->shuffled(); } // Do nothing virtual Tomahawk::result_ptr currentItem() const { return Tomahawk::result_ptr(); } @@ -70,19 +70,20 @@ public: ( m_w->ui->relatedArtists->playlistInterface() == other ) || ( m_w->ui->topHits->playlistInterface() == other ); } + public slots: virtual void setRepeatMode( RepeatMode mode ) { - m_w->ui->albums->proxyModel()->setRepeatMode( mode ); - m_w->ui->relatedArtists->proxyModel()->setRepeatMode( mode ); - m_w->ui->topHits->proxyModel()->setRepeatMode( mode ); + m_w->ui->albums->proxyModel()->getPlaylistInterface()->setRepeatMode( mode ); + m_w->ui->relatedArtists->proxyModel()->getPlaylistInterface()->setRepeatMode( mode ); + m_w->ui->topHits->proxyModel()->getPlaylistInterface()->setRepeatMode( mode ); } virtual void setShuffled( bool enabled ) { - m_w->ui->albums->proxyModel()->setShuffled( enabled ); - m_w->ui->relatedArtists->proxyModel()->setShuffled( enabled ); - m_w->ui->topHits->proxyModel()->setShuffled( enabled ); + m_w->ui->albums->proxyModel()->getPlaylistInterface()->setShuffled( enabled ); + m_w->ui->relatedArtists->proxyModel()->getPlaylistInterface()->setShuffled( enabled ); + m_w->ui->topHits->proxyModel()->getPlaylistInterface()->setShuffled( enabled ); } signals: diff --git a/src/libtomahawk/widgets/welcomewidget.cpp b/src/libtomahawk/widgets/welcomewidget.cpp index c5f02dbdb..aa776af6c 100644 --- a/src/libtomahawk/widgets/welcomewidget.cpp +++ b/src/libtomahawk/widgets/welcomewidget.cpp @@ -101,7 +101,7 @@ WelcomeWidget::~WelcomeWidget() Tomahawk::playlistinterface_ptr WelcomeWidget::playlistInterface() const { - return ui->tracksView->playlistInterface()->getSharedPointer(); + return ui->tracksView->playlistInterface(); } diff --git a/src/libtomahawk/widgets/whatshotwidget.cpp b/src/libtomahawk/widgets/whatshotwidget.cpp index 4666f972b..062139050 100644 --- a/src/libtomahawk/widgets/whatshotwidget.cpp +++ b/src/libtomahawk/widgets/whatshotwidget.cpp @@ -93,7 +93,7 @@ WhatsHotWidget::WhatsHotWidget( QWidget* parent ) ui->artistsViewLeft->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); ui->artistsViewLeft->header()->setVisible( false ); - m_playlistInterface = ( new ChartsPlaylistInterface( this ) )->getSharedPointer(); + m_playlistInterface = Tomahawk::playlistinterface_ptr( new ChartsPlaylistInterface( this ) ); m_workerThread = new QThread( this ); m_workerThread->start(); diff --git a/src/libtomahawk/widgets/whatshotwidget.h b/src/libtomahawk/widgets/whatshotwidget.h index 7ac5320e2..1cfcd0248 100644 --- a/src/libtomahawk/widgets/whatshotwidget.h +++ b/src/libtomahawk/widgets/whatshotwidget.h @@ -31,7 +31,6 @@ #include "dllmacro.h" -class ChartsPlaylistInterface; class QSortFilterProxyModel; class QStandardItemModel; class QStandardItem; @@ -49,6 +48,7 @@ namespace Ui namespace Tomahawk { class ChartDataLoader; + class ChartsPlaylistInterface; } /** @@ -119,7 +119,7 @@ private: QSet< QString > m_queuedFetches; QTimer* m_timer; - friend class ChartsPlaylistInterface; + friend class Tomahawk::ChartsPlaylistInterface; }; #endif // WHATSHOTWIDGET_H diff --git a/src/libtomahawk/widgets/whatshotwidget_p.h b/src/libtomahawk/widgets/whatshotwidget_p.h index 14fd48a90..904b0f7c1 100644 --- a/src/libtomahawk/widgets/whatshotwidget_p.h +++ b/src/libtomahawk/widgets/whatshotwidget_p.h @@ -28,12 +28,15 @@ #include -class ChartsPlaylistInterface : public QObject, public Tomahawk::PlaylistInterface +namespace Tomahawk +{ + +class ChartsPlaylistInterface : public Tomahawk::PlaylistInterface { Q_OBJECT public: explicit ChartsPlaylistInterface( WhatsHotWidget* w ) - : PlaylistInterface( this ) + : PlaylistInterface() , m_w( w ) { connect( m_w->ui->tracksViewLeft->proxyModel(), SIGNAL( repeatModeChanged( Tomahawk::PlaylistInterface::RepeatMode ) ), @@ -48,11 +51,10 @@ public: } virtual ~ChartsPlaylistInterface() {} - // Any one is fine, we keep them all synched - virtual RepeatMode repeatMode() const { return m_w->ui->tracksViewLeft->proxyModel()->repeatMode(); } + virtual RepeatMode repeatMode() const { return m_w->ui->tracksViewLeft->proxyModel()->getPlaylistInterface()->repeatMode(); } - virtual bool shuffled() const { return m_w->ui->tracksViewLeft->proxyModel()->shuffled(); } + virtual bool shuffled() const { return m_w->ui->tracksViewLeft->proxyModel()->getPlaylistInterface()->shuffled(); } // Do nothing virtual Tomahawk::result_ptr currentItem() const { return Tomahawk::result_ptr(); } @@ -67,17 +69,18 @@ public: m_w->ui->artistsViewLeft->playlistInterface() == other; } + public slots: virtual void setRepeatMode( RepeatMode mode ) { - m_w->ui->tracksViewLeft->proxyModel()->setRepeatMode( mode ); - m_w->ui->artistsViewLeft->proxyModel()->setRepeatMode( mode ); + m_w->ui->tracksViewLeft->proxyModel()->getPlaylistInterface()->setRepeatMode( mode ); + m_w->ui->artistsViewLeft->proxyModel()->getPlaylistInterface()->setRepeatMode( mode ); } virtual void setShuffled( bool enabled ) { - m_w->ui->tracksViewLeft->proxyModel()->setShuffled( enabled ); - m_w->ui->artistsViewLeft->proxyModel()->setShuffled( enabled ); + m_w->ui->tracksViewLeft->proxyModel()->getPlaylistInterface()->setShuffled( enabled ); + m_w->ui->artistsViewLeft->proxyModel()->getPlaylistInterface()->setShuffled( enabled ); } signals: @@ -104,4 +107,6 @@ private: }; +} //ns + #endif diff --git a/src/tomahawkwindow.cpp b/src/tomahawkwindow.cpp index e44f8f73d..06862e1a1 100644 --- a/src/tomahawkwindow.cpp +++ b/src/tomahawkwindow.cpp @@ -224,7 +224,7 @@ TomahawkWindow::setupSideBar() m_queueModel->setStyle( PlaylistModel::Short ); m_queueView->queue()->setPlaylistModel( m_queueModel ); m_queueView->queue()->playlistModel()->setReadOnly( false ); - AudioEngine::instance()->setQueue( m_queueView->queue()->proxyModel()->getSharedPointer() ); + AudioEngine::instance()->setQueue( m_queueView->queue()->proxyModel()->getPlaylistInterface() ); m_sidebar->addWidget( m_searchWidget ); m_sidebar->addWidget( m_sourcetree );