certmanager/lib Library API Documentation

enum.cpp

00001 /* 00002 kleo/enum.cpp 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2004 Klarälvdalens Datakonsult AB 00006 00007 Libkleopatra is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License as 00009 published by the Free Software Foundation; either version 2 of the 00010 License, or (at your option) any later version. 00011 00012 Libkleopatra is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the Qt library by Trolltech AS, Norway (or with modified versions 00024 of Qt that use the same license as Qt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 Qt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 00031 */ 00032 00033 #include "enum.h" 00034 00035 #include <klocale.h> 00036 00037 #include <qstring.h> 00038 #include <qstringlist.h> 00039 00040 static const struct { 00041 Kleo::CryptoMessageFormat format; 00042 const char * displayName; 00043 const char * configName; 00044 } cryptoMessageFormats[] = { 00045 { Kleo::InlineOpenPGPFormat, 00046 I18N_NOOP("Inline OpenPGP (deprecated)"), 00047 "inline openpgp" }, 00048 { Kleo::OpenPGPMIMEFormat, 00049 I18N_NOOP("OpenPGP/MIME"), 00050 "openpgp/mime" }, 00051 { Kleo::SMIMEFormat, 00052 I18N_NOOP("S/MIME"), 00053 "s/mime" }, 00054 { Kleo::SMIMEOpaqueFormat, 00055 I18N_NOOP("S/MIME opaque"), 00056 "s/mime opaque" }, 00057 }; 00058 static const unsigned int numCryptoMessageFormats 00059 = sizeof cryptoMessageFormats / sizeof *cryptoMessageFormats ; 00060 00061 const char * Kleo::cryptoMessageFormatToString( Kleo::CryptoMessageFormat f ) { 00062 if ( f == AutoFormat ) 00063 return "auto"; 00064 for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i ) 00065 if ( f == cryptoMessageFormats[i].format ) 00066 return cryptoMessageFormats[i].configName; 00067 return 0; 00068 } 00069 00070 QStringList Kleo::cryptoMessageFormatsToStringList( unsigned int f ) { 00071 QStringList result; 00072 for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i ) 00073 if ( f & cryptoMessageFormats[i].format ) 00074 result.push_back( cryptoMessageFormats[i].configName ); 00075 return result; 00076 } 00077 00078 QString Kleo::cryptoMessageFormatToLabel( Kleo::CryptoMessageFormat f ) { 00079 if ( f == AutoFormat ) 00080 return i18n("Any"); 00081 for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i ) 00082 if ( f == cryptoMessageFormats[i].format ) 00083 return i18n( cryptoMessageFormats[i].displayName ); 00084 return QString::null; 00085 } 00086 00087 Kleo::CryptoMessageFormat Kleo::stringToCryptoMessageFormat( const QString & s ) { 00088 const QString t = s.lower(); 00089 for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i ) 00090 if ( t == cryptoMessageFormats[i].configName ) 00091 return cryptoMessageFormats[i].format; 00092 return AutoFormat; 00093 } 00094 00095 unsigned int Kleo::stringListToCryptoMessageFormats( const QStringList & sl ) { 00096 unsigned int result = 0; 00097 for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it ) 00098 result |= stringToCryptoMessageFormat( *it ); 00099 return result; 00100 } 00101 00102 // For the config values used below, see also kaddressbook/editors/cryptowidget.cpp 00103 00104 const char* Kleo::encryptionPreferenceToString( EncryptionPreference pref ) 00105 { 00106 switch( pref ) { 00107 case UnknownPreference: 00108 return 0; 00109 case NeverEncrypt: 00110 return "never"; 00111 case AlwaysEncrypt: 00112 return "always"; 00113 case AlwaysEncryptIfPossible: 00114 return "alwaysIfPossible"; 00115 case AlwaysAskForEncryption: 00116 return "askAlways"; 00117 case AskWheneverPossible: 00118 return "askWhenPossible"; 00119 } 00120 return 0; // keep the compiler happy 00121 } 00122 00123 Kleo::EncryptionPreference Kleo::stringToEncryptionPreference( const QString& str ) 00124 { 00125 if ( str == "never" ) 00126 return NeverEncrypt; 00127 if ( str == "always" ) 00128 return AlwaysEncrypt; 00129 if ( str == "alwaysIfPossible" ) 00130 return AlwaysEncryptIfPossible; 00131 if ( str == "askAlways" ) 00132 return AlwaysAskForEncryption; 00133 if ( str == "askWhenPossible" ) 00134 return AskWheneverPossible; 00135 return UnknownPreference; 00136 } 00137 00138 QString Kleo::encryptionPreferenceToLabel( EncryptionPreference pref ) 00139 { 00140 switch( pref ) { 00141 case NeverEncrypt: 00142 return i18n( "Never Encrypt" ); 00143 case AlwaysEncrypt: 00144 return i18n( "Always Encrypt" ); 00145 case AlwaysEncryptIfPossible: 00146 return i18n( "Always Encrypt If Possible" ); 00147 case AlwaysAskForEncryption: 00148 return i18n( "Ask" ); 00149 case AskWheneverPossible: 00150 return i18n( "Ask Whenever Possible" ); 00151 default: 00152 return i18n( "no specific preference", "<none>" ); 00153 } 00154 } 00155 00156 const char* Kleo::signingPreferenceToString( SigningPreference pref ) 00157 { 00158 switch( pref ) { 00159 case UnknownSigningPreference: 00160 return 0; 00161 case NeverSign: 00162 return "never"; 00163 case AlwaysSign: 00164 return "always"; 00165 case AlwaysSignIfPossible: 00166 return "alwaysIfPossible"; 00167 case AlwaysAskForSigning: 00168 return "askAlways"; 00169 case AskSigningWheneverPossible: 00170 return "askWhenPossible"; 00171 } 00172 return 0; // keep the compiler happy 00173 } 00174 00175 Kleo::SigningPreference Kleo::stringToSigningPreference( const QString& str ) 00176 { 00177 if ( str == "never" ) 00178 return NeverSign; 00179 if ( str == "always" ) 00180 return AlwaysSign; 00181 if ( str == "alwaysIfPossible" ) 00182 return AlwaysSignIfPossible; 00183 if ( str == "askAlways" ) 00184 return AlwaysAskForSigning; 00185 if ( str == "askWhenPossible" ) 00186 return AskSigningWheneverPossible; 00187 return UnknownSigningPreference; 00188 } 00189 00190 QString Kleo::signingPreferenceToLabel( SigningPreference pref ) 00191 { 00192 switch( pref ) { 00193 case NeverSign: 00194 return i18n( "Never Sign" ); 00195 case AlwaysSign: 00196 return i18n( "Always Sign" ); 00197 case AlwaysSignIfPossible: 00198 return i18n( "Always Sign If Possible" ); 00199 case AlwaysAskForSigning: 00200 return i18n( "Ask" ); 00201 case AskSigningWheneverPossible: 00202 return i18n( "Ask Whenever Possible" ); 00203 default: 00204 return i18n( "no specific preference", "<none>" ); 00205 } 00206 }
KDE Logo
This file is part of the documentation for certmanager/lib Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:04 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003