00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "dirservconfigpage.h"
00033 #include "directoryserviceswidget.h"
00034
00035 #include <kleo/cryptobackendfactory.h>
00036
00037 #include <kmessagebox.h>
00038 #include <klocale.h>
00039 #include <kdebug.h>
00040 #include <kconfig.h>
00041 #include <knuminput.h>
00042 #include <kdialog.h>
00043
00044 #include <qhbox.h>
00045 #include <qlabel.h>
00046 #include <qdatetimeedit.h>
00047 #include <qcheckbox.h>
00048 #include <qlayout.h>
00049
00050
00051 #if 0 // disabled, since it is apparently confusing
00052
00053 class KABSynchronizer
00054 {
00055 public:
00056 KABSynchronizer()
00057 : mConfig( "kabldaprc" ) {
00058 mConfig.setGroup( "LDAP" );
00059 }
00060
00061 KURL::List readCurrentList() const {
00062
00063 KURL::List lst;
00064
00065 const uint numHosts = mConfig.readUnsignedNumEntry( "NumSelectedHosts" );
00066 for ( uint j = 0; j < numHosts; j++ ) {
00067 const QString num = QString::number( j );
00068
00069 KURL url;
00070 url.setProtocol( "ldap" );
00071 url.setPath( "/" );
00072 const QString host = mConfig.readEntry( QString( "SelectedHost" ) + num ).stripWhiteSpace();
00073 url.setHost( host );
00074
00075 const int port = mConfig.readUnsignedNumEntry( QString( "SelectedPort" ) + num );
00076 if ( port != 0 )
00077 url.setPort( port );
00078
00079 const QString base = mConfig.readEntry( QString( "SelectedBase" ) + num ).stripWhiteSpace();
00080 url.setQuery( base );
00081
00082 const QString bindDN = mConfig.readEntry( QString( "SelectedBind" ) + num ).stripWhiteSpace();
00083 url.setUser( bindDN.isEmpty()?QString::null:bindDN );
00084
00085 const QString pwdBindDN = mConfig.readEntry( QString( "SelectedPwdBind" ) + num ).stripWhiteSpace();
00086 url.setPass( pwdBindDN.isEmpty()?QString::null:pwdBindDN );
00087
00088 lst.append( url );
00089 }
00090 return lst;
00091 }
00092
00093 void writeList( const KURL::List& lst ) {
00094
00095 mConfig.writeEntry( "NumSelectedHosts", lst.count() );
00096
00097 KURL::List::const_iterator it = lst.begin();
00098 KURL::List::const_iterator end = lst.end();
00099 unsigned j = 0;
00100 for( ; it != end; ++it, ++j ) {
00101 const QString num = QString::number( j );
00102 KURL url = *it;
00103
00104 Q_ASSERT( url.protocol() == "ldap" );
00105 mConfig.writeEntry( QString( "SelectedHost" ) + num, url.host() );
00106 mConfig.writeEntry( QString( "SelectedPort" ) + num, url.port() );
00107
00108
00109
00110 const QString base = KURL::decode_string( url.query().mid(1) );
00111 mConfig.writeEntry( QString( "SelectedBase" ) + num, base );
00112 mConfig.writeEntry( QString( "SelectedBind" ) + num, url.user() );
00113 mConfig.writeEntry( QString( "SelectedPwdBind" ) + num, url.pass() );
00114 }
00115 mConfig.sync();
00116 }
00117
00118 private:
00119 KConfig mConfig;
00120 };
00121
00122 #endif
00123
00124 static const char s_dirserv_componentName[] = "dirmngr";
00125 static const char s_dirserv_groupName[] = "LDAP";
00126 static const char s_dirserv_entryName[] = "LDAP Server";
00127
00128 static const char s_timeout_componentName[] = "dirmngr";
00129 static const char s_timeout_groupName[] = "LDAP";
00130 static const char s_timeout_entryName[] = "ldaptimeout";
00131
00132 static const char s_maxitems_componentName[] = "dirmngr";
00133 static const char s_maxitems_groupName[] = "LDAP";
00134 static const char s_maxitems_entryName[] = "max-replies";
00135
00136 static const char s_addnewservers_componentName[] = "dirmngr";
00137 static const char s_addnewservers_groupName[] = "LDAP";
00138 static const char s_addnewservers_entryName[] = "add-servers";
00139
00140 DirectoryServicesConfigurationPage::DirectoryServicesConfigurationPage( QWidget * parent, const char * name )
00141 : KCModule( parent, name )
00142 {
00143 mConfig = Kleo::CryptoBackendFactory::instance()->config();
00144 QVBoxLayout* lay = new QVBoxLayout( this, 0, KDialog::spacingHint() );
00145 Kleo::CryptoConfigEntry* entry = configEntry( s_dirserv_componentName, s_dirserv_groupName, s_dirserv_entryName,
00146 Kleo::CryptoConfigEntry::ArgType_LDAPURL, true );
00147 mWidget = new Kleo::DirectoryServicesWidget( entry, this );
00148 lay->addWidget( mWidget );
00149 connect( mWidget, SIGNAL( changed() ), this, SLOT( slotChanged() ) );
00150
00151
00152 QHBox* box = new QHBox( this );
00153 box->setSpacing( KDialog::spacingHint() );
00154 lay->addWidget( box );
00155 QLabel* label = new QLabel( i18n( "LDAP &timeout (minutes:seconds)" ), box );
00156 mTimeout = new QTimeEdit( box );
00157 mTimeout->setDisplay( QTimeEdit::Minutes | QTimeEdit::Seconds );
00158 connect( mTimeout, SIGNAL( valueChanged( const QTime& ) ), this, SLOT( slotChanged() ) );
00159 label->setBuddy( mTimeout );
00160 QWidget* stretch = new QWidget( box );
00161 box->setStretchFactor( stretch, 2 );
00162
00163
00164 box = new QHBox( this );
00165 box->setSpacing( KDialog::spacingHint() );
00166 lay->addWidget( box );
00167 mMaxItems = new KIntNumInput( box );
00168 mMaxItems->setLabel( i18n( "&Maximum number of items returned by query" ), Qt::AlignLeft | Qt::AlignVCenter );
00169 mMaxItems->setMinValue( 0 );
00170 connect( mMaxItems, SIGNAL( valueChanged(int) ), this, SLOT( slotChanged() ) );
00171 stretch = new QWidget( box );
00172 box->setStretchFactor( stretch, 2 );
00173
00174 #ifdef NOT_USEFUL_CURRENTLY
00175 mAddNewServersCB = new QCheckBox( i18n( "Automatically add &new servers discovered in CRL distribution points" ), this );
00176 connect( mAddNewServersCB, SIGNAL( clicked() ), this, SLOT( slotChanged() ) );
00177 lay->addWidget( mAddNewServersCB );
00178 #endif
00179
00180 #ifndef HAVE_UNBROKEN_KCMULTIDIALOG
00181 load();
00182 #endif
00183 }
00184
00185 void DirectoryServicesConfigurationPage::load()
00186 {
00187 mWidget->load();
00188
00189 mTimeoutConfigEntry = configEntry( s_timeout_componentName, s_timeout_groupName, s_timeout_entryName, Kleo::CryptoConfigEntry::ArgType_UInt, false );
00190 if ( mTimeoutConfigEntry ) {
00191 QTime time = QTime().addSecs( mTimeoutConfigEntry->uintValue() );
00192
00193 mTimeout->setTime( time );
00194 }
00195
00196 mMaxItemsConfigEntry = configEntry( s_maxitems_componentName, s_maxitems_groupName, s_maxitems_entryName, Kleo::CryptoConfigEntry::ArgType_UInt, false );
00197 if ( mMaxItemsConfigEntry ) {
00198 mMaxItems->blockSignals( true );
00199 mMaxItems->setValue( mMaxItemsConfigEntry->uintValue() );
00200 mMaxItems->blockSignals( false );
00201 }
00202
00203 #ifdef NOT_USEFUL_CURRENTLY
00204 mAddNewServersConfigEntry = configEntry( s_addnewservers_componentName, s_addnewservers_groupName, s_addnewservers_entryName, Kleo::CryptoConfigEntry::ArgType_None, false );
00205 if ( mAddNewServersConfigEntry ) {
00206 mAddNewServersCB->setChecked( mAddNewServersConfigEntry->boolValue() );
00207 }
00208 #endif
00209 }
00210
00211 void DirectoryServicesConfigurationPage::save()
00212 {
00213 mWidget->save();
00214
00215 QTime time( mTimeout->time() );
00216 unsigned int timeout = time.minute() * 60 + time.second();
00217 if ( mTimeoutConfigEntry && mTimeoutConfigEntry->uintValue() != timeout )
00218 mTimeoutConfigEntry->setUIntValue( timeout );
00219 if ( mMaxItemsConfigEntry && mMaxItemsConfigEntry->uintValue() != (uint)mMaxItems->value() )
00220 mMaxItemsConfigEntry->setUIntValue( mMaxItems->value() );
00221 #ifdef NOT_USEFUL_CURRENTLY
00222 if ( mAddNewServersConfigEntry && mAddNewServersConfigEntry->boolValue() != mAddNewServersCB->isChecked() )
00223 mAddNewServersConfigEntry->setBoolValue( mAddNewServersCB->isChecked() );
00224 #endif
00225
00226 mConfig->sync( true );
00227
00228 #if 0
00229
00230 KABSynchronizer sync;
00231 const KURL::List toAdd = mWidget->urlList();
00232 KURL::List currentList = sync.readCurrentList();
00233
00234 KURL::List::const_iterator it = toAdd.begin();
00235 KURL::List::const_iterator end = toAdd.end();
00236 for( ; it != end; ++it ) {
00237
00238 if ( currentList.find( *it ) == currentList.end() )
00239
00240 currentList.append( *it );
00241 }
00242 sync.writeList( currentList );
00243 #endif
00244 }
00245
00246 void DirectoryServicesConfigurationPage::defaults()
00247 {
00248 mWidget->defaults();
00249 if ( mTimeoutConfigEntry )
00250 mTimeoutConfigEntry->resetToDefault();
00251 if ( mMaxItemsConfigEntry )
00252 mMaxItemsConfigEntry->resetToDefault();
00253 #ifdef NOT_USEFUL_CURRENTLY
00254 if ( mAddNewServersConfigEntry )
00255 mAddNewServersConfigEntry->resetToDefault();
00256 #endif
00257 load();
00258 }
00259
00260 extern "C"
00261 {
00262 KCModule *create_kleopatra_config_dirserv( QWidget *parent, const char * )
00263 {
00264 DirectoryServicesConfigurationPage *page =
00265 new DirectoryServicesConfigurationPage( parent, "kleopatra_config_dirserv" );
00266 return page;
00267 }
00268 }
00269
00270
00271 void DirectoryServicesConfigurationPage::slotChanged()
00272 {
00273 emit changed(true);
00274 }
00275
00276
00277
00278 Kleo::CryptoConfigEntry* DirectoryServicesConfigurationPage::configEntry( const char* componentName,
00279 const char* groupName,
00280 const char* entryName,
00281 Kleo::CryptoConfigEntry::ArgType argType,
00282 bool isList )
00283 {
00284 Kleo::CryptoConfigEntry* entry = mConfig->entry( componentName, groupName, entryName );
00285 if ( !entry ) {
00286 KMessageBox::error( this, i18n( "Backend error: gpgconf doesn't seem to know the entry for %1/%2/%3" ).arg( componentName, groupName, entryName ) );
00287 return 0;
00288 }
00289 if( entry->argType() != argType || entry->isList() != isList ) {
00290 KMessageBox::error( this, i18n( "Backend error: gpgconf has wrong type for %1/%2/%3: %4 %5" ).arg( componentName, groupName, entryName ).arg( entry->argType() ).arg( entry->isList() ) );
00291 return 0;
00292 }
00293 return entry;
00294 }
00295
00296 #include "dirservconfigpage.moc"