dkimmanagerkey.h 2.47 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
/*
Laurent Montel's avatar
Laurent Montel committed
2
   Copyright (C) 2018-2020 Laurent Montel <montel@kde.org>
Laurent Montel's avatar
Laurent Montel committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef DKIMMANAGERKEY_H
#define DKIMMANAGERKEY_H

#include <QObject>
Laurent Montel's avatar
Laurent Montel committed
24
#include "messageviewer_export.h"
25
#include "config-messageviewer.h"
26
#include <QVector>
Laurent Montel's avatar
Laurent Montel committed
27
#include <KSharedConfig>
28
29
30
namespace QCA {
class Initializer;
}
Laurent Montel's avatar
Laurent Montel committed
31
namespace MessageViewer {
Laurent Montel's avatar
Laurent Montel committed
32
33
34
35
/**
 * @brief The KeyInfo struct
 * @author Laurent Montel <montel@kde.org>
 */
36
struct MESSAGEVIEWER_EXPORT KeyInfo {
Laurent Montel's avatar
Laurent Montel committed
37
38
    KeyInfo()
    {
Laurent Montel's avatar
Laurent Montel committed
39
    }
Laurent Montel's avatar
Laurent Montel committed
40

Laurent Montel's avatar
Laurent Montel committed
41
    KeyInfo(const QString &key, const QString &sel, const QString &dom)
Laurent Montel's avatar
Laurent Montel committed
42
43
44
45
46
47
        : keyValue(key)
        , selector(sel)
        , domain(dom)
    {
    }

48
49
50
51
    QString keyValue;
    QString selector;
    QString domain;
    Q_REQUIRED_RESULT bool operator ==(const KeyInfo &) const;
52
    Q_REQUIRED_RESULT bool operator !=(const KeyInfo &) const;
53
};
Laurent Montel's avatar
Laurent Montel committed
54
55
56
57
58

/**
 * @brief The DKIMManagerKey class
 * @author Laurent Montel <montel@kde.org>
 */
Laurent Montel's avatar
Laurent Montel committed
59
class MESSAGEVIEWER_EXPORT DKIMManagerKey : public QObject
Laurent Montel's avatar
Laurent Montel committed
60
61
62
63
64
{
    Q_OBJECT
public:
    explicit DKIMManagerKey(QObject *parent = nullptr);
    ~DKIMManagerKey() override;
Laurent Montel's avatar
Laurent Montel committed
65
66
67
68

    static DKIMManagerKey *self();

    void loadKeys();
Laurent Montel's avatar
Laurent Montel committed
69
    void saveKeys(const QVector<KeyInfo> &lst);
70
71
72
73
74
75

    void addKey(const KeyInfo &key);
    void removeKey(const QString &key);

    Q_REQUIRED_RESULT QVector<KeyInfo> keys() const;

Laurent Montel's avatar
Laurent Montel committed
76
    void saveKeys();
Laurent Montel's avatar
Laurent Montel committed
77
    Q_REQUIRED_RESULT QString keyValue(const QString &selector, const QString &domain);
78
private:
Laurent Montel's avatar
Laurent Montel committed
79
    Q_REQUIRED_RESULT QStringList keyRecorderList(KSharedConfig::Ptr &config) const;
80
    QVector<KeyInfo> mKeys;
81
    QCA::Initializer *mQcaInitializer = nullptr;
Laurent Montel's avatar
Laurent Montel committed
82
83
};
}
84
Q_DECLARE_TYPEINFO(MessageViewer::KeyInfo, Q_MOVABLE_TYPE);
85
MESSAGEVIEWER_EXPORT QDebug operator <<(QDebug d, const MessageViewer::KeyInfo &t);
Laurent Montel's avatar
Laurent Montel committed
86
#endif // DKIMMANAGERKEY_H