37 #include "tdeconfigbasedkeyfilter.h"
39 #include <tdeconfigbase.h>
40 #include <tdelocale.h>
44 GpgME::Key::OwnerTrust trust;
45 GpgME::UserID::Validity validity;
46 } ownerTrustAndValidityMap[] = {
47 {
"unknown", GpgME::Key::Unknown, GpgME::UserID::Unknown },
48 {
"undefined", GpgME::Key::Undefined, GpgME::UserID::Undefined },
49 {
"never", GpgME::Key::Never, GpgME::UserID::Never },
50 {
"marginal", GpgME::Key::Marginal, GpgME::UserID::Marginal },
51 {
"full", GpgME::Key::Full, GpgME::UserID::Full },
52 {
"ultimate", GpgME::Key::Ultimate, GpgME::UserID::Ultimate },
55 static GpgME::Key::OwnerTrust map2OwnerTrust(
const TQString & s ) {
56 for (
unsigned int i = 0 ; i <
sizeof ownerTrustAndValidityMap /
sizeof *ownerTrustAndValidityMap ; ++i )
57 if ( s.lower() == ownerTrustAndValidityMap[i].name )
58 return ownerTrustAndValidityMap[i].trust;
59 return ownerTrustAndValidityMap[0].trust;
62 static GpgME::UserID::Validity map2Validity(
const TQString & s ) {
63 for (
unsigned int i = 0 ; i <
sizeof ownerTrustAndValidityMap /
sizeof *ownerTrustAndValidityMap ; ++i )
64 if ( s.lower() == ownerTrustAndValidityMap[i].name )
65 return ownerTrustAndValidityMap[i].validity;
66 return ownerTrustAndValidityMap[0].validity;
70 Kleo::TDEConfigBasedKeyFilter::TDEConfigBasedKeyFilter(
const TDEConfigBase & config )
76 mUseFullFont( false ),
77 mRevoked( DoesNotMatter ),
78 mExpired( DoesNotMatter ),
79 mDisabled( DoesNotMatter ),
80 mRoot( DoesNotMatter ),
81 mCanEncrypt( DoesNotMatter ),
82 mCanSign( DoesNotMatter ),
83 mCanCertify( DoesNotMatter ),
84 mCanAuthenticate( DoesNotMatter ),
85 mHasSecret( DoesNotMatter ),
86 mIsOpenPGP( DoesNotMatter ),
87 mWasValidated( DoesNotMatter ),
88 mOwnerTrust( LevelDoesNotMatter ),
89 mOwnerTrustReferenceLevel( GpgME::Key::Unknown ),
90 mValidity( LevelDoesNotMatter ),
91 mValidityReferenceLevel( GpgME::UserID::Unknown )
93 mFgColor = config.readColorEntry(
"foreground-color" );
94 mBgColor = config.readColorEntry(
"background-color" );
95 mName = config.readEntry(
"name", i18n(
"<unnamed>") );
96 mIcon = config.readEntry(
"icon" );
97 if ( config.hasKey(
"font" ) ) {
99 mFont = config.readFontEntry(
"font" );
101 mItalic = config.readBoolEntry(
"font-italic",
false );
102 mBold = config.readBoolEntry(
"font-bold",
false );
104 mStrikeOut = config.readBoolEntry(
"font-strikeout",
false );
108 #define SET(member,key) \
109 if ( config.hasKey( key ) ) { \
110 member = config.readBoolEntry( key ) ? Set : NotSet ; \
113 SET( mRevoked,
"is-revoked" );
114 SET( mExpired,
"is-expired" );
115 SET( mDisabled,
"is-disabled" );
116 SET( mRoot,
"is-root-certificate" );
117 SET( mCanEncrypt,
"can-encrypt" );
118 SET( mCanSign,
"can-sign" );
119 SET( mCanCertify,
"can-certify" );
120 SET( mCanAuthenticate,
"can-authenticate" );
121 SET( mHasSecret,
"has-secret-key" );
122 SET( mIsOpenPGP,
"is-openpgp-key" );
123 SET( mWasValidated,
"was-validated" );
125 static const struct {
130 {
"is-not-", IsNot },
131 {
"is-at-least-", IsAtLeast },
132 {
"is-at-most-", IsAtMost },
134 for (
unsigned int i = 0 ; i <
sizeof prefixMap /
sizeof *prefixMap ; ++i ) {
135 const TQString key = TQString( prefixMap[i].prefix ) +
"ownertrust";
136 if ( config.hasKey( key ) ) {
137 mOwnerTrust = prefixMap[i].state;
138 mOwnerTrustReferenceLevel = map2OwnerTrust( config.readEntry( key ) );
143 for (
unsigned int i = 0 ; i <
sizeof prefixMap /
sizeof *prefixMap ; ++i ) {
144 const TQString key = TQString( prefixMap[i].prefix ) +
"validity";
145 if ( config.hasKey( key ) ) {
146 mValidity = prefixMap[i].state;
147 mValidityReferenceLevel = map2Validity( config.readEntry( key ) );
154 Kleo::TDEConfigBasedKeyFilter::~TDEConfigBasedKeyFilter() {
158 bool Kleo::TDEConfigBasedKeyFilter::matches(
const GpgME::Key & key )
const {
162 #define MATCH(member,method) \
163 if ( member != DoesNotMatter && key.method() != bool( member == Set ) ) \
165 #define IS_MATCH(what) MATCH( m##what, is##what )
166 #define CAN_MATCH(what) MATCH( mCan##what, can##what )
169 IS_MATCH( Disabled );
171 CAN_MATCH( Encrypt );
173 CAN_MATCH( Certify );
174 CAN_MATCH( Authenticate );
175 MATCH( mHasSecret, isSecret );
177 if ( mIsOpenPGP != DoesNotMatter &&
178 bool( key.protocol() == GpgME::Context::OpenPGP ) !=
bool( mIsOpenPGP == Set ) )
180 if ( mWasValidated != DoesNotMatter &&
181 bool( key.keyListMode() & GpgME::Context::Validate ) !=
bool( mWasValidated == Set ) )
183 switch ( mOwnerTrust ) {
185 case LevelDoesNotMatter:
188 if ( key.ownerTrust() != mOwnerTrustReferenceLevel )
192 if ( key.ownerTrust() == mOwnerTrustReferenceLevel )
196 if ( (
int)key.ownerTrust() < (
int)mOwnerTrustReferenceLevel )
200 if ( (
int)key.ownerTrust() > (
int)mOwnerTrustReferenceLevel )
204 const GpgME::UserID uid = key.userID(0);
205 switch ( mValidity ) {
207 case LevelDoesNotMatter:
210 if ( uid.validity() != mValidityReferenceLevel )
214 if ( uid.validity() == mValidityReferenceLevel )
218 if ( (
int)uid.validity() < (
int)mValidityReferenceLevel )
222 if ( (
int)uid.validity() > (
int)mValidityReferenceLevel )
229 static inline TQFont resizedFont( TQFont font,
int pointSize,
bool strike ) {
230 font.setPointSize( pointSize );
232 font.setStrikeOut(
true );
236 static inline TQFont adapt( TQFont font,
bool it,
bool b,
bool strike ) {
238 font.setItalic(
true );
240 font.setBold(
true );
242 font.setStrikeOut(
true );
246 TQFont Kleo::TDEConfigBasedKeyFilter::font(
const TQFont & f )
const {
248 return resizedFont( mFont, f.pointSize(), mStrikeOut );
250 return adapt( f, mItalic, mBold, mStrikeOut );