diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveaction.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveaction.cpp index 254a93c..5ed9878 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::unknowTagValue(const QString &tagValue, QString &error) +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) { 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 bb52c25..9a70404 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 unknowTagValue(const QString &tagValue, QString &error); + void unknownTagValue(const QString &tagValue, QString &error); void tooManyArgument(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/sieveactionbreak.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactionbreak.cpp index c3338a7..bc20547 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactionbreak.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactionbreak.cpp @@ -1,118 +1,118 @@ /* 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 "sieveactionbreak.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "editor/sieveeditorutil.h" #include #include #include #include #include #include "libksieve_debug.h" using namespace KSieveUi; SieveActionBreak::SieveActionBreak(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveAction(sieveGraphicalModeWidget, QStringLiteral("break"), i18n("Break"), parent) { } QWidget *SieveActionBreak::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); QLabel *lab = new QLabel(i18n("Name (optional):")); lay->addWidget(lab); QLineEdit *subject = new QLineEdit; subject->setObjectName(QStringLiteral("name")); connect(subject, &QLineEdit::textChanged, this, &SieveActionBreak::valueChanged); lay->addWidget(subject); return w; } bool SieveActionBreak::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("name")) { QLineEdit *name = w->findChild(QStringLiteral("name")); name->setText(AutoCreateScriptUtil::strValue(element)); } else { - unknowTagValue(tagValue, error); + unknownTagValue(tagValue, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionBreak::setParamWidgetValue unknown tagValue " << tagValue; } } else if (tagName == QLatin1String("str")) { element.skipCurrentElement(); //Nothing } 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) << "SieveActionBreak::setParamWidgetValue unknown tag " << tagName; } } return true; } QUrl SieveActionBreak::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } QString SieveActionBreak::code(QWidget *w) const { const QLineEdit *name = w->findChild(QStringLiteral("name")); const QString nameStr = name->text(); if (!nameStr.isEmpty()) { return QStringLiteral("break :name \"%1\";").arg(nameStr); } return QStringLiteral("break;"); } QString SieveActionBreak::help() const { return i18n("The break command terminates the closest enclosing loop."); } QStringList SieveActionBreak::needRequires(QWidget */*parent*/) const { return QStringList() << QStringLiteral("foreverypart"); } bool SieveActionBreak::needCheckIfServerHasCapability() const { return true; } QString SieveActionBreak::serverNeedsCapability() const { return QStringLiteral("foreverypart"); } diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveactionenclose.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactionenclose.cpp index 77ea41a..d80be29 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactionenclose.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactionenclose.cpp @@ -1,161 +1,161 @@ /* 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 "sieveactionenclose.h" #include "widgets/multilineedit.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "editor/sieveeditorutil.h" #include #include #include #include #include "libksieve_debug.h" #include using namespace KSieveUi; SieveActionEnclose::SieveActionEnclose(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveAction(sieveGraphicalModeWidget, QStringLiteral("enclose"), i18n("Enclose"), parent) { } QWidget *SieveActionEnclose::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("Subject:")); grid->addWidget(lab, 0, 0); QLineEdit *subject = new QLineEdit; subject->setObjectName(QStringLiteral("subject")); connect(subject, &QLineEdit::textChanged, this, &SieveActionEnclose::valueChanged); grid->addWidget(subject, 0, 1); lab = new QLabel(i18n("headers:")); grid->addWidget(lab, 1, 0); QLineEdit *headers = new QLineEdit; headers->setObjectName(QStringLiteral("headers")); connect(headers, &QLineEdit::textChanged, this, &SieveActionEnclose::valueChanged); grid->addWidget(headers, 1, 1); lab = new QLabel(i18n("text:")); grid->addWidget(lab, 2, 0); MultiLineEdit *text = new MultiLineEdit; text->setObjectName(QStringLiteral("text")); connect(text, &MultiLineEdit::valueChanged, this, &SieveActionEnclose::valueChanged); grid->addWidget(text, 2, 1); return w; } bool SieveActionEnclose::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("headers")) { const QString strValue = AutoCreateScriptUtil::strValue(element); if (!strValue.isEmpty()) { QLineEdit *subject = w->findChild(QStringLiteral("headers")); subject->setText(strValue); } } else if (tagValue == QLatin1String("subject")) { const QString strValue = AutoCreateScriptUtil::strValue(element); if (!strValue.isEmpty()) { QLineEdit *headers = w->findChild(QStringLiteral("subject")); headers->setText(strValue); } } else { - unknowTagValue(tagValue, error); + unknownTagValue(tagValue, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionEnclose::setParamWidgetValue unknown tag value:" << tagValue; } } else if (tagName == QLatin1String("str")) { MultiLineEdit *edit = w->findChild(QStringLiteral("text")); edit->setPlainText(element.readElementText()); } 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) << " SieveActionEnclose::setParamWidgetValue unknown tagName " << tagName; } } return true; } QString SieveActionEnclose::code(QWidget *w) const { QString result = QStringLiteral("enclose "); const QLineEdit *subject = w->findChild(QStringLiteral("subject")); const QString subjectStr = subject->text(); if (!subjectStr.isEmpty()) { result += QStringLiteral(":subject \"%1\" ").arg(subjectStr); } const QLineEdit *headers = w->findChild(QStringLiteral("headers")); const QString headersStr = headers->text(); if (!headersStr.isEmpty()) { result += QStringLiteral(":headers \"%1\" ").arg(headersStr); } const MultiLineEdit *edit = w->findChild(QStringLiteral("text")); const QString text = edit->toPlainText(); if (!text.isEmpty()) { result += QStringLiteral("text:%1").arg(AutoCreateScriptUtil::createMultiLine(text)); } else { result += QLatin1Char(';'); } return result; } QStringList SieveActionEnclose::needRequires(QWidget * /*parent*/) const { return QStringList() << QStringLiteral("enclose"); } bool SieveActionEnclose::needCheckIfServerHasCapability() const { return true; } QString SieveActionEnclose::serverNeedsCapability() const { return QStringLiteral("enclose"); } QString SieveActionEnclose::help() const { return i18n("Enclose action command is defined to allow an entire message to be enclosed as an attachment to a new message."); } QUrl SieveActionEnclose::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveactionnotify.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactionnotify.cpp index 017918a..7245b2e 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactionnotify.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactionnotify.cpp @@ -1,157 +1,157 @@ /* 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 "sieveactionnotify.h" #include "editor/sieveeditorutil.h" #include "widgets/selectimportancecombobox.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include #include #include #include #include #include "libksieve_debug.h" using namespace KSieveUi; SieveActionNotify::SieveActionNotify(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveAction(sieveGraphicalModeWidget, QStringLiteral("notify"), i18n("Notify"), parent) { } QWidget *SieveActionNotify::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectImportanceCombobox *importanceCombobox = new SelectImportanceCombobox; importanceCombobox->setObjectName(QStringLiteral("importancecombo")); connect(importanceCombobox, &SelectImportanceCombobox::valueChanged, this, &SieveActionNotify::valueChanged); lay->addWidget(importanceCombobox); QLabel *lab = new QLabel(i18n("message:")); lay->addWidget(lab); QLineEdit *message = new QLineEdit; message->setObjectName(QStringLiteral("message")); connect(message, &QLineEdit::textChanged, this, &SieveActionNotify::valueChanged); lay->addWidget(message); lab = new QLabel(i18n("method:")); lay->addWidget(lab); QLineEdit *method = new QLineEdit; method->setObjectName(QStringLiteral("method")); lay->addWidget(method); connect(method, &QLineEdit::textChanged, this, &SieveActionNotify::valueChanged); return w; } bool SieveActionNotify::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("message")) { const QString strValue = AutoCreateScriptUtil::strValue(element); if (!strValue.isEmpty()) { QLineEdit *message = w->findChild(QStringLiteral("message")); message->setText(AutoCreateScriptUtil::quoteStr(strValue)); } } else if (tagValue == QLatin1String("importance")) { const QString strValue = AutoCreateScriptUtil::strValue(element); if (!strValue.isEmpty()) { SelectImportanceCombobox *importance = w->findChild(QStringLiteral("importancecombo")); importance->setCode(strValue, name(), error); } } else { - unknowTagValue(tagValue, error); + unknownTagValue(tagValue, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionNotify::setParamWidgetValue unknown tagValue" << tagValue; } } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { element.skipCurrentElement(); //implement in the future ? } else if (tagName == QLatin1String("str")) { QLineEdit *method = w->findChild(QStringLiteral("method")); method->setText(AutoCreateScriptUtil::quoteStr(element.readElementText())); } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionNotify::setParamWidgetValue unknown tagName " << tagName; } } return true; } QString SieveActionNotify::code(QWidget *w) const { QString result = QStringLiteral("notify"); const SelectImportanceCombobox *importance = w->findChild(QStringLiteral("importancecombo")); const QString importanceStr = importance->code(); if (!importanceStr.isEmpty()) { result += QStringLiteral(" :importance \"%1\"").arg(importanceStr); } const QLineEdit *message = w->findChild(QStringLiteral("message")); const QString messageStr = message->text(); if (!messageStr.isEmpty()) { result += QStringLiteral(" :message \"%1\"").arg(messageStr); } const QLineEdit *method = w->findChild(QStringLiteral("method")); const QString methodStr = method->text(); result += QStringLiteral(" \"%1\";").arg(methodStr); return result; } QString SieveActionNotify::serverNeedsCapability() const { return QStringLiteral("enotify"); } bool SieveActionNotify::needCheckIfServerHasCapability() const { return true; } QString SieveActionNotify::help() const { return i18n("The \"notify\" action specifies that a notification should be sent to a user."); } QStringList SieveActionNotify::needRequires(QWidget *) const { QStringList lst; lst << QStringLiteral("enotify"); return lst; } QUrl SieveActionNotify::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveactionredirect.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactionredirect.cpp index e17d487..37ae15d 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactionredirect.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactionredirect.cpp @@ -1,166 +1,166 @@ /* 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 "sieveactionredirect.h" #include "editor/sieveeditorutil.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "autocreatescripts/sieveeditorgraphicalmodewidget.h" #include "widgets/addresslineedit.h" #include #include #include #include #include "libksieve_debug.h" using namespace KSieveUi; SieveActionRedirect::SieveActionRedirect(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveAction(sieveGraphicalModeWidget, QStringLiteral("redirect"), i18n("Redirect"), parent) { mHasCopySupport = sieveCapabilities().contains(QLatin1String("copy")); mHasListSupport = sieveCapabilities().contains(QLatin1String("extlists")); } QWidget *SieveActionRedirect::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QHBoxLayout *lay = new QHBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); if (mHasCopySupport) { QCheckBox *copy = new QCheckBox(i18n("Keep a copy")); copy->setObjectName(QStringLiteral("copy")); connect(copy, &QCheckBox::clicked, this, &SieveActionRedirect::valueChanged); lay->addWidget(copy); } if (mHasListSupport) { QCheckBox *list = new QCheckBox(i18n("Use list")); list->setObjectName(QStringLiteral("list")); connect(list, &QCheckBox::clicked, this, &SieveActionRedirect::valueChanged); lay->addWidget(list); } KSieveUi::AbstractSelectEmailLineEdit *edit = AutoCreateScriptUtil::createSelectEmailsWidget(); edit->setObjectName(QStringLiteral("RedirectEdit")); connect(edit, &AddressLineEdit::valueChanged, this, &SieveActionRedirect::valueChanged); lay->addWidget(edit); return w; } bool SieveActionRedirect::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { AbstractSelectEmailLineEdit *edit = w->findChild(QStringLiteral("RedirectEdit")); const QString tagValue = element.readElementText(); edit->setText(AutoCreateScriptUtil::quoteStr(tagValue)); } else if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("copy")) { if (mHasCopySupport) { QCheckBox *copy = w->findChild(QStringLiteral("copy")); copy->setChecked(true); } else { serverDoesNotSupportFeatures(QStringLiteral("copy"), error); } } else if (tagValue == QLatin1String("list")) { if (mHasListSupport) { QCheckBox *list = w->findChild(QStringLiteral("list")); list->setChecked(true); } else { serverDoesNotSupportFeatures(QStringLiteral("list"), error); } } else { - unknowTagValue(tagValue, error); + unknownTagValue(tagValue, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionRedirect::setParamWidgetValue tagValue unknown" << tagValue; } } else if (tagName == QLatin1String("crlf")) { element.skipCurrentElement(); //nothing } else if (tagName == QLatin1String("comment")) { setComment(element.readElementText()); //implement in the future ? } else { unknownTag(tagName, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionRedirect::setParamWidgetValue unknown tagName " << tagName; } } return true; } QString SieveActionRedirect::code(QWidget *w) const { QString result = QStringLiteral("redirect "); const AbstractSelectEmailLineEdit *edit = w->findChild(QStringLiteral("RedirectEdit")); const QString text = edit->text(); if (mHasCopySupport) { const QCheckBox *copy = w->findChild(QStringLiteral("copy")); if (copy->isChecked()) { result += QLatin1String(":copy "); } } if (mHasListSupport) { const QCheckBox *list = w->findChild(QStringLiteral("list")); if (list->isChecked()) { result += QLatin1String(":list "); } } return result + QStringLiteral("\"%1\";").arg(text); } QStringList SieveActionRedirect::needRequires(QWidget *parent) const { QStringList lst; if (mHasCopySupport) { const QCheckBox *copy = parent->findChild(QStringLiteral("copy")); if (copy->isChecked()) { lst << QStringLiteral("copy"); } } if (mHasListSupport) { const QCheckBox *list = parent->findChild(QStringLiteral("list")); if (list->isChecked()) { lst << QStringLiteral("extlists"); } } return lst; } QString SieveActionRedirect::help() const { QString helpStr = i18n( "The \"redirect\" action is used to send the message to another user at a supplied address, as a mail forwarding feature does. The \"redirect\" action makes no changes to the message body or existing headers, but it may add new headers."); if (mHasCopySupport) { helpStr += QLatin1Char('\n') + i18n( "If the optional \":copy\" keyword is specified, the tagged command does not cancel the implicit \"keep\". Instead, it redirects a copy in addition to whatever else is happening to the message."); } //TODO add list info return helpStr; } QUrl SieveActionRedirect::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveactionreplace.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactionreplace.cpp index c10f555..5bd46ad 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactionreplace.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactionreplace.cpp @@ -1,161 +1,161 @@ /* 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 "sieveactionreplace.h" #include "editor/sieveeditorutil.h" #include "widgets/multilineedit.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include #include #include #include #include "libksieve_debug.h" #include #include using namespace KSieveUi; SieveActionReplace::SieveActionReplace(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveAction(sieveGraphicalModeWidget, QStringLiteral("replace"), i18n("Replace"), parent) { } QWidget *SieveActionReplace::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("Subject:")); grid->addWidget(lab, 0, 0); QLineEdit *subject = new QLineEdit; subject->setObjectName(QStringLiteral("subject")); connect(subject, &QLineEdit::textChanged, this, &SieveActionReplace::valueChanged); grid->addWidget(subject, 0, 1); lab = new QLabel(i18n("from:")); grid->addWidget(lab, 1, 0); KSieveUi::AbstractSelectEmailLineEdit *headers = AutoCreateScriptUtil::createSelectEmailsWidget(); headers->setObjectName(QStringLiteral("from")); connect(headers, &AbstractSelectEmailLineEdit::valueChanged, this, &SieveActionReplace::valueChanged); grid->addWidget(headers, 1, 1); lab = new QLabel(i18n("text:")); grid->addWidget(lab, 2, 0); MultiLineEdit *text = new MultiLineEdit; text->setObjectName(QStringLiteral("text")); connect(text, &MultiLineEdit::textChanged, this, &SieveActionReplace::valueChanged); grid->addWidget(text, 2, 1); return w; } bool SieveActionReplace::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("str")) { MultiLineEdit *edit = w->findChild(QStringLiteral("text")); edit->setPlainText(element.readElementText()); } else if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("subject")) { const QString strValue = AutoCreateScriptUtil::strValue(element); if (!strValue.isEmpty()) { QLineEdit *subject = w->findChild(QStringLiteral("subject")); subject->setText(strValue); } } else if (tagValue == QLatin1String("from")) { const QString strValue = AutoCreateScriptUtil::strValue(element); if (!strValue.isEmpty()) { KSieveUi::AbstractSelectEmailLineEdit *headers = w->findChild(QStringLiteral("from")); headers->setText(strValue); } } else { - unknowTagValue(tagValue, error); + unknownTagValue(tagValue, error); qCDebug(LIBKSIEVE_LOG) << " SieveActionReplace::setParamWidgetValue unknown tagValue " << tagValue; } } 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) << " SieveActionReplace::setParamWidgetValue unknown tagName " << tagName; } } return true; } QString SieveActionReplace::code(QWidget *w) const { QString result = QStringLiteral("replace "); const QLineEdit *subject = w->findChild(QStringLiteral("subject")); const QString subjectStr = subject->text(); if (!subjectStr.isEmpty()) { result += QStringLiteral(":subject \"%1\" ").arg(subjectStr); } const KSieveUi::AbstractSelectEmailLineEdit *headers = w->findChild(QStringLiteral("from")); const QString headersStr = headers->text(); if (!headersStr.isEmpty()) { result += QStringLiteral(":from \"%1\" ").arg(headersStr); } const MultiLineEdit *edit = w->findChild(QStringLiteral("text")); const QString text = edit->toPlainText(); if (!text.isEmpty()) { result += QStringLiteral("text:%1").arg(AutoCreateScriptUtil::createMultiLine(text)); } return result; } QStringList SieveActionReplace::needRequires(QWidget *) const { return QStringList() << QStringLiteral("replace"); } bool SieveActionReplace::needCheckIfServerHasCapability() const { return true; } QString SieveActionReplace::serverNeedsCapability() const { return QStringLiteral("replace"); } QString SieveActionReplace::help() const { return i18n("The \"replace\" command is defined to allow a MIME part to be replaced with the text supplied in the command."); } QUrl SieveActionReplace::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveactions/sieveactionvacation.cpp b/src/ksieveui/autocreatescripts/sieveactions/sieveactionvacation.cpp index 70b5d5f..603bf75 100644 --- a/src/ksieveui/autocreatescripts/sieveactions/sieveactionvacation.cpp +++ b/src/ksieveui/autocreatescripts/sieveactions/sieveactionvacation.cpp @@ -1,221 +1,221 @@ /* 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 "sieveactionvacation.h" #include "editor/sieveeditorutil.h" #include "autocreatescripts/sieveeditorgraphicalmodewidget.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "widgets/multilineedit.h" #include "widgets/selectvacationcombobox.h" #include #include #include #include #include "libksieve_debug.h" #include #include #include using namespace KSieveUi; SieveActionVacation::SieveActionVacation(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveAction(sieveGraphicalModeWidget, QStringLiteral("vacation"), i18n("Vacation"), parent) { mHasVacationSecondsSupport = sieveCapabilities().contains(QLatin1String("vacation-seconds")); } QWidget *SieveActionVacation::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QGridLayout *grid = new QGridLayout; grid->setContentsMargins(0, 0, 0, 0); w->setLayout(grid); QLabel *lab = nullptr; if (mHasVacationSecondsSupport) { SelectVacationComboBox *vacation = new SelectVacationComboBox; vacation->setObjectName(QStringLiteral("vacationcombobox")); connect(vacation, &SelectVacationComboBox::valueChanged, this, &SieveActionVacation::valueChanged); grid->addWidget(vacation, 0, 0); } else { lab = new QLabel(i18n("day:")); grid->addWidget(lab, 0, 0); } QSpinBox *day = new QSpinBox; day->setMinimum(1); day->setMaximum(999); day->setObjectName(QStringLiteral("day")); connect(day, QOverload::of(&QSpinBox::valueChanged), this, &SieveActionVacation::valueChanged); grid->addWidget(day, 0, 1); lab = new QLabel(i18n("Message subject:")); grid->addWidget(lab, 1, 0); QLineEdit *subject = new QLineEdit; subject->setObjectName(QStringLiteral("subject")); connect(subject, &QLineEdit::textChanged, this, &SieveActionVacation::valueChanged); grid->addWidget(subject, 1, 1); lab = new QLabel(i18n("Additional email:")); grid->addWidget(lab, 2, 0); AbstractSelectEmailLineEdit *addresses = AutoCreateScriptUtil::createSelectEmailsWidget(); addresses->setObjectName(QStringLiteral("addresses")); addresses->setMultiSelection(true); connect(addresses, &AbstractSelectEmailLineEdit::valueChanged, this, &SieveActionVacation::valueChanged); grid->addWidget(addresses, 2, 1); lab = new QLabel(i18n("Vacation reason:")); grid->addWidget(lab, 3, 0); MultiLineEdit *text = new MultiLineEdit; connect(text, &MultiLineEdit::valueChanged, this, &SieveActionVacation::valueChanged); text->setObjectName(QStringLiteral("text")); grid->addWidget(text, 3, 1); return w; } bool SieveActionVacation::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) { while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("seconds")) { if (mHasVacationSecondsSupport) { SelectVacationComboBox *vacationcombobox = w->findChild(QStringLiteral("vacationcombobox")); vacationcombobox->setCode(AutoCreateScriptUtil::tagValue(tagValue), name(), error); } else { serverDoesNotSupportFeatures(QStringLiteral("seconds"), error); } } else if (tagValue == QLatin1String("days")) { //Nothing wait num tag for it. } else if (tagValue == QLatin1String("addresses")) { AbstractSelectEmailLineEdit *addresses = w->findChild(QStringLiteral("addresses")); if (element.readNextStartElement()) { const QStringRef textElementTagName = element.name(); if (textElementTagName == QLatin1String("str")) { addresses->setText(element.readElementText()); } else if (textElementTagName == QLatin1String("list")) { addresses->setText(AutoCreateScriptUtil::listValueToStr(element)); } } } else if (tagValue == QLatin1String("subject")) { QLineEdit *subject = w->findChild(QStringLiteral("subject")); subject->setText(AutoCreateScriptUtil::strValue(element)); } else { - unknowTagValue(tagValue, error); + unknownTagValue(tagValue, error); qCDebug(LIBKSIEVE_LOG) << "SieveActionVacation::setParamWidgetValue unknown tagValue :" << tagValue; } } else if (tagName == QLatin1String("num")) { QSpinBox *day = w->findChild(QStringLiteral("day")); day->setValue(element.readElementText().toInt()); } else if (tagName == QLatin1String("str")) { MultiLineEdit *text = w->findChild(QStringLiteral("text")); text->setPlainText(element.readElementText()); } 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) << " SieveActionVacation::setParamWidgetValue unknown tagName " << tagName; } } return true; } QString SieveActionVacation::code(QWidget *w) const { QString vacationTypeStr = QStringLiteral(":days"); if (mHasVacationSecondsSupport) { const SelectVacationComboBox *vacationcombobox = w->findChild(QStringLiteral("vacationcombobox")); vacationTypeStr = vacationcombobox->code(); } const QSpinBox *day = w->findChild(QStringLiteral("day")); const QString dayStr = QString::number(day->value()); const MultiLineEdit *text = w->findChild(QStringLiteral("text")); const QString textStr = text->toPlainText(); const QLineEdit *subject = w->findChild(QStringLiteral("subject")); const QString subjectStr = subject->text(); const AbstractSelectEmailLineEdit *addresses = w->findChild(QStringLiteral("addresses")); const QString addressesStr = addresses->text(); QString result = QStringLiteral("vacation"); if (!dayStr.isEmpty()) { result += QStringLiteral(" %1 %2").arg(vacationTypeStr, dayStr); } if (!subjectStr.isEmpty()) { result += QStringLiteral(" :subject \"%1\"").arg(subjectStr); } if (!addressesStr.isEmpty()) { result += QStringLiteral(" :addresses %1").arg(AutoCreateScriptUtil::createAddressList(addressesStr, false)); } if (!textStr.isEmpty()) { result += QStringLiteral(" text:%1").arg(AutoCreateScriptUtil::createMultiLine(textStr)); } else { result += QLatin1Char(';'); //Be sure to have ";" } return result; } QString SieveActionVacation::serverNeedsCapability() const { return QStringLiteral("vacation"); } bool SieveActionVacation::needCheckIfServerHasCapability() const { return true; } QStringList SieveActionVacation::needRequires(QWidget *) const { QStringList lst; if (mHasVacationSecondsSupport) { lst << QStringLiteral("vacation-seconds"); } lst << QStringLiteral("vacation"); return lst; } QString SieveActionVacation::help() const { QString helpStr = i18n( "The \"vacation\" action implements a vacation autoresponder similar to the vacation command available under many versions of Unix. Its purpose is to provide correspondents with notification that the user is away for an extended period of time and that they should not expect quick responses."); if (mHasVacationSecondsSupport) { helpStr = QLatin1Char('\n') + i18n( "Through the \":days\" parameter, it limits the number of auto-replies to the same sender to one per [n] days, for a specified number of days. But there are cases when one needs more granularity, if one would like to generate \"vacation\" replies more frequently."); helpStr += QLatin1Char('\n') + i18n("This extension defines a \":seconds\" parameter to provide more granularity for such situations."); } return helpStr; } QUrl SieveActionVacation::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sievecondition.cpp index c166650..7b80d8b 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::unknowTagValue(const QString &tagValue, QString &error) +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) { 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) { tooManyArgument(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 3b24732..746d45f 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 unknowTagValue(const QString &tagValue, 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 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/sieveconditionspamtest.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionspamtest.cpp index 7d8d546..25c5307 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionspamtest.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionspamtest.cpp @@ -1,180 +1,180 @@ /* 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 "sieveconditionspamtest.h" #include "widgets/selectrelationalmatchtype.h" #include "widgets/selectcomparatorcombobox.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "autocreatescripts/sieveeditorgraphicalmodewidget.h" #include "editor/sieveeditorutil.h" #include #include #include "libksieve_debug.h" #include #include #include using namespace KSieveUi; SieveConditionSpamTest::SieveConditionSpamTest(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("spamtest"), i18n("Spam Test"), parent) { mHasSpamTestPlusSupport = sieveCapabilities().contains(QLatin1String("spamtestplus")); } QWidget *SieveConditionSpamTest::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QVBoxLayout *lay = new QVBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); if (mHasSpamTestPlusSupport) { QCheckBox *percent = new QCheckBox(i18n("Percent")); percent->setObjectName(QStringLiteral("percent")); connect(percent, &QCheckBox::toggled, this, &SieveConditionSpamTest::valueChanged); lay->addWidget(percent); } SelectRelationalMatchType *relation = new SelectRelationalMatchType; connect(relation, &SelectRelationalMatchType::valueChanged, this, &SieveConditionSpamTest::valueChanged); relation->setObjectName(QStringLiteral("relation")); lay->addWidget(relation); SelectComparatorComboBox *comparator = new SelectComparatorComboBox(mSieveGraphicalModeWidget); connect(comparator, &SelectComparatorComboBox::valueChanged, this, &SieveConditionSpamTest::valueChanged); comparator->setObjectName(QStringLiteral("comparator")); lay->addWidget(comparator); QSpinBox *spinbox = new QSpinBox; spinbox->setMaximum(10); spinbox->setMinimum(0); spinbox->setObjectName(QStringLiteral("value")); connect(spinbox, QOverload::of(&QSpinBox::valueChanged), this, &SieveConditionSpamTest::valueChanged); lay->addWidget(spinbox); return w; } QString SieveConditionSpamTest::code(QWidget *w) const { QString percentStr; if (mHasSpamTestPlusSupport) { const QCheckBox *checkbox = w->findChild(QStringLiteral("percent")); percentStr = checkbox->isChecked() ? QStringLiteral(":percent") : QString(); } const SelectRelationalMatchType *relation = w->findChild(QStringLiteral("relation")); const QString relationStr = relation->code(); const SelectComparatorComboBox *comparator = w->findChild(QStringLiteral("comparator")); const QString comparatorStr = comparator->code(); const QSpinBox *spinbox = w->findChild(QStringLiteral("value")); const QString value = QString::number(spinbox->value()); return QStringLiteral("spamtest %1 %2 %3 \"%4\"").arg(percentStr, relationStr, comparatorStr, value) + AutoCreateScriptUtil::generateConditionComment(comment()); } bool SieveConditionSpamTest::needCheckIfServerHasCapability() const { return true; } QString SieveConditionSpamTest::serverNeedsCapability() const { return QStringLiteral("spamtest"); } QStringList SieveConditionSpamTest::needRequires(QWidget *w) const { const SelectComparatorComboBox *comparator = w->findChild(QStringLiteral("comparator")); QStringList lst; lst << QStringLiteral("spamtest") << QStringLiteral("relational"); const QString comparatorRequires = comparator->require(); if (!comparatorRequires.isEmpty()) { lst << comparatorRequires; } if (mHasSpamTestPlusSupport) { lst << QStringLiteral("spamtestplus"); } return lst; } QString SieveConditionSpamTest::help() const { return i18n("Sieve implementations that implement the \"spamtest\" test use an identifier of either \"spamtest\" or \"spamtestplus\" for use with the capability mechanism."); } bool SieveConditionSpamTest::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error) { QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("count") || tagValue == QLatin1String("value")) { if (element.readNextStartElement()) { if (element.name() == QLatin1String("str")) { SelectRelationalMatchType *relation = w->findChild(QStringLiteral("relation")); relation->setCode(AutoCreateScriptUtil::tagValue(tagValue), element.readElementText(), name(), error); } } } else if (tagValue == QLatin1String("comparator")) { if (element.readNextStartElement()) { if (element.name() == QLatin1String("str")) { SelectComparatorComboBox *comparator = w->findChild(QStringLiteral("comparator")); comparator->setCode(element.readElementText(), name(), error); } } } else if (tagValue == QLatin1String("percent")) { if (mHasSpamTestPlusSupport) { QCheckBox *checkbox = w->findChild(QStringLiteral("percent")); checkbox->setChecked(true); } else { serverDoesNotSupportFeatures(QStringLiteral("percent"), error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionSpamTest::setParamWidgetValue server has not percent support"; } } else { - unknowTagValue(tagValue, error); + unknownTagValue(tagValue, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionSpamTest::setParamWidgetValue unknown tagvalue " << tagValue; } } else if (tagName == QLatin1String("str")) { QSpinBox *spinbox = w->findChild(QStringLiteral("value")); spinbox->setValue(element.readElementText().toInt()); } 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) << " SieveSpamTest::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } QUrl SieveConditionSpamTest::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); } diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionvirustest.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionvirustest.cpp index 83a6940..ba23e9e 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionvirustest.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionvirustest.cpp @@ -1,155 +1,155 @@ /* 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 "sieveconditionvirustest.h" #include "autocreatescripts/autocreatescriptutil_p.h" #include "editor/sieveeditorutil.h" #include "widgets/selectrelationalmatchtype.h" #include "widgets/selectcomparatorcombobox.h" #include #include #include "libksieve_debug.h" #include #include using namespace KSieveUi; SieveConditionVirusTest::SieveConditionVirusTest(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent) : SieveCondition(sieveGraphicalModeWidget, QStringLiteral("virustest"), i18n("Virus Test"), parent) { } QWidget *SieveConditionVirusTest::createParamWidget(QWidget *parent) const { QWidget *w = new QWidget(parent); QVBoxLayout *lay = new QVBoxLayout; lay->setContentsMargins(0, 0, 0, 0); w->setLayout(lay); SelectRelationalMatchType *relation = new SelectRelationalMatchType; connect(relation, &SelectRelationalMatchType::valueChanged, this, &SieveConditionVirusTest::valueChanged); relation->setObjectName(QStringLiteral("relation")); lay->addWidget(relation); SelectComparatorComboBox *comparator = new SelectComparatorComboBox(mSieveGraphicalModeWidget); connect(comparator, &SelectComparatorComboBox::valueChanged, this, &SieveConditionVirusTest::valueChanged); comparator->setObjectName(QStringLiteral("comparator")); lay->addWidget(comparator); QSpinBox *spinbox = new QSpinBox; spinbox->setMaximum(5); spinbox->setMinimum(0); spinbox->setObjectName(QStringLiteral("value")); connect(spinbox, QOverload::of(&QSpinBox::valueChanged), this, &SieveConditionVirusTest::valueChanged); lay->addWidget(spinbox); return w; } QString SieveConditionVirusTest::code(QWidget *w) const { const SelectRelationalMatchType *relation = w->findChild(QStringLiteral("relation")); const QString relationStr = relation->code(); const SelectComparatorComboBox *comparator = w->findChild(QStringLiteral("comparator")); const QString comparatorStr = comparator->code(); const QSpinBox *spinbox = w->findChild(QStringLiteral("value")); const QString value = QString::number(spinbox->value()); return QStringLiteral("virustest %1 %2 \"%3\"").arg(relationStr, comparatorStr, value) + AutoCreateScriptUtil::generateConditionComment(comment()); } bool SieveConditionVirusTest::needCheckIfServerHasCapability() const { return true; } QString SieveConditionVirusTest::serverNeedsCapability() const { return QStringLiteral("virustest"); } QStringList SieveConditionVirusTest::needRequires(QWidget *w) const { const SelectComparatorComboBox *comparator = w->findChild(QStringLiteral("comparator")); const QString comparatorRequires = comparator->require(); QStringList lst; lst << QStringLiteral("spamtest") << QStringLiteral("relational"); if (!comparatorRequires.isEmpty()) { lst << comparatorRequires; } return lst; } QString SieveConditionVirusTest::help() const { return i18n("Sieve implementations that implement the \"virustest\" test have an identifier of \"virustest\" for use with the capability mechanism."); } bool SieveConditionVirusTest::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error) { QString commentStr; while (element.readNextStartElement()) { const QStringRef tagName = element.name(); if (tagName == QLatin1String("tag")) { const QString tagValue = element.readElementText(); if (tagValue == QLatin1String("count") || tagValue == QLatin1String("value")) { if (element.readNextStartElement()) { if (element.name() == QLatin1String("str")) { SelectRelationalMatchType *relation = w->findChild(QStringLiteral("relation")); relation->setCode(AutoCreateScriptUtil::tagValue(tagValue), element.readElementText(), name(), error); } } } else if (tagValue == QLatin1String("comparator")) { if (element.readNextStartElement()) { if (element.name() == QLatin1String("str")) { SelectComparatorComboBox *comparator = w->findChild(QStringLiteral("comparator")); comparator->setCode(element.readElementText(), name(), error); } } } else { - unknowTagValue(tagValue, error); + unknownTagValue(tagValue, error); qCDebug(LIBKSIEVE_LOG) << " SieveConditionVirusTest::setParamWidgetValue unknown tagValue " << tagValue; } } else if (tagName == QLatin1String("str")) { QSpinBox *spinbox = w->findChild(QStringLiteral("value")); spinbox->setValue(element.readElementText().toInt()); } 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) << " SieveConditionVirusTest::setParamWidgetValue unknown tagName " << tagName; } } if (!commentStr.isEmpty()) { setComment(commentStr); } return true; } QUrl SieveConditionVirusTest::href() const { return SieveEditorUtil::helpUrl(SieveEditorUtil::strToVariableName(name())); }