| 1 |
/* |
| 2 |
* Copyright (C) 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 General Public License version 3 as |
| 6 |
* published by the Free Software Foundation. |
| 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 General Public License for more details. |
| 12 |
* |
| 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/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.9 |
| 18 |
import Lomiri.Components 1.3 |
| 19 |
import Lomiri.Content 1.3 |
| 20 |
import Gallery 1.0 |
| 21 |
import "Components" |
| 22 |
import "Controller" |
| 23 |
import "OrganicView" |
| 24 |
import "Utility" |
| 25 |
import "../js/Gallery.js" as Gallery |
| 26 |
import "../js/GalleryUtility.js" as GalleryUtility |
| 27 |
|
| 28 |
/*! |
| 29 |
The main view for picking content |
| 30 |
*/ |
| 31 |
MainView { |
| 32 |
id: overview |
| 33 |
objectName: "pickerMainView" |
| 34 |
|
| 35 |
property var transfer: application.transfer |
| 36 |
|
| 37 |
function setHeaderVisibility(visible) |
| 38 |
{ |
| 39 |
header.visible = visible; |
| 40 |
} |
| 41 |
|
| 42 |
function toggleHeaderVisibility() |
| 43 |
{ |
| 44 |
setHeaderVisibility(!header.visible); |
| 45 |
} |
| 46 |
|
| 47 |
function pushPage(page) { |
| 48 |
pageStack.push(page); |
| 49 |
} |
| 50 |
|
| 51 |
function popPage() { |
| 52 |
pageStack.pop(); |
| 53 |
} |
| 54 |
|
| 55 |
function getMediaTypeFilter() { |
| 56 |
if (!overview.transfer) { |
| 57 |
return MediaSource.None |
| 58 |
} |
| 59 |
|
| 60 |
if (overview.transfer.contentType === ContentType.Pictures) { |
| 61 |
return MediaSource.Photo |
| 62 |
} else if (overview.transfer.contentType === ContentType.Videos) { |
| 63 |
return MediaSource.Video |
| 64 |
} |
| 65 |
|
| 66 |
return MediaSource.None |
| 67 |
} |
| 68 |
|
| 69 |
function confirmExport() { |
| 70 |
var item |
| 71 |
var items = [] |
| 72 |
|
| 73 |
var selectedMedias = mediaLibraryLoader.item.selectedMediasQML |
| 74 |
for (var i = 0; i < selectedMedias.length; i++) { |
| 75 |
item = contentItemComponent.createObject(overview.transfer, {"url": selectedMedias[i].path}) |
| 76 |
items.push(item) |
| 77 |
} |
| 78 |
|
| 79 |
overview.transfer.items = items |
| 80 |
overview.transfer.state = ContentTransfer.Charged |
| 81 |
overview.transfer = null |
| 82 |
|
| 83 |
APP.pickModeEnabled = false |
| 84 |
} |
| 85 |
|
| 86 |
function cancelExport() { |
| 87 |
if (overview.transfer) { |
| 88 |
overview.transfer.state = ContentTransfer.Aborted |
| 89 |
overview.transfer = null |
| 90 |
} |
| 91 |
|
| 92 |
APP.pickModeEnabled = false |
| 93 |
} |
| 94 |
|
| 95 |
SettingsController { id: settings } |
| 96 |
|
| 97 |
PageStack { |
| 98 |
id: pageStack |
| 99 |
anchors.fill: parent |
| 100 |
} |
| 101 |
|
| 102 |
Loader { |
| 103 |
id: eventCollectionModelLoader |
| 104 |
sourceComponent: allLoaded ? eventCollectionModelComponent : "" |
| 105 |
|
| 106 |
Component { |
| 107 |
id: eventCollectionModelComponent |
| 108 |
EventCollectionModel { |
| 109 |
mediaTypeFilter: getMediaTypeFilter() |
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
Loader { |
| 115 |
id: mediaLibraryLoader |
| 116 |
sourceComponent: allLoaded ? mediaLibraryComponent : "" |
| 117 |
|
| 118 |
Component { |
| 119 |
id: mediaLibraryComponent |
| 120 |
MediaCollectionModel { |
| 121 |
monitored: true |
| 122 |
mediaTypeFilter: getMediaTypeFilter() |
| 123 |
} |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
Loader { |
| 128 |
id: selectionLoader |
| 129 |
sourceComponent: allLoaded ? selectionComponent : "" |
| 130 |
|
| 131 |
Component { |
| 132 |
id: selectionComponent |
| 133 |
SelectionState { |
| 134 |
inSelectionMode: true |
| 135 |
singleSelect: overview.transfer ? overview.transfer.selectionType === ContentTransfer.Single : false |
| 136 |
model: mediaLibraryLoader.item |
| 137 |
} |
| 138 |
} |
| 139 |
} |
| 140 |
|
| 141 |
anchors.fill: parent |
| 142 |
automaticOrientation: application.automaticOrientation |
| 143 |
|
| 144 |
Component.onCompleted: { |
| 145 |
pageStack.push(tabs); |
| 146 |
} |
| 147 |
|
| 148 |
Tabs { |
| 149 |
id: tabs |
| 150 |
anchors.fill: parent |
| 151 |
|
| 152 |
StateSaver.properties: "selectedTabIndex" |
| 153 |
// Select Photos tab by default |
| 154 |
selectedTabIndex: 1 |
| 155 |
|
| 156 |
Tab { |
| 157 |
id: eventsTab |
| 158 |
title: i18n.tr("Events") |
| 159 |
objectName: "eventsTab" |
| 160 |
page: Loader { |
| 161 |
id: eventSelectViewLoader |
| 162 |
objectName: 'eventSelectViewLoader' |
| 163 |
anchors.fill: parent |
| 164 |
sourceComponent: allLoaded ? eventSelectViewComponent : loadingScreenComponent |
| 165 |
|
| 166 |
Component { |
| 167 |
id: eventSelectViewComponent |
| 168 |
|
| 169 |
OrganicView { |
| 170 |
id: eventSelectView |
| 171 |
objectName: "eventSelectView" |
| 172 |
|
| 173 |
head.actions: pickActions |
| 174 |
|
| 175 |
selection: allLoaded ? selectionLoader.item : "" |
| 176 |
model: allLoaded && eventCollectionModelLoader.status == Loader.Ready ? eventCollectionModelLoader.item : "" |
| 177 |
|
| 178 |
delegate: OrganicMediaList { |
| 179 |
id: organicList |
| 180 |
width: eventSelectView.width |
| 181 |
event: model.event |
| 182 |
selection: eventSelectView.selection |
| 183 |
mediaTypeFilter: getMediaTypeFilter() |
| 184 |
onPressed: { |
| 185 |
var rect = GalleryUtility.translateRect(thumbnailRect, organicList, |
| 186 |
eventSelectView); |
| 187 |
eventSelectView.mediaSourcePressed(mediaSource, rect); |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
onMediaSourcePressed: { |
| 192 |
photoViewerLoader.load(); |
| 193 |
var rect = GalleryUtility.translateRect(thumbnailRect, |
| 194 |
eventSelectView, |
| 195 |
photoViewerLoader); |
| 196 |
photoViewerLoader.item.title = i18n.tr("Select"); |
| 197 |
photoViewerLoader.item.selection = selection; |
| 198 |
photoViewerLoader.item.animateOpen(mediaSource, rect); |
| 199 |
} |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
Tab { |
| 206 |
id: photosTab |
| 207 |
title: i18n.tr("Photos") |
| 208 |
objectName: "photosTab" |
| 209 |
page: Loader { |
| 210 |
id: photosOverviewLoader |
| 211 |
objectName: 'photosOverviewLoader' |
| 212 |
anchors.fill: parent |
| 213 |
sourceComponent: allLoaded ? photosOverviewComponent : loadingScreenComponent |
| 214 |
|
| 215 |
Component { |
| 216 |
id: photosOverviewComponent |
| 217 |
|
| 218 |
Page { |
| 219 |
id: photosOverview |
| 220 |
objectName: "photosPage" |
| 221 |
|
| 222 |
head.actions: pickActions |
| 223 |
|
| 224 |
signal mediaSourcePressed(var mediaSource, var thumbnailRect) |
| 225 |
|
| 226 |
Connections { |
| 227 |
target: photoViewerLoader.item |
| 228 |
onSelected: photosGrid.positionViewAtIndex(index, GridView.Contain); |
| 229 |
} |
| 230 |
|
| 231 |
MediaGrid { |
| 232 |
id: photosGrid |
| 233 |
property var gridSize: units.gu(settings.gridUnits) |
| 234 |
anchors.fill: parent |
| 235 |
model: allLoaded ? mediaLibraryLoader.item : "" |
| 236 |
selection: allLoaded ? selectionLoader.item : "" |
| 237 |
} |
| 238 |
|
| 239 |
onMediaSourcePressed: { |
| 240 |
photoViewerLoader.load(); |
| 241 |
var rect = GalleryUtility.translateRect(thumbnailRect, |
| 242 |
photosOverview, |
| 243 |
photoViewerLoader); |
| 244 |
photoViewerLoader.item.title = i18n.tr("Select"); |
| 245 |
photoViewerLoader.item.selection = photosGrid.selection; |
| 246 |
photoViewerLoader.item.animateOpen(mediaSource, rect); |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
Component { |
| 255 |
id: loadingScreenComponent |
| 256 |
LoadingScreen { |
| 257 |
id: loadingScreen |
| 258 |
anchors.fill: parent |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
Loader { |
| 263 |
id: photoViewerLoader |
| 264 |
|
| 265 |
anchors.fill: parent |
| 266 |
z: 100 |
| 267 |
|
| 268 |
function load() { |
| 269 |
setSource(Qt.resolvedUrl("MediaViewer/PopupPhotoViewer.qml"), {model: mediaLibraryLoader.item}); |
| 270 |
} |
| 271 |
|
| 272 |
Connections { |
| 273 |
target: photoViewerLoader.item |
| 274 |
onCloseRequested: { |
| 275 |
if (!APP.desktopMode) |
| 276 |
setFullScreenAppMode(false); |
| 277 |
popPage(); |
| 278 |
photoViewerLoader.item.fadeClosed(); |
| 279 |
} |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
Component { |
| 284 |
id: contentItemComponent |
| 285 |
ContentItem {} |
| 286 |
} |
| 287 |
|
| 288 |
property list<Action> pickActions: [ |
| 289 |
Action { |
| 290 |
text: i18n.tr("Cancel") |
| 291 |
objectName: "cancelButton" |
| 292 |
iconName: "close" |
| 293 |
onTriggered: cancelExport() |
| 294 |
}, |
| 295 |
Action { |
| 296 |
text: i18n.tr("Pick") |
| 297 |
objectName: "pickButton" |
| 298 |
enabled: allLoaded ? selectionLoader.item.selectedCount > 0 : false |
| 299 |
iconName: "ok" |
| 300 |
onTriggered: confirmExport() |
| 301 |
} |
| 302 |
] |
| 303 |
} |