35 #include <tdelocale.h>
38 #include <tqstringlist.h>
41 Kleo::CryptoMessageFormat format;
42 const char * displayName;
43 const char * configName;
44 } cryptoMessageFormats[] = {
45 { Kleo::InlineOpenPGPFormat,
46 I18N_NOOP(
"Inline OpenPGP (deprecated)"),
48 { Kleo::OpenPGPMIMEFormat,
49 I18N_NOOP(
"OpenPGP/MIME"),
54 { Kleo::SMIMEOpaqueFormat,
55 I18N_NOOP(
"S/MIME Opaque"),
58 static const unsigned int numCryptoMessageFormats
59 =
sizeof cryptoMessageFormats /
sizeof *cryptoMessageFormats ;
61 const char * Kleo::cryptoMessageFormatToString( Kleo::CryptoMessageFormat f ) {
62 if ( f == AutoFormat )
64 for (
unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i )
65 if ( f == cryptoMessageFormats[i].format )
66 return cryptoMessageFormats[i].configName;
70 TQStringList Kleo::cryptoMessageFormatsToStringList(
unsigned int f ) {
72 for (
unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i )
73 if ( f & cryptoMessageFormats[i].format )
74 result.push_back( cryptoMessageFormats[i].configName );
78 TQString Kleo::cryptoMessageFormatToLabel( Kleo::CryptoMessageFormat f ) {
79 if ( f == AutoFormat )
81 for (
unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i )
82 if ( f == cryptoMessageFormats[i].format )
83 return i18n( cryptoMessageFormats[i].displayName );
87 Kleo::CryptoMessageFormat Kleo::stringToCryptoMessageFormat(
const TQString & s ) {
88 const TQString t = s.lower();
89 for (
unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i )
90 if ( t == cryptoMessageFormats[i].configName )
91 return cryptoMessageFormats[i].format;
95 unsigned int Kleo::stringListToCryptoMessageFormats(
const TQStringList & sl ) {
96 unsigned int result = 0;
97 for ( TQStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
98 result |= stringToCryptoMessageFormat( *it );
104 const char* Kleo::encryptionPreferenceToString( EncryptionPreference pref )
107 case UnknownPreference:
113 case AlwaysEncryptIfPossible:
114 return "alwaysIfPossible";
115 case AlwaysAskForEncryption:
117 case AskWheneverPossible:
118 return "askWhenPossible";
123 Kleo::EncryptionPreference Kleo::stringToEncryptionPreference(
const TQString& str )
125 if ( str ==
"never" )
127 if ( str ==
"always" )
128 return AlwaysEncrypt;
129 if ( str ==
"alwaysIfPossible" )
130 return AlwaysEncryptIfPossible;
131 if ( str ==
"askAlways" )
132 return AlwaysAskForEncryption;
133 if ( str ==
"askWhenPossible" )
134 return AskWheneverPossible;
135 return UnknownPreference;
138 TQString Kleo::encryptionPreferenceToLabel( EncryptionPreference pref )
142 return i18n(
"Never Encrypt" );
144 return i18n(
"Always Encrypt" );
145 case AlwaysEncryptIfPossible:
146 return i18n(
"Always Encrypt If Possible" );
147 case AlwaysAskForEncryption:
148 return i18n(
"Ask" );
149 case AskWheneverPossible:
150 return i18n(
"Ask Whenever Possible" );
152 return i18n(
"no specific preference",
"<none>" );
156 const char* Kleo::signingPreferenceToString( SigningPreference pref )
159 case UnknownSigningPreference:
165 case AlwaysSignIfPossible:
166 return "alwaysIfPossible";
167 case AlwaysAskForSigning:
169 case AskSigningWheneverPossible:
170 return "askWhenPossible";
175 Kleo::SigningPreference Kleo::stringToSigningPreference(
const TQString& str )
177 if ( str ==
"never" )
179 if ( str ==
"always" )
181 if ( str ==
"alwaysIfPossible" )
182 return AlwaysSignIfPossible;
183 if ( str ==
"askAlways" )
184 return AlwaysAskForSigning;
185 if ( str ==
"askWhenPossible" )
186 return AskSigningWheneverPossible;
187 return UnknownSigningPreference;
190 TQString Kleo::signingPreferenceToLabel( SigningPreference pref )
194 return i18n(
"Never Sign" );
196 return i18n(
"Always Sign" );
197 case AlwaysSignIfPossible:
198 return i18n(
"Always Sign If Possible" );
199 case AlwaysAskForSigning:
200 return i18n(
"Ask" );
201 case AskSigningWheneverPossible:
202 return i18n(
"Ask Whenever Possible" );
204 return i18n(
"no specific preference",
"<none>" );