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
00033 #include <config.h>
00034
00035 #include "directoryserviceswidget.h"
00036 #include "adddirectoryservicedialogimpl.h"
00037 #include "cryptplugwrapper.h"
00038
00039 #include <klineedit.h>
00040 #include <kleo/cryptoconfig.h>
00041 #include <kiconloader.h>
00042 #include <kdebug.h>
00043
00044 #include <qbuttongroup.h>
00045 #include <qtoolbutton.h>
00046 #include <qlistview.h>
00047 #include <qpushbutton.h>
00048
00049 using namespace Kleo;
00050
00051 class QX500ListViewItem : public QListViewItem
00052 {
00053 public:
00054 QX500ListViewItem( QListView* lv, QListViewItem* prev,
00055 const QString& serverName,
00056 const QString& portNumber,
00057 const QString& dn,
00058 const QString& username,
00059 const QString& password )
00060 : QListViewItem( lv, prev, serverName, portNumber, dn, username ) {
00061 setPassword( password );
00062 }
00063
00064 void setPassword( const QString& pass ) {
00065 mPassword = pass;
00066 setText( 4, pass.isEmpty() ? QString::null : QString::fromLatin1( "******" ) );
00067 }
00068
00069 const QString& password() const { return mPassword; }
00070
00071 void setData( const QString& serverName,
00072 const QString& portNumber,
00073 const QString& dn,
00074 const QString& username,
00075 const QString& password ) {
00076 setText( 0, serverName );
00077 setText( 1, portNumber );
00078 setText( 2, dn );
00079 setText( 3, username );
00080 setPassword( password );
00081 }
00082
00083 void copyItem( QX500ListViewItem* item ) {
00084 for ( unsigned int i = 0; i < 4 ; ++i )
00085 setText( i, item->text( i ) );
00086 setPassword( item->password() );
00087 }
00088
00089 private:
00090 QString mPassword;
00091 };
00092
00093 Kleo::DirectoryServicesWidget::DirectoryServicesWidget(
00094 Kleo::CryptoConfigEntry* configEntry,
00095 QWidget* parent, const char* name, WFlags fl )
00096 : DirectoryServicesWidgetBase( parent, name, fl ),
00097 mConfigEntry( configEntry )
00098 {
00099 x500LV->setSorting( -1 );
00100
00101
00102 upButton->setIconSet( BarIconSet( "up", KIcon::SizeSmall ) );
00103 upButton->setEnabled( false );
00104
00105 downButton->setIconSet( BarIconSet( "down", KIcon::SizeSmall ) );
00106 downButton->setEnabled( false );
00107 }
00108
00109
00110
00111
00112
00113 DirectoryServicesWidget::~DirectoryServicesWidget()
00114 {
00115
00116 }
00117
00118
00123 void DirectoryServicesWidget::enableDisable( CryptPlugWrapper* cryptPlug )
00124 {
00125
00126
00127 setEnabled( cryptPlug->hasFeature( Feature_CertificateDirectoryService ) ||
00128 cryptPlug->hasFeature( Feature_CRLDirectoryService ) );
00129 }
00130
00131
00132
00133
00134
00135 void DirectoryServicesWidget::slotServiceChanged( QListViewItem* item )
00136 {
00137 if( item )
00138 removeServicePB->setEnabled( true );
00139 else
00140 removeServicePB->setEnabled( false );
00141 downButton->setEnabled( item && item->itemBelow() );
00142 upButton->setEnabled( item && item->itemAbove() );
00143 }
00144
00145
00146
00147
00148
00149 void DirectoryServicesWidget::slotServiceSelected( QListViewItem* item )
00150 {
00151 AddDirectoryServiceDialogImpl* dlg = new AddDirectoryServiceDialogImpl( this );
00152 dlg->serverNameED->setText( item->text( 0 ) );
00153 dlg->portED->setText( item->text( 1 ) );
00154 dlg->descriptionED->setText( item->text( 2 ) );
00155 dlg->usernameED->setText( item->text( 3 ) );
00156 QString pass = static_cast<QX500ListViewItem *>( item )->password();
00157 dlg->passwordED->setText( pass );
00158
00159 if( dlg->exec() == QDialog::Accepted ) {
00160 item->setText( 0, dlg->serverNameED->text() );
00161 item->setText( 1, dlg->portED->text() );
00162 item->setText( 2, dlg->descriptionED->text() );
00163 item->setText( 3, dlg->usernameED->text() );
00164 static_cast<QX500ListViewItem *>( item )->setPassword( dlg->passwordED->text() );
00165 emit changed();
00166 }
00167 delete dlg;
00168 }
00169
00170
00171
00172
00173
00174 void DirectoryServicesWidget::slotAddService()
00175 {
00176 AddDirectoryServiceDialogImpl* dlg = new AddDirectoryServiceDialogImpl( this );
00177 if( dlg->exec() == QDialog::Accepted ) {
00178 QX500ListViewItem *item = new QX500ListViewItem( x500LV, x500LV->lastItem(),
00179 dlg->serverNameED->text(),
00180 dlg->portED->text(),
00181 dlg->descriptionED->text(),
00182 dlg->usernameED->text(),
00183 dlg->passwordED->text() );
00184 slotServiceChanged(item);
00185 emit changed();
00186 }
00187 delete dlg;
00188 }
00189
00190
00191
00192
00193 void DirectoryServicesWidget::slotDeleteService()
00194 {
00195 QListViewItem* item = x500LV->selectedItem();
00196 Q_ASSERT( item );
00197 if( !item )
00198 return;
00199 else
00200 delete item;
00201 x500LV->triggerUpdate();
00202 item = x500LV->currentItem();
00203 x500LV->setCurrentItem( item );
00204 x500LV->setSelected( item, true );
00205 emit changed();
00206 }
00207
00208
00209 void DirectoryServicesWidget::setInitialServices( const KURL::List& urls )
00210 {
00211 x500LV->clear();
00212 for( KURL::List::const_iterator it = urls.begin(); it != urls.end(); ++it ) {
00213 QString dn = KURL::decode_string( (*it).query().mid( 1 ) );
00214 (void)new QX500ListViewItem( x500LV, x500LV->lastItem(),
00215 (*it).host(),
00216 QString::number( (*it).port() ),
00217 dn,
00218 (*it).user(),
00219 (*it).pass());
00220 }
00221 }
00222
00223 KURL::List DirectoryServicesWidget::urlList() const
00224 {
00225 KURL::List lst;
00226 QListViewItemIterator it( x500LV );
00227 for ( ; it.current() ; ++it ) {
00228 QListViewItem* item = it.current();
00229 KURL url;
00230 url.setProtocol( "ldap" );
00231 url.setHost( item->text( 0 ) );
00232 url.setPort( item->text( 1 ).toInt() );
00233 url.setPath( "/" );
00234 url.setQuery( item->text( 2 ) );
00235 url.setUser( item->text( 3 ) );
00236 url.setPass( static_cast<QX500ListViewItem *>( item )->password() );
00237 kdDebug() << url << endl;
00238 lst << url;
00239 }
00240 return lst;
00241 }
00242
00243 void DirectoryServicesWidget::clear()
00244 {
00245 x500LV->clear();
00246 emit changed();
00247 }
00248
00249 void DirectoryServicesWidget::load()
00250 {
00251 if ( mConfigEntry ) {
00252 setInitialServices( mConfigEntry->urlValueList() );
00253 }
00254 }
00255
00256 void DirectoryServicesWidget::save()
00257 {
00258 if ( mConfigEntry ) {
00259 mConfigEntry->setURLValueList( urlList() );
00260 }
00261 }
00262
00263 void DirectoryServicesWidget::defaults()
00264 {
00265 if ( mConfigEntry ) {
00266
00267
00268
00269 clear();
00270 }
00271 }
00272
00273 static void swapItems( QX500ListViewItem *item, QX500ListViewItem *other )
00274 {
00275 QString serverName = item->text( 0 );
00276 QString portNumber = item->text( 1 );
00277 QString dn = item->text( 2 );
00278 QString username = item->text( 3 );
00279 QString password = item->password();
00280 item->copyItem( other );
00281 other->setData( serverName, portNumber, dn, username, password );
00282 }
00283
00284 void Kleo::DirectoryServicesWidget::slotMoveUp()
00285 {
00286 QX500ListViewItem *item = static_cast<QX500ListViewItem *>( x500LV->selectedItem() );
00287 if ( !item ) return;
00288 QX500ListViewItem *above = static_cast<QX500ListViewItem *>( item->itemAbove() );
00289 if ( !above ) return;
00290 swapItems( item, above );
00291 x500LV->setCurrentItem( above );
00292 x500LV->setSelected( above, true );
00293 emit changed();
00294 }
00295
00296 void Kleo::DirectoryServicesWidget::slotMoveDown()
00297 {
00298 QX500ListViewItem *item = static_cast<QX500ListViewItem *>( x500LV->selectedItem() );
00299 if ( !item ) return;
00300 QX500ListViewItem *below = static_cast<QX500ListViewItem *>( item->itemBelow() );
00301 if ( !below ) return;
00302 swapItems( item, below );
00303 x500LV->setCurrentItem( below );
00304 x500LV->setSelected( below, true );
00305 emit changed();
00306 }
00307
00308 #include "directoryserviceswidget.moc"