1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 11:35:24 +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:
David Sansome 2010-04-09 00:23:17 +00:00
parent 0cd8f42ea5
commit fba0af14ae
13 changed files with 90 additions and 74 deletions

View File

@ -77,5 +77,6 @@
<file>osd_shadow_edge.png</file> <file>osd_shadow_edge.png</file>
<file>schema-6.sql</file> <file>schema-6.sql</file>
<file>list-add.png</file> <file>list-add.png</file>
<file>document-save.png</file>
</qresource> </qresource>
</RCC> </RCC>

BIN
data/document-save.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 798 B

View File

@ -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)), ui_.slider_container, SLOT(setEnabled(bool)));
connect(ui_.enable, SIGNAL(toggled(bool)), SLOT(Save())); connect(ui_.enable, SIGNAL(toggled(bool)), SLOT(Save()));
connect(ui_.preset, SIGNAL(currentIndexChanged(QString)), SLOT(PresetChanged(QString))); 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())); connect(ui_.preset_del, SIGNAL(clicked()), SLOT(DelPreset()));
} }
@ -82,6 +82,7 @@ void Equalizer::ReloadSettings() {
// Enabled? // Enabled?
ui_.enable->setChecked(s.value("enabled", false).toBool()); ui_.enable->setChecked(s.value("enabled", false).toBool());
ui_.slider_container->setEnabled(ui_.enable->isChecked());
PresetChanged(selected_preset); PresetChanged(selected_preset);
} }
@ -110,10 +111,18 @@ void Equalizer::LoadDefaultPresets() {
void Equalizer::AddPreset(const QString& name, const Params& params) { void Equalizer::AddPreset(const QString& name, const Params& params) {
presets_[name] = params; presets_[name] = params;
if (ui_.preset->findText(name) == -1)
ui_.preset->addItem(name); ui_.preset->addItem(name);
} }
void Equalizer::PresetChanged(const QString& 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]; Params& p = presets_[name];
loading_ = true; loading_ = true;
@ -123,30 +132,28 @@ void Equalizer::PresetChanged(const QString& name) {
loading_ = false; loading_ = false;
ParametersChanged(); ParametersChanged();
}
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;
}
AddPreset(name, Params());
ui_.preset->setCurrentIndex(ui_.preset->findText(name));
Save(); Save();
} }
void Equalizer::SavePreset() {
QString name = SaveCurrentPreset();
if (!name.isEmpty()) {
last_preset_ = name;
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() { void Equalizer::DelPreset() {
QString name = ui_.preset->currentText(); QString name = ui_.preset->currentText();
if (!presets_.contains(name) || name.isEmpty()) if (!presets_.contains(name) || name.isEmpty())
@ -189,23 +196,20 @@ QList<int> Equalizer::gain_values() const {
return ret; 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() { void Equalizer::ParametersChanged() {
if (loading_) if (loading_)
return; return;
emit ParametersChanged(preamp_value(), gain_values()); 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() { void Equalizer::Save() {
@ -229,6 +233,17 @@ void Equalizer::Save() {
s.setValue("enabled", ui_.enable->isChecked()); 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() Equalizer::Params::Params()
: preamp(0) : 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; 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) { QDataStream &operator<<(QDataStream& s, const Equalizer::Params& p) {
s << p.preamp; s << p.preamp;
for (int i=0 ; i<Equalizer::kBands ; ++i) for (int i=0 ; i<Equalizer::kBands ; ++i)
@ -258,5 +285,3 @@ QDataStream &operator>>(QDataStream& s, Equalizer::Params& p) {
s >> p.gain[i]; s >> p.gain[i];
return s; return s;
} }

View File

@ -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, Params(int g0, int g1, int g2, int g3, int g4, int g5, int g6, int g7,
int g8, int g9, int pre = 0); int g8, int g9, int pre = 0);
bool operator ==(const Params& other) const;
bool operator !=(const Params& other) const;
int preamp; int preamp;
int gain[kBands]; int gain[kBands];
}; };
@ -46,15 +49,19 @@ class Equalizer : public QDialog {
bool is_enabled() const; bool is_enabled() const;
int preamp_value() const; int preamp_value() const;
QList<int> gain_values() const; QList<int> gain_values() const;
Params current_params() const;
signals: signals:
void EnabledChanged(bool enabled); void EnabledChanged(bool enabled);
void ParametersChanged(int preamp, const QList<int>& band_gains); void ParametersChanged(int preamp, const QList<int>& band_gains);
protected:
void closeEvent(QCloseEvent *);
private slots: private slots:
void ParametersChanged(); void ParametersChanged();
void PresetChanged(const QString& name); void PresetChanged(const QString& name);
void AddPreset(); void SavePreset();
void DelPreset(); void DelPreset();
void Save(); void Save();
@ -63,11 +70,14 @@ class Equalizer : public QDialog {
void LoadDefaultPresets(); void LoadDefaultPresets();
void AddPreset(const QString& name, const Params& params); void AddPreset(const QString& name, const Params& params);
void ReloadSettings(); void ReloadSettings();
QString SaveCurrentPreset();
private: private:
Ui::Equalizer ui_; Ui::Equalizer ui_;
bool loading_; bool loading_;
QString last_preset_;
EqualizerSlider* preamp_; EqualizerSlider* preamp_;
EqualizerSlider* gain_[kBands]; EqualizerSlider* gain_[kBands];

View File

@ -34,10 +34,13 @@
</widget> </widget>
</item> </item>
<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"> <property name="icon">
<iconset resource="../data/data.qrc"> <iconset>
<normaloff>:/list-add.png</normaloff>:/list-add.png</iconset> <normaloff>:/document-save.png</normaloff>:/document-save.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -49,8 +52,11 @@
</item> </item>
<item> <item>
<widget class="QToolButton" name="preset_del"> <widget class="QToolButton" name="preset_del">
<property name="toolTip">
<string>Delete preset</string>
</property>
<property name="icon"> <property name="icon">
<iconset resource="../data/data.qrc"> <iconset>
<normaloff>:/list-remove.png</normaloff>:/list-remove.png</iconset> <normaloff>:/list-remove.png</normaloff>:/list-remove.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
@ -95,10 +101,8 @@
</widget> </widget>
<tabstops> <tabstops>
<tabstop>preset</tabstop> <tabstop>preset</tabstop>
<tabstop>preset_add</tabstop> <tabstop>preset_save</tabstop>
</tabstops> </tabstops>
<resources> <resources/>
<include location="../data/data.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>

View File

@ -470,15 +470,12 @@ msgstr ""
msgid "Zero" msgid "Zero"
msgstr "" msgstr ""
msgid "New preset" msgid "Save preset"
msgstr "" msgstr ""
msgid "Name" msgid "Name"
msgstr "" msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset" msgid "Delete preset"
msgstr "" msgstr ""

View File

@ -472,15 +472,12 @@ msgid "Zero"
msgstr "" msgstr ""
#, fuzzy #, fuzzy
msgid "New preset" msgid "Save preset"
msgstr "Νέα λίστα" msgstr "Νέα λίστα"
msgid "Name" msgid "Name"
msgstr "" msgstr ""
msgid "There is already a preset with that name"
msgstr ""
#, fuzzy #, fuzzy
msgid "Delete preset" msgid "Delete preset"
msgstr "Νέα λίστα" msgstr "Νέα λίστα"

View File

@ -471,15 +471,12 @@ msgid "Zero"
msgstr "" msgstr ""
#, fuzzy #, fuzzy
msgid "New preset" msgid "Save preset"
msgstr "Nueva lista de reproducción" msgstr "Nueva lista de reproducción"
msgid "Name" msgid "Name"
msgstr "" msgstr ""
msgid "There is already a preset with that name"
msgstr ""
#, fuzzy #, fuzzy
msgid "Delete preset" msgid "Delete preset"
msgstr "Nueva lista de reproducción" msgstr "Nueva lista de reproducción"

View File

@ -472,15 +472,12 @@ msgstr ""
msgid "Zero" msgid "Zero"
msgstr "" msgstr ""
msgid "New preset" msgid "Save preset"
msgstr "" msgstr ""
msgid "Name" msgid "Name"
msgstr "" msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset" msgid "Delete preset"
msgstr "" msgstr ""

View File

@ -468,15 +468,12 @@ msgstr ""
msgid "Zero" msgid "Zero"
msgstr "" msgstr ""
msgid "New preset" msgid "Save preset"
msgstr "" msgstr ""
msgid "Name" msgid "Name"
msgstr "" msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset" msgid "Delete preset"
msgstr "" msgstr ""

View File

@ -468,15 +468,12 @@ msgstr ""
msgid "Zero" msgid "Zero"
msgstr "" msgstr ""
msgid "New preset" msgid "Save preset"
msgstr "" msgstr ""
msgid "Name" msgid "Name"
msgstr "" msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset" msgid "Delete preset"
msgstr "" msgstr ""

View File

@ -470,15 +470,12 @@ msgid "Zero"
msgstr "" msgstr ""
#, fuzzy #, fuzzy
msgid "New preset" msgid "Save preset"
msgstr "Nový playlist" msgstr "Nový playlist"
msgid "Name" msgid "Name"
msgstr "" msgstr ""
msgid "There is already a preset with that name"
msgstr ""
#, fuzzy #, fuzzy
msgid "Delete preset" msgid "Delete preset"
msgstr "Nový playlist" msgstr "Nový playlist"

View File

@ -464,15 +464,12 @@ msgstr ""
msgid "Zero" msgid "Zero"
msgstr "" msgstr ""
msgid "New preset" msgid "Save preset"
msgstr "" msgstr ""
msgid "Name" msgid "Name"
msgstr "" msgstr ""
msgid "There is already a preset with that name"
msgstr ""
msgid "Delete preset" msgid "Delete preset"
msgstr "" msgstr ""