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

kleopatra

  • sources
  • kde-4.12
  • 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 <KLocale>
43 #include <KMessageBox>
44 #include <KStandardGuiItem>
45 #include <KDebug>
46 
47 #include <QLabel>
48 #include <QDialogButtonBox>
49 #include <QVBoxLayout>
50 #include <QWhatsThis>
51 #include <QCursor>
52 #include <QPushButton>
53 #include <QTreeView>
54 
55 #include <gpgme++/key.h>
56 
57 #include <boost/mem_fn.hpp>
58 
59 #include <cassert>
60 
61 using namespace Kleo;
62 using namespace Kleo::Dialogs;
63 using namespace GpgME;
64 using namespace boost;
65 
66 class DeleteCertificatesDialog::Private {
67  friend class ::Kleo::Dialogs::DeleteCertificatesDialog;
68  DeleteCertificatesDialog * const q;
69 public:
70  explicit Private( DeleteCertificatesDialog * qq )
71  : q( qq ),
72  ui( q )
73  {
74 
75  }
76 
77  void slotWhatsThisRequested() {
78  kDebug();
79  if ( QWidget * const widget = qobject_cast<QWidget*>( q->sender() ) )
80  if ( !widget->whatsThis().isEmpty() )
81  QWhatsThis::showText( QCursor::pos(), widget->whatsThis() );
82  }
83 
84 private:
85  struct UI {
86  QLabel selectedLB;
87  KeyTreeView selectedKTV;
88  QLabel unselectedLB;
89  KeyTreeView unselectedKTV;
90  QDialogButtonBox buttonBox;
91  QVBoxLayout vlay;
92 
93  explicit UI( DeleteCertificatesDialog * qq )
94  : selectedLB( i18n( "These are the certificates you have selected for deletion:" ), qq ),
95  selectedKTV( qq ),
96  unselectedLB( i18n("These certificates will be deleted even though you did <emphasis>not</emphasis><nl/> "
97  "explicitly select them (<a href=\"whatsthis://\">Why?</a>):"), qq ),
98  unselectedKTV( qq ),
99  buttonBox( QDialogButtonBox::Ok|QDialogButtonBox::Cancel ),
100  vlay( qq )
101  {
102  KDAB_SET_OBJECT_NAME( selectedLB );
103  KDAB_SET_OBJECT_NAME( selectedKTV );
104  KDAB_SET_OBJECT_NAME( unselectedLB );
105  KDAB_SET_OBJECT_NAME( unselectedKTV );
106  KDAB_SET_OBJECT_NAME( buttonBox );
107  KDAB_SET_OBJECT_NAME( vlay );
108 
109  vlay.addWidget( &selectedLB );
110  vlay.addWidget( &selectedKTV, 1 );
111  vlay.addWidget( &unselectedLB );
112  vlay.addWidget( &unselectedKTV, 1 );
113  vlay.addWidget( &buttonBox );
114 
115  const QString unselectedWhatsThis
116  = i18nc( "@info:whatsthis",
117  "<title>Why do you want to delete more certificates than I selected?</title>"
118  "<para>When you delete CA certificates (both root CAs and intermediate CAs), "
119  "the certificates issued by them will also be deleted.</para>"
120  "<para>This can be nicely seen in <application>Kleopatra</application>'s "
121  "hierarchical view mode: In this mode, if you delete a certificate that has "
122  "children, those children will also be deleted. Think of CA certificates as "
123  "folders containing other certificates: When you delete the folder, you "
124  "delete its contents, too.</para>" );
125 
126  unselectedLB.setWhatsThis( unselectedWhatsThis );
127  unselectedKTV.setWhatsThis( unselectedWhatsThis );
128 
129  buttonBox.button( QDialogButtonBox::Ok )->setText( i18nc("@action:button","Delete") );
130 
131  connect( &unselectedLB, SIGNAL(linkActivated(QString)), qq, SLOT(slotWhatsThisRequested()) );
132 
133  selectedKTV.setFlatModel( AbstractKeyListModel::createFlatKeyListModel( &selectedKTV ) );
134  unselectedKTV.setFlatModel( AbstractKeyListModel::createFlatKeyListModel( &unselectedKTV ) );
135 
136  selectedKTV.setHierarchicalView( false );
137  selectedKTV.view()->setSelectionMode( QAbstractItemView::NoSelection );
138  unselectedKTV.setHierarchicalView( false );
139  unselectedKTV.view()->setSelectionMode( QAbstractItemView::NoSelection );
140 
141  connect( &buttonBox, SIGNAL(accepted()), qq, SLOT(accept()) );
142  connect( &buttonBox, SIGNAL(rejected()), qq, SLOT(reject()) );
143  }
144  } ui;
145 };
146 
147 DeleteCertificatesDialog::DeleteCertificatesDialog( QWidget * p, Qt::WindowFlags f )
148  : QDialog( p, f ), d( new Private( this ) )
149 {
150 
151 }
152 
153 DeleteCertificatesDialog::~DeleteCertificatesDialog() {}
154 
155 
156 void DeleteCertificatesDialog::setSelectedKeys( const std::vector<Key> & keys ) {
157  d->ui.selectedKTV.setKeys( keys );
158 }
159 
160 void DeleteCertificatesDialog::setUnselectedKeys( const std::vector<Key> & keys ) {
161  d->ui.unselectedLB .setVisible( !keys.empty() );
162  d->ui.unselectedKTV.setVisible( !keys.empty() );
163  d->ui.unselectedKTV.setKeys( keys );
164 }
165 
166 std::vector<Key> DeleteCertificatesDialog::keys() const {
167  const std::vector<Key> sel = d->ui.selectedKTV.keys();
168  const std::vector<Key> uns = d->ui.unselectedKTV.keys();
169  std::vector<Key> result;
170  result.reserve( sel.size() + uns.size() );
171  result.insert( result.end(), sel.begin(), sel.end() );
172  result.insert( result.end(), uns.begin(), uns.end() );
173  return result;
174 }
175 
176 void DeleteCertificatesDialog::accept() {
177 
178  const std::vector<Key> sel = d->ui.selectedKTV.keys();
179  const std::vector<Key> uns = d->ui.unselectedKTV.keys();
180 
181  const uint secret = kdtools::count_if( sel, mem_fn( &Key::hasSecret ) )
182  + kdtools::count_if( uns, mem_fn( &Key::hasSecret ) );
183  const uint total = sel.size() + uns.size();
184 
185  int ret = KMessageBox::Continue;
186  if ( secret )
187  ret = KMessageBox::warningContinueCancel( this,
188  secret == total
189  ? i18np("The certificate to be deleted is your own. "
190  "It contains private key material, "
191  "which is needed to decrypt past communication "
192  "encrypted to the certificate, and should therefore "
193  "not be deleted.",
194 
195  "All of the certificates to be deleted "
196  "are your own. "
197  "They contain private key material, "
198  "which is needed to decrypt past communication "
199  "encrypted to the certificate, and should therefore "
200  "not be deleted.",
201 
202  secret )
203  : i18np("One of the certificates to be deleted "
204  "is your own. "
205  "It contains private key material, "
206  "which is needed to decrypt past communication "
207  "encrypted to the certificate, and should therefore "
208  "not be deleted.",
209 
210  "Some of the certificates to be deleted "
211  "are your own. "
212  "They contain private key material, "
213  "which is needed to decrypt past communication "
214  "encrypted to the certificate, and should therefore "
215  "not be deleted.",
216 
217  secret ),
218  i18n("Secret Key Deletion"),
219  KStandardGuiItem::guiItem( KStandardGuiItem::Delete ),
220  KStandardGuiItem::cancel(), QString(), KMessageBox::Notify|KMessageBox::Dangerous );
221 
222  if ( ret == KMessageBox::Continue )
223  QDialog::accept();
224  else
225  QDialog::reject();
226 }
227 
228 #include "moc_deletecertificatesdialog.cpp"
keytreeview.h
Kleo::KeyTreeView
Definition: keytreeview.h:54
QDialog
Kleo::Dialogs::DeleteCertificatesDialog::DeleteCertificatesDialog
DeleteCertificatesDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: deletecertificatesdialog.cpp:147
QWidget
d
#define d
Definition: adduseridcommand.cpp:90
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
Kleo::Dialogs::DeleteCertificatesDialog::~DeleteCertificatesDialog
~DeleteCertificatesDialog()
Definition: deletecertificatesdialog.cpp:153
Kleo::Dialogs::DeleteCertificatesDialog::setUnselectedKeys
void setUnselectedKeys(const std::vector< GpgME::Key > &keys)
Definition: deletecertificatesdialog.cpp:160
deletecertificatesdialog.h
Kleo::Dialogs::DeleteCertificatesDialog::setSelectedKeys
void setSelectedKeys(const std::vector< GpgME::Key > &keys)
Definition: deletecertificatesdialog.cpp:156
keylistmodel.h
Kleo::Dialogs::DeleteCertificatesDialog
Definition: deletecertificatesdialog.h:49
Ok
Definition: setinitialpindialog.cpp:59
Kleo::AbstractKeyListModel::createFlatKeyListModel
static AbstractKeyListModel * createFlatKeyListModel(QObject *parent=0)
Definition: keylistmodel.cpp:877
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::Dialogs::DeleteCertificatesDialog::accept
void accept()
Definition: deletecertificatesdialog.cpp:176
Kleo::Dialogs::DeleteCertificatesDialog::keys
std::vector< GpgME::Key > keys() const
Definition: deletecertificatesdialog.cpp:166
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 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

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