certmanager/lib

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