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-05-24 14:12:03 +00:00
|
|
|
#include <QSettings>
|
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-05-20 16:33:32 +00:00
|
|
|
|
2014-05-22 18:40:22 +00:00
|
|
|
DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent),
|
2014-05-20 16:33:32 +00:00
|
|
|
ui(new Ui::DiveLogExportDialog)
|
|
|
|
{
|
|
|
|
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-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-05-24 13:42:10 +00:00
|
|
|
ui->description->setText("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-05-24 13:42:10 +00:00
|
|
|
ui->description->setText("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-05-24 13:42:10 +00:00
|
|
|
ui->description->setText("Send the dive data to Divelogs.de website.");
|
2014-05-23 20:28:08 +00:00
|
|
|
} else if (ui->exportWorldMap->isChecked()) {
|
2014-05-24 13:42:10 +00:00
|
|
|
ui->description->setText("HTML export of the dive locations, visualized on a world map.");
|
2014-05-24 14:12:03 +00:00
|
|
|
} else if (ui->exportSubsurfaceXML->isChecked()) {
|
|
|
|
ui->description->setText("Subsurface native XML format.");
|
2014-05-23 18:49:49 +00:00
|
|
|
} else if (ui->exportHtml->isChecked()) {
|
|
|
|
ui->description->setText("Html export of dive list can be viewed in any web browser.");
|
2014-05-23 20:28:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (ui->exportUDDF->isChecked()) {
|
|
|
|
stylesheet = "uddf-export.xslt";
|
2014-05-24 14:12:03 +00:00
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export UDDF File as"), lastDir,
|
2014-05-20 16:33:32 +00:00
|
|
|
tr("UDDF files (*.uddf *.UDDF)"));
|
|
|
|
} else if (ui->exportCSV->isChecked()) {
|
|
|
|
stylesheet = "xml2csv.xslt";
|
2014-05-24 14:12:03 +00:00
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export CSV File as"), lastDir,
|
2014-05-20 16:33:32 +00:00
|
|
|
tr("CSV files (*.csv *.CSV)"));
|
|
|
|
} else if (ui->exportDivelogs->isChecked()) {
|
|
|
|
DivelogsDeWebServices::instance()->prepareDivesForUpload(ui->exportSelected->isChecked());
|
|
|
|
} else if (ui->exportWorldMap->isChecked()) {
|
2014-05-24 14:12:03 +00:00
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export World Map"), lastDir,
|
2014-05-22 18:40:22 +00:00
|
|
|
tr("HTML files (*.html)"));
|
2014-05-20 16:33:32 +00:00
|
|
|
if (!filename.isNull() && !filename.isEmpty())
|
2014-05-21 12:23:05 +00:00
|
|
|
export_worldmap_HTML(filename.toUtf8().data(), ui->exportSelected->isChecked());
|
2014-05-24 14:12:03 +00:00
|
|
|
} 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);
|
|
|
|
}
|
2014-05-23 18:49:49 +00:00
|
|
|
} else if (ui->exportHtml->isChecked()) {
|
|
|
|
filename = QFileDialog::getSaveFileName(this, tr("Export HTML"), lastDir,
|
|
|
|
tr("HTML files (*.html)"));
|
|
|
|
if (!filename.isNull() && !filename.isEmpty())
|
|
|
|
export_HTML(filename.toUtf8().data(), ui->exportSelected->isChecked());
|
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())
|
|
|
|
export_dives_xslt(filename.toUtf8(), ui->exportSelected->isChecked(), stylesheet.toStdString().c_str());
|
2014-05-20 16:33:32 +00:00
|
|
|
}
|
|
|
|
}
|