Libksieve

sieveconditionmailboxexists.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 "sieveconditionmailboxexists.h"
20 #include "autocreatescripts/autocreatescriptutil_p.h"
21 #include "editor/sieveeditorutil.h"
22 #include <KLocalizedString>
23 #include <QLineEdit>
24 
25 #include <QWidget>
26 #include <QHBoxLayout>
27 #include "libksieve_debug.h"
28 #include <QXmlStreamReader>
29 
30 using namespace KSieveUi;
31 SieveConditionMailboxExists::SieveConditionMailboxExists(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
32  : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("mailboxexists"), i18n("Mailbox exists"), parent)
33 {
34 }
35 
36 QWidget *SieveConditionMailboxExists::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  QLineEdit *edit = new QLineEdit;
44  connect(edit, &QLineEdit::textChanged, this, &SieveConditionMailboxExists::valueChanged);
45  edit->setClearButtonEnabled(true);
46  lay->addWidget(edit);
47  edit->setObjectName(QStringLiteral("edit"));
48 
49  return w;
50 }
51 
52 QString SieveConditionMailboxExists::code(QWidget *w) const
53 {
54  const QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
55  const QString editValue = edit->text();
56  return QStringLiteral("mailboxexists \"%1\"").arg(editValue) + AutoCreateScriptUtil::generateConditionComment(comment());
57 }
58 
59 QStringList SieveConditionMailboxExists::needRequires(QWidget *) const
60 {
61  return QStringList() << QStringLiteral("mailbox");
62 }
63 
64 bool SieveConditionMailboxExists::needCheckIfServerHasCapability() const
65 {
66  return true;
67 }
68 
69 QString SieveConditionMailboxExists::serverNeedsCapability() const
70 {
71  return QStringLiteral("mailbox");
72 }
73 
74 QString SieveConditionMailboxExists::help() const
75 {
76  return i18n(
77  "The \"mailboxexists\" test is true if all mailboxes listed in the \"mailbox-names\" argument exist in the mailstore, and each allows the user in whose context the Sieve script runs to \"deliver\" messages into it.");
78 }
79 
80 void SieveConditionMailboxExists::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error)
81 {
82  QString commentStr;
83  while (element.readNextStartElement()) {
84  const QStringRef tagName = element.name();
85  if (tagName == QLatin1String("str")) {
86  const QString tagValue = element.readElementText();
87  QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
88  edit->setText(AutoCreateScriptUtil::quoteStr(tagValue));
89  } else if (tagName == QLatin1String("crlf")) {
90  element.skipCurrentElement();
91  //nothing
92  } else if (tagName == QLatin1String("comment")) {
93  commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
94  } else {
95  unknownTag(tagName, error);
96  qCDebug(LIBKSIEVE_LOG) << " SieveConditionMailboxExists::setParamWidgetValue unknown tagName " << tagName;
97  }
98  }
99  if (!commentStr.isEmpty()) {
100  setComment(commentStr);
101  }
102 }
103 
104 QUrl SieveConditionMailboxExists::href() const
105 {
106  return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
107 }
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)
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 Mon Jul 13 2020 23:08:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.