2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2014-12-17 19:02:21 +01:00
|
|
|
Copyright 2009-2011, 2013, David Sansome <me@davidsansome.com>
|
|
|
|
Copyright 2011, Andrea Decorte <adecorte@gmail.com>
|
|
|
|
Copyright 2011, 2014, John Maguire <john.maguire@gmail.com>
|
|
|
|
Copyright 2012, Kacper "mattrick" Banasik <mattrick@jabster.pl>
|
|
|
|
Copyright 2014, Krzysztof Sobiecki <sobkas@gmail.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
|
|
|
|
2015-06-16 15:36:14 +02:00
|
|
|
#include <lastfm5/ws.h>
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2016-02-03 15:33:46 +01:00
|
|
|
#include <QDesktopServices>
|
2009-12-26 18:19:14 +01:00
|
|
|
#include <QMessageBox>
|
2010-02-03 19:32:48 +01:00
|
|
|
#include <QSettings>
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2014-03-27 18:55:58 +01:00
|
|
|
#include "core/application.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "internet/core/internetmodel.h"
|
|
|
|
#include "lastfmservice.h"
|
2014-03-27 18:55:58 +01:00
|
|
|
#include "ui/iconloader.h"
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "ui_lastfmsettingspage.h"
|
2014-03-27 18:55:58 +01:00
|
|
|
|
2011-08-14 01:07:10 +02:00
|
|
|
LastFMSettingsPage::LastFMSettingsPage(SettingsDialog* dialog)
|
2014-02-07 16:34:20 +01:00
|
|
|
: SettingsPage(dialog),
|
2014-03-27 18:55:58 +01:00
|
|
|
service_(static_cast<LastFMService*>(dialog->app()->scrobbler())),
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_(new Ui_LastFMSettingsPage),
|
|
|
|
waiting_for_auth_(false) {
|
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
|
2015-10-14 03:01:08 +02:00
|
|
|
setWindowIcon(IconLoader::Load("lastfm", IconLoader::Provider));
|
2010-05-19 17:45:29 +02:00
|
|
|
|
2017-08-24 20:32:14 +02:00
|
|
|
connect(service_, SIGNAL(AuthenticationComplete(bool)),
|
|
|
|
SLOT(AuthenticationComplete(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
|
|
|
|
2016-02-03 15:33:46 +01:00
|
|
|
ui_->login_state->AddCredentialGroup(ui_->login_container);
|
2011-08-27 23:01:28 +02:00
|
|
|
|
2010-05-17 02:47:43 +02:00
|
|
|
resize(sizeHint());
|
2010-05-10 23:50:31 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
LastFMSettingsPage::~LastFMSettingsPage() { 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);
|
2017-08-24 20:32:14 +02:00
|
|
|
service_->Authenticate();
|
2016-02-03 15:33:46 +01:00
|
|
|
}
|
|
|
|
|
2017-08-24 20:32:14 +02:00
|
|
|
void LastFMSettingsPage::AuthenticationComplete(bool success) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!waiting_for_auth_) return; // Wasn't us that was waiting for auth
|
2010-02-03 19:32:48 +01:00
|
|
|
|
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
|
|
|
// Save settings
|
|
|
|
Save();
|
2009-12-26 18:19:14 +01:00
|
|
|
} else {
|
2017-08-28 23:03:22 +02:00
|
|
|
QString dialog_text = tr("Could not log in to Last.fm. Please try again.");
|
2013-02-05 14:12:39 +01:00
|
|
|
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);
|
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-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::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() {
|
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) {
|
2014-02-07 16:34:20 +01:00
|
|
|
ui_->login_state->SetLoggedIn(
|
|
|
|
authenticated ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut,
|
|
|
|
lastfm::ws::Username);
|
2011-04-09 11:00:10 +02:00
|
|
|
}
|