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