2014-12-17 19:02:21 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2011, 2013, Alan Briolat <alan.briolat@gmail.com>
|
|
|
|
Copyright 2013, Ross Wolfson <ross.wolfson@gmail.com>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.com>
|
|
|
|
Copyright 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
|
|
|
|
Clementine 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.
|
|
|
|
|
|
|
|
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-12-06 00:10:25 +01:00
|
|
|
#include "subsonicsettingspage.h"
|
|
|
|
#include "ui_subsonicsettingspage.h"
|
|
|
|
|
|
|
|
#include <QSettings>
|
|
|
|
|
2014-12-19 00:40:30 +01:00
|
|
|
#include "core/logging.h"
|
|
|
|
#include "internet/core/internetmodel.h"
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
SubsonicSettingsPage::SubsonicSettingsPage(SettingsDialog* dialog)
|
|
|
|
: SettingsPage(dialog),
|
|
|
|
ui_(new Ui_SubsonicSettingsPage),
|
|
|
|
service_(InternetModel::Service<SubsonicService>()) {
|
2011-12-06 00:10:25 +01:00
|
|
|
ui_->setupUi(this);
|
2011-12-07 15:01:28 +01:00
|
|
|
setWindowIcon(QIcon(":/providers/subsonic-32.png"));
|
2011-12-08 21:00:50 +01:00
|
|
|
|
2013-01-27 13:06:12 +01:00
|
|
|
connect(ui_->server, SIGNAL(editingFinished()),
|
|
|
|
SLOT(ServerEditingFinished()));
|
2011-12-08 21:00:50 +01:00
|
|
|
connect(ui_->login, SIGNAL(clicked()), SLOT(Login()));
|
|
|
|
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(Logout()));
|
|
|
|
connect(service_, SIGNAL(LoginStateChanged(SubsonicService::LoginState)),
|
|
|
|
SLOT(LoginStateChanged(SubsonicService::LoginState)));
|
|
|
|
|
|
|
|
ui_->login_state->AddCredentialField(ui_->server);
|
|
|
|
ui_->login_state->AddCredentialField(ui_->username);
|
|
|
|
ui_->login_state->AddCredentialField(ui_->password);
|
2013-05-05 03:33:03 +02:00
|
|
|
ui_->login_state->AddCredentialField(ui_->usesslv3);
|
2011-12-08 21:00:50 +01:00
|
|
|
ui_->login_state->AddCredentialGroup(ui_->server_group);
|
2013-01-27 13:06:12 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("Streaming from a Subsonic server requires a valid server license "
|
|
|
|
"after the 30-day trial period."));
|
2013-01-27 13:06:12 +01:00
|
|
|
ui_->login_state->SetAccountTypeVisible(true);
|
2011-12-06 00:10:25 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
SubsonicSettingsPage::~SubsonicSettingsPage() { delete ui_; }
|
2011-12-06 00:10:25 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SubsonicSettingsPage::Load() {
|
2011-12-06 00:10:25 +01:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(SubsonicService::kSettingsGroup);
|
|
|
|
|
|
|
|
ui_->server->setText(s.value("server").toString());
|
|
|
|
ui_->username->setText(s.value("username").toString());
|
|
|
|
ui_->password->setText(s.value("password").toString());
|
2013-05-05 03:33:03 +02:00
|
|
|
ui_->usesslv3->setChecked(s.value("usesslv3").toBool());
|
2011-12-08 21:00:50 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// If the settings are complete, SubsonicService will have used them already
|
|
|
|
// and
|
2013-01-27 13:06:12 +01:00
|
|
|
// we can tell the user if they worked
|
|
|
|
if (ui_->server->text() != "" && ui_->username->text() != "") {
|
|
|
|
LoginStateChanged(service_->login_state());
|
|
|
|
}
|
2011-12-06 00:10:25 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SubsonicSettingsPage::Save() {
|
2011-12-06 00:10:25 +01:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(SubsonicService::kSettingsGroup);
|
|
|
|
|
|
|
|
s.setValue("server", ui_->server->text());
|
|
|
|
s.setValue("username", ui_->username->text());
|
|
|
|
s.setValue("password", ui_->password->text());
|
2013-05-05 03:33:03 +02:00
|
|
|
s.setValue("usesslv3", ui_->usesslv3->isChecked());
|
2011-12-06 00:10:25 +01:00
|
|
|
}
|
2011-12-08 21:00:50 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SubsonicSettingsPage::LoginStateChanged(
|
|
|
|
SubsonicService::LoginState newstate) {
|
2011-12-08 21:00:50 +01:00
|
|
|
const bool logged_in = newstate == SubsonicService::LoginState_Loggedin;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->login_state->SetLoggedIn(
|
|
|
|
logged_in ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut,
|
|
|
|
QString("%1 (%2)").arg(ui_->username->text()).arg(ui_->server->text()));
|
2011-12-08 21:00:50 +01:00
|
|
|
ui_->login_state->SetAccountTypeVisible(!logged_in);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
switch (newstate) {
|
|
|
|
case SubsonicService::LoginState_BadServer:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("Could not connect to Subsonic, check server URL. "
|
|
|
|
"Example: http://localhost:4040/"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_BadCredentials:
|
|
|
|
ui_->login_state->SetAccountTypeText(tr("Wrong username or password."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_OutdatedClient:
|
|
|
|
ui_->login_state->SetAccountTypeText(tr(
|
|
|
|
"Incompatible Subsonic REST protocol version. Client must upgrade."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_OutdatedServer:
|
|
|
|
ui_->login_state->SetAccountTypeText(tr(
|
|
|
|
"Incompatible Subsonic REST protocol version. Server must upgrade."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_Unlicensed:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("The trial period for the Subsonic server is over. "
|
|
|
|
"Please donate to get a license key. Visit subsonic.org for "
|
|
|
|
"details."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_OtherError:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("An unspecified error occurred."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_ConnectionRefused:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("Connection refused by server, check server URL. "
|
|
|
|
"Example: http://localhost:4040/"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_HostNotFound:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("Host not found, check server URL. "
|
|
|
|
"Example: http://localhost:4040/"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_Timeout:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("Connection timed out, check server URL. "
|
|
|
|
"Example: http://localhost:4040/"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_SslError:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("SSL handshake error, verify server configuration. "
|
|
|
|
"SSLv3 option below may workaround some issues."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_IncompleteCredentials:
|
|
|
|
ui_->login_state->SetAccountTypeText(tr(
|
|
|
|
"Incomplete configuration, please ensure all fields are populated."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_RedirectLimitExceeded:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("Redirect limit exceeded, verify server configuration."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SubsonicService::LoginState_RedirectNoUrl:
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
|
|
|
tr("HTTP 3xx status code received without URL, "
|
|
|
|
"verify server configuration."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2011-12-08 21:00:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-27 13:06:12 +01:00
|
|
|
void SubsonicSettingsPage::ServerEditingFinished() {
|
|
|
|
QString input = ui_->server->text();
|
|
|
|
QUrl url = QUrl::fromUserInput(input);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Veto things that don't get guessed as an HTTP URL, the result will be
|
|
|
|
// unhelpful
|
2013-01-27 13:06:12 +01:00
|
|
|
if (!url.scheme().startsWith("http")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// If the user specified a /rest location, remove it since we're going to
|
|
|
|
// re-add it later
|
2013-07-03 03:16:41 +02:00
|
|
|
url = SubsonicService::ScrubUrl(url);
|
2013-01-27 13:06:12 +01:00
|
|
|
|
|
|
|
ui_->server->setText(url.toString());
|
|
|
|
qLog(Debug) << "URL fixed:" << input << "to" << url;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SubsonicSettingsPage::Login() {
|
2011-12-08 21:00:50 +01:00
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
|
2014-02-07 16:34:20 +01:00
|
|
|
service_->Login(ui_->server->text(), ui_->username->text(),
|
|
|
|
ui_->password->text(), ui_->usesslv3->isChecked());
|
2011-12-08 21:00:50 +01:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void SubsonicSettingsPage::Logout() {
|
2011-12-08 21:00:50 +01:00
|
|
|
ui_->username->setText("");
|
|
|
|
ui_->password->setText("");
|
|
|
|
}
|