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