2014-05-20 16:33:32 +00:00
|
|
|
#include <QFileDialog>
|
2014-05-21 12:41:46 +00:00
|
|
|
#include <QShortcut>
|
2014-05-24 14:12:03 +00:00
|
|
|
#include <QSettings>
|
2015-01-30 19:42:33 +00:00
|
|
|
#include <QtConcurrent>
|
2015-02-22 16:30:34 +00:00
|
|
|
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/divelogexportdialog.h"
|
|
|
|
#include "core/divelogexportlogic.h"
|
|
|
|
#include "desktop-widgets/diveshareexportdialog.h"
|
2014-05-20 16:33:32 +00:00
|
|
|
#include "ui_divelogexportdialog.h"
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "desktop-widgets/subsurfacewebservices.h"
|
|
|
|
#include "core/worldmap-save.h"
|
|
|
|
#include "core/save-html.h"
|
|
|
|
#include "desktop-widgets/mainwindow.h"
|
2016-10-03 15:08:02 +00:00
|
|
|
#include "profile-widget/profilewidget2.h"
|
|
|
|
|
2014-05-20 16:33:32 +00:00
|
|
|
|
2014-10-17 20:46:33 +00:00
|
|
|
#define GET_UNIT(name, field, f, t) \
|
|
|
|
v = settings.value(QString(name)); \
|
|
|
|
if (v.isValid()) \
|
|
|
|
field = (v.toInt() == 0) ? (t) : (f); \
|
|
|
|
else \
|
|
|
|
field = default_prefs.units.field
|
|
|
|
|
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);
|
2015-05-25 19:01:57 +00:00
|
|
|
connect(quit, SIGNAL(activated()), MainWindow::instance(), SLOT(close()));
|
2014-05-21 12:41:46 +00:00
|
|
|
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());
|
|
|
|
}
|
2014-08-10 04:10:19 +00:00
|
|
|
if (settings.contains("subsurfaceNumbers")) {
|
|
|
|
ui->exportSubsurfaceNumber->setChecked(settings.value("subsurfaceNumbers").toBool());
|
|
|
|
}
|
|
|
|
if (settings.contains("yearlyStatistics")) {
|
|
|
|
ui->exportStatistics->setChecked(settings.value("yearlyStatistics").toBool());
|
|
|
|
}
|
|
|
|
if (settings.contains("listOnly")) {
|
|
|
|
ui->exportListOnly->setChecked(settings.value("listOnly").toBool());
|
|
|
|
}
|
2015-03-13 13:36:52 +00:00
|
|
|
if (settings.contains("exportPhotos")) {
|
|
|
|
ui->exportPhotos->setChecked(settings.value("exportPhotos").toBool());
|
|
|
|
}
|
2014-06-02 15:38:35 +00:00
|
|
|
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-12-29 15:45:29 +00:00
|
|
|
ui->description->setText(tr("Comma separated values describing the dive profile."));
|
2014-12-29 15:45:28 +00:00
|
|
|
} else if (ui->exportCSVDetails->isChecked()) {
|
|
|
|
ui->description->setText(tr("Comma separated values of the dive information. This includes most of the dive details but no profile information."));
|
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-09-21 14:11:58 +00:00
|
|
|
} else if (ui->exportDiveshare->isChecked()) {
|
|
|
|
ui->description->setText(tr("Send the dive data to dive-share.appspot.com 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-09-28 21:47:41 +00:00
|
|
|
} else if (ui->exportImageDepths->isChecked()) {
|
|
|
|
ui->description->setText(tr("Write depths of images to file."));
|
2016-10-03 15:08:02 +00:00
|
|
|
} else if (ui->exportTeX->isChecked()) {
|
|
|
|
ui->description->setText(tr("Write dive as TeX macros to file."));
|
2014-05-23 20:28:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 11:02:55 +00:00
|
|
|
void DiveLogExportDialog::exportHtmlInit(const QString &filename)
|
2014-06-01 04:38:59 +00:00
|
|
|
{
|
2015-06-16 13:34:40 +00:00
|
|
|
struct htmlExportSetting hes;
|
|
|
|
hes.themeFile = (ui->themeSelection->currentText() == tr("Light")) ? "light.css" : "sand.css";
|
|
|
|
hes.exportPhotos = ui->exportPhotos->isChecked();
|
|
|
|
hes.selectedOnly = ui->exportSelectedDives->isChecked();
|
|
|
|
hes.listOnly = ui->exportListOnly->isChecked();
|
|
|
|
hes.fontFamily = ui->fontSelection->itemData(ui->fontSelection->currentIndex()).toString();
|
|
|
|
hes.fontSize = ui->fontSizeSelection->currentText();
|
|
|
|
hes.themeSelection = ui->themeSelection->currentIndex();
|
|
|
|
hes.subsurfaceNumbers = ui->exportSubsurfaceNumber->isChecked();
|
|
|
|
hes.yearlyStatistics = ui->exportStatistics->isChecked();
|
|
|
|
|
|
|
|
exportHtmlInitLogic(filename, hes);
|
2014-06-01 04:38:59 +00:00
|
|
|
}
|
|
|
|
|
2014-05-24 13:42:10 +00:00
|
|
|
void DiveLogExportDialog::on_exportGroup_buttonClicked(QAbstractButton *button)
|
|
|
|
{
|
2016-03-10 04:28:56 +00:00
|
|
|
Q_UNUSED(button)
|
2014-05-24 13:42:10 +00:00
|
|
|
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)"));
|
2014-12-22 01:53:18 +00:00
|
|
|
} else if (ui->exportCSVDetails->isChecked()) {
|
|
|
|
stylesheet = "xml2manualcsv.xslt";
|
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export CSV file as"), lastDir,
|
|
|
|
tr("CSV files (*.csv *.CSV)"));
|
2014-06-01 04:38:59 +00:00
|
|
|
} else if (ui->exportDivelogs->isChecked()) {
|
|
|
|
DivelogsDeWebServices::instance()->prepareDivesForUpload(ui->exportSelected->isChecked());
|
2014-09-21 14:11:58 +00:00
|
|
|
} else if (ui->exportDiveshare->isChecked()) {
|
|
|
|
DiveShareExportDialog::instance()->prepareDivesForUpload(ui->exportSelected->isChecked());
|
2014-06-01 04:38:59 +00:00
|
|
|
} 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-09-28 21:47:41 +00:00
|
|
|
} else if (ui->exportImageDepths->isChecked()) {
|
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Save image depths"), lastDir);
|
|
|
|
if (!filename.isNull() && !filename.isEmpty())
|
|
|
|
export_depths(filename.toUtf8().data(), ui->exportSelected->isChecked());
|
2016-10-03 15:08:02 +00:00
|
|
|
} else if (ui->exportTeX->isChecked()) {
|
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export to TeX file"), lastDir, tr("TeX files (*.tex)"));
|
|
|
|
if (!filename.isNull() && !filename.isEmpty())
|
|
|
|
export_TeX(filename.toUtf8().data(), ui->exportSelected->isChecked());
|
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
|
2015-02-26 14:07:39 +00:00
|
|
|
if (!stylesheet.isEmpty()) {
|
2015-01-30 19:42:33 +00:00
|
|
|
future = QtConcurrent::run(export_dives_xslt, filename.toUtf8(), ui->exportSelected->isChecked(), ui->CSVUnits_2->currentIndex(), stylesheet.toUtf8());
|
2015-09-04 22:25:35 +00:00
|
|
|
MainWindow::instance()->getNotificationWidget()->showNotification(tr("Please wait, exporting..."), KMessageWidget::Information);
|
2015-02-26 14:07:39 +00:00
|
|
|
MainWindow::instance()->getNotificationWidget()->setFuture(future);
|
|
|
|
}
|
2014-05-20 16:33:32 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-28 21:47:41 +00:00
|
|
|
|
|
|
|
void DiveLogExportDialog::export_depths(const char *filename, const bool selected_only)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
struct dive *dive;
|
|
|
|
depth_t depth;
|
|
|
|
int i;
|
2015-01-25 14:47:50 +00:00
|
|
|
const char *unit = NULL;
|
2014-09-28 21:47:41 +00:00
|
|
|
|
2016-03-10 04:28:56 +00:00
|
|
|
struct membuffer buf = {};
|
2014-09-28 21:47:41 +00:00
|
|
|
|
|
|
|
for_each_dive (i, dive) {
|
|
|
|
if (selected_only && !dive->selected)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
FOR_EACH_PICTURE (dive) {
|
|
|
|
int n = dive->dc.samples;
|
|
|
|
struct sample *s = dive->dc.sample;
|
|
|
|
depth.mm = 0;
|
2014-10-27 20:41:20 +00:00
|
|
|
while (--n >= 0 && (int32_t)s->time.seconds <= picture->offset.seconds) {
|
2014-09-28 21:47:41 +00:00
|
|
|
depth.mm = s->depth.mm;
|
|
|
|
s++;
|
|
|
|
}
|
2015-01-25 14:47:51 +00:00
|
|
|
put_format(&buf, "%s\t%.1f", picture->filename, get_depth_units(depth.mm, NULL, &unit));
|
|
|
|
put_format(&buf, "%s\n", unit);
|
2014-09-28 21:47:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f = subsurface_fopen(filename, "w+");
|
|
|
|
if (!f) {
|
|
|
|
report_error(tr("Can't open file %s").toUtf8().data(), filename);
|
|
|
|
} else {
|
|
|
|
flush_buffer(&buf, f); /*check for writing errors? */
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
free_buffer(&buf);
|
|
|
|
}
|
2016-10-03 15:08:02 +00:00
|
|
|
|
|
|
|
void DiveLogExportDialog::export_TeX(const char *filename, const bool selected_only)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
struct dive *dive;
|
|
|
|
int i;
|
|
|
|
bool need_pagebreak = false;
|
|
|
|
|
|
|
|
struct membuffer buf = {};
|
|
|
|
|
|
|
|
put_format(&buf, "\\input subsurfacetemplate\n");
|
|
|
|
put_format(&buf, "%% This is a plain TeX file. Compile with pdftex, not pdflatex!\n");
|
|
|
|
put_format(&buf, "%% You will also need a subsurfacetemplate.tex in the current directory.\n");
|
|
|
|
put_format(&buf, "%% You can downlaod an example from http://www.atdotde.de/~robert/subsurfacetemplate\n%%\n");
|
|
|
|
for_each_dive (i, dive) {
|
|
|
|
if (selected_only && !dive->selected)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
QString filename = "profile%1.png";
|
|
|
|
ProfileWidget2 *profile = MainWindow::instance()->graphics();
|
|
|
|
profile->plotDive(dive, true);
|
|
|
|
profile->setToolTipVisibile(false);
|
|
|
|
QPixmap pix = QPixmap::grabWidget(profile);
|
|
|
|
profile->setToolTipVisibile(true);
|
|
|
|
pix.save(filename.arg(dive->number));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct tm tm;
|
|
|
|
utc_mkdate(dive->when, &tm);
|
|
|
|
|
2016-10-19 18:56:01 +00:00
|
|
|
dive_site *site = get_dive_site_by_uuid(dive->dive_site_uuid);
|
|
|
|
QRegExp ct("countrytag: (\\w+)");
|
|
|
|
QString country;
|
|
|
|
if (ct.indexIn(site->notes) >= 0)
|
|
|
|
country = ct.cap(1);
|
|
|
|
else
|
|
|
|
country = "";
|
2016-10-03 15:08:02 +00:00
|
|
|
|
|
|
|
pressure_t delta_p = {.mbar = 0};
|
|
|
|
|
|
|
|
QString star = "*";
|
|
|
|
QString viz = star.repeated(dive->visibility);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CYLINDERS; i++)
|
2017-02-03 15:31:03 +00:00
|
|
|
if (is_cylinder_used(dive, i))
|
2016-10-03 15:08:02 +00:00
|
|
|
delta_p.mbar += dive->cylinder[i].start.mbar - dive->cylinder[i].end.mbar;
|
|
|
|
|
|
|
|
if (need_pagebreak)
|
|
|
|
put_format(&buf, "\\vfill\\eject\n");
|
|
|
|
need_pagebreak = true;
|
|
|
|
put_format(&buf, "\\def\\date{%04u-%02u-%02u}\n",
|
|
|
|
tm.tm_year, tm.tm_mon+1, tm.tm_mday);
|
|
|
|
put_format(&buf, "\\def\\number{%d}\n", dive->number);
|
2016-10-13 11:39:58 +00:00
|
|
|
put_format(&buf, "\\def\\place{%s}\n", site ? site->name : "");
|
2016-10-03 15:08:02 +00:00
|
|
|
put_format(&buf, "\\def\\spot{}\n");
|
2016-10-19 18:56:01 +00:00
|
|
|
put_format(&buf, "\\def\\country{%s}\n", country.toUtf8().data());
|
2016-10-03 15:08:02 +00:00
|
|
|
put_format(&buf, "\\def\\entrance{}\n");
|
|
|
|
put_format(&buf, "\\def\\time{%u:%02u}\n", FRACTION(dive->duration.seconds, 60));
|
|
|
|
put_format(&buf, "\\def\\depth{%u.%01um}\n", FRACTION(dive->maxdepth.mm / 100, 10));
|
|
|
|
put_format(&buf, "\\def\\gasuse{%u.%01ubar}\n", FRACTION(delta_p.mbar / 100, 10));
|
|
|
|
put_format(&buf, "\\def\\sac{%u.%01u l/min}\n", FRACTION(dive->sac/100,10));
|
|
|
|
put_format(&buf, "\\def\\type{%s}\n", dive->tag_list ? dive->tag_list->tag->name : "");
|
|
|
|
put_format(&buf, "\\def\\viz{%s}\n", viz.toUtf8().data());
|
|
|
|
put_format(&buf, "\\def\\plot{\\includegraphics[width=9cm,height=4cm]{profile%d}}\n", dive->number);
|
2016-10-13 11:39:58 +00:00
|
|
|
put_format(&buf, "\\def\\comment{%s}\n", dive->notes ? dive->notes : "");
|
|
|
|
put_format(&buf, "\\def\\buddy{%s}\n", dive->buddy ? dive->buddy : "");
|
2016-10-03 15:08:02 +00:00
|
|
|
put_format(&buf, "\\page\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
put_format(&buf, "\\bye\n");
|
|
|
|
|
|
|
|
f = subsurface_fopen(filename, "w+");
|
|
|
|
if (!f) {
|
|
|
|
report_error(tr("Can't open file %s").toUtf8().data(), filename);
|
|
|
|
} else {
|
|
|
|
flush_buffer(&buf, f); /*check for writing errors? */
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
free_buffer(&buf);
|
|
|
|
}
|