24 #include <QApplication>
34 #include <QVBoxLayout>
35 #include <QHBoxLayout>
36 #include <QProgressBar>
37 #include <QButtonGroup>
40 #include <QTreeWidget>
41 #include <QHeaderView>
42 #include <QScrollArea>
44 #include <QAbstractTextDocumentLayout>
47 #include <kconfiggroup.h>
49 #include <kpassworddialog.h>
50 #include <kcharsets.h>
51 #include <kseparator.h>
52 #include <kiconloader.h>
53 #include <kconfigbase.h>
55 #include <kprogressdialog.h>
56 #include <kwindowsystem.h>
57 #include <kpushbutton.h>
58 #include <kglobalsettings.h>
59 #include <klineedit.h>
64 #ifndef QT_NO_TREEWIDGET
65 const int Kpgp::KeySelectionDialog::sCheckSelectionDelay = 250;
71 const QString &caption,
72 const QString &keyID )
75 setCaption( caption );
76 setButtons(
Ok|Cancel );
78 setPixmap( BarIcon(QLatin1String(
"dialog-password")) );
81 setPrompt(i18n(
"Please enter your OpenPGP passphrase:"));
83 setPrompt(i18n(
"Please enter the OpenPGP passphrase for\n\"%1\":", keyID) );
108 QVBoxLayout *topLayout =
new QVBoxLayout(
this );
109 topLayout->setSpacing( KDialog::spacingHint() );
110 topLayout->setMargin( 0 );
112 group =
new QGroupBox( i18n(
"Warning"),
this );
113 QVBoxLayout *lay =
new QVBoxLayout(group);
114 lay->setSpacing( KDialog::spacingHint() );
117 label =
new QLabel( i18n(
"Please check if encryption really "
118 "works before you start using it seriously. Also note that attachments "
119 "are not encrypted by the PGP/GPG module."), group );
120 label->setWordWrap(
true );
121 lay->addWidget( label );
123 QFont labelFont = label->font();
124 labelFont.setBold(
true );
125 label->setFont( labelFont );
129 topLayout->addWidget( group );
130 group =
new QGroupBox( i18n(
"Encryption Tool"),
this );
131 lay =
new QVBoxLayout(group);
132 lay->setSpacing( KDialog::spacingHint() );
134 KHBox * hbox =
new KHBox( group );
135 lay->addWidget( hbox );
136 label =
new QLabel( i18n(
"Select encryption tool to &use:"), hbox );
140 << i18n(
"Autodetect")
141 << i18n(
"GnuPG - Gnu Privacy Guard")
142 << i18n(
"PGP Version 2.x")
143 << i18n(
"PGP Version 5.x")
144 << i18n(
"PGP Version 6.x")
145 << i18n(
"Do not use any encryption tool") );
148 connect(
toolCombo, SIGNAL(activated(
int)),
152 topLayout->addWidget( group );
156 lay->setSpacing( KDialog::spacingHint() );
157 storePass =
new QCheckBox( i18n(
"&Keep passphrase in memory"),
160 connect(
storePass, SIGNAL(toggled(
bool)),
162 msg = i18n(
"<qt><p>When this option is enabled, the passphrase of your "
163 "private key will be remembered by the application as long "
164 "as the application is running. Thus you will only have to "
165 "enter the passphrase once.</p><p>Be aware that this could be a "
166 "security risk. If you leave your computer, others "
167 "can use it to send signed messages and/or read your encrypted "
168 "messages. If a core dump occurs, the contents of your RAM will "
169 "be saved onto disk, including your passphrase.</p>"
170 "<p>Note that when using KMail, this setting only applies "
171 "if you are not using gpg-agent. It is also ignored "
172 "if you are using crypto plugins.</p></qt>" );
175 encToSelf =
new QCheckBox( i18n(
"Always encr&ypt to self"),
177 connect(
encToSelf, SIGNAL(toggled(
bool)),
180 msg = i18n(
"<qt><p>When this option is enabled, the message/file "
181 "will not only be encrypted with the receiver's public key, "
182 "but also with your key. This will enable you to decrypt the "
183 "message/file at a later time. This is generally a good idea."
189 showCipherText =
new QCheckBox( i18n(
"&Show signed/encrypted text after "
195 msg = i18n(
"<qt><p>When this option is enabled, the signed/encrypted text "
196 "will be shown in a separate window, enabling you to know how "
197 "it will look before it is sent. This is a good idea when "
198 "you are verifying that your encryption system works.</p></qt>" );
202 "keys &for approval"));
206 msg = i18n(
"<qt><p>When this option is enabled, the application will "
207 "always show you a list of public keys from which you can "
208 "choose the one it will use for encryption. If it is off, "
209 "the application will only show the dialog if it cannot find "
210 "the right key or if there are several which could be used. "
219 topLayout->addStretch(1);
280 #ifndef QT_NO_TREEWIDGET
285 const QString& title,
288 const bool rememberChoice,
289 const unsigned int allowedKeys,
290 const bool extendedSelection,
294 mAllowedKeys( allowedKeys ),
295 mCurrentContextMenuItem( 0 )
298 setButtons( Default|
Ok|Cancel );
300 KWindowSystem::setIcons( winId(),
301 qApp->windowIcon().pixmap( IconSize( KIconLoader::Desktop ),
302 IconSize( KIconLoader::Desktop ) ),
303 qApp->windowIcon().pixmap( IconSize( KIconLoader::Small ),
304 IconSize( KIconLoader::Small ) ) );
308 KConfigGroup dialogConfig( config,
"Key Selection Dialog" );
310 QSize defaultSize( 580, 400 );
311 QSize dialogSize = dialogConfig.readEntry(
"Dialog size", defaultSize );
313 resize( dialogSize );
315 mCheckSelectionTimer =
new QTimer(
this );
316 mStartSearchTimer =
new QTimer(
this );
317 mStartSearchTimer->setSingleShot(
true );
320 mKeyGoodPix =
new QPixmap( UserIcon(QLatin1String(
"key_ok")) );
321 mKeyBadPix =
new QPixmap( UserIcon(QLatin1String(
"key_bad")) );
322 mKeyUnknownPix =
new QPixmap( UserIcon(QLatin1String(
"key_unknown")) );
323 mKeyValidPix =
new QPixmap( UserIcon(QLatin1String(
"key")) );
325 QFrame *page =
new QFrame(
this );
326 setMainWidget( page );
327 QVBoxLayout *topLayout =
new QVBoxLayout( page );
328 topLayout->setSpacing( spacingHint() );
329 topLayout->setMargin( 0 );
331 if( !text.isEmpty() ) {
332 QLabel *label =
new QLabel( page );
333 label->setText( text );
334 topLayout->addWidget( label );
337 QHBoxLayout * hlay =
new QHBoxLayout();
338 topLayout->addLayout( hlay );
339 QLineEdit * le =
new QLineEdit( page );
340 QLabel *label =
new QLabel( i18n(
"&Search for:"), page );
341 label->setBuddy( le );
342 hlay->addWidget( label );
343 hlay->addWidget( le, 1 );
346 connect( le, SIGNAL(textChanged(QString)),
348 connect( mStartSearchTimer, SIGNAL(timeout()), SLOT(
slotFilter()) );
350 mListView =
new QTreeWidget( page );
351 mListView->setHeaderLabels( QStringList()
353 << i18n(
"User ID") );
354 mListView->setAllColumnsShowFocus(
true );
355 mListView->header()->setStretchLastSection(
true );
356 mListView->setRootIsDecorated(
true );
357 mListView->setSortingEnabled(
true );
358 mListView->header()->setSortIndicatorShown(
true );
359 mListView->sortItems( 1, Qt::AscendingOrder );
361 if( extendedSelection ) {
362 mListView->setSelectionMode( QTreeWidget::ExtendedSelection );
365 topLayout->addWidget( mListView, 10 );
367 if (rememberChoice) {
368 mRememberCB =
new QCheckBox( i18n(
"Remember choice"), page );
369 topLayout->addWidget( mRememberCB );
370 mRememberCB->setWhatsThis(
371 i18n(
"<qt><p>If you check this box your choice will "
372 "be stored and you will not be asked again."
376 initKeylist( keyList, keyIds );
378 QTreeWidgetItem *lvi = 0;
379 if( extendedSelection ) {
380 lvi = mListView->currentItem();
384 if ( mListView->selectedItems().size() > 0 )
385 lvi = mListView->selectedItems().first();
389 mListView->scrollToItem( lvi );
391 if( extendedSelection ) {
392 connect( mCheckSelectionTimer, SIGNAL(timeout()),
394 connect( mListView, SIGNAL(itemSelectionChanged()),
398 connect( mListView, SIGNAL(itemSelectionChanged()),
401 connect( mListView, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
this, SLOT(accept()) );
403 mListView->setContextMenuPolicy( Qt::CustomContextMenu );
404 connect( mListView, SIGNAL(customContextMenuRequested(QPoint)),
407 setButtonGuiItem( KDialog::Default, KGuiItem(i18n(
"&Reread Keys")) );
408 connect(
this, SIGNAL(defaultClicked()),
410 connect(
this, SIGNAL(okClicked()),SLOT(
slotOk()));
411 connect(
this,SIGNAL(cancelClicked()),SLOT(
slotCancel()));
419 KConfigGroup dialogConfig( config,
"Key Selection Dialog" );
420 dialogConfig.writeEntry(
"Dialog size", size() );
424 delete mKeyUnknownPix;
431 if( mListView->selectionMode() == QTreeWidget::ExtendedSelection || mKeyIds.isEmpty() )
434 return mKeyIds.first();
438 void KeySelectionDialog::initKeylist(
const KeyList& keyList,
441 QTreeWidgetItem* firstSelectedItem = 0;
446 foreach (
Key*
key, keyList ) {
449 QTreeWidgetItem* primaryUserID =
new QTreeWidgetItem( mListView );
450 primaryUserID->setText( 0, QLatin1String(curKeyId) );
454 if( keyIds.indexOf( curKeyId ) != -1 ) {
455 if( 0 == firstSelectedItem ) {
456 firstSelectedItem = primaryUserID;
458 primaryUserID->setSelected(
true );
459 mKeyIds.append( curKeyId );
461 primaryUserID->setExpanded(
false );
464 switch( keyValidity( key ) ) {
466 primaryUserID->setData( 0, Qt::DecorationRole, *mKeyUnknownPix );
469 primaryUserID->setData( 0, Qt::DecorationRole, *mKeyValidPix );
472 primaryUserID->setData( 0, Qt::DecorationRole, *mKeyGoodPix );
475 primaryUserID->setData( 0, Qt::DecorationRole, *mKeyBadPix );
479 QTreeWidgetItem* childItem;
481 childItem =
new QTreeWidgetItem( primaryUserID );
482 childItem->setText( 1, i18n(
"Fingerprint: %1" , beautifyFingerprint( key->
primaryFingerprint() ) ) );
483 if( primaryUserID->isSelected() && mListView->selectionMode() == QTreeWidget::ExtendedSelection ) {
484 childItem->setSelected(
true );
487 childItem =
new QTreeWidgetItem( primaryUserID );
488 childItem->setText( 1, keyInfo( key ) );
489 if( primaryUserID->isSelected() && mListView->selectionMode() == QTreeWidget::ExtendedSelection ) {
490 childItem->setSelected(
true );
494 UserIDList::Iterator uidit( userIDs.begin() );
495 if( uidit != userIDs.end() ) {
497 for( ; uidit != userIDs.end(); ++uidit ) {
498 childItem =
new QTreeWidgetItem( primaryUserID );
499 childItem->setText( 1, (*uidit)->text() );
500 if( primaryUserID->isSelected() && mListView->selectionMode() == QTreeWidget::ExtendedSelection ) {
501 childItem->setSelected(
true );
507 if( 0 != firstSelectedItem ) {
508 mListView->setCurrentItem( firstSelectedItem );
513 QString KeySelectionDialog::keyInfo(
const Kpgp::Key *key )
const
515 QString status, remark;
517 status = i18n(
"Revoked");
520 status = i18n(
"Expired");
523 status = i18n(
"Disabled");
526 status = i18n(
"Invalid");
532 status = i18n(
"Undefined trust");
535 status = i18n(
"Untrusted");
538 status = i18n(
"Marginally trusted");
541 status = i18n(
"Fully trusted");
544 status = i18n(
"Ultimately trusted");
548 status = i18n(
"Unknown");
551 remark = i18n(
"Secret key available");
554 remark = i18n(
"Sign only key");
557 remark = i18n(
"Encryption only key");
563 if( remark.isEmpty() ) {
564 return QLatin1Char(
' ') + i18nc(
"creation date and status of an OpenPGP key",
565 "Creation date: %1, Status: %2",
566 KGlobal::locale()->formatDate( dt.date(), KLocale::ShortDate ) ,
570 return QLatin1Char(
' ') + i18nc(
"creation date, status and remark of an OpenPGP key",
571 "Creation date: %1, Status: %2 (%3)",
572 KGlobal::locale()->formatDate( dt.date(), KLocale::ShortDate ) ,
578 QString KeySelectionDialog::beautifyFingerprint(
const QByteArray& fpr )
const
582 if( 40 == fpr.length() ) {
585 result.fill(
' ', 50 );
586 memcpy( result.data() , fpr.data() , 4 );
587 memcpy( result.data() + 5, fpr.data() + 4, 4 );
588 memcpy( result.data() + 10, fpr.data() + 8, 4 );
589 memcpy( result.data() + 15, fpr.data() + 12, 4 );
590 memcpy( result.data() + 20, fpr.data() + 16, 4 );
591 memcpy( result.data() + 26, fpr.data() + 20, 4 );
592 memcpy( result.data() + 31, fpr.data() + 24, 4 );
593 memcpy( result.data() + 36, fpr.data() + 28, 4 );
594 memcpy( result.data() + 41, fpr.data() + 32, 4 );
595 memcpy( result.data() + 46, fpr.data() + 36, 4 );
597 else if( 32 == fpr.length() ) {
600 result.fill(
' ', 48 );
601 memcpy( result.data() , fpr.data() , 2 );
602 memcpy( result.data() + 3, fpr.data() + 2, 2 );
603 memcpy( result.data() + 6, fpr.data() + 4, 2 );
604 memcpy( result.data() + 9, fpr.data() + 6, 2 );
605 memcpy( result.data() + 12, fpr.data() + 8, 2 );
606 memcpy( result.data() + 15, fpr.data() + 10, 2 );
607 memcpy( result.data() + 18, fpr.data() + 12, 2 );
608 memcpy( result.data() + 21, fpr.data() + 14, 2 );
609 memcpy( result.data() + 25, fpr.data() + 16, 2 );
610 memcpy( result.data() + 28, fpr.data() + 18, 2 );
611 memcpy( result.data() + 31, fpr.data() + 20, 2 );
612 memcpy( result.data() + 34, fpr.data() + 22, 2 );
613 memcpy( result.data() + 37, fpr.data() + 24, 2 );
614 memcpy( result.data() + 40, fpr.data() + 26, 2 );
615 memcpy( result.data() + 43, fpr.data() + 28, 2 );
616 memcpy( result.data() + 46, fpr.data() + 30, 2 );
622 return QLatin1String(result);
625 int KeySelectionDialog::keyValidity(
const Kpgp::Key *key )
const
641 else if( ( mAllowedKeys & EncrSignKeys ) ==
SigningKeys ) {
651 else if( ( mAllowedKeys & ValidKeys ) && !key->
isValid() ) {
686 void KeySelectionDialog::updateKeyInfo(
const Kpgp::Key* key,
687 QTreeWidgetItem* lvi )
const
693 if( lvi->parent() != 0 ) {
699 while( lvi->childCount() ) {
700 kDebug( 5326 ) <<
"Deleting '" << lvi->child( 0 )->text( 1 ) <<
"'";
701 delete lvi->takeChild( 0 );
703 kDebug( 5326 ) <<
"Deleting key 0x" << lvi->text( 0 ) <<
" ("
704 << lvi->text( 1 ) <<
")\n";
711 switch( keyValidity( key ) ) {
713 lvi->setData( 0, Qt::DecorationRole, *mKeyUnknownPix );
716 lvi->setData( 0, Qt::DecorationRole, *mKeyValidPix );
719 lvi->setData( 0, Qt::DecorationRole, *mKeyGoodPix );
722 lvi->setData( 0, Qt::DecorationRole, *mKeyBadPix );
729 QTreeWidgetItemIterator it( lvi );
731 if( lvi->text( 1 ).at(0) == QLatin1Char(
' ') ) {
732 lvi->setText( 1, keyInfo( key ) );
741 KeySelectionDialog::keyAdmissibility( QTreeWidgetItem* lvi,
742 TrustCheckMode trustCheckMode )
const
750 if( mAllowedKeys ==
AllKeys ) {
760 KeyID keyId = getKeyId( lvi );
768 if( trustCheckMode == ForceTrustCheck ) {
770 updateKeyInfo( key, lvi );
771 val = keyValidity( key );
774 val = keyValidity( key );
775 if( ( trustCheckMode == AllowExpensiveTrustCheck ) && ( 0 == val ) ) {
777 updateKeyInfo( key, lvi );
778 val = keyValidity( key );
800 kDebug( 5326 ) <<
"Error: Invalid key status value.";
808 KeySelectionDialog::getKeyId(
const QTreeWidgetItem* lvi )
const
813 if( 0 != lvi->parent() ) {
814 keyId = lvi->parent()->text(0).toLocal8Bit();
817 keyId = lvi->text(0).toLocal8Bit();
845 int offsetY = mListView->verticalScrollBar()->value();
847 disconnect( mListView, SIGNAL(itemSelectionChanged()),
850 initKeylist( keys,
KeyIDList( mKeyIds ) );
853 connect( mListView, SIGNAL(itemSelectionChanged()),
858 mListView->verticalScrollBar()->setValue( offsetY );
864 kDebug( 5326 ) <<
"KeySelectionDialog::slotSelectionChanged()";
866 if ( mListView->selectionMode() == QTreeWidget::ExtendedSelection ) {
870 mCheckSelectionTimer->start( sCheckSelectionDelay );
872 if ( mListView->selectedItems().size() > 0 )
880 kDebug( 5326 ) <<
"KeySelectionDialog::slotCheckSelection()";
882 if( mListView->selectionMode() != QTreeWidget::ExtendedSelection ) {
884 KeyID keyId = getKeyId( plvi );
885 if( !keyId.isEmpty() ) {
886 mKeyIds.append( keyId );
887 enableButton(
Ok, 1 == keyAdmissibility( plvi, AllowExpensiveTrustCheck ) );
890 enableButton(
Ok,
false );
894 mCheckSelectionTimer->stop();
898 disconnect( mListView, SIGNAL(itemSelectionChanged()),
904 bool keysAllowed =
true;
905 enum { UNKNOWN, SELECTED, DESELECTED } userAction = UNKNOWN;
907 for(
int lviIndex = 0; lviIndex < mListView->topLevelItemCount(); ++lviIndex ) {
908 QTreeWidgetItem *lvi = mListView->topLevelItem( lviIndex );
915 int itemCount = 1 + lvi->childCount();
916 int selectedCount = lvi->isSelected() ? 1 : 0;
917 for(
int clviIndex = 0; clviIndex < lvi->childCount(); ++clviIndex ) {
918 QTreeWidgetItem *clvi = lvi->child( clviIndex );
919 if( clvi->isSelected() ) {
924 if( userAction == UNKNOWN ) {
929 if( 0 < selectedCount ) {
930 if( -1 == mKeyIds.indexOf( lvi->text(0).toLocal8Bit() ) ) {
933 kDebug( 5326 ) <<
"selectedCount:"<<selectedCount<<
"/"<<itemCount
934 <<
"--- User selected key"<<lvi->text(0);
935 userAction = SELECTED;
937 else if( ( itemCount > selectedCount ) &&
938 ( -1 != mKeyIds.indexOf( lvi->text(0).toLocal8Bit() ) ) ) {
941 kDebug( 5326 ) <<
"selectedCount:"<<selectedCount<<
"/"<<itemCount
942 <<
"--- User deselected key"<<lvi->text(0);
943 userAction = DESELECTED;
947 if( itemCount == selectedCount ) {
949 KeyID keyId = lvi->text(0).toLocal8Bit();
950 newKeyIdList.append( keyId );
951 int admissibility = keyAdmissibility( lvi, NoExpensiveTrustCheck );
952 if( -1 == admissibility ) {
955 else if ( 0 == admissibility ) {
956 keysToBeChecked.append( lvi );
959 else if( 0 < selectedCount ) {
962 if( userAction == SELECTED ) {
964 lvi->setSelected(
true );
965 for(
int clviIndex = 0; clviIndex < lvi->childCount(); ++clviIndex ) {
966 QTreeWidgetItem *clvi = lvi->child( clviIndex );
967 clvi->setSelected(
true );
970 KeyID keyId = lvi->text(0).toLocal8Bit();
971 newKeyIdList.append( keyId );
972 int admissibility = keyAdmissibility( lvi, NoExpensiveTrustCheck );
973 if( -1 == admissibility ) {
976 else if ( 0 == admissibility ) {
977 keysToBeChecked.append( lvi );
982 lvi->setSelected(
false );
983 for (
int clviIndex = 0; clviIndex < lvi->childCount(); ++clviIndex ) {
984 QTreeWidgetItem *clvi = lvi->child( clviIndex );
985 clvi->setSelected(
false );
990 kDebug( 5326 ) <<
"Selected keys:" << newKeyIdList.
toStringList().join(QLatin1String(
","));
991 mKeyIds = newKeyIdList;
992 if( !keysToBeChecked.isEmpty() ) {
993 keysAllowed = keysAllowed && checkKeys( keysToBeChecked );
995 enableButton(
Ok, keysAllowed );
997 connect( mListView, SIGNAL(selectionChanged()),
1005 KProgressDialog* pProgressDlg = 0;
1006 bool keysAllowed =
true;
1007 kDebug( 5326 ) <<
"Checking keys...";
1009 pProgressDlg =
new KProgressDialog( 0, i18n(
"Checking Keys"),
1010 i18n(
"Checking key 0xMMMMMMMM..."));
1011 pProgressDlg->setModal(
true );
1012 pProgressDlg->setAllowCancel(
false );
1013 pProgressDlg->progressBar()->setMaximum( keys.count() );
1014 pProgressDlg->setMinimumDuration( 1000 );
1015 pProgressDlg->show();
1020 kDebug( 5326 ) <<
"Checking key 0x" << getKeyId( *it ) <<
"...";
1021 pProgressDlg->setLabelText( i18n(
"Checking key 0x%1...",
1022 QString::fromLatin1( getKeyId( *it ) ) ) );
1023 qApp->processEvents();
1024 keysAllowed = keysAllowed && ( -1 != keyAdmissibility( *it, AllowExpensiveTrustCheck ) );
1025 pProgressDlg->progressBar()->setValue( pProgressDlg->progressBar()->value() + 1 );
1026 qApp->processEvents();
1029 delete pProgressDlg;
1038 QTreeWidgetItem *lvi = mListView->itemAt( pos );
1043 mCurrentContextMenuItem = lvi;
1046 menu.addAction( i18n(
"Recheck Key" ),
this, SLOT(
slotRecheckKey()) );
1047 menu.exec( mListView->viewport()->mapToGlobal( pos ) );
1053 if( 0 != mCurrentContextMenuItem ) {
1055 keyAdmissibility( mCurrentContextMenuItem, ForceTrustCheck );
1063 if( mCheckSelectionTimer->isActive() ) {
1066 mStartSearchTimer->stop();
1073 mCheckSelectionTimer->stop();
1074 mStartSearchTimer->stop();
1081 mSearchText = text.trimmed().toUpper();
1082 mStartSearchTimer->start( sCheckSelectionDelay );
1087 if ( mSearchText.isEmpty() ) {
1093 QRegExp keyIdRegExp( QLatin1String(
"(?:0x)?[A-F0-9]{1,8}"), Qt::CaseInsensitive );
1094 if ( keyIdRegExp.exactMatch( mSearchText ) ) {
1095 if ( mSearchText.startsWith( QLatin1String(
"0X") ) )
1097 filterByKeyID( mSearchText.mid( 2 ) );
1100 filterByKeyIDOrUID( mSearchText );
1103 filterByUID( mSearchText );
1107 void KeySelectionDialog::filterByKeyID(
const QString & keyID )
1109 assert( keyID.length() <= 8 );
1110 assert( !keyID.isEmpty() );
1111 if ( keyID.isEmpty() )
1114 for (
int i = 0; i < mListView->topLevelItemCount(); ++i ) {
1115 QTreeWidgetItem * item = mListView->topLevelItem( i );
1116 item->setHidden( !item->text( 0 ).toUpper().startsWith( keyID ) );
1121 void KeySelectionDialog::filterByKeyIDOrUID(
const QString & str )
1123 assert( !str.isEmpty() );
1126 QRegExp rx( QLatin1String(
"\\b") + QRegExp::escape( str ), Qt::CaseInsensitive );
1128 for (
int i = 0; i < mListView->topLevelItemCount(); ++i ) {
1129 QTreeWidgetItem * item = mListView->topLevelItem( i );
1130 item->setHidden( !item->text( 0 ).toUpper().startsWith( str )
1131 && rx.indexIn( item->text( 1 ) ) < 0
1132 && !anyChildMatches( item, rx ) );
1136 void KeySelectionDialog::filterByUID(
const QString & str )
1138 assert( !str.isEmpty() );
1141 QRegExp rx( QLatin1String(
"\\b") + QRegExp::escape( str ), Qt::CaseInsensitive );
1143 for (
int i = 0; i < mListView->topLevelItemCount(); ++i ) {
1144 QTreeWidgetItem * item = mListView->topLevelItem( i );
1145 item->setHidden( rx.indexIn( item->text( 1 ) ) < 0
1146 && !anyChildMatches( item, rx ) );
1151 bool KeySelectionDialog::anyChildMatches(
const QTreeWidgetItem * item, QRegExp & rx )
const
1156 for (
int i = 0; i < item->childCount(); ++i ) {
1157 QTreeWidgetItem* it = item->child( i );
1158 if ( rx.indexIn( it->text( 1 ) ) >= 0 ) {
1167 void KeySelectionDialog::showAllItems()
1169 for ( QTreeWidgetItemIterator it( mListView ); *it; ++it )
1170 (*it)->setHidden(
false );
1173 #endif // QT_NO_TREEWIDGET
1177 unsigned int allowedKeys,
const char * name )
1179 mDialogCaption( i18n(
"OpenPGP Key Selection") ),
1180 mDialogMessage( i18n(
"Please select an OpenPGP key to use.") ),
1181 mMulti( multipleKeys ),
1182 mAllowedKeys( allowedKeys ),
1185 setObjectName( QLatin1String(name) );
1186 QHBoxLayout * hlay =
new QHBoxLayout(
this );
1187 hlay->setSpacing( KDialog::spacingHint() );
1188 hlay->setMargin( 0 );
1191 mLabel =
new QLabel(
this );
1192 mLabel->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
1197 mEraseButton->setSizePolicy( QSizePolicy( QSizePolicy::Minimum,
1198 QSizePolicy::Minimum ) );
1199 mEraseButton->setIcon( KIcon( QLatin1String(
"edit-clear-locationbar-rtl") ) );
1206 hlay->addWidget(
mLabel, 1 );
1213 setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding,
1214 QSizePolicy::Fixed ) );
1227 if (
mKeys.empty() ) {
1231 if (
mKeys.size() > 1 )
1244 kWarning(5326) <<
"Kpgp::KeyRequester::slotDialogButtonClicked(): No pgp module found!";
1271 if ( multi ==
mMulti )
return;
1273 if ( !multi &&
mKeys.size() > 1 )
1289 unsigned int allowed,
const char * name )
1305 unsigned int allowed,
const char * name )
1331 const QVector<KeyIDList>& keyIDs,
1332 const int allowedKeys,
1336 mAllowedKeys( allowedKeys ),
1337 mPrefsChanged( false )
1339 setCaption( i18n(
"Encryption Key Approval") );
1340 setButtons(
Ok|Cancel );
1352 QFrame *page =
new QFrame(
this );
1353 setMainWidget( page );
1354 QVBoxLayout *topLayout =
new QVBoxLayout( page );
1355 topLayout->setSpacing( KDialog::spacingHint() );
1356 topLayout->setMargin( 0 );
1358 QLabel *label =
new QLabel( i18n(
"The following keys will be used for "
1361 topLayout->addWidget( label );
1363 QScrollArea* sv =
new QScrollArea( page );
1364 sv->setWidgetResizable(
true );
1365 topLayout->addWidget( sv );
1366 KVBox* bigvbox =
new KVBox;
1367 sv->setWidget( bigvbox );
1369 bigvbox->setSpacing( KDialog::spacingHint() );
1371 QButtonGroup *mChangeButtonGroup =
new QButtonGroup;
1372 mAddressLabels.resize( addresses.count() );
1373 mKeyIdsLabels.resize( keyIDs.size() );
1375 mEncrPrefCombos.resize( addresses.count() );
1380 KHBox* hbox =
new KHBox( bigvbox );
1381 new QLabel( i18n(
"Your keys:"), hbox );
1382 QLabel* keyidsL =
new QLabel( hbox );
1383 if( keyIDs[0].isEmpty() ) {
1384 keyidsL->setText( i18nc(
"@info",
"<placeholder>none</placeholder> means 'no key'" ) );
1387 keyidsL->setText( QLatin1String(
"0x") + keyIDs[0].toStringList().join( QLatin1String(
"\n0x") ) );
1389 keyidsL->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
1401 QPushButton *button =
new QPushButton( i18n(
"Change..."), hbox );
1402 mChangeButtonGroup->addButton( button );
1403 button->setAutoDefault(
false );
1404 hbox->setStretchFactor( keyidsL, 10 );
1405 mKeyIdsLabels.insert( 0, keyidsL );
1409 new KSeparator( Qt::Horizontal, bigvbox );
1414 mKeyIdsLabels.insert( 0, 0 );
1418 QStringList::ConstIterator ait;
1419 QVector<KeyIDList>::const_iterator kit;
1421 for( ait = addresses.begin(), kit = keyIDs.begin(), i = 0;
1422 ( ait != addresses.end() ) && ( kit != keyIDs.end() );
1423 ++ait, ++kit, ++i ) {
1428 new KSeparator( Qt::Horizontal, bigvbox );
1431 KHBox *hbox =
new KHBox( bigvbox );
1432 new QLabel( i18n(
"Recipient:"), hbox );
1433 QLabel *addressL =
new QLabel( *ait, hbox );
1434 hbox->setStretchFactor( addressL, 10 );
1435 mAddressLabels.insert( i, addressL );
1437 hbox =
new KHBox( bigvbox );
1438 new QLabel( i18n(
"Encryption keys:"), hbox );
1439 QLabel* keyidsL =
new QLabel( hbox );
1440 if( (*kit).isEmpty() ) {
1441 keyidsL->setText( i18nc(
"@info",
"<placeholder>none</placeholder> means 'no key'" ) );
1444 keyidsL->setText( QLatin1String(
"0x") + (*kit).toStringList().join( QLatin1String(
"\n0x") ) );
1446 keyidsL->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
1458 QPushButton *button =
new QPushButton( i18n(
"Change..."), hbox );
1459 mChangeButtonGroup->addButton( button );
1460 button->setAutoDefault(
false );
1461 hbox->setStretchFactor( keyidsL, 10 );
1462 mKeyIdsLabels.insert( i + 1, keyidsL );
1466 hbox =
new KHBox( bigvbox );
1467 new QLabel( i18n(
"Encryption preference:"), hbox );
1468 QComboBox *encrPrefCombo =
new QComboBox( hbox );
1469 encrPrefCombo->addItem( i18nc(
"@item:inlistbox",
"<placeholder>none</placeholder>") );
1470 encrPrefCombo->addItem( i18nc(
"@item:inlistbox",
"Never Encrypt with This Key") );
1471 encrPrefCombo->addItem( i18nc(
"@item:inlistbox",
"Always Encrypt with This Key") );
1472 encrPrefCombo->addItem( i18nc(
"@item:inlistbox",
"Encrypt Whenever Encryption is Possible") );
1473 encrPrefCombo->addItem( i18nc(
"@item:inlistbox",
"Always Ask") );
1474 encrPrefCombo->addItem( i18nc(
"@item:inlistbox",
"Ask Whenever Encryption is Possible") );
1477 switch( encrPref ) {
1479 encrPrefCombo->setCurrentIndex( 1 );
1482 encrPrefCombo->setCurrentIndex( 2 );
1485 encrPrefCombo->setCurrentIndex( 3 );
1488 encrPrefCombo->setCurrentIndex( 4 );
1491 encrPrefCombo->setCurrentIndex( 5 );
1494 encrPrefCombo->setCurrentIndex( 0 );
1496 connect( encrPrefCombo, SIGNAL(activated(
int)),
1498 mEncrPrefCombos.insert( i, encrPrefCombo );
1500 connect( mChangeButtonGroup, SIGNAL(buttonClicked(
int)),
1503 QSize size = sizeHint();
1506 QRect desk = KGlobalSettings::desktopGeometry(
this);
1507 int screenWidth = desk.width();
1508 if( size.width() > 3*screenWidth/4 )
1509 size.setWidth( 3*screenWidth/4 );
1510 int screenHeight = desk.height();
1511 if( size.height() > 7*screenHeight/8 )
1512 size.setHeight( 7*screenHeight/8 );
1513 connect(
this,SIGNAL(okClicked()),SLOT(
slotOk()));
1514 connect(
this,SIGNAL(cancelClicked()),SLOT(
slotCancel()));
1515 setInitialSize( size );
1523 kDebug( 5326 )<<
"Key approval dialog size is"
1524 <<width()<<
"x"<<height();
1529 if( !mEncryptToSelf )
1534 i18nc(
"if in your language something like "
1535 "'key(s)' isn't possible please "
1536 "use the plural in the translation",
1537 "Select the key(s) which should "
1538 "be used to encrypt the message "
1546 i18nc(
"if in your language something like "
1547 "'key(s)' isn't possible please "
1548 "use the plural in the translation",
1549 "Select the key(s) which should "
1550 "be used to encrypt the message "
1552 mAddressLabels[nr-1]->text() ),
1554 mAddressLabels[nr-1]->text(),
1557 if( !keyIds.isEmpty() ) {
1559 QLabel* keyidsL = mKeyIdsLabels[nr];
1560 keyidsL->setText( QLatin1String(
"0x") + keyIds.
toStringList().join( QLatin1String(
"\n0x") ) );
1580 if( mPrefsChanged ) {
1582 for(
int i = 0; i < mAddressLabels.size(); ++i ) {
1585 switch( mEncrPrefCombos[i]->currentIndex() ) {
1623 const QByteArray & charset,
QWidget *parent )
1626 setCaption( i18n(
"OpenPGP Information") );
1627 setButtons(
Ok|Cancel );
1630 QFrame *page =
new QFrame(
this );
1631 setMainWidget( page );
1632 QVBoxLayout *topLayout =
new QVBoxLayout( page );
1633 topLayout->setSpacing( spacingHint() );
1634 topLayout->setMargin( 0 );
1636 QLabel *label =
new QLabel( page );
1637 label->setText(i18n(
"Result of the last encryption/sign operation:"));
1638 topLayout->addWidget( label );
1640 mEditBox =
new QTextEdit( page );
1641 mEditBox->setReadOnly(
true);
1642 topLayout->addWidget( mEditBox, 10 );
1644 QString unicodeText;
1645 if (charset.isEmpty())
1646 unicodeText = QString::fromLocal8Bit(text.data());
1649 QTextCodec *codec = KGlobal::charsets()->codecForName(QLatin1String(charset), ok);
1651 unicodeText = QString::fromLocal8Bit(text.data());
1653 unicodeText = codec->toUnicode(text.data(), text.length());
1656 mEditBox->setText(unicodeText);
1661 void CipherTextDialog::setMinimumSize()
1665 (void) mEditBox->document()->documentLayout()->documentSize();
1667 mEditBox->setMinimumHeight( mEditBox->fontMetrics().lineSpacing() * 25 );
1669 int textWidth = mEditBox->viewport()->width() + 30;
1672 int maxWidth = KGlobalSettings::desktopGeometry(parentWidget()).width()-100;
1674 mEditBox->setMinimumWidth( qMin( textWidth, maxWidth ) );
1691 #include "kpgpui.moc"
KeyApprovalDialog(const QStringList &, const QVector< KeyIDList > &, const int allowedKeys, QWidget *parent=0)
bool isValidEncryptionKey() const
Returns true if the key is a valid encryption key.
Validity
These are the possible validity values for a PGP user id and for the owner trust. ...
QPushButton * mEraseButton
void slotDialogButtonClicked()
virtual void slotFilter()
const UserIDList userIDs() const
Returns the list of userIDs.
virtual ~PassphraseDialog()
virtual void slotSelectionChanged()
bool encryptToSelf(void) const
bool isMultipleKeysEnabled() const
virtual void slotRereadKeys()
void setAllowedKeys(int allowed)
virtual void slotSearch(const QString &text)
void readPublicKeys(bool reread=false)
Reads the list of public keys if necessary or if reread is true.
void slotPrefsChanged(int)
void setEncryptionPreference(const QString &address, const EncryptPref pref)
Writes the given encryption preference for the given address to the config file.
bool showCipherText(void) const
KeySelectionDialog(const KeyList &keyList, const QString &title, const QString &text=QString(), const KeyIDList &keyIds=KeyIDList(), const bool rememberChoice=false, const unsigned int allowedKeys=AllKeys, const bool extendedSelection=false, QWidget *parent=0)
allowedKeys: see kpgp.h
virtual void virtual_hook(int, void *)
QPushButton * mDialogButton
virtual void virtual_hook(int, void *)
KeyID selectSecretKey(const QString &title, const QString &text=QString(), const KeyID &keyId=KeyID())
Shows a key selection dialog with all secret keys and the given title and the (optional) text...
bool canEncrypt() const
Returns true if the key can be used to encrypt data.
Key * rereadKey(const KeyID &keyID, const bool readTrust=true)
Rereads the key data for the given key and returns the reread data.
void setStorePassPhrase(bool)
store passphrase in pgp object Problem: passphrase stays in memory.
virtual KeyID key() const
Returns the key ID of the selected key in single selection mode.
bool showKeyApprovalDlg(void) const
const KeyList publicKeys()
get the list of cached public keys.
void setDialogMessage(const QString &message)
virtual KeyIDList keys() const
Returns a list of selected key IDs.
time_t creationDate() const
Returns the creation date of the primary subkey.
bool isValid() const
Returns true if the key is valid, i.e.
static Kpgp::Module * getKpgp()
return the actual pgp object
void setKeyIDs(const KeyIDList &keyIDs)
bool invalid() const
Returns true if the key is invalid.
bool canSign() const
Returns true if the key can be used to sign data.
bool disabled() const
Returns true if the key has been disabled.
KeyRequester(QWidget *parent=0, bool multipleKeys=false, unsigned int allowedKeys=AllKeys, const char *name=0)
const KeyList secretKeys()
get the list of cached secret keys.
CipherTextDialog(const QByteArray &text, const QByteArray &charset=0, QWidget *parent=0)
bool revoked() const
Returns true if the key has been revoked.
bool secret() const
Returns true if the key is a secret key.
KeyIDList selectPublicKeys(const QString &title, const QString &text=QString(), const KeyIDList &oldKeyIds=KeyIDList(), const QString &address=QString(), const unsigned int allowedKeys=AllKeys)
Shows a key selection dialog with all public keys and the given title and the (optional) text...
virtual void slotCheckSelection(QTreeWidgetItem *=0)
void slotEraseButtonClicked()
virtual void slotRecheckKey()
void setDialogCaption(const QString &caption)
void slotChangeEncryptionKey(int)
virtual ~KeySelectionDialog()
KeyIDList keyRequestHook(Module *pgp) const
Reimplement this to return a list of selected keys.
virtual void slotRMB(const QPoint &pos)
enum Kpgp::Module::PGPType pgpType
bool expired() const
Returns true if the key has expired.
void setShowCipherText(const bool flag)
KeyIDList keyRequestHook(Module *pgp) const
Reimplement this to return a list of selected keys.
QString primaryUserID() const
Returns the primary user ID or a null string if there are no user IDs.
QList< UserID * > UserIDList
SecretKeyRequester(QWidget *parent=0, bool multipleKeys=false, unsigned int allowedKeys=SecretKeys, const char *name=0)
Validity keyTrust() const
Returns the trust value of this key.
void setMultipleKeysEnabled(bool enable)
QGroupBox * mpOptionsGroupBox
void setEncryptToSelf(bool flag)
always encrypt message to oneself?
EncryptPref encryptionPreference(const QString &address)
Reads the encryption preference for the given address from the config file.
Config(QWidget *parent=0, bool encrypt=true)
virtual void writeConfig(bool sync)
bool isValidSigningKey() const
Returns true if the key is a valid signing key.
virtual void slotCancel()
QByteArray primaryFingerprint() const
Returns the fingerprint of the primary key or a null string if there are no subkeys.
virtual KeyIDList keyRequestHook(Module *pgp) const =0
Reimplement this to return a list of selected keys.
virtual void applySettings()
EncryptPref
These are the possible preferences for encryption.
PublicKeyRequester(QWidget *parent=0, bool multipleKeys=false, unsigned int allowedKeys=PublicKeys, const char *name=0)
This class is used to store information about a PGP key.
virtual void virtual_hook(int, void *)
QCheckBox * showCipherText
QStringList toStringList() const
Converts from a KeyIDList to a QStringList.
Key * publicKey(const KeyID &keyID)
Returns the public key with the given key ID or null if no matching key is found. ...
QCheckBox * showKeyApprovalDlg
static KConfig * getConfig()
get the kpgp config object
void setShowKeyApprovalDlg(const bool flag)
void readSecretKeys(bool reread=false)
Reads the list of secret keys if necessary or if reread is true.
virtual void slotCancel()
bool storePassPhrase(void) const
virtual ~SecretKeyRequester()
PassphraseDialog(QWidget *parent=0, const QString &caption=QString(), const QString &keyID=QString())
virtual ~PublicKeyRequester()
KeyID primaryKeyID() const
Returns the key ID of the primary key or a null string if there are no subkeys.