#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QUrl>
#include <KLocalizedContext>
#include <KLocalizedString>
#include "invoicemodel.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QCoreApplication::setOrganizationName("KDE");
    QCoreApplication::setOrganizationDomain("kde.org");
    QCoreApplication::setApplicationName("XROverview");

    KLocalizedString::setApplicationDomain("xroverview");

    InvoiceModel model;

    const QStringList args = app.arguments();
    int fi = args.indexOf("--filter");
    if (fi != -1 && fi + 1 < args.size())
        model.setFilter(args.at(fi + 1));

    QString outputDir;
    int oi = args.indexOf("--output");
    if (oi != -1 && oi + 1 < args.size())
        outputDir = args.at(oi + 1);

    QQmlApplicationEngine engine;
    engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
    engine.rootContext()->setContextProperty("invoiceModel", &model);
    engine.rootContext()->setContextProperty("initialOutputDir", outputDir);

    engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
    if (engine.rootObjects().isEmpty())
        return -1;

    return app.exec();
}
