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  vbox = addVBoxPage( comp->description(), TQString(), loadIcon( comp->iconName() ) );
102  }
103 
104  TQScrollView * scrollView = new TQScrollView( vbox );
105  scrollView->setHScrollBarMode( TQScrollView::AlwaysOff );
106  scrollView->setResizePolicy( TQScrollView::AutoOneFit );
107  TQVBox* boxInScrollView = new TQVBox( scrollView->viewport() );
108  boxInScrollView->setMargin( KDialog::marginHint() );
109  scrollView->addChild( boxInScrollView );
110 
111  CryptoConfigComponentGUI* compGUI =
112  new CryptoConfigComponentGUI( this, comp, boxInScrollView, (*it).local8Bit() );
113  // KJanusWidget doesn't seem to have iterators, so we store a copy...
114  mComponentGUIs.append( compGUI );
115 
116  // Set a nice startup size
117  const int deskHeight = TQApplication::desktop()->height();
118  int dialogHeight;
119  if (deskHeight > 1000) // very big desktop ?
120  dialogHeight = 800;
121  else if (deskHeight > 650) // big desktop ?
122  dialogHeight = 500;
123  else // small (800x600, 640x480) desktop
124  dialogHeight = 400;
125  TQSize sz = scrollView->sizeHint();
126  scrollView->setMinimumSize( sz.width()
127  + scrollView->style().pixelMetric(TQStyle::PM_ScrollBarExtent),
128  TQMIN( compGUI->sizeHint().height(), dialogHeight ) );
129  }
130  if ( mComponentGUIs.empty() ) {
131  Q_ASSERT( face() == Plain );
132  const TQString msg = i18n("The gpgconf tool used to provide the information "
133  "for this dialog does not seem to be installed "
134  "properly. It did not return any components. "
135  "Try running \"%1\" on the command line for more "
136  "information.")
137  .arg( components.empty() ? "gpgconf --list-components" : "gpgconf --list-options gpg" );
138  TQLabel * label = new TQLabel( msg, vbox );
139  label->setAlignment( TQt::WordBreak );
140  label->setMinimumHeight( fontMetrics().lineSpacing() * 5 );
141  }
142 }
143 
144 bool Kleo::CryptoConfigModule::hasError() const {
145  return mComponentGUIs.empty();
146 }
147 
148 void Kleo::CryptoConfigModule::save()
149 {
150  bool changed = false;
151  TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
152  for( ; it != mComponentGUIs.end(); ++it ) {
153  if ( (*it)->save() )
154  changed = true;
155  }
156  if ( changed )
157  mConfig->sync(true /*runtime*/);
158 }
159 
160 void Kleo::CryptoConfigModule::reset()
161 {
162  TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
163  for( ; it != mComponentGUIs.end(); ++it ) {
164  (*it)->load();
165  }
166 }
167 
168 void Kleo::CryptoConfigModule::defaults()
169 {
170  TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
171  for( ; it != mComponentGUIs.end(); ++it ) {
172  (*it)->defaults();
173  }
174 }
175 
176 void Kleo::CryptoConfigModule::cancel()
177 {
178  mConfig->clear();
179 }
180 
182 
183 Kleo::CryptoConfigComponentGUI::CryptoConfigComponentGUI(
185  TQWidget* parent, const char* name )
186  : TQWidget( parent, name ),
187  mComponent( component )
188 {
189  TQGridLayout * glay = new TQGridLayout( this, 1, 3, 0, KDialog::spacingHint() );
190  const TQStringList groups = mComponent->groupList();
191  if ( groups.size() > 1 ) {
192  glay->setColSpacing( 0, KDHorizontalLine::indentHint() );
193  for ( TQStringList::const_iterator it = groups.begin(), end = groups.end() ; it != end; ++it ) {
194  Kleo::CryptoConfigGroup* group = mComponent->group( *it );
195  Q_ASSERT( group );
196  if ( !group )
197  continue;
198  KDHorizontalLine * hl = new KDHorizontalLine( group->description(), this );
199  const int row = glay->numRows();
200  glay->addMultiCellWidget( hl, row, row, 0, 2 );
201  mGroupGUIs.append( new CryptoConfigGroupGUI( module, group, glay, this ) );
202  }
203  } else if ( !groups.empty() ) {
204  mGroupGUIs.append( new CryptoConfigGroupGUI( module, mComponent->group( groups.front() ), glay, this ) );
205  }
206  glay->setRowStretch( glay->numRows(), 1 );
207 }
208 
209 
210 bool Kleo::CryptoConfigComponentGUI::save()
211 {
212  bool changed = false;
213  TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
214  for( ; it != mGroupGUIs.end(); ++it ) {
215  if ( (*it)->save() )
216  changed = true;
217  }
218  return changed;
219 }
220 
221 void Kleo::CryptoConfigComponentGUI::load()
222 {
223  TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
224  for( ; it != mGroupGUIs.end(); ++it )
225  (*it)->load();
226 }
227 
228 void Kleo::CryptoConfigComponentGUI::defaults()
229 {
230  TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
231  for( ; it != mGroupGUIs.end(); ++it )
232  (*it)->defaults();
233 }
234 
236 
237 Kleo::CryptoConfigGroupGUI::CryptoConfigGroupGUI(
239  TQGridLayout * glay, TQWidget* widget, const char* name )
240  : TQObject( module, name ), mGroup( group )
241 {
242  const int startRow = glay->numRows();
243  const TQStringList entries = mGroup->entryList();
244  for( TQStringList::const_iterator it = entries.begin(), end = entries.end() ; it != end; ++it ) {
245  Kleo::CryptoConfigEntry* entry = group->entry( *it );
246  Q_ASSERT( entry );
247  if ( entry->level() > CryptoConfigEntry::Level_Advanced ) continue;
248  CryptoConfigEntryGUI* entryGUI =
249  CryptoConfigEntryGUIFactory::createEntryGUI( module, entry, *it, glay, widget );
250  if ( entryGUI ) {
251  mEntryGUIs.append( entryGUI );
252  entryGUI->load();
253  }
254  }
255  const int endRow = glay->numRows() - 1;
256  if ( endRow < startRow )
257  return;
258 
259  const TQString iconName = group->iconName();
260  if ( iconName.isEmpty() )
261  return;
262 
263  TQLabel * l = new TQLabel( widget );
264  l->setPixmap( loadIcon( iconName ) );
265  glay->addMultiCellWidget( l, startRow, endRow, 0, 0, TQt::AlignTop );
266 }
267 
268 bool Kleo::CryptoConfigGroupGUI::save()
269 {
270  bool changed = false;
271  TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
272  for( ; it != mEntryGUIs.end(); ++it ) {
273  if ( (*it)->isChanged() ) {
274  (*it)->save();
275  changed = true;
276  }
277  }
278  return changed;
279 }
280 
281 void Kleo::CryptoConfigGroupGUI::load()
282 {
283  TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
284  for( ; it != mEntryGUIs.end(); ++it )
285  (*it)->load();
286 }
287 
288 void Kleo::CryptoConfigGroupGUI::defaults()
289 {
290  TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
291  for( ; it != mEntryGUIs.end(); ++it )
292  (*it)->resetToDefault();
293 }
294 
296 
297 CryptoConfigEntryGUI* Kleo::CryptoConfigEntryGUIFactory::createEntryGUI( CryptoConfigModule* module, Kleo::CryptoConfigEntry* entry, const TQString& entryName, TQGridLayout * glay, TQWidget* widget, const char* name )
298 {
299  if ( entry->isList() ) {
300  switch( entry->argType() ) {
301  case Kleo::CryptoConfigEntry::ArgType_None:
302  // A list of options with no arguments (e.g. -v -v -v) is shown as a spinbox
303  return new CryptoConfigEntrySpinBox( module, entry, entryName, glay, widget, name );
304  case Kleo::CryptoConfigEntry::ArgType_Int:
305  case Kleo::CryptoConfigEntry::ArgType_UInt:
306  // Let people type list of numbers (1,2,3....). Untested.
307  return new CryptoConfigEntryLineEdit( module, entry, entryName, glay, widget, name );
308  case Kleo::CryptoConfigEntry::ArgType_URL:
309  case Kleo::CryptoConfigEntry::ArgType_Path:
310  case Kleo::CryptoConfigEntry::ArgType_DirPath:
311  case Kleo::CryptoConfigEntry::ArgType_String:
312  kdWarning(5150) << "No widget implemented for list of type " << entry->argType() << endl;
313  return 0; // TODO when the need arises :)
314  case Kleo::CryptoConfigEntry::ArgType_LDAPURL:
315  return new CryptoConfigEntryLDAPURL( module, entry, entryName, glay, widget, name );
316  }
317  kdWarning(5150) << "No widget implemented for list of (unknown) type " << entry->argType() << endl;
318  return 0;
319  }
320 
321  switch( entry->argType() ) {
322  case Kleo::CryptoConfigEntry::ArgType_None:
323  return new CryptoConfigEntryCheckBox( module, entry, entryName, glay, widget, name );
324  case Kleo::CryptoConfigEntry::ArgType_Int:
325  case Kleo::CryptoConfigEntry::ArgType_UInt:
326  return new CryptoConfigEntrySpinBox( module, entry, entryName, glay, widget, name );
327  case Kleo::CryptoConfigEntry::ArgType_URL:
328  return new CryptoConfigEntryURL( module, entry, entryName, glay, widget, name );
329  case Kleo::CryptoConfigEntry::ArgType_Path:
330  return new CryptoConfigEntryPath( module, entry, entryName, glay, widget, name );
331  case Kleo::CryptoConfigEntry::ArgType_DirPath:
332  return new CryptoConfigEntryDirPath( module, entry, entryName, glay, widget, name );
333  case Kleo::CryptoConfigEntry::ArgType_LDAPURL:
334  kdWarning(5150) << "No widget implemented for type " << entry->argType() << endl;
335  return 0; // TODO when the need arises :)
336  case Kleo::CryptoConfigEntry::ArgType_String:
337  return new CryptoConfigEntryLineEdit( module, entry, entryName, glay, widget, name );
338  }
339  kdWarning(5150) << "No widget implemented for (unknown) type " << entry->argType() << endl;
340  return 0;
341 }
342 
344 
345 Kleo::CryptoConfigEntryGUI::CryptoConfigEntryGUI(
346  CryptoConfigModule* module,
348  const TQString& entryName,
349  const char* name )
350  : TQObject( module, name ), mEntry( entry ), mName( entryName ), mChanged( false )
351 {
352  connect( this, TQT_SIGNAL( changed() ), module, TQT_SIGNAL( changed() ) );
353 }
354 
355 TQString Kleo::CryptoConfigEntryGUI::description() const
356 {
357  TQString descr = mEntry->description();
358  if ( descr.isEmpty() ) // shouldn't happen
359  descr = TQString( "<%1>" ).arg( mName );
360  return descr;
361 }
362 
363 void Kleo::CryptoConfigEntryGUI::resetToDefault()
364 {
365  mEntry->resetToDefault();
366  load();
367 }
368 
370 
371 Kleo::CryptoConfigEntryLineEdit::CryptoConfigEntryLineEdit(
372  CryptoConfigModule* module,
373  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
374  TQGridLayout * glay, TQWidget* widget, const char* name )
375  : CryptoConfigEntryGUI( module, entry, entryName, name )
376 {
377  const int row = glay->numRows();
378  mLineEdit = new KLineEdit( widget );
379  TQLabel* label = new TQLabel( mLineEdit, description(), widget );
380  glay->addWidget( label, row, 1 );
381  glay->addWidget( mLineEdit, row, 2 );
382  if ( entry->isReadOnly() ) {
383  label->setEnabled( false );
384  mLineEdit->setEnabled( false );
385  } else {
386  connect( mLineEdit, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotChanged() ) );
387  }
388 }
389 
390 void Kleo::CryptoConfigEntryLineEdit::doSave()
391 {
392  mEntry->setStringValue( mLineEdit->text() );
393 }
394 
395 void Kleo::CryptoConfigEntryLineEdit::doLoad()
396 {
397  mLineEdit->setText( mEntry->stringValue() );
398 }
399 
401 
402 Kleo::CryptoConfigEntryPath::CryptoConfigEntryPath(
403  CryptoConfigModule* module,
404  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
405  TQGridLayout * glay, TQWidget* widget, const char* name )
406  : CryptoConfigEntryGUI( module, entry, entryName, name )
407 {
408  const int row = glay->numRows();
409  mUrlRequester = new KURLRequester( widget );
410  mUrlRequester->setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly );
411  TQLabel* label = new TQLabel( mUrlRequester, description(), widget );
412  glay->addWidget( label, row, 1 );
413  glay->addWidget( mUrlRequester, row, 2 );
414  if ( entry->isReadOnly() ) {
415  label->setEnabled( false );
416  mUrlRequester->setEnabled( false );
417  } else {
418  connect( mUrlRequester, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotChanged() ) );
419  }
420 }
421 
422 void Kleo::CryptoConfigEntryPath::doSave()
423 {
424  KURL url;
425  url.setPath( mUrlRequester->url() );
426  mEntry->setURLValue( url );
427 }
428 
429 void Kleo::CryptoConfigEntryPath::doLoad()
430 {
431  mUrlRequester->setURL( mEntry->urlValue().path() );
432 }
433 
435 
436 Kleo::CryptoConfigEntryDirPath::CryptoConfigEntryDirPath(
437  CryptoConfigModule* module,
438  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
439  TQGridLayout * glay, TQWidget* widget, const char* name )
440  : CryptoConfigEntryGUI( module, entry, entryName, name )
441 {
442  const int row = glay->numRows();
443  mUrlRequester = new KURLRequester( widget );
444  mUrlRequester->setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
445  TQLabel* label = new TQLabel( mUrlRequester, description(), widget );
446  glay->addWidget( label, row, 1 );
447  glay->addWidget( mUrlRequester, row, 2 );
448  if ( entry->isReadOnly() ) {
449  label->setEnabled( false );
450  mUrlRequester->setEnabled( false );
451  } else {
452  connect( mUrlRequester, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotChanged() ) );
453  }
454 }
455 
456 void Kleo::CryptoConfigEntryDirPath::doSave()
457 {
458  KURL url;
459  url.setPath( mUrlRequester->url() );
460  mEntry->setURLValue( url );
461 
462 }
463 
464 void Kleo::CryptoConfigEntryDirPath::doLoad()
465 {
466  mUrlRequester->setURL( mEntry->urlValue().path() );
467 }
468 
470 
471 Kleo::CryptoConfigEntryURL::CryptoConfigEntryURL(
472  CryptoConfigModule* module,
473  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
474  TQGridLayout * glay, TQWidget* widget, const char* name )
475  : CryptoConfigEntryGUI( module, entry, entryName, name )
476 {
477  const int row = glay->numRows();
478  mUrlRequester = new KURLRequester( widget );
479  mUrlRequester->setMode( KFile::File | KFile::ExistingOnly );
480  TQLabel* label = new TQLabel( mUrlRequester, description(), widget );
481  glay->addWidget( label, row, 1 );
482  glay->addWidget( mUrlRequester, row, 2 );
483  if ( entry->isReadOnly() ) {
484  label->setEnabled( false );
485  mUrlRequester->setEnabled( false );
486  } else {
487  connect( mUrlRequester, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotChanged() ) );
488  }
489 }
490 
491 void Kleo::CryptoConfigEntryURL::doSave()
492 {
493  mEntry->setURLValue( mUrlRequester->url() );
494 }
495 
496 void Kleo::CryptoConfigEntryURL::doLoad()
497 {
498  mUrlRequester->setURL( mEntry->urlValue().url() );
499 }
500 
502 
503 Kleo::CryptoConfigEntrySpinBox::CryptoConfigEntrySpinBox(
504  CryptoConfigModule* module,
505  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
506  TQGridLayout * glay, TQWidget* widget, const char* name )
507  : CryptoConfigEntryGUI( module, entry, entryName, name )
508 {
509 
510  if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_None && entry->isList() ) {
511  mKind = ListOfNone;
512  } else if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_UInt ) {
513  mKind = UInt;
514  } else {
515  Q_ASSERT( entry->argType() == Kleo::CryptoConfigEntry::ArgType_Int );
516  mKind = Int;
517  }
518 
519  const int row = glay->numRows();
520  mNumInput = new KIntNumInput( widget );
521  TQLabel* label = new TQLabel( mNumInput, description(), widget );
522  glay->addWidget( label, row, 1 );
523  glay->addWidget( mNumInput, row, 2 );
524 
525  if ( entry->isReadOnly() ) {
526  label->setEnabled( false );
527  mNumInput->setEnabled( false );
528  } else {
529  if ( mKind == UInt || mKind == ListOfNone )
530  mNumInput->setMinValue( 0 );
531  connect( mNumInput, TQT_SIGNAL( valueChanged(int) ), TQT_SLOT( slotChanged() ) );
532  }
533 }
534 
535 void Kleo::CryptoConfigEntrySpinBox::doSave()
536 {
537  int value = mNumInput->value();
538  switch ( mKind ) {
539  case ListOfNone:
540  mEntry->setNumberOfTimesSet( value );
541  break;
542  case UInt:
543  mEntry->setUIntValue( value );
544  break;
545  case Int:
546  mEntry->setIntValue( value );
547  break;
548  }
549 }
550 
551 void Kleo::CryptoConfigEntrySpinBox::doLoad()
552 {
553  int value = 0;
554  switch ( mKind ) {
555  case ListOfNone:
556  value = mEntry->numberOfTimesSet();
557  break;
558  case UInt:
559  value = mEntry->uintValue();
560  break;
561  case Int:
562  value = mEntry->intValue();
563  break;
564  }
565  mNumInput->setValue( value );
566 }
567 
569 
570 Kleo::CryptoConfigEntryCheckBox::CryptoConfigEntryCheckBox(
571  CryptoConfigModule* module,
572  Kleo::CryptoConfigEntry* entry, const TQString& entryName,
573  TQGridLayout * glay, TQWidget* widget, const char* name )
574  : CryptoConfigEntryGUI( module, entry, entryName, name )
575 {
576  const int row = glay->numRows();
577  mCheckBox = new TQCheckBox( widget );
578  glay->addMultiCellWidget( mCheckBox, row, row, 1, 2 );
579  mCheckBox->setText( description() );
580  if ( entry->isReadOnly() ) {
581  mCheckBox->setEnabled( false );
582  } else {
583  connect( mCheckBox, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( slotChanged() ) );
584  }
585 }
586 
587 void Kleo::CryptoConfigEntryCheckBox::doSave()
588 {
589  mEntry->setBoolValue( mCheckBox->isChecked() );
590 }
591 
592 void Kleo::CryptoConfigEntryCheckBox::doLoad()
593 {
594  mCheckBox->setChecked( mEntry->boolValue() );
595 }
596 
597 Kleo::CryptoConfigEntryLDAPURL::CryptoConfigEntryLDAPURL(
598  CryptoConfigModule* module,
600  const TQString& entryName,
601  TQGridLayout * glay, TQWidget* widget, const char* name )
602  : CryptoConfigEntryGUI( module, entry, entryName, name )
603 {
604  mLabel = new TQLabel( widget );
605  mPushButton = new TQPushButton( i18n( "Edit..." ), widget );
606 
607  const int row = glay->numRows();
608  glay->addWidget( new TQLabel( mPushButton, description(), widget ), row, 1 );
609  TQHBoxLayout * hlay = new TQHBoxLayout;
610  glay->addLayout( hlay, row, 2 );
611  hlay->addWidget( mLabel, 1 );
612  hlay->addWidget( mPushButton );
613 
614  if ( entry->isReadOnly() ) {
615  mLabel->setEnabled( false );
616  mPushButton->hide();
617  } else {
618  connect( mPushButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOpenDialog() ) );
619  }
620 }
621 
622 void Kleo::CryptoConfigEntryLDAPURL::doLoad()
623 {
624  setURLList( mEntry->urlValueList() );
625 }
626 
627 void Kleo::CryptoConfigEntryLDAPURL::doSave()
628 {
629  mEntry->setURLValueList( mURLList );
630 }
631 
632 void Kleo::CryptoConfigEntryLDAPURL::slotOpenDialog()
633 {
634  // I'm a bad boy and I do it all on the stack. Enough classes already :)
635  // This is just a simple dialog around the directory-services-widget
636  KDialogBase dialog( mPushButton->parentWidget(), 0, true /*modal*/,
637  i18n( "Configure LDAP Servers" ),
638  KDialogBase::Default|KDialogBase::Cancel|KDialogBase::Ok,
639  KDialogBase::Ok, true /*separator*/ );
640  DirectoryServicesWidget* dirserv = new DirectoryServicesWidget( mEntry, &dialog );
641  dirserv->load();
642  dialog.setMainWidget( dirserv );
643  connect( &dialog, TQT_SIGNAL( defaultClicked() ), dirserv, TQT_SLOT( defaults() ) );
644  if ( dialog.exec() ) {
645  // Note that we just grab the urls from the dialog, we don't call its save method,
646  // since the user hasn't confirmed the big config dialog yet.
647  setURLList( dirserv->urlList() );
648  slotChanged();
649  }
650 }
651 
652 void Kleo::CryptoConfigEntryLDAPURL::setURLList( const KURL::List& urlList )
653 {
654  mURLList = urlList;
655  if ( mURLList.isEmpty() )
656  mLabel->setText( i18n( "No server configured yet" ) );
657  else
658  mLabel->setText( i18n( "1 server configured", "%n servers configured", mURLList.count() ) );
659 }
660 
661 #include "cryptoconfigmodule.moc"
662 #include "cryptoconfigmodule_p.moc"
virtual TQStringList groupList() const =0
Returns the list of groups that are known about.
virtual TQString iconName() const =0
Return the name of the icon for this group.
virtual TQString iconName() const =0
Return the name of the icon for this component.
Main interface to crypto configuration.
Definition: cryptoconfig.h:334
virtual bool isList() const =0
virtual bool isReadOnly() const =0
Crypto config for one component (e.g.
Definition: cryptoconfig.h:295
Group containing a set of config options.
Definition: cryptoconfig.h:252
virtual TQString description() const =0
Return user-visible description of this component.
Crypto Config Module widget, dynamically generated from CryptoConfig It&#39;s a simple TQWidget so that i...
Description of a single option.
Definition: cryptoconfig.h:49
virtual TQString description() const =0
virtual TQStringList componentList() const =0
Returns the list of known components (e.g.
virtual Level level() const =0
User level.
virtual CryptoConfigEntry * entry(const TQString &name) const =0
virtual ArgType argType() const =0
Argument type.
virtual CryptoConfigComponent * component(const TQString &name) const =0