Commit 7a3a6670 authored by Laurent Montel's avatar Laurent Montel 😁

Comment code, porting

parent 1940eb8b
......@@ -24,8 +24,6 @@
#include <QDialog>
class QDomDocument;
namespace KSieveUi {
class SieveImapAccountSettings;
class SieveEditorGraphicalModeWidget;
......
......@@ -131,8 +131,9 @@ QString AutoCreateScriptUtil::tagValue(const QString &tag)
return QLatin1Char(':') + tag;
}
QString AutoCreateScriptUtil::strValue(QDomNode &node)
QString AutoCreateScriptUtil::strValue(QXmlStreamReader &node)
{
#ifdef REMOVE_QDOMELEMENT
node = node.nextSibling();
QDomElement textElement = node.toElement();
if (!textElement.isNull()) {
......@@ -141,18 +142,20 @@ QString AutoCreateScriptUtil::strValue(QDomNode &node)
return textElement.text();
}
}
#endif
return QString();
}
QString AutoCreateScriptUtil::listValueToStr(const QDomElement &element)
QString AutoCreateScriptUtil::listValueToStr(QXmlStreamReader &element)
{
const QStringList lst = AutoCreateScriptUtil::listValue(element);
//Don't add semicolon
return createList(lst, false);
}
QStringList AutoCreateScriptUtil::listValue(const QDomElement &element)
QStringList AutoCreateScriptUtil::listValue(QXmlStreamReader &element)
{
#ifdef REMOVE_QDOMELEMENT
QStringList lst;
QDomNode node = element.firstChild();
while (!node.isNull()) {
......@@ -166,6 +169,8 @@ QStringList AutoCreateScriptUtil::listValue(const QDomElement &element)
node = node.nextSibling();
}
return lst;
#endif
return {};
}
QString AutoCreateScriptUtil::fixListValue(QString valueStr)
......
......@@ -22,7 +22,7 @@
#include <QString>
#include <QStringList>
#include <QDomNode>
#include <QXmlStreamReader>
#include <KSieveUi/AbstractRegexpEditorLineEdit>
namespace KSieveUi {
namespace AutoCreateScriptUtil {
......@@ -34,9 +34,9 @@ QString createAddressList(const QString &str, bool addSemiColon = true);
QString negativeString(bool isNegative);
QString tagValueWithCondition(const QString &tag, bool notCondition);
QString tagValue(const QString &tag);
QString strValue(QDomNode &node);
QStringList listValue(const QDomElement &element);
QString listValueToStr(const QDomElement &element);
QString strValue(QXmlStreamReader &node);
QStringList listValue(QXmlStreamReader &element);
QString listValueToStr(QXmlStreamReader &element);
QString fixListValue(QString valueStr);
QString quoteStr(QString str, bool protectSlash = true);
void comboboxItemNotFound(const QString &searchItem, const QString &name, QString &error);
......
......@@ -99,7 +99,7 @@ QString SieveAction::help() const
return QString();
}
bool SieveAction::setParamWidgetValue(const QDomElement &, QWidget *, QString &)
bool SieveAction::setParamWidgetValue(QXmlStreamReader &, QWidget *, QString &)
{
return true;
}
......@@ -114,9 +114,9 @@ void SieveAction::setComment(const QString &comment)
mComment = comment;
}
void SieveAction::unknownTag(const QString &tag, QString &error)
void SieveAction::unknownTag(const QStringRef &tag, QString &error)
{
error += i18n("An unknown tag \"%1\" was found during parsing action \"%2\".", tag, name()) + QLatin1Char('\n');
error += i18n("An unknown tag \"%1\" was found during parsing action \"%2\".", *tag.string(), name()) + QLatin1Char('\n');
}
void SieveAction::unknowTagValue(const QString &tagValue, QString &error)
......
......@@ -21,7 +21,7 @@
#include <QObject>
#include <QUrl>
class QDomElement;
class QXmlStreamReader;
namespace KSieveUi {
class SieveImapAccountSettings;
class SieveEditorGraphicalModeWidget;
......@@ -37,7 +37,7 @@ public:
virtual QWidget *createParamWidget(QWidget *parent) const;
virtual bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error);
virtual bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error);
virtual QString code(QWidget *) const;
......@@ -54,7 +54,7 @@ public:
void setComment(const QString &comment);
void unknownTag(const QString &tag, QString &error);
void unknownTag(const QStringRef &tag, QString &error);
void unknowTagValue(const QString &tagValue, QString &error);
void tooManyArgument(const QString &tagName, int index, int maxValue, QString &error);
void serverDoesNotSupportFeatures(const QString &feature, QString &error);
......
......@@ -22,7 +22,7 @@
#include "widgets/selectflagswidget.h"
#include <QHBoxLayout>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
using namespace KSieveUi;
......@@ -44,8 +44,26 @@ QWidget *SieveActionAbstractFlags::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionAbstractFlags::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionAbstractFlags::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
while (element.readNextStartElement()) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("list")) {
SelectFlagsWidget *flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
flagsWidget->setFlags(AutoCreateScriptUtil::listValue(element));
} else if (tagName == QLatin1String("str")) {
SelectFlagsWidget *flagsWidget = w->findChild<SelectFlagsWidget *>(QStringLiteral("flagswidget"));
flagsWidget->setFlags(QStringList() << element.readElementText());
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << " SieveActionAbstractFlags::setParamWidgetValue unknown tag :" << tagName;
}
}
#ifdef REMOVE_QDOMELEMENT
QDomNode node = element.firstChild();
while (!node.isNull()) {
QDomElement e = node.toElement();
......@@ -68,6 +86,7 @@ bool SieveActionAbstractFlags::setParamWidgetValue(const QDomElement &element, Q
}
node = node.nextSibling();
}
#endif
return true;
}
......
......@@ -28,7 +28,7 @@ public:
SieveActionAbstractFlags(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, const QString &name, const QString &label, QObject *parent = nullptr);
QWidget *createParamWidget(QWidget *parent) const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
QString code(QWidget *) const override;
QStringList needRequires(QWidget *parent) const override;
......
......@@ -25,7 +25,7 @@
#include <QWidget>
#include <QLabel>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
#include <QGridLayout>
......@@ -67,8 +67,9 @@ QWidget *SieveActionAddHeader::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionAddHeader::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionAddHeader::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
int index = 0;
QDomNode node = element.firstChild();
while (!node.isNull()) {
......@@ -101,6 +102,7 @@ bool SieveActionAddHeader::setParamWidgetValue(const QDomElement &element, QWidg
}
node = node.nextSibling();
}
#endif
return true;
}
......
......@@ -28,7 +28,7 @@ public:
explicit SieveActionAddHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = nullptr);
QString code(QWidget *w) const override;
QWidget *createParamWidget(QWidget *parent) const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
QString help() const override;
QUrl href() const override;
};
......
......@@ -25,7 +25,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
using namespace KSieveUi;
......@@ -51,8 +51,32 @@ QWidget *SieveActionBreak::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionBreak::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionBreak::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
while (element.readNextStartElement()) {
const QStringRef tagName = element.name();
if (tagName == QLatin1String("tag")) {
const QString tagValue = element.readElementText();
if (tagValue == QLatin1String("name")) {
QLineEdit *name = w->findChild<QLineEdit *>(QStringLiteral("name"));
name->setText(AutoCreateScriptUtil::strValue(element));
} else {
unknowTagValue(tagValue, error);
qCDebug(LIBKSIEVE_LOG) << " SieveActionBreak::setParamWidgetValue unknown tagValue " << tagValue;
}
} else if (tagName == QLatin1String("str")) {
//Nothing
} else if (tagName == QLatin1String("crlf")) {
//nothing
} else if (tagName == QLatin1String("comment")) {
//implement in the future ?
} else {
unknownTag(tagName, error);
qCDebug(LIBKSIEVE_LOG) << "SieveActionBreak::setParamWidgetValue unknown tag " << tagName;
}
}
#ifdef REMOVE_QDOMELEMENT
QDomNode node = element.firstChild();
while (!node.isNull()) {
QDomElement e = node.toElement();
......@@ -80,6 +104,7 @@ bool SieveActionBreak::setParamWidgetValue(const QDomElement &element, QWidget *
}
node = node.nextSibling();
}
#endif
return true;
}
......
......@@ -32,7 +32,7 @@ public:
bool needCheckIfServerHasCapability() const override;
QString serverNeedsCapability() const override;
QWidget *createParamWidget(QWidget *parent) const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
QUrl href() const override;
};
}
......
......@@ -25,7 +25,7 @@
#include <QLabel>
#include "libksieve_debug.h"
#include <QDomNode>
#include <QXmlStreamReader>
#include <QGridLayout>
using namespace KSieveUi;
......@@ -68,8 +68,9 @@ QWidget *SieveActionConvert::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionConvert::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionConvert::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
int index = 0;
QDomNode node = element.firstChild();
while (!node.isNull()) {
......@@ -102,6 +103,7 @@ bool SieveActionConvert::setParamWidgetValue(const QDomElement &element, QWidget
}
node = node.nextSibling();
}
#endif
return true;
}
......
......@@ -32,7 +32,7 @@ public:
QStringList needRequires(QWidget *parent) const override;
bool needCheckIfServerHasCapability() const override;
QString serverNeedsCapability() const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
QString help() const override;
QUrl href() const override;
};
......
......@@ -26,7 +26,7 @@
#include <QWidget>
#include <QLabel>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
#include <QGridLayout>
......@@ -67,8 +67,9 @@ QWidget *SieveActionDeleteHeader::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionDeleteHeader::parseValue(const QDomElement &element, QWidget *w, QString &error, bool isNegative)
bool SieveActionDeleteHeader::parseValue(QXmlStreamReader &element, QWidget *w, QString &error, bool isNegative)
{
#ifdef REMOVE_QDOMELEMENT
int index = 0;
QDomNode node = element.firstChild();
while (!node.isNull()) {
......@@ -106,10 +107,11 @@ bool SieveActionDeleteHeader::parseValue(const QDomElement &element, QWidget *w,
}
node = node.nextSibling();
}
#endif
return true;
}
bool SieveActionDeleteHeader::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionDeleteHeader::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
return parseValue(element, w, error, false);
}
......
......@@ -28,12 +28,12 @@ public:
explicit SieveActionDeleteHeader(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = nullptr);
QString code(QWidget *w) const override;
QWidget *createParamWidget(QWidget *parent) const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
QString help() const override;
QUrl href() const override;
QStringList needRequires(QWidget *parent) const override;
private:
bool parseValue(const QDomElement &element, QWidget *w, QString &error, bool isNegative);
bool parseValue(QXmlStreamReader &element, QWidget *w, QString &error, bool isNegative);
};
}
......
......@@ -25,7 +25,7 @@
#include <QLineEdit>
#include <QLabel>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
#include <QGridLayout>
......@@ -69,8 +69,9 @@ QWidget *SieveActionEnclose::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionEnclose::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionEnclose::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
QDomNode node = element.firstChild();
while (!node.isNull()) {
QDomElement e = node.toElement();
......@@ -108,6 +109,7 @@ bool SieveActionEnclose::setParamWidgetValue(const QDomElement &element, QWidget
}
node = node.nextSibling();
}
#endif
return true;
}
......
......@@ -28,7 +28,7 @@ public:
explicit SieveActionEnclose(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent = nullptr);
QString code(QWidget *) const override;
QWidget *createParamWidget(QWidget *parent) const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
QStringList needRequires(QWidget *parent) const override;
bool needCheckIfServerHasCapability() const override;
QString serverNeedsCapability() const override;
......
......@@ -25,7 +25,7 @@
#include <QLabel>
#include <QHBoxLayout>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
using namespace KSieveUi;
......@@ -50,8 +50,9 @@ QWidget *SieveActionEReject::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionEReject::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionEReject::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
QDomNode node = element.firstChild();
while (!node.isNull()) {
QDomElement e = node.toElement();
......@@ -72,6 +73,7 @@ bool SieveActionEReject::setParamWidgetValue(const QDomElement &element, QWidget
}
node = node.nextSibling();
}
#endif
return true;
}
......
......@@ -30,7 +30,7 @@ public:
QWidget *createParamWidget(QWidget *parent) const override;
QString code(QWidget *) const override;
QStringList needRequires(QWidget *parent) const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
bool needCheckIfServerHasCapability() const override;
......
......@@ -24,7 +24,7 @@
#include <QLabel>
#include <QSpinBox>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
#include <QGridLayout>
......@@ -62,8 +62,9 @@ QWidget *SieveActionExtractText::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionExtractText::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionExtractText::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
QDomNode node = element.firstChild();
while (!node.isNull()) {
QDomElement e = node.toElement();
......@@ -88,6 +89,7 @@ bool SieveActionExtractText::setParamWidgetValue(const QDomElement &element, QWi
}
node = node.nextSibling();
}
#endif
return true;
}
......
......@@ -30,7 +30,7 @@ public:
QString code(QWidget *) const override;
QStringList needRequires(QWidget *parent) const override;
bool needCheckIfServerHasCapability() const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
QString serverNeedsCapability() const override;
QString help() const override;
QUrl href() const override;
......
......@@ -29,7 +29,7 @@
#include <QHBoxLayout>
#include "libksieve_debug.h"
#include <KPluginFactory>
#include <QDomNode>
#include <QXmlStreamReader>
//Add support for adding flags
using namespace KSieveUi;
SieveActionFileInto::SieveActionFileInto(SieveEditorGraphicalModeWidget *sieveGraphicalModeWidget, QObject *parent)
......@@ -59,8 +59,9 @@ QString SieveActionFileInto::code(QWidget *w) const
return result + QStringLiteral("\"%1\";").arg(text);
}
bool SieveActionFileInto::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionFileInto::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
QDomNode node = element.firstChild();
while (!node.isNull()) {
QDomElement e = node.toElement();
......@@ -103,6 +104,7 @@ bool SieveActionFileInto::setParamWidgetValue(const QDomElement &element, QWidge
}
node = node.nextSibling();
}
#endif
return true;
}
......
......@@ -29,7 +29,7 @@ public:
QString code(QWidget *) const override;
QWidget *createParamWidget(QWidget *parent) const override;
QStringList needRequires(QWidget *parent) const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *parent, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *parent, QString &error) override;
bool needCheckIfServerHasCapability() const override;
QString serverNeedsCapability() const override;
QString help() const override;
......
......@@ -25,7 +25,7 @@
#include <KLocalizedString>
#include <QLabel>
#include <QHBoxLayout>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
using namespace KSieveUi;
......@@ -77,8 +77,9 @@ QWidget *SieveActionKeep::createParamWidget(QWidget *parent) const
}
}
bool SieveActionKeep::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionKeep::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
if (mHasFlagSupport) {
QDomNode node = element.firstChild();
while (!node.isNull()) {
......@@ -107,6 +108,7 @@ bool SieveActionKeep::setParamWidgetValue(const QDomElement &element, QWidget *w
} else {
qCDebug(LIBKSIEVE_LOG) << " Server doesn't support imapflags";
}
#endif
return true;
}
......
......@@ -29,7 +29,7 @@ public:
QString code(QWidget *) const override;
QString help() const override;
QWidget *createParamWidget(QWidget *parent) const override;
bool setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error) override;
bool setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error) override;
QStringList needRequires(QWidget *) const override;
QUrl href() const override;
......
......@@ -26,7 +26,7 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QDomNode>
#include <QXmlStreamReader>
#include "libksieve_debug.h"
using namespace KSieveUi;
......@@ -67,8 +67,9 @@ QWidget *SieveActionNotify::createParamWidget(QWidget *parent) const
return w;
}
bool SieveActionNotify::setParamWidgetValue(const QDomElement &element, QWidget *w, QString &error)
bool SieveActionNotify::setParamWidgetValue(QXmlStreamReader &element, QWidget *w, QString &error)
{
#ifdef REMOVE_QDOMELEMENT
QDomNode node = element.firstChild();
while (!node.isNull()) {
QDomElement e = node.toElement();
......@@ -106,6 +107,7 @@ bool SieveActionNotify::setParamWidgetValue(const QDomElement &element, QWidget
}
node = node.nextSibling();
}
#endif
return true;