File indexing completed on 2024-04-14 03:51:28

0001 /*
0002     SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #include <QGuiApplication>
0007 #include <QQmlApplicationEngine>
0008 
0009 #include "../src/addressformat.h"
0010 #include <KContacts/Address>
0011 #include <KContacts/Addressee>
0012 
0013 using namespace KContacts;
0014 
0015 int main(int argc, char **argv)
0016 {
0017     QCoreApplication::setApplicationName(QStringLiteral("kcontacts-qmlintegrationtest"));
0018     QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
0019     QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
0020 
0021     QGuiApplication app(argc, argv);
0022 
0023     // ### this should probably eventually move into a real QML plugin for KContacts
0024     qmlRegisterUncreatableMetaObject(KContacts::staticMetaObject, "org.kde.contacts", 1, 0, "KContacts", {});
0025     qmlRegisterSingletonType("org.kde.contacts", 1, 0, "AddressFormatRepository", [](QQmlEngine *, QJSEngine *jsEngine) -> QJSValue {
0026         return jsEngine->toScriptValue(AddressFormatRepository());
0027     });
0028     qRegisterMetaType<AddressFormat>();
0029     qRegisterMetaType<AddressFormatElement>();
0030     qRegisterMetaType<AddressFormatRepository>();
0031     qRegisterMetaType<AddressFormatPreference>();
0032     qRegisterMetaType<AddressFormatScriptPreference>();
0033 
0034     // test data
0035     qmlRegisterSingletonType("org.kde.contacts.test", 1, 0, "TestData", [](QQmlEngine *, QJSEngine *jsEngine) -> QJSValue {
0036         Address address;
0037         address.setCountry(QStringLiteral("DE"));
0038         address.setRegion(QStringLiteral("BE"));
0039         address.setLocality(QStringLiteral("Berlin"));
0040         address.setPostalCode(QStringLiteral("10969"));
0041         address.setStreet(QStringLiteral("Prinzenstraße 85 F"));
0042 
0043         Addressee addressee;
0044         addressee.insertAddress(address);
0045         addressee.setEmails({QStringLiteral("one@test.local"), QStringLiteral("two@test.local")});
0046 
0047         auto obj = jsEngine->newObject();
0048         obj.setProperty(QStringLiteral("address"), jsEngine->toScriptValue(address));
0049         obj.setProperty(QStringLiteral("addressee"), jsEngine->toScriptValue(addressee));
0050         return obj;
0051     });
0052 
0053     QQmlApplicationEngine engine;
0054     engine.load(QStringLiteral("qrc:/qmlintegrationtest.qml"));
0055     return app.exec();
0056 }