Use single url setting instead for subsonic, check http code
This commit is contained in:
parent
2c8cde4d91
commit
1d67b623e0
@ -44,16 +44,13 @@ SubsonicSettingsPage::SubsonicSettingsPage(SettingsDialog *parent)
|
||||
|
||||
connect(ui_->button_test, SIGNAL(clicked()), SLOT(TestClicked()));
|
||||
|
||||
connect(this, SIGNAL(Test(QString, int, QString, QString)), service_, SLOT(SendPing(QString, int, QString, QString)));
|
||||
connect(this, SIGNAL(Test(QUrl, const QString&, const QString&)), service_, SLOT(SendPing(QUrl, const QString&, const QString&)));
|
||||
|
||||
connect(service_, SIGNAL(TestFailure(QString)), SLOT(TestFailure(QString)));
|
||||
connect(service_, SIGNAL(TestSuccess()), SLOT(TestSuccess()));
|
||||
|
||||
dialog()->installEventFilter(this);
|
||||
|
||||
ui_->scheme->addItem("HTTP", "http");
|
||||
ui_->scheme->addItem("HTTPS", "https");
|
||||
|
||||
}
|
||||
|
||||
SubsonicSettingsPage::~SubsonicSettingsPage() { delete ui_; }
|
||||
@ -64,9 +61,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_->url->setText(s.value("url").toString());
|
||||
ui_->username->setText(s.value("username").toString());
|
||||
QByteArray password = s.value("password").toByteArray();
|
||||
if (password.isEmpty()) ui_->password->clear();
|
||||
@ -82,9 +77,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("url", QUrl(ui_->url->text()));
|
||||
s.setValue("username", ui_->username->text());
|
||||
s.setValue("password", QString::fromUtf8(ui_->password->text().toUtf8().toBase64()));
|
||||
s.setValue("verifycertificate", ui_->checkbox_verify_certificate->isChecked());
|
||||
@ -97,12 +90,18 @@ void SubsonicSettingsPage::Save() {
|
||||
|
||||
void SubsonicSettingsPage::TestClicked() {
|
||||
|
||||
if (ui_->hostname->text().isEmpty() || ui_->username->text().isEmpty() || ui_->password->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing hostname, username or password."));
|
||||
if (ui_->url->text().isEmpty() || ui_->username->text().isEmpty() || ui_->password->text().isEmpty()) {
|
||||
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing url, username or password."));
|
||||
return;
|
||||
}
|
||||
|
||||
emit Test(ui_->hostname->text(), ui_->port->text().toInt(), ui_->username->text(), ui_->password->text());
|
||||
QUrl url(ui_->url->text());
|
||||
if (!url.isValid()) {
|
||||
QMessageBox::critical(this, tr("Configuration incorrect"), tr("URL is invalid."));
|
||||
return;
|
||||
}
|
||||
|
||||
emit Test(url, ui_->username->text(), ui_->password->text());
|
||||
ui_->button_test->setEnabled(false);
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ class SubsonicSettingsPage : public SettingsPage {
|
||||
|
||||
signals:
|
||||
void Test();
|
||||
void Test(const QString &hostname, const int port, const QString &username, const QString &password);
|
||||
void Test(QUrl url, const QString &username, const QString &password);
|
||||
|
||||
private slots:
|
||||
void TestClicked();
|
||||
|
@ -31,33 +31,13 @@
|
||||
<item>
|
||||
<widget class="QGroupBox" name="server_group">
|
||||
<property name="title">
|
||||
<string>Server</string>
|
||||
<string>Server URL</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_server">
|
||||
<item>
|
||||
<widget class="QComboBox" name="scheme"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="hostname"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_port">
|
||||
<property name="text">
|
||||
<string>Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="port">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="url"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="spacer_server">
|
||||
|
@ -72,12 +72,7 @@ QUrl SubsonicBaseRequest::CreateUrl(const QString &ressource_name, const QList<P
|
||||
url_query.addQueryItem(encoded_param.first, encoded_param.second);
|
||||
}
|
||||
|
||||
QUrl url;
|
||||
if (scheme().isEmpty()) url.setScheme("https");
|
||||
else url.setScheme(scheme());
|
||||
url.setHost(hostname());
|
||||
if (port() > 0 && port() != 443)
|
||||
url.setPort(port());
|
||||
QUrl url(server_url());
|
||||
url.setPath(QString("/rest/") + ressource_name);
|
||||
url.setQuery(url_query);
|
||||
|
||||
@ -90,7 +85,7 @@ QNetworkReply *SubsonicBaseRequest::CreateGetRequest(const QString &ressource_na
|
||||
QUrl url = CreateUrl(ressource_name, params_provided);
|
||||
QNetworkRequest req(url);
|
||||
|
||||
if (!verify_certificate()) {
|
||||
if (url.scheme() == "https" && !verify_certificate()) {
|
||||
QSslConfiguration sslconfig = QSslConfiguration::defaultConfiguration();
|
||||
sslconfig.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
req.setSslConfiguration(sslconfig);
|
||||
@ -117,7 +112,13 @@ QByteArray SubsonicBaseRequest::GetReplyData(QNetworkReply *reply, QString &erro
|
||||
QByteArray data;
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError) {
|
||||
data = reply->readAll();
|
||||
int http_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (http_code == 200) {
|
||||
data = reply->readAll();
|
||||
}
|
||||
else {
|
||||
error = Error(QString("Received HTTP code %1").arg(http_code));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (reply->error() < 200) {
|
||||
@ -149,7 +150,6 @@ QByteArray SubsonicBaseRequest::GetReplyData(QNetworkReply *reply, QString &erro
|
||||
}
|
||||
error = Error(failure_reason);
|
||||
}
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -68,9 +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(); }
|
||||
QUrl server_url() { return service_->server_url(); }
|
||||
QString username() { return service_->username(); }
|
||||
QString password() { return service_->password(); }
|
||||
bool verify_certificate() { return service_->verify_certificate(); }
|
||||
|
@ -105,9 +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();
|
||||
server_url_ = s.value("url").toUrl();
|
||||
username_ = s.value("username").toString();
|
||||
QByteArray password = s.value("password").toByteArray();
|
||||
if (password.isEmpty()) password_.clear();
|
||||
@ -125,10 +123,10 @@ QString SubsonicService::CoverCacheDir() {
|
||||
}
|
||||
|
||||
void SubsonicService::SendPing() {
|
||||
SendPing(hostname_, port_, username_, password_);
|
||||
SendPing(server_url_, username_, password_);
|
||||
}
|
||||
|
||||
void SubsonicService::SendPing(const QString &hostname, const int port, const QString &username, const QString &password) {
|
||||
void SubsonicService::SendPing(QUrl url, const QString &username, const QString &password) {
|
||||
|
||||
const ParamList params = ParamList() << Param("c", kClientName)
|
||||
<< Param("v", kApiVersion)
|
||||
@ -142,17 +140,12 @@ void SubsonicService::SendPing(const QString &hostname, const int port, const QS
|
||||
url_query.addQueryItem(encoded_param.first, encoded_param.second);
|
||||
}
|
||||
|
||||
QUrl url;
|
||||
if (scheme_.isEmpty()) url.setScheme("https");
|
||||
else url.setScheme(scheme_);
|
||||
url.setHost(hostname);
|
||||
url.setPort(port);
|
||||
url.setPath("/rest/ping.view");
|
||||
url.setQuery(url_query);
|
||||
|
||||
QNetworkRequest req(url);
|
||||
|
||||
if (!verify_certificate_) {
|
||||
if (url.scheme() == "https" && !verify_certificate_) {
|
||||
QSslConfiguration sslconfig = QSslConfiguration::defaultConfiguration();
|
||||
sslconfig.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
req.setSslConfiguration(sslconfig);
|
||||
@ -205,6 +198,12 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply) {
|
||||
}
|
||||
}
|
||||
|
||||
int http_code = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||
if (http_code != 200) {
|
||||
PingError(QString("Received HTTP code %1").arg(http_code));
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data(reply->readAll());
|
||||
|
||||
QJsonParseError json_error;
|
||||
@ -288,8 +287,8 @@ void SubsonicService::HandlePingReply(QNetworkReply *reply) {
|
||||
|
||||
void SubsonicService::CheckConfiguration() {
|
||||
|
||||
if (hostname_.isEmpty()) {
|
||||
emit TestComplete(false, "Missing Subsonic hostname.");
|
||||
if (server_url_.isEmpty()) {
|
||||
emit TestComplete(false, "Missing Subsonic server url.");
|
||||
return;
|
||||
}
|
||||
if (username_.isEmpty()) {
|
||||
|
@ -63,9 +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_; }
|
||||
QUrl server_url() { return server_url_; }
|
||||
QString username() { return username_; }
|
||||
QString password() { return password_; }
|
||||
bool verify_certificate() { return verify_certificate_; }
|
||||
@ -86,7 +84,7 @@ class SubsonicService : public InternetService {
|
||||
public slots:
|
||||
void ShowConfig();
|
||||
void SendPing();
|
||||
void SendPing(const QString &hostname, const int port, const QString &username, const QString &password);
|
||||
void SendPing(QUrl url, const QString &username, const QString &password);
|
||||
void GetSongs();
|
||||
void ResetSongsRequest();
|
||||
|
||||
@ -119,9 +117,7 @@ class SubsonicService : public InternetService {
|
||||
|
||||
std::shared_ptr<SubsonicRequest> songs_request_;
|
||||
|
||||
QString scheme_;
|
||||
QString hostname_;
|
||||
int port_;
|
||||
QUrl server_url_;
|
||||
QString username_;
|
||||
QString password_;
|
||||
bool verify_certificate_;
|
||||
|
@ -44,12 +44,7 @@ UrlHandler::LoadResult SubsonicUrlHandler::StartLoading(const QUrl &url) {
|
||||
url_query.addQueryItem(encoded_param.first, encoded_param.second);
|
||||
}
|
||||
|
||||
QUrl media_url;
|
||||
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());
|
||||
QUrl media_url(server_url());
|
||||
media_url.setPath("/rest/stream");
|
||||
media_url.setQuery(url_query);
|
||||
|
||||
|
@ -41,7 +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(); }
|
||||
QUrl server_url() const { return service_->server_url(); }
|
||||
LoadResult StartLoading(const QUrl &url);
|
||||
|
||||
private:
|
||||
|
Loading…
x
Reference in New Issue
Block a user