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
80KLEO_EXPORT QString prettyDN(const char *utf8DN);
81
82/* Formats a fingerprint or keyid into groups of four */
83KLEO_EXPORT QString prettyID(const char *id);
84KLEO_EXPORT QString accessibleHexID(const char *id);
85
86/**
87 * Formats a signature from a VerificationResult.
88 *
89 * @param signature The signature to display.
90 * @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
91 * displayed.
92 *
93 * @note The resulting string will contains links to the key in the following format "key:<fingerprint>".
94 */
95KLEO_EXPORT QString prettySignature(const GpgME::Signature &signature, const QString &sender);
96
97// clang-format off
98enum ToolTipOption {
99 KeyID = 0x001,
100 Validity = 0x002,
101 StorageLocation = 0x004,
102 SerialNumber = 0x008,
103 Issuer = 0x010,
104 Subject = 0x020,
105 ExpiryDates = 0x040,
106 CertificateType = 0x080,
107 CertificateUsage = 0x100,
108 Fingerprint = 0x200,
109 UserIDs = 0x400,
110 OwnerTrust = 0x800,
111
112 AllOptions = 0xffff
113};
114// clang-format on
115
116KLEO_EXPORT QString toolTip(const GpgME::Key &key, int opts);
117KLEO_EXPORT QString toolTip(const Kleo::KeyGroup &group, int opts);
118KLEO_EXPORT QString toolTip(const GpgME::UserID &userID, int opts);
119
120/// Returns expiration date of @p key as string, or @p noExpiration if the key doesn't expire.
121KLEO_EXPORT QString expirationDateString(const GpgME::Key &key, const QString &noExpiration = {});
122/// Returns expiration date of @p subkey as string, or @p noExpiration if the subkey doesn't expire.
123KLEO_EXPORT QString expirationDateString(const GpgME::Subkey &subkey, const QString &noExpiration = {});
124/// Returns expiration date of @p sig as string, or @p noExpiration if the signature doesn't expire.
125KLEO_EXPORT QString expirationDateString(const GpgME::UserID::Signature &sig, const QString &noExpiration = {});
126KLEO_EXPORT QDate expirationDate(const GpgME::Key &key);
127KLEO_EXPORT QDate expirationDate(const GpgME::Subkey &subkey);
128KLEO_EXPORT QDate expirationDate(const GpgME::UserID::Signature &sig);
129/**
130 * Returns expiration date of @p key as string suitable for screen readers.
131 * If the key doesn't expire, then it returns @p noExpiration if @p noExpiration is not empty. Otherwise,
132 * returns the localization of "unlimited".
133 */
134KLEO_EXPORT QString accessibleExpirationDate(const GpgME::Key &key, const QString &noExpiration = {});
135/**
136 * Returns expiration date of @p subkey as string suitable for screen readers.
137 * If the subkey doesn't expire, then it returns @p noExpiration if @p noExpiration is not empty. Otherwise,
138 * returns the localization of "unlimited".
139 */
140KLEO_EXPORT QString accessibleExpirationDate(const GpgME::Subkey &subkey, const QString &noExpiration = {});
141/**
142 * Returns expiration date of @p sig as string suitable for screen readers.
143 * If the signature doesn't expire, then it returns @p noExpiration if @p noExpiration is not empty. Otherwise,
144 * returns the localization of "unlimited".
145 */
146KLEO_EXPORT QString accessibleExpirationDate(const GpgME::UserID::Signature &sig, const QString &noExpiration = {});
147
148KLEO_EXPORT QString creationDateString(const GpgME::Key &key);
149KLEO_EXPORT QString creationDateString(const GpgME::Subkey &subkey);
150KLEO_EXPORT QString creationDateString(const GpgME::UserID::Signature &sig);
151KLEO_EXPORT QDate creationDate(const GpgME::Key &key);
152KLEO_EXPORT QDate creationDate(const GpgME::Subkey &subkey);
153KLEO_EXPORT QDate creationDate(const GpgME::UserID::Signature &sig);
154KLEO_EXPORT QString accessibleCreationDate(const GpgME::Key &key);
155KLEO_EXPORT QString accessibleCreationDate(const GpgME::Subkey &subkey);
156
157/* Convert a GPGME style time or a QDate to a localized string */
158KLEO_EXPORT QString dateString(time_t t);
159KLEO_EXPORT QString dateString(const QDate &date);
160KLEO_EXPORT QString accessibleDate(time_t t);
161KLEO_EXPORT QString accessibleDate(const QDate &date);
162
163KLEO_EXPORT QString displayName(GpgME::Protocol prot);
164KLEO_EXPORT QString type(const GpgME::Key &key);
165KLEO_EXPORT QString type(const GpgME::Subkey &subkey);
166KLEO_EXPORT QString type(const Kleo::KeyGroup &group);
167
168KLEO_EXPORT QString ownerTrustShort(const GpgME::Key &key);
169KLEO_EXPORT QString ownerTrustShort(GpgME::Key::OwnerTrust trust);
170
171KLEO_EXPORT QString validityShort(const GpgME::Subkey &subkey);
172KLEO_EXPORT QString validityShort(const GpgME::UserID &uid);
173KLEO_EXPORT QString validityShort(const GpgME::UserID::Signature &sig);
174KLEO_EXPORT QIcon validityIcon(const GpgME::UserID::Signature &sig);
175/* A sentence about the validity of the UserID */
176KLEO_EXPORT QString validity(const GpgME::UserID &uid);
177KLEO_EXPORT QString validity(const Kleo::KeyGroup &group);
178KLEO_EXPORT QIcon validityIcon(const Kleo::KeyGroup &group);
179
180KLEO_EXPORT QString formatForComboBox(const GpgME::Key &key);
181
182KLEO_EXPORT QString formatKeyLink(const GpgME::Key &key);
183
184KLEO_EXPORT QString signatureToString(const GpgME::Signature &sig, const GpgME::Key &key);
185
186KLEO_EXPORT const char *summaryToString(const GpgME::Signature::Summary summary);
187
188KLEO_EXPORT QString importMetaData(const GpgME::Import &import);
189KLEO_EXPORT QString importMetaData(const GpgME::Import &import, const QStringList &sources);
190
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/* A sentence if the key confirms to the current compliance mode */
207KLEO_EXPORT QString complianceStringForKey(const GpgME::Key &key);
208KLEO_EXPORT QString complianceStringForUserID(const GpgME::UserID &userID);
209
210/* A single word for use in keylists to describe the validity of the
211 * given key, including any conformance statements relevant to the
212 * current conformance mode. */
213KLEO_EXPORT QString complianceStringShort(const GpgME::Key &key);
214KLEO_EXPORT QString complianceStringShort(const GpgME::UserID &id);
215KLEO_EXPORT QString complianceStringShort(const Kleo::KeyGroup &group);
216
217/* The origin of the key mapped to a localized string */
218KLEO_EXPORT QString origin(int o);
219
220/* Human-readable trust signature scope (for trust signature regexp created by GnuPG) */
221KLEO_EXPORT QString trustSignatureDomain(const GpgME::UserID::Signature &sig);
222/* Summary of trust signature properties */
223KLEO_EXPORT QString trustSignature(const GpgME::UserID::Signature &sig);
224
225/**
226 * Returns the value of Error::asString() for the error \p error as Unicode string.
227 */
228KLEO_EXPORT QString errorAsString(const GpgME::Error &error);
229
230/**
231 * Returns a name suitable for being displayed for the GPG algorithm name @p algorithm.
232 */
233KLEO_EXPORT QString prettyAlgorithmName(const std::string &algorithm);
234
235/**
236 * Returns the email associated to a UserID.
237 */
238KLEO_EXPORT QString email(const GpgME::UserID &uid);
239}
240}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 4 2025 12:04:00 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.