Libkleo

messagebox.cpp
1/*
2 messagebox.cpp
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include <config-libkleo.h>
11
12#include "messagebox.h"
13
14#include "auditlogviewer.h"
15
16#include <kleo/auditlogentry.h>
17
18#include <kleo_ui_debug.h>
19
20#include <KGuiItem>
21#include <KLocalizedString>
22#include <KSharedConfig>
23
24#include <QGpgME/Job>
25
26#include <QDialog>
27#include <QDialogButtonBox>
28#include <QPushButton>
29
30#include <gpgme++/encryptionresult.h>
31#include <gpgme++/signingresult.h>
32
33#include <gpg-error.h>
34
35using namespace Kleo;
36using namespace GpgME;
37using namespace QGpgME;
38
39namespace
40{
41bool showAuditLogButton(const AuditLogEntry &auditLog)
42{
43 if (auditLog.error().code() == GPG_ERR_NOT_IMPLEMENTED) {
44 qCDebug(KLEO_UI_LOG) << "not showing audit log button (not supported)";
45 return false;
46 }
47 if (auditLog.error().code() == GPG_ERR_NO_DATA) {
48 qCDebug(KLEO_UI_LOG) << "not showing audit log button (GPG_ERR_NO_DATA)";
49 return false;
50 }
51 if (!auditLog.error() && auditLog.text().isEmpty()) {
52 qCDebug(KLEO_UI_LOG) << "not showing audit log button (success, but result empty)";
53 return false;
54 }
55 return true;
56}
57
58void showMessageBox(QWidget *parent,
60 const QString &text,
61 const AuditLogEntry &auditLog,
62 const QString &title,
63 KMessageBox::Options options)
64{
65 if (showAuditLogButton(auditLog)) {
66 QDialog *dialog = new QDialog{parent};
67 dialog->setWindowTitle(title);
69 KGuiItem::assign(box->button(QDialogButtonBox::Yes), KGuiItem{i18nc("@action:button", "Show Audit Log")});
71
72 if (options & KMessageBox::WindowModal) {
74 }
75 dialog->setModal(true);
76
77 // Flag as Dangerous to make the Ok button the default button
78 const auto choice = KMessageBox::createKMessageBox(dialog, box, icon, text, QStringList{}, QString{}, nullptr, options | KMessageBox::Dangerous);
79 if (choice == QDialogButtonBox::Yes) {
80 AuditLogViewer::showAuditLog(parent, auditLog);
81 }
82 } else {
83 const auto dialogType = (icon == QMessageBox::Information) ? KMessageBox::Information : KMessageBox::Error;
84 KMessageBox::messageBox(parent, dialogType, text, title, {}, {}, {}, QString{}, options);
85 }
86}
87}
88
89void MessageBox::information(QWidget *parent, const QString &text, const Kleo::AuditLogEntry &auditLog, const QString &title, KMessageBox::Options options)
90{
91 showMessageBox(parent, QMessageBox::Information, text, auditLog, title.isEmpty() ? i18nc("@title:window", "Information") : title, options);
92}
93
94void MessageBox::error(QWidget *parent, const QString &text, const Kleo::AuditLogEntry &auditLog, const QString &title, KMessageBox::Options options)
95{
96 showMessageBox(parent, QMessageBox::Critical, text, auditLog, title.isEmpty() ? i18nc("@title:window", "Error") : title, options);
97}
98
99void MessageBox::auditLog(QWidget *parent, const QString &log, const QString &title)
100{
101 AuditLogViewer::showAuditLog(parent, AuditLogEntry{log, Error{}}, title);
102}
static void assign(QPushButton *button, const KGuiItem &item)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QDialogButtonBox::StandardButton createKMessageBox(QDialog *dialog, QDialogButtonBox *buttons, const QIcon &icon, const QString &text, const QStringList &strlist, const QString &ask, bool *checkboxReturn, Options options, const QString &details=QString(), QMessageBox::Icon notifyType=QMessageBox::Information)
ButtonCode messageBox(QWidget *parent, DialogType type, const QString &text, const QString &title, const KGuiItem &primaryAction, const KGuiItem &secondaryAction, const KGuiItem &cancelAction=KStandardGuiItem::cancel(), const QString &dontShowAskAgainName=QString(), Options options=Notify)
void setModal(bool modal)
QPushButton * button(StandardButton which) const const
bool isEmpty() const const
WindowModal
void setWindowModality(Qt::WindowModality windowModality)
void setWindowTitle(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.