From f3fa818cbfe9eb39184f68324689c2ad9eeb6371 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Wed, 4 Sep 2024 00:36:25 +0200 Subject: [PATCH] Revert changes to QML incompatible with Qt 6.6 and older - Revert "plasmoid: Port to pragma ComponentBehavior: Bound" This reverts commit 9ee0b23727f053d4a36093f4a2f4936ebcf203ad. - Revert "plasmoid: Flatten plugin controllers, menu and other non-graphical components" This reverts commit d2ee2bfdd807194bd1204e308299883df929ab97. - Revert "plasmoid: Basic code cleanup" This reverts commit 90946829bfdfd328b3a8f5dc3af892cd9252b652. --- .../kdeconnectdeclarativeplugin.cpp | 13 - declarativeplugin/qml/DBusProperty.qml | 47 +- declarativeplugin/qml/PluginChecker.qml | 60 +-- declarativeplugin/qml/RemoteKeyboard.qml | 90 ++-- plasmoid/package/contents/ui/Battery.qml | 82 ++-- plasmoid/package/contents/ui/Clipboard.qml | 22 +- .../contents/ui/CompactRepresentation.qml | 36 +- plasmoid/package/contents/ui/Connectivity.qml | 54 ++- .../package/contents/ui/DeviceDelegate.qml | 402 +++++++++--------- plasmoid/package/contents/ui/FindMyPhone.qml | 22 +- .../contents/ui/FullRepresentation.qml | 37 +- .../package/contents/ui/RemoteCommands.qml | 17 +- plasmoid/package/contents/ui/SMS.qml | 18 +- plasmoid/package/contents/ui/Sftp.qml | 25 +- plasmoid/package/contents/ui/Share.qml | 18 +- .../package/contents/ui/VirtualMonitor.qml | 24 +- plasmoid/package/contents/ui/main.qml | 60 +-- 17 files changed, 444 insertions(+), 583 deletions(-) diff --git a/declarativeplugin/kdeconnectdeclarativeplugin.cpp b/declarativeplugin/kdeconnectdeclarativeplugin.cpp index e07f6624c..b99ab8eae 100644 --- a/declarativeplugin/kdeconnectdeclarativeplugin.cpp +++ b/declarativeplugin/kdeconnectdeclarativeplugin.cpp @@ -71,19 +71,6 @@ void KdeConnectDeclarativePlugin::registerTypes(const char *uri) "RemoteKeyboardDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces")); qmlRegisterUncreatableType(uri, 1, 0, "DeviceDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces")); - qmlRegisterUncreatableType(uri, 1, 0, "BatteryDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces")); - qmlRegisterUncreatableType(uri, - 1, - 0, - "ConnectivityReportDbusInterface", - QStringLiteral("You're not supposed to instantiate interfaces")); - qmlRegisterUncreatableType(uri, 1, 0, "SftpDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces")); - qmlRegisterUncreatableType(uri, 1, 0, "SmsDbusInterface", QStringLiteral("You're not supposed to instantiate interfaces")); - qmlRegisterUncreatableType(uri, - 1, - 0, - "VirtualmonitorDbusInterface", - QStringLiteral("You're not supposed to instantiate interfaces")); qmlRegisterUncreatableType(uri, 1, 0, diff --git a/declarativeplugin/qml/DBusProperty.qml b/declarativeplugin/qml/DBusProperty.qml index 1ea6fda94..beabb5e3d 100644 --- a/declarativeplugin/qml/DBusProperty.qml +++ b/declarativeplugin/qml/DBusProperty.qml @@ -1,43 +1,36 @@ /** * SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - -import QtQml - -import org.kde.kdeconnect as KDEConnect +import QtQml 2.2 +import org.kde.kdeconnect 1.0 QtObject { id: prop - - property QtObject object + property QtObject object: null property string read - property string change: read + "Changed" + property string change: read+"Changed" - Component.onCompleted: { - get(); - } + Component.onCompleted: get(); onChangeChanged: { if (object) { - const signal = object[change]; - if (signal) { - signal.connect(valueReceived); + var theSignal = object[change]; + if (theSignal) { + theSignal.connect(valueReceived); } else { - console.warn(`couldn't find signal ${change} for ${object}`); + console.warn("couldn't find signal", change, "for", object) } } } - function valueReceived(value: var): void { - if (!value) { + function valueReceived(val) { + if (!val) { get(); } else { - _value = value; + _value = val; } } @@ -45,26 +38,18 @@ QtObject { property var _value: defaultValue readonly property var value: _value - readonly property KDEConnect.DBusAsyncResponse __response: KDEConnect.DBusAsyncResponse { + readonly property var v: DBusAsyncResponse { id: response - autoDelete: false - onSuccess: result => { prop._value = result; } - onError: message => { - console.warn("failed call", prop.object, prop.read, prop.change, message); + console.warn("failed call", prop.object, prop.read, prop.change, message) } } - function get(): void { - if (object) { - const method = object[read]; - if (method) { - response.setPendingCall(method()); - } - } + function get() { + response.setPendingCall(object[read]()); } } diff --git a/declarativeplugin/qml/PluginChecker.qml b/declarativeplugin/qml/PluginChecker.qml index d16db2500..632e42334 100644 --- a/declarativeplugin/qml/PluginChecker.qml +++ b/declarativeplugin/qml/PluginChecker.qml @@ -1,71 +1,47 @@ /** * SPDX-FileCopyrightText: 2014 Samoilenko Yuri * SPDX-FileCopyrightText: 2016 David Kahles - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - -import QtQml - -import org.kde.kdeconnect as KDEConnect +import QtQml 2.2 +import org.kde.kdeconnect 1.0 QtObject { + id: root - property KDEConnect.DeviceDbusInterface device - property string pluginName - property bool available - property string iconName + property alias device: conn.target + property string pluginName: "" + property bool available: false + property string iconName: "" readonly property Connections connection: Connections { id: conn - - target: root.device - - function onPluginsChanged(): void { + function onPluginsChanged() { root.pluginsChanged(); } } - Component.onCompleted: { - pluginsChanged(); - } + Component.onCompleted: pluginsChanged() - readonly property KDEConnect.DBusAsyncResponse __availableResponse: KDEConnect.DBusAsyncResponse { + readonly property var v: DBusAsyncResponse { id: availableResponse - autoDelete: false - - onSuccess: result => { - root.available = result; - } - - onError: message => { - root.available = false; - } + onSuccess: (result) => { root.available = result; } + onError: () => { root.available = false } } - function pluginsChanged(): void { - if (device) { - availableResponse.setPendingCall(device.hasPlugin("kdeconnect_" + pluginName)); - iconResponse.setPendingCall(device.pluginIconName("kdeconnect_" + pluginName)); - } + function pluginsChanged() { + availableResponse.setPendingCall(device.hasPlugin("kdeconnect_" + pluginName)) + iconResponse.setPendingCall(device.pluginIconName("kdeconnect_" + pluginName)) } - readonly property KDEConnect.DBusAsyncResponse __iconResponse: KDEConnect.DBusAsyncResponse { + readonly property var vv: DBusAsyncResponse { id: iconResponse - autoDelete: false - - onSuccess: result => { - root.iconName = result; - } - - onError: message => { - root.iconName = ""; - } + onSuccess: (result) => { root.iconName = result; } + onError: () => { root.iconName = "" } } } diff --git a/declarativeplugin/qml/RemoteKeyboard.qml b/declarativeplugin/qml/RemoteKeyboard.qml index 737195029..34eec8b88 100644 --- a/declarativeplugin/qml/RemoteKeyboard.qml +++ b/declarativeplugin/qml/RemoteKeyboard.qml @@ -1,108 +1,102 @@ /** * SPDX-FileCopyrightText: 2017 Holger Kaelberer - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound +import QtQuick 2.1 +import org.kde.kdeconnect 1.0 +import QtQuick.Controls 2.4 -import QtQuick -import QtQuick.Controls as QQC2 +TextField { -import org.kde.kdeconnect as KDEConnect - -QQC2.TextField { id: root - property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "remotekeyboard" - device: root.device } - property KDEConnect.RemoteKeyboardDbusInterface remoteKeyboard + property var remoteKeyboard: null - readonly property bool remoteState: available && remoteKeyboard ? remoteKeyboard.remoteState : false + readonly property bool remoteState: available ? remoteKeyboard.remoteState : false Connections { - target: root.remoteKeyboard - - function onKeyPressReceived(key: string, specialKey: int, shift: bool, ctrl: bool, alt: bool): void { + target: remoteKeyboard + function onKeyPressReceived() { //console.log("XXX received keypress key=" + key + " special=" + specialKey + " shift=" + shift + " ctrl=" + ctrl + " text=" + text + " cursorPos=" + cursorPosition); // interpret some special keys: - if (specialKey === 12 || specialKey === 14) { // Return/Esc -> clear + if (specialKey == 12 || specialKey == 14) // Return/Esc -> clear text = ""; - } else if (specialKey === 4 // Left - && cursorPosition > 0) { + else if (specialKey == 4 // Left + && cursorPosition > 0) --cursorPosition; - } else if (specialKey === 6 // Right - && cursorPosition < text.length) { + else if (specialKey == 6 // Right + && cursorPosition < text.length) ++cursorPosition; - } else if (specialKey === 1) { // Backspace -> delete left - const pos = cursorPosition; + else if (specialKey == 1) { // Backspace -> delete left + var pos = cursorPosition; if (pos > 0) { - text = text.substring(0, pos - 1) - + text.substring(pos, text.length); + text = text.substring(0, pos-1) + + text.substring(pos, text.length); cursorPosition = pos - 1; } - } else if (specialKey === 13) { // Delete -> delete right - const pos = cursorPosition; + } else if (specialKey == 13) { // Delete -> delete right + var pos = cursorPosition; if (pos < text.length) { - text = text.substring(0, pos) - + text.substring(pos + 1, text.length); + text = text.substring(0, pos) + + text.substring(pos+1, text.length); cursorPosition = pos; // seems to be set to text.length automatically! } - } else if (specialKey === 10) { // Home + } else if (specialKey == 10) // Home cursorPosition = 0; - } else if (specialKey == 11) { // End + else if (specialKey == 11) // End cursorPosition = text.length; - } else { + else { // echo visible keys - let sanitized = ""; - for (let i = 0; i < key.length; i++) { - if (key.charCodeAt(i) > 31) { + var sanitized = ""; + for (var i = 0; i < key.length; i++) { + if (key.charCodeAt(i) > 31) sanitized += key.charAt(i); - } } if (sanitized.length > 0 && !ctrl && !alt) { // insert sanitized at current pos: - const pos = cursorPosition; + var pos = cursorPosition; text = text.substring(0, pos) - + sanitized - + text.substring(pos, text.length); + + sanitized + + text.substring(pos, text.length); cursorPosition = pos + 1; // seems to be set to text.length automatically! } } - // console.log("XXX After received keypress key=" + key + " special=" + specialKey + " shift=" + shift + " ctrl=" + ctrl + " text=" + text + " cursorPos=" + cursorPosition); +// console.log("XXX After received keypress key=" + key + " special=" + specialKey + " shift=" + shift + " ctrl=" + ctrl + " text=" + text + " cursorPos=" + cursorPosition); } } - function sendEvent(event: KeyEvent): void { + + function sendEvent(event) { if (remoteKeyboard) { - const transEvent = JSON.parse(JSON.stringify(event)); // transform to anonymous object + var transEvent = JSON.parse(JSON.stringify(event)); // transform to anonymous object remoteKeyboard.sendQKeyEvent(transEvent); event.accepted = true } } - Keys.onPressed: event => { - if (available) { + Keys.onPressed: { + if (available) sendEvent(event); - } event.accepted = true; } onAvailableChanged: { - if (available && device !== null) { - remoteKeyboard = KDEConnect.RemoteKeyboardDbusInterfaceFactory.create(device.id()); + if (available) { + remoteKeyboard = RemoteKeyboardDbusInterfaceFactory.create(device.id()); + //remoteKeyboard.keyPressReceived.connect(keyPressReceived); remoteKeyboard.remoteStateChanged.connect(remoteStateChanged); } else { - remoteKeyboard = null; + remoteKeyboard = null } } } diff --git a/plasmoid/package/contents/ui/Battery.qml b/plasmoid/package/contents/ui/Battery.qml index e68ad6080..fe204fe5e 100644 --- a/plasmoid/package/contents/ui/Battery.qml +++ b/plasmoid/package/contents/ui/Battery.qml @@ -1,80 +1,62 @@ /** * SPDX-FileCopyrightText: 2014 Samoilenko Yuri - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.kdeconnect as KDEConnect +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect QtObject { + id: root - required property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "battery" - device: root.device } - readonly property bool charging: battery?.isCharging ?? false - readonly property int charge: battery?.charge ?? -1 - - readonly property string displayString: { - if (available && charge > -1) { - if (charging) { - return i18n("%1% charging", charge); - } else { - return i18n("%1%", charge); - } - } else { - return i18n("No info"); - } - } - - property KDEConnect.BatteryDbusInterface battery + property bool charging: battery ? battery.isCharging : false + property int charge: battery ? battery.charge : -1 + property string displayString: (available && charge > -1) ? ((charging) ? (i18n("%1% charging", charge)) : (i18n("%1%", charge))) : i18n("No info") + property variant battery: null /** * Suggests an icon name to use for the current battery level */ readonly property string iconName: { - if (charge < 0) { - return "battery-missing-symbolic"; - } else if (charge < 10) { - return charging - ? "battery-empty-charging-symbolic" - : "battery-empty-symbolic"; - } else if (charge < 25) { - return charging - ? "battery-caution-charging-symbolic" - : "battery-caution-symbolic"; - } else if (charge < 50) { - return charging - ? "battery-low-charging-symbolic" - : "battery-low-symbolic"; - } else if (charge < 75) { - return charging - ? "battery-good-charging-symbolic" - : "battery-good-symbolic"; - } else { - return charging - ? "battery-full-charging-symbolic" - : "battery-full-symbolic"; - } + charge < 0 ? + "battery-missing-symbolic" : + charge < 10 ? + charging ? + "battery-empty-charging-symbolic" : + "battery-empty-symbolic" : + charge < 25 ? + charging ? + "battery-caution-charging-symbolic" : + "battery-caution-symbolic" : + charge < 50 ? + charging ? + "battery-low-charging-symbolic" : + "battery-low-symbolic" : + charge < 75 ? + charging ? + "battery-good-charging-symbolic" : + "battery-good-symbolic" : + charging ? + "battery-full-charging-symbolic": + "battery-full-symbolic" } onAvailableChanged: { if (available) { - battery = KDEConnect.DeviceBatteryDbusInterfaceFactory.create(device.id()); + battery = DeviceBatteryDbusInterfaceFactory.create(device.id()) } else { - battery = null; + battery = null } } } diff --git a/plasmoid/package/contents/ui/Clipboard.qml b/plasmoid/package/contents/ui/Clipboard.qml index d7b1b0e10..fb8f4ccad 100644 --- a/plasmoid/package/contents/ui/Clipboard.qml +++ b/plasmoid/package/contents/ui/Clipboard.qml @@ -1,32 +1,28 @@ /** * SPDX-FileCopyrightText: 2021 Yaman Qalieh - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.kdeconnect as KDEConnect +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect QtObject { + id: root - required property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "clipboard" - device: root.device } - property KDEConnect.ClipboardDbusInterface clipboard + property variant clipboard: null - function sendClipboard(): void { + function sendClipboard() { if (clipboard) { clipboard.sendClipboard(); } @@ -34,9 +30,9 @@ QtObject { onAvailableChanged: { if (available) { - clipboard = KDEConnect.ClipboardDbusInterfaceFactory.create(device.id()); + clipboard = ClipboardDbusInterfaceFactory.create(device.id()) } else { - clipboard = null; + clipboard = null } } } diff --git a/plasmoid/package/contents/ui/CompactRepresentation.qml b/plasmoid/package/contents/ui/CompactRepresentation.qml index 4d9b4976f..762b3380c 100644 --- a/plasmoid/package/contents/ui/CompactRepresentation.qml +++ b/plasmoid/package/contents/ui/CompactRepresentation.qml @@ -1,44 +1,32 @@ -/** - * SPDX-FileCopyrightText: 2014-2015 Frederic St-Pierre - * SPDX-FileCopyrightText: 2024 ivan tkachenko - * - * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL - */ +/* + SPDX-FileCopyrightText: 2014-2015 Frederic St-Pierre -pragma ComponentBehavior: Bound + SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL +*/ import QtQuick - +import QtQuick.Layouts import org.kde.kirigami as Kirigami -import org.kde.plasma.plasmoid DropArea { - id: root - - required property PlasmoidItem plasmoidItem - - onEntered: drag => { + onEntered: { if (drag.hasUrls) { - root.plasmoidItem.expanded = true; + root.expanded = true; } } MouseArea { + id: kdeConnectMouseArea anchors.fill: parent - property bool wasExpanded: false - - onPressed: mouse => { - wasExpanded = root.plasmoidItem.expanded; - } - - onClicked: mouse => { - root.plasmoidItem.expanded = !root.plasmoidItem.expanded; + onClicked: { + root.expanded = !root.expanded; } } Kirigami.Icon { + id: kdeConnectIcon anchors.fill: parent - source: Plasmoid.icon + source: plasmoid.icon } } diff --git a/plasmoid/package/contents/ui/Connectivity.qml b/plasmoid/package/contents/ui/Connectivity.qml index ea24653f2..9b58eb778 100644 --- a/plasmoid/package/contents/ui/Connectivity.qml +++ b/plasmoid/package/contents/ui/Connectivity.qml @@ -1,27 +1,24 @@ /** * SPDX-FileCopyrightText: 2021 David Shlemayev - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.kdeconnect as KDEConnect +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect QtObject { + id: root - required property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available + readonly property bool ready: connectivity - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "connectivity_report" - device: root.device } /** @@ -40,22 +37,20 @@ QtObject { * The parsing from Android values into these strings is handled in the * [ConnectivityReportPlugin.networkTypeToString method](https://invent.kde.org/network/kdeconnect-android/-/blob/master/src/org/kde/kdeconnect/Plugins/ConnectivityReportPlugin/ConnectivityReportPlugin.java#L82) */ - readonly property string networkType: connectivity?.cellularNetworkType ?? i18n("Unknown") + readonly property string networkType: connectivity ? connectivity.cellularNetworkType : i18n("Unknown") /** * Reports a value between 0 and 4 (inclusive) which represents the strength of the cellular connection */ - readonly property int signalStrength: connectivity?.cellularNetworkStrength ?? -1 - - readonly property string displayString: { - if (connectivity !== null) { + readonly property int signalStrength: connectivity ? connectivity.cellularNetworkStrength : -1 + property string displayString: { + if (ready) { return `${networkType} ${signalStrength}/4`; } else { return i18n("No signal"); } } - - property KDEConnect.ConnectivityReportDbusInterface connectivity + property variant connectivity: null /** * Suggests an icon name to use for the current signal level @@ -65,27 +60,27 @@ QtObject { */ readonly property string iconName: { // Firstly, get the name prefix which represents the signal strength - const signalStrengthIconName = - (signalStrength < 0 || connectivity === null) ? + var signalStrengthIconName = + (signalStrength < 0 || !ready) ? // As long as the signal strength is nonsense or the plugin reports as non-ready, // show us as disconnected "network-mobile-off" : - (signalStrength === 0) ? + (signalStrength == 0) ? "network-mobile-0" : - (signalStrength === 1) ? + (signalStrength == 1) ? "network-mobile-20" : - (signalStrength === 2) ? + (signalStrength == 2) ? "network-mobile-60" : - (signalStrength === 3) ? + (signalStrength == 3) ? "network-mobile-80" : - (signalStrength === 4) ? + (signalStrength == 4) ? "network-mobile-100" : // Since all possible values are enumerated above, this default case should never be hit. // However, I need it in order for my ternary syntax to be valid! - "network-mobile-available"; + "network-mobile-available" // If we understand the network type, append to the icon name to show the type - const networkTypeSuffix = + var networkTypeSuffix = (networkType === "5G") ? // No icon for this case! "" : @@ -115,16 +110,15 @@ QtObject { // GSconnect just uses the 2g icon // No icon for this case! "" : - ""; // We didn't recognize the network type. Don't append anything. - - return signalStrengthIconName + networkTypeSuffix; + "" // We didn't recognize the network type. Don't append anything. + return signalStrengthIconName + networkTypeSuffix } onAvailableChanged: { if (available) { - connectivity = KDEConnect.DeviceConnectivityReportDbusInterfaceFactory.create(device.id()); + connectivity = DeviceConnectivityReportDbusInterfaceFactory.create(device.id()) } else { - connectivity = null; + connectivity = null } } } diff --git a/plasmoid/package/contents/ui/DeviceDelegate.qml b/plasmoid/package/contents/ui/DeviceDelegate.qml index 9e5c35449..386d944fb 100644 --- a/plasmoid/package/contents/ui/DeviceDelegate.qml +++ b/plasmoid/package/contents/ui/DeviceDelegate.qml @@ -1,79 +1,28 @@ /** * SPDX-FileCopyrightText: 2013 Albert Vaca - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - -import QtCore import QtQuick -import QtQuick.Dialogs as QtDialogs import QtQuick.Layouts - -import org.kde.kdeconnect as KDEConnect -import org.kde.kirigami as Kirigami -import org.kde.plasma.components as PlasmaComponents import org.kde.plasma.core as PlasmaCore +import org.kde.plasma.components as PlasmaComponents +import org.kde.kdeconnect +import QtQuick.Controls +import org.kde.kirigami as Kirigami import org.kde.plasma.extras as PlasmaExtras +import QtQuick.Dialogs +import QtCore -PlasmaComponents.ItemDelegate { +PlasmaComponents.ItemDelegate +{ id: root - - required property int index - required property var model - - readonly property KDEConnect.DeviceDbusInterface device: KDEConnect.DeviceDbusInterfaceFactory.create(model.deviceId) + readonly property QtObject device: DeviceDbusInterfaceFactory.create(model.deviceId) hoverEnabled: false down: false - Battery { - id: battery - device: root.device - } - - Clipboard { - id: clipboard - device: root.device - } - - Connectivity { - id: connectivity - device: root.device - } - - FindMyPhone { - id: findmyphone - device: root.device - } - - RemoteCommands { - id: remoteCommands - device: root.device - } - - Sftp { - id: sftp - device: root.device - } - - Share { - id: share - device: root.device - } - - SMS { - id: sms - device: root.device - } - - VirtualMonitor { - id: virtualmonitor - device: root.device - } - Kirigami.PromptDialog { id: prompt visible: false @@ -82,83 +31,27 @@ PlasmaComponents.ItemDelegate { title: i18n("Virtual Monitor is not available") } - QtDialogs.FileDialog { - id: fileDialog - title: i18n("Please choose a file") - currentFolder: StandardPaths.writableLocation(StandardPaths.HomeLocation) - fileMode: QtDialogs.FileDialog.OpenFiles - onAccepted: { - selectedFiles.forEach(url => share.plugin.shareUrl(url)); - } - } - - PlasmaExtras.Menu { - id: menu - - visualParent: overflowMenu - placement: PlasmaExtras.Menu.BottomPosedLeftAlignedPopup - - // Share - PlasmaExtras.MenuItem { - icon: "document-share" - visible: share.available - text: i18n("Share file") - onClicked: fileDialog.open() - } - - // Clipboard - PlasmaExtras.MenuItem { - icon: "klipper" - visible: clipboard.clipboard?.isAutoShareDisabled ?? false - text: i18n("Send Clipboard") - - onClicked: { - clipboard.sendClipboard() - } - } - - // Find my phone - PlasmaExtras.MenuItem { - icon: "irc-voice" - visible: findmyphone.available - text: i18n("Ring my phone") - - onClicked: { - findmyphone.ring() - } - } - - // SFTP - PlasmaExtras.MenuItem { - icon: "document-open-folder" - visible: sftp.available - text: i18n("Browse this device") - - onClicked: { - sftp.browse() - } - } - - // SMS - PlasmaExtras.MenuItem { - icon: "message-new" - visible: sms.available - text: i18n("SMS Messages") - - onClicked: { - sms.plugin.launchApp() - } - } - } - DropArea { id: fileDropArea anchors.fill: parent - onDropped: drop => { + onDropped: { if (drop.hasUrls) { - const urls = new Set(drop.urls.map(url => url.toString())); - urls.forEach(url => share.plugin.shareUrl(url)); + + var urls = []; + + for (var v in drop.urls) { + if (drop.urls[v] != null) { + if (urls.indexOf(drop.urls[v].toString()) == -1) { + urls.push(drop.urls[v].toString()); + } + } + } + + var i; + for (i = 0; i < urls.length; i++) { + share.plugin.shareUrl(urls[i]); + } } drop.accepted = true; } @@ -175,14 +68,30 @@ PlasmaComponents.ItemDelegate { contentItem: ColumnLayout { spacing: Kirigami.Units.smallSpacing - RowLayout { + RowLayout + { width: parent.width spacing: Kirigami.Units.smallSpacing + Battery { + id: battery + device: root.device + } + + Connectivity { + id: connectivity + device: root.device + } + + VirtualMonitor { + id: virtualmonitor + device: root.device + } + PlasmaComponents.Label { id: deviceName elide: Text.ElideRight - text: root.model.name + text: model.name Layout.fillWidth: true textFormat: Text.PlainText } @@ -210,10 +119,9 @@ PlasmaComponents.ItemDelegate { } } } - - RowLayout { + RowLayout + { id: connectionInformation - visible: connectivity.available spacing: Kirigami.Units.smallSpacing @@ -239,10 +147,10 @@ PlasmaComponents.ItemDelegate { } } - RowLayout { + RowLayout + { id: batteryInformation - - visible: battery.available && battery.charge > -1 + visible: (battery.available && battery.charge > -1) spacing: Kirigami.Units.smallSpacing Kirigami.Icon { @@ -263,15 +171,110 @@ PlasmaComponents.ItemDelegate { PlasmaComponents.ToolButton { id: overflowMenu - icon.name: "application-menu" checked: menu.status === PlasmaExtras.Menu.Open onPressed: menu.openRelative() + + PlasmaExtras.Menu { + id: menu + visualParent: overflowMenu + placement: PlasmaExtras.Menu.BottomPosedLeftAlignedPopup + + //Share + PlasmaExtras.MenuItem + { + property FileDialog data: FileDialog { + id: fileDialog + title: i18n("Please choose a file") + currentFolder: StandardPaths.writableLocation(StandardPaths.HomeLocation) + fileMode: FileDialog.OpenFiles + onAccepted: fileDialog.selectedFiles.forEach(url => share.plugin.shareUrl(url)) + } + + id: shareFile + icon: "document-share" + visible: share.available + text: i18n("Share file") + onClicked: fileDialog.open() + } + + //Clipboard + PlasmaExtras.MenuItem + { + property Clipboard data: Clipboard { + id: clipboard + device: root.device + } + + id: sendclipboard + icon: "klipper" + visible: clipboard.available && clipboard.clipboard.isAutoShareDisabled + text: i18n("Send Clipboard") + + onClicked: { + clipboard.sendClipboard() + } + } + + + //Find my phone + PlasmaExtras.MenuItem + { + property FindMyPhone data: FindMyPhone { + id: findmyphone + device: root.device + } + + id: ring + icon: "irc-voice" + visible: findmyphone.available + text: i18n("Ring my phone") + + onClicked: { + findmyphone.ring() + } + } + + //SFTP + PlasmaExtras.MenuItem + { + property Sftp data: Sftp { + id: sftp + device: root.device + } + + id: browse + icon: "document-open-folder" + visible: sftp.available + text: i18n("Browse this device") + + onClicked: { + sftp.browse() + } + } + + //SMS + PlasmaExtras.MenuItem + { + property SMS data: SMS { + id: sms + device: root.device + } + + icon: "message-new" + visible: sms.available + text: i18n("SMS Messages") + + onClicked: { + sms.plugin.launchApp() + } + } + } } } - // RemoteKeyboard + //RemoteKeyboard PlasmaComponents.ItemDelegate { visible: remoteKeyboard.remoteState Layout.fillWidth: true @@ -285,7 +288,7 @@ PlasmaComponents.ItemDelegate { text: i18n("Remote Keyboard") } - KDEConnect.RemoteKeyboard { + RemoteKeyboard { id: remoteKeyboard device: root.device Layout.fillWidth: true @@ -293,9 +296,9 @@ PlasmaComponents.ItemDelegate { } } - // Notifications + //Notifications PlasmaComponents.ItemDelegate { - visible: notificationsModel.count > 0 + visible: notificationsModel.count>0 enabled: true Layout.fillWidth: true @@ -311,26 +314,19 @@ PlasmaComponents.ItemDelegate { visible: notificationsModel.isAnyDimissable; Layout.alignment: Qt.AlignRight icon.name: "edit-clear-history" - PlasmaComponents.ToolTip.text: i18n("Dismiss all notifications") + ToolTip.text: i18n("Dismiss all notifications") onClicked: notificationsModel.dismissAll(); } } } - Repeater { id: notificationsView - - model: KDEConnect.NotificationsModel { + model: NotificationsModel { id: notificationsModel - deviceId: root.model.deviceId + deviceId: root.device.id() } - delegate: PlasmaComponents.ItemDelegate { id: listitem - - required property int index - required property var model - enabled: true onClicked: checked = !checked Layout.fillWidth: true @@ -345,79 +341,72 @@ PlasmaComponents.ItemDelegate { Kirigami.Icon { id: notificationIcon - source: listitem.model.appIcon - width: (valid && listitem.model.appIcon !== "") ? dismissButton.width : 0 + source: appIcon + width: (valid && appIcon.length) ? dismissButton.width : 0 height: width Layout.alignment: Qt.AlignLeft } PlasmaComponents.Label { id: notificationLabel - text: { - const { appName, notitext, title } = listitem.model; - const description = title !== "" ? (appName === title ? notitext : `${title}: ${notitext}`) : notitext; - return `${appName}: ${description}`; - } + text: appName + ": " + (title.length>0 ? (appName==title?notitext:title+": "+notitext) : model.name) elide: listitem.checked ? Text.ElideNone : Text.ElideRight maximumLineCount: listitem.checked ? 0 : 1 - wrapMode: Text.Wrap + wrapMode: Text.WordWrap Layout.fillWidth: true } PlasmaComponents.ToolButton { id: replyButton - visible: listitem.model.repliable - enabled: listitem.model.repliable && !listitem.replying + visible: repliable + enabled: repliable && !replying icon.name: "mail-reply-sender" - PlasmaComponents.ToolTip.text: i18n("Reply") - onClicked: { - listitem.replying = true; - replyTextField.forceActiveFocus(); - } + ToolTip.text: i18n("Reply") + onClicked: { replying = true; replyTextField.forceActiveFocus(); } } PlasmaComponents.ToolButton { id: dismissButton visible: notificationsModel.isAnyDimissable; - enabled: listitem.model.dismissable + enabled: dismissable Layout.alignment: Qt.AlignRight icon.name: "window-close" - PlasmaComponents.ToolTip.text: i18n("Dismiss") - onClicked: listitem.model.dbusInterface.dismiss(); + ToolTip.text: i18n("Dismiss") + onClicked: dbusInterface.dismiss(); } } RowLayout { - visible: listitem.replying + visible: replying width: notificationLabel.width + replyButton.width + dismissButton.width + Kirigami.Units.smallSpacing * 2 spacing: Kirigami.Units.smallSpacing PlasmaComponents.Button { - id: replyCancelButton Layout.alignment: Qt.AlignBottom + id: replyCancelButton text: i18n("Cancel") display: PlasmaComponents.AbstractButton.IconOnly PlasmaComponents.ToolTip { - text: replyCancelButton.text + text: parent.text } icon.name: "dialog-cancel" onClicked: { replyTextField.text = ""; - listitem.replying = false; + replying = false; } } PlasmaComponents.TextArea { id: replyTextField - placeholderText: i18nc("@info:placeholder", "Reply to %1…", listitem.model.appName) + placeholderText: i18nc("@info:placeholder", "Reply to %1…", appName) wrapMode: TextEdit.Wrap Layout.fillWidth: true - Keys.onPressed: event => { - if ((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && !(event.modifiers & Qt.ShiftModifier)) { + Keys.onPressed: { + if ((event.key == Qt.Key_Return || event.key == Qt.Key_Enter) && !(event.modifiers & Qt.ShiftModifier)) { replySendButton.clicked(); event.accepted = true; } - if (event.key === Qt.Key_Escape) { + if (event.key == Qt.Key_Escape) { replyCancelButton.clicked(); event.accepted = true; } @@ -429,11 +418,11 @@ PlasmaComponents.ItemDelegate { id: replySendButton text: i18n("Send") icon.name: "document-send" - enabled: replyTextField.text !== "" + enabled: replyTextField.text onClicked: { - listitem.model.dbusInterface.sendReply(replyTextField.text); + dbusInterface.sendReply(replyTextField.text); replyTextField.text = ""; - listitem.replying = false; + replying = false; } } } @@ -441,9 +430,14 @@ PlasmaComponents.ItemDelegate { } } + RemoteCommands { + id: rc + device: root.device + } + // Commands RowLayout { - visible: remoteCommands.available + visible: rc.available width: parent.width spacing: Kirigami.Units.smallSpacing @@ -452,43 +446,37 @@ PlasmaComponents.ItemDelegate { Layout.fillWidth: true } - PlasmaComponents.Button { + PlasmaComponents.Button + { id: addCommandButton icon.name: "list-add" - PlasmaComponents.ToolTip.text: i18n("Add command") - onClicked: remoteCommands.plugin.editCommands() - visible: remoteCommands.plugin?.canAddCommand ?? false + ToolTip.text: i18n("Add command") + onClicked: rc.plugin.editCommands() + visible: rc.plugin && rc.plugin.canAddCommand } } - Repeater { id: commandsView - - visible: remoteCommands.available - - model: KDEConnect.RemoteCommandsModel { + visible: rc.available + model: RemoteCommandsModel { id: commandsModel - deviceId: root.model.deviceId + deviceId: rc.device.id() } - delegate: PlasmaComponents.ItemDelegate { - id: commandDelegate - - required property int index - required property var model - enabled: true - - onClicked: { - remoteCommands.plugin?.triggerCommand(commandDelegate.model.key); - } - + onClicked: rc.plugin.triggerCommand(key) Layout.fillWidth: true contentItem: PlasmaComponents.Label { - text: `${commandDelegate.model.name}\n${commandDelegate.model.command}` + text: name + "\n" + command } } } + + // Share + Share { + id: share + device: root.device + } } } diff --git a/plasmoid/package/contents/ui/FindMyPhone.qml b/plasmoid/package/contents/ui/FindMyPhone.qml index aaa11f4b9..422be4aa7 100644 --- a/plasmoid/package/contents/ui/FindMyPhone.qml +++ b/plasmoid/package/contents/ui/FindMyPhone.qml @@ -1,32 +1,28 @@ /** * SPDX-FileCopyrightText: 2014 Samoilenko Yuri - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.kdeconnect as KDEConnect +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect QtObject { + id: root - required property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "findmyphone" - device: root.device } - property KDEConnect.FindMyPhoneDbusInterface findMyPhone + property variant findMyPhone: null - function ring(): void { + function ring() { if (findMyPhone) { findMyPhone.ring(); } @@ -34,9 +30,9 @@ QtObject { onAvailableChanged: { if (available) { - findMyPhone = KDEConnect.FindMyPhoneDbusInterfaceFactory.create(device.id()); + findMyPhone = FindMyPhoneDbusInterfaceFactory.create(device.id()) } else { - findMyPhone = null; + findMyPhone = null } } } diff --git a/plasmoid/package/contents/ui/FullRepresentation.qml b/plasmoid/package/contents/ui/FullRepresentation.qml index b4efce81d..c53cacdd1 100644 --- a/plasmoid/package/contents/ui/FullRepresentation.qml +++ b/plasmoid/package/contents/ui/FullRepresentation.qml @@ -1,45 +1,40 @@ /** * SPDX-FileCopyrightText: 2013 Albert Vaca - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick -import QtQuick.Controls as QQC2 -import QtQuick.Layouts - -import org.kde.config as KConfig -import org.kde.kcmutils as KCMUtils -import org.kde.kdeconnect as KDEConnect -import org.kde.kirigami as Kirigami +import QtQuick.Controls +import org.kde.plasma.core as PlasmaCore import org.kde.plasma.components as PlasmaComponents3 import org.kde.plasma.extras as PlasmaExtras +import org.kde.kdeconnect as KdeConnect +import QtQuick.Layouts +import org.kde.kquickcontrolsaddons +import org.kde.kirigami as Kirigami +import org.kde.kcmutils as KCMUtils +import org.kde.config as KConfig PlasmaExtras.Representation { id: kdeconnect - property alias devicesModel: devicesView.model - collapseMarginsHint: true - KDEConnect.DevicesModel { + KdeConnect.DevicesModel { id: allDevicesModel } - - KDEConnect.DevicesModel { + KdeConnect.DevicesModel { id: pairedDevicesModel - displayFilter: KDEConnect.DevicesModel.Paired + displayFilter: KdeConnect.DevicesModel.Paired } PlasmaComponents3.ScrollView { + id: dialogItem anchors.fill: parent contentItem: ListView { id: devicesView - spacing: Kirigami.Units.smallSpacing clip: true @@ -62,16 +57,16 @@ PlasmaExtras.Representation { text: { if (pairedDevicesModel.count >= 0) { - return pairedDevicesModel.count === 0 ? i18n("No paired devices") : i18np("Paired device is unavailable", "All paired devices are unavailable", pairedDevicesModel.count) - } else if (allDevicesModel.count === 0) { + return pairedDevicesModel.count == 0 ? i18n("No paired devices") : i18np("Paired device is unavailable", "All paired devices are unavailable", pairedDevicesModel.count) + } else if (allDevicesModel.count == 0) { return i18n("Install KDE Connect on your Android device to integrate it with Plasma!") } } - helpfulAction: QQC2.Action { + helpfulAction: Action { text: i18n("Pair a Device…") icon.name: "list-add" onTriggered: KCMUtils.KCMLauncher.openSystemSettings("kcm_kdeconnect") - enabled: pairedDevicesModel.count === 0 && KConfig.KAuthorized.authorizeControlModule("kcm_kdeconnect") + enabled: pairedDevicesModel.count == 0 && KConfig.KAuthorized.authorizeControlModule("kcm_kdeconnect") } PlasmaComponents3.Button { diff --git a/plasmoid/package/contents/ui/RemoteCommands.qml b/plasmoid/package/contents/ui/RemoteCommands.qml index 4eec58306..e9c388c5a 100644 --- a/plasmoid/package/contents/ui/RemoteCommands.qml +++ b/plasmoid/package/contents/ui/RemoteCommands.qml @@ -1,29 +1,24 @@ /** * SPDX-FileCopyrightText: 2018 Nicolas Fella - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.kdeconnect as KDEConnect +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect QtObject { + id: root - required property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "remotecommands" - device: root.device } - property KDEConnect.RemoteCommandsDbusInterface plugin: - available ? KDEConnect.RemoteCommandsDbusInterfaceFactory.create(device.id()) : null + property variant plugin: available ? RemoteCommandsDbusInterfaceFactory.create(device.id()) : null } diff --git a/plasmoid/package/contents/ui/SMS.qml b/plasmoid/package/contents/ui/SMS.qml index 39b951fd2..9d615efe2 100644 --- a/plasmoid/package/contents/ui/SMS.qml +++ b/plasmoid/package/contents/ui/SMS.qml @@ -1,29 +1,25 @@ /** * SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.kdeconnect as KDEConnect +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect QtObject { + id: root - required property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "sms" - device: root.device } - readonly property KDEConnect.SmsDbusInterface plugin: - available ? KDEConnect.SmsDbusInterfaceFactory.create(device.id()) : null + readonly property variant plugin: available ? SmsDbusInterfaceFactory.create(device.id()) : null } + diff --git a/plasmoid/package/contents/ui/Sftp.qml b/plasmoid/package/contents/ui/Sftp.qml index a032969fb..0a426fc0a 100644 --- a/plasmoid/package/contents/ui/Sftp.qml +++ b/plasmoid/package/contents/ui/Sftp.qml @@ -1,42 +1,37 @@ /** * SPDX-FileCopyrightText: 2014 Samoilenko Yuri - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.kdeconnect as KDEConnect +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect QtObject { + id: root - required property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "sftp" - device: root.device } - property KDEConnect.SftpDbusInterface sftp + property variant sftp: null - function browse(): void { - if (sftp) { + function browse() { + if (sftp) sftp.startBrowsing(); - } } onAvailableChanged: { if (available) { - sftp = KDEConnect.SftpDbusInterfaceFactory.create(device.id()); + sftp = SftpDbusInterfaceFactory.create(device.id()) } else { - sftp = null; + sftp = null } } } diff --git a/plasmoid/package/contents/ui/Share.qml b/plasmoid/package/contents/ui/Share.qml index a55450feb..319984865 100644 --- a/plasmoid/package/contents/ui/Share.qml +++ b/plasmoid/package/contents/ui/Share.qml @@ -1,29 +1,25 @@ /** * SPDX-FileCopyrightText: 2018 Nicolas Fella - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.kdeconnect as KDEConnect +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect QtObject { + id: root - required property KDEConnect.DeviceDbusInterface device - + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "share" - device: root.device } - property KDEConnect.ShareDbusInterface plugin: - available ? KDEConnect.ShareDbusInterfaceFactory.create(device.id()) : null + property variant plugin: available ? ShareDbusInterfaceFactory.create(device.id()) : null } + diff --git a/plasmoid/package/contents/ui/VirtualMonitor.qml b/plasmoid/package/contents/ui/VirtualMonitor.qml index b7b693697..2438214a1 100644 --- a/plasmoid/package/contents/ui/VirtualMonitor.qml +++ b/plasmoid/package/contents/ui/VirtualMonitor.qml @@ -1,29 +1,23 @@ /** - * SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez - * SPDX-FileCopyrightText: 2024 ivan tkachenko + * SPDX-FileCopyrightText: 2021 Aleix Pol i Gonzalez * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick +import org.kde.plasma.core as PlasmaCore +import org.kde.kdeconnect -import org.kde.kdeconnect as KDEConnect - -QtObject { - id: root - - required property KDEConnect.DeviceDbusInterface device - +QtObject +{ + property alias device: checker.device readonly property alias available: checker.available - readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker { + readonly property PluginChecker pluginChecker: PluginChecker { id: checker pluginName: "virtualmonitor" - device: root.device } - readonly property KDEConnect.VirtualmonitorDbusInterface plugin: - available ? KDEConnect.VirtualmonitorDbusInterfaceFactory.create(device.id()) : null + readonly property QtObject plugin: available ? VirtualmonitorDbusInterfaceFactory.create(device.id()) : null } + diff --git a/plasmoid/package/contents/ui/main.qml b/plasmoid/package/contents/ui/main.qml index 8ac2d87cf..6aad1e95d 100644 --- a/plasmoid/package/contents/ui/main.qml +++ b/plasmoid/package/contents/ui/main.qml @@ -1,61 +1,65 @@ /** * SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez - * SPDX-FileCopyrightText: 2024 ivan tkachenko * * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL */ -pragma ComponentBehavior: Bound - import QtQuick - -import org.kde.config as KConfig -import org.kde.kcmutils as KCMUtils -import org.kde.kdeconnect as KDEConnect -import org.kde.kquickcontrolsaddons as KQuickControlsAddons import org.kde.plasma.core as PlasmaCore import org.kde.plasma.plasmoid +import org.kde.kquickcontrolsaddons +import org.kde.kdeconnect +import org.kde.kcmutils as KCMUtils +import org.kde.config as KConfig -PlasmoidItem { +PlasmoidItem +{ id: root - readonly property bool inPanel: [ - PlasmaCore.Types.TopEdge, - PlasmaCore.Types.RightEdge, - PlasmaCore.Types.BottomEdge, - PlasmaCore.Types.LeftEdge, - ].includes(Plasmoid.location) + readonly property bool inPanel: (plasmoid.location == PlasmaCore.Types.TopEdge + || plasmoid.location == PlasmaCore.Types.RightEdge + || plasmoid.location == PlasmaCore.Types.BottomEdge + || plasmoid.location == PlasmaCore.Types.LeftEdge) - KDEConnect.DevicesModel { - id: connectedDeviceModel - displayFilter: KDEConnect.DevicesModel.Paired | KDEConnect.DevicesModel.Reachable + DevicesModel { + id: connectDeviceModel + displayFilter: DevicesModel.Paired | DevicesModel.Reachable } - KDEConnect.DevicesModel { + DevicesModel { id: pairedDeviceModel - displayFilter: KDEConnect.DevicesModel.Paired + displayFilter: DevicesModel.Paired } - Plasmoid.icon: inPanel - ? "kdeconnect-tray-symbolic" - : "kdeconnect-tray" + Plasmoid.icon: { + let iconName = "kdeconnect-tray"; - Plasmoid.status: connectedDeviceModel.count > 0 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus + if (inPanel) { + return "kdeconnect-tray-symbolic"; + } + + return iconName; + } + + Binding { + target: plasmoid + property: "status" + value: (connectDeviceModel.count > 0) ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus + } fullRepresentation: FullRepresentation { - devicesModel: connectedDeviceModel + devicesModel: connectDeviceModel } compactRepresentation: CompactRepresentation { - plasmoidItem: root } PlasmaCore.Action { id: configureAction text: i18n("KDE Connect Settings…") icon.name: "configure" - visible: KConfig.KAuthorized.authorizeControlModule("kcm_kdeconnect") - onTriggered: checked => { + visible: KConfig.KAuthorized.authorizeControlModule("kcm_kdeconnect"); + onTriggered: { KCMUtils.KCMLauncher.openSystemSettings("kcm_kdeconnect"); } }