Created SubsonicUrlHandler
This commit is contained in:
parent
eafb351126
commit
577d13038a
|
@ -171,6 +171,7 @@ set(SOURCES
|
|||
internet/somafmurlhandler.cpp
|
||||
internet/subsonicservice.cpp
|
||||
internet/subsonicsettingspage.cpp
|
||||
internet/subsonicurlhandler.cpp
|
||||
|
||||
library/groupbydialog.cpp
|
||||
library/library.cpp
|
||||
|
@ -415,6 +416,7 @@ set(HEADERS
|
|||
internet/somafmurlhandler.h
|
||||
internet/subsonicservice.h
|
||||
internet/subsonicsettingspage.h
|
||||
internet/subsonicurlhandler.h
|
||||
|
||||
library/groupbydialog.h
|
||||
library/library.h
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "subsonicurlhandler.h"
|
||||
#include "subsonicservice.h"
|
||||
#include "internetmodel.h"
|
||||
#include "core/logging.h"
|
||||
#include "core/player.h"
|
||||
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
|
@ -15,9 +17,13 @@ const char* SubsonicService::kApiClientName = "Clementine";
|
|||
SubsonicService::SubsonicService(InternetModel *parent)
|
||||
: InternetService(kServiceName, parent, parent),
|
||||
network_(new QNetworkAccessManager(this)),
|
||||
http_url_handler_(new SubsonicUrlHandler(this, this)),
|
||||
https_url_handler_(new SubsonicHttpsUrlHandler(this, this)),
|
||||
login_state_(LoginState_OtherError),
|
||||
item_lookup_()
|
||||
{
|
||||
model()->player()->RegisterUrlHandler(http_url_handler_);
|
||||
model()->player()->RegisterUrlHandler(https_url_handler_);
|
||||
}
|
||||
|
||||
SubsonicService::~SubsonicService()
|
||||
|
@ -171,6 +177,7 @@ void SubsonicService::ReadTrack(QXmlStreamReader *reader, QStandardItem *parent)
|
|||
length *= 1000000000;
|
||||
song.set_length_nanosec(length);
|
||||
QUrl url = BuildRequestUrl("stream");
|
||||
url.setScheme(url.scheme() == "https" ? "subsonics" : "subsonic");
|
||||
url.addQueryItem("id", id);
|
||||
song.set_url(url);
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
class QNetworkAccessManager;
|
||||
class QXmlStreamReader;
|
||||
|
||||
class SubsonicUrlHandler;
|
||||
class SubsonicHttpsUrlHandler;
|
||||
|
||||
class SubsonicService : public InternetService
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -84,6 +87,8 @@ class SubsonicService : public InternetService
|
|||
QModelIndex context_item_;
|
||||
QStandardItem* root_;
|
||||
QNetworkAccessManager* network_;
|
||||
SubsonicUrlHandler* http_url_handler_;
|
||||
SubsonicHttpsUrlHandler* https_url_handler_;
|
||||
|
||||
// Configuration
|
||||
QString server_;
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#include "subsonicservice.h"
|
||||
#include "subsonicurlhandler.h"
|
||||
|
||||
SubsonicUrlHandler::SubsonicUrlHandler(SubsonicService* service, QObject* parent)
|
||||
: UrlHandler(parent),
|
||||
service_(service) {
|
||||
}
|
||||
|
||||
UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl& url) {
|
||||
if (service_->login_state() != SubsonicService::LoginState_Loggedin)
|
||||
return LoadResult();
|
||||
|
||||
QUrl newurl(url);
|
||||
newurl.setScheme(realscheme());
|
||||
return LoadResult(url, LoadResult::TrackAvailable, newurl);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef SUBSONICURLHANDLER_H
|
||||
#define SUBSONICURLHANDLER_H
|
||||
|
||||
#include "core/urlhandler.h"
|
||||
|
||||
class SubsonicService;
|
||||
|
||||
// Subsonic URL handler.
|
||||
// For now, at least, Subsonic URLs are just HTTP URLs but with the scheme
|
||||
// replaced with "subsonic" (or "subsonics" for HTTPS). This is a hook to
|
||||
// allow magic to be implemented later.
|
||||
class SubsonicUrlHandler : public UrlHandler {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SubsonicUrlHandler(SubsonicService* service, QObject* parent);
|
||||
|
||||
QString scheme() const { return "subsonic"; }
|
||||
QIcon icon() const { return QIcon(":providers/subsonic-32.png"); }
|
||||
LoadResult StartLoading(const QUrl& url);
|
||||
//LoadResult LoadNext(const QUrl& url);
|
||||
|
||||
protected:
|
||||
virtual QString realscheme() const { return "http"; }
|
||||
|
||||
private:
|
||||
SubsonicService* service_;
|
||||
};
|
||||
|
||||
class SubsonicHttpsUrlHandler : public SubsonicUrlHandler {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SubsonicHttpsUrlHandler(SubsonicService* service, QObject* parent)
|
||||
: SubsonicUrlHandler(service, parent) {}
|
||||
|
||||
QString scheme() const { return "subsonics"; }
|
||||
|
||||
protected:
|
||||
QString realscheme() const { return "https"; }
|
||||
};
|
||||
|
||||
#endif // SUBSONICURLHANDLER_H
|
Loading…
Reference in New Issue