• 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
  • models
subkeylistmodel.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  models/subkeylistmodel.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2007 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 "subkeylistmodel.h"
36 
37 #include <utils/formatting.h>
38 
39 #include <gpgme++/key.h>
40 
41 #include <KLocalizedString>
42 
43 #include <QVariant>
44 #include <QDate>
45 
46 #ifndef Q_MOC_RUN
47 #include <boost/bind.hpp>
48 #endif
49 
50 #include <algorithm>
51 #include <iterator>
52 
53 using namespace GpgME;
54 using namespace Kleo;
55 using namespace boost;
56 
57 class SubkeyListModel::Private {
58  friend class ::Kleo::SubkeyListModel;
59  SubkeyListModel * const q;
60 public:
61  explicit Private( SubkeyListModel * qq )
62  : q( qq ), key() {}
63 
64 private:
65  Key key;
66 };
67 
68 
69 
70 SubkeyListModel::SubkeyListModel( QObject * p )
71  : QAbstractTableModel( p ), d( new Private( this ) )
72 {
73 
74 }
75 
76 SubkeyListModel::~SubkeyListModel() {}
77 
78 
79 Key SubkeyListModel::key() const {
80  return d->key;
81 }
82 
83 // slot
84 void SubkeyListModel::setKey( const Key & key ) {
85 
86  const Key oldKey = d->key;
87 
88  d->key = key;
89 
90  if ( qstricmp( key.primaryFingerprint(), oldKey.primaryFingerprint() ) != 0 ) {
91  // different key -> reset
92  reset();
93  return;
94  }
95 
96  // ### diff them, and signal more fine-grained than this:
97 
98  if ( key.numSubkeys() > 0 && oldKey.numSubkeys() == key.numSubkeys() ) {
99  emit dataChanged( index( 0, 0 ), index( key.numSubkeys() - 1, NumColumns - 1 ) );
100  } else {
101  emit layoutAboutToBeChanged();
102  emit layoutChanged();
103  }
104 }
105 
106 Subkey SubkeyListModel::subkey( const QModelIndex & idx ) const {
107  if ( idx.isValid() )
108  return d->key.subkey( idx.row() );
109  else
110  return Subkey();
111 }
112 
113 std::vector<Subkey> SubkeyListModel::subkeys( const QList<QModelIndex> & indexes ) const {
114  std::vector<Subkey> result;
115  result.reserve( indexes.size() );
116  std::transform( indexes.begin(), indexes.end(),
117  std::back_inserter( result ),
118  boost::bind( &SubkeyListModel::subkey, this, _1 ) );
119  return result;
120 }
121 
122 QModelIndex SubkeyListModel::index( const Subkey & subkey, int col ) const {
123  // O(N), but not sorted, so no better way...
124  for ( unsigned int row = 0, end = d->key.numSubkeys() ; row != end ; ++row )
125  if ( qstricmp( subkey.keyID(), d->key.subkey( row ).keyID() ) == 0 )
126  return index( row, col );
127  return QModelIndex();
128 }
129 
130 QList<QModelIndex> SubkeyListModel::indexes( const std::vector<Subkey> & subkeys ) const {
131  QList<QModelIndex> result;
132  // O(N*M), but who cares...?
133  std::transform( subkeys.begin(), subkeys.end(),
134  std::back_inserter( result ),
135  // if some compilers are complaining about ambigious overloads, use this line instead:
136  //bind( static_cast<QModelIndex(SubKeyListModel::*)(const Subkey&,int)const>( &SubkeyListModel::index ), this, _1, 0 ) );
137  boost::bind( &SubkeyListModel::index, this, _1, 0 ) );
138  return result;
139 }
140 
141 void SubkeyListModel::clear() {
142  d->key = Key::null;
143  reset();
144 }
145 
146 int SubkeyListModel::columnCount( const QModelIndex & ) const {
147  return NumColumns;
148 }
149 
150 int SubkeyListModel::rowCount( const QModelIndex & pidx ) const {
151  return pidx.isValid() ? 0 : d->key.numSubkeys() ;
152 }
153 
154 QVariant SubkeyListModel::headerData( int section, Qt::Orientation o, int role ) const {
155  if ( o == Qt::Horizontal )
156  if ( role == Qt::DisplayRole || role == Qt::EditRole || role == Qt::ToolTipRole )
157  switch ( section ) {
158  case ID: return i18n( "ID" );
159  case Type: return i18n( "Type" );
160  case ValidFrom: return i18n( "Valid From" );
161  case ValidUntil: return i18n( "Valid Until" );
162  case Status: return i18n( "Status" );
163  case Bits: return i18n( "Strength" );
164  case NumColumns: ;
165  }
166  return QVariant();
167 }
168 
169 QVariant SubkeyListModel::data( const QModelIndex & idx, int role ) const {
170 
171  if ( role != Qt::DisplayRole && role != Qt::EditRole && role != Qt::ToolTipRole )
172  return QVariant();
173 
174  const Subkey subkey = this->subkey( idx );
175  if ( subkey.isNull() )
176  return QVariant();
177 
178  switch ( idx.column() ) {
179  case ID:
180  return QString::fromLatin1( subkey.keyID() );
181  case Type:
182  return Formatting::type( subkey );
183  case ValidFrom:
184  if ( role == Qt::EditRole )
185  return Formatting::creationDate( subkey );
186  else
187  return Formatting::creationDateString( subkey );
188  case ValidUntil:
189  if ( role == Qt::EditRole )
190  return Formatting::expirationDate( subkey );
191  else
192  return Formatting::expirationDateString( subkey );
193  case Status:
194  return Formatting::validityShort( subkey );
195  case Bits:
196  return subkey.length();
197  }
198 
199  return QVariant();
200 }
201 
Kleo::SubkeyListModel::ValidFrom
Definition: subkeylistmodel.h:59
QModelIndex
Kleo::SubkeyListModel::indexes
QList< QModelIndex > indexes(const std::vector< GpgME::Subkey > &subkeys) const
Definition: subkeylistmodel.cpp:130
QAbstractItemModel::layoutChanged
void layoutChanged()
Kleo::Formatting::type
QString type(const GpgME::Key &key)
Kleo::SubkeyListModel::rowCount
int rowCount(const QModelIndex &pidx=QModelIndex()) const
Definition: subkeylistmodel.cpp:150
Kleo::SubkeyListModel::subkey
GpgME::Subkey subkey(const QModelIndex &idx) const
Definition: subkeylistmodel.cpp:106
QAbstractTableModel
Kleo::Formatting::creationDateString
QString creationDateString(const GpgME::Key &key)
Kleo::SubkeyListModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
Definition: subkeylistmodel.cpp:169
formatting.h
Kleo::Formatting::expirationDateString
QString expirationDateString(const GpgME::Key &key)
QList::size
int size() const
Kleo::SubkeyListModel::Type
Definition: subkeylistmodel.h:58
Kleo::SubkeyListModel::subkeys
std::vector< GpgME::Subkey > subkeys(const QList< QModelIndex > &indexes) const
Definition: subkeylistmodel.cpp:113
QAbstractItemModel::layoutAboutToBeChanged
void layoutAboutToBeChanged()
Kleo::SubkeyListModel::setKey
void setKey(const GpgME::Key &key)
Definition: subkeylistmodel.cpp:84
QAbstractItemModel::reset
void reset()
QModelIndex::isValid
bool isValid() const
d
#define d
Definition: adduseridcommand.cpp:89
Kleo::SubkeyListModel
Definition: subkeylistmodel.h:48
Kleo::SubkeyListModel::~SubkeyListModel
~SubkeyListModel()
Definition: subkeylistmodel.cpp:76
Kleo::SubkeyListModel::ValidUntil
Definition: subkeylistmodel.h:60
QAbstractItemModel::dataChanged
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
QObject
Kleo::SubkeyListModel::clear
void clear()
Definition: subkeylistmodel.cpp:141
Kleo::Formatting::validityShort
QString validityShort(const GpgME::Subkey &subkey)
QModelIndex::row
int row() const
Kleo::Formatting::expirationDate
QDate expirationDate(const GpgME::Key &key)
Kleo::SubkeyListModel::ID
Definition: subkeylistmodel.h:57
subkeylistmodel.h
Kleo::SubkeyListModel::headerData
QVariant headerData(int section, Qt::Orientation o, int role=Qt::DisplayRole) const
Definition: subkeylistmodel.cpp:154
QList
Definition: commands/command.h:46
Kleo::SubkeyListModel::key
GpgME::Key key() const
Definition: subkeylistmodel.cpp:79
QList::end
iterator end()
Kleo::SubkeyListModel::NumColumns
Definition: subkeylistmodel.h:64
Kleo::SubkeyListModel::Bits
Definition: subkeylistmodel.h:62
Kleo::Formatting::creationDate
QDate creationDate(const GpgME::Key &key)
q
#define q
Definition: adduseridcommand.cpp:90
QModelIndex::column
int column() const
QString::fromLatin1
QString fromLatin1(const char *str, int size)
Kleo::SubkeyListModel::index
QModelIndex index(const GpgME::Subkey &subkey, int col=0) const
Definition: subkeylistmodel.cpp:122
Kleo::SubkeyListModel::columnCount
int columnCount(const QModelIndex &pidx=QModelIndex()) const
Definition: subkeylistmodel.cpp:146
QList::begin
iterator begin()
Kleo::SubkeyListModel::Status
Definition: subkeylistmodel.h:61
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 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