diff --git a/src/ui/messagebox.cpp b/src/ui/messagebox.cpp index 4d28db4f6..305fe8bd7 100644 --- a/src/ui/messagebox.cpp +++ b/src/ui/messagebox.cpp @@ -1,218 +1,105 @@ /* 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::auditLog(QWidget *parent, const Job *job, const QString &caption) { if (!job) { return; } AuditLogViewer::showAuditLog(parent, AuditLogEntry::fromJob(job), caption); } void MessageBox::auditLog(QWidget *parent, const QString &log, const QString &caption) { AuditLogViewer::showAuditLog(parent, AuditLogEntry{log, Error{}}, caption); } void MessageBox::auditLog(QWidget *parent, const Job *job) { if (!job) { return; } AuditLogViewer::showAuditLog(parent, AuditLogEntry::fromJob(job)); } void MessageBox::auditLog(QWidget *parent, const QString &log) { AuditLogViewer::showAuditLog(parent, AuditLogEntry{log, Error{}}); } - -static QString to_information_string(const SigningResult &result) -{ - return (result.error() // - ? i18n("Signing failed: %1", QString::fromLocal8Bit(result.error().asString())) - : i18n("Signing successful")); -} - -static QString to_error_string(const SigningResult &result) -{ - return to_information_string(result); -} - -static QString to_information_string(const EncryptionResult &result) -{ - return (result.error() // - ? i18n("Encryption failed: %1", QString::fromLocal8Bit(result.error().asString())) - : i18n("Encryption successful")); -} - -static QString to_error_string(const EncryptionResult &result) -{ - return to_information_string(result); -} - -static QString to_information_string(const SigningResult &sresult, const EncryptionResult &eresult) -{ - return to_information_string(sresult) + QLatin1Char('\n') + to_information_string(eresult); -} - -static QString to_error_string(const SigningResult &sresult, const EncryptionResult &eresult) -{ - return to_information_string(sresult, eresult); -} - -void MessageBox::information(QWidget *parent, const SigningResult &result, const Job *job, KMessageBox::Options options) -{ - information(parent, result, job, i18n("Signing Result"), options); -} - -void MessageBox::information(QWidget *parent, const SigningResult &result, const Job *job, const QString &caption, KMessageBox::Options options) -{ - showMessageBox(parent, QMessageBox::Information, to_information_string(result), AuditLogEntry::fromJob(job), caption, options); -} - -void MessageBox::error(QWidget *parent, const SigningResult &result, const Job *job, KMessageBox::Options options) -{ - error(parent, result, job, i18n("Signing Error"), options); -} - -void MessageBox::error(QWidget *parent, const SigningResult &result, const Job *job, const QString &caption, KMessageBox::Options options) -{ - showMessageBox(parent, QMessageBox::Critical, to_error_string(result), AuditLogEntry::fromJob(job), caption, options); -} - -void MessageBox::information(QWidget *parent, const EncryptionResult &result, const Job *job, KMessageBox::Options options) -{ - information(parent, result, job, i18n("Encryption Result"), options); -} - -void MessageBox::information(QWidget *parent, const EncryptionResult &result, const Job *job, const QString &caption, KMessageBox::Options options) -{ - showMessageBox(parent, QMessageBox::Information, to_information_string(result), AuditLogEntry::fromJob(job), caption, options); -} - -void MessageBox::error(QWidget *parent, const EncryptionResult &result, const Job *job, KMessageBox::Options options) -{ - error(parent, result, job, i18n("Encryption Error"), options); -} - -void MessageBox::error(QWidget *parent, const EncryptionResult &result, const Job *job, const QString &caption, KMessageBox::Options options) -{ - showMessageBox(parent, QMessageBox::Critical, to_error_string(result), AuditLogEntry::fromJob(job), caption, options); -} - -void MessageBox::information(QWidget *parent, const SigningResult &sresult, const EncryptionResult &eresult, const Job *job, KMessageBox::Options options) -{ - information(parent, sresult, eresult, job, i18n("Encryption Result"), options); -} - -void MessageBox::information(QWidget *parent, - const SigningResult &sresult, - const EncryptionResult &eresult, - const Job *job, - const QString &caption, - KMessageBox::Options options) -{ - showMessageBox(parent, QMessageBox::Information, to_information_string(sresult, eresult), AuditLogEntry::fromJob(job), caption, options); -} - -void MessageBox::error(QWidget *parent, const SigningResult &sresult, const EncryptionResult &eresult, const Job *job, KMessageBox::Options options) -{ - error(parent, sresult, eresult, job, i18n("Encryption Error"), options); -} - -void MessageBox::error(QWidget *parent, - const SigningResult &sresult, - const EncryptionResult &eresult, - const Job *job, - const QString &caption, - KMessageBox::Options options) -{ - showMessageBox(parent, QMessageBox::Critical, to_error_string(sresult, eresult), AuditLogEntry::fromJob(job), caption, options); -} - -bool MessageBox::showAuditLogButton(const QGpgME::Job *job) -{ - if (!job) { - qCDebug(KLEO_UI_LOG) << "not showing audit log button (no job instance)"; - return false; - } - return ::showAuditLogButton(AuditLogEntry::fromJob(job)); -} diff --git a/src/ui/messagebox.h b/src/ui/messagebox.h index 17aaf06d6..70fb6e094 100644 --- a/src/ui/messagebox.h +++ b/src/ui/messagebox.h @@ -1,126 +1,57 @@ /* 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 namespace GpgME { class SigningResult; class EncryptionResult; } namespace QGpgME { class Job; } class QWidget; class QString; namespace Kleo { namespace MessageBox { -KLEO_EXPORT -void information(QWidget *parent, - const GpgME::SigningResult &result, - const QGpgME::Job *job, - const QString &caption, - KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void information(QWidget *parent, const GpgME::SigningResult &result, const QGpgME::Job *job, KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void error(QWidget *parent, - const GpgME::SigningResult &result, - const QGpgME::Job *job, - const QString &caption, - KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void error(QWidget *parent, const GpgME::SigningResult &result, const QGpgME::Job *job, KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void information(QWidget *parent, - const GpgME::EncryptionResult &result, - const QGpgME::Job *job, - const QString &caption, - KMessageBox::Options options = KMessageBox::Notify); -KLEO_EXPORT -void information(QWidget *parent, const GpgME::EncryptionResult &result, const QGpgME::Job *job, KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void error(QWidget *parent, - const GpgME::EncryptionResult &result, - const QGpgME::Job *job, - const QString &caption, - KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void error(QWidget *parent, const GpgME::EncryptionResult &result, const QGpgME::Job *job, KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void information(QWidget *parent, - const GpgME::SigningResult &sresult, - const GpgME::EncryptionResult &eresult, - const QGpgME::Job *job, - const QString &caption, - KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void information(QWidget *parent, - const GpgME::SigningResult &sresult, - const GpgME::EncryptionResult &eresult, - const QGpgME::Job *job, - KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void error(QWidget *parent, - const GpgME::SigningResult &sresult, - const GpgME::EncryptionResult &eresult, - const QGpgME::Job *job, - const QString &caption, - KMessageBox::Options options = KMessageBox::Notify); - -KLEO_EXPORT -void error(QWidget *parent, - const GpgME::SigningResult &sresult, - const GpgME::EncryptionResult &eresult, - const QGpgME::Job *job, - KMessageBox::Options options = KMessageBox::Notify); - KLEO_EXPORT KLEO_DEPRECATED_VERSION(5, 23, "Use AuditLogViewer::showAuditLog()") void auditLog(QWidget *parent, const QGpgME::Job *job, const QString &caption); KLEO_EXPORT KLEO_DEPRECATED_VERSION(5, 23, "Use AuditLogViewer::showAuditLog()") void auditLog(QWidget *parent, const QGpgME::Job *job); KLEO_EXPORT KLEO_DEPRECATED_VERSION(5, 23, "Use AuditLogViewer::showAuditLog()") void auditLog(QWidget *parent, const QString &log, const QString &caption); KLEO_EXPORT KLEO_DEPRECATED_VERSION(5, 23, "Use AuditLogViewer::showAuditLog()") void auditLog(QWidget *parent, const QString &log); KLEO_EXPORT bool showAuditLogButton(const QGpgME::Job *job); } }