6#include "sieveactionreplace.h"
7#include "autocreatescripts/autocreatescriptutil_p.h"
8#include "editor/sieveeditorutil.h"
9#include "widgets/multilineedit.h"
11#include <KLineEditEventHandler>
12#include <KLocalizedString>
15#include "libksieveui_debug.h"
18#include <QXmlStreamReader>
20#include <KSieveUi/AbstractSelectEmailLineEdit>
22using namespace KSieveUi;
23SieveActionReplace::SieveActionReplace(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget,
QObject *parent)
24 : SieveAction(sieveGraphicalModeWidget, QStringLiteral(
"replace"),
i18n(
"Replace"), parent)
28QWidget *SieveActionReplace::createParamWidget(
QWidget *parent)
const
30 auto w =
new QWidget(
parent);
31 auto grid =
new QGridLayout;
32 grid->setContentsMargins({});
35 auto lab =
new QLabel(
i18nc(
"@label:textbox",
"Subject:"));
36 grid->addWidget(lab, 0, 0);
38 auto subject =
new QLineEdit;
40 subject->setObjectName(QLatin1StringView(
"subject"));
42 grid->addWidget(subject, 0, 1);
44 lab =
new QLabel(
i18nc(
"@label:textbox",
"from:"));
45 grid->addWidget(lab, 1, 0);
47 KSieveUi::AbstractSelectEmailLineEdit *headers = AutoCreateScriptUtil::createSelectEmailsWidget();
49 connect(headers, &AbstractSelectEmailLineEdit::valueChanged,
this, &SieveActionReplace::valueChanged);
50 grid->addWidget(headers, 1, 1);
52 lab =
new QLabel(
i18nc(
"@label:textbox",
"text:"));
53 grid->addWidget(lab, 2, 0);
55 auto text =
new MultiLineEdit;
56 text->setObjectName(QLatin1StringView(
"text"));
58 grid->addWidget(text, 2, 1);
63void SieveActionReplace::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
66 const QStringView tagName = element.
name();
67 if (tagName == QLatin1StringView(
"str")) {
68 auto edit = w->
findChild<MultiLineEdit *>(QStringLiteral(
"text"));
70 }
else if (tagName == QLatin1StringView(
"tag")) {
72 if (tagValue == QLatin1StringView(
"subject")) {
73 const QString strValue = AutoCreateScriptUtil::strValue(element);
75 auto subject = w->
findChild<QLineEdit *>(QStringLiteral(
"subject"));
76 subject->setText(strValue);
78 }
else if (tagValue == QLatin1StringView(
"from")) {
79 const QString strValue = AutoCreateScriptUtil::strValue(element);
81 auto headers = w->
findChild<KSieveUi::AbstractSelectEmailLineEdit *>(QStringLiteral(
"from"));
82 headers->setText(strValue);
85 unknownTagValue(tagValue, error);
86 qCDebug(LIBKSIEVEUI_LOG) <<
" SieveActionReplace::setParamWidgetValue unknown tagValue " <<
tagValue;
88 }
else if (tagName == QLatin1StringView(
"crlf")) {
91 }
else if (tagName == QLatin1StringView(
"comment")) {
95 unknownTag(tagName, error);
96 qCDebug(LIBKSIEVEUI_LOG) <<
" SieveActionReplace::setParamWidgetValue unknown tagName " << tagName;
101QString SieveActionReplace::code(QWidget *w)
const
103 QString result = QStringLiteral(
"replace ");
104 const QLineEdit *subject = w->
findChild<QLineEdit *>(QStringLiteral(
"subject"));
105 const QString subjectStr = subject->
text();
106 if (!subjectStr.isEmpty()) {
107 result += QStringLiteral(
":subject \"%1\" ").
arg(subjectStr);
110 const KSieveUi::AbstractSelectEmailLineEdit *headers = w->
findChild<KSieveUi::AbstractSelectEmailLineEdit *>(QStringLiteral(
"from"));
111 const QString headersStr = headers->text();
112 if (!headersStr.isEmpty()) {
113 result += QStringLiteral(
":from \"%1\" ").
arg(headersStr);
116 const MultiLineEdit *edit = w->
findChild<MultiLineEdit *>(QStringLiteral(
"text"));
118 if (!text.isEmpty()) {
119 result += QStringLiteral(
"text:%1").
arg(AutoCreateScriptUtil::createMultiLine(text));
125QStringList SieveActionReplace::needRequires(QWidget *)
const
127 return QStringList() << QStringLiteral(
"replace");
130bool SieveActionReplace::needCheckIfServerHasCapability()
const
135QString SieveActionReplace::serverNeedsCapability()
const
137 return QStringLiteral(
"replace");
140QString SieveActionReplace::help()
const
142 return i18n(
"The \"replace\" command is defined to allow a MIME part to be replaced with the text supplied in the command.");
145QUrl SieveActionReplace::href()
const
147 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
150#include "moc_sieveactionreplace.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
void catchReturnKey(QObject *lineEdit)
QByteArray tagValue(const Elem &elem, const char *keyName)
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
void setObjectName(QAnyStringView name)
QString toPlainText() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void skipCurrentElement()