diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestStation.cpp b/src/libtomahawk/playlist/dynamic/echonest/EchonestStation.cpp new file mode 100644 index 000000000..bd8d28c25 --- /dev/null +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestStation.cpp @@ -0,0 +1,56 @@ +#include "EchonestStation.h" + +#include "PlayableItem.h" +#include "audio/AudioEngine.h" + +namespace Tomahawk +{ + +EchonestStation::EchonestStation( PlayableProxyModel *model, geninterface_ptr generator, QObject *parent ) + : QObject(parent) + , m_model(model) + , m_generator(generator) +{ + +} + +Tomahawk::DynamicControl* EchonestStation::mainControl() { + foreach(dyncontrol_ptr control, m_generator->controls()) { + qDebug() << "got control" << control->selectedType(); + if(control->selectedType() == "Artist" || control->selectedType() == "Style") { + return control.data(); + } + } + return 0; +} + +bool EchonestStation::configured() +{ + return mainControl() != 0; +} + +void EchonestStation::playItem(int row) +{ + QModelIndex index( m_model->index( row, 0) ); + PlayableItem* item = m_model->itemFromIndex( index ); + if ( item && !item->query().isNull() ) + { + m_model->setCurrentIndex( index ); + AudioEngine::instance()->playItem( m_model->playlistInterface(), item->query() ); + } +} + +void EchonestStation::setMainControl(const QString &type) +{ + dyncontrol_ptr control = m_generator->createControl("echonest"); + control->setSelectedType("Style"); + control->setMatch("1"); + control->setInput(type); + qDebug() << "created control" << control->type() << control->selectedType() << control->match(); + m_generator->generate(20); + + emit configuredChanged(); +} + +} + diff --git a/src/libtomahawk/playlist/dynamic/echonest/EchonestStation.h b/src/libtomahawk/playlist/dynamic/echonest/EchonestStation.h new file mode 100644 index 000000000..aa402ab59 --- /dev/null +++ b/src/libtomahawk/playlist/dynamic/echonest/EchonestStation.h @@ -0,0 +1,35 @@ +#ifndef ECHONESTSTATION_H +#define ECHONESTSTATION_H + +#include "PlayableProxyModel.h" +#include "dynamic/GeneratorInterface.h" + +namespace Tomahawk +{ +class EchonestStation: public QObject +{ + Q_OBJECT + Q_PROPERTY(bool configured READ configured NOTIFY configuredChanged) + Q_PROPERTY(Tomahawk::DynamicControl* mainControl READ mainControl) + +public: + EchonestStation( PlayableProxyModel *model, geninterface_ptr generator, QObject *parent = 0); + + Tomahawk::DynamicControl* mainControl(); + bool configured(); + +public slots: + void playItem( int row ); + + void setMainControl(const QString &type); + +signals: + void configuredChanged(); + +private: + PlayableProxyModel *m_model; + geninterface_ptr m_generator; +}; +} + +#endif diff --git a/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp new file mode 100644 index 000000000..ce434b0ca --- /dev/null +++ b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.cpp @@ -0,0 +1,49 @@ +#include "DeclarativeCoverArtProvider.h" +#include "PlayableItem.h" +#include "playlist/PlayableProxyModel.h" +#include "Query.h" + +#include +#include +#include + +namespace Tomahawk +{ + +DeclarativeCoverArtProvider::DeclarativeCoverArtProvider( PlayableProxyModel *model ) + : QDeclarativeImageProvider( QDeclarativeImageProvider::Pixmap ) + , m_model( model ) +{ + +} + +DeclarativeCoverArtProvider::~DeclarativeCoverArtProvider() +{ +} + +QPixmap DeclarativeCoverArtProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) +{ + // We always can generate it in the requested size + int width = requestedSize.width() > 0 ? requestedSize.width() : 230; + int height = requestedSize.height() > 0 ? requestedSize.height() : 230; + + if( size ) + *size = QSize( width, height ); + + PlayableItem *item = m_model->itemFromIndex( id.toInt() ); + if( item ) { + qDebug() << "item:" << item; + qDebug() << "item2:" << item->artistName() << item->name(); + if ( !item->query().isNull() ) { + return item->query()->displayQuery()->cover( *size ); + } + } + + // TODO: create default cover art image + QPixmap pixmap( *size ); + pixmap.fill(); + + return pixmap; +} + +} diff --git a/src/libtomahawk/widgets/DeclarativeCoverArtProvider.h b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.h new file mode 100644 index 000000000..af3e3426f --- /dev/null +++ b/src/libtomahawk/widgets/DeclarativeCoverArtProvider.h @@ -0,0 +1,26 @@ +#ifndef DECLARATIVECOVERARTPROVIDER_H +#define DECLARATIVECOVERARTPROVIDER_H + + +#include "playlist/PlayableProxyModel.h" + +#include + + +namespace Tomahawk +{ + +class DeclarativeCoverArtProvider: public QDeclarativeImageProvider +{ +public: + DeclarativeCoverArtProvider( PlayableProxyModel *model ); + ~DeclarativeCoverArtProvider(); + + QPixmap requestPixmap( const QString &id, QSize *size, const QSize &requestedSize ); + +private: + PlayableProxyModel *m_model; +}; + +} +#endif // DECLARATIVECOVERARTPROVIDER_H