File indexing completed on 2024-12-29 04:54:42

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "sieveconditionfalse.h"
0007 #include "autocreatescripts/autocreatescriptutil_p.h"
0008 #include "editor/sieveeditorutil.h"
0009 #include "libksieveui_debug.h"
0010 
0011 #include <KLocalizedString>
0012 
0013 #include <QHBoxLayout>
0014 #include <QLabel>
0015 #include <QXmlStreamReader>
0016 
0017 using namespace KSieveUi;
0018 
0019 SieveConditionFalse::SieveConditionFalse(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
0020     : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("false"), i18n("False"), parent)
0021 {
0022 }
0023 
0024 QWidget *SieveConditionFalse::createParamWidget(QWidget *parent) const
0025 {
0026     auto w = new QWidget(parent);
0027     auto lay = new QHBoxLayout;
0028     lay->setContentsMargins({});
0029     w->setLayout(lay);
0030 
0031     auto label = new QLabel(i18n("false"));
0032     lay->addWidget(label);
0033     return w;
0034 }
0035 
0036 QString SieveConditionFalse::code(QWidget *) const
0037 {
0038     return QStringLiteral("false") + AutoCreateScriptUtil::generateConditionComment(comment());
0039 }
0040 
0041 QString SieveConditionFalse::help() const
0042 {
0043     return i18n("The \"false\" test always evaluates to false.");
0044 }
0045 
0046 void SieveConditionFalse::setParamWidgetValue(QXmlStreamReader &element, QWidget *, bool, QString &error)
0047 {
0048     QString commentStr;
0049     while (element.readNextStartElement()) {
0050         const QStringView tagName = element.name();
0051         if (tagName == QLatin1StringView("comment")) {
0052             commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
0053         } else if (tagName == QLatin1StringView("crlf")) {
0054             element.skipCurrentElement();
0055             // nothing
0056         } else {
0057             unknownTag(tagName, error);
0058             qCDebug(LIBKSIEVEUI_LOG) << " SieveConditionFalse::setParamWidgetValue unknown tagName " << tagName;
0059         }
0060     }
0061     if (!commentStr.isEmpty()) {
0062         setComment(commentStr);
0063     }
0064 }
0065 
0066 QUrl SieveConditionFalse::href() const
0067 {
0068     return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
0069 }
0070 
0071 #include "moc_sieveconditionfalse.cpp"