8#include "filteractionaddheader.h"
12#include <KLocalizedString>
20FilterActionAddHeader::FilterActionAddHeader(
QObject *parent)
23 mParameterList <<
QString() << QStringLiteral(
"Reply-To") << QStringLiteral(
"Delivered-To") << QStringLiteral(
"X-KDE-PR-Message")
24 << QStringLiteral(
"X-KDE-PR-Package") << QStringLiteral(
"X-KDE-PR-Keywords");
26 mParameter = mParameterList.at(0);
29bool FilterActionAddHeader::isEmpty()
const
31 return mParameter.isEmpty() || mValue.isEmpty();
42 KMime::Headers::Base *header = KMime::Headers::createHeader(mParameter.toLatin1());
44 header =
new KMime::Headers::Generic(mParameter.toLatin1().constData());
46 header->fromUnicodeString(mValue);
48 msg->setHeader(header);
56QWidget *FilterActionAddHeader::createParamWidget(QWidget *parent)
const
58 auto widget =
new QWidget(
parent);
59 auto layout =
new QHBoxLayout(widget);
60 layout->setSpacing(4);
61 layout->setContentsMargins({});
63 auto comboBox =
new KComboBox(widget);
64 comboBox->setMinimumWidth(50);
65 comboBox->setObjectName(QLatin1StringView(
"combo"));
66 comboBox->setEditable(
true);
69 KCompletion *comp = comboBox->completionObject();
74 layout->addWidget(comboBox, 0 );
76 auto label =
new QLabel(
i18nc(
"@label:textbox",
"With value:"), widget);
77 label->setObjectName(QLatin1StringView(
"label_value"));
78 label->setFixedWidth(
label->sizeHint().width());
79 layout->addWidget(
label, 0);
81 auto lineEdit =
new KLineEdit(widget);
82 lineEdit->setObjectName(QLatin1StringView(
"ledit"));
83 lineEdit->setTrapReturnKey(
true);
84 lineEdit->setClearButtonEnabled(
true);
85 layout->addWidget(lineEdit, 1);
87 setParamWidgetValue(widget);
95void FilterActionAddHeader::setParamWidgetValue(QWidget *paramWidget)
const
97 const int index = mParameterList.indexOf(mParameter);
99 const auto comboBox = paramWidget->
findChild<KComboBox *>(QStringLiteral(
"combo"));
102 comboBox->addItems(mParameterList);
105 comboBox->addItem(mParameter);
106 comboBox->setCurrentIndex(comboBox->count() - 1);
108 comboBox->setCurrentIndex(index);
111 auto lineEdit = paramWidget->
findChild<QLineEdit *>(QStringLiteral(
"ledit"));
114 lineEdit->setText(mValue);
117void FilterActionAddHeader::applyParamWidgetValue(QWidget *paramWidget)
119 const auto comboBox = paramWidget->
findChild<KComboBox *>(QStringLiteral(
"combo"));
121 mParameter = comboBox->currentText();
123 const QLineEdit *lineEdit = paramWidget->
findChild<QLineEdit *>(QStringLiteral(
"ledit"));
125 mValue = lineEdit->
text();
128void FilterActionAddHeader::clearParamWidget(QWidget *paramWidget)
const
130 const auto comboBox = paramWidget->
findChild<KComboBox *>(QStringLiteral(
"combo"));
132 comboBox->setCurrentIndex(0);
134 auto lineEdit = paramWidget->
findChild<QLineEdit *>(QStringLiteral(
"ledit"));
144QString FilterActionAddHeader::argsAsString()
const
146 QString result = mParameter;
147 result += QLatin1Char(
'\t');
153QString FilterActionAddHeader::displayString()
const
155 return label() + QStringLiteral(
" \"") + argsAsString().
toHtmlEscaped() + QStringLiteral(
"\"");
158void FilterActionAddHeader::argsFromString(
const QString &argsStr)
160 const QStringList
list = argsStr.
split(QLatin1Char(
'\t'));
170 int index = mParameterList.indexOf(result);
172 mParameterList.append(result);
173 index = mParameterList.count() - 1;
176 mParameter = mParameterList.at(index);
181 return new FilterActionAddHeader;
184QStringList FilterActionAddHeader::sieveRequires()
const
186 return QStringList() << QStringLiteral(
"editheader");
189QString FilterActionAddHeader::sieveCode()
const
192 return QStringLiteral(
"# invalid filter. Need to fix it by hand");
194 return QStringLiteral(
"addheader \"%1\" \"%2\";").arg(mParameter, mValue);
198QString FilterActionAddHeader::informationAboutNotValidAction()
const
201 if (mParameter.isEmpty()) {
202 result =
i18n(
"The header name was missing.");
204 if (mValue.isEmpty()) {
206 result += QLatin1Char(
'\n');
208 result +=
i18n(
"The header value was missing.");
211 result =
name() + QLatin1Char(
'\n') + result;
216#include "moc_filteractionaddheader.cpp"
void insertItems(const QStringList &items)
virtual void setCompletionMode(CompletionMode mode)
virtual void setIgnoreCase(bool ignoreCase)
QSharedPointer< Message > Ptr
Abstract base class for filter actions with a fixed set of string parameters.
Abstract base class for mail filter actions.
QString name() const
Returns identifier name, ie.
ReturnCode
Describes the possible return codes of filter processing:
@ ErrorButGoOn
A non-critical error occurred.
@ GoOn
Go on with applying filter actions.
void filterActionModified()
Called to notify that the current FilterAction has had some value modification.
QString label() const
Returns i18n'd label, ie.
A helper class for the filtering process.
void setNeedsPayloadStore()
Marks that the item's payload has been changed and needs to be written back.
Akonadi::Item & item()
Returns the item of the context.
RequiredPart
Possible required parts.
@ CompleteMessage
Whole message.
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)
void currentIndexChanged(int index)
void textChanged(const QString &text)
qsizetype count() const const
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
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString toHtmlEscaped() const const