File indexing completed on 2025-01-26 04:57:26

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl.schwan@gnupg.com>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #include <KLocalizedContext>
0005 #include <KLocalizedString>
0006 #include <QApplication>
0007 #include <QCommandLineParser>
0008 #include <QDir>
0009 #include <QQmlApplicationEngine>
0010 #include <QQmlContext>
0011 #include <QQuickWindow>
0012 
0013 #include "messagehandler.h"
0014 #include <MimeTreeParserCore/FileOpener>
0015 #include <MimeTreeParserCore/MessageParser>
0016 
0017 int main(int argc, char *argv[])
0018 {
0019     QApplication app(argc, argv);
0020 
0021     QCommandLineParser parser;
0022     parser.setApplicationDescription(i18n("View mbox file"));
0023     parser.addPositionalArgument(QStringLiteral("file"), i18n("mbox file"));
0024 
0025     QQmlApplicationEngine engine;
0026     engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
0027     QObject::connect(&engine, &QQmlApplicationEngine::quit, &app, &QCoreApplication::quit);
0028 
0029     constexpr auto uri = "org.kde.mimetreeparser";
0030 
0031     qmlRegisterType<MessageParser>(uri, 1, 0, "MessageParser");
0032     qmlRegisterType<MessageHandler>(uri, 1, 0, "MessageHandler");
0033 
0034     engine.load(QUrl(QStringLiteral("qrc:/content/main.qml")));
0035     const auto rootObjects = engine.rootObjects();
0036     if (rootObjects.isEmpty()) {
0037         return -1;
0038     }
0039     parser.process(app);
0040 
0041     const QStringList args = parser.positionalArguments();
0042     if (args.length() > 0) {
0043         for (auto obj : rootObjects) {
0044             auto view = qobject_cast<QQuickWindow *>(obj);
0045             auto messageHandler = view->findChild<MessageHandler *>(QStringLiteral("MessageHandler"));
0046             const auto file = QUrl::fromUserInput(args.at(args.count() - 1), QDir::currentPath());
0047             messageHandler->open(file);
0048         }
0049     }
0050 
0051     return QCoreApplication::exec();
0052 }