41 #include "keyapprovaldialog.h"
43 #include "keyrequester.h"
45 #include <cryptplugfactory.h>
46 #include <kleo/cryptobackend.h>
48 #include <tdelocale.h>
49 #include <tdeglobalsettings.h>
50 #include <kseparator.h>
52 #include <tqstringlist.h>
56 #include <tqcombobox.h>
57 #include <tqscrollview.h>
58 #include <tqpushbutton.h>
60 #include <gpgmepp/key.h>
64 static Kleo::EncryptionPreference cb2pref(
int i ) {
67 case 0:
return Kleo::UnknownPreference;
68 case 1:
return Kleo::NeverEncrypt;
69 case 2:
return Kleo::AlwaysEncrypt;
70 case 3:
return Kleo::AlwaysEncryptIfPossible;
71 case 4:
return Kleo::AlwaysAskForEncryption;
72 case 5:
return Kleo::AskWheneverPossible;
76 static int pref2cb( Kleo::EncryptionPreference p ) {
79 case Kleo::NeverEncrypt:
return 1;
80 case Kleo::AlwaysEncrypt:
return 2;
81 case Kleo::AlwaysEncryptIfPossible:
return 3;
82 case Kleo::AlwaysAskForEncryption:
return 4;
83 case Kleo::AskWheneverPossible:
return 5;
87 static TQStringList preferencesStrings() {
88 return TQStringList() << i18n(
"<none>")
89 << i18n(
"Never Encrypt with This Key")
90 << i18n(
"Always Encrypt with This Key")
91 << i18n(
"Encrypt Whenever Encryption is Possible")
93 << i18n(
"Ask Whenever Encryption is Possible");
97 struct Kleo::KeyApprovalDialog::Private {
98 Private() : selfRequester( 0 ), prefsChanged( false ) {}
101 TQStringList addresses;
102 std::vector<Kleo::KeyRequester*> requesters;
103 std::vector<TQComboBox*> preferences;
107 Kleo::KeyApprovalDialog::KeyApprovalDialog(
const std::vector<Item> & recipients,
108 const std::vector<GpgME::Key> & sender,
109 TQWidget * parent,
const char * name,
111 : KDialogBase( parent, name, modal, i18n(
"Encryption Key Approval"), Ok|Cancel, Ok ),
114 assert( !recipients.empty() );
118 TQFrame *page = makeMainWidget();
119 TQVBoxLayout * vlay =
new TQVBoxLayout( page, 0, spacingHint() );
121 vlay->addWidget(
new TQLabel( i18n(
"The following keys will be used for encryption:"), page ) );
123 TQScrollView * sv =
new TQScrollView( page );
124 sv->setResizePolicy( TQScrollView::AutoOneFit );
125 vlay->addWidget( sv );
127 TQWidget * view =
new TQWidget( sv->viewport() );
129 TQGridLayout * glay =
new TQGridLayout( view, 3, 2, marginHint(), spacingHint() );
130 glay->setColStretch( 1, 1 );
131 sv->addChild( view );
135 if ( !sender.empty() ) {
137 glay->addWidget(
new TQLabel( i18n(
"Your keys:"), view ), row, 0 );
138 d->selfRequester =
new EncryptionKeyRequester(
true, EncryptionKeyRequester::AllProtocols, view );
139 d->selfRequester->setKeys( sender );
140 glay->addWidget( d->selfRequester, row, 1 );
142 glay->addMultiCellWidget(
new KSeparator( TQt::Horizontal, view ), row, row, 0, 1 );
145 const TQStringList prefs = preferencesStrings();
147 for ( std::vector<Item>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it ) {
149 glay->addWidget(
new TQLabel( i18n(
"Recipient:"), view ), row, 0 );
150 glay->addWidget(
new TQLabel( it->address, view ), row, 1 );
151 d->addresses.push_back( it->address );
154 glay->addWidget(
new TQLabel( i18n(
"Encryption keys:"), view ), row, 0 );
155 KeyRequester * req =
new EncryptionKeyRequester(
true, EncryptionKeyRequester::AllProtocols, view );
156 req->setKeys( it->keys );
157 glay->addWidget( req, row, 1 );
158 d->requesters.push_back( req );
161 glay->addWidget(
new TQLabel( i18n(
"Encryption preference:"), view ), row, 0 );
162 TQComboBox * cb =
new TQComboBox(
false, view );
163 cb->insertStringList( prefs );
164 glay->addWidget( cb, row, 1 );
165 cb->setCurrentItem( pref2cb( it->pref ) );
166 connect( cb, TQ_SIGNAL(activated(
int)), TQ_SLOT(slotPrefsChanged()) );
167 d->preferences.push_back( cb );
171 const int dialogWidth = marginHint()
173 + view->sizeHint().width()
174 + sv->verticalScrollBar()->sizeHint().width()
179 const int dialogHeight = marginHint()
180 + fontMetrics().height()
183 + view->sizeHint().height()
184 + sv->horizontalScrollBar()->sizeHint().height()
187 + actionButton( KDialogBase::Cancel )->sizeHint().height()
192 const TQRect desk = TDEGlobalSettings::desktopGeometry(
this );
193 setInitialSize( TQSize( kMin( dialogWidth, 3 * desk.width() / 4 ),
194 kMin( dialogHeight, 7 * desk.height() / 8 ) ) );
197 Kleo::KeyApprovalDialog::~KeyApprovalDialog() {
201 std::vector<GpgME::Key> Kleo::KeyApprovalDialog::senderKeys()
const {
202 return d->selfRequester ? d->selfRequester->keys() : std::vector<GpgME::Key>() ;
205 std::vector<Kleo::KeyApprovalDialog::Item> Kleo::KeyApprovalDialog::items()
const {
206 assert( d->requesters.size() == d->addresses.size() );
207 assert( d->requesters.size() == d->preferences.size() );
209 std::vector<Item> result;
210 result.reserve( d->requesters.size() );
211 TQStringList::const_iterator ait = d->addresses.begin();
212 std::vector<KeyRequester*>::const_iterator rit = d->requesters.begin();
213 std::vector<TQComboBox*>::const_iterator cit = d->preferences.begin();
214 while ( ait != d->addresses.end() )
215 result.push_back( Item( *ait++, (*rit++)->keys(), cb2pref( (*cit++)->currentItem() ) ) );
219 bool Kleo::KeyApprovalDialog::preferencesChanged()
const {
220 return d->prefsChanged;
223 void Kleo::KeyApprovalDialog::slotPrefsChanged() {
224 d->prefsChanged =
true;
227 #include "keyapprovaldialog.moc"
Base class for SigningKeyRequester and EncryptionKeyRequester.