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

kleopatra

  • sources
  • kde-4.14
  • kdepim
  • kleopatra
  • dialogs
deletecertificatesdialog.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  dialogs/deletecertificatesdialog.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2009 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  In addition, as a special exception, the copyright holders give
22  permission to link the code of this program with any edition of
23  the Qt library by Trolltech AS, Norway (or with modified versions
24  of Qt that use the same license as Qt), and distribute linked
25  combinations including the two. You must obey the GNU General
26  Public License in all respects for all of the code used other than
27  Qt. If you modify this file, you may extend this exception to
28  your version of the file, but you are not obligated to do so. If
29  you do not wish to do so, delete this exception statement from
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "deletecertificatesdialog.h"
36 
37 #include <view/keytreeview.h>
38 #include <models/keylistmodel.h>
39 
40 #include <kleo/stl_util.h>
41 
42 #include <KLocalizedString>
43 #include <KMessageBox>
44 #include <KStandardGuiItem>
45 #include <KDebug>
46 #include <KConfigGroup>
47 #include <KSharedConfig>
48 
49 #include <QLabel>
50 #include <QDialogButtonBox>
51 #include <QVBoxLayout>
52 #include <QWhatsThis>
53 #include <QCursor>
54 #include <QPushButton>
55 #include <QTreeView>
56 
57 #include <gpgme++/key.h>
58 
59 #ifndef Q_MOC_RUN
60 #include <boost/mem_fn.hpp>
61 #endif
62 
63 #include <cassert>
64 
65 using namespace Kleo;
66 using namespace Kleo::Dialogs;
67 using namespace GpgME;
68 using namespace boost;
69 
70 class DeleteCertificatesDialog::Private {
71  friend class ::Kleo::Dialogs::DeleteCertificatesDialog;
72  DeleteCertificatesDialog * const q;
73 public:
74  explicit Private( DeleteCertificatesDialog * qq )
75  : q( qq ),
76  ui( q )
77  {
78 
79  }
80 
81  void slotWhatsThisRequested() {
82  kDebug();
83  if ( QWidget * const widget = qobject_cast<QWidget*>( q->sender() ) )
84  if ( !widget->whatsThis().isEmpty() )
85  QWhatsThis::showText( QCursor::pos(), widget->whatsThis() );
86  }
87 
88  void readConfig()
89  {
90  KConfigGroup dialog( KGlobal::config(), "DeleteCertificatesDialog" );
91  const QSize size = dialog.readEntry( "Size", QSize(600, 400) );
92  if ( size.isValid() ) {
93  q->resize( size );
94  }
95  }
96 
97  void writeConfig()
98  {
99  KConfigGroup dialog( KGlobal::config(), "DeleteCertificatesDialog" );
100  dialog.writeEntry( "Size", q->size() );
101  dialog.sync();
102  }
103 
104 private:
105  struct UI {
106  QLabel selectedLB;
107  KeyTreeView selectedKTV;
108  QLabel unselectedLB;
109  KeyTreeView unselectedKTV;
110  QDialogButtonBox buttonBox;
111  QVBoxLayout vlay;
112 
113  explicit UI( DeleteCertificatesDialog * qq )
114  : selectedLB( i18n( "These are the certificates you have selected for deletion:" ), qq ),
115  selectedKTV( qq ),
116  unselectedLB( i18n("These certificates will be deleted even though you did <emphasis>not</emphasis><nl/> "
117  "explicitly select them (<a href=\"whatsthis://\">Why?</a>):"), qq ),
118  unselectedKTV( qq ),
119  buttonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel ),
120  vlay( qq )
121  {
122  KDAB_SET_OBJECT_NAME( selectedLB );
123  KDAB_SET_OBJECT_NAME( selectedKTV );
124  KDAB_SET_OBJECT_NAME( unselectedLB );
125  KDAB_SET_OBJECT_NAME( unselectedKTV );
126  KDAB_SET_OBJECT_NAME( buttonBox );
127  KDAB_SET_OBJECT_NAME( vlay );
128 
129  vlay.addWidget( &selectedLB );
130  vlay.addWidget( &selectedKTV, 1 );
131  vlay.addWidget( &unselectedLB );
132  vlay.addWidget( &unselectedKTV, 1 );
133  vlay.addWidget( &buttonBox );
134 
135  const QString unselectedWhatsThis
136  = i18nc( "@info:whatsthis",
137  "<title>Why do you want to delete more certificates than I selected?</title>"
138  "<para>When you delete CA certificates (both root CAs and intermediate CAs), "
139  "the certificates issued by them will also be deleted.</para>"
140  "<para>This can be nicely seen in <application>Kleopatra</application>'s "
141  "hierarchical view mode: In this mode, if you delete a certificate that has "
142  "children, those children will also be deleted. Think of CA certificates as "
143  "folders containing other certificates: When you delete the folder, you "
144  "delete its contents, too.</para>" );
145  unselectedLB.setContextMenuPolicy(Qt::NoContextMenu);
146  unselectedLB.setWhatsThis( unselectedWhatsThis );
147  unselectedKTV.setWhatsThis( unselectedWhatsThis );
148 
149  buttonBox.button( QDialogButtonBox::Ok )->setText( i18nc("@action:button","Delete") );
150 
151  connect( &unselectedLB, SIGNAL(linkActivated(QString)), qq, SLOT(slotWhatsThisRequested()) );
152 
153  selectedKTV.setFlatModel( AbstractKeyListModel::createFlatKeyListModel( &selectedKTV ) );
154  unselectedKTV.setFlatModel( AbstractKeyListModel::createFlatKeyListModel( &unselectedKTV ) );
155 
156  selectedKTV.setHierarchicalView( false );
157  selectedKTV.view()->setSelectionMode( QAbstractItemView::NoSelection );
158  unselectedKTV.setHierarchicalView( false );
159  unselectedKTV.view()->setSelectionMode( QAbstractItemView::NoSelection );
160 
161  connect( &buttonBox, SIGNAL(accepted()), qq, SLOT(accept()) );
162  connect( &buttonBox, SIGNAL(rejected()), qq, SLOT(reject()) );
163  }
164  } ui;
165 };
166 
167 DeleteCertificatesDialog::DeleteCertificatesDialog( QWidget * p, Qt::WindowFlags f )
168  : QDialog( p, f ), d( new Private( this ) )
169 {
170  d->readConfig();
171 }
172 
173 DeleteCertificatesDialog::~DeleteCertificatesDialog()
174 {
175  d->writeConfig();
176 }
177 
178 
179 void DeleteCertificatesDialog::setSelectedKeys( const std::vector<Key> & keys ) {
180  d->ui.selectedKTV.setKeys( keys );
181 }
182 
183 void DeleteCertificatesDialog::setUnselectedKeys( const std::vector<Key> & keys ) {
184  d->ui.unselectedLB .setVisible( !keys.empty() );
185  d->ui.unselectedKTV.setVisible( !keys.empty() );
186  d->ui.unselectedKTV.setKeys( keys );
187 }
188 
189 std::vector<Key> DeleteCertificatesDialog::keys() const {
190  const std::vector<Key> sel = d->ui.selectedKTV.keys();
191  const std::vector<Key> uns = d->ui.unselectedKTV.keys();
192  std::vector<Key> result;
193  result.reserve( sel.size() + uns.size() );
194  result.insert( result.end(), sel.begin(), sel.end() );
195  result.insert( result.end(), uns.begin(), uns.end() );
196  return result;
197 }
198 
199 void DeleteCertificatesDialog::accept() {
200 
201  const std::vector<Key> sel = d->ui.selectedKTV.keys();
202  const std::vector<Key> uns = d->ui.unselectedKTV.keys();
203 
204  const uint secret = kdtools::count_if( sel, mem_fn( &Key::hasSecret ) )
205  + kdtools::count_if( uns, mem_fn( &Key::hasSecret ) );
206  const uint total = sel.size() + uns.size();
207 
208  int ret = KMessageBox::Continue;
209  if ( secret )
210  ret = KMessageBox::warningContinueCancel( this,
211  secret == total
212  ? i18np("The certificate to be deleted is your own. "
213  "It contains private key material, "
214  "which is needed to decrypt past communication "
215  "encrypted to the certificate, and should therefore "
216  "not be deleted.",
217 
218  "All of the certificates to be deleted "
219  "are your own. "
220  "They contain private key material, "
221  "which is needed to decrypt past communication "
222  "encrypted to the certificate, and should therefore "
223  "not be deleted.",
224 
225  secret )
226  : i18np("One of the certificates to be deleted "
227  "is your own. "
228  "It contains private key material, "
229  "which is needed to decrypt past communication "
230  "encrypted to the certificate, and should therefore "
231  "not be deleted.",
232 
233  "Some of the certificates to be deleted "
234  "are your own. "
235  "They contain private key material, "
236  "which is needed to decrypt past communication "
237  "encrypted to the certificate, and should therefore "
238  "not be deleted.",
239 
240  secret ),
241  i18n("Secret Key Deletion"),
242  KStandardGuiItem::guiItem( KStandardGuiItem::Delete ),
243  KStandardGuiItem::cancel(), QString(), KMessageBox::Notify|KMessageBox::Dangerous );
244 
245  if ( ret == KMessageBox::Continue )
246  QDialog::accept();
247  else
248  QDialog::reject();
249 }
250 
251 #include "moc_deletecertificatesdialog.cpp"
QWhatsThis::showText
void showText(const QPoint &pos, const QString &text, QWidget *w)
keytreeview.h
QWidget
QSize::isValid
bool isValid() const
QDialog::reject
virtual void reject()
Kleo::KeyTreeView
Definition: keytreeview.h:56
Kleo::Dialogs::DeleteCertificatesDialog::DeleteCertificatesDialog
DeleteCertificatesDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: deletecertificatesdialog.cpp:167
d
#define d
Definition: adduseridcommand.cpp:89
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
Kleo::Dialogs::DeleteCertificatesDialog::~DeleteCertificatesDialog
~DeleteCertificatesDialog()
Definition: deletecertificatesdialog.cpp:173
QVBoxLayout
QDialog::result
int result() const
Kleo::Dialogs::DeleteCertificatesDialog::setUnselectedKeys
void setUnselectedKeys(const std::vector< GpgME::Key > &keys)
Definition: deletecertificatesdialog.cpp:183
QString
QDialog::accept
virtual void accept()
deletecertificatesdialog.h
Kleo::Dialogs::DeleteCertificatesDialog::setSelectedKeys
void setSelectedKeys(const std::vector< GpgME::Key > &keys)
Definition: deletecertificatesdialog.cpp:179
QSize
keylistmodel.h
QCursor::pos
QPoint pos()
Kleo::Dialogs::DeleteCertificatesDialog
Definition: deletecertificatesdialog.h:49
Ok
Definition: setinitialpindialog.cpp:61
QDialogButtonBox
Kleo::AbstractKeyListModel::createFlatKeyListModel
static AbstractKeyListModel * createFlatKeyListModel(QObject *parent=0)
Definition: keylistmodel.cpp:871
q
#define q
Definition: adduseridcommand.cpp:90
QDialog
Qt::WindowFlags
typedef WindowFlags
QLabel
Kleo::Dialogs::DeleteCertificatesDialog::accept
void accept()
Definition: deletecertificatesdialog.cpp:199
Kleo::Dialogs::DeleteCertificatesDialog::keys
std::vector< GpgME::Key > keys() const
Definition: deletecertificatesdialog.cpp:189
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • 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
  • pimprint

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