/* This file is part of Clementine. Copyright 2010, David Sansome 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 . */ #include "spotifysettingspage.h" #include "core/network.h" #include "spotifyservice.h" #include "internetmodel.h" #include "ui_spotifysettingspage.h" #include "ui/iconloader.h" #include #include #include #include #include SpotifySettingsPage::SpotifySettingsPage(SettingsDialog* dialog) : SettingsPage(dialog), network_(new NetworkAccessManager(this)), ui_(new Ui_SpotifySettingsPage), service_(InternetModel::Service()), validated_(false) { ui_->setupUi(this); setWindowIcon(QIcon(":/icons/svg/spotify.svg")); QFont bold_font(font()); bold_font.setBold(true); ui_->blob_status->setFont(bold_font); connect(ui_->download_blob, SIGNAL(clicked()), SLOT(DownloadBlob())); connect(ui_->login, SIGNAL(clicked()), SLOT(Login())); connect(ui_->login_state, SIGNAL(LogoutClicked()), SLOT(Logout())); connect(ui_->login_state, SIGNAL(LoginClicked()), SLOT(Login())); connect(service_, SIGNAL(LoginFinished(bool)), SLOT(LoginFinished(bool))); connect(service_, SIGNAL(BlobStateChanged()), SLOT(BlobStateChanged())); ui_->login_state->AddCredentialField(ui_->username); ui_->login_state->AddCredentialField(ui_->password); ui_->login_state->AddCredentialGroup(ui_->account_group); BlobStateChanged(); } SpotifySettingsPage::~SpotifySettingsPage() { delete ui_; } void SpotifySettingsPage::BlobStateChanged() { const bool installed = service_->IsBlobInstalled(); ui_->account_group->setEnabled(installed); ui_->blob_status->setText(installed ? tr("Installed") : tr("Not installed")); #ifdef Q_OS_LINUX ui_->download_blob->setEnabled(!installed); #else ui_->download_blob->setEnabled(false); #endif } void SpotifySettingsPage::DownloadBlob() { service_->InstallBlob(); } void SpotifySettingsPage::Login() { if (!service_->IsBlobInstalled()) { return; } if (ui_->username->text() == original_username_ && ui_->password->text() == original_password_ && service_->login_state() == SpotifyService::LoginState_LoggedIn) { return; } ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress); service_->Login(ui_->username->text(), ui_->password->text()); } void SpotifySettingsPage::Load() { QSettings s; s.beginGroup(SpotifyService::kSettingsGroup); original_username_ = s.value("username").toString(); original_password_ = s.value("password").toString(); ui_->username->setText(original_username_); ui_->password->setText(original_password_); validated_ = false; UpdateLoginState(); } void SpotifySettingsPage::Save() { QSettings s; s.beginGroup(SpotifyService::kSettingsGroup); s.setValue("username", ui_->username->text()); s.setValue("password", ui_->password->text()); } void SpotifySettingsPage::LoginFinished(bool success) { validated_ = success; Save(); UpdateLoginState(); } void SpotifySettingsPage::UpdateLoginState() { const bool logged_in = service_->login_state() == SpotifyService::LoginState_LoggedIn; ui_->login_state->SetLoggedIn(logged_in ? LoginStateWidget::LoggedIn : LoginStateWidget::LoggedOut, ui_->username->text()); ui_->login_state->SetAccountTypeVisible(!logged_in); switch (service_->login_state()) { case SpotifyService::LoginState_NoPremium: ui_->login_state->SetAccountTypeText(tr("You do not have a Spotify Premium account.")); break; case SpotifyService::LoginState_Banned: case SpotifyService::LoginState_BadCredentials: ui_->login_state->SetAccountTypeText(tr("Your username or password was incorrect.")); break; default: ui_->login_state->SetAccountTypeText(tr("A Spotify Premium account is required.")); break; } } void SpotifySettingsPage::Logout() { service_->Logout(); UpdateLoginState(); ui_->username->clear(); }