Save and load the magnatune settings properly

This commit is contained in:
David Sansome 2010-06-08 23:18:20 +00:00
parent f1fb9ab6b9
commit 38a92e802b
5 changed files with 49 additions and 1 deletions

View File

@ -16,8 +16,11 @@
#include "magnatuneconfig.h"
#include "magnatuneservice.h"
#include "radiomodel.h"
#include "ui_magnatuneconfig.h"
#include <QSettings>
MagnatuneConfig::MagnatuneConfig(QWidget *parent)
: QWidget(parent),
ui_(new Ui_MagnatuneConfig)
@ -31,6 +34,28 @@ MagnatuneConfig::~MagnatuneConfig() {
delete ui_;
}
void MagnatuneConfig::Load() {
QSettings s;
s.beginGroup(MagnatuneService::kSettingsGroup);
ui_->membership->setCurrentIndex(s.value("membership", MagnatuneService::Membership_None).toInt());
ui_->username->setText(s.value("username").toString());
ui_->password->setText(s.value("password").toString());
ui_->format->setCurrentIndex(s.value("format", MagnatuneService::Format_Ogg).toInt());
}
void MagnatuneConfig::Save() {
QSettings s;
s.beginGroup(MagnatuneService::kSettingsGroup);
s.setValue("membership", ui_->membership->currentIndex());
s.setValue("username", ui_->username->text());
s.setValue("password", ui_->password->text());
s.setValue("format", ui_->format->currentIndex());
RadioModel::Service<MagnatuneService>()->ReloadSettings();
}
void MagnatuneConfig::MembershipChanged(int value) {
bool enabled = MagnatuneService::MembershipType(value) !=
MagnatuneService::Membership_None;

View File

@ -27,6 +27,10 @@ public:
MagnatuneConfig(QWidget* parent = 0);
~MagnatuneConfig();
public slots:
void Load();
void Save();
private slots:
void MembershipChanged(int value);

View File

@ -57,6 +57,7 @@ MagnatuneService::MagnatuneService(RadioModel* parent)
library_model_(NULL),
library_sort_model_(new QSortFilterProxyModel(this)),
membership_(Membership_None),
format_(Format_Ogg),
total_song_count_(0),
network_(parent->network()->network())
{
@ -96,6 +97,7 @@ void MagnatuneService::ReloadSettings() {
membership_ = MembershipType(s.value("membership", Membership_None).toInt());
username_ = s.value("username").toString();
password_ = s.value("password").toString();
format_ = PreferredFormat(s.value("format", Format_Ogg).toInt());
}
RadioItem* MagnatuneService::CreateRootItem(RadioItem *parent) {
@ -287,5 +289,6 @@ QUrl MagnatuneService::ModifyUrl(const QUrl& url) const {
ret.setUserName(username_);
ret.setPassword(password_);
qDebug() << url << "becomes" << ret;
return ret;
}

View File

@ -35,13 +35,24 @@ class MagnatuneService : public RadioService {
MagnatuneService(RadioModel* parent);
~MagnatuneService();
// Values are saved in QSettings
// Values are saved in QSettings and are indices into the combo box in
// MagnatuneConfig
enum MembershipType {
Membership_None = 0,
Membership_Streaming = 1,
Membership_Download = 2,
};
// Values are saved in QSettings and are indices into the combo box in
// MagnatuneConfig
enum PreferredFormat {
Format_Ogg = 0,
Format_Flac = 1,
Format_Wav = 2,
Format_MP3_VBR = 3,
Format_MP3_128 = 4,
};
static const char* kServiceName;
static const char* kSettingsGroup;
static const char* kDatabaseUrl;
@ -90,6 +101,7 @@ class MagnatuneService : public RadioService {
MembershipType membership_;
QString username_;
QString password_;
PreferredFormat format_;
int total_song_count_;

View File

@ -178,6 +178,7 @@ void SettingsDialog::accept() {
s.endGroup();
ui_->library_config->Save();
ui_->magnatune->Save();
QDialog::accept();
}
@ -201,6 +202,9 @@ void SettingsDialog::showEvent(QShowEvent*) {
// Last.fm
ui_->lastfm->Load();
// Magnatune
ui_->magnatune->Load();
// Playback
s.beginGroup(Engine::Base::kSettingsGroup);
ui_->fading_out->setChecked(s.value("FadeoutEnabled", true).toBool());