Clementine-audio-player-Mac.../src/internet/lastfm/lastfmsettingspage.cpp

114 lines
3.6 KiB
C++
Raw Normal View History

/* This file is part of Clementine.
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>
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/>.
*/
#include "lastfmsettingspage.h"
2009-12-26 18:19:14 +01:00
#include <lastfm5/ws.h>
2009-12-26 18:19:14 +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
#include "core/application.h"
2020-09-18 16:15:19 +02:00
#include "internet/core/internetmodel.h"
#include "lastfmservice.h"
#include "ui/iconloader.h"
2020-09-18 16:15:19 +02:00
#include "ui_lastfmsettingspage.h"
LastFMSettingsPage::LastFMSettingsPage(SettingsDialog* dialog)
: SettingsPage(dialog),
service_(static_cast<LastFMService*>(dialog->app()->scrobbler())),
ui_(new Ui_LastFMSettingsPage),
waiting_for_auth_(false) {
ui_->setupUi(this);
2009-12-26 18:19:14 +01:00
// Icons
setWindowIcon(IconLoader::Load("lastfm", IconLoader::Provider));
2017-08-24 20:32:14 +02:00
connect(service_, SIGNAL(AuthenticationComplete(bool)),
SLOT(AuthenticationComplete(bool)));
connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(Logout()));
connect(ui_->login_state, SIGNAL(LoginClicked()), SLOT(Login()));
connect(ui_->login, SIGNAL(clicked()), SLOT(Login()));
ui_->login_state->AddCredentialGroup(ui_->login_container);
resize(sizeHint());
}
LastFMSettingsPage::~LastFMSettingsPage() { delete ui_; }
2009-12-26 18:19:14 +01:00
void LastFMSettingsPage::Login() {
waiting_for_auth_ = true;
2009-12-26 18:19:14 +01:00
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
2017-08-24 20:32:14 +02:00
service_->Authenticate();
}
2017-08-24 20:32:14 +02:00
void LastFMSettingsPage::AuthenticationComplete(bool success) {
if (!waiting_for_auth_) return; // Wasn't us that was waiting for auth
2010-02-03 19:32:48 +01:00
waiting_for_auth_ = false;
2009-12-26 18:19:14 +01:00
if (success) {
// Save settings
Save();
2009-12-26 18:19:14 +01:00
} else {
QString dialog_text = tr("Could not log in to Last.fm. Please try again.");
QMessageBox::warning(this, tr("Authentication failed"), dialog_text);
2009-12-26 18:19:14 +01:00
}
2010-02-03 19:32:48 +01:00
RefreshControls(success);
2010-02-03 19:32:48 +01:00
}
void LastFMSettingsPage::Load() {
ui_->scrobble->setChecked(service_->IsScrobblingEnabled());
ui_->love_ban_->setChecked(service_->AreButtonsVisible());
ui_->scrobble_button->setChecked(service_->IsScrobbleButtonVisible());
ui_->prefer_albumartist->setChecked(service_->PreferAlbumArtist());
RefreshControls(service_->IsAuthenticated());
2010-02-03 19:32:48 +01:00
}
void LastFMSettingsPage::Save() {
2010-02-03 19:32:48 +01:00
QSettings s;
s.beginGroup(LastFMService::kSettingsGroup);
s.setValue("ScrobblingEnabled", ui_->scrobble->isChecked());
s.setValue("ShowLoveBanButtons", ui_->love_ban_->isChecked());
s.setValue("ShowScrobbleButton", ui_->scrobble_button->isChecked());
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
}
void LastFMSettingsPage::Logout() {
RefreshControls(false);
service_->SignOut();
}
void LastFMSettingsPage::RefreshControls(bool authenticated) {
ui_->login_state->SetLoggedIn(
authenticated ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut,
lastfm::ws::Username);
}