PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 10ms RepoModel.GetById 30ms app.codeStats 0ms

/src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h

http://github.com/tomahawk-player/tomahawk
C Header | 147 lines | 95 code | 33 blank | 19 comment | 0 complexity | 50ad706296ed7283dd590d02f2a379b1 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  4 *
  5 *   Tomahawk is free software: you can redistribute it and/or modify
  6 *   it under the terms of the GNU General Public License as published by
  7 *   the Free Software Foundation, either version 3 of the License, or
  8 *   (at your option) any later version.
  9 *
 10 *   Tomahawk is distributed in the hope that it will be useful,
 11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 13 *   GNU General Public License for more details.
 14 *
 15 *   You should have received a copy of the GNU General Public License
 16 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19#ifndef ECHONEST_GENERATOR_H
 20#define ECHONEST_GENERATOR_H
 21
 22#include <stdexcept>
 23
 24#include "playlist/dynamic/GeneratorInterface.h"
 25#include "playlist/dynamic/GeneratorFactory.h"
 26#include "playlist/dynamic/DynamicControl.h"
 27#include "database/DatabaseCommand_CollectionAttributes.h"
 28
 29#include "DllMacro.h"
 30
 31#include <echonest5/Playlist.h>
 32#include <echonest5/Genre.h>
 33
 34namespace Tomahawk
 35{
 36
 37class EchonestSteerer;
 38
 39class CatalogManager : public QObject
 40{
 41    Q_OBJECT
 42public:
 43    CatalogManager( QObject* parent );
 44
 45    QHash< QString, QString > catalogs() const;
 46
 47signals:
 48   void catalogsUpdated();
 49
 50private slots:
 51    void init();
 52    void doCatalogUpdate();
 53    void collectionAttributes( const PairList& );
 54
 55private:
 56    QHash< QString, QString > m_catalogs;
 57};
 58
 59class DLLEXPORT EchonestFactory : public GeneratorFactoryInterface
 60{
 61public:
 62    EchonestFactory();
 63
 64    virtual GeneratorInterface* create();
 65    virtual dyncontrol_ptr createControl( const QString& controlType = QString() );
 66    virtual QStringList typeSelectors() const;
 67};
 68
 69class DLLEXPORT EchonestGenerator : public GeneratorInterface
 70{
 71    Q_OBJECT
 72public:
 73    explicit EchonestGenerator( QObject* parent = 0 );
 74    virtual ~EchonestGenerator();
 75
 76    virtual dyncontrol_ptr createControl( const QString& type = QString() );
 77    virtual QPixmap logo();
 78    virtual void generate ( int number = -1 );
 79    virtual void startOnDemand();
 80    virtual void fetchNext( int rating = -1 );
 81    virtual QString sentenceSummary();
 82    virtual bool onDemandSteerable() const { return false; }
 83    virtual QWidget* steeringWidget() { return 0; }
 84
 85    static QStringList styles();
 86    static QStringList moods();
 87    static QStringList genres();
 88    static QStringList userCatalogs();
 89    static QByteArray catalogId( const QString& collectionId );
 90
 91    static void setupCatalogs();
 92signals:
 93    void paramsGenerated( const Echonest::DynamicPlaylist::PlaylistParams& );
 94
 95    void stylesSaved();
 96    void moodsSaved();
 97    void genresSaved();
 98
 99private slots:
100    void staticFinished();
101    void dynamicStarted();
102    void dynamicFetched();
103
104    void doGenerate( const Echonest::DynamicPlaylist::PlaylistParams& params );
105    void doStartOnDemand( const Echonest::DynamicPlaylist::PlaylistParams& params );
106
107    void loadStyles();
108    void loadMoods();
109    void loadGenres();
110
111    void stylesReceived();
112    void moodsReceived();
113    void genresReceived();
114    void knownCatalogsChanged();
115
116    void songLookupFinished();
117private:
118    // get result from signal paramsGenerated
119    void getParams() throw( std::runtime_error );
120
121    query_ptr queryFromSong( const Echonest::Song& song );
122    Echonest::DynamicPlaylist::ArtistTypeEnum appendRadioType( Echonest::DynamicPlaylist::PlaylistParams& params ) const throw( std::runtime_error );
123    bool onlyThisArtistType( Echonest::DynamicPlaylist::ArtistTypeEnum type ) const throw( std::runtime_error );
124
125    void loadStylesMoodsAndGenres();
126
127    Echonest::DynamicPlaylist* m_dynPlaylist;
128    QPixmap m_logo;
129
130    static QStringList s_styles;
131    static QStringList s_moods;
132    static QStringList s_genres;
133    static QNetworkReply* s_stylesJob;
134    static QNetworkReply* s_moodsJob;
135    static QNetworkReply* s_genresJob;
136
137    static CatalogManager* s_catalogs;
138
139    // used for the intermediary song id lookup
140    QSet< QNetworkReply* > m_waiting;
141    Echonest::DynamicPlaylist::PlaylistParams m_storedParams;
142};
143
144};
145
146#endif
147