Libksieve

sieveactionereject.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 "sieveactionereject.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;
19SieveActionEReject::SieveActionEReject(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20 : SieveAction(sieveGraphicalModeWidget, QStringLiteral("ereject"), i18n("E-Reject"), parent)
21{
22}
23
24QWidget *SieveActionEReject::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(i18nc("@label:textbox", "text:"));
31 lay->addWidget(lab);
32
33 auto edit = new MultiLineEdit;
34 connect(edit, &MultiLineEdit::textChanged, this, &SieveActionEReject::valueChanged);
35 edit->setObjectName(QLatin1StringView("rejectmessage"));
36 lay->addWidget(edit);
37 return w;
38}
39
40void SieveActionEReject::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) << " SieveActionEReject::setParamWidgetValue unknown tagName " << tagName;
57 }
58 }
59}
60
61QString SieveActionEReject::code(QWidget *w) const
62{
63 const MultiLineEdit *edit = w->findChild<MultiLineEdit *>(QStringLiteral("rejectmessage"));
64 const QString text = edit->toPlainText();
65
66 return QStringLiteral("ereject text:%1").arg(AutoCreateScriptUtil::createMultiLine(text));
67}
68
69QStringList SieveActionEReject::needRequires(QWidget *) const
70{
71 return QStringList() << QStringLiteral("ereject");
72}
73
74QString SieveActionEReject::serverNeedsCapability() const
75{
76 return QStringLiteral("ereject");
77}
78
79bool SieveActionEReject::needCheckIfServerHasCapability() const
80{
81 return true;
82}
83
84QString SieveActionEReject::help() const
85{
86 return i18n(" The \"ereject\" action cancels the implicit keep and refuses delivery of a message.");
87}
88
89QUrl SieveActionEReject::href() const
90{
91 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
92}
93
94#include "moc_sieveactionereject.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
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
void textChanged()
QString toPlainText() const const
QString arg(Args &&... args) 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 Sat Dec 21 2024 16:57:10 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.