2 * Copyright (C) 2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 import Ubuntu.Components 1.3
19 import Ubuntu.Content 1.1
23 implicitHeight: button.height
24 implicitWidth: button.width
26 property var shareData
27 property alias active: peerPicker.active
28 readonly property bool isUrlExternal: url && url.indexOf("file:///") != 0 && url.indexOf("/") != 0
29 readonly property string contentType: shareData ? shareData["content-type"] : ""
30 readonly property var url: shareData ? shareData["uri"] : ""
31 readonly property Item rootItem: QuickUtils.rootItem(root)
37 onClicked: peerPicker.visible = true
40 anchors.centerIn: parent
43 source: "image://theme/share"
48 id: exportItemComponent
50 name: i18n.tr("Preview Share Item")
55 id: contentPeerComponent
57 handler: ContentHandler.Share
59 // for now, treat all external urls as Links, or it will break contenthub
60 if (root.isUrlExternal) return ContentType.Links;
62 switch(root.contentType) {
63 case "all": return ContentType.All;
64 case "contacts": return ContentType.Contacts;
65 case "documents": return ContentType.Documents;
66 case "links": return ContentType.Links;
67 case "music": return ContentType.Music;
68 case "pictures": return ContentType.Pictures;
69 case "text": return ContentType.Text;
71 case "unknown": return ContentType.Unknown;
72 case "videos": return ContentType.Videos;
77 var transfer = peer.request();
78 if (transfer.state === ContentTransfer.InProgress) {
79 var items = new Array();
80 for (var i = 0; i < url.length; i++) {
81 var exportItem = exportItemComponent.createObject();
82 exportItem.url = url[i];
83 items.push(exportItem);
85 transfer.items = items;
86 transfer.state = ContentTransfer.Charged;
88 peerPicker.visible = false;
90 onCancelPressed: peerPicker.visible = false;
96 objectName: "peerPicker"
100 active: root.url != ""
102 sourceComponent: contentPeerComponent