Libkleo

formatting.h
1/* -*- mode: c++; c-basic-offset:4 -*-
2 utils/formatting.h
3
4 This file is part of Kleopatra, the KDE keymanager
5 SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
6 SPDX-FileCopyrightText: 2021, 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#pragma once
13
14#include "keyusage.h"
15
16#include "kleo_export.h"
17
18#include <QStringList>
19
20#include <gpgme++/key.h>
21
22class QString;
23class QDate;
24class QIcon;
25
26namespace GpgME
27{
28class Error;
29class Import;
30}
31
32namespace Kleo
33{
34class KeyGroup;
35
36namespace Formatting
37{
38
39class KLEO_EXPORT IconProvider
40{
41public:
42 inline explicit IconProvider(KeyUsage::Flags requiredUsages)
43 : usage{requiredUsages}
44 {
45 }
46
47 QIcon icon(const GpgME::Key &key) const;
48 QIcon icon(const KeyGroup &group) const;
49 QIcon icon(const GpgME::UserID &userID) const;
50
51private:
52 KeyUsage usage;
53};
54
55KLEO_EXPORT QIcon successIcon();
56KLEO_EXPORT QIcon infoIcon();
57KLEO_EXPORT QIcon questionIcon();
58KLEO_EXPORT QIcon unavailableIcon();
59KLEO_EXPORT QIcon warningIcon();
60KLEO_EXPORT QIcon errorIcon();
61
62KLEO_EXPORT QString prettyNameAndEMail(int proto, const char *id, const char *name, const char *email, const char *comment = nullptr);
63KLEO_EXPORT QString prettyNameAndEMail(int proto, const QString &id, const QString &name, const QString &email, const QString &comment = {});
64KLEO_EXPORT QString prettyNameAndEMail(const GpgME::Key &key);
65KLEO_EXPORT QString prettyNameAndEMail(const GpgME::UserID &key);
66
67KLEO_EXPORT QString prettyUserID(const GpgME::UserID &uid);
68KLEO_EXPORT QString prettyKeyID(const char *id);
69
70KLEO_EXPORT QString prettyName(int proto, const char *id, const char *name, const char *comment = nullptr);
71KLEO_EXPORT QString prettyName(const GpgME::Key &key);
72KLEO_EXPORT QString prettyName(const GpgME::UserID &uid);
73KLEO_EXPORT QString prettyName(const GpgME::UserID::Signature &sig);
74
75KLEO_EXPORT QString prettyEMail(const char *email, const char *id);
76KLEO_EXPORT QString prettyEMail(const GpgME::Key &key);
77KLEO_EXPORT QString prettyEMail(const GpgME::UserID &uid);
78KLEO_EXPORT QString prettyEMail(const GpgME::UserID::Signature &sig);
79
80/* Formats a fingerprint or keyid into groups of four */
81KLEO_EXPORT QString prettyID(const char *id);
82KLEO_EXPORT QString accessibleHexID(const char *id);
83
84/**
85 * Formats a signature from a VerificationResult.
86 *
87 * @param signature The signature to display.
88 * @param sender The sender of the signature, if multiple UserIds are found, this will be the displayed one otherwise the first non empty UserID will be
89 * displayed.
90 *
91 * @note The resulting string will contains links to the key in the following format "key:<fingerprint>".
92 */
93KLEO_EXPORT QString prettySignature(const GpgME::Signature &signature, const QString &sender);
94
95// clang-format off
96enum ToolTipOption {
97 KeyID = 0x001,
98 Validity = 0x002,
99 StorageLocation = 0x004,
100 SerialNumber = 0x008,
101 Issuer = 0x010,
102 Subject = 0x020,
103 ExpiryDates = 0x040,
104 CertificateType = 0x080,
105 CertificateUsage = 0x100,
106 Fingerprint = 0x200,
107 UserIDs = 0x400,
108 OwnerTrust = 0x800,
109 Subkeys = 0x1000,
110
111 AllOptions = 0xffff
112};
113// clang-format on
114
115KLEO_EXPORT QString toolTip(const GpgME::Key &key, int opts);
116KLEO_EXPORT QString toolTip(const Kleo::KeyGroup &group, int opts);
117KLEO_EXPORT QString toolTip(const GpgME::UserID &userID, int opts);
118
119/// Returns expiration date of @p key as string, or @p noExpiration if the key doesn't expire.
120KLEO_EXPORT QString expirationDateString(const GpgME::Key &key, const QString &noExpiration = {});
121/// Returns expiration date of @p subkey as string, or @p noExpiration if the subkey doesn't expire.
122KLEO_EXPORT QString expirationDateString(const GpgME::Subkey &subkey, const QString &noExpiration = {});
123/// Returns expiration date of @p sig as string, or @p noExpiration if the signature doesn't expire.
124KLEO_EXPORT QString expirationDateString(const GpgME::UserID::Signature &sig, const QString &noExpiration = {});
125KLEO_EXPORT QDate expirationDate(const GpgME::Key &key);
126KLEO_EXPORT QDate expirationDate(const GpgME::Subkey &subkey);
127KLEO_EXPORT QDate expirationDate(const GpgME::UserID::Signature &sig);
128/**
129 * Returns expiration date of @p key as string suitable for screen readers.
130 * If the key doesn't expire, then it returns @p noExpiration if @p noExpiration is not empty. Otherwise,
131 * returns the localization of "unlimited".
132 */
133KLEO_EXPORT QString accessibleExpirationDate(const GpgME::Key &key, const QString &noExpiration = {});
134/**
135 * Returns expiration date of @p subkey as string suitable for screen readers.
136 * If the subkey doesn't expire, then it returns @p noExpiration if @p noExpiration is not empty. Otherwise,
137 * returns the localization of "unlimited".
138 */
139KLEO_EXPORT QString accessibleExpirationDate(const GpgME::Subkey &subkey, const QString &noExpiration = {});
140/**
141 * Returns expiration date of @p sig as string suitable for screen readers.
142 * If the signature doesn't expire, then it returns @p noExpiration if @p noExpiration is not empty. Otherwise,
143 * returns the localization of "unlimited".
144 */
145KLEO_EXPORT QString accessibleExpirationDate(const GpgME::UserID::Signature &sig, const QString &noExpiration = {});
146
147KLEO_EXPORT QString creationDateString(const GpgME::Key &key);
148KLEO_EXPORT QString creationDateString(const GpgME::Subkey &subkey);
149KLEO_EXPORT QString creationDateString(const GpgME::UserID::Signature &sig);
150KLEO_EXPORT QDate creationDate(const GpgME::Key &key);
151KLEO_EXPORT QDate creationDate(const GpgME::Subkey &subkey);
152KLEO_EXPORT QDate creationDate(const GpgME::UserID::Signature &sig);
153KLEO_EXPORT QString accessibleCreationDate(const GpgME::Key &key);
154KLEO_EXPORT QString accessibleCreationDate(const GpgME::Subkey &subkey);
155
156/* Convert a GPGME style time or a QDate to a localized string */
157KLEO_EXPORT QString dateString(time_t t);
158KLEO_EXPORT QString dateString(const QDate &date);
159KLEO_EXPORT QString accessibleDate(time_t t);
160KLEO_EXPORT QString accessibleDate(const QDate &date);
161
162KLEO_EXPORT QString displayName(GpgME::Protocol prot);
163KLEO_EXPORT QString type(const GpgME::Key &key);
164KLEO_EXPORT QString type(const GpgME::Subkey &subkey);
165KLEO_EXPORT QString type(const Kleo::KeyGroup &group);
166
167KLEO_EXPORT QString ownerTrustShort(const GpgME::Key &key);
168KLEO_EXPORT QString ownerTrustShort(GpgME::Key::OwnerTrust trust);
169
170KLEO_EXPORT QString validityShort(const GpgME::Subkey &subkey);
171KLEO_EXPORT QString validityShort(const GpgME::UserID &uid);
172KLEO_EXPORT QString validityShort(const GpgME::UserID::Signature &sig);
173KLEO_EXPORT QIcon validityIcon(const GpgME::UserID::Signature &sig);
174/* A sentence about the validity of the UserID */
175KLEO_EXPORT QString validity(const GpgME::UserID &uid);
176KLEO_EXPORT QString validity(const Kleo::KeyGroup &group);
177KLEO_EXPORT QIcon validityIcon(const Kleo::KeyGroup &group);
178
179KLEO_EXPORT QString formatForComboBox(const GpgME::Key &key);
180
181KLEO_EXPORT QString formatKeyLink(const GpgME::Key &key);
182
183KLEO_EXPORT QString signatureToString(const GpgME::Signature &sig, const GpgME::Key &key);
184
185KLEO_EXPORT const char *summaryToString(const GpgME::Signature::Summary summary);
186
187KLEO_EXPORT QString importMetaData(const GpgME::Import &import);
188KLEO_EXPORT QString importMetaData(const GpgME::Import &import, const QStringList &sources);
189
190KLEO_EXPORT QString formatOverview(const GpgME::Key &key);
191KLEO_EXPORT QString usageString(const GpgME::Subkey &subkey);
192KLEO_EXPORT QString summaryLine(const GpgME::UserID &id);
193KLEO_EXPORT QString summaryLine(const GpgME::Key &key);
194KLEO_EXPORT QString summaryLine(const KeyGroup &group);
195KLEO_EXPORT QString nameAndEmailForSummaryLine(const GpgME::Key &key);
196KLEO_EXPORT QString nameAndEmailForSummaryLine(const GpgME::UserID &id);
197
198KLEO_EXPORT QIcon iconForUid(const GpgME::UserID &uid);
199
200/* The compliance mode of the gnupg system. Empty if compliance
201 * mode is not set.
202 * Use Kleo::gnupgComplianceMode() instead.
203 */
204KLEO_DEPRECATED_EXPORT QString complianceMode();
205
206/**
207 * Use Kleo::DeVSCompliance::name(bool) instead.
208 */
209KLEO_DEPRECATED_EXPORT QString deVsString(bool compliant = true);
210
211/* A sentence if the key confirms to the current compliance mode */
212KLEO_EXPORT QString complianceStringForKey(const GpgME::Key &key);
213KLEO_EXPORT QString complianceStringForUserID(const GpgME::UserID &userID);
214
215/* A single word for use in keylists to describe the validity of the
216 * given key, including any conformance statements relevant to the
217 * current conformance mode. */
218KLEO_EXPORT QString complianceStringShort(const GpgME::Key &key);
219KLEO_EXPORT QString complianceStringShort(const GpgME::UserID &id);
220KLEO_EXPORT QString complianceStringShort(const Kleo::KeyGroup &group);
221
222/* The origin of the key mapped to a localized string */
223KLEO_EXPORT QString origin(int o);
224
225/* Human-readable trust signature scope (for trust signature regexp created by GnuPG) */
226KLEO_EXPORT QString trustSignatureDomain(const GpgME::UserID::Signature &sig);
227/* Summary of trust signature properties */
228KLEO_EXPORT QString trustSignature(const GpgME::UserID::Signature &sig);
229
230/**
231 * Returns the value of Error::asString() for the error \p error as Unicode string.
232 */
233KLEO_EXPORT QString errorAsString(const GpgME::Error &error);
234
235/**
236 * Returns a name suitable for being displayed for the GPG algorithm name @p algorithm.
237 */
238KLEO_EXPORT QString prettyAlgorithmName(const std::string &algorithm);
239
240/**
241 * Returns the email associated to a UserID.
242 */
243KLEO_EXPORT QString email(const GpgME::UserID &uid);
244}
245}
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:00:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.