Improve experience of setting up a subsonic connection

This commit is contained in:
Alan Briolat 2013-01-27 12:06:12 +00:00 committed by John Maguire
parent 90803fa0e0
commit 970a615846
4 changed files with 35 additions and 5 deletions

View File

@ -179,7 +179,7 @@ void SubsonicService::Ping() {
}
QUrl SubsonicService::BuildRequestUrl(const QString& view) const {
QUrl url(server_ + "rest/" + view + ".view");
QUrl url(server_ + "/rest/" + view + ".view");
url.addQueryItem("v", kApiVersion);
url.addQueryItem("c", kApiClientName);
url.addQueryItem("u", username_);

View File

@ -1,5 +1,6 @@
#include "subsonicsettingspage.h"
#include "ui_subsonicsettingspage.h"
#include "core/logging.h"
#include "internetmodel.h"
#include <QSettings>
@ -12,6 +13,8 @@ SubsonicSettingsPage::SubsonicSettingsPage(SettingsDialog *dialog)
ui_->setupUi(this);
setWindowIcon(QIcon(":/providers/subsonic-32.png"));
connect(ui_->server, SIGNAL(editingFinished()),
SLOT(ServerEditingFinished()));
connect(ui_->login, SIGNAL(clicked()), SLOT(Login()));
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(Logout()));
connect(service_, SIGNAL(LoginStateChanged(SubsonicService::LoginState)),
@ -21,6 +24,10 @@ SubsonicSettingsPage::SubsonicSettingsPage(SettingsDialog *dialog)
ui_->login_state->AddCredentialField(ui_->username);
ui_->login_state->AddCredentialField(ui_->password);
ui_->login_state->AddCredentialGroup(ui_->server_group);
ui_->login_state->SetAccountTypeText(tr(
"Streaming from a Subsonic server requires a valid server license after the 30-day trial period."));
ui_->login_state->SetAccountTypeVisible(true);
}
SubsonicSettingsPage::~SubsonicSettingsPage()
@ -37,9 +44,11 @@ void SubsonicSettingsPage::Load()
ui_->username->setText(s.value("username").toString());
ui_->password->setText(s.value("password").toString());
// These are the same settings SubsonicService will have used already, so see if
// they were successful...
LoginStateChanged(service_->login_state());
// If the settings are complete, SubsonicService will have used them already and
// we can tell the user if they worked
if (ui_->server->text() != "" && ui_->username->text() != "") {
LoginStateChanged(service_->login_state());
}
}
void SubsonicSettingsPage::Save()
@ -96,6 +105,26 @@ void SubsonicSettingsPage::LoginStateChanged(SubsonicService::LoginState newstat
}
}
void SubsonicSettingsPage::ServerEditingFinished() {
QString input = ui_->server->text();
QUrl url = QUrl::fromUserInput(input);
// Veto things that don't get guessed as an HTTP URL, the result will be unhelpful
if (!url.scheme().startsWith("http")) {
return;
}
// A direct paste of the server URL will probably include the trailing index.view, so remove it
if (url.path().endsWith("index.view")) {
QString newpath = url.path();
newpath.chop(10);
url.setPath(newpath);
}
ui_->server->setText(url.toString());
qLog(Debug) << "URL fixed:" << input << "to" << url;
}
void SubsonicSettingsPage::Login()
{
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);

View File

@ -21,6 +21,7 @@ class SubsonicSettingsPage : public SettingsPage
void LoginStateChanged(SubsonicService::LoginState newstate);
private slots:
void ServerEditingFinished();
void Login();
void Logout();

View File

@ -26,7 +26,7 @@
<item row="0" column="0">
<widget class="QLabel" name="server_label">
<property name="text">
<string>Server</string>
<string>Server URL</string>
</property>
</widget>
</item>