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"
|
2014-09-21 14:11:58 +00:00
|
|
|
#include "diveshareexportdialog.h"
|
2014-05-20 16:33:32 +00:00
|
|
|
#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-08-04 07:30:31 +00:00
|
|
|
#include "statistics.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);
|
|
|
|
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());
|
|
|
|
}
|
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());
|
|
|
|
}
|
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-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-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."));
|
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-08-28 08:12:21 +00:00
|
|
|
QString json_dive_data = exportFiles + QDir::separator() + "file.js";
|
|
|
|
QString json_settings = exportFiles + QDir::separator() + "settings.js";
|
|
|
|
QString translation = exportFiles + QDir::separator() + "translation.js";
|
|
|
|
QString stat_file = exportFiles + QDir::separator() + "stat.js";
|
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-08-04 07:30:31 +00:00
|
|
|
exportHTMLstatistics(stat_file);
|
2014-08-10 07:12:29 +00:00
|
|
|
export_translation(translation.toUtf8().data());
|
2014-08-04 11:02:16 +00:00
|
|
|
|
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());
|
2014-08-10 04:10:19 +00:00
|
|
|
settings.setValue("subsurfaceNumbers", ui->exportSubsurfaceNumber->isChecked());
|
|
|
|
settings.setValue("yearlyStatistics", ui->exportStatistics->isChecked());
|
|
|
|
settings.setValue("listOnly", ui->exportListOnly->isChecked());
|
2014-06-02 15:38:35 +00:00
|
|
|
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\":\""
|
2014-10-17 20:46:33 +00:00
|
|
|
<< ui->exportListOnly->isChecked() << "\",\"subsurfaceNumbers\":\"" << ui->exportSubsurfaceNumber->isChecked() << "\",";
|
|
|
|
//save units preferences
|
|
|
|
settings.beginGroup("Units");
|
|
|
|
if (settings.value("unit_system").toString() == "metric") {
|
|
|
|
out << "\"unit_system\":\"Meteric\"";
|
|
|
|
} else if (settings.value("unit_system").toString() == "imperial") {
|
|
|
|
out << "\"unit_system\":\"Imperial\"";
|
|
|
|
} else {
|
|
|
|
QVariant v;
|
|
|
|
QString length, pressure, volume, temperature, weight;
|
|
|
|
GET_UNIT("length", length, "FEET", "METER");
|
|
|
|
GET_UNIT("pressure", pressure, "PSI", "BAR");
|
|
|
|
GET_UNIT("volume", volume, "CUFT", "LITER");
|
|
|
|
GET_UNIT("temperature", temperature, "FAHRENHEIT", "CELSIUS");
|
|
|
|
GET_UNIT("weight", weight, "LBS", "KG");
|
|
|
|
out << "\"unit_system\":\"Personalize\",";
|
|
|
|
out << "\"units\":{\"depth\":\"" << length << "\",\"pressure\":\"" << pressure << "\",\"volume\":\"" << volume << "\",\"temperature\":\"" << temperature << "\",\"weight\":\"" << weight << "\"}";
|
|
|
|
}
|
|
|
|
out << "}";
|
|
|
|
settings.endGroup();
|
2014-06-01 04:38:59 +00:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2014-08-04 07:30:31 +00:00
|
|
|
void DiveLogExportDialog::exportHTMLstatistics(const QString &filename)
|
|
|
|
{
|
|
|
|
QFile file(filename);
|
|
|
|
file.open(QIODevice::WriteOnly | QIODevice::Text);
|
|
|
|
QTextStream out(&file);
|
2014-08-07 13:11:23 +00:00
|
|
|
|
|
|
|
stats_t total_stats;
|
|
|
|
|
|
|
|
total_stats.selection_size = 0;
|
|
|
|
total_stats.total_time.seconds = 0;
|
|
|
|
|
2014-08-04 07:30:31 +00:00
|
|
|
int i = 0;
|
|
|
|
out << "divestat=[";
|
2014-08-04 11:02:16 +00:00
|
|
|
if (ui->exportStatistics->isChecked()) {
|
|
|
|
while (stats_yearly != NULL && stats_yearly[i].period) {
|
|
|
|
out << "{";
|
|
|
|
out << "\"YEAR\":\"" << stats_yearly[i].period << "\",";
|
|
|
|
out << "\"DIVES\":\"" << stats_yearly[i].selection_size << "\",";
|
|
|
|
out << "\"TOTAL_TIME\":\"" << get_time_string(stats_yearly[i].total_time.seconds, 0) << "\",";
|
|
|
|
out << "\"AVERAGE_TIME\":\"" << get_minutes(stats_yearly[i].total_time.seconds / stats_yearly[i].selection_size) << "\",";
|
|
|
|
out << "\"SHORTEST_TIME\":\"" << get_minutes(stats_yearly[i].shortest_time.seconds) << "\",";
|
|
|
|
out << "\"LONGEST_TIME\":\"" << get_minutes(stats_yearly[i].longest_time.seconds) << "\",";
|
|
|
|
out << "\"AVG_DEPTH\":\"" << get_depth_string(stats_yearly[i].avg_depth) << "\",";
|
|
|
|
out << "\"MIN_DEPTH\":\"" << get_depth_string(stats_yearly[i].min_depth) << "\",";
|
|
|
|
out << "\"MAX_DEPTH\":\"" << get_depth_string(stats_yearly[i].max_depth) << "\",";
|
|
|
|
out << "\"AVG_SAC\":\"" << get_volume_string(stats_yearly[i].avg_sac) << "\",";
|
|
|
|
out << "\"MIN_SAC\":\"" << get_volume_string(stats_yearly[i].min_sac) << "\",";
|
|
|
|
out << "\"MAX_SAC\":\"" << get_volume_string(stats_yearly[i].max_sac) << "\",";
|
|
|
|
out << "\"AVG_TEMP\":\"" << QString::number(stats_yearly[i].combined_temp / stats_yearly[i].combined_count, 'f', 1) << "\",";
|
|
|
|
out << "\"MIN_TEMP\":\"" << get_temp_units(stats_yearly[i].min_temp, NULL) << "\",";
|
|
|
|
out << "\"MAX_TEMP\":\"" << get_temp_units(stats_yearly[i].max_temp, NULL) << "\",";
|
|
|
|
out << "},";
|
2014-08-07 13:11:23 +00:00
|
|
|
total_stats.selection_size += stats_yearly[i].selection_size;
|
|
|
|
total_stats.total_time.seconds += stats_yearly[i].total_time.seconds;
|
2014-08-04 11:02:16 +00:00
|
|
|
i++;
|
|
|
|
}
|
2014-08-10 04:10:41 +00:00
|
|
|
exportHTMLstatisticsTotal(out, &total_stats);
|
2014-08-04 07:30:31 +00:00
|
|
|
}
|
|
|
|
out << "]";
|
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
2014-08-07 13:11:23 +00:00
|
|
|
void exportHTMLstatisticsTotal(QTextStream &out, stats_t *total_stats)
|
|
|
|
{
|
|
|
|
out << "{";
|
|
|
|
out << "\"YEAR\":\"Total\",";
|
|
|
|
out << "\"DIVES\":\"" << total_stats->selection_size << "\",";
|
|
|
|
out << "\"TOTAL_TIME\":\"" << get_time_string(total_stats->total_time.seconds, 0) << "\",";
|
|
|
|
out << "\"AVERAGE_TIME\":\"--\",";
|
|
|
|
out << "\"SHORTEST_TIME\":\"--\",";
|
|
|
|
out << "\"LONGEST_TIME\":\"--\",";
|
|
|
|
out << "\"AVG_DEPTH\":\"--\",";
|
|
|
|
out << "\"MIN_DEPTH\":\"--\",";
|
|
|
|
out << "\"MAX_DEPTH\":\"--\",";
|
|
|
|
out << "\"AVG_SAC\":\"--\",";
|
|
|
|
out << "\"MIN_SAC\":\"--\",";
|
|
|
|
out << "\"MAX_SAC\":\"--\",";
|
|
|
|
out << "\"AVG_TEMP\":\"--\",";
|
|
|
|
out << "\"MIN_TEMP\":\"--\",";
|
|
|
|
out << "\"MAX_TEMP\":\"--\",";
|
|
|
|
out << "},";
|
|
|
|
}
|
|
|
|
|
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());
|
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());
|
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
|
|
|
}
|
|
|
|
}
|
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;
|
2014-10-25 09:05:28 +00:00
|
|
|
const char **unit = NULL;
|
2014-09-28 21:47:41 +00:00
|
|
|
|
|
|
|
struct membuffer buf = { 0 };
|
|
|
|
|
|
|
|
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++;
|
|
|
|
}
|
|
|
|
put_format(&buf, "%s\t%.1f%s\n", picture->filename, get_depth_units(depth.mm, NULL, unit), *unit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|