diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index ee83fac32..a56559933 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -71,6 +71,7 @@ set(core_SOURCES
format/BitwardenReader.cpp
format/CsvExporter.cpp
format/CsvParser.cpp
+ format/HtmlExporter.cpp
format/KeePass1Reader.cpp
format/KeePass2.cpp
format/KeePass2RandomStream.cpp
@@ -127,7 +128,7 @@ set(gui_SOURCES
gui/FileDialog.cpp
gui/Font.cpp
gui/GuiTools.cpp
- gui/HtmlExporter.cpp
+ gui/HtmlGuiExporter.cpp
gui/IconModels.cpp
gui/KMessageWidget.cpp
gui/MainWindow.cpp
diff --git a/src/cli/Export.cpp b/src/cli/Export.cpp
index a7f454776..36b38b1de 100644
--- a/src/cli/Export.cpp
+++ b/src/cli/Export.cpp
@@ -21,13 +21,14 @@
#include "Utils.h"
#include "core/Global.h"
#include "format/CsvExporter.h"
+#include "format/HtmlExporter.h"
#include
const QCommandLineOption Export::FormatOption = QCommandLineOption(
QStringList() << "f" << "format",
- QObject::tr("Format to use when exporting. Available choices are 'xml' or 'csv'. Defaults to 'xml'."),
- QStringLiteral("xml|csv"));
+ QObject::tr("Format to use when exporting. Available choices are 'xml', 'csv' or 'html'. Defaults to 'xml'."),
+ QStringLiteral("xml|csv|html"));
Export::Export()
{
@@ -53,6 +54,9 @@ int Export::executeWithDatabase(QSharedPointer database, QSharedPointe
} else if (format.startsWith(QStringLiteral("csv"), Qt::CaseInsensitive)) {
CsvExporter csvExporter;
out << csvExporter.exportDatabase(database);
+ } else if (format.startsWith(QStringLiteral("html"), Qt::CaseInsensitive)) {
+ HtmlExporter htmlExporter;
+ out << htmlExporter.exportDatabase(database);
} else {
err << QObject::tr("Unsupported format %1").arg(format) << Qt::endl;
return EXIT_FAILURE;
diff --git a/src/gui/HtmlExporter.cpp b/src/format/HtmlExporter.cpp
similarity index 82%
rename from src/gui/HtmlExporter.cpp
rename to src/format/HtmlExporter.cpp
index 0c45259ac..eb57d0377 100644
--- a/src/gui/HtmlExporter.cpp
+++ b/src/format/HtmlExporter.cpp
@@ -17,28 +17,13 @@
#include "HtmlExporter.h"
-#include
#include
#include "core/Group.h"
#include "core/Metadata.h"
-#include "gui/Icons.h"
namespace
{
- QString PixmapToHTML(const QPixmap& pixmap)
- {
- if (pixmap.isNull()) {
- return "";
- }
-
- // Based on https://stackoverflow.com/a/6621278
- QByteArray a;
- QBuffer buffer(&a);
- pixmap.save(&buffer, "PNG");
- return QString("";
- }
-
QString formatEntry(const Entry& entry)
{
// Here we collect the table rows with this entry's data fields
@@ -127,15 +112,62 @@ QString HtmlExporter::errorString() const
return m_error;
}
+QString HtmlExporter::groupIconToHtml(const Group* /* group */) {
+ return "";
+}
+
+QString HtmlExporter::entryIconToHtml(const Entry* /* entry */) {
+ return "";
+}
+
bool HtmlExporter::exportDatabase(QIODevice* device,
const QSharedPointer& db,
bool sorted,
bool ascending)
+{
+ if (device->write(exportHeader(db).toUtf8()) == -1) {
+ m_error = device->errorString();
+ return false;
+ }
+
+ if (db->rootGroup()) {
+ if (device->write(exportGroup(*db->rootGroup(), QString(), sorted, ascending).toUtf8()) == -1) {
+ m_error = device->errorString();
+ return false;
+ }
+ }
+
+ if (device->write(exportFooter().toUtf8()) == -1) {
+ m_error = device->errorString();
+ return false;
+ }
+
+ return true;
+}
+
+QString HtmlExporter::exportDatabase(const QSharedPointer& db,
+ bool sorted,
+ bool ascending)
+{
+ QString response;
+
+ response = exportHeader(db);
+ if (!response.isEmpty()) {
+ if (db->rootGroup()) {
+ response.append(exportGroup(*db->rootGroup(), QString(), sorted, ascending));
+ }
+ response.append(exportFooter());
+ }
+
+ return response;
+}
+
+QString HtmlExporter::exportHeader(const QSharedPointer& db)
{
const auto meta = db->metadata();
if (!meta) {
m_error = "Internal error: metadata is NULL";
- return false;
+ return "";
}
const auto header = QString(""
@@ -171,33 +203,23 @@ bool HtmlExporter::exportDatabase(QIODevice* device,
+ "
"
""
+ db->filePath().toHtmlEscaped() + "
");
- const auto footer = QString(""
- "