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>
This commit is contained in:
Gehad elrobey 2014-06-01 07:38:59 +03:00 committed by Dirk Hohndel
parent b6fce3f556
commit e21032c99b
3 changed files with 560 additions and 237 deletions

View file

@ -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()) {

View file

@ -23,6 +23,8 @@ slots:
private:
Ui::DiveLogExportDialog *ui;
void showExplanation();
void exportHtmlInit(QString filename);
void exportHTMLsettings(QString filename);
};
#endif // DIVELOGEXPORTDIALOG_H

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>448</width>
<height>522</height>
<width>507</width>
<height>616</height>
</rect>
</property>
<property name="windowTitle">
@ -16,9 +16,9 @@
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>20</x>
<y>450</y>
<width>341</width>
<x>30</x>
<y>560</y>
<width>411</width>
<height>32</height>
</rect>
</property>
@ -29,13 +29,462 @@
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QTabWidget" name="tabWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>481</width>
<height>491</height>
</rect>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="General_tab">
<attribute name="title">
<string>General Export</string>
</attribute>
<widget class="QGroupBox" name="exportSelection">
<property name="geometry">
<rect>
<x>250</x>
<y>20</y>
<width>171</width>
<height>114</height>
</rect>
</property>
<property name="title">
<string>Selection</string>
</property>
<widget class="QRadioButton" name="exportSelected">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>151</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Selected dives</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="exportAll">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>110</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>All dives</string>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="exportFormat">
<property name="geometry">
<rect>
<x>40</x>
<y>20</y>
<width>191</width>
<height>221</height>
</rect>
</property>
<property name="title">
<string>Export format</string>
</property>
<widget class="QRadioButton" name="exportUDDF">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>110</width>
<height>24</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>UDDF</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportDivelogs">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>131</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>divelogs.de</string>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportCSV">
<property name="geometry">
<rect>
<x>10</x>
<y>130</y>
<width>110</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>CSV</string>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportWorldMap">
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<width>171</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Worldmap</string>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportSubsurfaceXML">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>171</width>
<height>21</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>171</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Subsurface XML</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
</widget>
<widget class="QLabel" name="description">
<property name="geometry">
<rect>
<x>60</x>
<y>310</y>
<width>341</width>
<height>91</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>110</x>
<y>250</y>
<width>231</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</widget>
<widget class="QWidget" name="HTML_tab">
<attribute name="title">
<string>HTML</string>
</attribute>
<widget class="QGroupBox" name="advanceOptions">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>20</x>
<y>240</y>
<width>441</width>
<height>191</height>
</rect>
</property>
<property name="title">
<string>Advanced Options</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<widget class="QWidget" name="layoutWidget1">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>291</width>
<height>29</height>
</rect>
</property>
<layout class="QHBoxLayout" name="fontLayout">
<item>
<widget class="QLabel" name="fontLabel">
<property name="text">
<string>Font</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="fontSelection"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget2">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>291</width>
<height>29</height>
</rect>
</property>
<layout class="QHBoxLayout" name="fontSizeLayout">
<item>
<widget class="QLabel" name="fontSizeLabel">
<property name="text">
<string>Font size</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="fontSizeSelection">
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>10</string>
</property>
</item>
<item>
<property name="text">
<string>12</string>
</property>
</item>
<item>
<property name="text">
<string>14</string>
</property>
</item>
<item>
<property name="text">
<string>16</string>
</property>
</item>
<item>
<property name="text">
<string>18</string>
</property>
</item>
<item>
<property name="text">
<string>20</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget3">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>291</width>
<height>29</height>
</rect>
</property>
<layout class="QHBoxLayout" name="ThemeLayout">
<item>
<widget class="QLabel" name="themeLabel">
<property name="text">
<string>Theme</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="themeSelection">
<item>
<property name="text">
<string>Light</string>
</property>
</item>
<item>
<property name="text">
<string>Sand</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QGroupBox" name="GeneralOptions">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>441</width>
<height>201</height>
</rect>
</property>
<property name="title">
<string>General Settings</string>
</property>
<widget class="Line" name="line_2">
<property name="geometry">
<rect>
<x>230</x>
<y>40</y>
<width>20</width>
<height>141</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
<widget class="QWidget" name="layoutWidget4">
<property name="geometry">
<rect>
<x>10</x>
<y>50</y>
<width>201</width>
<height>80</height>
</rect>
</property>
<layout class="QVBoxLayout" name="exportOptions">
<item>
<widget class="QRadioButton" name="exportSelectedDives">
<property name="minimumSize">
<size>
<width>117</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Selected Dives</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="exportAllDives">
<property name="minimumSize">
<size>
<width>117</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>All</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget5">
<property name="geometry">
<rect>
<x>250</x>
<y>50</y>
<width>191</width>
<height>80</height>
</rect>
</property>
<layout class="QVBoxLayout" name="additionalOptions">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Dives Starting from 0</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>Minimum Javascript</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<property name="text">
<string>Dive List only</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>-50</x>
<y>10</y>
<width>497</width>
<height>24</height>
<x>0</x>
<y>20</y>
<width>491</width>
<height>23</height>
</rect>
</property>
<property name="font">
@ -56,207 +505,6 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QGroupBox" name="exportFormat">
<property name="geometry">
<rect>
<x>20</x>
<y>70</y>
<width>201</width>
<height>241</height>
</rect>
</property>
<property name="title">
<string>Export format</string>
</property>
<widget class="QRadioButton" name="exportUDDF">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>110</width>
<height>24</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>UDDF</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportDivelogs">
<property name="geometry">
<rect>
<x>10</x>
<y>100</y>
<width>131</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>divelogs.de</string>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportCSV">
<property name="geometry">
<rect>
<x>10</x>
<y>130</y>
<width>110</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>CSV</string>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportWorldMap">
<property name="geometry">
<rect>
<x>10</x>
<y>160</y>
<width>171</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Worldmap</string>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportSubsurfaceXML">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>171</width>
<height>21</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>171</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Subsurface XML</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="exportHtml">
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<width>117</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>HTML</string>
</property>
<attribute name="buttonGroup">
<string notr="true">exportGroup</string>
</attribute>
</widget>
<widget class="Line" name="line">
<property name="geometry">
<rect>
<x>40</x>
<y>230</y>
<width>231</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="exportSelection">
<property name="geometry">
<rect>
<x>240</x>
<y>70</y>
<width>191</width>
<height>141</height>
</rect>
</property>
<property name="title">
<string>Selection</string>
</property>
<widget class="QRadioButton" name="exportSelected">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>151</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Selected dives</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="exportAll">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>110</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>All dives</string>
</property>
</widget>
</widget>
<widget class="QLabel" name="description">
<property name="geometry">
<rect>
<x>30</x>
<y>330</y>
<width>341</width>
<height>91</height>
</rect>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</widget>
<resources/>
<connections>
@ -295,5 +543,6 @@
</connections>
<buttongroups>
<buttongroup name="exportGroup"/>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>