Warning, /network/neochat/src/qml/ShareAction.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 
0004 import QtQuick
0005 import QtQuick.Layouts
0006 import org.kde.kirigami as Kirigami
0007 
0008 /**
0009  * Action that allows an user to share data with other apps and service
0010  * installed on their computer. The goal of this high level API is to
0011  * adapte itself for each platform and adopt the native component.
0012  *
0013  * TODO add Android support
0014  */
0015 Kirigami.Action {
0016     id: root
0017 
0018     icon.name: "emblem-shared-symbolic"
0019     text: i18n("Share")
0020     tooltip: i18n("Share the selected media")
0021 
0022     property var doBeforeSharing: () => {}
0023     visible: false
0024 
0025     /**
0026      * This property holds the input data for purpose.
0027      *
0028      * @code{.qml}
0029      * Purpose.ShareAction {
0030      *     inputData: {
0031      *         'urls': ['file://home/notroot/Pictures/mypicture.png'],
0032      *         'mimeType': ['image/png']
0033      *     }
0034      * }
0035      * @endcode
0036      */
0037     property var inputData: ({})
0038 
0039     property Instantiator _instantiator: Instantiator {
0040         Component.onCompleted: {
0041             const purposeModel = Qt.createQmlObject('import org.kde.purpose as Purpose;
0042 Purpose.PurposeAlternativesModel {
0043     pluginType: "Export"
0044 }', root._instantiator);
0045             purposeModel.inputData = Qt.binding(function () {
0046                 return root.inputData;
0047             });
0048             _instantiator.model = purposeModel;
0049             root.visible = true;
0050         }
0051 
0052         delegate: Kirigami.Action {
0053             property int index
0054             text: model.display
0055             icon.name: model.iconName
0056             onTriggered: {
0057                 doBeforeSharing();
0058                 applicationWindow().pageStack.pushDialogLayer('qrc:/org/kde/neochat/qml/ShareDialog.qml', {
0059                     title: root.tooltip,
0060                     index: index,
0061                     model: root._instantiator.model
0062                 });
0063             }
0064         }
0065         onObjectAdded: (index, object) => {
0066             object.index = index;
0067             root.children.push(object);
0068         }
0069         onObjectRemoved: (index, object) => root.children = Array.from(root.children).filter(obj => obj.pluginId !== object.pluginId)
0070     }
0071 }