File indexing completed on 2024-04-14 04:51:42

0001 /**
0002  * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 #include "kdeconnectdeclarativeplugin.h"
0008 
0009 #include <QDBusPendingCall>
0010 #include <QDBusPendingReply>
0011 #include <QGuiApplication>
0012 #include <QQmlContext>
0013 #include <QQmlEngine>
0014 #include <devicespluginfilterproxymodel.h>
0015 
0016 #include "objectfactory.h"
0017 #include "responsewaiter.h"
0018 
0019 #include "core/kdeconnectpluginconfig.h"
0020 #include "interfaces/commandsmodel.h"
0021 #include "interfaces/devicesmodel.h"
0022 #include "interfaces/devicessortproxymodel.h"
0023 #include "interfaces/notificationsmodel.h"
0024 #include "openconfig.h"
0025 #include "pointerlocker.h"
0026 #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
0027 #include "pointerlockerwayland.h"
0028 #endif
0029 #include <pluginmodel.h>
0030 #include <remotecommandsmodel.h>
0031 #include <remotesinksmodel.h>
0032 
0033 QObject *createDBusResponse()
0034 {
0035     return new DBusAsyncResponse();
0036 }
0037 
0038 template<typename T>
0039 void registerFactory(const char *uri, const char *name)
0040 {
0041     qmlRegisterSingletonType<ObjectFactory>(uri, 1, 0, name, [](QQmlEngine *engine, QJSEngine *) -> QObject * {
0042         return new ObjectFactory(engine, [](const QVariant &deviceId) -> QObject * {
0043             return new T(deviceId.toString());
0044         });
0045     });
0046 }
0047 
0048 void KdeConnectDeclarativePlugin::registerTypes(const char *uri)
0049 {
0050     qmlRegisterType<DevicesModel>(uri, 1, 0, "DevicesModel");
0051     qmlRegisterType<NotificationsModel>(uri, 1, 0, "NotificationsModel");
0052     qmlRegisterType<RemoteCommandsModel>(uri, 1, 0, "RemoteCommandsModel");
0053     qmlRegisterType<DBusAsyncResponse>(uri, 1, 0, "DBusAsyncResponse");
0054     qmlRegisterType<DevicesSortProxyModel>(uri, 1, 0, "DevicesSortProxyModel");
0055     qmlRegisterType<DevicesPluginFilterProxyModel>(uri, 1, 0, "DevicesPluginFilterProxyModel");
0056     qmlRegisterType<RemoteSinksModel>(uri, 1, 0, "RemoteSinksModel");
0057     qmlRegisterType<PluginModel>(uri, 1, 0, "PluginModel");
0058     qmlRegisterType<KdeConnectPluginConfig>(uri, 1, 0, "KdeConnectPluginConfig");
0059     qmlRegisterType<CommandsModel>(uri, 1, 0, "CommandsModel");
0060     qmlRegisterUncreatableType<MprisDbusInterface>(uri, 1, 0, "MprisDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces"));
0061     qmlRegisterUncreatableType<LockDeviceDbusInterface>(uri, 1, 0, "LockDeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces"));
0062     qmlRegisterUncreatableType<FindMyPhoneDeviceDbusInterface>(uri,
0063                                                                1,
0064                                                                0,
0065                                                                "FindMyPhoneDbusInterface",
0066                                                                QStringLiteral("You're not supposed to instantiate interfaces"));
0067     qmlRegisterUncreatableType<ClipboardDbusInterface>(uri, 1, 0, "ClipboardDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces"));
0068     qmlRegisterUncreatableType<RemoteKeyboardDbusInterface>(uri,
0069                                                             1,
0070                                                             0,
0071                                                             "RemoteKeyboardDbusInterface",
0072                                                             QStringLiteral("You're not supposed to instantiate interfaces"));
0073     qmlRegisterUncreatableType<DeviceDbusInterface>(uri, 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces"));
0074     qmlRegisterUncreatableType<RemoteCommandsDbusInterface>(uri,
0075                                                             1,
0076                                                             0,
0077                                                             "RemoteCommandsDbusInterface",
0078                                                             QStringLiteral("You're not supposed to instantiate interfaces"));
0079     qmlRegisterUncreatableType<RemoteSystemVolumeDbusInterface>(uri,
0080                                                                 1,
0081                                                                 0,
0082                                                                 "RemoteSystemVolumeInterface",
0083                                                                 QStringLiteral("You're not supposed to instantiate interfaces"));
0084     qmlRegisterUncreatableType<ShareDbusInterface>(uri, 1, 0, "ShareDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces"));
0085     qmlRegisterUncreatableType<BigscreenDbusInterface>(uri, 1, 0, "BigscreenDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces"));
0086     qmlRegisterSingletonType<DaemonDbusInterface>(uri, 1, 0, "DaemonDbusInterface", [](QQmlEngine *, QJSEngine *) -> QObject * {
0087         return new DaemonDbusInterface;
0088     });
0089     qmlRegisterSingletonType<AbstractPointerLocker>("org.kde.kdeconnect", 1, 0, "PointerLocker", [](QQmlEngine *, QJSEngine *) -> QObject * {
0090         AbstractPointerLocker *ret;
0091 #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
0092         if (qGuiApp->platformName() == QLatin1String("wayland"))
0093             ret = new PointerLockerWayland;
0094         else
0095 #endif
0096             ret = new PointerLockerQt;
0097         return ret;
0098     });
0099 
0100     qmlRegisterSingletonType<OpenConfig>(uri, 1, 0, "OpenConfig", [](QQmlEngine *, QJSEngine *) -> QObject * {
0101         return new OpenConfig;
0102     });
0103 
0104     qmlRegisterAnonymousType<QAbstractItemModel>(uri, 1);
0105 
0106     registerFactory<DeviceDbusInterface>(uri, "DeviceDbusInterfaceFactory");
0107     registerFactory<BatteryDbusInterface>(uri, "DeviceBatteryDbusInterfaceFactory");
0108     registerFactory<ConnectivityReportDbusInterface>(uri, "DeviceConnectivityReportDbusInterfaceFactory");
0109     registerFactory<FindMyPhoneDeviceDbusInterface>(uri, "FindMyPhoneDbusInterfaceFactory");
0110     registerFactory<SftpDbusInterface>(uri, "SftpDbusInterfaceFactory");
0111     registerFactory<RemoteKeyboardDbusInterface>(uri, "RemoteKeyboardDbusInterfaceFactory");
0112     registerFactory<ClipboardDbusInterface>(uri, "ClipboardDbusInterfaceFactory");
0113     registerFactory<MprisDbusInterface>(uri, "MprisDbusInterfaceFactory");
0114     registerFactory<RemoteControlDbusInterface>(uri, "RemoteControlDbusInterfaceFactory");
0115     registerFactory<LockDeviceDbusInterface>(uri, "LockDeviceDbusInterfaceFactory");
0116     registerFactory<SmsDbusInterface>(uri, "SmsDbusInterfaceFactory");
0117     registerFactory<RemoteCommandsDbusInterface>(uri, "RemoteCommandsDbusInterfaceFactory");
0118     registerFactory<ShareDbusInterface>(uri, "ShareDbusInterfaceFactory");
0119     registerFactory<RemoteSystemVolumeDbusInterface>(uri, "RemoteSystemVolumeDbusInterfaceFactory");
0120     registerFactory<BigscreenDbusInterface>(uri, "BigscreenDbusInterfaceFactory");
0121     registerFactory<VirtualmonitorDbusInterface>(uri, "VirtualmonitorDbusInterfaceFactory");
0122 }
0123 
0124 void KdeConnectDeclarativePlugin::initializeEngine(QQmlEngine *engine, const char *uri)
0125 {
0126     QQmlExtensionPlugin::initializeEngine(engine, uri);
0127 
0128     engine->rootContext()->setContextProperty(QStringLiteral("DBusResponseFactory"), new ObjectFactory(engine, createDBusResponse));
0129 
0130     engine->rootContext()->setContextProperty(QStringLiteral("DBusResponseWaiter"), DBusResponseWaiter::instance());
0131 }
0132 
0133 #include "moc_kdeconnectdeclarativeplugin.cpp"