certmanager/lib Library API Documentation

directoryserviceswidget.cpp

00001 /* 00002 directoryserviceswidget.cpp 00003 00004 This file is part of Kleopatra, the KDE keymanager 00005 Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB 00006 00007 Kleopatra is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 Kleopatra is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 In addition, as a special exception, the copyright holders give 00022 permission to link the code of this program with any edition of 00023 the Qt library by Trolltech AS, Norway (or with modified versions 00024 of Qt that use the same license as Qt), and distribute linked 00025 combinations including the two. You must obey the GNU General 00026 Public License in all respects for all of the code used other than 00027 Qt. If you modify this file, you may extend this exception to 00028 your version of the file, but you are not obligated to do so. If 00029 you do not wish to do so, delete this exception statement from 00030 your version. 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 // taken from kmail's configuredialog.cpp 00102 upButton->setPixmap( BarIcon( "up", KIcon::SizeSmall ) ); 00103 upButton->setEnabled( false ); // b/c no item is selected yet 00104 00105 downButton->setPixmap( BarIcon( "down", KIcon::SizeSmall ) ); 00106 downButton->setEnabled( false ); // b/c no item is selected yet 00107 } 00108 00109 00110 /* 00111 * Destroys the object and frees any allocated resources 00112 */ 00113 DirectoryServicesWidget::~DirectoryServicesWidget() 00114 { 00115 // no need to delete child widgets, Qt does it all for us 00116 } 00117 00118 00123 void DirectoryServicesWidget::enableDisable( CryptPlugWrapper* cryptPlug ) // unused? 00124 { 00125 // disable the whole page if the plugin does not support the use 00126 // of directory services 00127 setEnabled( cryptPlug->hasFeature( Feature_CertificateDirectoryService ) || 00128 cryptPlug->hasFeature( Feature_CRLDirectoryService ) ); 00129 } 00130 00131 00132 /* 00133 * protected slot, connected to selectionChanged() 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 * protected slot, connected to returnPressed/doubleClicked 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 * protected slot 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 * protected slot 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 ); // seems necessary... 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 ) ); // decode query and skip leading '?' 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( "/" ); // workaround KURL parsing bug 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 // resetToDefault doesn't work since gpgconf doesn't know any defaults for this entry. 00265 //mConfigEntry->resetToDefault(); 00266 //load(); 00267 clear(); // the default is an empty list. 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"
KDE Logo
This file is part of the documentation for certmanager/lib Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:50:04 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003