Libksieve

sieveconditiontrue.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 "sieveconditiontrue.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
19SieveConditionTrue::SieveConditionTrue(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20 : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("true"), i18n("True"), parent)
21{
22}
23
24QWidget *SieveConditionTrue::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(i18nc("@label:textbox", "true"));
32 lay->addWidget(label);
33 return w;
34}
35
36QString SieveConditionTrue::code(QWidget *) const
37{
38 return QStringLiteral("true") + AutoCreateScriptUtil::generateConditionComment(comment());
39}
40
41QString SieveConditionTrue::help() const
42{
43 return i18n("The \"true\" test always evaluates to true.");
44}
45
46void SieveConditionTrue::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) << " SieveConditionTrue::setParamWidgetValue unknown tagName " << tagName;
59 }
60 }
61 if (!commentStr.isEmpty()) {
62 setComment(commentStr);
63 }
64}
65
66QUrl SieveConditionTrue::href() const
67{
68 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
69}
70
71#include "moc_sieveconditiontrue.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
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 Fri Dec 6 2024 12:07:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.