cryptoconfigmodule.cpp
00001 /* 00002 cryptoconfigmodule.cpp 00003 00004 This file is part of kgpgcertmanager 00005 Copyright (c) 2004 Klar�vdalens Datakonsult AB 00006 00007 Libkleopatra is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU General Public License, 00009 version 2, as published by the Free Software Foundation. 00010 00011 Libkleopatra is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 00020 In addition, as a special exception, the copyright holders give 00021 permission to link the code of this program with any edition of 00022 the TQt library by Trolltech AS, Norway (or with modified versions 00023 of TQt that use the same license as TQt), and distribute linked 00024 combinations including the two. You must obey the GNU General 00025 Public License in all respects for all of the code used other than 00026 TQt. If you modify this file, you may extend this exception to 00027 your version of the file, but you are not obligated to do so. If 00028 you do not wish to do so, delete this exception statement from 00029 your version. 00030 */ 00031 00032 #include "cryptoconfigmodule.h" 00033 #include "cryptoconfigmodule_p.h" 00034 #include "directoryserviceswidget.h" 00035 #include "kdhorizontalline.h" 00036 00037 #include <kleo/cryptoconfig.h> 00038 00039 #include <klineedit.h> 00040 #include <klocale.h> 00041 #include <kdialogbase.h> 00042 #include <kdebug.h> 00043 #include <knuminput.h> 00044 #include <kiconloader.h> 00045 #include <kglobal.h> 00046 #include <kurlrequester.h> 00047 00048 #include <tqgrid.h> 00049 #include <tqlabel.h> 00050 #include <tqlayout.h> 00051 #include <tqvbox.h> 00052 #include <tqhbox.h> 00053 #include <tqpushbutton.h> 00054 #include <tqregexp.h> 00055 #include <tqstyle.h> 00056 #include <tqapplication.h> 00057 00058 using namespace Kleo; 00059 00060 static inline TQPixmap loadIcon( TQString s ) { 00061 return KGlobal::instance()->iconLoader() 00062 ->loadIcon( s.replace( TQRegExp( "[^a-zA-Z0-9_]" ), "_" ), KIcon::NoGroup, KIcon::SizeMedium ); 00063 } 00064 00065 static unsigned int num_components_with_options( const Kleo::CryptoConfig * config ) { 00066 if ( !config ) 00067 return 0; 00068 const TQStringList components = config->componentList(); 00069 unsigned int result = 0; 00070 for ( TQStringList::const_iterator it = components.begin() ; it != components.end() ; ++it ) 00071 if ( const Kleo::CryptoConfigComponent * const comp = config->component( *it ) ) 00072 if ( !comp->groupList().empty() ) 00073 ++result; 00074 return result; 00075 } 00076 00077 static const KJanusWidget::Face determineJanusFace( const Kleo::CryptoConfig * config ) { 00078 return num_components_with_options( config ) < 2 00079 ? KJanusWidget::Plain 00080 : KJanusWidget::IconList ; 00081 } 00082 00083 Kleo::CryptoConfigModule::CryptoConfigModule( Kleo::CryptoConfig* config, TQWidget * parent, const char * name ) 00084 : KJanusWidget( parent, name, determineJanusFace( config ) ), mConfig( config ) 00085 { 00086 TQWidget * vbox = 0; 00087 if ( face() == Plain ) { 00088 vbox = plainPage(); 00089 TQVBoxLayout * vlay = new TQVBoxLayout( vbox, 0, KDialog::spacingHint() ); 00090 vlay->setAutoAdd( true ); 00091 } 00092 00093 const TQStringList components = config->componentList(); 00094 for ( TQStringList::const_iterator it = components.begin(); it != components.end(); ++it ) { 00095 //kdDebug(5150) << "Component " << (*it).local8Bit() << ":" << endl; 00096 Kleo::CryptoConfigComponent* comp = config->component( *it ); 00097 Q_ASSERT( comp ); 00098 if ( comp->groupList().empty() ) 00099 continue; 00100 if ( face() != Plain ) { 00101 vbox = addVBoxPage( comp->description(), TQString(), loadIcon( comp->iconName() ) ); 00102 } 00103 00104 TQScrollView * scrollView = new TQScrollView( vbox ); 00105 scrollView->setHScrollBarMode( TQScrollView::AlwaysOff ); 00106 scrollView->setResizePolicy( TQScrollView::AutoOneFit ); 00107 TQVBox* boxInScrollView = new TQVBox( scrollView->viewport() ); 00108 boxInScrollView->setMargin( KDialog::marginHint() ); 00109 scrollView->addChild( boxInScrollView ); 00110 00111 CryptoConfigComponentGUI* compGUI = 00112 new CryptoConfigComponentGUI( this, comp, boxInScrollView, (*it).local8Bit() ); 00113 // KJanusWidget doesn't seem to have iterators, so we store a copy... 00114 mComponentGUIs.append( compGUI ); 00115 00116 // Set a nice startup size 00117 const int deskHeight = TQApplication::desktop()->height(); 00118 int dialogHeight; 00119 if (deskHeight > 1000) // very big desktop ? 00120 dialogHeight = 800; 00121 else if (deskHeight > 650) // big desktop ? 00122 dialogHeight = 500; 00123 else // small (800x600, 640x480) desktop 00124 dialogHeight = 400; 00125 TQSize sz = scrollView->sizeHint(); 00126 scrollView->setMinimumSize( sz.width() 00127 + scrollView->style().pixelMetric(TQStyle::PM_ScrollBarExtent), 00128 TQMIN( compGUI->sizeHint().height(), dialogHeight ) ); 00129 } 00130 if ( mComponentGUIs.empty() ) { 00131 Q_ASSERT( face() == Plain ); 00132 const TQString msg = i18n("The gpgconf tool used to provide the information " 00133 "for this dialog does not seem to be installed " 00134 "properly. It did not return any components. " 00135 "Try running \"%1\" on the command line for more " 00136 "information.") 00137 .arg( components.empty() ? "gpgconf --list-components" : "gpgconf --list-options gpg" ); 00138 TQLabel * label = new TQLabel( msg, vbox ); 00139 label->setAlignment( TQt::WordBreak ); 00140 label->setMinimumHeight( fontMetrics().lineSpacing() * 5 ); 00141 } 00142 } 00143 00144 bool Kleo::CryptoConfigModule::hasError() const { 00145 return mComponentGUIs.empty(); 00146 } 00147 00148 void Kleo::CryptoConfigModule::save() 00149 { 00150 bool changed = false; 00151 TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin(); 00152 for( ; it != mComponentGUIs.end(); ++it ) { 00153 if ( (*it)->save() ) 00154 changed = true; 00155 } 00156 if ( changed ) 00157 mConfig->sync(true /*runtime*/); 00158 } 00159 00160 void Kleo::CryptoConfigModule::reset() 00161 { 00162 TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin(); 00163 for( ; it != mComponentGUIs.end(); ++it ) { 00164 (*it)->load(); 00165 } 00166 } 00167 00168 void Kleo::CryptoConfigModule::defaults() 00169 { 00170 TQValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin(); 00171 for( ; it != mComponentGUIs.end(); ++it ) { 00172 (*it)->defaults(); 00173 } 00174 } 00175 00176 void Kleo::CryptoConfigModule::cancel() 00177 { 00178 mConfig->clear(); 00179 } 00180 00182 00183 Kleo::CryptoConfigComponentGUI::CryptoConfigComponentGUI( 00184 CryptoConfigModule* module, Kleo::CryptoConfigComponent* component, 00185 TQWidget* parent, const char* name ) 00186 : TQWidget( parent, name ), 00187 mComponent( component ) 00188 { 00189 TQGridLayout * glay = new TQGridLayout( this, 1, 3, 0, KDialog::spacingHint() ); 00190 const TQStringList groups = mComponent->groupList(); 00191 if ( groups.size() > 1 ) { 00192 glay->setColSpacing( 0, KDHorizontalLine::indentHint() ); 00193 for ( TQStringList::const_iterator it = groups.begin(), end = groups.end() ; it != end; ++it ) { 00194 Kleo::CryptoConfigGroup* group = mComponent->group( *it ); 00195 Q_ASSERT( group ); 00196 if ( !group ) 00197 continue; 00198 KDHorizontalLine * hl = new KDHorizontalLine( group->description(), this ); 00199 const int row = glay->numRows(); 00200 glay->addMultiCellWidget( hl, row, row, 0, 2 ); 00201 mGroupGUIs.append( new CryptoConfigGroupGUI( module, group, glay, this ) ); 00202 } 00203 } else if ( !groups.empty() ) { 00204 mGroupGUIs.append( new CryptoConfigGroupGUI( module, mComponent->group( groups.front() ), glay, this ) ); 00205 } 00206 glay->setRowStretch( glay->numRows(), 1 ); 00207 } 00208 00209 00210 bool Kleo::CryptoConfigComponentGUI::save() 00211 { 00212 bool changed = false; 00213 TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin(); 00214 for( ; it != mGroupGUIs.end(); ++it ) { 00215 if ( (*it)->save() ) 00216 changed = true; 00217 } 00218 return changed; 00219 } 00220 00221 void Kleo::CryptoConfigComponentGUI::load() 00222 { 00223 TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin(); 00224 for( ; it != mGroupGUIs.end(); ++it ) 00225 (*it)->load(); 00226 } 00227 00228 void Kleo::CryptoConfigComponentGUI::defaults() 00229 { 00230 TQValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin(); 00231 for( ; it != mGroupGUIs.end(); ++it ) 00232 (*it)->defaults(); 00233 } 00234 00236 00237 Kleo::CryptoConfigGroupGUI::CryptoConfigGroupGUI( 00238 CryptoConfigModule* module, Kleo::CryptoConfigGroup* group, 00239 TQGridLayout * glay, TQWidget* widget, const char* name ) 00240 : TQObject( module, name ), mGroup( group ) 00241 { 00242 const int startRow = glay->numRows(); 00243 const TQStringList entries = mGroup->entryList(); 00244 for( TQStringList::const_iterator it = entries.begin(), end = entries.end() ; it != end; ++it ) { 00245 Kleo::CryptoConfigEntry* entry = group->entry( *it ); 00246 Q_ASSERT( entry ); 00247 if ( entry->level() > CryptoConfigEntry::Level_Advanced ) continue; 00248 CryptoConfigEntryGUI* entryGUI = 00249 CryptoConfigEntryGUIFactory::createEntryGUI( module, entry, *it, glay, widget ); 00250 if ( entryGUI ) { 00251 mEntryGUIs.append( entryGUI ); 00252 entryGUI->load(); 00253 } 00254 } 00255 const int endRow = glay->numRows() - 1; 00256 if ( endRow < startRow ) 00257 return; 00258 00259 const TQString iconName = group->iconName(); 00260 if ( iconName.isEmpty() ) 00261 return; 00262 00263 TQLabel * l = new TQLabel( widget ); 00264 l->setPixmap( loadIcon( iconName ) ); 00265 glay->addMultiCellWidget( l, startRow, endRow, 0, 0, TQt::AlignTop ); 00266 } 00267 00268 bool Kleo::CryptoConfigGroupGUI::save() 00269 { 00270 bool changed = false; 00271 TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin(); 00272 for( ; it != mEntryGUIs.end(); ++it ) { 00273 if ( (*it)->isChanged() ) { 00274 (*it)->save(); 00275 changed = true; 00276 } 00277 } 00278 return changed; 00279 } 00280 00281 void Kleo::CryptoConfigGroupGUI::load() 00282 { 00283 TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin(); 00284 for( ; it != mEntryGUIs.end(); ++it ) 00285 (*it)->load(); 00286 } 00287 00288 void Kleo::CryptoConfigGroupGUI::defaults() 00289 { 00290 TQValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin(); 00291 for( ; it != mEntryGUIs.end(); ++it ) 00292 (*it)->resetToDefault(); 00293 } 00294 00296 00297 CryptoConfigEntryGUI* Kleo::CryptoConfigEntryGUIFactory::createEntryGUI( CryptoConfigModule* module, Kleo::CryptoConfigEntry* entry, const TQString& entryName, TQGridLayout * glay, TQWidget* widget, const char* name ) 00298 { 00299 if ( entry->isList() ) { 00300 switch( entry->argType() ) { 00301 case Kleo::CryptoConfigEntry::ArgType_None: 00302 // A list of options with no arguments (e.g. -v -v -v) is shown as a spinbox 00303 return new CryptoConfigEntrySpinBox( module, entry, entryName, glay, widget, name ); 00304 case Kleo::CryptoConfigEntry::ArgType_Int: 00305 case Kleo::CryptoConfigEntry::ArgType_UInt: 00306 // Let people type list of numbers (1,2,3....). Untested. 00307 return new CryptoConfigEntryLineEdit( module, entry, entryName, glay, widget, name ); 00308 case Kleo::CryptoConfigEntry::ArgType_URL: 00309 case Kleo::CryptoConfigEntry::ArgType_Path: 00310 case Kleo::CryptoConfigEntry::ArgType_DirPath: 00311 case Kleo::CryptoConfigEntry::ArgType_String: 00312 kdWarning(5150) << "No widget implemented for list of type " << entry->argType() << endl; 00313 return 0; // TODO when the need arises :) 00314 case Kleo::CryptoConfigEntry::ArgType_LDAPURL: 00315 return new CryptoConfigEntryLDAPURL( module, entry, entryName, glay, widget, name ); 00316 } 00317 kdWarning(5150) << "No widget implemented for list of (unknown) type " << entry->argType() << endl; 00318 return 0; 00319 } 00320 00321 switch( entry->argType() ) { 00322 case Kleo::CryptoConfigEntry::ArgType_None: 00323 return new CryptoConfigEntryCheckBox( module, entry, entryName, glay, widget, name ); 00324 case Kleo::CryptoConfigEntry::ArgType_Int: 00325 case Kleo::CryptoConfigEntry::ArgType_UInt: 00326 return new CryptoConfigEntrySpinBox( module, entry, entryName, glay, widget, name ); 00327 case Kleo::CryptoConfigEntry::ArgType_URL: 00328 return new CryptoConfigEntryURL( module, entry, entryName, glay, widget, name ); 00329 case Kleo::CryptoConfigEntry::ArgType_Path: 00330 return new CryptoConfigEntryPath( module, entry, entryName, glay, widget, name ); 00331 case Kleo::CryptoConfigEntry::ArgType_DirPath: 00332 return new CryptoConfigEntryDirPath( module, entry, entryName, glay, widget, name ); 00333 case Kleo::CryptoConfigEntry::ArgType_LDAPURL: 00334 kdWarning(5150) << "No widget implemented for type " << entry->argType() << endl; 00335 return 0; // TODO when the need arises :) 00336 case Kleo::CryptoConfigEntry::ArgType_String: 00337 return new CryptoConfigEntryLineEdit( module, entry, entryName, glay, widget, name ); 00338 } 00339 kdWarning(5150) << "No widget implemented for (unknown) type " << entry->argType() << endl; 00340 return 0; 00341 } 00342 00344 00345 Kleo::CryptoConfigEntryGUI::CryptoConfigEntryGUI( 00346 CryptoConfigModule* module, 00347 Kleo::CryptoConfigEntry* entry, 00348 const TQString& entryName, 00349 const char* name ) 00350 : TQObject( module, name ), mEntry( entry ), mName( entryName ), mChanged( false ) 00351 { 00352 connect( this, TQT_SIGNAL( changed() ), module, TQT_SIGNAL( changed() ) ); 00353 } 00354 00355 TQString Kleo::CryptoConfigEntryGUI::description() const 00356 { 00357 TQString descr = mEntry->description(); 00358 if ( descr.isEmpty() ) // shouldn't happen 00359 descr = TQString( "<%1>" ).arg( mName ); 00360 return descr; 00361 } 00362 00363 void Kleo::CryptoConfigEntryGUI::resetToDefault() 00364 { 00365 mEntry->resetToDefault(); 00366 load(); 00367 } 00368 00370 00371 Kleo::CryptoConfigEntryLineEdit::CryptoConfigEntryLineEdit( 00372 CryptoConfigModule* module, 00373 Kleo::CryptoConfigEntry* entry, const TQString& entryName, 00374 TQGridLayout * glay, TQWidget* widget, const char* name ) 00375 : CryptoConfigEntryGUI( module, entry, entryName, name ) 00376 { 00377 const int row = glay->numRows(); 00378 mLineEdit = new KLineEdit( widget ); 00379 TQLabel* label = new TQLabel( mLineEdit, description(), widget ); 00380 glay->addWidget( label, row, 1 ); 00381 glay->addWidget( mLineEdit, row, 2 ); 00382 if ( entry->isReadOnly() ) { 00383 label->setEnabled( false ); 00384 mLineEdit->setEnabled( false ); 00385 } else { 00386 connect( mLineEdit, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotChanged() ) ); 00387 } 00388 } 00389 00390 void Kleo::CryptoConfigEntryLineEdit::doSave() 00391 { 00392 mEntry->setStringValue( mLineEdit->text() ); 00393 } 00394 00395 void Kleo::CryptoConfigEntryLineEdit::doLoad() 00396 { 00397 mLineEdit->setText( mEntry->stringValue() ); 00398 } 00399 00401 00402 Kleo::CryptoConfigEntryPath::CryptoConfigEntryPath( 00403 CryptoConfigModule* module, 00404 Kleo::CryptoConfigEntry* entry, const TQString& entryName, 00405 TQGridLayout * glay, TQWidget* widget, const char* name ) 00406 : CryptoConfigEntryGUI( module, entry, entryName, name ) 00407 { 00408 const int row = glay->numRows(); 00409 mUrlRequester = new KURLRequester( widget ); 00410 mUrlRequester->setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly ); 00411 TQLabel* label = new TQLabel( mUrlRequester, description(), widget ); 00412 glay->addWidget( label, row, 1 ); 00413 glay->addWidget( mUrlRequester, row, 2 ); 00414 if ( entry->isReadOnly() ) { 00415 label->setEnabled( false ); 00416 mUrlRequester->setEnabled( false ); 00417 } else { 00418 connect( mUrlRequester, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotChanged() ) ); 00419 } 00420 } 00421 00422 void Kleo::CryptoConfigEntryPath::doSave() 00423 { 00424 KURL url; 00425 url.setPath( mUrlRequester->url() ); 00426 mEntry->setURLValue( url ); 00427 } 00428 00429 void Kleo::CryptoConfigEntryPath::doLoad() 00430 { 00431 mUrlRequester->setURL( mEntry->urlValue().path() ); 00432 } 00433 00435 00436 Kleo::CryptoConfigEntryDirPath::CryptoConfigEntryDirPath( 00437 CryptoConfigModule* module, 00438 Kleo::CryptoConfigEntry* entry, const TQString& entryName, 00439 TQGridLayout * glay, TQWidget* widget, const char* name ) 00440 : CryptoConfigEntryGUI( module, entry, entryName, name ) 00441 { 00442 const int row = glay->numRows(); 00443 mUrlRequester = new KURLRequester( widget ); 00444 mUrlRequester->setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly ); 00445 TQLabel* label = new TQLabel( mUrlRequester, description(), widget ); 00446 glay->addWidget( label, row, 1 ); 00447 glay->addWidget( mUrlRequester, row, 2 ); 00448 if ( entry->isReadOnly() ) { 00449 label->setEnabled( false ); 00450 mUrlRequester->setEnabled( false ); 00451 } else { 00452 connect( mUrlRequester, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotChanged() ) ); 00453 } 00454 } 00455 00456 void Kleo::CryptoConfigEntryDirPath::doSave() 00457 { 00458 KURL url; 00459 url.setPath( mUrlRequester->url() ); 00460 mEntry->setURLValue( url ); 00461 00462 } 00463 00464 void Kleo::CryptoConfigEntryDirPath::doLoad() 00465 { 00466 mUrlRequester->setURL( mEntry->urlValue().path() ); 00467 } 00468 00470 00471 Kleo::CryptoConfigEntryURL::CryptoConfigEntryURL( 00472 CryptoConfigModule* module, 00473 Kleo::CryptoConfigEntry* entry, const TQString& entryName, 00474 TQGridLayout * glay, TQWidget* widget, const char* name ) 00475 : CryptoConfigEntryGUI( module, entry, entryName, name ) 00476 { 00477 const int row = glay->numRows(); 00478 mUrlRequester = new KURLRequester( widget ); 00479 mUrlRequester->setMode( KFile::File | KFile::ExistingOnly ); 00480 TQLabel* label = new TQLabel( mUrlRequester, description(), widget ); 00481 glay->addWidget( label, row, 1 ); 00482 glay->addWidget( mUrlRequester, row, 2 ); 00483 if ( entry->isReadOnly() ) { 00484 label->setEnabled( false ); 00485 mUrlRequester->setEnabled( false ); 00486 } else { 00487 connect( mUrlRequester, TQT_SIGNAL( textChanged( const TQString& ) ), TQT_SLOT( slotChanged() ) ); 00488 } 00489 } 00490 00491 void Kleo::CryptoConfigEntryURL::doSave() 00492 { 00493 mEntry->setURLValue( mUrlRequester->url() ); 00494 } 00495 00496 void Kleo::CryptoConfigEntryURL::doLoad() 00497 { 00498 mUrlRequester->setURL( mEntry->urlValue().url() ); 00499 } 00500 00502 00503 Kleo::CryptoConfigEntrySpinBox::CryptoConfigEntrySpinBox( 00504 CryptoConfigModule* module, 00505 Kleo::CryptoConfigEntry* entry, const TQString& entryName, 00506 TQGridLayout * glay, TQWidget* widget, const char* name ) 00507 : CryptoConfigEntryGUI( module, entry, entryName, name ) 00508 { 00509 00510 if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_None && entry->isList() ) { 00511 mKind = ListOfNone; 00512 } else if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_UInt ) { 00513 mKind = UInt; 00514 } else { 00515 Q_ASSERT( entry->argType() == Kleo::CryptoConfigEntry::ArgType_Int ); 00516 mKind = Int; 00517 } 00518 00519 const int row = glay->numRows(); 00520 mNumInput = new KIntNumInput( widget ); 00521 TQLabel* label = new TQLabel( mNumInput, description(), widget ); 00522 glay->addWidget( label, row, 1 ); 00523 glay->addWidget( mNumInput, row, 2 ); 00524 00525 if ( entry->isReadOnly() ) { 00526 label->setEnabled( false ); 00527 mNumInput->setEnabled( false ); 00528 } else { 00529 if ( mKind == UInt || mKind == ListOfNone ) 00530 mNumInput->setMinValue( 0 ); 00531 connect( mNumInput, TQT_SIGNAL( valueChanged(int) ), TQT_SLOT( slotChanged() ) ); 00532 } 00533 } 00534 00535 void Kleo::CryptoConfigEntrySpinBox::doSave() 00536 { 00537 int value = mNumInput->value(); 00538 switch ( mKind ) { 00539 case ListOfNone: 00540 mEntry->setNumberOfTimesSet( value ); 00541 break; 00542 case UInt: 00543 mEntry->setUIntValue( value ); 00544 break; 00545 case Int: 00546 mEntry->setIntValue( value ); 00547 break; 00548 } 00549 } 00550 00551 void Kleo::CryptoConfigEntrySpinBox::doLoad() 00552 { 00553 int value = 0; 00554 switch ( mKind ) { 00555 case ListOfNone: 00556 value = mEntry->numberOfTimesSet(); 00557 break; 00558 case UInt: 00559 value = mEntry->uintValue(); 00560 break; 00561 case Int: 00562 value = mEntry->intValue(); 00563 break; 00564 } 00565 mNumInput->setValue( value ); 00566 } 00567 00569 00570 Kleo::CryptoConfigEntryCheckBox::CryptoConfigEntryCheckBox( 00571 CryptoConfigModule* module, 00572 Kleo::CryptoConfigEntry* entry, const TQString& entryName, 00573 TQGridLayout * glay, TQWidget* widget, const char* name ) 00574 : CryptoConfigEntryGUI( module, entry, entryName, name ) 00575 { 00576 const int row = glay->numRows(); 00577 mCheckBox = new TQCheckBox( widget ); 00578 glay->addMultiCellWidget( mCheckBox, row, row, 1, 2 ); 00579 mCheckBox->setText( description() ); 00580 if ( entry->isReadOnly() ) { 00581 mCheckBox->setEnabled( false ); 00582 } else { 00583 connect( mCheckBox, TQT_SIGNAL( toggled(bool) ), TQT_SLOT( slotChanged() ) ); 00584 } 00585 } 00586 00587 void Kleo::CryptoConfigEntryCheckBox::doSave() 00588 { 00589 mEntry->setBoolValue( mCheckBox->isChecked() ); 00590 } 00591 00592 void Kleo::CryptoConfigEntryCheckBox::doLoad() 00593 { 00594 mCheckBox->setChecked( mEntry->boolValue() ); 00595 } 00596 00597 Kleo::CryptoConfigEntryLDAPURL::CryptoConfigEntryLDAPURL( 00598 CryptoConfigModule* module, 00599 Kleo::CryptoConfigEntry* entry, 00600 const TQString& entryName, 00601 TQGridLayout * glay, TQWidget* widget, const char* name ) 00602 : CryptoConfigEntryGUI( module, entry, entryName, name ) 00603 { 00604 mLabel = new TQLabel( widget ); 00605 mPushButton = new TQPushButton( i18n( "Edit..." ), widget ); 00606 00607 const int row = glay->numRows(); 00608 glay->addWidget( new TQLabel( mPushButton, description(), widget ), row, 1 ); 00609 TQHBoxLayout * hlay = new TQHBoxLayout; 00610 glay->addLayout( hlay, row, 2 ); 00611 hlay->addWidget( mLabel, 1 ); 00612 hlay->addWidget( mPushButton ); 00613 00614 if ( entry->isReadOnly() ) { 00615 mLabel->setEnabled( false ); 00616 mPushButton->hide(); 00617 } else { 00618 connect( mPushButton, TQT_SIGNAL( clicked() ), TQT_SLOT( slotOpenDialog() ) ); 00619 } 00620 } 00621 00622 void Kleo::CryptoConfigEntryLDAPURL::doLoad() 00623 { 00624 setURLList( mEntry->urlValueList() ); 00625 } 00626 00627 void Kleo::CryptoConfigEntryLDAPURL::doSave() 00628 { 00629 mEntry->setURLValueList( mURLList ); 00630 } 00631 00632 void Kleo::CryptoConfigEntryLDAPURL::slotOpenDialog() 00633 { 00634 // I'm a bad boy and I do it all on the stack. Enough classes already :) 00635 // This is just a simple dialog around the directory-services-widget 00636 KDialogBase dialog( mPushButton->parentWidget(), 0, true /*modal*/, 00637 i18n( "Configure LDAP Servers" ), 00638 KDialogBase::Default|KDialogBase::Cancel|KDialogBase::Ok, 00639 KDialogBase::Ok, true /*separator*/ ); 00640 DirectoryServicesWidget* dirserv = new DirectoryServicesWidget( mEntry, &dialog ); 00641 dirserv->load(); 00642 dialog.setMainWidget( dirserv ); 00643 connect( &dialog, TQT_SIGNAL( defaultClicked() ), dirserv, TQT_SLOT( defaults() ) ); 00644 if ( dialog.exec() ) { 00645 // Note that we just grab the urls from the dialog, we don't call its save method, 00646 // since the user hasn't confirmed the big config dialog yet. 00647 setURLList( dirserv->urlList() ); 00648 slotChanged(); 00649 } 00650 } 00651 00652 void Kleo::CryptoConfigEntryLDAPURL::setURLList( const KURL::List& urlList ) 00653 { 00654 mURLList = urlList; 00655 if ( mURLList.isEmpty() ) 00656 mLabel->setText( i18n( "No server configured yet" ) ); 00657 else 00658 mLabel->setText( i18n( "1 server configured", "%n servers configured", mURLList.count() ) ); 00659 } 00660 00661 #include "cryptoconfigmodule.moc" 00662 #include "cryptoconfigmodule_p.moc"