Libksieve

sieveconditionservermetadataexists.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 "sieveconditionservermetadataexists.h"
7#include "autocreatescripts/autocreatescriptutil_p.h"
8#include "editor/sieveeditorutil.h"
9#include <KLineEditEventHandler>
10#include <KLocalizedString>
11#include <QLineEdit>
12
13#include "libksieveui_debug.h"
14#include <QHBoxLayout>
15#include <QLabel>
16#include <QXmlStreamReader>
17
18using namespace KSieveUi;
19SieveConditionServerMetaDataExists::SieveConditionServerMetaDataExists(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20 : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("servermetadataexists"), i18n("Server Meta Data Exists"), parent)
21{
22}
23
24QWidget *SieveConditionServerMetaDataExists::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 lab = new QLabel(i18nc("@label:textbox", "Annotation:"));
32 lay->addWidget(lab);
33
34 auto value = new QLineEdit;
36 value->setObjectName(QLatin1StringView("value"));
37 connect(value, &QLineEdit::textChanged, this, &SieveConditionServerMetaDataExists::valueChanged);
38 lay->addWidget(value);
39
40 return w;
41}
42
43QString SieveConditionServerMetaDataExists::code(QWidget *w) const
44{
45 const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
46 const QString valueStr = value->text();
47 return QStringLiteral("servermetadataexists \"%1\"").arg(valueStr) + AutoCreateScriptUtil::generateConditionComment(comment());
48}
49
50QStringList SieveConditionServerMetaDataExists::needRequires(QWidget *) const
51{
52 return QStringList() << QStringLiteral("servermetadata");
53}
54
55bool SieveConditionServerMetaDataExists::needCheckIfServerHasCapability() const
56{
57 return true;
58}
59
60QString SieveConditionServerMetaDataExists::serverNeedsCapability() const
61{
62 return QStringLiteral("servermetadata");
63}
64
65QString SieveConditionServerMetaDataExists::help() const
66{
67 return i18n("The \"servermetadataexists\" test is true if all of the server annotations listed in the \"annotation-names\" argument exist.");
68}
69
70void SieveConditionServerMetaDataExists::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error)
71{
72 QString commentStr;
73 while (element.readNextStartElement()) {
74 const QStringView tagName = element.name();
75 if (tagName == QLatin1StringView("str")) {
76 const QString tagValue = element.readElementText();
77 auto value = w->findChild<QLineEdit *>(QStringLiteral("value"));
78 value->setText(tagValue);
79 } else if (tagName == QLatin1StringView("crlf")) {
80 element.skipCurrentElement();
81 // nothing
82 } else if (tagName == QLatin1StringView("comment")) {
83 commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
84 } else {
85 unknownTag(tagName, error);
86 qCDebug(LIBKSIEVEUI_LOG) << " SieveConditionServerMetaDataExists::setParamWidgetValue unknown tagName " << tagName;
87 }
88 }
89 if (!commentStr.isEmpty()) {
90 setComment(commentStr);
91 }
92}
93
94QUrl SieveConditionServerMetaDataExists::href() const
95{
96 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
97}
98
99#include "moc_sieveconditionservermetadataexists.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
QByteArray tagValue(const Elem &elem, const char *keyName)
void setContentsMargins(const QMargins &margins)
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T findChild(const QString &name, Qt::FindChildOptions options) const const
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.