2019-06-17 23:54:24 +02:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2019-2021, Jonas Kvinge <jonas@jkvinge.net>
|
2019-06-17 23:54:24 +02:00
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <QObject>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QVariant>
|
|
|
|
#include <QByteArray>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QString>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QUrl>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QSettings>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
2019-06-17 23:54:24 +02:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QEvent>
|
|
|
|
|
2020-02-09 02:29:35 +01:00
|
|
|
#include "settingsdialog.h"
|
2019-06-17 23:54:24 +02:00
|
|
|
#include "subsonicsettingspage.h"
|
|
|
|
#include "ui_subsonicsettingspage.h"
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/iconloader.h"
|
2024-04-11 02:56:01 +02:00
|
|
|
#include "core/settings.h"
|
2024-06-12 22:23:05 +02:00
|
|
|
#include "streaming/streamingservices.h"
|
2019-06-17 23:54:24 +02:00
|
|
|
#include "subsonic/subsonicservice.h"
|
|
|
|
|
|
|
|
const char *SubsonicSettingsPage::kSettingsGroup = "Subsonic";
|
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
SubsonicSettingsPage::SubsonicSettingsPage(SettingsDialog *dialog, QWidget *parent)
|
|
|
|
: SettingsPage(dialog, parent),
|
2019-06-17 23:54:24 +02:00
|
|
|
ui_(new Ui::SubsonicSettingsPage),
|
2024-06-12 22:23:05 +02:00
|
|
|
service_(dialog->app()->streaming_services()->Service<SubsonicService>()) {
|
2019-06-17 23:54:24 +02:00
|
|
|
|
|
|
|
ui_->setupUi(this);
|
2024-04-09 23:20:26 +02:00
|
|
|
setWindowIcon(IconLoader::Load(QStringLiteral("subsonic"), true, 0, 32));
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2021-01-26 16:48:04 +01:00
|
|
|
QObject::connect(ui_->button_test, &QPushButton::clicked, this, &SubsonicSettingsPage::TestClicked);
|
2023-07-21 05:55:24 +02:00
|
|
|
QObject::connect(ui_->button_deletesongs, &QPushButton::clicked, &*service_, &SubsonicService::DeleteSongs);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2023-07-21 05:55:24 +02:00
|
|
|
QObject::connect(this, &SubsonicSettingsPage::Test, &*service_, &SubsonicService::SendPingWithCredentials);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2023-07-21 05:55:24 +02:00
|
|
|
QObject::connect(&*service_, &SubsonicService::TestFailure, this, &SubsonicSettingsPage::TestFailure);
|
|
|
|
QObject::connect(&*service_, &SubsonicService::TestSuccess, this, &SubsonicSettingsPage::TestSuccess);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
dialog->installEventFilter(this);
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2021-09-26 16:49:53 +02:00
|
|
|
ui_->checkbox_http2->show();
|
2021-06-13 19:55:45 +02:00
|
|
|
|
2019-06-17 23:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SubsonicSettingsPage::~SubsonicSettingsPage() { delete ui_; }
|
|
|
|
|
|
|
|
void SubsonicSettingsPage::Load() {
|
|
|
|
|
2024-04-11 02:56:01 +02:00
|
|
|
Settings s;
|
2019-06-17 23:54:24 +02:00
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
ui_->enable->setChecked(s.value("enabled", false).toBool());
|
2019-06-22 08:38:50 +02:00
|
|
|
ui_->server_url->setText(s.value("url").toString());
|
2019-06-17 23:54:24 +02:00
|
|
|
ui_->username->setText(s.value("username").toString());
|
|
|
|
QByteArray password = s.value("password").toByteArray();
|
|
|
|
if (password.isEmpty()) ui_->password->clear();
|
|
|
|
else ui_->password->setText(QString::fromUtf8(QByteArray::fromBase64(password)));
|
2021-09-26 16:50:41 +02:00
|
|
|
ui_->checkbox_http2->setChecked(s.value("http2", false).toBool());
|
2019-06-17 23:54:24 +02:00
|
|
|
ui_->checkbox_verify_certificate->setChecked(s.value("verifycertificate", false).toBool());
|
2019-07-01 01:01:30 +02:00
|
|
|
ui_->checkbox_download_album_covers->setChecked(s.value("downloadalbumcovers", true).toBool());
|
2020-09-23 17:55:12 +02:00
|
|
|
ui_->checkbox_server_scrobbling->setChecked(s.value("serversidescrobbling", false).toBool());
|
2021-07-30 21:16:41 +02:00
|
|
|
|
2023-02-18 14:09:27 +01:00
|
|
|
const AuthMethod auth_method = static_cast<AuthMethod>(s.value("authmethod", static_cast<int>(AuthMethod::MD5)).toInt());
|
2022-03-22 21:09:05 +01:00
|
|
|
switch (auth_method) {
|
2023-02-18 14:09:27 +01:00
|
|
|
case AuthMethod::Hex:
|
2021-07-30 21:16:41 +02:00
|
|
|
ui_->auth_method_hex->setChecked(true);
|
|
|
|
break;
|
2023-02-18 14:09:27 +01:00
|
|
|
case AuthMethod::MD5:
|
2021-07-30 21:16:41 +02:00
|
|
|
ui_->auth_method_md5->setChecked(true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-17 23:54:24 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
2020-05-25 23:56:54 +02:00
|
|
|
Init(ui_->layout_subsonicsettingspage->parentWidget());
|
|
|
|
|
2024-04-11 02:56:01 +02:00
|
|
|
if (!Settings().childGroups().contains(QLatin1String(kSettingsGroup))) set_changed();
|
2020-10-12 17:20:18 +02:00
|
|
|
|
2019-06-17 23:54:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SubsonicSettingsPage::Save() {
|
|
|
|
|
2024-04-11 02:56:01 +02:00
|
|
|
Settings s;
|
2019-06-17 23:54:24 +02:00
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
s.setValue("enabled", ui_->enable->isChecked());
|
2019-06-22 08:38:50 +02:00
|
|
|
s.setValue("url", QUrl(ui_->server_url->text()));
|
2019-06-17 23:54:24 +02:00
|
|
|
s.setValue("username", ui_->username->text());
|
|
|
|
s.setValue("password", QString::fromUtf8(ui_->password->text().toUtf8().toBase64()));
|
2021-06-13 19:55:45 +02:00
|
|
|
s.setValue("http2", ui_->checkbox_http2->isChecked());
|
2019-06-17 23:54:24 +02:00
|
|
|
s.setValue("verifycertificate", ui_->checkbox_verify_certificate->isChecked());
|
2019-07-01 01:01:30 +02:00
|
|
|
s.setValue("downloadalbumcovers", ui_->checkbox_download_album_covers->isChecked());
|
2020-09-23 17:55:12 +02:00
|
|
|
s.setValue("serversidescrobbling", ui_->checkbox_server_scrobbling->isChecked());
|
2021-07-30 21:16:41 +02:00
|
|
|
if (ui_->auth_method_hex->isChecked()) {
|
2023-02-18 14:09:27 +01:00
|
|
|
s.setValue("authmethod", static_cast<int>(AuthMethod::Hex));
|
2021-07-30 21:16:41 +02:00
|
|
|
}
|
|
|
|
else {
|
2023-02-18 14:09:27 +01:00
|
|
|
s.setValue("authmethod", static_cast<int>(AuthMethod::MD5));
|
2021-07-30 21:16:41 +02:00
|
|
|
}
|
2019-06-17 23:54:24 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubsonicSettingsPage::TestClicked() {
|
|
|
|
|
2019-06-22 08:38:50 +02:00
|
|
|
if (ui_->server_url->text().isEmpty() || ui_->username->text().isEmpty() || ui_->password->text().isEmpty()) {
|
|
|
|
QMessageBox::critical(this, tr("Configuration incomplete"), tr("Missing server url, username or password."));
|
2019-06-18 01:22:03 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-22 08:38:50 +02:00
|
|
|
QUrl server_url(ui_->server_url->text());
|
|
|
|
if (!server_url.isValid() || server_url.scheme().isEmpty() || server_url.host().isEmpty()) {
|
|
|
|
QMessageBox::critical(this, tr("Configuration incorrect"), tr("Server URL is invalid."));
|
2019-06-17 23:54:24 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-25 01:06:30 +02:00
|
|
|
Q_EMIT Test(server_url, ui_->username->text(), ui_->password->text(), ui_->auth_method_hex->isChecked() ? AuthMethod::Hex : AuthMethod::MD5);
|
2019-06-17 23:54:24 +02:00
|
|
|
ui_->button_test->setEnabled(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SubsonicSettingsPage::eventFilter(QObject *object, QEvent *event) {
|
|
|
|
|
|
|
|
if (object == dialog() && event->type() == QEvent::Enter) {
|
|
|
|
ui_->button_test->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SettingsPage::eventFilter(object, event);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SubsonicSettingsPage::TestSuccess() {
|
|
|
|
|
2021-09-13 20:49:33 +02:00
|
|
|
if (!isVisible()) return;
|
2019-06-17 23:54:24 +02:00
|
|
|
ui_->button_test->setEnabled(true);
|
|
|
|
|
|
|
|
QMessageBox::information(this, tr("Test successful!"), tr("Test successful!"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-06-20 19:04:08 +02:00
|
|
|
void SubsonicSettingsPage::TestFailure(const QString &failure_reason) {
|
2019-06-17 23:54:24 +02:00
|
|
|
|
2021-09-13 20:49:33 +02:00
|
|
|
if (!isVisible()) return;
|
2019-06-17 23:54:24 +02:00
|
|
|
ui_->button_test->setEnabled(true);
|
|
|
|
|
|
|
|
QMessageBox::warning(this, tr("Test failed!"), failure_reason);
|
|
|
|
|
|
|
|
}
|