10#include <config-libkleo.h>
12#include "kconfigbasedkeyfilter.h"
15#include <KConfigGroup>
18#include <QRegularExpression>
31struct KeyFilter::FontDescription::Private {
32 bool bold, italic, strikeOut, fullFont;
36KeyFilter::FontDescription::FontDescription()
39 d->bold = d->italic = d->strikeOut = d->fullFont =
false;
42KeyFilter::FontDescription::FontDescription(
const FontDescription &other)
43 : d(new Private(*other.d))
47KeyFilter::FontDescription::~FontDescription() =
default;
49KeyFilter::FontDescription KeyFilter::FontDescription::create(
bool b,
bool i,
bool s)
58KeyFilter::FontDescription KeyFilter::FontDescription::create(
const QFont &f,
bool b,
bool i,
bool s)
61 fd.d->fullFont =
true;
69QFont KeyFilter::FontDescription::font(
const QFont &base)
const
90KeyFilter::FontDescription KeyFilter::FontDescription::resolve(
const FontDescription &other)
const
93 fd.d->fullFont = this->d->fullFont || other.d->fullFont;
95 fd.d->font = this->d->fullFont ? this->d->font : other.d->font;
97 fd.d->
bold = this->d->bold || other.d->bold;
98 fd.d->italic = this->d->italic || other.d->italic;
99 fd.d->strikeOut = this->d->strikeOut || other.d->strikeOut;
105 Key::OwnerTrust trust;
106 UserID::Validity validity;
107} ownerTrustAndValidityMap[] = {
109 {
"unknown", Key::Unknown, UserID::Unknown },
110 {
"undefined", Key::Undefined, UserID::Undefined},
111 {
"never", Key::Never, UserID::Never },
112 {
"marginal", Key::Marginal, UserID::Marginal },
113 {
"full", Key::Full, UserID::Full },
114 {
"ultimate", Key::Ultimate, UserID::Ultimate },
118static Key::OwnerTrust map2OwnerTrust(
const QString &s)
120 for (
unsigned int i = 0; i <
sizeof ownerTrustAndValidityMap /
sizeof *ownerTrustAndValidityMap; ++i) {
122 return ownerTrustAndValidityMap[i].trust;
125 return ownerTrustAndValidityMap[0].trust;
128static UserID::Validity map2Validity(
const QString &s)
130 for (
unsigned int i = 0; i <
sizeof ownerTrustAndValidityMap /
sizeof *ownerTrustAndValidityMap; ++i) {
132 return ownerTrustAndValidityMap[i].validity;
135 return ownerTrustAndValidityMap[0].validity;
138KConfigBasedKeyFilter::KConfigBasedKeyFilter(
const KConfigGroup &config)
147 if (config.
hasKey(
"font")) {
148 setUseFullFont(
true);
151 setUseFullFont(
false);
152 setItalic(config.
readEntry(
"font-italic",
false));
153 setBold(config.
readEntry(
"font-bold",
false));
155 setStrikeOut(config.
readEntry(
"font-strikeout",
false));
159#define SET(member, key) \
160 if (config.hasKey(key)) { \
161 set##member(config.readEntry(key, false) ? Set : NotSet); \
162 setSpecificity(specificity() + 1); \
164 SET(Revoked,
"is-revoked");
165 SET(Expired,
"is-expired");
166 SET(Disabled,
"is-disabled");
167 SET(Root,
"is-root-certificate");
168 SET(CanEncrypt,
"can-encrypt");
169 SET(CanSign,
"can-sign");
170 SET(CanCertify,
"can-certify");
171 SET(CanAuthenticate,
"can-authenticate");
172 SET(HasEncrypt,
"has-encrypt");
173 SET(HasSign,
"has-sign");
174 SET(HasCertify,
"has-certify");
175 SET(HasAuthenticate,
"has-authenticate");
176 SET(Qualified,
"is-qualified");
177 SET(CardKey,
"is-cardkey");
178 SET(HasSecret,
"has-secret-key");
179 SET(IsOpenPGP,
"is-openpgp-key");
180 SET(WasValidated,
"was-validated");
181 SET(IsDeVs,
"is-de-vs");
183 static const struct {
189 {
"is-at-least-", IsAtLeast},
190 {
"is-at-most-", IsAtMost},
192 for (
unsigned int i = 0; i <
sizeof prefixMap /
sizeof *prefixMap; ++i) {
195 setOwnerTrust(prefixMap[i].state);
196 setOwnerTrustReferenceLevel(map2OwnerTrust(config.
readEntry(key,
QString())));
197 setSpecificity(specificity() + 1);
201 for (
unsigned int i = 0; i <
sizeof prefixMap /
sizeof *prefixMap; ++i) {
204 setValidity(prefixMap[i].state);
206 setSpecificity(specificity() + 1);
211 if (config.
hasKey(
"specificity")) {
212 setSpecificity(config.
readEntry(
"specificity", 0u));
215 static const struct {
217 MatchContext context;
219 {
"any", AnyMatchContext},
220 {
"appearance", Appearance},
221 {
"filtering", Filtering},
225 setMatchContexts(NoMatchContext);
226 for (
const QString &ctx : contexts) {
228 for (
unsigned int i = 0; i <
sizeof matchMap /
sizeof *matchMap; ++i) {
230 setMatchContexts(availableMatchContexts() |= matchMap[i].context);
234 setMatchContexts(availableMatchContexts() &= matchMap[i].context);
240 qWarning() << QStringLiteral(
"KConfigBasedKeyFilter: found unknown match context '%1' in group '%2'").arg(ctx, config.
name());
243 if (availableMatchContexts() == NoMatchContext) {
244 qWarning() << QStringLiteral(
245 "KConfigBasedKeyFilter: match context in group '%1' evaluates to NoMatchContext, "
246 "replaced by AnyMatchContext")
248 setMatchContexts(AnyMatchContext);
bool hasKey(const char *key) const
QString readEntry(const char *key, const char *aDefault=nullptr) const
Default implementation of key filter class.
int pointSize() const const
void setBold(bool enable)
void setItalic(bool enable)
void setPointSize(int pointSize)
void setStrikeOut(bool enable)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString toLower() const const