File indexing completed on 2023-09-24 07:59:52
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 0012 using namespace KContacts; 0013 0014 int main(int argc, char **argv) 0015 { 0016 QCoreApplication::setApplicationName(QStringLiteral("kcontacts-qmlintegrationtest")); 0017 QCoreApplication::setOrganizationName(QStringLiteral("KDE")); 0018 QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org")); 0019 0020 QGuiApplication app(argc, argv); 0021 0022 // ### this should probably eventually move into a real QML plugin for KContacts 0023 qmlRegisterUncreatableMetaObject(KContacts::staticMetaObject, "org.kde.contacts", 1, 0, "KContacts", {}); 0024 qmlRegisterSingletonType("org.kde.contacts", 1, 0, "AddressFormatRepository", [](QQmlEngine *, QJSEngine *jsEngine) -> QJSValue { 0025 return jsEngine->toScriptValue(AddressFormatRepository()); 0026 }); 0027 qRegisterMetaType<AddressFormat>(); 0028 qRegisterMetaType<AddressFormatElement>(); 0029 qRegisterMetaType<AddressFormatRepository>(); 0030 qRegisterMetaType<AddressFormatPreference>(); 0031 qRegisterMetaType<AddressFormatScriptPreference>(); 0032 0033 // test data 0034 qmlRegisterSingletonType("org.kde.contacts.test", 1, 0, "TestData", [](QQmlEngine *, QJSEngine *jsEngine) -> QJSValue { 0035 Address address; 0036 address.setCountry(QStringLiteral("DE")); 0037 address.setRegion(QStringLiteral("BE")); 0038 address.setLocality(QStringLiteral("Berlin")); 0039 address.setPostalCode(QStringLiteral("10969")); 0040 address.setStreet(QStringLiteral("Prinzenstraße 85 F")); 0041 0042 auto obj = jsEngine->newObject(); 0043 obj.setProperty(QStringLiteral("address"), jsEngine->toScriptValue(address)); 0044 return obj; 0045 }); 0046 0047 QQmlApplicationEngine engine; 0048 engine.load(QStringLiteral("qrc:/qmlintegrationtest.qml")); 0049 return app.exec(); 0050 }