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 
26 using namespace Kleo;
27 
28 class AuditLogEntry::Private
29 {
30 public:
31  QString text;
32  GpgME::Error error;
33 };
34 
35 AuditLogEntry::AuditLogEntry()
36  : AuditLogEntry{QString{}, GpgME::Error{}}
37 {
38 }
39 
40 AuditLogEntry::AuditLogEntry(const GpgME::Error &error)
41  : AuditLogEntry{QString{}, error}
42 {
43 }
44 
45 AuditLogEntry::AuditLogEntry(const QString &text, const GpgME::Error &error)
46  : d{new Private{text, error}}
47 {
48 }
49 
50 AuditLogEntry::~AuditLogEntry() = default;
51 
52 AuditLogEntry::AuditLogEntry(const AuditLogEntry &other)
53  : d{new Private{*other.d}}
54 {
55 }
56 
57 AuditLogEntry &AuditLogEntry::operator=(const AuditLogEntry &other)
58 {
59  *d = *other.d;
60  return *this;
61 }
62 
63 AuditLogEntry::AuditLogEntry(AuditLogEntry &&other) = default;
64 AuditLogEntry &AuditLogEntry::operator=(AuditLogEntry &&other) = default;
65 
66 AuditLogEntry 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 
75 GpgME::Error AuditLogEntry::error() const
76 {
77  return d->error;
78 }
79 
80 QString AuditLogEntry::text() const
81 {
82  return d->text;
83 }
84 
85 QUrl 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 
112 QDebug 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 }
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
void setAutoInsertSpaces(bool b)
QDebug & nospace()
bool autoInsertSpaces() const const
QDebug & maybeSpace()
void addQueryItem(const QString &key, const QString &value)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
void setQuery(const QString &query, QUrl::ParsingMode mode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:56:13 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.