From 92805d37c1b0b9d8918705c36d3368ea0073afd1 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Wed, 8 Jun 2011 21:33:50 -0400 Subject: [PATCH] Add a "New Additions" entry to each source to show the SourceInfoWidget --- .../widgets/infowidgets/sourceinfowidget.cpp | 6 ++--- src/sourcetree/items/collectionitem.cpp | 25 +++++++++++++++++++ src/sourcetree/items/collectionitem.h | 5 ++++ src/sourcetree/items/genericpageitems.cpp | 1 + src/sourcetree/items/genericpageitems.h | 3 +++ 5 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp b/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp index 8ac75a8c6..a56fe386d 100644 --- a/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp +++ b/src/libtomahawk/widgets/infowidgets/sourceinfowidget.cpp @@ -41,11 +41,11 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* ui->historyView->overlay()->setEnabled( false ); m_recentCollectionModel = new CollectionFlatModel( ui->recentCollectionView ); - ui->recentCollectionView->setModel( m_recentCollectionModel ); + ui->recentCollectionView->setTrackModel( m_recentCollectionModel ); m_recentCollectionModel->addFilteredCollection( source->collection(), 250, DatabaseCommand_AllTracks::ModificationTime ); m_historyModel = new PlaylistModel( ui->historyView ); - ui->historyView->setModel( m_historyModel ); + ui->historyView->setPlaylistModel( m_historyModel ); m_historyModel->loadHistory( source ); connect( source.data(), SIGNAL( playbackFinished( Tomahawk::query_ptr ) ), SLOT( onPlaybackFinished( Tomahawk::query_ptr ) ) ); @@ -59,7 +59,7 @@ SourceInfoWidget::SourceInfoWidget( const Tomahawk::source_ptr& source, QWidget* ui->historyView->setColumnHidden( TrackModel::Filesize, true ); m_recentAlbumModel = new AlbumModel( ui->recentAlbumView ); - ui->recentAlbumView->setModel( m_recentAlbumModel ); + ui->recentAlbumView->setAlbumModel( m_recentAlbumModel ); m_recentAlbumModel->addFilteredCollection( source->collection(), 20, DatabaseCommand_AllAlbums::ModificationTime ); m_title = tr( "Info about %1" ).arg( source->isLocal() ? tr( "Your Collection" ) : source->friendlyName() ); diff --git a/src/sourcetree/items/collectionitem.cpp b/src/sourcetree/items/collectionitem.cpp index 4aa76867b..a47b3a258 100644 --- a/src/sourcetree/items/collectionitem.cpp +++ b/src/sourcetree/items/collectionitem.cpp @@ -33,13 +33,22 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons , m_playlists( 0 ) , m_stations( 0 ) , m_tempItem( 0 ) + , m_sourceInfoItem( 0 ) , m_curTempPage( 0 ) + , m_sourceInfoPage( 0 ) { if( m_source.isNull() ) { // super collection connect( ViewManager::instance(), SIGNAL( tempPageActivated( Tomahawk::ViewPage*) ), this, SLOT( tempPageActivated( Tomahawk::ViewPage* ) ) ); return; } + + m_sourceInfoItem = new GenericPageItem( model(), this, tr( "New Additions" ), QIcon(), + boost::bind( &CollectionItem::sourceInfoClicked, this ), + boost::bind( &CollectionItem::getSourceInfoPage, this ) + ); + m_sourceInfoItem->setSortValue( -300 ); + // create category items if there are playlists to show, or stations to show QList< playlist_ptr > playlists = source->collection()->playlists(); QList< dynplaylist_ptr > autoplaylists = source->collection()->autoPlaylists(); @@ -306,3 +315,19 @@ CollectionItem::getTempPage() const { return m_curTempPage; } + +ViewPage* +CollectionItem::sourceInfoClicked() +{ + if( m_source.isNull() ) + return 0; + + m_sourceInfoPage = ViewManager::instance()->show( m_source ); + return m_sourceInfoPage; +} + +ViewPage* +CollectionItem::getSourceInfoPage() const +{ + return m_sourceInfoPage; +} diff --git a/src/sourcetree/items/collectionitem.h b/src/sourcetree/items/collectionitem.h index 8bb23bee7..c8519cf77 100644 --- a/src/sourcetree/items/collectionitem.h +++ b/src/sourcetree/items/collectionitem.h @@ -55,6 +55,9 @@ private slots: Tomahawk::ViewPage* tempItemClicked(); Tomahawk::ViewPage* getTempPage() const; + Tomahawk::ViewPage* sourceInfoClicked(); + Tomahawk::ViewPage* getSourceInfoPage() const; + private: void playlistsAddedInternal( SourceTreeItem* parent, const QList< Tomahawk::dynplaylist_ptr >& playlists ); template< typename T > @@ -65,7 +68,9 @@ private: CategoryItem* m_stations; GenericPageItem* m_tempItem; + GenericPageItem* m_sourceInfoItem; Tomahawk::ViewPage* m_curTempPage; + Tomahawk::ViewPage* m_sourceInfoPage; }; diff --git a/src/sourcetree/items/genericpageitems.cpp b/src/sourcetree/items/genericpageitems.cpp index 3739fa7cb..9a2787b93 100644 --- a/src/sourcetree/items/genericpageitems.cpp +++ b/src/sourcetree/items/genericpageitems.cpp @@ -26,6 +26,7 @@ GenericPageItem::GenericPageItem( SourcesModel* model, SourceTreeItem* parent, c : SourceTreeItem( model, parent, SourcesModel::GenericPage ) , m_icon( icon ) , m_text( text ) + , m_sortValue( 0 ) , m_show( show ) , m_get( get ) { diff --git a/src/sourcetree/items/genericpageitems.h b/src/sourcetree/items/genericpageitems.h index 5a980f7c3..378224bb1 100644 --- a/src/sourcetree/items/genericpageitems.h +++ b/src/sourcetree/items/genericpageitems.h @@ -35,14 +35,17 @@ public: virtual void activate(); virtual bool willAcceptDrag( const QMimeData* data ) const; virtual QIcon icon() const; + virtual int peerSortValue() const { return m_sortValue; } // How to sort relative to peers in the tree. void setText( const QString& text ); + void setSortValue( int value ) { m_sortValue = value; } signals: void activated(); private: QIcon m_icon; QString m_text; + int m_sortValue; boost::function< Tomahawk::ViewPage*() > m_show; boost::function< Tomahawk::ViewPage*() > m_get; };