From 1bf5787d748c49ca59e15abd1bce8872a93d348d Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 15 Feb 2013 11:13:05 +0100 Subject: [PATCH] Move ScriptCollection items to their own top-level category. --- src/libtomahawk/SourceList.cpp | 21 ++++----- src/libtomahawk/SourceList.h | 6 ++- src/sourcetree/SourcesModel.cpp | 76 +++++++++++++++++++++++++++++++-- src/sourcetree/SourcesModel.h | 9 ++++ 4 files changed, 97 insertions(+), 15 deletions(-) diff --git a/src/libtomahawk/SourceList.cpp b/src/libtomahawk/SourceList.cpp index 91ba0b831..90b687e8e 100644 --- a/src/libtomahawk/SourceList.cpp +++ b/src/libtomahawk/SourceList.cpp @@ -253,6 +253,14 @@ SourceList::count() const return m_sources.size(); } + +QList +SourceList::scriptCollections() const +{ + return m_scriptCollections; +} + + void SourceList::latchedOff( const source_ptr& to ) { @@ -305,26 +313,19 @@ SourceList::addScriptCollection( const collection_ptr& collection ) { m_scriptCollections.append( collection ); - matchSourceForScriptCollection( collection ); + emit scriptCollectionAdded( collection ); } void SourceList::removeScriptCollection( const collection_ptr& collection ) { - getLocal()->removeCollection( collection ); + emit scriptCollectionRemoved( collection ); + m_scriptCollections.removeAll( collection ); } -void -SourceList::matchSourceForScriptCollection( const collection_ptr& collection ) -{ - //TODO: implement for multi-collection resolvers - getLocal()->addCollection( collection ); -} - - void SourceList::latchedOn( const source_ptr& to ) { diff --git a/src/libtomahawk/SourceList.h b/src/libtomahawk/SourceList.h index 099adb68e..c38e8cbea 100644 --- a/src/libtomahawk/SourceList.h +++ b/src/libtomahawk/SourceList.h @@ -52,6 +52,8 @@ public: QList sources( bool onlyOnline = false ) const; unsigned int count() const; + QList scriptCollections() const; + Tomahawk::source_ptr get( const QString& username, const QString& friendlyName = QString(), bool autoCreate = false ); Tomahawk::source_ptr get( int id ) const; @@ -69,6 +71,9 @@ signals: void sourceAdded( const Tomahawk::source_ptr& ); void sourceRemoved( const Tomahawk::source_ptr& ); + void scriptCollectionAdded( const Tomahawk::collection_ptr& ); + void scriptCollectionRemoved( const Tomahawk::collection_ptr& ); + void sourceLatchedOn( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to ); void sourceLatchedOff( const Tomahawk::source_ptr& from, const Tomahawk::source_ptr& to ); @@ -84,7 +89,6 @@ private slots: private: void add( const Tomahawk::source_ptr& source ); - void matchSourceForScriptCollection( const Tomahawk::collection_ptr& collection ); QMap< QString, Tomahawk::source_ptr > m_sources; QMap< int, QString > m_sources_id2name; diff --git a/src/sourcetree/SourcesModel.cpp b/src/sourcetree/SourcesModel.cpp index 7a3ed0325..312db4d1d 100644 --- a/src/sourcetree/SourcesModel.cpp +++ b/src/sourcetree/SourcesModel.cpp @@ -58,9 +58,22 @@ SourcesModel::SourcesModel( QObject* parent ) appendGroups(); onSourcesAdded( SourceList::instance()->sources() ); - connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); - connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), SLOT( onSourceRemoved( Tomahawk::source_ptr ) ) ); - connect( ViewManager::instance(), SIGNAL( viewPageActivated( Tomahawk::ViewPage* ) ), this, SLOT( viewPageActivated( Tomahawk::ViewPage* ) ) ); + connect( SourceList::instance(), SIGNAL( sourceAdded( Tomahawk::source_ptr ) ), + SLOT( onSourceAdded( Tomahawk::source_ptr ) ) ); + connect( SourceList::instance(), SIGNAL( sourceRemoved( Tomahawk::source_ptr ) ), + SLOT( onSourceRemoved( Tomahawk::source_ptr ) ) ); + connect( ViewManager::instance(), SIGNAL( viewPageActivated( Tomahawk::ViewPage* ) ), + this, SLOT( viewPageActivated( Tomahawk::ViewPage* ) ) ); + + foreach ( const collection_ptr& c, SourceList::instance()->scriptCollections() ) + { + onScriptCollectionAdded( c ); + } + + connect( SourceList::instance(), SIGNAL( scriptCollectionAdded( Tomahawk::collection_ptr ) ), + this, SLOT( onScriptCollectionAdded( Tomahawk::collection_ptr ) ) ); + connect( SourceList::instance(), SIGNAL( scriptCollectionRemoved( Tomahawk::collection_ptr ) ), + this, SLOT( onScriptCollectionRemoved( Tomahawk::collection_ptr ) ) ); } @@ -275,7 +288,7 @@ SourcesModel::flags( const QModelIndex& index ) const void SourcesModel::appendGroups() { - beginInsertRows( QModelIndex(), rowCount(), rowCount() + 3 ); + beginInsertRows( QModelIndex(), rowCount(), rowCount() + 4 ); GroupItem* browse = new GroupItem( this, m_rootItem, tr( "Browse" ), 0 ); new HistoryItem( this, m_rootItem, tr( "Search History" ), 1 ); @@ -314,6 +327,8 @@ SourcesModel::appendGroups() m_collectionsGroup = new GroupItem( this, m_rootItem, tr( "Friends" ), 4 ); + m_cloudGroup = new GroupItem( this, m_rootItem, tr( "Cloud" ), 5 ); + endInsertRows(); } @@ -492,6 +507,59 @@ SourcesModel::onSourceRemoved( const source_ptr& source ) } +void +SourcesModel::onScriptCollectionAdded( const collection_ptr& collection ) +{ + if ( m_scriptCollections.contains( collection ) ) + return; + + QModelIndex parent = indexFromItem( m_cloudGroup ); + beginInsertRows( parent, rowCount( parent ), rowCount( parent ) ); + GenericPageItem* item = new GenericPageItem( this, + m_cloudGroup, + collection->itemName(), + collection->icon(), + boost::bind( &SourcesModel::scriptCollectionClicked, this, collection ), + boost::bind( &SourcesModel::getScriptCollectionPage, this, collection ) ); + endInsertRows(); + + m_scriptCollections.insert( collection, item ); + m_cloudGroup->checkExpandedState(); +} + + +void +SourcesModel::onScriptCollectionRemoved( const collection_ptr& collection ) +{ + SourceTreeItem* item = m_scriptCollections.value( collection ); + int row = indexFromItem( item ).row(); + + QModelIndex parent = indexFromItem( m_cloudGroup ); + beginRemoveRows( parent, row, row ); + m_cloudGroup->removeChild( item ); + endRemoveRows(); + + m_scriptCollectionPages.remove( collection ); + m_scriptCollections.remove( collection ); + item->deleteLater(); +} + + +ViewPage* +SourcesModel::scriptCollectionClicked( const Tomahawk::collection_ptr& collection ) +{ + m_scriptCollectionPages[ collection ] = ViewManager::instance()->show( collection ); + return m_scriptCollectionPages[ collection ]; +} + + +ViewPage* +SourcesModel::getScriptCollectionPage( const Tomahawk::collection_ptr& collection ) const +{ + return m_scriptCollectionPages[ collection ]; +} + + void SourcesModel::itemUpdated() { diff --git a/src/sourcetree/SourcesModel.h b/src/sourcetree/SourcesModel.h index 03ed2dd43..80c1f55b7 100644 --- a/src/sourcetree/SourcesModel.h +++ b/src/sourcetree/SourcesModel.h @@ -135,6 +135,12 @@ private slots: void onSourceAdded( const Tomahawk::source_ptr& source ); void onSourceRemoved( const Tomahawk::source_ptr& source ); + void onScriptCollectionAdded( const Tomahawk::collection_ptr& collection ); + void onScriptCollectionRemoved( const Tomahawk::collection_ptr& collection ); + + Tomahawk::ViewPage* scriptCollectionClicked( const Tomahawk::collection_ptr& collection ); + Tomahawk::ViewPage* getScriptCollectionPage( const Tomahawk::collection_ptr& collection ) const; + void onWidgetDestroyed( QWidget* w ); private: @@ -145,9 +151,12 @@ private: SourceTreeItem* m_rootItem; GroupItem* m_collectionsGroup; GroupItem* m_myMusicGroup; + GroupItem* m_cloudGroup; QList< Tomahawk::source_ptr > m_sourcesWithViewPage; QHash< Tomahawk::source_ptr, SourceTreeItem* > m_sourcesWithViewPageItems; + QHash< Tomahawk::collection_ptr, SourceTreeItem* > m_scriptCollections; + QHash< Tomahawk::collection_ptr, Tomahawk::ViewPage* > m_scriptCollectionPages; QHash< Tomahawk::ViewPage*, SourceTreeItem* > m_sourceTreeLinks; Tomahawk::ViewPage* m_viewPageDelayedCacheItem;