Libksieve

sieveconditionmailboxexists.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
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 <KLineEditEventHandler>
10#include <KLocalizedString>
11#include <QLineEdit>
12
13#include "libksieveui_debug.h"
14#include <QHBoxLayout>
15#include <QWidget>
16#include <QXmlStreamReader>
17
18using namespace KSieveUi;
19SieveConditionMailboxExists::SieveConditionMailboxExists(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
20 : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("mailboxexists"), i18n("Mailbox exists"), parent)
21{
22}
23
24QWidget *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;
33 connect(edit, &QLineEdit::textChanged, this, &SieveConditionMailboxExists::valueChanged);
34 edit->setClearButtonEnabled(true);
35 lay->addWidget(edit);
36 edit->setObjectName(QLatin1StringView("edit"));
37
38 return w;
39}
40
41QString 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
48QStringList SieveConditionMailboxExists::needRequires(QWidget *) const
49{
50 return QStringList() << QStringLiteral("mailbox");
51}
52
53bool SieveConditionMailboxExists::needCheckIfServerHasCapability() const
54{
55 return true;
56}
57
58QString SieveConditionMailboxExists::serverNeedsCapability() const
59{
60 return QStringLiteral("mailbox");
61}
62
63QString 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
70void SieveConditionMailboxExists::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error)
71{
72 QString commentStr;
73 while (element.readNextStartElement()) {
74 const QStringView tagName = element.name();
75 if (tagName == QLatin1StringView("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 == QLatin1StringView("crlf")) {
80 element.skipCurrentElement();
81 // nothing
82 } else if (tagName == QLatin1StringView("comment")) {
83 commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
84 } else {
85 unknownTag(tagName, error);
86 qCDebug(LIBKSIEVEUI_LOG) << " SieveConditionMailboxExists::setParamWidgetValue unknown tagName " << tagName;
87 }
88 }
89 if (!commentStr.isEmpty()) {
90 setComment(commentStr);
91 }
92}
93
94QUrl SieveConditionMailboxExists::href() const
95{
96 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
97}
98
99#include "moc_sieveconditionmailboxexists.cpp"
QString i18n(const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
QByteArray tagValue(const Elem &elem, const char *keyName)
void setContentsMargins(const QMargins &margins)
void textChanged(const QString &text)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T findChild(const QString &name, Qt::FindChildOptions options) const const
QObject * parent() const const
bool isEmpty() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void skipCurrentElement()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:19 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.