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

134 lines
4.2 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 <QObject>
#include <QPair>
2020-02-09 02:29:35 +01:00
#include <QSet>
2019-06-17 23:54:24 +02:00
#include <QList>
#include <QMap>
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/scoped_ptr.h"
#include "core/shared_ptr.h"
2019-06-17 23:54:24 +02:00
#include "core/song.h"
#include "internet/internetservice.h"
#include "settings/subsonicsettingspage.h"
2019-06-17 23:54:24 +02:00
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:
explicit SubsonicService(Application *app, QObject *parent = nullptr);
2020-06-15 21:55:05 +02:00
~SubsonicService() override;
2019-06-17 23:54:24 +02:00
static const Song::Source kSource;
static const char *kClientName;
static const char *kApiVersion;
2019-06-17 23:54:24 +02:00
2020-06-15 21:55:05 +02:00
void ReloadSettings() override;
void Exit() override;
Application *app() const { return app_; }
2019-06-17 23:54:24 +02:00
QUrl server_url() const { return server_url_; }
QString username() const { return username_; }
QString password() const { return password_; }
bool http2() const { return http2_; }
bool verify_certificate() const { return verify_certificate_; }
bool download_album_covers() const { return download_album_covers_; }
SubsonicSettingsPage::AuthMethod auth_method() const { return auth_method_; }
2019-06-17 23:54:24 +02:00
SharedPtr<CollectionBackend> collection_backend() const { return collection_backend_; }
CollectionModel *collection_model() const { return collection_model_; }
QSortFilterProxyModel *collection_sort_model() const { return collection_sort_model_; }
2019-06-17 23:54:24 +02:00
SharedPtr<CollectionBackend> songs_collection_backend() override { return collection_backend_; }
2020-06-15 21:55:05 +02:00
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();
2021-06-20 19:04:08 +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();
void SendPingWithCredentials(QUrl url, const QString &username, const QString &password, const SubsonicSettingsPage::AuthMethod auth_method, const bool redirect = false);
2020-06-15 21:55:05 +02:00
void GetSongs() override;
void DeleteSongs();
2020-06-15 21:55:05 +02:00
void ResetSongsRequest() override;
2019-06-17 23:54:24 +02:00
private slots:
2021-06-20 19:04:08 +02:00
void HandlePingSSLErrors(const QList<QSslError> &ssl_errors);
void HandlePingReply(QNetworkReply *reply, const QUrl &url, const QString &username, const QString &password, const SubsonicSettingsPage::AuthMethod auth_method);
void SongsResultsReceived(const SongMap &songs, const QString &error);
2019-06-17 23:54:24 +02:00
private:
void PingError(const QString &error = QString(), const QVariant &debug = QVariant());
2019-06-17 23:54:24 +02:00
Application *app_;
ScopedPtr<QNetworkAccessManager> network_;
2019-06-17 23:54:24 +02:00
SubsonicUrlHandler *url_handler_;
SharedPtr<CollectionBackend> collection_backend_;
2019-06-17 23:54:24 +02:00
CollectionModel *collection_model_;
QSortFilterProxyModel *collection_sort_model_;
SharedPtr<SubsonicRequest> songs_request_;
SharedPtr<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 http2_;
2019-06-17 23:54:24 +02:00
bool verify_certificate_;
bool download_album_covers_;
SubsonicSettingsPage::AuthMethod auth_method_;
2019-06-17 23:54:24 +02:00
QStringList errors_;
int ping_redirects_;
QList<QNetworkReply*> replies_;
2019-06-17 23:54:24 +02:00
};
using SubsonicServicePtr = SharedPtr<SubsonicService>;
2019-06-17 23:54:24 +02:00
#endif // SUBSONICSERVICE_H