2
* Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 2 or (at your option)
7
* version 3 of the License.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include "ExportDialog.h"
19
#include "ui_ExportDialog.h"
21
#include "gui/FileDialog.h"
22
#include "gui/HtmlExporter.h"
24
ExportDialog::ExportDialog(QSharedPointer<const Database> db, DatabaseTabWidget* parent)
26
, m_ui(new Ui::ExportDialog())
31
setAttribute(Qt::WA_DeleteOnClose);
33
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(close()));
34
connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(exportDatabase()));
36
m_ui->sortingStrategy->addItem(getStrategyName(BY_NAME_ASC), BY_NAME_ASC);
37
m_ui->sortingStrategy->addItem(getStrategyName(BY_NAME_DESC), BY_NAME_DESC);
38
m_ui->sortingStrategy->addItem(getStrategyName(BY_DATABASE_ORDER), BY_DATABASE_ORDER);
40
m_ui->messageWidget->setCloseButtonVisible(false);
41
m_ui->messageWidget->setAutoHideTimeout(-1);
42
m_ui->messageWidget->showMessage(tr("You are about to export your database to an unencrypted file.\n"
43
"This will leave your passwords and sensitive information vulnerable!\n"),
44
MessageWidget::Warning);
47
ExportDialog::~ExportDialog() = default;
49
QString ExportDialog::getStrategyName(ExportSortingStrategy strategy)
52
case ExportSortingStrategy::BY_DATABASE_ORDER:
53
return tr("database order");
54
case ExportSortingStrategy::BY_NAME_ASC:
55
return tr("name (ascending)");
56
case ExportSortingStrategy::BY_NAME_DESC:
57
return tr("name (descending)");
62
void ExportDialog::exportDatabase()
64
auto sortBy = m_ui->sortingStrategy->currentData().toInt();
65
bool ascendingOrder = sortBy == ExportSortingStrategy::BY_NAME_ASC;
67
const QString fileName = fileDialog()->getSaveFileName(
68
this, tr("Export database to HTML file"), FileDialog::getLastDir("html"), tr("HTML file").append(" (*.html)"));
69
if (fileName.isEmpty()) {
73
FileDialog::saveLastDir("html", fileName, true);
75
HtmlExporter htmlExporter;
76
if (!htmlExporter.exportDatabase(
77
fileName, m_db, sortBy != ExportSortingStrategy::BY_DATABASE_ORDER, ascendingOrder)) {
78
emit exportFailed(htmlExporter.errorString());