Commit d649b946 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add support for groups of keys to AbstractKeyListModel::data()

GnuPG-bug-id: 5175, 5238
parent b8753c24
......@@ -3,6 +3,8 @@
This file is part of libkleopatra, the KDE keymanagement library
SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB
SPDX-FileCopyrightText: 2021 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
......@@ -16,6 +18,7 @@ namespace KeyList
{
static const int FingerprintRole = 0xF1;
static const int KeyRole = 0xF2;
static const int GroupRole = 0xF3;
enum Columns {
PrettyName,
......
......@@ -55,6 +55,7 @@ using namespace Kleo;
using namespace Kleo::KeyList;
Q_DECLARE_METATYPE(GpgME::Key)
Q_DECLARE_METATYPE(KeyGroup)
class AbstractKeyListModel::Private
{
......@@ -261,13 +262,21 @@ static QVariant returnIfValid(const QIcon &t)
QVariant AbstractKeyListModel::data(const QModelIndex &index, int role) const
{
const Key key = this->key(index);
if (key.isNull()) {
return QVariant();
if (!key.isNull()) {
return data(key, index.column(), role);
}
const int column = index.column();
const KeyGroup group = this->group(index);
if (!group.isNull()) {
return data(group, index.column(), role);
}
if (role == Qt::DisplayRole || role == Qt::EditRole) {
return QVariant();
}
QVariant AbstractKeyListModel::data(const Key &key, int column, int role) const
{
if (role == Qt::DisplayRole || role == Qt::EditRole) {
switch (column) {
case PrettyName:
return Formatting::prettyName(key);
......@@ -371,6 +380,59 @@ QVariant AbstractKeyListModel::data(const QModelIndex &index, int role) const
return QVariant();
}
QVariant AbstractKeyListModel::data(const KeyGroup &group, int column, int role) const
{
if (role == Qt::DisplayRole || role == Qt::EditRole) {
switch (column) {
case PrettyName:
return group.name();
case PrettyEMail:
return QVariant();
case Validity:
return QString();
case ValidFrom:
return QString();
case ValidUntil:
return QString();
case TechnicalDetails:
return i18nc("a group of keys/certificates", "Group");
case ShortKeyID:
return QString();
case KeyID:
return QString();
case Summary:
return group.name(); // used for filtering
case Fingerprint:
return QString();
case Issuer:
return QString();
case Origin:
return QString();
case LastUpdate:
return QString();
case SerialNumber:
return QString();
case OwnerTrust:
return QString();
case Remarks:
return QVariant();
case NumColumns:
break;
}
} else if (role == Qt::ToolTipRole) {
return QString();
} else if (role == Qt::FontRole) {
return QFont();
} else if (role == Qt::DecorationRole) {
return column == Icon ? QIcon::fromTheme("group") : QVariant();
} else if (role == Qt::BackgroundRole) {
} else if (role == Qt::ForegroundRole) {
} else if (role == GroupRole) {
return QVariant::fromValue(group);
}
return QVariant();
}
namespace
{
template <typename Base>
......
......@@ -95,6 +95,9 @@ public:
std::vector<GpgME::Key> remarkKeys() const;
private:
QVariant data(const GpgME::Key &key, int column, int role) const;
QVariant data(const KeyGroup &group, int column, int role) const;
virtual GpgME::Key doMapToKey(const QModelIndex &index) const = 0;
virtual QModelIndex doMapFromKey(const GpgME::Key &key, int column) const = 0;
virtual QList<QModelIndex> doAddKeys(const std::vector<GpgME::Key> &keys) = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment