From e21032c99b33ebb9b0067c9314595ae75030740f Mon Sep 17 00:00:00 2001 From: Gehad elrobey Date: Sun, 1 Jun 2014 07:38:59 +0300 Subject: 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 Signed-off-by: Miika Turkia Signed-off-by: Dirk Hohndel --- qt-ui/divelogexportdialog.cpp | 126 ++++++-- qt-ui/divelogexportdialog.h | 2 + qt-ui/divelogexportdialog.ui | 669 +++++++++++++++++++++++++++++------------- 3 files changed, 560 insertions(+), 237 deletions(-) (limited to 'qt-ui') 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 #include #include +#include #include +#include #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()) { diff --git a/qt-ui/divelogexportdialog.h b/qt-ui/divelogexportdialog.h index 92510a7aa..8322fa1d1 100644 --- a/qt-ui/divelogexportdialog.h +++ b/qt-ui/divelogexportdialog.h @@ -23,6 +23,8 @@ slots: private: Ui::DiveLogExportDialog *ui; void showExplanation(); + void exportHtmlInit(QString filename); + void exportHTMLsettings(QString filename); }; #endif // DIVELOGEXPORTDIALOG_H diff --git a/qt-ui/divelogexportdialog.ui b/qt-ui/divelogexportdialog.ui index 09143f0d9..5bd41e1f9 100644 --- a/qt-ui/divelogexportdialog.ui +++ b/qt-ui/divelogexportdialog.ui @@ -6,8 +6,8 @@ 0 0 - 448 - 522 + 507 + 616 @@ -16,9 +16,9 @@ - 20 - 450 - 341 + 30 + 560 + 411 32 @@ -29,13 +29,462 @@ QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + 10 + 60 + 481 + 491 + + + + 0 + + + + General Export + + + + + 250 + 20 + 171 + 114 + + + + Selection + + + + true + + + + 10 + 30 + 151 + 24 + + + + Selected dives + + + true + + + + + + 10 + 60 + 110 + 24 + + + + All dives + + + + + + + 40 + 20 + 191 + 221 + + + + Export format + + + + + 10 + 70 + 110 + 24 + + + + + 110 + 16777215 + + + + UDDF + + + false + + + exportGroup + + + + + + 10 + 100 + 131 + 24 + + + + divelogs.de + + + exportGroup + + + + + + 10 + 130 + 110 + 24 + + + + CSV + + + exportGroup + + + + + + 10 + 160 + 171 + 24 + + + + Worldmap + + + exportGroup + + + + + + 10 + 40 + 171 + 21 + + + + + 171 + 16777215 + + + + Subsurface XML + + + true + + + exportGroup + + + + + + + 60 + 310 + 341 + 91 + + + + + + + true + + + + + + 110 + 250 + 231 + 16 + + + + Qt::Horizontal + + + + + + HTML + + + + true + + + + 20 + 240 + 441 + 191 + + + + Advanced Options + + + true + + + false + + + + + 10 + 40 + 291 + 29 + + + + + + + Font + + + + + + + + + + + + 10 + 80 + 291 + 29 + + + + + + + Font size + + + + + + + + 8 + + + + + 10 + + + + + 12 + + + + + 14 + + + + + 16 + + + + + 18 + + + + + 20 + + + + + + + + + + 10 + 120 + 291 + 29 + + + + + + + Theme + + + + + + + + Light + + + + + Sand + + + + + + + + + + + 20 + 20 + 441 + 201 + + + + General Settings + + + + + 230 + 40 + 20 + 141 + + + + Qt::Vertical + + + + + + 10 + 50 + 201 + 80 + + + + + + + + 117 + 0 + + + + Selected Dives + + + true + + + buttonGroup + + + + + + + + 117 + 0 + + + + All + + + buttonGroup + + + + + + + + + 250 + 50 + 191 + 80 + + + + + + + Dives Starting from 0 + + + + + + + Minimum Javascript + + + + + + + Dive List only + + + + + + + + - -50 - 10 - 497 - 24 + 0 + 20 + 491 + 23 @@ -56,207 +505,6 @@ Qt::AlignCenter - - - - 20 - 70 - 201 - 241 - - - - Export format - - - - - 10 - 70 - 110 - 24 - - - - - 110 - 16777215 - - - - UDDF - - - false - - - exportGroup - - - - - - 10 - 100 - 131 - 24 - - - - divelogs.de - - - exportGroup - - - - - - 10 - 130 - 110 - 24 - - - - CSV - - - exportGroup - - - - - - 10 - 160 - 171 - 24 - - - - Worldmap - - - exportGroup - - - - - - 10 - 40 - 171 - 21 - - - - - 171 - 16777215 - - - - Subsurface XML - - - true - - - exportGroup - - - - - - 10 - 190 - 117 - 22 - - - - HTML - - - exportGroup - - - - - - 40 - 230 - 231 - 16 - - - - Qt::Horizontal - - - - - - - 240 - 70 - 191 - 141 - - - - Selection - - - - true - - - - 10 - 30 - 151 - 24 - - - - Selected dives - - - true - - - - - - 10 - 60 - 110 - 24 - - - - All dives - - - - - - - 30 - 330 - 341 - 91 - - - - - - - true - - @@ -295,5 +543,6 @@ + -- cgit v1.2.3-70-g09d2