2009-12-26 18:19:14 +01:00
|
|
|
#include "lastfmconfig.h"
|
|
|
|
#include "lastfmservice.h"
|
2010-02-03 19:32:48 +01:00
|
|
|
#include "radiomodel.h"
|
2009-12-26 18:19:14 +01:00
|
|
|
|
|
|
|
#include <lastfm/ws.h>
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
2010-02-03 19:32:48 +01:00
|
|
|
#include <QSettings>
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2010-02-03 19:32:48 +01:00
|
|
|
LastFMConfig::LastFMConfig(QWidget *parent)
|
|
|
|
: QWidget(parent),
|
|
|
|
service_(static_cast<LastFMService*>(RadioModel::ServiceByName("Last.fm")))
|
2009-12-26 18:19:14 +01:00
|
|
|
{
|
|
|
|
ui_.setupUi(this);
|
|
|
|
ui_.busy->hide();
|
|
|
|
|
|
|
|
connect(service_, SIGNAL(AuthenticationComplete(bool)), SLOT(AuthenticationComplete(bool)));
|
|
|
|
}
|
|
|
|
|
2010-02-03 19:32:48 +01:00
|
|
|
bool LastFMConfig::NeedsValidation() const {
|
|
|
|
return !ui_.username->text().isEmpty() && !ui_.password->text().isEmpty();
|
|
|
|
}
|
2009-12-26 18:19:14 +01:00
|
|
|
|
2010-02-03 19:32:48 +01:00
|
|
|
void LastFMConfig::Validate() {
|
2009-12-26 18:19:14 +01:00
|
|
|
ui_.busy->show();
|
|
|
|
|
|
|
|
service_->Authenticate(ui_.username->text(), ui_.password->text());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LastFMConfig::AuthenticationComplete(bool success) {
|
2010-02-03 19:32:48 +01:00
|
|
|
if (!ui_.busy->isVisible())
|
|
|
|
return; // Wasn't us that was waiting for auth
|
|
|
|
|
2009-12-26 18:19:14 +01:00
|
|
|
ui_.busy->hide();
|
|
|
|
|
|
|
|
if (success) {
|
|
|
|
ui_.username->setText(lastfm::ws::Username);
|
|
|
|
ui_.password->clear();
|
|
|
|
} else {
|
|
|
|
QMessageBox::warning(this, "Authentication failed", "Your Last.fm credentials were incorrect");
|
|
|
|
}
|
2010-02-03 19:32:48 +01:00
|
|
|
|
|
|
|
emit ValidationComplete(success);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LastFMConfig::Load() {
|
|
|
|
ui_.username->setText(lastfm::ws::Username);
|
|
|
|
ui_.scrobble->setChecked(service_->IsScrobblingEnabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LastFMConfig::Save() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(LastFMService::kSettingsGroup);
|
|
|
|
s.setValue("ScrobblingEnabled", ui_.scrobble->isChecked());
|
|
|
|
s.endGroup();
|
|
|
|
|
|
|
|
service_->ReloadSettings();
|
2009-12-26 18:19:14 +01:00
|
|
|
}
|