2011-12-06 00:10:25 +01:00
|
|
|
#ifndef SUBSONICSERVICE_H
|
|
|
|
#define SUBSONICSERVICE_H
|
|
|
|
|
2011-12-09 01:13:17 +01:00
|
|
|
#include "internetmodel.h"
|
2011-12-06 00:10:25 +01:00
|
|
|
#include "internetservice.h"
|
|
|
|
|
2011-12-07 19:06:11 +01:00
|
|
|
class QNetworkAccessManager;
|
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
class SubsonicService : public InternetService
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2011-12-07 19:06:11 +01:00
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
public:
|
|
|
|
SubsonicService(InternetModel *parent);
|
|
|
|
~SubsonicService();
|
|
|
|
|
2011-12-07 19:06:11 +01:00
|
|
|
enum LoginState {
|
|
|
|
LoginState_Loggedin,
|
|
|
|
LoginState_BadServer,
|
|
|
|
LoginState_BadCredentials,
|
|
|
|
LoginState_Unlicensed,
|
|
|
|
LoginState_OtherError,
|
2011-12-08 21:00:50 +01:00
|
|
|
LoginState_Unknown,
|
2011-12-07 19:06:11 +01:00
|
|
|
};
|
|
|
|
|
2011-12-09 01:13:17 +01:00
|
|
|
enum Type {
|
|
|
|
Type_TopLevel = InternetModel::TypeCount,
|
|
|
|
Type_Artist,
|
|
|
|
Type_Album,
|
|
|
|
Type_Track,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Role {
|
|
|
|
Role_Id = InternetModel::RoleCount,
|
|
|
|
};
|
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
typedef QMap<QString, QString> RequestOptions;
|
|
|
|
|
|
|
|
QStandardItem* CreateRootItem();
|
|
|
|
void LazyPopulate(QStandardItem *item);
|
2011-12-07 19:06:11 +01:00
|
|
|
void ReloadSettings();
|
|
|
|
|
|
|
|
void Login();
|
|
|
|
void Login(const QString &server, const QString &username, const QString &password);
|
|
|
|
LoginState login_state() const { return login_state_; }
|
|
|
|
|
|
|
|
// Subsonic API methods
|
|
|
|
void Ping();
|
2011-12-09 01:13:17 +01:00
|
|
|
void GetMusicFolders();
|
2011-12-06 00:10:25 +01:00
|
|
|
|
|
|
|
static const char* kServiceName;
|
|
|
|
static const char* kSettingsGroup;
|
|
|
|
static const char* kApiVersion;
|
|
|
|
static const char* kApiClientName;
|
|
|
|
|
2011-12-07 19:06:11 +01: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
|
|
|
protected:
|
|
|
|
QModelIndex GetCurrentIndex();
|
|
|
|
|
|
|
|
private:
|
2011-12-07 19:06:11 +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,
|
|
|
|
};
|
|
|
|
|
2011-12-09 01:13:17 +01:00
|
|
|
QUrl BuildRequestUrl(const QString &view);
|
|
|
|
// Convenience function to reduce QNetworkRequest/QNetworkReply/connect boilerplate
|
|
|
|
void Send(const QUrl &url, const char *slot);
|
2011-12-06 00:10:25 +01:00
|
|
|
|
|
|
|
QModelIndex context_item_;
|
|
|
|
QStandardItem* root_;
|
2011-12-07 19:06:11 +01:00
|
|
|
QNetworkAccessManager* network_;
|
2011-12-06 00:10:25 +01:00
|
|
|
|
|
|
|
// Configuration
|
2011-12-07 19:06:11 +01:00
|
|
|
QString server_;
|
2011-12-06 00:10:25 +01:00
|
|
|
QString username_;
|
|
|
|
QString password_;
|
|
|
|
|
2011-12-07 19:06:11 +01:00
|
|
|
LoginState login_state_;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onPingFinished();
|
2011-12-09 01:13:17 +01:00
|
|
|
void onGetMusicFoldersFinished();
|
2011-12-06 00:10:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SUBSONICSERVICE_H
|