From 1dd2518624cc001afacead74caed854ac78a5b6a Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Tue, 28 Jul 2015 09:05:58 +0200 Subject: Printing: support importing/exporting of templates Implement 'import/export' features, so it's easier to share customized printing templates. Also support deleting existing templates. Signed-off-by: Gehad elrobey Signed-off-by: Lubomir I. Ivanov --- qt-ui/printoptions.cpp | 37 +++++++++++++++++++++++++++++++++++++ qt-ui/printoptions.h | 3 +++ 2 files changed, 40 insertions(+) (limited to 'qt-ui') diff --git a/qt-ui/printoptions.cpp b/qt-ui/printoptions.cpp index 6cfbed481..916d9d696 100644 --- a/qt-ui/printoptions.cpp +++ b/qt-ui/printoptions.cpp @@ -1,6 +1,10 @@ #include "printoptions.h" #include "templateedit.h" +#include "helpers.h" + #include +#include +#include PrintOptions::PrintOptions(QWidget *parent, struct print_options *printOpt, struct template_options *templateOpt) { @@ -97,6 +101,39 @@ void PrintOptions::on_editButton_clicked() setup(); } +void PrintOptions::on_importButton_clicked() +{ + QString filename = QFileDialog::getOpenFileName(this, tr("Import Template file"), "", + tr("HTML files (*.html)")); + QFileInfo fileInfo(filename); + QFile::copy(filename, getSubsurfaceDataPath("printing_templates") + QDir::separator() + fileInfo.fileName()); + find_all_templates(); + setup(); +} + +void PrintOptions::on_exportButton_clicked() +{ + QString filename = QFileDialog::getSaveFileName(this, tr("Export Template files as"), "", + tr("HTML files (*.html)")); + QFile::copy(getSubsurfaceDataPath("printing_templates") + QDir::separator() + getSelectedTemplate(), filename); +} + +void PrintOptions::on_deleteButton_clicked() +{ + QString templateName = getSelectedTemplate(); + QMessageBox msgBox; + msgBox.setText("This action cannot be undone!"); + msgBox.setInformativeText("Delete '" + templateName + "' template?"); + msgBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Cancel); + if (msgBox.exec() == QMessageBox::Ok) { + QFile f(getSubsurfaceDataPath("printing_templates") + QDir::separator() + templateName); + f.remove(); + find_all_templates(); + setup(); + } +} + QString PrintOptions::getSelectedTemplate() { return ui.printTemplate->currentData().toString(); diff --git a/qt-ui/printoptions.h b/qt-ui/printoptions.h index b9912d2ed..528c5ed4d 100644 --- a/qt-ui/printoptions.h +++ b/qt-ui/printoptions.h @@ -69,6 +69,9 @@ slots: void on_radioDiveListPrint_clicked(bool check); void on_printTemplate_currentIndexChanged(int index); void on_editButton_clicked(); + void on_importButton_clicked(); + void on_exportButton_clicked(); + void on_deleteButton_clicked(); }; #endif // PRINTOPTIONS_H -- cgit v1.2.3-70-g09d2