mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-18 20:40:43 +01:00
Replace the "new preset" button with a "save preset" button. Stops the user accidentally overwriting default equalizer presets. Fixes issue #190
This commit is contained in:
parent
0cd8f42ea5
commit
fba0af14ae
@ -77,5 +77,6 @@
|
||||
<file>osd_shadow_edge.png</file>
|
||||
<file>schema-6.sql</file>
|
||||
<file>list-add.png</file>
|
||||
<file>document-save.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
BIN
data/document-save.png
Normal file
BIN
data/document-save.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 798 B |
@ -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<int> Equalizer::gain_values() const {
|
||||
return ret;
|
||||
}
|
||||
|
||||
Equalizer::Params Equalizer::current_params() const {
|
||||
QList<int> 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 ; i<kBands ; ++i)
|
||||
p.gain[i] = gain_[i]->value();
|
||||
|
||||
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<Equalizer::kBands ; ++i) {
|
||||
if (gain[i] != other.gain[i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Equalizer::Params::operator !=(const Equalizer::Params& other) const {
|
||||
return ! (*this == other);
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream& s, const Equalizer::Params& p) {
|
||||
s << p.preamp;
|
||||
for (int i=0 ; i<Equalizer::kBands ; ++i)
|
||||
@ -258,5 +285,3 @@ QDataStream &operator>>(QDataStream& s, Equalizer::Params& p) {
|
||||
s >> p.gain[i];
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<int> gain_values() const;
|
||||
Params current_params() const;
|
||||
|
||||
signals:
|
||||
void EnabledChanged(bool enabled);
|
||||
void ParametersChanged(int preamp, const QList<int>& 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];
|
||||
|
||||
|
@ -34,10 +34,13 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="preset_add">
|
||||
<widget class="QToolButton" name="preset_save">
|
||||
<property name="toolTip">
|
||||
<string>Save preset</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<normaloff>:/list-add.png</normaloff>:/list-add.png</iconset>
|
||||
<iconset>
|
||||
<normaloff>:/document-save.png</normaloff>:/document-save.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
@ -49,8 +52,11 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="preset_del">
|
||||
<property name="toolTip">
|
||||
<string>Delete preset</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../data/data.qrc">
|
||||
<iconset>
|
||||
<normaloff>:/list-remove.png</normaloff>:/list-remove.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
@ -95,10 +101,8 @@
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>preset</tabstop>
|
||||
<tabstop>preset_add</tabstop>
|
||||
<tabstop>preset_save</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../data/data.qrc"/>
|
||||
</resources>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -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 ""
|
||||
|
||||
|
@ -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 "Νέα λίστα"
|
||||
|
@ -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"
|
||||
|
@ -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 ""
|
||||
|
||||
|
@ -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 ""
|
||||
|
||||
|
@ -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 ""
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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 ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user