From bc6146577d0c3524a02733d79811a6bc9310d839 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Thu, 23 Nov 2017 02:54:27 +0200 Subject: printing: improve messaging in printoptions.cpp 1) on_deleteButton_clicked() show a proper message box with icon title and also quote the file name. 2) When exporting a file, make sure that the destination is not read-only even if the source is. 3) Do not allow editing of read-only templates (e.g. the bundled ones). Instruct the user to Export first. Signed-off-by: Lubomir I. Ivanov --- desktop-widgets/printoptions.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'desktop-widgets/printoptions.cpp') diff --git a/desktop-widgets/printoptions.cpp b/desktop-widgets/printoptions.cpp index 34aac318f..7ed8ecb46 100644 --- a/desktop-widgets/printoptions.cpp +++ b/desktop-widgets/printoptions.cpp @@ -121,6 +121,19 @@ void PrintOptions::on_printTemplate_currentIndexChanged(int index) void PrintOptions::on_editButton_clicked() { + QString templateName = getSelectedTemplate(); + QFile f(getPrintingTemplatePathUser() + QDir::separator() + templateName); + if (!f.open(QFile::ReadWrite | QFile::Text)) { + QMessageBox msgBox(this); + msgBox.setWindowTitle(tr("Read-only template!")); + msgBox.setText(tr("The template '%1' is read-only and connot be edited.\n" + "Please export this template to a different file.").arg(templateName)); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); + return; + } else { + f.close(); + } TemplateEdit te(this, printOptions, templateOptions); te.exec(); setup(); @@ -148,6 +161,11 @@ void PrintOptions::on_exportButton_clicked() if (filename.isEmpty()) return; QFile::copy(pathUser + QDir::separator() + getSelectedTemplate(), filename); + QFile f(filename); + if (!f.open(QFile::ReadWrite | QFile::Text)) + f.setPermissions(QFileDevice::ReadUser | QFileDevice::ReadOwner | QFileDevice::WriteUser | QFileDevice::WriteOwner); + else + f.close(); find_all_templates(); setup(); } @@ -155,9 +173,9 @@ void PrintOptions::on_exportButton_clicked() void PrintOptions::on_deleteButton_clicked() { QString templateName = getSelectedTemplate(); - QMessageBox msgBox; - msgBox.setText(tr("This action cannot be undone!")); - msgBox.setInformativeText(tr("Delete template: %1?").arg(templateName)); + QMessageBox msgBox(this); + msgBox.setWindowTitle(tr("This action cannot be undone!")); + msgBox.setText(tr("Delete template '%1'?").arg(templateName)); msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Cancel); if (msgBox.exec() == QMessageBox::Ok) { -- cgit v1.2.3-70-g09d2