Add scheme setting for subsonic

This commit is contained in:
Jonas Kvinge 2019-06-18 00:28:36 +02:00
parent 8cc1d48115
commit 2c8cde4d91
8 changed files with 17 additions and 8 deletions

View File

@ -51,6 +51,9 @@ SubsonicSettingsPage::SubsonicSettingsPage(SettingsDialog *parent)
dialog()->installEventFilter(this);
ui_->scheme->addItem("HTTP", "http");
ui_->scheme->addItem("HTTPS", "https");
}
SubsonicSettingsPage::~SubsonicSettingsPage() { delete ui_; }
@ -61,6 +64,7 @@ void SubsonicSettingsPage::Load() {
s.beginGroup(kSettingsGroup);
ui_->enable->setChecked(s.value("enabled", false).toBool());
dialog()->ComboBoxLoadFromSettings(s, ui_->scheme, "scheme", "https");
ui_->hostname->setText(s.value("hostname").toString());
ui_->port->setText(QString::number(s.value("port", 4040).toInt()));
ui_->username->setText(s.value("username").toString());
@ -78,6 +82,7 @@ void SubsonicSettingsPage::Save() {
QSettings s;
s.beginGroup(kSettingsGroup);
s.setValue("enabled", ui_->enable->isChecked());
s.setValue("scheme", ui_->scheme->itemData(ui_->scheme->currentIndex()));
s.setValue("hostname", ui_->hostname->text());
s.setValue("port", ui_->port->text().toInt());
s.setValue("username", ui_->username->text());

View File

@ -37,11 +37,7 @@
<item>
<layout class="QHBoxLayout" name="layout_server">
<item>
<widget class="QLabel" name="label_server_url">
<property name="text">
<string>Hostname</string>
</property>
</widget>
<widget class="QComboBox" name="scheme"/>
</item>
<item>
<widget class="QLineEdit" name="hostname"/>

View File

@ -73,7 +73,8 @@ QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const QList<P
}
QUrl url;
url.setScheme("https");
if (scheme().isEmpty()) url.setScheme("https");
else url.setScheme(scheme());
url.setHost(hostname());
if (port() > 0 && port() != 443)
url.setPort(port());

View File

@ -68,6 +68,7 @@ class SubsonicBaseRequest : public QObject {
QString client_name() { return service_->client_name(); }
QString api_version() { return service_->api_version(); }
QString scheme() { return service_->scheme(); }
QString hostname() { return service_->hostname(); }
int port() { return service_->port(); }
QString username() { return service_->username(); }

View File

@ -105,6 +105,7 @@ void SubsonicService::ReloadSettings() {
QSettings s;
s.beginGroup(SubsonicSettingsPage::kSettingsGroup);
scheme_ = s.value("scheme", "https").toString();
hostname_ = s.value("hostname").toString();
port_ = s.value("port", 443).toInt();
username_ = s.value("username").toString();
@ -142,7 +143,8 @@ void SubsonicService::SendPing(const QString &hostname, const int port, const QS
}
QUrl url;
url.setScheme("https");
if (scheme_.isEmpty()) url.setScheme("https");
else url.setScheme(scheme_);
url.setHost(hostname);
url.setPort(port);
url.setPath("/rest/ping.view");

View File

@ -63,6 +63,7 @@ class SubsonicService : public InternetService {
QString client_name() { return kClientName; }
QString api_version() { return kApiVersion; }
QString scheme() { return scheme_; }
QString hostname() { return hostname_; }
int port() { return port_; }
QString username() { return username_; }
@ -118,6 +119,7 @@ class SubsonicService : public InternetService {
std::shared_ptr<SubsonicRequest> songs_request_;
QString scheme_;
QString hostname_;
int port_;
QString username_;

View File

@ -45,7 +45,8 @@ UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl &url) {
}
QUrl media_url;
media_url.setScheme("https");
if (server_scheme().isEmpty()) media_url.setScheme("https");
else media_url.setScheme(server_scheme());
media_url.setHost(service_->hostname());
if (service_->port() > 0 && service_->port() != 443)
media_url.setPort(service_->port());

View File

@ -41,6 +41,7 @@ class SubsonicUrlHandler : public UrlHandler {
SubsonicUrlHandler(Application *app, SubsonicService *service);
QString scheme() const { return service_->url_scheme(); }
QString server_scheme() const { return service_->scheme(); }
LoadResult StartLoading(const QUrl &url);
private: