2011-09-20 00:54:22 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.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 "groovesharkservice.h"
|
2011-11-27 18:54:36 +01:00
|
|
|
#include "groovesharksettingspage.h"
|
2011-09-20 00:54:22 +02:00
|
|
|
#include "internetmodel.h"
|
2011-11-27 18:54:36 +01:00
|
|
|
#include "core/logging.h"
|
|
|
|
#include "core/network.h"
|
2011-09-20 00:54:22 +02:00
|
|
|
#include "ui_groovesharksettingspage.h"
|
|
|
|
#include "ui/iconloader.h"
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
#include <QNetworkRequest>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QtDebug>
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
GroovesharkSettingsPage::GroovesharkSettingsPage(SettingsDialog* dialog)
|
2011-09-20 00:54:22 +02:00
|
|
|
: SettingsPage(dialog),
|
2011-10-05 21:59:15 +02:00
|
|
|
ui_(new Ui_GroovesharkSettingsPage),
|
|
|
|
service_(InternetModel::Service<GroovesharkService>()),
|
2011-09-20 00:54:22 +02:00
|
|
|
validated_(false)
|
|
|
|
{
|
|
|
|
ui_->setupUi(this);
|
|
|
|
|
|
|
|
setWindowIcon(QIcon(":/providers/grooveshark.png"));
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
ui_->login_state->AddCredentialField(ui_->username);
|
|
|
|
ui_->login_state->AddCredentialField(ui_->password);
|
|
|
|
ui_->login_state->AddCredentialGroup(ui_->account_group);
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
GroovesharkSettingsPage::~GroovesharkSettingsPage() {
|
2011-09-20 00:54:22 +02:00
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
void GroovesharkSettingsPage::Login() {
|
2011-09-20 00:54:22 +02:00
|
|
|
if (service_->IsLoggedIn()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui_->login_state->SetLoggedIn(LoginStateWidget::LoginInProgress);
|
|
|
|
service_->Login(ui_->username->text(), ui_->password->text());
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
void GroovesharkSettingsPage::Load() {
|
2011-09-20 00:54:22 +02:00
|
|
|
QSettings s;
|
2011-10-05 21:59:15 +02:00
|
|
|
s.beginGroup(GroovesharkService::kSettingsGroup);
|
2011-09-20 00:54:22 +02:00
|
|
|
|
|
|
|
original_username_ = s.value("username").toString();
|
|
|
|
|
|
|
|
ui_->username->setText(original_username_);
|
|
|
|
validated_ = false;
|
|
|
|
|
|
|
|
UpdateLoginState();
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
void GroovesharkSettingsPage::Save() {
|
2011-09-20 00:54:22 +02:00
|
|
|
QSettings s;
|
2011-10-05 21:59:15 +02:00
|
|
|
s.beginGroup(GroovesharkService::kSettingsGroup);
|
2011-09-20 00:54:22 +02:00
|
|
|
|
|
|
|
s.setValue("username", ui_->username->text());
|
|
|
|
s.setValue("sessionid", service_->session_id());
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
void GroovesharkSettingsPage::LoginFinished(bool success) {
|
2011-09-20 00:54:22 +02:00
|
|
|
validated_ = success;
|
|
|
|
|
|
|
|
Save();
|
|
|
|
UpdateLoginState();
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
void GroovesharkSettingsPage::UpdateLoginState() {
|
2011-09-20 00:54:22 +02:00
|
|
|
const bool logged_in = service_->IsLoggedIn();
|
|
|
|
|
|
|
|
ui_->login_state->SetLoggedIn(logged_in ? LoginStateWidget::LoggedIn
|
|
|
|
: LoginStateWidget::LoggedOut,
|
|
|
|
ui_->username->text());
|
|
|
|
ui_->login_state->SetAccountTypeVisible(!logged_in);
|
|
|
|
|
|
|
|
switch (service_->login_state()) {
|
2011-10-05 21:59:15 +02:00
|
|
|
case GroovesharkService::LoginState_NoPremium:
|
|
|
|
ui_->login_state->SetAccountTypeText(tr("You do not have a Grooveshark Anywhere account."));
|
2011-09-20 00:54:22 +02:00
|
|
|
break;
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
case GroovesharkService::LoginState_AuthFailed:
|
2011-09-20 00:54:22 +02:00
|
|
|
ui_->login_state->SetAccountTypeText(tr("Your username or password was incorrect."));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-10-05 21:59:15 +02:00
|
|
|
ui_->login_state->SetAccountTypeText(tr("A Grooveshark Anywhere account is required."));
|
2011-09-20 00:54:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-05 21:59:15 +02:00
|
|
|
void GroovesharkSettingsPage::Logout() {
|
2011-09-20 00:54:22 +02:00
|
|
|
service_->Logout();
|
|
|
|
UpdateLoginState();
|
|
|
|
}
|