| 1 |
/* |
| 2 |
* Copyright (C) 2012-2015 Canonical Ltd. |
| 3 |
* Copyright (C) 2017 Emanuele Sorce <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License version 3 as |
| 7 |
* published by the Free Software Foundation. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
* |
| 17 |
* Authors: |
| 18 |
* Charles Lindsay <[email protected] |
| 19 |
*/ |
| 20 |
|
| 21 |
import QtQuick 2.9 |
| 22 |
import Qt.labs.settings 1.0 |
| 23 |
import QtQuick.Controls.Suru 2.2 |
| 24 |
import Lomiri.Components 1.3 |
| 25 |
import Lomiri.Content 1.3 |
| 26 |
import Gallery 1.0 |
| 27 |
import "../js/GalleryUtility.js" as GalleryUtility |
| 28 |
import "AlbumEditor" |
| 29 |
import "AlbumViewer" |
| 30 |
import "Controller" |
| 31 |
|
| 32 |
MainView { |
| 33 |
id: overview |
| 34 |
objectName: "overview" |
| 35 |
|
| 36 |
Suru.theme: theme.name === "Lomiri.Components.Themes.SuruDark" ? Suru.Dark : Suru.Light |
| 37 |
|
| 38 |
backgroundColor: Suru.backgroundColor |
| 39 |
|
| 40 |
anchors.fill: parent |
| 41 |
automaticOrientation: application.automaticOrientation |
| 42 |
|
| 43 |
property string mediaCurrentlyInView |
| 44 |
StateSaver.properties: "mediaCurrentlyInView" |
| 45 |
|
| 46 |
property bool applicationLoaded: application.allLoaded |
| 47 |
|
| 48 |
//fullScreen property is used on autopilot tests |
| 49 |
property bool fullScreen: APP.fullScreenAppMode || APP.fullScreenUserMode |
| 50 |
|
| 51 |
property alias currentPage: pageStack.currentPage |
| 52 |
|
| 53 |
function openMediaFile(media) { |
| 54 |
if (__isPhotoViewerOpen) { |
| 55 |
popPage(); |
| 56 |
photoViewerLoader.item.fadeClosed(); |
| 57 |
} |
| 58 |
|
| 59 |
mediaCurrentlyInView = media; |
| 60 |
for (var i = 0; i < mediaLibraryLoader.item.count; i++) { |
| 61 |
if (mediaLibraryLoader.item.getAt(i).path == mediaCurrentlyInView) { |
| 62 |
photoViewerLoader.load(); |
| 63 |
if (tabs.selectedTabIndex === 0) { |
| 64 |
if (albumsTab.isAlbumOpened) { |
| 65 |
photoViewerLoader.item.title = i18n.tr("Album"); |
| 66 |
} else { |
| 67 |
photoViewerLoader.item.title = albumsTab.title; |
| 68 |
} |
| 69 |
} else if (tabs.selectedTabIndex === 1) { |
| 70 |
photoViewerLoader.item.title = eventTab.title; |
| 71 |
} else { |
| 72 |
photoViewerLoader.item.title = photosTab.title; |
| 73 |
} |
| 74 |
photoViewerLoader.item.animateOpen(mediaLibraryLoader.item.getAt(i), |
| 75 |
Qt.rect(0,0,0,0)); |
| 76 |
return; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
function eventsViewRequested() { |
| 82 |
if (!allLoaded) { |
| 83 |
return; |
| 84 |
} |
| 85 |
|
| 86 |
if (__isPhotoViewerOpen) { |
| 87 |
photoViewerLoader.item.closeRequested(); |
| 88 |
} |
| 89 |
|
| 90 |
if (albumsCheckerboardLoader.item) { |
| 91 |
albumsCheckerboardLoader.item.closeAlbum(); |
| 92 |
} |
| 93 |
|
| 94 |
if (tabs.selectedTabIndex == 0) { |
| 95 |
// Move from Albums Tab to Events Tab |
| 96 |
tabs.selectedTabIndex = 1; |
| 97 |
} |
| 98 |
|
| 99 |
if (tabs.selectedTabIndex == 1 && eventsOverviewLoader.item) { |
| 100 |
eventsOverviewLoader.item.positionViewAtBeginning(); |
| 101 |
} |
| 102 |
|
| 103 |
if (tabs.selectedTabIndex == 2 && eventsOverviewLoader.item) { |
| 104 |
photosOverviewLoader.item.positionViewAtBeginning(); |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
function pushPage(page, properties) { |
| 109 |
return pageStack.push(page, properties); |
| 110 |
} |
| 111 |
|
| 112 |
function popPage() { |
| 113 |
pageStack.pop(); |
| 114 |
} |
| 115 |
|
| 116 |
Component.onCompleted: { |
| 117 |
pageStack.push(tabs); |
| 118 |
} |
| 119 |
|
| 120 |
onApplicationLoadedChanged: { |
| 121 |
if (applicationLoaded) { |
| 122 |
if (APP.mediaFile !== "") |
| 123 |
openMediaFile(APP.mediaFile); |
| 124 |
else if (mediaCurrentlyInView !== "") |
| 125 |
openMediaFile(mediaCurrentlyInView); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
Timer { |
| 130 |
id: setFullScreenTimer |
| 131 |
interval: 10; |
| 132 |
onTriggered: setFullScreenAppMode(!header.visible) |
| 133 |
} |
| 134 |
|
| 135 |
PageStack { |
| 136 |
id: pageStack |
| 137 |
anchors.fill: parent |
| 138 |
} |
| 139 |
|
| 140 |
Tabs { |
| 141 |
id: tabs |
| 142 |
anchors.fill: parent |
| 143 |
|
| 144 |
visible: !(photoViewerLoader.item && photoViewerLoader.item.isPoppedUp) |
| 145 |
|
| 146 |
selectedTabIndex: 1 |
| 147 |
|
| 148 |
Tab { |
| 149 |
id: albumsTab |
| 150 |
objectName: "albumsTab" |
| 151 |
title: i18n.tr("Albums") |
| 152 |
property bool isAlbumOpened: (page.item && page.item.isAlbumOpened) |
| 153 |
page: Loader { |
| 154 |
id: albumsCheckerboardLoader |
| 155 |
objectName: "albumsCheckerboardLoader" |
| 156 |
anchors.fill: parent |
| 157 |
source: allLoaded ? Qt.resolvedUrl("AlbumsOverview.qml") : Qt.resolvedUrl("LoadingScreen.qml") |
| 158 |
asynchronous: true |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
Tab { |
| 163 |
id: eventTab |
| 164 |
objectName: "eventsTab" |
| 165 |
title: i18n.tr("Events") |
| 166 |
page: Loader { |
| 167 |
id: eventsOverviewLoader |
| 168 |
objectName: 'eventsOverviewLoader' |
| 169 |
anchors.fill: parent |
| 170 |
sourceComponent: allLoaded ? eventsOverviewComponent : loadingScreenComponent |
| 171 |
|
| 172 |
Component { |
| 173 |
id: eventsOverviewComponent |
| 174 |
EventsOverview { |
| 175 |
id: eventsOverview |
| 176 |
anchors.fill: parent |
| 177 |
|
| 178 |
Connections { |
| 179 |
target: photoViewerLoader.item |
| 180 |
onCloseRequested: { |
| 181 |
eventsOverview.head.visible = true; |
| 182 |
eventsOverview.head.locked = false; |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
onMediaSourcePressed: { |
| 187 |
eventsOverview.head.visible = false; |
| 188 |
eventsOverview.head.locked = true; |
| 189 |
|
| 190 |
photoViewerLoader.load(); |
| 191 |
overview.mediaCurrentlyInView = mediaSource.path; |
| 192 |
|
| 193 |
var rect = GalleryUtility.translateRect( |
| 194 |
thumbnailRect, eventsOverview,photoViewerLoader); |
| 195 |
photoViewerLoader.item.title = eventTab.title; |
| 196 |
photoViewerLoader.item.selection = selection; |
| 197 |
photoViewerLoader.item.animateOpen(mediaSource, rect); |
| 198 |
} |
| 199 |
|
| 200 |
onInSelectionModeChanged: { |
| 201 |
if (eventsOverview.inSelectionMode) |
| 202 |
eventTab.title = i18n.tr("Select") |
| 203 |
else |
| 204 |
eventTab.title = i18n.tr("Events") |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
Tab { |
| 212 |
id: photosTab |
| 213 |
title: i18n.tr("Photos") |
| 214 |
objectName: "photosTab" |
| 215 |
page: Loader { |
| 216 |
id: photosOverviewLoader |
| 217 |
anchors.fill: parent |
| 218 |
|
| 219 |
sourceComponent: allLoaded ? photosOverviewComponent : loadingScreenComponent |
| 220 |
|
| 221 |
Component { |
| 222 |
id: photosOverviewComponent |
| 223 |
PhotosOverview { |
| 224 |
id: photosOverview |
| 225 |
anchors.fill: parent |
| 226 |
model: mediaLibraryLoader.item |
| 227 |
|
| 228 |
Connections { |
| 229 |
target: photoViewerLoader.item |
| 230 |
onSelected: positionViewAtSelected(index); |
| 231 |
onCloseRequested: { |
| 232 |
photosOverview.head.visible = true; |
| 233 |
photosOverview.head.locked = false; |
| 234 |
} |
| 235 |
} |
| 236 |
|
| 237 |
onMediaSourcePressed: { |
| 238 |
photosOverview.head.visible = false; |
| 239 |
photosOverview.head.locked = true; |
| 240 |
|
| 241 |
photoViewerLoader.load(); |
| 242 |
overview.mediaCurrentlyInView = mediaSource.path; |
| 243 |
|
| 244 |
var rect = GalleryUtility.translateRect(thumbnailRect, |
| 245 |
photosOverview, |
| 246 |
photoViewerLoader); |
| 247 |
photoViewerLoader.item.title = photosTab.title; |
| 248 |
photoViewerLoader.item.selection = selection; |
| 249 |
photoViewerLoader.item.animateOpen(mediaSource, rect); |
| 250 |
} |
| 251 |
|
| 252 |
onInSelectionModeChanged: { |
| 253 |
if (photosOverview.inSelectionMode) |
| 254 |
photosTab.title = i18n.tr("Select") |
| 255 |
else |
| 256 |
photosTab.title = i18n.tr("Photos") |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
Component { |
| 265 |
id: loadingScreenComponent |
| 266 |
LoadingScreen { |
| 267 |
id: loadingScreen |
| 268 |
anchors.fill: parent |
| 269 |
} |
| 270 |
} |
| 271 |
|
| 272 |
/// Indicates if the photo viewer is currently open (shown to the user) |
| 273 |
property bool __isPhotoViewerOpen: photoViewerLoader.item && photoViewerLoader.item.isPoppedUp |
| 274 |
Loader { |
| 275 |
id: photoViewerLoader |
| 276 |
objectName: "photoViewerLoader" |
| 277 |
|
| 278 |
/// is true, if the photoviewer is currently loaded |
| 279 |
property bool loaded: photoViewerLoader.status === Loader.Ready |
| 280 |
|
| 281 |
function load() { |
| 282 |
setSource(Qt.resolvedUrl("MediaViewer/PopupPhotoViewer.qml"), {model: mediaLibraryLoader.item}); |
| 283 |
} |
| 284 |
|
| 285 |
anchors.fill: parent |
| 286 |
z: 100 |
| 287 |
|
| 288 |
|
| 289 |
Connections { |
| 290 |
target: photoViewerLoader.item |
| 291 |
onCloseRequested: { |
| 292 |
if (!APP.desktopMode) |
| 293 |
setFullScreenAppMode(false); |
| 294 |
popPage(); |
| 295 |
photoViewerLoader.item.fadeClosed(); |
| 296 |
overview.mediaCurrentlyInView = ""; |
| 297 |
} |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
Loader { |
| 302 |
id: mediaLibraryLoader |
| 303 |
sourceComponent: allLoaded ? mediaLibraryComponent : null |
| 304 |
|
| 305 |
Component { |
| 306 |
id: mediaLibraryComponent |
| 307 |
MediaCollectionModel { |
| 308 |
id: mediaLibrary |
| 309 |
monitored: true |
| 310 |
onIndexAdded: { |
| 311 |
if (APP.mediaFile == mediaLibrary.getAt(index).path) |
| 312 |
openMediaFile(APP.mediaFile); |
| 313 |
} |
| 314 |
} |
| 315 |
} |
| 316 |
} |
| 317 |
|
| 318 |
MouseArea { |
| 319 |
id: blocker |
| 320 |
anchors.fill: parent |
| 321 |
enabled: photoViewerLoader.item && photoViewerLoader.item.animationRunning |
| 322 |
} |
| 323 |
|
| 324 |
ActionContext { |
| 325 |
id: hudCtx |
| 326 |
active: __isPhotoViewerOpen |
| 327 |
} |
| 328 |
|
| 329 |
actionManager.localContexts: [ hudCtx ] |
| 330 |
|
| 331 |
SettingsController { id: settings } |
| 332 |
|
| 333 |
Settings { |
| 334 |
property alias defaultViewIndex: tabs.selectedTabIndex |
| 335 |
} |
| 336 |
|
| 337 |
Connections { |
| 338 |
target: UriHandler |
| 339 |
onOpened: { |
| 340 |
for (var i = 0; i < uris.length; ++i) { |
| 341 |
APP.parseUri(uris[i]) |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
Connections { |
| 347 |
target: APP |
| 348 |
onMediaFileChanged: { |
| 349 |
if (applicationLoaded && APP.mediaFile != "") { |
| 350 |
openMediaFile(APP.mediaFile); |
| 351 |
} |
| 352 |
} |
| 353 |
} |
| 354 |
|
| 355 |
Connections { |
| 356 |
target: ContentHub |
| 357 |
onExportRequested: { |
| 358 |
application.transfer = transfer |
| 359 |
APP.pickModeEnabled = true |
| 360 |
} |
| 361 |
onImportRequested: { |
| 362 |
for (var i = 0; i < transfer.items.length; i++) { |
| 363 |
APP.handleImportedFile(transfer.items[i].url) |
| 364 |
} |
| 365 |
transfer.finalize() |
| 366 |
eventsViewRequested() |
| 367 |
} |
| 368 |
} |
| 369 |
} |