summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <[email protected]>2017-06-21 22:34:40 +0200
committerMontel Laurent <[email protected]>2017-06-21 22:34:40 +0200
commiteb16457d8baffc83c6f59a10cf61b3b841c46792 (patch)
tree42ae5e739d6bd7aa42dada752f328bfdc333c6cb
parentdd5683b6f85eb8f7fa880e06cb3f9ca0bf63516b (diff)
Simplify code
-rw-r--r--src/ksieveui/autocreatescripts/tests/parsingscript_gui.cpp4
-rw-r--r--src/ksieveui/editor/sieveeditortextmodewidget.cpp4
-rw-r--r--src/ksieveui/scriptsparsing/tests/main.cpp4
-rw-r--r--src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.cpp20
-rw-r--r--src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.h6
5 files changed, 29 insertions, 9 deletions
diff --git a/src/ksieveui/autocreatescripts/tests/parsingscript_gui.cpp b/src/ksieveui/autocreatescripts/tests/parsingscript_gui.cpp
index c56076c..8d801f4 100644
--- a/src/ksieveui/autocreatescripts/tests/parsingscript_gui.cpp
+++ b/src/ksieveui/autocreatescripts/tests/parsingscript_gui.cpp
@@ -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;
diff --git a/src/ksieveui/editor/sieveeditortextmodewidget.cpp b/src/ksieveui/editor/sieveeditortextmodewidget.cpp
index 55b9928..b697a62 100644
--- a/src/ksieveui/editor/sieveeditortextmodewidget.cpp
+++ b/src/ksieveui/editor/sieveeditortextmodewidget.cpp
@@ -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"));
}
diff --git a/src/ksieveui/scriptsparsing/tests/main.cpp b/src/ksieveui/scriptsparsing/tests/main.cpp
index 4ecd49a..7104db8 100644
--- a/src/ksieveui/scriptsparsing/tests/main.cpp
+++ b/src/ksieveui/scriptsparsing/tests/main.cpp
@@ -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();
diff --git a/src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.cpp b/src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.cpp
index a7d77f5..ca45d4e 100644
--- a/src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.cpp
+++ b/src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.cpp
@@ -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"));
}
diff --git a/src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.h b/src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.h
index a04dd77..bf4772a 100644
--- a/src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.h
+++ b/src/ksieveui/scriptsparsing/xmlprintingscriptbuilder.h
@@ -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