diff --git a/.kde-ci.yml b/.kde-ci.yml
index d4380ac00..c91c9e503 100644
--- a/.kde-ci.yml
+++ b/.kde-ci.yml
@@ -31,6 +31,7 @@ Dependencies:
- 'on': ['Linux', 'FreeBSD']
'require':
'frameworks/kdbusaddons': '@latest-kf6'
+ 'frameworks/purpose': '@latest-kf6'
- 'on': ['Linux']
'require':
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4b7045ed0..0e8a225e9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -293,7 +293,6 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
qml/RoomInformation.qml
qml/RoomMedia.qml
qml/ChooseRoomDialog.qml
- qml/ShareAction.qml
qml/SpaceHomePage.qml
qml/SpaceHierarchyDelegate.qml
qml/RemoveChildDialog.qml
@@ -332,6 +331,16 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
qml/glowdot.png
)
+if(UNIX)
+ qt_target_qml_sources(neochat QML_FILES qml/ShareAction.qml)
+else()
+ set_source_files_properties(qml/ShareActionStub.qml PROPERTIES
+ QT_RESOURCE_ALIAS qml/ShareAction.qml
+ )
+ qt_target_qml_sources(neochat QML_FILES qml/ShareActionStub.qml)
+endif()
+
+
configure_file(config-neochat.h.in ${CMAKE_CURRENT_BINARY_DIR}/config-neochat.h)
if(WIN32)
diff --git a/src/neochat.notifyrc b/src/neochat.notifyrc
index 578c946d1..359ec9e0b 100644
--- a/src/neochat.notifyrc
+++ b/src/neochat.notifyrc
@@ -243,3 +243,8 @@ Comment[x-test]=xxThere is a new invitation to a roomxx
Comment[zh_CN]=有新的聊天室邀请
Comment[zh_TW]=有新的加入聊天室邀請
Action=Popup
+
+[Event/Share]
+Name=Share
+Comment=The result of sharing a piece of content
+Action=Popup
diff --git a/src/qml/FileDelegateContextMenu.qml b/src/qml/FileDelegateContextMenu.qml
index 0ed8b65ee..a783c67e6 100644
--- a/src/qml/FileDelegateContextMenu.qml
+++ b/src/qml/FileDelegateContextMenu.qml
@@ -89,20 +89,12 @@ DelegateContextMenu {
ShareAction {
id: shareAction
inputData: {
- 'urls': [],
- 'mimeType': [root.mimeType]
+ "urls": [filename],
+ "mimeType": [root.mimeType]
}
+ room: currentRoom
+ eventId: root.eventId
property string filename: StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(eventId)
-
- doBeforeSharing: () => {
- currentRoom.downloadFile(eventId, filename);
- }
- Component.onCompleted: {
- shareAction.inputData = {
- urls: [filename],
- mimeType: [root.mimeType]
- };
- }
}
]
diff --git a/src/qml/ShareAction.qml b/src/qml/ShareAction.qml
index c5d77eec2..d62afb7b3 100644
--- a/src/qml/ShareAction.qml
+++ b/src/qml/ShareAction.qml
@@ -3,12 +3,16 @@
import QtQuick
import QtQuick.Layouts
+
import org.kde.kirigami as Kirigami
+import org.kde.purpose as Purpose
+
+import org.kde.neochat
/**
- * Action that allows an user to share data with other apps and service
+ * Action that allows a user to share data with other apps and services
* installed on their computer. The goal of this high level API is to
- * adapte itself for each platform and adopt the native component.
+ * adapt itself for each platform and adopt the native component.
*
* TODO add Android support
*/
@@ -19,7 +23,6 @@ Kirigami.Action {
text: i18n("Share")
tooltip: i18n("Share the selected media")
- property var doBeforeSharing: () => {}
visible: false
/**
@@ -34,19 +37,15 @@ Kirigami.Action {
* }
* @endcode
*/
- property var inputData: ({})
+ property var inputData
+
+ required property string eventId
+ required property NeoChatRoom room
property Instantiator _instantiator: Instantiator {
- Component.onCompleted: {
- const purposeModel = Qt.createQmlObject('import org.kde.purpose as Purpose;
-Purpose.PurposeAlternativesModel {
- pluginType: "Export"
-}', root._instantiator);
- purposeModel.inputData = Qt.binding(function () {
- return root.inputData;
- });
- _instantiator.model = purposeModel;
- root.visible = true;
+ model: Purpose.PurposeAlternativesModel {
+ pluginType: "Export"
+ inputData: root.inputData
}
delegate: Kirigami.Action {
@@ -54,12 +53,21 @@ Purpose.PurposeAlternativesModel {
text: model.display
icon.name: model.iconName
onTriggered: {
- doBeforeSharing();
+ root.room.download(root.eventId, root.inputData.urls[0]);
+ root.room.fileTransferCompleted.connect(share);
+ }
+ function share(id) {
+ if (id != root.eventId) {
+ return;
+ }
applicationWindow().pageStack.pushDialogLayer('qrc:/org/kde/neochat/qml/ShareDialog.qml', {
- title: root.tooltip,
+ title: root.text,
index: index,
model: root._instantiator.model
+ }, {
+ title: i18nc("@title", "Share")
});
+ root.room.fileTransferCompleted.disconnect(share);
}
}
onObjectAdded: (index, object) => {
diff --git a/src/qml/ShareActionAndroid.qml b/src/qml/ShareActionStub.qml
similarity index 84%
rename from src/qml/ShareActionAndroid.qml
rename to src/qml/ShareActionStub.qml
index 0adef963b..c03ea9572 100644
--- a/src/qml/ShareActionAndroid.qml
+++ b/src/qml/ShareActionStub.qml
@@ -5,6 +5,7 @@ import org.kde.kirigami as Kirigami
Kirigami.Action {
property var inputData: ({})
- property var doBeforeSharing: () => {}
+ property var room
+ property string eventId
visible: false
}
diff --git a/src/qml/ShareDialog.qml b/src/qml/ShareDialog.qml
index e08986911..e7ec24a43 100644
--- a/src/qml/ShareDialog.qml
+++ b/src/qml/ShareDialog.qml
@@ -8,9 +8,12 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Controls as QQC2
+
import org.kde.purpose as Purpose
-import org.kde.notification
import org.kde.kirigami as Kirigami
+import org.kde.notification
+
+import org.kde.neochat
Kirigami.Page {
id: root
@@ -30,29 +33,31 @@ Kirigami.Page {
Notification {
id: sharingFailed
- eventId: "sharingFailed"
+ eventId: "Share"
text: i18n("Sharing failed")
urgency: Notification.NormalUrgency
}
Notification {
id: sharingSuccess
- eventId: "sharingSuccess"
+ eventId: "Share"
flags: Notification.Persistent
}
- Component.onCompleted: jobView.start()
+ Component.onCompleted: {
+ jobView.start();
+ }
- contentItem: Purpose.JobView {
+ Purpose.JobView {
id: jobView
+
+ anchors.fill: parent
onStateChanged: {
if (state === Purpose.PurposeJobController.Finished) {
- if (jobView.job.output.url !== "") {
- // Show share url
- // TODO no needed anymore in purpose > 5.90
- sharingSuccess.text = i18n("Shared url for image is %1", jobView.output.url);
+ if (jobView.job?.output?.url?.length > 0) {
+ sharingSuccess.text = i18n("Shared url for image is %1", jobView.job.output.url);
sharingSuccess.sendEvent();
- Clipboard.saveText(jobView.output.url);
+ Clipboard.saveText(jobView.job.output.url);
}
root.closeDialog();
} else if (state === Purpose.PurposeJobController.Error) {