diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveaction.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveaction.cpp index 5ed9878..9003f4d 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveaction.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveaction.cpp @@ -1,150 +1,150 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveaction.h" #include "libksieve_debug.h" #include #include #include #include "autocreatescripts/sieveeditorgraphicalmodewidget.h" using namespace KSieveUi; SieveAction::SieveAction(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent) : QObject(parent) , mSieveGraphicalModeWidget(sieveGraphicalModeWidget) , mName(name) , mLabel(label) { } SieveAction::~SieveAction() { } KSieveUi::SieveImapAccountSettings SieveAction::sieveImapAccountSettings() const { if (mSieveGraphicalModeWidget) { return mSieveGraphicalModeWidget->sieveImapAccountSettings(); } qCWarning(LIBKSIEVE_LOG) << "SieveAction::sieveImapAccountSettings Problem during initialize mSieveGraphicalModeWidget "; return {}; } QStringList SieveAction::listOfIncludeFile() const { if (mSieveGraphicalModeWidget) { return mSieveGraphicalModeWidget->listOfIncludeFile(); } qCWarning(LIBKSIEVE_LOG) << "SieveAction::listOfIncludeFile Problem during initialize mSieveGraphicalModeWidget "; return {}; } QStringList SieveAction::sieveCapabilities() const { if (mSieveGraphicalModeWidget) { return mSieveGraphicalModeWidget->sieveCapabilities(); } qCWarning(LIBKSIEVE_LOG) << "SieveAction::sieveCapabilities Problem during initialize mSieveGraphicalModeWidget "; return {}; } QString SieveAction::name() const { return mName; } QString SieveAction::label() const { return mLabel; } QWidget *SieveAction::createParamWidget(QWidget *parent) const { return new QWidget(parent); } QString SieveAction::code(QWidget *) const { return QString(); } QStringList SieveAction::needRequires(QWidget *parent) const { Q_UNUSED(parent); return QStringList(); } bool SieveAction::needCheckIfServerHasCapability() const { return false; } QString SieveAction::serverNeedsCapability() const { return QString(); } QString SieveAction::help() const { return QString(); } bool SieveAction::setParamWidgetValue(QXmlStreamReader &n, QWidget *, QString &) { n.skipCurrentElement(); return true; } QString SieveAction::comment() const { return mComment; } void SieveAction::setComment(const QString &comment) { mComment = comment; } void SieveAction::unknownTag(const QStringRef &tag, QString &error) { error += i18n("An unknown tag \"%1\" was found during parsing action \"%2\".", *tag.string(), name()) + QLatin1Char('\n'); } void SieveAction::unknownTagValue(const QString &tagValue, QString &error) { error += i18n("An unknown tag value \"%1\" was found during parsing action \"%2\".", tagValue, name()) + QLatin1Char('\n'); } -void SieveAction::tooManyArgument(const QStringRef &tagName, int index, int maxValue, QString &error) +void SieveAction::tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error) { error += i18n("Too many argument found for \"%1\", max value is %2, number of value found %3 for %4", name(), maxValue, index, *tagName.string()) + QLatin1Char('\n'); } void SieveAction::serverDoesNotSupportFeatures(const QString &feature, QString &error) { error += i18n("A feature \"%1\" in condition \"%2\" is not supported by server", feature, name()) + QLatin1Char('\n'); } QUrl SieveAction::href() const { return QUrl(); } diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveaction.h b/src/ksieveui/autocreatescripts/sieveactions/sieveaction.h index 9a70404..65f82ba 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveaction.h +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveaction.h @@ -1,79 +1,79 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SIEVEACTION_H #define SIEVEACTION_H #include #include class QXmlStreamReader; namespace KSieveUi { class SieveImapAccountSettings; class SieveEditorGraphicalModeWidget; class SieveAction : public QObject { Q_OBJECT public: SieveAction(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = nullptr); ~SieveAction() override; Q_REQUIRED_RESULT QString name() const; Q_REQUIRED_RESULT QString label() const; Q_REQUIRED_RESULT virtual QWidget *createParamWidget(QWidget *parent) const; Q_REQUIRED_RESULT virtual bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error); Q_REQUIRED_RESULT virtual QString code(QWidget *) const; Q_REQUIRED_RESULT virtual QStringList needRequires(QWidget *parent) const; Q_REQUIRED_RESULT virtual bool needCheckIfServerHasCapability() const; Q_REQUIRED_RESULT virtual QString serverNeedsCapability() const; Q_REQUIRED_RESULT virtual QString help() const; Q_REQUIRED_RESULT virtual QUrl href() const; Q_REQUIRED_RESULT QString comment() const; void setComment(const QString &comment); void unknownTag(const QStringRef &tag, QString &error); void unknownTagValue(const QString &tagValue, QString &error); - void tooManyArgument(const QStringRef &tagName, int index, int maxValue, QString &error); + void tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error); void serverDoesNotSupportFeatures(const QString &feature, QString &error); protected: Q_REQUIRED_RESULT SieveImapAccountSettings sieveImapAccountSettings() const; Q_REQUIRED_RESULT QStringList listOfIncludeFile() const; Q_REQUIRED_RESULT QStringList sieveCapabilities() const; SieveEditorGraphicalModeWidget *mSieveGraphicalModeWidget = nullptr; Q_SIGNALS: void valueChanged(); private: Q_DISABLE_COPY(SieveAction) QString mName; QString mLabel; QString mComment; }; } #endif // SIEVEACTION_H diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveactionaddheader.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactionaddheader.cpp index d7da213..3e6db24 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactionaddheader.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactionaddheader.cpp @@ -1,131 +1,131 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveactionaddheader.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "widgets/selectaddheaderpositioncombobox.h" #include #include #include #include #include #include "libksieve_debug.h" #include using namespace KSieveUi; SieveActionAddHeader::SieveActionAddHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveActionAbstractEditHeader(sieveGraphicalModeWidget, QStringLiteral("addheader"), i18n("Add header"), parent) { } QWidget *SieveActionAddHeader::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); w->setLayout(grid); SelectAddHeaderPositionCombobox *combo = new SelectAddHeaderPositionCombobox; combo->setObjectName(QStringLiteral("selectposition")); connect(combo, &SelectAddHeaderPositionCombobox::valueChanged, this, &SieveActionAddHeader::valueChanged); grid->addWidget(combo, 0, 0); QLabel *lab = new QLabel(i18n("header:")); grid->addWidget(lab, 0, 1); QLineEdit *headerEdit = new QLineEdit; connect(headerEdit, &QLineEdit::textChanged, this, &SieveActionAddHeader::valueChanged); headerEdit->setObjectName(QStringLiteral("headeredit")); grid->addWidget(headerEdit, 0, 2); lab = new QLabel(i18n("value:")); grid->addWidget(lab, 1, 1); QLineEdit *valueEdit = new QLineEdit; connect(valueEdit, &QLineEdit::textChanged, this, &SieveActionAddHeader::valueChanged); valueEdit->setObjectName(QStringLiteral("valueedit")); grid->addWidget(valueEdit, 1, 2); return w; } bool SieveActionAddHeader::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { int index = 0; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { SelectAddHeaderPositionCombobox *combo = w->findChild(QStringLiteral("selectposition")); combo->setCode(AutoCreateScriptUtil::tagValue(element.readElementText()), name(), error); } else if (tagName == QLatin1String("str")) { if (index == 0) { QLineEdit *edit = w->findChild(QStringLiteral("headeredit")); edit->setText(element.readElementText()); } else if (index == 1) { QLineEdit *value = w->findChild(QStringLiteral("valueedit")); value->setText(AutoCreateScriptUtil::quoteStr(element.readElementText())); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionAddHeader::setParamWidgetValue too many argument :" << index; } ++index; } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { element.skipCurrentElement(); //implement in the future ? } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << "SieveActionAddHeader::setParamWidgetValue unknown tag " << tagName; } } return true; } QString SieveActionAddHeader::code(QWidget *w) const { const SelectAddHeaderPositionCombobox *combo = w->findChild(QStringLiteral("selectposition")); const QString position = combo->code(); const QLineEdit *edit = w->findChild(QStringLiteral("headeredit")); const QString headerStr = edit->text(); const QLineEdit *value = w->findChild(QStringLiteral("valueedit")); const QString valueStr = value->text(); if (position.isEmpty()) { return QStringLiteral("addheader \"%1\" \"%2\";").arg(headerStr, valueStr); } else { return QStringLiteral("addheader %1 \"%2\" \"%3\";").arg(position, headerStr, valueStr); } } QString SieveActionAddHeader::help() const { return i18n("The addheader action adds a header field to the existing message header."); } QUrl SieveActionAddHeader::href() const { return QUrl(QStringLiteral("https://tools.ietf.org/html/rfc5293")); } diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveactionconvert.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactionconvert.cpp index 1d033bc..3b09244 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactionconvert.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactionconvert.cpp @@ -1,149 +1,149 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveactionconvert.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "autocreatescripts/commonwidgets/selectconvertparameterwidget.h" #include "autocreatescripts/commonwidgets/selectmimetypecombobox.h" #include #include #include "libksieve_debug.h" #include #include using namespace KSieveUi; SieveActionConvert::SieveActionConvert(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveAction(sieveGraphicalModeWidget, QStringLiteral("convert"), i18n("Convert"), parent) { } QWidget *SieveActionConvert::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QGridLayout *lay = new QGridLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); QLabel *lab = new QLabel(i18n("From:")); lay->addWidget(lab, 0, 0); SelectMimeTypeComboBox *fromMimeType = new SelectMimeTypeComboBox; connect(fromMimeType, &SelectMimeTypeComboBox::valueChanged, this, &SieveActionConvert::valueChanged); fromMimeType->setObjectName(QStringLiteral("from")); lay->addWidget(fromMimeType, 0, 1); lab = new QLabel(i18n("To:")); lay->addWidget(lab, 0, 2); SelectMimeTypeComboBox *toMimeType = new SelectMimeTypeComboBox; connect(toMimeType, &SelectMimeTypeComboBox::valueChanged, this, &SieveActionConvert::valueChanged); toMimeType->setObjectName(QStringLiteral("to")); lay->addWidget(toMimeType, 0, 3); lab = new QLabel(i18n("Parameters:")); lay->addWidget(lab, 1, 0); SelectConvertParameterWidget *params = new SelectConvertParameterWidget; connect(params, &SelectConvertParameterWidget::valueChanged, this, &SieveActionConvert::valueChanged); params->setObjectName(QStringLiteral("params")); lay->addWidget(params, 1, 1, 2, 3); return w; } bool SieveActionConvert::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { int index = 0; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { if (index == 0) { SelectMimeTypeComboBox *fromMimeType = w->findChild(QStringLiteral("from")); fromMimeType->setCode(element.readElementText(), name(), error); } else if (index == 1) { SelectMimeTypeComboBox *toMimeType = w->findChild(QStringLiteral("to")); toMimeType->setCode(element.readElementText(), name(), error); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionConvert::setParamWidgetValue too many argument :" << index; } ++index; } else if (tagName == QLatin1String("list")) { SelectConvertParameterWidget *params = w->findChild(QStringLiteral("params")); params->setCode(AutoCreateScriptUtil::listValue(element), error); } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { element.skipCurrentElement(); //implement in the future ? } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << "SieveActionConvert::setParamWidgetValue unknown tag " << tagName; } } return true; } QString SieveActionConvert::code(QWidget *w) const { QString result = QStringLiteral("convert "); const SelectMimeTypeComboBox *fromMimeType = w->findChild(QStringLiteral("from")); const QString fromMimeTypeStr = fromMimeType->code(); result += QStringLiteral("%1 ").arg(fromMimeTypeStr); const SelectMimeTypeComboBox *toMimeType = w->findChild(QStringLiteral("to")); const QString toMimeTypeStr = toMimeType->code(); result += QStringLiteral("%1 ").arg(toMimeTypeStr); const SelectConvertParameterWidget *params = w->findChild(QStringLiteral("params")); const QString paramsStr = params->code(); if (!paramsStr.isEmpty()) { result += paramsStr; } result += QLatin1Char(';'); return result; } QStringList SieveActionConvert::needRequires(QWidget *) const { return QStringList() << QStringLiteral("convert"); } bool SieveActionConvert::needCheckIfServerHasCapability() const { return true; } QString SieveActionConvert::serverNeedsCapability() const { return QStringLiteral("convert"); } QString SieveActionConvert::help() const { return i18n("The \"convert\" action specifies that all body parts with a media type equal to \"media-type\" be converted to the media type in \"media-type\" using conversion parameters."); } QUrl SieveActionConvert::href() const { return QUrl(QStringLiteral("https://tools.ietf.org/html/draft-ietf-sieve-convert-06")); } diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveactiondeleteheader.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactiondeleteheader.cpp index 5008fe3..d056ff7 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactiondeleteheader.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactiondeleteheader.cpp @@ -1,148 +1,148 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveactiondeleteheader.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "editor/sieveeditorutil.h" #include #include #include #include #include #include "libksieve_debug.h" #include using namespace KSieveUi; SieveActionDeleteHeader::SieveActionDeleteHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveActionAbstractEditHeader(sieveGraphicalModeWidget, QStringLiteral("deleteheader"), i18n("Delete header"), parent) { } QWidget *SieveActionDeleteHeader::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); w->setLayout(grid); SelectMatchTypeComboBox *matchType = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); matchType->setObjectName(QStringLiteral("matchtype")); connect(matchType, &SelectMatchTypeComboBox::valueChanged, this, &SieveActionDeleteHeader::valueChanged); grid->addWidget(matchType, 0, 0); QLabel *lab = new QLabel(i18n("header:")); grid->addWidget(lab, 0, 1); QLineEdit *headerEdit = new QLineEdit; headerEdit->setObjectName(QStringLiteral("headeredit")); connect(headerEdit, &QLineEdit::textChanged, this, &SieveActionDeleteHeader::valueChanged); grid->addWidget(headerEdit, 0, 2); lab = new QLabel(i18n("value:")); grid->addWidget(lab, 1, 1); QLineEdit *valueEdit = new QLineEdit; valueEdit->setObjectName(QStringLiteral("valueedit")); connect(valueEdit, &QLineEdit::textChanged, this, &SieveActionDeleteHeader::valueChanged); grid->addWidget(valueEdit, 1, 2); return w; } bool SieveActionDeleteHeader::parseValue(QXmlStreamReader &element, QWidget *w, QString &error, bool isNegative) { int index = 0; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("test")) { QString nameValue; if (element.attributes().hasAttribute(QLatin1String("name"))) { nameValue = element.attributes().value(QLatin1String("name")).toString(); } const bool isNegative = (nameValue == QLatin1String("not")); bool result = parseValue(element, w, error, isNegative); element.skipCurrentElement(); return result; } else if (tagName == QLatin1String("tag")) { SelectMatchTypeComboBox *combo = w->findChild(QStringLiteral("matchtype")); combo->setCode(AutoCreateScriptUtil::tagValueWithCondition(element.readElementText(), isNegative), name(), error); } else if (tagName == QLatin1String("str")) { if (index == 0) { QLineEdit *edit = w->findChild(QStringLiteral("headeredit")); edit->setText(element.readElementText()); } else if (index == 1) { QLineEdit *value = w->findChild(QStringLiteral("valueedit")); value->setText(element.readElementText()); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionAddHeader::setParamWidgetValue too many argument :" << index; } ++index; } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { element.skipCurrentElement(); //implement in the future ? } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << "SieveActionAddHeader::setParamWidgetValue unknown tag " << tagName; } } return true; } bool SieveActionDeleteHeader::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { return parseValue(element, w, error, false); } QString SieveActionDeleteHeader::code(QWidget *w) const { const SelectMatchTypeComboBox *combo = w->findChild(QStringLiteral("matchtype")); bool isNegative = false; const QString matchTypeStr = combo->code(isNegative); const QLineEdit *edit = w->findChild(QStringLiteral("headeredit")); const QString headerStr = edit->text(); const QLineEdit *value = w->findChild(QStringLiteral("valueedit")); const QString valueStr = value->text(); return QStringLiteral("deleteheader %1 \"%2\" \"%3\";").arg((isNegative ? QLatin1String("not ") + matchTypeStr : matchTypeStr), headerStr, valueStr); } QString SieveActionDeleteHeader::help() const { return i18n("By default, the deleteheader action deletes all occurrences of the named header field."); } QUrl SieveActionDeleteHeader::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } QStringList SieveActionDeleteHeader::needRequires(QWidget *w) const { const SelectMatchTypeComboBox *combo = w->findChild(QStringLiteral("matchtype")); return SieveActionAbstractEditHeader::needRequires(w) + combo->needRequires(); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.cpp index 7b80d8b..b62a552 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.cpp @@ -1,144 +1,144 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sievecondition.h" #include "autocreatescripts/sieveeditorgraphicalmodewidget.h" #include #include using namespace KSieveUi; SieveCondition::SieveCondition(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent) : QObject(parent) , mSieveGraphicalModeWidget(sieveGraphicalModeWidget) , mName(name) , mLabel(label) { } SieveCondition::~SieveCondition() { } QStringList SieveCondition::sieveCapabilities() const { if (mSieveGraphicalModeWidget) { return mSieveGraphicalModeWidget->sieveCapabilities(); } return {}; } QString SieveCondition::name() const { return mName; } QString SieveCondition::label() const { return mLabel; } SieveCondition *SieveCondition::newAction() { return nullptr; } QWidget *SieveCondition::createParamWidget(QWidget *parent) const { return new QWidget(parent); } QString SieveCondition::code(QWidget *parent) const { Q_UNUSED(parent); return QString(); } QStringList SieveCondition::needRequires(QWidget *parent) const { Q_UNUSED(parent); return QStringList(); } bool SieveCondition::needCheckIfServerHasCapability() const { return false; } QString SieveCondition::serverNeedsCapability() const { return QString(); } QString SieveCondition::help() const { return QString(); } bool SieveCondition::setParamWidgetValue(QXmlStreamReader & /*element*/, QWidget * /*parent*/, bool /*notCondition*/, QString & /*error*/) { return true; } void SieveCondition::unknownTag(const QStringRef &tag, QString &error) { error += i18n("Unknown tag \"%1\" during parsing condition \"%2\"", *tag.string(), name()) + QLatin1Char('\n'); } void SieveCondition::unknownTagValue(const QString &tagValue, QString &error) { error += i18n("An unknown tag value \"%1\" was found during parsing condition \"%2\".", tagValue, name()) + QLatin1Char('\n'); } -void SieveCondition::tooManyArgument(const QString &tagName, int index, int maxValue, QString &error) +void SieveCondition::tooManyArguments(const QString &tagName, int index, int maxValue, QString &error) { error += i18n("Too many argument found for \"%1\", max value is %2, number of value found %3 for %4", name(), maxValue, (index + 1), tagName) + QLatin1Char('\n'); } -void SieveCondition::tooManyArgument(const QStringRef &tagName, int index, int maxValue, QString &error) +void SieveCondition::tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error) { - tooManyArgument(tagName.toString(), index, maxValue, error); + tooManyArguments(tagName.toString(), index, maxValue, error); } void SieveCondition::serverDoesNotSupportFeatures(const QString &feature, QString &error) { error += i18n("A feature \"%1\" in condition \"%2\" is not supported by server", feature, name()) + QLatin1Char('\n'); } QUrl SieveCondition::href() const { return QUrl(); } QString SieveCondition::comment() const { return mComment; } void SieveCondition::setComment(const QString &comment) { mComment = comment; } QString SieveCondition::generateComment() const { return {}; } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.h b/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.h index 746d45f..4448aca 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.h +++ b/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.h @@ -1,85 +1,85 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef SIEVECONDITION_H #define SIEVECONDITION_H #include #include class QXmlStreamReader; namespace KSieveUi { class SieveEditorGraphicalModeWidget; class SieveCondition : public QObject { Q_OBJECT public: SieveCondition(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = nullptr); ~SieveCondition() override; QString name() const; QString label() const; /** * Static function that creates a filter action of this type. */ static SieveCondition *newAction(); Q_REQUIRED_RESULT virtual QWidget *createParamWidget(QWidget *parent) const; Q_REQUIRED_RESULT virtual QString code(QWidget *parent) const; Q_REQUIRED_RESULT virtual QStringList needRequires(QWidget *parent) const; Q_REQUIRED_RESULT virtual bool needCheckIfServerHasCapability() const; Q_REQUIRED_RESULT virtual QString serverNeedsCapability() const; Q_REQUIRED_RESULT virtual QString help() const; Q_REQUIRED_RESULT virtual QUrl href() const; Q_REQUIRED_RESULT virtual bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, bool notCondition, QString &error); void unknownTag(const QStringRef &tag, QString &error); void unknownTagValue(const QString &tagValue, QString &error); - void tooManyArgument(const QStringRef &tagName, int index, int maxValue, QString &error); - void tooManyArgument(const QString &tagName, int index, int maxValue, QString &error); + void tooManyArguments(const QStringRef &tagName, int index, int maxValue, QString &error); + void tooManyArguments(const QString &tagName, int index, int maxValue, QString &error); void serverDoesNotSupportFeatures(const QString &feature, QString &error); QString comment() const; void setComment(const QString &comment); QString generateComment() const; protected: QStringList sieveCapabilities() const; SieveEditorGraphicalModeWidget *mSieveGraphicalModeWidget = nullptr; Q_SIGNALS: void valueChanged(); private: Q_DISABLE_COPY(SieveCondition) QString mName; QString mLabel; QString mComment; }; } #endif // SIEVECONDITION_H diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionaddress.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionaddress.cpp index bc8abdb..44c0f97 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionaddress.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionaddress.cpp @@ -1,189 +1,189 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionaddress.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "widgets/selectaddresspartcombobox.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "widgets/selectheadertypecombobox.h" #include "editor/sieveeditorutil.h" #include #include #include #include "libksieve_debug.h" #include using namespace KSieveUi; SieveConditionAddress::SieveConditionAddress(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("address"), i18n("Address"), parent) { } QWidget *SieveConditionAddress::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectAddressPartComboBox *selectAddressPart = new SelectAddressPartComboBox(mSieveGraphicalModeWidget); connect(selectAddressPart, &SelectAddressPartComboBox::valueChanged, this, &SieveConditionAddress::valueChanged); selectAddressPart->setObjectName(QStringLiteral("addresspartcombobox")); lay->addWidget(selectAddressPart); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); lay->addLayout(grid); SelectMatchTypeComboBox *selectMatchCombobox = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); connect(selectMatchCombobox, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionAddress::valueChanged); selectMatchCombobox->setObjectName(QStringLiteral("matchtypecombobox")); grid->addWidget(selectMatchCombobox, 0, 0); SelectHeaderTypeComboBox *selectHeaderType = new SelectHeaderTypeComboBox(true); connect(selectHeaderType, &SelectHeaderTypeComboBox::valueChanged, this, &SieveConditionAddress::valueChanged); selectHeaderType->setObjectName(QStringLiteral("headertypecombobox")); grid->addWidget(selectHeaderType, 0, 1); QLabel *lab = new QLabel(i18n("address:")); grid->addWidget(lab, 1, 0); AbstractRegexpEditorLineEdit *edit = AutoCreateScriptUtil::createRegexpEditorLineEdit(); connect(edit, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionAddress::valueChanged); connect(selectMatchCombobox, &SelectMatchTypeComboBox::switchToRegexp, edit, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit); edit->setClearButtonEnabled(true); edit->setPlaceholderText(i18n("Use ; to separate emails")); grid->addWidget(edit, 1, 1); edit->setObjectName(QStringLiteral("editaddress")); return w; } QString SieveConditionAddress::code(QWidget *w) const { const SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); bool isNegative = false; const QString matchTypeStr = selectMatchCombobox->code(isNegative); const SelectAddressPartComboBox *selectAddressPart = w->findChild(QStringLiteral("addresspartcombobox")); const QString selectAddressPartStr = selectAddressPart->code(); const SelectHeaderTypeComboBox *selectHeaderType = w->findChild(QStringLiteral("headertypecombobox")); const QString selectHeaderTypeStr = selectHeaderType->code(); const AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("editaddress")); const QString addressStr = AutoCreateScriptUtil::createAddressList(edit->code().trimmed(), false); return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("address %1 %2 %3 %4").arg(selectAddressPartStr, matchTypeStr, selectHeaderTypeStr, addressStr) + AutoCreateScriptUtil::generateConditionComment(comment()); } QStringList SieveConditionAddress::needRequires(QWidget *w) const { const SelectAddressPartComboBox *selectAddressPart = w->findChild(QStringLiteral("addresspartcombobox")); const SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); return selectAddressPart->extraRequire() + selectMatchCombobox->needRequires(); } QString SieveConditionAddress::help() const { return i18n( "The \"address\" test matches Internet addresses in structured headers that contain addresses. It returns true if any header contains any key in the specified part of the address, as modified by the comparator and the match keyword."); } bool SieveConditionAddress::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) { int index = 0; int indexStr = 0; QStringList lstTagValue; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { lstTagValue << element.readElementText(); ++index; } else if (tagName == QLatin1String("str")) { if (indexStr == 0) { SelectHeaderTypeComboBox *selectHeaderType = w->findChild(QStringLiteral("headertypecombobox")); selectHeaderType->setCode(element.readElementText()); } else if (indexStr == 1) { AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("editaddress")); edit->setCode(AutoCreateScriptUtil::quoteStr(element.readElementText())); } else { - tooManyArgument(tagName, indexStr, 2, error); + tooManyArguments(tagName, indexStr, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionAddress::setParamWidgetValue too many argument :" << index; } ++indexStr; } else if (tagName == QLatin1String("list")) { if (indexStr == 0) { SelectHeaderTypeComboBox *selectHeaderType = w->findChild(QStringLiteral("headertypecombobox")); selectHeaderType->setCode(AutoCreateScriptUtil::listValueToStr(element)); } else if (indexStr == 1) { AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("editaddress")); edit->setCode(AutoCreateScriptUtil::listValueToStr(element)); } else { - tooManyArgument(tagName, indexStr, 2, error); + tooManyArguments(tagName, indexStr, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionAddress::setParamWidgetValue too many argument :" << index; } ++indexStr; } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionAddress::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } if (lstTagValue.count() == 1) { QString specificError; SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(lstTagValue.at(0), notCondition), name(), specificError); if (!specificError.isEmpty()) { //Test if default match type == is SelectAddressPartComboBox *selectAddressPart = w->findChild(QStringLiteral("addresspartcombobox")); selectAddressPart->setCode(AutoCreateScriptUtil::tagValue(lstTagValue.at(0)), name(), error); } } else if (lstTagValue.count() == 2) { QString errorStr; SelectAddressPartComboBox *selectAddressPart = w->findChild(QStringLiteral("addresspartcombobox")); selectAddressPart->setCode(AutoCreateScriptUtil::tagValue(lstTagValue.at(0)), name(), errorStr); if (errorStr.isEmpty()) { SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(lstTagValue.at(1), notCondition), name(), error); } else { //Problem with order SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(lstTagValue.at(0), notCondition), name(), error); selectAddressPart->setCode(AutoCreateScriptUtil::tagValue(lstTagValue.at(1)), name(), error); } } else if (lstTagValue.count() > 2) { - tooManyArgument(QStringLiteral("tag"), lstTagValue.count(), 2, error); + tooManyArguments(QStringLiteral("tag"), lstTagValue.count(), 2, error); qCDebug(LIBKSIEVE_LOG) << "SieveConditionAddress::setParamWidgetValue too many argument :" << lstTagValue.count(); } return true; } QUrl SieveConditionAddress::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionbody.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionbody.cpp index e38d503..d65a155 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionbody.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionbody.cpp @@ -1,181 +1,181 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionbody.h" #include "widgets/selectbodytypewidget.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "editor/sieveeditorutil.h" #include #include #include #include "libksieve_debug.h" using namespace KSieveUi; SieveConditionBody::SieveConditionBody(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("body"), i18n("Body"), parent) { } QWidget *SieveConditionBody::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectBodyTypeWidget *bodyType = new SelectBodyTypeWidget; bodyType->setObjectName(QStringLiteral("bodytype")); connect(bodyType, &SelectBodyTypeWidget::valueChanged, this, &SieveConditionBody::valueChanged); lay->addWidget(bodyType); SelectMatchTypeComboBox *matchType = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); lay->addWidget(matchType); matchType->setObjectName(QStringLiteral("matchtype")); connect(matchType, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionBody::valueChanged); AbstractRegexpEditorLineEdit *edit = AutoCreateScriptUtil::createRegexpEditorLineEdit(); connect(edit, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionBody::valueChanged); connect(matchType, &SelectMatchTypeComboBox::switchToRegexp, edit, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit); edit->setClearButtonEnabled(true); lay->addWidget(edit); edit->setObjectName(QStringLiteral("edit")); return w; } QString SieveConditionBody::code(QWidget *w) const { const SelectBodyTypeWidget *bodyType = w->findChild(QStringLiteral("bodytype")); const QString bodyValue = bodyType->code(); const SelectMatchTypeComboBox *matchType = w->findChild(QStringLiteral("matchtype")); bool isNegative = false; const QString matchValue = matchType->code(isNegative); const AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("edit")); const QString editValue = AutoCreateScriptUtil::createAddressList(edit->code().trimmed(), false); return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("body %1 %2 %3").arg(bodyValue, matchValue, editValue) + AutoCreateScriptUtil::generateConditionComment(comment()); } QStringList SieveConditionBody::needRequires(QWidget *w) const { const SelectMatchTypeComboBox *matchType = w->findChild(QStringLiteral("matchtype")); return QStringList() << QStringLiteral("body") << matchType->needRequires(); } bool SieveConditionBody::needCheckIfServerHasCapability() const { return true; } QString SieveConditionBody::serverNeedsCapability() const { return QStringLiteral("body"); } QString SieveConditionBody::help() const { return i18n( "The body test matches content in the body of an email message, that is, anything following the first empty line after the header. (The empty line itself, if present, is not considered to be part of the body.)"); } bool SieveConditionBody::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) { int index = 0; int indexStr = 0; QStringList tagValueList; QStringList strValue; bool wasListElement = false; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (index == 0) { tagValueList << AutoCreateScriptUtil::tagValue(tagValue); } else if (index == 1) { tagValueList << AutoCreateScriptUtil::tagValueWithCondition(tagValue, notCondition); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionBody::setParamWidgetValue too many argument " << index; } ++index; } else if (tagName == QLatin1String("str")) { strValue << element.readElementText(); ++indexStr; } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else if (tagName == QLatin1String("list")) { strValue << AutoCreateScriptUtil::listValueToStr(element); wasListElement = true; ++indexStr; } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionBody::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } QString errorStr; if (strValue.count() == 1) { SelectBodyTypeWidget *bodyType = w->findChild(QStringLiteral("bodytype")); bodyType->setCode(tagValueList.at(0), QString(), name(), errorStr); if (errorStr.isEmpty()) { SelectMatchTypeComboBox *matchType = w->findChild(QStringLiteral("matchtype")); matchType->setCode(tagValueList.at(1), name(), error); } else { SelectMatchTypeComboBox *matchType = w->findChild(QStringLiteral("matchtype")); if (tagValueList.count() == 1) { matchType->setCode(tagValueList.at(0), name(), error); } else if (tagValueList.count() == 2) { matchType->setCode(tagValueList.at(0), name(), error); bodyType->setCode(tagValueList.at(1), QString(), name(), errorStr); } } AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("edit")); edit->setCode(wasListElement ? strValue.at(0) : AutoCreateScriptUtil::quoteStr(strValue.at(0))); } else if (strValue.count() == 2) { SelectBodyTypeWidget *bodyType = w->findChild(QStringLiteral("bodytype")); bodyType->setCode(tagValueList.at(0), indexStr == 2 ? strValue.at(0) : QString(), name(), errorStr); SelectMatchTypeComboBox *matchType = w->findChild(QStringLiteral("matchtype")); if (!errorStr.isEmpty()) { matchType->setCode(tagValueList.at(0), name(), error); bodyType->setCode(tagValueList.at(1), indexStr == 2 ? strValue.at(0) : QString(), name(), error); } else { matchType->setCode(tagValueList.at(1), name(), error); } AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("edit")); edit->setCode(indexStr == 1 ? AutoCreateScriptUtil::quoteStr(strValue.at(0)) : AutoCreateScriptUtil::quoteStr(strValue.at(1))); } return true; } QUrl SieveConditionBody::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionconvert.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionconvert.cpp index 12678e7..bfb4ff7 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionconvert.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionconvert.cpp @@ -1,144 +1,144 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionconvert.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "autocreatescripts/commonwidgets/selectconvertparameterwidget.h" #include "autocreatescripts/commonwidgets/selectmimetypecombobox.h" #include #include #include #include "libksieve_debug.h" #include using namespace KSieveUi; SieveConditionConvert::SieveConditionConvert(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("convert"), i18n("Convert"), parent) { } QWidget *SieveConditionConvert::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QGridLayout *lay = new QGridLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); QLabel *lab = new QLabel(i18n("From:")); lay->addWidget(lab, 0, 0); SelectMimeTypeComboBox *fromMimeType = new SelectMimeTypeComboBox; fromMimeType->setObjectName(QStringLiteral("from")); connect(fromMimeType, &SelectMimeTypeComboBox::valueChanged, this, &SieveConditionConvert::valueChanged); lay->addWidget(fromMimeType, 0, 1); lab = new QLabel(i18n("To:")); lay->addWidget(lab, 0, 2); SelectMimeTypeComboBox *toMimeType = new SelectMimeTypeComboBox; connect(toMimeType, &SelectMimeTypeComboBox::valueChanged, this, &SieveConditionConvert::valueChanged); toMimeType->setObjectName(QStringLiteral("to")); lay->addWidget(toMimeType, 0, 3); lab = new QLabel(i18n("Parameters:")); lay->addWidget(lab, 1, 0); SelectConvertParameterWidget *params = new SelectConvertParameterWidget; connect(params, &SelectConvertParameterWidget::valueChanged, this, &SieveConditionConvert::valueChanged); params->setObjectName(QStringLiteral("params")); lay->addWidget(params, 1, 1, 2, 3); return w; } QString SieveConditionConvert::code(QWidget *w) const { QString result = QStringLiteral("convert "); const SelectMimeTypeComboBox *fromMimeType = w->findChild(QStringLiteral("from")); const QString fromMimeTypeStr = fromMimeType->code(); result += QStringLiteral("%1 ").arg(fromMimeTypeStr); const SelectMimeTypeComboBox *toMimeType = w->findChild(QStringLiteral("to")); const QString toMimeTypeStr = toMimeType->code(); result += QStringLiteral("%1 ").arg(toMimeTypeStr); const SelectConvertParameterWidget *params = w->findChild(QStringLiteral("params")); const QString paramsStr = params->code(); if (!paramsStr.isEmpty()) { result += paramsStr; } return result + AutoCreateScriptUtil::generateConditionComment(comment()); } QStringList SieveConditionConvert::needRequires(QWidget *) const { return QStringList() << QStringLiteral("convert"); } bool SieveConditionConvert::needCheckIfServerHasCapability() const { return true; } QString SieveConditionConvert::serverNeedsCapability() const { return QStringLiteral("convert"); } QString SieveConditionConvert::help() const { return i18n("The \"convert\" action specifies that all body parts with a media type equal to \"media-type\" be converted to the media type in \"media-type\" using conversion parameters."); } bool SieveConditionConvert::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error) { int index = 0; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { if (index == 0) { SelectMimeTypeComboBox *fromMimeType = w->findChild(QStringLiteral("from")); fromMimeType->setCode(element.readElementText(), name(), error); } else if (index == 1) { SelectMimeTypeComboBox *toMimeType = w->findChild(QStringLiteral("to")); toMimeType->setCode(element.readElementText(), name(), error); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionConvert::setParamWidgetValue too many argument :" << index; } ++index; } else if (tagName == QLatin1String("list")) { SelectConvertParameterWidget *params = w->findChild(QStringLiteral("params")); params->setCode(AutoCreateScriptUtil::listValue(element), error); } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << "SieveActionConvert::setParamWidgetValue unknown tag " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditioncurrentdate.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditioncurrentdate.cpp index 6d7dd97..40c9e90 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditioncurrentdate.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditioncurrentdate.cpp @@ -1,137 +1,137 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditioncurrentdate.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "widgets/selectdatewidget.h" #include "editor/sieveeditorutil.h" #include #include #include #include "libksieve_debug.h" using namespace KSieveUi; SieveConditionCurrentDate::SieveConditionCurrentDate(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("currentdate"), i18n("Currentdate"), parent) { } QWidget *SieveConditionCurrentDate::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectMatchTypeComboBox *matchTypeCombo = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); matchTypeCombo->setObjectName(QStringLiteral("matchtype")); lay->addWidget(matchTypeCombo); connect(matchTypeCombo, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionCurrentDate::valueChanged); SelectDateWidget *dateWidget = new SelectDateWidget; connect(dateWidget, &SelectDateWidget::valueChanged, this, &SieveConditionCurrentDate::valueChanged); dateWidget->setObjectName(QStringLiteral("datewidget")); lay->addWidget(dateWidget); return w; } QString SieveConditionCurrentDate::code(QWidget *w) const { const SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtype")); bool isNegative = false; const QString matchTypeStr = selectMatchCombobox->code(isNegative); const SelectDateWidget *dateWidget = w->findChild(QStringLiteral("datewidget")); const QString dateWidgetStr = dateWidget->code(); return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("currentdate %1 %2").arg(matchTypeStr, dateWidgetStr) + AutoCreateScriptUtil::generateConditionComment(comment()); } bool SieveConditionCurrentDate::needCheckIfServerHasCapability() const { return true; } QString SieveConditionCurrentDate::serverNeedsCapability() const { return QStringLiteral("date"); } QStringList SieveConditionCurrentDate::needRequires(QWidget *w) const { const SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtype")); return QStringList() << QStringLiteral("date") << selectMatchCombobox->needRequires(); } QString SieveConditionCurrentDate::help() const { return i18n("The currentdate test is similar to the date test, except that it operates on the current date/time rather than a value extracted from the message header."); } bool SieveConditionCurrentDate::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) { int index = 0; QString type; QString value; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { if (index == 0) { type = element.readElementText(); } else if (index == 1) { value = element.readElementText(); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionCurrentDate::setParamWidgetValue too many argument :" << index; } ++index; } else if (tagName == QLatin1String("tag")) { SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtype")); selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(element.readElementText(), notCondition), name(), error); } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << "SieveConditionCurrentDate::setParamWidgetValue unknown tag " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } SelectDateWidget *dateWidget = w->findChild(QStringLiteral("datewidget")); dateWidget->setCode(type, value); return true; } QUrl SieveConditionCurrentDate::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditiondate.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditiondate.cpp index f41b8f2..559557f 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditiondate.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditiondate.cpp @@ -1,156 +1,156 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditiondate.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "widgets/selectdatewidget.h" #include "editor/sieveeditorutil.h" #include #include #include #include #include "libksieve_debug.h" using namespace KSieveUi; SieveConditionDate::SieveConditionDate(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("date"), i18n("Date"), parent) { } QWidget *SieveConditionDate::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectMatchTypeComboBox *matchTypeCombo = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); matchTypeCombo->setObjectName(QStringLiteral("matchtype")); connect(matchTypeCombo, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionDate::valueChanged); lay->addWidget(matchTypeCombo); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); lay->addLayout(grid); QLabel *lab = new QLabel(i18n("header:")); grid->addWidget(lab, 0, 0); QLineEdit *header = new QLineEdit; connect(header, &QLineEdit::textChanged, this, &SieveConditionDate::valueChanged); header->setObjectName(QStringLiteral("header")); grid->addWidget(header, 0, 1); SelectDateWidget *dateWidget = new SelectDateWidget; connect(dateWidget, &SelectDateWidget::valueChanged, this, &SieveConditionDate::valueChanged); dateWidget->setObjectName(QStringLiteral("datewidget")); grid->addWidget(dateWidget, 1, 0, 1, 2); return w; } QString SieveConditionDate::code(QWidget *w) const { const SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtype")); bool isNegative = false; const QString matchTypeStr = selectMatchCombobox->code(isNegative); const QLineEdit *header = w->findChild(QStringLiteral("header")); const QString headerStr = header->text(); const SelectDateWidget *dateWidget = w->findChild(QStringLiteral("datewidget")); const QString dateWidgetStr = dateWidget->code(); return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("date %1 \"%2\" %3").arg(matchTypeStr, headerStr, dateWidgetStr) + AutoCreateScriptUtil::generateConditionComment(comment()); } bool SieveConditionDate::needCheckIfServerHasCapability() const { return true; } QString SieveConditionDate::serverNeedsCapability() const { return QStringLiteral("date"); } QStringList SieveConditionDate::needRequires(QWidget *w) const { const SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtype")); return QStringList() << QStringLiteral("date") << selectMatchCombobox->needRequires(); } QString SieveConditionDate::help() const { return i18n("The date test matches date/time information derived from headers containing date-time values."); } bool SieveConditionDate::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) { int index = 0; QString type; QString value; QString headerStr; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { if (index == 0) { headerStr = element.readElementText(); } else if (index == 1) { type = element.readElementText(); } else if (index == 2) { value = element.readElementText(); } else { - tooManyArgument(tagName, index, 3, error); + tooManyArguments(tagName, index, 3, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionDate::setParamWidgetValue too many argument :" << index; } ++index; } else if (tagName == QLatin1String("tag")) { SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtype")); selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(element.readElementText(), notCondition), name(), error); } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << "SieveConditionDate::setParamWidgetValue unknown tag " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } SelectDateWidget *dateWidget = w->findChild(QStringLiteral("datewidget")); dateWidget->setCode(type, value); QLineEdit *header = w->findChild(QStringLiteral("header")); header->setText(headerStr); return true; } QUrl SieveConditionDate::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvelope.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvelope.cpp index b316d65..a9f0c00 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvelope.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvelope.cpp @@ -1,189 +1,189 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionenvelope.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "widgets/selectaddresspartcombobox.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "widgets/selectheadertypecombobox.h" #include "editor/sieveeditorutil.h" #include #include #include #include "libksieve_debug.h" #include using namespace KSieveUi; SieveConditionEnvelope::SieveConditionEnvelope(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("envelope"), i18n("Envelope"), parent) { } QWidget *SieveConditionEnvelope::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectAddressPartComboBox *selectAddressPart = new SelectAddressPartComboBox(mSieveGraphicalModeWidget); connect(selectAddressPart, &SelectAddressPartComboBox::valueChanged, this, &SieveConditionEnvelope::valueChanged); selectAddressPart->setObjectName(QStringLiteral("addresspartcombobox")); lay->addWidget(selectAddressPart); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); lay->addLayout(grid); SelectMatchTypeComboBox *selectMatchCombobox = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); selectMatchCombobox->setObjectName(QStringLiteral("matchtypecombobox")); connect(selectMatchCombobox, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionEnvelope::valueChanged); grid->addWidget(selectMatchCombobox, 0, 0); SelectHeaderTypeComboBox *selectHeaderType = new SelectHeaderTypeComboBox(true); selectHeaderType->setObjectName(QStringLiteral("headertypecombobox")); connect(selectHeaderType, &SelectHeaderTypeComboBox::valueChanged, this, &SieveConditionEnvelope::valueChanged); grid->addWidget(selectHeaderType, 0, 1); QLabel *lab = new QLabel(i18n("address:")); grid->addWidget(lab, 1, 0); AbstractRegexpEditorLineEdit *edit = AutoCreateScriptUtil::createRegexpEditorLineEdit(); edit->setObjectName(QStringLiteral("editaddress")); connect(edit, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionEnvelope::valueChanged); connect(selectMatchCombobox, &SelectMatchTypeComboBox::switchToRegexp, edit, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit); edit->setClearButtonEnabled(true); edit->setPlaceholderText(i18n("Use ; to separate emails")); grid->addWidget(edit, 1, 1); return w; } QString SieveConditionEnvelope::code(QWidget *w) const { const SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); bool isNegative = false; const QString matchTypeStr = selectMatchCombobox->code(isNegative); const SelectAddressPartComboBox *selectAddressPart = w->findChild(QStringLiteral("addresspartcombobox")); const QString selectAddressPartStr = selectAddressPart->code(); const SelectHeaderTypeComboBox *selectHeaderType = w->findChild(QStringLiteral("headertypecombobox")); const QString selectHeaderTypeStr = selectHeaderType->code(); const AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("editaddress")); const QString addressStr = AutoCreateScriptUtil::createAddressList(edit->code().trimmed(), false); return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("envelope %1 %2 %3 %4").arg(selectAddressPartStr, matchTypeStr, selectHeaderTypeStr, addressStr) + AutoCreateScriptUtil::generateConditionComment(comment()); } QStringList SieveConditionEnvelope::needRequires(QWidget *w) const { const SelectAddressPartComboBox *selectAddressPart = w->findChild(QStringLiteral("addresspartcombobox")); const SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); return QStringList() << QStringLiteral("envelope") << selectAddressPart->extraRequire() << selectMatchCombobox->needRequires(); } bool SieveConditionEnvelope::needCheckIfServerHasCapability() const { return true; } QString SieveConditionEnvelope::serverNeedsCapability() const { return QStringLiteral("envelope"); } QString SieveConditionEnvelope::help() const { return i18n("The \"envelope\" test is true if the specified part of the [SMTP] (or equivalent) envelope matches the specified key."); } bool SieveConditionEnvelope::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) { int indexTag = 0; int indexStr = 0; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (indexTag == 0) { QString err; SelectAddressPartComboBox *selectAddressPart = w->findChild(QStringLiteral("addresspartcombobox")); selectAddressPart->setCode(AutoCreateScriptUtil::tagValue(tagValue), name(), err); //all: is default sometime we don't add it. if (!err.isEmpty()) { SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(tagValue, notCondition), name(), error); } } else if (indexTag == 1) { SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(tagValue, notCondition), name(), error); } else { - tooManyArgument(tagName, indexTag, 2, error); + tooManyArguments(tagName, indexTag, 2, error); qCDebug(LIBKSIEVE_LOG) << "SieveConditionEnvelope::setParamWidgetValue too many argument :" << indexTag; } ++indexTag; } else if (tagName == QLatin1String("str")) { if (indexStr == 0) { SelectHeaderTypeComboBox *selectHeaderType = w->findChild(QStringLiteral("headertypecombobox")); selectHeaderType->setCode(element.readElementText()); } else if (indexStr == 1) { AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("editaddress")); edit->setCode(AutoCreateScriptUtil::quoteStr(element.readElementText())); } else { - tooManyArgument(tagName, indexStr, 2, error); + tooManyArguments(tagName, indexStr, 2, error); qCDebug(LIBKSIEVE_LOG) << "SieveConditionEnvelope::setParamWidgetValue too many argument indexStr " << indexStr; } ++indexStr; } else if (tagName == QLatin1String("list")) { if (indexStr == 0) { SelectHeaderTypeComboBox *selectHeaderType = w->findChild(QStringLiteral("headertypecombobox")); selectHeaderType->setCode(AutoCreateScriptUtil::listValueToStr(element)); } else if (indexStr == 1) { AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("editaddress")); edit->setCode(AutoCreateScriptUtil::listValueToStr(element)); } ++indexStr; } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionEnvelope::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } QUrl KSieveUi::SieveConditionEnvelope::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvironment.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvironment.cpp index 83605b2..82ffd96 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvironment.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvironment.cpp @@ -1,146 +1,146 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionenvironment.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "editor/sieveeditorutil.h" #include #include #include #include #include #include "libksieve_debug.h" #include #include using namespace KSieveUi; SieveConditionEnvironment::SieveConditionEnvironment(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("environment"), i18n("Environment"), parent) { } QWidget *SieveConditionEnvironment::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); w->setLayout(grid); QLabel *lab = new QLabel(i18n("Item:")); grid->addWidget(lab, 0, 0); QLineEdit *item = new QLineEdit; QStringList itemList; itemList << QStringLiteral("domain") << QStringLiteral("host") << QStringLiteral("location") << QStringLiteral("name") << QStringLiteral("phase") << QStringLiteral("remote-host") << QStringLiteral("remote-ip") << QStringLiteral("version"); QCompleter *completer = new QCompleter(itemList, w); completer->setCaseSensitivity(Qt::CaseInsensitive); item->setCompleter(completer); connect(item, &QLineEdit::textChanged, this, &SieveConditionEnvironment::valueChanged); item->setObjectName(QStringLiteral("item")); grid->addWidget(item, 0, 1); lab = new QLabel(i18n("Value:")); grid->addWidget(lab, 1, 0); QLineEdit *value = new QLineEdit; connect(value, &QLineEdit::textChanged, this, &SieveConditionEnvironment::valueChanged); value->setObjectName(QStringLiteral("value")); grid->addWidget(value, 1, 1); return w; } QString SieveConditionEnvironment::code(QWidget *w) const { const QLineEdit *item = w->findChild(QStringLiteral("item")); const QString itemStr = item->text(); const QLineEdit *value = w->findChild(QStringLiteral("value")); const QString valueStr = value->text(); return QStringLiteral("environment \"%1\" \"%2\"").arg(itemStr, valueStr) + AutoCreateScriptUtil::generateConditionComment(comment()); } QStringList SieveConditionEnvironment::needRequires(QWidget *) const { return QStringList() << QStringLiteral("environment"); } bool SieveConditionEnvironment::needCheckIfServerHasCapability() const { return true; } QString SieveConditionEnvironment::serverNeedsCapability() const { return QStringLiteral("environment"); } QString SieveConditionEnvironment::help() const { return i18n("The environment test retrieves the item of environment information specified by the name string and matches it to the values specified in the key-list argument."); } bool SieveConditionEnvironment::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error) { int index = 0; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { if (index == 0) { QLineEdit *item = w->findChild(QStringLiteral("item")); item->setText(AutoCreateScriptUtil::quoteStr(element.readElementText())); } else if (index == 1) { QLineEdit *value = w->findChild(QStringLiteral("value")); value->setText(AutoCreateScriptUtil::quoteStr(element.readElementText())); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionEnvironment::setParamWidgetValue to many argument " << index; } ++index; } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionSetVariable::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } QUrl KSieveUi::SieveConditionEnvironment::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionheader.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionheader.cpp index 2a147db..15b8232 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionheader.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionheader.cpp @@ -1,154 +1,154 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionheader.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "widgets/selectheadertypecombobox.h" #include "editor/sieveeditorutil.h" #include #include #include #include #include "libksieve_debug.h" using namespace KSieveUi; SieveConditionHeader::SieveConditionHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("header"), i18n("Header"), parent) { } QWidget *SieveConditionHeader::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectMatchTypeComboBox *matchTypeCombo = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); matchTypeCombo->setObjectName(QStringLiteral("matchtypecombobox")); connect(matchTypeCombo, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionHeader::valueChanged); lay->addWidget(matchTypeCombo); QGridLayout *grid = new QGridLayout; lay->addLayout(grid); SelectHeaderTypeComboBox *headerType = new SelectHeaderTypeComboBox; headerType->setObjectName(QStringLiteral("headertype")); connect(headerType, &SelectHeaderTypeComboBox::valueChanged, this, &SieveConditionHeader::valueChanged); grid->addWidget(headerType, 0, 0, 1, 2); QLabel *lab = new QLabel(i18n("With value:")); grid->addWidget(lab, 1, 0); AbstractRegexpEditorLineEdit *value = AutoCreateScriptUtil::createRegexpEditorLineEdit(); connect(value, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionHeader::valueChanged); connect(matchTypeCombo, &SelectMatchTypeComboBox::switchToRegexp, value, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit); value->setObjectName(QStringLiteral("value")); grid->addWidget(value, 1, 1); return w; } QString SieveConditionHeader::code(QWidget *w) const { const SelectMatchTypeComboBox *matchTypeCombo = w->findChild(QStringLiteral("matchtypecombobox")); bool isNegative = false; const QString matchString = matchTypeCombo->code(isNegative); const SelectHeaderTypeComboBox *headerType = w->findChild(QStringLiteral("headertype")); const QString headerStr = headerType->code(); const AbstractRegexpEditorLineEdit *edit = w->findChild(QStringLiteral("value")); QString valueStr = edit->code(); valueStr = AutoCreateScriptUtil::fixListValue(valueStr); return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("header %1 %2 %3").arg(matchString, headerStr, valueStr) + AutoCreateScriptUtil::generateConditionComment(comment()); } QString SieveConditionHeader::help() const { return i18n("The \"header\" test evaluates to true if the value of any of the named headers, ignoring leading and trailing whitespace, matches any key."); } bool SieveConditionHeader::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) { int index = 0; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("comparator")) { qCWarning(LIBKSIEVE_LOG) << " comparator support not implemented yet!"; } else { SelectMatchTypeComboBox *selectMatchCombobox = w->findChild(QStringLiteral("matchtypecombobox")); selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(tagValue, notCondition), name(), error); } } else if (tagName == QLatin1String("str")) { if (index == 0) { SelectHeaderTypeComboBox *headerType = w->findChild(QStringLiteral("headertype")); headerType->setCode(element.readElementText()); } else if (index == 1) { AbstractRegexpEditorLineEdit *value = w->findChild(QStringLiteral("value")); QString st = AutoCreateScriptUtil::quoteStr(element.readElementText(), true); value->setCode(st); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionHeader::setParamWidgetValue too many argument " << index; } ++index; } else if (tagName == QLatin1String("list")) { //Header list if (index == 0) { SelectHeaderTypeComboBox *headerType = w->findChild(QStringLiteral("headertype")); headerType->setCode(AutoCreateScriptUtil::listValueToStr(element)); } else if (index == 1) { AbstractRegexpEditorLineEdit *value = w->findChild(QStringLiteral("value")); value->setCode(AutoCreateScriptUtil::listValueToStr(element)); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionHeader::setParamWidgetValue too many argument " << index; } ++index; } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionHeader::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } QStringList KSieveUi::SieveConditionHeader::needRequires(QWidget *w) const { const SelectMatchTypeComboBox *matchTypeCombo = w->findChild(QStringLiteral("matchtypecombobox")); return matchTypeCombo->needRequires(); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadata.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadata.cpp index c74de83..c09f71b 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadata.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadata.cpp @@ -1,187 +1,187 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionmetadata.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "editor/sieveeditorutil.h" #include #include #include #include #include #include "libksieve_debug.h" #include #include using namespace KSieveUi; SieveConditionMetaData::SieveConditionMetaData(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("metadata"), i18n("Meta Data"), parent) { } QWidget *SieveConditionMetaData::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectMatchTypeComboBox *selectType = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); selectType->setObjectName(QStringLiteral("selecttype")); connect(selectType, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionMetaData::valueChanged); lay->addWidget(selectType); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); lay->addLayout(grid); QLabel *lab = new QLabel(i18n("Mailbox:")); grid->addWidget(lab, 0, 0); KSieveUi::AbstractMoveImapFolderWidget *mailbox = AutoCreateScriptUtil::createImapFolderWidget(); connect(mailbox, &KSieveUi::AbstractMoveImapFolderWidget::textChanged, this, &SieveConditionMetaData::valueChanged); mailbox->setObjectName(QStringLiteral("mailbox")); grid->addWidget(mailbox, 0, 1); lab = new QLabel(i18n("Annotations:")); grid->addWidget(lab, 1, 0); QLineEdit *annotation = new QLineEdit; connect(annotation, &QLineEdit::textChanged, this, &SieveConditionMetaData::valueChanged); annotation->setObjectName(QStringLiteral("annotation")); grid->addWidget(annotation, 1, 1); lab = new QLabel(i18n("Value:")); grid->addWidget(lab, 2, 0); AbstractRegexpEditorLineEdit *value = AutoCreateScriptUtil::createRegexpEditorLineEdit(); connect(value, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionMetaData::valueChanged); connect(selectType, &SelectMatchTypeComboBox::switchToRegexp, value, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit); value->setObjectName(QStringLiteral("value")); grid->addWidget(value, 2, 1); return w; } QString SieveConditionMetaData::code(QWidget *w) const { const SelectMatchTypeComboBox *selectType = w->findChild(QStringLiteral("selecttype")); bool isNegative = false; const QString matchString = selectType->code(isNegative); QString result = AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("metadata %1 ").arg(matchString); const KSieveUi::AbstractMoveImapFolderWidget *mailbox = w->findChild(QStringLiteral("mailbox")); const QString mailboxStr = mailbox->text(); result += QStringLiteral("\"%1\" ").arg(mailboxStr); const QLineEdit *annotation = w->findChild(QStringLiteral("annotation")); const QString annotationStr = annotation->text(); result += QStringLiteral("\"%1\" ").arg(annotationStr); const AbstractRegexpEditorLineEdit *value = w->findChild(QStringLiteral("value")); const QString valueStr = value->code(); result += QStringLiteral("\"%1\"").arg(valueStr); return result + AutoCreateScriptUtil::generateConditionComment(comment()); } QStringList SieveConditionMetaData::needRequires(QWidget *w) const { const SelectMatchTypeComboBox *selectType = w->findChild(QStringLiteral("selecttype")); return QStringList() << QStringLiteral("mboxmetadata") << selectType->needRequires(); } bool SieveConditionMetaData::needCheckIfServerHasCapability() const { return true; } QString SieveConditionMetaData::serverNeedsCapability() const { return QStringLiteral("mboxmetadata"); } QString SieveConditionMetaData::help() const { return i18n( "This test retrieves the value of the mailbox annotation \"annotation-name\" for the mailbox \"mailbox\". The retrieved value is compared to the \"key-list\". The test returns true if the annotation exists and its value matches any of the keys."); } bool SieveConditionMetaData::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) { int index = 0; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { const QString tagValue = element.readElementText(); switch (index) { case 0: { KSieveUi::AbstractMoveImapFolderWidget *mailbox = w->findChild(QStringLiteral("mailbox")); mailbox->setText(tagValue); break; } case 1: { QLineEdit *annotation = w->findChild(QStringLiteral("annotation")); annotation->setText(AutoCreateScriptUtil::quoteStr(tagValue)); break; } case 2: { AbstractRegexpEditorLineEdit *value = w->findChild(QStringLiteral("value")); value->setCode(AutoCreateScriptUtil::quoteStr(tagValue)); break; } default: - tooManyArgument(tagName, index, 3, error); + tooManyArguments(tagName, index, 3, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionMetaData::setParamWidgetValue too many argument " << index; break; } ++index; } else if (tagName == QLatin1String("tag")) { SelectMatchTypeComboBox *selectType = w->findChild(QStringLiteral("selecttype")); selectType->setCode(AutoCreateScriptUtil::tagValueWithCondition(element.readElementText(), notCondition), name(), error); } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionMetaData::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } QUrl SieveConditionMetaData::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadataexists.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadataexists.cpp index 1e3a2c8..71d7ffd 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadataexists.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadataexists.cpp @@ -1,132 +1,132 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionmetadataexists.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "editor/sieveeditorutil.h" #include #include #include #include "libksieve_debug.h" #include #include #include using namespace KSieveUi; SieveConditionMetaDataExists::SieveConditionMetaDataExists(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("metadataexists"), i18n("Metadata exists"), parent) { } QWidget *SieveConditionMetaDataExists::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); w->setLayout(grid); QLabel *lab = new QLabel(i18n("Mailbox:")); grid->addWidget(lab, 0, 0); KSieveUi::AbstractMoveImapFolderWidget *mailbox = AutoCreateScriptUtil::createImapFolderWidget(); connect(mailbox, &KSieveUi::AbstractMoveImapFolderWidget::textChanged, this, &SieveConditionMetaDataExists::valueChanged); mailbox->setObjectName(QStringLiteral("mailbox")); grid->addWidget(mailbox, 0, 1); lab = new QLabel(i18n("Annotation:")); grid->addWidget(lab, 1, 0); QLineEdit *value = new QLineEdit; connect(value, &QLineEdit::textChanged, this, &SieveConditionMetaDataExists::valueChanged); value->setObjectName(QStringLiteral("value")); grid->addWidget(value, 1, 1); return w; } QString SieveConditionMetaDataExists::code(QWidget *w) const { const KSieveUi::AbstractMoveImapFolderWidget *mailbox = w->findChild(QStringLiteral("mailbox")); const QString mailboxStr = mailbox->text(); const QLineEdit *value = w->findChild(QStringLiteral("value")); const QString valueStr = value->text(); return QStringLiteral("metadataexists \"%1\" \"%2\"").arg(mailboxStr, valueStr) + AutoCreateScriptUtil::generateConditionComment(comment()); } QStringList SieveConditionMetaDataExists::needRequires(QWidget *) const { return QStringList() << QStringLiteral("mboxmetadata"); } bool SieveConditionMetaDataExists::needCheckIfServerHasCapability() const { return true; } QString SieveConditionMetaDataExists::serverNeedsCapability() const { return QStringLiteral("mboxmetadata"); } QString SieveConditionMetaDataExists::help() const { return i18n("The \"metadataexists\" test is true if all of the annotations listed in the \"annotation-names\" argument exist for the specified mailbox."); } bool SieveConditionMetaDataExists::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error) { int index = 0; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { const QString tagValue = element.readElementText(); if (index == 0) { KSieveUi::AbstractMoveImapFolderWidget *mailbox = w->findChild(QStringLiteral("mailbox")); mailbox->setText(tagValue); } else if (index == 1) { QLineEdit *value = w->findChild(QStringLiteral("value")); value->setText(AutoCreateScriptUtil::quoteStr(tagValue)); } else { - tooManyArgument(tagName, index, 2, error); + tooManyArguments(tagName, index, 2, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaDataExists::setParamWidgetValue to many attribute " << index; } ++index; } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaDataExists::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } QUrl SieveConditionMetaDataExists::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionservermetadata.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionservermetadata.cpp index f9e62c2..93faea9 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionservermetadata.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionservermetadata.cpp @@ -1,186 +1,186 @@ /* Copyright (C) 2013-2019 Laurent Montel This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sieveconditionservermetadata.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "autocreatescripts/commonwidgets/selectmatchtypecombobox.h" #include "editor/sieveeditorutil.h" #include #include #include #include #include "libksieve_debug.h" #include #include using namespace KSieveUi; SieveConditionServerMetaData::SieveConditionServerMetaData(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("servermetadata"), i18n("Server Meta Data"), parent) { } QWidget *SieveConditionServerMetaData::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectMatchTypeComboBox *selectType = new SelectMatchTypeComboBox(mSieveGraphicalModeWidget); selectType->setObjectName(QStringLiteral("selecttype")); connect(selectType, &SelectMatchTypeComboBox::valueChanged, this, &SieveConditionServerMetaData::valueChanged); lay->addWidget(selectType); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); lay->addLayout(grid); QLabel *lab = new QLabel(i18n("Mailbox:")); grid->addWidget(lab, 0, 0); QLineEdit *mailbox = new QLineEdit; mailbox->setObjectName(QStringLiteral("mailbox")); connect(mailbox, &QLineEdit::textChanged, this, &SieveConditionServerMetaData::valueChanged); grid->addWidget(mailbox, 0, 1); lab = new QLabel(i18n("Annotations:")); grid->addWidget(lab, 1, 0); QLineEdit *annotation = new QLineEdit; connect(annotation, &QLineEdit::textChanged, this, &SieveConditionServerMetaData::valueChanged); annotation->setObjectName(QStringLiteral("annotation")); grid->addWidget(annotation, 1, 1); lab = new QLabel(i18n("Value:")); grid->addWidget(lab, 2, 0); AbstractRegexpEditorLineEdit *value = AutoCreateScriptUtil::createRegexpEditorLineEdit(); connect(value, &AbstractRegexpEditorLineEdit::textChanged, this, &SieveConditionServerMetaData::valueChanged); connect(selectType, &SelectMatchTypeComboBox::switchToRegexp, value, &AbstractRegexpEditorLineEdit::switchToRegexpEditorLineEdit); value->setObjectName(QStringLiteral("value")); grid->addWidget(value, 2, 1); return w; } QString SieveConditionServerMetaData::code(QWidget *w) const { const SelectMatchTypeComboBox *selectType = w->findChild(QStringLiteral("selecttype")); bool isNegative = false; const QString matchString = selectType->code(isNegative); QString result = (isNegative ? QStringLiteral("not ") : QString()) + QStringLiteral("servermetadata %1 ").arg(matchString); const QLineEdit *mailbox = w->findChild(QStringLiteral("mailbox")); const QString mailboxStr = mailbox->text(); result += QStringLiteral("\"%1\" ").arg(mailboxStr); const QLineEdit *annotation = w->findChild(QStringLiteral("annotation")); const QString annotationStr = annotation->text(); result += QStringLiteral("\"%1\" ").arg(annotationStr); const AbstractRegexpEditorLineEdit *value = w->findChild(QStringLiteral("value")); const QString valueStr = value->code(); result += QStringLiteral("\"%1\"").arg(valueStr); return result + AutoCreateScriptUtil::generateConditionComment(comment()); } QStringList SieveConditionServerMetaData::needRequires(QWidget *w) const { const SelectMatchTypeComboBox *selectType = w->findChild(QStringLiteral("selecttype")); return QStringList() << QStringLiteral("servermetadata") << selectType->needRequires(); } bool SieveConditionServerMetaData::needCheckIfServerHasCapability() const { return true; } QString SieveConditionServerMetaData::serverNeedsCapability() const { return QStringLiteral("servermetadata"); } QString SieveConditionServerMetaData::help() const { return i18n( "This test retrieves the value of the server annotation \"annotation-name\". The retrieved value is compared to the \"key-list\". The test returns true if the annotation exists and its value matches any of the keys."); } bool SieveConditionServerMetaData::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) { int index = 0; QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { const QString tagValue = element.readElementText(); switch (index) { case 0: { QLineEdit *mailbox = w->findChild(QStringLiteral("mailbox")); mailbox->setText(tagValue); break; } case 1: { QLineEdit *annotation = w->findChild(QStringLiteral("annotation")); annotation->setText(tagValue); break; } case 2: { AbstractRegexpEditorLineEdit *value = w->findChild(QStringLiteral("value")); value->setCode(tagValue); break; } default: - tooManyArgument(tagName, index, 3, error); + tooManyArguments(tagName, index, 3, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaData::setParamWidgetValue too many argument " << index; break; } ++index; } else if (tagName == QLatin1String("tag")) { SelectMatchTypeComboBox *selectType = w->findChild(QStringLiteral("selecttype")); selectType->setCode(AutoCreateScriptUtil::tagValueWithCondition(element.readElementText(), notCondition), name(), error); } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText()); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionServerMetaData::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } QUrl SieveConditionServerMetaData::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); }