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

kgpg

  • sources
  • kde-4.12
  • kdeutils
  • kgpg
selectpublickeydialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002 Jean-Baptiste Mardelle <bj@altern.org>
3  * Copyright (C) 2007,2008,2009,2010,2011,2012
4  * Rolf Eike Beer <kde@opensource.sf-tec.de>
5  */
6 
7 /***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "selectpublickeydialog.h"
17 
18 #include "kgpgsettings.h"
19 #include "core/images.h"
20 #include "core/KGpgRootNode.h"
21 #include "model/kgpgitemmodel.h"
22 #include "model/selectkeyproxymodel.h"
23 
24 #include <KAction>
25 #include <KActionCollection>
26 #include <KHBox>
27 #include <KLineEdit>
28 #include <KLocale>
29 #include <KVBox>
30 #include <QCheckBox>
31 #include <QLabel>
32 #include <QPainter>
33 #include <QTableView>
34 #include <QVBoxLayout>
35 
36 using namespace KgpgCore;
37 
38 KgpgSelectPublicKeyDlg::KgpgSelectPublicKeyDlg(QWidget *parent, KGpgItemModel *model, const KShortcut &goDefaultKey, const bool hideasciioption, const KUrl::List &files)
39  : KDialog(parent),
40  m_customoptions(NULL),
41  imodel(model),
42  m_files(files),
43  m_hideasciioption(hideasciioption)
44 {
45  setButtons(Details | Ok | Cancel);
46  setDefaultButton(Ok);
47  setButtonText(Details, i18n("O&ptions"));
48 
49  int fcount = files.count();
50  bool fmode = (fcount > 0);
51 
52  switch (fcount) {
53  case 0:
54  setCaption(i18n("Select Public Key"));
55  break;
56  case 1:
57  setCaption(i18n("Select Public Key for %1", files.first().fileName()));
58  break;
59  default:
60  setCaption(i18np("Select Public Key for %2 and one more file", "Select Public Key for %2 and %1 more files", files.count() - 1, files.first().fileName()));
61  }
62 
63  QWidget *page = new QWidget(this);
64 
65  m_searchbar = new KHBox(page);
66  m_searchbar->setSpacing(spacingHint());
67  m_searchbar->setFrameShape(QFrame::StyledPanel);
68 
69  QLabel *searchlabel = new QLabel(i18n("&Search: "), m_searchbar);
70 
71  m_searchlineedit = new KLineEdit(m_searchbar);
72  m_searchlineedit->setClearButtonShown(true);
73  searchlabel->setBuddy(m_searchlineedit);
74 
75  iproxy = new SelectKeyProxyModel(this);
76  iproxy->setKeyModel(imodel);
77 
78  m_keyslist = new QTableView(page);
79  m_keyslist->setSortingEnabled(true);
80  m_keyslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
81  m_keyslist->setSelectionBehavior(QAbstractItemView::SelectRows);
82  m_keyslist->setModel(iproxy);
83  m_keyslist->resizeColumnsToContents();
84  m_keyslist->setWhatsThis(i18n("<b>Public keys list</b>: select the key that will be used for encryption."));
85  connect(m_searchlineedit, SIGNAL(textChanged(QString)), iproxy, SLOT(setFilterFixedString(QString)));
86 
87  optionsbox = new KVBox();
88  optionsbox->setFrameShape(QFrame::StyledPanel);
89  setDetailsWidget(optionsbox);
90 
91  if (m_hideasciioption)
92  m_cbarmor = 0;
93  else
94  {
95  m_cbarmor = new QCheckBox(i18n("ASCII armored encryption"), optionsbox);
96  m_cbarmor->setChecked(KGpgSettings::asciiArmor());
97  m_cbarmor->setWhatsThis(i18n("<b>ASCII encryption</b>: makes it possible to open the encrypted file/message in a text editor"));
98  }
99 
100  m_cbuntrusted = new QCheckBox(i18n("Allow encryption with untrusted keys"), optionsbox);
101  m_cbuntrusted->setChecked(KGpgSettings::allowUntrustedKeys());
102  m_cbuntrusted->setWhatsThis(i18n("<b>Allow encryption with untrusted keys</b>: when you import a public key, it is usually "
103  "marked as untrusted and you cannot use it unless you sign it in order to make it 'trusted'. Checking this "
104  "box enables you to use any key, even if it has not be signed."));
105 
106  m_cbhideid = new QCheckBox(i18n("Hide user id"), optionsbox);
107  connect(m_cbuntrusted, SIGNAL(toggled(bool)), this, SLOT(slotUntrusted(bool)));
108  m_cbhideid->setChecked(KGpgSettings::hideUserID());
109  m_cbhideid->setWhatsThis(i18n("<b>Hide user ID</b>: Do not put the keyid into encrypted packets. This option hides the receiver "
110  "of the message and is a countermeasure against traffic analysis. It may slow down the decryption process because "
111  "all available secret keys are tried."));
112 
113  m_cbsymmetric = new QCheckBox(i18n("Symmetrical encryption"), optionsbox);
114  m_cbsymmetric->setWhatsThis(i18n("<b>Symmetrical encryption</b>: encryption does not use keys. You just need to give a password "
115  "to encrypt/decrypt the file"));
116 
117  QVBoxLayout *dialoglayout = new QVBoxLayout(page);
118  dialoglayout->setSpacing(spacingHint());
119  dialoglayout->setMargin(0);
120  dialoglayout->addWidget(m_searchbar);
121  dialoglayout->addWidget(m_keyslist);
122  page->setLayout(dialoglayout);
123 
124  if (KGpgSettings::allowCustomEncryptionOptions())
125  {
126  KHBox *expertbox = new KHBox(page);
127  (void) new QLabel(i18n("Custom option:"), expertbox);
128 
129  m_customoptions = new KLineEdit(expertbox);
130  m_customoptions->setText(KGpgSettings::customEncryptionOptions());
131  m_customoptions->setWhatsThis(i18n("<b>Custom option</b>: for experienced users only, allows you to enter a gpg command line option, like: '--armor'"));
132 
133  dialoglayout->addWidget(expertbox);
134  }
135 
136  KActionCollection *actcol = new KActionCollection(this);
137  KAction *action = actcol->addAction(QLatin1String( "go_default_key" ));
138  action->setText(i18n("&Go to Default Key"));
139  action->setShortcut(goDefaultKey);
140 
141  connect(action, SIGNAL(triggered(bool)), SLOT(slotGotoDefaultKey()));
142  connect(m_cbsymmetric, SIGNAL(toggled(bool)), this, SLOT(slotSymmetric(bool)));
143  connect(m_keyslist->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(slotSelectionChanged()));
144  connect(m_keyslist, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotOk()));
145 
146  setMinimumSize(550, 200);
147  updateGeometry();
148 
149  setMainWidget(page);
150  slotSelectionChanged();
151 
152  if (fmode)
153  slotGotoDefaultKey();
154 }
155 
156 QStringList KgpgSelectPublicKeyDlg::selectedKeys() const
157 {
158  if (getSymmetric())
159  return QStringList();
160 
161  QStringList selectedKeys;
162 
163  foreach (const QModelIndex &idx, m_keyslist->selectionModel()->selectedIndexes()) {
164  if (idx.column() != 0)
165  continue;
166  KGpgNode *nd = iproxy->nodeForIndex(idx);
167  if (nd->getType() == ITYPE_GROUP)
168  selectedKeys << nd->getName();
169  else
170  selectedKeys << nd->getId();
171  }
172 
173  return selectedKeys;
174 }
175 
176 bool KgpgSelectPublicKeyDlg::getSymmetric() const
177 {
178  return m_cbsymmetric->isChecked();
179 }
180 
181 QString KgpgSelectPublicKeyDlg::getCustomOptions() const
182 {
183  if (m_customoptions == 0)
184  return QString();
185  return m_customoptions->text().simplified();
186 }
187 
188 bool KgpgSelectPublicKeyDlg::getUntrusted() const
189 {
190  return m_cbuntrusted->isChecked();
191 }
192 
193 bool KgpgSelectPublicKeyDlg::getArmor() const
194 {
195  return m_hideasciioption || m_cbarmor->isChecked();
196 }
197 
198 const KUrl::List &KgpgSelectPublicKeyDlg::getFiles() const
199 {
200  return m_files;
201 }
202 
203 bool KgpgSelectPublicKeyDlg::getHideId() const
204 {
205  return m_cbhideid->isChecked();
206 }
207 
208 void KgpgSelectPublicKeyDlg::slotOk()
209 {
210  if (getSymmetric() || m_keyslist->selectionModel()->hasSelection())
211  slotButtonClicked(Ok);
212 }
213 
214 void KgpgSelectPublicKeyDlg::slotSelectionChanged()
215 {
216  enableButtonOk(getSymmetric() || m_keyslist->selectionModel()->hasSelection());
217 }
218 
219 void KgpgSelectPublicKeyDlg::slotSymmetric(const bool state)
220 {
221  m_keyslist->setDisabled(state);
222  m_cbuntrusted->setDisabled(state);
223  m_cbhideid->setDisabled(state);
224  m_searchbar->setDisabled(state);
225  slotSelectionChanged();
226 }
227 
228 void KgpgSelectPublicKeyDlg::slotUntrusted(const bool state)
229 {
230  iproxy->setShowUntrusted(state);
231 }
232 
233 void KgpgSelectPublicKeyDlg::slotGotoDefaultKey()
234 {
235  KGpgNode *nd = imodel->getRootNode()->findKey(KGpgSettings::defaultKey());
236  if (nd == NULL)
237  return;
238  QModelIndex sidx = imodel->nodeIndex(nd);
239  QModelIndex pidx = iproxy->mapFromSource(sidx);
240  m_keyslist->selectionModel()->setCurrentIndex(pidx, QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
241 }
242 
243 #include "selectpublickeydialog.moc"
SelectKeyProxyModel::nodeForIndex
KGpgNode * nodeForIndex(const QModelIndex &index) const
Definition: selectkeyproxymodel.cpp:79
KGpgItemModel
Definition: kgpgitemmodel.h:44
KGpgSettings::defaultKey
static QString defaultKey()
Definition: kgpgsettings.h:24
KgpgSelectPublicKeyDlg::selectedKeys
QStringList selectedKeys() const
Definition: selectpublickeydialog.cpp:156
KgpgSelectPublicKeyDlg::getFiles
const KUrl::List & getFiles() const
return the files passed in the constructor
Definition: selectpublickeydialog.cpp:198
SelectKeyProxyModel
filter model to select a public key for encryption
Definition: selectkeyproxymodel.h:30
QWidget
KgpgSelectPublicKeyDlg::KgpgSelectPublicKeyDlg
KgpgSelectPublicKeyDlg(QWidget *parent, KGpgItemModel *model, const KShortcut &goDefaultKey=KShortcut(QKeySequence(Qt::CTRL+Qt::Key_Home)), const bool hideasciioption=false, const KUrl::List &files=KUrl::List())
Definition: selectpublickeydialog.cpp:38
images.h
KDialog
KgpgSelectPublicKeyDlg::getCustomOptions
QString getCustomOptions() const
Definition: selectpublickeydialog.cpp:181
selectpublickeydialog.h
KGpgRootNode.h
KGpgNode::getType
virtual KgpgCore::KgpgItemType getType() const =0
Returns the item type of this object.
KGpgSettings::asciiArmor
static bool asciiArmor()
Get Use ASCII armored encryption.
Definition: kgpgsettings.h:174
KGpgSettings::hideUserID
static bool hideUserID()
Get Hide the user ID.
Definition: kgpgsettings.h:231
KgpgSelectPublicKeyDlg::getHideId
bool getHideId() const
Definition: selectpublickeydialog.cpp:203
kgpgitemmodel.h
KgpgSelectPublicKeyDlg::getArmor
bool getArmor() const
Definition: selectpublickeydialog.cpp:193
SelectKeyProxyModel::setKeyModel
void setKeyModel(KGpgItemModel *)
Definition: selectkeyproxymodel.cpp:35
KGpgSettings::customEncryptionOptions
static QString customEncryptionOptions()
Get Custom encryption options.
Definition: kgpgsettings.h:98
KgpgCore::ITYPE_GROUP
the element is a GnuPG key group
Definition: kgpgkey.h:109
KGpgNode
The abstract base class for all classes representing keyring data.
Definition: KGpgNode.h:42
KGpgItemModel::getRootNode
KGpgRootNode * getRootNode() const
Definition: kgpgitemmodel.cpp:250
KGpgSettings::allowCustomEncryptionOptions
static bool allowCustomEncryptionOptions()
Get Allow custom encryption options.
Definition: kgpgsettings.h:117
KGpgRootNode::findKey
KGpgKeyNode * findKey(const QString &keyId)
Find a key node with the given id.
Definition: KGpgRootNode.cpp:118
kgpgsettings.h
KgpgSelectPublicKeyDlg::optionsbox
KVBox * optionsbox
Definition: selectpublickeydialog.h:60
KGpgNode::getId
virtual QString getId() const
Definition: KGpgNode.cpp:318
KGpgSettings::allowUntrustedKeys
static bool allowUntrustedKeys()
Get Allow encryption with untrusted keys.
Definition: kgpgsettings.h:193
KGpgNode::getName
virtual QString getName() const
Definition: KGpgNode.cpp:294
KGpgItemModel::nodeIndex
QModelIndex nodeIndex(KGpgNode *node, const int column=0)
Definition: kgpgitemmodel.cpp:405
KgpgSelectPublicKeyDlg::getSymmetric
bool getSymmetric() const
Definition: selectpublickeydialog.cpp:176
SelectKeyProxyModel::setShowUntrusted
void setShowUntrusted(const bool &b)
Definition: selectkeyproxymodel.cpp:164
KgpgSelectPublicKeyDlg::getUntrusted
bool getUntrusted() const
Definition: selectpublickeydialog.cpp:188
selectkeyproxymodel.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:07:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeutils API Reference

Skip menu "kdeutils API Reference"
  • ark
  • filelight
  • kcalc
  • kcharselect
  • kdf
  • kfloppy
  • kgpg
  • kremotecontrol
  • ktimer
  • kwallet
  • superkaramba
  • sweeper

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