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

152 lines
4.2 KiB
C
Raw Normal View History

2019-06-17 23:54:24 +02:00
/*
* Strawberry Music Player
* Copyright 2019, Jonas Kvinge <jonas@jkvinge.net>
*
* 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 SUBSONICREQUEST_H
#define SUBSONICREQUEST_H
#include "config.h"
#include <memory>
2019-06-17 23:54:24 +02:00
#include <QtGlobal>
#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 <QHash>
2020-02-09 02:29:35 +01:00
#include <QMap>
2019-06-17 23:54:24 +02:00
#include <QMultiMap>
#include <QQueue>
2020-02-09 02:29:35 +01:00
#include <QVariant>
2019-06-17 23:54:24 +02:00
#include <QString>
#include <QStringList>
2019-06-17 23:54:24 +02:00
#include <QUrl>
2020-02-09 02:29:35 +01:00
#include <QNetworkAccessManager>
2019-06-17 23:54:24 +02:00
#include <QJsonObject>
#include "core/song.h"
#include "subsonicbaserequest.h"
2020-02-09 02:29:35 +01:00
class QNetworkReply;
class Application;
2019-06-17 23:54:24 +02:00
class SubsonicService;
class SubsonicUrlHandler;
class SubsonicRequest : public SubsonicBaseRequest {
Q_OBJECT
public:
SubsonicRequest(SubsonicService *service, SubsonicUrlHandler *url_handler, Application *app, QObject *parent);
2019-06-17 23:54:24 +02:00
~SubsonicRequest();
void ReloadSettings();
void GetAlbums();
void Reset();
signals:
void Results(const SongList &songs, const QString &error);
void UpdateStatus(const QString &text);
void ProgressSetMaximum(const int max);
void UpdateProgress(const int max);
2019-06-17 23:54:24 +02:00
private slots:
void AlbumsReplyReceived(QNetworkReply *reply, const int offset_requested);
2019-06-19 20:40:11 +02:00
void AlbumSongsReplyReceived(QNetworkReply *reply, const qint64 artist_id, const qint64 album_id, const QString &album_artist);
void AlbumCoverReceived(QNetworkReply *reply, const QString &album_id, const QUrl &url, const QString &filename);
2019-06-17 23:54:24 +02:00
private:
typedef QPair<QString, QString> Param;
typedef QList<Param> ParamList;
struct Request {
2019-06-19 20:40:11 +02:00
qint64 artist_id = 0;
2020-01-20 17:45:40 +01:00
QString album_id;
2019-06-19 20:40:11 +02:00
qint64 song_id = 0;
2019-06-17 23:54:24 +02:00
int offset = 0;
int size = 0;
QString album_artist;
};
struct AlbumCoverRequest {
2019-06-19 20:40:11 +02:00
qint64 artist_id = 0;
QString album_id = 0;
2019-06-17 23:54:24 +02:00
QUrl url;
QString filename;
};
void AddAlbumsRequest(const int offset = 0, const int size = 0);
void FlushAlbumsRequests();
void AlbumsFinishCheck(const int offset = 0, const int albums_received = 0);
void SongsFinishCheck();
2020-01-20 17:45:40 +01:00
void AddAlbumSongsRequest(const qint64 artist_id, const QString &album_id, const QString &album_artist, const int offset = 0);
2019-06-17 23:54:24 +02:00
void FlushAlbumSongsRequests();
2019-06-19 20:40:11 +02:00
int ParseSong(Song &song, const QJsonObject &json_obj, const qint64 artist_id_requested = 0, const qint64 album_id_requested = 0, const QString &album_artist = QString());
2019-06-17 23:54:24 +02:00
void GetAlbumCovers();
void AddAlbumCoverRequest(Song &song);
void FlushAlbumCoverRequests();
void AlbumCoverFinishCheck();
void FinishCheck();
void Warn(const QString &error, const QVariant &debug = QVariant());
void Error(const QString &error, const QVariant &debug = QVariant());
2019-06-17 23:54:24 +02:00
static const int kMaxConcurrentAlbumsRequests;
static const int kMaxConcurrentArtistAlbumsRequests;
static const int kMaxConcurrentAlbumSongsRequests;
static const int kMaxConcurrentAlbumCoverRequests;
SubsonicService *service_;
SubsonicUrlHandler *url_handler_;
Application *app_;
std::unique_ptr<QNetworkAccessManager> network_;
2019-06-17 23:54:24 +02:00
bool finished_;
QQueue<Request> albums_requests_queue_;
QQueue<Request> album_songs_requests_queue_;
QQueue<AlbumCoverRequest> album_cover_requests_queue_;
2020-01-20 17:45:40 +01:00
QHash<QString, Request> album_songs_requests_pending_;
QMultiMap<QString, Song*> album_covers_requests_sent_;
2019-06-17 23:54:24 +02:00
int albums_requests_active_;
int album_songs_requests_active_;
int album_songs_requested_;
int album_songs_received_;
int album_covers_requests_active_;
int album_covers_requested_;
int album_covers_received_;
SongList songs_;
QStringList errors_;
2019-06-17 23:54:24 +02:00
bool no_results_;
2019-08-05 18:38:27 +02:00
QList<QNetworkReply*> replies_;
2019-06-17 23:54:24 +02:00
QList<QNetworkReply*> album_cover_replies_;
};
#endif // SUBSONICREQUEST_H