Commit 12d78e99 authored by Ariel Vieira Lima Serafim's avatar Ariel Vieira Lima Serafim Committed by Julius Künzel
Browse files

Add description to save stack effect dialog



We've modified the dialog used to save the new effect name to now accept the name and description.
If no description is provided, a yes/no dialog confirms with the user if it should be saved anyways.

Co-authored-by: Rafael Pereira's avatarRafael Pereira <180108344@aluno.unb.br>

Co-authored-by: Felipe Agustini's avatarFelipe Agustini <felipeboccardi@hotmail.com>

Fixes #582
parent 61c735cd
Pipeline #221673 failed with stage
in 2 minutes and 40 seconds
......@@ -17,6 +17,7 @@
#include <QDir>
#include <QDrag>
#include <QFormLayout>
#include <QDragEnterEvent>
#include <QFontDatabase>
#include <QInputDialog>
......@@ -506,50 +507,88 @@ void EffectStackView::slotSaveStack()
KMessageBox::error(this, i18n("No effect selected."));
return;
}
QString name = QInputDialog::getText(this, i18nc("@title:window", "Save Effect Stack"), i18n("Name for saved stack: "));
if (name.trimmed().isEmpty()) {
KMessageBox::error(this, i18n("No name provided, effect stack not saved."));
return;
}
QDialog dialog(this);
QFormLayout form(&dialog);
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/effects/"));
if (!dir.exists()) {
dir.mkpath(QStringLiteral("."));
}
dialog.setWindowTitle(i18nc("@title:window", "Save current Effect Stack"));
auto *stackName = new QLineEdit(&dialog);
auto *stackDescription = new QTextEdit(&dialog);
form.addRow(i18n("Name for saved stack:"), stackName);
form.addRow(i18n("Description:"), stackDescription);
if (dir.exists(name + QStringLiteral(".xml"))) {
if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", name + QStringLiteral(".xml"))) == KMessageBox::No) {
QDialogButtonBox buttonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, &dialog);
form.addRow(&buttonBox);
QObject::connect(&buttonBox, &QDialogButtonBox::accepted, &dialog, &QDialog::accept);
QObject::connect(&buttonBox, &QDialogButtonBox::rejected, &dialog, &QDialog::reject);
if (dialog.exec() == QDialog::Accepted) {
QString name = stackName->text();
QString description = stackDescription->toPlainText();
if (name.trimmed().isEmpty()) {
KMessageBox::error(this, i18n("No name provided, effect stack not saved."));
return;
}
}
QDomDocument doc;
QDomElement effect = doc.createElement(QStringLiteral("effectgroup"));
effect.setAttribute(QStringLiteral("id"), name);
auto item = m_model->getEffectStackRow(0);
if (item->isAudio()) {
effect.setAttribute(QStringLiteral("type"), QStringLiteral("customAudio"));
}
effect.setAttribute(QStringLiteral("parentIn"), pCore->getItemIn(m_model->getOwnerId()));
doc.appendChild(effect);
for (int i = 0; i <= m_model->rowCount(); ++i) {
CollapsibleEffectView *w = static_cast<CollapsibleEffectView *>(m_effectsTree->indexWidget(m_model->index(i, 0, QModelIndex())));
if (w) {
effect.appendChild(doc.importNode(w->toXml().documentElement(), true));
QString effectfilename = name + QStringLiteral(".xml");
if (description.trimmed().isEmpty()) {
if (KMessageBox::questionYesNo(this, i18n("No description provided. \nSave effect with no description?")) == KMessageBox::No) {
return;
}
}
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/effects/"));
if (!dir.exists()) {
dir.mkpath(QStringLiteral("."));
}
if (dir.exists(effectfilename)) {
if (KMessageBox::questionYesNo(this, i18n("File %1 already exists.\nDo you want to overwrite it?", effectfilename)) == KMessageBox::No) {
return;
}
}
QDomDocument doc;
QDomElement effect = doc.createElement(QStringLiteral("effectgroup"));
effect.setAttribute(QStringLiteral("id"), name);
QDomElement describtionNode = doc.createElement(QString("description"));
QDomText descriptionText = doc.createTextNode(description);
describtionNode.appendChild(descriptionText);
effect.appendChild(describtionNode);
effect.setAttribute(QStringLiteral("description"), description);
auto item = m_model->getEffectStackRow(0);
if (item->isAudio()) {
effect.setAttribute(QStringLiteral("type"), QStringLiteral("customAudio"));
}
effect.setAttribute(QStringLiteral("parentIn"), pCore->getItemIn(m_model->getOwnerId()));
doc.appendChild(effect);
for (int i = 0; i <= m_model->rowCount(); ++i) {
CollapsibleEffectView *w = static_cast<CollapsibleEffectView *>(m_effectsTree->indexWidget(m_model->index(i, 0, QModelIndex())));
if (w) {
effect.appendChild(doc.importNode(w->toXml().documentElement(), true));
}
}
QFile file(dir.absoluteFilePath(effectfilename));
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream out(&file);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
out.setCodec("UTF-8");
#endif
out << doc.toString();
} else {
KMessageBox::error(QApplication::activeWindow(), i18n("Cannot write to file %1", file.fileName()));
}
file.close();
emit reloadEffect(dir.absoluteFilePath(effectfilename));
}
QFile file(dir.absoluteFilePath(name + QStringLiteral(".xml")));
if (file.open(QFile::WriteOnly | QFile::Truncate)) {
QTextStream out(&file);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
out.setCodec("UTF-8");
#endif
out << doc.toString();
} else {
KMessageBox::error(QApplication::activeWindow(), i18n("Cannot write to file %1", file.fileName()));
}
file.close();
emit reloadEffect(dir.absoluteFilePath(name + QStringLiteral(".xml")));
}
/*
......
Supports Markdown
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