mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-21 00:09:47 +01:00
Have SourceList populate the local source with ScriptCollections.
This commit is contained in:
parent
32780f79a0
commit
df5fa2c55f
@ -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* ) ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://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
|
||||
* 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 )
|
||||
{
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* === This file is part of Tomahawk Player - <http://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
|
||||
* 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;
|
||||
|
@ -513,7 +513,6 @@ QtScriptResolver::stop()
|
||||
{
|
||||
emit collectionRemoved( collection );
|
||||
}
|
||||
m_collections.clear();
|
||||
|
||||
Tomahawk::Pipeline::instance()->removeResolver( this );
|
||||
emit stopped();
|
||||
|
@ -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() );
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user