Libksieve

sieveactionereject.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 #include "sieveactionereject.h"
20 #include "editor/sieveeditorutil.h"
21 #include "widgets/multilineedit.h"
22 #include "autocreatescripts/autocreatescriptutil_p.h"
23 
24 #include <KLocalizedString>
25 
26 #include <QLabel>
27 #include <QHBoxLayout>
28 #include <QXmlStreamReader>
29 #include "libksieve_debug.h"
30 
31 using namespace KSieveUi;
32 SieveActionEReject::SieveActionEReject(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
33  : SieveAction(sieveGraphicalModeWidget, QStringLiteral("ereject"), i18n("E-Reject"), parent)
34 {
35 }
36 
37 QWidget *SieveActionEReject::createParamWidget(QWidget *parent) const
38 {
39  QWidget *w = new QWidget(parent);
40  QHBoxLayout *lay = new QHBoxLayout;
41  lay->setContentsMargins(0, 0, 0, 0);
42  w->setLayout(lay);
43  QLabel *lab = new QLabel(i18n("text:"));
44  lay->addWidget(lab);
45 
46  MultiLineEdit *edit = new MultiLineEdit;
47  connect(edit, &MultiLineEdit::textChanged, this, &SieveActionEReject::valueChanged);
48  edit->setObjectName(QStringLiteral("rejectmessage"));
49  lay->addWidget(edit);
50  return w;
51 }
52 
53 void SieveActionEReject::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
54 {
55  while (element.readNextStartElement()) {
56  const QStringRef tagName = element.name();
57  if (tagName == QLatin1String("str")) {
58  const QString tagValue = element.readElementText();
59  MultiLineEdit *edit = w->findChild<MultiLineEdit *>(QStringLiteral("rejectmessage"));
60  edit->setPlainText(tagValue);
61  } else if (tagName == QLatin1String("crlf")) {
62  element.skipCurrentElement();
63  //nothing
64  } else if (tagName == QLatin1String("comment")) {
65  element.skipCurrentElement();
66  //implement in the future ?
67  } else {
68  unknownTag(tagName, error);
69  qCDebug(LIBKSIEVE_LOG) << " SieveActionEReject::setParamWidgetValue unknown tagName " << tagName;
70  }
71  }
72 }
73 
74 QString SieveActionEReject::code(QWidget *w) const
75 {
76  const MultiLineEdit *edit = w->findChild<MultiLineEdit *>(QStringLiteral("rejectmessage"));
77  const QString text = edit->toPlainText();
78 
79  return QStringLiteral("ereject text:%1").arg(AutoCreateScriptUtil::createMultiLine(text));
80 }
81 
82 QStringList SieveActionEReject::needRequires(QWidget *) const
83 {
84  return QStringList() << QStringLiteral("ereject");
85 }
86 
87 QString SieveActionEReject::serverNeedsCapability() const
88 {
89  return QStringLiteral("ereject");
90 }
91 
92 bool SieveActionEReject::needCheckIfServerHasCapability() const
93 {
94  return true;
95 }
96 
97 QString SieveActionEReject::help() const
98 {
99  return i18n(" The \"ereject\" action cancels the implicit keep and refuses delivery of a message.");
100 }
101 
102 QUrl SieveActionEReject::href() const
103 {
104  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
105 }
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
QString name(const QVariant &location)
void skipCurrentElement()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setLayout(QLayout *layout)
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
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-2020 The KDE developers.
Generated on Tue Jul 14 2020 23:08:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.