Debian Codegraph @

rc/qml/EventsOverview.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 * Emanuele Sorce <[email protected]>
18 *
19 */
20
21 import QtQuick 2.9
22 import Lomiri.Components 1.3
23 import Lomiri.Components.Popups 1.3
24 import Gallery 1.0
25 import Lomiri.Content 1.3
26 import "Components"
27 import "OrganicView"
28 import "Utility"
29 import "../js/GalleryUtility.js" as GalleryUtility
30
31 // An "organic" vertically-scrollable view of all events, each containing a
32 // horizontally-scrollable "tray" of photos.
33 OrganicView {
34 id: organicEventView
35
36 /// True if in the selection mode
37 property alias inSelectionMode: select.inSelectionMode
38
39 /// Quit selection mode, and unselect all photos
40 function leaveSelectionMode() {
41 selection.unselectAll()
42 selection.inSelectionMode = false
43 }
44
45 selection: SelectionState {
46 id: select
47 }
48
49 model: EventCollectionModel {
50 }
51
52 delegate: OrganicMediaList {
53 id: photosList
54 objectName: "organicEventItem" + index
55
56 Connections {
57 target: organicEventView
58 onPositionEventsAtBeginning: {
59 photosList.positionViewAtBeginning();
60 }
61 }
62
63 width: organicEventView.width
64 event: model.event
65 selection: organicEventView.selection
66
67 onPressed: {
68 var rect = GalleryUtility.translateRect(thumbnailRect, photosList,
69 organicEventView);
70 organicEventView.mediaSourcePressed(mediaSource, rect);
71 }
72 }
73
74 Component {
75 id: deleteDialog
76 DeleteDialog {
77 title: {
78 if (organicEventView.selection.selectedVideosCount === 0) {
79 //No videos
80 return i18n.tr("Delete %1 photo",
81 "Delete %1 photos",
82 organicEventView.selection.selectedPhotosCount)
83 .arg(organicEventView.selection.selectedPhotosCount);
84 } else if (organicEventView.selection.selectedPhotosCount === 0) {
85 //No photos
86 return i18n.tr("Delete %1 video",
87 "Delete %1 videos",
88 organicEventView.selection.selectedVideosCount)
89 .arg(organicEventView.selection.selectedVideosCount);
90 } else {
91 //Mix of photos and videos
92 return i18n.tr("Delete %1 media file",
93 "Delete %1 media files",
94 organicEventView.selection.selectedMediaCount)
95 .arg(organicEventView.selection.selectedMediaCount);
96 }
97 }
98
99 onDeleteClicked: {
100 organicEventView.selection.model.destroySelectedMedia();
101 organicEventView.leaveSelectionMode();
102 }
103 }
104 }
105
106 property list<Action> overviewActions: [
107 Action {
108 objectName: "cameraButton"
109 text: i18n.tr("Camera")
110 visible: !APP.desktopMode
111 iconName: "camera-app-symbolic"
112 onTriggered: Qt.openUrlExternally("appid://camera.ubports/camera/current-user-version")
113 }
114 ]
115
116 property list<Action> selectActions: [
117 Action {
118 objectName: "deleteButton"
119
120 text: i18n.tr("Delete")
121 iconName: "delete"
122 enabled: selection.selectedCount > 0
123 onTriggered: PopupUtils.open(deleteDialog, null);
124 },
125 Action {
126 objectName: "shareButton"
127 text: i18n.tr("Share")
128 iconName: "share"
129 enabled: selection.selectedMediaCount > 0
130 onTriggered: {
131 if (selection.isMixed) {
132 PopupUtils.open(unableShareDialog, null);
133 return;
134 }
135 overview.pushPage(sharePicker);
136 sharePicker.visible = true;
137 }
138 },
139 Action {
140 objectName: "selectAllButton"
141 text: selection.model.count == selection.selectedCount ? i18n.tr("Unselect all") : i18n.tr("Select all")
142 iconName: selection.model.count == selection.selectedCount ? "select-none" : "select"
143 enabled: true
144 onTriggered: {
145 if (selection.model.count == selection.selectedCount) {
146 selection.unselectAll()
147 } else {
148 selection.selectAll()
149 }
150 }
151 },
152 Action {
153 id: addButton
154 objectName: "addButton"
155
156 text: i18n.tr("Add")
157 iconName: "add"
158 enabled: selection.selectedCount > 0
159 onTriggered: __albumPicker = PopupUtils.open(Qt.resolvedUrl("Components/PopupAlbumPicker.qml"),
160 null,
161 {contentHeight: organicEventView.__pickerContentHeight});
162 }
163 ]
164
165 property Action selectBackAction: Action {
166 text: i18n.tr("Cancel")
167 iconName: "back"
168 onTriggered: organicEventView.leaveSelectionMode();
169 }
170
171 property int __pickerContentHeight: height - units.gu(20)
172 property PopupAlbumPicker __albumPicker
173 Connections {
174 target: __albumPicker
175 onAlbumPicked: {
176 album.addSelectedMediaSources(selection.model.selectedMedias);
177 organicEventView.leaveSelectionMode();
178 }
179 }
180
181 property bool selectionMode: selection.inSelectionMode
182
183 // header: PageHeader {
184 // trailingActionBar {
185 // actions: selectionMode ? selectActions : overviewActions
186 // numberOfSlots: 4
187 // }
188 // leadingActionBar.actions: selectionMode ? selectBackAction : null
189 // }
190 head.actions: selectionMode ? selectActions : overviewActions
191 head.backAction: selectionMode ? selectBackAction : null
192 head.locked: true
193
194 Component {
195 id: unableShareDialog
196 UnableShareDialog {}
197 }
198
199 Component {
200 id: contentItemComp
201 ContentItem {}
202 }
203
204 Page {
205 id: sharePicker
206 visible: false
207
208 title: i18n.tr("Share to")
209
210 ContentPeerPicker {
211 objectName: "sharePickerEvents"
212 anchors.fill: parent
213 showTitle: false
214
215 contentType: organicEventView.selection.mediaType === MediaSource.Video ? ContentType.Videos : ContentType.Pictures
216 handler: ContentHandler.Share
217
218 onPeerSelected: {
219 overview.popPage();
220 sharePicker.visible = false;
221
222 var curTransfer = peer.request();
223 if (curTransfer.state === ContentTransfer.InProgress)
224 {
225 var medias = organicEventView.selection.model.selectedMediasQML;
226 curTransfer.items = medias.filter(function(data) {
227 return data.hasOwnProperty('type'); // filter out event headers
228 }).map(function(data) {
229 return contentItemComp.createObject(parent, {"url": data.path});
230 });
231 curTransfer.state = ContentTransfer.Charged;
232 }
233 }
234 onCancelPressed: {
235 overview.popPage();
236 sharePicker.visible = false;
237 }
238 }
239 }
240 }