Much needed clean on the HTML export dialog code.

Correct usage of QFile, QString and code cleanup.

[Dirk Hohndel: plus whitespace cleanup and removal of qDebug() calls]

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-06-10 08:02:55 -03:00 committed by Dirk Hohndel
parent 21be237b0e
commit 748198891d
2 changed files with 17 additions and 33 deletions

View file

@ -5,6 +5,7 @@
#include <QTextStream> #include <QTextStream>
#include <QSettings> #include <QSettings>
#include <QDir> #include <QDir>
#include <QDebug>
#include "mainwindow.h" #include "mainwindow.h"
#include "divelogexportdialog.h" #include "divelogexportdialog.h"
@ -15,7 +16,7 @@
#include "helpers.h" #include "helpers.h"
DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent), DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent),
ui(new Ui::DiveLogExportDialog) ui(new Ui::DiveLogExportDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
showExplanation(); showExplanation();
@ -66,52 +67,35 @@ void DiveLogExportDialog::showExplanation()
} }
} }
void DiveLogExportDialog::exportHtmlInit(QString filename) void DiveLogExportDialog::exportHtmlInit(const QString &filename)
{ {
QDir dir(filename); QDir dir(filename);
if (!dir.exists()) { if (!dir.exists()) {
/* I think this will not work as expected on windows */ dir.mkpath(filename);
QDir::home().mkpath(filename);
} }
QString json_dive_data = filename + QDir::separator() + "file.json"; QString json_dive_data = filename + QDir::separator() + "file.json";
QString json_settings = filename + "/settings.json"; QString json_settings = filename + QDir::separator() + "settings.json";
exportHTMLsettings(json_settings); exportHTMLsettings(json_settings);
export_HTML(json_dive_data.toUtf8().data(), ui->exportSelectedDives->isChecked()); export_HTML(json_dive_data.toUtf8().data(), ui->exportSelectedDives->isChecked());
QString searchPath = getSubsurfaceDataPath("theme"); QString searchPath = getSubsurfaceDataPath("theme");
if (searchPath.isEmpty()) if (searchPath.isEmpty())
return; return;
QFile *tmpFile; searchPath += QDir::separator();
QString dirname = filename + QDir::separator();
tmpFile = new QFile(searchPath + "/dive_export.html"); QFile::copy(searchPath + "dive_export.html", dirname + "dive_export.html");
tmpFile->copy(filename + "/dive_export.html"); QFile::copy(searchPath + "list_lib.js", dirname + "list_lib.js");
delete tmpFile; QFile::copy(searchPath + "poster.png", dirname + "poster.png");
QFile::copy(searchPath + "index.html", dirname + "index.html");
tmpFile = new QFile(searchPath + "/list_lib.js"); QFile::copy(searchPath + ui->themeSelection->currentText() == "Light" ? "light.css" : "sand.css",
tmpFile->copy(filename + "/list_lib.js"); filename + "theme.css");
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) void DiveLogExportDialog::exportHTMLsettings(const QString &filename)
{ {
QSettings settings; QSettings settings;
settings.beginGroup("HTML"); settings.beginGroup("HTML");

View file

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