File indexing completed on 2024-12-29 04:54:43
0001 /* 0002 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "sieveconditionservermetadataexists.h" 0007 #include "autocreatescripts/autocreatescriptutil_p.h" 0008 #include "editor/sieveeditorutil.h" 0009 #include <KLineEditEventHandler> 0010 #include <KLocalizedString> 0011 #include <QLineEdit> 0012 0013 #include "libksieveui_debug.h" 0014 #include <QHBoxLayout> 0015 #include <QLabel> 0016 #include <QXmlStreamReader> 0017 0018 using namespace KSieveUi; 0019 SieveConditionServerMetaDataExists::SieveConditionServerMetaDataExists(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) 0020 : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("servermetadataexists"), i18n("Server Meta Data Exists"), parent) 0021 { 0022 } 0023 0024 QWidget *SieveConditionServerMetaDataExists::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 lab = new QLabel(i18n("Annotation:")); 0032 lay->addWidget(lab); 0033 0034 auto value = new QLineEdit; 0035 KLineEditEventHandler::catchReturnKey(value); 0036 value->setObjectName(QLatin1StringView("value")); 0037 connect(value, &QLineEdit::textChanged, this, &SieveConditionServerMetaDataExists::valueChanged); 0038 lay->addWidget(value); 0039 0040 return w; 0041 } 0042 0043 QString SieveConditionServerMetaDataExists::code(QWidget *w) const 0044 { 0045 const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value")); 0046 const QString valueStr = value->text(); 0047 return QStringLiteral("servermetadataexists \"%1\"").arg(valueStr) + AutoCreateScriptUtil::generateConditionComment(comment()); 0048 } 0049 0050 QStringList SieveConditionServerMetaDataExists::needRequires(QWidget *) const 0051 { 0052 return QStringList() << QStringLiteral("servermetadata"); 0053 } 0054 0055 bool SieveConditionServerMetaDataExists::needCheckIfServerHasCapability() const 0056 { 0057 return true; 0058 } 0059 0060 QString SieveConditionServerMetaDataExists::serverNeedsCapability() const 0061 { 0062 return QStringLiteral("servermetadata"); 0063 } 0064 0065 QString SieveConditionServerMetaDataExists::help() const 0066 { 0067 return i18n("The \"servermetadataexists\" test is true if all of the server annotations listed in the \"annotation-names\" argument exist."); 0068 } 0069 0070 void SieveConditionServerMetaDataExists::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error) 0071 { 0072 QString commentStr; 0073 while (element.readNextStartElement()) { 0074 const QStringView tagName = element.name(); 0075 if (tagName == QLatin1StringView("str")) { 0076 const QString tagValue = element.readElementText(); 0077 auto value = w->findChild<QLineEdit *>(QStringLiteral("value")); 0078 value->setText(tagValue); 0079 } else if (tagName == QLatin1StringView("crlf")) { 0080 element.skipCurrentElement(); 0081 // nothing 0082 } else if (tagName == QLatin1StringView("comment")) { 0083 commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); 0084 } else { 0085 unknownTag(tagName, error); 0086 qCDebug(LIBKSIEVEUI_LOG) << " SieveConditionServerMetaDataExists::setParamWidgetValue unknown tagName " << tagName; 0087 } 0088 } 0089 if (!commentStr.isEmpty()) { 0090 setComment(commentStr); 0091 } 0092 } 0093 0094 QUrl SieveConditionServerMetaDataExists::href() const 0095 { 0096 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); 0097 } 0098 0099 #include "moc_sieveconditionservermetadataexists.cpp"