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

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • conf
dirservconfigpage.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  conf/dirservconfigpage.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2004,2008 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra 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 <config-kleopatra.h>
34 
35 #include "dirservconfigpage.h"
36 #include "libkleo/ui/directoryserviceswidget.h"
37 #include "libkleo/ui/cryptoconfigmodule.h"
38 #include "libkleo/kleo/cryptobackendfactory.h"
39 
40 #include <kdemacros.h>
41 #include <kmessagebox.h>
42 #include <klocale.h>
43 #include <kdebug.h>
44 #include <kconfig.h>
45 #include <knuminput.h>
46 #include <kdialog.h>
47 #include <kcomponentdata.h>
48 
49 #include <QLabel>
50 #include <qdatetimeedit.h>
51 #include <QCheckBox>
52 #include <QLayout>
53 
54 using namespace Kleo;
55 
56 #if 0 // disabled, since it is apparently confusing
57 // For sync'ing kabldaprc
58 class KABSynchronizer
59 {
60 public:
61  KABSynchronizer()
62  : mConfig( "kabldaprc" ) {
63  mConfig.setGroup( "LDAP" );
64  }
65 
66  KUrl::List readCurrentList() const {
67 
68  KUrl::List lst;
69  // stolen from kabc/ldapclient.cpp
70  const uint numHosts = mConfig.readEntry( "NumSelectedHosts" );
71  for ( uint j = 0; j < numHosts; j++ ) {
72  const QString num = QString::number( j );
73 
74  KUrl url;
75  url.setProtocol( "ldap" );
76  url.setPath( "/" ); // workaround KUrl parsing bug
77  const QString host = mConfig.readEntry( QString( "SelectedHost" ) + num ).trimmed();
78  url.setHost( host );
79 
80  const int port = mConfig.readEntry( QString( "SelectedPort" ) + num );
81  if ( port != 0 )
82  url.setPort( port );
83 
84  const QString base = mConfig.readEntry( QString( "SelectedBase" ) + num ).trimmed();
85  url.setQuery( base );
86 
87  const QString bindDN = mConfig.readEntry( QString( "SelectedBind" ) + num ).trimmed();
88  url.setUser( bindDN );
89 
90  const QString pwdBindDN = mConfig.readEntry( QString( "SelectedPwdBind" ) + num ).trimmed();
91  url.setPass( pwdBindDN );
92  lst.append( url );
93  }
94  return lst;
95  }
96 
97  void writeList( const KUrl::List& lst ) {
98 
99  mConfig.writeEntry( "NumSelectedHosts", lst.count() );
100 
101  KUrl::List::const_iterator it = lst.begin();
102  KUrl::List::const_iterator end = lst.end();
103  unsigned j = 0;
104  for( ; it != end; ++it, ++j ) {
105  const QString num = QString::number( j );
106  KUrl url = *it;
107 
108  Q_ASSERT( url.protocol() == "ldap" );
109  mConfig.writeEntry( QString( "SelectedHost" ) + num, url.host() );
110  mConfig.writeEntry( QString( "SelectedPort" ) + num, url.port() );
111 
112  // KUrl automatically encoded the query (e.g. for spaces inside it),
113  // so decode it before writing it out
114  const QString base = KUrl::decode_string( url.query().mid(1) );
115  mConfig.writeEntry( QString( "SelectedBase" ) + num, base );
116  mConfig.writeEntry( QString( "SelectedBind" ) + num, url.user() );
117  mConfig.writeEntry( QString( "SelectedPwdBind" ) + num, url.pass() );
118  }
119  mConfig.sync();
120  }
121 
122 private:
123  KConfig mConfig;
124 };
125 
126 #endif
127 
128 static const char s_x509services_componentName[] = "dirmngr";
129 static const char s_x509services_groupName[] = "LDAP";
130 static const char s_x509services_entryName[] = "LDAP Server";
131 
132 static const char s_x509services_new_componentName[] = "gpgsm";
133 static const char s_x509services_new_groupName[] = "Configuration";
134 static const char s_x509services_new_entryName[] = "keyserver";
135 
136 static const char s_pgpservice_componentName[] = "gpg";
137 static const char s_pgpservice_groupName[] = "Keyserver";
138 static const char s_pgpservice_entryName[] = "keyserver";
139 
140 static const char s_timeout_componentName[] = "dirmngr";
141 static const char s_timeout_groupName[] = "LDAP";
142 static const char s_timeout_entryName[] = "ldaptimeout";
143 
144 static const char s_maxitems_componentName[] = "dirmngr";
145 static const char s_maxitems_groupName[] = "LDAP";
146 static const char s_maxitems_entryName[] = "max-replies";
147 
148 static const char s_addnewservers_componentName[] = "dirmngr";
149 static const char s_addnewservers_groupName[] = "LDAP";
150 static const char s_addnewservers_entryName[] = "add-servers";
151 
152 DirectoryServicesConfigurationPage::DirectoryServicesConfigurationPage( const KComponentData &instance, QWidget *parent, const QVariantList &args )
153  : KCModule( instance, parent, args )
154 {
155  mConfig = Kleo::CryptoBackendFactory::instance()->config();
156  QGridLayout * glay = new QGridLayout( this );
157  glay->setSpacing( KDialog::spacingHint() );
158  glay->setMargin( 0 );
159 
160  int row = 0;
161  mWidget = new Kleo::DirectoryServicesWidget( this );
162  if ( QLayout * l = mWidget->layout() ) {
163  l->setSpacing( KDialog::spacingHint() );
164  l->setMargin( 0 );
165  }
166  glay->addWidget( mWidget, row, 0, 1, 3 );
167  connect( mWidget, SIGNAL(changed()), this, SLOT(changed()) );
168 
169  // LDAP timeout
170  ++row;
171  QLabel* label = new QLabel( i18n( "LDAP &timeout (minutes:seconds):" ), this );
172  mTimeout = new QTimeEdit( this );
173  mTimeout->setDisplayFormat( QLatin1String("mm:ss") );
174  connect( mTimeout, SIGNAL(timeChanged(QTime)), this, SLOT(changed()) );
175  label->setBuddy( mTimeout );
176  glay->addWidget( label, row, 0 );
177  glay->addWidget( mTimeout, row, 1 );
178 
179  // Max number of items returned by queries
180  ++row;
181  mMaxItemsLabel = new QLabel( i18n( "&Maximum number of items returned by query:" ), this );
182  mMaxItems = new KIntNumInput( this );
183  mMaxItems->setMinimum( 0 );
184  mMaxItemsLabel->setBuddy( mMaxItems );
185  connect( mMaxItems, SIGNAL(valueChanged(int)), this, SLOT(changed()) );
186  glay->addWidget( mMaxItemsLabel, row, 0 );
187  glay->addWidget( mMaxItems, row, 1 );
188 
189 #ifdef NOT_USEFUL_CURRENTLY
190  ++row
191  mAddNewServersCB = new QCheckBox( i18n( "Automatically add &new servers discovered in CRL distribution points" ), this );
192  connect( mAddNewServersCB, SIGNAL(clicked()), this, SLOT(changed()) );
193  glay->addWidget( mAddNewServersCB, row, 0, 1, 3 );
194 #endif
195 
196  glay->setRowStretch( ++row, 1 );
197  glay->setColumnStretch( 2, 1 );
198 
199 #ifndef HAVE_UNBROKEN_KCMULTIDIALOG
200  load();
201 #endif
202 }
203 
204 static KUrl::List string2urls( const QString & str ) {
205  return str.isEmpty() ? KUrl::List() : KUrl( str ) ;
206 }
207 
208 static KUrl::List strings2urls( const QStringList & strs ) {
209  KUrl::List urls;
210  Q_FOREACH( const QString & str, strs )
211  if ( !str.isEmpty() )
212  urls.push_back( KUrl( str ) );
213  return urls;
214 }
215 
216 static QStringList urls2strings( const KUrl::List & urls ) {
217  QStringList result;
218  Q_FOREACH( const KUrl & url, urls )
219  result.push_back( url.url() );
220  return result;
221 }
222 
223 void DirectoryServicesConfigurationPage::load()
224 {
225 
226  mWidget->clear();
227 
228  // gpgsm/Configuration/keyserver is not provided by older gpgconf versions; it's type changed from String to LDAPURL
229  if ( ( mX509ServicesEntry = configEntry( s_x509services_new_componentName, s_x509services_new_groupName, s_x509services_new_entryName,
230  Kleo::CryptoConfigEntry::ArgType_LDAPURL, /*isList=*/true, /*showError=*/false ) ) )
231  mWidget->addX509Services( mX509ServicesEntry->urlValueList() );
232  else if ( ( mX509ServicesEntry = configEntry( s_x509services_new_componentName, s_x509services_new_groupName, s_x509services_new_entryName,
233  Kleo::CryptoConfigEntry::ArgType_String, /*isList=*/true, /*showError=*/false ) ) )
234  mWidget->addX509Services( strings2urls( mX509ServicesEntry->stringValueList() ) );
235  else if ( ( mX509ServicesEntry = configEntry( s_x509services_componentName, s_x509services_groupName, s_x509services_entryName,
236  Kleo::CryptoConfigEntry::ArgType_LDAPURL, true ) ) )
237  mWidget->addX509Services( mX509ServicesEntry->urlValueList() );
238 
239  mWidget->setX509ReadOnly( mX509ServicesEntry && mX509ServicesEntry->isReadOnly() );
240 
241  mOpenPGPServiceEntry = configEntry( s_pgpservice_componentName, s_pgpservice_groupName, s_pgpservice_entryName,
242  Kleo::CryptoConfigEntry::ArgType_String, false );
243  if ( mOpenPGPServiceEntry )
244  mWidget->addOpenPGPServices( string2urls( parseKeyserver( mOpenPGPServiceEntry->stringValue() ).url ) );
245 
246  mWidget->setOpenPGPReadOnly( mOpenPGPServiceEntry && mOpenPGPServiceEntry->isReadOnly() );
247 
248  if ( mX509ServicesEntry )
249  if ( mOpenPGPServiceEntry )
250  mWidget->setAllowedProtocols( DirectoryServicesWidget::AllProtocols );
251  else
252  mWidget->setAllowedProtocols( DirectoryServicesWidget::X509Protocol );
253  else
254  if ( mOpenPGPServiceEntry )
255  mWidget->setAllowedProtocols( DirectoryServicesWidget::OpenPGPProtocol );
256  else
257  mWidget->setDisabled( true );
258 
259  DirectoryServicesWidget::Protocols readOnlyProtocols;
260  if ( mX509ServicesEntry && mX509ServicesEntry->isReadOnly() )
261  readOnlyProtocols = DirectoryServicesWidget::X509Protocol;
262 
263  mTimeoutConfigEntry = configEntry( s_timeout_componentName, s_timeout_groupName, s_timeout_entryName, Kleo::CryptoConfigEntry::ArgType_UInt, false );
264  if ( mTimeoutConfigEntry ) {
265  QTime time = QTime().addSecs( mTimeoutConfigEntry->uintValue() );
266  //kDebug() <<"timeout:" << mTimeoutConfigEntry->uintValue() <<" ->" << time;
267  mTimeout->setTime( time );
268  }
269 
270  mMaxItemsConfigEntry = configEntry( s_maxitems_componentName, s_maxitems_groupName, s_maxitems_entryName, Kleo::CryptoConfigEntry::ArgType_UInt, false );
271  if ( mMaxItemsConfigEntry ) {
272  mMaxItems->blockSignals( true ); // KNumInput emits valueChanged from setValue!
273  mMaxItems->setValue( mMaxItemsConfigEntry->uintValue() );
274  mMaxItems->blockSignals( false );
275  }
276  const bool maxItemsEnabled = mMaxItemsConfigEntry && !mMaxItemsConfigEntry->isReadOnly();
277  mMaxItems->setEnabled( maxItemsEnabled );
278  mMaxItemsLabel->setEnabled( maxItemsEnabled );
279 
280 #ifdef NOT_USEFUL_CURRENTLY
281  mAddNewServersConfigEntry = configEntry( s_addnewservers_componentName, s_addnewservers_groupName, s_addnewservers_entryName, Kleo::CryptoConfigEntry::ArgType_None, false );
282  if ( mAddNewServersConfigEntry ) {
283  mAddNewServersCB->setChecked( mAddNewServersConfigEntry->boolValue() );
284  }
285 #endif
286 }
287 
288 void DirectoryServicesConfigurationPage::save()
289 {
290  if ( mX509ServicesEntry ) {
291  if ( mX509ServicesEntry->argType() == Kleo::CryptoConfigEntry::ArgType_LDAPURL )
292  mX509ServicesEntry->setURLValueList( mWidget->x509Services() );
293  else
294  mX509ServicesEntry->setStringValueList( urls2strings( mWidget->x509Services() ) );
295  }
296 
297  if ( mOpenPGPServiceEntry ) {
298  const KUrl::List serv = mWidget->openPGPServices();
299  if ( serv.empty() )
300  mOpenPGPServiceEntry->setStringValue( QString() );
301  else {
302  ParsedKeyserver pks = parseKeyserver( mOpenPGPServiceEntry->stringValue() );
303  pks.url = serv.front().url();
304  mOpenPGPServiceEntry->setStringValue( assembleKeyserver( pks ) );
305  }
306  }
307 
308  QTime time( mTimeout->time() );
309  unsigned int timeout = time.minute() * 60 + time.second();
310  if ( mTimeoutConfigEntry && mTimeoutConfigEntry->uintValue() != timeout )
311  mTimeoutConfigEntry->setUIntValue( timeout );
312  if ( mMaxItemsConfigEntry && mMaxItemsConfigEntry->uintValue() != (uint)mMaxItems->value() )
313  mMaxItemsConfigEntry->setUIntValue( mMaxItems->value() );
314 #ifdef NOT_USEFUL_CURRENTLY
315  if ( mAddNewServersConfigEntry && mAddNewServersConfigEntry->boolValue() != mAddNewServersCB->isChecked() )
316  mAddNewServersConfigEntry->setBoolValue( mAddNewServersCB->isChecked() );
317 #endif
318 
319  mConfig->sync( true );
320 
321 #if 0
322  // Also write the LDAP URLs to kabldaprc so that they are used by kaddressbook
323  KABSynchronizer sync;
324  const KUrl::List toAdd = mWidget->urlList();
325  KUrl::List currentList = sync.readCurrentList();
326 
327  KUrl::List::const_iterator it = toAdd.begin();
328  KUrl::List::const_iterator end = toAdd.end();
329  for( ; it != end; ++it ) {
330  // check if the URL is already in currentList
331  if ( currentList.find( *it ) == currentList.end() )
332  // if not, add it
333  currentList.append( *it );
334  }
335  sync.writeList( currentList );
336 #endif
337 }
338 
339 void DirectoryServicesConfigurationPage::defaults()
340 {
341  // these guys don't have a default, to clear them:
342  if ( mX509ServicesEntry ) {
343  if ( mX509ServicesEntry->argType() == Kleo::CryptoConfigEntry::ArgType_LDAPURL )
344  mX509ServicesEntry->setURLValueList( KUrl() );
345  else
346  mX509ServicesEntry->setStringValueList( QStringList() );
347  }
348  if ( mOpenPGPServiceEntry )
349  mOpenPGPServiceEntry->setStringValue( QString() );
350  // these presumably have a default, use that one:
351  if ( mTimeoutConfigEntry )
352  mTimeoutConfigEntry->resetToDefault();
353  if ( mMaxItemsConfigEntry )
354  mMaxItemsConfigEntry->resetToDefault();
355 #ifdef NOT_USEFUL_CURRENTLY
356  if ( mAddNewServersConfigEntry )
357  mAddNewServersConfigEntry->resetToDefault();
358 #endif
359  load();
360 }
361 
362 extern "C"
363 {
364  KDE_EXPORT KCModule *create_kleopatra_config_dirserv( QWidget *parent=0, const QVariantList &args=QVariantList() )
365  {
366  DirectoryServicesConfigurationPage *page =
367  new DirectoryServicesConfigurationPage( KComponentData( "kleopatra" ), parent, args );
368  page->setObjectName( QLatin1String("kleopatra_config_dirserv") );
369  return page;
370  }
371 }
372 
373 // Find config entry for ldap servers. Implements runtime checks on the configuration option.
374 Kleo::CryptoConfigEntry* DirectoryServicesConfigurationPage::configEntry( const char* componentName,
375  const char* groupName,
376  const char* entryName,
377  Kleo::CryptoConfigEntry::ArgType argType,
378  bool isList,
379  bool showError )
380 {
381  Kleo::CryptoConfigEntry* entry = mConfig->entry( QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName) );
382 
383  if ( !entry ) {
384  if ( showError )
385  KMessageBox::error( this, i18n( "Backend error: gpgconf does not seem to know the entry for %1/%2/%3", QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName) ) );
386  return 0;
387  }
388  if( entry->argType() != argType || entry->isList() != isList ) {
389  if ( showError )
390  KMessageBox::error( this, i18n( "Backend error: gpgconf has wrong type for %1/%2/%3: %4 %5", QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName), entry->argType(), entry->isList() ) );
391  return 0;
392  }
393  return entry;
394 }
395 
396 #include "dirservconfigpage.moc"
s_x509services_new_groupName
static const char s_x509services_new_groupName[]
Definition: dirservconfigpage.cpp:133
s_x509services_entryName
static const char s_x509services_entryName[]
Definition: dirservconfigpage.cpp:130
urls2strings
static QStringList urls2strings(const KUrl::List &urls)
Definition: dirservconfigpage.cpp:216
DirectoryServicesConfigurationPage::save
void save()
Definition: dirservconfigpage.cpp:288
DirectoryServicesConfigurationPage::DirectoryServicesConfigurationPage
DirectoryServicesConfigurationPage(const KComponentData &instance, QWidget *parent=0, const QVariantList &args=QVariantList())
Definition: dirservconfigpage.cpp:152
s_x509services_componentName
static const char s_x509services_componentName[]
Definition: dirservconfigpage.cpp:128
string2urls
static KUrl::List string2urls(const QString &str)
Definition: dirservconfigpage.cpp:204
QWidget
s_addnewservers_entryName
static const char s_addnewservers_entryName[]
Definition: dirservconfigpage.cpp:150
s_maxitems_componentName
static const char s_maxitems_componentName[]
Definition: dirservconfigpage.cpp:144
strings2urls
static KUrl::List strings2urls(const QStringList &strs)
Definition: dirservconfigpage.cpp:208
s_timeout_componentName
static const char s_timeout_componentName[]
Definition: dirservconfigpage.cpp:140
s_x509services_groupName
static const char s_x509services_groupName[]
Definition: dirservconfigpage.cpp:129
s_x509services_new_entryName
static const char s_x509services_new_entryName[]
Definition: dirservconfigpage.cpp:134
s_pgpservice_entryName
static const char s_pgpservice_entryName[]
Definition: dirservconfigpage.cpp:138
DirectoryServicesConfigurationPage::defaults
void defaults()
Definition: dirservconfigpage.cpp:339
s_addnewservers_componentName
static const char s_addnewservers_componentName[]
Definition: dirservconfigpage.cpp:148
s_x509services_new_componentName
static const char s_x509services_new_componentName[]
Definition: dirservconfigpage.cpp:132
DirectoryServicesConfigurationPage::load
void load()
Definition: dirservconfigpage.cpp:223
s_addnewservers_groupName
static const char s_addnewservers_groupName[]
Definition: dirservconfigpage.cpp:149
s_timeout_groupName
static const char s_timeout_groupName[]
Definition: dirservconfigpage.cpp:141
s_pgpservice_componentName
static const char s_pgpservice_componentName[]
Definition: dirservconfigpage.cpp:136
s_pgpservice_groupName
static const char s_pgpservice_groupName[]
Definition: dirservconfigpage.cpp:137
s_timeout_entryName
static const char s_timeout_entryName[]
Definition: dirservconfigpage.cpp:142
s_maxitems_entryName
static const char s_maxitems_entryName[]
Definition: dirservconfigpage.cpp:146
DirectoryServicesConfigurationPage
"Directory Services" configuration page for kleopatra's configuration dialog The user can configure L...
Definition: dirservconfigpage.h:55
dirservconfigpage.h
s_maxitems_groupName
static const char s_maxitems_groupName[]
Definition: dirservconfigpage.cpp:145
create_kleopatra_config_dirserv
KCModule * create_kleopatra_config_dirserv(QWidget *parent=0, const QVariantList &args=QVariantList())
Definition: dirservconfigpage.cpp:364
KCModule
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • 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