Libksieve

sieveconditionservermetadataexists.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
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 <KLocalizedString>
10 #include <Libkdepim/LineEditCatchReturnKey>
11 #include <QLineEdit>
12 
13 #include "libksieve_debug.h"
14 #include <QHBoxLayout>
15 #include <QLabel>
16 #include <QXmlStreamReader>
17 
18 using namespace KSieveUi;
19 SieveConditionServerMetaDataExists::SieveConditionServerMetaDataExists(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20  : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("servermetadataexists"), i18n("Server Meta Data Exists"), parent)
21 {
22 }
23 
24 QWidget *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(i18n("Annotation:"));
32  lay->addWidget(lab);
33 
34  auto value = new QLineEdit;
35  new KPIM::LineEditCatchReturnKey(value, w);
36  value->setObjectName(QStringLiteral("value"));
37  connect(value, &QLineEdit::textChanged, this, &SieveConditionServerMetaDataExists::valueChanged);
38  lay->addWidget(value);
39 
40  return w;
41 }
42 
43 QString 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 
50 QStringList SieveConditionServerMetaDataExists::needRequires(QWidget *) const
51 {
52  return QStringList() << QStringLiteral("servermetadata");
53 }
54 
55 bool SieveConditionServerMetaDataExists::needCheckIfServerHasCapability() const
56 {
57  return true;
58 }
59 
60 QString SieveConditionServerMetaDataExists::serverNeedsCapability() const
61 {
62  return QStringLiteral("servermetadata");
63 }
64 
65 QString 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 
70 void SieveConditionServerMetaDataExists::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error)
71 {
72  QString commentStr;
73  while (element.readNextStartElement()) {
74  const QStringRef tagName = element.name();
75  if (tagName == QLatin1String("str")) {
76  const QString tagValue = element.readElementText();
77  auto value = w->findChild<QLineEdit *>(QStringLiteral("value"));
78  value->setText(tagValue);
79  } else if (tagName == QLatin1String("crlf")) {
80  element.skipCurrentElement();
81  // nothing
82  } else if (tagName == QLatin1String("comment")) {
83  commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
84  } else {
85  unknownTag(tagName, error);
86  qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaDataExists::setParamWidgetValue unknown tagName " << tagName;
87  }
88  }
89  if (!commentStr.isEmpty()) {
90  setComment(commentStr);
91  }
92 }
93 
94 QUrl SieveConditionServerMetaDataExists::href() const
95 {
96  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
97 }
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
QString name(const QVariant &location)
void textChanged(const QString &text)
void skipCurrentElement()
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QByteArray tagValue(const Elem &elem, TagKey key)
bool isEmpty() const const
QString i18n(const char *text, const TYPE &arg...)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
QStringRef name() const const
T findChild(const QString &name, Qt::FindChildOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Apr 16 2021 23:09:34 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.