Commit 1940eb8b authored by Laurent Montel's avatar Laurent Montel 😁

Start to port action/condition

parent c584bc91
......@@ -403,8 +403,149 @@ void SieveScriptListBox::loadScript(const QString &doc, QString &error)
void SieveScriptListBox::loadBlock(QXmlStreamReader &n, SieveScriptPage *currentPage, ParseSieveScriptTypeBlock typeBlock, QString &error)
{
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();
//qCDebug(LIBKSIEVE_LOG)<<" tagName "<<tagName;
if (tagName == QLatin1String("control")) {
previousElementWasAComment = false;
//Create a new page when before it was "onlyactions"
if (typeBlock == TypeBlockAction) {
currentPage = nullptr;
}
if (e.hasAttribute(QStringLiteral("name"))) {
const QString controlType = e.attribute(QStringLiteral("name"));
//qCDebug(LIBKSIEVE_LOG)<<" controlType"<<controlType;
if (controlType == QLatin1String("if")) {
typeBlock = TypeBlockIf;
if (!currentPage || hasCreatedAIfBlock) {
currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
}
hasCreatedAIfBlock = true;
comment.clear();
currentPage->blockIfWidget()->loadScript(e, false, error);
} else if (controlType == QLatin1String("elsif")) {
typeBlock = TypeBlockElsif;
if (!currentPage) {
qCDebug(LIBKSIEVE_LOG) << " script is not correct missing if block";
currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
}
SieveScriptBlockWidget *blockWidget = currentPage->addScriptBlock(KSieveUi::SieveWidgetPageAbstract::BlockElsIf);
if (blockWidget) {
blockWidget->loadScript(e, false, error);
}
} else if (controlType == QLatin1String("else")) {
typeBlock = TypeBlockElse;
if (!currentPage) {
currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
qCDebug(LIBKSIEVE_LOG) << " script is not correct missing if block";
}
SieveScriptBlockWidget *blockWidget = currentPage->addScriptBlock(KSieveUi::SieveWidgetPageAbstract::BlockElse);
if (blockWidget) {
blockWidget->loadScript(e, false, error);
}
//We are sure that we can't have another elsif
currentPage = nullptr;
} else if (controlType == QLatin1String("foreverypart")) {
typeBlock = TypeBlockForeachBlock;
if (!currentPage) {
currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
comment.clear();
}
if (currentPage->forEveryPartWidget()) {
currentPage->forEveryPartWidget()->loadScript(e, error);
} else {
error += i18n("forEveryPart is not supported by your server") + QLatin1Char('\n');
}
//TODO verify it.
QDomNode block = e.firstChildElement(QStringLiteral("block")).firstChild();
loadBlock(block, currentPage, typeBlock, error);
} else if (controlType == QLatin1String("require")) {
//Nothing. autogenerated
} else {
qCDebug(LIBKSIEVE_LOG) << " unknown controlType :" << controlType;
}
}
} else if (tagName == QLatin1String("comment")) {
previousElementWasAComment = true;
if (e.hasAttribute(QStringLiteral("hash"))) {
//TODO
} else if (e.hasAttribute(QStringLiteral("bracket"))) {
//TODO
}
QString str(e.text());
if (str.contains(defaultScriptName())) {
scriptName = str.remove(defaultScriptName());
} else {
if (!comment.isEmpty()) {
comment += QLatin1Char('\n');
}
comment += e.text();
}
} else if (tagName == QLatin1String("action")) {
previousElementWasAComment = false;
if (e.hasAttribute(QStringLiteral("name"))) {
const QString actionName = e.attribute(QStringLiteral("name"));
if (actionName == QLatin1String("include")) {
if (!currentPage || (typeBlock == TypeBlockIf) || (typeBlock == TypeBlockElse) || (typeBlock == TypeBlockElsif)) {
currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
comment.clear();
}
typeBlock = TypeBlockInclude;
if (currentPage->includeWidget()) {
currentPage->includeWidget()->loadScript(e, error);
} else {
qCDebug(LIBKSIEVE_LOG) << " include not supported";
}
} else if (actionName == QLatin1String("global")) {
if (!currentPage || (typeBlock == TypeBlockIf) || (typeBlock == TypeBlockElse) || (typeBlock == TypeBlockElsif)) {
currentPage = createNewScript(scriptName.isEmpty() ? createUniqName() : scriptName, comment);
comment.clear();
}
typeBlock = TypeBlockGlobal;
if (currentPage->globalVariableWidget()) {
currentPage->globalVariableWidget()->loadScript(e, error);
} else {
qCDebug(LIBKSIEVE_LOG) << " globalVariable not supported";
}
} else if (actionName == QLatin1String("set") && (typeBlock == TypeBlockGlobal)) {
if (currentPage->globalVariableWidget()) {
if (!currentPage->globalVariableWidget()->loadSetVariable(e, 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);
}
} else {
qCDebug(LIBKSIEVE_LOG) << " set not supported";
}
} else {
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);
}
}
} else if (tagName == QLatin1String("crlf")) {
//If it was a comment previously you will create a \n
if (previousElementWasAComment) {
comment += QLatin1Char('\n');
}
} else {
qCDebug(LIBKSIEVE_LOG) << " unknown tagname" << tagName;
}
}
n = n.nextSibling();
}
#ifdef REMOVE_QDOMELEMENT
QString scriptName;
......
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