keepassxc

Форк
0
/
ExportDialog.cpp 
83 строки · 2.9 Кб
1
/*
2
 *  Copyright (C) 2021 KeePassXC Team <team@keepassxc.org>
3
 *
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.
8
 *
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.
13
 *
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/>.
16
 */
17

18
#include "ExportDialog.h"
19
#include "ui_ExportDialog.h"
20

21
#include "gui/FileDialog.h"
22
#include "gui/HtmlExporter.h"
23

24
ExportDialog::ExportDialog(QSharedPointer<const Database> db, DatabaseTabWidget* parent)
25
    : QDialog(parent)
26
    , m_ui(new Ui::ExportDialog())
27
    , m_db(std::move(db))
28
{
29
    m_ui->setupUi(this);
30

31
    setAttribute(Qt::WA_DeleteOnClose);
32

33
    connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(close()));
34
    connect(m_ui->buttonBox, SIGNAL(accepted()), SLOT(exportDatabase()));
35

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);
39

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);
45
}
46

47
ExportDialog::~ExportDialog() = default;
48

49
QString ExportDialog::getStrategyName(ExportSortingStrategy strategy)
50
{
51
    switch (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)");
58
    }
59
    return tr("unknown");
60
}
61

62
void ExportDialog::exportDatabase()
63
{
64
    auto sortBy = m_ui->sortingStrategy->currentData().toInt();
65
    bool ascendingOrder = sortBy == ExportSortingStrategy::BY_NAME_ASC;
66

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()) {
70
        return;
71
    }
72

73
    FileDialog::saveLastDir("html", fileName, true);
74

75
    HtmlExporter htmlExporter;
76
    if (!htmlExporter.exportDatabase(
77
            fileName, m_db, sortBy != ExportSortingStrategy::BY_DATABASE_ORDER, ascendingOrder)) {
78
        emit exportFailed(htmlExporter.errorString());
79
        reject();
80
    }
81

82
    accept();
83
}
84

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.