Libksieve

sieveconditionmailboxexists.cpp
1 /*
2  SPDX-FileCopyrightText: 2013-2021 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "sieveconditionmailboxexists.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 <QWidget>
16 #include <QXmlStreamReader>
17 
18 using namespace KSieveUi;
19 SieveConditionMailboxExists::SieveConditionMailboxExists(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20  : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("mailboxexists"), i18n("Mailbox exists"), parent)
21 {
22 }
23 
24 QWidget *SieveConditionMailboxExists::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 edit = new QLineEdit;
32  new KPIM::LineEditCatchReturnKey(edit, w);
33  connect(edit, &QLineEdit::textChanged, this, &SieveConditionMailboxExists::valueChanged);
34  edit->setClearButtonEnabled(true);
35  lay->addWidget(edit);
36  edit->setObjectName(QStringLiteral("edit"));
37 
38  return w;
39 }
40 
41 QString SieveConditionMailboxExists::code(QWidget *w) const
42 {
43  const QLineEdit *edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
44  const QString editValue = edit->text();
45  return QStringLiteral("mailboxexists \"%1\"").arg(editValue) + AutoCreateScriptUtil::generateConditionComment(comment());
46 }
47 
48 QStringList SieveConditionMailboxExists::needRequires(QWidget *) const
49 {
50  return QStringList() << QStringLiteral("mailbox");
51 }
52 
53 bool SieveConditionMailboxExists::needCheckIfServerHasCapability() const
54 {
55  return true;
56 }
57 
58 QString SieveConditionMailboxExists::serverNeedsCapability() const
59 {
60  return QStringLiteral("mailbox");
61 }
62 
63 QString SieveConditionMailboxExists::help() const
64 {
65  return i18n(
66  "The \"mailboxexists\" test is true if all mailboxes listed in the \"mailbox-names\" argument exist in the mailstore, and each allows the user in "
67  "whose context the Sieve script runs to \"deliver\" messages into it.");
68 }
69 
70 void SieveConditionMailboxExists::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 edit = w->findChild<QLineEdit *>(QStringLiteral("edit"));
78  edit->setText(AutoCreateScriptUtil::quoteStr(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) << " SieveConditionMailboxExists::setParamWidgetValue unknown tagName " << tagName;
87  }
88  }
89  if (!commentStr.isEmpty()) {
90  setComment(commentStr);
91  }
92 }
93 
94 QUrl SieveConditionMailboxExists::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 Sun Apr 11 2021 23:09:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.