1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 14:16:32 +02:00

Have SourceList populate the local source with ScriptCollections.

This commit is contained in:
Teo Mrnjavac
2013-01-22 19:54:17 +01:00
parent 32780f79a0
commit df5fa2c55f
7 changed files with 95 additions and 5 deletions

View File

@@ -26,6 +26,7 @@
#include "resolvers/ScriptResolver.h" #include "resolvers/ScriptResolver.h"
#include "resolvers/QtScriptResolver.h" #include "resolvers/QtScriptResolver.h"
#include "Source.h" #include "Source.h"
#include "SourceList.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@@ -59,6 +60,11 @@ Pipeline::Pipeline( QObject* parent )
m_temporaryQueryTimer.setInterval( CLEANUP_TIMEOUT ); m_temporaryQueryTimer.setInterval( CLEANUP_TIMEOUT );
connect( &m_temporaryQueryTimer, SIGNAL( timeout() ), SLOT( onTemporaryQueryTimer() ) ); 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* ) ) );
} }

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -24,6 +25,8 @@
#include "network/RemoteCollection.h" #include "network/RemoteCollection.h"
#include "network/ControlConnection.h" #include "network/ControlConnection.h"
#include "infosystem/InfoSystemCache.h" #include "infosystem/InfoSystemCache.h"
#include "ExternalResolver.h"
#include "resolvers/ScriptCollection.h"
#include "utils/Logger.h" #include "utils/Logger.h"
@@ -259,6 +262,69 @@ SourceList::latchedOff( const source_ptr& to )
emit sourceLatchedOff( source, 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 void
SourceList::latchedOn( const source_ptr& to ) SourceList::latchedOn( const source_ptr& to )
{ {

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * 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 createPlaylist( const Tomahawk::source_ptr& src, const QVariant& contents );
void createDynamicPlaylist( 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: signals:
void ready(); void ready();
@@ -75,12 +79,18 @@ private slots:
void latchedOn( const Tomahawk::source_ptr& ); void latchedOn( const Tomahawk::source_ptr& );
void latchedOff( 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: private:
void add( const Tomahawk::source_ptr& source ); void add( const Tomahawk::source_ptr& source );
void matchSourceForScriptCollection( const Tomahawk::collection_ptr& collection );
QMap< QString, Tomahawk::source_ptr > m_sources; QMap< QString, Tomahawk::source_ptr > m_sources;
QMap< int, QString > m_sources_id2name; QMap< int, QString > m_sources_id2name;
QList< Tomahawk::collection_ptr > m_scriptCollections;
bool m_isReady; bool m_isReady;
Tomahawk::source_ptr m_local; Tomahawk::source_ptr m_local;
Tomahawk::source_ptr m_dummy; Tomahawk::source_ptr m_dummy;

View File

@@ -513,7 +513,6 @@ QtScriptResolver::stop()
{ {
emit collectionRemoved( collection ); emit collectionRemoved( collection );
} }
m_collections.clear();
Tomahawk::Pipeline::instance()->removeResolver( this ); Tomahawk::Pipeline::instance()->removeResolver( this );
emit stopped(); emit stopped();

View File

@@ -45,5 +45,7 @@ ScriptCollection::~ScriptCollection()
QString QString
ScriptCollection::prettyName() const 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() );
} }

View File

@@ -43,6 +43,8 @@ public:
virtual QString prettyName() const; virtual QString prettyName() const;
virtual QString type() const { return "scriptcollection"; } virtual QString type() const { return "scriptcollection"; }
virtual ExternalResolver* resolver() { return m_resolver; }
private: private:
ExternalResolver* m_resolver; ExternalResolver* m_resolver;

View File

@@ -315,11 +315,16 @@ SourceItem::onCollectionAdded( const collection_ptr& collection )
void void
SourceItem::onCollectionRemoved( const collection_ptr& collection ) SourceItem::onCollectionRemoved( const collection_ptr& collection )
{ {
delete m_collectionPages.value( collection, 0 ); GenericPageItem* item = m_collectionItems.value( collection );
m_collectionPages.remove( 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 ); m_collectionItems.remove( collection );
item->deleteLater();
} }