From 4ecf463cd19967fff70c3874664d368f6ebe07e2 Mon Sep 17 00:00:00 2001 From: Kareem Abduljaleel Date: Wed, 28 Sep 2022 13:03:48 +0000 Subject: [PATCH] [plasmoid] Add Photo to Plasmoid menu Adds a menu entry to ask the remote device to take a photo to the Plasmoid menu --- .../kdeconnectdeclarativeplugin.cpp | 2 ++ interfaces/CMakeLists.txt | 1 + interfaces/dbusinterfaces.cpp | 14 ++++++---- interfaces/dbusinterfaces.h | 13 ++++++++- .../package/contents/ui/DeviceDelegate.qml | 28 +++++++++++++++++++ plasmoid/package/contents/ui/Photo.qml | 26 +++++++++++++++++ 6 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 plasmoid/package/contents/ui/Photo.qml diff --git a/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/declarativeplugin/kdeconnectdeclarativeplugin.cpp index ab21ff872..1acbe4e5c 100644 --- a/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -79,6 +79,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char *uri) "RemoteSystemVolumeInterface", QStringLiteral("You're not supposed to instantiate interfaces")); qmlRegisterUncreatableType(uri, 1, 0, "ShareDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces")); + qmlRegisterUncreatableType(uri, 1, 0, "PhotoDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces")); qmlRegisterUncreatableType(uri, 1, 0, "BigscreenDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces")); qmlRegisterSingletonType(uri, 1, 0, "DaemonDbusInterface", [](QQmlEngine *, QJSEngine *) -> QObject * { return new DaemonDbusInterface; @@ -116,6 +117,7 @@ void KdeConnectDeclarativePlugin::registerTypes(const char *uri) registerFactory(uri, "SmsDbusInterfaceFactory"); registerFactory(uri, "RemoteCommandsDbusInterfaceFactory"); registerFactory(uri, "ShareDbusInterfaceFactory"); + registerFactory(uri, "PhotoDbusInterfaceFactory"); registerFactory(uri, "RemoteSystemVolumeDbusInterfaceFactory"); registerFactory(uri, "BigscreenDbusInterfaceFactory"); registerFactory(uri, "VirtualmonitorDbusInterfaceFactory"); diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt index d53bd3541..c415acc70 100644 --- a/interfaces/CMakeLists.txt +++ b/interfaces/CMakeLists.txt @@ -57,6 +57,7 @@ geninterface(${PROJECT_SOURCE_DIR}/plugins/share/shareplugin.h shareinterface) geninterface(${PROJECT_SOURCE_DIR}/plugins/remotesystemvolume/remotesystemvolumeplugin.h remotesystemvolumeinterface) geninterface(${PROJECT_SOURCE_DIR}/plugins/bigscreen/bigscreenplugin.h bigscreeninterface) geninterface(${PROJECT_SOURCE_DIR}/plugins/virtualmonitor/virtualmonitorplugin.h virtualmonitorinterface) +geninterface(${PROJECT_SOURCE_DIR}/plugins/photo/photoplugin.h photointerface) add_library(kdeconnectinterfaces ${libkdeconnect_SRC}) set_target_properties(kdeconnectinterfaces PROPERTIES diff --git a/interfaces/dbusinterfaces.cpp b/interfaces/dbusinterfaces.cpp index fce2138e0..8d608cad6 100644 --- a/interfaces/dbusinterfaces.cpp +++ b/interfaces/dbusinterfaces.cpp @@ -227,11 +227,15 @@ ShareDbusInterface::ShareDbusInterface(const QString &deviceId, QObject *parent) ShareDbusInterface::~ShareDbusInterface() = default; -RemoteSystemVolumeDbusInterface::RemoteSystemVolumeDbusInterface(const QString &deviceId, QObject *parent) - : OrgKdeKdeconnectDeviceRemotesystemvolumeInterface(DaemonDbusInterface::activatedService(), - QStringLiteral("/modules/kdeconnect/devices/") + deviceId + QStringLiteral("/remotesystemvolume"), - QDBusConnection::sessionBus(), - parent) +PhotoDbusInterface::PhotoDbusInterface(const QString& deviceId, QObject* parent): + OrgKdeKdeconnectDevicePhotoInterface(DaemonDbusInterface::activatedService(), QStringLiteral("/modules/kdeconnect/devices/") + deviceId + QStringLiteral("/photo"), QDBusConnection::sessionBus(), parent) +{ +} + +PhotoDbusInterface::~PhotoDbusInterface() = default; + +RemoteSystemVolumeDbusInterface::RemoteSystemVolumeDbusInterface(const QString& deviceId, QObject* parent): + OrgKdeKdeconnectDeviceRemotesystemvolumeInterface(DaemonDbusInterface::activatedService(), QStringLiteral("/modules/kdeconnect/devices/") + deviceId + QStringLiteral("/remotesystemvolume"), QDBusConnection::sessionBus(), parent) { } diff --git a/interfaces/dbusinterfaces.h b/interfaces/dbusinterfaces.h index 0e1c74899..ff23cb5a9 100644 --- a/interfaces/dbusinterfaces.h +++ b/interfaces/dbusinterfaces.h @@ -28,6 +28,7 @@ #include "shareinterface.h" #include "smsinterface.h" #include "virtualmonitorinterface.h" +#include "photointerface.h" /** * Using these "proxy" classes just in case we need to rename the @@ -229,7 +230,17 @@ public: ~ShareDbusInterface() override; }; -class KDECONNECTINTERFACES_EXPORT RemoteSystemVolumeDbusInterface : public OrgKdeKdeconnectDeviceRemotesystemvolumeInterface +class KDECONNECTINTERFACES_EXPORT PhotoDbusInterface + : public OrgKdeKdeconnectDevicePhotoInterface +{ + Q_OBJECT +public: + explicit PhotoDbusInterface(const QString& deviceId, QObject* parent = nullptr); + ~PhotoDbusInterface() override; +}; + +class KDECONNECTINTERFACES_EXPORT RemoteSystemVolumeDbusInterface + : public OrgKdeKdeconnectDeviceRemotesystemvolumeInterface { Q_OBJECT public: diff --git a/plasmoid/package/contents/ui/DeviceDelegate.qml b/plasmoid/package/contents/ui/DeviceDelegate.qml index 35f883b2c..9cf829edc 100644 --- a/plasmoid/package/contents/ui/DeviceDelegate.qml +++ b/plasmoid/package/contents/ui/DeviceDelegate.qml @@ -170,6 +170,28 @@ PlasmaComponents.ListItem onClicked: fileDialog.open() } + //Photo + PlasmaComponents.MenuItem + { + FileDialog { + id: photoFileDialog + title: i18n("Save As") + folder: shortcuts.pictures + selectMultiple: false + selectExisting: false + onAccepted: { + var path = photoFileDialog.fileUrl.toString(); + photo.plugin.requestPhoto(path); + } + } + + id: takePhoto + icon: "camera-photo-symbolic" + visible: photo.available + text: i18n("Take a photo") + onClicked: photoFileDialog.open() + } + //Find my phone PlasmaComponents.MenuItem { @@ -407,5 +429,11 @@ PlasmaComponents.ListItem id: share device: root.device } + + // Photo + Photo { + id: photo + device: root.device + } } } diff --git a/plasmoid/package/contents/ui/Photo.qml b/plasmoid/package/contents/ui/Photo.qml new file mode 100644 index 000000000..fa3d289b2 --- /dev/null +++ b/plasmoid/package/contents/ui/Photo.qml @@ -0,0 +1,26 @@ +/** + * SPDX-FileCopyrightText: 2022 Kareem Abduljaleel + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + */ + +import QtQuick 2.1 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.kdeconnect 1.0 + +QtObject { + + id: root + + property alias device: checker.device + readonly property alias available: checker.available + + readonly property PluginChecker pluginChecker: PluginChecker { + id: checker + pluginName: "photo" + } + + property variant plugin: available ? PhotoDbusInterfaceFactory.create(device.id()) : null +} +