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

libkleo

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

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