| 1 |
/* |
| 2 |
* Copyright 2014 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 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 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.12 |
| 18 |
import Lomiri.Components 1.3 |
| 19 |
import Lomiri.Content 1.3 |
| 20 |
import Lomiri.Thumbnailer 0.1 |
| 21 |
|
| 22 |
import CameraApp 0.1 |
| 23 |
import "MimeTypeMapper.js" as MimeTypeMapper |
| 24 |
|
| 25 |
Item { |
| 26 |
id: galleryView |
| 27 |
|
| 28 |
signal exit |
| 29 |
property bool inView |
| 30 |
property bool inTransition: false |
| 31 |
property bool touchAcquired: slideshowView.touchAcquired |
| 32 |
property bool userSelectionMode: false |
| 33 |
property Item currentView: state == "GRID" ? photogridView : slideshowView |
| 34 |
property var model: FoldersModel { |
| 35 |
folders: [StorageLocations.picturesLocation, StorageLocations.videosLocation, |
| 36 |
StorageLocations.removableStoragePicturesLocation, |
| 37 |
StorageLocations.removableStorageVideosLocation] |
| 38 |
typeFilters: !main.contentExportMode ? [ "image", "video" ] |
| 39 |
: [MimeTypeMapper.contentTypeToMimeType(main.transferContentType)] |
| 40 |
singleSelectionOnly: main.contentExportMode && main.transfer.selectionType === ContentTransfer.Single |
| 41 |
} |
| 42 |
|
| 43 |
property bool gridMode: main.contentExportMode |
| 44 |
property bool showLastPhotoTakenPending: false |
| 45 |
|
| 46 |
function showLastPhotoTaken() { |
| 47 |
galleryView.gridMode = false; |
| 48 |
// do not immediately try to show the photo in the slideshow as it |
| 49 |
// might not be in the photo roll model yet |
| 50 |
showLastPhotoTakenPending = true; |
| 51 |
} |
| 52 |
|
| 53 |
function prependMediaToModel(filePath) { |
| 54 |
galleryView.model.prependFile(filePath); |
| 55 |
} |
| 56 |
|
| 57 |
function precacheThumbnail(filePath) { |
| 58 |
preCachingThumbnail.filename = filePath; |
| 59 |
} |
| 60 |
|
| 61 |
function exitUserSelectionMode() { |
| 62 |
model.clearSelection(); |
| 63 |
userSelectionMode = false; |
| 64 |
} |
| 65 |
|
| 66 |
onExit: { |
| 67 |
slideshowView.exit(); |
| 68 |
photogridView.exit(); |
| 69 |
galleryPageStack.clear(); |
| 70 |
} |
| 71 |
|
| 72 |
Component { |
| 73 |
id:advancedOptionsComponent |
| 74 |
AdvancedOptions { |
| 75 |
id:advancedOptions |
| 76 |
settings: viewFinderView.finderOverlay.settings |
| 77 |
|
| 78 |
onBack: galleryPageStack.pop() |
| 79 |
|
| 80 |
OverlayPanel { |
| 81 |
z:-1 |
| 82 |
overlayItem: advancedOptions |
| 83 |
blur.visible: appSettings.blurEffects && !appSettings.blurEffectsPreviewOnly |
| 84 |
blur.backgroundItem: currentView |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
Component { |
| 90 |
id:infoPageComponent |
| 91 |
Information { |
| 92 |
id:infoPage |
| 93 |
onBack: galleryPageStack.pop() |
| 94 |
OverlayPanel { |
| 95 |
z:-1 |
| 96 |
overlayItem: infoPage |
| 97 |
blur.visible: appSettings.blurEffects && !appSettings.blurEffectsPreviewOnly |
| 98 |
blur.backgroundItem: currentView |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
OrientationHelper { |
| 104 |
id: orientHelper |
| 105 |
visible: inView |
| 106 |
|
| 107 |
PageStack { |
| 108 |
id:galleryPageStack |
| 109 |
z:10 |
| 110 |
anchors.topMargin:header.height+header.y |
| 111 |
anchors.fill:parent |
| 112 |
} |
| 113 |
|
| 114 |
SlideshowView { |
| 115 |
id: slideshowView |
| 116 |
anchors.fill: parent |
| 117 |
model: galleryView.model |
| 118 |
visible: opacity != 0.0 |
| 119 |
inView: galleryView.inView && ( galleryView.currentView == slideshowView || galleryView.inTransition ) |
| 120 |
focus: inView |
| 121 |
inSelectionMode: main.contentExportMode || galleryView.userSelectionMode |
| 122 |
onToggleSelection: model.toggleSelected(currentIndex) |
| 123 |
onToggleHeader: header.toggle(); |
| 124 |
onBottomEdgeCommit : { galleryView.gridMode = true; header.show();} |
| 125 |
} |
| 126 |
|
| 127 |
PhotogridView { |
| 128 |
id: photogridView |
| 129 |
anchors.fill: parent |
| 130 |
headerHeight: header.height |
| 131 |
userSelectionMode: galleryView.userSelectionMode |
| 132 |
model: galleryView.model |
| 133 |
visible: opacity != 0.0 |
| 134 |
inView: galleryView.inView && ( galleryView.currentView == photogridView || galleryView.inTransition ) |
| 135 |
focus: inView |
| 136 |
inSelectionMode: main.contentExportMode || galleryView.userSelectionMode |
| 137 |
onPhotoClicked: { |
| 138 |
slideshowView.showPhotoAtIndex(index); |
| 139 |
photogridView.showPhotoAtIndex(index); |
| 140 |
galleryView.inTransition = true; |
| 141 |
galleryView.gridMode = false; |
| 142 |
} |
| 143 |
onPhotoPressAndHold: { |
| 144 |
if (!galleryView.userSelectionMode) { |
| 145 |
galleryView.userSelectionMode = true; |
| 146 |
model.toggleSelected(index); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
onPhotoSelectionAreaClicked: { |
| 151 |
if (main.contentExportMode || galleryView.userSelectionMode) |
| 152 |
model.toggleSelected(index); |
| 153 |
} |
| 154 |
onExitUserSelectionMode: galleryView.exitUserSelectionMode() |
| 155 |
onToggleHeader: header.toggle() |
| 156 |
} |
| 157 |
|
| 158 |
OverlayPanel { |
| 159 |
overlayItem: header |
| 160 |
visible: galleryView.gridMode |
| 161 |
blur.visible: appSettings.blurEffects && !appSettings.blurEffectsPreviewOnly |
| 162 |
blur.transparentBorder:false |
| 163 |
blur.backgroundItem: photogridView |
| 164 |
} |
| 165 |
|
| 166 |
OverlayPanel { |
| 167 |
overlayItem: header |
| 168 |
visible: !galleryView.gridMode |
| 169 |
blur.visible: appSettings.blurEffects && !appSettings.blurEffectsPreviewOnly |
| 170 |
blur.transparentBorder:false |
| 171 |
blur.backgroundItem: slideshowView |
| 172 |
|
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
// FIXME: it would be better to use the standard header from the toolkit |
| 177 |
GalleryViewHeader { |
| 178 |
id: header |
| 179 |
z:10 |
| 180 |
actions: currentView.actions |
| 181 |
gridMode: galleryView.gridMode |
| 182 |
validationVisible: main.contentExportMode && model.selectedFiles.length > 0 && galleryView.gridMode |
| 183 |
userSelectionMode: galleryView.userSelectionMode |
| 184 |
onExit: { |
| 185 |
if ((main.contentExportMode || userSelectionMode) && !galleryView.gridMode) { |
| 186 |
galleryView.gridMode = true; |
| 187 |
// position grid view so that the current photo in slideshow view is visible |
| 188 |
photogridView.showPhotoAtIndex(slideshowView.currentIndex); |
| 189 |
} else if (userSelectionMode) { |
| 190 |
galleryView.exitUserSelectionMode(); |
| 191 |
} else { |
| 192 |
galleryView.exit() |
| 193 |
} |
| 194 |
} |
| 195 |
onToggleViews: { |
| 196 |
if (!galleryView.gridMode) { |
| 197 |
// position grid view so that the current photo in slideshow view is visible |
| 198 |
photogridView.showPhotoAtIndex(slideshowView.currentIndex); |
| 199 |
} |
| 200 |
galleryView.inTransition = true; |
| 201 |
galleryView.gridMode = !galleryView.gridMode |
| 202 |
} |
| 203 |
onToggleSelectAll: { |
| 204 |
if (model.selectedFiles.length != model.count) |
| 205 |
model.selectAll(); |
| 206 |
else |
| 207 |
model.clearSelection(); |
| 208 |
} |
| 209 |
onValidationClicked: { |
| 210 |
var selection = model.selectedFiles; |
| 211 |
var urls = []; |
| 212 |
for (var i=0; i<selection.length; i++) { |
| 213 |
urls.push(model.get(selection[i], "fileURL")); |
| 214 |
} |
| 215 |
model.clearSelection(); |
| 216 |
main.exportContent(urls); |
| 217 |
} |
| 218 |
|
| 219 |
onAdvanceSettingsToggle:{ |
| 220 |
galleryPageStack.push(advancedOptionsComponent) |
| 221 |
} |
| 222 |
|
| 223 |
onDrawerToggle:{ |
| 224 |
if(isOpen && galleryPageStack.depth > 0 ) { |
| 225 |
galleryPageStack.clear(); |
| 226 |
} |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
|
| 231 |
onInViewChanged: { |
| 232 |
if (inView) { |
| 233 |
header.show(); |
| 234 |
if (showLastPhotoTakenPending) { |
| 235 |
slideshowView.showLastPhotoTaken(); |
| 236 |
showLastPhotoTakenPending = false; |
| 237 |
} |
| 238 |
} |
| 239 |
} |
| 240 |
|
| 241 |
Rectangle { |
| 242 |
objectName: "noMediaHint" |
| 243 |
anchors.fill: parent |
| 244 |
visible: model.count === 0 && !model.loading |
| 245 |
color: theme.palette.normal.base |
| 246 |
|
| 247 |
Icon { |
| 248 |
id: noMediaIcon |
| 249 |
anchors { |
| 250 |
horizontalCenter: parent.horizontalCenter |
| 251 |
verticalCenter: parent.verticalCenter |
| 252 |
verticalCenterOffset: -units.gu(1) |
| 253 |
} |
| 254 |
height: units.gu(9) |
| 255 |
width: units.gu(9) |
| 256 |
color: theme.palette.normal.backgroundText |
| 257 |
opacity: 0.2 |
| 258 |
name: "camera-app-symbolic" |
| 259 |
asynchronous: true |
| 260 |
} |
| 261 |
|
| 262 |
Label { |
| 263 |
id: noMediaLabel |
| 264 |
anchors { |
| 265 |
horizontalCenter: parent.horizontalCenter |
| 266 |
top: noMediaIcon.bottom |
| 267 |
topMargin: units.gu(4) |
| 268 |
} |
| 269 |
text: i18n.tr("No media available.") |
| 270 |
color: theme.palette.normal.backgroundText |
| 271 |
opacity: 0.2 |
| 272 |
fontSize: "large" |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
Rectangle { |
| 277 |
objectName: "scanningMediaHint" |
| 278 |
anchors.fill: parent |
| 279 |
visible: model.count === 0 && model.loading |
| 280 |
color: theme.palette.normal.base |
| 281 |
|
| 282 |
Icon { |
| 283 |
id: scanningMediaIcon |
| 284 |
anchors { |
| 285 |
horizontalCenter: parent.horizontalCenter |
| 286 |
verticalCenter: parent.verticalCenter |
| 287 |
verticalCenterOffset: -units.gu(1) |
| 288 |
} |
| 289 |
height: units.gu(9) |
| 290 |
width: units.gu(9) |
| 291 |
color: theme.palette.normal.backgroundText |
| 292 |
opacity: 0.2 |
| 293 |
name: "camera-app-symbolic" |
| 294 |
asynchronous: true |
| 295 |
} |
| 296 |
|
| 297 |
Label { |
| 298 |
id: scanningMediaLabel |
| 299 |
anchors { |
| 300 |
horizontalCenter: parent.horizontalCenter |
| 301 |
top: scanningMediaIcon.bottom |
| 302 |
topMargin: units.gu(4) |
| 303 |
} |
| 304 |
text: i18n.tr("Scanning for content...") |
| 305 |
color: theme.palette.normal.backgroundText |
| 306 |
opacity: 0.2 |
| 307 |
fontSize: "large" |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
// This image component is used to pre-load thumbnails of recently |
| 312 |
// created files. This is primarily to hide the delays in |
| 313 |
// thumbnailing videos. |
| 314 |
Image { |
| 315 |
id: preCachingThumbnail |
| 316 |
property string filename |
| 317 |
|
| 318 |
visible: false |
| 319 |
asynchronous: true |
| 320 |
cache: false |
| 321 |
sourceSize.width: 32 |
| 322 |
sourceSize.height: 32 |
| 323 |
source: filename ? "image://thumbnailer/%1".arg(filename) : "" |
| 324 |
|
| 325 |
onStatusChanged: { |
| 326 |
if (status == Image.Ready) { |
| 327 |
filename = ""; |
| 328 |
} |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
state: galleryView.gridMode ? "GRID" : "SLIDESHOW" |
| 333 |
onStateChanged: inTransition = true; |
| 334 |
states: [ |
| 335 |
State { |
| 336 |
name: "SLIDESHOW" |
| 337 |
PropertyChanges { |
| 338 |
target: slideshowView |
| 339 |
scale: 1.0 |
| 340 |
opacity: 1.0 |
| 341 |
} |
| 342 |
PropertyChanges { |
| 343 |
target: photogridView |
| 344 |
scale: 1.4 |
| 345 |
opacity: 0.0 |
| 346 |
} |
| 347 |
}, |
| 348 |
State { |
| 349 |
name: "GRID" |
| 350 |
PropertyChanges { |
| 351 |
target: slideshowView |
| 352 |
scale: 0.4 |
| 353 |
opacity: 0.0 |
| 354 |
} |
| 355 |
PropertyChanges { |
| 356 |
target: photogridView |
| 357 |
scale: 1.0 |
| 358 |
opacity: 1.0 |
| 359 |
} |
| 360 |
} |
| 361 |
] |
| 362 |
|
| 363 |
transitions: [ |
| 364 |
Transition { |
| 365 |
id:galleryViewTransition |
| 366 |
to: "*" |
| 367 |
LomiriNumberAnimation { properties: "scale,opacity"; duration: LomiriAnimation.BriskDuration } |
| 368 |
onRunningChanged: { |
| 369 |
inTransition = running; |
| 370 |
} |
| 371 |
} |
| 372 |
] |
| 373 |
} |