Libksieve

sieveconditionfalse.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 "sieveconditionfalse.h"
20 #include "editor/sieveeditorutil.h"
21 #include "libksieve_debug.h"
22 #include "autocreatescripts/autocreatescriptutil_p.h"
23 
24 #include <KLocalizedString>
25 
26 #include <QHBoxLayout>
27 #include <QLabel>
28 #include <QXmlStreamReader>
29 
30 using namespace KSieveUi;
31 
32 SieveConditionFalse::SieveConditionFalse(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
33  : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("false"), i18n("False"), parent)
34 {
35 }
36 
37 QWidget *SieveConditionFalse::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 
44  QLabel *label = new QLabel(i18n("false"));
45  lay->addWidget(label);
46  return w;
47 }
48 
49 QString SieveConditionFalse::code(QWidget *) const
50 {
51  return QStringLiteral("false") + AutoCreateScriptUtil::generateConditionComment(comment());
52 }
53 
54 QString SieveConditionFalse::help() const
55 {
56  return i18n("The \"false\" test always evaluates to false.");
57 }
58 
59 void SieveConditionFalse::setParamWidgetValue(QXmlStreamReader &element, QWidget *, bool, QString &error)
60 {
61  QString commentStr;
62  while (element.readNextStartElement()) {
63  const QStringRef tagName = element.name();
64  if (tagName == QLatin1String("comment")) {
65  commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
66  } else if (tagName == QLatin1String("crlf")) {
67  element.skipCurrentElement();
68  //nothing
69  } else {
70  unknownTag(tagName, error);
71  qCDebug(LIBKSIEVE_LOG) << " SieveConditionFalse::setParamWidgetValue unknown tagName " << tagName;
72  }
73  }
74  if (!commentStr.isEmpty()) {
75  setComment(commentStr);
76  }
77 }
78 
79 QUrl SieveConditionFalse::href() const
80 {
81  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
82 }
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 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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.