• 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
  • backends
  • qgpgme
qgpgmenewcryptoconfig.cpp
Go to the documentation of this file.
1 /*
2  qgpgmenewcryptoconfig.cpp
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2010 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 "qgpgmenewcryptoconfig.h"
34 
35 #include <KLocalizedString>
36 #include <KMessageBox>
37 #include <KDebug>
38 
39 #include <QFile>
40 
41 #include <gpgme++/global.h>
42 #include <gpgme++/error.h>
43 
44 #include <boost/foreach.hpp>
45 #include <boost/bind.hpp>
46 #include <boost/mem_fn.hpp>
47 
48 #include <sstream>
49 #include <string>
50 #include <cassert>
51 
52 using namespace boost;
53 using namespace Kleo;
54 using namespace GpgME;
55 using namespace GpgME::Configuration;
56 
57 namespace {
58  struct Select1St {
59  template <typename U, typename V>
60  const U & operator()( const std::pair<U,V> & p ) const { return p.first; }
61  template <typename U, typename V>
62  const U & operator()( const QPair<U,V> & p ) const { return p.first; }
63  };
64 }
65 
66 // Just for the Q_ASSERT in the dtor. Not thread-safe, but who would
67 // have 2 threads talking to gpgconf anyway? :)
68 static bool s_duringClear = false;
69 
70 QGpgMENewCryptoConfig::QGpgMENewCryptoConfig()
71  : m_parsed( false )
72 {
73 }
74 
75 QGpgMENewCryptoConfig::~QGpgMENewCryptoConfig()
76 {
77  clear();
78 }
79 
80 void QGpgMENewCryptoConfig::reloadConfiguration( bool showErrors )
81 {
82  clear();
83 
84  Error error;
85  const std::vector<Component> components = Component::load( error );
86 #ifndef NDEBUG
87  {
88  std::stringstream ss;
89  ss << "error: " << error
90  << "components:\n";
91  std::copy( components.begin(), components.end(),
92  std::ostream_iterator<Component>( ss, "\n" ) );
93  kDebug(5150) << ss.str().c_str();
94  }
95 #endif
96  if ( error && showErrors ) {
97  const QString wmsg = i18n("<qt>Failed to execute gpgconf:<p>%1</p></qt>", QString::fromLocal8Bit( error.asString() ) );
98  kWarning(5150) << wmsg; // to see it from test_cryptoconfig.cpp
99  KMessageBox::error(0, wmsg);
100  }
101  BOOST_FOREACH( const Component & c, components ) {
102  const shared_ptr<QGpgMENewCryptoConfigComponent> comp( new QGpgMENewCryptoConfigComponent );
103  comp->setComponent( c );
104  m_componentsByName[ comp->name() ] = comp;
105  }
106  m_parsed = true;
107 }
108 
109 QStringList QGpgMENewCryptoConfig::componentList() const
110 {
111  if ( !m_parsed )
112  const_cast<QGpgMENewCryptoConfig*>( this )->reloadConfiguration( true );
113  QStringList result;
114  std::transform( m_componentsByName.begin(), m_componentsByName.end(),
115  std::back_inserter( result ),
116  mem_fn( &QGpgMENewCryptoConfigComponent::name ) );
117  return result;
118 }
119 
120 QGpgMENewCryptoConfigComponent * QGpgMENewCryptoConfig::component( const QString & name ) const
121 {
122  if ( !m_parsed )
123  const_cast<QGpgMENewCryptoConfig*>( this )->reloadConfiguration( false );
124  return m_componentsByName.value( name ).get();
125 }
126 
127 void QGpgMENewCryptoConfig::sync( bool runtime )
128 {
129  BOOST_FOREACH( const shared_ptr<QGpgMENewCryptoConfigComponent> & c, m_componentsByName )
130  c->sync( runtime );
131 }
132 
133 void QGpgMENewCryptoConfig::clear()
134 {
135  s_duringClear = true;
136  m_componentsByName.clear();
137  s_duringClear = false;
138  m_parsed = false; // next call to componentList/component will need to run gpgconf again
139 }
140 
142 
143 QGpgMENewCryptoConfigComponent::QGpgMENewCryptoConfigComponent()
144  : CryptoConfigComponent(),
145  m_component()
146 {
147 
148 }
149 
150 void QGpgMENewCryptoConfigComponent::setComponent( const Component & component )
151 {
152  m_component = component;
153  m_groupsByName.clear();
154 
155  shared_ptr<QGpgMENewCryptoConfigGroup> group;
156 
157  const std::vector<Option> options = m_component.options();
158  BOOST_FOREACH( const Option & o, options )
159  if ( o.flags() & Group ) {
160  if ( group )
161  m_groupsByName[group->name()] = group;
162  group.reset( new QGpgMENewCryptoConfigGroup( shared_from_this(), o ) );
163  } else if ( group ) {
164  const shared_ptr<QGpgMENewCryptoConfigEntry> entry( new QGpgMENewCryptoConfigEntry( group, o ) );
165  const QString name = entry->name();
166  group->m_entryNames.push_back( name );
167  group->m_entriesByName[name] = entry;
168  } else {
169  kWarning(5150) << "found no group for entry" << o.name() << "of component" << name() ;
170  }
171  if ( group )
172  m_groupsByName[group->name()] = group;
173 
174 }
175 
176 QGpgMENewCryptoConfigComponent::~QGpgMENewCryptoConfigComponent() {}
177 
178 QString QGpgMENewCryptoConfigComponent::name() const
179 {
180  return QString::fromUtf8( m_component.name() );
181 }
182 
183 QString QGpgMENewCryptoConfigComponent::description() const
184 {
185  return QString::fromUtf8( m_component.description() );
186 }
187 
188 QStringList QGpgMENewCryptoConfigComponent::groupList() const
189 {
190  QStringList result;
191  result.reserve( m_groupsByName.size() );
192  std::transform( m_groupsByName.begin(), m_groupsByName.end(),
193  std::back_inserter( result ),
194  mem_fn( &QGpgMENewCryptoConfigGroup::name ) );
195  return result;
196 }
197 
198 QGpgMENewCryptoConfigGroup* QGpgMENewCryptoConfigComponent::group(const QString& name ) const
199 {
200  return m_groupsByName.value( name ).get();
201 }
202 
203 void QGpgMENewCryptoConfigComponent::sync( bool runtime )
204 {
205  Q_UNUSED( runtime )
206  // ### how to pass --runtime to gpgconf? -> marcus: not yet supported (2010-11-20)
207  if ( const Error err = m_component.save() ) {
208  const QString wmsg = i18n( "Error from gpgconf while saving configuration: %1", QString::fromLocal8Bit( err.asString() ) );
209  kWarning(5150) <<":" << wmsg;
210  KMessageBox::error(0, wmsg);
211  }
212  // ### unset dirty state again
213 }
214 
216 
217 QGpgMENewCryptoConfigGroup::QGpgMENewCryptoConfigGroup( const shared_ptr<QGpgMENewCryptoConfigComponent> & comp, const Option & option )
218  : CryptoConfigGroup(),
219  m_component( comp ),
220  m_option( option )
221 {
222 }
223 
224 QGpgMENewCryptoConfigGroup::~QGpgMENewCryptoConfigGroup() {}
225 
226 QString QGpgMENewCryptoConfigGroup::name() const
227 {
228  return QString::fromUtf8( m_option.name() );
229 }
230 
231 QString QGpgMENewCryptoConfigGroup::description() const
232 {
233  return QString::fromUtf8( m_option.description() );
234 }
235 
236 QString QGpgMENewCryptoConfigGroup::path() const
237 {
238  if ( const shared_ptr<QGpgMENewCryptoConfigComponent> c = m_component.lock() )
239  return c->name() + QLatin1Char( '/' ) + name() ;
240  else
241  return QString();
242 }
243 
244 CryptoConfigEntry::Level QGpgMENewCryptoConfigGroup::level() const
245 {
246  // two casts to make SunCC happy:
247  return static_cast<CryptoConfigEntry::Level>( static_cast<unsigned int>( m_option.level() ) );
248 }
249 
250 QStringList QGpgMENewCryptoConfigGroup::entryList() const
251 {
252  return m_entryNames;
253 }
254 
255 QGpgMENewCryptoConfigEntry* QGpgMENewCryptoConfigGroup::entry( const QString& name ) const
256 {
257  return m_entriesByName.value( name ).get();
258 }
259 
260 
261 #if 0
262 
264 static QString gpgconf_unescape( const QString& str )
265 {
266  // Looks like it's the same rules as KUrl.
267  return KUrl::fromPercentEncoding( str.toLatin1() );
268 }
269 
270 static QString gpgconf_escape( const QString& str )
271 {
272  // Escape special chars (including ':' and '%')
273  QString enc = KUrl::toPercentEncoding( str ); // and convert to utf8 first (to get %12%34 for one special char)
274  // Also encode commas, for lists.
275  enc.replace( ',', "%2c" );
276  return enc;
277 }
278 #endif
279 
280 static QString urlpart_encode( const QString& str )
281 {
282  QString enc( str );
283  enc.replace( QLatin1Char('%'), QLatin1String("%25") ); // first!
284  enc.replace( QLatin1Char(':'), QLatin1String("%3a") );
285  //kDebug(5150) <<" urlpart_encode:" << str <<" ->" << enc;
286  return enc;
287 }
288 
289 static QString urlpart_decode( const QString& str )
290 {
291  return KUrl::fromPercentEncoding( str.toLatin1() );
292 }
293 
294 // gpgconf arg type number -> NewCryptoConfigEntry arg type enum mapping
295 static Kleo::CryptoConfigEntry::ArgType knownArgType( int argType, bool& ok ) {
296  ok = true;
297  switch( argType ) {
298  case 0: // none
299  return Kleo::CryptoConfigEntry::ArgType_None;
300  case 1: // string
301  return Kleo::CryptoConfigEntry::ArgType_String;
302  case 2: // int32
303  return Kleo::CryptoConfigEntry::ArgType_Int;
304  case 3: // uint32
305  return Kleo::CryptoConfigEntry::ArgType_UInt;
306  case 32: // pathname
307  return Kleo::CryptoConfigEntry::ArgType_Path;
308  case 33: // ldap server
309  return Kleo::CryptoConfigEntry::ArgType_LDAPURL;
310  default:
311  ok = false;
312  return Kleo::CryptoConfigEntry::ArgType_None;
313  }
314 }
315 
316 QGpgMENewCryptoConfigEntry::QGpgMENewCryptoConfigEntry( const shared_ptr<QGpgMENewCryptoConfigGroup> & group, const Option & option )
317  : m_group( group ), m_option( option )
318 {
319 }
320 
321 #if 0
322 QVariant QGpgMENewCryptoConfigEntry::stringToValue( const QString& str, bool unescape ) const
323 {
324  const bool isString = isStringType();
325 
326  if ( isList() ) {
327  if ( argType() == ArgType_None ) {
328  bool ok = true;
329  const QVariant v = str.isEmpty() ? 0U : str.toUInt( &ok ) ;
330  if ( !ok )
331  kWarning(5150) << "list-of-none should have an unsigned int as value:" << str;
332  return v;
333  }
334  QList<QVariant> lst;
335  QStringList items = str.split( ',', QString::SkipEmptyParts );
336  for( QStringList::const_iterator valit = items.constBegin(); valit != items.constEnd(); ++valit ) {
337  QString val = *valit;
338  if ( isString ) {
339  if ( val.isEmpty() ) {
340  lst << QVariant( QString() );
341  continue;
342  }
343  else if ( unescape ) {
344  if( val[0] != '"' ) // see README.gpgconf
345  kWarning(5150) <<"String value should start with '\"' :" << val;
346  val = val.mid( 1 );
347  }
348  }
349  lst << QVariant( unescape ? gpgconf_unescape( val ) : val );
350  }
351  return lst;
352  } else { // not a list
353  QString val( str );
354  if ( isString ) {
355  if ( val.isEmpty() )
356  return QVariant( QString() ); // not set [ok with lists too?]
357  else if ( unescape ) {
358  if( val[0] != '"' ) // see README.gpgconf
359  kWarning(5150) <<"String value should start with '\"' :" << val;
360  val = val.mid( 1 );
361  }
362  }
363  return QVariant( unescape ? gpgconf_unescape( val ) : val );
364  }
365 }
366 #endif
367 
368 QGpgMENewCryptoConfigEntry::~QGpgMENewCryptoConfigEntry()
369 {
370 #ifndef NDEBUG
371  if ( !s_duringClear && m_option.dirty() )
372  kWarning(5150) <<"Deleting a QGpgMENewCryptoConfigEntry that was modified (" << m_option.description() <<")"
373  << "You forgot to call sync() (to commit) or clear() (to discard)";
374 #endif
375 }
376 
377 QString QGpgMENewCryptoConfigEntry::name() const
378 {
379  return QString::fromUtf8( m_option.name() );
380 }
381 
382 QString QGpgMENewCryptoConfigEntry::description() const
383 {
384  return QString::fromUtf8( m_option.description() );
385 }
386 
387 QString QGpgMENewCryptoConfigEntry::path() const
388 {
389  if ( const shared_ptr<QGpgMENewCryptoConfigGroup> g = m_group.lock() )
390  return g->path() + QLatin1Char( '/' ) + name() ;
391  else
392  return QString();
393 }
394 
395 bool QGpgMENewCryptoConfigEntry::isOptional() const
396 {
397  return m_option.flags() & Optional ;
398 }
399 
400 bool QGpgMENewCryptoConfigEntry::isReadOnly() const
401 {
402  return m_option.flags() & NoChange ;
403 }
404 
405 bool QGpgMENewCryptoConfigEntry::isList() const
406 {
407  return m_option.flags() & List ;
408 }
409 
410 bool QGpgMENewCryptoConfigEntry::isRuntime() const
411 {
412  return m_option.flags() & Runtime ;
413 }
414 
415 CryptoConfigEntry::Level QGpgMENewCryptoConfigEntry::level() const
416 {
417  // two casts to make SunCC happy:
418  return static_cast<Level>( static_cast<unsigned int>( m_option.level() ) );
419 }
420 
421 CryptoConfigEntry::ArgType QGpgMENewCryptoConfigEntry::argType() const
422 {
423  bool ok = false;
424  const ArgType type = knownArgType( m_option.type(), ok );
425  if ( ok )
426  return type;
427  else
428  return knownArgType( m_option.alternateType(), ok );
429 }
430 
431 bool QGpgMENewCryptoConfigEntry::isSet() const
432 {
433  return m_option.set();
434 }
435 
436 bool QGpgMENewCryptoConfigEntry::boolValue() const
437 {
438  Q_ASSERT( m_option.alternateType() == NoType );
439  Q_ASSERT( !isList() );
440  return m_option.currentValue().boolValue();
441 }
442 
443 QString QGpgMENewCryptoConfigEntry::stringValue() const
444 {
445  //return toString( false );
446  Q_ASSERT( m_option.alternateType() == StringType );
447  Q_ASSERT( !isList() );
448  return QString::fromUtf8( m_option.currentValue().stringValue() );
449 }
450 
451 int QGpgMENewCryptoConfigEntry::intValue() const
452 {
453  Q_ASSERT( m_option.alternateType() == IntegerType );
454  Q_ASSERT( !isList() );
455  return m_option.currentValue().intValue();
456 }
457 
458 unsigned int QGpgMENewCryptoConfigEntry::uintValue() const
459 {
460  Q_ASSERT( m_option.alternateType() == UnsignedIntegerType );
461  Q_ASSERT( !isList() );
462  return m_option.currentValue().uintValue();
463 }
464 
465 static KUrl parseURL( int mRealArgType, const QString& str )
466 {
467  if ( mRealArgType == 33 ) { // LDAP server
468  // The format is HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN
469  QStringList items = str.split( QLatin1Char(':') );
470  if ( items.count() == 5 ) {
471  QStringList::const_iterator it = items.constBegin();
472  KUrl url;
473  url.setProtocol( QLatin1String("ldap") );
474  url.setHost( urlpart_decode( *it++ ) );
475 
476  bool ok;
477  const int port = (*it++).toInt( &ok );
478  if ( ok )
479  url.setPort( port );
480  else if ( !it->isEmpty() )
481  kWarning(5150) <<"parseURL: malformed LDAP server port, ignoring: \"" << *it << "\"";
482 
483  url.setPath( QLatin1String("/") ); // workaround KUrl parsing bug
484  url.setUserName( urlpart_decode( *it++ ) );
485  url.setPassword( urlpart_decode( *it++ ) );
486  url.setQuery( urlpart_decode( *it ) );
487  return url;
488  } else
489  kWarning(5150) <<"parseURL: malformed LDAP server:" << str;
490  }
491  // other URLs : assume wellformed URL syntax.
492  return KUrl( str );
493 }
494 
495 // The opposite of parseURL
496 static QString splitURL( int mRealArgType, const KUrl& url )
497 {
498  if ( mRealArgType == 33 ) { // LDAP server
499  // The format is HOSTNAME:PORT:USERNAME:PASSWORD:BASE_DN
500  Q_ASSERT( url.protocol() == QLatin1String("ldap") );
501  return urlpart_encode( url.host() ) + QLatin1Char(':') +
502  ( url.port() != -1 ? QString::number( url.port() ) : QString() ) + QLatin1Char(':') + // -1 is used for default ports, omit
503  urlpart_encode( url.user() ) + QLatin1Char(':') +
504  urlpart_encode( url.pass() ) + QLatin1Char(':') +
505  // KUrl automatically encoded the query (e.g. for spaces inside it),
506  // so decode it before writing it out to gpgconf (issue119)
507  urlpart_encode( KUrl::fromPercentEncoding( url.query().mid(1).toLatin1() ) );
508  }
509  return url.path();
510 }
511 
512 KUrl QGpgMENewCryptoConfigEntry::urlValue() const
513 {
514  const Type type = m_option.type();
515  Q_ASSERT( type == FilenameType || type == LdapServerType );
516  Q_ASSERT( !isList() );
517  if ( type == FilenameType )
518  {
519  KUrl url;
520  url.setPath( QFile::decodeName( m_option.currentValue().stringValue() ) );
521  return url;
522  }
523  return parseURL( type, stringValue() );
524 }
525 
526 unsigned int QGpgMENewCryptoConfigEntry::numberOfTimesSet() const
527 {
528  Q_ASSERT( m_option.alternateType() == NoType );
529  Q_ASSERT( isList() );
530  return m_option.currentValue().uintValue();
531 }
532 
533 QStringList QGpgMENewCryptoConfigEntry::stringValueList() const
534 {
535  Q_ASSERT( m_option.alternateType() == StringType );
536  Q_ASSERT( isList() );
537  const Argument arg = m_option.currentValue();
538  const std::vector<const char*> values = arg.stringValues();
539  QStringList result;
540  BOOST_FOREACH( const char * value, values )
541  result.push_back( QString::fromUtf8( value ) );
542  return result;
543 }
544 
545 std::vector<int> QGpgMENewCryptoConfigEntry::intValueList() const
546 {
547  Q_ASSERT( m_option.alternateType() == IntegerType );
548  Q_ASSERT( isList() );
549  return m_option.currentValue().intValues();
550 }
551 
552 std::vector<unsigned int> QGpgMENewCryptoConfigEntry::uintValueList() const
553 {
554  Q_ASSERT( m_option.alternateType() == UnsignedIntegerType );
555  Q_ASSERT( isList() );
556  return m_option.currentValue().uintValues();
557 }
558 
559 KUrl::List QGpgMENewCryptoConfigEntry::urlValueList() const
560 {
561  const Type type = m_option.type();
562  Q_ASSERT( type == FilenameType || type == LdapServerType );
563  Q_ASSERT( isList() );
564  const Argument arg = m_option.currentValue();
565  const std::vector<const char*> values = arg.stringValues();
566  KUrl::List ret;
567  BOOST_FOREACH( const char * value, values )
568  if ( type == FilenameType ) {
569  KUrl url;
570  url.setPath( QFile::decodeName( value ) );
571  ret << url;
572  } else {
573  ret << parseURL( type, QString::fromUtf8( value ) );
574  }
575  return ret;
576 }
577 
578 void QGpgMENewCryptoConfigEntry::resetToDefault()
579 {
580  m_option.resetToDefaultValue();
581 }
582 
583 void QGpgMENewCryptoConfigEntry::setBoolValue( bool b )
584 {
585  Q_ASSERT( m_option.alternateType() == NoType );
586  Q_ASSERT( !isList() );
587  // A "no arg" option is either set or not set.
588  // Being set means createNoneArgument(), being unset means resetToDefault()
589  m_option.setNewValue( m_option.createNoneArgument( b ) );
590 }
591 
592 void QGpgMENewCryptoConfigEntry::setStringValue( const QString& str )
593 {
594  Q_ASSERT( m_option.alternateType() == StringType );
595  Q_ASSERT( !isList() );
596  const Type type = m_option.type();
597  // When setting a string to empty (and there's no default), we need to act like resetToDefault
598  // Otherwise we try e.g. "ocsp-responder:0:" and gpgconf answers:
599  // "gpgconf: argument required for option ocsp-responder"
600  if ( str.isEmpty() && !isOptional() )
601  m_option.resetToDefaultValue();
602  else if ( type == FilenameType )
603  m_option.setNewValue( m_option.createStringArgument( QFile::encodeName( str ).constData() ) );
604  else
605  m_option.setNewValue( m_option.createStringArgument( str.toUtf8().constData() ) );
606 }
607 
608 void QGpgMENewCryptoConfigEntry::setIntValue( int i )
609 {
610  Q_ASSERT( m_option.alternateType() == IntegerType );
611  Q_ASSERT( !isList() );
612  m_option.setNewValue( m_option.createIntArgument( i ) );
613 }
614 
615 void QGpgMENewCryptoConfigEntry::setUIntValue( unsigned int i )
616 {
617  Q_ASSERT( m_option.alternateType() == UnsignedIntegerType );
618  Q_ASSERT( !isList() );
619  m_option.setNewValue( m_option.createUIntArgument( i ) );
620 }
621 
622 void QGpgMENewCryptoConfigEntry::setURLValue( const KUrl& url )
623 {
624  const Type type = m_option.type();
625  Q_ASSERT( type == FilenameType || type == LdapServerType );
626  Q_ASSERT( !isList() );
627  const QString str = splitURL( type, url );
628  // cf. setStringValue()
629  if ( str.isEmpty() && !isOptional() )
630  m_option.resetToDefaultValue();
631  else if ( type == FilenameType )
632  m_option.setNewValue( m_option.createStringArgument( QFile::encodeName( str ).constData() ) );
633  else
634  m_option.setNewValue( m_option.createStringArgument( str.toUtf8().constData() ) );
635 }
636 
637 void QGpgMENewCryptoConfigEntry::setNumberOfTimesSet( unsigned int i )
638 {
639  Q_ASSERT( m_option.alternateType() == NoType );
640  Q_ASSERT( isList() );
641  m_option.setNewValue( m_option.createNoneListArgument( i ) );
642 }
643 
644 void QGpgMENewCryptoConfigEntry::setStringValueList( const QStringList& lst )
645 {
646  const Type type = m_option.type();
647  Q_ASSERT( m_option.alternateType() == StringType );
648  Q_ASSERT( isList() );
649  std::vector<std::string> values;
650  values.reserve( lst.size() );
651  Q_FOREACH( const QString & s, lst )
652  if ( type == FilenameType )
653  values.push_back( QFile::encodeName( s ).constData() );
654  else
655  values.push_back( s.toUtf8().constData() );
656  m_option.setNewValue( m_option.createStringListArgument( values ) );
657 }
658 
659 void QGpgMENewCryptoConfigEntry::setIntValueList( const std::vector<int> & lst )
660 {
661  Q_ASSERT( m_option.alternateType() == IntegerType );
662  Q_ASSERT( isList() );
663  m_option.setNewValue( m_option.createIntListArgument( lst ) );
664 }
665 
666 void QGpgMENewCryptoConfigEntry::setUIntValueList( const std::vector<unsigned int> & lst )
667 {
668  Q_ASSERT( m_option.alternateType() == UnsignedIntegerType );
669  Q_ASSERT( isList() );
670  m_option.setNewValue( m_option.createUIntListArgument( lst ) );
671 }
672 
673 void QGpgMENewCryptoConfigEntry::setURLValueList( const KUrl::List& urls )
674 {
675  const Type type = m_option.type();
676  Q_ASSERT( m_option.alternateType() == StringType );
677  Q_ASSERT( isList() );
678  std::vector<std::string> values;
679  values.reserve( urls.size() );
680  Q_FOREACH( const KUrl & url, urls )
681  if ( type == FilenameType )
682  values.push_back( QFile::encodeName( url.path() ).constData() );
683  else
684  values.push_back( splitURL( type, url ).toUtf8().constData() );
685  m_option.setNewValue( m_option.createStringListArgument( values ) );
686 }
687 
688 bool QGpgMENewCryptoConfigEntry::isDirty() const
689 {
690  return m_option.dirty();
691 }
692 
693 #if 0
694 QString QGpgMENewCryptoConfigEntry::toString( bool escape ) const
695 {
696  // Basically the opposite of stringToValue
697  if ( isStringType() ) {
698  if ( mValue.isNull() )
699  return QString();
700  else if ( isList() ) { // string list
701  QStringList lst = mValue.toStringList();
702  if ( escape ) {
703  for( QStringList::iterator it = lst.begin(); it != lst.end(); ++it ) {
704  if ( !(*it).isNull() )
705  *it = gpgconf_escape( *it ).prepend( "\"" );
706  }
707  }
708  QString res = lst.join( "," );
709  //kDebug(5150) <<"toString:" << res;
710  return res;
711  } else { // normal string
712  QString res = mValue.toString();
713  if ( escape )
714  res = gpgconf_escape( res ).prepend( "\"" );
715  return res;
716  }
717  }
718  if ( !isList() ) // non-list non-string
719  {
720  if ( mArgType == ArgType_None ) {
721  return mValue.toBool() ? QString::fromLatin1( "1" ) : QString();
722  } else { // some int
723  Q_ASSERT( mArgType == ArgType_Int || mArgType == ArgType_UInt );
724  return mValue.toString(); // int to string conversion
725  }
726  }
727 
728  // Lists (of other types than strings)
729  if ( mArgType == ArgType_None )
730  return QString::number( numberOfTimesSet() );
731  QStringList ret;
732  QList<QVariant> lst = mValue.toList();
733  for( QList<QVariant>::const_iterator it = lst.constBegin(); it != lst.constEnd(); ++it ) {
734  ret << (*it).toString(); // QVariant does the conversion
735  }
736  return ret.join( "," );
737 }
738 
739 QString QGpgMENewCryptoConfigEntry::outputString() const
740 {
741  Q_ASSERT( mSet );
742  return toString( true );
743 }
744 
745 bool QGpgMENewCryptoConfigEntry::isStringType() const
746 {
747  return ( mArgType == Kleo::NewCryptoConfigEntry::ArgType_String
748  || mArgType == Kleo::NewCryptoConfigEntry::ArgType_Path
749  || mArgType == Kleo::NewCryptoConfigEntry::ArgType_URL
750  || mArgType == Kleo::NewCryptoConfigEntry::ArgType_LDAPURL );
751 }
752 
753 void QGpgMENewCryptoConfigEntry::setDirty( bool b )
754 {
755  mDirty = b;
756 }
757 #endif
758 
759 #include "qgpgmenewcryptoconfig.moc"
QGpgMENewCryptoConfigEntry::isReadOnly
bool isReadOnly() const
Definition: qgpgmenewcryptoconfig.cpp:400
QGpgMENewCryptoConfigEntry::setNumberOfTimesSet
void setNumberOfTimesSet(unsigned int)
Definition: qgpgmenewcryptoconfig.cpp:637
ArgType_LDAPURL
Definition: cryptoconfig.h:87
QGpgMENewCryptoConfig::QGpgMENewCryptoConfig
QGpgMENewCryptoConfig()
Constructor.
Definition: qgpgmenewcryptoconfig.cpp:70
QGpgMENewCryptoConfigEntry::setURLValue
void setURLValue(const KUrl &)
Definition: qgpgmenewcryptoconfig.cpp:622
QGpgMENewCryptoConfigEntry::setUIntValue
void setUIntValue(unsigned int)
Definition: qgpgmenewcryptoconfig.cpp:615
name
const char * name
Definition: kconfigbasedkeyfilter.cpp:124
QGpgMENewCryptoConfigComponent::groupList
QStringList groupList() const
Definition: qgpgmenewcryptoconfig.cpp:188
QGpgMENewCryptoConfigGroup::QGpgMENewCryptoConfigGroup
QGpgMENewCryptoConfigGroup(const boost::shared_ptr< QGpgMENewCryptoConfigComponent > &parent, const GpgME::Configuration::Option &option)
Definition: qgpgmenewcryptoconfig.cpp:217
QGpgMENewCryptoConfigGroup::~QGpgMENewCryptoConfigGroup
~QGpgMENewCryptoConfigGroup()
Definition: qgpgmenewcryptoconfig.cpp:224
QGpgMENewCryptoConfigEntry::setBoolValue
void setBoolValue(bool)
Definition: qgpgmenewcryptoconfig.cpp:583
QGpgMENewCryptoConfig
CryptoConfig implementation around the gpgconf command-line tool For method docu, see kleo/cryptoconf...
Definition: qgpgmenewcryptoconfig.h:157
QGpgMENewCryptoConfigEntry::QGpgMENewCryptoConfigEntry
QGpgMENewCryptoConfigEntry(const boost::shared_ptr< QGpgMENewCryptoConfigGroup > &group, const GpgME::Configuration::Option &option)
Definition: qgpgmenewcryptoconfig.cpp:316
parseURL
static KUrl parseURL(int mRealArgType, const QString &str)
Definition: qgpgmenewcryptoconfig.cpp:465
QGpgMENewCryptoConfigGroup::path
QString path() const
Definition: qgpgmenewcryptoconfig.cpp:236
QGpgMENewCryptoConfigComponent::setComponent
void setComponent(const GpgME::Configuration::Component &component)
Definition: qgpgmenewcryptoconfig.cpp:150
QGpgMENewCryptoConfigEntry::description
QString description() const
Definition: qgpgmenewcryptoconfig.cpp:382
ArgType_String
Definition: cryptoconfig.h:82
QGpgMENewCryptoConfigEntry::urlValue
KUrl urlValue() const
Definition: qgpgmenewcryptoconfig.cpp:512
s_duringClear
static bool s_duringClear
Definition: qgpgmenewcryptoconfig.cpp:68
QGpgMENewCryptoConfigEntry::~QGpgMENewCryptoConfigEntry
~QGpgMENewCryptoConfigEntry()
Definition: qgpgmenewcryptoconfig.cpp:368
QGpgMENewCryptoConfigGroup::level
Kleo::CryptoConfigEntry::Level level() const
Definition: qgpgmenewcryptoconfig.cpp:244
QGpgMENewCryptoConfig::component
QGpgMENewCryptoConfigComponent * component(const QString &name) const
Definition: qgpgmenewcryptoconfig.cpp:120
QString
QGpgMENewCryptoConfigEntry::stringValue
QString stringValue() const
Definition: qgpgmenewcryptoconfig.cpp:443
QGpgMENewCryptoConfigEntry::isRuntime
bool isRuntime() const
Definition: qgpgmenewcryptoconfig.cpp:410
QGpgMENewCryptoConfigGroup::entryList
QStringList entryList() const
Definition: qgpgmenewcryptoconfig.cpp:250
gpgconf_unescape
static QString gpgconf_unescape(const QString &str)
Definition: qgpgmecryptoconfig.cpp:419
QGpgMENewCryptoConfigEntry::isSet
bool isSet() const
Definition: qgpgmenewcryptoconfig.cpp:431
QGpgMENewCryptoConfig::~QGpgMENewCryptoConfig
~QGpgMENewCryptoConfig()
Definition: qgpgmenewcryptoconfig.cpp:75
QGpgMENewCryptoConfigGroup::name
QString name() const
Definition: qgpgmenewcryptoconfig.cpp:226
QGpgMENewCryptoConfig::sync
void sync(bool runtime)
Definition: qgpgmenewcryptoconfig.cpp:127
ArgType_Path
Definition: cryptoconfig.h:85
QGpgMENewCryptoConfigComponent::name
QString name() const
Definition: qgpgmenewcryptoconfig.cpp:178
QGpgMENewCryptoConfigComponent::description
QString description() const
Definition: qgpgmenewcryptoconfig.cpp:183
QGpgMENewCryptoConfig::clear
void clear()
Definition: qgpgmenewcryptoconfig.cpp:133
boost::shared_ptr
Definition: checksumdefinition.h:46
QGpgMENewCryptoConfigComponent::sync
void sync(bool runtime)
Definition: qgpgmenewcryptoconfig.cpp:203
QGpgMENewCryptoConfigEntry::setIntValueList
void setIntValueList(const std::vector< int > &)
Definition: qgpgmenewcryptoconfig.cpp:659
QGpgMENewCryptoConfigEntry::isDirty
bool isDirty() const
Definition: qgpgmenewcryptoconfig.cpp:688
QGpgMENewCryptoConfigGroup::entry
QGpgMENewCryptoConfigEntry * entry(const QString &name) const
Definition: qgpgmenewcryptoconfig.cpp:255
splitURL
static QString splitURL(int mRealArgType, const KUrl &url)
Definition: qgpgmenewcryptoconfig.cpp:496
QGpgMENewCryptoConfigEntry::intValue
int intValue() const
Definition: qgpgmenewcryptoconfig.cpp:451
QGpgMENewCryptoConfigEntry::setURLValueList
void setURLValueList(const KUrl::List &)
Definition: qgpgmenewcryptoconfig.cpp:673
kdtools::transform
O transform(const I &i, P p)
Definition: stl_util.h:374
QGpgMENewCryptoConfigGroup
Definition: qgpgmenewcryptoconfig.h:111
Level
Level
Definition: cryptoconfig.h:60
QGpgMENewCryptoConfigEntry::argType
ArgType argType() const
Definition: qgpgmenewcryptoconfig.cpp:421
QGpgMENewCryptoConfigComponent::group
QGpgMENewCryptoConfigGroup * group(const QString &name) const
Definition: qgpgmenewcryptoconfig.cpp:198
QGpgMENewCryptoConfigEntry::stringValueList
QStringList stringValueList() const
Definition: qgpgmenewcryptoconfig.cpp:533
knownArgType
static Kleo::CryptoConfigEntry::ArgType knownArgType(int argType, bool &ok)
Definition: qgpgmenewcryptoconfig.cpp:295
QGpgMENewCryptoConfigEntry::setIntValue
void setIntValue(int)
Definition: qgpgmenewcryptoconfig.cpp:608
urlpart_encode
static QString urlpart_encode(const QString &str)
Definition: qgpgmenewcryptoconfig.cpp:280
QGpgMENewCryptoConfigGroup::description
QString description() const
Definition: qgpgmenewcryptoconfig.cpp:231
qgpgmenewcryptoconfig.h
gpgconf_escape
static QString gpgconf_escape(const QString &str)
Definition: qgpgmecryptoconfig.cpp:425
kdtools::copy
O copy(const I &i)
Definition: stl_util.h:425
QGpgMENewCryptoConfigComponent::~QGpgMENewCryptoConfigComponent
~QGpgMENewCryptoConfigComponent()
Definition: qgpgmenewcryptoconfig.cpp:176
ArgType
ArgType
Type of the argument.
Definition: cryptoconfig.h:81
QGpgMENewCryptoConfigEntry::boolValue
bool boolValue() const
Definition: qgpgmenewcryptoconfig.cpp:436
QGpgMENewCryptoConfigEntry::setStringValueList
void setStringValueList(const QStringList &)
Definition: qgpgmenewcryptoconfig.cpp:644
QGpgMENewCryptoConfigComponent
For docu, see kleo/cryptoconfig.h.
Definition: qgpgmenewcryptoconfig.h:133
QGpgMENewCryptoConfigEntry::setStringValue
void setStringValue(const QString &)
Definition: qgpgmenewcryptoconfig.cpp:592
QGpgMENewCryptoConfigEntry::urlValueList
KUrl::List urlValueList() const
Definition: qgpgmenewcryptoconfig.cpp:559
QGpgMENewCryptoConfigEntry::name
QString name() const
Definition: qgpgmenewcryptoconfig.cpp:377
QGpgMENewCryptoConfigEntry::uintValue
unsigned int uintValue() const
Definition: qgpgmenewcryptoconfig.cpp:458
QGpgMENewCryptoConfigEntry::level
Level level() const
Definition: qgpgmenewcryptoconfig.cpp:415
QGpgMENewCryptoConfigEntry::isOptional
bool isOptional() const
Definition: qgpgmenewcryptoconfig.cpp:395
ArgType_UInt
Definition: cryptoconfig.h:84
ArgType_URL
Definition: cryptoconfig.h:86
QGpgMENewCryptoConfig::componentList
QStringList componentList() const
Definition: qgpgmenewcryptoconfig.cpp:109
QGpgMENewCryptoConfigEntry::setUIntValueList
void setUIntValueList(const std::vector< unsigned int > &)
Definition: qgpgmenewcryptoconfig.cpp:666
QGpgMENewCryptoConfigEntry::isList
bool isList() const
Definition: qgpgmenewcryptoconfig.cpp:405
QGpgMENewCryptoConfigEntry::resetToDefault
void resetToDefault()
Definition: qgpgmenewcryptoconfig.cpp:578
ArgType_None
Definition: cryptoconfig.h:81
ArgType_Int
Definition: cryptoconfig.h:83
QGpgMENewCryptoConfigEntry::path
QString path() const
Definition: qgpgmenewcryptoconfig.cpp:387
urlpart_decode
static QString urlpart_decode(const QString &str)
Definition: qgpgmenewcryptoconfig.cpp:289
QGpgMENewCryptoConfigEntry::numberOfTimesSet
unsigned int numberOfTimesSet() const
Definition: qgpgmenewcryptoconfig.cpp:526
QGpgMENewCryptoConfigComponent::QGpgMENewCryptoConfigComponent
QGpgMENewCryptoConfigComponent()
Definition: qgpgmenewcryptoconfig.cpp:143
QGpgMENewCryptoConfigEntry::intValueList
std::vector< int > intValueList() const
Definition: qgpgmenewcryptoconfig.cpp:545
QGpgMENewCryptoConfigEntry
Definition: qgpgmenewcryptoconfig.h:59
QGpgMENewCryptoConfigEntry::uintValueList
std::vector< unsigned int > uintValueList() const
Definition: qgpgmenewcryptoconfig.cpp:552
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:49 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