diff --git a/src/kleo/auditlogentry.cpp b/src/kleo/auditlogentry.cpp index 9ad1d86cc..5eaf7f68a 100644 --- a/src/kleo/auditlogentry.cpp +++ b/src/kleo/auditlogentry.cpp @@ -1,109 +1,117 @@ /* -*- mode: c++; c-basic-offset:4 -*- kleo/auditlogentry.cpp This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "auditlogentry.h" #include #include #include #include #include using namespace Kleo; class AuditLogEntry::Private { public: QString text; GpgME::Error error; }; AuditLogEntry::AuditLogEntry() : AuditLogEntry{QString{}, GpgME::Error{}} { } AuditLogEntry::AuditLogEntry(const GpgME::Error &error) : AuditLogEntry{QString{}, error} { } AuditLogEntry::AuditLogEntry(const QString &text, const GpgME::Error &error) : d{new Private{text, error}} { } AuditLogEntry::~AuditLogEntry() = default; AuditLogEntry::AuditLogEntry(const AuditLogEntry &other) : d{new Private{*other.d}} { } AuditLogEntry &AuditLogEntry::operator=(const AuditLogEntry &other) { *d = *other.d; return *this; } AuditLogEntry::AuditLogEntry(AuditLogEntry &&other) = default; AuditLogEntry &AuditLogEntry::operator=(AuditLogEntry &&other) = default; AuditLogEntry AuditLogEntry::fromJob(const QGpgME::Job *job) { if (job) { return AuditLogEntry{job->auditLogAsHtml(), job->auditLogError()}; } else { return AuditLogEntry{}; } } GpgME::Error AuditLogEntry::error() const { return d->error; } QString AuditLogEntry::text() const { return d->text; } QUrl AuditLogEntry::asUrl(const QUrl &urlTemplate) const { // more or less the same as // kmail/objecttreeparser.cpp:makeShowAuditLogLink(), so any bug // fixed here equally applies there: if (const int code = d->error.code()) { if (code == GPG_ERR_NOT_IMPLEMENTED) { qCDebug(LIBKLEO_LOG) << "not showing link (not implemented)"; } else if (code == GPG_ERR_NO_DATA) { qCDebug(LIBKLEO_LOG) << "not showing link (not available)"; } else { qCDebug(LIBKLEO_LOG) << "Error Retrieving Audit Log:" << QString::fromLocal8Bit(d->error.asString()); } return {}; } if (d->text.isEmpty()) { return {}; } QUrl url = urlTemplate; QUrlQuery urlQuery{url}; urlQuery.addQueryItem(QStringLiteral("log"), d->text); url.setQuery(urlQuery); return url; } + +QDebug operator<<(QDebug debug, const AuditLogEntry &auditLog) +{ + const bool oldSetting = debug.autoInsertSpaces(); + debug.nospace() << "AuditLogEntry(" << auditLog.error().asString() << ", " << auditLog.text() << ')'; + debug.setAutoInsertSpaces(oldSetting); + return debug.maybeSpace(); +} diff --git a/src/kleo/auditlogentry.h b/src/kleo/auditlogentry.h index 3a8df3bfe..830e3cb6b 100644 --- a/src/kleo/auditlogentry.h +++ b/src/kleo/auditlogentry.h @@ -1,60 +1,62 @@ /* -*- mode: c++; c-basic-offset:4 -*- kleo/auditlogentry.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include "kleo_export.h" #include class QDebug; class QString; class QUrl; namespace GpgME { class Error; } namespace QGpgME { class Job; } namespace Kleo { class KLEO_EXPORT AuditLogEntry { public: AuditLogEntry(); explicit AuditLogEntry(const GpgME::Error &error); AuditLogEntry(const QString &text, const GpgME::Error &error); ~AuditLogEntry(); AuditLogEntry(const AuditLogEntry &other); AuditLogEntry &operator=(const AuditLogEntry &other); AuditLogEntry(AuditLogEntry &&other); AuditLogEntry &operator=(AuditLogEntry &&other); static AuditLogEntry fromJob(const QGpgME::Job *); GpgME::Error error() const; QString text() const; QUrl asUrl(const QUrl &urlTemplate) const; private: class Private; std::unique_ptr d; }; } + +KLEO_EXPORT QDebug operator<<(QDebug debug, const Kleo::AuditLogEntry &auditLog);