File indexing completed on 2024-06-23 05:14:19
0001 /* utils/tags.cpp 0002 0003 This file is part of Kleopatra, the KDE keymanager 0004 SPDX-FileCopyrightText: 2019 g10code GmbH 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "tags.h" 0010 0011 #include "tagspreferences.h" 0012 0013 #include "kleopatra_debug.h" 0014 0015 #include <KSharedConfig> 0016 #include <Libkleo/KeyCache> 0017 0018 using namespace Kleo; 0019 0020 bool Tags::tagsEnabled() 0021 { 0022 return TagsPreferences().useTags(); 0023 } 0024 0025 void Tags::enableTags() 0026 { 0027 TagsPreferences().setUseTags(true); 0028 KeyCache::mutableInstance()->enableRemarks(true); 0029 } 0030 0031 GpgME::Key Tags::tagKey() 0032 { 0033 const auto tagKeyFpr = TagsPreferences().tagKey(); 0034 GpgME::Key key; 0035 if (tagKeyFpr.isEmpty()) { 0036 return key; 0037 } 0038 key = KeyCache::instance()->findByKeyIDOrFingerprint(tagKeyFpr.toLatin1().constData()); 0039 if (key.isNull()) { 0040 qCDebug(KLEOPATRA_LOG) << "Failed to find tag key: " << tagKeyFpr; 0041 return key; 0042 } 0043 return key; 0044 } 0045 0046 std::vector<GpgME::Key> Tags::tagKeys() 0047 { 0048 std::vector<GpgME::Key> ret; 0049 for (const auto &key : KeyCache::instance()->keys()) { 0050 if (key.isNull() || key.isRevoked() || key.isExpired() || key.isDisabled() || key.isInvalid() || key.protocol() != GpgME::OpenPGP) { 0051 continue; 0052 } 0053 if (key.ownerTrust() >= GpgME::Key::Full) { 0054 ret.push_back(key); 0055 } 0056 } 0057 return ret; 0058 } 0059 0060 void Tags::setTagKey(const GpgME::Key &key) 0061 { 0062 TagsPreferences().setTagKey(key.isNull() ? QString() : QString::fromLatin1(key.primaryFingerprint())); 0063 }