Libksieve

sieveactionbreak.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 "sieveactionbreak.h"
7#include "autocreatescripts/autocreatescriptutil_p.h"
8#include "editor/sieveeditorutil.h"
9
10#include <KLineEditEventHandler>
11#include <KLocalizedString>
12#include <QLineEdit>
13
14#include "libksieveui_debug.h"
15#include <QHBoxLayout>
16#include <QLabel>
17#include <QXmlStreamReader>
18
19using namespace KSieveUi;
20SieveActionBreak::SieveActionBreak(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
21 : SieveAction(sieveGraphicalModeWidget, QStringLiteral("break"), i18n("Break"), parent)
22{
23}
24
25QWidget *SieveActionBreak::createParamWidget(QWidget *parent) const
26{
27 auto w = new QWidget(parent);
28 auto lay = new QHBoxLayout;
29 lay->setContentsMargins({});
30 w->setLayout(lay);
31
32 auto lab = new QLabel(i18nc("@label:textbox", "Name (optional):"));
33 lay->addWidget(lab);
34
35 auto subject = new QLineEdit;
37 subject->setObjectName(QLatin1StringView("name"));
38 connect(subject, &QLineEdit::textChanged, this, &SieveActionBreak::valueChanged);
39 lay->addWidget(subject);
40 return w;
41}
42
43void SieveActionBreak::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
44{
45 while (element.readNextStartElement()) {
46 const QStringView tagName = element.name();
47 if (tagName == QLatin1StringView("tag")) {
48 const QString tagValue = element.readElementText();
49 if (tagValue == QLatin1StringView("name")) {
50 auto name = w->findChild<QLineEdit *>(QStringLiteral("name"));
51 name->setText(AutoCreateScriptUtil::strValue(element));
52 } else {
53 unknownTagValue(tagValue, error);
54 qCDebug(LIBKSIEVEUI_LOG) << " SieveActionBreak::setParamWidgetValue unknown tagValue " << tagValue;
55 }
56 } else if (tagName == QLatin1StringView("str")) {
57 element.skipCurrentElement();
58 // Nothing
59 } else if (tagName == QLatin1StringView("crlf")) {
60 element.skipCurrentElement();
61 // nothing
62 } else if (tagName == QLatin1StringView("comment")) {
63 element.skipCurrentElement();
64 // implement in the future ?
65 } else {
66 unknownTag(tagName, error);
67 qCDebug(LIBKSIEVEUI_LOG) << "SieveActionBreak::setParamWidgetValue unknown tag " << tagName;
68 }
69 }
70}
71
72QUrl SieveActionBreak::href() const
73{
74 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
75}
76
77QString SieveActionBreak::code(QWidget *w) const
78{
79 const QLineEdit *name = w->findChild<QLineEdit *>(QStringLiteral("name"));
80 const QString nameStr = name->text();
81 if (!nameStr.isEmpty()) {
82 return QStringLiteral("break :name \"%1\";").arg(nameStr);
83 }
84 return QStringLiteral("break;");
85}
86
87QString SieveActionBreak::help() const
88{
89 return i18n("The break command terminates the closest enclosing loop.");
90}
91
92QStringList SieveActionBreak::needRequires(QWidget * /*parent*/) const
93{
94 return QStringList() << QStringLiteral("foreverypart");
95}
96
97bool SieveActionBreak::needCheckIfServerHasCapability() const
98{
99 return true;
100}
101
102QString SieveActionBreak::serverNeedsCapability() const
103{
104 return QStringLiteral("foreverypart");
105}
106
107#include "moc_sieveactionbreak.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
QString name(StandardAction id)
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
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 Mon Nov 18 2024 12:14:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.