Messagelib

dkimrulewidget.cpp
1/*
2 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
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
15using namespace MessageViewer;
16DKIMRuleWidget::DKIMRuleWidget(QWidget *parent)
17 : QWidget(parent)
18 , mEnabled(new QCheckBox(i18nc("@option:check", "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(QLatin1StringView("layout"));
28 layout->setContentsMargins({});
29
30 mEnabled->setObjectName(QLatin1StringView("enabled"));
31 mEnabled->setChecked(true);
32 layout->addWidget(mEnabled);
33
34 mDomain->setObjectName(QLatin1StringView("domain"));
35 mDomain->setClearButtonEnabled(true);
36 layout->addRow(i18n("Domain:"), mDomain);
37 connect(mDomain, &QLineEdit::textChanged, this, &DKIMRuleWidget::updateOkButton);
38
39 mListId->setObjectName(QLatin1StringView("listid"));
40 mListId->setClearButtonEnabled(true);
41 layout->addRow(i18n("List-Id:"), mListId);
42
43 mFrom->setObjectName(QLatin1StringView("from"));
44 mFrom->setClearButtonEnabled(true);
45 layout->addRow(i18n("From:"), mFrom);
46 mFrom->setPlaceholderText(i18nc("@info:placeholder", "Use '*' to specify all emails from domain"));
47 connect(mFrom, &QLineEdit::textChanged, this, &DKIMRuleWidget::updateOkButton);
48
49 mSignatureDomainIdentifier->setObjectName(QLatin1StringView("signaturedomainidentifier"));
50 mSignatureDomainIdentifier->setClearButtonEnabled(true);
51 layout->addRow(i18n("SDID:"), mSignatureDomainIdentifier);
52
53 mRuleType->setObjectName(QLatin1StringView("ruletype"));
54 layout->addRow(i18n("Rule:"), mRuleType);
55
56 mPriority->setObjectName(QLatin1StringView("priority"));
57 mPriority->setMinimum(1);
58 mPriority->setMaximum(9999);
59 mPriority->setValue(1000); // Default Value
60 layout->addRow(i18n("Priority:"), mPriority);
61}
62
63DKIMRuleWidget::~DKIMRuleWidget() = default;
64
65void DKIMRuleWidget::updateOkButton()
66{
67 Q_EMIT updateOkButtonRequested(!mFrom->text().trimmed().isEmpty() && !mDomain->text().trimmed().isEmpty());
68}
69
70void 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
81MessageViewer::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}
93
94#include "moc_dkimrulewidget.cpp"
The DKIMRule class.
Definition dkimrule.h:18
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void setChecked(bool)
void textChanged(const QString &text)
Q_EMITQ_EMIT
void setValue(int val)
QString join(QChar separator) const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.