2019-06-17 23:54:24 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2019-06-17 23:54:24 +02:00
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SUBSONICBASEREQUEST_H
|
|
|
|
#define SUBSONICBASEREQUEST_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2019-08-20 12:33:01 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QList>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QSet>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QPair>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QVariant>
|
|
|
|
#include <QByteArray>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QString>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QStringList>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QUrl>
|
2019-08-20 12:33:01 +02:00
|
|
|
#include <QSslError>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QJsonObject>
|
|
|
|
|
|
|
|
#include "subsonicservice.h"
|
2021-09-21 01:27:55 +02:00
|
|
|
#include "settings/subsonicsettingspage.h"
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2019-08-20 12:33:01 +02:00
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
|
|
|
|
2019-06-17 23:54:24 +02:00
|
|
|
class SubsonicBaseRequest : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2021-07-01 02:01:38 +02:00
|
|
|
explicit SubsonicBaseRequest(SubsonicService *service, QObject *parent = nullptr);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2021-07-01 02:01:38 +02:00
|
|
|
protected:
|
2019-06-17 23:54:24 +02:00
|
|
|
typedef QPair<QString, QString> Param;
|
|
|
|
typedef QList<Param> ParamList;
|
|
|
|
|
2021-09-21 01:27:55 +02:00
|
|
|
public:
|
2021-09-25 01:18:08 +02:00
|
|
|
static QUrl CreateUrl(const QUrl &server_url, const SubsonicSettingsPage::AuthMethod auth_method, const QString &username, const QString &password, const QString &ressource_name, const ParamList ¶ms_provided);
|
2021-09-21 01:27:55 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
QNetworkReply *CreateGetRequest(const QString &ressource_name, const ParamList ¶ms_provided) const;
|
2019-07-07 21:14:24 +02:00
|
|
|
QByteArray GetReplyData(QNetworkReply *reply);
|
|
|
|
QJsonObject ExtractJsonObj(QByteArray &data);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
virtual void Error(const QString &error, const QVariant &debug = QVariant()) = 0;
|
2021-06-22 13:41:38 +02:00
|
|
|
static QString ErrorsToHTML(const QStringList &errors);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2021-06-13 19:55:45 +02:00
|
|
|
QUrl server_url() const { return service_->server_url(); }
|
|
|
|
QString username() const { return service_->username(); }
|
|
|
|
QString password() const { return service_->password(); }
|
2021-09-21 01:27:55 +02:00
|
|
|
SubsonicSettingsPage::AuthMethod auth_method() const { return service_->auth_method(); }
|
2021-06-13 19:55:45 +02:00
|
|
|
bool http2() const { return service_->http2(); }
|
|
|
|
bool verify_certificate() const { return service_->verify_certificate(); }
|
|
|
|
bool download_album_covers() const { return service_->download_album_covers(); }
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2019-07-07 21:14:24 +02:00
|
|
|
private slots:
|
2021-06-20 19:04:08 +02:00
|
|
|
void HandleSSLErrors(const QList<QSslError> &ssl_errors);
|
2019-07-07 21:14:24 +02:00
|
|
|
|
2019-06-17 23:54:24 +02:00
|
|
|
private:
|
|
|
|
SubsonicService *service_;
|
2019-08-20 12:33:01 +02:00
|
|
|
std::unique_ptr<QNetworkAccessManager> network_;
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SUBSONICBASEREQUEST_H
|