• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

libkleo

cryptoconfigmodule.cpp

Go to the documentation of this file.
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 #include "filenamerequester.h"
00037 
00038 #include "kleo/cryptoconfig.h"
00039 
00040 #include <klineedit.h>
00041 #include <klocale.h>
00042 #include <kdebug.h>
00043 #include <knuminput.h>
00044 #include <kiconloader.h>
00045 #include <kglobal.h>
00046 #include <kcomponentdata.h>
00047 #include <kicon.h>
00048 #ifndef ONLY_KLEO
00049 # include <kurlrequester.h>
00050 #endif
00051 
00052 #include <QApplication>
00053 #include <QLabel>
00054 #include <QLayout>
00055 #include <QPushButton>
00056 #include <QRegExp>
00057 #include <QPixmap>
00058 #include <QVBoxLayout>
00059 #include <QList>
00060 #include <QHBoxLayout>
00061 #include <QGridLayout>
00062 #include <QScrollArea>
00063 #include <QDesktopWidget>
00064 #include <QCheckBox>
00065 #include <QStyle>
00066 #include <QComboBox>
00067 
00068 #include <cassert>
00069 
00070 using namespace Kleo;
00071 
00072 namespace {
00073 
00074 class ScrollArea : public QScrollArea {
00075 public:
00076     explicit ScrollArea( QWidget* p ) : QScrollArea( p ) {}
00077     /* reimp */ QSize sizeHint() const {
00078         const QSize wsz = widget() ? widget()->sizeHint() : QSize();
00079         return QSize( wsz.width() + style()->pixelMetric( QStyle::PM_ScrollBarExtent ), QScrollArea::sizeHint().height() );
00080     }
00081 };
00082 
00083 }
00084 inline KIcon loadIcon( const QString &s ) {
00085   QString ss = s;
00086   return KIcon( ss.replace( QRegExp( "[^a-zA-Z0-9_]" ), "-" ) );
00087 }
00088 
00089 static const KPageView::FaceType determineJanusFace( const Kleo::CryptoConfig * config ) {
00090   return config && config->componentList().size() < 2
00091     ? KPageView::Plain
00092     : KPageView::List ;
00093 }
00094 
00095 Kleo::CryptoConfigModule::CryptoConfigModule( Kleo::CryptoConfig* config, QWidget * parent )
00096   : KPageWidget( parent ), mConfig( config )
00097 {
00098   const KPageView::FaceType type=determineJanusFace( config );
00099   setFaceType(type);
00100   QVBoxLayout * vlay = 0;
00101   QWidget * vbox = 0;
00102   if ( type == Plain ) {
00103     vbox = new QWidget(this);
00104     vlay = new QVBoxLayout( vbox );
00105     vlay->setSpacing( KDialog::spacingHint() );
00106     vlay->setMargin( 0 );
00107   }
00108 
00109   const QStringList components = config->componentList();
00110   for ( QStringList::const_iterator it = components.begin(); it != components.end(); ++it ) {
00111     //kDebug(5150) <<"Component" << (*it).toLocal8Bit() <<":";
00112     Kleo::CryptoConfigComponent* comp = config->component( *it );
00113     Q_ASSERT( comp );
00114     if ( comp->groupList().empty() )
00115       continue;
00116     if ( type != Plain ) {
00117       vbox = new QWidget(this);
00118       vlay = new QVBoxLayout( vbox );
00119       vlay->setSpacing( KDialog::spacingHint() );
00120       vlay->setMargin( 0 );
00121       KPageWidgetItem *pageItem = new KPageWidgetItem( vbox, comp->description() );
00122       pageItem->setIcon( loadIcon( comp->iconName() ) );
00123       addPage(pageItem);
00124     }
00125 
00126     ScrollArea* scrollArea = new ScrollArea( this );
00127     scrollArea->setWidgetResizable( true );
00128 
00129     vlay->addWidget( scrollArea );
00130 
00131     CryptoConfigComponentGUI* compGUI =
00132       new CryptoConfigComponentGUI( this, comp, scrollArea );
00133     compGUI->setObjectName( *it );
00134     scrollArea->setWidget( compGUI );
00135     scrollArea->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred );
00136     // KJanusWidget doesn't seem to have iterators, so we store a copy...
00137     mComponentGUIs.append( compGUI );
00138 
00139     // Set a nice startup size
00140     const int deskHeight = QApplication::desktop()->height();
00141     int dialogHeight;
00142     if (deskHeight > 1000) // very big desktop ?
00143       dialogHeight = 800;
00144     else if (deskHeight > 650) // big desktop ?
00145       dialogHeight = 500;
00146     else // small (800x600, 640x480) desktop
00147       dialogHeight = 400;
00148     assert( scrollArea->widget() );
00149     scrollArea->setMinimumHeight( qMin( compGUI->sizeHint().height(), dialogHeight ) );
00150   }
00151 }
00152 
00153 void Kleo::CryptoConfigModule::save()
00154 {
00155   bool changed = false;
00156   QList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
00157   for( ; it != mComponentGUIs.end(); ++it ) {
00158     if ( (*it)->save() )
00159       changed = true;
00160   }
00161   if ( changed )
00162     mConfig->sync(true /*runtime*/);
00163 }
00164 
00165 void Kleo::CryptoConfigModule::reset()
00166 {
00167   QList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
00168   for( ; it != mComponentGUIs.end(); ++it ) {
00169     (*it)->load();
00170   }
00171 }
00172 
00173 void Kleo::CryptoConfigModule::defaults()
00174 {
00175   QList<CryptoConfigComponentGUI *>::Iterator it = mComponentGUIs.begin();
00176   for( ; it != mComponentGUIs.end(); ++it ) {
00177     (*it)->defaults();
00178   }
00179 }
00180 
00181 void Kleo::CryptoConfigModule::cancel()
00182 {
00183   mConfig->clear();
00184 }
00185 
00187 
00188 Kleo::CryptoConfigComponentGUI::CryptoConfigComponentGUI(
00189   CryptoConfigModule* module, Kleo::CryptoConfigComponent* component,
00190   QWidget* parent )
00191   : QWidget( parent ),
00192     mComponent( component )
00193 {
00194   QGridLayout * glay = new QGridLayout( this );
00195   glay->setSpacing( KDialog::spacingHint() );
00196   const QStringList groups = mComponent->groupList();
00197   if ( groups.size() > 1 ) {
00198     glay->setColumnMinimumWidth( 0, KDHorizontalLine::indentHint() );
00199     for ( QStringList::const_iterator it = groups.begin(), end = groups.end() ; it != end; ++it ) {
00200       Kleo::CryptoConfigGroup* group = mComponent->group( *it );
00201       Q_ASSERT( group );
00202       if ( !group )
00203         continue;
00204       const QString title = group->description();
00205       KDHorizontalLine * hl = new KDHorizontalLine( title.isEmpty() ? *it : title, this );
00206       const int row = glay->rowCount();
00207       glay->addWidget( hl, row, 0, 1, 3 );
00208       mGroupGUIs.append( new CryptoConfigGroupGUI( module, group, glay, this ) );
00209     }
00210   } else if ( !groups.empty() ) {
00211     mGroupGUIs.append( new CryptoConfigGroupGUI( module, mComponent->group( groups.front() ), glay, this ) );
00212   }
00213   glay->setRowStretch( glay->rowCount(), 1 );
00214 }
00215 
00216 
00217 bool Kleo::CryptoConfigComponentGUI::save()
00218 {
00219   bool changed = false;
00220   QList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
00221   for( ; it != mGroupGUIs.end(); ++it ) {
00222     if ( (*it)->save() )
00223       changed = true;
00224   }
00225   return changed;
00226 }
00227 
00228 void Kleo::CryptoConfigComponentGUI::load()
00229 {
00230   QList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
00231   for( ; it != mGroupGUIs.end(); ++it )
00232     (*it)->load();
00233 }
00234 
00235 void Kleo::CryptoConfigComponentGUI::defaults()
00236 {
00237   QList<CryptoConfigGroupGUI *>::Iterator it = mGroupGUIs.begin();
00238   for( ; it != mGroupGUIs.end(); ++it )
00239     (*it)->defaults();
00240 }
00241 
00243 
00244 Kleo::CryptoConfigGroupGUI::CryptoConfigGroupGUI(
00245   CryptoConfigModule* module, Kleo::CryptoConfigGroup* group,
00246   QGridLayout * glay, QWidget* widget)
00247   : QObject( module ), mGroup( group )
00248 {
00249   const int startRow = glay->rowCount();
00250   const QStringList entries = mGroup->entryList();
00251   for( QStringList::const_iterator it = entries.begin(), end = entries.end() ; it != end; ++it ) {
00252     Kleo::CryptoConfigEntry* entry = group->entry( *it );
00253     Q_ASSERT( entry );
00254     if ( entry->level() > CryptoConfigEntry::Level_Advanced ) continue;
00255     CryptoConfigEntryGUI* entryGUI =
00256       CryptoConfigEntryGUIFactory::createEntryGUI( module, entry, *it, glay, widget );
00257     if ( entryGUI ) {
00258       mEntryGUIs.append( entryGUI );
00259       entryGUI->load();
00260     }
00261   }
00262   const int endRow = glay->rowCount() - 1;
00263   if ( endRow < startRow )
00264     return;
00265 
00266   const QString iconName = group->iconName();
00267   if ( iconName.isEmpty() )
00268     return;
00269 
00270   QLabel * l = new QLabel( widget );
00271   l->setPixmap( loadIcon( iconName ).pixmap( KIconLoader::SizeMedium, KIconLoader::SizeMedium ) );
00272   glay->addWidget( l, startRow, 0, endRow-startRow+1, 1, Qt::AlignTop );
00273 }
00274 
00275 bool Kleo::CryptoConfigGroupGUI::save()
00276 {
00277   bool changed = false;
00278   QList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
00279   for( ; it != mEntryGUIs.end(); ++it ) {
00280     if ( (*it)->isChanged() ) {
00281       (*it)->save();
00282       changed = true;
00283     }
00284   }
00285   return changed;
00286 }
00287 
00288 void Kleo::CryptoConfigGroupGUI::load()
00289 {
00290   QList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
00291   for( ; it != mEntryGUIs.end(); ++it )
00292     (*it)->load();
00293 }
00294 
00295 void Kleo::CryptoConfigGroupGUI::defaults()
00296 {
00297   QList<CryptoConfigEntryGUI *>::Iterator it = mEntryGUIs.begin();
00298   for( ; it != mEntryGUIs.end(); ++it )
00299     (*it)->resetToDefault();
00300 }
00301 
00303 
00304 typedef CryptoConfigEntryGUI * (*constructor)( CryptoConfigModule *, Kleo::CryptoConfigEntry *, const QString &, QGridLayout *, QWidget * );
00305 
00306 namespace {
00307 template <typename T_Widget>
00308 CryptoConfigEntryGUI * _create( CryptoConfigModule * m, Kleo::CryptoConfigEntry * e, const QString & n, QGridLayout * l, QWidget * p ) {
00309     return new T_Widget( m, e, n, l, p );
00310 }
00311 }
00312 
00313 static const struct WidgetsByEntryName {
00314     const char * entryGlob;
00315     constructor create;
00316 } widgetsByEntryName[] = {
00317     { "*/*/debug-level",   &_create<CryptoConfigEntryDebugLevel> },
00318     { "gpg/*/keyserver",   &_create<CryptoConfigEntryKeyserver>  }
00319 };
00320 static const unsigned int numWidgetsByEntryName = sizeof widgetsByEntryName / sizeof *widgetsByEntryName;
00321 
00322 static const constructor listWidgets[CryptoConfigEntry::NumArgType] = {
00323     // None: A list of options with no arguments (e.g. -v -v -v) is shown as a spinbox
00324     &_create<CryptoConfigEntrySpinBox>,
00325     0, // String
00326     // Int/UInt: Let people type list of numbers (1,2,3....). Untested.
00327     &_create<CryptoConfigEntryLineEdit>,
00328     &_create<CryptoConfigEntryLineEdit>,
00329     0, // Path
00330     0, // URL
00331     &_create<CryptoConfigEntryLDAPURL>,
00332     0, // DirPath
00333 };
00334 
00335 static const constructor scalarWidgets[CryptoConfigEntry::NumArgType] = {
00336   &_create<CryptoConfigEntryCheckBox>, // None
00337   &_create<CryptoConfigEntryLineEdit>, // String
00338   &_create<CryptoConfigEntrySpinBox>,  // Int
00339   &_create<CryptoConfigEntrySpinBox>,  // UInt
00340   &_create<CryptoConfigEntryPath>,     // Path
00341   &_create<CryptoConfigEntryURL>,      // URL
00342   0,                                   // LDAPURL
00343   &_create<CryptoConfigEntryDirPath>,  // DirPath
00344 };
00345 
00346 CryptoConfigEntryGUI* Kleo::CryptoConfigEntryGUIFactory::createEntryGUI( CryptoConfigModule* module, Kleo::CryptoConfigEntry* entry, const QString& entryName, QGridLayout * glay, QWidget* widget )
00347 {
00348     assert( entry );
00349 
00350     // try to lookup by path:
00351     const QString path = entry->path();
00352     for ( unsigned int i = 0 ; i < numWidgetsByEntryName ; ++i )
00353         if ( QRegExp( QLatin1String( widgetsByEntryName[i].entryGlob ), Qt::CaseSensitive, QRegExp::Wildcard ).exactMatch( path ) )
00354             return widgetsByEntryName[i].create( module, entry, entryName, glay, widget );
00355 
00356     // none found, so look up by type:
00357     const unsigned int argType = entry->argType();
00358     assert( argType < CryptoConfigEntry::NumArgType );
00359     if ( entry->isList() )
00360         if ( const constructor create = listWidgets[argType] )
00361             return create( module, entry, entryName, glay, widget );
00362         else
00363             kWarning(5150) <<"No widget implemented for list of type" << entry->argType();
00364     else
00365         if ( const constructor create = scalarWidgets[argType] )
00366             return create( module, entry, entryName, glay, widget );
00367         else
00368             kWarning(5150) <<"No widget implemented for type" << entry->argType();
00369 
00370     return 0;
00371 }
00372 
00374 
00375 Kleo::CryptoConfigEntryGUI::CryptoConfigEntryGUI(
00376   CryptoConfigModule* module,
00377   Kleo::CryptoConfigEntry* entry,
00378   const QString& entryName )
00379   : QObject( module ), mEntry( entry ), mName( entryName ), mChanged( false )
00380 {
00381   connect( this, SIGNAL( changed() ), module, SIGNAL( changed() ) );
00382 }
00383 
00384 QString Kleo::CryptoConfigEntryGUI::description() const
00385 {
00386     QString descr = mEntry->description();
00387     if ( descr.isEmpty() ) // shouldn't happen
00388         return QString( "<%1>" ).arg( mName );
00389     if ( i18nc( "Translate this to 'yes' or 'no' (use the English words!) "
00390                 "depending on whether your language uses "
00391                 "Sentence style capitalisation in GUI labels (yes) or not (no). "
00392                 "Context: We get some backend strings in that have the wrong "
00393                 "capitalizaion (in English, at least) so we need to force the "
00394                 "first character to upper-case. It is this behaviour you can "
00395                 "control for your language with this translation.", "yes" ) == QLatin1String( "yes" ) )
00396         descr[0] = descr[0].toUpper();
00397     return descr;
00398 }
00399 
00400 void Kleo::CryptoConfigEntryGUI::resetToDefault()
00401 {
00402   mEntry->resetToDefault();
00403   load();
00404 }
00405 
00407 
00408 Kleo::CryptoConfigEntryLineEdit::CryptoConfigEntryLineEdit(
00409   CryptoConfigModule* module,
00410   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00411   QGridLayout * glay, QWidget* widget )
00412   : CryptoConfigEntryGUI( module, entry, entryName )
00413 {
00414   const int row = glay->rowCount();
00415   mLineEdit = new KLineEdit( widget );
00416   QLabel *label = new QLabel( description(), widget );
00417   label->setBuddy( mLineEdit );
00418   glay->addWidget( label, row, 1 );
00419   glay->addWidget( mLineEdit, row, 2 );
00420   if ( entry->isReadOnly() ) {
00421     label->setEnabled( false );
00422     mLineEdit->setEnabled( false );
00423   } else {
00424     connect( mLineEdit, SIGNAL( textChanged( const QString& ) ), SLOT( slotChanged() ) );
00425   }
00426 }
00427 
00428 void Kleo::CryptoConfigEntryLineEdit::doSave()
00429 {
00430   mEntry->setStringValue( mLineEdit->text() );
00431 }
00432 
00433 void Kleo::CryptoConfigEntryLineEdit::doLoad()
00434 {
00435   mLineEdit->setText( mEntry->stringValue() );
00436 }
00437 
00439 
00440 static const struct {
00441     const char * label;
00442     const char * name;
00443 } debugLevels[] = {
00444     { I18N_NOOP( "None (no debugging at all)" ),               "none"     },
00445     { I18N_NOOP( "Basic (some basic debug messages)" ),        "basic"    },
00446     { I18N_NOOP( "Advanced (more verbose debug messages)" ),   "advanced" },
00447     { I18N_NOOP( "Expert (even more detailed messages)" ),     "expert"   },
00448     { I18N_NOOP( "Guru (all of the debug messages you can get)" ), "guru" },
00449 };
00450 static const unsigned int numDebugLevels = sizeof debugLevels / sizeof *debugLevels;
00451 
00452 Kleo::CryptoConfigEntryDebugLevel::CryptoConfigEntryDebugLevel( CryptoConfigModule * module, Kleo::CryptoConfigEntry * entry,
00453                                                                 const QString & entryName, QGridLayout * glay, QWidget * widget )
00454     : CryptoConfigEntryGUI( module, entry, entryName ),
00455       mComboBox( new QComboBox( widget ) )
00456 {
00457     QLabel *label = new QLabel( i18n("Set the debugging level to"), widget );
00458     label->setBuddy( mComboBox );
00459 
00460     for ( unsigned int i = 0 ; i < numDebugLevels ; ++i )
00461         mComboBox->addItem( i18n( debugLevels[i].label ) );
00462 
00463     if ( entry->isReadOnly() ) {
00464         label->setEnabled( false );
00465         mComboBox->setEnabled( false );
00466     } else {
00467         connect( mComboBox, SIGNAL(currentIndexChanged(int)), SLOT(slotChanged()) );
00468     }
00469 
00470     const int row = glay->rowCount();
00471     glay->addWidget( label, row, 1 );
00472     glay->addWidget( mComboBox, row, 2 );
00473 }
00474 
00475 void Kleo::CryptoConfigEntryDebugLevel::doSave()
00476 {
00477     const unsigned int idx = mComboBox->currentIndex();
00478     if ( idx < numDebugLevels )
00479         mEntry->setStringValue( QLatin1String( debugLevels[idx].name ) );
00480     else
00481         mEntry->setStringValue( QString() );
00482 }
00483 
00484 void Kleo::CryptoConfigEntryDebugLevel::doLoad()
00485 {
00486     const QString str = mEntry->stringValue();
00487     for ( unsigned int i = 0 ; i < numDebugLevels ; ++i )
00488         if ( str == QLatin1String( debugLevels[i].name ) ) {
00489             mComboBox->setCurrentIndex( i );
00490             return;
00491         }
00492     mComboBox->setCurrentIndex( 0 );
00493 }
00494 
00496 
00497 Kleo::CryptoConfigEntryPath::CryptoConfigEntryPath(
00498   CryptoConfigModule* module,
00499   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00500   QGridLayout * glay, QWidget* widget )
00501     : CryptoConfigEntryGUI( module, entry, entryName ),
00502       mUrlRequester( 0 ),
00503       mFileNameRequester( 0 )
00504 {
00505   const int row = glay->rowCount();
00506   QWidget * req;
00507 #ifdef ONLY_KLEO
00508   req = mFileNameRequester = new FileNameRequester( widget );
00509   mFileNameRequester->setExistingOnly( false );
00510   mFileNameRequester->setFilter( QDir::Files );
00511 #else
00512   req = mUrlRequester = new KUrlRequester( widget );
00513   mUrlRequester->setMode( KFile::File | KFile::LocalOnly );
00514 #endif
00515   QLabel *label = new QLabel( description(), widget );
00516   label->setBuddy( req );
00517   glay->addWidget( label, row, 1 );
00518   glay->addWidget( req, row, 2 );
00519   if ( entry->isReadOnly() ) {
00520     label->setEnabled( false );
00521 #ifndef ONLY_KLEO
00522     if ( mUrlRequester )
00523         mUrlRequester->setEnabled( false );
00524 #endif
00525     if ( mFileNameRequester )
00526         mFileNameRequester->setEnabled( false );
00527   } else {
00528 #ifndef ONLY_KLEO
00529       if ( mUrlRequester )
00530           connect( mUrlRequester, SIGNAL(textChanged(QString)),
00531                    this, SLOT(slotChanged()) );
00532 #endif
00533       if ( mFileNameRequester )
00534           connect( mFileNameRequester, SIGNAL(fileNameChanged(QString)),
00535                    this, SLOT(slotChanged()) );
00536   }
00537 }
00538 
00539 void Kleo::CryptoConfigEntryPath::doSave()
00540 {
00541 #ifdef ONLY_KLEO
00542   mEntry->setURLValue( KUrl::fromPath( mFileNameRequester->fileName() ) );
00543 #else
00544   mEntry->setURLValue( mUrlRequester->url() );
00545 #endif
00546 }
00547 
00548 void Kleo::CryptoConfigEntryPath::doLoad()
00549 {
00550 #ifdef ONLY_KLEO
00551   mFileNameRequester->setFileName( mEntry->urlValue().path() );
00552 #else
00553   mUrlRequester->setUrl( mEntry->urlValue() );
00554 #endif
00555 }
00556 
00558 
00559 Kleo::CryptoConfigEntryDirPath::CryptoConfigEntryDirPath(
00560   CryptoConfigModule* module,
00561   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00562   QGridLayout * glay, QWidget* widget )
00563     : CryptoConfigEntryGUI( module, entry, entryName ),
00564       mUrlRequester( 0 ),
00565       mFileNameRequester( 0 )
00566 {
00567   const int row = glay->rowCount();
00568   QWidget * req;
00569 #ifdef ONLY_KLEO
00570   req = mFileNameRequester = new FileNameRequester( widget );
00571   mFileNameRequester->setExistingOnly( false );
00572   mFileNameRequester->setFilter( QDir::Dirs );
00573 #else
00574   req = mUrlRequester = new KUrlRequester( widget );
00575   mUrlRequester->setMode( KFile::Directory | KFile::LocalOnly );
00576 #endif
00577   QLabel *label = new QLabel( description(), widget );
00578   label->setBuddy( req );
00579   glay->addWidget( label, row, 1 );
00580   glay->addWidget( req, row, 2 );
00581   if ( entry->isReadOnly() ) {
00582     label->setEnabled( false );
00583 #ifndef ONLY_KLEO
00584     if ( mUrlRequester )
00585         mUrlRequester->setEnabled( false );
00586 #endif
00587     if ( mFileNameRequester )
00588         mFileNameRequester->setEnabled( false );
00589   } else {
00590 #ifndef ONLY_KLEO
00591       if ( mUrlRequester )
00592           connect( mUrlRequester, SIGNAL(textChanged(QString)),
00593                    this, SLOT(slotChanged()) );
00594 #endif
00595       if ( mFileNameRequester )
00596           connect( mFileNameRequester, SIGNAL(fileNameChanged(QString)),
00597                    this, SLOT(slotChanged()) );
00598   }
00599 }
00600 
00601 void Kleo::CryptoConfigEntryDirPath::doSave()
00602 {
00603 #ifdef ONLY_KLEO
00604   mEntry->setURLValue( KUrl::fromPath( mFileNameRequester->fileName() ) );
00605 #else
00606   mEntry->setURLValue( mUrlRequester->url() );
00607 #endif
00608 }
00609 
00610 void Kleo::CryptoConfigEntryDirPath::doLoad()
00611 {
00612 #ifdef ONLY_KLEO
00613   mFileNameRequester->setFileName( mEntry->urlValue().path() );
00614 #else
00615   mUrlRequester->setUrl( mEntry->urlValue() );
00616 #endif
00617 }
00618 
00620 
00621 Kleo::CryptoConfigEntryURL::CryptoConfigEntryURL(
00622   CryptoConfigModule* module,
00623   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00624   QGridLayout * glay, QWidget* widget )
00625     : CryptoConfigEntryGUI( module, entry, entryName ),
00626     mLineEdit( 0 )
00627 #ifndef ONLY_KLEO
00628       , mUrlRequester( 0 )
00629 #endif
00630 {
00631   const int row = glay->rowCount();
00632   QWidget * req;
00633 #ifdef ONLY_KLEO
00634   req = mLineEdit = new QLineEdit( widget );
00635 #else
00636   req = mUrlRequester = new KUrlRequester( widget );
00637   mUrlRequester->setMode( KFile::File | KFile::ExistingOnly );
00638 #endif
00639   QLabel *label = new QLabel( description(), widget );
00640   label->setBuddy( req );
00641   glay->addWidget( label, row, 1 );
00642   glay->addWidget( req, row, 2 );
00643   if ( entry->isReadOnly() ) {
00644     label->setEnabled( false );
00645 #ifndef ONLY_KLEO
00646     if ( mUrlRequester )
00647         mUrlRequester->setEnabled( false );
00648 #endif
00649     if ( mLineEdit )
00650         mLineEdit->setEnabled( false );
00651   } else {
00652       connect( req, SIGNAL(textChanged(QString)),
00653                this, SLOT(slotChanged()) );
00654   }
00655 }
00656 
00657 void Kleo::CryptoConfigEntryURL::doSave()
00658 {
00659 #ifdef ONLY_KLEO
00660   mEntry->setURLValue( KUrl( mLineEdit->text() ) );
00661 #else
00662   mEntry->setURLValue( mUrlRequester->url() );
00663 #endif
00664 }
00665 
00666 void Kleo::CryptoConfigEntryURL::doLoad()
00667 {
00668 #ifdef ONLY_KLEO
00669   mLineEdit->setText( mEntry->urlValue().url() );
00670 #else
00671   mUrlRequester->setUrl( mEntry->urlValue().url() );
00672 #endif
00673 }
00674 
00676 
00677 Kleo::CryptoConfigEntrySpinBox::CryptoConfigEntrySpinBox(
00678   CryptoConfigModule* module,
00679   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00680   QGridLayout * glay, QWidget* widget )
00681   : CryptoConfigEntryGUI( module, entry, entryName )
00682 {
00683 
00684   if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_None && entry->isList() ) {
00685     mKind = ListOfNone;
00686   } else if ( entry->argType() == Kleo::CryptoConfigEntry::ArgType_UInt ) {
00687     mKind = UInt;
00688   } else {
00689     Q_ASSERT( entry->argType() == Kleo::CryptoConfigEntry::ArgType_Int );
00690     mKind = Int;
00691   }
00692 
00693   const int row = glay->rowCount();
00694   mNumInput = new KIntNumInput( widget );
00695   QLabel *label = new QLabel( description(), widget );
00696   label->setBuddy( mNumInput );
00697   glay->addWidget( label, row, 1 );
00698   glay->addWidget( mNumInput, row, 2 );
00699 
00700   if ( entry->isReadOnly() ) {
00701     label->setEnabled( false );
00702     mNumInput->setEnabled( false );
00703   } else {
00704     if ( mKind == UInt || mKind == ListOfNone )
00705       mNumInput->setMinimum( 0 );
00706     connect( mNumInput, SIGNAL( valueChanged(int) ), SLOT( slotChanged() ) );
00707   }
00708 }
00709 
00710 void Kleo::CryptoConfigEntrySpinBox::doSave()
00711 {
00712   int value = mNumInput->value();
00713   switch ( mKind ) {
00714   case ListOfNone:
00715     mEntry->setNumberOfTimesSet( value );
00716     break;
00717   case UInt:
00718     mEntry->setUIntValue( value );
00719     break;
00720   case Int:
00721     mEntry->setIntValue( value );
00722     break;
00723   }
00724 }
00725 
00726 void Kleo::CryptoConfigEntrySpinBox::doLoad()
00727 {
00728   int value = 0;
00729   switch ( mKind ) {
00730   case ListOfNone:
00731     value = mEntry->numberOfTimesSet();
00732     break;
00733   case UInt:
00734     value = mEntry->uintValue();
00735     break;
00736   case Int:
00737     value = mEntry->intValue();
00738     break;
00739   }
00740   mNumInput->setValue( value );
00741 }
00742 
00744 
00745 Kleo::CryptoConfigEntryCheckBox::CryptoConfigEntryCheckBox(
00746   CryptoConfigModule* module,
00747   Kleo::CryptoConfigEntry* entry, const QString& entryName,
00748   QGridLayout * glay, QWidget* widget )
00749   : CryptoConfigEntryGUI( module, entry, entryName )
00750 {
00751   const int row = glay->rowCount();
00752   mCheckBox = new QCheckBox( widget );
00753   glay->addWidget( mCheckBox, row, 1, 1, 2 );
00754   mCheckBox->setText( description() );
00755   if ( entry->isReadOnly() ) {
00756     mCheckBox->setEnabled( false );
00757   } else {
00758     connect( mCheckBox, SIGNAL( toggled(bool) ), SLOT( slotChanged() ) );
00759   }
00760 }
00761 
00762 void Kleo::CryptoConfigEntryCheckBox::doSave()
00763 {
00764   mEntry->setBoolValue( mCheckBox->isChecked() );
00765 }
00766 
00767 void Kleo::CryptoConfigEntryCheckBox::doLoad()
00768 {
00769   mCheckBox->setChecked( mEntry->boolValue() );
00770 }
00771 
00772 
00773 
00774 Kleo::CryptoConfigEntryLDAPURL::CryptoConfigEntryLDAPURL(
00775   CryptoConfigModule* module,
00776   Kleo::CryptoConfigEntry* entry,
00777   const QString& entryName,
00778   QGridLayout * glay, QWidget* widget )
00779   : CryptoConfigEntryGUI( module, entry, entryName )
00780 {
00781   mLabel = new QLabel( widget );
00782   mPushButton = new QPushButton( entry->isReadOnly() ? i18n("Show...") : i18n( "Edit..." ), widget );
00783 
00784 
00785   const int row = glay->rowCount();
00786   QLabel *label = new QLabel( description(), widget );
00787   label->setBuddy( mPushButton );
00788   glay->addWidget( label, row, 1 );
00789   QHBoxLayout * hlay = new QHBoxLayout;
00790   glay->addLayout( hlay, row, 2 );
00791   hlay->addWidget( mLabel, 1 );
00792   hlay->addWidget( mPushButton );
00793 
00794   if ( entry->isReadOnly() )
00795     mLabel->setEnabled( false );
00796   connect( mPushButton, SIGNAL( clicked() ), SLOT( slotOpenDialog() ) );
00797 }
00798 
00799 static KUrl::List strings2urls( const QStringList & strs ) {
00800     KUrl::List urls;
00801     Q_FOREACH( const QString & str, strs )
00802         if ( !str.isEmpty() )
00803             urls.push_back( KUrl( str ) );
00804     return urls;
00805 }
00806 
00807 static QStringList urls2strings( const KUrl::List & urls ) {
00808     QStringList result;
00809     Q_FOREACH( const KUrl & url, urls )
00810         result.push_back( url.url() );
00811     return result;
00812 }
00813 
00814 void Kleo::CryptoConfigEntryLDAPURL::doLoad()
00815 {
00816   setURLList( mEntry->urlValueList() );
00817 }
00818 
00819 void Kleo::CryptoConfigEntryLDAPURL::doSave()
00820 {
00821   mEntry->setURLValueList( mURLList );
00822 }
00823 
00824 void Kleo::CryptoConfigEntryLDAPURL::slotOpenDialog()
00825 {
00826   // I'm a bad boy and I do it all on the stack. Enough classes already :)
00827   // This is just a simple dialog around the directory-services-widget
00828   KDialog dialog( mPushButton->parentWidget() );
00829   dialog.setCaption( i18n( "Configure LDAP Servers" ) );
00830   if ( mEntry->isReadOnly() )
00831     dialog.setButtons( KDialog::Ok );
00832   else
00833     dialog.setButtons( KDialog::Default|KDialog::Cancel|KDialog::Ok );
00834   DirectoryServicesWidget* dirserv = new DirectoryServicesWidget( &dialog );
00835   dirserv->setX509ReadOnly( mEntry->isReadOnly() );
00836   dirserv->setAllowedSchemes( DirectoryServicesWidget::LDAP );
00837   dirserv->setAllowedProtocols( DirectoryServicesWidget::X509Protocol );
00838   dirserv->addX509Services( mURLList );
00839   dialog.setMainWidget( dirserv );
00840   connect( &dialog, SIGNAL(defaultClicked()), dirserv, SLOT(clear()) );
00841   if ( dialog.exec() ) {
00842     setURLList( dirserv->x509Services() );
00843     slotChanged();
00844   }
00845 }
00846 
00847 void Kleo::CryptoConfigEntryLDAPURL::setURLList( const KUrl::List& urlList )
00848 {
00849   mURLList = urlList;
00850   if ( mURLList.isEmpty() )
00851     mLabel->setText( i18n( "No server configured yet" ) );
00852   else
00853     mLabel->setText( i18np( "1 server configured", "%1 servers configured", mURLList.count() ) );
00854 }
00855 
00856 
00857 
00858 Kleo::CryptoConfigEntryKeyserver::CryptoConfigEntryKeyserver(
00859   CryptoConfigModule* module,
00860   Kleo::CryptoConfigEntry* entry,
00861   const QString& entryName,
00862   QGridLayout * glay, QWidget* widget )
00863   : CryptoConfigEntryGUI( module, entry, entryName )
00864 {
00865   mLabel = new QLabel( widget );
00866   mPushButton = new QPushButton( i18n( "Edit..." ), widget );
00867 
00868 
00869   const int row = glay->rowCount();
00870   QLabel *label = new QLabel( i18n("Use keyserver at"), widget );
00871   label->setBuddy( mPushButton );
00872   glay->addWidget( label, row, 1 );
00873   QHBoxLayout * hlay = new QHBoxLayout;
00874   glay->addLayout( hlay, row, 2 );
00875   hlay->addWidget( mLabel, 1 );
00876   hlay->addWidget( mPushButton );
00877 
00878   if ( entry->isReadOnly() ) {
00879     mLabel->setEnabled( false );
00880     mPushButton->hide();
00881   } else {
00882     connect( mPushButton, SIGNAL( clicked() ), SLOT( slotOpenDialog() ) );
00883   }
00884 }
00885 
00886 void Kleo::CryptoConfigEntryKeyserver::doLoad()
00887 {
00888   mLabel->setText( mEntry->stringValue() );
00889 }
00890 
00891 void Kleo::CryptoConfigEntryKeyserver::doSave()
00892 {
00893   mEntry->setStringValue( mLabel->text() );
00894 }
00895 
00896 static KUrl::List string2urls( const QString & str ) {
00897     return str.isEmpty() ? KUrl::List() : KUrl( str ) ;
00898 }
00899 
00900 static QString urls2string( const KUrl::List & urls ) {
00901     return urls.empty() ? QString() : urls.front().url() ;
00902 }
00903 
00904 void Kleo::CryptoConfigEntryKeyserver::slotOpenDialog()
00905 {
00906   // I'm a bad boy and I do it all on the stack. Enough classes already :)
00907   // This is just a simple dialog around the directory-services-widget
00908   KDialog dialog( mPushButton->parentWidget() );
00909   dialog.setCaption( i18n( "Configure Keyservers" ) );
00910   dialog.setButtons( KDialog::Default|KDialog::Cancel|KDialog::Ok );
00911   DirectoryServicesWidget dirserv( &dialog );
00912   dirserv.setOpenPGPReadOnly( mEntry->isReadOnly() );
00913   dirserv.setAllowedSchemes( DirectoryServicesWidget::AllSchemes );
00914   dirserv.setAllowedProtocols( DirectoryServicesWidget::OpenPGPProtocol );
00915   dirserv.addOpenPGPServices( string2urls( mLabel->text() ) );
00916   dialog.setMainWidget( &dirserv );
00917   connect( &dialog, SIGNAL(defaultClicked()), &dirserv, SLOT(clear()) );
00918   if ( dialog.exec() ) {
00919     mLabel->setText( urls2string( dirserv.openPGPServices() ) );
00920     slotChanged();
00921   }
00922 }
00923 
00924 #include "cryptoconfigmodule.moc"
00925 #include "cryptoconfigmodule_p.moc"

libkleo

Skip menu "libkleo"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal