/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. #ifndef ECHONEST_GENERATOR_H
  19. #define ECHONEST_GENERATOR_H
  20. #include <stdexcept>
  21. #include "playlist/dynamic/GeneratorInterface.h"
  22. #include "playlist/dynamic/GeneratorFactory.h"
  23. #include "playlist/dynamic/DynamicControl.h"
  24. #include "database/DatabaseCommand_CollectionAttributes.h"
  25. #include "DllMacro.h"
  26. #include <echonest5/Playlist.h>
  27. #include <echonest5/Genre.h>
  28. namespace Tomahawk
  29. {
  30. class EchonestSteerer;
  31. class CatalogManager : public QObject
  32. {
  33. Q_OBJECT
  34. public:
  35. CatalogManager( QObject* parent );
  36. QHash< QString, QString > catalogs() const;
  37. signals:
  38. void catalogsUpdated();
  39. private slots:
  40. void init();
  41. void doCatalogUpdate();
  42. void collectionAttributes( const PairList& );
  43. private:
  44. QHash< QString, QString > m_catalogs;
  45. };
  46. class DLLEXPORT EchonestFactory : public GeneratorFactoryInterface
  47. {
  48. public:
  49. EchonestFactory();
  50. virtual GeneratorInterface* create();
  51. virtual dyncontrol_ptr createControl( const QString& controlType = QString() );
  52. virtual QStringList typeSelectors() const;
  53. };
  54. class DLLEXPORT EchonestGenerator : public GeneratorInterface
  55. {
  56. Q_OBJECT
  57. public:
  58. explicit EchonestGenerator( QObject* parent = 0 );
  59. virtual ~EchonestGenerator();
  60. virtual dyncontrol_ptr createControl( const QString& type = QString() );
  61. virtual QPixmap logo();
  62. virtual void generate ( int number = -1 );
  63. virtual void startOnDemand();
  64. virtual void fetchNext( int rating = -1 );
  65. virtual QString sentenceSummary();
  66. virtual bool onDemandSteerable() const { return false; }
  67. virtual QWidget* steeringWidget() { return 0; }
  68. static QStringList styles();
  69. static QStringList moods();
  70. static QStringList genres();
  71. static QStringList userCatalogs();
  72. static QByteArray catalogId( const QString& collectionId );
  73. static void setupCatalogs();
  74. signals:
  75. void paramsGenerated( const Echonest::DynamicPlaylist::PlaylistParams& );
  76. void stylesSaved();
  77. void moodsSaved();
  78. void genresSaved();
  79. private slots:
  80. void staticFinished();
  81. void dynamicStarted();
  82. void dynamicFetched();
  83. void doGenerate( const Echonest::DynamicPlaylist::PlaylistParams& params );
  84. void doStartOnDemand( const Echonest::DynamicPlaylist::PlaylistParams& params );
  85. void loadStyles();
  86. void loadMoods();
  87. void loadGenres();
  88. void stylesReceived();
  89. void moodsReceived();
  90. void genresReceived();
  91. void knownCatalogsChanged();
  92. void songLookupFinished();
  93. private:
  94. // get result from signal paramsGenerated
  95. void getParams() throw( std::runtime_error );
  96. query_ptr queryFromSong( const Echonest::Song& song );
  97. Echonest::DynamicPlaylist::ArtistTypeEnum appendRadioType( Echonest::DynamicPlaylist::PlaylistParams& params ) const throw( std::runtime_error );
  98. bool onlyThisArtistType( Echonest::DynamicPlaylist::ArtistTypeEnum type ) const throw( std::runtime_error );
  99. void loadStylesMoodsAndGenres();
  100. Echonest::DynamicPlaylist* m_dynPlaylist;
  101. QPixmap m_logo;
  102. static QStringList s_styles;
  103. static QStringList s_moods;
  104. static QStringList s_genres;
  105. static QNetworkReply* s_stylesJob;
  106. static QNetworkReply* s_moodsJob;
  107. static QNetworkReply* s_genresJob;
  108. static CatalogManager* s_catalogs;
  109. // used for the intermediary song id lookup
  110. QSet< QNetworkReply* > m_waiting;
  111. Echonest::DynamicPlaylist::PlaylistParams m_storedParams;
  112. };
  113. };
  114. #endif