2011-11-03 00:41:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2011, 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DIGITALLYIMPORTEDCLIENT_H
|
|
|
|
#define DIGITALLYIMPORTEDCLIENT_H
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QObject>
|
2011-11-04 23:31:19 +01:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QUrl>
|
2011-11-03 00:41:46 +01:00
|
|
|
|
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
2011-11-04 23:31:19 +01:00
|
|
|
class QNetworkRequest;
|
2011-11-03 00:41:46 +01:00
|
|
|
|
|
|
|
class DigitallyImportedClient : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
public:
|
2011-11-03 00:41:46 +01:00
|
|
|
DigitallyImportedClient(const QString& service_name, QObject* parent = 0);
|
|
|
|
|
|
|
|
static const char* kApiUsername;
|
|
|
|
static const char* kApiPassword;
|
|
|
|
static const char* kAuthUrl;
|
2011-11-04 23:31:19 +01:00
|
|
|
static const char* kChannelListUrl;
|
2011-11-03 00:41:46 +01:00
|
|
|
|
|
|
|
struct AuthReply {
|
|
|
|
bool success_;
|
|
|
|
|
|
|
|
// Set if success_ == false
|
|
|
|
QString error_reason_;
|
|
|
|
|
|
|
|
// Set if success_ == true
|
|
|
|
QString first_name_;
|
|
|
|
QString last_name_;
|
|
|
|
QDateTime expires_;
|
|
|
|
QString listen_hash_;
|
|
|
|
};
|
|
|
|
|
2011-11-04 23:31:19 +01:00
|
|
|
struct Channel {
|
|
|
|
QUrl art_url_;
|
|
|
|
|
|
|
|
QString director_;
|
|
|
|
QString description_;
|
|
|
|
QString name_;
|
|
|
|
QString key_;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
bool operator<(const Channel& other) const { return name_ < other.name_; }
|
2011-11-04 23:31:19 +01:00
|
|
|
};
|
|
|
|
typedef QList<Channel> ChannelList;
|
|
|
|
|
2011-11-03 00:41:46 +01:00
|
|
|
QNetworkReply* Auth(const QString& username, const QString& password);
|
|
|
|
AuthReply ParseAuthReply(QNetworkReply* reply) const;
|
|
|
|
|
2011-11-04 23:31:19 +01:00
|
|
|
QNetworkReply* GetChannelList();
|
|
|
|
ChannelList ParseChannelList(QNetworkReply* reply) const;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-11-04 23:31:19 +01:00
|
|
|
void SetAuthorisationHeader(QNetworkRequest* req) const;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
private:
|
2011-11-03 00:41:46 +01:00
|
|
|
QNetworkAccessManager* network_;
|
|
|
|
|
|
|
|
QString service_name_;
|
|
|
|
};
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QDataStream& operator<<(QDataStream& out,
|
|
|
|
const DigitallyImportedClient::Channel& channel);
|
|
|
|
QDataStream& operator>>(QDataStream& in,
|
|
|
|
DigitallyImportedClient::Channel& channel);
|
2011-11-05 23:56:10 +01:00
|
|
|
Q_DECLARE_METATYPE(DigitallyImportedClient::Channel)
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
#endif // DIGITALLYIMPORTEDCLIENT_H
|