Libksieve

sieveconditionfalse.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
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 "libksieveui_debug.h"
10
11#include <KLocalizedString>
12
13#include <QHBoxLayout>
14#include <QLabel>
15#include <QXmlStreamReader>
16
17using namespace KSieveUi;
18
19SieveConditionFalse::SieveConditionFalse(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20 : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("false"), i18n("False"), parent)
21{
22}
23
24QWidget *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
36QString SieveConditionFalse::code(QWidget *) const
37{
38 return QStringLiteral("false") + AutoCreateScriptUtil::generateConditionComment(comment());
39}
40
41QString SieveConditionFalse::help() const
42{
43 return i18n("The \"false\" test always evaluates to false.");
44}
45
46void SieveConditionFalse::setParamWidgetValue(QXmlStreamReader &element, QWidget *, bool, QString &error)
47{
48 QString commentStr;
49 while (element.readNextStartElement()) {
50 const QStringView tagName = element.name();
51 if (tagName == QLatin1StringView("comment")) {
52 commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
53 } else if (tagName == QLatin1StringView("crlf")) {
54 element.skipCurrentElement();
55 // nothing
56 } else {
57 unknownTag(tagName, error);
58 qCDebug(LIBKSIEVEUI_LOG) << " SieveConditionFalse::setParamWidgetValue unknown tagName " << tagName;
59 }
60 }
61 if (!commentStr.isEmpty()) {
62 setComment(commentStr);
63 }
64}
65
66QUrl SieveConditionFalse::href() const
67{
68 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
69}
70
71#include "moc_sieveconditionfalse.cpp"
QString i18n(const char *text, const TYPE &arg...)
void setContentsMargins(const QMargins &margins)
QObject * parent() const const
bool isEmpty() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void skipCurrentElement()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:19 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.