Merge lp:~verzegnassi-stefano/ubuntu-docviewer-app/reboot-app-init into lp:ubuntu-docviewer-app

Proposed by Stefano Verzegnassi
Status: Merged
Approved by: Stefano Verzegnassi
Approved revision: 196
Merged at revision: 190
Proposed branch: lp:~verzegnassi-stefano/ubuntu-docviewer-app/reboot-app-init
Merge into: lp:ubuntu-docviewer-app
Diff against target: 1171 lines (+257/-692)
15 files modified
po/com.ubuntu.docviewer.pot (+28/-6)
src/app/CMakeLists.txt (+10/-3)
src/app/command-line-parser.cpp (+0/-134)
src/app/command-line-parser.h (+0/-60)
src/app/config.h.in (+45/-0)
src/app/docviewer-application.cpp (+0/-245)
src/app/docviewer-application.h (+0/-80)
src/app/main.cpp (+52/-15)
src/app/qml/common/CommandLineProxy.qml (+82/-0)
src/app/qml/pdfView/PdfView.qml (+2/-2)
src/app/qml/ubuntu-docviewer-app.qml (+25/-34)
src/app/urlhandler.cpp (+0/-70)
src/app/urlhandler.h (+0/-43)
src/plugin/file-qml-plugin/docviewerutils.cpp (+10/-0)
src/plugin/file-qml-plugin/docviewerutils.h (+3/-0)
To merge this branch: bzr merge lp:~verzegnassi-stefano/ubuntu-docviewer-app/reboot-app-init
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Stefano Verzegnassi Approve
Roman Shchekin Approve
Review via email: mp+274806@code.launchpad.net

Commit message

* Refactored cpp init
* Moved command line parser to QML

Description of the change

* Refactored cpp init
* Moved command line parser to QML

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Roman Shchekin (mrqtros) wrote :

A lot of changes, but looks ok! Hope didn't missed something important :)

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
194. By Stefano Verzegnassi

Merged 'reboot' branch

195. By Stefano Verzegnassi

Updated translation template

(src/app/config.h cannot work and Jenkins tests should fail, I suppose)

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

Currently config.h needs to be configured by CMake. Both in rev.193 (which has been approved by Jenkins) and rev. 195 that does not happen.

For what I understand, the Debian package created by Jenkins tries to load "@DATA_DIR@/qml/ubuntu-docviewer-app.qml", which is not a legal path.

Don't know how it successed with tests, since they should fail.

review: Needs Fixing
Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

Indeed, just created the .deb package on my pc and it does NOT work.

0) Open terminal
1) Used 'dpkg-buildpackage -us -uc' on the sources
2) Installed the created package via USC
3) From terminal, tried to run 'ubuntu-docviewer-app'

Console output:
"file:///home/stefano/@DATA_DIR@/qml/ubuntu-docviewer-app.qml: File not found"

I'm sorry for my mistake, but here's the big question:

- Is Jenkins set to run Autopilot tests for 'reboot' branch?

196. By Stefano Verzegnassi

Fixed app launch when running from QtCreator or an installed .deb package

Revision history for this message
Stefano Verzegnassi (verzegnassi-stefano) wrote :

Ok, now it works. Also, I gave a run to the Autopilot tests on my PC and everything was okay.

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'po/com.ubuntu.docviewer.pot'
2--- po/com.ubuntu.docviewer.pot 2015-10-18 21:27:16 +0000
3+++ po/com.ubuntu.docviewer.pot 2015-10-20 11:59:20 +0000
4@@ -8,7 +8,7 @@
5 msgstr ""
6 "Project-Id-Version: \n"
7 "Report-Msgid-Bugs-To: \n"
8-"POT-Creation-Date: 2015-10-19 00:19+0300\n"
9+"POT-Creation-Date: 2015-10-20 00:24+0200\n"
10 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
11 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
12 "Language-Team: LANGUAGE <LL@li.org>\n"
13@@ -18,9 +18,27 @@
14 "Content-Transfer-Encoding: 8bit\n"
15 "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
16
17-#: ../src/app/docviewer-application.cpp:162
18-#: /home/qtros/dev/build-ubuntu-docviewer-app-more-oop-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:1
19-msgid "Document Viewer"
20+#: ../src/app/qml/common/CommandLineProxy.qml:49
21+msgid "Some of the provided arguments is not valid."
22+msgstr ""
23+
24+#: ../src/app/qml/common/CommandLineProxy.qml:58
25+msgid "Opens ubuntu-docviewer-app displaying the selected file"
26+msgstr ""
27+
28+#: ../src/app/qml/common/CommandLineProxy.qml:65
29+msgid "Run fullscreen"
30+msgstr ""
31+
32+#: ../src/app/qml/common/CommandLineProxy.qml:71
33+msgid "Open ubuntu-docviewer-app in pick mode. Use it for tests only."
34+msgstr ""
35+
36+#: ../src/app/qml/common/CommandLineProxy.qml:77
37+msgid ""
38+"Load the list of documents from the given folder, instead of default ~/"
39+"Documents.\n"
40+"The path must exist prior to running ubuntu-docviewer-app"
41 msgstr ""
42
43 #: ../src/app/qml/common/DetailsPage.qml:27
44@@ -443,11 +461,15 @@
45 #.
46 #. where "2" is given by the argument "%1"
47 #.
48-#: ../src/plugin/file-qml-plugin/docviewerutils.cpp:101
49+#: ../src/plugin/file-qml-plugin/docviewerutils.cpp:111
50 #, qt-format
51 msgid "copy %1"
52 msgstr ""
53
54-#: /home/qtros/dev/build-ubuntu-docviewer-app-more-oop-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:2
55+#: /tmp/build-reboot-app-init-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:1
56+msgid "Document Viewer"
57+msgstr ""
58+
59+#: /tmp/build-reboot-app-init-Desktop-Default/po/com.ubuntu.docviewer.desktop.in.in.h:2
60 msgid "documents;viewer;pdf;reader;"
61 msgstr ""
62
63=== modified file 'src/app/CMakeLists.txt'
64--- src/app/CMakeLists.txt 2015-09-19 14:54:11 +0000
65+++ src/app/CMakeLists.txt 2015-10-20 11:59:20 +0000
66@@ -6,11 +6,18 @@
67 -DGETTEXT_LOCALEDIR=\"${CMAKE_INSTALL_LOCALEDIR}\"
68 )
69
70+configure_file(
71+ config.h.in
72+ ${CMAKE_CURRENT_BINARY_DIR}/config.h
73+ @ONLY
74+)
75+
76+include_directories(
77+ ${CMAKE_CURRENT_BINARY_DIR}
78+)
79+
80 set(docviewer_SRCS
81 main.cpp
82- command-line-parser.cpp
83- docviewer-application.cpp
84- urlhandler.cpp
85 ${QML_SRCS}
86 )
87
88
89=== removed file 'src/app/command-line-parser.cpp'
90--- src/app/command-line-parser.cpp 2015-09-02 08:32:02 +0000
91+++ src/app/command-line-parser.cpp 1970-01-01 00:00:00 +0000
92@@ -1,134 +0,0 @@
93-/*
94- * Copyright (C) 2013 Canonical, Ltd.
95- *
96- * Authors:
97- * Nicolas d'Offay <nicolas.doffay@canonical.com>
98- *
99- * This program is free software; you can redistribute it and/or modify
100- * it under the terms of the GNU General Public License as published by
101- * the Free Software Foundation; version 3.
102- *
103- * This program is distributed in the hope that it will be useful,
104- * but WITHOUT ANY WARRANTY; without even the implied warranty of
105- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
106- * GNU General Public License for more details.
107- *
108- * You should have received a copy of the GNU General Public License
109- * along with this program. If not, see <http://www.gnu.org/licenses/>.
110- *
111- */
112-
113-#include "command-line-parser.h"
114-
115-#include "urlhandler.h"
116-
117-#include <QDebug>
118-#include <QDir>
119-#include <QStandardPaths>
120-#include <QTextStream>
121-#include <QUrl>
122-
123-CommandLineParser::CommandLineParser()
124- : m_pickMode(false),
125- m_isFullscreen(false),
126- m_testability(false),
127- m_documentFile(""),
128- m_documentsDir("")
129-{
130- m_urlHandler = new UrlHandler();
131-}
132-
133-/*!
134- * @brief CommandLineParser::processArguments parsers our input commandline args and sets attributes accordingly.
135- * @param QStringList of commandline args to parse and set attributes.
136- * @return false if invalid parameter is input or -h/--help is called.
137- */
138-bool CommandLineParser::processArguments(const QStringList& args)
139-{
140- bool valid_args = true;
141-
142- for (int i = 1; i < args.count(); ++i)
143- {
144- if (args[i] == "--help" || args[i] == "-h") {
145- usage();
146- return false;
147- }
148- else if (args[i] == "--fullscreen") {
149- m_isFullscreen = true;
150- }
151- else if (args[i] == "--pick-mode") {
152- m_pickMode = true;
153- }
154- else if (args[i] == "--testability") {
155- m_testability = true;
156- }
157- else if (args[i].contains("--documents-dir")) {
158- // Extract the given path
159- QString dirPath = args[i].split("--documents-dir=").last();
160-
161- if (!dirPath.isEmpty()) {
162- QDir di(dirPath);
163-
164- if (di.exists())
165- m_documentsDir = di.absolutePath();
166- else {
167- QTextStream(stderr) << m_documentsDir << ": Not found" << endl;
168- valid_args = false;
169- }
170-
171- i++;
172- }
173- else {
174- QTextStream(stderr) << "Missing PATH argument for --documents-dir'" << endl;
175- usage();
176- valid_args = false;
177- }
178- }
179- else {
180- if (args[i].startsWith("--desktop_file_hint")) {
181- // ignore this command line switch, hybris uses it to get application info
182- }
183- else if (!args.at(i).isEmpty()) {
184- QFileInfo fi(args.at(i));
185-
186- if (fi.exists()) {
187- m_documentFile = fi.absoluteFilePath();
188- }
189- else if (m_urlHandler->processUri(args.at(i))) {
190- m_documentFile = m_urlHandler->documentFile();
191- }
192- }
193- else {
194- valid_args = !invalidArg(args[i]);
195- }
196- }
197- }
198-
199- return valid_args;
200-}
201-
202-/*!
203- * @brief CommandLineParser::usage() prints out our form factors.
204- */
205-void CommandLineParser::usage()
206-{
207- QTextStream out(stdout);
208- out << "Usage: ubuntu-docviewer-app [options] [file_path]" << endl;
209- out << "Options:" << endl;
210- out << " --fullscreen\trun fullscreen" << endl;
211- out << " --pick-mode\t\tEnable mode to pick photos" << endl;
212- out << " file_path\t\tOpens ubuntu-docviewer-app displaying the selected file" << endl;
213- out << " --documents-dir=PATH\n\t\tLoad the list of documents from the given folder, instead of default ~/Documents.\nThe path must exist prior to running ubuntu-docviewer-app" << endl;
214-}
215-
216-/*!
217- * @brief CommandLineParser::invalidArg() if an invalid argument is contained in our QStringList.
218- * @return returns true.
219- */
220-bool CommandLineParser::invalidArg(QString arg)
221-{
222- QTextStream(stderr) << "Invalid argument '" << arg << "'" << endl;
223- usage();
224-
225- return true;
226-}
227
228=== removed file 'src/app/command-line-parser.h'
229--- src/app/command-line-parser.h 2015-04-29 15:23:32 +0000
230+++ src/app/command-line-parser.h 1970-01-01 00:00:00 +0000
231@@ -1,60 +0,0 @@
232-/*
233- * Copyright (C) 2013 Canonical, Ltd.
234- *
235- * Authors:
236- * Nicolas d'Offay <nicolas.doffay@canonical.com>
237- *
238- * This program is free software; you can redistribute it and/or modify
239- * it under the terms of the GNU General Public License as published by
240- * the Free Software Foundation; version 3.
241- *
242- * This program is distributed in the hope that it will be useful,
243- * but WITHOUT ANY WARRANTY; without even the implied warranty of
244- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
245- * GNU General Public License for more details.
246- *
247- * You should have received a copy of the GNU General Public License
248- * along with this program. If not, see <http://www.gnu.org/licenses/>.
249- *
250- */
251-
252-#ifndef COMMANDLINEPARSER_H
253-#define COMMANDLINEPARSER_H
254-
255-#include <QHash>
256-#include <QSize>
257-#include <QString>
258-
259-class UrlHandler;
260-
261-/*!
262- * @brief The CommandLineParser is used to parse our commandline inputs and set
263- * parameters accordingly.
264- */
265-class CommandLineParser
266-{
267-public:
268- CommandLineParser();
269-
270- bool processArguments(const QStringList& args);
271-
272- bool isFullscreen() const { return m_isFullscreen; }
273- const QString &documentsDir() const { return m_documentsDir; }
274- bool pickModeEnabled() const { return m_pickMode; }
275- bool testability() const { return m_testability; }
276- const QString &documentFile() const { return m_documentFile; }
277-
278-private:
279- bool invalidArg(QString arg);
280- void usage();
281-
282- UrlHandler *m_urlHandler;
283-
284- bool m_isFullscreen;
285- bool m_pickMode;
286- bool m_testability;
287- QString m_documentFile;
288- QString m_documentsDir;
289-};
290-
291-#endif // COMMANDLINEPARSER_H
292
293=== added file 'src/app/config.h.in'
294--- src/app/config.h.in 1970-01-01 00:00:00 +0000
295+++ src/app/config.h.in 2015-10-20 11:59:20 +0000
296@@ -0,0 +1,45 @@
297+/*
298+ * Copyright (C) 2013 Canonical Ltd.
299+ *
300+ * This program is free software; you can redistribute it and/or modify
301+ * it under the terms of the GNU General Public License as published by
302+ * the Free Software Foundation; version 3.
303+ *
304+ * This program is distributed in the hope that it will be useful,
305+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
306+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
307+ * GNU General Public License for more details.
308+ *
309+ * You should have received a copy of the GNU General Public License
310+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
311+ */
312+
313+#ifndef __CONFIG_H__
314+#define __CONFIG_H__
315+
316+#include <QtCore/QCoreApplication>
317+#include <QtCore/QDir>
318+#include <QtCore/QString>
319+
320+inline bool isClick() {
321+ static bool click = (QCoreApplication::applicationDirPath().contains("click.ubuntu.com"));
322+ return click;
323+}
324+
325+inline bool isRunningInstalled()
326+{
327+ static bool installed = (QCoreApplication::applicationDirPath().startsWith("/usr"));
328+ return installed;
329+}
330+
331+inline QString docviewerDirectory()
332+{
333+ if (isClick()) {
334+ return QString(".");
335+ } else if (isRunningInstalled()) {
336+ return QString("@CMAKE_INSTALL_PREFIX@/@DATA_DIR@");
337+ } else {
338+ return QString("@CMAKE_CURRENT_SOURCE_DIR@");
339+ }
340+}
341+#endif // __CONFIG_H__
342
343=== removed file 'src/app/docviewer-application.cpp'
344--- src/app/docviewer-application.cpp 2015-09-11 14:48:57 +0000
345+++ src/app/docviewer-application.cpp 1970-01-01 00:00:00 +0000
346@@ -1,245 +0,0 @@
347-/*
348- * Copyright (C) 2012 Canonical Ltd
349- *
350- * This program is free software: you can redistribute it and/or modify
351- * it under the terms of the GNU General Public License version 3 as
352- * published by the Free Software Foundation.
353- *
354- * This program is distributed in the hope that it will be useful,
355- * but WITHOUT ANY WARRANTY; without even the implied warranty of
356- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
357- * GNU General Public License for more details.
358- *
359- * You should have received a copy of the GNU General Public License
360- * along with this program. If not, see <http://www.gnu.org/licenses/>.
361- *
362- * Authors:
363- * Charles Lindsay <chaz@yorba.org>
364- */
365-
366-#include "docviewer-application.h"
367-#include "command-line-parser.h"
368-#include "urlhandler.h"
369-
370-#include <QQuickItem>
371-#include <QStandardPaths>
372-#include <QQuickView>
373-#include <QtQml/QtQml>
374-#include <QString>
375-#include <QUrl>
376-#include <QtGui/QGuiApplication>
377-
378-/*!
379- * \brief DocViewerApplication::DocViewerApplication
380- * \param argc
381- * \param argv
382- */
383-DocViewerApplication::DocViewerApplication(int& argc, char** argv)
384- : QApplication(argc, argv),
385- m_view(new QQuickView()),
386- m_documentFile(""),
387- m_documentLoaded(false)
388-{
389- //
390-}
391-
392-bool DocViewerApplication::init()
393-{
394- m_cmdLineParser = new CommandLineParser();
395-
396- if (!m_cmdLineParser->processArguments(arguments()))
397- return false;
398-
399- if (qgetenv("QT_LOAD_TESTABILITY") == "1" || m_cmdLineParser->testability()) {
400- QLibrary testLib(QLatin1String("qttestability"));
401- if (testLib.load()) {
402- typedef void (*TasInitialize)(void);
403- TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
404- if (initFunction) {
405- initFunction();
406- } else {
407- qCritical("Library qttestability resolve failed!");
408- }
409- } else {
410- qCritical("Library qttestability load failed!");
411- }
412- }
413-
414- m_urlHandler = new UrlHandler();
415-
416- registerQML();
417-
418- // FIXME: Broken after removal of it.
419- /*if (m_cmdLineParser->pickModeEnabled())
420- setDefaultUiMode(DocViewerApplication::PickContentMode);
421-*/
422- return true;
423-}
424-
425-/*!
426- * \brief DocViewerApplication::~DocViewerApplication
427- */
428-DocViewerApplication::~DocViewerApplication()
429-{
430- delete m_view;
431- delete m_cmdLineParser;
432-}
433-
434-/*!
435- * \brief DocViewerApplication::exec
436- * \return
437- */
438-int DocViewerApplication::exec()
439-{
440- createView();
441-
442- return QApplication::exec();
443-}
444-
445-/*!
446- * \brief DocViewerApplication::registerQML
447- */
448-void DocViewerApplication::registerQML()
449-{
450- // Set up import paths
451- QStringList importPathList = m_view->engine()->importPathList();
452-
453- // Prepend the location of the plugin in the build dir,
454- // so that Qt Creator finds it there, thus overriding the one installed
455- // in the sistem if there is one
456- importPathList.prepend(QCoreApplication::applicationDirPath() + "/../plugin/");
457- m_view->engine()->setImportPathList(importPathList);
458-}
459-
460-/*!
461- * \brief DocViewerApplication::isDesktopMode
462- * Returns true if the DESKTOP_MODE env var is set
463- */
464-bool DocViewerApplication::isDesktopMode() const
465-{
466-
467- // Assume that platformName (QtUbuntu) with ubuntu
468- // in name means it's running on device
469- // TODO: replace this check with SDK call for formfactor
470- QString platform = QGuiApplication::platformName();
471- return !((platform == "ubuntu") || (platform == "ubuntumirclient"));
472-}
473-
474-/*!
475- * \brief DocViewerApplication::isFullScreen
476- * Returns true if window is on FullScreen mode
477- */
478-bool DocViewerApplication::isFullScreen() const
479-{
480- return m_view->windowState() == Qt::WindowFullScreen;
481-}
482-
483-/*!
484- * \brief DocViewerApplication::getDocumentFile
485- * Returns the document file passed as a parameter
486- */
487-const QString& DocViewerApplication::getDocumentFile() const
488-{
489- return m_documentFile;
490-}
491-
492-/*!
493- * \brief DocViewerApplication::getDocumentsDir
494- * Returns the documents dir passed as a parameter
495- */
496-const QString& DocViewerApplication::getDocumentsDir() const
497-{
498- return m_cmdLineParser->documentsDir();
499-}
500-
501-
502-/*!
503- * \brief DocViewerApplication::createView
504- * Create the master QDeclarativeView that all the pages will operate within
505- */
506-void DocViewerApplication::createView()
507-{
508- m_view->setTitle(tr("Document Viewer"));
509-
510- // Set ourselves up to expose functionality to run external commands from QML...
511- m_view->engine()->rootContext()->setContextProperty("DOC_VIEWER", this);
512-
513- QObject::connect(m_view->engine(), SIGNAL(quit()), this, SLOT(quit()));
514-
515- QString qmlfile;
516- const QString filePath = QLatin1String("qml/ubuntu-docviewer-app.qml");
517- QStringList paths = QStandardPaths::standardLocations(QStandardPaths::DataLocation);
518- paths.prepend(QDir::currentPath());
519- paths.prepend(QCoreApplication::applicationDirPath());
520- Q_FOREACH (const QString &path, paths) {
521- QString myPath = path + QLatin1Char('/') + filePath;
522-
523- if (QFile::exists(myPath)) {
524- qmlfile = myPath;
525- break;
526- } else {
527- myPath.replace(QCoreApplication::applicationName(), "ubuntu-docviewer-app");
528-
529- if (QFile::exists(myPath)) {
530- qmlfile = myPath;
531- break;
532- }
533- }
534- }
535- // sanity check
536- if (qmlfile.isEmpty()) {
537- qFatal("File: %s does not exist at any of the standard paths!", qPrintable(filePath));
538- }
539-
540- m_view->setSource(QUrl::fromLocalFile(qmlfile));
541- setDocumentFile(m_cmdLineParser->documentFile());
542-
543- m_view->setResizeMode(QQuickView::SizeRootObjectToView);
544-
545- //run fullscreen if specified at command line
546- if (m_cmdLineParser->isFullscreen()) {
547- setFullScreen(true);
548- m_view->showFullScreen();
549- } else {
550- m_view->show();
551- }
552-}
553-
554-/*!
555- * \brief DocViewerApplication::setFullScreen
556- * Change window state to fullScreen or no state
557- */
558-void DocViewerApplication::setFullScreen(bool fullScreen)
559-{
560- if(fullScreen) {
561- m_view->setWindowState(Qt::WindowFullScreen);
562- } else {
563- m_view->setWindowState(Qt::WindowNoState);
564- }
565-
566- Q_EMIT fullScreenChanged();
567-}
568-
569-void DocViewerApplication::setDocumentFile(const QString &documentFile)
570-{
571- if(!documentFile.isEmpty()) {
572- if (m_documentFile != documentFile) {
573- m_documentFile = "file://" + documentFile;
574- Q_EMIT documentFileChanged();;
575- }
576- }
577-}
578-
579-void DocViewerApplication::parseUri(const QString &arg)
580-{
581- if (m_urlHandler->processUri(arg)) {
582- setDocumentFile(m_urlHandler->documentFile());
583- }
584-}
585-
586-void DocViewerApplication::releaseResources()
587-{
588- if (m_view) {
589- m_view->releaseResources();
590- }
591-}
592
593=== removed file 'src/app/docviewer-application.h'
594--- src/app/docviewer-application.h 2015-09-11 14:48:57 +0000
595+++ src/app/docviewer-application.h 1970-01-01 00:00:00 +0000
596@@ -1,80 +0,0 @@
597-/*
598- * Copyright (C) 2012 Canonical Ltd
599- *
600- * This program is free software: you can redistribute it and/or modify
601- * it under the terms of the GNU General Public License version 3 as
602- * published by the Free Software Foundation.
603- *
604- * This program is distributed in the hope that it will be useful,
605- * but WITHOUT ANY WARRANTY; without even the implied warranty of
606- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
607- * GNU General Public License for more details.
608- *
609- * You should have received a copy of the GNU General Public License
610- * along with this program. If not, see <http://www.gnu.org/licenses/>.
611- *
612- * Authors:
613- * Charles Lindsay <chaz@yorba.org>
614- */
615-
616-#ifndef DOCVIEWERAPPLICATION_H
617-#define DOCVIEWERAPPLICATION_H
618-
619-#include <QApplication>
620-#include <QElapsedTimer>
621-#include <QFileInfo>
622-#include <QTimer>
623-
624-class CommandLineParser;
625-class UrlHandler;
626-class ContentCommunicator;
627-
628-class QQuickView;
629-
630-/*!
631- * \brief The DocViewerApplication class
632- */
633-class DocViewerApplication : public QApplication
634-{
635- Q_OBJECT
636- Q_PROPERTY(bool desktopMode READ isDesktopMode CONSTANT)
637- Q_PROPERTY(bool fullScreen READ isFullScreen WRITE setFullScreen NOTIFY fullScreenChanged)
638- Q_PROPERTY(QString documentFile READ getDocumentFile WRITE setDocumentFile NOTIFY documentFileChanged)
639- Q_PROPERTY(QString documentsDir READ getDocumentsDir CONSTANT)
640-
641-public:
642- explicit DocViewerApplication(int& argc, char** argv);
643- virtual ~DocViewerApplication();
644-
645- bool init();
646- int exec();
647-
648- bool isDesktopMode() const;
649- bool isFullScreen() const;
650- const QString &getDocumentFile() const;
651- const QString &getDocumentsDir() const;
652-
653- Q_INVOKABLE void parseUri(const QString &arg);
654- Q_INVOKABLE void releaseResources();
655-
656-signals:
657- void fullScreenChanged();
658- void documentFileChanged();
659-
660-private slots:
661- void setFullScreen(bool fullScreen);
662- void setDocumentFile(const QString &documentFile);
663-
664-private:
665- void registerQML();
666- void createView();
667-
668- QQuickView *m_view;
669- CommandLineParser* m_cmdLineParser;
670- UrlHandler *m_urlHandler;
671-
672- QString m_documentFile;
673- bool m_documentLoaded;
674-};
675-
676-#endif // DOCVIEWERAPPLICATION_H
677
678=== modified file 'src/app/main.cpp'
679--- src/app/main.cpp 2015-09-14 18:59:09 +0000
680+++ src/app/main.cpp 2015-10-20 11:59:20 +0000
681@@ -1,37 +1,74 @@
682 /*
683- * Copyright: 2015 Canonical Ltd.
684- *
685- * This file is part of docviewer
686- *
687- * docviewer is free software: you can redistribute it and/or modify
688+ * Copyright (C) 2013-2015 Canonical Ltd.
689+ *
690+ * This program is free software; you can redistribute it and/or modify
691 * it under the terms of the GNU General Public License as published by
692- * the Free Software Foundation, either version 3 of the License, or
693- * (at your option) any later version.
694+ * the Free Software Foundation; version 3.
695 *
696- * reminders is distributed in the hope that it will be useful,
697+ * This program is distributed in the hope that it will be useful,
698 * but WITHOUT ANY WARRANTY; without even the implied warranty of
699 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
700 * GNU General Public License for more details.
701 *
702 * You should have received a copy of the GNU General Public License
703- * along with this program. If not, see <http://www.gnu.org/licenses/>.
704+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
705 */
706
707 // Uncomment if you need to use QML analyzer
708 // #define QT_QML_DEBUG
709 // #include <QtQuick>
710
711-#include "docviewer-application.h"
712+#include <QGuiApplication>
713+#include <QQuickView>
714+#include <QLibrary>
715+#include <QtQml>
716+
717 #include <QDebug>
718
719+#include "config.h"
720+
721+void loadTestability() {
722+ QLibrary testLib(QLatin1String("qttestability"));
723+
724+ if (testLib.load()) {
725+ typedef void (*TasInitialize)(void);
726+ TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
727+
728+ if (initFunction) {
729+ initFunction();
730+ } else {
731+ qCritical("Library qttestability resolve failed!");
732+ }
733+ } else {
734+ qCritical("Library qttestability load failed!");
735+ }
736+}
737+
738 int main(int argc, char *argv[])
739 {
740+ QGuiApplication app(argc, argv);
741+ QQuickView view;
742+
743 QCoreApplication::setApplicationName("com.ubuntu.docviewer");
744 QCoreApplication::setOrganizationDomain("com.ubuntu.docviewer");
745
746- DocViewerApplication app(argc, argv);
747- if (!app.init())
748- return 0;
749-
750- app.exec();
751+ view.rootContext()->setContextProperty("window", &view);
752+ QObject::connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));
753+
754+ if (qgetenv("QT_LOAD_TESTABILITY") == "1")
755+ loadTestability();
756+
757+ if (!isRunningInstalled())
758+ view.engine()->addImportPath(QCoreApplication::applicationDirPath() + "/../plugin/");
759+
760+ view.setSource(QUrl::fromLocalFile(docviewerDirectory() + "/qml/ubuntu-docviewer-app.qml"));
761+ view.setResizeMode(QQuickView::SizeRootObjectToView);
762+
763+ // UITK/QML command line arguments are parsed before view's window becomes visible.
764+ if (view.windowState() == Qt::WindowFullScreen)
765+ view.showFullScreen();
766+ else
767+ view.show();
768+
769+ return app.exec();
770 }
771
772=== added file 'src/app/qml/common/CommandLineProxy.qml'
773--- src/app/qml/common/CommandLineProxy.qml 1970-01-01 00:00:00 +0000
774+++ src/app/qml/common/CommandLineProxy.qml 2015-10-20 11:59:20 +0000
775@@ -0,0 +1,82 @@
776+/*
777+ * Copyright (C) 2015 Stefano Verzegnassi
778+ *
779+ * This program is free software; you can redistribute it and/or modify
780+ * it under the terms of the GNU General Public License as published by
781+ * the Free Software Foundation; version 3.
782+ *
783+ * This program is distributed in the hope that it will be useful,
784+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
785+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
786+ * GNU General Public License for more details.
787+ *
788+ * You should have received a copy of the GNU General Public License
789+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
790+ */
791+
792+import QtQuick 2.3
793+import Ubuntu.Components 1.1
794+
795+Item {
796+ id: rootItem
797+
798+ property string documentFile: ""
799+ property string documentsDir: ""
800+ property bool fullscreen: false
801+ property bool pickMode: false
802+
803+ Component.onCompleted: {
804+ var docFile = args.defaultArgument.at(0)
805+ if (docFile)
806+ rootItem.documentFile = docFile
807+
808+ var docsDir = args.values.documentsDir
809+ if (docsDir)
810+ rootItem.documentsDir = docsDir
811+
812+ var fullscreen = args.values.fullscreen
813+ if (fullscreen)
814+ rootItem.fullscreen = fullscreen
815+
816+ var pickMode = args.values.pickMode
817+ if (pickMode)
818+ rootItem.pickMode = pickMode
819+
820+ // Error catching
821+ // This does not include any argument which is not expected: they are
822+ // just skipped.
823+ if (args.error) {
824+ var errorString = i18n.tr("Some of the provided arguments is not valid.")
825+ args.quitWithError(errorString)
826+ }
827+ }
828+
829+ Arguments {
830+ id: args
831+
832+ defaultArgument {
833+ help: i18n.tr("Opens ubuntu-docviewer-app displaying the selected file")
834+ valueNames: ["file_path"]
835+ required: false
836+ }
837+
838+ Argument {
839+ name: "fullscreen"
840+ help: i18n.tr("Run fullscreen")
841+ required: false
842+ }
843+
844+ Argument {
845+ name: "pickMode"
846+ help: i18n.tr("Open ubuntu-docviewer-app in pick mode. Use it for tests only.")
847+ required: false
848+ }
849+
850+ Argument {
851+ name: "documentsDir"
852+ help: i18n.tr("Load the list of documents from the given folder, instead of default ~/Documents.\nThe path must exist prior to running ubuntu-docviewer-app")
853+ valueNames: ["PATH"]
854+ required: false
855+ }
856+ }
857+}
858
859=== modified file 'src/app/qml/pdfView/PdfView.qml'
860--- src/app/qml/pdfView/PdfView.qml 2015-04-15 14:47:28 +0000
861+++ src/app/qml/pdfView/PdfView.qml 2015-10-20 11:59:20 +0000
862@@ -58,7 +58,7 @@
863
864 model: poppler
865 delegate: PdfViewDelegate {
866- Component.onDestruction: DOC_VIEWER.releaseResources()
867+ Component.onDestruction: window.releaseResources()
868 }
869
870 // FIXME: On zooming, keep the same content position.
871@@ -78,7 +78,7 @@
872 // This is a bit expensive, so it's safer to put it here.
873 // It won't be called on desktop (where PinchArea is not used),
874 // but it's not a problem at the moment (our target is phone).
875- DOC_VIEWER.releaseResources();
876+ window.releaseResources();
877 }
878
879 MouseArea {
880
881=== modified file 'src/app/qml/ubuntu-docviewer-app.qml'
882--- src/app/qml/ubuntu-docviewer-app.qml 2015-10-05 20:53:25 +0000
883+++ src/app/qml/ubuntu-docviewer-app.qml 2015-10-20 11:59:20 +0000
884@@ -28,13 +28,13 @@
885 id: mainView
886 objectName: "mainView"
887
888- // TODO: Connect with arguments
889- property bool pickMode: false
890+ property bool pickMode: commandLineProxy.pickMode
891+ property bool fullscreen: commandLineProxy.fullscreen
892 readonly property bool isLandscape: Screen.orientation == Qt.LandscapeOrientation ||
893 Screen.orientation == Qt.InvertedLandscapeOrientation
894
895 applicationName: "com.ubuntu.docviewer"
896- useDeprecatedToolbar: false
897+ useDeprecatedToolbar: false
898 automaticOrientation: true
899
900 width: units.gu(150)
901@@ -67,12 +67,8 @@
902 mainView, { parent: mainView });
903 }
904
905- function setFullScreen(fullScreen) {
906- DOC_VIEWER.fullScreen = fullScreen;
907- }
908-
909 function toggleFullScreen() {
910- DOC_VIEWER.fullScreen = !DOC_VIEWER.fullScreen;
911+ mainView.fullscreen = !mainView.fullscreen
912 }
913
914 function setHeaderVisibility(visible, toggleFullscreen) {
915@@ -81,41 +77,43 @@
916
917 // If device orientation is landscape and screen width is limited,
918 // force hiding Unity 8 indicators panel.
919- if (!DOC_VIEWER.desktopMode && mainView.isLandscape &&
920+ if (!DocumentViewer.desktopMode && mainView.isLandscape &&
921 mainView.width < units.gu(51)) {
922- setFullScreen(true);
923+ mainView.fullscreen = true;
924 return;
925 }
926
927- if (!DOC_VIEWER.desktopMode && toggleFullscreen)
928- setFullScreen(!visible);
929+ if (!DocumentViewer.desktopMode && toggleFullscreen)
930+ mainView.fullscreen = !visible;
931 }
932
933 function toggleHeaderVisibility() {
934 setHeaderVisibility(!header.visible);
935 }
936
937- function setPickMode(pickMode) {
938- mainView.pickMode = pickMode
939- }
940-
941 function switchToBrowseMode() {
942- setPickMode(false)
943+ mainView.pickMode = false
944 }
945
946 function switchToPickMode() {
947- setPickMode(true)
948+ mainView.pickMode = true
949 }
950
951-
952 // On screen rotation, force updating of header/U8 indicators panel visibility
953 onIsLandscapeChanged: setHeaderVisibility(true);
954
955+ onFullscreenChanged: {
956+ if (mainView.fullscreen)
957+ window.visibility = Window.FullScreen
958+ else
959+ window.visibility = Window.Windowed
960+ }
961+
962 Component.onCompleted: {
963 pageStack.push(Qt.resolvedUrl("documentPage/DocumentPage.qml"));
964
965 // Open the document, if one has been specified.
966- openDocument(DOC_VIEWER.documentFile);
967+ openDocument(commandLineProxy.documentFile);
968 }
969
970 File {
971@@ -142,7 +140,7 @@
972 id: docModel
973
974 // Used for autopilot tests! If customDir is empty, this property is not used.
975- customDir: DOC_VIEWER.documentsDir
976+ customDir: commandLineProxy.documentsDir
977 }
978
979 sort.property: {
980@@ -183,6 +181,11 @@
981 property bool reverseOrder: false
982 }
983
984+ // CommandLine parser
985+ CommandLineProxy {
986+ id: commandLineProxy
987+ }
988+
989 // Content Hub support
990 property alias contentHubProxy: contentHubLoader.item
991 Loader {
992@@ -195,19 +198,7 @@
993 // Uri Handler support
994 Connections {
995 target: UriHandler
996- onOpened: {
997- for (var i = 0; i < uris.length; ++i) {
998- DOC_VIEWER.parseUri(uris[i])
999- }
1000- }
1001- }
1002-
1003- Connections {
1004- target: DOC_VIEWER
1005-
1006- onDocumentFileChanged: {
1007- openDocument(DOC_VIEWER.documentFile);
1008- }
1009+ onOpened: openDocument(uris[0])
1010 }
1011
1012 onPickModeChanged: {
1013
1014=== removed file 'src/app/urlhandler.cpp'
1015--- src/app/urlhandler.cpp 2015-02-13 15:30:01 +0000
1016+++ src/app/urlhandler.cpp 1970-01-01 00:00:00 +0000
1017@@ -1,70 +0,0 @@
1018-/*
1019- * Copyright (C) 2014 Canonical, Ltd.
1020- *
1021- * Authors:
1022- * Arthur Mello <arthur.mello@canonical.com>
1023- *
1024- * This program is free software; you can redistribute it and/or modify
1025- * it under the terms of the GNU General Public License as published by
1026- * the Free Software Foundation; version 3.
1027- *
1028- * This program is distributed in the hope that it will be useful,
1029- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1030- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1031- * GNU General Public License for more details.
1032- *
1033- * You should have received a copy of the GNU General Public License
1034- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1035- *
1036- */
1037-
1038-#include "urlhandler.h"
1039-
1040-#include <QUrl>
1041-#include <QStringList>
1042-#include <QFileInfo>
1043-#include <QDir>
1044-#include <QDebug>
1045-
1046-UrlHandler::UrlHandler()
1047- : m_documentFile("")
1048-{
1049- m_validSchemes << "document";
1050-}
1051-
1052-/*!
1053- * @brief UrlHandler::processUri parsers our input uri and sets attributes accordingly.
1054- * @param QString uri to parse and set attributes.
1055- * @return false if invalid parameter is input.
1056- */
1057-bool UrlHandler::processUri(const QString& arg)
1058-{
1059- QUrl uri(arg);
1060-
1061- if (!m_validSchemes.contains(uri.scheme())) {
1062- return false;
1063- }
1064-
1065- if (uri.scheme() == "document") {
1066- uri.setScheme("file");
1067- }
1068-
1069- if (uri.isRelative()) {
1070- uri = QUrl::fromLocalFile(QDir::current().absoluteFilePath(arg));
1071- }
1072-
1073- // Check if it's a local file
1074- if (uri.isValid() && uri.isLocalFile()) {
1075- QFileInfo info(uri.toLocalFile());
1076- if (info.exists() && info.isFile()) {
1077- m_documentFile = info.absoluteFilePath();
1078- return true;
1079- } else {
1080- qWarning() << "File not found:" << uri << info.exists() << info.isFile();
1081- }
1082- } else {
1083- qWarning() << "Invalid uri:" << uri;
1084- }
1085-
1086- return false;
1087-}
1088
1089=== removed file 'src/app/urlhandler.h'
1090--- src/app/urlhandler.h 2015-02-13 15:30:01 +0000
1091+++ src/app/urlhandler.h 1970-01-01 00:00:00 +0000
1092@@ -1,43 +0,0 @@
1093-/*
1094- * Copyright (C) 2014 Canonical, Ltd.
1095- *
1096- * Authors:
1097- * Arthur Mello <arthur.mello@canonical.com>
1098- *
1099- * This program is free software; you can redistribute it and/or modify
1100- * it under the terms of the GNU General Public License as published by
1101- * the Free Software Foundation; version 3.
1102- *
1103- * This program is distributed in the hope that it will be useful,
1104- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1105- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1106- * GNU General Public License for more details.
1107- *
1108- * You should have received a copy of the GNU General Public License
1109- * along with this program. If not, see <http://www.gnu.org/licenses/>.
1110- *
1111- */
1112-
1113-#ifndef URLHANDLER_H
1114-#define URLHANDLER_H
1115-
1116-#include <QString>
1117-#include <QList>
1118-
1119-/*!
1120- * @brief The UrlHandler is used to parse calls of docviewer from the url schema.
1121- */
1122-class UrlHandler
1123-{
1124-public:
1125- UrlHandler();
1126-
1127- bool processUri(const QString &arg);
1128- const QString &documentFile() { return m_documentFile; }
1129-
1130-private:
1131- QList<QString> m_validSchemes;
1132- QString m_documentFile;
1133-};
1134-
1135-#endif // URLHANDLER_H
1136
1137=== modified file 'src/plugin/file-qml-plugin/docviewerutils.cpp'
1138--- src/plugin/file-qml-plugin/docviewerutils.cpp 2015-09-21 11:31:20 +0000
1139+++ src/plugin/file-qml-plugin/docviewerutils.cpp 2015-10-20 11:59:20 +0000
1140@@ -22,6 +22,16 @@
1141 #include <QStandardPaths>
1142 #include <QDirIterator>
1143 #include <QDateTime>
1144+#include <QtGui/QGuiApplication>
1145+
1146+bool DocviewerUtils::desktopMode() const
1147+{
1148+ // Assume that platformName (QtUbuntu) with ubuntu
1149+ // in name means it's running on device
1150+ // TODO: replace this check with SDK call for formfactor
1151+ QString platform = QGuiApplication::platformName();
1152+ return !((platform == "ubuntu") || (platform == "ubuntumirclient"));
1153+}
1154
1155 bool DocviewerUtils::exists(const QString &path)
1156 {
1157
1158=== modified file 'src/plugin/file-qml-plugin/docviewerutils.h'
1159--- src/plugin/file-qml-plugin/docviewerutils.h 2015-09-21 11:15:29 +0000
1160+++ src/plugin/file-qml-plugin/docviewerutils.h 2015-10-20 11:59:20 +0000
1161@@ -23,8 +23,11 @@
1162 class DocviewerUtils : public QObject
1163 {
1164 Q_OBJECT
1165+ Q_PROPERTY(bool desktopMode READ desktopMode CONSTANT)
1166
1167 public:
1168+ bool desktopMode() const;
1169+
1170 Q_INVOKABLE static bool exists(const QString &path);
1171 Q_INVOKABLE static bool copy(const QString &source, const QString &destination);
1172

Subscribers

People subscribed via source and target branches