Messagelib

dkimrulewidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2019-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "dkimrulewidget.h"
8 #include "dkimmanagerulescombobox.h"
9 #include <KLocalizedString>
10 #include <QCheckBox>
11 #include <QFormLayout>
12 #include <QLineEdit>
13 #include <QSpinBox>
14 
15 using namespace MessageViewer;
16 DKIMRuleWidget::DKIMRuleWidget(QWidget *parent)
17  : QWidget(parent)
18  , mEnabled(new QCheckBox(i18n("Enabled"), this))
19  , mDomain(new QLineEdit(this))
20  , mSignatureDomainIdentifier(new QLineEdit(this))
21  , mFrom(new QLineEdit(this))
22  , mListId(new QLineEdit(this))
23  , mPriority(new QSpinBox(this))
24  , mRuleType(new DKIMManageRulesComboBox(this))
25 {
26  auto layout = new QFormLayout(this);
27  layout->setObjectName(QStringLiteral("layout"));
28  layout->setContentsMargins({});
29 
30  mEnabled->setObjectName(QStringLiteral("enabled"));
31  mEnabled->setChecked(true);
32  layout->addWidget(mEnabled);
33 
34  mDomain->setObjectName(QStringLiteral("domain"));
35  mDomain->setClearButtonEnabled(true);
36  layout->addRow(i18n("Domain:"), mDomain);
37  connect(mDomain, &QLineEdit::textChanged, this, &DKIMRuleWidget::updateOkButton);
38 
39  mListId->setObjectName(QStringLiteral("listid"));
40  mListId->setClearButtonEnabled(true);
41  layout->addRow(i18n("List-Id:"), mListId);
42 
43  mFrom->setObjectName(QStringLiteral("from"));
44  mFrom->setClearButtonEnabled(true);
45  layout->addRow(i18n("From:"), mFrom);
46  mFrom->setPlaceholderText(i18n("Use '*' to specify all emails from domain"));
47  connect(mFrom, &QLineEdit::textChanged, this, &DKIMRuleWidget::updateOkButton);
48 
49  mSignatureDomainIdentifier->setObjectName(QStringLiteral("signaturedomainidentifier"));
50  mSignatureDomainIdentifier->setClearButtonEnabled(true);
51  layout->addRow(i18n("SDID:"), mSignatureDomainIdentifier);
52 
53  mRuleType->setObjectName(QStringLiteral("ruletype"));
54  layout->addRow(i18n("Rule:"), mRuleType);
55 
56  mPriority->setObjectName(QStringLiteral("priority"));
57  mPriority->setMinimum(1);
58  mPriority->setMaximum(9999);
59  mPriority->setValue(1000); // Default Value
60  layout->addRow(i18n("Priority:"), mPriority);
61 }
62 
63 DKIMRuleWidget::~DKIMRuleWidget() = default;
64 
65 void DKIMRuleWidget::updateOkButton()
66 {
67  Q_EMIT updateOkButtonRequested(!mFrom->text().trimmed().isEmpty() && !mDomain->text().trimmed().isEmpty());
68 }
69 
70 void DKIMRuleWidget::loadRule(const MessageViewer::DKIMRule &rule)
71 {
72  mEnabled->setChecked(rule.enabled());
73  mDomain->setText(rule.domain());
74  mSignatureDomainIdentifier->setText(rule.signedDomainIdentifier().join(QLatin1Char(' ')));
75  mFrom->setText(rule.from());
76  mListId->setText(rule.listId());
77  mRuleType->setRuleType(rule.ruleType());
78  mPriority->setValue(rule.priority());
79 }
80 
81 MessageViewer::DKIMRule DKIMRuleWidget::rule() const
82 {
84  rule.setEnabled(mEnabled->isChecked());
85  rule.setDomain(mDomain->text());
86  rule.setSignedDomainIdentifier(mSignatureDomainIdentifier->text().split(QLatin1Char(' ')));
87  rule.setFrom(mFrom->text());
88  rule.setListId(mListId->text());
89  rule.setRuleType(mRuleType->ruleType());
90  rule.setPriority(mPriority->value());
91  return rule;
92 }
void textChanged(const QString &text)
QString join(const QString &separator) const const
bool isEmpty() const const
QString trimmed() const const
QString i18n(const char *text, const TYPE &arg...)
The DKIMRule class.
Definition: dkimrule.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Nov 26 2021 23:16:41 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.