mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-04-22 08:52:12 +02:00
Update collection metadata when reregistering it
This commit is contained in:
parent
40c499303e
commit
f7f4901bbe
@ -30,6 +30,8 @@
|
||||
|
||||
#include <QImageReader>
|
||||
#include <QPainter>
|
||||
#include <QFileInfo>
|
||||
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
@ -183,6 +185,53 @@ ScriptCollection::trackCount() const
|
||||
}
|
||||
|
||||
|
||||
const QVariantMap
|
||||
ScriptCollection::readMetaData()
|
||||
{
|
||||
return scriptObject()->syncInvoke( "collection" ).toMap();
|
||||
}
|
||||
|
||||
|
||||
void ScriptCollection::parseMetaData()
|
||||
{
|
||||
return parseMetaData( readMetaData() );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCollection::parseMetaData( const QVariantMap& metadata )
|
||||
{
|
||||
tLog() << Q_FUNC_INFO;
|
||||
|
||||
const QString prettyname = metadata.value( "prettyname" ).toString();
|
||||
const QString desc = metadata.value( "description" ).toString();
|
||||
|
||||
setServiceName( prettyname );
|
||||
setDescription( desc );
|
||||
|
||||
if ( metadata.contains( "trackcount" ) ) //a resolver might not expose this
|
||||
{
|
||||
bool ok = false;
|
||||
int trackCount = metadata.value( "trackcount" ).toInt( &ok );
|
||||
if ( ok )
|
||||
setTrackCount( trackCount );
|
||||
}
|
||||
|
||||
if ( metadata.contains( "iconfile" ) )
|
||||
{
|
||||
QString iconPath = QFileInfo( scriptAccount()->filePath() ).path() + "/"
|
||||
+ metadata.value( "iconfile" ).toString();
|
||||
|
||||
QPixmap iconPixmap;
|
||||
bool ok = iconPixmap.load( iconPath );
|
||||
if ( ok && !iconPixmap.isNull() )
|
||||
setIcon( iconPixmap );
|
||||
|
||||
fetchIcon( metadata.value( "iconurl" ).toString() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ScriptCollection::fetchIcon( const QString& iconUrlString )
|
||||
{
|
||||
|
@ -85,6 +85,10 @@ public:
|
||||
void setTrackCount( int count );
|
||||
int trackCount() const override;
|
||||
|
||||
const QVariantMap readMetaData();
|
||||
void parseMetaData();
|
||||
void parseMetaData( const QVariantMap& metadata );
|
||||
|
||||
private slots:
|
||||
void onIconFetched();
|
||||
|
||||
|
@ -20,12 +20,13 @@
|
||||
#include "SourceList.h"
|
||||
#include "../ScriptAccount.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
using namespace Tomahawk;
|
||||
|
||||
void ScriptCollectionFactory::addPlugin( const QSharedPointer<ScriptCollection>& collection ) const
|
||||
{
|
||||
// FIXME: no need for the same javascript call, already done in createPlugin
|
||||
collection->parseMetaData();
|
||||
|
||||
SourceList::instance()->addScriptCollection( collection );
|
||||
}
|
||||
|
||||
@ -43,38 +44,12 @@ const QSharedPointer< ScriptCollection > ScriptCollectionFactory::createPlugin(
|
||||
!collectionInfo.contains( "description" ) )
|
||||
return QSharedPointer< ScriptCollection >();
|
||||
|
||||
const QString prettyname = collectionInfo.value( "prettyname" ).toString();
|
||||
const QString desc = collectionInfo.value( "description" ).toString();
|
||||
|
||||
// at this point we assume that all the tracks browsable through a resolver belong to the local source
|
||||
Tomahawk::ScriptCollection* sc = new Tomahawk::ScriptCollection( object, SourceList::instance()->getLocal(), scriptAccount );
|
||||
QSharedPointer<ScriptCollection> collection( sc );
|
||||
collection->setWeakRef( collection.toWeakRef() );
|
||||
|
||||
|
||||
sc->setServiceName( prettyname );
|
||||
sc->setDescription( desc );
|
||||
|
||||
if ( collectionInfo.contains( "trackcount" ) ) //a resolver might not expose this
|
||||
{
|
||||
bool ok = false;
|
||||
int trackCount = collectionInfo.value( "trackcount" ).toInt( &ok );
|
||||
if ( ok )
|
||||
sc->setTrackCount( trackCount );
|
||||
}
|
||||
|
||||
if ( collectionInfo.contains( "iconfile" ) )
|
||||
{
|
||||
QString iconPath = QFileInfo( scriptAccount->filePath() ).path() + "/"
|
||||
+ collectionInfo.value( "iconfile" ).toString();
|
||||
|
||||
QPixmap iconPixmap;
|
||||
bool ok = iconPixmap.load( iconPath );
|
||||
if ( ok && !iconPixmap.isNull() )
|
||||
sc->setIcon( iconPixmap );
|
||||
}
|
||||
|
||||
sc->fetchIcon( collectionInfo.value( "iconurl" ).toString() );
|
||||
collection->parseMetaData( collectionInfo );
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user