2014-12-17 19:02:21 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2011-2013, Alan Briolat <alan.briolat@gmail.com>
|
|
|
|
Copyright 2013, Ross Wolfson <ross.wolfson@gmail.com>
|
|
|
|
Copyright 2013, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2013-2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.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/>.
|
|
|
|
*/
|
|
|
|
|
2014-12-18 23:54:21 +01:00
|
|
|
#ifndef INTERNET_SUBSONIC_SUBSONICSERVICE_H_
|
|
|
|
#define INTERNET_SUBSONIC_SUBSONICSERVICE_H_
|
2011-12-06 00:10:25 +01:00
|
|
|
|
2013-01-15 00:36:23 +01:00
|
|
|
#include <QQueue>
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <memory>
|
2013-01-15 00:36:23 +01:00
|
|
|
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/internetmodel.h"
|
|
|
|
#include "internet/core/internetservice.h"
|
2015-12-01 07:13:37 +01:00
|
|
|
#include "internet/subsonic/subsonicdynamicplaylist.h"
|
2013-01-24 17:48:58 +01:00
|
|
|
|
2011-12-07 19:06:11 +01:00
|
|
|
class QNetworkAccessManager;
|
2013-01-15 00:36:23 +01:00
|
|
|
class QNetworkReply;
|
2013-01-24 17:48:58 +01:00
|
|
|
class QSortFilterProxyModel;
|
|
|
|
class QXmlStreamReader;
|
2011-12-07 19:06:11 +01:00
|
|
|
|
2012-01-10 17:52:54 +01:00
|
|
|
class SubsonicUrlHandler;
|
2013-01-15 00:36:23 +01:00
|
|
|
class SubsonicLibraryScanner;
|
2012-01-10 17:52:54 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
class SubsonicService : public InternetService {
|
2011-12-06 00:10:25 +01:00
|
|
|
Q_OBJECT
|
2012-01-16 15:22:30 +01:00
|
|
|
Q_ENUMS(LoginState)
|
2012-01-16 15:31:45 +01:00
|
|
|
Q_ENUMS(ApiError)
|
2011-12-07 19:06:11 +01:00
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
public:
|
2014-02-07 16:34:20 +01:00
|
|
|
SubsonicService(Application* app, InternetModel* parent);
|
2011-12-06 00:10:25 +01:00
|
|
|
~SubsonicService();
|
|
|
|
|
2011-12-07 19:06:11 +01:00
|
|
|
enum LoginState {
|
|
|
|
LoginState_Loggedin,
|
|
|
|
LoginState_BadServer,
|
2012-01-19 23:59:59 +01:00
|
|
|
LoginState_OutdatedClient,
|
|
|
|
LoginState_OutdatedServer,
|
2011-12-07 19:06:11 +01:00
|
|
|
LoginState_BadCredentials,
|
|
|
|
LoginState_Unlicensed,
|
|
|
|
LoginState_OtherError,
|
2011-12-08 21:00:50 +01:00
|
|
|
LoginState_Unknown,
|
2013-05-08 04:33:45 +02:00
|
|
|
LoginState_ConnectionRefused,
|
|
|
|
LoginState_HostNotFound,
|
|
|
|
LoginState_Timeout,
|
|
|
|
LoginState_SslError,
|
2013-06-11 03:57:57 +02:00
|
|
|
LoginState_IncompleteCredentials,
|
2013-07-03 03:16:41 +02:00
|
|
|
LoginState_RedirectLimitExceeded,
|
|
|
|
LoginState_RedirectNoUrl,
|
2011-12-07 19:06:11 +01:00
|
|
|
};
|
|
|
|
|
2012-01-16 15:31:45 +01:00
|
|
|
enum ApiError {
|
|
|
|
ApiError_Generic = 0,
|
|
|
|
ApiError_ParameterMissing = 10,
|
|
|
|
ApiError_OutdatedClient = 20,
|
|
|
|
ApiError_OutdatedServer = 30,
|
|
|
|
ApiError_BadCredentials = 40,
|
|
|
|
ApiError_Unauthorized = 50,
|
|
|
|
ApiError_Unlicensed = 60,
|
|
|
|
ApiError_NotFound = 70,
|
|
|
|
};
|
|
|
|
|
2014-12-17 19:02:21 +01:00
|
|
|
enum Type {
|
|
|
|
Type_Artist = InternetModel::TypeCount,
|
|
|
|
Type_Album,
|
|
|
|
Type_Track,
|
|
|
|
};
|
2011-12-09 01:13:17 +01:00
|
|
|
|
2014-12-17 19:02:21 +01:00
|
|
|
enum Role {
|
|
|
|
Role_Id = InternetModel::RoleCount,
|
|
|
|
};
|
2011-12-09 01:13:17 +01:00
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
typedef QMap<QString, QString> RequestOptions;
|
|
|
|
|
2013-02-17 05:14:55 +01:00
|
|
|
bool IsConfigured() const;
|
2015-12-08 23:15:56 +01:00
|
|
|
bool IsAmpache() const;
|
2013-02-17 05:14:55 +01:00
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
QStandardItem* CreateRootItem();
|
2013-07-03 03:16:41 +02:00
|
|
|
void LazyPopulate(QStandardItem* item);
|
|
|
|
void ShowContextMenu(const QPoint& global_pos);
|
2013-01-17 22:01:54 +01:00
|
|
|
QWidget* HeaderWidget() const;
|
2011-12-07 19:06:11 +01:00
|
|
|
void ReloadSettings();
|
|
|
|
|
|
|
|
void Login();
|
2014-02-07 16:34:20 +01:00
|
|
|
void Login(const QString& server, const QString& username,
|
2018-05-23 15:23:53 +02:00
|
|
|
const QString& password, const bool& usesslv3,
|
|
|
|
const bool& verifycert);
|
2013-07-03 03:16:41 +02:00
|
|
|
|
2011-12-07 19:06:11 +01:00
|
|
|
LoginState login_state() const { return login_state_; }
|
|
|
|
|
|
|
|
// Subsonic API methods
|
|
|
|
void Ping();
|
2011-12-06 00:10:25 +01:00
|
|
|
|
2013-01-24 17:48:58 +01:00
|
|
|
QUrl BuildRequestUrl(const QString& view) const;
|
2013-07-03 03:16:41 +02:00
|
|
|
// Scrubs the part of the path that we re-add in BuildRequestUrl().
|
|
|
|
static QUrl ScrubUrl(const QUrl& url);
|
2014-02-07 16:34:20 +01:00
|
|
|
// Convenience function to reduce QNetworkRequest/QSslConfiguration
|
|
|
|
// boilerplate.
|
2013-01-24 17:48:58 +01:00
|
|
|
QNetworkReply* Send(const QUrl& url);
|
2013-01-09 23:20:55 +01:00
|
|
|
|
2020-05-13 07:10:29 +02:00
|
|
|
Song ReadSong(QXmlStreamReader& reader);
|
|
|
|
|
2020-04-08 16:26:58 +02:00
|
|
|
friend PlaylistItemList SubsonicDynamicPlaylist::GenerateMoreAlbums(int);
|
|
|
|
friend PlaylistItemList SubsonicDynamicPlaylist::GenerateMoreSongs(int);
|
2015-12-01 07:13:37 +01:00
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
static const char* kServiceName;
|
|
|
|
static const char* kSettingsGroup;
|
|
|
|
static const char* kApiVersion;
|
|
|
|
static const char* kApiClientName;
|
|
|
|
|
2013-01-10 23:08:52 +01:00
|
|
|
static const char* kSongsTable;
|
|
|
|
static const char* kFtsTable;
|
|
|
|
|
2013-07-03 03:16:41 +02:00
|
|
|
static const int kMaxRedirects;
|
2016-03-29 21:23:53 +02:00
|
|
|
static const int kCoverArtSize;
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
signals:
|
2011-12-08 21:00:50 +01:00
|
|
|
void LoginStateChanged(SubsonicService::LoginState newstate);
|
2011-12-07 19:06:11 +01:00
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
private:
|
2013-01-17 22:01:54 +01:00
|
|
|
void EnsureMenuCreated();
|
2013-07-03 03:16:41 +02:00
|
|
|
// Update configured and working server state
|
|
|
|
void UpdateServer(const QString& server);
|
2013-01-17 22:01:54 +01:00
|
|
|
|
2011-12-07 19:06:11 +01:00
|
|
|
QNetworkAccessManager* network_;
|
2013-01-09 23:20:55 +01:00
|
|
|
SubsonicUrlHandler* url_handler_;
|
2013-01-17 23:13:57 +01:00
|
|
|
|
2013-01-15 00:36:23 +01:00
|
|
|
SubsonicLibraryScanner* scanner_;
|
2013-01-17 23:13:57 +01:00
|
|
|
int load_database_task_id_;
|
2011-12-06 00:10:25 +01:00
|
|
|
|
2013-01-17 22:01:54 +01:00
|
|
|
QMenu* context_menu_;
|
|
|
|
QStandardItem* root_;
|
|
|
|
|
2020-01-12 08:34:35 +01:00
|
|
|
std::shared_ptr<LibraryBackend> library_backend_;
|
2013-01-10 23:08:52 +01:00
|
|
|
LibraryModel* library_model_;
|
2013-01-17 22:01:54 +01:00
|
|
|
LibraryFilterWidget* library_filter_;
|
2013-01-10 23:08:52 +01:00
|
|
|
QSortFilterProxyModel* library_sort_model_;
|
2013-01-21 00:25:54 +01:00
|
|
|
int total_song_count_;
|
2013-01-10 23:08:52 +01:00
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
// Configuration
|
2013-07-03 03:16:41 +02:00
|
|
|
// The server that shows up in the GUI (use UpdateServer() to update)
|
|
|
|
QString configured_server_;
|
2011-12-06 00:10:25 +01:00
|
|
|
QString username_;
|
|
|
|
QString password_;
|
2013-05-05 03:33:03 +02:00
|
|
|
bool usesslv3_;
|
2018-05-23 15:23:53 +02:00
|
|
|
bool verifycert_;
|
2011-12-06 00:10:25 +01:00
|
|
|
|
2011-12-07 19:06:11 +01:00
|
|
|
LoginState login_state_;
|
2014-02-07 16:34:20 +01:00
|
|
|
QString working_server_; // The actual server, possibly post-redirect
|
2013-07-03 03:16:41 +02:00
|
|
|
int redirect_count_;
|
2015-12-08 23:15:56 +01:00
|
|
|
bool is_ampache_;
|
2011-12-07 19:06:11 +01:00
|
|
|
|
|
|
|
private slots:
|
2013-01-17 23:13:57 +01:00
|
|
|
void UpdateTotalSongCount(int count);
|
|
|
|
void ReloadDatabase();
|
|
|
|
void ReloadDatabaseFinished();
|
2013-01-24 17:48:58 +01:00
|
|
|
void OnLoginStateChanged(SubsonicService::LoginState newstate);
|
|
|
|
void OnPingFinished(QNetworkReply* reply);
|
2013-01-21 23:13:48 +01:00
|
|
|
|
|
|
|
void ShowConfig();
|
2013-01-15 00:36:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class SubsonicLibraryScanner : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2015-05-20 13:50:17 +02:00
|
|
|
explicit SubsonicLibraryScanner(SubsonicService* service,
|
|
|
|
QObject* parent = nullptr);
|
2013-01-15 00:36:23 +01:00
|
|
|
~SubsonicLibraryScanner();
|
|
|
|
|
|
|
|
void Scan();
|
2013-01-17 23:13:57 +01:00
|
|
|
const SongList& GetSongs() const { return songs_; }
|
2013-01-15 00:36:23 +01:00
|
|
|
|
|
|
|
static const int kAlbumChunkSize;
|
|
|
|
static const int kConcurrentRequests;
|
2016-03-29 21:23:53 +02:00
|
|
|
static const int kCoverArtSize;
|
2013-01-15 00:36:23 +01:00
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
signals:
|
2013-01-17 23:13:57 +01:00
|
|
|
void ScanFinished();
|
2013-01-15 00:36:23 +01:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
// Step 1: use getAlbumList2 type=alphabeticalByName to list all albums
|
2013-01-24 17:48:58 +01:00
|
|
|
void OnGetAlbumListFinished(QNetworkReply* reply, int offset);
|
2013-01-15 00:36:23 +01:00
|
|
|
// Step 2: use getAlbum id=? to list all songs for each album
|
2016-03-29 22:12:54 +02:00
|
|
|
void OnGetAlbumFinished(QNetworkReply* reply);
|
2013-01-15 00:36:23 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void GetAlbumList(int offset);
|
2013-01-24 17:48:58 +01:00
|
|
|
void GetAlbum(const QString& id);
|
2015-05-20 13:50:17 +02:00
|
|
|
void ParsingError(const QString& message);
|
2013-01-15 00:36:23 +01:00
|
|
|
|
|
|
|
SubsonicService* service_;
|
2013-01-17 23:13:57 +01:00
|
|
|
bool scanning_;
|
2013-01-15 00:36:23 +01:00
|
|
|
QQueue<QString> album_queue_;
|
2013-01-17 23:13:57 +01:00
|
|
|
QSet<QNetworkReply*> pending_requests_;
|
|
|
|
SongList songs_;
|
2011-12-06 00:10:25 +01:00
|
|
|
};
|
|
|
|
|
2014-12-18 23:54:21 +01:00
|
|
|
#endif // INTERNET_SUBSONIC_SUBSONICSERVICE_H_
|