2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
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-08-14 01:07:10 +02:00
|
|
|
#include "lastfmsettingspage.h"
|
2009-12-26 18:19:14 +01:00
|
|
|
#include "lastfmservice.h"
|
2011-07-15 15:27:50 +02:00
|
|
|
#include "internetmodel.h"
|
2011-08-14 01:07:10 +02:00
|
|
|
#include "ui_lastfmsettingspage.h"
|
2010-05-19 17:45:29 +02:00
|
|
|
#include "ui/iconloader.h"
|
2009-12-26 18:19:14 +01:00
|
|
|
|
|
|
|
#include <lastfm/ws.h>
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
2011-04-14 13:11:34 +02:00
|
|
|
#include <QMovie>
|
2010-02-03 19:32:48 +01:00
|
|
|
#include <QSettings>
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
LastFMSettingsPage::LastFMSettingsPage(SettingsDialog* dialog)
|
|
|
|
: SettingsPage(dialog),
|
2011-07-15 15:27:50 +02:00
|
|
|
service_(static_cast<LastFMService*>(InternetModel::ServiceByName("Last.fm"))),
|
2011-08-14 01:07:10 +02:00
|
|
|
ui_(new Ui_LastFMSettingsPage),
|
2010-09-13 23:40:50 +02:00
|
|
|
waiting_for_auth_(false)
|
2009-12-26 18:19:14 +01:00
|
|
|
{
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->setupUi(this);
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2010-05-19 17:45:29 +02:00
|
|
|
// Icons
|
2011-08-14 01:07:10 +02:00
|
|
|
setWindowIcon(QIcon(":/last.fm/as.png"));
|
2010-05-19 17:45:29 +02:00
|
|
|
|
2013-02-05 14:12:39 +01:00
|
|
|
connect(service_, SIGNAL(AuthenticationComplete(bool,QString)),
|
|
|
|
SLOT(AuthenticationComplete(bool,QString)));
|
2011-04-14 13:11:34 +02:00
|
|
|
connect(service_, SIGNAL(UpdatedSubscriberStatus(bool)), SLOT(UpdatedSubscriberStatus(bool)));
|
2011-08-27 23:01:28 +02:00
|
|
|
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(Logout()));
|
|
|
|
connect(ui_->login_state, SIGNAL(LoginClicked()), SLOT(Login()));
|
2011-08-14 01:07:10 +02:00
|
|
|
connect(ui_->login, SIGNAL(clicked()), SLOT(Login()));
|
2010-05-17 02:47:43 +02:00
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
ui_->login_state->AddCredentialField(ui_->username);
|
|
|
|
ui_->login_state->AddCredentialField(ui_->password);
|
|
|
|
ui_->login_state->AddCredentialGroup(ui_->groupBox);
|
|
|
|
|
2010-05-17 02:47:43 +02:00
|
|
|
ui_->username->setMinimumWidth(QFontMetrics(QFont()).width("WWWWWWWWWWWW"));
|
|
|
|
resize(sizeHint());
|
2010-05-10 23:50:31 +02:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
LastFMSettingsPage::~LastFMSettingsPage() {
|
2010-05-10 23:50:31 +02:00
|
|
|
delete ui_;
|
2009-12-26 18:19:14 +01:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void LastFMSettingsPage::Login() {
|
2010-09-13 23:40:50 +02:00
|
|
|
waiting_for_auth_ = true;
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
|
2010-05-10 23:50:31 +02:00
|
|
|
service_->Authenticate(ui_->username->text(), ui_->password->text());
|
2009-12-26 18:19:14 +01:00
|
|
|
}
|
|
|
|
|
2013-02-05 14:12:39 +01:00
|
|
|
void LastFMSettingsPage::AuthenticationComplete(bool success,
|
|
|
|
const QString& message) {
|
2010-09-13 23:40:50 +02:00
|
|
|
if (!waiting_for_auth_)
|
2010-02-03 19:32:48 +01:00
|
|
|
return; // Wasn't us that was waiting for auth
|
|
|
|
|
2010-09-13 23:40:50 +02:00
|
|
|
waiting_for_auth_ = false;
|
2009-12-26 18:19:14 +01:00
|
|
|
|
|
|
|
if (success) {
|
2011-05-09 21:54:04 +02:00
|
|
|
// Clear password just to be sure
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->password->clear();
|
2011-05-09 21:54:04 +02:00
|
|
|
// Save settings
|
|
|
|
Save();
|
2009-12-26 18:19:14 +01:00
|
|
|
} else {
|
2013-02-05 14:12:39 +01:00
|
|
|
QString dialog_text = tr("Your Last.fm credentials were incorrect");
|
|
|
|
if (!message.isEmpty()) {
|
|
|
|
dialog_text = message;
|
|
|
|
}
|
|
|
|
QMessageBox::warning(this, tr("Authentication failed"), dialog_text);
|
2009-12-26 18:19:14 +01:00
|
|
|
}
|
2010-02-03 19:32:48 +01:00
|
|
|
|
2011-11-27 18:53:04 +01:00
|
|
|
RefreshControls(success);
|
2011-04-14 13:11:34 +02:00
|
|
|
service_->UpdateSubscriberStatus();
|
2010-02-03 19:32:48 +01:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void LastFMSettingsPage::Load() {
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->scrobble->setChecked(service_->IsScrobblingEnabled());
|
|
|
|
ui_->love_ban_->setChecked(service_->AreButtonsVisible());
|
2011-04-07 18:25:52 +02:00
|
|
|
ui_->scrobble_button->setChecked(service_->IsScrobbleButtonVisible());
|
2012-05-13 17:04:55 +02:00
|
|
|
ui_->prefer_albumartist->setChecked(service_->PreferAlbumArtist());
|
2011-04-09 11:00:10 +02:00
|
|
|
|
2011-04-14 13:11:34 +02:00
|
|
|
if (service_->IsAuthenticated()) {
|
|
|
|
service_->UpdateSubscriberStatus();
|
|
|
|
}
|
|
|
|
|
2011-04-13 17:54:15 +02:00
|
|
|
RefreshControls(service_->IsAuthenticated());
|
2010-02-03 19:32:48 +01:00
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void LastFMSettingsPage::UpdatedSubscriberStatus(bool is_subscriber) {
|
2011-08-27 23:01:28 +02:00
|
|
|
ui_->login_state->SetAccountTypeVisible(!is_subscriber);
|
2011-04-14 13:11:34 +02:00
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
if (!is_subscriber) {
|
2011-04-28 12:32:56 +02:00
|
|
|
if (service_->HasConnectionProblems()) {
|
2011-08-27 23:01:28 +02:00
|
|
|
ui_->login_state->SetAccountTypeText(
|
2011-04-28 12:32:56 +02:00
|
|
|
tr("Clementine couldn't fetch your subscription status since there are problems "
|
|
|
|
"with your connection. Played tracks will be cached and sent later to Last.fm."));
|
|
|
|
} else {
|
2011-08-27 23:01:28 +02:00
|
|
|
ui_->login_state->SetAccountTypeText(
|
2011-04-28 12:32:56 +02:00
|
|
|
tr("You will not be able to play Last.fm radio stations "
|
|
|
|
"as you are not a Last.fm subscriber."));
|
|
|
|
}
|
2011-04-14 13:11:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void LastFMSettingsPage::Save() {
|
2010-02-03 19:32:48 +01:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(LastFMService::kSettingsGroup);
|
2010-05-10 23:50:31 +02:00
|
|
|
s.setValue("ScrobblingEnabled", ui_->scrobble->isChecked());
|
|
|
|
s.setValue("ShowLoveBanButtons", ui_->love_ban_->isChecked());
|
2011-04-07 18:25:52 +02:00
|
|
|
s.setValue("ShowScrobbleButton", ui_->scrobble_button->isChecked());
|
2012-05-13 17:04:55 +02:00
|
|
|
s.setValue("PreferAlbumArtist", ui_->prefer_albumartist->isChecked());
|
2010-02-03 19:32:48 +01:00
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
service_->ReloadSettings();
|
2009-12-26 18:19:14 +01:00
|
|
|
}
|
2010-04-07 21:26:49 +02:00
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
void LastFMSettingsPage::Logout() {
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->username->clear();
|
|
|
|
ui_->password->clear();
|
2011-04-09 11:00:10 +02:00
|
|
|
RefreshControls(false);
|
|
|
|
|
2010-04-07 21:26:49 +02:00
|
|
|
service_->SignOut();
|
|
|
|
}
|
2011-04-09 11:00:10 +02:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
void LastFMSettingsPage::RefreshControls(bool authenticated) {
|
2011-08-27 23:01:28 +02:00
|
|
|
ui_->login_state->SetLoggedIn(authenticated ? LoginStateWidget::LoggedIn
|
|
|
|
: LoginStateWidget::LoggedOut,
|
|
|
|
lastfm::ws::Username);
|
|
|
|
ui_->login_state->SetAccountTypeVisible(!authenticated);
|
2011-04-17 17:25:32 +02:00
|
|
|
|
2011-08-27 23:01:28 +02:00
|
|
|
if (!authenticated) {
|
|
|
|
ui_->login_state->SetAccountTypeText(
|
2011-04-13 17:54:15 +02:00
|
|
|
tr("You can scrobble tracks for free, but only "
|
|
|
|
"<span style=\" font-weight:600;\">paid subscribers</span> "
|
|
|
|
"can stream Last.fm radio from Clementine."));
|
2011-04-09 11:00:10 +02:00
|
|
|
}
|
|
|
|
}
|