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

kgpg

  • sources
  • kde-4.14
  • kdeutils
  • kgpg
  • model
groupeditproxymodel.cpp
Go to the documentation of this file.
1 /* Copyright 2008,2010,2012,2013,2014 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 "groupeditproxymodel.h"
20 #include "model/kgpgitemnode.h"
21 #include "kgpgitemmodel.h"
22 #include "core/kgpgkey.h"
23 
24 #include <KDebug>
25 #include <KLocale>
26 #include <QIcon>
27 
28 using namespace KgpgCore;
29 
30 GroupEditProxyModel::GroupEditProxyModel(QObject *parent, const bool invert, QList<KGpgNode *> *ids, const KgpgCore::KgpgKeyTrust mintrust)
31  : QSortFilterProxyModel(parent),
32  m_model(NULL),
33  m_invert(invert),
34  m_ids(ids),
35  m_mintrust(mintrust)
36 {
37 }
38 
39 void
40 GroupEditProxyModel::setKeyModel(KGpgItemModel *md)
41 {
42  m_model = md;
43  setSourceModel(md);
44 }
45 
46 bool
47 GroupEditProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
48 {
49  QModelIndex idx = m_model->index(source_row, 0, source_parent);
50  KGpgNode *l = m_model->nodeForIndex(idx);
51 
52  if (l->getType() & ~ITYPE_PAIR)
53  return false;
54 
55  if (l->getTrust() < m_mintrust)
56  return false;
57 
58  const KGpgKeyNode * const lk = l->toKeyNode();
59  for (int i = 0; i < m_ids->count(); i++)
60  if (lk->compareId(m_ids->at(i)->getId()))
61  return !m_invert;
62 
63  return m_invert;
64 }
65 
66 KGpgNode *
67 GroupEditProxyModel::nodeForIndex(const QModelIndex &index) const
68 {
69  return m_model->nodeForIndex(mapToSource(index));
70 }
71 
72 int
73 GroupEditProxyModel::columnCount(const QModelIndex &) const
74 {
75  return 3;
76 }
77 
78 int
79 GroupEditProxyModel::rowCount(const QModelIndex &parent) const
80 {
81  if (parent.column() > 0)
82  return 0;
83  if (parent.isValid())
84  return 0;
85  if (m_model == NULL)
86  return 0;
87  return QSortFilterProxyModel::rowCount(parent);
88 }
89 
90 QVariant
91 GroupEditProxyModel::data(const QModelIndex &index, int role) const
92 {
93  if (!index.isValid() || (index.column() >= 3))
94  return QVariant();
95 
96  KGpgNode *nd = m_model->nodeForIndex(mapToSource(index));
97 
98  switch (role) {
99  case Qt::ToolTipRole:
100  case Qt::DisplayRole:
101  switch (index.column()) {
102  case 0:
103  if (role == Qt::ToolTipRole)
104  return nd->getNameComment();
105  else
106  return nd->getName();
107  case 1:
108  if (role == Qt::ToolTipRole) {
109  if (nd->toKeyNode()->getExpiration().isValid() && (nd->toKeyNode()->getExpiration() <= QDateTime::currentDateTime()))
110  return i18nc("Expired key", "Expired");
111  break;
112  } else {
113  return nd->getEmail();
114  }
115  case 2:
116  if (role == Qt::ToolTipRole)
117  return nd->toKeyNode()->getBeautifiedFingerprint();
118  else
119  return nd->getId().right(8);
120  default:
121  break;
122  }
123  case Qt::DecorationRole:
124  if (index.column() != 1)
125  break;
126 
127  if (nd->toKeyNode()->getExpiration().isValid() && (nd->toKeyNode()->getExpiration() <= QDateTime::currentDateTime()))
128  return QIcon::fromTheme(QLatin1String("dialog-warning"));
129  }
130 
131  return QVariant();
132 }
133 
134 bool
135 GroupEditProxyModel::hasChildren(const QModelIndex &parent) const
136 {
137  if (m_model == NULL)
138  return false;
139  if (parent.column() > 0)
140  return false;
141  return !parent.isValid();
142 }
143 
144 QVariant
145 GroupEditProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
146 {
147  if (role != Qt::DisplayRole)
148  return QVariant();
149 
150  if (orientation != Qt::Horizontal)
151  return QVariant();
152 
153  if (m_model == NULL)
154  return QVariant();
155 
156  switch (section) {
157  case 0:
158  return m_model->headerData(KEYCOLUMN_NAME, orientation, role);
159  case 1:
160  return m_model->headerData(KEYCOLUMN_EMAIL, orientation, role);
161  case 2:
162  return m_model->headerData(KEYCOLUMN_ID, orientation, role);
163  default:
164  return QVariant();
165  }
166 }
KGpgItemModel
Definition: kgpgitemmodel.h:44
QModelIndex
GroupEditProxyModel::filterAcceptsRow
virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
Definition: groupeditproxymodel.cpp:47
GroupEditProxyModel::data
virtual QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: groupeditproxymodel.cpp:91
QSortFilterProxyModel::setSourceModel
virtual void setSourceModel(QAbstractItemModel *sourceModel)
KGpgNode::getNameComment
virtual QString getNameComment() const
Definition: KGpgNode.cpp:51
QList::at
const T & at(int i) const
GroupEditProxyModel::setKeyModel
void setKeyModel(KGpgItemModel *)
Definition: groupeditproxymodel.cpp:40
GroupEditProxyModel::GroupEditProxyModel
GroupEditProxyModel(QObject *parent, const bool invert, QList< KGpgNode * > *ids, const KgpgCore::KgpgKeyTrust mintrust=KgpgCore::TRUST_FULL)
Definition: groupeditproxymodel.cpp:30
kgpgkey.h
QSortFilterProxyModel::rowCount
virtual int rowCount(const QModelIndex &parent) const
GroupEditProxyModel::hasChildren
virtual bool hasChildren(const QModelIndex &parent) const
Definition: groupeditproxymodel.cpp:135
KGpgKeyNode
A public key with or without corresponding secret key.
Definition: KGpgKeyNode.h:33
KGpgNode::getType
virtual KgpgCore::KgpgItemType getType() const =0
Returns the item type of this object.
QModelIndex::isValid
bool isValid() const
QList::count
int count(const T &value) const
GroupEditProxyModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: groupeditproxymodel.cpp:145
QObject
kgpgitemmodel.h
KGpgItemModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: kgpgitemmodel.cpp:44
QList< KGpgNode * >
kgpgitemnode.h
QString::right
QString right(int n) const
groupeditproxymodel.h
GroupEditProxyModel::rowCount
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: groupeditproxymodel.cpp:79
KGpgNode
The abstract base class for all classes representing keyring data.
Definition: KGpgNode.h:42
KgpgCore::ITYPE_PAIR
key pair
Definition: kgpgkey.h:94
QSortFilterProxyModel
GroupEditProxyModel::nodeForIndex
KGpgNode * nodeForIndex(const QModelIndex &index) const
Definition: groupeditproxymodel.cpp:67
QDateTime::isValid
bool isValid() const
KGpgItemModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: kgpgitemmodel.cpp:363
KGpgKeyNode::getExpiration
virtual QDateTime getExpiration() const
Definition: KGpgKeyNode.cpp:101
QSortFilterProxyModel::mapToSource
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const
QDateTime::currentDateTime
QDateTime currentDateTime()
KGpgNode::toKeyNode
KGpgKeyNode * toKeyNode()
Definition: KGpgNode.cpp:94
QLatin1String
KGpgNode::getId
virtual QString getId() const
Definition: KGpgNode.cpp:318
KGpgNode::getEmail
virtual QString getEmail() const
Definition: KGpgNode.cpp:300
QModelIndex::column
int column() const
KGpgItemModel::nodeForIndex
KGpgNode * nodeForIndex(const QModelIndex &index) const
Definition: kgpgitemmodel.cpp:230
KGpgNode::getName
virtual QString getName() const
Definition: KGpgNode.cpp:294
QIcon::fromTheme
QIcon fromTheme(const QString &name, const QIcon &fallback)
KGpgKeyNode::compareId
bool compareId(const QString &other) const
compare the id of this node to the given other node
Definition: KGpgKeyNode.cpp:339
GroupEditProxyModel::columnCount
virtual int columnCount(const QModelIndex &) const
Definition: groupeditproxymodel.cpp:73
KGpgKeyNode::getBeautifiedFingerprint
QString getBeautifiedFingerprint() const
Print the full key fingerprint with spaces inserted.
Definition: KGpgKeyNode.cpp:137
KGpgNode::getTrust
virtual KgpgCore::KgpgKeyTrust getTrust() const
Definition: KGpgNode.cpp:282
KEYCOLUMN_EMAIL
#define KEYCOLUMN_EMAIL
Definition: kgpgitemmodel.h:31
KEYCOLUMN_NAME
#define KEYCOLUMN_NAME
Definition: kgpgitemmodel.h:30
QVariant
KEYCOLUMN_ID
#define KEYCOLUMN_ID
Definition: kgpgitemmodel.h:36
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:42:08 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
  • ktimer
  • kwallet
  • 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