File indexing completed on 2024-05-05 16:16:34

0001 /*
0002     Persons Model
0003     SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-or-later
0006 */
0007 
0008 #include "peopleqmlplugin.h"
0009 
0010 #include <QQmlEngine>
0011 
0012 #include <actions.h>
0013 #include <personactionsmodel_p.h>
0014 #include <persondata.h>
0015 #include <personpluginmanager.h>
0016 #include <personsmodel.h>
0017 #include <personssortfilterproxymodel.h>
0018 
0019 #include "avatarimageprovider.h"
0020 #include "declarativepersondata.h"
0021 
0022 class ActionTypeWrapper : public QObject
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     enum ActionType {
0028         TextChatAction = KPeople::TextChatAction,
0029         AudioCallAction = KPeople::AudioCallAction,
0030         VideoCallAction = KPeople::VideoCallAction,
0031         SendEmailAction = KPeople::SendEmailAction,
0032         SendFileAction = KPeople::SendFileAction,
0033         OtherAction = KPeople::OtherAction,
0034     };
0035     Q_ENUM(ActionType)
0036 };
0037 
0038 class DeclarativePersonPluginManager : public QObject
0039 {
0040     Q_OBJECT
0041 public:
0042     Q_SCRIPTABLE bool addContact(const QVariantMap &properties)
0043     {
0044         return KPeople::PersonPluginManager::addContact(properties);
0045     }
0046     Q_SCRIPTABLE bool deleteContact(const QString &uri)
0047     {
0048         return KPeople::PersonPluginManager::deleteContact(uri);
0049     }
0050 };
0051 
0052 void PeopleQMLPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
0053 {
0054     Q_ASSERT(uri == QByteArrayLiteral("org.kde.people"));
0055     engine->addImageProvider(QStringLiteral("kpeople-avatar"), new AvatarImageProvider());
0056 }
0057 
0058 void PeopleQMLPlugin::registerTypes(const char *uri)
0059 {
0060     qmlRegisterType<KPeople::PersonsModel>(uri, 1, 0, "PersonsModel");
0061     qmlRegisterType<KPeople::PersonsSortFilterProxyModel>(uri, 1, 0, "PersonsSortFilterProxyModel");
0062     qmlRegisterType<KPeople::PersonActionsModel>(uri, 1, 0, "PersonActions");
0063     qmlRegisterType<DeclarativePersonData>(uri, 1, 0, "PersonData");
0064     qmlRegisterAnonymousType<KPeople::PersonData>(uri, 1);
0065     qmlRegisterUncreatableType<ActionTypeWrapper>(uri, 1, 0, "ActionType", QStringLiteral("You cannot create ActionType"));
0066     qmlRegisterSingletonType<DeclarativePersonPluginManager>(uri, 1, 0, "PersonPluginManager", [](QQmlEngine *, QJSEngine *) -> QObject * {
0067         return new DeclarativePersonPluginManager;
0068     });
0069 
0070     qmlRegisterUncreatableMetaObject(KPeople::staticMetaObject, uri, 1, 0, "KPeople", QStringLiteral("Access to enums & flags only"));
0071 }
0072 
0073 #include "moc_peopleqmlplugin.cpp"
0074 #include "peopleqmlplugin.moc"