Libkleo

auditlogentry.cpp
1/* -*- mode: c++; c-basic-offset:4 -*-
2 kleo/auditlogentry.cpp
3
4 This file is part of libkleopatra, the KDE keymanagement library
5 SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
6 SPDX-FileCopyrightText: 2022 g10 Code GmbH
7 SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10*/
11
12#include <config-libkleo.h>
13
14#include "auditlogentry.h"
15
16#include <libkleo/formatting.h>
17#include <libkleo_debug.h>
18
19#include <QGpgME/Job>
20
21#include <QUrl>
22#include <QUrlQuery>
23
24#include <gpgme++/error.h>
25
26using namespace Kleo;
27
28class AuditLogEntry::Private
29{
30public:
31 QString text;
32 GpgME::Error error;
33};
34
35AuditLogEntry::AuditLogEntry()
36 : AuditLogEntry{QString{}, GpgME::Error{}}
37{
38}
39
40AuditLogEntry::AuditLogEntry(const GpgME::Error &error)
41 : AuditLogEntry{QString{}, error}
42{
43}
44
45AuditLogEntry::AuditLogEntry(const QString &text, const GpgME::Error &error)
46 : d{new Private{text, error}}
47{
48}
49
50AuditLogEntry::~AuditLogEntry() = default;
51
52AuditLogEntry::AuditLogEntry(const AuditLogEntry &other)
53 : d{new Private{*other.d}}
54{
55}
56
57AuditLogEntry &AuditLogEntry::operator=(const AuditLogEntry &other)
58{
59 *d = *other.d;
60 return *this;
61}
62
63AuditLogEntry::AuditLogEntry(AuditLogEntry &&other) = default;
64AuditLogEntry &AuditLogEntry::operator=(AuditLogEntry &&other) = default;
65
66AuditLogEntry AuditLogEntry::fromJob(const QGpgME::Job *job)
67{
68 if (job) {
69 return AuditLogEntry{job->auditLogAsHtml(), job->auditLogError()};
70 } else {
71 return AuditLogEntry{};
72 }
73}
74
75GpgME::Error AuditLogEntry::error() const
76{
77 return d->error;
78}
79
80QString AuditLogEntry::text() const
81{
82 return d->text;
83}
84
85QUrl AuditLogEntry::asUrl(const QUrl &urlTemplate) const
86{
87 // more or less the same as
88 // kmail/objecttreeparser.cpp:makeShowAuditLogLink(), so any bug
89 // fixed here equally applies there:
90 if (const int code = d->error.code()) {
91 if (code == GPG_ERR_NOT_IMPLEMENTED) {
92 qCDebug(LIBKLEO_LOG) << "not showing link (not implemented)";
93 } else if (code == GPG_ERR_NO_DATA) {
94 qCDebug(LIBKLEO_LOG) << "not showing link (not available)";
95 } else {
96 qCDebug(LIBKLEO_LOG) << "Error Retrieving Audit Log:" << Formatting::errorAsString(d->error);
97 }
98 return {};
99 }
100
101 if (d->text.isEmpty()) {
102 return {};
103 }
104
105 QUrl url = urlTemplate;
106 QUrlQuery urlQuery{url};
107 urlQuery.addQueryItem(QStringLiteral("log"), d->text);
108 url.setQuery(urlQuery);
109 return url;
110}
111
112QDebug operator<<(QDebug debug, const AuditLogEntry &auditLog)
113{
114 const bool oldSetting = debug.autoInsertSpaces();
115 debug.nospace() << "AuditLogEntry(" << Formatting::errorAsString(auditLog.error()) << ", " << auditLog.text() << ')';
116 debug.setAutoInsertSpaces(oldSetting);
117 return debug.maybeSpace();
118}
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
QDebug operator<<(QDebug dbg, const PerceptualColor::LchaDouble &value)
bool autoInsertSpaces() const const
QDebug & maybeSpace()
QDebug & nospace()
void setAutoInsertSpaces(bool b)
void setQuery(const QString &query, ParsingMode mode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:11 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.