Merge lp:~artmello/gallery-app/gallery-app-support_photo_url into lp:gallery-app

Proposed by Arthur Mello
Status: Merged
Approved by: Bill Filler
Approved revision: 1091
Merged at revision: 1083
Proposed branch: lp:~artmello/gallery-app/gallery-app-support_photo_url
Merge into: lp:gallery-app
Diff against target: 531 lines (+248/-14)
12 files modified
click/manifest.json.in (+2/-1)
debian/gallery-app.install (+1/-0)
desktop/CMakeLists.txt (+6/-0)
desktop/gallery-app.url-dispatcher (+5/-0)
rc/qml/MainScreen.qml (+46/-11)
src/gallery-application.cpp (+31/-1)
src/gallery-application.h (+8/-0)
src/util/CMakeLists.txt (+2/-0)
src/util/command-line-parser.cpp (+29/-1)
src/util/command-line-parser.h (+5/-0)
src/util/urlhandler.cpp (+70/-0)
src/util/urlhandler.h (+43/-0)
To merge this branch: bzr merge lp:~artmello/gallery-app/gallery-app-support_photo_url
Reviewer Review Type Date Requested Status
Bill Filler (community) Approve
PS Jenkins bot continuous-integration Needs Fixing
Review via email: mp+235656@code.launchpad.net

Commit message

Add support for the photo and video url schema

Description of the change

Add support for the photo and video url schema

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1085. By Arthur Mello

Add "file://" protocol to the media selected property

1086. By Arthur Mello

Remove support for the video scheme

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

two issues:
1) remove pot file from the MR
2) the url-dispatcher registration is not working during the click package install

review: Needs Fixing
1087. By Arthur Mello

Add urls to the manifest of the click pkg

1088. By Arthur Mello

Fix manifest file

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1089. By Arthur Mello

Undo changes on pot file

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

It's registered properly but it has issues:

1) Launch app, go to events page
- call url-dispatcher photo://file1.jpg
- the photo is opened correctly
- tap the photo to display the header
- press the back button in the header to go back to Events view
- call url-dispatcher photo://file1.jpg again
- the photo is never shown
Photos are never shown if they were previously requested by url-dispatcher.

2) Launch app, go to events page
- call url-dispatcher photo://file1.jpg
- the photo is opened correctly
- call url-dispatcher photo://file2.jpg
- the photo is opened correctly
- tap on the photo to display header
- press the back button
- You get a blank page, still showing the Gallery header with the back button
- press the back button again and it correctly shows the Events view

Seems like each time you open a photo via the url-dispatcher you are putting a new page on the stack and you have to pop all of them by pressing the back button each time to get back to the event view. This is not correct. If you repeat the same thing above 5 times you have to press back button 5 times to get back to Events view.

3) Similar problem
- open a photo from Events view or Photo view
- call url-dispatcher photo://file1.jpg
- tap photo to reveal header
- press back button
- get a blank page with Gallery header

review: Needs Fixing
1090. By Arthur Mello

Make sure we do not keep stacking new pages for it photo opened

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1091. By Arthur Mello

Make sure the selected mediaFile should open if it was the same as the last call

Revision history for this message
Arthur Mello (artmello) wrote :

The 3 issues are fixed on rev1091

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

Did you perform an exploratory manual test run of the code change and any related functionality on device or emulator?
yes

Did you successfully run all tests found in your component's Test Plan (https://wiki.ubuntu.com/Process/Merges/TestPlan/<package-name>) on device or emulator?
yes

Did CI run pass? If not, please explain why.
yes

Have you checked that submitter has accurately filled out the submitter checklist and has taken no shortcut?
yes

review: Approve
1092. By Arthur Mello

Fix gallery-app.install file

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click/manifest.json.in'
2--- click/manifest.json.in 2014-09-09 08:14:03 +0000
3+++ click/manifest.json.in 2014-09-25 20:20:53 +0000
4@@ -6,7 +6,8 @@
5 "gallery": {
6 "apparmor": "gallery.apparmor",
7 "content-hub": "gallery-content.json",
8- "desktop": "@CMAKE_INSTALL_DATADIR@/applications/@DESKTOP_FILE@"
9+ "desktop": "@CMAKE_INSTALL_DATADIR@/applications/@DESKTOP_FILE@",
10+ "urls": "share/url-dispatcher/urls/gallery-app.url-dispatcher"
11 }
12 },
13 "icon": "share/icons/gallery-app.svg",
14
15=== modified file 'debian/gallery-app.install'
16--- debian/gallery-app.install 2013-05-22 17:29:50 +0000
17+++ debian/gallery-app.install 2014-09-25 20:20:53 +0000
18@@ -3,3 +3,4 @@
19 usr/share/gallery-app
20 usr/share/icons
21 usr/share/locale/*/LC_MESSAGES/gallery-app.mo
22+usr/share/url-dispatcher/urls/*
23
24=== modified file 'desktop/CMakeLists.txt'
25--- desktop/CMakeLists.txt 2014-09-15 12:19:20 +0000
26+++ desktop/CMakeLists.txt 2014-09-25 20:20:53 +0000
27@@ -10,6 +10,8 @@
28 set(ICON "${GALLERY}")
29 endif(CLICK_MODE)
30
31+set(GALLERY_URL_DISPATCHER gallery-app.url-dispatcher)
32+
33 configure_file(${DESKTOP_FILE}.in.in ${DESKTOP_FILE}.in @ONLY)
34 add_custom_target(${DESKTOP_FILE} ALL
35 COMMENT "Merging translations into ${DESKTOP_FILE}"
36@@ -18,3 +20,7 @@
37
38 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${DESKTOP_FILE}
39 DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
40+
41+install(FILES ${GALLERY_URL_DISPATCHER}
42+ DESTINATION ${CMAKE_INSTALL_DATADIR}/url-dispatcher/urls
43+ )
44
45=== added file 'desktop/gallery-app.url-dispatcher'
46--- desktop/gallery-app.url-dispatcher 1970-01-01 00:00:00 +0000
47+++ desktop/gallery-app.url-dispatcher 2014-09-25 20:20:53 +0000
48@@ -0,0 +1,5 @@
49+[
50+ {
51+ "protocol": "photo"
52+ }
53+]
54
55=== modified file 'rc/qml/MainScreen.qml'
56--- rc/qml/MainScreen.qml 2014-09-19 01:05:46 +0000
57+++ rc/qml/MainScreen.qml 2014-09-25 20:20:53 +0000
58@@ -38,26 +38,43 @@
59 property string mediaCurrentlyInView
60 StateSaver.properties: "mediaCurrentlyInView"
61
62+ property bool applicationLoaded: application.allLoaded
63+
64 //fullScreen property is used on autopilot tests
65 property bool fullScreen: APP.fullScreen
66
67 property alias currentPage: pageStack.currentPage
68
69+ function openMediaFile(media) {
70+ if (__isPhotoViewerOpen) {
71+ popPage();
72+ photoViewerLoader.item.fadeClosed();
73+ }
74+
75+ mediaCurrentlyInView = media;
76+ for (var i = 0; i < MANAGER.mediaLibrary.count; i++) {
77+ if (MANAGER.mediaLibrary.getAt(i).path == mediaCurrentlyInView) {
78+ photoViewerLoader.load();
79+ photoViewerLoader.item.animateOpen(MANAGER.mediaLibrary.getAt(i),
80+ Qt.rect(0,0,0,0));
81+ return;
82+ }
83+ }
84+ }
85+
86 Component.onCompleted: {
87- if (mediaCurrentlyInView !== "") {
88- for (var i = 0; i < MANAGER.mediaLibrary.count; i++) {
89- if (MANAGER.mediaLibrary.getAt(i).path == mediaCurrentlyInView) {
90- photoViewerLoader.load();
91- photoViewerLoader.item.animateOpen(MANAGER.mediaLibrary.getAt(i),
92- Qt.rect(0,0,0,0));
93- return;
94- }
95- }
96- }
97-
98 pageStack.push(tabs);
99 }
100
101+ onApplicationLoadedChanged: {
102+ if (applicationLoaded) {
103+ if (APP.mediaFile !== "")
104+ openMediaFile(APP.mediaFile);
105+ else if (mediaCurrentlyInView !== "")
106+ openMediaFile(mediaCurrentlyInView);
107+ }
108+ }
109+
110 function pushPage(page) {
111 pageStack.push(page);
112 }
113@@ -216,4 +233,22 @@
114 active: __isPhotoViewerOpen
115 }
116 ]
117+
118+ Connections {
119+ target: UriHandler
120+ onOpened: {
121+ for (var i = 0; i < uris.length; ++i) {
122+ APP.parseUri(uris[i])
123+ }
124+ }
125+ }
126+
127+ Connections {
128+ target: APP
129+ onMediaFileChanged: {
130+ if (applicationLoaded) {
131+ openMediaFile(APP.mediaFile);
132+ }
133+ }
134+ }
135 }
136
137=== modified file 'src/gallery-application.cpp'
138--- src/gallery-application.cpp 2014-08-20 18:37:06 +0000
139+++ src/gallery-application.cpp 2014-09-25 20:20:53 +0000
140@@ -45,6 +45,7 @@
141
142 // util
143 #include "command-line-parser.h"
144+#include "urlhandler.h"
145 #include "resource.h"
146
147 #include <QQuickItem>
148@@ -67,7 +68,8 @@
149 m_contentCommunicator(new ContentCommunicator(this)),
150 m_pickModeEnabled(false),
151 m_defaultUiMode(BrowseContentMode),
152- m_mediaTypeFilter(MediaSource::None)
153+ m_mediaTypeFilter(MediaSource::None),
154+ m_mediaFile("")
155 {
156 m_bguSize = QProcessEnvironment::systemEnvironment().value("GRID_UNIT_PX", "8").toInt();
157 if (m_bguSize <= 0)
158@@ -98,6 +100,8 @@
159 }
160 }
161
162+ m_urlHandler = new UrlHandler();
163+
164 registerQML();
165
166 m_galleryManager = new GalleryManager(isDesktopMode(), m_cmdLineParser->picturesDir());
167@@ -181,6 +185,15 @@
168 }
169
170 /*!
171+ * \brief GalleryApplication::getMediaFile
172+ * Returns the media file passed as a parameter
173+ */
174+const QString& GalleryApplication::getMediaFile() const
175+{
176+ return m_mediaFile;
177+}
178+
179+/*!
180 * \brief GalleryApplication::createView
181 * Create the master QDeclarativeView that all the pages will operate within
182 */
183@@ -225,6 +238,8 @@
184
185 if (m_cmdLineParser->startupTimer())
186 qDebug() << "GalleryApplication view created" << m_timer->elapsed() << "ms";
187+
188+ setMediaFile(m_cmdLineParser->mediaFile());
189 }
190
191 /*!
192@@ -333,6 +348,14 @@
193 Q_EMIT fullScreenChanged();
194 }
195
196+void GalleryApplication::setMediaFile(const QString &mediaFile)
197+{
198+ if(!mediaFile.isEmpty()) {
199+ m_mediaFile = "file://" + mediaFile;
200+ Q_EMIT mediaFileChanged();
201+ }
202+}
203+
204 /*!
205 * \brief GalleryApplication::returnPickedContent passes the selcted items to the
206 * content manager
207@@ -399,3 +422,10 @@
208 // during start-up.
209 m_contentCommunicator->registerWithHub();
210 }
211+
212+void GalleryApplication::parseUri(const QString &arg)
213+{
214+ if (m_urlHandler->processUri(arg)) {
215+ setMediaFile(m_urlHandler->mediaFile());
216+ }
217+}
218
219=== modified file 'src/gallery-application.h'
220--- src/gallery-application.h 2014-08-19 08:28:09 +0000
221+++ src/gallery-application.h 2014-09-25 20:20:53 +0000
222@@ -27,6 +27,7 @@
223 #include "media-source.h"
224
225 class CommandLineParser;
226+class UrlHandler;
227 class ContentCommunicator;
228 class GalleryManager;
229
230@@ -42,6 +43,7 @@
231 Q_PROPERTY(MediaSource::MediaType mediaTypeFilter READ mediaTypeFilter NOTIFY mediaTypeFilterChanged)
232 Q_PROPERTY(bool desktopMode READ isDesktopMode CONSTANT)
233 Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged)
234+ Q_PROPERTY(QString mediaFile READ getMediaFile WRITE setMediaFile NOTIFY mediaFileChanged)
235
236 public:
237 enum UiMode{
238@@ -61,9 +63,11 @@
239 bool isDesktopMode() const;
240 bool isFullScreen() const;
241 MediaSource::MediaType mediaTypeFilter() const;
242+ const QString &getMediaFile() const;
243
244 Q_INVOKABLE void returnPickedContent(QVariant variant);
245 Q_INVOKABLE void contentPickingCanceled();
246+ Q_INVOKABLE void parseUri(const QString &arg);
247
248 static void startStartupTimer();
249
250@@ -72,12 +76,14 @@
251 void pickModeEnabledChanged();
252 void fullScreenChanged();
253 void mediaTypeFilterChanged();
254+ void mediaFileChanged();
255
256 private slots:
257 void initCollections();
258 void switchToPickMode(QString mediaTypeFilter);
259 void setFullScreen(bool fullScreen);
260 void consistencyCheckFinished();
261+ void setMediaFile(const QString &mediaFile);
262
263 private:
264 void registerQML();
265@@ -86,12 +92,14 @@
266 QQuickView *m_view;
267 GalleryManager *m_galleryManager;
268 CommandLineParser* m_cmdLineParser;
269+ UrlHandler *m_urlHandler;
270 ContentCommunicator *m_contentCommunicator;
271 QHash<QString, QSize> m_formFactors;
272 int m_bguSize;
273 bool m_pickModeEnabled;
274 UiMode m_defaultUiMode;
275 MediaSource::MediaType m_mediaTypeFilter;
276+ QString m_mediaFile;
277
278 static QElapsedTimer *m_timer;
279 };
280
281=== modified file 'src/util/CMakeLists.txt'
282--- src/util/CMakeLists.txt 2013-08-26 10:44:00 +0000
283+++ src/util/CMakeLists.txt 2014-09-25 20:20:53 +0000
284@@ -14,6 +14,7 @@
285 orientation.h
286 resource.h
287 variants.h
288+ urlhandler.h
289 )
290
291 set(gallery_util_SRCS
292@@ -21,6 +22,7 @@
293 imaging.cpp
294 orientation.cpp
295 resource.cpp
296+ urlhandler.cpp
297 )
298
299 add_library(${GALLERY_UTIL_LIB}
300
301=== modified file 'src/util/command-line-parser.cpp'
302--- src/util/command-line-parser.cpp 2013-08-27 06:48:42 +0000
303+++ src/util/command-line-parser.cpp 2014-09-25 20:20:53 +0000
304@@ -20,10 +20,13 @@
305
306 #include "command-line-parser.h"
307
308+#include "urlhandler.h"
309+
310 #include <QDebug>
311 #include <QDir>
312 #include <QStandardPaths>
313 #include <QTextStream>
314+#include <QUrl>
315
316 CommandLineParser::CommandLineParser(const QHash<QString, QSize>& form_factors)
317 : m_startupTimer(false),
318@@ -33,8 +36,10 @@
319 m_pickMode(false),
320 m_logImageLoading(false),
321 m_formFactors(form_factors),
322- m_formFactor("desktop")
323+ m_formFactor("desktop"),
324+ m_mediaFile("")
325 {
326+ m_urlHandler = new UrlHandler();
327 }
328
329 /*!
330@@ -72,6 +77,25 @@
331 else if (args[i] == "--pick-mode") {
332 m_pickMode = true;
333 }
334+ else if (args[i] == "--media-file") {
335+ if (!value.isEmpty()) {
336+ QFileInfo fi(value);
337+
338+ if (fi.exists())
339+ m_mediaFile = fi.absoluteFilePath();
340+ else {
341+ QTextStream(stderr) << m_mediaFile << ": Not found" << endl;
342+ valid_args = false;
343+ }
344+
345+ i++;
346+ }
347+ else {
348+ QTextStream(stderr) << "Missing FILE argument for --media-file'" << endl;
349+ usage();
350+ valid_args = false;
351+ }
352+ }
353 else {
354 QString form_factor = args[i].mid(2); // minus initial "--"
355
356@@ -81,6 +105,9 @@
357 else if (args[i].startsWith("--desktop_file_hint")) {
358 // ignore this command line switch, hybris uses it to get application info
359 }
360+ else if (m_urlHandler->processUri(args.at(i))) {
361+ m_mediaFile = m_urlHandler->mediaFile();
362+ }
363 else if (i == args.count() - 1 && QDir(args[i]).exists()) {
364 m_picturesDir = args[i];
365 }
366@@ -112,6 +139,7 @@
367 out << " --startup-timer\n\t\tdebug-print startup time" << endl;
368 out << " --log-image-loading\n\t\tlog image loading" << endl;
369 out << " --pick-mode\n\t\tEnable mode to pick photos" << endl;
370+ out << " --media-file FILE\n\t\tOpens gallery displaying the selected file" << endl;
371 out << "pictures_dir defaults to ~/Pictures, and must exist prior to running gallery" << endl;
372 }
373
374
375=== modified file 'src/util/command-line-parser.h'
376--- src/util/command-line-parser.h 2013-08-27 06:48:42 +0000
377+++ src/util/command-line-parser.h 2014-09-25 20:20:53 +0000
378@@ -25,6 +25,8 @@
379 #include <QSize>
380 #include <QString>
381
382+class UrlHandler;
383+
384 /*!
385 * @brief The CommandLineParser is used to parse our commandline inputs and set
386 * parameters accordingly.
387@@ -43,11 +45,13 @@
388 bool logImageLoading() const { return m_logImageLoading; }
389 bool pickModeEnabled() const { return m_pickMode; }
390 const QString &formFactor() const { return m_formFactor; }
391+ const QString &mediaFile() const { return m_mediaFile; }
392
393 private:
394 bool invalidArg(QString arg);
395 void usage();
396
397+ UrlHandler *m_urlHandler;
398 bool m_startupTimer;
399 bool m_isFullscreen;
400 bool m_isPortrait;
401@@ -57,6 +61,7 @@
402
403 const QHash<QString, QSize> m_formFactors;
404 QString m_formFactor;
405+ QString m_mediaFile;
406 };
407
408 #endif // COMMANDLINEPARSER_H
409
410=== added file 'src/util/urlhandler.cpp'
411--- src/util/urlhandler.cpp 1970-01-01 00:00:00 +0000
412+++ src/util/urlhandler.cpp 2014-09-25 20:20:53 +0000
413@@ -0,0 +1,70 @@
414+/*
415+ * Copyright (C) 2014 Canonical, Ltd.
416+ *
417+ * Authors:
418+ * Arthur Mello <arthur.mello@canonical.com>
419+ *
420+ * This program is free software; you can redistribute it and/or modify
421+ * it under the terms of the GNU General Public License as published by
422+ * the Free Software Foundation; version 3.
423+ *
424+ * This program is distributed in the hope that it will be useful,
425+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
426+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
427+ * GNU General Public License for more details.
428+ *
429+ * You should have received a copy of the GNU General Public License
430+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
431+ *
432+ */
433+
434+#include "urlhandler.h"
435+
436+#include <QUrl>
437+#include <QStringList>
438+#include <QFileInfo>
439+#include <QDir>
440+#include <QDebug>
441+
442+UrlHandler::UrlHandler()
443+ : m_mediaFile("")
444+{
445+ m_validSchemes << "photo";
446+}
447+
448+/*!
449+ * @brief UrlHandler::processUri parsers our input uri and sets attributes accordingly.
450+ * @param QString uri to parse and set attributes.
451+ * @return false if invalid parameter is input.
452+ */
453+bool UrlHandler::processUri(const QString& arg)
454+{
455+ QUrl uri(arg);
456+
457+ if (!m_validSchemes.contains(uri.scheme())) {
458+ return false;
459+ }
460+
461+ if (uri.scheme() == "photo") {
462+ uri.setScheme("file");
463+ }
464+
465+ if (uri.isRelative()) {
466+ uri = QUrl::fromLocalFile(QDir::current().absoluteFilePath(arg));
467+ }
468+
469+ // Check if it's a local file
470+ if (uri.isValid() && uri.isLocalFile()) {
471+ QFileInfo info(uri.toLocalFile());
472+ if (info.exists() && info.isFile()) {
473+ m_mediaFile = info.absoluteFilePath();
474+ return true;
475+ } else {
476+ qWarning() << "File not found:" << uri << info.exists() << info.isFile();
477+ }
478+ } else {
479+ qWarning() << "Invalid uri:" << uri;
480+ }
481+
482+ return false;
483+}
484
485=== added file 'src/util/urlhandler.h'
486--- src/util/urlhandler.h 1970-01-01 00:00:00 +0000
487+++ src/util/urlhandler.h 2014-09-25 20:20:53 +0000
488@@ -0,0 +1,43 @@
489+/*
490+ * Copyright (C) 2014 Canonical, Ltd.
491+ *
492+ * Authors:
493+ * Arthur Mello <arthur.mello@canonical.com>
494+ *
495+ * This program is free software; you can redistribute it and/or modify
496+ * it under the terms of the GNU General Public License as published by
497+ * the Free Software Foundation; version 3.
498+ *
499+ * This program is distributed in the hope that it will be useful,
500+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
501+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
502+ * GNU General Public License for more details.
503+ *
504+ * You should have received a copy of the GNU General Public License
505+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
506+ *
507+ */
508+
509+#ifndef URLHANDLER_H
510+#define URLHANDLER_H
511+
512+#include <QString>
513+#include <QList>
514+
515+/*!
516+ * @brief The UrlHandler is used to parse calls of gallery from the url schema.
517+ */
518+class UrlHandler
519+{
520+public:
521+ UrlHandler();
522+
523+ bool processUri(const QString &arg);
524+ const QString &mediaFile() { return m_mediaFile; }
525+
526+private:
527+ QList<QString> m_validSchemes;
528+ QString m_mediaFile;
529+};
530+
531+#endif // URLHANDLER_H

Subscribers

People subscribed via source and target branches