dkimpolicywidget.cpp 4.92 KB
Newer Older
Laurent Montel's avatar
Laurent Montel committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
   Copyright (C) 2019 Laurent Montel <montel@kde.org>

   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.
*/

#include "dkimpolicywidget.h"
Laurent Montel's avatar
Laurent Montel committed
21
#include "dkimmanagerulesdialog.h"
22
23
#include <KLocalizedString>
#include <QCheckBox>
Laurent Montel's avatar
Laurent Montel committed
24
25
#include <QVBoxLayout>

26
27
#include "messageviewer/messageviewersettings.h"
#include <PimCommon/ConfigureImmutableWidgetUtils>
Laurent Montel's avatar
Laurent Montel committed
28
29
#include <QPointer>
#include <QPushButton>
30
31
32

using namespace PimCommon::ConfigureImmutableWidgetUtils;

Laurent Montel's avatar
Laurent Montel committed
33
34
35
36
37
38
DKIMPolicyWidget::DKIMPolicyWidget(QWidget *parent)
    : QWidget(parent)
{
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    mainLayout->setObjectName(QStringLiteral("mainLayout"));
    mainLayout->setContentsMargins(0, 0, 0, 0);
39
40
41
42

    mVerifyIfEmailMustBeSigned = new QCheckBox(i18n("Check if e-mail should be signed"), this);
    mVerifyIfEmailMustBeSigned->setObjectName(QStringLiteral("mVerifyIfEmailMustBeSigned"));
    mainLayout->addWidget(mVerifyIfEmailMustBeSigned);
Laurent Montel's avatar
Laurent Montel committed
43
    connect(mVerifyIfEmailMustBeSigned, &QCheckBox::toggled, this, [this](bool state) {
44
        mUseDMARC->setEnabled(state);
Laurent Montel's avatar
Laurent Montel committed
45
        mUseDefaultRules->setEnabled(state);
Laurent Montel's avatar
Laurent Montel committed
46
        mRulesButton->setEnabled(state);
Laurent Montel's avatar
Laurent Montel committed
47
        mAutoGenerateRule->setEnabled(state);
48
        mReadAuthResultHeader->setEnabled(state);
49
50
51
52
53
54
55
    });

    mUseDMARC = new QCheckBox(i18n("Use DMARC to heuristically determine if an e-mail should be signed"), this);
    mUseDMARC->setObjectName(QStringLiteral("mUseDMARC"));
    mUseDMARC->setEnabled(false);
    mainLayout->addWidget(mUseDMARC);

56
57
58
    mReadAuthResultHeader = new QCheckBox(i18n("Read Authentication-Results header"), this);
    mReadAuthResultHeader->setObjectName(QStringLiteral("mReadAuthResultHeader"));
    mReadAuthResultHeader->setEnabled(false);
Laurent Montel's avatar
Laurent Montel committed
59
    //mReadAuthResultHeader->setVisible(false); //Reenable when code will be clean!
60
61
62
63
64
65
66
    mainLayout->addWidget(mReadAuthResultHeader);

    mUseDefaultRules = new QCheckBox(i18n("Use default rule"), this);
    mUseDefaultRules->setObjectName(QStringLiteral("mUseDefaultRules"));
    mUseDefaultRules->setEnabled(false);
    mainLayout->addWidget(mUseDefaultRules);

Laurent Montel's avatar
Laurent Montel committed
67
68
69
70
71
    mAutoGenerateRule = new QCheckBox(i18n("Autogenerate rule"), this);
    mAutoGenerateRule->setObjectName(QStringLiteral("mAutoGenerateRule"));
    mAutoGenerateRule->setEnabled(false);
    mainLayout->addWidget(mAutoGenerateRule);

Laurent Montel's avatar
Laurent Montel committed
72
73
74
75
76
77
78
79
80
81
82
83
84
    QHBoxLayout *ruleLayout = new QHBoxLayout;
    mainLayout->addLayout(ruleLayout);
    mRulesButton = new QPushButton(i18n("Show Rules"), this);
    mRulesButton->setObjectName(QStringLiteral("rules"));
    mRulesButton->setEnabled(false);
    ruleLayout->addWidget(mRulesButton);
    connect(mRulesButton, &QPushButton::clicked, this, [this]() {
        QPointer<DKIMManageRulesDialog> dlg = new DKIMManageRulesDialog(this);
        dlg->exec();
        delete dlg;
    });
    ruleLayout->addStretch(1);

85
    mainLayout->addStretch(1);
Laurent Montel's avatar
Laurent Montel committed
86
87
88
89
90
}

DKIMPolicyWidget::~DKIMPolicyWidget()
{
}
91
92
93
94
95

void DKIMPolicyWidget::loadSettings()
{
    loadWidget(mVerifyIfEmailMustBeSigned, MessageViewer::MessageViewerSettings::self()->checkIfEmailShouldBeSignedItem());
    loadWidget(mUseDMARC, MessageViewer::MessageViewerSettings::self()->useDMarcItem());
Laurent Montel's avatar
Laurent Montel committed
96
    loadWidget(mUseDefaultRules, MessageViewer::MessageViewerSettings::self()->useDefaultRulesItem());
Laurent Montel's avatar
Laurent Montel committed
97
    loadWidget(mAutoGenerateRule, MessageViewer::MessageViewerSettings::self()->autogenerateRuleItem());
98
    loadWidget(mReadAuthResultHeader, MessageViewer::MessageViewerSettings::self()->useAuthenticationResultsItem());
99
100
101
102
103
104
}

void DKIMPolicyWidget::saveSettings()
{
    saveCheckBox(mVerifyIfEmailMustBeSigned, MessageViewer::MessageViewerSettings::self()->checkIfEmailShouldBeSignedItem());
    saveCheckBox(mUseDMARC, MessageViewer::MessageViewerSettings::self()->useDMarcItem());
Laurent Montel's avatar
Laurent Montel committed
105
    saveCheckBox(mUseDefaultRules, MessageViewer::MessageViewerSettings::self()->useDefaultRulesItem());
Laurent Montel's avatar
Laurent Montel committed
106
    saveCheckBox(mAutoGenerateRule, MessageViewer::MessageViewerSettings::self()->autogenerateRuleItem());
107
    saveCheckBox(mReadAuthResultHeader, MessageViewer::MessageViewerSettings::self()->useAuthenticationResultsItem());
108
109
110
111
112
113
114
115
}

void DKIMPolicyWidget::resetSettings()
{
    const bool bUseDefaults = MessageViewer::MessageViewerSettings::self()->useDefaults(true);
    loadSettings();
    MessageViewer::MessageViewerSettings::self()->useDefaults(bUseDefaults);
}