• 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
  • model
selectkeyproxymodel.cpp
Go to the documentation of this file.
1 /* Copyright 2008,2010,2012,2013 Rolf Eike Beer <kde@opensource.sf-tec.de>
2  *
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License as
5  * published by the Free Software Foundation; either version 2 of
6  * the License or (at your option) version 3 or any later version
7  * accepted by the membership of KDE e.V. (or its successor approved
8  * by the membership of KDE e.V.), which shall act as a proxy
9  * defined in Section 14 of version 3 of the license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #include "selectkeyproxymodel.h"
20 #include "model/kgpgitemnode.h"
21 #include "kgpgitemmodel.h"
22 #include "core/kgpgkey.h"
23 #include "core/convert.h"
24 
25 using namespace KgpgCore;
26 
27 SelectKeyProxyModel::SelectKeyProxyModel(QObject *parent)
28  : QSortFilterProxyModel(parent),
29  m_model(NULL),
30  m_showUntrusted(false)
31 {
32 }
33 
34 void
35 SelectKeyProxyModel::setKeyModel(KGpgItemModel *md)
36 {
37  m_model = md;
38  setSourceModel(md);
39 }
40 
41 bool
42 SelectKeyProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
43 {
44  QModelIndex idx = m_model->index(source_row, 0, source_parent);
45  KGpgNode *l = m_model->nodeForIndex(idx);
46 
47  switch (l->getType()) {
48  case ITYPE_GROUP:
49  break;
50  case ITYPE_PAIR:
51  case ITYPE_PUBLIC:
52  if (!l->toKeyNode()->canEncrypt())
53  return false;
54  break;
55  default:
56  return false;
57  }
58 
59  if (!m_showUntrusted && ((l->getTrust() != TRUST_FULL) && (l->getTrust() != TRUST_ULTIMATE)))
60  return false;
61 
62  // there is probably a better place to do this
63  QRegExp rx = filterRegExp();
64  rx.setCaseSensitivity(Qt::CaseInsensitive);
65 
66  if (l->getName().contains(rx))
67  return true;
68 
69  if (l->getEmail().contains(rx))
70  return true;
71 
72  if (l->getId().contains(rx))
73  return true;
74 
75  return false;
76 }
77 
78 KGpgNode *
79 SelectKeyProxyModel::nodeForIndex(const QModelIndex &index) const
80 {
81  return m_model->nodeForIndex(mapToSource(index));
82 }
83 
84 int
85 SelectKeyProxyModel::columnCount(const QModelIndex &) const
86 {
87  return 3;
88 }
89 
90 int
91 SelectKeyProxyModel::rowCount(const QModelIndex &parent) const
92 {
93  if (parent.column() > 0)
94  return 0;
95  if (parent.isValid())
96  return 0;
97  if (m_model == NULL)
98  return 0;
99  return QSortFilterProxyModel::rowCount(parent);
100 }
101 
102 QVariant
103 SelectKeyProxyModel::data(const QModelIndex &index, int role) const
104 {
105  if (index.column() >= 3)
106  return QVariant();
107 
108  QModelIndex sidx = mapToSource(index);
109  KGpgNode *nd = m_model->nodeForIndex(sidx);
110 
111  if ((index.column() == 2) && (role == Qt::ToolTipRole))
112  return nd->getId();
113 
114  if ((role != Qt::DisplayRole) && (index.column() <= 1))
115  return m_model->data(sidx, role);
116 
117  if (role != Qt::DisplayRole)
118  return QVariant();
119 
120  switch (index.column()) {
121  case 0: return nd->getName();
122  case 1: return nd->getEmail();
123  case 2: return nd->getId().right(8);
124  }
125 
126  return QVariant();
127 }
128 
129 bool
130 SelectKeyProxyModel::hasChildren(const QModelIndex &parent) const
131 {
132  if (m_model == NULL)
133  return false;
134  return !parent.isValid();
135 }
136 
137 QVariant
138 SelectKeyProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
139 {
140  if (role != Qt::DisplayRole)
141  return QVariant();
142 
143  if (orientation != Qt::Horizontal)
144  return QVariant();
145 
146  if (m_model == NULL)
147  return QVariant();
148 
149  switch (section) {
150  case 0: return m_model->headerData(KEYCOLUMN_NAME, orientation, role);
151  case 1: return m_model->headerData(KEYCOLUMN_EMAIL, orientation, role);
152  case 2: return m_model->headerData(KEYCOLUMN_ID, orientation, role);
153  default: return QVariant();
154  }
155 }
156 
157 bool
158 SelectKeyProxyModel::showUntrusted() const
159 {
160  return m_showUntrusted;
161 }
162 
163 void
164 SelectKeyProxyModel::setShowUntrusted(const bool &b)
165 {
166  m_showUntrusted = b;
167  invalidate();
168 }
169 
170 SelectSecretKeyProxyModel::SelectSecretKeyProxyModel(QObject *parent)
171  : SelectKeyProxyModel(parent)
172 {
173 }
174 
175 bool
176 SelectSecretKeyProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
177 {
178  QModelIndex idx = m_model->index(source_row, 0, source_parent);
179  KGpgNode *l = m_model->nodeForIndex(idx);
180 
181  return ((l->getType() == ITYPE_PAIR) && !(l->getTrust() == TRUST_EXPIRED) && !(l->getTrust() == TRUST_DISABLED));
182 }
183 
184 int
185 SelectSecretKeyProxyModel::columnCount(const QModelIndex &) const
186 {
187  return 4;
188 }
189 
190 int
191 SelectSecretKeyProxyModel::rowCount(const QModelIndex &parent) const
192 {
193  if (parent.column() > 0)
194  return 0;
195  if (parent.isValid())
196  return 0;
197  if (m_model == NULL)
198  return 0;
199  return QSortFilterProxyModel::rowCount(parent);
200 }
201 
202 QVariant
203 SelectSecretKeyProxyModel::data(const QModelIndex &index, int role) const
204 {
205  if (index.column() >= 4)
206  return QVariant();
207 
208  QModelIndex sidx = mapToSource(index);
209  KGpgNode *nd = m_model->nodeForIndex(sidx);
210 
211  if ((index.column() == 3) && (role == Qt::ToolTipRole))
212  return nd->getId();
213 
214  if ((role != Qt::DisplayRole) && (index.column() <= 1))
215  return m_model->data(sidx, role);
216 
217  if (role != Qt::DisplayRole)
218  return QVariant();
219 
220  switch (index.column()) {
221  case 0: return nd->getName();
222  case 1: return nd->getEmail();
223  case 2: return Convert::toString(nd->getExpiration().date());
224  case 3: return nd->getId().right(8);
225  }
226 
227  return QVariant();
228 }
229 
230 bool
231 SelectSecretKeyProxyModel::hasChildren(const QModelIndex &parent) const
232 {
233  if (m_model == NULL)
234  return false;
235  return !parent.isValid();
236 }
237 
238 QVariant
239 SelectSecretKeyProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
240 {
241  if (role != Qt::DisplayRole)
242  return QVariant();
243 
244  if (orientation != Qt::Horizontal)
245  return QVariant();
246 
247  if (m_model == NULL)
248  return QVariant();
249 
250  switch (section) {
251  case 0: return m_model->headerData(KEYCOLUMN_NAME, orientation, role);
252  case 1: return m_model->headerData(KEYCOLUMN_EMAIL, orientation, role);
253  case 2: return m_model->headerData(KEYCOLUMN_EXPIR, orientation, role);
254  case 3: return m_model->headerData(KEYCOLUMN_ID, orientation, role);
255  default: return QVariant();
256  }
257 }
SelectKeyProxyModel::nodeForIndex
KGpgNode * nodeForIndex(const QModelIndex &index) const
Definition: selectkeyproxymodel.cpp:79
KGpgItemModel
Definition: kgpgitemmodel.h:44
SelectKeyProxyModel
filter model to select a public key for encryption
Definition: selectkeyproxymodel.h:30
SelectSecretKeyProxyModel::filterAcceptsRow
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
Definition: selectkeyproxymodel.cpp:176
SelectKeyProxyModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: selectkeyproxymodel.cpp:91
kgpgkey.h
QObject
SelectKeyProxyModel::SelectKeyProxyModel
SelectKeyProxyModel(QObject *parent)
Definition: selectkeyproxymodel.cpp:27
SelectSecretKeyProxyModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: selectkeyproxymodel.cpp:191
SelectSecretKeyProxyModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: selectkeyproxymodel.cpp:203
SelectKeyProxyModel::showUntrusted
bool showUntrusted() const
KGpgNode::getType
virtual KgpgCore::KgpgItemType getType() const =0
Returns the item type of this object.
KGpgNode::getExpiration
virtual QDateTime getExpiration() const
Definition: KGpgNode.cpp:306
SelectSecretKeyProxyModel::SelectSecretKeyProxyModel
SelectSecretKeyProxyModel(QObject *parent)
Definition: selectkeyproxymodel.cpp:170
KgpgCore::TRUST_DISABLED
key is disabled by user (not owner)
Definition: kgpgkey.h:55
kgpgitemmodel.h
KGpgKeyNode::canEncrypt
bool canEncrypt() const
return if this key can be used for encryption
Definition: KGpgKeyNode.cpp:349
KgpgCore::ITYPE_PUBLIC
public key
Definition: kgpgkey.h:111
SelectSecretKeyProxyModel::hasChildren
virtual bool hasChildren(const QModelIndex &parent) const
Definition: selectkeyproxymodel.cpp:231
KgpgCore::Convert::toString
QString toString(const KgpgKeyAlgo algorithm)
Definition: convert.cpp:37
SelectKeyProxyModel::setKeyModel
void setKeyModel(KGpgItemModel *)
Definition: selectkeyproxymodel.cpp:35
KGpgItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: kgpgitemmodel.cpp:44
KGpgItemModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: kgpgitemmodel.cpp:95
KgpgCore::TRUST_FULL
you can fully trust this key
Definition: kgpgkey.h:62
KgpgCore::ITYPE_GROUP
the element is a GnuPG key group
Definition: kgpgkey.h:109
SelectKeyProxyModel::filterAcceptsRow
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
Definition: selectkeyproxymodel.cpp:42
kgpgitemnode.h
KGpgNode
The abstract base class for all classes representing keyring data.
Definition: KGpgNode.h:42
KgpgCore::ITYPE_PAIR
key pair
Definition: kgpgkey.h:112
KgpgCore::TRUST_EXPIRED
key is beyond it's expiry date
Definition: kgpgkey.h:57
SelectKeyProxyModel::m_model
KGpgItemModel * m_model
Definition: selectkeyproxymodel.h:54
KEYCOLUMN_EXPIR
#define KEYCOLUMN_EXPIR
Definition: kgpgitemmodel.h:33
KGpgItemModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: kgpgitemmodel.cpp:362
KGpgNode::toKeyNode
KGpgKeyNode * toKeyNode()
Definition: KGpgNode.cpp:94
SelectKeyProxyModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: selectkeyproxymodel.cpp:103
SelectSecretKeyProxyModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: selectkeyproxymodel.cpp:239
KGpgNode::getId
virtual QString getId() const
Definition: KGpgNode.cpp:318
KGpgNode::getEmail
virtual QString getEmail() const
Definition: KGpgNode.cpp:300
KGpgItemModel::nodeForIndex
KGpgNode * nodeForIndex(const QModelIndex &index) const
Definition: kgpgitemmodel.cpp:230
KGpgNode::getName
virtual QString getName() const
Definition: KGpgNode.cpp:294
SelectKeyProxyModel::setShowUntrusted
void setShowUntrusted(const bool &b)
Definition: selectkeyproxymodel.cpp:164
KgpgCore::TRUST_ULTIMATE
this key has highest possible level of trust (e.g. your own secret keys)
Definition: kgpgkey.h:63
SelectKeyProxyModel::columnCount
virtual int columnCount(const QModelIndex &) const
Definition: selectkeyproxymodel.cpp:85
SelectKeyProxyModel::hasChildren
virtual bool hasChildren(const QModelIndex &parent) const
Definition: selectkeyproxymodel.cpp:130
KGpgNode::getTrust
virtual KgpgCore::KgpgKeyTrust getTrust() const
Definition: KGpgNode.cpp:282
convert.h
KEYCOLUMN_EMAIL
#define KEYCOLUMN_EMAIL
Definition: kgpgitemmodel.h:31
SelectKeyProxyModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: selectkeyproxymodel.cpp:138
selectkeyproxymodel.h
KEYCOLUMN_NAME
#define KEYCOLUMN_NAME
Definition: kgpgitemmodel.h:30
SelectSecretKeyProxyModel::columnCount
virtual int columnCount(const QModelIndex &) const
Definition: selectkeyproxymodel.cpp:185
KEYCOLUMN_ID
#define KEYCOLUMN_ID
Definition: kgpgitemmodel.h:36
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