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// clang-format off
85enum ToolTipOption {
86 KeyID = 0x001,
87 Validity = 0x002,
88 StorageLocation = 0x004,
89 SerialNumber = 0x008,
90 Issuer = 0x010,
91 Subject = 0x020,
92 ExpiryDates = 0x040,
93 CertificateType = 0x080,
94 CertificateUsage = 0x100,
95 Fingerprint = 0x200,
96 UserIDs = 0x400,
97 OwnerTrust = 0x800,
98 Subkeys = 0x1000,
99
100 AllOptions = 0xffff
101};
102// clang-format on
103
104KLEO_EXPORT QString toolTip(const GpgME::Key &key, int opts);
105KLEO_EXPORT QString toolTip(const Kleo::KeyGroup &group, int opts);
106KLEO_EXPORT QString toolTip(const GpgME::UserID &userID, int opts);
107
108/// Returns expiration date of @p key as string, or @p noExpiration if the key doesn't expire.
109KLEO_EXPORT QString expirationDateString(const GpgME::Key &key, const QString &noExpiration = {});
110/// Returns expiration date of @p subkey as string, or @p noExpiration if the subkey doesn't expire.
111KLEO_EXPORT QString expirationDateString(const GpgME::Subkey &subkey, const QString &noExpiration = {});
112/// Returns expiration date of @p sig as string, or @p noExpiration if the signature doesn't expire.
113KLEO_EXPORT QString expirationDateString(const GpgME::UserID::Signature &sig, const QString &noExpiration = {});
114KLEO_EXPORT QDate expirationDate(const GpgME::Key &key);
115KLEO_EXPORT QDate expirationDate(const GpgME::Subkey &subkey);
116KLEO_EXPORT QDate expirationDate(const GpgME::UserID::Signature &sig);
117/**
118 * Returns expiration date of @p key as string suitable for screen readers.
119 * If the key doesn't expire, then it returns @p noExpiration if @p noExpiration is not empty. Otherwise,
120 * returns the localization of "unlimited".
121 */
122KLEO_EXPORT QString accessibleExpirationDate(const GpgME::Key &key, const QString &noExpiration = {});
123/**
124 * Returns expiration date of @p subkey as string suitable for screen readers.
125 * If the subkey doesn't expire, then it returns @p noExpiration if @p noExpiration is not empty. Otherwise,
126 * returns the localization of "unlimited".
127 */
128KLEO_EXPORT QString accessibleExpirationDate(const GpgME::Subkey &subkey, const QString &noExpiration = {});
129/**
130 * Returns expiration date of @p sig as string suitable for screen readers.
131 * If the signature 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::UserID::Signature &sig, const QString &noExpiration = {});
135
136KLEO_EXPORT QString creationDateString(const GpgME::Key &key);
137KLEO_EXPORT QString creationDateString(const GpgME::Subkey &subkey);
138KLEO_EXPORT QString creationDateString(const GpgME::UserID::Signature &sig);
139KLEO_EXPORT QDate creationDate(const GpgME::Key &key);
140KLEO_EXPORT QDate creationDate(const GpgME::Subkey &subkey);
141KLEO_EXPORT QDate creationDate(const GpgME::UserID::Signature &sig);
142KLEO_EXPORT QString accessibleCreationDate(const GpgME::Key &key);
143KLEO_EXPORT QString accessibleCreationDate(const GpgME::Subkey &subkey);
144
145/* Convert a GPGME style time or a QDate to a localized string */
146KLEO_EXPORT QString dateString(time_t t);
147KLEO_EXPORT QString dateString(const QDate &date);
148KLEO_EXPORT QString accessibleDate(time_t t);
149KLEO_EXPORT QString accessibleDate(const QDate &date);
150
151KLEO_EXPORT QString displayName(GpgME::Protocol prot);
152KLEO_EXPORT QString type(const GpgME::Key &key);
153KLEO_EXPORT QString type(const GpgME::Subkey &subkey);
154KLEO_EXPORT QString type(const Kleo::KeyGroup &group);
155
156KLEO_EXPORT QString ownerTrustShort(const GpgME::Key &key);
157KLEO_EXPORT QString ownerTrustShort(GpgME::Key::OwnerTrust trust);
158
159KLEO_EXPORT QString validityShort(const GpgME::Subkey &subkey);
160KLEO_EXPORT QString validityShort(const GpgME::UserID &uid);
161KLEO_EXPORT QString validityShort(const GpgME::UserID::Signature &sig);
162KLEO_EXPORT QIcon validityIcon(const GpgME::UserID::Signature &sig);
163/* A sentence about the validity of the UserID */
164KLEO_EXPORT QString validity(const GpgME::UserID &uid);
165KLEO_EXPORT QString validity(const Kleo::KeyGroup &group);
166KLEO_EXPORT QIcon validityIcon(const Kleo::KeyGroup &group);
167
168KLEO_EXPORT QString formatForComboBox(const GpgME::Key &key);
169
170KLEO_EXPORT QString formatKeyLink(const GpgME::Key &key);
171
172KLEO_EXPORT QString signatureToString(const GpgME::Signature &sig, const GpgME::Key &key);
173
174KLEO_EXPORT const char *summaryToString(const GpgME::Signature::Summary summary);
175
176KLEO_EXPORT QString importMetaData(const GpgME::Import &import);
177KLEO_EXPORT QString importMetaData(const GpgME::Import &import, const QStringList &sources);
178
179KLEO_EXPORT QString formatOverview(const GpgME::Key &key);
180KLEO_EXPORT QString usageString(const GpgME::Subkey &subkey);
181KLEO_EXPORT QString summaryLine(const GpgME::UserID &id);
182KLEO_EXPORT QString summaryLine(const GpgME::Key &key);
183KLEO_EXPORT QString summaryLine(const KeyGroup &group);
184KLEO_EXPORT QString nameAndEmailForSummaryLine(const GpgME::Key &key);
185KLEO_EXPORT QString nameAndEmailForSummaryLine(const GpgME::UserID &id);
186
187KLEO_EXPORT QIcon iconForUid(const GpgME::UserID &uid);
188
189/* Is the key valid i.e. are all uids fully trusted? */
190KLEO_EXPORT bool uidsHaveFullValidity(const GpgME::Key &key);
191
192/* The compliance mode of the gnupg system. Empty if compliance
193 * mode is not set.
194 * Use Kleo::gnupgComplianceMode() instead.
195 */
196KLEO_DEPRECATED_EXPORT QString complianceMode();
197
198/* Is the given key in compliance with CO_DE_VS? */
199KLEO_EXPORT bool isKeyDeVs(const GpgME::Key &key);
200
201/**
202 * Use Kleo::DeVSCompliance::name(bool) instead.
203 */
204KLEO_DEPRECATED_EXPORT QString deVsString(bool compliant = true);
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}
Type type(const QSqlDatabase &db)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:12 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.