43 #include <kpushbutton.h>
45 #include <kglobalsettings.h>
46 #include <kseparator.h>
48 #include <QStringList>
52 #include <QScrollArea>
53 #include <QPushButton>
54 #include <QVBoxLayout>
55 #include <QGridLayout>
57 #include <gpgme++/key.h>
85 return QStringList() << i18n(
"<placeholder>none</placeholder>")
86 << i18n(
"Never Encrypt with This Key")
87 << i18n(
"Always Encrypt with This Key")
88 << i18n(
"Encrypt Whenever Encryption is Possible")
90 << i18n(
"Ask Whenever Encryption is Possible");
94 class Kleo::KeyApprovalDialog::Private {
96 Private() : selfRequester( 0 ), prefsChanged( false ) {}
99 QStringList addresses;
100 std::vector<Kleo::KeyRequester*> requesters;
101 std::vector<QComboBox*> preferences;
106 const std::vector<GpgME::Key> & sender,
111 setCaption( i18n(
"Encryption Key Approval") );
112 setButtons( Ok|Cancel );
113 setDefaultButton( Ok );
114 assert( !recipients.empty() );
118 setMainWidget( page );
119 QVBoxLayout * vlay =
new QVBoxLayout( page );
120 vlay->setMargin( 0 );
121 vlay->setSpacing( spacingHint() );
123 vlay->addWidget(
new QLabel( i18n(
"The following keys will be used for encryption:"), page ) );
125 QScrollArea * sv =
new QScrollArea( page );
127 sv->setWidgetResizable(
true);
129 vlay->addWidget( sv );
133 QGridLayout * glay =
new QGridLayout( view );
134 glay->setMargin( marginHint() );
135 glay->setSpacing( spacingHint() );
136 glay->setColumnStretch( 1, 1 );
137 sv->setWidget( view );
141 if ( !sender.empty() ) {
143 glay->addWidget(
new QLabel( i18n(
"Your keys:"), view ), row, 0 );
145 d->selfRequester->setKeys( sender );
146 glay->addWidget( d->selfRequester, row, 1 );
148 glay->addWidget(
new KSeparator( Qt::Horizontal, view ), row, 0, 1, 2 );
153 for ( std::vector<Item>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it ) {
155 glay->addWidget(
new QLabel( i18n(
"Recipient:"), view ), row, 0 );
156 glay->addWidget(
new QLabel( it->address, view ), row, 1 );
157 d->addresses.push_back( it->address );
160 glay->addWidget(
new QLabel( i18n(
"Encryption keys:"), view ), row, 0 );
163 glay->addWidget( req, row, 1 );
164 d->requesters.push_back( req );
167 glay->addWidget(
new QLabel( i18n(
"Encryption preference:"), view ), row, 0 );
168 QComboBox * cb =
new QComboBox( view );
169 cb->setEditable(
false );
170 cb->addItems( prefs );
171 glay->addWidget( cb, row, 1 );
172 cb->setCurrentIndex(
pref2cb( it->pref ) );
173 connect( cb, SIGNAL(activated(
int)), SLOT(slotPrefsChanged()) );
174 d->preferences.push_back( cb );
177 QSize size = sizeHint();
180 const QRect desk = KGlobalSettings::desktopGeometry(
this );
181 setInitialSize( QSize( qMin( size.width(), 3 * desk.width() / 4 ),
182 qMin( size.height(), 7 * desk.height() / 8 ) ) );
190 return d->selfRequester ? d->selfRequester->keys() : std::vector<GpgME::Key>() ;
194 assert( d->requesters.size() ==
static_cast<unsigned int>( d->addresses.size() ) );
195 assert( d->requesters.size() == d->preferences.size() );
197 std::vector<Item> result;
198 result.reserve( d->requesters.size() );
199 QStringList::const_iterator ait = d->addresses.constBegin();
200 std::vector<KeyRequester*>::iterator rit = d->requesters.begin();
201 std::vector<QComboBox*>::iterator cit = d->preferences.begin();
202 while ( ait != d->addresses.constEnd() )
203 result.push_back(
Item( *ait++, (*rit++)->keys(),
cb2pref( (*cit++)->currentIndex() ) ) );
208 return d->prefsChanged;
211 void Kleo::KeyApprovalDialog::slotPrefsChanged() {
212 d->prefsChanged =
true;
215 #include "keyapprovaldialog.moc"
static Kleo::EncryptionPreference cb2pref(int i)
std::vector< Item > items() const
void setKeys(const std::vector< GpgME::Key > &keys)
Preferred method to set a key for multi-KeyRequesters.
static int pref2cb(Kleo::EncryptionPreference p)
KeyApprovalDialog(const std::vector< Item > &recipients, const std::vector< GpgME::Key > &sender, QWidget *parent=0)
std::vector< GpgME::Key > senderKeys() const
static QStringList preferencesStrings()
Base class for SigningKeyRequester and EncryptionKeyRequester.
bool preferencesChanged() const