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

Porting ++ (8success/71 failed) still in progress

parent 2d108811
......@@ -365,6 +365,68 @@ int SieveActionWidgetLister::actionNumber() const
void SieveActionWidgetLister::loadScript(QXmlStreamReader &element, bool onlyActions, QString &error)
{
QString comment;
if (onlyActions) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("action")) {
if (element.attributes().hasAttribute(QStringLiteral("name"))) {
const QString actionName = element.attributes().value(QStringLiteral("name")).toString();
SieveActionWidget *w = qobject_cast<SieveActionWidget *>(widgets().constLast());
if (w->isConfigurated()) {
addWidgetAfterThisWidget(widgets().constLast());
w = qobject_cast<SieveActionWidget *>(widgets().constLast());
}
w->setAction(actionName, element, comment, error);
//comment.clear();
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else {
qCDebug(LIBKSIEVE_LOG) << " SieveActionWidgetLister::loadScript don't have name attribute " << tagName;
}
} else {
qCDebug(LIBKSIEVE_LOG) << " SieveActionWidgetLister::loadScript Unknow tag name " << tagName;
}
} else {
bool firstAction = true;
bool previousActionWasAComment = false;
while (element.readNextStartElement()) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("action") || tagName == QLatin1String("control") /*for break action*/) {
if (element.attributes().hasAttribute(QStringLiteral("name"))) {
const QString actionName = element.attributes().value(QStringLiteral("name")).toString();
if (tagName == QLatin1String("control") && actionName == QLatin1String("if")) {
qCDebug(LIBKSIEVE_LOG) << "We found an loop if in a loop if. Not supported";
error += i18n("We detected a loop if in a loop if. It's not supported") + QLatin1Char('\n');
}
if (firstAction) {
firstAction = false;
} else {
addWidgetAfterThisWidget(widgets().constLast());
}
SieveActionWidget *w = qobject_cast<SieveActionWidget *>(widgets().constLast());
w->setAction(actionName, element, comment, error);
comment.clear();
} else {
qCDebug(LIBKSIEVE_LOG) << " SieveActionWidgetLister::loadScript don't have name attribute " << tagName;
}
previousActionWasAComment = false;
} else if (tagName == QLatin1String("comment")) {
if (!comment.isEmpty()) {
comment += QLatin1Char('\n');
}
previousActionWasAComment = true;
comment += element.readElementText();
} else if (tagName == QLatin1String("crlf")) {
//Add new line if previous action was a comment
if (previousActionWasAComment) {
comment += QLatin1Char('\n');
}
} else {
qCDebug(LIBKSIEVE_LOG) << " SieveActionWidgetLister::loadScript unknown tagName " << tagName;
}
}
}
#ifdef REMOVE_QDOMELEMENT
QString comment;
if (onlyActions) {
......
......@@ -318,6 +318,36 @@ void SieveGlobalVariableLister::loadScript(QXmlStreamReader &element, QString &e
bool SieveGlobalVariableLister::loadSetVariable(QXmlStreamReader &element, QString & /*error*/)
{
QString variableName;
QString variableValue;
int index = 0;
while (element.readNextStartElement()) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("str")) {
if (index == 0) {
variableName = element.readElementText();
} else if (index == 1) {
variableValue = element.readElementText();
} else {
qCDebug(LIBKSIEVE_LOG) << " SieveGlobalVariableLister::loadSetVariable too many argument:" << index;
}
++index;
} else {
qCDebug(LIBKSIEVE_LOG) << " SieveGlobalVariableLister::loadSetVariable unknown tagName " << tagName;
}
}
const QList<QWidget *> lstWidget = widgets();
bool globalVariableFound = false;
for (QWidget *widget : lstWidget) {
SieveGlobalVariableActionWidget *w = static_cast<SieveGlobalVariableActionWidget *>(widget);
if (w->variableName() == variableName) {
w->setVariableValue(variableValue);
globalVariableFound = true;
}
}
return globalVariableFound;
#ifdef REMOVE_QDOMELEMENT
QString variableName;
QString variableValue;
......@@ -353,8 +383,5 @@ bool SieveGlobalVariableLister::loadSetVariable(QXmlStreamReader &element, QStri
}
}
return globalVariableFound;
#else
bool globalVariableFound = false;
return globalVariableFound;
#endif
}
......@@ -267,11 +267,7 @@ void SieveIncludeWidget::generatedScript(QString &script, QStringList &requires,
void SieveIncludeWidget::loadScript(QXmlStreamReader &element, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
mIncludeLister->loadScript(element, error);
#else
mIncludeLister->loadScript(element, error);
#endif
}
SieveIncludeWidgetLister::SieveIncludeWidgetLister(QWidget *parent)
......
......@@ -248,6 +248,42 @@ void SieveScriptBlockWidget::updateCondition()
void SieveScriptBlockWidget::loadScript(QXmlStreamReader &element, bool onlyActions, QString &error)
{
if (onlyActions) {
mScriptActionLister->loadScript(element, true, error);
mMatchCondition = AllCondition;
updateCondition();
} else {
bool uniqueTest = false;
while (element.readNextStartElement()) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("test")) {
bool notCondition = false;
if (element.attributes().hasAttribute(QStringLiteral("name"))) {
const QString typeCondition = element.attributes().value(QStringLiteral("name")).toString();
if (typeCondition == QLatin1String("anyof")) {
mMatchCondition = OrCondition;
} else if (typeCondition == QLatin1String("allof")) {
mMatchAll->setChecked(true);
} else {
if (typeCondition == QLatin1String("not")) {
notCondition = true;
}
uniqueTest = true;
mMatchCondition = OrCondition;
}
updateCondition();
}
mScriptConditionLister->loadScript(element, uniqueTest, notCondition, error);
} else if (tagName == QLatin1String("block")) {
mScriptActionLister->loadScript(element, false, error);
} else {
if (tagName != QLatin1String("crlf")) {
qCDebug(LIBKSIEVE_LOG) << " e.tag" << tagName;
}
}
}
}
#ifdef REMOVE_QDOMELEMENT
if (onlyActions) {
mScriptActionLister->loadScript(element, true, 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