mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 07:07:05 +02:00
Update collection metadata when reregistering it
This commit is contained in:
@@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
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
|
void
|
||||||
ScriptCollection::fetchIcon( const QString& iconUrlString )
|
ScriptCollection::fetchIcon( const QString& iconUrlString )
|
||||||
{
|
{
|
||||||
|
@@ -85,6 +85,10 @@ public:
|
|||||||
void setTrackCount( int count );
|
void setTrackCount( int count );
|
||||||
int trackCount() const override;
|
int trackCount() const override;
|
||||||
|
|
||||||
|
const QVariantMap readMetaData();
|
||||||
|
void parseMetaData();
|
||||||
|
void parseMetaData( const QVariantMap& metadata );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onIconFetched();
|
void onIconFetched();
|
||||||
|
|
||||||
|
@@ -20,12 +20,13 @@
|
|||||||
#include "SourceList.h"
|
#include "SourceList.h"
|
||||||
#include "../ScriptAccount.h"
|
#include "../ScriptAccount.h"
|
||||||
|
|
||||||
#include <QFileInfo>
|
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
void ScriptCollectionFactory::addPlugin( const QSharedPointer<ScriptCollection>& collection ) const
|
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 );
|
SourceList::instance()->addScriptCollection( collection );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,38 +44,12 @@ const QSharedPointer< ScriptCollection > ScriptCollectionFactory::createPlugin(
|
|||||||
!collectionInfo.contains( "description" ) )
|
!collectionInfo.contains( "description" ) )
|
||||||
return QSharedPointer< ScriptCollection >();
|
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
|
// 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 );
|
Tomahawk::ScriptCollection* sc = new Tomahawk::ScriptCollection( object, SourceList::instance()->getLocal(), scriptAccount );
|
||||||
QSharedPointer<ScriptCollection> collection( sc );
|
QSharedPointer<ScriptCollection> collection( sc );
|
||||||
collection->setWeakRef( collection.toWeakRef() );
|
collection->setWeakRef( collection.toWeakRef() );
|
||||||
|
|
||||||
|
collection->parseMetaData( collectionInfo );
|
||||||
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() );
|
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user