File indexing completed on 2025-03-09 04:54:30

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "messageviewer_export.h"
0010 #include <KSharedConfig>
0011 #include <QDateTime>
0012 #include <QList>
0013 #include <QObject>
0014 namespace QCA
0015 {
0016 class Initializer;
0017 }
0018 namespace MessageViewer
0019 {
0020 /**
0021  * @brief The KeyInfo struct
0022  * @author Laurent Montel <montel@kde.org>
0023  */
0024 struct MESSAGEVIEWER_EXPORT KeyInfo {
0025     KeyInfo() = default;
0026 
0027     KeyInfo(const QString &key, const QString &sel, const QString &dom, const QDateTime &storedAt = {}, const QDateTime &lastUsed = {})
0028         : keyValue(key)
0029         , selector(sel)
0030         , domain(dom)
0031         , storedAtDateTime(storedAt)
0032         , lastUsedDateTime(lastUsed)
0033     {
0034     }
0035 
0036     QString keyValue;
0037     QString selector;
0038     QString domain;
0039     QDateTime storedAtDateTime;
0040     QDateTime lastUsedDateTime;
0041     [[nodiscard]] bool operator==(const KeyInfo &) const;
0042     [[nodiscard]] bool operator!=(const KeyInfo &) const;
0043 };
0044 
0045 /**
0046  * @brief The DKIMManagerKey class
0047  * @author Laurent Montel <montel@kde.org>
0048  */
0049 class MESSAGEVIEWER_EXPORT DKIMManagerKey : public QObject
0050 {
0051     Q_OBJECT
0052 public:
0053     explicit DKIMManagerKey(QObject *parent = nullptr);
0054     ~DKIMManagerKey() override;
0055 
0056     static DKIMManagerKey *self();
0057 
0058     void loadKeys();
0059     void saveKeys(const QList<KeyInfo> &lst);
0060 
0061     void addKey(const KeyInfo &key);
0062     void removeKey(const QString &key);
0063 
0064     [[nodiscard]] QList<KeyInfo> keys() const;
0065 
0066     void saveKeys();
0067     [[nodiscard]] QString keyValue(const QString &selector, const QString &domain);
0068 
0069     void updateLastUsed(const QString &selector, const QString &domain);
0070 
0071 private:
0072     [[nodiscard]] MESSAGEVIEWER_NO_EXPORT QStringList keyRecorderList(KSharedConfig::Ptr &config) const;
0073     QList<KeyInfo> mKeys;
0074     QCA::Initializer *const mQcaInitializer;
0075 };
0076 }
0077 Q_DECLARE_TYPEINFO(MessageViewer::KeyInfo, Q_RELOCATABLE_TYPE);
0078 Q_DECLARE_METATYPE(MessageViewer::KeyInfo)
0079 MESSAGEVIEWER_EXPORT QDebug operator<<(QDebug d, const MessageViewer::KeyInfo &t);