2
* Copyright (C) 2023 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 "ReportsDialog.h"
19
#include "ui_ReportsDialog.h"
21
#include "ReportsPageHealthcheck.h"
22
#include "ReportsPageHibp.h"
23
#include "ReportsPageStatistics.h"
25
#include "ReportsPageBrowserStatistics.h"
26
#include "ReportsWidgetBrowserStatistics.h"
28
#ifdef WITH_XC_BROWSER_PASSKEYS
29
#include "ReportsPagePasskeys.h"
30
#include "ReportsWidgetPasskeys.h"
32
#include "ReportsWidgetHealthcheck.h"
33
#include "ReportsWidgetHibp.h"
35
#include "core/Global.h"
36
#include "core/Group.h"
38
class ReportsDialog::ExtraPage
41
ExtraPage(QSharedPointer<IReportsPage> p, QWidget* w)
46
void loadSettings(QSharedPointer<Database> db) const
48
page->loadSettings(widget, db);
50
void saveSettings() const
52
page->saveSettings(widget);
56
QSharedPointer<IReportsPage> page;
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())
67
, m_browserStatPage(new ReportsPageBrowserStatistics())
69
#ifdef WITH_XC_BROWSER_PASSKEYS
70
, m_passkeysPage(new ReportsPagePasskeys())
72
, m_editEntryWidget(new EditEntryWidget(this))
76
connect(m_ui->buttonBox, SIGNAL(rejected()), SLOT(reject()));
78
addPage(m_healthPage);
79
#ifdef WITH_XC_BROWSER_PASSKEYS
80
addPage(m_passkeysPage);
83
addPage(m_browserStatPage);
87
m_ui->stackedWidget->setCurrentIndex(0);
89
m_editEntryWidget->setObjectName("editEntryWidget");
90
m_editEntryWidget->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
91
m_ui->stackedWidget->addWidget(m_editEntryWidget);
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*)));
98
connect(m_browserStatPage->m_browserWidget,
99
SIGNAL(entryActivated(Entry*)),
100
SLOT(entryActivationSignalReceived(Entry*)));
102
#ifdef WITH_XC_BROWSER_PASSKEYS
104
m_passkeysPage->m_passkeysWidget, SIGNAL(entryActivated(Entry*)), SLOT(entryActivationSignalReceived(Entry*)));
106
connect(m_editEntryWidget, SIGNAL(editFinished(bool)), SLOT(switchToMainView(bool)));
109
ReportsDialog::~ReportsDialog() = default;
111
void ReportsDialog::load(const QSharedPointer<Database>& db)
113
m_ui->categoryList->setCurrentCategory(0);
114
for (const ExtraPage& page : asConst(m_extraPages)) {
115
page.loadSettings(db);
120
void ReportsDialog::addPage(QSharedPointer<IReportsPage> page)
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);
131
#ifdef WITH_XC_BROWSER_PASSKEYS
132
void ReportsDialog::activatePasskeysPage()
134
m_ui->stackedWidget->setCurrentWidget(m_passkeysPage->m_passkeysWidget);
135
auto index = m_ui->stackedWidget->currentIndex();
136
m_ui->categoryList->setCurrentCategory(index);
140
void ReportsDialog::reject()
142
emit editFinished(true);
145
void ReportsDialog::entryActivationSignalReceived(Entry* entry)
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);
152
void ReportsDialog::switchToMainView(bool previousDialogAccepted)
159
// Return to the previous widget
160
m_ui->stackedWidget->setCurrentWidget(m_sender);
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();
170
#ifdef WITH_XC_BROWSER
171
if (m_sender == m_browserStatPage->m_browserWidget) {
172
m_browserStatPage->m_browserWidget->calculateBrowserStatistics();
175
#ifdef WITH_XC_BROWSER_PASSKEYS
176
if (m_sender == m_passkeysPage->m_passkeysWidget) {
177
m_passkeysPage->m_passkeysWidget->updateEntries();
182
// Don't process the same sender twice