Libksieve

sieveactionbreak.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "sieveactionbreak.h"
7 #include "autocreatescripts/autocreatescriptutil_p.h"
8 #include "editor/sieveeditorutil.h"
9 
10 #include <KLocalizedString>
11 #include <Libkdepim/LineEditCatchReturnKey>
12 #include <QLineEdit>
13 
14 #include "libksieve_debug.h"
15 #include <QHBoxLayout>
16 #include <QLabel>
17 #include <QXmlStreamReader>
18 
19 using namespace KSieveUi;
20 SieveActionBreak::SieveActionBreak(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
21  : SieveAction(sieveGraphicalModeWidget, QStringLiteral("break"), i18n("Break"), parent)
22 {
23 }
24 
25 QWidget *SieveActionBreak::createParamWidget(QWidget *parent) const
26 {
27  auto w = new QWidget(parent);
28  auto lay = new QHBoxLayout;
29  lay->setContentsMargins({});
30  w->setLayout(lay);
31 
32  auto lab = new QLabel(i18n("Name (optional):"));
33  lay->addWidget(lab);
34 
35  auto subject = new QLineEdit;
36  new KPIM::LineEditCatchReturnKey(subject, w);
37  subject->setObjectName(QStringLiteral("name"));
38  connect(subject, &QLineEdit::textChanged, this, &SieveActionBreak::valueChanged);
39  lay->addWidget(subject);
40  return w;
41 }
42 
43 void SieveActionBreak::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
44 {
45  while (element.readNextStartElement()) {
46  const QStringRef tagName = element.name();
47  if (tagName == QLatin1String("tag")) {
48  const QString tagValue = element.readElementText();
49  if (tagValue == QLatin1String("name")) {
50  auto name = w->findChild<QLineEdit *>(QStringLiteral("name"));
51  name->setText(AutoCreateScriptUtil::strValue(element));
52  } else {
53  unknownTagValue(tagValue, error);
54  qCDebug(LIBKSIEVE_LOG) << " SieveActionBreak::setParamWidgetValue unknown tagValue " << tagValue;
55  }
56  } else if (tagName == QLatin1String("str")) {
57  element.skipCurrentElement();
58  // Nothing
59  } else if (tagName == QLatin1String("crlf")) {
60  element.skipCurrentElement();
61  // nothing
62  } else if (tagName == QLatin1String("comment")) {
63  element.skipCurrentElement();
64  // implement in the future ?
65  } else {
66  unknownTag(tagName, error);
67  qCDebug(LIBKSIEVE_LOG) << "SieveActionBreak::setParamWidgetValue unknown tag " << tagName;
68  }
69  }
70 }
71 
72 QUrl SieveActionBreak::href() const
73 {
74  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
75 }
76 
77 QString SieveActionBreak::code(QWidget *w) const
78 {
79  const QLineEdit *name = w->findChild<QLineEdit *>(QStringLiteral("name"));
80  const QString nameStr = name->text();
81  if (!nameStr.isEmpty()) {
82  return QStringLiteral("break :name \"%1\";").arg(nameStr);
83  }
84  return QStringLiteral("break;");
85 }
86 
87 QString SieveActionBreak::help() const
88 {
89  return i18n("The break command terminates the closest enclosing loop.");
90 }
91 
92 QStringList SieveActionBreak::needRequires(QWidget * /*parent*/) const
93 {
94  return QStringList() << QStringLiteral("foreverypart");
95 }
96 
97 bool SieveActionBreak::needCheckIfServerHasCapability() const
98 {
99  return true;
100 }
101 
102 QString SieveActionBreak::serverNeedsCapability() const
103 {
104  return QStringLiteral("foreverypart");
105 }
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
QString name(const QVariant &location)
void textChanged(const QString &text)
void skipCurrentElement()
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QByteArray tagValue(const Elem &elem, TagKey key)
QString i18n(const char *text, const TYPE &arg...)
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 Sat Apr 17 2021 23:09:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.