Libksieve

sieveconditionihave.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 "sieveconditionihave.h"
20 #include "autocreatescripts/autocreatescriptutil_p.h"
21 #include "editor/sieveeditorutil.h"
22 
23 #include <KLocalizedString>
24 #include <QLineEdit>
25 
26 #include <QWidget>
27 #include <QHBoxLayout>
28 #include "libksieve_debug.h"
29 #include <QXmlStreamReader>
30 
31 using namespace KSieveUi;
32 SieveConditionIhave::SieveConditionIhave(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
33  : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("ihave"), i18n("IHave"), parent)
34 {
35 }
36 
37 QWidget *SieveConditionIhave::createParamWidget(QWidget *parent) const
38 {
39  QWidget *w = new QWidget(parent);
40  QHBoxLayout *lay = new QHBoxLayout;
41  lay->setContentsMargins(0, 0, 0, 0);
42  w->setLayout(lay);
43 
44  QLineEdit *edit = new QLineEdit;
45  connect(edit, &QLineEdit::textChanged, this, &SieveConditionIhave::valueChanged);
46  edit->setPlaceholderText(i18n("Use \",\" to separate capabilities"));
47  edit->setClearButtonEnabled(true);
48  lay->addWidget(edit);
49  edit->setObjectName(QStringLiteral("edit"));
50 
51  return w;
52 }
53 
54 QString SieveConditionIhave::code(QWidget *w) const
55 {
56  const QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
57  const QString editValue = edit->text();
58  return QStringLiteral("ihave %1").arg(AutoCreateScriptUtil::createList(editValue, QLatin1Char(',')))
59  + AutoCreateScriptUtil::generateConditionComment(comment());
60 }
61 
62 QStringList SieveConditionIhave::needRequires(QWidget *) const
63 {
64  return QStringList() << QStringLiteral("ihave");
65 }
66 
67 bool SieveConditionIhave::needCheckIfServerHasCapability() const
68 {
69  return true;
70 }
71 
72 QString SieveConditionIhave::serverNeedsCapability() const
73 {
74  return QStringLiteral("ihave");
75 }
76 
77 QString SieveConditionIhave::help() const
78 {
79  return i18n("The \"ihave\" test provides a means for Sieve scripts to test for the existence of a given extension prior to actually using it.");
80 }
81 
82 void SieveConditionIhave::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool, QString &error)
83 {
84  QString commentStr;
85  while (element.readNextStartElement()) {
86  const QStringRef tagName = element.name();
87  if (tagName == QLatin1String("str")) {
88  const QString tagValue = element.readElementText();
89  QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
90  edit->setText(tagValue);
91  } else if (tagName == QLatin1String("crlf")) {
92  element.skipCurrentElement();
93  //nothing
94  } else if (tagName == QLatin1String("comment")) {
95  commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
96  } else {
97  unknownTag(tagName, error);
98  qCDebug(LIBKSIEVE_LOG) << " SieveConditionIhave::setParamWidgetValue unknown tagName " << tagName;
99  }
100  }
101  if (!commentStr.isEmpty()) {
102  setComment(commentStr);
103  }
104 }
105 
106 QUrl SieveConditionIhave::href() const
107 {
108  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
109 }
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
void setClearButtonEnabled(bool enable)
void setPlaceholderText(const QString &)
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 Tue Aug 4 2020 23:07:29 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.