From df5fa2c55f8c130e2fc529f318ea59976e04e0a1 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Tue, 22 Jan 2013 19:54:17 +0100 Subject: [PATCH] Have SourceList populate the local source with ScriptCollections. --- src/libtomahawk/Pipeline.cpp | 6 ++ src/libtomahawk/SourceList.cpp | 66 +++++++++++++++++++ src/libtomahawk/SourceList.h | 10 +++ .../resolvers/QtScriptResolver.cpp | 1 - .../resolvers/ScriptCollection.cpp | 4 +- src/libtomahawk/resolvers/ScriptCollection.h | 2 + src/sourcetree/items/SourceItem.cpp | 11 +++- 7 files changed, 95 insertions(+), 5 deletions(-) diff --git a/src/libtomahawk/Pipeline.cpp b/src/libtomahawk/Pipeline.cpp index dfd7bd07b..88a2f9fc9 100644 --- a/src/libtomahawk/Pipeline.cpp +++ b/src/libtomahawk/Pipeline.cpp @@ -26,6 +26,7 @@ #include "resolvers/ScriptResolver.h" #include "resolvers/QtScriptResolver.h" #include "Source.h" +#include "SourceList.h" #include "utils/Logger.h" @@ -59,6 +60,11 @@ Pipeline::Pipeline( QObject* parent ) m_temporaryQueryTimer.setInterval( CLEANUP_TIMEOUT ); connect( &m_temporaryQueryTimer, SIGNAL( timeout() ), SLOT( onTemporaryQueryTimer() ) ); + + connect( this, SIGNAL( resolverAdded( Tomahawk::Resolver* ) ), + SourceList::instance(), SLOT( onResolverAdded( Tomahawk::Resolver* ) ) ); + connect( this, SIGNAL( resolverRemoved( Tomahawk::Resolver* ) ), + SourceList::instance(), SLOT( onResolverRemoved( Tomahawk::Resolver* ) ) ); } diff --git a/src/libtomahawk/SourceList.cpp b/src/libtomahawk/SourceList.cpp index a0204a19e..2d2fd378d 100644 --- a/src/libtomahawk/SourceList.cpp +++ b/src/libtomahawk/SourceList.cpp @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +25,8 @@ #include "network/RemoteCollection.h" #include "network/ControlConnection.h" #include "infosystem/InfoSystemCache.h" +#include "ExternalResolver.h" +#include "resolvers/ScriptCollection.h" #include "utils/Logger.h" @@ -259,6 +262,69 @@ SourceList::latchedOff( const source_ptr& to ) emit sourceLatchedOff( source, to ); } + +void +SourceList::onResolverAdded( Resolver* resolver ) +{ + ExternalResolver* r = qobject_cast< ExternalResolver* >( resolver ); + if ( r == 0 ) + return; + + foreach ( const Tomahawk::collection_ptr& collection, r->collections() ) + { + addScriptCollection( collection ); + } + + connect( r, SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ), + this, SLOT( addScriptCollection( Tomahawk::collection_ptr ) ) ); + connect( r, SIGNAL( collectionRemoved(Tomahawk::collection_ptr) ), + this, SLOT( removeScriptCollection( Tomahawk::collection_ptr ) ) ); +} + + +void +SourceList::onResolverRemoved( Resolver* resolver ) +{ + ExternalResolver* r = qobject_cast< ExternalResolver* >( resolver ); + if ( r == 0 ) + return; + + foreach ( const Tomahawk::collection_ptr& collection, m_scriptCollections ) + if ( qobject_cast< ScriptCollection* >( collection.data() )->resolver() == r ) + removeScriptCollection( collection ); + + disconnect( r, SIGNAL( collectionAdded( Tomahawk::collection_ptr ) ), + this, SLOT( addScriptCollection( Tomahawk::collection_ptr ) ) ); + disconnect( r, SIGNAL( collectionRemoved(Tomahawk::collection_ptr) ), + this, SLOT( removeScriptCollection( Tomahawk::collection_ptr ) ) ); +} + + +void +SourceList::addScriptCollection( const collection_ptr& collection ) +{ + m_scriptCollections.append( collection ); + + matchSourceForScriptCollection( collection ); +} + + +void +SourceList::removeScriptCollection( const collection_ptr& collection ) +{ + getLocal()->removeCollection( 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 618fa2d90..099adb68e 100644 --- a/src/libtomahawk/SourceList.h +++ b/src/libtomahawk/SourceList.h @@ -1,6 +1,7 @@ /* === This file is part of Tomahawk Player - === * * Copyright 2010-2011, Christian Muehlhaeuser + * Copyright 2013, Teo Mrnjavac * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,6 +60,9 @@ public slots: void createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ); void createDynamicPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents ); + void onResolverAdded( Tomahawk::Resolver* resolver ); + void onResolverRemoved( Tomahawk::Resolver* resolver ); + signals: void ready(); @@ -75,12 +79,18 @@ private slots: void latchedOn( const Tomahawk::source_ptr& ); void latchedOff( const Tomahawk::source_ptr& ); + void addScriptCollection( const Tomahawk::collection_ptr& collection ); + void removeScriptCollection( const Tomahawk::collection_ptr& collection ); + 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; + QList< Tomahawk::collection_ptr > m_scriptCollections; + bool m_isReady; Tomahawk::source_ptr m_local; Tomahawk::source_ptr m_dummy; diff --git a/src/libtomahawk/resolvers/QtScriptResolver.cpp b/src/libtomahawk/resolvers/QtScriptResolver.cpp index 66e5546b8..7b66798aa 100644 --- a/src/libtomahawk/resolvers/QtScriptResolver.cpp +++ b/src/libtomahawk/resolvers/QtScriptResolver.cpp @@ -513,7 +513,6 @@ QtScriptResolver::stop() { emit collectionRemoved( collection ); } - m_collections.clear(); Tomahawk::Pipeline::instance()->removeResolver( this ); emit stopped(); diff --git a/src/libtomahawk/resolvers/ScriptCollection.cpp b/src/libtomahawk/resolvers/ScriptCollection.cpp index e9e062c5c..c1b0ce8d1 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.cpp +++ b/src/libtomahawk/resolvers/ScriptCollection.cpp @@ -45,5 +45,7 @@ ScriptCollection::~ScriptCollection() QString ScriptCollection::prettyName() const { - return QString(); + return tr( "%1 Collection", + "Name of a collection based on a resolver, e.g. Subsonic Collection" ) + .arg( m_resolver->name() ); } diff --git a/src/libtomahawk/resolvers/ScriptCollection.h b/src/libtomahawk/resolvers/ScriptCollection.h index b4162872f..3e71e54d6 100644 --- a/src/libtomahawk/resolvers/ScriptCollection.h +++ b/src/libtomahawk/resolvers/ScriptCollection.h @@ -43,6 +43,8 @@ public: virtual QString prettyName() const; virtual QString type() const { return "scriptcollection"; } + virtual ExternalResolver* resolver() { return m_resolver; } + private: ExternalResolver* m_resolver; diff --git a/src/sourcetree/items/SourceItem.cpp b/src/sourcetree/items/SourceItem.cpp index 4cf96fcb7..382bb6983 100644 --- a/src/sourcetree/items/SourceItem.cpp +++ b/src/sourcetree/items/SourceItem.cpp @@ -315,11 +315,16 @@ SourceItem::onCollectionAdded( const collection_ptr& collection ) void SourceItem::onCollectionRemoved( const collection_ptr& collection ) { - delete m_collectionPages.value( collection, 0 ); - m_collectionPages.remove( collection ); + GenericPageItem* item = m_collectionItems.value( collection ); + int row = model()->indexFromItem( item ).row(); - m_collectionItems.value( collection )->deleteLater(); + beginRowsRemoved( row, row ); + removeChild( item ); + endRowsRemoved(); + + m_collectionPages.remove( collection ); m_collectionItems.remove( collection ); + item->deleteLater(); }