6#include "sieveactionredirect.h"
7#include "autocreatescripts/autocreatescriptutil_p.h"
8#include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
9#include "editor/sieveeditorutil.h"
10#include "widgets/addresslineedit.h"
12#include <KLocalizedString>
14#include "libksieveui_debug.h"
17#include <QXmlStreamReader>
19using namespace KSieveUi;
21SieveActionRedirect::SieveActionRedirect(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget,
QObject *parent)
22 : SieveAction(sieveGraphicalModeWidget, QStringLiteral(
"redirect"),
i18n(
"Redirect"), parent)
28QWidget *SieveActionRedirect::createParamWidget(
QWidget *parent)
const
30 auto w =
new QWidget(
parent);
31 auto lay =
new QHBoxLayout;
32 lay->setContentsMargins({});
34 if (mHasCopySupport) {
35 auto copy =
new QCheckBox(
i18nc(
"@option:check",
"Keep a copy"));
40 if (mHasListSupport) {
41 auto list =
new QCheckBox(
i18nc(
"@option:check",
"Use list"));
42 list->setObjectName(QLatin1StringView(
"list"));
47 KSieveUi::AbstractSelectEmailLineEdit *edit = AutoCreateScriptUtil::createSelectEmailsWidget();
49 connect(edit, &AddressLineEdit::valueChanged,
this, &SieveActionRedirect::valueChanged);
54void SieveActionRedirect::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
57 const QStringView tagName = element.
name();
58 if (tagName == QLatin1StringView(
"str")) {
59 auto edit = w->
findChild<AbstractSelectEmailLineEdit *>(QStringLiteral(
"RedirectEdit"));
61 edit->setText(AutoCreateScriptUtil::quoteStr(tagValue));
62 }
else if (tagName == QLatin1StringView(
"tag")) {
64 if (tagValue == QLatin1StringView(
"copy")) {
65 if (mHasCopySupport) {
66 auto copy = w->
findChild<QCheckBox *>(QStringLiteral(
"copy"));
69 serverDoesNotSupportFeatures(QStringLiteral(
"copy"), error);
71 }
else if (tagValue == QLatin1StringView(
"list")) {
72 if (mHasListSupport) {
73 auto list = w->
findChild<QCheckBox *>(QStringLiteral(
"list"));
74 list->setChecked(
true);
76 serverDoesNotSupportFeatures(QStringLiteral(
"list"), error);
79 unknownTagValue(tagValue, error);
80 qCDebug(LIBKSIEVEUI_LOG) <<
" SieveActionRedirect::setParamWidgetValue tagValue unknown" <<
tagValue;
82 }
else if (tagName == QLatin1StringView(
"crlf")) {
85 }
else if (tagName == QLatin1StringView(
"comment")) {
89 unknownTag(tagName, error);
90 qCDebug(LIBKSIEVEUI_LOG) <<
" SieveActionRedirect::setParamWidgetValue unknown tagName " << tagName;
95QString SieveActionRedirect::code(QWidget *w)
const
97 QString result = QStringLiteral(
"redirect ");
98 const AbstractSelectEmailLineEdit *edit = w->
findChild<AbstractSelectEmailLineEdit *>(QStringLiteral(
"RedirectEdit"));
99 const QString text = edit->text();
101 if (mHasCopySupport) {
102 const QCheckBox *
copy = w->
findChild<QCheckBox *>(QStringLiteral(
"copy"));
104 result += QLatin1StringView(
":copy ");
108 if (mHasListSupport) {
109 const QCheckBox *
list = w->
findChild<QCheckBox *>(QStringLiteral(
"list"));
110 if (
list->isChecked()) {
111 result += QLatin1StringView(
":list ");
115 return result + QStringLiteral(
"\"%1\";").
arg(text);
118QStringList SieveActionRedirect::needRequires(QWidget *parent)
const
121 if (mHasCopySupport) {
122 const QCheckBox *
copy =
parent->findChild<QCheckBox *>(QStringLiteral(
"copy"));
124 lst << QStringLiteral(
"copy");
127 if (mHasListSupport) {
128 const QCheckBox *
list =
parent->findChild<QCheckBox *>(QStringLiteral(
"list"));
129 if (
list->isChecked()) {
130 lst << QStringLiteral(
"extlists");
136QString SieveActionRedirect::help()
const
138 QString helpStr =
i18n(
139 "The \"redirect\" action is used to send the message to another user at a supplied address, as a mail forwarding feature does. The \"redirect\" "
140 "action makes no changes to the message body or existing headers, but it may add new headers.");
141 if (mHasCopySupport) {
142 helpStr += QLatin1Char(
'\n')
143 +
i18n(
"If the optional \":copy\" keyword is specified, the tagged command does not cancel the implicit \"keep\". Instead, it redirects a copy in "
144 "addition to whatever else is happening to the message.");
150QUrl SieveActionRedirect::href()
const
152 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
155#include "moc_sieveactionredirect.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
QAction * copy(const QObject *recvr, const char *slot, QObject *parent)
QByteArray tagValue(const Elem &elem, const char *keyName)
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 arg(Args &&... args) const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void skipCurrentElement()