summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2017-06-02 13:18:01 +0200
committerMontel Laurent <[email protected]>2017-06-02 13:18:01 +0200
commit17d441b665bb7412f8b7f26b2daea91e1127ea8c (patch)
tree370086df6104ee86da3fa6d91e94dcefacd8bf35
parent52b8bbea5712cb96f062a61d092c3bcd4533882e (diff)
Fix comment after true/false condition
-rw-r--r--src/ksieveui/autocreatescripts/autotests/data/test-comment9-ref.siv9
-rw-r--r--src/ksieveui/autocreatescripts/autotests/data/test-comment9.siv8
-rw-r--r--src/ksieveui/autocreatescripts/autotests/sieveeditorgraphicalmodewidgettest.cpp1
-rw-r--r--src/ksieveui/autocreatescripts/sieveconditions/sieveconditionfalse.cpp29
-rw-r--r--src/ksieveui/autocreatescripts/sieveconditions/sieveconditiontrue.cpp30
5 files changed, 71 insertions, 6 deletions
diff --git a/src/ksieveui/autocreatescripts/autotests/data/test-comment9-ref.siv b/src/ksieveui/autocreatescripts/autotests/data/test-comment9-ref.siv
new file mode 100644
index 0000000..37cdbc0
--- /dev/null
+++ b/src/ksieveui/autocreatescripts/autotests/data/test-comment9-ref.siv
@@ -0,0 +1,9 @@
+#SCRIPTNAME: Script part 0
+if false # allof(not header :contains "X-Spam-Flag" "YES")
+{
+}
+
+#SCRIPTNAME: Script part 1
+if true # allof(not header :contains "X-Spam-Flag" "YES")
+{
+} \ No newline at end of file
diff --git a/src/ksieveui/autocreatescripts/autotests/data/test-comment9.siv b/src/ksieveui/autocreatescripts/autotests/data/test-comment9.siv
new file mode 100644
index 0000000..84727c7
--- /dev/null
+++ b/src/ksieveui/autocreatescripts/autotests/data/test-comment9.siv
@@ -0,0 +1,8 @@
+if false # allof(not header :contains "X-Spam-Flag" "YES")
+{
+}
+
+if true # allof(not header :contains "X-Spam-Flag" "YES")
+{
+}
+
diff --git a/src/ksieveui/autocreatescripts/autotests/sieveeditorgraphicalmodewidgettest.cpp b/src/ksieveui/autocreatescripts/autotests/sieveeditorgraphicalmodewidgettest.cpp
index 4fbae1e..100dad9 100644
--- a/src/ksieveui/autocreatescripts/autotests/sieveeditorgraphicalmodewidgettest.cpp
+++ b/src/ksieveui/autocreatescripts/autotests/sieveeditorgraphicalmodewidgettest.cpp
@@ -208,6 +208,7 @@ void SieveEditorGraphicalModeWidgetTest::shouldLoadScripts_data()
QTest::newRow("test-comment6") << QStringLiteral("test-comment6") << false << true;
QTest::newRow("test-comment7") << QStringLiteral("test-comment7") << false << true;
QTest::newRow("test-comment8") << QStringLiteral("test-comment8") << false << true;
+ QTest::newRow("test-comment9") << QStringLiteral("test-comment9") << false << true;
}
QTEST_MAIN(SieveEditorGraphicalModeWidgetTest)
diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionfalse.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionfalse.cpp
index 275c607..a0da718 100644
--- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionfalse.cpp
+++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditionfalse.cpp
@@ -18,11 +18,14 @@
*/
#include "sieveconditionfalse.h"
#include "editor/sieveeditorutil.h"
+#include "libksieve_debug.h"
+#include "autocreatescripts/autocreatescriptutil_p.h"
#include <KLocalizedString>
#include <QHBoxLayout>
#include <QLabel>
+#include <QDomNode>
using namespace KSieveUi;
@@ -45,7 +48,7 @@ QWidget *SieveConditionFalse::createParamWidget(QWidget *parent) const
QString SieveConditionFalse::code(QWidget *) const
{
- return QStringLiteral("false");
+ return QStringLiteral("false") + AutoCreateScriptUtil::generateConditionComment(comment());
}
QString SieveConditionFalse::help() const
@@ -53,9 +56,29 @@ QString SieveConditionFalse::help() const
return i18n("The \"false\" test always evaluates to false.");
}
-bool SieveConditionFalse::setParamWidgetValue(const QDomElement &, QWidget *, bool, QString &)
+bool SieveConditionFalse::setParamWidgetValue(const QDomElement &element, QWidget *, bool, QString &error)
{
- //Nothing
+ QDomNode node = element.firstChild();
+ QString commentStr;
+ while (!node.isNull()) {
+ QDomElement e = node.toElement();
+ if (!e.isNull()) {
+ const QString tagName = e.tagName();
+ if (tagName == QLatin1String("comment")) {
+ commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, e.text());
+ } else if (tagName == QLatin1String("crlf")) {
+ //nothing
+ } else {
+ unknownTag(tagName, error);
+ qCDebug(LIBKSIEVE_LOG) << " SieveConditionFalse::setParamWidgetValue unknown tagName " << tagName;
+ }
+ }
+ node = node.nextSibling();
+ }
+ if (!commentStr.isEmpty()) {
+ setComment(commentStr);
+ }
+
return true;
}
diff --git a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditiontrue.cpp b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditiontrue.cpp
index ba4aa91..c827a99 100644
--- a/src/ksieveui/autocreatescripts/sieveconditions/sieveconditiontrue.cpp
+++ b/src/ksieveui/autocreatescripts/sieveconditions/sieveconditiontrue.cpp
@@ -18,8 +18,12 @@
*/
#include "sieveconditiontrue.h"
#include "editor/sieveeditorutil.h"
+#include "libksieve_debug.h"
+#include "autocreatescripts/autocreatescriptutil_p.h"
+
#include <KLocalizedString>
+#include <QDomNode>
#include <QHBoxLayout>
#include <QLabel>
@@ -44,7 +48,7 @@ QWidget *SieveConditionTrue::createParamWidget(QWidget *parent) const
QString SieveConditionTrue::code(QWidget *) const
{
- return QStringLiteral("true");
+ return QStringLiteral("true") + AutoCreateScriptUtil::generateConditionComment(comment());
}
QString SieveConditionTrue::help() const
@@ -52,9 +56,29 @@ QString SieveConditionTrue::help() const
return i18n("The \"true\" test always evaluates to true.");
}
-bool SieveConditionTrue::setParamWidgetValue(const QDomElement &, QWidget *, bool, QString &)
+bool SieveConditionTrue::setParamWidgetValue(const QDomElement &element, QWidget *, bool, QString &error)
{
- //Nothing
+ QDomNode node = element.firstChild();
+ QString commentStr;
+ while (!node.isNull()) {
+ QDomElement e = node.toElement();
+ if (!e.isNull()) {
+ const QString tagName = e.tagName();
+ if (tagName == QLatin1String("comment")) {
+ commentStr = AutoCreateScriptUtil::loadConditionComment(commentStr, e.text());
+ } else if (tagName == QLatin1String("crlf")) {
+ //nothing
+ } else {
+ unknownTag(tagName, error);
+ qCDebug(LIBKSIEVE_LOG) << " SieveConditionTrue::setParamWidgetValue unknown tagName " << tagName;
+ }
+ }
+ node = node.nextSibling();
+ }
+ if (!commentStr.isEmpty()) {
+ setComment(commentStr);
+ }
+
return true;
}