certmanager/lib Library API Documentation

keyapprovaldialog.cpp

00001 /* -*- c++ -*- 00002 keyapprovaldialog.h 00003 00004 This file is part of libkleopatra, the KDE keymanagement library 00005 Copyright (c) 2004 Klarälvdalens Datakonsult AB 00006 00007 Based on kpgpui.h 00008 Copyright (C) 2001,2002 the KPGP authors 00009 See file libkdenetwork/AUTHORS.kpgp for details 00010 00011 Libkleopatra is free software; you can redistribute it and/or 00012 modify it under the terms of the GNU General Public License as 00013 published by the Free Software Foundation; either version 2 of the 00014 License, or (at your option) any later version. 00015 00016 Libkleopatra is distributed in the hope that it will be useful, 00017 but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00019 General Public License for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with this program; if not, write to the Free Software 00023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00024 00025 In addition, as a special exception, the copyright holders give 00026 permission to link the code of this program with any edition of 00027 the Qt library by Trolltech AS, Norway (or with modified versions 00028 of Qt that use the same license as Qt), and distribute linked 00029 combinations including the two. You must obey the GNU General 00030 Public License in all respects for all of the code used other than 00031 Qt. If you modify this file, you may extend this exception to 00032 your version of the file, but you are not obligated to do so. If 00033 you do not wish to do so, delete this exception statement from 00034 your version. 00035 */ 00036 00037 #ifdef HAVE_CONFIG_H 00038 #include <config.h> 00039 #endif 00040 00041 #include "keyapprovaldialog.h" 00042 00043 #include "keyrequester.h" 00044 00045 #include <cryptplugfactory.h> 00046 #include <kleo/cryptobackend.h> 00047 00048 #include <klocale.h> 00049 #include <kglobalsettings.h> 00050 #include <kseparator.h> 00051 00052 #include <qstringlist.h> 00053 #include <qframe.h> 00054 #include <qlayout.h> 00055 #include <qlabel.h> 00056 #include <qcombobox.h> 00057 #include <qscrollview.h> 00058 #include <qpushbutton.h> 00059 00060 #include <gpgmepp/key.h> 00061 00062 #include <assert.h> 00063 00064 static Kleo::EncryptionPreference cb2pref( int i ) { 00065 switch ( i ) { 00066 default: 00067 case 0: return Kleo::UnknownPreference; 00068 case 1: return Kleo::NeverEncrypt; 00069 case 2: return Kleo::AlwaysEncrypt; 00070 case 3: return Kleo::AlwaysEncryptIfPossible; 00071 case 4: return Kleo::AlwaysAskForEncryption; 00072 case 5: return Kleo::AskWheneverPossible; 00073 } 00074 } 00075 00076 static int pref2cb( Kleo::EncryptionPreference p ) { 00077 switch ( p ) { 00078 default: return 0; 00079 case Kleo::NeverEncrypt: return 1; 00080 case Kleo::AlwaysEncrypt: return 2; 00081 case Kleo::AlwaysEncryptIfPossible: return 3; 00082 case Kleo::AlwaysAskForEncryption: return 4; 00083 case Kleo::AskWheneverPossible: return 5; 00084 } 00085 } 00086 00087 static QStringList preferencesStrings() { 00088 return QStringList() << i18n("<none>") 00089 << i18n("Never Encrypt with This Key") 00090 << i18n("Always Encrypt with This Key") 00091 << i18n("Encrypt Whenever Encryption is Possible") 00092 << i18n("Always Ask") 00093 << i18n("Ask Whenever Encryption is Possible"); 00094 } 00095 00096 00097 struct Kleo::KeyApprovalDialog::Private { 00098 Private() : selfRequester( 0 ), prefsChanged( false ) {} 00099 00100 Kleo::KeyRequester * selfRequester; 00101 QStringList addresses; 00102 std::vector<Kleo::KeyRequester*> requesters; 00103 std::vector<QComboBox*> preferences; 00104 bool prefsChanged; 00105 }; 00106 00107 Kleo::KeyApprovalDialog::KeyApprovalDialog( const std::vector<Item> & recipients, 00108 const std::vector<GpgME::Key> & sender, 00109 QWidget * parent, const char * name, 00110 bool modal ) 00111 : KDialogBase( parent, name, modal, i18n("Encryption Key Approval"), Ok|Cancel, Ok ), 00112 d( 0 ) 00113 { 00114 assert( !recipients.empty() ); 00115 00116 d = new Private(); 00117 00118 QFrame *page = makeMainWidget(); 00119 QVBoxLayout * vlay = new QVBoxLayout( page, 0, spacingHint() ); 00120 00121 vlay->addWidget( new QLabel( i18n("The following keys will be used for encryption:"), page ) ); 00122 00123 QScrollView * sv = new QScrollView( page ); 00124 sv->setResizePolicy( QScrollView::AutoOneFit ); 00125 vlay->addWidget( sv ); 00126 00127 QWidget * view = new QWidget( sv->viewport() ); 00128 00129 QGridLayout * glay = new QGridLayout( view, 3, 2, marginHint(), spacingHint() ); 00130 glay->setColStretch( 1, 1 ); 00131 sv->addChild( view ); 00132 00133 int row = -1; 00134 00135 if ( !sender.empty() ) { 00136 ++row; 00137 glay->addWidget( new QLabel( i18n("Your keys:"), view ), row, 0 ); 00138 d->selfRequester = new EncryptionKeyRequester( true, EncryptionKeyRequester::AllProtocols, view ); 00139 d->selfRequester->setKeys( sender ); 00140 glay->addWidget( d->selfRequester, row, 1 ); 00141 ++row; 00142 glay->addMultiCellWidget( new KSeparator( Horizontal, view ), row, row, 0, 1 ); 00143 } 00144 00145 const QStringList prefs = preferencesStrings(); 00146 00147 for ( std::vector<Item>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it ) { 00148 ++row; 00149 glay->addWidget( new QLabel( i18n("Recipient:"), view ), row, 0 ); 00150 glay->addWidget( new QLabel( it->address, view ), row, 1 ); 00151 d->addresses.push_back( it->address ); 00152 00153 ++row; 00154 glay->addWidget( new QLabel( i18n("Encryption keys:"), view ), row, 0 ); 00155 KeyRequester * req = new EncryptionKeyRequester( true, EncryptionKeyRequester::AllProtocols, view ); 00156 req->setKeys( it->keys ); 00157 glay->addWidget( req, row, 1 ); 00158 d->requesters.push_back( req ); 00159 00160 ++row; 00161 glay->addWidget( new QLabel( i18n("Encryption preference:"), view ), row, 0 ); 00162 QComboBox * cb = new QComboBox( false, view ); 00163 cb->insertStringList( prefs ); 00164 glay->addWidget( cb, row, 1 ); 00165 cb->setCurrentItem( pref2cb( it->pref ) ); 00166 connect( cb, SIGNAL(activated(int)), SLOT(slotPrefsChanged()) ); 00167 d->preferences.push_back( cb ); 00168 } 00169 00170 // calculate the optimal width for the dialog 00171 const int dialogWidth = marginHint() 00172 + sv->frameWidth() 00173 + view->sizeHint().width() 00174 + sv->verticalScrollBar()->sizeHint().width() 00175 + sv->frameWidth() 00176 + marginHint() 00177 + 2; 00178 // calculate the optimal height for the dialog 00179 const int dialogHeight = marginHint() 00180 + fontMetrics().height() 00181 + spacingHint() 00182 + sv->frameWidth() 00183 + view->sizeHint().height() 00184 + sv->horizontalScrollBar()->sizeHint().height() 00185 + sv->frameWidth() 00186 + spacingHint() 00187 + actionButton( KDialogBase::Cancel )->sizeHint().height() 00188 + marginHint() 00189 + 2; 00190 00191 // don't make the dialog too large 00192 const QRect desk = KGlobalSettings::desktopGeometry( this ); 00193 setInitialSize( QSize( kMin( dialogWidth, 3 * desk.width() / 4 ), 00194 kMin( dialogHeight, 7 * desk.height() / 8 ) ) ); 00195 } 00196 00197 Kleo::KeyApprovalDialog::~KeyApprovalDialog() { 00198 delete d; d = 0; 00199 } 00200 00201 std::vector<GpgME::Key> Kleo::KeyApprovalDialog::senderKeys() const { 00202 return d->selfRequester ? d->selfRequester->keys() : std::vector<GpgME::Key>() ; 00203 } 00204 00205 std::vector<Kleo::KeyApprovalDialog::Item> Kleo::KeyApprovalDialog::items() const { 00206 assert( d->requesters.size() == d->addresses.size() ); 00207 assert( d->requesters.size() == d->preferences.size() ); 00208 00209 std::vector<Item> result; 00210 result.reserve( d->requesters.size() ); 00211 QStringList::const_iterator ait = d->addresses.begin(); 00212 std::vector<KeyRequester*>::const_iterator rit = d->requesters.begin(); 00213 std::vector<QComboBox*>::const_iterator cit = d->preferences.begin(); 00214 while ( ait != d->addresses.end() ) 00215 result.push_back( Item( *ait++, (*rit++)->keys(), cb2pref( (*cit++)->currentItem() ) ) ); 00216 return result; 00217 } 00218 00219 bool Kleo::KeyApprovalDialog::preferencesChanged() const { 00220 return d->prefsChanged; 00221 } 00222 00223 void Kleo::KeyApprovalDialog::slotPrefsChanged() { 00224 d->prefsChanged = true; 00225 } 00226 00227 #include "keyapprovaldialog.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