Debian Codegraph @

import/Lomiri/Content/qml5/ContentPeerPicker11.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 1.1
19 import Lomiri.Components.Popups 0.1
20 import Lomiri.Components.ListItems 0.1 as ListItem
21 import Lomiri.Content 1.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 string headerText
38 property var completed: false
39
40 signal peerSelected
41 signal cancelPressed
42
43 Rectangle {
44 id: background
45 anchors.fill: parent
46 color: Theme.palette.normal.background
47 }
48
49 Header {
50 id: header
51 title: headerText ? headerText : (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"))
52 useDeprecatedToolbar: false
53 dividerColor: Qt.darker(Theme.palette.normal.background, 1.1)
54 config: PageHeadConfiguration {
55 backAction: Action {
56 objectName: "cancel"
57
58 iconName: "close"
59 text: i18n.dtr("lomiri-content-hub", "Cancel")
60 onTriggered: {
61 if(root.activeTransfer) {
62 root.activeTransfer.state = ContentTransfer.Aborted;
63 }
64 cancelPressed()
65 }
66
67 }
68 }
69 }
70
71 Loader {
72 id: peerModelLoader
73 active: false
74 asynchronous: true
75 sourceComponent: ContentPeerModel { }
76 onLoaded: {
77 item.handler = root.handler;
78 item.contentType = root.contentType;
79 }
80 }
81
82 Component.onCompleted: {
83 if (root.visible) {
84 if (customPeerModelLoader) {
85 customPeerModelLoader.active = true;
86 } else {
87 peerModelLoader.active = true;
88 }
89 }
90 completed = true;
91 }
92
93 onVisibleChanged: {
94 if (completed) {
95 if (customPeerModelLoader) {
96 customPeerModelLoader.active = true;
97 } else {
98 peerModelLoader.active = true;
99 }
100 }
101 }
102
103 onHandlerChanged: {
104 if (!customPeerModelLoader && peerModelLoader.item) {
105 appPeers.model = undefined; // Clear grid view
106 peerModelLoader.item.handler = root.handler;
107 appPeers.model = peerModelLoader.item.peers;
108 }
109 }
110
111 onContentTypeChanged: {
112 if (!customPeerModelLoader && peerModelLoader.item) {
113 appPeers.model = undefined; // Clear grid view
114 peerModelLoader.item.contentType = root.contentType;
115 appPeers.model = peerModelLoader.item.peers;
116 }
117 }
118
119 Component {
120 id: peerDelegate
121 Item {
122 width: units.gu(13.5)
123 height: units.gu(16)
124 AbstractButton {
125 width: parent.width
126 height: icon.height + label.height
127 LomiriShape {
128 id: icon
129 anchors {
130 top: parent.top
131 horizontalCenter: parent.horizontalCenter
132 }
133 radius: "medium"
134 width: units.gu(8)
135 height: units.gu(7.5)
136 image: Image {
137 id: image
138 objectName: "image"
139 sourceSize { width: icon.width; height: icon.height }
140 asynchronous: true
141 cache: false
142 source: "image://lomiri-content-hub/" + modelData.appId
143 horizontalAlignment: Image.AlignHCenter
144 verticalAlignment: Image.AlignVCenter
145 }
146 }
147
148 Label {
149 id: label
150 objectName: "label"
151 anchors {
152 baseline: icon.bottom
153 baselineOffset: units.gu(2)
154 left: parent.left
155 right: parent.right
156 leftMargin: units.gu(1)
157 rightMargin: units.gu(1)
158 }
159
160 opacity: 0.9
161 fontSize: "small"
162 horizontalAlignment: Text.AlignHCenter
163 text: modelData.name || modelData.appId
164 wrapMode: Text.Wrap
165 maximumLineCount: 2
166 }
167
168 onClicked: {
169 peer = modelData
170 peerSelected()
171 }
172 }
173
174 }
175 }
176
177 ListItem.Header {
178 id: appTitle
179 anchors.top: header.visible ? header.bottom : parent.top
180 text: i18n.dtr("lomiri-content-hub", "Apps")
181 }
182
183 Rectangle {
184 id: apps
185 color: ColorUtils.luminance(background.color) >= 0.85 ? "#FFFFFF" : Qt.darker(background.color)
186 clip: true
187 anchors {
188 left: parent.left
189 right: parent.right
190 top: appTitle.bottom
191 bottom: devTitle.visible ? devTitle.top : parent.bottom
192 bottomMargin: units.gu(1)
193 }
194
195 Flickable {
196 anchors.fill: parent
197
198 ResponsiveGridView {
199 id: appPeers
200 anchors.fill: parent
201 minimumHorizontalSpacing: units.gu(0.5)
202 maximumNumberOfColumns: 6
203 delegateWidth: units.gu(11)
204 delegateHeight: units.gu(11)
205 verticalSpacing: units.gu(2)
206 model: customPeerModelLoader ? customPeerModelLoader.item.peers : peerModelLoader.item.peers
207 delegate: peerDelegate
208
209 Label {
210 anchors.top: parent.top
211 anchors.topMargin: units.gu(2.5)
212 anchors.horizontalCenter: parent.horizontalCenter
213 width: parent.width - units.gu(5)
214 wrapMode: Text.WordWrap
215 horizontalAlignment: Text.AlignHCenter
216 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.")
217 visible: appPeers.model ? appPeers.model.length == 0 : false
218 }
219 }
220 }
221 }
222
223 ListItem.Header {
224 id: devTitle
225 // TODO: make this visible when we have a way to populate devices
226 visible: false
227 anchors {
228 left: parent.left
229 right: parent.right
230 top: apps.bottom
231 }
232 text: i18n.dtr("lomiri-content-hub", "Devices")
233 }
234
235 Rectangle {
236 id: devices
237 // TODO: make this visible when we have a way to populate devices
238 visible: false
239 color: ColorUtils.luminance(background.color) >= 0.85 ? "#FFFFFF" : Qt.darker(background.color)
240 width: parent.width
241 radius: 0
242 anchors {
243 left: parent.left
244 right: parent.right
245 top: devTitle.bottom
246 bottom: parent.bottom
247 bottomMargin: units.gu(1)
248 }
249
250 Flickable {
251 anchors.fill: parent
252
253 ResponsiveGridView {
254 id: devPeers
255 anchors.fill: parent
256 minimumHorizontalSpacing: units.gu(0.5)
257 maximumNumberOfColumns: 6
258 delegateWidth: units.gu(11)
259 delegateHeight: units.gu(9.5)
260 verticalSpacing: units.gu(2)
261 delegate: peerDelegate
262 }
263 }
264 }
265
266 }