Warning, /network/tokodon/src/content/ui/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 2.7
0005 import QtQuick.Layouts 1.3
0006 import QtQuick.Controls 2.15 as QQC2
0007 import org.kde.kirigami 2.14 as Kirigami
0008 
0009 /**
0010  * Action that allows an user to share data with other apps and service
0011  * installed on their computer. The goal of this high level API is to
0012  * adapte itself for each platform and adopt the native component.
0013  *
0014  * TODO add Android support
0015  */
0016 Kirigami.Action {
0017     id: shareAction
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 1.0 as Purpose;
0042 Purpose.PurposeAlternativesModel {
0043     pluginType: "ShareUrl"
0044 }', shareAction._instantiator);
0045             purposeModel.inputData = Qt.binding(function() {
0046                 return shareAction.inputData;
0047             });
0048             _instantiator.model = purposeModel;
0049             shareAction.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:/content/ui/ShareDialog.qml', {
0059                     title: shareAction.tooltip,
0060                     index: index,
0061                     model: shareAction._instantiator.model
0062                 })
0063             }
0064         }
0065         onObjectAdded: {
0066             object.index = index;
0067             shareAction.children.push(object)
0068         }
0069         onObjectRemoved: shareAction.children = Array.from(shareAction.children).filter(obj => obj.pluginId !== object.pluginId)
0070     }
0071 }