Debian Codegraph @

rc/qml/PhotosOverview.qml

raw
1 /*
2 * Copyright (C) 2012-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 * Authors:
17 * Jim Nelson <[email protected]>
18 */
19
20 import QtQuick 2.9
21 import Gallery 1.0
22 import Lomiri.Components 1.3
23 import Lomiri.Components.Popups 1.3
24 import Lomiri.Content 1.3
25 import "Components"
26 import "Utility"
27 import "../js/Gallery.js" as Gallery
28 import "../js/GalleryUtility.js" as GalleryUtility
29
30 /*!
31 PhotosOverview show all the photos of the collection in chronological order in one big grid
32 */
33 Page {
34 id: photosOverview
35
36 /// Emitted when a photos was clicked
37 /// @param mediaSource is the photo object
38 /// @param thumbnailRect is the rect, the photo thumbnails is shown in
39 signal mediaSourcePressed(var mediaSource, var thumbnailRect)
40
41 /// The photo to show in this view
42 property MediaCollectionModel model
43
44 /// True if in the selection mode
45 property alias inSelectionMode: d.inSelectionMode
46
47 property alias selection: d.selection
48
49 /// Quit selection mode, and unselect all photos
50 function leaveSelectionMode() {
51 d.selection.unselectAll();
52 d.selection.inSelectionMode = false;
53 }
54
55 function positionViewAtBeginning() {
56 photosGrid.positionViewAtBeginning();
57 //FIXME Initial content is hide bellow Page Header after a positionViewAtBeginning()
58 photosGrid.contentY = units.gu(7) * -1;
59 }
60
61 function positionViewAtSelected(index) {
62 photosGrid.positionViewAtIndex(index, GridView.Center);
63 }
64
65 property string pageTitle
66
67 // header: PageHeader {
68 // trailingActionBar {
69 // actions: inSelectionMode ? d.selectActions : d.overviewActions
70 // numberOfSlots: 4
71 // }
72 // leadingActionBar.actions: inSelectionMode ? d.selectBackAction : null
73 // // title: pageTitle
74 // }
75
76 head.actions: inSelectionMode ? d.selectActions : d.overviewActions
77 head.backAction: inSelectionMode ? d.selectBackAction : null
78 head.locked: true
79
80 ScrollView {
81 id: scrollWrapper
82 anchors.top: parent.top
83 anchors.topMargin: units.gu(6) //header height
84 anchors.bottom: parent.bottom
85 width: parent.width
86 contentItem: photosGrid
87 }
88
89 MediaGrid {
90 id: photosGrid
91 property var gridSize: units.gu(settings.gridUnits)
92 anchors.fill: parent
93 model: photosOverview.model
94 selection: d.selection
95 }
96
97 Component {
98 id: deleteDialog
99 DeleteDialog {
100 title: {
101 if (d.selection.selectedVideosCount === 0) {
102 //No videos
103 return i18n.tr("Delete %1 photo",
104 "Delete %1 photos",
105 d.selection.selectedPhotosCount)
106 .arg(d.selection.selectedPhotosCount);
107 } else if (d.selection.selectedPhotosCount === 0) {
108 //No photos
109 return i18n.tr("Delete %1 video",
110 "Delete %1 videos",
111 d.selection.selectedVideosCount)
112 .arg(d.selection.selectedVideosCount);
113 } else {
114 //Mix of photos and videos
115 return i18n.tr("Delete %1 media file",
116 "Delete %1 media files",
117 d.selection.selectedMediaCount)
118 .arg(d.selection.selectedMediaCount);
119 }
120 }
121 onDeleteClicked: {
122 d.selection.model.destroySelectedMedia();
123 photosOverview.leaveSelectionMode();
124 }
125 }
126 }
127
128 Component {
129 id: gridSel
130 Dialog {
131 id: gridDia
132 title: i18n.tr("Grid Size")
133 text: i18n.tr("Select the grid size in gu units between 8 and 20 (default is 12)")
134
135 Slider {
136 function formatValue(v) { return v.toFixed(0) }
137 minimumValue: 8
138 maximumValue: 20
139 value: settings.gridUnits
140 live: true
141
142 onValueChanged: {
143 settings.gridUnits = value
144 }
145 }
146
147 Button {
148 text: i18n.tr("Finished")
149 onClicked: PopupUtils.close(gridDia)
150 }
151 }
152 }
153
154 property int __pickerContentHeight: height - units.gu(20)
155 property PopupAlbumPicker __albumPicker
156 Connections {
157 target: __albumPicker
158 onAlbumPicked: {
159 album.addSelectedMediaSources(d.selection.model.selectedMedias);
160 photosOverview.leaveSelectionMode();
161 }
162 }
163
164 Item {
165 id: d
166
167 property bool inSelectionMode: selection.inSelectionMode
168 property SelectionState selection: SelectionState {
169 model: photosOverview.model
170 }
171
172 property list<Action> overviewActions: [
173 Action {
174 objectName: "gridButton"
175 text: i18n.tr("Grid Size")
176 iconName: "view-grid-symbolic"
177 enabled: d.selection !== null
178 onTriggered: PopupUtils.open(gridSel);
179 },
180 Action {
181 objectName: "cameraButton"
182 text: i18n.tr("Camera")
183 visible: !APP.desktopMode
184 iconName: "camera-app-symbolic"
185 onTriggered: Qt.openUrlExternally("appid://camera.ubports/camera/current-user-version")
186 }
187 ]
188
189 property list<Action> selectActions: [
190 Action {
191 objectName: "deleteButton"
192
193 text: i18n.tr("Delete")
194 iconName: "delete"
195 enabled: d.selection.selectedCount > 0
196 onTriggered: PopupUtils.open(deleteDialog, null);
197 },
198 Action {
199 objectName: "shareButton"
200 text: i18n.tr("Share")
201 iconName: "share"
202 enabled: d.selection.selectedMediaCount > 0
203 onTriggered: {
204 if (selection.isMixed) {
205 PopupUtils.open(unableShareDialog, null);
206 return;
207 }
208
209 overview.pushPage(sharePicker)
210 sharePicker.visible = true;
211 }
212 },
213 Action {
214 objectName: "selectAllButton"
215 text: photosGrid.count == d.selection.selectedMediaCount ? i18n.tr("Unselect all") : i18n.tr("Select all")
216 iconName: photosGrid.count == d.selection.selectedMediaCount ? "select-none" : "select"
217 enabled: true
218 onTriggered: {
219 if (photosGrid.count == d.selection.selectedMediaCount) {
220 d.selection.unselectAll()
221 } else {
222 d.selection.selectAll()
223 }
224 }
225 },
226 Action {
227 id: addButton
228 objectName: "addButton"
229
230 text: i18n.tr("Add")
231 iconName: "add"
232 enabled: d.selection.selectedCount > 0
233 onTriggered: __albumPicker = PopupUtils.open(Qt.resolvedUrl("Components/PopupAlbumPicker.qml"),
234 null,
235 {contentHeight: photosOverview.__pickerContentHeight});
236 }
237 ]
238
239 property Action selectBackAction: Action {
240 text: i18n.tr("Cancel")
241 iconName: "back"
242 onTriggered: photosOverview.leaveSelectionMode();
243 }
244 }
245
246 Component {
247 id: unableShareDialog
248 UnableShareDialog {}
249 }
250
251 Component {
252 id: contentItemComp
253 ContentItem {}
254 }
255
256 Page {
257 id: sharePicker
258 visible: false
259 title: i18n.tr("Share to")
260
261 ContentPeerPicker {
262 objectName: "sharePickerPhotos"
263 showTitle: false
264 anchors.fill: parent
265 contentType: d.selection.mediaType === MediaSource.Video ? ContentType.Videos : ContentType.Pictures
266 handler: ContentHandler.Share
267
268 onPeerSelected: {
269 overview.popPage();
270 sharePicker.visible = false;
271
272 var curTransfer = peer.request();
273 if (curTransfer.state === ContentTransfer.InProgress)
274 {
275 curTransfer.items = d.selection.model.selectedMediasQML.map(function(data) {
276 return contentItemComp.createObject(parent, {"url": data.path});
277 });
278 curTransfer.state = ContentTransfer.Charged;
279 }
280 }
281 onCancelPressed: {
282 overview.popPage();
283 sharePicker.visible = false;
284 }
285 }
286 }
287 }