diff --git a/data/data.qrc b/data/data.qrc
index 5a7f9ce0f..238419c70 100644
--- a/data/data.qrc
+++ b/data/data.qrc
@@ -77,5 +77,6 @@
osd_shadow_edge.png
schema-6.sql
list-add.png
+ document-save.png
diff --git a/data/document-save.png b/data/document-save.png
new file mode 100644
index 000000000..a81e70d47
Binary files /dev/null and b/data/document-save.png differ
diff --git a/src/equalizer.cpp b/src/equalizer.cpp
index 48d5c87b7..f95600281 100644
--- a/src/equalizer.cpp
+++ b/src/equalizer.cpp
@@ -51,7 +51,7 @@ Equalizer::Equalizer(QWidget *parent)
connect(ui_.enable, SIGNAL(toggled(bool)), ui_.slider_container, SLOT(setEnabled(bool)));
connect(ui_.enable, SIGNAL(toggled(bool)), SLOT(Save()));
connect(ui_.preset, SIGNAL(currentIndexChanged(QString)), SLOT(PresetChanged(QString)));
- connect(ui_.preset_add, SIGNAL(clicked()), SLOT(AddPreset()));
+ connect(ui_.preset_save, SIGNAL(clicked()), SLOT(SavePreset()));
connect(ui_.preset_del, SIGNAL(clicked()), SLOT(DelPreset()));
}
@@ -82,6 +82,7 @@ void Equalizer::ReloadSettings() {
// Enabled?
ui_.enable->setChecked(s.value("enabled", false).toBool());
+ ui_.slider_container->setEnabled(ui_.enable->isChecked());
PresetChanged(selected_preset);
}
@@ -110,10 +111,18 @@ void Equalizer::LoadDefaultPresets() {
void Equalizer::AddPreset(const QString& name, const Params& params) {
presets_[name] = params;
- ui_.preset->addItem(name);
+ if (ui_.preset->findText(name) == -1)
+ ui_.preset->addItem(name);
}
void Equalizer::PresetChanged(const QString& name) {
+ if (presets_.contains(last_preset_)) {
+ if (presets_[last_preset_] != current_params()) {
+ SaveCurrentPreset();
+ }
+ }
+ last_preset_ = name;
+
Params& p = presets_[name];
loading_ = true;
@@ -123,28 +132,26 @@ void Equalizer::PresetChanged(const QString& name) {
loading_ = false;
ParametersChanged();
+ Save();
}
-void Equalizer::AddPreset() {
- QString name;
- forever {
- name = QInputDialog::getText(this, tr("New preset"), tr("Name"),
- QLineEdit::Normal, name);
- if (name.isEmpty())
- return;
-
- if (presets_.contains(name)) {
- QMessageBox::information(this, tr("New preset"), tr("There is already a preset with that name"),
- QMessageBox::Ok);
- continue;
- }
-
- break;
+void Equalizer::SavePreset() {
+ QString name = SaveCurrentPreset();
+ if (!name.isEmpty()) {
+ last_preset_ = name;
+ ui_.preset->setCurrentIndex(ui_.preset->findText(name));
}
+}
- AddPreset(name, Params());
- ui_.preset->setCurrentIndex(ui_.preset->findText(name));
+QString Equalizer::SaveCurrentPreset() {
+ QString name = QInputDialog::getText(this, tr("Save preset"), tr("Name"),
+ QLineEdit::Normal, last_preset_);
+ if (name.isEmpty())
+ return QString();
+
+ AddPreset(name, current_params());
Save();
+ return name;
}
void Equalizer::DelPreset() {
@@ -189,23 +196,20 @@ QList Equalizer::gain_values() const {
return ret;
}
+Equalizer::Params Equalizer::current_params() const {
+ QList gains = gain_values();
+
+ Params ret;
+ ret.preamp = preamp_value();
+ std::copy(gains.begin(), gains.end(), ret.gain);
+ return ret;
+}
+
void Equalizer::ParametersChanged() {
if (loading_)
return;
emit ParametersChanged(preamp_value(), gain_values());
-
- // Update the preset
- QString name = ui_.preset->currentText();
- if (!presets_.contains(name) || name.isEmpty())
- return;
-
- Params& p = presets_[name];
- p.preamp = preamp_->value();
- for (int i=0 ; ivalue();
-
- Save();
}
void Equalizer::Save() {
@@ -229,6 +233,17 @@ void Equalizer::Save() {
s.setValue("enabled", ui_.enable->isChecked());
}
+void Equalizer::closeEvent(QCloseEvent* e) {
+ QString name = ui_.preset->currentText();
+ if (!presets_.contains(name))
+ return;
+
+ if (presets_[name] == current_params())
+ return;
+
+ SavePreset();
+}
+
Equalizer::Params::Params()
: preamp(0)
@@ -245,6 +260,18 @@ Equalizer::Params::Params(int g0, int g1, int g2, int g3, int g4, int g5,
gain[5] = g5; gain[6] = g6; gain[7] = g7; gain[8] = g8; gain[9] = g9;
}
+bool Equalizer::Params::operator ==(const Equalizer::Params& other) const {
+ if (preamp != other.preamp) return false;
+ for (int i=0 ; i>(QDataStream& s, Equalizer::Params& p) {
s >> p.gain[i];
return s;
}
-
-
diff --git a/src/equalizer.h b/src/equalizer.h
index 2fe77c649..7f0b39fbc 100644
--- a/src/equalizer.h
+++ b/src/equalizer.h
@@ -39,6 +39,9 @@ class Equalizer : public QDialog {
Params(int g0, int g1, int g2, int g3, int g4, int g5, int g6, int g7,
int g8, int g9, int pre = 0);
+ bool operator ==(const Params& other) const;
+ bool operator !=(const Params& other) const;
+
int preamp;
int gain[kBands];
};
@@ -46,15 +49,19 @@ class Equalizer : public QDialog {
bool is_enabled() const;
int preamp_value() const;
QList gain_values() const;
+ Params current_params() const;
signals:
void EnabledChanged(bool enabled);
void ParametersChanged(int preamp, const QList& band_gains);
+ protected:
+ void closeEvent(QCloseEvent *);
+
private slots:
void ParametersChanged();
void PresetChanged(const QString& name);
- void AddPreset();
+ void SavePreset();
void DelPreset();
void Save();
@@ -63,11 +70,14 @@ class Equalizer : public QDialog {
void LoadDefaultPresets();
void AddPreset(const QString& name, const Params& params);
void ReloadSettings();
+ QString SaveCurrentPreset();
private:
Ui::Equalizer ui_;
bool loading_;
+ QString last_preset_;
+
EqualizerSlider* preamp_;
EqualizerSlider* gain_[kBands];
diff --git a/src/equalizer.ui b/src/equalizer.ui
index a4838fc3d..43462899b 100644
--- a/src/equalizer.ui
+++ b/src/equalizer.ui
@@ -34,10 +34,13 @@
-
-
+
+
+ Save preset
+
-
- :/list-add.png:/list-add.png
+
+ :/document-save.png:/document-save.png
@@ -49,8 +52,11 @@
-
+
+ Delete preset
+
-
+
:/list-remove.png:/list-remove.png
@@ -95,10 +101,8 @@
preset
- preset_add
+ preset_save
-
-
-
+
diff --git a/src/translations/cs.po b/src/translations/cs.po
index fb4b3a316..e9697357b 100644
--- a/src/translations/cs.po
+++ b/src/translations/cs.po
@@ -470,15 +470,12 @@ msgstr ""
msgid "Zero"
msgstr ""
-msgid "New preset"
+msgid "Save preset"
msgstr ""
msgid "Name"
msgstr ""
-msgid "There is already a preset with that name"
-msgstr ""
-
msgid "Delete preset"
msgstr ""
diff --git a/src/translations/el.po b/src/translations/el.po
index d00399ee7..277450ca1 100644
--- a/src/translations/el.po
+++ b/src/translations/el.po
@@ -472,15 +472,12 @@ msgid "Zero"
msgstr ""
#, fuzzy
-msgid "New preset"
+msgid "Save preset"
msgstr "Νέα λίστα"
msgid "Name"
msgstr ""
-msgid "There is already a preset with that name"
-msgstr ""
-
#, fuzzy
msgid "Delete preset"
msgstr "Νέα λίστα"
diff --git a/src/translations/es.po b/src/translations/es.po
index a6bf59806..482e858a4 100644
--- a/src/translations/es.po
+++ b/src/translations/es.po
@@ -471,15 +471,12 @@ msgid "Zero"
msgstr ""
#, fuzzy
-msgid "New preset"
+msgid "Save preset"
msgstr "Nueva lista de reproducción"
msgid "Name"
msgstr ""
-msgid "There is already a preset with that name"
-msgstr ""
-
#, fuzzy
msgid "Delete preset"
msgstr "Nueva lista de reproducción"
diff --git a/src/translations/fr.po b/src/translations/fr.po
index 979cee4a8..bb6943433 100644
--- a/src/translations/fr.po
+++ b/src/translations/fr.po
@@ -472,15 +472,12 @@ msgstr ""
msgid "Zero"
msgstr ""
-msgid "New preset"
+msgid "Save preset"
msgstr ""
msgid "Name"
msgstr ""
-msgid "There is already a preset with that name"
-msgstr ""
-
msgid "Delete preset"
msgstr ""
diff --git a/src/translations/pl.po b/src/translations/pl.po
index 4daad93c5..6e91138e9 100644
--- a/src/translations/pl.po
+++ b/src/translations/pl.po
@@ -468,15 +468,12 @@ msgstr ""
msgid "Zero"
msgstr ""
-msgid "New preset"
+msgid "Save preset"
msgstr ""
msgid "Name"
msgstr ""
-msgid "There is already a preset with that name"
-msgstr ""
-
msgid "Delete preset"
msgstr ""
diff --git a/src/translations/ru.po b/src/translations/ru.po
index 0d031ffe9..f5d85930b 100644
--- a/src/translations/ru.po
+++ b/src/translations/ru.po
@@ -468,15 +468,12 @@ msgstr ""
msgid "Zero"
msgstr ""
-msgid "New preset"
+msgid "Save preset"
msgstr ""
msgid "Name"
msgstr ""
-msgid "There is already a preset with that name"
-msgstr ""
-
msgid "Delete preset"
msgstr ""
diff --git a/src/translations/sk.po b/src/translations/sk.po
index 45741d629..23661f294 100644
--- a/src/translations/sk.po
+++ b/src/translations/sk.po
@@ -470,15 +470,12 @@ msgid "Zero"
msgstr ""
#, fuzzy
-msgid "New preset"
+msgid "Save preset"
msgstr "Nový playlist"
msgid "Name"
msgstr ""
-msgid "There is already a preset with that name"
-msgstr ""
-
#, fuzzy
msgid "Delete preset"
msgstr "Nový playlist"
diff --git a/src/translations/translations.pot b/src/translations/translations.pot
index fe4a7be65..09f4ef7a8 100644
--- a/src/translations/translations.pot
+++ b/src/translations/translations.pot
@@ -464,15 +464,12 @@ msgstr ""
msgid "Zero"
msgstr ""
-msgid "New preset"
+msgid "Save preset"
msgstr ""
msgid "Name"
msgstr ""
-msgid "There is already a preset with that name"
-msgstr ""
-
msgid "Delete preset"
msgstr ""