6#include "sieveactionvacation.h"
7#include "autocreatescripts/autocreatescriptutil_p.h"
8#include "autocreatescripts/sieveeditorgraphicalmodewidget.h"
9#include "editor/sieveeditorutil.h"
10#include "widgets/multilineedit.h"
11#include "widgets/selectvacationcombobox.h"
13#include <KLineEditEventHandler>
14#include <KLocalizedString>
17#include "libksieveui_debug.h"
18#include <KSieveUi/AbstractSelectEmailLineEdit>
22#include <QXmlStreamReader>
24using namespace KSieveUi;
26SieveActionVacation::SieveActionVacation(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget,
QObject *parent)
27 : SieveAction(sieveGraphicalModeWidget, QStringLiteral(
"vacation"),
i18n(
"Vacation"), parent)
29 mHasVacationSecondsSupport = sieveCapabilities().contains(
QLatin1StringView(
"vacation-seconds"));
32QWidget *SieveActionVacation::createParamWidget(
QWidget *parent)
const
34 auto w =
new QWidget(
parent);
35 auto grid =
new QGridLayout;
36 grid->setContentsMargins({});
39 QLabel *lab =
nullptr;
40 if (mHasVacationSecondsSupport) {
41 auto vacation =
new SelectVacationComboBox;
42 vacation->setObjectName(QLatin1StringView(
"vacationcombobox"));
43 connect(vacation, &SelectVacationComboBox::valueChanged,
this, &SieveActionVacation::valueChanged);
44 grid->addWidget(vacation, 0, 0);
46 lab =
new QLabel(
i18nc(
"@label:textbox",
"day:"));
47 grid->addWidget(lab, 0, 0);
50 auto day =
new QSpinBox;
53 day->setObjectName(QLatin1StringView(
"day"));
55 grid->addWidget(day, 0, 1);
57 lab =
new QLabel(
i18nc(
"@label:textbox",
"Message subject:"));
58 grid->addWidget(lab, 1, 0);
60 auto subject =
new QLineEdit;
62 subject->setObjectName(QLatin1StringView(
"subject"));
64 grid->addWidget(subject, 1, 1);
66 lab =
new QLabel(
i18nc(
"@label:textbox",
"Additional email:"));
67 grid->addWidget(lab, 2, 0);
69 AbstractSelectEmailLineEdit *addresses = AutoCreateScriptUtil::createSelectEmailsWidget();
71 addresses->setMultiSelection(
true);
72 connect(addresses, &AbstractSelectEmailLineEdit::valueChanged,
this, &SieveActionVacation::valueChanged);
73 grid->addWidget(addresses, 2, 1);
75 lab =
new QLabel(
i18nc(
"@label:textbox",
"Vacation reason:"));
76 grid->addWidget(lab, 3, 0);
78 auto text =
new MultiLineEdit;
79 connect(text, &MultiLineEdit::valueChanged,
this, &SieveActionVacation::valueChanged);
80 text->setObjectName(QLatin1StringView(
"text"));
81 grid->addWidget(text, 3, 1);
86void SieveActionVacation::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
89 const QStringView tagName = element.
name();
90 if (tagName == QLatin1StringView(
"tag")) {
92 if (tagValue == QLatin1StringView(
"seconds")) {
93 if (mHasVacationSecondsSupport) {
94 auto vacationcombobox = w->
findChild<SelectVacationComboBox *>(QStringLiteral(
"vacationcombobox"));
95 vacationcombobox->setCode(AutoCreateScriptUtil::tagValue(tagValue), name(), error);
97 serverDoesNotSupportFeatures(QStringLiteral(
"seconds"), error);
99 }
else if (tagValue == QLatin1StringView(
"days")) {
101 }
else if (tagValue == QLatin1StringView(
"addresses")) {
102 auto addresses = w->
findChild<AbstractSelectEmailLineEdit *>(QStringLiteral(
"addresses"));
104 const QStringView textElementTagName = element.
name();
105 if (textElementTagName == QLatin1StringView(
"str")) {
107 }
else if (textElementTagName == QLatin1StringView(
"list")) {
108 addresses->setText(AutoCreateScriptUtil::listValueToStr(element));
111 }
else if (tagValue == QLatin1StringView(
"subject")) {
112 auto subject = w->
findChild<QLineEdit *>(QStringLiteral(
"subject"));
113 subject->setText(AutoCreateScriptUtil::strValue(element));
115 unknownTagValue(tagValue, error);
116 qCDebug(LIBKSIEVEUI_LOG) <<
"SieveActionVacation::setParamWidgetValue unknown tagValue :" <<
tagValue;
118 }
else if (tagName == QLatin1StringView(
"num")) {
119 auto day = w->
findChild<QSpinBox *>(QStringLiteral(
"day"));
121 }
else if (tagName == QLatin1StringView(
"str")) {
122 auto text = w->
findChild<MultiLineEdit *>(QStringLiteral(
"text"));
124 }
else if (tagName == QLatin1StringView(
"crlf")) {
127 }
else if (tagName == QLatin1StringView(
"comment")) {
131 unknownTag(tagName, error);
132 qCDebug(LIBKSIEVEUI_LOG) <<
" SieveActionVacation::setParamWidgetValue unknown tagName " << tagName;
137QString SieveActionVacation::code(QWidget *w)
const
139 QString vacationTypeStr = QStringLiteral(
":days");
140 if (mHasVacationSecondsSupport) {
141 const SelectVacationComboBox *vacationcombobox = w->
findChild<SelectVacationComboBox *>(QStringLiteral(
"vacationcombobox"));
142 vacationTypeStr = vacationcombobox->code();
144 const QSpinBox *day = w->
findChild<QSpinBox *>(QStringLiteral(
"day"));
147 const MultiLineEdit *text = w->
findChild<MultiLineEdit *>(QStringLiteral(
"text"));
150 const QLineEdit *subject = w->
findChild<QLineEdit *>(QStringLiteral(
"subject"));
151 const QString subjectStr = subject->
text();
153 const AbstractSelectEmailLineEdit *addresses = w->
findChild<AbstractSelectEmailLineEdit *>(QStringLiteral(
"addresses"));
154 const QString addressesStr = addresses->text();
155 QString result = QStringLiteral(
"vacation");
156 if (!dayStr.isEmpty()) {
157 result += QStringLiteral(
" %1 %2").
arg(vacationTypeStr, dayStr);
159 if (!subjectStr.isEmpty()) {
160 result += QStringLiteral(
" :subject \"%1\"").
arg(subjectStr);
162 if (!addressesStr.isEmpty()) {
163 result += QStringLiteral(
" :addresses %1").
arg(AutoCreateScriptUtil::createAddressList(addressesStr,
false));
165 if (!textStr.isEmpty()) {
166 result += QStringLiteral(
" text:%1").
arg(AutoCreateScriptUtil::createMultiLine(textStr));
168 result += QLatin1Char(
';');
173QString SieveActionVacation::serverNeedsCapability()
const
175 return QStringLiteral(
"vacation");
178bool SieveActionVacation::needCheckIfServerHasCapability()
const
183QStringList SieveActionVacation::needRequires(QWidget *)
const
186 if (mHasVacationSecondsSupport) {
187 lst << QStringLiteral(
"vacation-seconds");
189 lst << QStringLiteral(
"vacation");
193QString SieveActionVacation::help()
const
195 QString helpStr =
i18n(
196 "The \"vacation\" action implements a vacation autoresponder similar to the vacation command available under many versions of Unix. Its purpose is to "
197 "provide correspondents with notification that the user is away for an extended period of time and that they should not expect quick responses.");
198 if (mHasVacationSecondsSupport) {
199 helpStr = QLatin1Char(
'\n')
200 +
i18n(
"Through the \":days\" parameter, it limits the number of auto-replies to the same sender to one per [n] days, for a specified number of "
201 "days. But there are cases when one needs more granularity, if one would like to generate \"vacation\" replies more frequently.");
202 helpStr += QLatin1Char(
'\n') +
i18n(
"This extension defines a \":seconds\" parameter to provide more granularity for such situations.");
207QUrl SieveActionVacation::href()
const
209 return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name()));
212#include "moc_sieveactionvacation.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
QString number(double n, char format, int precision)
int toInt(bool *ok, int base) const const
QStringView name() const const
QString readElementText(ReadElementTextBehaviour behaviour)
bool readNextStartElement()
void skipCurrentElement()