• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkleo

  • sources
  • kde-4.12
  • kdepim
  • libkleo
  • ui
keyapprovaldialog.cpp
Go to the documentation of this file.
1 /* -*- c++ -*-
2  keyapprovaldialog.h
3 
4  This file is part of libkleopatra, the KDE keymanagement library
5  Copyright (c) 2004 Klarälvdalens Datakonsult AB
6 
7  Based on kpgpui.h
8  Copyright (C) 2001,2002 the KPGP authors
9  See file libkdenetwork/AUTHORS.kpgp for details
10 
11  Libkleopatra is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15 
16  Libkleopatra is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 
25  In addition, as a special exception, the copyright holders give
26  permission to link the code of this program with any edition of
27  the Qt library by Trolltech AS, Norway (or with modified versions
28  of Qt that use the same license as Qt), and distribute linked
29  combinations including the two. You must obey the GNU General
30  Public License in all respects for all of the code used other than
31  Qt. If you modify this file, you may extend this exception to
32  your version of the file, but you are not obligated to do so. If
33  you do not wish to do so, delete this exception statement from
34  your version.
35 */
36 
37 
38 #include "keyapprovaldialog.h"
39 
40 #include "keyrequester.h"
41 
42 #include "kleo/cryptobackend.h"
43 #include <kpushbutton.h>
44 #include <klocale.h>
45 #include <kglobalsettings.h>
46 #include <kseparator.h>
47 
48 #include <QStringList>
49 #include <QLayout>
50 #include <QLabel>
51 #include <QComboBox>
52 #include <QScrollArea>
53 #include <QPushButton>
54 #include <QVBoxLayout>
55 #include <QGridLayout>
56 
57 #include <gpgme++/key.h>
58 
59 #include <assert.h>
60 
61 static Kleo::EncryptionPreference cb2pref( int i ) {
62  switch ( i ) {
63  default:
64  case 0: return Kleo::UnknownPreference;
65  case 1: return Kleo::NeverEncrypt;
66  case 2: return Kleo::AlwaysEncrypt;
67  case 3: return Kleo::AlwaysEncryptIfPossible;
68  case 4: return Kleo::AlwaysAskForEncryption;
69  case 5: return Kleo::AskWheneverPossible;
70  }
71 }
72 
73 static int pref2cb( Kleo::EncryptionPreference p ) {
74  switch ( p ) {
75  default: return 0;
76  case Kleo::NeverEncrypt: return 1;
77  case Kleo::AlwaysEncrypt: return 2;
78  case Kleo::AlwaysEncryptIfPossible: return 3;
79  case Kleo::AlwaysAskForEncryption: return 4;
80  case Kleo::AskWheneverPossible: return 5;
81  }
82 }
83 
84 static QStringList preferencesStrings() {
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")
89  << i18n("Always Ask")
90  << i18n("Ask Whenever Encryption is Possible");
91 }
92 
93 
94 class Kleo::KeyApprovalDialog::Private {
95 public:
96  Private() : selfRequester( 0 ), prefsChanged( false ) {}
97 
98  Kleo::KeyRequester * selfRequester;
99  QStringList addresses;
100  std::vector<Kleo::KeyRequester*> requesters;
101  std::vector<QComboBox*> preferences;
102  bool prefsChanged;
103 };
104 
105 Kleo::KeyApprovalDialog::KeyApprovalDialog( const std::vector<Item> & recipients,
106  const std::vector<GpgME::Key> & sender,
107  QWidget * parent )
108  : KDialog( parent ),
109  d( new Private() )
110 {
111  setCaption( i18n("Encryption Key Approval") );
112  setButtons( Ok|Cancel );
113  setDefaultButton( Ok );
114  assert( !recipients.empty() );
115 
116 
117  QFrame *page = new QFrame( this );
118  setMainWidget( page );
119  QVBoxLayout * vlay = new QVBoxLayout( page );
120  vlay->setMargin( 0 );
121  vlay->setSpacing( spacingHint() );
122 
123  vlay->addWidget( new QLabel( i18n("The following keys will be used for encryption:"), page ) );
124 
125  QScrollArea * sv = new QScrollArea( page );
126  //Laurent not sure
127  sv->setWidgetResizable(true);
128  //sv->setResizePolicy( Q3ScrollView::AutoOneFit );
129  vlay->addWidget( sv );
130 
131  QWidget * view = new QWidget( sv->viewport() );
132 
133  QGridLayout * glay = new QGridLayout( view );
134  glay->setMargin( marginHint() );
135  glay->setSpacing( spacingHint() );
136  glay->setColumnStretch( 1, 1 );
137  sv->setWidget( view );
138 
139  int row = -1;
140 
141  if ( !sender.empty() ) {
142  ++row;
143  glay->addWidget( new QLabel( i18n("Your keys:"), view ), row, 0 );
144  d->selfRequester = new EncryptionKeyRequester( true, EncryptionKeyRequester::AllProtocols, view );
145  d->selfRequester->setKeys( sender );
146  glay->addWidget( d->selfRequester, row, 1 );
147  ++row;
148  glay->addWidget( new KSeparator( Qt::Horizontal, view ), row, 0, 1, 2 );
149  }
150 
151  const QStringList prefs = preferencesStrings();
152 
153  for ( std::vector<Item>::const_iterator it = recipients.begin() ; it != recipients.end() ; ++it ) {
154  ++row;
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 );
158 
159  ++row;
160  glay->addWidget( new QLabel( i18n("Encryption keys:"), view ), row, 0 );
161  KeyRequester * req = new EncryptionKeyRequester( true, EncryptionKeyRequester::AllProtocols, view );
162  req->setKeys( it->keys );
163  glay->addWidget( req, row, 1 );
164  d->requesters.push_back( req );
165 
166  ++row;
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 );
175  }
176 
177  QSize size = sizeHint();
178 
179  // don't make the dialog too large
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 ) ) );
183 }
184 
185 Kleo::KeyApprovalDialog::~KeyApprovalDialog() {
186  delete d;
187 }
188 
189 std::vector<GpgME::Key> Kleo::KeyApprovalDialog::senderKeys() const {
190  return d->selfRequester ? d->selfRequester->keys() : std::vector<GpgME::Key>() ;
191 }
192 
193 std::vector<Kleo::KeyApprovalDialog::Item> Kleo::KeyApprovalDialog::items() const {
194  assert( d->requesters.size() == static_cast<unsigned int>( d->addresses.size() ) );
195  assert( d->requesters.size() == d->preferences.size() );
196 
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() ) ) );
204  return result;
205 }
206 
207 bool Kleo::KeyApprovalDialog::preferencesChanged() const {
208  return d->prefsChanged;
209 }
210 
211 void Kleo::KeyApprovalDialog::slotPrefsChanged() {
212  d->prefsChanged = true;
213 }
214 
215 #include "keyapprovaldialog.moc"
Kleo::AlwaysEncrypt
Definition: enum.h:67
cb2pref
static Kleo::EncryptionPreference cb2pref(int i)
Definition: keyapprovaldialog.cpp:61
Kleo::KeyApprovalDialog::items
std::vector< Item > items() const
Definition: keyapprovaldialog.cpp:193
QWidget
Kleo::AskWheneverPossible
Definition: enum.h:70
Kleo::EncryptionKeyRequester
Definition: keyrequester.h:159
Kleo::KeyApprovalDialog::~KeyApprovalDialog
~KeyApprovalDialog()
Definition: keyapprovaldialog.cpp:185
Kleo::EncryptionPreference
EncryptionPreference
Definition: enum.h:64
Kleo::KeyApprovalDialog::Item
Definition: keyapprovaldialog.h:59
KDialog
Kleo::AlwaysEncryptIfPossible
Definition: enum.h:68
cryptobackend.h
Kleo::KeyRequester::setKeys
void setKeys(const std::vector< GpgME::Key > &keys)
Preferred method to set a key for multi-KeyRequesters.
Definition: keyrequester.cpp:158
pref2cb
static int pref2cb(Kleo::EncryptionPreference p)
Definition: keyapprovaldialog.cpp:73
Kleo::AlwaysAskForEncryption
Definition: enum.h:69
keyapprovaldialog.h
Kleo::UnknownPreference
Definition: enum.h:65
Kleo::NeverEncrypt
Definition: enum.h:66
keyrequester.h
Kleo::KeyApprovalDialog::KeyApprovalDialog
KeyApprovalDialog(const std::vector< Item > &recipients, const std::vector< GpgME::Key > &sender, QWidget *parent=0)
Definition: keyapprovaldialog.cpp:105
Kleo::KeyApprovalDialog::senderKeys
std::vector< GpgME::Key > senderKeys() const
Definition: keyapprovaldialog.cpp:189
preferencesStrings
static QStringList preferencesStrings()
Definition: keyapprovaldialog.cpp:84
Kleo::KeyRequester
Base class for SigningKeyRequester and EncryptionKeyRequester.
Definition: keyrequester.h:74
QFrame
Kleo::EncryptionKeyRequester::AllProtocols
Definition: keyrequester.h:162
Kleo::KeyApprovalDialog::preferencesChanged
bool preferencesChanged() const
Definition: keyapprovaldialog.cpp:207
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:57:48 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkleo

Skip menu "libkleo"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal