mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-10 16:14:40 +02:00
Allow script resolvers to choose icons for their scriptcollections.
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <QImageReader>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
@@ -925,16 +926,71 @@ QtScriptResolver::loadCollections()
|
|||||||
sc->setTrackCount( trackCount );
|
sc->setTrackCount( trackCount );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( collectionInfo.contains( "iconfile" ) )
|
||||||
|
{
|
||||||
|
bool ok = false;
|
||||||
|
QString iconPath = QFileInfo( filePath() ).path() + "/"
|
||||||
|
+ collectionInfo.value( "iconfile" ).toString();
|
||||||
|
|
||||||
|
QPixmap iconPixmap;
|
||||||
|
ok = iconPixmap.load( iconPath );
|
||||||
|
if ( ok && !iconPixmap.isNull() )
|
||||||
|
sc->setIcon( QIcon( iconPixmap ) );
|
||||||
|
}
|
||||||
|
|
||||||
Tomahawk::collection_ptr collection( sc );
|
Tomahawk::collection_ptr collection( sc );
|
||||||
|
|
||||||
m_collections.insert( collection->name(), collection );
|
m_collections.insert( collection->name(), collection );
|
||||||
emit collectionAdded( collection );
|
emit collectionAdded( collection );
|
||||||
|
|
||||||
|
if ( collectionInfo.contains( "iconurl" ) )
|
||||||
|
{
|
||||||
|
QString iconUrlString = collectionInfo.value( "iconurl" ).toString();
|
||||||
|
if ( !iconUrlString.isEmpty() )
|
||||||
|
{
|
||||||
|
QUrl iconUrl = QUrl::fromEncoded( iconUrlString.toLatin1() );
|
||||||
|
if ( iconUrl.isValid() )
|
||||||
|
{
|
||||||
|
QNetworkRequest req( iconUrl );
|
||||||
|
tDebug() << "Creating a QNetworkReply with url:" << req.url().toString();
|
||||||
|
QNetworkReply* reply = TomahawkUtils::nam()->get( req );
|
||||||
|
reply->setProperty( "collectionName", collection->name() );
|
||||||
|
|
||||||
|
connect( reply, SIGNAL( finished() ),
|
||||||
|
this, SLOT( onCollectionIconFetched() ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: implement multiple collections from a resolver
|
//TODO: implement multiple collections from a resolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
QtScriptResolver::onCollectionIconFetched()
|
||||||
|
{
|
||||||
|
QNetworkReply* reply = qobject_cast< QNetworkReply* >( sender() );
|
||||||
|
if ( reply != 0 )
|
||||||
|
{
|
||||||
|
Tomahawk::collection_ptr collection;
|
||||||
|
collection = m_collections.value( reply->property( "collectionName" ).toString() );
|
||||||
|
if ( !collection.isNull() )
|
||||||
|
{
|
||||||
|
if ( reply->error() == QNetworkReply::NoError )
|
||||||
|
{
|
||||||
|
QImageReader imageReader( reply );
|
||||||
|
QPixmap collectionIcon = QPixmap::fromImageReader( &imageReader );
|
||||||
|
|
||||||
|
if ( !collectionIcon.isNull() )
|
||||||
|
qobject_cast< Tomahawk::ScriptCollection* >( collection.data() )->setIcon( collectionIcon );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reply->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QVariantMap
|
QVariantMap
|
||||||
QtScriptResolver::resolverSettings()
|
QtScriptResolver::resolverSettings()
|
||||||
{
|
{
|
||||||
|
@@ -181,6 +181,9 @@ public slots:
|
|||||||
signals:
|
signals:
|
||||||
void stopped();
|
void stopped();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onCollectionIconFetched();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
@@ -27,7 +27,6 @@
|
|||||||
#include "resolvers/ScriptCommand_AllAlbums.h"
|
#include "resolvers/ScriptCommand_AllAlbums.h"
|
||||||
#include "resolvers/ScriptCommand_AllTracks.h"
|
#include "resolvers/ScriptCommand_AllTracks.h"
|
||||||
|
|
||||||
#include <QIcon>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
@@ -45,6 +44,12 @@ ScriptCollection::ScriptCollection( const source_ptr& source,
|
|||||||
m_resolver = resolver;
|
m_resolver = resolver;
|
||||||
|
|
||||||
m_servicePrettyName = m_resolver->name();
|
m_servicePrettyName = m_resolver->name();
|
||||||
|
|
||||||
|
ExternalResolverGui* gResolver = qobject_cast< ExternalResolverGui* >( m_resolver );
|
||||||
|
if ( gResolver )
|
||||||
|
{
|
||||||
|
m_icon = gResolver->icon();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -77,15 +82,18 @@ ScriptCollection::itemName() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScriptCollection::setIcon( const QIcon& icon )
|
||||||
|
{
|
||||||
|
m_icon = icon;
|
||||||
|
emit changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QIcon
|
QIcon
|
||||||
ScriptCollection::icon() const
|
ScriptCollection::icon() const
|
||||||
{
|
{
|
||||||
ExternalResolverGui* gResolver = qobject_cast< ExternalResolverGui* >( m_resolver );
|
return m_icon;
|
||||||
if ( gResolver )
|
|
||||||
{
|
|
||||||
return gResolver->icon();
|
|
||||||
}
|
|
||||||
return QIcon();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -28,6 +28,8 @@
|
|||||||
#include "Typedefs.h"
|
#include "Typedefs.h"
|
||||||
#include "DllMacro.h"
|
#include "DllMacro.h"
|
||||||
|
|
||||||
|
#include <QIcon>
|
||||||
|
|
||||||
|
|
||||||
namespace Tomahawk
|
namespace Tomahawk
|
||||||
{
|
{
|
||||||
@@ -55,6 +57,8 @@ public:
|
|||||||
virtual QString prettyName() const;
|
virtual QString prettyName() const;
|
||||||
virtual QString itemName() const;
|
virtual QString itemName() const;
|
||||||
virtual BackendType backendType() const { return ScriptCollectionType; }
|
virtual BackendType backendType() const { return ScriptCollectionType; }
|
||||||
|
|
||||||
|
virtual void setIcon( const QIcon& icon );
|
||||||
virtual QIcon icon() const;
|
virtual QIcon icon() const;
|
||||||
virtual QPixmap bigIcon() const;
|
virtual QPixmap bigIcon() const;
|
||||||
|
|
||||||
@@ -75,6 +79,7 @@ private:
|
|||||||
QString m_servicePrettyName;
|
QString m_servicePrettyName;
|
||||||
QString m_description;
|
QString m_description;
|
||||||
int m_trackCount;
|
int m_trackCount;
|
||||||
|
QIcon m_icon;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //ns
|
} //ns
|
||||||
|
Reference in New Issue
Block a user