Libksieve

sieveactionreject.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#include "sieveactionreject.h"
7#include "autocreatescripts/autocreatescriptutil_p.h"
8#include "editor/sieveeditorutil.h"
9#include "widgets/multilineedit.h"
10
11#include <KLocalizedString>
12
13#include "libksieveui_debug.h"
14#include <QHBoxLayout>
15#include <QLabel>
16#include <QXmlStreamReader>
17
18using namespace KSieveUi;
19SieveActionReject::SieveActionReject(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20 : SieveAction(sieveGraphicalModeWidget, QStringLiteral("reject"), i18n("Reject"), parent)
21{
22}
23
24QWidget *SieveActionReject::createParamWidget(QWidget *parent) const
25{
26 auto w = new QWidget(parent);
27 auto lay = new QHBoxLayout;
28 lay->setContentsMargins({});
29 w->setLayout(lay);
30 auto lab = new QLabel(i18n("text:"));
31 lay->addWidget(lab);
32
33 auto edit = new MultiLineEdit;
34 connect(edit, &MultiLineEdit::textChanged, this, &SieveActionReject::valueChanged);
35 edit->setObjectName(QLatin1StringView("rejectmessage"));
36 lay->addWidget(edit);
37 return w;
38}
39
40void SieveActionReject::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
41{
42 while (element.readNextStartElement()) {
43 const QStringView tagName = element.name();
44 if (tagName == QLatin1StringView("str")) {
45 const QString tagValue = element.readElementText();
46 auto edit = w->findChild<MultiLineEdit *>(QStringLiteral("rejectmessage"));
47 edit->setPlainText(tagValue);
48 } else if (tagName == QLatin1StringView("crlf")) {
49 element.skipCurrentElement();
50 // nothing
51 } else if (tagName == QLatin1StringView("comment")) {
52 element.skipCurrentElement();
53 // implement in the future ?
54 } else {
55 unknownTag(tagName, error);
56 qCDebug(LIBKSIEVEUI_LOG) << " SieveActionReject::setParamWidgetValue unknown tagName " << tagName;
57 }
58 }
59}
60
61QString SieveActionReject::code(QWidget *w) const
62{
63 const MultiLineEdit *edit = w->findChild<MultiLineEdit *>(QStringLiteral("rejectmessage"));
64 const QString text = edit->toPlainText();
65
66 return QStringLiteral("reject text:%1").arg(AutoCreateScriptUtil::createMultiLine(text));
67}
68
69QStringList SieveActionReject::needRequires(QWidget *) const
70{
71 return QStringList() << QStringLiteral("reject");
72}
73
74QString SieveActionReject::serverNeedsCapability() const
75{
76 return QStringLiteral("reject");
77}
78
79bool SieveActionReject::needCheckIfServerHasCapability() const
80{
81 return true;
82}
83
84QString SieveActionReject::help() const
85{
86 return i18n(" The \"reject\" action cancels the implicit keep and refuses delivery of a message.");
87}
88
89QUrl SieveActionReject::href() const
90{
91 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
92}
93
94#include "moc_sieveactionreject.cpp"
QString i18n(const char *text, const TYPE &arg...)
QByteArray tagValue(const Elem &elem, const char *keyName)
void setContentsMargins(const QMargins &margins)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T findChild(const QString &name, Qt::FindChildOptions options) const const
QObject * parent() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void skipCurrentElement()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:19 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.