• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkleo

  • sources
  • kde-4.12
  • kdepim
  • libkleo
  • kleo
enum.cpp
Go to the documentation of this file.
1 /*
2  kleo/enum.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of the
10  License, or (at your option) any later version.
11 
12  Libkleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include "enum.h"
34 
35 #include <klocale.h>
36 
37 #include <QString>
38 #include <QStringList>
39 
40 static const struct {
41  Kleo::CryptoMessageFormat format;
42  const char * displayName;
43  const char * configName;
44 } cryptoMessageFormats[] = {
45  { Kleo::InlineOpenPGPFormat,
46  I18N_NOOP("Inline OpenPGP (deprecated)"),
47  "inline openpgp" },
48  { Kleo::OpenPGPMIMEFormat,
49  I18N_NOOP("OpenPGP/MIME"),
50  "openpgp/mime" },
51  { Kleo::SMIMEFormat,
52  I18N_NOOP("S/MIME"),
53  "s/mime" },
54  { Kleo::SMIMEOpaqueFormat,
55  I18N_NOOP("S/MIME Opaque"),
56  "s/mime opaque" },
57 };
58 static const unsigned int numCryptoMessageFormats
59  = sizeof cryptoMessageFormats / sizeof *cryptoMessageFormats ;
60 
61 const char * Kleo::cryptoMessageFormatToString( Kleo::CryptoMessageFormat f ) {
62  if ( f == AutoFormat )
63  return "auto";
64  for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i )
65  if ( f == cryptoMessageFormats[i].format )
66  return cryptoMessageFormats[i].configName;
67  return 0;
68 }
69 
70 QStringList Kleo::cryptoMessageFormatsToStringList( unsigned int f ) {
71  QStringList result;
72  for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i )
73  if ( f & cryptoMessageFormats[i].format )
74  result.push_back( QLatin1String(cryptoMessageFormats[i].configName) );
75  return result;
76 }
77 
78 QString Kleo::cryptoMessageFormatToLabel( Kleo::CryptoMessageFormat f ) {
79  if ( f == AutoFormat )
80  return i18n("Any");
81  for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i )
82  if ( f == cryptoMessageFormats[i].format )
83  return i18n( cryptoMessageFormats[i].displayName );
84  return QString();
85 }
86 
87 Kleo::CryptoMessageFormat Kleo::stringToCryptoMessageFormat( const QString & s ) {
88  const QString t = s.toLower();
89  for ( unsigned int i = 0 ; i < numCryptoMessageFormats ; ++i )
90  if ( t == QLatin1String(cryptoMessageFormats[i].configName) )
91  return cryptoMessageFormats[i].format;
92  return AutoFormat;
93 }
94 
95 unsigned int Kleo::stringListToCryptoMessageFormats( const QStringList & sl ) {
96  unsigned int result = 0;
97  for ( QStringList::const_iterator it = sl.begin() ; it != sl.end() ; ++it )
98  result |= stringToCryptoMessageFormat( *it );
99  return result;
100 }
101 
102 // For the config values used below, see also kaddressbook/editors/cryptowidget.cpp
103 
104 const char* Kleo::encryptionPreferenceToString( EncryptionPreference pref )
105 {
106  switch( pref ) {
107  case UnknownPreference:
108  return 0;
109  case NeverEncrypt:
110  return "never";
111  case AlwaysEncrypt:
112  return "always";
113  case AlwaysEncryptIfPossible:
114  return "alwaysIfPossible";
115  case AlwaysAskForEncryption:
116  return "askAlways";
117  case AskWheneverPossible:
118  return "askWhenPossible";
119  }
120  return 0; // keep the compiler happy
121 }
122 
123 Kleo::EncryptionPreference Kleo::stringToEncryptionPreference( const QString& str )
124 {
125  if ( str == QLatin1String("never") )
126  return NeverEncrypt;
127  if ( str == QLatin1String("always") )
128  return AlwaysEncrypt;
129  if ( str == QLatin1String("alwaysIfPossible") )
130  return AlwaysEncryptIfPossible;
131  if ( str == QLatin1String("askAlways"))
132  return AlwaysAskForEncryption;
133  if ( str == QLatin1String("askWhenPossible") )
134  return AskWheneverPossible;
135  return UnknownPreference;
136 }
137 
138 QString Kleo::encryptionPreferenceToLabel( EncryptionPreference pref )
139 {
140  switch( pref ) {
141  case NeverEncrypt:
142  return i18n( "Never Encrypt" );
143  case AlwaysEncrypt:
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" );
151  default:
152  return i18nc( "no specific preference", "<placeholder>none</placeholder>" );
153  }
154 }
155 
156 const char* Kleo::signingPreferenceToString( SigningPreference pref )
157 {
158  switch( pref ) {
159  case UnknownSigningPreference:
160  return 0;
161  case NeverSign:
162  return "never";
163  case AlwaysSign:
164  return "always";
165  case AlwaysSignIfPossible:
166  return "alwaysIfPossible";
167  case AlwaysAskForSigning:
168  return "askAlways";
169  case AskSigningWheneverPossible:
170  return "askWhenPossible";
171  }
172  return 0; // keep the compiler happy
173 }
174 
175 Kleo::SigningPreference Kleo::stringToSigningPreference( const QString& str )
176 {
177  if ( str == QLatin1String("never") )
178  return NeverSign;
179  if ( str == QLatin1String("always") )
180  return AlwaysSign;
181  if ( str == QLatin1String("alwaysIfPossible") )
182  return AlwaysSignIfPossible;
183  if ( str == QLatin1String("askAlways") )
184  return AlwaysAskForSigning;
185  if ( str == QLatin1String("askWhenPossible") )
186  return AskSigningWheneverPossible;
187  return UnknownSigningPreference;
188 }
189 
190 QString Kleo::signingPreferenceToLabel( SigningPreference pref )
191 {
192  switch( pref ) {
193  case NeverSign:
194  return i18n( "Never Sign" );
195  case AlwaysSign:
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" );
203  default:
204  return i18nc( "no specific preference", "<none>" );
205  }
206 }
Kleo::signingPreferenceToString
KLEO_EXPORT const char * signingPreferenceToString(SigningPreference pref)
Definition: enum.cpp:156
Kleo::cryptoMessageFormatsToStringList
KLEO_EXPORT QStringList cryptoMessageFormatsToStringList(unsigned int f)
Definition: enum.cpp:70
numCryptoMessageFormats
static const unsigned int numCryptoMessageFormats
Definition: enum.cpp:59
Kleo::AlwaysEncrypt
Definition: enum.h:67
cryptoMessageFormats
static const struct @2 cryptoMessageFormats[]
Kleo::AlwaysSignIfPossible
Definition: enum.h:82
Kleo::AskWheneverPossible
Definition: enum.h:70
Kleo::encryptionPreferenceToLabel
KLEO_EXPORT QString encryptionPreferenceToLabel(EncryptionPreference pref)
Definition: enum.cpp:138
Kleo::AlwaysAskForSigning
Definition: enum.h:83
format
Kleo::CryptoMessageFormat format
Definition: enum.cpp:41
Kleo::EncryptionPreference
EncryptionPreference
Definition: enum.h:64
Kleo::signingPreferenceToLabel
KLEO_EXPORT QString signingPreferenceToLabel(SigningPreference pref)
Definition: enum.cpp:190
QString
Kleo::AlwaysEncryptIfPossible
Definition: enum.h:68
Kleo::AlwaysAskForEncryption
Definition: enum.h:69
Kleo::SigningPreference
SigningPreference
Definition: enum.h:78
Kleo::stringListToCryptoMessageFormats
KLEO_EXPORT unsigned int stringListToCryptoMessageFormats(const QStringList &sl)
Definition: enum.cpp:95
Kleo::InlineOpenPGPFormat
Definition: enum.h:44
Kleo::stringToSigningPreference
KLEO_EXPORT SigningPreference stringToSigningPreference(const QString &str)
Definition: enum.cpp:175
enum.h
Kleo::stringToCryptoMessageFormat
KLEO_EXPORT CryptoMessageFormat stringToCryptoMessageFormat(const QString &s)
Definition: enum.cpp:87
Kleo::cryptoMessageFormatToLabel
KLEO_EXPORT QString cryptoMessageFormatToLabel(CryptoMessageFormat f)
Definition: enum.cpp:78
Kleo::OpenPGPMIMEFormat
Definition: enum.h:45
Kleo::encryptionPreferenceToString
KLEO_EXPORT const char * encryptionPreferenceToString(EncryptionPreference pref)
Definition: enum.cpp:104
Kleo::CryptoMessageFormat
CryptoMessageFormat
Definition: enum.h:43
Kleo::NeverSign
Definition: enum.h:80
Kleo::UnknownPreference
Definition: enum.h:65
Kleo::AutoFormat
Definition: enum.h:50
Kleo::SMIMEOpaqueFormat
Definition: enum.h:47
Kleo::NeverEncrypt
Definition: enum.h:66
Kleo::UnknownSigningPreference
Definition: enum.h:79
Kleo::SMIMEFormat
Definition: enum.h:46
Kleo::cryptoMessageFormatToString
KLEO_EXPORT const char * cryptoMessageFormatToString(CryptoMessageFormat f)
Definition: enum.cpp:61
configName
const char * configName
Definition: enum.cpp:43
Kleo::AskSigningWheneverPossible
Definition: enum.h:84
displayName
const char * displayName
Definition: enum.cpp:42
Kleo::stringToEncryptionPreference
KLEO_EXPORT EncryptionPreference stringToEncryptionPreference(const QString &str)
Definition: enum.cpp:123
Kleo::AlwaysSign
Definition: enum.h:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal