diff --git a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml --- a/applets/clipboard/contents/ui/ClipboardItemDelegate.qml +++ b/applets/clipboard/contents/ui/ClipboardItemDelegate.qml @@ -29,13 +29,15 @@ property bool supportsBarcodes property int maximumNumberOfPreviews: Math.floor(width / (units.gridUnit * 4 + units.smallSpacing)) + property string labelText readonly property real gradientThreshold: (label.width - toolButtonsLoader.width) / label.width signal itemSelected(string uuid) signal remove(string uuid) signal edit(string uuid) signal barcode(string uuid) signal action(string uuid) + signal share(string text) // the 1.6 comes from ToolButton's default height height: Math.max(label.height, Math.round(units.gridUnit * 1.6)) + 2 * units.smallSpacing @@ -103,6 +105,9 @@ Loader { width: parent.width source: ["Text", "Image", "Url"][TypeRole] + "ItemDelegate.qml" + function textUpdated(text) { + labelText = text + } } } diff --git a/applets/clipboard/contents/ui/ClipboardPage.qml b/applets/clipboard/contents/ui/ClipboardPage.qml --- a/applets/clipboard/contents/ui/ClipboardPage.qml +++ b/applets/clipboard/contents/ui/ClipboardPage.qml @@ -122,5 +122,13 @@ clipboardSource.service(uuid, "action") clipboardMenu.view.currentIndex = 0 } + onShare: { + shareLoader.item.share(text) + } + } + + Loader { + id: shareLoader + source: "Share.qml" } } diff --git a/applets/clipboard/contents/ui/DelegateToolButtons.qml b/applets/clipboard/contents/ui/DelegateToolButtons.qml --- a/applets/clipboard/contents/ui/DelegateToolButtons.qml +++ b/applets/clipboard/contents/ui/DelegateToolButtons.qml @@ -26,6 +26,12 @@ id: toolButtonsLayout visible: menuItem.ListView.isCurrentItem + PlasmaComponents.ToolButton { + iconSource: "system-run" + visible: TypeRole === 0 + tooltip: i18n("Invoke action") + onClicked: menuItem.share(labelText) + } PlasmaComponents.ToolButton { // TODO: only show for items supporting actions? iconSource: "system-run" diff --git a/applets/clipboard/contents/ui/Menu.qml b/applets/clipboard/contents/ui/Menu.qml --- a/applets/clipboard/contents/ui/Menu.qml +++ b/applets/clipboard/contents/ui/Menu.qml @@ -30,6 +30,7 @@ signal edit(string uuid) signal barcode(string uuid) signal action(string uuid) + signal share(string text) ListView { id: menuListView @@ -51,6 +52,7 @@ onEdit: menu.edit(uuid) onBarcode: menu.barcode(uuid) onAction: menu.action(uuid) + onShare: menu.share(text) } } } diff --git a/applets/clipboard/contents/ui/Share.qml b/applets/clipboard/contents/ui/Share.qml new file mode 100644 --- /dev/null +++ b/applets/clipboard/contents/ui/Share.qml @@ -0,0 +1,50 @@ +import QtQuick 2.1 +import QtQml 2.11 +import QtQuick.Controls 2.4 +import org.kde.plasma.core 2.0 as PlasmaCore +import QtQml.Models 2.11 +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.kdeconnect 1.0 + +Row { + id: share + + property int deviceIndex: -1 + property string shareText + property QtObject device + property variant plugin + + Menu { + id: deviceMenu + Instantiator { + model: DevicesSortProxyModel { + id: devicesModel + sourceModel: DevicesModel { displayFilter: DevicesModel.Paired | DevicesModel.Reachable } + } + delegate: MenuItem { + text: deviceName + onTriggered: { + var urlRegx = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/ + if (deviceIndex != index) { + device = devicesModel.data(devicesModel.index(index, 0), DevicesModel.DeviceRole) + plugin = ShareDbusInterfaceFactory.create(device.id()) + deviceIndex = index + } + deviceMenu.dismiss() + if (urlRegx.test(shareText)) { + plugin.shareUrl(shareText) + } else { + plugin.shareText(shareText) + } + } + } + onObjectAdded: deviceMenu.insertItem(index, object) + onObjectRemoved: deviceMenu.removeItem(object) + } + } + + function share(text) { + shareText = text + deviceMenu.open() + } +} diff --git a/applets/clipboard/contents/ui/TextItemDelegate.qml b/applets/clipboard/contents/ui/TextItemDelegate.qml --- a/applets/clipboard/contents/ui/TextItemDelegate.qml +++ b/applets/clipboard/contents/ui/TextItemDelegate.qml @@ -47,6 +47,7 @@ // finally turn line breaks into HTML br tags text = text.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, "
") + textUpdated(text) return text }