Libksieve

sieveconditionservermetadataexists.cpp
1 /*
2  Copyright (C) 2013-2020 Laurent Montel <[email protected]>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 #include "sieveconditionservermetadataexists.h"
20 #include "editor/sieveeditorutil.h"
21 #include "autocreatescripts/autocreatescriptutil_p.h"
22 #include <KLocalizedString>
23 #include <QLineEdit>
24 
25 #include <QHBoxLayout>
26 #include "libksieve_debug.h"
27 #include <QLabel>
28 #include <QXmlStreamReader>
29 
30 using namespace KSieveUi;
31 SieveConditionServerMetaDataExists::SieveConditionServerMetaDataExists(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
32  : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("servermetadataexists"), i18n("Server Meta Data Exists"), parent)
33 {
34 }
35 
36 QWidget *SieveConditionServerMetaDataExists::createParamWidget(QWidget *parent) const
37 {
38  QWidget *w = new QWidget(parent);
39  QHBoxLayout *lay = new QHBoxLayout;
40  lay->setContentsMargins(0, 0, 0, 0);
41  w->setLayout(lay);
42 
43  QLabel *lab = new QLabel(i18n("Annotation:"));
44  lay->addWidget(lab);
45 
46  QLineEdit *value = new QLineEdit;
47  value->setObjectName(QStringLiteral("value"));
48  connect(value, &QLineEdit::textChanged, this, &SieveConditionServerMetaDataExists::valueChanged);
49  lay->addWidget(value);
50 
51  return w;
52 }
53 
54 QString SieveConditionServerMetaDataExists::code(QWidget *w) const
55 {
56  const QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
57  const QString valueStr = value->text();
58  return QStringLiteral("servermetadataexists \"%1\"").arg(valueStr) + AutoCreateScriptUtil::generateConditionComment(comment());
59 }
60 
61 QStringList SieveConditionServerMetaDataExists::needRequires(QWidget *) const
62 {
63  return QStringList() << QStringLiteral("servermetadata");
64 }
65 
66 bool SieveConditionServerMetaDataExists::needCheckIfServerHasCapability() const
67 {
68  return true;
69 }
70 
71 QString SieveConditionServerMetaDataExists::serverNeedsCapability() const
72 {
73  return QStringLiteral("servermetadata");
74 }
75 
76 QString SieveConditionServerMetaDataExists::help() const
77 {
78  return i18n("The \"servermetadataexists\" test is true if all of the server annotations listed in the \"annotation-names\" argument exist.");
79 }
80 
81 void SieveConditionServerMetaDataExists::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error)
82 {
83  QString commentStr;
84  while (element.readNextStartElement()) {
85  const QStringRef tagName = element.name();
86  if (tagName == QLatin1String("str")) {
87  const QString tagValue = element.readElementText();
88  QLineEdit *value = w->findChild<QLineEdit *>(QStringLiteral("value"));
89  value->setText(tagValue);
90  } else if (tagName == QLatin1String("crlf")) {
91  element.skipCurrentElement();
92  //nothing
93  } else if (tagName == QLatin1String("comment")) {
94  commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
95  } else {
96  unknownTag(tagName, error);
97  qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaDataExists::setParamWidgetValue unknown tagName " << tagName;
98  }
99  }
100  if (!commentStr.isEmpty()) {
101  setComment(commentStr);
102  }
103 }
104 
105 QUrl SieveConditionServerMetaDataExists::href() const
106 {
107  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
108 }
bool readNextStartElement()
void setContentsMargins(int left, int top, int right, int bottom)
QString name(const QVariant &location)
void textChanged(const QString &text)
void skipCurrentElement()
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
void setLayout(QLayout *layout)
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
void setObjectName(const QString &name)
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-2020 The KDE developers.
Generated on Thu Jul 9 2020 23:07:44 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.