diff options
author | Gehad elrobey <gehadelrobey@gmail.com> | 2014-06-01 07:38:59 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-03 21:07:45 -0700 |
commit | e21032c99b33ebb9b0067c9314595ae75030740f (patch) | |
tree | e2b5fc4aafc5e61594964c6022915236e7d36e3d /qt-ui/divelogexportdialog.cpp | |
parent | b6fce3f5562178b22e44dbe72742e9674e43e4cc (diff) | |
download | subsurface-e21032c99b33ebb9b0067c9314595ae75030740f.tar.gz |
Add HTML tab in export dialog
- Separate the export dialog into two tabs general exports for other
exports and HTML export.
- Save HTML settings to JSON file
- Copy HTML templates to the exporting directory
Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelogexportdialog.cpp')
-rw-r--r-- | qt-ui/divelogexportdialog.cpp | 126 |
1 files changed, 99 insertions, 27 deletions
diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp index a3193d5ce..e8dabc131 100644 --- a/qt-ui/divelogexportdialog.cpp +++ b/qt-ui/divelogexportdialog.cpp @@ -2,7 +2,9 @@ #include <QString> #include <QShortcut> #include <QAbstractButton> +#include <QTextStream> #include <QSettings> +#include <QDir> #include "mainwindow.h" #include "divelogexportdialog.h" @@ -10,6 +12,7 @@ #include "subsurfacewebservices.h" #include "worldmap-save.h" #include "save-html.h" +#include "helpers.h" DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DiveLogExportDialog) @@ -20,6 +23,14 @@ DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent), connect(quit, SIGNAL(activated()), parent, SLOT(close())); QShortcut *close = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_W), this); connect(close, SIGNAL(activated()), this, SLOT(close())); + + /* the names are not the actual values exported to the json files,The font-family property should hold several + font names as a "fallback" system, to ensure maximum compatibility between browsers/operating systems */ + ui->fontSelection->addItem("Arial", "Arial, Helvetica, sans-serif"); + ui->fontSelection->addItem("Impact", "Impact, Charcoal, sans-serif"); + ui->fontSelection->addItem("Georgia", "Georgia, serif"); + ui->fontSelection->addItem("Courier", "Courier, monospace"); + ui->fontSelection->addItem("Verdana", "Verdana, Geneva, sans-serif"); } DiveLogExportDialog::~DiveLogExportDialog() @@ -39,11 +50,67 @@ void DiveLogExportDialog::showExplanation() ui->description->setText("HTML export of the dive locations, visualized on a world map."); } else if (ui->exportSubsurfaceXML->isChecked()) { ui->description->setText("Subsurface native XML format."); - } else if (ui->exportHtml->isChecked()) { - ui->description->setText("Html export of dive list can be viewed in any web browser."); } } +void DiveLogExportDialog::exportHtmlInit(QString filename) +{ + QDir dir(filename); + if (!dir.exists()) { + /* I think this will not work as expected on windows */ + QDir::home().mkpath(filename); + } + + QString json_dive_data = filename + "/file.json"; + QString json_settings = filename + "/settings.json"; + + exportHTMLsettings(json_settings); + export_HTML(json_dive_data.toUtf8().data(), ui->exportSelectedDives->isChecked()); + + QString searchPath = getSubsurfaceDataPath("theme"); + + if (searchPath == "") { + return ; + } + + QFile *tmpFile; + + tmpFile = new QFile(searchPath + "/dive_export.html"); + tmpFile->copy(filename + "/dive_export.html"); + delete tmpFile; + + tmpFile = new QFile(searchPath + "/list_lib.js"); + tmpFile->copy(filename + "/list_lib.js"); + delete tmpFile; + + tmpFile = new QFile(searchPath + "/poster.png"); + tmpFile->copy(filename + "/poster.png"); + delete tmpFile; + + tmpFile = new QFile(searchPath + "/index.html"); + tmpFile->copy(filename + "/index.html"); + delete tmpFile; + + if (ui->themeSelection->currentText() == "Light") { + tmpFile = new QFile(searchPath + "/light.css"); + } else { + tmpFile = new QFile(searchPath + "/sand.css"); + } + tmpFile->copy(filename + "/theme.css"); + delete tmpFile; +} + +void DiveLogExportDialog::exportHTMLsettings(QString filename) +{ + QString fontSize = ui->fontSizeSelection->currentText(); + QString fontFamily = ui->fontSelection->itemData(ui->fontSelection->currentIndex()).toString(); + QFile file(filename); + file.open(QIODevice::WriteOnly | QIODevice::Text); + QTextStream out(&file); + out << "settings = {\"fontSize\":\"" << fontSize << "\",\"fontFamily\":\"" << fontFamily << "\",}"; + file.close(); +} + void DiveLogExportDialog::on_exportGroup_buttonClicked(QAbstractButton *button) { showExplanation(); @@ -64,33 +131,38 @@ void DiveLogExportDialog::on_buttonBox_accepted() } settings.endGroup(); - if (ui->exportUDDF->isChecked()) { - stylesheet = "uddf-export.xslt"; - filename = QFileDialog::getSaveFileName(this, tr("Export UDDF File as"), lastDir, - tr("UDDF files (*.uddf *.UDDF)")); - } else if (ui->exportCSV->isChecked()) { - stylesheet = "xml2csv.xslt"; - filename = QFileDialog::getSaveFileName(this, tr("Export CSV File as"), lastDir, - tr("CSV files (*.csv *.CSV)")); - } else if (ui->exportDivelogs->isChecked()) { - DivelogsDeWebServices::instance()->prepareDivesForUpload(ui->exportSelected->isChecked()); - } else if (ui->exportWorldMap->isChecked()) { - filename = QFileDialog::getSaveFileName(this, tr("Export World Map"), lastDir, - tr("HTML files (*.html)")); - if (!filename.isNull() && !filename.isEmpty()) - export_worldmap_HTML(filename.toUtf8().data(), ui->exportSelected->isChecked()); - } else if (ui->exportSubsurfaceXML->isChecked()) { - filename = QFileDialog::getSaveFileName(this, tr("Export Subsurface XML"), lastDir, - tr("XML files (*.xml *.ssrf)")); - if (!filename.isNull() && !filename.isEmpty()) { - QByteArray bt = QFile::encodeName(filename); - save_dives_logic(bt.data(), true); + switch (ui->tabWidget->currentIndex()) { + case 0: + if (ui->exportUDDF->isChecked()) { + stylesheet = "uddf-export.xslt"; + filename = QFileDialog::getSaveFileName(this, tr("Export UDDF File as"), lastDir, + tr("UDDF files (*.uddf *.UDDF)")); + } else if (ui->exportCSV->isChecked()) { + stylesheet = "xml2csv.xslt"; + filename = QFileDialog::getSaveFileName(this, tr("Export CSV File as"), lastDir, + tr("CSV files (*.csv *.CSV)")); + } else if (ui->exportDivelogs->isChecked()) { + DivelogsDeWebServices::instance()->prepareDivesForUpload(ui->exportSelected->isChecked()); + } else if (ui->exportWorldMap->isChecked()) { + filename = QFileDialog::getSaveFileName(this, tr("Export World Map"), lastDir, + tr("HTML files (*.html)")); + if (!filename.isNull() && !filename.isEmpty()) + export_worldmap_HTML(filename.toUtf8().data(), ui->exportSelected->isChecked()); + } else if (ui->exportSubsurfaceXML->isChecked()) { + filename = QFileDialog::getSaveFileName(this, tr("Export Subsurface XML"), lastDir, + tr("XML files (*.xml *.ssrf)")); + if (!filename.isNull() && !filename.isEmpty()) { + QByteArray bt = QFile::encodeName(filename); + save_dives_logic(bt.data(), true); + } } - } else if (ui->exportHtml->isChecked()) { - filename = QFileDialog::getSaveFileName(this, tr("Export HTML"), lastDir, - tr("HTML files (*.html)")); + break; + case 1: + filename = QFileDialog::getSaveFileName(this, tr("Export Subsurface"), lastDir, + tr("Folders"),0 , QFileDialog::ShowDirsOnly); if (!filename.isNull() && !filename.isEmpty()) - export_HTML(filename.toUtf8().data(), ui->exportSelected->isChecked()); + exportHtmlInit(filename); + break; } if (!filename.isNull() && !filename.isEmpty()) { |