Commit effe13aa authored by Laurent Montel's avatar Laurent Montel 😁

Port load block

parent cd26efb0
......@@ -403,15 +403,12 @@ void SieveScriptListBox::loadScript(const QString &doc, QString &error)
void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *currentPage, ParseSieveScriptTypeBlock typeBlock, QString &error)
{
#if 0
QString scriptName;
QString comment;
bool hasCreatedAIfBlock = false;
bool previousElementWasAComment = false;
while (n.readNextStartElement()) {
QDomElement e = n.toElement();
if (!e.isNull()) {
const QStringRef tagName = e.tagName();
const QStringRef tagName = n.name();
//qCDebug(LIBKSIEVE_LOG)<<" tagName "<<tagName;
if (tagName == QLatin1String("control")) {
previousElementWasAComment = false;
......@@ -419,8 +416,8 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
if (typeBlock == TypeBlockAction) {
currentPage = nullptr;
}
if (e.hasAttribute(QStringLiteral("name"))) {
const QString controlType = e.attribute(QStringLiteral("name"));
if (n.attributes().hasAttribute(QStringLiteral("name"))) {
const QString controlType =n.attributes().value(QStringLiteral("name")).toString();
//qCDebug(LIBKSIEVE_LOG)<<" controlType"<<controlType;
if (controlType == QLatin1String("if")) {
typeBlock = TypeBlockIf;
......@@ -429,7 +426,7 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
}
hasCreatedAIfBlock = true;
comment.clear();
currentPage->blockIfWidget()->loadScript(e, false, error);
currentPage->blockIfWidget()->loadScript(n, false, error);
} else if (controlType == QLatin1String("elsif")) {
typeBlock = TypeBlockElsif;
if (!currentPage) {
......@@ -438,7 +435,7 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
}
SieveScriptBlockWidget *blockWidget = currentPage->addScriptBlock(KSieveUi::SieveWidgetPageAbstract::BlockElsIf);
if (blockWidget) {
blockWidget->loadScript(e, false, error);
blockWidget->loadScript(n, false, error);
}
} else if (controlType == QLatin1String("else")) {
typeBlock = TypeBlockElse;
......@@ -448,7 +445,7 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
}
SieveScriptBlockWidget *blockWidget = currentPage->addScriptBlock(KSieveUi::SieveWidgetPageAbstract::BlockElse);
if (blockWidget) {
blockWidget->loadScript(e, false, error);
blockWidget->loadScript(n, false, error);
}
//We are sure that we can't have another elsif
currentPage = nullptr;
......@@ -459,13 +456,15 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
comment.clear();
}
if (currentPage->forEveryPartWidget()) {
currentPage->forEveryPartWidget()->loadScript(e, error);
currentPage->forEveryPartWidget()->loadScript(n, error);
} else {
error += i18n("forEveryPart is not supported by your server") + QLatin1Char('\n');
}
//TODO verify it.
#ifdef QDOMELEMENT_FIXME
QDomNode block = e.firstChildElement(QStringLiteral("block")).firstChild();
loadBlock(block, currentPage, typeBlock, error);
#endif
} else if (controlType == QLatin1String("require")) {
//Nothing. autogenerated
} else {
......@@ -474,24 +473,26 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
}
} else if (tagName == QLatin1String("comment")) {
previousElementWasAComment = true;
#ifdef QDOMELEMENT_FIXME
if (e.hasAttribute(QStringLiteral("hash"))) {
//TODO
} else if (e.hasAttribute(QStringLiteral("bracket"))) {
//TODO
}
QString str(e.text());
#endif
QString str(n.readElementText());
if (str.contains(defaultScriptName())) {
scriptName = str.remove(defaultScriptName());
} else {
if (!comment.isEmpty()) {
comment += QLatin1Char('\n');
}
comment += e.text();
comment += n.readElementText();
}
} else if (tagName == QLatin1String("action")) {
previousElementWasAComment = false;
if (e.hasAttribute(QStringLiteral("name"))) {
const QString actionName = e.attribute(QStringLiteral("name"));
if (n.attributes().hasAttribute(QStringLiteral("name"))) {
const QString actionName = n.attributes().value(QStringLiteral("name")).toString();
if (actionName == QLatin1String("include")) {
if (!currentPage || (typeBlock == TypeBlockIf) || (typeBlock == TypeBlockElse) || (typeBlock == TypeBlockElsif)) {
currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
......@@ -499,7 +500,7 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
}
typeBlock = TypeBlockInclude;
if (currentPage->includeWidget()) {
currentPage->includeWidget()->loadScript(e, error);
currentPage->includeWidget()->loadScript(n, error);
} else {
qCDebug(LIBKSIEVE_LOG) << " include not supported";
}
......@@ -510,20 +511,20 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
}
typeBlock = TypeBlockGlobal;
if (currentPage->globalVariableWidget()) {
currentPage->globalVariableWidget()->loadScript(e, error);
currentPage->globalVariableWidget()->loadScript(n, error);
} else {
qCDebug(LIBKSIEVE_LOG) << " globalVariable not supported";
}
} else if (actionName == QLatin1String("set") && (typeBlock == TypeBlockGlobal)) {
if (currentPage->globalVariableWidget()) {
if (!currentPage->globalVariableWidget()->loadSetVariable(e, error)) {
if (!currentPage->globalVariableWidget()->loadSetVariable(n, error)) {
qCDebug(LIBKSIEVE_LOG) << "It's not a global variable";
if (!currentPage || (typeBlock == TypeBlockIf) || (typeBlock == TypeBlockElse) || (typeBlock == TypeBlockElsif)) {
currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
}
typeBlock = TypeBlockAction;
comment.clear();
currentPage->blockIfWidget()->loadScript(e, true, error);
currentPage->blockIfWidget()->loadScript(n, true, error);
}
} else {
qCDebug(LIBKSIEVE_LOG) << " set not supported";
......@@ -534,7 +535,7 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
}
typeBlock = TypeBlockAction;
comment.clear();
currentPage->blockIfWidget()->loadScript(e, true, error);
currentPage->blockIfWidget()->loadScript(n, true, error);
}
}
} else if (tagName == QLatin1String("crlf")) {
......@@ -545,10 +546,7 @@ void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *current
} else {
qCDebug(LIBKSIEVE_LOG) << " unknown tagname" << tagName;
}
}
n = n.nextSibling();
}
#endif
#ifdef REMOVE_QDOMELEMENT
QString scriptName;
QString comment;
......
......@@ -24,8 +24,6 @@
#include <QListWidgetItem>
#include "ksieveui_private_export.h"
class QListWidget;
class QDomDocument;
class QDomNode;
class QPushButton;
class QXmlStreamReader;
......
......@@ -614,7 +614,6 @@ void SieveEditorWidget::slotSwitchMode()
case TextMode:
{
bool result = false;
//Remove QDomDocument here
const QString doc = ParsingUtil::parseScript(mTextModeWidget->currentscript(), result);
if (result) {
QString error;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment