exporttemplatedialog:confirm file overwrite

work/spdx
Michail Vourlakos 4 years ago
parent c5c61dffe3
commit 7f11e50ecb

@ -43,6 +43,7 @@
// KDE // KDE
#include <KLocalizedString> #include <KLocalizedString>
#include <KMessageBox>
#include <KIO/OpenFileManagerWindowJob> #include <KIO/OpenFileManagerWindowJob>
// Plasma // Plasma
@ -198,6 +199,17 @@ void ExportTemplateHandler::chooseFileDialog()
void ExportTemplateHandler::onExport() void ExportTemplateHandler::onExport()
{ {
QString curbasename = QFileInfo(c_filepath).baseName();
QString curfilename = QFileInfo(c_filepath).fileName();
//! Confirm Overwrite if that is the case
if (QFile(c_filepath).exists()) {
if (!overwriteConfirmation(curfilename)) {
return;
}
}
//! Proceed with export
auto showExportTemplateError = [this](const QString &templateName) { auto showExportTemplateError = [this](const QString &templateName) {
showInlineMessage(i18nc("settings:template export fail","Template <b>%0</b> export <b>failed</b>...").arg(templateName), showInlineMessage(i18nc("settings:template export fail","Template <b>%0</b> export <b>failed</b>...").arg(templateName),
KMessageWidget::Error, KMessageWidget::Error,
@ -230,7 +242,7 @@ void ExportTemplateHandler::onExport()
} }
}); });
showInlineMessage(i18nc("settings:template export success","Template <b>%0</b> export succeeded...").arg(QFileInfo(c_filepath).baseName()), showInlineMessage(i18nc("settings:template export success","Template <b>%0</b> export succeeded...").arg(curbasename),
KMessageWidget::Information, KMessageWidget::Information,
false, false,
actions); actions);
@ -289,6 +301,15 @@ void ExportTemplateHandler::save()
//do nothing //do nothing
} }
bool ExportTemplateHandler::overwriteConfirmation(const QString &fileName)
{
return (KMessageBox::warningYesNo(m_dialog,
i18n("The file \"%0\" already exists. Do you wish to overwrite it?").arg(fileName),
i18n("Overwrite File?"),
KStandardGuiItem::overwrite(),
KStandardGuiItem::cancel()) == KMessageBox::Yes);
}
} }
} }
} }

@ -91,6 +91,8 @@ private:
void setFilepath(const QString &filepath); void setFilepath(const QString &filepath);
bool overwriteConfirmation(const QString &fileName);
private slots: private slots:
void onExport(); void onExport();
void onFilepathChanged(); void onFilepathChanged();

Loading…
Cancel
Save