2014-05-20 16:33:32 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QString>
|
2014-05-21 12:41:46 +00:00
|
|
|
#include <QShortcut>
|
2014-05-23 20:28:08 +00:00
|
|
|
#include <QAbstractButton>
|
2014-06-01 04:38:59 +00:00
|
|
|
#include <QTextStream>
|
2014-05-24 14:12:03 +00:00
|
|
|
#include <QSettings>
|
2014-06-01 04:38:59 +00:00
|
|
|
#include <QDir>
|
2014-06-10 11:02:55 +00:00
|
|
|
#include <QDebug>
|
2014-05-20 16:33:32 +00:00
|
|
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "divelogexportdialog.h"
|
|
|
|
#include "ui_divelogexportdialog.h"
|
|
|
|
#include "subsurfacewebservices.h"
|
|
|
|
#include "worldmap-save.h"
|
2014-05-23 18:49:49 +00:00
|
|
|
#include "save-html.h"
|
2014-06-01 04:38:59 +00:00
|
|
|
#include "helpers.h"
|
2014-05-20 16:33:32 +00:00
|
|
|
|
2014-05-22 18:40:22 +00:00
|
|
|
DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent),
|
2014-06-10 11:02:55 +00:00
|
|
|
ui(new Ui::DiveLogExportDialog)
|
2014-05-20 16:33:32 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-05-24 13:42:10 +00:00
|
|
|
showExplanation();
|
2014-05-21 12:41:46 +00:00
|
|
|
QShortcut *quit = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this);
|
|
|
|
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()));
|
2014-06-01 04:38:59 +00:00
|
|
|
|
|
|
|
/* 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");
|
2014-06-02 15:38:35 +00:00
|
|
|
|
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("HTML");
|
|
|
|
if (settings.contains("fontSelection")) {
|
|
|
|
ui->fontSelection->setCurrentIndex(settings.value("fontSelection").toInt());
|
|
|
|
}
|
|
|
|
if (settings.contains("fontSizeSelection")) {
|
|
|
|
ui->fontSizeSelection->setCurrentIndex(settings.value("fontSizeSelection").toInt());
|
|
|
|
}
|
|
|
|
if (settings.contains("themeSelection")) {
|
|
|
|
ui->themeSelection->setCurrentIndex(settings.value("themeSelection").toInt());
|
|
|
|
}
|
|
|
|
settings.endGroup();
|
2014-05-20 16:33:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DiveLogExportDialog::~DiveLogExportDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2014-05-24 13:42:10 +00:00
|
|
|
void DiveLogExportDialog::showExplanation()
|
2014-05-23 20:28:08 +00:00
|
|
|
{
|
|
|
|
if (ui->exportUDDF->isChecked()) {
|
2014-07-10 23:06:44 +00:00
|
|
|
ui->description->setText(tr("Generic format that is used for data exchange between a variety of diving related programs."));
|
2014-05-23 20:28:08 +00:00
|
|
|
} else if (ui->exportCSV->isChecked()) {
|
2014-07-10 23:06:44 +00:00
|
|
|
ui->description->setText(tr("Comma separated values that include the most relevant information of the dive profile."));
|
2014-05-23 20:28:08 +00:00
|
|
|
} else if (ui->exportDivelogs->isChecked()) {
|
2014-07-10 23:06:44 +00:00
|
|
|
ui->description->setText(tr("Send the dive data to divelogs.de website."));
|
2014-05-23 20:28:08 +00:00
|
|
|
} else if (ui->exportWorldMap->isChecked()) {
|
2014-07-10 23:06:44 +00:00
|
|
|
ui->description->setText(tr("HTML export of the dive locations, visualized on a world map."));
|
2014-05-24 14:12:03 +00:00
|
|
|
} else if (ui->exportSubsurfaceXML->isChecked()) {
|
2014-07-10 23:06:44 +00:00
|
|
|
ui->description->setText(tr("Subsurface native XML format."));
|
2014-05-23 20:28:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-24 13:01:52 +00:00
|
|
|
void DiveLogExportDialog::copy_and_overwrite(const QString &fileName, const QString &newName)
|
|
|
|
{
|
|
|
|
QFile file(newName);
|
|
|
|
if (file.exists())
|
|
|
|
file.remove();
|
|
|
|
QFile::copy(fileName, newName);
|
|
|
|
}
|
|
|
|
|
2014-06-10 11:02:55 +00:00
|
|
|
void DiveLogExportDialog::exportHtmlInit(const QString &filename)
|
2014-06-01 04:38:59 +00:00
|
|
|
{
|
2014-06-10 15:55:07 +00:00
|
|
|
QFile file(filename);
|
|
|
|
QFileInfo info(file);
|
|
|
|
QDir mainDir = info.absoluteDir();
|
|
|
|
mainDir.mkdir(file.fileName() + "_files");
|
2014-07-13 21:36:35 +00:00
|
|
|
QString exportFiles = file.fileName() + "_files";
|
2014-06-01 04:38:59 +00:00
|
|
|
|
2014-06-10 15:55:07 +00:00
|
|
|
QString json_dive_data = exportFiles + QDir::separator() + "file.json";
|
|
|
|
QString json_settings = exportFiles + QDir::separator() + "settings.json";
|
2014-07-13 21:36:35 +00:00
|
|
|
QString photos_directory = exportFiles + QDir::separator() + "photos" + QDir::separator();
|
|
|
|
mainDir.mkdir(photos_directory);
|
|
|
|
exportFiles += "/";
|
2014-06-01 04:38:59 +00:00
|
|
|
|
|
|
|
exportHTMLsettings(json_settings);
|
2014-07-13 21:36:35 +00:00
|
|
|
export_HTML(json_dive_data.toUtf8().data(), photos_directory.toUtf8().data(), ui->exportSelectedDives->isChecked(), ui->exportListOnly->isChecked());
|
2014-06-01 04:38:59 +00:00
|
|
|
|
|
|
|
QString searchPath = getSubsurfaceDataPath("theme");
|
2014-06-08 14:53:22 +00:00
|
|
|
if (searchPath.isEmpty())
|
2014-06-10 11:02:55 +00:00
|
|
|
return;
|
2014-06-01 04:38:59 +00:00
|
|
|
|
2014-06-10 11:02:55 +00:00
|
|
|
searchPath += QDir::separator();
|
2014-06-10 15:55:07 +00:00
|
|
|
|
2014-06-24 13:01:52 +00:00
|
|
|
copy_and_overwrite(searchPath + "dive_export.html", filename);
|
|
|
|
copy_and_overwrite(searchPath + "list_lib.js", exportFiles + "list_lib.js");
|
|
|
|
copy_and_overwrite(searchPath + "poster.png", exportFiles + "poster.png");
|
2014-06-26 13:43:57 +00:00
|
|
|
copy_and_overwrite(searchPath + "jqplot.highlighter.min.js", exportFiles + "jqplot.highlighter.min.js");
|
|
|
|
copy_and_overwrite(searchPath + "jquery.jqplot.min.js", exportFiles + "jquery.jqplot.min.js");
|
|
|
|
copy_and_overwrite(searchPath + "jqplot.canvasAxisTickRenderer.min.js", exportFiles + "jqplot.canvasAxisTickRenderer.min.js");
|
|
|
|
copy_and_overwrite(searchPath + "jqplot.canvasTextRenderer.min.js", exportFiles + "jqplot.canvasTextRenderer.min.js");
|
|
|
|
copy_and_overwrite(searchPath + "jquery.min.js", exportFiles + "jquery.min.js");
|
2014-07-07 12:01:36 +00:00
|
|
|
copy_and_overwrite(searchPath + "jquery.jqplot.css", exportFiles + "jquery.jqplot.css");
|
2014-06-24 13:01:52 +00:00
|
|
|
copy_and_overwrite(searchPath + (ui->themeSelection->currentText() == "Light" ? "light.css" : "sand.css"),
|
|
|
|
exportFiles + "theme.css");
|
2014-06-01 04:38:59 +00:00
|
|
|
}
|
|
|
|
|
2014-06-10 11:02:55 +00:00
|
|
|
void DiveLogExportDialog::exportHTMLsettings(const QString &filename)
|
2014-06-01 04:38:59 +00:00
|
|
|
{
|
2014-06-02 15:38:35 +00:00
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup("HTML");
|
|
|
|
settings.setValue("fontSelection", ui->fontSelection->currentIndex());
|
|
|
|
settings.setValue("fontSizeSelection", ui->fontSizeSelection->currentIndex());
|
|
|
|
settings.setValue("themeSelection", ui->themeSelection->currentIndex());
|
|
|
|
settings.endGroup();
|
|
|
|
|
2014-06-01 04:38:59 +00:00
|
|
|
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);
|
2014-06-24 13:01:50 +00:00
|
|
|
out << "settings = {\"fontSize\":\"" << fontSize << "\",\"fontFamily\":\"" << fontFamily << "\",\"listOnly\":\""
|
|
|
|
<< ui->exportListOnly->isChecked() << "\",\"subsurfaceNumbers\":\"" << ui->exportSubsurfaceNumber->isChecked() << "\",}";
|
2014-06-01 04:38:59 +00:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2014-05-24 13:42:10 +00:00
|
|
|
void DiveLogExportDialog::on_exportGroup_buttonClicked(QAbstractButton *button)
|
|
|
|
{
|
|
|
|
showExplanation();
|
|
|
|
}
|
|
|
|
|
2014-05-20 16:33:32 +00:00
|
|
|
void DiveLogExportDialog::on_buttonBox_accepted()
|
|
|
|
{
|
|
|
|
QString filename;
|
|
|
|
QString stylesheet;
|
2014-05-24 14:12:03 +00:00
|
|
|
QSettings settings;
|
|
|
|
QString lastDir = QDir::homePath();
|
|
|
|
|
|
|
|
settings.beginGroup("FileDialog");
|
|
|
|
if (settings.contains("LastDir")) {
|
|
|
|
if (QDir::setCurrent(settings.value("LastDir").toString())) {
|
|
|
|
lastDir = settings.value("LastDir").toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
settings.endGroup();
|
2014-05-20 16:33:32 +00:00
|
|
|
|
2014-06-01 04:38:59 +00:00
|
|
|
switch (ui->tabWidget->currentIndex()) {
|
|
|
|
case 0:
|
|
|
|
if (ui->exportUDDF->isChecked()) {
|
|
|
|
stylesheet = "uddf-export.xslt";
|
2014-07-10 23:06:43 +00:00
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export UDDF file as"), lastDir,
|
2014-06-01 04:38:59 +00:00
|
|
|
tr("UDDF files (*.uddf *.UDDF)"));
|
|
|
|
} else if (ui->exportCSV->isChecked()) {
|
|
|
|
stylesheet = "xml2csv.xslt";
|
2014-07-10 23:06:43 +00:00
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export CSV file as"), lastDir,
|
2014-06-01 04:38:59 +00:00
|
|
|
tr("CSV files (*.csv *.CSV)"));
|
|
|
|
} else if (ui->exportDivelogs->isChecked()) {
|
|
|
|
DivelogsDeWebServices::instance()->prepareDivesForUpload(ui->exportSelected->isChecked());
|
|
|
|
} else if (ui->exportWorldMap->isChecked()) {
|
2014-07-10 23:06:43 +00:00
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export world map"), lastDir,
|
2014-06-01 04:38:59 +00:00
|
|
|
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()) {
|
2014-07-31 17:38:36 +00:00
|
|
|
if (!filename.contains('.'))
|
|
|
|
filename.append(".ssrf");
|
2014-06-01 04:38:59 +00:00
|
|
|
QByteArray bt = QFile::encodeName(filename);
|
2014-07-10 13:36:53 +00:00
|
|
|
save_dives_logic(bt.data(), ui->exportSelected->isChecked());
|
2014-06-01 04:38:59 +00:00
|
|
|
}
|
2014-05-24 14:12:03 +00:00
|
|
|
}
|
2014-06-01 04:38:59 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2014-06-10 15:55:07 +00:00
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export HTML files as"), lastDir,
|
|
|
|
tr("HTML files (*.html)"));
|
2014-05-23 18:49:49 +00:00
|
|
|
if (!filename.isNull() && !filename.isEmpty())
|
2014-06-01 04:38:59 +00:00
|
|
|
exportHtmlInit(filename);
|
|
|
|
break;
|
2014-05-24 14:12:03 +00:00
|
|
|
}
|
2014-05-23 18:49:49 +00:00
|
|
|
|
2014-05-24 14:12:03 +00:00
|
|
|
if (!filename.isNull() && !filename.isEmpty()) {
|
|
|
|
// remember the last export path
|
|
|
|
QFileInfo fileInfo(filename);
|
|
|
|
settings.beginGroup("FileDialog");
|
|
|
|
settings.setValue("LastDir", fileInfo.dir().path());
|
|
|
|
settings.endGroup();
|
|
|
|
// the non XSLT exports are called directly above, the XSLT based ons are called here
|
|
|
|
if (!stylesheet.isEmpty())
|
2014-06-15 20:45:24 +00:00
|
|
|
export_dives_xslt(filename.toUtf8(), ui->exportSelected->isChecked(), stylesheet.toUtf8());
|
2014-05-20 16:33:32 +00:00
|
|
|
}
|
|
|
|
}
|