Libksieve

sieveconditionfalse.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "sieveconditionfalse.h"
7 #include "autocreatescripts/autocreatescriptutil_p.h"
8 #include "editor/sieveeditorutil.h"
9 #include "libksieve_debug.h"
10 
11 #include <KLocalizedString>
12 
13 #include <QHBoxLayout>
14 #include <QLabel>
15 #include <QXmlStreamReader>
16 
17 using namespace KSieveUi;
18 
19 SieveConditionFalse::SieveConditionFalse(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20  : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("false"), i18n("False"), parent)
21 {
22 }
23 
24 QWidget *SieveConditionFalse::createParamWidget(QWidget *parent) const
25 {
26  auto w = new QWidget(parent);
27  auto lay = new QHBoxLayout;
28  lay->setContentsMargins({});
29  w->setLayout(lay);
30 
31  auto label = new QLabel(i18n("false"));
32  lay->addWidget(label);
33  return w;
34 }
35 
36 QString SieveConditionFalse::code(QWidget *) const
37 {
38  return QStringLiteral("false") + AutoCreateScriptUtil::generateConditionComment(comment());
39 }
40 
41 QString SieveConditionFalse::help() const
42 {
43  return i18n("The \"false\" test always evaluates to false.");
44 }
45 
46 void SieveConditionFalse::setParamWidgetValue(QXmlStreamReader &element, QWidget *, bool, QString &error)
47 {
48  QString commentStr;
49  while (element.readNextStartElement()) {
50  const QStringRef tagName = element.name();
51  if (tagName == QLatin1String("comment")) {
52  commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
53  } else if (tagName == QLatin1String("crlf")) {
54  element.skipCurrentElement();
55  // nothing
56  } else {
57  unknownTag(tagName, error);
58  qCDebug(LIBKSIEVE_LOG) << " SieveConditionFalse::setParamWidgetValue unknown tagName " << tagName;
59  }
60  }
61  if (!commentStr.isEmpty()) {
62  setComment(commentStr);
63  }
64 }
65 
66 QUrl SieveConditionFalse::href() const
67 {
68  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
69 }
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
QString name(const QVariant &location)
void skipCurrentElement()
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QString label(StandardShortcut id)
bool isEmpty() const const
QString i18n(const char *text, const TYPE &arg...)
QObject * parent() const const
QStringRef name() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sun Apr 11 2021 23:09:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.