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->setPixmap( BarIcon(
"up", KIcon::SizeSmall ) );
00103 upButton->setEnabled(
false );
00104
00105 downButton->setPixmap( BarIcon(
"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 (
void)
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 emit changed();
00185 }
00186 }
00187
00188
00189
00190
00191
void DirectoryServicesWidget::slotDeleteService()
00192 {
00193
QListViewItem* item = x500LV->selectedItem();
00194 Q_ASSERT( item );
00195
if( !item )
00196
return;
00197
else
00198
delete item;
00199 x500LV->triggerUpdate();
00200 item = x500LV->currentItem();
00201 x500LV->setCurrentItem( item );
00202 x500LV->setSelected( item,
true );
00203 emit changed();
00204 }
00205
00206
00207
void DirectoryServicesWidget::setInitialServices(
const KURL::List& urls )
00208 {
00209 x500LV->clear();
00210
for( KURL::List::const_iterator it = urls.begin(); it != urls.end(); ++it ) {
00211
QString dn = KURL::decode_string( (*it).query().mid( 1 ) );
00212 (
void)
new QX500ListViewItem( x500LV, x500LV->lastItem(),
00213 (*it).host(),
00214 QString::number( (*it).port() ),
00215 dn,
00216 (*it).user(),
00217 (*it).pass());
00218 }
00219 }
00220
00221 KURL::List DirectoryServicesWidget::urlList()
const
00222
{
00223 KURL::List lst;
00224
QListViewItemIterator it( x500LV );
00225
for ( ; it.current() ; ++it ) {
00226
QListViewItem* item = it.current();
00227 KURL url;
00228 url.setProtocol(
"ldap" );
00229 url.setHost( item->text( 0 ) );
00230 url.setPort( item->text( 1 ).toInt() );
00231 url.setPath(
"/" );
00232 url.setQuery( item->text( 2 ) );
00233 url.setUser( item->text( 3 ) );
00234 url.setPass( static_cast<QX500ListViewItem *>( item )->password() );
00235 kdDebug() << url << endl;
00236 lst << url;
00237 }
00238
return lst;
00239 }
00240
00241
void DirectoryServicesWidget::clear()
00242 {
00243 x500LV->clear();
00244 emit changed();
00245 }
00246
00247
void DirectoryServicesWidget::load()
00248 {
00249
if ( mConfigEntry ) {
00250 setInitialServices( mConfigEntry->urlValueList() );
00251 }
00252 }
00253
00254
void DirectoryServicesWidget::save()
00255 {
00256
if ( mConfigEntry ) {
00257 mConfigEntry->setURLValueList( urlList() );
00258 }
00259 }
00260
00261
void DirectoryServicesWidget::defaults()
00262 {
00263
if ( mConfigEntry ) {
00264
00265
00266
00267 clear();
00268 }
00269 }
00270
00271
static void swapItems( QX500ListViewItem *item, QX500ListViewItem *other )
00272 {
00273
QString serverName = item->text( 0 );
00274
QString portNumber = item->text( 1 );
00275
QString dn = item->text( 2 );
00276
QString username = item->text( 3 );
00277
QString password = item->password();
00278 item->copyItem( other );
00279 other->setData( serverName, portNumber, dn, username, password );
00280 }
00281
00282
void Kleo::DirectoryServicesWidget::slotMoveUp()
00283 {
00284 QX500ListViewItem *item = static_cast<QX500ListViewItem *>( x500LV->selectedItem() );
00285
if ( !item )
return;
00286 QX500ListViewItem *above = static_cast<QX500ListViewItem *>( item->itemAbove() );
00287
if ( !above )
return;
00288 swapItems( item, above );
00289 x500LV->setCurrentItem( above );
00290 x500LV->setSelected( above,
true );
00291 emit changed();
00292 }
00293
00294
void Kleo::DirectoryServicesWidget::slotMoveDown()
00295 {
00296 QX500ListViewItem *item = static_cast<QX500ListViewItem *>( x500LV->selectedItem() );
00297
if ( !item )
return;
00298 QX500ListViewItem *below = static_cast<QX500ListViewItem *>( item->itemBelow() );
00299
if ( !below )
return;
00300 swapItems( item, below );
00301 x500LV->setCurrentItem( below );
00302 x500LV->setSelected( below,
true );
00303 emit changed();
00304 }
00305
00306
#include "directoryserviceswidget.moc"