From e9c7fd7a16507da68d91b07030428accf9a1bd38 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 20 Oct 2014 03:49:23 +0200 Subject: [PATCH] Reload Collection-related models when it changed. --- .../viewpages/CollectionViewPage.cpp | 83 ++++++++++++------- .../viewpages/CollectionViewPage.h | 1 + 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/libtomahawk/viewpages/CollectionViewPage.cpp b/src/libtomahawk/viewpages/CollectionViewPage.cpp index f685b0f15..adf651f24 100644 --- a/src/libtomahawk/viewpages/CollectionViewPage.cpp +++ b/src/libtomahawk/viewpages/CollectionViewPage.cpp @@ -126,70 +126,70 @@ CollectionViewPage::~CollectionViewPage() void CollectionViewPage::loadCollection( const collection_ptr& collection ) { - m_collection = collection; - - TreeModel* model = new TreeModel(); - PlayableModel* flatModel = new PlayableModel(); - PlayableModel* albumModel = new PlayableModel(); - - setTreeModel( model ); - setFlatModel( flatModel ); - setAlbumModel( albumModel ); - - model->addCollection( collection ); - flatModel->appendTracks( collection ); - albumModel->appendAlbums( collection ); - - if ( collection && collection->source() && collection->source()->isLocal() ) + if ( m_collection ) { - setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) ); + disconnect( collection.data(), SIGNAL( changed() ), this, SLOT( onCollectionChanged() ) ); } - else - setEmptyTip( tr( "This collection is empty." ) ); - if ( collection.objectCast() ) - m_trackView->setEmptyTip( tr( "Cloud collections aren't supported in the flat view yet. We will have them covered soon. Switch to another view to navigate them." ) ); + m_collection = collection; + connect( collection.data(), SIGNAL( changed() ), SLOT( onCollectionChanged() ), Qt::UniqueConnection ); + + onCollectionChanged(); } void CollectionViewPage::setTreeModel( TreeModel* model ) { - if ( m_model ) - { - disconnect( m_model, SIGNAL( changed() ), this, SLOT( onModelChanged() ) ); - delete m_model; - } - + QPointer oldModel = m_model; m_model = model; m_columnView->setTreeModel( model ); connect( model, SIGNAL( changed() ), SLOT( onModelChanged() ), Qt::UniqueConnection ); onModelChanged(); + + if ( oldModel ) + { + disconnect( oldModel.data(), SIGNAL( changed() ), this, SLOT( onModelChanged() ) ); + delete oldModel.data(); + } } void CollectionViewPage::setFlatModel( PlayableModel* model ) { - if ( m_flatModel ) - delete m_flatModel; + QPointer oldModel = m_flatModel; m_flatModel = model; m_trackView->setPlayableModel( model ); m_trackView->setSortingEnabled( true ); m_trackView->sortByColumn( 0, Qt::AscendingOrder ); + + if ( oldModel ) + { + disconnect( oldModel.data(), SIGNAL( changed() ), this, SLOT( onModelChanged() ) ); + delete oldModel.data(); + } } void CollectionViewPage::setAlbumModel( PlayableModel* model ) { + QPointer oldModel = m_albumModel; + if ( m_albumModel ) delete m_albumModel; m_albumModel = model; m_albumView->setPlayableModel( model ); + + if ( oldModel ) + { + disconnect( oldModel.data(), SIGNAL( changed() ), this, SLOT( onModelChanged() ) ); + delete oldModel.data(); + } } @@ -357,6 +357,33 @@ CollectionViewPage::onModelChanged() } +void +CollectionViewPage::onCollectionChanged() +{ + TreeModel* model = new TreeModel(); + PlayableModel* flatModel = new PlayableModel(); + PlayableModel* albumModel = new PlayableModel(); + + setTreeModel( model ); + setFlatModel( flatModel ); + setAlbumModel( albumModel ); + + model->addCollection( m_collection ); + flatModel->appendTracks( m_collection ); + albumModel->appendAlbums( m_collection ); + + if ( m_collection && m_collection->source() && m_collection->source()->isLocal() ) + { + setEmptyTip( tr( "After you have scanned your music collection you will find your tracks right here." ) ); + } + else + setEmptyTip( tr( "This collection is empty." ) ); + + if ( m_collection.objectCast() ) + m_trackView->setEmptyTip( tr( "Cloud collections aren't supported in the flat view yet. We will have them covered soon. Switch to another view to navigate them." ) ); +} + + bool CollectionViewPage::isTemporaryPage() const { diff --git a/src/libtomahawk/viewpages/CollectionViewPage.h b/src/libtomahawk/viewpages/CollectionViewPage.h index 782f2e70d..825072f61 100644 --- a/src/libtomahawk/viewpages/CollectionViewPage.h +++ b/src/libtomahawk/viewpages/CollectionViewPage.h @@ -76,6 +76,7 @@ signals: private slots: void onModelChanged(); + void onCollectionChanged(); private: FilterHeader* m_header;