35 #include "directoryserviceswidget.h"
36 #include "adddirectoryservicedialogimpl.h"
39 #include <klineedit.h>
40 #include <kleo/cryptoconfig.h>
41 #include <kiconloader.h>
44 #include <tqbuttongroup.h>
45 #include <tqtoolbutton.h>
46 #include <tqlistview.h>
47 #include <tqpushbutton.h>
51 class QX500ListViewItem :
public TQListViewItem
54 QX500ListViewItem( TQListView* lv, TQListViewItem* prev,
55 const TQString& serverName,
56 const TQString& portNumber,
58 const TQString& username,
59 const TQString& password )
60 : TQListViewItem( lv, prev, serverName, portNumber, dn, username ) {
61 setPassword( password );
64 void setPassword(
const TQString& pass ) {
66 setText( 4, pass.isEmpty() ? TQString() : TQString::fromLatin1(
"******" ) );
69 const TQString& password()
const {
return mPassword; }
71 void setData(
const TQString& serverName,
72 const TQString& portNumber,
74 const TQString& username,
75 const TQString& password ) {
76 setText( 0, serverName );
77 setText( 1, portNumber );
79 setText( 3, username );
80 setPassword( password );
83 void copyItem( QX500ListViewItem* item ) {
84 for (
unsigned int i = 0; i < 4 ; ++i )
85 setText( i, item->text( i ) );
86 setPassword( item->password() );
93 Kleo::DirectoryServicesWidget::DirectoryServicesWidget(
95 TQWidget* parent,
const char* name, WFlags fl )
96 : DirectoryServicesWidgetBase( parent, name, fl ),
97 mConfigEntry( configEntry )
99 x500LV->setSorting( -1 );
102 upButton->setIconSet( BarIconSet(
"go-up", TDEIcon::SizeSmall ) );
103 upButton->setEnabled(
false );
105 downButton->setIconSet( BarIconSet(
"go-down", TDEIcon::SizeSmall ) );
106 downButton->setEnabled(
false );
113 DirectoryServicesWidget::~DirectoryServicesWidget()
127 setEnabled( cryptPlug->
hasFeature( Feature_CertificateDirectoryService ) ||
128 cryptPlug->
hasFeature( Feature_CRLDirectoryService ) );
135 void DirectoryServicesWidget::slotServiceChanged( TQListViewItem* item )
138 removeServicePB->setEnabled(
true );
140 removeServicePB->setEnabled(
false );
141 downButton->setEnabled( item && item->itemBelow() );
142 upButton->setEnabled( item && item->itemAbove() );
149 void DirectoryServicesWidget::slotServiceSelected( TQListViewItem* item )
151 AddDirectoryServiceDialogImpl* dlg =
new AddDirectoryServiceDialogImpl(
this );
152 dlg->serverNameED->setText( item->text( 0 ) );
153 dlg->portED->setText( item->text( 1 ) );
154 dlg->descriptionED->setText( item->text( 2 ) );
155 dlg->usernameED->setText( item->text( 3 ) );
156 TQString pass =
static_cast<QX500ListViewItem *
>( item )->password();
157 dlg->passwordED->setText( pass );
159 if( dlg->exec() == TQDialog::Accepted ) {
160 item->setText( 0, dlg->serverNameED->text() );
161 item->setText( 1, dlg->portED->text() );
162 item->setText( 2, dlg->descriptionED->text() );
163 item->setText( 3, dlg->usernameED->text() );
164 static_cast<QX500ListViewItem *
>( item )->setPassword( dlg->passwordED->text() );
174 void DirectoryServicesWidget::slotAddService()
176 AddDirectoryServiceDialogImpl* dlg =
new AddDirectoryServiceDialogImpl(
this );
177 if( dlg->exec() == TQDialog::Accepted ) {
178 QX500ListViewItem *item =
new QX500ListViewItem( x500LV, x500LV->lastItem(),
179 dlg->serverNameED->text(),
181 dlg->descriptionED->text(),
182 dlg->usernameED->text(),
183 dlg->passwordED->text() );
184 slotServiceChanged(item);
193 void DirectoryServicesWidget::slotDeleteService()
195 TQListViewItem* item = x500LV->selectedItem();
201 x500LV->triggerUpdate();
202 item = x500LV->currentItem();
203 x500LV->setCurrentItem( item );
204 x500LV->setSelected( item,
true );
209 void DirectoryServicesWidget::setInitialServices(
const KURL::List& urls )
212 for( KURL::List::const_iterator it = urls.begin(); it != urls.end(); ++it ) {
213 TQString dn = KURL::decode_string( (*it).query().mid( 1 ) );
214 (void)
new QX500ListViewItem( x500LV, x500LV->lastItem(),
216 TQString::number( (*it).port() ),
223 KURL::List DirectoryServicesWidget::urlList()
const
226 TQListViewItemIterator it( x500LV );
227 for ( ; it.current() ; ++it ) {
228 TQListViewItem* item = it.current();
230 url.setProtocol(
"ldap" );
231 url.setHost( item->text( 0 ) );
232 url.setPort( item->text( 1 ).toInt() );
234 url.setQuery( item->text( 2 ) );
235 url.setUser( item->text( 3 ) );
236 url.setPass(
static_cast<QX500ListViewItem *
>( item )->password() );
237 kdDebug() << url << endl;
243 void DirectoryServicesWidget::clear()
249 void DirectoryServicesWidget::load()
251 if ( mConfigEntry ) {
252 setInitialServices( mConfigEntry->urlValueList() );
256 void DirectoryServicesWidget::save()
258 if ( mConfigEntry ) {
259 mConfigEntry->setURLValueList( urlList() );
263 void DirectoryServicesWidget::defaults()
265 if ( mConfigEntry ) {
273 static void swapItems( QX500ListViewItem *item, QX500ListViewItem *other )
275 TQString serverName = item->text( 0 );
276 TQString portNumber = item->text( 1 );
277 TQString dn = item->text( 2 );
278 TQString username = item->text( 3 );
279 TQString password = item->password();
280 item->copyItem( other );
281 other->setData( serverName, portNumber, dn, username, password );
284 void Kleo::DirectoryServicesWidget::slotMoveUp()
286 QX500ListViewItem *item =
static_cast<QX500ListViewItem *
>( x500LV->selectedItem() );
288 QX500ListViewItem *above =
static_cast<QX500ListViewItem *
>( item->itemAbove() );
289 if ( !above )
return;
290 swapItems( item, above );
291 x500LV->setCurrentItem( above );
292 x500LV->setSelected( above,
true );
296 void Kleo::DirectoryServicesWidget::slotMoveDown()
298 QX500ListViewItem *item =
static_cast<QX500ListViewItem *
>( x500LV->selectedItem() );
300 QX500ListViewItem *below =
static_cast<QX500ListViewItem *
>( item->itemBelow() );
301 if ( !below )
return;
302 swapItems( item, below );
303 x500LV->setCurrentItem( below );
304 x500LV->setSelected( below,
true );
308 #include "directoryserviceswidget.moc"
This class provides C++ access to the CRYPTPLUG API.
Description of a single option.
C++ wrapper for the CRYPTPLUG library API.
bool hasFeature(::Feature)
This function returns true if the specified feature is available in the plugin, and false otherwise.