certmanager/lib

cryptoconfigmodule.cpp
1 /*
2  cryptoconfigmodule.cpp
3 
4  This file is part of kgpgcertmanager
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Libkleopatra is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License,
9  version 2, as published by the Free Software Foundation.
10 
11  Libkleopatra is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20  In addition, as a special exception, the copyright holders give
21  permission to link the code of this program with any edition of
22  the TQt library by Trolltech AS, Norway (or with modified versions
23  of TQt that use the same license as TQt), and distribute linked
24  combinations including the two. You must obey the GNU General
25  Public License in all respects for all of the code used other than
26  TQt. If you modify this file, you may extend this exception to
27  your version of the file, but you are not obligated to do so. If
28  you do not wish to do so, delete this exception statement from
29  your version.
30 */
31 
32 #include "cryptoconfigmodule.h"
33 #include "cryptoconfigmodule_p.h"
34 #include "directoryserviceswidget.h"
35 #include "kdhorizontalline.h"
36 
37 #include <kleo/cryptoconfig.h>
38 
39 #include <klineedit.h>
40 #include <tdelocale.h>
41 #include <kdialogbase.h>
42 #include <kdebug.h>
43 #include <knuminput.h>
44 #include <kiconloader.h>
45 #include <tdeglobal.h>
46 #include <kurlrequester.h>
47 
48 #include <tqgrid.h>
49 #include <tqlabel.h>
50 #include <tqlayout.h>
51 #include <tqvbox.h>
52 #include <tqhbox.h>
53 #include <tqpushbutton.h>
54 #include <tqregexp.h>
55 #include <tqstyle.h>
56 #include <tqapplication.h>
57 
58 using namespace Kleo;
59 
60 static inline TQPixmap loadIcon( TQString s ) {
61  return TDEGlobal::instance()->iconLoader()
62  ->loadIcon( s.replace( TQRegExp( "[^a-zA-Z0-9_]" ), "_" ), TDEIcon::NoGroup, TDEIcon::SizeMedium );
63 }
64 
65 static unsigned int num_components_with_options( const Kleo::CryptoConfig * config ) {
66  if ( !config )
67  return 0;
68  const TQStringList components = config->componentList();
69  unsigned int result = 0;
70  for ( TQStringList::const_iterator it = components.begin() ; it != components.end() ; ++it )
71  if ( const Kleo::CryptoConfigComponent * const comp = config->component( *it ) )
72  if ( !comp->groupList().empty() )
73  ++result;
74  return result;
75 }
76 
77 static const KJanusWidget::Face determineJanusFace( const Kleo::CryptoConfig * config ) {
78  return num_components_with_options( config ) < 2
79  ? KJanusWidget::Plain
80  : KJanusWidget::IconList ;
81 }
82 
83 Kleo::CryptoConfigModule::CryptoConfigModule( Kleo::CryptoConfig* config, TQWidget * parent, const char * name )
84  : KJanusWidget( parent, name, determineJanusFace( config ) ), mConfig( config )
85 {
86  TQWidget * vbox = 0;
87  if ( face() == Plain ) {
88  vbox = plainPage();
89  TQVBoxLayout * vlay = new TQVBoxLayout( vbox, 0, KDialog::spacingHint() );
90  vlay->setAutoAdd( true );
91  }
92 
93  const TQStringList components = config->componentList();
94  for ( TQStringList::const_iterator it = components.begin(); it != components.end(); ++it ) {
95  //kdDebug(5150) << "Component " << (*it).local8Bit() << ":" << endl;
96  Kleo::CryptoConfigComponent* comp = config->component( *it );
97  Q_ASSERT( comp );
98  if ( comp->groupList().empty() )
99  continue;
100  if ( face() != Plain ) {
101  TQString iconName = comp->iconName();
102  if (iconName == TQString::null || iconName == "") {
103  iconName = "gpg";
104  }
105  vbox = addVBoxPage( comp->description(), TQString(), loadIcon(iconName) );
106  }
107 
108  TQScrollView * scrollView = new TQScrollView( vbox );
109  scrollView->setHScrollBarMode( TQScrollView::AlwaysOff );
110  scrollView->setResizePolicy( TQScrollView::AutoOneFit );
111  TQVBox* boxInScrollView = new TQVBox( scrollView->viewport() );
112  boxInScrollView->setMargin( KDialog::marginHint() );
113  scrollView->addChild( boxInScrollView );
114 
115  CryptoConfigComponentGUI* compGUI =
116  new CryptoConfigComponentGUI( this, comp, boxInScrollView, (*it).local8Bit() );
117  // KJanusWidget doesn't seem to have iterators, so we store a copy...
118  mComponentGUIs.append( compGUI );
119 
120  // Set a nice startup size
121  const int deskHeight = TQApplication::desktop()->height();
122  int dialogHeight;
123  if (deskHeight > 1000) // very big desktop ?
124  dialogHeight = 800;
125  else if (deskHeight > 650) // big desktop ?
126  dialogHeight = 500;
127  else // small (800x600, 640x480) desktop
128  dialogHeight = 400;
129  TQSize sz = scrollView->sizeHint();
130  scrollView->setMinimumSize( sz.width()
131  + scrollView->style().pixelMetric(TQStyle::PM_ScrollBarExtent),
132  TQMIN( compGUI->sizeHint().height(), dialogHeight ) );
133  }
134  if ( mComponentGUIs.empty() ) {
135  Q_ASSERT( face() == Plain );
136  const TQString msg = i18n("The gpgconf tool used to provide the information "
137  "for this dialog does not seem to be installed "
138  "properly. It did not return any components. "
139  "Try running \"%1\" on the command line for more "
140  "information.")
141  .arg( components.empty() ? "gpgconf --list-components" : "gpgconf --list-options gpg" );
142  TQLabel * label = new TQLabel( msg, vbox );
143  label->setAlignment( TQt::WordBreak );
144  label->setMinimumHeight( fontMetrics().lineSpacing() * 5 );
145  }
146 }
147 
148 bool Kleo::CryptoConfigModule::hasError() const {
149  return mComponentGUIs.empty();
150 }
151 
152 void Kleo::CryptoConfigModule::save()
153 {
154  bool changed = false;
155  TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
156  for( ; it != mComponentGUIs.end(); ++it ) {
157  if ( (*it)->save() )
158  changed = true;
159  }
160  if ( changed )
161  mConfig->sync(true /*runtime*/);
162 }
163 
164 void Kleo::CryptoConfigModule::reset()
165 {
166  TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
167  for( ; it != mComponentGUIs.end(); ++it ) {
168  (*it)->load();
169  }
170 }
171 
172 void Kleo::CryptoConfigModule::defaults()
173 {
174  TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
175  for( ; it != mComponentGUIs.end(); ++it ) {
176  (*it)->defaults();
177  }
178 }
179 
180 void Kleo::CryptoConfigModule::cancel()
181 {
182  mConfig->clear();
183 }
184 
186 
187 Kleo::CryptoConfigComponentGUI::CryptoConfigComponentGUI(
189  TQWidget* parent, const char* name )
190  : TQWidget( parent, name ),
191  mComponent( component )
192 {
193  TQGridLayout * glay = new TQGridLayout( this, 1, 3, 0, KDialog::spacingHint() );
194  const TQStringList groups = mComponent->groupList();
195  if ( groups.size() > 1 ) {
196  glay->setColSpacing( 0, KDHorizontalLine::indentHint() );
197  for ( TQStringList::const_iterator it = groups.begin(), end = groups.end() ; it != end; ++it ) {
198  Kleo::CryptoConfigGroup* group = mComponent->group( *it );
199  Q_ASSERT( group );
200  if ( !group )
201  continue;
202  KDHorizontalLine * hl = new KDHorizontalLine( group->description(), this );
203  const int row = glay->numRows();
204  glay->addMultiCellWidget( hl, row, row, 0, 2 );
205  mGroupGUIs.append( new CryptoConfigGroupGUI( module, group, glay, this ) );
206  }
207  } else if ( !groups.empty() ) {
208  mGroupGUIs.append( new CryptoConfigGroupGUI( module, mComponent->group( groups.front() ), glay, this ) );
209  }
210  glay->setRowStretch( glay->numRows(), 1 );
211 }
212 
213 
214 bool Kleo::CryptoConfigComponentGUI::save()
215 {
216  bool changed = false;
217  TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
218  for( ; it != mGroupGUIs.end(); ++it ) {
219  if ( (*it)->save() )
220  changed = true;
221  }
222  return changed;
223 }
224 
225 void Kleo::CryptoConfigComponentGUI::load()
226 {
227  TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
228  for( ; it != mGroupGUIs.end(); ++it )
229  (*it)->load();
230 }
231 
232 void Kleo::CryptoConfigComponentGUI::defaults()
233 {
234  TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
235  for( ; it != mGroupGUIs.end(); ++it )
236  (*it)->defaults();
237 }
238 
240 
241 Kleo::CryptoConfigGroupGUI::CryptoConfigGroupGUI(
243  TQGridLayout * glay, TQWidget* widget, const char* name )
244  : TQObject( module, name ), mGroup( group )
245 {
246  const int startRow = glay->numRows();
247  const TQStringList entries = mGroup->entryList();
248  for( TQStringList::const_iterator it = entries.begin(), end = entries.end() ; it != end; ++it ) {
249  Kleo::CryptoConfigEntry* entry = group->entry( *it );
250  Q_ASSERT( entry );
251  if ( entry->level() > CryptoConfigEntry::Level_Advanced ) continue;
252  CryptoConfigEntryGUI* entryGUI =
253  CryptoConfigEntryGUIFactory::createEntryGUI( module, entry, *it, glay, widget );
254  if ( entryGUI ) {
255  mEntryGUIs.append( entryGUI );
256  entryGUI->load();
257  }
258  }
259  const int endRow = glay->numRows() - 1;
260  if ( endRow < startRow )
261  return;
262 
263  const TQString iconName = group->iconName();
264  if ( iconName.isEmpty() )
265  return;
266 
267  TQLabel * l = new TQLabel( widget );
268  l->setPixmap( loadIcon( iconName ) );
269  glay->addMultiCellWidget( l, startRow, endRow, 0, 0, TQt::AlignTop );
270 }
271 
272 bool Kleo::CryptoConfigGroupGUI::save()
273 {
274  bool changed = false;
275  TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
276  for( ; it != mEntryGUIs.end(); ++it ) {
277  if ( (*it)->isChanged() ) {
278  (*it)->save();
279  changed = true;
280  }
281  }
282  return changed;
283 }
284 
285 void Kleo::CryptoConfigGroupGUI::load()
286 {
287  TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
288  for( ; it != mEntryGUIs.end(); ++it )
289  (*it)->load();
290 }
291 
292 void Kleo::CryptoConfigGroupGUI::defaults()
293 {
294  TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
295  for( ; it != mEntryGUIs.end(); ++it )
296  (*it)->resetToDefault();
297 }
298 
300 
301 CryptoConfigEntryGUI* Kleo::CryptoConfigEntryGUIFactory::createEntryGUI( CryptoConfigModule* module, Kleo::CryptoConfigEntry* entry, const TQString& entryName, TQGridLayout * glay, TQWidget* widget, const char* name )
302 {
303  if ( entry->isList() ) {
304  switch( entry->argType() ) {
305  case Kleo::CryptoConfigEntry::ArgType_None:
306  // A list of options with no arguments (e.g. -v -v -v) is shown as a spinbox
307  return new CryptoConfigEntrySpinBox( module, entry, entryName, glay, widget, name );
308  case Kleo::CryptoConfigEntry::ArgType_Int:
309  case Kleo::CryptoConfigEntry::ArgType_UInt:
310  // Let people type list of numbers (1,2,3....). Untested.
311  return new CryptoConfigEntryLineEdit( module, entry, entryName, glay, widget, name );
312  case Kleo::CryptoConfigEntry::ArgType_URL:
313  case Kleo::CryptoConfigEntry::ArgType_Path:
314  case Kleo::CryptoConfigEntry::ArgType_DirPath:
315  case Kleo::CryptoConfigEntry::ArgType_String:
316  kdWarning(5150) << "No widget implemented for list of type " << entry->argType() << endl;
317  return 0; // TODO when the need arises :)
318  case Kleo::CryptoConfigEntry::ArgType_LDAPURL:
319  return new CryptoConfigEntryLDAPURL( module, entry, entryName, glay, widget, name );
320  }
321  kdWarning(5150) << "No widget implemented for list of (unknown) type " << entry->argType() << endl;
322  return 0;
323  }
324 
325  switch( entry->argType() ) {
326  case Kleo::CryptoConfigEntry::ArgType_None:
327  return new CryptoConfigEntryCheckBox( module, entry, entryName, glay, widget, name );
328  case Kleo::CryptoConfigEntry::ArgType_Int:
329  case Kleo::CryptoConfigEntry::ArgType_UInt:
330  return new CryptoConfigEntrySpinBox( module, entry, entryName, glay, widget, name );
331  case Kleo::CryptoConfigEntry::ArgType_URL:
332  return new CryptoConfigEntryURL( module, entry, entryName, glay, widget, name );
333  case Kleo::CryptoConfigEntry::ArgType_Path:
334  return new CryptoConfigEntryPath( module, entry, entryName, glay, widget, name );
335  case Kleo::CryptoConfigEntry::ArgType_DirPath:
336  return new CryptoConfigEntryDirPath( module, entry, entryName, glay, widget, name );
337  case Kleo::CryptoConfigEntry::ArgType_LDAPURL:
338  kdWarning(5150) << "No widget implemented for type " << entry->argType() << endl;
339  return 0; // TODO when the need arises :)
340  case Kleo::CryptoConfigEntry::ArgType_String:
341  return new CryptoConfigEntryLineEdit( module, entry, entryName, glay, widget, name );
342  }
343  kdWarning(5150) << "No widget implemented for (unknown) type " << entry->argType() << endl;
344  return 0;
345 }
346 
348 
349 Kleo::CryptoConfigEntryGUI::CryptoConfigEntryGUI(
350  CryptoConfigModule* module,
352  const TQString& entryName,
353  const char* name )
354  : TQObject( module, name ), mEntry( entry ), mName( entryName ), mChanged( false )
355 {
356  connect( this, TQ_SIGNAL( changed() ), module, TQ_SIGNAL( changed() ) );
357 }
358 
359 TQString Kleo::CryptoConfigEntryGUI::description() const
360 {
361  TQString descr = mEntry->description();
362  if ( descr.isEmpty() ) // shouldn't happen
363  descr = TQString( "<%1>" ).arg( mName );
364  return descr;
365 }
366 
367 void Kleo::CryptoConfigEntryGUI::resetToDefault()
368 {
369  mEntry->resetToDefault();
370  load();
371 }
372 
374 
375 Kleo::CryptoConfigEntryLineEdit::CryptoConfigEntryLineEdit(
376  CryptoConfigModule* module,
377  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
378  TQGridLayout * glay, TQWidget* widget, const char* name )
379  : CryptoConfigEntryGUI( module, entry, entryName, name )
380 {
381  const int row = glay->numRows();
382  mLineEdit = new KLineEdit( widget );
383  TQLabel* label = new TQLabel( mLineEdit, description(), widget );
384  glay->addWidget( label, row, 1 );
385  glay->addWidget( mLineEdit, row, 2 );
386  if ( entry->isReadOnly() ) {
387  label->setEnabled( false );
388  mLineEdit->setEnabled( false );
389  } else {
390  connect( mLineEdit, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( slotChanged() ) );
391  }
392 }
393 
394 void Kleo::CryptoConfigEntryLineEdit::doSave()
395 {
396  mEntry->setStringValue( mLineEdit->text() );
397 }
398 
399 void Kleo::CryptoConfigEntryLineEdit::doLoad()
400 {
401  mLineEdit->setText( mEntry->stringValue() );
402 }
403 
405 
406 Kleo::CryptoConfigEntryPath::CryptoConfigEntryPath(
407  CryptoConfigModule* module,
408  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
409  TQGridLayout * glay, TQWidget* widget, const char* name )
410  : CryptoConfigEntryGUI( module, entry, entryName, name )
411 {
412  const int row = glay->numRows();
413  mUrlRequester = new KURLRequester( widget );
414  mUrlRequester->setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly );
415  TQLabel* label = new TQLabel( mUrlRequester, description(), widget );
416  glay->addWidget( label, row, 1 );
417  glay->addWidget( mUrlRequester, row, 2 );
418  if ( entry->isReadOnly() ) {
419  label->setEnabled( false );
420  mUrlRequester->setEnabled( false );
421  } else {
422  connect( mUrlRequester, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( slotChanged() ) );
423  }
424 }
425 
426 void Kleo::CryptoConfigEntryPath::doSave()
427 {
428  KURL url;
429  url.setPath( mUrlRequester->url() );
430  mEntry->setURLValue( url );
431 }
432 
433 void Kleo::CryptoConfigEntryPath::doLoad()
434 {
435  mUrlRequester->setURL( mEntry->urlValue().path() );
436 }
437 
439 
440 Kleo::CryptoConfigEntryDirPath::CryptoConfigEntryDirPath(
441  CryptoConfigModule* module,
442  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
443  TQGridLayout * glay, TQWidget* widget, const char* name )
444  : CryptoConfigEntryGUI( module, entry, entryName, name )
445 {
446  const int row = glay->numRows();
447  mUrlRequester = new KURLRequester( widget );
448  mUrlRequester->setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
449  TQLabel* label = new TQLabel( mUrlRequester, description(), widget );
450  glay->addWidget( label, row, 1 );
451  glay->addWidget( mUrlRequester, row, 2 );
452  if ( entry->isReadOnly() ) {
453  label->setEnabled( false );
454  mUrlRequester->setEnabled( false );
455  } else {
456  connect( mUrlRequester, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( slotChanged() ) );
457  }
458 }
459 
460 void Kleo::CryptoConfigEntryDirPath::doSave()
461 {
462  KURL url;
463  url.setPath( mUrlRequester->url() );
464  mEntry->setURLValue( url );
465 
466 }
467 
468 void Kleo::CryptoConfigEntryDirPath::doLoad()
469 {
470  mUrlRequester->setURL( mEntry->urlValue().path() );
471 }
472 
474 
475 Kleo::CryptoConfigEntryURL::CryptoConfigEntryURL(
476  CryptoConfigModule* module,
477  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
478  TQGridLayout * glay, TQWidget* widget, const char* name )
479  : CryptoConfigEntryGUI( module, entry, entryName, name )
480 {
481  const int row = glay->numRows();
482  mUrlRequester = new KURLRequester( widget );
483  mUrlRequester->setMode( KFile::File | KFile::ExistingOnly );
484  TQLabel* label = new TQLabel( mUrlRequester, description(), widget );
485  glay->addWidget( label, row, 1 );
486  glay->addWidget( mUrlRequester, row, 2 );
487  if ( entry->isReadOnly() ) {
488  label->setEnabled( false );
489  mUrlRequester->setEnabled( false );
490  } else {
491  connect( mUrlRequester, TQ_SIGNAL( textChanged( const TQString& ) ), TQ_SLOT( slotChanged() ) );
492  }
493 }
494 
495 void Kleo::CryptoConfigEntryURL::doSave()
496 {
497  mEntry->setURLValue( mUrlRequester->url() );
498 }
499 
500 void Kleo::CryptoConfigEntryURL::doLoad()
501 {
502  mUrlRequester->setURL( mEntry->urlValue().url() );
503 }
504 
506 
507 Kleo::CryptoConfigEntrySpinBox::CryptoConfigEntrySpinBox(
508  CryptoConfigModule* module,
509  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
510  TQGridLayout * glay, TQWidget* widget, const char* name )
511  : CryptoConfigEntryGUI( module, entry, entryName, name )
512 {
513 
514  if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_None && entry->isList() ) {
515  mKind = ListOfNone;
516  } else if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_UInt ) {
517  mKind = UInt;
518  } else {
519  Q_ASSERT( entry->argType() == Kleo::CryptoConfigEntry::ArgType_Int );
520  mKind = Int;
521  }
522 
523  const int row = glay->numRows();
524  mNumInput = new KIntNumInput( widget );
525  TQLabel* label = new TQLabel( mNumInput, description(), widget );
526  glay->addWidget( label, row, 1 );
527  glay->addWidget( mNumInput, row, 2 );
528 
529  if ( entry->isReadOnly() ) {
530  label->setEnabled( false );
531  mNumInput->setEnabled( false );
532  } else {
533  if ( mKind == UInt || mKind == ListOfNone )
534  mNumInput->setMinValue( 0 );
535  connect( mNumInput, TQ_SIGNAL( valueChanged(int) ), TQ_SLOT( slotChanged() ) );
536  }
537 }
538 
539 void Kleo::CryptoConfigEntrySpinBox::doSave()
540 {
541  int value = mNumInput->value();
542  switch ( mKind ) {
543  case ListOfNone:
544  mEntry->setNumberOfTimesSet( value );
545  break;
546  case UInt:
547  mEntry->setUIntValue( value );
548  break;
549  case Int:
550  mEntry->setIntValue( value );
551  break;
552  }
553 }
554 
555 void Kleo::CryptoConfigEntrySpinBox::doLoad()
556 {
557  int value = 0;
558  switch ( mKind ) {
559  case ListOfNone:
560  value = mEntry->numberOfTimesSet();
561  break;
562  case UInt:
563  value = mEntry->uintValue();
564  break;
565  case Int:
566  value = mEntry->intValue();
567  break;
568  }
569  mNumInput->setValue( value );
570 }
571 
573 
574 Kleo::CryptoConfigEntryCheckBox::CryptoConfigEntryCheckBox(
575  CryptoConfigModule* module,
576  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
577  TQGridLayout * glay, TQWidget* widget, const char* name )
578  : CryptoConfigEntryGUI( module, entry, entryName, name )
579 {
580  const int row = glay->numRows();
581  mCheckBox = new TQCheckBox( widget );
582  glay->addMultiCellWidget( mCheckBox, row, row, 1, 2 );
583  mCheckBox->setText( description() );
584  if ( entry->isReadOnly() ) {
585  mCheckBox->setEnabled( false );
586  } else {
587  connect( mCheckBox, TQ_SIGNAL( toggled(bool) ), TQ_SLOT( slotChanged() ) );
588  }
589 }
590 
591 void Kleo::CryptoConfigEntryCheckBox::doSave()
592 {
593  mEntry->setBoolValue( mCheckBox->isChecked() );
594 }
595 
596 void Kleo::CryptoConfigEntryCheckBox::doLoad()
597 {
598  mCheckBox->setChecked( mEntry->boolValue() );
599 }
600 
601 Kleo::CryptoConfigEntryLDAPURL::CryptoConfigEntryLDAPURL(
602  CryptoConfigModule* module,
604  const TQString& entryName,
605  TQGridLayout * glay, TQWidget* widget, const char* name )
606  : CryptoConfigEntryGUI( module, entry, entryName, name )
607 {
608  mLabel = new TQLabel( widget );
609  mPushButton = new TQPushButton( i18n( "Edit..." ), widget );
610 
611  const int row = glay->numRows();
612  glay->addWidget( new TQLabel( mPushButton, description(), widget ), row, 1 );
613  TQHBoxLayout * hlay = new TQHBoxLayout;
614  glay->addLayout( hlay, row, 2 );
615  hlay->addWidget( mLabel, 1 );
616  hlay->addWidget( mPushButton );
617 
618  if ( entry->isReadOnly() ) {
619  mLabel->setEnabled( false );
620  mPushButton->hide();
621  } else {
622  connect( mPushButton, TQ_SIGNAL( clicked() ), TQ_SLOT( slotOpenDialog() ) );
623  }
624 }
625 
626 void Kleo::CryptoConfigEntryLDAPURL::doLoad()
627 {
628  setURLList( mEntry->urlValueList() );
629 }
630 
631 void Kleo::CryptoConfigEntryLDAPURL::doSave()
632 {
633  mEntry->setURLValueList( mURLList );
634 }
635 
636 void Kleo::CryptoConfigEntryLDAPURL::slotOpenDialog()
637 {
638  // I'm a bad boy and I do it all on the stack. Enough classes already :)
639  // This is just a simple dialog around the directory-services-widget
640  KDialogBase dialog( mPushButton->parentWidget(), 0, true /*modal*/,
641  i18n( "Configure LDAP Servers" ),
642  KDialogBase::Default|KDialogBase::Cancel|KDialogBase::Ok,
643  KDialogBase::Ok, true /*separator*/ );
644  DirectoryServicesWidget* dirserv = new DirectoryServicesWidget( mEntry, &dialog );
645  dirserv->load();
646  dialog.setMainWidget( dirserv );
647  connect( &dialog, TQ_SIGNAL( defaultClicked() ), dirserv, TQ_SLOT( defaults() ) );
648  if ( dialog.exec() ) {
649  // Note that we just grab the urls from the dialog, we don't call its save method,
650  // since the user hasn't confirmed the big config dialog yet.
651  setURLList( dirserv->urlList() );
652  slotChanged();
653  }
654 }
655 
656 void Kleo::CryptoConfigEntryLDAPURL::setURLList( const KURL::List& urlList )
657 {
658  mURLList = urlList;
659  if ( mURLList.isEmpty() )
660  mLabel->setText( i18n( "No server configured yet" ) );
661  else
662  mLabel->setText( i18n( "1 server configured", "%n servers configured", mURLList.count() ) );
663 }
664 
665 #include "cryptoconfigmodule.moc"
666 #include "cryptoconfigmodule_p.moc"
Crypto config for one component (e.g.
Definition: cryptoconfig.h:295
virtual TQString iconName() const =0
Return the name of the icon for this component.
virtual TQString description() const =0
Return user-visible description of this component.
virtual TQStringList groupList() const =0
Returns the list of groups that are known about.
Description of a single option.
Definition: cryptoconfig.h:49
virtual bool isList() const =0
virtual ArgType argType() const =0
Argument type.
virtual Level level() const =0
User level.
virtual bool isReadOnly() const =0
Group containing a set of config options.
Definition: cryptoconfig.h:252
virtual CryptoConfigEntry * entry(const TQString &name) const =0
virtual TQString description() const =0
virtual TQString iconName() const =0
Return the name of the icon for this group.
Crypto Config Module widget, dynamically generated from CryptoConfig It's a simple TQWidget so that i...
Main interface to crypto configuration.
Definition: cryptoconfig.h:334
virtual TQStringList componentList() const =0
Returns the list of known components (e.g.
virtual CryptoConfigComponent * component(const TQString &name) const =0