Commit 7bc34df4 authored by Julius Künzel's avatar Julius Künzel
Browse files

Fixes for saving and editing render presets

parent 8a714260
......@@ -29,7 +29,7 @@ static int gcd(int a, int b)
RenderPresetDialog::RenderPresetDialog(QWidget *parent, RenderPresetModel *preset, Mode mode)
: QDialog(parent)
, m_saveName()
, m_saveName(preset ? preset->name() : "")
, m_monitor(nullptr)
, m_fixedResRatio(1.)
{
......@@ -375,7 +375,7 @@ RenderPresetDialog::RenderPresetDialog(QWidget *parent, RenderPresetModel *prese
QString::number(aQuality->value()),
speeds_list_str));
m_saveName = RenderPresetRepository::get()->savePreset(newPreset.get());
m_saveName = RenderPresetRepository::get()->savePreset(newPreset.get(), mode == Mode::Edit);
if ((mode == Mode::Edit) && !m_saveName.isEmpty() && (oldName != m_saveName)) {
RenderPresetRepository::get()->deletePreset(oldName);
}
......
......@@ -287,13 +287,10 @@ bool RenderPresetRepository::presetExists(const QString &name) const
return m_profiles.count(name) > 0;
}
const QString RenderPresetRepository::savePreset(RenderPresetModel *preset, const QString &overrideGroupName)
const QString RenderPresetRepository::savePreset(RenderPresetModel *preset, bool editMode, const QString &oldName)
{
QDomElement newPreset = preset->toXml();
if (!overrideGroupName.isEmpty()) {
newPreset.setAttribute(QStringLiteral("category"), overrideGroupName);
}
QDomDocument doc;
......@@ -331,23 +328,31 @@ const QString RenderPresetRepository::savePreset(RenderPresetModel *preset, cons
i++;
}
bool ok;
QString newPresetName = preset->name();
while (existingProfileNames.contains(newPresetName)) {
QString updatedPresetName = QInputDialog::getText(nullptr, i18n("Preset already exists"),
i18n("This preset name already exists. Change the name if you do not want to overwrite it."),
QLineEdit::Normal, newPresetName, &ok);
if (!ok) {
return {};
QString updatedPresetName = newPresetName;
if (!editMode) {
bool ok;
updatedPresetName = QInputDialog::getText(nullptr, i18n("Preset already exists"),
i18n("This preset name already exists. Change the name if you do not want to overwrite it."),
QLineEdit::Normal, newPresetName, &ok);
if (!ok) {
return {};
}
}
if (updatedPresetName == newPresetName) {
// remove previous profile
profiles.removeChild(profilelist.item(existingProfileNames.indexOf(newPresetName)));
int ix = existingProfileNames.indexOf(newPresetName);
profiles.removeChild(profilelist.item(ix));
existingProfileNames.removeAt(ix);
break;
} else {
newPresetName = updatedPresetName;
newPreset.setAttribute(QStringLiteral("name"), newPresetName);
}
newPresetName = updatedPresetName;
newPreset.setAttribute(QStringLiteral("name"), newPresetName);
}
if (editMode && !oldName.isEmpty() && existingProfileNames.contains(oldName)) {
profiles.removeChild(profilelist.item(existingProfileNames.indexOf(oldName)));
}
profiles.appendChild(newPreset);
......
......@@ -51,7 +51,7 @@ public:
/** @brief Saves given preset
* @returns The name of the saved preset
*/
const QString savePreset(RenderPresetModel *profile, const QString &overrideGroupName = {});
const QString savePreset(RenderPresetModel *profile, bool editMode = false, const QString &oldName = QString());
/** @brief Delete a (custom) preset*/
bool deletePreset(const QString &path, bool dontRefresh = false);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment