Commit 609bb85a authored by Laurent Montel's avatar Laurent Montel 😁

Porting

parent c681d51c
...@@ -133,6 +133,13 @@ QString AutoCreateScriptUtil::tagValue(const QString &tag) ...@@ -133,6 +133,13 @@ QString AutoCreateScriptUtil::tagValue(const QString &tag)
QString AutoCreateScriptUtil::strValue(QXmlStreamReader &node) QString AutoCreateScriptUtil::strValue(QXmlStreamReader &node)
{ {
if (node.readNextStartElement()) {
const QStringRef textElementTagName = node.name();
if (textElementTagName == QLatin1String("str")) {
return node.readElementText();
}
}
#ifdef REMOVE_QDOMELEMENT #ifdef REMOVE_QDOMELEMENT
node = node.nextSibling(); node = node.nextSibling();
QDomElement textElement = node.toElement(); QDomElement textElement = node.toElement();
...@@ -155,7 +162,15 @@ QString AutoCreateScriptUtil::listValueToStr(QXmlStreamReader &element) ...@@ -155,7 +162,15 @@ QString AutoCreateScriptUtil::listValueToStr(QXmlStreamReader &element)
QStringList AutoCreateScriptUtil::listValue(QXmlStreamReader &element) QStringList AutoCreateScriptUtil::listValue(QXmlStreamReader &element)
{ {
#ifdef REMOVE_QDOMELEMENT QStringList lst;
while (element.readNextStartElement()) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("str")) {
lst << element.readElementText();
}
}
return lst;
#ifdef REMOVE_QDOMELEMENT
QStringList lst; QStringList lst;
QDomNode node = element.firstChild(); QDomNode node = element.firstChild();
while (!node.isNull()) { while (!node.isNull()) {
......
...@@ -108,9 +108,14 @@ void SieveCondition::unknowTagValue(const QString &tagValue, QString &error) ...@@ -108,9 +108,14 @@ void SieveCondition::unknowTagValue(const QString &tagValue, QString &error)
error += i18n("An unknown tag value \"%1\" was found during parsing condition \"%2\".", tagValue, name()) + QLatin1Char('\n'); 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) void SieveCondition::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 + 1), *tagName.string()) + QLatin1Char('\n'); tooManyArgument(tagName.toString(), index, maxValue, error);
} }
void SieveCondition::serverDoesNotSupportFeatures(const QString &feature, QString &error) void SieveCondition::serverDoesNotSupportFeatures(const QString &feature, QString &error)
......
...@@ -58,6 +58,7 @@ public: ...@@ -58,6 +58,7 @@ public:
void unknownTag(const QStringRef &tag, QString &error); void unknownTag(const QStringRef &tag, QString &error);
void unknowTagValue(const QString &tagValue, QString &error); void unknowTagValue(const QString &tagValue, QString &error);
void tooManyArgument(const QStringRef &tagName, int index, int maxValue, 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); void serverDoesNotSupportFeatures(const QString &feature, QString &error);
QString comment() const; QString comment() const;
......
...@@ -105,11 +105,81 @@ QStringList SieveConditionAddress::needRequires(QWidget *w) const ...@@ -105,11 +105,81 @@ QStringList SieveConditionAddress::needRequires(QWidget *w) const
QString SieveConditionAddress::help() const QString SieveConditionAddress::help() const
{ {
return i18n( 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."); "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) 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<SelectHeaderTypeComboBox *>(QStringLiteral("headertypecombobox"));
selectHeaderType->setCode(element.readElementText());
} else if (indexStr == 1) {
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("editaddress"));
edit->setCode(AutoCreateScriptUtil::quoteStr(element.readElementText()));
} else {
tooManyArgument(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<SelectHeaderTypeComboBox *>(QStringLiteral("headertypecombobox"));
selectHeaderType->setCode(AutoCreateScriptUtil::listValueToStr(element));
} else if (indexStr == 1) {
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("editaddress"));
edit->setCode(AutoCreateScriptUtil::listValueToStr(element));
} else {
tooManyArgument(tagName, indexStr, 2, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionAddress::setParamWidgetValue too many argument :" << index;
}
++indexStr;
} else if (tagName == QLatin1String("crlf")) {
//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<SelectMatchTypeComboBox *>(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<SelectAddressPartComboBox *>(QStringLiteral("addresspartcombobox"));
selectAddressPart->setCode(AutoCreateScriptUtil::tagValue(lstTagValue.at(0)), name(), error);
}
} else if (lstTagValue.count() == 2) {
QString errorStr;
SelectAddressPartComboBox *selectAddressPart = w->findChild<SelectAddressPartComboBox *>(QStringLiteral("addresspartcombobox"));
selectAddressPart->setCode(AutoCreateScriptUtil::tagValue(lstTagValue.at(0)), name(), errorStr);
if (errorStr.isEmpty()) {
SelectMatchTypeComboBox *selectMatchCombobox = w->findChild<SelectMatchTypeComboBox *>(QStringLiteral("matchtypecombobox"));
selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(lstTagValue.at(1), notCondition), name(), error);
} else { //Problem with order
SelectMatchTypeComboBox *selectMatchCombobox = w->findChild<SelectMatchTypeComboBox *>(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);
qCDebug(LIBKSIEVE_LOG) << "SieveConditionAddress::setParamWidgetValue too many argument :" << lstTagValue.count();
}
#ifdef REMOVE_QDOMELEMENT #ifdef REMOVE_QDOMELEMENT
int index = 0; int index = 0;
int indexStr = 0; int indexStr = 0;
......
...@@ -96,11 +96,79 @@ QString SieveConditionBody::serverNeedsCapability() const ...@@ -96,11 +96,79 @@ QString SieveConditionBody::serverNeedsCapability() const
QString SieveConditionBody::help() const QString SieveConditionBody::help() const
{ {
return i18n( 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.)"); "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) 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(element.readElementText(), notCondition);
} else {
tooManyArgument(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")) {
//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<SelectBodyTypeWidget *>(QStringLiteral("bodytype"));
bodyType->setCode(tagValueList.at(0), QString(), name(), errorStr);
if (errorStr.isEmpty()) {
SelectMatchTypeComboBox *matchType = w->findChild<SelectMatchTypeComboBox *>(QStringLiteral("matchtype"));
matchType->setCode(tagValueList.at(1), name(), error);
} else {
SelectMatchTypeComboBox *matchType = w->findChild<SelectMatchTypeComboBox *>(QStringLiteral("matchtype"));
matchType->setCode(tagValueList.at(0), name(), error);
bodyType->setCode(tagValueList.at(1), QString(), name(), errorStr);
}
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("edit"));
edit->setCode(wasListElement ? strValue.at(0) : AutoCreateScriptUtil::quoteStr(strValue.at(0)));
} else if (strValue.count() == 2) {
SelectBodyTypeWidget *bodyType = w->findChild<SelectBodyTypeWidget *>(QStringLiteral("bodytype"));
bodyType->setCode(tagValueList.at(0), indexStr == 2 ? strValue.at(0) : QString(), name(), errorStr);
SelectMatchTypeComboBox *matchType = w->findChild<SelectMatchTypeComboBox *>(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<AbstractRegexpEditorLineEdit *>(QStringLiteral("edit"));
edit->setCode(indexStr == 1 ? AutoCreateScriptUtil::quoteStr(strValue.at(0)) : AutoCreateScriptUtil::quoteStr(strValue.at(1)));
}
#ifdef REMOVE_QDOMELEMENT #ifdef REMOVE_QDOMELEMENT
int index = 0; int index = 0;
int indexStr = 0; int indexStr = 0;
......
...@@ -121,6 +121,65 @@ QString SieveConditionEnvelope::help() const ...@@ -121,6 +121,65 @@ QString SieveConditionEnvelope::help() const
bool SieveConditionEnvelope::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) 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<SelectAddressPartComboBox *>(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<SelectMatchTypeComboBox *>(QStringLiteral("matchtypecombobox"));
selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(tagValue, notCondition), name(), error);
}
} else if (indexTag == 1) {
SelectMatchTypeComboBox *selectMatchCombobox = w->findChild<SelectMatchTypeComboBox *>(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<SelectHeaderTypeComboBox *>(QStringLiteral("headertypecombobox"));
selectHeaderType->setCode(element.readElementText());
} else if (indexStr == 1) {
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(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<SelectHeaderTypeComboBox *>(QStringLiteral("headertypecombobox"));
selectHeaderType->setCode(AutoCreateScriptUtil::listValueToStr(element));
} else if (indexStr == 1) {
AbstractRegexpEditorLineEdit *edit = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("editaddress"));
edit->setCode(AutoCreateScriptUtil::listValueToStr(element));
}
++indexStr;
} else if (tagName == QLatin1String("crlf")) {
//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);
}
#ifdef REMOVE_QDOMELEMENT #ifdef REMOVE_QDOMELEMENT
int indexTag = 0; int indexTag = 0;
int indexStr = 0; int indexStr = 0;
......
...@@ -140,6 +140,50 @@ QString SieveConditionHasFlag::help() const ...@@ -140,6 +140,50 @@ QString SieveConditionHasFlag::help() const
bool SieveConditionHasFlag::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) bool SieveConditionHasFlag::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error)
{ {
QStringList strList;
QString commentStr;
while (element.readNextStartElement()) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("tag")) {
SelectMatchTypeComboBox *matchTypeCombo = w->findChild<SelectMatchTypeComboBox *>(QStringLiteral("matchtype"));
matchTypeCombo->setCode(AutoCreateScriptUtil::tagValueWithCondition(element.readElementText(), notCondition), name(), error);
} else if (tagName == QLatin1String("str")) {
strList << element.readElementText();
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, element.readElementText());
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionExists::setParamWidgetValue unknown tagName " << tagName;
}
}
if (!commentStr.isEmpty()) {
setComment(commentStr);
}
switch (strList.count()) {
case 1:
{
AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
value->setCode(strList.at(0));
break;
}
case 2:
if (hasVariableSupport) {
QLineEdit *variableName = w->findChild<QLineEdit *>(QStringLiteral("variablename"));
variableName->setText(strList.at(0));
AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
value->setCode(strList.at(1));
} else {
qCDebug(LIBKSIEVE_LOG) << " SieveConditionHasFlag has not variable support";
}
break;
default:
qCDebug(LIBKSIEVE_LOG) << " SieveConditionHasFlag::setParamWidgetValue str list count not correct :" << strList.count();
break;
}
#ifdef REMOVE_QDOMELEMENT #ifdef REMOVE_QDOMELEMENT
QStringList strList; QStringList strList;
QDomNode node = element.firstChild(); QDomNode node = element.firstChild();
......
...@@ -82,7 +82,7 @@ QString SieveConditionHeader::code(QWidget *w) const ...@@ -82,7 +82,7 @@ QString SieveConditionHeader::code(QWidget *w) const
valueStr = AutoCreateScriptUtil::fixListValue(valueStr); valueStr = AutoCreateScriptUtil::fixListValue(valueStr);
return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("header %1 %2 %3").arg(matchString, headerStr, valueStr) return AutoCreateScriptUtil::negativeString(isNegative) + QStringLiteral("header %1 %2 %3").arg(matchString, headerStr, valueStr)
+ AutoCreateScriptUtil::generateConditionComment(comment()); + AutoCreateScriptUtil::generateConditionComment(comment());
} }
QString SieveConditionHeader::help() const QString SieveConditionHeader::help() const
...@@ -92,6 +92,58 @@ QString SieveConditionHeader::help() const ...@@ -92,6 +92,58 @@ QString SieveConditionHeader::help() const
bool SieveConditionHeader::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool notCondition, QString &error) 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<SelectMatchTypeComboBox *>(QStringLiteral("matchtypecombobox"));
selectMatchCombobox->setCode(AutoCreateScriptUtil::tagValueWithCondition(tagValue, notCondition), name(), error);
}
} else if (tagName == QLatin1String("str")) {
if (index == 0) {
SelectHeaderTypeComboBox *headerType = w->findChild<SelectHeaderTypeComboBox *>(QStringLiteral("headertype"));
headerType->setCode(element.readElementText());
} else if (index == 1) {
AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
QString st = AutoCreateScriptUtil::quoteStr(element.readElementText(), true);
value->setCode(st);
} else {
tooManyArgument(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<SelectHeaderTypeComboBox *>(QStringLiteral("headertype"));
headerType->setCode(AutoCreateScriptUtil::listValueToStr(element));
} else if (index == 1) {
AbstractRegexpEditorLineEdit *value = w->findChild<AbstractRegexpEditorLineEdit *>(QStringLiteral("value"));
value->setCode(AutoCreateScriptUtil::listValueToStr(element));
} else {
tooManyArgument(tagName, index, 2, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionHeader::setParamWidgetValue too many argument " << index;
}
++index;
} else if (tagName == QLatin1String("crlf")) {
//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);
}
#ifdef REMOVE_QDOMELEMENT #ifdef REMOVE_QDOMELEMENT
int index = 0; int index = 0;
QDomNode node = element.firstChild(); QDomNode node = element.firstChild();
......
...@@ -124,6 +124,64 @@ QString SieveConditionSpamTest::help() const ...@@ -124,6 +124,64 @@ QString SieveConditionSpamTest::help() const
bool SieveConditionSpamTest::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, bool /*notCondition*/, QString &error) 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")) {
#ifdef QDOMELEMENT_FIXME
node = node.nextSibling();
if (!node.isNull()) {
QDomElement relationalElement = node.toElement();
if (!relationalElement.isNull()) {
if (relationalElement.tagName() == QLatin1String("str")) {
SelectRelationalMatchType *relation = w->findChild<SelectRelationalMatchType *>(QStringLiteral("relation"));
relation->setCode(AutoCreateScriptUtil::tagValue(tagValue), relationalElement.text(), name(), error);
}
}
}
#endif
} else if (tagValue == QLatin1String("comparator")) {
#ifdef QDOMELEMENT_FIXME
node = node.nextSibling();
if (!node.isNull()) {
QDomElement comparatorElement = node.toElement();
if (!comparatorElement.isNull()) {
if (comparatorElement.tagName() == QLatin1String("str")) {
SelectComparatorComboBox *comparator = w->findChild<SelectComparatorComboBox *>(QStringLiteral("comparator"));
comparator->setCode(comparatorElement.text(), name(), error);
}
}
}
#endif
} else if (tagValue == QLatin1String("percent")) {
if (mHasSpamTestPlusSupport) {
QCheckBox *checkbox = w->findChild<QCheckBox *>(QStringLiteral("percent"));
checkbox->setChecked(true);
} else {
serverDoesNotSupportFeatures(QStringLiteral("percent"), error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionSpamTest::setParamWidgetValue server has not percent support";
}
} else {
unknowTagValue(tagValue, error);
qCDebug(LIBKSIEVE_LOG) << " SieveConditionSpamTest::setParamWidgetValue unknown tagvalue " << tagValue;
}
} else if (tagName == QLatin1String("str")) {
QSpinBox *spinbox = w->findChild<QSpinBox *>(QStringLiteral("value"));
spinbox->setValue(element.readElementText().toInt());
} else if (tagName == QLatin1String("crlf")) {
//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);
}
#ifdef REMOVE_QDOMELEMENT #ifdef REMOVE_QDOMELEMENT
QDomNode node = element.firstChild(); QDomNode node = element.firstChild();
QString commentStr; QString commentStr;
......
...@@ -342,6 +342,14 @@ int SieveConditionWidgetLister::conditionNumber() const ...@@ -342,6 +342,14 @@ int SieveConditionWidgetLister::conditionNumber() const
void SieveConditionWidgetLister::loadTest(QXmlStreamReader &element, bool notCondition, QString &error) void SieveConditionWidgetLister::loadTest(QXmlStreamReader &element, bool notCondition, QString &error)
{ {
if (notCondition) {
element.readNextStartElement();
}
if (element.attributes().hasAttribute(QStringLiteral("name"))) {
const QString conditionName = element.attributes().value(QStringLiteral("name")).toString();
SieveConditionWidget *w = qobject_cast<SieveConditionWidget *>(widgets().constLast());
w->setCondition(conditionName, element, notCondition, error);
}
#ifdef REMOVE_QDOMELEMENT #ifdef REMOVE_QDOMELEMENT
QDomElement testElement = element; QDomElement testElement = element;
if (notCondition) { if (notCondition) {
...@@ -358,8 +366,58 @@ void SieveConditionWidgetLister::loadTest(QXmlStreamReader &element, bool notCon ...@@ -358,8 +366,58 @@ void SieveConditionWidgetLister::loadTest(QXmlStreamReader &element, bool notCon
#endif #endif
} }
void SieveConditionWidgetLister::loadScript(QXmlStreamReader &e, bool uniqTest, bool notCondition, QString &error) void SieveConditionWidgetLister::loadScript(QXmlStreamReader &element, bool uniqTest, bool notCondition, QString &error)
{ {
if (uniqTest) {
loadTest(element, notCondition, error);
} else {
bool firstCondition = true;
if (notCondition) {
element.readNextStartElement();
}
while (element.readNextStartElement()) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("testlist")) {
while (element.readNextStartElement()) {
const QStringRef testTagName = element.name();
if (testTagName == QLatin1String("test")) {
if (element.attributes().hasAttribute(QStringLiteral("name"))) {
QString conditionName = element.attributes().value(QStringLiteral("name")).toStrin