From 0e6c79b92199013748aa3a5f083eddfe89670322 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 10 Aug 2011 21:09:47 +0200 Subject: [PATCH] auto-expand the local collections on startup --- src/sourcetree/items/collectionitem.cpp | 10 ++++++++++ src/sourcetree/items/collectionitem.h | 2 ++ src/sourcetree/items/sourcetreeitem.cpp | 1 + src/sourcetree/items/sourcetreeitem.h | 1 + src/sourcetree/sourcesmodel.cpp | 7 +++++++ src/sourcetree/sourcesmodel.h | 3 +++ src/sourcetree/sourcesproxymodel.cpp | 12 ++++++++++-- src/sourcetree/sourcesproxymodel.h | 2 ++ src/sourcetree/sourcetreeview.cpp | 8 ++++++++ src/sourcetree/sourcetreeview.h | 2 ++ 10 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/sourcetree/items/collectionitem.cpp b/src/sourcetree/items/collectionitem.cpp index d3ec1660b..c91c39771 100644 --- a/src/sourcetree/items/collectionitem.cpp +++ b/src/sourcetree/items/collectionitem.cpp @@ -114,6 +114,9 @@ CollectionItem::CollectionItem( SourcesModel* mdl, SourceTreeItem* parent, cons SLOT( onAutoPlaylistsAdded( QList ) ), Qt::QueuedConnection ); connect( source->collection().data(), SIGNAL( stationsAdded( QList ) ), SLOT( onStationsAdded( QList ) ), Qt::QueuedConnection ); + + if ( m_source->isLocal() ) + QTimer::singleShot(0, this, SLOT(requestExpanding())); } @@ -343,6 +346,13 @@ CollectionItem::onStationDeleted( const dynplaylist_ptr& station ) } +void +CollectionItem::requestExpanding() +{ + emit expandRequest(this); +} + + void CollectionItem::tempPageActivated( Tomahawk::ViewPage* v ) { diff --git a/src/sourcetree/items/collectionitem.h b/src/sourcetree/items/collectionitem.h index b92a75e47..5a8b5fb23 100644 --- a/src/sourcetree/items/collectionitem.h +++ b/src/sourcetree/items/collectionitem.h @@ -51,6 +51,8 @@ private slots: void onStationsAdded( const QList& stations ); void onStationDeleted( const Tomahawk::dynplaylist_ptr& stations ); + void requestExpanding(); + void tempPageActivated( Tomahawk::ViewPage* ); Tomahawk::ViewPage* tempItemClicked(); Tomahawk::ViewPage* getTempPage() const; diff --git a/src/sourcetree/items/sourcetreeitem.cpp b/src/sourcetree/items/sourcetreeitem.cpp index c15c33047..5cc9e3f7d 100644 --- a/src/sourcetree/items/sourcetreeitem.cpp +++ b/src/sourcetree/items/sourcetreeitem.cpp @@ -33,6 +33,7 @@ SourceTreeItem::SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, Sou connect( this, SIGNAL( childRowsRemoved() ), m_model, SLOT( onItemRowsRemovedDone() ) ); connect( this, SIGNAL( updated() ), m_model, SLOT( itemUpdated() ) ); connect( this, SIGNAL( selectRequest( SourceTreeItem* ) ), m_model, SLOT( itemSelectRequest( SourceTreeItem* ) ) ); + connect( this, SIGNAL( expandRequest( SourceTreeItem* ) ), m_model, SLOT( itemExpandRequest( SourceTreeItem* ) ) ); if( !m_parent ) return; diff --git a/src/sourcetree/items/sourcetreeitem.h b/src/sourcetree/items/sourcetreeitem.h index 57553988e..bfab5e1b1 100644 --- a/src/sourcetree/items/sourcetreeitem.h +++ b/src/sourcetree/items/sourcetreeitem.h @@ -63,6 +63,7 @@ public: signals: void updated(); void selectRequest( SourceTreeItem* ); + void expandRequest( SourceTreeItem* ); void beginChildRowsAdded( int fromRow, int toRow ); void childRowsAdded(); diff --git a/src/sourcetree/sourcesmodel.cpp b/src/sourcetree/sourcesmodel.cpp index 7330c53c1..8c99f5702 100644 --- a/src/sourcetree/sourcesmodel.cpp +++ b/src/sourcetree/sourcesmodel.cpp @@ -493,3 +493,10 @@ SourcesModel::itemSelectRequest( SourceTreeItem* item ) { emit selectRequest( indexFromItem( item ) ); } + +void +SourcesModel::itemExpandRequest( SourceTreeItem *item ) +{ + qDebug() << "expanding source" << indexFromItem( item ) << item; + emit expandRequest( indexFromItem( item ) ); +} diff --git a/src/sourcetree/sourcesmodel.h b/src/sourcetree/sourcesmodel.h index 94ca4008c..cfcb62776 100644 --- a/src/sourcetree/sourcesmodel.h +++ b/src/sourcetree/sourcesmodel.h @@ -102,8 +102,11 @@ public slots: void viewPageActivated( Tomahawk::ViewPage* ); void itemSelectRequest( SourceTreeItem* item ); + void itemExpandRequest( SourceTreeItem* item ); + signals: void selectRequest( const QModelIndex& idx ); + void expandRequest( const QModelIndex& idx ); private slots: void onSourcesAdded( const QList& sources ); diff --git a/src/sourcetree/sourcesproxymodel.cpp b/src/sourcetree/sourcesproxymodel.cpp index 6fe6c3bcb..93ec73b64 100644 --- a/src/sourcetree/sourcesproxymodel.cpp +++ b/src/sourcetree/sourcesproxymodel.cpp @@ -37,8 +37,8 @@ SourcesProxyModel::SourcesProxyModel( SourcesModel* model, QObject* parent ) setSourceModel( model ); - if ( model && model->metaObject()->indexOfSignal( "trackCountChanged(QModelIndex)" ) > -1 ) - connect( model, SIGNAL( askForExpand( QModelIndex ) ), this, SLOT( askedToExpand( QModelIndex ) ) ); + if ( model && model->metaObject()->indexOfSignal( "expandRequest(QModelIndex)" ) > -1 ) + connect( model, SIGNAL( expandRequest( QModelIndex ) ), this, SLOT( expandRequested( QModelIndex ) ) ); if ( model && model->metaObject()->indexOfSignal( "selectRequest(QModelIndex)" ) > -1 ) connect( model, SIGNAL( selectRequest( QModelIndex ) ), this, SLOT( selectRequested( QModelIndex ) ) ); } @@ -73,6 +73,14 @@ SourcesProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourcePar void SourcesProxyModel::selectRequested( const QModelIndex& idx ) { + qDebug() << "selectRequested for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ); emit selectRequest( mapFromSource( idx ) ); } +void +SourcesProxyModel::expandRequested( const QModelIndex& idx ) +{ + qDebug() << "emitting expand for idx" << idx << idx.data(Qt::DisplayRole).toString() << mapFromSource( idx ); + emit expandRequest( mapFromSource( idx ) ); +} + diff --git a/src/sourcetree/sourcesproxymodel.h b/src/sourcetree/sourcesproxymodel.h index 4599d8c5c..65e3198d8 100644 --- a/src/sourcetree/sourcesproxymodel.h +++ b/src/sourcetree/sourcesproxymodel.h @@ -34,9 +34,11 @@ public slots: void showOfflineSources( bool offlineSourcesShown ); void selectRequested( const QModelIndex& ); + void expandRequested( const QModelIndex& ); signals: void selectRequest( const QModelIndex& idx ); + void expandRequest( const QModelIndex& idx ); protected: bool filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const; diff --git a/src/sourcetree/sourcetreeview.cpp b/src/sourcetree/sourcetreeview.cpp index b7f4226d9..4acbf7f56 100644 --- a/src/sourcetree/sourcetreeview.cpp +++ b/src/sourcetree/sourcetreeview.cpp @@ -108,6 +108,7 @@ SourceTreeView::SourceTreeView( QWidget* parent ) m_model = new SourcesModel( this ); m_proxyModel = new SourcesProxyModel( m_model, this ); connect( m_proxyModel, SIGNAL( selectRequest( QModelIndex ) ), this, SLOT( selectRequest( QModelIndex ) ), Qt::QueuedConnection ); + connect( m_proxyModel, SIGNAL( expandRequest( QModelIndex ) ), this, SLOT( expandRequest( QModelIndex ) ), Qt::QueuedConnection ); setModel( m_proxyModel ); @@ -246,6 +247,13 @@ SourceTreeView::selectRequest( const QModelIndex& idx ) } } +void +SourceTreeView::expandRequest( const QModelIndex &idx ) +{ + qDebug() << "Expanding idx" << idx; + expand( idx ); +} + void SourceTreeView::loadPlaylist() diff --git a/src/sourcetree/sourcetreeview.h b/src/sourcetree/sourcetreeview.h index 0e62deab6..3566895ff 100644 --- a/src/sourcetree/sourcetreeview.h +++ b/src/sourcetree/sourcetreeview.h @@ -49,6 +49,7 @@ private slots: void onItemExpanded( const QModelIndex& idx ); void onItemActivated( const QModelIndex& index ); void selectRequest( const QModelIndex& idx ); + void expandRequest( const QModelIndex& idx ); void loadPlaylist(); void deletePlaylist( const QModelIndex& = QModelIndex() ); @@ -73,6 +74,7 @@ protected: private: void setupMenus(); + int totalSize(const QModelIndex &parentIndex); template< typename T > T* itemFromIndex( const QModelIndex& index ) const;