File indexing completed on 2024-12-29 04:54:49

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "../parsingresultdialog.h"
0008 #include <KSieveCore/XMLPrintingScriptBuilder>
0009 
0010 #include "parser.h"
0011 using KSieve::Parser;
0012 
0013 #include "scriptbuilder.h"
0014 
0015 #include <QApplication>
0016 #include <QCommandLineOption>
0017 #include <QCommandLineParser>
0018 #include <QDebug>
0019 #include <QFileDialog>
0020 #include <QStandardPaths>
0021 
0022 int main(int argc, char **argv)
0023 {
0024     QApplication app(argc, argv);
0025     QStandardPaths::setTestModeEnabled(true);
0026     QCommandLineParser parser;
0027     parser.addVersionOption();
0028     parser.addHelpOption();
0029     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("+[url]"), QStringLiteral("URL of a sieve script to be opened")));
0030 
0031     parser.process(app);
0032 
0033     QByteArray script;
0034 
0035     QString fileName;
0036     if (!parser.positionalArguments().isEmpty()) {
0037         fileName = parser.positionalArguments().at(0);
0038     } else {
0039         fileName = QFileDialog::getOpenFileName(nullptr, QString(), QString(), QStringLiteral("Sieve File (*.siv)"));
0040     }
0041     if (!fileName.isEmpty()) {
0042         QFile file(fileName);
0043         if (file.open(QIODevice::ReadOnly)) {
0044             script = file.readAll();
0045         }
0046     } else {
0047         return 0;
0048     }
0049     // qDebug() << "scriptUtf8 = \"" + script +"\"";
0050 
0051     KSieve::Parser sieveParser(script.constBegin(), script.constBegin() + script.length());
0052     KSieveCore::XMLPrintingScriptBuilder psb(1);
0053     sieveParser.setScriptBuilder(&psb);
0054     if (sieveParser.parse()) {
0055         qDebug() << "ok";
0056     } else {
0057         qDebug() << "bad";
0058     }
0059     KSieveUi::ParsingResultDialog dlg;
0060     dlg.setResultParsing(psb.result());
0061 
0062     dlg.show();
0063     app.exec();
0064     return 0;
0065 }