Warning, /graphics/koko/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 QtQml.Models
0005 import QtQuick
0006 import QtQuick.Layouts
0007 import QtQuick.Controls 2 as Controls
0008 import org.kde.purpose 1 as Purpose
0009 import org.kde.kirigami 2 as Kirigami
0010
0011 /**
0012 * Action that allows an user to share data with other apps and service
0013 * installed on their computer. The goal of this high level API is to
0014 * adapte itself for each platform and adopt the native component.
0015 *
0016 * TODO add more doc, before moving to Peruse upstream
0017 *
0018 * TODO add Android support
0019 */
0020 Kirigami.Action {
0021 id: shareAction
0022 icon.name: "emblem-shared-symbolic"
0023 text: i18n("Share")
0024 tooltip: i18n("Share the selected media")
0025
0026 /**
0027 * This property holds the input data for purpose.
0028 *
0029 * @code{.qml}
0030 * Purpose.ShareAction {
0031 * inputData: {
0032 * 'urls': ['file://home/notroot/Pictures/mypicture.png'],
0033 * 'mimeType': ['image/png']
0034 * }
0035 * }
0036 * @endcode
0037 */
0038 property var inputData: ({})
0039
0040 onTriggered: {
0041 if (!Kirigami.Settings.isMobile) {
0042 return;
0043 }
0044 const shareDrawerComponent = Qt.createComponent('qrc:/qml/ShareDrawer.qml');
0045 const drawer = shareDrawerComponent.createObject(applicationWindow().overlay, {
0046 inputData: shareAction.inputData,
0047 title: shareAction.text
0048 });
0049 drawer.open();
0050 }
0051
0052 property Instantiator _instantiator: Instantiator {
0053 active: !Kirigami.Settings.isMobile
0054 model: Purpose.PurposeAlternativesModel {
0055 pluginType: "Export"
0056 inputData: shareAction.inputData
0057 }
0058
0059 delegate: Kirigami.Action {
0060 property int index
0061 text: model.display
0062 icon.name: model.iconName
0063 onTriggered: {
0064 applicationWindow().pageStack.pushDialogLayer('qrc:/qml/ShareDialog.qml', {
0065 title: shareAction.tooltip,
0066 index: index,
0067 model: shareAction._instantiator.model
0068 })
0069 }
0070 }
0071 onObjectAdded: (index, object) => {
0072 object.index = index;
0073 shareAction.children.push(object)
0074 }
0075 onObjectRemoved: (index, object) => {
0076 shareAction.children = Array.from(shareAction.children).filter(obj => obj.pluginId !== object.pluginId)
0077 }
0078 }
0079 }