keepassxc

Форк
0
/
ReportsDialog.cpp 
184 строки · 5.7 Кб
1
/*
2
 *  Copyright (C) 2023 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 "ReportsDialog.h"
19
#include "ui_ReportsDialog.h"
20

21
#include "ReportsPageHealthcheck.h"
22
#include "ReportsPageHibp.h"
23
#include "ReportsPageStatistics.h"
24
#ifdef WITH_XC_BROWSER
25
#include "ReportsPageBrowserStatistics.h"
26
#include "ReportsWidgetBrowserStatistics.h"
27
#endif
28
#ifdef WITH_XC_BROWSER_PASSKEYS
29
#include "ReportsPagePasskeys.h"
30
#include "ReportsWidgetPasskeys.h"
31
#endif
32
#include "ReportsWidgetHealthcheck.h"
33
#include "ReportsWidgetHibp.h"
34

35
#include "core/Global.h"
36
#include "core/Group.h"
37

38
class ReportsDialog::ExtraPage
39
{
40
public:
41
    ExtraPage(QSharedPointer<IReportsPage> p, QWidget* w)
42
        : page(p)
43
        , widget(w)
44
    {
45
    }
46
    void loadSettings(QSharedPointer<Database> db) const
47
    {
48
        page->loadSettings(widget, db);
49
    }
50
    void saveSettings() const
51
    {
52
        page->saveSettings(widget);
53
    }
54

55
private:
56
    QSharedPointer<IReportsPage> page;
57
    QWidget* widget;
58
};
59

60
ReportsDialog::ReportsDialog(QWidget* parent)
61
    : DialogyWidget(parent)
62
    , m_ui(new Ui::ReportsDialog())
63
    , m_healthPage(new ReportsPageHealthcheck())
64
    , m_hibpPage(new ReportsPageHibp())
65
    , m_statPage(new ReportsPageStatistics())
66
#ifdef WITH_XC_BROWSER
67
    , m_browserStatPage(new ReportsPageBrowserStatistics())
68
#endif
69
#ifdef WITH_XC_BROWSER_PASSKEYS
70
    , m_passkeysPage(new ReportsPagePasskeys())
71
#endif
72
    , m_editEntryWidget(new EditEntryWidget(this))
73
{
74
    m_ui->setupUi(this);
75

76
    connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
77
    addPage(m_statPage);
78
    addPage(m_healthPage);
79
#ifdef WITH_XC_BROWSER_PASSKEYS
80
    addPage(m_passkeysPage);
81
#endif
82
#ifdef WITH_XC_BROWSER
83
    addPage(m_browserStatPage);
84
#endif
85
    addPage(m_hibpPage);
86

87
    m_ui->stackedWidget->setCurrentIndex(0);
88

89
    m_editEntryWidget->setObjectName("editEntryWidget");
90
    m_editEntryWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
91
    m_ui->stackedWidget->addWidget(m_editEntryWidget);
92
    adjustSize();
93

94
    connect(m_ui->categoryList, SIGNAL(categoryChanged(int)), m_ui->stackedWidget, SLOT(setCurrentIndex(int)));
95
    connect(m_healthPage->m_healthWidget, SIGNAL(entryActivated(Entry*)), SLOT(entryActivationSignalReceived(Entry*)));
96
    connect(m_hibpPage->m_hibpWidget, SIGNAL(entryActivated(Entry*)), SLOT(entryActivationSignalReceived(Entry*)));
97
#ifdef WITH_XC_BROWSER
98
    connect(m_browserStatPage->m_browserWidget,
99
            SIGNAL(entryActivated(Entry*)),
100
            SLOT(entryActivationSignalReceived(Entry*)));
101
#endif
102
#ifdef WITH_XC_BROWSER_PASSKEYS
103
    connect(
104
        m_passkeysPage->m_passkeysWidget, SIGNAL(entryActivated(Entry*)), SLOT(entryActivationSignalReceived(Entry*)));
105
#endif
106
    connect(m_editEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchToMainView(bool)));
107
}
108

109
ReportsDialog::~ReportsDialog() = default;
110

111
void ReportsDialog::load(const QSharedPointer<Database>& db)
112
{
113
    m_ui->categoryList->setCurrentCategory(0);
114
    for (const ExtraPage& page : asConst(m_extraPages)) {
115
        page.loadSettings(db);
116
    }
117
    m_db = db;
118
}
119

120
void ReportsDialog::addPage(QSharedPointer<IReportsPage> page)
121
{
122
    const auto category = m_ui->categoryList->currentCategory();
123
    const auto widget = page->createWidget();
124
    widget->setParent(this);
125
    m_extraPages.append(ExtraPage(page, widget));
126
    m_ui->stackedWidget->addWidget(widget);
127
    m_ui->categoryList->addCategory(page->name(), page->icon());
128
    m_ui->categoryList->setCurrentCategory(category);
129
}
130

131
#ifdef WITH_XC_BROWSER_PASSKEYS
132
void ReportsDialog::activatePasskeysPage()
133
{
134
    m_ui->stackedWidget->setCurrentWidget(m_passkeysPage->m_passkeysWidget);
135
    auto index = m_ui->stackedWidget->currentIndex();
136
    m_ui->categoryList->setCurrentCategory(index);
137
}
138
#endif
139

140
void ReportsDialog::reject()
141
{
142
    emit editFinished(true);
143
}
144

145
void ReportsDialog::entryActivationSignalReceived(Entry* entry)
146
{
147
    m_sender = static_cast<QWidget*>(sender());
148
    m_editEntryWidget->loadEntry(entry, false, false, entry->group()->hierarchy().join(" > "), m_db);
149
    m_ui->stackedWidget->setCurrentWidget(m_editEntryWidget);
150
}
151

152
void ReportsDialog::switchToMainView(bool previousDialogAccepted)
153
{
154
    // Sanity check
155
    if (!m_sender) {
156
        return;
157
    }
158

159
    // Return to the previous widget
160
    m_ui->stackedWidget->setCurrentWidget(m_sender);
161

162
    // If "OK" was clicked, and if we came from the Health Check pane,
163
    // re-compute Health Check
164
    if (previousDialogAccepted) {
165
        if (m_sender == m_healthPage->m_healthWidget) {
166
            m_healthPage->m_healthWidget->calculateHealth();
167
        } else if (m_sender == m_hibpPage->m_hibpWidget) {
168
            m_hibpPage->m_hibpWidget->refreshAfterEdit();
169
        }
170
#ifdef WITH_XC_BROWSER
171
        if (m_sender == m_browserStatPage->m_browserWidget) {
172
            m_browserStatPage->m_browserWidget->calculateBrowserStatistics();
173
        }
174
#endif
175
#ifdef WITH_XC_BROWSER_PASSKEYS
176
        if (m_sender == m_passkeysPage->m_passkeysWidget) {
177
            m_passkeysPage->m_passkeysWidget->updateEntries();
178
        }
179
#endif
180
    }
181

182
    // Don't process the same sender twice
183
    m_sender = nullptr;
184
}
185

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

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

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

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