Clementine-audio-player-Mac.../src/internet/somafmservice.h

104 lines
2.6 KiB
C
Raw Normal View History

/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
2010-01-18 03:23:55 +01:00
#ifndef SOMAFMSERVICE_H
#define SOMAFMSERVICE_H
2010-02-10 14:15:18 +01:00
#include <QXmlStreamReader>
#include "internetservice.h"
2011-11-06 01:00:26 +01:00
#include "core/cachedlist.h"
2010-01-18 03:23:55 +01:00
class SomaFMUrlHandler;
2010-01-18 03:23:55 +01:00
class QNetworkAccessManager;
2010-01-18 03:49:07 +01:00
class QMenu;
2010-01-18 03:23:55 +01:00
class SomaFMService : public InternetService {
2010-01-18 03:23:55 +01:00
Q_OBJECT
2011-11-06 01:00:26 +01:00
public:
SomaFMService(InternetModel* parent);
2010-01-18 03:49:07 +01:00
~SomaFMService();
2010-01-18 03:23:55 +01:00
enum ItemType {
Type_Stream = 2000,
};
2011-11-06 01:00:26 +01:00
struct Stream {
QString title_;
QString dj_;
QUrl url_;
Song ToSong() const;
};
typedef QList<Stream> StreamList;
2010-01-18 03:23:55 +01:00
static const char* kServiceName;
2011-11-06 01:00:26 +01:00
static const char* kSettingsGroup;
2010-01-18 03:23:55 +01:00
static const char* kChannelListUrl;
2010-01-18 03:49:07 +01:00
static const char* kHomepage;
2011-11-06 01:00:26 +01:00
static const int kStreamsCacheDurationSecs;
2010-01-18 03:23:55 +01:00
QStandardItem* CreateRootItem();
void LazyPopulate(QStandardItem* item);
void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos);
2010-01-18 03:23:55 +01:00
PlaylistItem::Options playlistitem_options() const;
QNetworkAccessManager* network() const { return network_; }
2010-01-18 03:23:55 +01:00
2011-11-06 01:00:26 +01:00
void ReloadSettings();
bool IsStreamListStale() const { return streams_.IsStale(); }
StreamList Streams();
signals:
void StreamsChanged();
protected:
QModelIndex GetCurrentIndex();
2011-11-06 01:00:26 +01:00
private slots:
void ForceRefreshStreams();
void RefreshStreams();
void RefreshStreamsFinished(QNetworkReply* reply, int task_id);
2010-01-18 03:23:55 +01:00
2010-01-18 03:49:07 +01:00
void Homepage();
2011-11-06 01:00:26 +01:00
private:
void ReadChannel(QXmlStreamReader& reader, StreamList* ret);
2010-01-18 03:23:55 +01:00
void ConsumeElement(QXmlStreamReader& reader);
2011-11-06 01:00:26 +01:00
void PopulateStreams();
2010-01-18 03:23:55 +01:00
2011-11-06 01:00:26 +01:00
private:
SomaFMUrlHandler* url_handler_;
QStandardItem* root_;
2010-01-18 03:49:07 +01:00
QMenu* context_menu_;
QStandardItem* context_item_;
2010-01-18 03:23:55 +01:00
QNetworkAccessManager* network_;
2011-11-06 01:00:26 +01:00
CachedList<Stream> streams_;
2010-01-18 03:23:55 +01:00
};
2011-11-06 01:00:26 +01:00
QDataStream& operator<<(QDataStream& out, const SomaFMService::Stream& stream);
QDataStream& operator>>(QDataStream& in, SomaFMService::Stream& stream);
Q_DECLARE_METATYPE(SomaFMService::Stream)
2010-01-18 03:23:55 +01:00
#endif // SOMAFMSERVICE_H