4 This file is part of kgpgcertmanager
5 Copyright (c) 2004 Klar�vdalens Datakonsult AB
7 Libkleopatra is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License,
9 version 2, as published by the Free Software Foundation.
11 Libkleopatra is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 In addition, as a special exception, the copyright holders give
21 permission to link the code of this program with any edition of
22 the Qt library by Trolltech AS, Norway (or with modified versions
23 of Qt that use the same license as Qt), and distribute linked
24 combinations including the two. You must obey the GNU General
25 Public License in all respects for all of the code used other than
26 Qt. If you modify this file, you may extend this exception to
27 your version of the file, but you are not obligated to do so. If
28 you do not wish to do so, delete this exception statement from
32 #include "cryptoconfigmodule.h"
33 #include "cryptoconfigmodule_p.h"
34 #include "directoryserviceswidget.h"
35 #include "kdhorizontalline.h"
36 #include "filenamerequester.h"
38 #include "kleo/cryptoconfig.h"
40 #include <klineedit.h>
43 #include <knuminput.h>
44 #include <kiconloader.h>
46 #include <kcomponentdata.h>
48 #ifndef KDEPIM_ONLY_KLEO
49 # include <kurlrequester.h>
52 #include <QApplication>
55 #include <QPushButton>
58 #include <QVBoxLayout>
60 #include <QHBoxLayout>
61 #include <QGridLayout>
62 #include <QScrollArea>
63 #include <QDesktopWidget>
74 class ScrollArea
: public QScrollArea
{
76 explicit ScrollArea( QWidget
* p
) : QScrollArea( p
) {}
77 /* reimp */ QSize
sizeHint() const {
78 const QSize wsz
= widget() ? widget()->sizeHint() : QSize();
79 return QSize( wsz
.width() + style()->pixelMetric( QStyle::PM_ScrollBarExtent
), QScrollArea::sizeHint().height() );
84 inline KIcon
loadIcon( const QString
&s
) {
86 return KIcon( ss
.replace( QRegExp( "[^a-zA-Z0-9_]" ), "-" ) );
89 static unsigned int num_components_with_options( const Kleo::CryptoConfig
* config
) {
92 const QStringList components
= config
->componentList();
93 unsigned int result
= 0;
94 for ( QStringList::const_iterator it
= components
.begin() ; it
!= components
.end() ; ++it
)
95 if ( const Kleo::CryptoConfigComponent
* const comp
= config
->component( *it
) )
96 if ( !comp
->groupList().empty() )
101 static const KPageView::FaceType
determineJanusFace( const Kleo::CryptoConfig
* config
, Kleo::CryptoConfigModule::Layout layout
) {
102 return num_components_with_options( config
) < 2
104 : layout
== Kleo::CryptoConfigModule::TabbedLayout
? KPageView::Tabbed
: KPageView::List
;
107 Kleo::CryptoConfigModule::CryptoConfigModule( Kleo::CryptoConfig
* config
, QWidget
* parent
)
108 : KPageWidget( parent
), mConfig( config
)
110 init( IconListLayout
);
113 Kleo::CryptoConfigModule::CryptoConfigModule( Kleo::CryptoConfig
* config
, Layout layout
, QWidget
* parent
)
114 : KPageWidget( parent
), mConfig( config
)
119 void Kleo::CryptoConfigModule::init( Layout layout
) {
120 Kleo::CryptoConfig
* const config
= mConfig
;
121 const KPageView::FaceType type
=determineJanusFace( config
, layout
);
123 QVBoxLayout
* vlay
= 0;
125 if ( type
== Plain
) {
126 vbox
= new QWidget(this);
127 vlay
= new QVBoxLayout( vbox
);
128 vlay
->setSpacing( KDialog::spacingHint() );
129 vlay
->setMargin( 0 );
130 addPage( vbox
, i18n("GpgConf Error") );
133 const QStringList components
= config
->componentList();
134 for ( QStringList::const_iterator it
= components
.begin(); it
!= components
.end(); ++it
) {
135 //kDebug(5150) <<"Component" << (*it).toLocal8Bit() <<":";
136 Kleo::CryptoConfigComponent
* comp
= config
->component( *it
);
138 if ( comp
->groupList().empty() )
140 if ( type
!= Plain
) {
141 vbox
= new QWidget(this);
142 vlay
= new QVBoxLayout( vbox
);
143 vlay
->setSpacing( KDialog::spacingHint() );
144 vlay
->setMargin( 0 );
145 KPageWidgetItem
*pageItem
= new KPageWidgetItem( vbox
, comp
->description() );
146 if ( type
!= Tabbed
)
147 pageItem
->setIcon( loadIcon( comp
->iconName() ) );
151 QScrollArea
* scrollArea
= type
== Tabbed
? new QScrollArea( this ) : new ScrollArea( this );
152 scrollArea
->setWidgetResizable( true );
154 vlay
->addWidget( scrollArea
);
156 CryptoConfigComponentGUI
* compGUI
=
157 new CryptoConfigComponentGUI( this, comp
, scrollArea
);
158 compGUI
->setObjectName( *it
);
159 scrollArea
->setWidget( compGUI
);
160 scrollArea
->setSizePolicy( QSizePolicy::MinimumExpanding
, QSizePolicy::Preferred
);
161 // KJanusWidget doesn't seem to have iterators, so we store a copy...
162 mComponentGUIs
.append( compGUI
);
164 // Set a nice startup size
165 const int deskHeight
= QApplication::desktop()->height();
167 if (deskHeight
> 1000) // very big desktop ?
169 else if (deskHeight
> 650) // big desktop ?
171 else // small (800x600, 640x480) desktop
173 assert( scrollArea
->widget() );
174 if ( type
!= Tabbed
)
175 scrollArea
->setMinimumHeight( qMin( compGUI
->sizeHint().height(), dialogHeight
) );
177 if ( mComponentGUIs
.empty() ) {
178 const QString msg
= i18n("The gpgconf tool used to provide the information "
179 "for this dialog does not seem to be installed "
180 "properly. It did not return any components. "
181 "Try running \"%1\" on the command line for more "
183 components
.empty() ? "gpgconf --list-components" : "gpgconf --list-options gpg" );
184 QLabel
* label
= new QLabel( msg
, vbox
);
185 label
->setWordWrap( true);
186 label
->setMinimumHeight( fontMetrics().lineSpacing() * 5 );
187 vlay
->addWidget( label
);
191 bool Kleo::CryptoConfigModule::hasError() const {
192 return mComponentGUIs
.empty();
195 void Kleo::CryptoConfigModule::save()
197 bool changed
= false;
198 QList
<CryptoConfigComponentGUI
*>::Iterator it
= mComponentGUIs
.begin();
199 for( ; it
!= mComponentGUIs
.end(); ++it
) {
204 mConfig
->sync(true /*runtime*/);
207 void Kleo::CryptoConfigModule::reset()
209 QList
<CryptoConfigComponentGUI
*>::Iterator it
= mComponentGUIs
.begin();
210 for( ; it
!= mComponentGUIs
.end(); ++it
) {
215 void Kleo::CryptoConfigModule::defaults()
217 QList
<CryptoConfigComponentGUI
*>::Iterator it
= mComponentGUIs
.begin();
218 for( ; it
!= mComponentGUIs
.end(); ++it
) {
223 void Kleo::CryptoConfigModule::cancel()
230 Kleo::CryptoConfigComponentGUI::CryptoConfigComponentGUI(
231 CryptoConfigModule
* module
, Kleo::CryptoConfigComponent
* component
,
234 mComponent( component
)
236 QGridLayout
* glay
= new QGridLayout( this );
237 glay
->setSpacing( KDialog::spacingHint() );
238 const QStringList groups
= mComponent
->groupList();
239 if ( groups
.size() > 1 ) {
240 glay
->setColumnMinimumWidth( 0, KDHorizontalLine::indentHint() );
241 for ( QStringList::const_iterator it
= groups
.begin(), end
= groups
.end() ; it
!= end
; ++it
) {
242 Kleo::CryptoConfigGroup
* group
= mComponent
->group( *it
);
246 const QString title
= group
->description();
247 KDHorizontalLine
* hl
= new KDHorizontalLine( title
.isEmpty() ? *it
: title
, this );
248 const int row
= glay
->rowCount();
249 glay
->addWidget( hl
, row
, 0, 1, 3 );
250 mGroupGUIs
.append( new CryptoConfigGroupGUI( module
, group
, glay
, this ) );
252 } else if ( !groups
.empty() ) {
253 mGroupGUIs
.append( new CryptoConfigGroupGUI( module
, mComponent
->group( groups
.front() ), glay
, this ) );
255 glay
->setRowStretch( glay
->rowCount(), 1 );
259 bool Kleo::CryptoConfigComponentGUI::save()
261 bool changed
= false;
262 QList
<CryptoConfigGroupGUI
*>::Iterator it
= mGroupGUIs
.begin();
263 for( ; it
!= mGroupGUIs
.end(); ++it
) {
270 void Kleo::CryptoConfigComponentGUI::load()
272 QList
<CryptoConfigGroupGUI
*>::Iterator it
= mGroupGUIs
.begin();
273 for( ; it
!= mGroupGUIs
.end(); ++it
)
277 void Kleo::CryptoConfigComponentGUI::defaults()
279 QList
<CryptoConfigGroupGUI
*>::Iterator it
= mGroupGUIs
.begin();
280 for( ; it
!= mGroupGUIs
.end(); ++it
)
286 Kleo::CryptoConfigGroupGUI::CryptoConfigGroupGUI(
287 CryptoConfigModule
* module
, Kleo::CryptoConfigGroup
* group
,
288 QGridLayout
* glay
, QWidget
* widget
)
289 : QObject( module
), mGroup( group
)
291 const int startRow
= glay
->rowCount();
292 const QStringList entries
= mGroup
->entryList();
293 for( QStringList::const_iterator it
= entries
.begin(), end
= entries
.end() ; it
!= end
; ++it
) {
294 Kleo::CryptoConfigEntry
* entry
= group
->entry( *it
);
296 if ( entry
->level() > CryptoConfigEntry::Level_Advanced
) {
297 kDebug(5150) << "entry" << *it
<< "too advanced, skipping";
300 CryptoConfigEntryGUI
* entryGUI
=
301 CryptoConfigEntryGUIFactory::createEntryGUI( module
, entry
, *it
, glay
, widget
);
303 mEntryGUIs
.append( entryGUI
);
307 const int endRow
= glay
->rowCount() - 1;
308 if ( endRow
< startRow
)
311 const QString iconName
= group
->iconName();
312 if ( iconName
.isEmpty() )
315 QLabel
* l
= new QLabel( widget
);
316 l
->setPixmap( loadIcon( iconName
).pixmap( KIconLoader::SizeMedium
, KIconLoader::SizeMedium
) );
317 glay
->addWidget( l
, startRow
, 0, endRow
-startRow
+1, 1, Qt::AlignTop
);
320 bool Kleo::CryptoConfigGroupGUI::save()
322 bool changed
= false;
323 QList
<CryptoConfigEntryGUI
*>::Iterator it
= mEntryGUIs
.begin();
324 for( ; it
!= mEntryGUIs
.end(); ++it
) {
325 if ( (*it
)->isChanged() ) {
333 void Kleo::CryptoConfigGroupGUI::load()
335 QList
<CryptoConfigEntryGUI
*>::Iterator it
= mEntryGUIs
.begin();
336 for( ; it
!= mEntryGUIs
.end(); ++it
)
340 void Kleo::CryptoConfigGroupGUI::defaults()
342 QList
<CryptoConfigEntryGUI
*>::Iterator it
= mEntryGUIs
.begin();
343 for( ; it
!= mEntryGUIs
.end(); ++it
)
344 (*it
)->resetToDefault();
349 typedef CryptoConfigEntryGUI
* (*constructor
)( CryptoConfigModule
*, Kleo::CryptoConfigEntry
*, const QString
&, QGridLayout
*, QWidget
* );
352 template <typename T_Widget
>
353 CryptoConfigEntryGUI
* _create( CryptoConfigModule
* m
, Kleo::CryptoConfigEntry
* e
, const QString
& n
, QGridLayout
* l
, QWidget
* p
) {
354 return new T_Widget( m
, e
, n
, l
, p
);
358 static const struct WidgetsByEntryName
{
359 const char * entryGlob
;
361 } widgetsByEntryName
[] = {
362 { "*/*/debug-level", &_create
<CryptoConfigEntryDebugLevel
> },
363 { "gpg/*/keyserver", &_create
<CryptoConfigEntryKeyserver
> }
365 static const unsigned int numWidgetsByEntryName
= sizeof widgetsByEntryName
/ sizeof *widgetsByEntryName
;
367 static const constructor listWidgets
[CryptoConfigEntry::NumArgType
] = {
368 // None: A list of options with no arguments (e.g. -v -v -v) is shown as a spinbox
369 &_create
<CryptoConfigEntrySpinBox
>,
371 // Int/UInt: Let people type list of numbers (1,2,3....). Untested.
372 &_create
<CryptoConfigEntryLineEdit
>,
373 &_create
<CryptoConfigEntryLineEdit
>,
376 &_create
<CryptoConfigEntryLDAPURL
>,
380 static const constructor scalarWidgets
[CryptoConfigEntry::NumArgType
] = {
381 &_create
<CryptoConfigEntryCheckBox
>, // None
382 &_create
<CryptoConfigEntryLineEdit
>, // String
383 &_create
<CryptoConfigEntrySpinBox
>, // Int
384 &_create
<CryptoConfigEntrySpinBox
>, // UInt
385 &_create
<CryptoConfigEntryPath
>, // Path
386 &_create
<CryptoConfigEntryURL
>, // URL
388 &_create
<CryptoConfigEntryDirPath
>, // DirPath
391 CryptoConfigEntryGUI
* Kleo::CryptoConfigEntryGUIFactory::createEntryGUI( CryptoConfigModule
* module
, Kleo::CryptoConfigEntry
* entry
, const QString
& entryName
, QGridLayout
* glay
, QWidget
* widget
)
395 // try to lookup by path:
396 const QString path
= entry
->path();
397 for ( unsigned int i
= 0 ; i
< numWidgetsByEntryName
; ++i
)
398 if ( QRegExp( QLatin1String( widgetsByEntryName
[i
].entryGlob
), Qt::CaseSensitive
, QRegExp::Wildcard
).exactMatch( path
) )
399 return widgetsByEntryName
[i
].create( module
, entry
, entryName
, glay
, widget
);
401 // none found, so look up by type:
402 const unsigned int argType
= entry
->argType();
403 assert( argType
< CryptoConfigEntry::NumArgType
);
404 if ( entry
->isList() )
405 if ( const constructor create
= listWidgets
[argType
] )
406 return create( module
, entry
, entryName
, glay
, widget
);
408 kWarning(5150) <<"No widget implemented for list of type" << entry
->argType();
410 if ( const constructor create
= scalarWidgets
[argType
] )
411 return create( module
, entry
, entryName
, glay
, widget
);
413 kWarning(5150) <<"No widget implemented for type" << entry
->argType();
420 Kleo::CryptoConfigEntryGUI::CryptoConfigEntryGUI(
421 CryptoConfigModule
* module
,
422 Kleo::CryptoConfigEntry
* entry
,
423 const QString
& entryName
)
424 : QObject( module
), mEntry( entry
), mName( entryName
), mChanged( false )
426 connect( this, SIGNAL( changed() ), module
, SIGNAL( changed() ) );
429 QString
Kleo::CryptoConfigEntryGUI::description() const
431 QString descr
= mEntry
->description();
432 if ( descr
.isEmpty() ) // shouldn't happen
433 return QString( "<%1>" ).arg( mName
);
434 if ( i18nc( "Translate this to 'yes' or 'no' (use the English words!) "
435 "depending on whether your language uses "
436 "Sentence style capitalisation in GUI labels (yes) or not (no). "
437 "Context: We get some backend strings in that have the wrong "
438 "capitalizaion (in English, at least) so we need to force the "
439 "first character to upper-case. It is this behaviour you can "
440 "control for your language with this translation.", "yes" ) == QLatin1String( "yes" ) )
441 descr
[0] = descr
[0].toUpper();
445 void Kleo::CryptoConfigEntryGUI::resetToDefault()
447 mEntry
->resetToDefault();
453 Kleo::CryptoConfigEntryLineEdit::CryptoConfigEntryLineEdit(
454 CryptoConfigModule
* module
,
455 Kleo::CryptoConfigEntry
* entry
, const QString
& entryName
,
456 QGridLayout
* glay
, QWidget
* widget
)
457 : CryptoConfigEntryGUI( module
, entry
, entryName
)
459 const int row
= glay
->rowCount();
460 mLineEdit
= new KLineEdit( widget
);
461 QLabel
*label
= new QLabel( description(), widget
);
462 label
->setBuddy( mLineEdit
);
463 glay
->addWidget( label
, row
, 1 );
464 glay
->addWidget( mLineEdit
, row
, 2 );
465 if ( entry
->isReadOnly() ) {
466 label
->setEnabled( false );
467 mLineEdit
->setEnabled( false );
469 connect( mLineEdit
, SIGNAL( textChanged( const QString
& ) ), SLOT( slotChanged() ) );
473 void Kleo::CryptoConfigEntryLineEdit::doSave()
475 mEntry
->setStringValue( mLineEdit
->text() );
478 void Kleo::CryptoConfigEntryLineEdit::doLoad()
480 mLineEdit
->setText( mEntry
->stringValue() );
485 static const struct {
489 { I18N_NOOP( "None (no debugging at all)" ), "none" },
490 { I18N_NOOP( "Basic (some basic debug messages)" ), "basic" },
491 { I18N_NOOP( "Advanced (more verbose debug messages)" ), "advanced" },
492 { I18N_NOOP( "Expert (even more detailed messages)" ), "expert" },
493 { I18N_NOOP( "Guru (all of the debug messages you can get)" ), "guru" },
495 static const unsigned int numDebugLevels
= sizeof debugLevels
/ sizeof *debugLevels
;
497 Kleo::CryptoConfigEntryDebugLevel::CryptoConfigEntryDebugLevel( CryptoConfigModule
* module
, Kleo::CryptoConfigEntry
* entry
,
498 const QString
& entryName
, QGridLayout
* glay
, QWidget
* widget
)
499 : CryptoConfigEntryGUI( module
, entry
, entryName
),
500 mComboBox( new QComboBox( widget
) )
502 QLabel
*label
= new QLabel( i18n("Set the debugging level to"), widget
);
503 label
->setBuddy( mComboBox
);
505 for ( unsigned int i
= 0 ; i
< numDebugLevels
; ++i
)
506 mComboBox
->addItem( i18n( debugLevels
[i
].label
) );
508 if ( entry
->isReadOnly() ) {
509 label
->setEnabled( false );
510 mComboBox
->setEnabled( false );
512 connect( mComboBox
, SIGNAL(currentIndexChanged(int)), SLOT(slotChanged()) );
515 const int row
= glay
->rowCount();
516 glay
->addWidget( label
, row
, 1 );
517 glay
->addWidget( mComboBox
, row
, 2 );
520 void Kleo::CryptoConfigEntryDebugLevel::doSave()
522 const unsigned int idx
= mComboBox
->currentIndex();
523 if ( idx
< numDebugLevels
)
524 mEntry
->setStringValue( QLatin1String( debugLevels
[idx
].name
) );
526 mEntry
->setStringValue( QString() );
529 void Kleo::CryptoConfigEntryDebugLevel::doLoad()
531 const QString str
= mEntry
->stringValue();
532 for ( unsigned int i
= 0 ; i
< numDebugLevels
; ++i
)
533 if ( str
== QLatin1String( debugLevels
[i
].name
) ) {
534 mComboBox
->setCurrentIndex( i
);
537 mComboBox
->setCurrentIndex( 0 );
542 Kleo::CryptoConfigEntryPath::CryptoConfigEntryPath(
543 CryptoConfigModule
* module
,
544 Kleo::CryptoConfigEntry
* entry
, const QString
& entryName
,
545 QGridLayout
* glay
, QWidget
* widget
)
546 : CryptoConfigEntryGUI( module
, entry
, entryName
),
548 mFileNameRequester( 0 )
550 const int row
= glay
->rowCount();
552 #ifdef KDEPIM_ONLY_KLEO
553 req
= mFileNameRequester
= new FileNameRequester( widget
);
554 mFileNameRequester
->setExistingOnly( false );
555 mFileNameRequester
->setFilter( QDir::Files
);
557 req
= mUrlRequester
= new KUrlRequester( widget
);
558 mUrlRequester
->setMode( KFile::File
| KFile::LocalOnly
);
560 QLabel
*label
= new QLabel( description(), widget
);
561 label
->setBuddy( req
);
562 glay
->addWidget( label
, row
, 1 );
563 glay
->addWidget( req
, row
, 2 );
564 if ( entry
->isReadOnly() ) {
565 label
->setEnabled( false );
566 #ifndef KDEPIM_ONLY_KLEO
568 mUrlRequester
->setEnabled( false );
570 if ( mFileNameRequester
)
571 mFileNameRequester
->setEnabled( false );
573 #ifndef KDEPIM_ONLY_KLEO
575 connect( mUrlRequester
, SIGNAL(textChanged(QString
)),
576 this, SLOT(slotChanged()) );
578 if ( mFileNameRequester
)
579 connect( mFileNameRequester
, SIGNAL(fileNameChanged(QString
)),
580 this, SLOT(slotChanged()) );
584 void Kleo::CryptoConfigEntryPath::doSave()
586 #ifdef KDEPIM_ONLY_KLEO
587 mEntry
->setURLValue( KUrl::fromPath( mFileNameRequester
->fileName() ) );
589 mEntry
->setURLValue( mUrlRequester
->url() );
593 void Kleo::CryptoConfigEntryPath::doLoad()
595 #ifdef KDEPIM_ONLY_KLEO
596 mFileNameRequester
->setFileName( mEntry
->urlValue().path() );
598 mUrlRequester
->setUrl( mEntry
->urlValue() );
604 Kleo::CryptoConfigEntryDirPath::CryptoConfigEntryDirPath(
605 CryptoConfigModule
* module
,
606 Kleo::CryptoConfigEntry
* entry
, const QString
& entryName
,
607 QGridLayout
* glay
, QWidget
* widget
)
608 : CryptoConfigEntryGUI( module
, entry
, entryName
),
610 mFileNameRequester( 0 )
612 const int row
= glay
->rowCount();
614 #ifdef KDEPIM_ONLY_KLEO
615 req
= mFileNameRequester
= new FileNameRequester( widget
);
616 mFileNameRequester
->setExistingOnly( false );
617 mFileNameRequester
->setFilter( QDir::Dirs
);
619 req
= mUrlRequester
= new KUrlRequester( widget
);
620 mUrlRequester
->setMode( KFile::Directory
| KFile::LocalOnly
);
622 QLabel
*label
= new QLabel( description(), widget
);
623 label
->setBuddy( req
);
624 glay
->addWidget( label
, row
, 1 );
625 glay
->addWidget( req
, row
, 2 );
626 if ( entry
->isReadOnly() ) {
627 label
->setEnabled( false );
628 #ifndef KDEPIM_ONLY_KLEO
630 mUrlRequester
->setEnabled( false );
632 if ( mFileNameRequester
)
633 mFileNameRequester
->setEnabled( false );
635 #ifndef KDEPIM_ONLY_KLEO
637 connect( mUrlRequester
, SIGNAL(textChanged(QString
)),
638 this, SLOT(slotChanged()) );
640 if ( mFileNameRequester
)
641 connect( mFileNameRequester
, SIGNAL(fileNameChanged(QString
)),
642 this, SLOT(slotChanged()) );
646 void Kleo::CryptoConfigEntryDirPath::doSave()
648 #ifdef KDEPIM_ONLY_KLEO
649 mEntry
->setURLValue( KUrl::fromPath( mFileNameRequester
->fileName() ) );
651 mEntry
->setURLValue( mUrlRequester
->url() );
655 void Kleo::CryptoConfigEntryDirPath::doLoad()
657 #ifdef KDEPIM_ONLY_KLEO
658 mFileNameRequester
->setFileName( mEntry
->urlValue().path() );
660 mUrlRequester
->setUrl( mEntry
->urlValue() );
666 Kleo::CryptoConfigEntryURL::CryptoConfigEntryURL(
667 CryptoConfigModule
* module
,
668 Kleo::CryptoConfigEntry
* entry
, const QString
& entryName
,
669 QGridLayout
* glay
, QWidget
* widget
)
670 : CryptoConfigEntryGUI( module
, entry
, entryName
),
672 #ifndef KDEPIM_ONLY_KLEO
676 const int row
= glay
->rowCount();
678 #ifdef KDEPIM_ONLY_KLEO
679 req
= mLineEdit
= new QLineEdit( widget
);
681 req
= mUrlRequester
= new KUrlRequester( widget
);
682 mUrlRequester
->setMode( KFile::File
| KFile::ExistingOnly
);
684 QLabel
*label
= new QLabel( description(), widget
);
685 label
->setBuddy( req
);
686 glay
->addWidget( label
, row
, 1 );
687 glay
->addWidget( req
, row
, 2 );
688 if ( entry
->isReadOnly() ) {
689 label
->setEnabled( false );
690 #ifndef KDEPIM_ONLY_KLEO
692 mUrlRequester
->setEnabled( false );
695 mLineEdit
->setEnabled( false );
697 connect( req
, SIGNAL(textChanged(QString
)),
698 this, SLOT(slotChanged()) );
702 void Kleo::CryptoConfigEntryURL::doSave()
704 #ifdef KDEPIM_ONLY_KLEO
705 mEntry
->setURLValue( KUrl( mLineEdit
->text() ) );
707 mEntry
->setURLValue( mUrlRequester
->url() );
711 void Kleo::CryptoConfigEntryURL::doLoad()
713 #ifdef KDEPIM_ONLY_KLEO
714 mLineEdit
->setText( mEntry
->urlValue().url() );
716 mUrlRequester
->setUrl( mEntry
->urlValue().url() );
722 Kleo::CryptoConfigEntrySpinBox::CryptoConfigEntrySpinBox(
723 CryptoConfigModule
* module
,
724 Kleo::CryptoConfigEntry
* entry
, const QString
& entryName
,
725 QGridLayout
* glay
, QWidget
* widget
)
726 : CryptoConfigEntryGUI( module
, entry
, entryName
)
729 if ( entry
->argType() == Kleo::CryptoConfigEntry::ArgType_None
&& entry
->isList() ) {
731 } else if ( entry
->argType() == Kleo::CryptoConfigEntry::ArgType_UInt
) {
734 Q_ASSERT( entry
->argType() == Kleo::CryptoConfigEntry::ArgType_Int
);
738 const int row
= glay
->rowCount();
739 mNumInput
= new KIntNumInput( widget
);
740 QLabel
*label
= new QLabel( description(), widget
);
741 label
->setBuddy( mNumInput
);
742 glay
->addWidget( label
, row
, 1 );
743 glay
->addWidget( mNumInput
, row
, 2 );
745 if ( entry
->isReadOnly() ) {
746 label
->setEnabled( false );
747 mNumInput
->setEnabled( false );
749 if ( mKind
== UInt
|| mKind
== ListOfNone
)
750 mNumInput
->setMinimum( 0 );
751 connect( mNumInput
, SIGNAL( valueChanged(int) ), SLOT( slotChanged() ) );
755 void Kleo::CryptoConfigEntrySpinBox::doSave()
757 int value
= mNumInput
->value();
760 mEntry
->setNumberOfTimesSet( value
);
763 mEntry
->setUIntValue( value
);
766 mEntry
->setIntValue( value
);
771 void Kleo::CryptoConfigEntrySpinBox::doLoad()
776 value
= mEntry
->numberOfTimesSet();
779 value
= mEntry
->uintValue();
782 value
= mEntry
->intValue();
785 mNumInput
->setValue( value
);
790 Kleo::CryptoConfigEntryCheckBox::CryptoConfigEntryCheckBox(
791 CryptoConfigModule
* module
,
792 Kleo::CryptoConfigEntry
* entry
, const QString
& entryName
,
793 QGridLayout
* glay
, QWidget
* widget
)
794 : CryptoConfigEntryGUI( module
, entry
, entryName
)
796 const int row
= glay
->rowCount();
797 mCheckBox
= new QCheckBox( widget
);
798 glay
->addWidget( mCheckBox
, row
, 1, 1, 2 );
799 mCheckBox
->setText( description() );
800 if ( entry
->isReadOnly() ) {
801 mCheckBox
->setEnabled( false );
803 connect( mCheckBox
, SIGNAL( toggled(bool) ), SLOT( slotChanged() ) );
807 void Kleo::CryptoConfigEntryCheckBox::doSave()
809 mEntry
->setBoolValue( mCheckBox
->isChecked() );
812 void Kleo::CryptoConfigEntryCheckBox::doLoad()
814 mCheckBox
->setChecked( mEntry
->boolValue() );
819 Kleo::CryptoConfigEntryLDAPURL::CryptoConfigEntryLDAPURL(
820 CryptoConfigModule
* module
,
821 Kleo::CryptoConfigEntry
* entry
,
822 const QString
& entryName
,
823 QGridLayout
* glay
, QWidget
* widget
)
824 : CryptoConfigEntryGUI( module
, entry
, entryName
)
826 mLabel
= new QLabel( widget
);
827 mPushButton
= new QPushButton( entry
->isReadOnly() ? i18n("Show...") : i18n( "Edit..." ), widget
);
830 const int row
= glay
->rowCount();
831 QLabel
*label
= new QLabel( description(), widget
);
832 label
->setBuddy( mPushButton
);
833 glay
->addWidget( label
, row
, 1 );
834 QHBoxLayout
* hlay
= new QHBoxLayout
;
835 glay
->addLayout( hlay
, row
, 2 );
836 hlay
->addWidget( mLabel
, 1 );
837 hlay
->addWidget( mPushButton
);
839 if ( entry
->isReadOnly() )
840 mLabel
->setEnabled( false );
841 connect( mPushButton
, SIGNAL( clicked() ), SLOT( slotOpenDialog() ) );
844 static KUrl::List
strings2urls( const QStringList
& strs
) {
846 Q_FOREACH( const QString
& str
, strs
)
847 if ( !str
.isEmpty() )
848 urls
.push_back( KUrl( str
) );
852 static QStringList
urls2strings( const KUrl::List
& urls
) {
854 Q_FOREACH( const KUrl
& url
, urls
)
855 result
.push_back( url
.url() );
859 void Kleo::CryptoConfigEntryLDAPURL::doLoad()
861 setURLList( mEntry
->urlValueList() );
864 void Kleo::CryptoConfigEntryLDAPURL::doSave()
866 mEntry
->setURLValueList( mURLList
);
869 void Kleo::CryptoConfigEntryLDAPURL::slotOpenDialog()
871 // I'm a bad boy and I do it all on the stack. Enough classes already :)
872 // This is just a simple dialog around the directory-services-widget
873 KDialog
dialog( mPushButton
->parentWidget() );
874 dialog
.setCaption( i18n( "Configure LDAP Servers" ) );
875 if ( mEntry
->isReadOnly() )
876 dialog
.setButtons( KDialog::Ok
);
878 dialog
.setButtons( KDialog::Default
|KDialog::Cancel
|KDialog::Ok
);
879 DirectoryServicesWidget
* dirserv
= new DirectoryServicesWidget( &dialog
);
880 dirserv
->setX509ReadOnly( mEntry
->isReadOnly() );
881 dirserv
->setAllowedSchemes( DirectoryServicesWidget::LDAP
);
882 dirserv
->setAllowedProtocols( DirectoryServicesWidget::X509Protocol
);
883 dirserv
->addX509Services( mURLList
);
884 dialog
.setMainWidget( dirserv
);
885 connect( &dialog
, SIGNAL(defaultClicked()), dirserv
, SLOT(clear()) );
886 if ( dialog
.exec() ) {
887 setURLList( dirserv
->x509Services() );
892 void Kleo::CryptoConfigEntryLDAPURL::setURLList( const KUrl::List
& urlList
)
895 if ( mURLList
.isEmpty() )
896 mLabel
->setText( i18n( "No server configured yet" ) );
898 mLabel
->setText( i18np( "1 server configured", "%1 servers configured", mURLList
.count() ) );
903 Kleo::CryptoConfigEntryKeyserver::CryptoConfigEntryKeyserver(
904 CryptoConfigModule
* module
,
905 Kleo::CryptoConfigEntry
* entry
,
906 const QString
& entryName
,
907 QGridLayout
* glay
, QWidget
* widget
)
908 : CryptoConfigEntryGUI( module
, entry
, entryName
)
910 mLabel
= new QLabel( widget
);
911 mPushButton
= new QPushButton( i18n( "Edit..." ), widget
);
914 const int row
= glay
->rowCount();
915 QLabel
*label
= new QLabel( i18n("Use keyserver at"), widget
);
916 label
->setBuddy( mPushButton
);
917 glay
->addWidget( label
, row
, 1 );
918 QHBoxLayout
* hlay
= new QHBoxLayout
;
919 glay
->addLayout( hlay
, row
, 2 );
920 hlay
->addWidget( mLabel
, 1 );
921 hlay
->addWidget( mPushButton
);
923 if ( entry
->isReadOnly() ) {
924 mLabel
->setEnabled( false );
927 connect( mPushButton
, SIGNAL( clicked() ), SLOT( slotOpenDialog() ) );
931 Kleo::ParsedKeyserver
Kleo::parseKeyserver( const QString
& str
) {
932 const QStringList list
= str
.split( QRegExp( QLatin1String( "[\\s,]" ) ), QString::SkipEmptyParts
);
934 return Kleo::ParsedKeyserver();
935 Kleo::ParsedKeyserver result
;
936 result
.url
= list
.front();
937 Q_FOREACH( const QString
& kvpair
, list
.mid( 1 ) ) {
938 const int idx
= kvpair
.indexOf( QLatin1Char( '=' ) );
940 result
.options
.push_back( qMakePair( kvpair
, QString() ) ); // null QString
942 const QString key
= kvpair
.left( idx
);
943 const QString value
= kvpair
.mid( idx
+1 );
944 if ( value
.isEmpty() )
945 result
.options
.push_back( qMakePair( key
, QString("") ) ); // make sure it's not a null QString, only an empty one
947 result
.options
.push_back( qMakePair( key
, value
) );
953 QString
Kleo::assembleKeyserver( const ParsedKeyserver
& keyserver
) {
954 if ( keyserver
.options
.empty() )
955 return keyserver
.url
;
956 QString result
= keyserver
.url
;
957 typedef QPair
<QString
,QString
> Pair
;
958 Q_FOREACH( const Pair
& pair
, keyserver
.options
)
959 if ( pair
.second
.isNull() )
960 result
+= QLatin1Char( ' ' ) + pair
.first
;
962 result
+= QLatin1Char( ' ' ) + pair
.first
+ QLatin1Char( '=' ) + pair
.second
;
966 void Kleo::CryptoConfigEntryKeyserver::doLoad()
968 mParsedKeyserver
= parseKeyserver( mEntry
->stringValue() );
969 mLabel
->setText( mParsedKeyserver
.url
);
972 void Kleo::CryptoConfigEntryKeyserver::doSave()
974 mParsedKeyserver
.url
= mLabel
->text();
975 mEntry
->setStringValue( assembleKeyserver( mParsedKeyserver
) );
978 static KUrl::List
string2urls( const QString
& str
) {
979 return str
.isEmpty() ? KUrl::List() : KUrl( str
) ;
982 static QString
urls2string( const KUrl::List
& urls
) {
983 return urls
.empty() ? QString() : urls
.front().url() ;
986 void Kleo::CryptoConfigEntryKeyserver::slotOpenDialog()
988 // I'm a bad boy and I do it all on the stack. Enough classes already :)
989 // This is just a simple dialog around the directory-services-widget
990 KDialog
dialog( mPushButton
->parentWidget() );
991 dialog
.setCaption( i18n( "Configure Keyservers" ) );
992 dialog
.setButtons( KDialog::Default
|KDialog::Cancel
|KDialog::Ok
);
993 DirectoryServicesWidget
dirserv( &dialog
);
994 dirserv
.setOpenPGPReadOnly( mEntry
->isReadOnly() );
995 dirserv
.setAllowedSchemes( DirectoryServicesWidget::AllSchemes
);
996 dirserv
.setAllowedProtocols( DirectoryServicesWidget::OpenPGPProtocol
);
997 dirserv
.addOpenPGPServices( string2urls( mLabel
->text() ) );
998 dialog
.setMainWidget( &dirserv
);
999 connect( &dialog
, SIGNAL(defaultClicked()), &dirserv
, SLOT(clear()) );
1000 if ( dialog
.exec() ) {
1001 mLabel
->setText( urls2string( dirserv
.openPGPServices() ) );
1006 #include "cryptoconfigmodule.moc"
1007 #include "cryptoconfigmodule_p.moc"