Libksieve

sieveactionereject.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
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 "libksieve_debug.h"
14 #include <QHBoxLayout>
15 #include <QLabel>
16 #include <QXmlStreamReader>
17 
18 using namespace KSieveUi;
19 SieveActionEReject::SieveActionEReject(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20  : SieveAction(sieveGraphicalModeWidget, QStringLiteral("ereject"), i18n("E-Reject"), parent)
21 {
22 }
23 
24 QWidget *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(i18n("text:"));
31  lay->addWidget(lab);
32 
33  auto edit = new MultiLineEdit;
34  connect(edit, &MultiLineEdit::textChanged, this, &SieveActionEReject::valueChanged);
35  edit->setObjectName(QStringLiteral("rejectmessage"));
36  lay->addWidget(edit);
37  return w;
38 }
39 
40 void SieveActionEReject::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
41 {
42  while (element.readNextStartElement()) {
43  const QStringRef tagName = element.name();
44  if (tagName == QLatin1String("str")) {
45  const QString tagValue = element.readElementText();
46  auto edit = w->findChild<MultiLineEdit *>(QStringLiteral("rejectmessage"));
47  edit->setPlainText(tagValue);
48  } else if (tagName == QLatin1String("crlf")) {
49  element.skipCurrentElement();
50  // nothing
51  } else if (tagName == QLatin1String("comment")) {
52  element.skipCurrentElement();
53  // implement in the future ?
54  } else {
55  unknownTag(tagName, error);
56  qCDebug(LIBKSIEVE_LOG) << " SieveActionEReject::setParamWidgetValue unknown tagName " << tagName;
57  }
58  }
59 }
60 
61 QString 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 
69 QStringList SieveActionEReject::needRequires(QWidget *) const
70 {
71  return QStringList() << QStringLiteral("ereject");
72 }
73 
74 QString SieveActionEReject::serverNeedsCapability() const
75 {
76  return QStringLiteral("ereject");
77 }
78 
79 bool SieveActionEReject::needCheckIfServerHasCapability() const
80 {
81  return true;
82 }
83 
84 QString SieveActionEReject::help() const
85 {
86  return i18n(" The \"ereject\" action cancels the implicit keep and refuses delivery of a message.");
87 }
88 
89 QUrl SieveActionEReject::href() const
90 {
91  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
92 }
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
QString name(const QVariant &location)
void skipCurrentElement()
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QByteArray tagValue(const Elem &elem, TagKey key)
QString i18n(const char *text, const TYPE &arg...)
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QStringRef name() const const
T findChild(const QString &name, Qt::FindChildOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.