strawberry-audio-player-win.../src/subsonic/subsonicservice.h

138 lines
4.1 KiB
C
Raw Normal View History

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 SUBSONICSERVICE_H
#define SUBSONICSERVICE_H
#include "config.h"
#include <memory>
#include <QObject>
#include <QPair>
2020-02-09 02:29:35 +01:00
#include <QSet>
2019-06-17 23:54:24 +02:00
#include <QList>
2020-02-09 02:29:35 +01:00
#include <QVariant>
#include <QByteArray>
2019-06-17 23:54:24 +02:00
#include <QString>
#include <QStringList>
2019-06-17 23:54:24 +02:00
#include <QUrl>
2020-06-15 21:55:05 +02:00
#include <QNetworkAccessManager>
#include <QSslError>
#include <QDateTime>
2019-06-17 23:54:24 +02:00
#include "core/song.h"
#include "internet/internetservice.h"
class QSortFilterProxyModel;
class QNetworkReply;
2019-06-17 23:54:24 +02:00
class Application;
class SubsonicUrlHandler;
class SubsonicRequest;
class SubsonicScrobbleRequest;
2019-06-17 23:54:24 +02:00
class CollectionBackend;
class CollectionModel;
class SubsonicService : public InternetService {
Q_OBJECT
public:
2020-04-07 16:49:15 +02:00
explicit SubsonicService(Application *app, QObject *parent);
2020-06-15 21:55:05 +02:00
~SubsonicService() override;
2019-06-17 23:54:24 +02:00
static const Song::Source kSource;
2020-06-15 21:55:05 +02:00
void ReloadSettings() override;
void Exit() override;
Application *app() { return app_; }
2019-06-17 23:54:24 +02:00
QString client_name() { return kClientName; }
QString api_version() { return kApiVersion; }
QUrl server_url() { return server_url_; }
2019-06-17 23:54:24 +02:00
QString username() { return username_; }
QString password() { return password_; }
bool verify_certificate() { return verify_certificate_; }
bool download_album_covers() { return download_album_covers_; }
2019-06-17 23:54:24 +02:00
CollectionBackend *collection_backend() { return collection_backend_; }
CollectionModel *collection_model() { return collection_model_; }
QSortFilterProxyModel *collection_sort_model() { return collection_sort_model_; }
2020-06-15 21:55:05 +02:00
CollectionBackend *songs_collection_backend() override { return collection_backend_; }
CollectionModel *songs_collection_model() override { return collection_model_; }
QSortFilterProxyModel *songs_collection_sort_model() override { return collection_sort_model_; }
2019-06-17 23:54:24 +02:00
void CheckConfiguration();
2020-09-30 01:02:41 +02:00
void Scrobble(const QString &song_id, const bool submission, const QDateTime time);
2019-06-17 23:54:24 +02:00
public slots:
2020-06-15 21:55:05 +02:00
void ShowConfig() override;
2019-06-17 23:54:24 +02:00
void SendPing();
2021-01-26 16:48:04 +01:00
void SendPingWithCredentials(QUrl url, const QString &username, const QString &password, const bool redirect = false);
2020-06-15 21:55:05 +02:00
void GetSongs() override;
void ResetSongsRequest() override;
2019-06-17 23:54:24 +02:00
private slots:
void HandlePingSSLErrors(QList<QSslError> ssl_errors);
void HandlePingReply(QNetworkReply *reply, const QUrl &url, const QString &username, const QString &password);
void SongsResultsReceived(const SongList &songs, const QString &error);
2019-06-17 23:54:24 +02:00
private:
typedef QPair<QString, QString> Param;
typedef QList<Param> ParamList;
typedef QPair<QByteArray, QByteArray> EncodedParam;
typedef QList<EncodedParam> EncodedParamList;
void PingError(const QString &error = QString(), const QVariant &debug = QVariant());
2019-06-17 23:54:24 +02:00
static const char *kClientName;
static const char *kApiVersion;
static const char *kSongsTable;
static const char *kSongsFtsTable;
static const int kMaxRedirects;
2019-06-17 23:54:24 +02:00
Application *app_;
std::unique_ptr<QNetworkAccessManager> network_;
2019-06-17 23:54:24 +02:00
SubsonicUrlHandler *url_handler_;
CollectionBackend *collection_backend_;
CollectionModel *collection_model_;
QSortFilterProxyModel *collection_sort_model_;
std::shared_ptr<SubsonicRequest> songs_request_;
std::shared_ptr<SubsonicScrobbleRequest> scrobble_request_;
2019-06-17 23:54:24 +02:00
QUrl server_url_;
2019-06-17 23:54:24 +02:00
QString username_;
QString password_;
bool verify_certificate_;
bool download_album_covers_;
2019-06-17 23:54:24 +02:00
QStringList errors_;
int ping_redirects_;
QList<QNetworkReply*> replies_;
2019-06-17 23:54:24 +02:00
};
#endif // SUBSONICSERVICE_H