PageRenderTime 176ms CodeModel.GetById 50ms app.highlight 4ms RepoModel.GetById 87ms app.codeStats 0ms

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