Libkleo

useridlistproxymodel.cpp
1// SPDX-FileCopyrightText: 2024 g10 Code GmbH
2// SPDX-FileContributor: Tobias Fella <tobias.fella@gnupg.com>
3// SPDX-License-Identifier: GPL-2.0-or-later
4
5#include "useridlistproxymodel.h"
6
7#include "keycache.h"
8#include "useridlistmodel.h"
9
10#include <gpgme++/key.h>
11
12using namespace Kleo;
13
14class UserIDListProxyModel::Private
15{
16public:
17 bool showOnlyOwnCertifications = false;
18};
19
20UserIDListProxyModel::UserIDListProxyModel(QObject *parent)
21 : QSortFilterProxyModel(parent)
22 , d(std::make_unique<Private>())
23{
24}
25
26UserIDListProxyModel::~UserIDListProxyModel() = default;
27
28bool UserIDListProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
29{
30 if (!d->showOnlyOwnCertifications || !sourceParent.isValid()) {
31 return true;
32 }
33 const auto id = sourceModel()->index(sourceRow, 0, sourceParent).data(UserIDListModel::SignerKeyIdRole).value<const char *>();
34 const auto key = KeyCache::instance()->findByKeyIDOrFingerprint(id);
35 return !key.isNull() && key.hasSecret();
36}
37
38void UserIDListProxyModel::setShowOnlyOwnCertifications(bool showOnlyOwnCertifications)
39{
40 d->showOnlyOwnCertifications = showOnlyOwnCertifications;
42}
43
44GpgME::UserID::Signature UserIDListProxyModel::signature(const QModelIndex &index) const
45{
46 return dynamic_cast<UserIDListModel *>(sourceModel())->signature(mapToSource(index));
47}
48
49GpgME::UserID UserIDListProxyModel::userID(const QModelIndex &index) const
50{
51 return dynamic_cast<UserIDListModel *>(sourceModel())->userID(mapToSource(index));
52}
53
54#include "moc_useridlistproxymodel.cpp"
QVariant data(int role) const const
bool isValid() const const
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const const override
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.