/thirdparty/liblastfm2/src/radio/RadioTuner.h

http://github.com/tomahawk-player/tomahawk · C Header · 85 lines · 39 code · 11 blank · 35 comment · 0 complexity · fc7723fbff89d8e2fc25369581cc1e45 MD5 · raw file

  1. /*
  2. Copyright 2009 Last.fm Ltd.
  3. - Primarily authored by Max Howell, Jono Cole and Doug Mansell
  4. This file is part of liblastfm.
  5. liblastfm 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. liblastfm is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef LASTFM_TUNER_H
  17. #define LASTFM_TUNER_H
  18. #include <lastfm/RadioStation>
  19. #include <lastfm/Track>
  20. #include <lastfm/Xspf>
  21. #include <lastfm/ws.h>
  22. #include <QList>
  23. namespace lastfm
  24. {
  25. /** With regard to error handling. We handle Ws::TryAgain up to 5 times,
  26. * don't try again after that! Just tell the user to try again later.
  27. */
  28. class LASTFM_DLLEXPORT RadioTuner : public QObject
  29. {
  30. Q_OBJECT
  31. public:
  32. /** You need to have assigned Ws::* for this to work, creating the tuner
  33. * automatically fetches the first 5 tracks for the station */
  34. explicit RadioTuner( const RadioStation& );
  35. Track takeNextTrack();
  36. void retune( const RadioStation& );
  37. signals:
  38. void title( const QString& );
  39. void supportsDisco( bool supportsDisco );
  40. void trackAvailable();
  41. void error( lastfm::ws::Error, const QString& message );
  42. private slots:
  43. void onTuneReturn();
  44. void onGetPlaylistReturn();
  45. void onXspfExpired();
  46. void onTwoSecondTimeout();
  47. private:
  48. /** Tries again up to 5 times
  49. * @returns true if we tried again, otherwise you should emit error */
  50. bool tryAgain();
  51. /** Will emit 5 tracks from tracks(), they have to played within an hour
  52. * or the streamer will refuse to stream them. Also the previous five are
  53. * invalidated apart from the one that is currently playing, so sorry, you
  54. * can't build up big lists of tracks.
  55. *
  56. * I feel I must point out that asking the user which one they want to play
  57. * is also not allowed according to our terms and conditions, which you
  58. * already agreed to in order to get your API key. Sorry about that dude.
  59. */
  60. void fetchFiveMoreTracks();
  61. private:
  62. QList<Xspf*> m_playlistQueue;
  63. uint m_retry_counter;
  64. bool m_fetchingPlaylist;
  65. bool m_requestedPlaylist;
  66. class QTimer* m_twoSecondTimer;
  67. RadioStation m_retuneStation;
  68. };
  69. }
  70. #endif