Debian Codegraph @

import/Lomiri/Content/qml5/ContentPeerPicker10.qml

raw
1 /*
2 * Copyright 2013 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.0
18 import Lomiri.Components 0.1
19 import Lomiri.Components.Popups 0.1
20 import Lomiri.Components.ListItems 0.1 as ListItem
21 import Lomiri.Content 0.1
22 import "."
23
24 /*!
25 \internal
26 Documentation is in ContentPeerPicker.qdoc
27 */
28 Item {
29 id: root
30 anchors.fill: parent
31
32 property var handler
33 property var contentType
34 property alias showTitle: header.visible
35 property var peer
36 property var customPeerModelLoader
37 property var completed: false
38
39 signal peerSelected
40 signal cancelPressed
41
42 Rectangle {
43 id: background
44 anchors.fill: parent
45 color: Theme.palette.normal.background
46 }
47
48 Header {
49 id: header
50 title: (handler === ContentHandler.Source) ? i18n.dtr("lomiri-content-hub", "Choose from") : (handler === ContentHandler.Destination ? i18n.dtr("lomiri-content-hub", "Open with") : i18n.dtr("lomiri-content-hub", "Share to"))
51 }
52
53 Loader {
54 id: peerModelLoader
55 active: false
56 asynchronous: true
57 sourceComponent: ContentPeerModel { }
58 onLoaded: {
59 item.handler = root.handler;
60 item.contentType = root.contentType;
61 }
62 }
63
64 Component.onCompleted: {
65 if (root.visible) {
66 if (customPeerModelLoader) {
67 customPeerModelLoader.active = true;
68 } else {
69 peerModelLoader.active = true;
70 }
71 }
72 completed = true;
73 }
74
75 onVisibleChanged: {
76 if (completed) {
77 if (customPeerModelLoader) {
78 customPeerModelLoader.active = true;
79 } else {
80 peerModelLoader.active = true;
81 }
82 }
83 }
84
85 onHandlerChanged: {
86 if (!customPeerModelLoader && peerModelLoader.item) {
87 appPeers.model = undefined; // Clear grid view
88 peerModelLoader.item.handler = root.handler;
89 appPeers.model = peerModelLoader.item.peers;
90 }
91 }
92
93 onContentTypeChanged: {
94 if (!customPeerModelLoader && peerModelLoader.item) {
95 appPeers.model = undefined; // Clear grid view
96 peerModelLoader.item.contentType = root.contentType;
97 appPeers.model = peerModelLoader.item.peers;
98 }
99 }
100
101 Component {
102 id: peerDelegate
103 Item {
104 width: units.gu(13.5)
105 height: units.gu(16)
106 AbstractButton {
107 width: parent.width
108 height: icon.height + label.height
109 LomiriShape {
110 id: icon
111 anchors {
112 top: parent.top
113 horizontalCenter: parent.horizontalCenter
114 }
115 radius: "medium"
116 width: units.gu(8)
117 height: units.gu(7.5)
118 image: Image {
119 id: image
120 objectName: "image"
121 sourceSize { width: icon.width; height: icon.height }
122 asynchronous: true
123 cache: false
124 source: "image://lomiri-content-hub/" + modelData.appId
125 horizontalAlignment: Image.AlignHCenter
126 verticalAlignment: Image.AlignVCenter
127 }
128 }
129
130 Label {
131 id: label
132 objectName: "label"
133 anchors {
134 baseline: icon.bottom
135 baselineOffset: units.gu(2)
136 left: parent.left
137 right: parent.right
138 leftMargin: units.gu(1)
139 rightMargin: units.gu(1)
140 }
141
142 opacity: 0.9
143 fontSize: "small"
144 horizontalAlignment: Text.AlignHCenter
145 text: modelData.name || modelData.appId
146 wrapMode: Text.Wrap
147 maximumLineCount: 2
148 }
149
150 onClicked: {
151 peer = modelData
152 peerSelected()
153 }
154 }
155
156 }
157 }
158
159 ListItem.Header {
160 id: appTitle
161 anchors.top: header.visible ? header.bottom : parent.top
162 text: i18n.dtr("lomiri-content-hub", "Apps")
163 }
164
165 Rectangle {
166 id: apps
167 color: ColorUtils.luminance(background.color) >= 0.85 ? "#FFFFFF" : Qt.darker(background.color)
168 clip: true
169 anchors {
170 left: parent.left
171 right: parent.right
172 top: appTitle.bottom
173 bottom: devTitle.visible ? devTitle.top : cancelButton.top
174 bottomMargin: units.gu(1)
175 }
176
177 Flickable {
178 anchors.fill: parent
179
180 ResponsiveGridView {
181 id: appPeers
182 anchors.fill: parent
183 minimumHorizontalSpacing: units.gu(0.5)
184 maximumNumberOfColumns: 6
185 delegateWidth: units.gu(11)
186 delegateHeight: units.gu(11)
187 verticalSpacing: units.gu(2)
188 model: customPeerModelLoader ? customPeerModelLoader.item.peers : peerModelLoader.item.peers
189 delegate: peerDelegate
190
191 Label {
192 anchors.top: parent.top
193 anchors.topMargin: units.gu(2.5)
194 anchors.horizontalCenter: parent.horizontalCenter
195 width: parent.width - units.gu(5)
196 wrapMode: Text.WordWrap
197 horizontalAlignment: Text.AlignHCenter
198 text: root.handler === ContentHandler.Source ? i18n.dtr("lomiri-content-hub", "Sorry, there aren't currently any apps installed that can provide this type of content.") : i18n.dtr("lomiri-content-hub", "Sorry, there aren't currently any apps installed that can handle this type of content.")
199 visible: appPeers.model ? appPeers.model.length == 0 : false
200 }
201 }
202 }
203 }
204
205 ListItem.Header {
206 id: devTitle
207 // TODO: make this visible when we have a way to populate devices
208 visible: false
209 anchors {
210 left: parent.left
211 right: parent.right
212 top: apps.bottom
213 }
214 text: i18n.dtr("lomiri-content-hub", "Devices")
215 }
216
217 Rectangle {
218 id: devices
219 // TODO: make this visible when we have a way to populate devices
220 visible: false
221 color: ColorUtils.luminance(background.color) >= 0.85 ? "#FFFFFF" : Qt.darker(background.color)
222 width: parent.width
223 radius: 0
224 anchors {
225 left: parent.left
226 right: parent.right
227 top: devTitle.bottom
228 bottom: cancelButton.top
229 bottomMargin: units.gu(1)
230 }
231
232 Flickable {
233 anchors.fill: parent
234
235 ResponsiveGridView {
236 id: devPeers
237 anchors.fill: parent
238 minimumHorizontalSpacing: units.gu(0.5)
239 maximumNumberOfColumns: 6
240 delegateWidth: units.gu(11)
241 delegateHeight: units.gu(9.5)
242 verticalSpacing: units.gu(2)
243 delegate: peerDelegate
244 }
245 }
246 }
247
248 Button {
249 id: cancelButton
250 objectName: "contentPeerPickerCancelButton"
251 text: i18n.dtr("lomiri-content-hub", "Cancel")
252 anchors {
253 left: parent.left
254 bottom: parent.bottom
255 margins: units.gu(1)
256 }
257 onClicked: {
258 if(root.activeTransfer) {
259 root.activeTransfer.state = ContentTransfer.Aborted;
260 }
261 cancelPressed();
262 }
263 }
264
265 }