Fix sharing

This commit is contained in:
Tobias Fella
2024-02-19 22:50:16 +01:00
parent 5b0068d9e4
commit 38acfe04b9
7 changed files with 61 additions and 40 deletions

View File

@@ -31,6 +31,7 @@ Dependencies:
- 'on': ['Linux', 'FreeBSD'] - 'on': ['Linux', 'FreeBSD']
'require': 'require':
'frameworks/kdbusaddons': '@latest-kf6' 'frameworks/kdbusaddons': '@latest-kf6'
'frameworks/purpose': '@latest-kf6'
- 'on': ['Linux'] - 'on': ['Linux']
'require': 'require':

View File

@@ -293,7 +293,6 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
qml/RoomInformation.qml qml/RoomInformation.qml
qml/RoomMedia.qml qml/RoomMedia.qml
qml/ChooseRoomDialog.qml qml/ChooseRoomDialog.qml
qml/ShareAction.qml
qml/SpaceHomePage.qml qml/SpaceHomePage.qml
qml/SpaceHierarchyDelegate.qml qml/SpaceHierarchyDelegate.qml
qml/RemoveChildDialog.qml qml/RemoveChildDialog.qml
@@ -332,6 +331,16 @@ qt_add_qml_module(neochat URI org.kde.neochat NO_PLUGIN
qml/glowdot.png 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) configure_file(config-neochat.h.in ${CMAKE_CURRENT_BINARY_DIR}/config-neochat.h)
if(WIN32) if(WIN32)

View File

@@ -243,3 +243,8 @@ Comment[x-test]=xxThere is a new invitation to a roomxx
Comment[zh_CN]=有新的聊天室邀请 Comment[zh_CN]=有新的聊天室邀请
Comment[zh_TW]=有新的加入聊天室邀請 Comment[zh_TW]=有新的加入聊天室邀請
Action=Popup Action=Popup
[Event/Share]
Name=Share
Comment=The result of sharing a piece of content
Action=Popup

View File

@@ -89,20 +89,12 @@ DelegateContextMenu {
ShareAction { ShareAction {
id: shareAction id: shareAction
inputData: { inputData: {
'urls': [], "urls": [filename],
'mimeType': [root.mimeType] "mimeType": [root.mimeType]
} }
room: currentRoom
eventId: root.eventId
property string filename: StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/" + eventId.replace(":", "_").replace("/", "_").replace("+", "_") + currentRoom.fileNameToDownload(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]
};
}
} }
] ]

View File

@@ -3,12 +3,16 @@
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import org.kde.kirigami as Kirigami 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 * 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 * TODO add Android support
*/ */
@@ -19,7 +23,6 @@ Kirigami.Action {
text: i18n("Share") text: i18n("Share")
tooltip: i18n("Share the selected media") tooltip: i18n("Share the selected media")
property var doBeforeSharing: () => {}
visible: false visible: false
/** /**
@@ -34,19 +37,15 @@ Kirigami.Action {
* } * }
* @endcode * @endcode
*/ */
property var inputData: ({}) property var inputData
required property string eventId
required property NeoChatRoom room
property Instantiator _instantiator: Instantiator { property Instantiator _instantiator: Instantiator {
Component.onCompleted: { model: Purpose.PurposeAlternativesModel {
const purposeModel = Qt.createQmlObject('import org.kde.purpose as Purpose; pluginType: "Export"
Purpose.PurposeAlternativesModel { inputData: root.inputData
pluginType: "Export"
}', root._instantiator);
purposeModel.inputData = Qt.binding(function () {
return root.inputData;
});
_instantiator.model = purposeModel;
root.visible = true;
} }
delegate: Kirigami.Action { delegate: Kirigami.Action {
@@ -54,12 +53,21 @@ Purpose.PurposeAlternativesModel {
text: model.display text: model.display
icon.name: model.iconName icon.name: model.iconName
onTriggered: { 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', { applicationWindow().pageStack.pushDialogLayer('qrc:/org/kde/neochat/qml/ShareDialog.qml', {
title: root.tooltip, title: root.text,
index: index, index: index,
model: root._instantiator.model model: root._instantiator.model
}, {
title: i18nc("@title", "Share")
}); });
root.room.fileTransferCompleted.disconnect(share);
} }
} }
onObjectAdded: (index, object) => { onObjectAdded: (index, object) => {

View File

@@ -5,6 +5,7 @@ import org.kde.kirigami as Kirigami
Kirigami.Action { Kirigami.Action {
property var inputData: ({}) property var inputData: ({})
property var doBeforeSharing: () => {} property var room
property string eventId
visible: false visible: false
} }

View File

@@ -8,9 +8,12 @@
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Controls as QQC2 import QtQuick.Controls as QQC2
import org.kde.purpose as Purpose import org.kde.purpose as Purpose
import org.kde.notification
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
import org.kde.notification
import org.kde.neochat
Kirigami.Page { Kirigami.Page {
id: root id: root
@@ -30,29 +33,31 @@ Kirigami.Page {
Notification { Notification {
id: sharingFailed id: sharingFailed
eventId: "sharingFailed" eventId: "Share"
text: i18n("Sharing failed") text: i18n("Sharing failed")
urgency: Notification.NormalUrgency urgency: Notification.NormalUrgency
} }
Notification { Notification {
id: sharingSuccess id: sharingSuccess
eventId: "sharingSuccess" eventId: "Share"
flags: Notification.Persistent flags: Notification.Persistent
} }
Component.onCompleted: jobView.start() Component.onCompleted: {
jobView.start();
}
contentItem: Purpose.JobView { Purpose.JobView {
id: jobView id: jobView
anchors.fill: parent
onStateChanged: { onStateChanged: {
if (state === Purpose.PurposeJobController.Finished) { if (state === Purpose.PurposeJobController.Finished) {
if (jobView.job.output.url !== "") { if (jobView.job?.output?.url?.length > 0) {
// Show share url sharingSuccess.text = i18n("Shared url for image is <a href='%1'>%1</a>", jobView.job.output.url);
// TODO no needed anymore in purpose > 5.90
sharingSuccess.text = i18n("Shared url for image is <a href='%1'>%1</a>", jobView.output.url);
sharingSuccess.sendEvent(); sharingSuccess.sendEvent();
Clipboard.saveText(jobView.output.url); Clipboard.saveText(jobView.job.output.url);
} }
root.closeDialog(); root.closeDialog();
} else if (state === Purpose.PurposeJobController.Error) { } else if (state === Purpose.PurposeJobController.Error) {