[utilities/qrca] /: Add a share button using Purpose AlternativesView

Kai Uwe Broulik <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 7f48d8c15b2e9c66cbb52689f21e0508914d05aa by Kai Uwe Broulik, on behalf of Michael Rostom.
Committed on 21/07/2026 at 05:16.
Pushed by broulik into branch 'master'.

Add a share button using Purpose AlternativesView

See also #16

M  +1    -0    .kde-ci.yml
M  +1    -1    CMakeLists.txt
M  +4    -0    src/CMakeLists.txt
M  +17   -1    src/qml/QrCodeScannerPage.qml
A  +36   -0    src/qml/ShareSheet.qml  *

The files marked with a * at the end have a non valid license. Please read: https://community.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://invent.kde.org/utilities/qrca/-/commit/7f48d8c15b2e9c66cbb52689f21e0508914d05aa

diff --git a/.kde-ci.yml b/.kde-ci.yml
index 7e9a37e..7e40296 100644
--- a/.kde-ci.yml
+++ b/.kde-ci.yml
@@ -18,6 +18,7 @@ Dependencies:
     'frameworks/kservice': '@latest-kf6'
     'frameworks/kio': '@latest-kf6'
     'frameworks/kcrash': '@latest-kf6'
+    'frameworks/purpose': '@latest-kf6'
 
  - 'on': ['Linux']
    'require':
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 22733b9..ecdec88 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,7 +42,7 @@ find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS Kirigami I18n Contacts Co
 find_package(KF6KirigamiAddons REQUIRED)
 
 if(NOT ANDROID)
-    find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS Service KIO Crash DBusAddons)
+    find_package(KF6 ${KF_MIN_VERSION} REQUIRED COMPONENTS Service KIO Crash DBusAddons Purpose)
     find_package(KF6 ${KF_MIN_VERSION} OPTIONAL_COMPONENTS NetworkManagerQt)
 endif()
 
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f301e3f..0b40223 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -25,6 +25,7 @@ ecm_target_qml_sources(qrca SOURCES
     qml/QrCodeScannerPage.qml
     qml/QrCodeEncoderPage.qml
     qml/AboutPage.qml
+    qml/ShareSheet.qml
 )
 
 file(GLOB ICONS_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/../icons/*.png")
@@ -36,6 +37,9 @@ if (TARGET KF6::NetworkManagerQt)
     target_link_libraries(qrca PRIVATE KF6::NetworkManagerQt)
 endif()
 
+if (NOT ANDROID)
+    target_link_libraries(qrca PRIVATE KF6::Purpose)
+endif()
 target_compile_definitions(qrca PRIVATE -DQT_NO_CAST_FROM_ASCII)
 
 if(ANDROID)
diff --git a/src/qml/QrCodeScannerPage.qml b/src/qml/QrCodeScannerPage.qml
index ab8b8e9..cddff1b 100644
--- a/src/qml/QrCodeScannerPage.qml
+++ b/src/qml/QrCodeScannerPage.qml
@@ -274,7 +274,7 @@ Kirigami.Page {
                 Layout.fillWidth: true
             }
             Controls.Button {
-                text: i18n("Copy to Clipboard")
+                text: i18nc("@action:button","Copy to Clipboard")
                 icon.name: "edit-copy-symbolic"
                 onClicked: {
                     Qrca.copyToClipboard(resultSheet.tag);
@@ -282,8 +282,24 @@ Kirigami.Page {
                 }
                 Layout.fillWidth: true
             }
+            Controls.Button {
+                text: i18nc("@action:button","Share…")
+                icon.name: "emblem-shared-symbolic"
+                visible: Qt.platform.os != "android"
+                onClicked: {
+                    // disabledPlugins won't disable clipboard plugin on old versions of purpose framework, because it didn't have the property
+                    shareSheetLoader.setSource("ShareSheet.qml",
+                                               { "text": resultSheet.tag.text, "disabledPlugins": ["clipboardplugin"]});
+                    shareSheetLoader.item.open();
+                }
+                Layout.fillWidth: true
+            }
         }
     }
+    Loader {
+        id: shareSheetLoader
+    }
+
 
     Kirigami.OverlaySheet {
         id: cameraSelectorSheet
diff --git a/src/qml/ShareSheet.qml b/src/qml/ShareSheet.qml
new file mode 100644
index 0000000..918fcbe
--- /dev/null
+++ b/src/qml/ShareSheet.qml
@@ -0,0 +1,36 @@
+import QtQml
+import QtQuick.Layouts
+
+import org.kde.kirigami as Kirigami
+import org.kde.purpose as Purpose
+
+Kirigami.PromptDialog {
+    id: shareSheet
+    required property string text
+    property var disabledPlugins: []
+    implicitWidth: Kirigami.Units.gridUnit * 20
+    title: i18nc("@title:window", "Share")
+    Purpose.AlternativesView {
+        id: alternativesView
+        Layout.fillWidth: true
+        pluginType: "ShareUrl"
+
+        Component.onCompleted: {
+            if ("disabledPlugins" in alternativesView) {
+                alternativesView.disabledPlugins = shareSheet.disabledPlugins;
+            }
+        }
+        inputData: {
+            "urls": [shareSheet.text],
+            "title": i18n("Scanned using Qrca")
+        }
+        onFinished: (output, error, message) => {
+            shareSheet.close();
+            if (error !== 0) {
+                console.error("job finished with error", error, message);
+            }
+            alternativesView.reset();
+            shareSheetLoader.source = "";
+        }
+    }
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.