certmanager/lib Library API Documentation

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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 Qt library by Trolltech AS, Norway (or with modified versions
00023     of Qt that use the same license as Qt), 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     Qt.  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 <qgrid.h>
00049 #include <qlabel.h>
00050 #include <qlayout.h>
00051 #include <qvbox.h>
00052 #include <qpushbutton.h>
00053 #include <qregexp.h>
00054 #include <qstyle.h>
00055 #include <qapplication.h>
00056 
00057 using namespace Kleo;
00058 
00059 static inline QPixmap loadIcon( QString s ) {
00060   return KGlobal::instance()->iconLoader()
00061     ->loadIcon( s.replace( QRegExp( "[^a-zA-Z0-9_]" ), "_" ), KIcon::NoGroup, KIcon::SizeMedium );
00062 }
00063 
00064 static const KJanusWidget::Face determineJanusFace( const Kleo::CryptoConfig * config ) {
00065   return config && config->componentList().size() < 2
00066     ? KJanusWidget::Plain
00067     : KJanusWidget::IconList ;
00068 }
00069 
00070 Kleo::CryptoConfigModule::CryptoConfigModule( Kleo::CryptoConfig* config, QWidget * parent, const char * name )
00071   : KJanusWidget( parent, name, determineJanusFace( config ) ), mConfig( config )
00072 {
00073   QWidget * vbox = 0;
00074   if ( face() == Plain ) {
00075     vbox = plainPage();
00076     QVBoxLayout * vlay = new QVBoxLayout( vbox, 0, KDialog::spacingHint() );
00077     vlay->setAutoAdd( true );
00078   }
00079 
00080   const QStringList components = config->componentList();
00081   for ( QStringList::const_iterator it = components.begin(); it != components.end(); ++it ) {
00082     //kdDebug(5150) << "Component " << (*it).local8Bit() << ":" << endl;
00083     Kleo::CryptoConfigComponent* comp = config->component( *it );
00084     Q_ASSERT( comp );
00085     if ( comp->groupList().empty() )
00086       continue;
00087     if ( face() != Plain ) {
00088       vbox = addVBoxPage( comp->description(), QString::null, loadIcon( comp->iconName() ) );
00089     }
00090 
00091     QScrollView * scrollView = new QScrollView( vbox );
00092     scrollView->setHScrollBarMode( QScrollView::AlwaysOff );
00093     scrollView->setResizePolicy( QScrollView::AutoOneFit );
00094     QVBox* boxInScrollView = new QVBox( scrollView->viewport() );
00095     boxInScrollView->setMargin( KDialog::marginHint() );
00096     scrollView->addChild( boxInScrollView );
00097 
00098     CryptoConfigComponentGUI* compGUI =
00099       new CryptoConfigComponentGUI( this, comp, boxInScrollView, (*it).local8Bit() );
00100     // KJanusWidget doesn't seem to have iterators, so we store a copy...
00101     mComponentGUIs.append( compGUI );
00102 
00103     // Set a nice startup size
00104     const int deskHeight = QApplication::desktop()->height();
00105     int dialogHeight;
00106     if (deskHeight > 1000) // very big desktop ?
00107       dialogHeight = 800;
00108     else if (deskHeight > 650) // big desktop ?
00109       dialogHeight = 500;
00110     else // small (800x600, 640x480) desktop
00111       dialogHeight = 400;
00112     QSize sz = scrollView->sizeHint();
00113     scrollView->setMinimumSize( sz.width()
00114                                 + scrollView->style().pixelMetric(QStyle::PM_ScrollBarExtent),
00115                                 QMIN( compGUI->sizeHint().height(), dialogHeight ) );
00116   }
00117 }
00118 
00119 void Kleo::CryptoConfigModule::save()
00120 {
00121   bool changed = false;
00122   QValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
00123   for( ; it != mComponentGUIs.end(); ++it ) {
00124     if ( (*it)->save() )
00125       changed = true;
00126   }
00127   if ( changed )
00128     mConfig->sync(true /*runtime*/);
00129 }
00130 
00131 void Kleo::CryptoConfigModule::reset()
00132 {
00133   QValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
00134   for( ; it != mComponentGUIs.end(); ++it ) {
00135     (*it)->load();
00136   }
00137 }
00138 
00139 void Kleo::CryptoConfigModule::defaults()
00140 {
00141   QValueList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
00142   for( ; it != mComponentGUIs.end(); ++it ) {
00143     (*it)->defaults();
00144   }
00145 }
00146 
00147 void Kleo::CryptoConfigModule::cancel()
00148 {
00149   mConfig->clear();
00150 }
00151 
00153 
00154 Kleo::CryptoConfigComponentGUI::CryptoConfigComponentGUI(
00155   CryptoConfigModule* module, Kleo::CryptoConfigComponent* component,
00156   QWidget* parent, const char* name )
00157   : QWidget( parent, name ),
00158     mComponent( component )
00159 {
00160   QGridLayout * glay = new QGridLayout( this, 1, 3, 0, KDialog::spacingHint() );
00161   const QStringList groups = mComponent->groupList();
00162   if ( groups.size() > 1 ) {
00163     glay->setColSpacing( 0, KDHorizontalLine::indentHint() );
00164     for ( QStringList::const_iterator it = groups.begin(), end = groups.end() ; it != end; ++it ) {
00165       Kleo::CryptoConfigGroup* group = mComponent->group( *it );
00166       Q_ASSERT( group );
00167       if ( !group )
00168         continue;
00169       KDHorizontalLine * hl = new KDHorizontalLine( group->description(), this );
00170       const int row = glay->numRows();
00171       glay->addMultiCellWidget( hl, row, row, 0, 2 );
00172       mGroupGUIs.append( new CryptoConfigGroupGUI( module, group, glay, this ) );
00173     }
00174   } else if ( !groups.empty() ) {
00175     mGroupGUIs.append( new CryptoConfigGroupGUI( module, mComponent->group( groups.front() ), glay, this ) );
00176   }
00177   glay->setRowStretch( glay->numRows(), 1 );
00178 }
00179 
00180 
00181 bool Kleo::CryptoConfigComponentGUI::save()
00182 {
00183   bool changed = false;
00184   QValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
00185   for( ; it != mGroupGUIs.end(); ++it ) {
00186     if ( (*it)->save() )
00187       changed = true;
00188   }
00189   return changed;
00190 }
00191 
00192 void Kleo::CryptoConfigComponentGUI::load()
00193 {
00194   QValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
00195   for( ; it != mGroupGUIs.end(); ++it )
00196     (*it)->load();
00197 }
00198 
00199 void Kleo::CryptoConfigComponentGUI::defaults()
00200 {
00201   QValueList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
00202   for( ; it != mGroupGUIs.end(); ++it )
00203     (*it)->defaults();
00204 }
00205 
00207 
00208 Kleo::CryptoConfigGroupGUI::CryptoConfigGroupGUI(
00209   CryptoConfigModule* module, Kleo::CryptoConfigGroup* group,
00210   QGridLayout * glay, QWidget* widget, const char* name )
00211   : QObject( module, name ), mGroup( group )
00212 {
00213   const int startRow = glay->numRows();
00214   const QStringList entries = mGroup->entryList();
00215   for( QStringList::const_iterator it = entries.begin(), end = entries.end() ; it != end; ++it ) {
00216     Kleo::CryptoConfigEntry* entry = group->entry( *it );
00217     Q_ASSERT( entry );
00218     if ( entry->level() > CryptoConfigEntry::Level_Advanced ) continue;
00219     CryptoConfigEntryGUI* entryGUI =
00220       CryptoConfigEntryGUIFactory::createEntryGUI( module, entry, *it, glay, widget );
00221     if ( entryGUI ) {
00222       mEntryGUIs.append( entryGUI );
00223       entryGUI->load();
00224     }
00225   }
00226   const int endRow = glay->numRows() - 1;
00227   if ( endRow < startRow )
00228     return;
00229 
00230   const QString iconName = group->iconName();
00231   if ( iconName.isEmpty() )
00232     return;
00233 
00234   QLabel * l = new QLabel( widget );
00235   l->setPixmap( loadIcon( iconName ) );
00236   glay->addMultiCellWidget( l, startRow, endRow, 0, 0, Qt::AlignTop );
00237 }
00238 
00239 bool Kleo::CryptoConfigGroupGUI::save()
00240 {
00241   bool changed = false;
00242   QValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
00243   for( ; it != mEntryGUIs.end(); ++it ) {
00244     if ( (*it)->isChanged() ) {
00245       (*it)->save();
00246       changed = true;
00247     }
00248   }
00249   return changed;
00250 }
00251 
00252 void Kleo::CryptoConfigGroupGUI::load()
00253 {
00254   QValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
00255   for( ; it != mEntryGUIs.end(); ++it )
00256     (*it)->load();
00257 }
00258 
00259 void Kleo::CryptoConfigGroupGUI::defaults()
00260 {
00261   QValueList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
00262   for( ; it != mEntryGUIs.end(); ++it )
00263     (*it)->resetToDefault();
00264 }
00265 
00267 
00268 CryptoConfigEntryGUI* Kleo::CryptoConfigEntryGUIFactory::createEntryGUI( CryptoConfigModule* module, Kleo::CryptoConfigEntry* entry, const QString& entryName, QGridLayout * glay, QWidget* widget, const char* name )
00269 {
00270   if ( entry->isList() ) {
00271     switch( entry->argType() ) {
00272     case Kleo::CryptoConfigEntry::ArgType_None:
00273       // A list of options with no arguments (e.g. -v -v -v) is shown as a spinbox
00274       return new CryptoConfigEntrySpinBox( module, entry, entryName, glay, widget, name );
00275     case Kleo::CryptoConfigEntry::ArgType_Int:
00276     case Kleo::CryptoConfigEntry::ArgType_UInt:
00277       // Let people type list of numbers (1,2,3....). Untested.
00278       return new CryptoConfigEntryLineEdit( module, entry, entryName, glay, widget, name );
00279     case Kleo::CryptoConfigEntry::ArgType_URL:
00280     case Kleo::CryptoConfigEntry::ArgType_Path:
00281     case Kleo::CryptoConfigEntry::ArgType_DirPath:
00282     case Kleo::CryptoConfigEntry::ArgType_String:
00283       kdWarning(5150) << "No widget implemented for list of type " << entry->argType() << endl;
00284       return 0; // TODO when the need arises :)
00285     case Kleo::CryptoConfigEntry::ArgType_LDAPURL:
00286       return new CryptoConfigEntryLDAPURL( module, entry, entryName, glay, widget, name );
00287     }
00288     kdWarning(5150) << "No widget implemented for list of (unknown) type " << entry->argType() << endl;
00289     return 0;
00290   }
00291 
00292   switch( entry->argType() ) {
00293   case Kleo::CryptoConfigEntry::ArgType_None:
00294     return new CryptoConfigEntryCheckBox( module, entry, entryName, glay, widget, name );
00295   case Kleo::CryptoConfigEntry::ArgType_Int:
00296   case Kleo::CryptoConfigEntry::ArgType_UInt:
00297     return new CryptoConfigEntrySpinBox( module, entry, entryName, glay, widget, name );
00298   case Kleo::CryptoConfigEntry::ArgType_URL:
00299     return new CryptoConfigEntryURL( module, entry, entryName, glay, widget, name );
00300   case Kleo::CryptoConfigEntry::ArgType_Path:
00301     return new CryptoConfigEntryPath( module, entry, entryName, glay, widget, name );
00302   case Kleo::CryptoConfigEntry::ArgType_DirPath:
00303     return new CryptoConfigEntryDirPath( module, entry, entryName, glay, widget, name );
00304   case Kleo::CryptoConfigEntry::ArgType_LDAPURL:
00305       kdWarning(5150) << "No widget implemented for type " << entry->argType() << endl;
00306       return 0; // TODO when the need arises :)
00307   case Kleo::CryptoConfigEntry::ArgType_String:
00308     return new CryptoConfigEntryLineEdit( module, entry, entryName, glay, widget, name );
00309   }
00310   kdWarning(5150) << "No widget implemented for (unknown) type " << entry->argType() << endl;
00311   return 0;
00312 }
00313 
00315 
00316 Kleo::CryptoConfigEntryGUI::CryptoConfigEntryGUI(
00317   CryptoConfigModule* module,
00318   Kleo::CryptoConfigEntry* entry,
00319   const QString& entryName,
00320   const char* name )
00321   : QObject( module, name ), mEntry( entry ), mName( entryName ), mChanged( false )
00322 {
00323   connect( this, SIGNAL( changed() ), module, SIGNAL( changed() ) );
00324 }
00325 
00326 QString Kleo::CryptoConfigEntryGUI::description() const
00327 {
00328   QString descr = mEntry->description();
00329   if ( descr.isEmpty() ) // shouldn't happen
00330     descr = QString( "<%1>" ).arg( mName );
00331   return descr;
00332 }
00333 
00334 void Kleo::CryptoConfigEntryGUI::resetToDefault()
00335 {
00336   mEntry->resetToDefault();
00337   load();
00338 }
00339 
00341 
00342 Kleo::CryptoConfigEntryLineEdit::CryptoConfigEntryLineEdit(
00343   CryptoConfigModule* module,
00344   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00345   QGridLayout * glay, QWidget* widget, const char* name )
00346   : CryptoConfigEntryGUI( module, entry, entryName, name )
00347 {
00348   const int row = glay->numRows();
00349   mLineEdit = new KLineEdit( widget );
00350   QLabel* label = new QLabel( mLineEdit, description(), widget );
00351   glay->addWidget( label, row, 1 );
00352   glay->addWidget( mLineEdit, row, 2 );
00353   if ( entry->isReadOnly() ) {
00354     label->setEnabled( false );
00355     mLineEdit->setEnabled( false );
00356   } else {
00357     connect( mLineEdit, SIGNAL( textChanged( const QString& ) ), SLOT( slotChanged() ) );
00358   }
00359 }
00360 
00361 void Kleo::CryptoConfigEntryLineEdit::doSave()
00362 {
00363   mEntry->setStringValue( mLineEdit->text() );
00364 }
00365 
00366 void Kleo::CryptoConfigEntryLineEdit::doLoad()
00367 {
00368   mLineEdit->setText( mEntry->stringValue() );
00369 }
00370 
00372 
00373 Kleo::CryptoConfigEntryPath::CryptoConfigEntryPath(
00374   CryptoConfigModule* module,
00375   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00376   QGridLayout * glay, QWidget* widget, const char* name )
00377   : CryptoConfigEntryGUI( module, entry, entryName, name )
00378 {
00379   const int row = glay->numRows();
00380   mUrlRequester = new KURLRequester( widget );
00381   mUrlRequester->setMode( KFile::File | KFile::ExistingOnly | KFile::LocalOnly );
00382   QLabel* label = new QLabel( mUrlRequester, description(), widget );
00383   glay->addWidget( label, row, 1 );
00384   glay->addWidget( mUrlRequester, row, 2 );
00385   if ( entry->isReadOnly() ) {
00386     label->setEnabled( false );
00387     mUrlRequester->setEnabled( false );
00388   } else {
00389     connect( mUrlRequester, SIGNAL( textChanged( const QString& ) ), SLOT( slotChanged() ) );
00390   }
00391 }
00392 
00393 void Kleo::CryptoConfigEntryPath::doSave()
00394 {
00395   KURL url;
00396   url.setPath( mUrlRequester->url() );
00397   mEntry->setURLValue( url );
00398 }
00399 
00400 void Kleo::CryptoConfigEntryPath::doLoad()
00401 {
00402   mUrlRequester->setURL( mEntry->urlValue().path() );
00403 }
00404 
00406 
00407 Kleo::CryptoConfigEntryDirPath::CryptoConfigEntryDirPath(
00408   CryptoConfigModule* module,
00409   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00410   QGridLayout * glay, QWidget* widget, const char* name )
00411   : CryptoConfigEntryGUI( module, entry, entryName, name )
00412 {
00413   const int row = glay->numRows();
00414   mUrlRequester = new KURLRequester( widget );
00415   mUrlRequester->setMode( KFile::Directory | KFile::ExistingOnly | KFile::LocalOnly );
00416   QLabel* label = new QLabel( mUrlRequester, description(), widget );
00417   glay->addWidget( label, row, 1 );
00418   glay->addWidget( mUrlRequester, row, 2 );
00419   if ( entry->isReadOnly() ) {
00420     label->setEnabled( false );
00421     mUrlRequester->setEnabled( false );
00422   } else {
00423     connect( mUrlRequester, SIGNAL( textChanged( const QString& ) ), SLOT( slotChanged() ) );
00424   }
00425 }
00426 
00427 void Kleo::CryptoConfigEntryDirPath::doSave()
00428 {
00429   KURL url;
00430   url.setPath( mUrlRequester->url() );
00431   mEntry->setURLValue( url );
00432 
00433 }
00434 
00435 void Kleo::CryptoConfigEntryDirPath::doLoad()
00436 {
00437   mUrlRequester->setURL( mEntry->urlValue().path() );
00438 }
00439 
00441 
00442 Kleo::CryptoConfigEntryURL::CryptoConfigEntryURL(
00443   CryptoConfigModule* module,
00444   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00445   QGridLayout * glay, QWidget* widget, const char* name )
00446   : CryptoConfigEntryGUI( module, entry, entryName, name )
00447 {
00448   const int row = glay->numRows();
00449   mUrlRequester = new KURLRequester( widget );
00450   mUrlRequester->setMode( KFile::File | KFile::ExistingOnly );
00451   QLabel* label = new QLabel( mUrlRequester, description(), widget );
00452   glay->addWidget( label, row, 1 );
00453   glay->addWidget( mUrlRequester, row, 2 );
00454   if ( entry->isReadOnly() ) {
00455     label->setEnabled( false );
00456     mUrlRequester->setEnabled( false );
00457   } else {
00458     connect( mUrlRequester, SIGNAL( textChanged( const QString& ) ), SLOT( slotChanged() ) );
00459   }
00460 }
00461 
00462 void Kleo::CryptoConfigEntryURL::doSave()
00463 {
00464   mEntry->setURLValue( mUrlRequester->url() );
00465 }
00466 
00467 void Kleo::CryptoConfigEntryURL::doLoad()
00468 {
00469   mUrlRequester->setURL( mEntry->urlValue().url() );
00470 }
00471 
00473 
00474 Kleo::CryptoConfigEntrySpinBox::CryptoConfigEntrySpinBox(
00475   CryptoConfigModule* module,
00476   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00477   QGridLayout * glay, QWidget* widget, const char* name )
00478   : CryptoConfigEntryGUI( module, entry, entryName, name )
00479 {
00480 
00481   if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_None && entry->isList() ) {
00482     mKind = ListOfNone;
00483   } else if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_UInt ) {
00484     mKind = UInt;
00485   } else {
00486     Q_ASSERT( entry->argType() == Kleo::CryptoConfigEntry::ArgType_Int );
00487     mKind = Int;
00488   }
00489 
00490   const int row = glay->numRows();
00491   mNumInput = new KIntNumInput( widget );
00492   QLabel* label = new QLabel( mNumInput, description(), widget );
00493   glay->addWidget( label, row, 1 );
00494   glay->addWidget( mNumInput, row, 2 );
00495 
00496   if ( entry->isReadOnly() ) {
00497     label->setEnabled( false );
00498     mNumInput->setEnabled( false );
00499   } else {
00500     if ( mKind == UInt || mKind == ListOfNone )
00501       mNumInput->setMinValue( 0 );
00502     connect( mNumInput, SIGNAL( valueChanged(int) ), SLOT( slotChanged() ) );
00503   }
00504 }
00505 
00506 void Kleo::CryptoConfigEntrySpinBox::doSave()
00507 {
00508   int value = mNumInput->value();
00509   switch ( mKind ) {
00510   case ListOfNone:
00511     mEntry->setNumberOfTimesSet( value );
00512     break;
00513   case UInt:
00514     mEntry->setUIntValue( value );
00515     break;
00516   case Int:
00517     mEntry->setIntValue( value );
00518     break;
00519   }
00520 }
00521 
00522 void Kleo::CryptoConfigEntrySpinBox::doLoad()
00523 {
00524   int value = 0;
00525   switch ( mKind ) {
00526   case ListOfNone:
00527     value = mEntry->numberOfTimesSet();
00528     break;
00529   case UInt:
00530     value = mEntry->uintValue();
00531     break;
00532   case Int:
00533     value = mEntry->intValue();
00534     break;
00535   }
00536   mNumInput->setValue( value );
00537 }
00538 
00540 
00541 Kleo::CryptoConfigEntryCheckBox::CryptoConfigEntryCheckBox(
00542   CryptoConfigModule* module,
00543   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00544   QGridLayout * glay, QWidget* widget, const char* name )
00545   : CryptoConfigEntryGUI( module, entry, entryName, name )
00546 {
00547   const int row = glay->numRows();
00548   mCheckBox = new QCheckBox( widget );
00549   glay->addMultiCellWidget( mCheckBox, row, row, 1, 2 );
00550   mCheckBox->setText( description() );
00551   if ( entry->isReadOnly() ) {
00552     mCheckBox->setEnabled( false );
00553   } else {
00554     connect( mCheckBox, SIGNAL( toggled(bool) ), SLOT( slotChanged() ) );
00555   }
00556 }
00557 
00558 void Kleo::CryptoConfigEntryCheckBox::doSave()
00559 {
00560   mEntry->setBoolValue( mCheckBox->isChecked() );
00561 }
00562 
00563 void Kleo::CryptoConfigEntryCheckBox::doLoad()
00564 {
00565   mCheckBox->setChecked( mEntry->boolValue() );
00566 }
00567 
00568 Kleo::CryptoConfigEntryLDAPURL::CryptoConfigEntryLDAPURL(
00569   CryptoConfigModule* module,
00570   Kleo::CryptoConfigEntry* entry,
00571   const QString& entryName,
00572   QGridLayout * glay, QWidget* widget, const char* name )
00573   : CryptoConfigEntryGUI( module, entry, entryName, name )
00574 {
00575   mLabel = new QLabel( widget );
00576   mPushButton = new QPushButton( i18n( "Edit..." ), widget );
00577 
00578   const int row = glay->numRows();
00579   glay->addWidget( new QLabel( mPushButton, description(), widget ), row, 1 );
00580   QHBoxLayout * hlay = new QHBoxLayout;
00581   glay->addLayout( hlay, row, 2 );
00582   hlay->addWidget( mLabel, 1 );
00583   hlay->addWidget( mPushButton );
00584 
00585   if ( entry->isReadOnly() ) {
00586     mLabel->setEnabled( false );
00587     mPushButton->hide();
00588   } else {
00589     connect( mPushButton, SIGNAL( clicked() ), SLOT( slotOpenDialog() ) );
00590   }
00591 }
00592 
00593 void Kleo::CryptoConfigEntryLDAPURL::doLoad()
00594 {
00595   setURLList( mEntry->urlValueList() );
00596 }
00597 
00598 void Kleo::CryptoConfigEntryLDAPURL::doSave()
00599 {
00600   mEntry->setURLValueList( mURLList );
00601 }
00602 
00603 void Kleo::CryptoConfigEntryLDAPURL::slotOpenDialog()
00604 {
00605   // I'm a bad boy and I do it all on the stack. Enough classes already :)
00606   // This is just a simple dialog around the directory-services-widget
00607   KDialogBase dialog( mPushButton->parentWidget(), 0, true /*modal*/,
00608                       i18n( "Configure LDAP Servers" ),
00609                       KDialogBase::Default|KDialogBase::Cancel|KDialogBase::Ok,
00610                       KDialogBase::Ok, true /*separator*/ );
00611   DirectoryServicesWidget* dirserv = new DirectoryServicesWidget( mEntry, &dialog );
00612   dirserv->load();
00613   dialog.setMainWidget( dirserv );
00614   connect( &dialog, SIGNAL( defaultClicked() ), dirserv, SLOT( defaults() ) );
00615   if ( dialog.exec() ) {
00616     // Focus out any spinbox that might still have the focus - aegypten issue440
00617     // Not needed with kdelibs >= 3.4.
00618     dialog.actionButton( KDialogBase::Ok )->setFocus();
00619     // Note that we just grab the urls from the dialog, we don't call its save method,
00620     // since the user hasn't confirmed the big config dialog yet.
00621     setURLList( dirserv->urlList() );
00622     slotChanged();
00623   }
00624 }
00625 
00626 void Kleo::CryptoConfigEntryLDAPURL::setURLList( const KURL::List& urlList )
00627 {
00628   mURLList = urlList;
00629   if ( mURLList.isEmpty() )
00630     mLabel->setText( i18n( "No server configured yet" ) );
00631   else
00632     mLabel->setText( i18n( "1 server configured", "%n servers configured", mURLList.count() ) );
00633 }
00634 
00635 #include "cryptoconfigmodule.moc"
00636 #include "cryptoconfigmodule_p.moc"
KDE Logo
This file is part of the documentation for certmanager/lib Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Dec 21 14:23:03 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003