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

Simplify code

parent dd5683b6
......@@ -73,7 +73,7 @@ int main(int argc, char **argv)
KSieve::Parser sieveParser(script.begin(),
script.begin() + script.length());
KSieveUi::XMLPrintingScriptBuilder psb;
KSieveUi::XMLPrintingScriptBuilder psb(2);
sieveParser.setScriptBuilder(&psb);
if (sieveParser.parse()) {
qDebug() << "ok";
......@@ -81,7 +81,7 @@ int main(int argc, char **argv)
qDebug() << "bad";
}
KSieveUi::ParsingResultDialog dlg;
dlg.setResultParsing(psb.toDom().toString(2));
dlg.setResultParsing(psb.result());
dlg.show();
KSieveUi::AutoCreateScriptDialog *dialog = new KSieveUi::AutoCreateScriptDialog;
......
......@@ -218,12 +218,12 @@ void SieveEditorTextModeWidget::generateXml()
const QByteArray script = mTextEdit->toPlainText().toUtf8();
KSieve::Parser parser(script.begin(),
script.begin() + script.length());
KSieveUi::XMLPrintingScriptBuilder psb;
KSieveUi::XMLPrintingScriptBuilder psb(2);
parser.setScriptBuilder(&psb);
const bool result = parser.parse();
QPointer<ParsingResultDialog> dlg = new ParsingResultDialog(this);
if (result) {
dlg->setResultParsing(psb.toDom().toString(2));
dlg->setResultParsing(psb.result());
} else {
dlg->setResultParsing(i18n("Error during parsing"));
}
......
......@@ -71,7 +71,7 @@ int main(int argc, char **argv)
KSieve::Parser sieveParser(script.begin(),
script.begin() + script.length());
KSieveUi::XMLPrintingScriptBuilder psb;
KSieveUi::XMLPrintingScriptBuilder psb(1);
sieveParser.setScriptBuilder(&psb);
if (sieveParser.parse()) {
qDebug() << "ok";
......@@ -79,7 +79,7 @@ int main(int argc, char **argv)
qDebug() << "bad";
}
KSieveUi::ParsingResultDialog dlg;
dlg.setResultParsing(psb.toDom().toString());
dlg.setResultParsing(psb.result());
dlg.show();
app.exec();
......
......@@ -24,14 +24,32 @@ using KSieve::Parser;
#include <ksieve/error.h>
#include "libksieve_debug.h"
#include <QXmlStreamWriter>
#include <QDebug>
using namespace KSieveUi;
XMLPrintingScriptBuilder::XMLPrintingScriptBuilder(int indent)
: KSieve::ScriptBuilder(),
mStream(nullptr)
{
initialize(indent);
}
XMLPrintingScriptBuilder::XMLPrintingScriptBuilder()
: KSieve::ScriptBuilder(),
mStream(nullptr)
{
initialize();
}
void XMLPrintingScriptBuilder::initialize(int indent)
{
mStream = new QXmlStreamWriter(&mResult);
mStream->setAutoFormatting(false);
if (indent == 0) {
mStream->setAutoFormatting(false);
} else {
mStream->setAutoFormatting(true);
mStream->setAutoFormattingIndent(indent);
}
mStream->writeStartDocument();
mStream->writeStartElement(QStringLiteral("script"));
}
......
......@@ -29,7 +29,8 @@ namespace KSieveUi
class KSIEVEUI_TESTS_EXPORT XMLPrintingScriptBuilder : public KSieve::ScriptBuilder
{
public:
explicit XMLPrintingScriptBuilder();
XMLPrintingScriptBuilder();
XMLPrintingScriptBuilder(int indent);
~XMLPrintingScriptBuilder();
void taggedArgument(const QString &tag) override;
......@@ -62,12 +63,13 @@ public:
QDomDocument toDom() const;
private:
void initialize(int indent = 0);
void write(const QString &key, const QString &value);
void write(const QString &key, const QString &qualifiedName, const QString &attribute, const QString &value);
QXmlStreamWriter *mStream;
QString mResult;
QString mError;
};
};
}
#endif
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