diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvelope.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvelope.cpp index 1c8bfdb..76c3cdd 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvelope.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionenvelope.cpp @@ -1,189 +1,189 @@ /* Copyright (C) 2013-2018 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->setMargin(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->setMargin(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); - edit->setObjectName(QStringLiteral("editaddress")); 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); 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); 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/sieveconditionmetadata.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadata.cpp index 4a54dcc..3519b21 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadata.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadata.cpp @@ -1,185 +1,187 @@ /* Copyright (C) 2013-2018 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->setMargin(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->setMargin(0); lay->addLayout(grid); QLabel *lab = new QLabel(i18n("Mailbox:")); grid->addWidget(lab, 0, 0); - QLineEdit *mailbox = new QLineEdit; - connect(mailbox, &QLineEdit::textChanged, this, &SieveConditionMetaData::valueChanged); + 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 QLineEdit *mailbox = w->findChild(QStringLiteral("mailbox")); + 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: { - QLineEdit *mailbox = w->findChild(QStringLiteral("mailbox")); + 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); 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 ad3bcaa..289d4a9 100644 --- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadataexists.cpp +++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionmetadataexists.cpp @@ -1,131 +1,132 @@ /* Copyright (C) 2013-2018 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->setMargin(0); w->setLayout(grid); QLabel *lab = new QLabel(i18n("Mailbox:")); grid->addWidget(lab, 0, 0); - QLineEdit *mailbox = new QLineEdit; - connect(mailbox, &QLineEdit::textChanged, this, &SieveConditionMetaDataExists::valueChanged); + 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 QLineEdit *mailbox = w->findChild(QStringLiteral("mailbox")); + 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) { - QLineEdit *mailbox = w->findChild(QStringLiteral("mailbox")); + 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); 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())); }