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