diff --git a/src/ui/messagebox.cpp b/src/ui/messagebox.cpp index 1f1d79995..d6f7f201d 100644 --- a/src/ui/messagebox.cpp +++ b/src/ui/messagebox.cpp @@ -1,84 +1,94 @@ /* messagebox.cpp This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2004 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "messagebox.h" #include "auditlogviewer.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace GpgME; using namespace QGpgME; namespace { bool showAuditLogButton(const AuditLogEntry &auditLog) { if (auditLog.error().code() == GPG_ERR_NOT_IMPLEMENTED) { qCDebug(KLEO_UI_LOG) << "not showing audit log button (not supported)"; return false; } if (auditLog.error().code() == GPG_ERR_NO_DATA) { qCDebug(KLEO_UI_LOG) << "not showing audit log button (GPG_ERR_NO_DATA)"; return false; } if (!auditLog.error() && auditLog.text().isEmpty()) { qCDebug(KLEO_UI_LOG) << "not showing audit log button (success, but result empty)"; return false; } return true; } void showMessageBox(QWidget *parent, QMessageBox::Icon icon, const QString &text, const AuditLogEntry &auditLog, const QString &caption, KMessageBox::Options options) { QDialog *dialog = new QDialog(parent); dialog->setWindowTitle(caption); QDialogButtonBox *box = new QDialogButtonBox(showAuditLogButton(auditLog) ? (QDialogButtonBox::Yes | QDialogButtonBox::No) : QDialogButtonBox::Yes, parent); QPushButton *yesButton = box->button(QDialogButtonBox::Yes); yesButton->setDefault(true); dialog->setObjectName(QStringLiteral("error")); dialog->setModal(true); KGuiItem::assign(yesButton, KStandardGuiItem::ok()); KGuiItem::assign(box->button(QDialogButtonBox::No), KGuiItem(i18n("&Show Audit Log"))); if (QDialogButtonBox::No == KMessageBox::createKMessageBox(dialog, box, icon, text, QStringList(), QString(), nullptr, options)) { AuditLogViewer::showAuditLog(parent, auditLog); } } } +void MessageBox::information(QWidget *parent, const QString &text, const Kleo::AuditLogEntry &auditLog, const QString &title, KMessageBox::Options options) +{ + showMessageBox(parent, QMessageBox::Information, text, auditLog, title.isEmpty() ? i18nc("@title:window", "Information") : title, options); +} + +void MessageBox::error(QWidget *parent, const QString &text, const Kleo::AuditLogEntry &auditLog, const QString &title, KMessageBox::Options options) +{ + showMessageBox(parent, QMessageBox::Critical, text, auditLog, title.isEmpty() ? i18nc("@title:window", "Error") : title, options); +} + void MessageBox::auditLog(QWidget *parent, const QString &log, const QString &title) { AuditLogViewer::showAuditLog(parent, AuditLogEntry{log, Error{}}, title); } diff --git a/src/ui/messagebox.h b/src/ui/messagebox.h index 5cbf7a789..1f09f7595 100644 --- a/src/ui/messagebox.h +++ b/src/ui/messagebox.h @@ -1,42 +1,58 @@ /* messagebox.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include "kleo_export.h" #include #undef MessageBox // Windows +class QString; +class QWidget; + namespace GpgME { class SigningResult; class EncryptionResult; } namespace QGpgME { class Job; } -class QWidget; -class QString; - namespace Kleo { +class AuditLogEntry; + namespace MessageBox { +KLEO_EXPORT +void information(QWidget *parent, + const QString &text, + const Kleo::AuditLogEntry &auditLog, + const QString &title = {}, + KMessageBox::Options options = KMessageBox::Notify); + +KLEO_EXPORT +void error(QWidget *parent, + const QString &text, + const Kleo::AuditLogEntry &auditLog, + const QString &title = {}, + KMessageBox::Options options = KMessageBox::Notify); + KLEO_EXPORT KLEO_DEPRECATED_VERSION(5, 23, "Use AuditLogViewer::showAuditLog()") void auditLog(QWidget *parent, const QString &log, const QString &title = {}); } }