10#include <config-libkleo.h>
12#include "subkeylistmodel.h"
14#include <libkleo/formatting.h>
16#include <KLocalizedString>
21#include <gpgme++/key.h>
29class SubkeyListModel::Private
31 friend class ::Kleo::SubkeyListModel;
32 SubkeyListModel *
const q;
35 explicit Private(SubkeyListModel *qq)
45SubkeyListModel::SubkeyListModel(
QObject *p)
47 , d(new Private(this))
51SubkeyListModel::~SubkeyListModel()
55Key SubkeyListModel::key()
const
61void SubkeyListModel::setKey(
const Key &key)
63 const Key oldKey = d->key;
65 if (qstricmp(key.primaryFingerprint(), oldKey.primaryFingerprint()) != 0) {
77 if (key.numSubkeys() > 0 && oldKey.numSubkeys() == key.numSubkeys()) {
85Subkey SubkeyListModel::subkey(
const QModelIndex &idx)
const
88 return d->key.subkey(idx.
row());
96 std::vector<Subkey> result;
97 result.reserve(indexes.
size());
98 std::transform(indexes.
begin(),
100 std::back_inserter(result),
107QModelIndex SubkeyListModel::index(
const Subkey &subkey,
int col)
const
110 for (
unsigned int row = 0, end = d->key.numSubkeys(); row != end; ++row) {
111 if (qstricmp(subkey.keyID(), d->key.subkey(row).keyID()) == 0) {
112 return index(row, col);
121 result.
reserve(subkeys.size());
123 std::transform(subkeys.begin(),
125 std::back_inserter(result),
126 [
this](
const Subkey &key) {
132void SubkeyListModel::clear()
139int SubkeyListModel::columnCount(
const QModelIndex &)
const
144int SubkeyListModel::rowCount(
const QModelIndex &pidx)
const
146 return pidx.
isValid() ? 0 : d->key.numSubkeys();
159 return i18n(
"Valid From");
161 return i18n(
"Valid Until");
163 return i18n(
"Status");
165 return i18n(
"Strength");
167 return i18n(
"Usage");
181 const Subkey subkey = this->subkey(idx);
182 if (subkey.isNull()) {
190 return Formatting::type(subkey);
193 return Formatting::creationDate(subkey);
195 return Formatting::creationDateString(subkey);
199 return Formatting::expirationDate(subkey);
201 return Formatting::expirationDateString(subkey);
204 return Formatting::validityShort(subkey);
206 return Formatting::usageString(subkey);
217#include "moc_subkeylistmodel.cpp"
QString i18n(const char *text, const TYPE &arg...)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
void layoutAboutToBeChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
void layoutChanged(const QList< QPersistentModelIndex > &parents, QAbstractItemModel::LayoutChangeHint hint)
void reserve(qsizetype size)
qsizetype size() const const
bool isValid() const const
QString fromLatin1(QByteArrayView str)
QString fromStdString(const std::string &str)
bool isEmpty() const const