keepassxc

Форк
0
/
GuiTools.cpp 
121 строка · 5.1 Кб
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 "GuiTools.h"
19

20
#include "core/Config.h"
21
#include "core/Group.h"
22
#include "gui/MessageBox.h"
23

24
namespace GuiTools
25
{
26
    bool confirmDeleteEntries(QWidget* parent, const QList<Entry*>& entries, bool permanent)
27
    {
28
        if (!parent || entries.isEmpty()) {
29
            return false;
30
        }
31

32
        if (permanent) {
33
            QString prompt;
34
            if (entries.size() == 1) {
35
                prompt = QObject::tr("Do you really want to delete the entry \"%1\" for good?")
36
                             .arg(entries.first()->title().toHtmlEscaped());
37
            } else {
38
                prompt = QObject::tr("Do you really want to delete %n entry(s) for good?", "", entries.size());
39
            }
40

41
            auto answer = MessageBox::question(parent,
42
                                               QObject::tr("Delete entry(s)?", "", entries.size()),
43
                                               prompt,
44
                                               MessageBox::Delete | MessageBox::Cancel,
45
                                               MessageBox::Cancel);
46

47
            return answer == MessageBox::Delete;
48
        } else if (config()->get(Config::Security_NoConfirmMoveEntryToRecycleBin).toBool()) {
49
            return true;
50
        } else {
51
            QString prompt;
52
            if (entries.size() == 1) {
53
                prompt = QObject::tr("Do you really want to move entry \"%1\" to the recycle bin?")
54
                             .arg(entries.first()->title().toHtmlEscaped());
55
            } else {
56
                prompt = QObject::tr("Do you really want to move %n entry(s) to the recycle bin?", "", entries.size());
57
            }
58

59
            auto answer = MessageBox::question(parent,
60
                                               QObject::tr("Move entry(s) to recycle bin?", "", entries.size()),
61
                                               prompt,
62
                                               MessageBox::Move | MessageBox::Cancel,
63
                                               MessageBox::Cancel);
64

65
            return answer == MessageBox::Move;
66
        }
67
    }
68

69
    size_t deleteEntriesResolveReferences(QWidget* parent, const QList<Entry*>& entries, bool permanent)
70
    {
71
        if (!parent || entries.isEmpty()) {
72
            return 0;
73
        }
74

75
        QList<Entry*> selectedEntries;
76
        // Find references to entries and prompt for direction if necessary
77
        for (auto entry : entries) {
78
            if (permanent) {
79
                auto references = entry->database()->rootGroup()->referencesRecursive(entry);
80
                if (!references.isEmpty()) {
81
                    // Ignore references that are part of this cohort
82
                    for (auto e : entries) {
83
                        references.removeAll(e);
84
                    }
85
                    // Prompt the user on what to do with the reference (Overwrite, Delete, Skip)
86
                    auto result = MessageBox::question(
87
                        parent,
88
                        QObject::tr("Replace references to entry?"),
89
                        QObject::tr(
90
                            "Entry \"%1\" has %2 reference(s). "
91
                            "Do you want to overwrite references with values, skip this entry, or delete anyway?",
92
                            "",
93
                            references.size())
94
                            .arg(entry->resolvePlaceholder(entry->title()).toHtmlEscaped())
95
                            .arg(references.size()),
96
                        MessageBox::Overwrite | MessageBox::Skip | MessageBox::Delete,
97
                        MessageBox::Overwrite);
98

99
                    if (result == MessageBox::Overwrite) {
100
                        for (auto ref : references) {
101
                            ref->replaceReferencesWithValues(entry);
102
                        }
103
                    } else if (result == MessageBox::Skip) {
104
                        continue;
105
                    }
106
                }
107
            }
108
            // Marked for deletion
109
            selectedEntries << entry;
110
        }
111

112
        for (auto entry : asConst(selectedEntries)) {
113
            if (permanent) {
114
                delete entry;
115
            } else {
116
                entry->database()->recycleEntry(entry);
117
            }
118
        }
119
        return selectedEntries.size();
120
    }
121
} // namespace GuiTools
122

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

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

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

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