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 <gehadelrobey@gmail.com>
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Gehad elrobey 2015-07-28 09:05:58 +02:00 committed by Lubomir I. Ivanov
parent fc9cba692e
commit 1dd2518624
2 changed files with 40 additions and 0 deletions

View file

@ -1,6 +1,10 @@
#include "printoptions.h"
#include "templateedit.h"
#include "helpers.h"
#include <QDebug>
#include <QFileDialog>
#include <QMessageBox>
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();

View file

@ -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