File indexing completed on 2024-05-12 05:17:08

0001 // SPDX-FileCopyrightText: 2023 Claudio Cambra <claudio.cambra@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #include "cryptographyeditorbackend.h"
0005 
0006 #include "cryptographybackendinterface.h"
0007 #include "identity.h"
0008 
0009 namespace KIdentityManagementQuick
0010 {
0011 
0012 CryptographyEditorBackend::CryptographyEditorBackend(QObject *parent, const CryptographyBackendInterfacePtr &cryptoBackend)
0013     : QObject{parent}
0014     , mCryptoBackend(cryptoBackend)
0015 {
0016     connect(this, &CryptographyEditorBackend::cryptographyBackendChanged, this, &CryptographyEditorBackend::openPgpKeyListModelChanged);
0017     connect(this, &CryptographyEditorBackend::cryptographyBackendChanged, this, &CryptographyEditorBackend::smimeKeyListModelChanged);
0018 }
0019 
0020 CryptographyBackendInterfacePtr CryptographyEditorBackend::cryptographyBackend() const
0021 {
0022     return mCryptoBackend;
0023 }
0024 
0025 void CryptographyEditorBackend::setCryptographyBackend(const CryptographyBackendInterfacePtr &cryptoBackend)
0026 {
0027     if (cryptoBackend.get() == mCryptoBackend.get()) {
0028         return;
0029     }
0030 
0031     mCryptoBackend = cryptoBackend;
0032     Q_EMIT cryptographyBackendChanged();
0033 }
0034 
0035 QAbstractItemModel *CryptographyEditorBackend::openPgpKeyListModel() const
0036 {
0037     if (!mCryptoBackend) {
0038         return nullptr;
0039     }
0040     return mCryptoBackend->openPgpKeyListModel();
0041 }
0042 
0043 QAbstractItemModel *CryptographyEditorBackend::smimeKeyListModel() const
0044 {
0045     if (!mCryptoBackend) {
0046         return nullptr;
0047     }
0048     return mCryptoBackend->smimeKeyListModel();
0049 }
0050 
0051 KIdentityManagementCore::Identity CryptographyEditorBackend::identity() const
0052 {
0053     return mCryptoBackend->identity();
0054 }
0055 
0056 void CryptographyEditorBackend::setIdentity(const KIdentityManagementCore::Identity &identity)
0057 {
0058     mCryptoBackend->setIdentity(identity);
0059     Q_EMIT identityChanged();
0060 }
0061 
0062 QModelIndex
0063 CryptographyEditorBackend::indexForIdentity(QAbstractItemModel *model, const KIdentityManagementCore::Identity &identity, const KeyUseTypes::KeyUse keyUse)
0064 {
0065     Q_ASSERT(model);
0066     const auto klmInterface = dynamic_cast<const KeyListModelInterface *>(model);
0067     Q_ASSERT(klmInterface);
0068     return klmInterface->indexForIdentity(identity, keyUse);
0069 }
0070 
0071 QString CryptographyEditorBackend::stringFromKeyByteArray(const QByteArray &key)
0072 {
0073     return QString::fromUtf8(key);
0074 }
0075 }
0076 
0077 #include "moc_cryptographyeditorbackend.cpp"