Merge lp:~fcole90/ubuntu-docviewer-app/include-file-plugin into lp:ubuntu-docviewer-app/trunk

Proposed by David Planella
Status: Superseded
Proposed branch: lp:~fcole90/ubuntu-docviewer-app/include-file-plugin
Merge into: lp:ubuntu-docviewer-app/trunk
Diff against target: 496 lines (+434/-0)
11 files modified
CMakeLists.txt (+2/-0)
plugins/CMakeLists.txt (+1/-0)
plugins/file-qml-plugin/CMakeLists.txt (+45/-0)
plugins/file-qml-plugin/backend.cpp (+22/-0)
plugins/file-qml-plugin/backend.h (+43/-0)
plugins/file-qml-plugin/docviewerFile.cpp (+105/-0)
plugins/file-qml-plugin/docviewerFile.h (+56/-0)
plugins/file-qml-plugin/fileReader.cpp (+82/-0)
plugins/file-qml-plugin/fileReader.h (+39/-0)
plugins/file-qml-plugin/main.pro (+38/-0)
plugins/file-qml-plugin/qmldir (+1/-0)
To merge this branch: bzr merge lp:~fcole90/ubuntu-docviewer-app/include-file-plugin
Reviewer Review Type Date Requested Status
Ubuntu Document Viewer Developers Pending
Review via email: mp+237543@code.launchpad.net

This proposal has been superseded by a proposal from 2014-10-08.

Commit message

Adds the file plugin to the source tree.

Description of the change

Adds the file plugin to the source tree.

Note: while developing, to run the app on the desktop, or on any device, it requires an argument. The only way to pass that argument is by adding it as parameter to the .desktop(.in.in) file's Exec key. E.g., here's how I run it on my desktop:

Exec=@EXEC@ /home/dpm/docviewer.txt

In the future, we will want to improve this, so that the app can be launched standalone. A workaround for now would be to ship a README.txt file that is loaded by default if no argument has been specified.

Note: autopilot tests still need to be adapted. I'll do that in this same merge proposal. In the meantime, the code changes in cmake and app+plugin can already be reviewed.

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-09-24 09:46:30 +0000
3+++ CMakeLists.txt 2014-10-08 07:04:22 +0000
4@@ -19,6 +19,8 @@
5 set(UBUNTU_MANIFEST_PATH "manifest.json.in" CACHE INTERNAL "Relative path to the manifest file")
6
7 if(CLICK_MODE)
8+ #adds the plugins dir only if building a click package
9+ add_subdirectory(plugins)
10 if(NOT DEFINED BZR_SOURCE)
11 set(BZR_SOURCE "lp:ubuntu-${APP_HARDCODE}")
12 message("-- Setting BZR_SOURCE to ${BZR_SOURCE}")
13
14=== added directory 'plugins'
15=== added file 'plugins/CMakeLists.txt'
16--- plugins/CMakeLists.txt 1970-01-01 00:00:00 +0000
17+++ plugins/CMakeLists.txt 2014-10-08 07:04:22 +0000
18@@ -0,0 +1,1 @@
19+add_subdirectory(file-qml-plugin)
20
21=== added directory 'plugins/file-qml-plugin'
22=== added file 'plugins/file-qml-plugin/CMakeLists.txt'
23--- plugins/file-qml-plugin/CMakeLists.txt 1970-01-01 00:00:00 +0000
24+++ plugins/file-qml-plugin/CMakeLists.txt 2014-10-08 07:04:22 +0000
25@@ -0,0 +1,45 @@
26+cmake_minimum_required(VERSION 2.8.9)
27+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
28+
29+#set cpp flags
30+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra -fPIC")
31+
32+# Standard install paths
33+include(GNUInstallDirs)
34+
35+#add the sources to compile
36+set(FILE_QML_PLUGIN_SOURCES
37+ backend.cpp
38+ backend.h
39+ docviewerFile.cpp
40+ docviewerFile.h
41+ fileReader.cpp
42+ fileReader.h
43+ )
44+
45+#should be deprecated in current cmake version
46+#qt5_use_modules(Qml Quick)
47+
48+if(CLICK_MODE)
49+ #none
50+else(CLICK_MODE)
51+ #creates QT_IMPORTS_DIR and olds the qml plugin path
52+ execute_process(
53+ COMMAND qmake -query QT_INSTALL_QML
54+ OUTPUT_VARIABLE QT_IMPORTS_DIR
55+ OUTPUT_STRIP_TRAILING_WHITESPACE
56+ )
57+endif(CLICK_MODE)
58+
59+
60+# Copy qmldir file to build dir for running in QtCreator
61+if(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
62+add_custom_target(file-qml-plugin ALL
63+ COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/qmldir ${CMAKE_CURRENT_BINARY_DIR}
64+ DEPENDS ${QMLFILES}
65+)
66+endif(NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
67+
68+# Install plugin file under org.docviewer.file
69+install(TARGETS file-qml-plugin DESTINATION ${QT_IMPORTS_DIR}/org.docviewer.file/)
70+install(FILES qmldir DESTINATION ${QT_IMPORTS_DIR}/org.docviewer.file/)
71
72=== added file 'plugins/file-qml-plugin/backend.cpp'
73--- plugins/file-qml-plugin/backend.cpp 1970-01-01 00:00:00 +0000
74+++ plugins/file-qml-plugin/backend.cpp 2014-10-08 07:04:22 +0000
75@@ -0,0 +1,22 @@
76+#include <QtQml>
77+#include <QtQml/QQmlContext>
78+
79+#include "backend.h"
80+#include "docviewerFile.h"
81+#include "fileReader.h"
82+
83+void BackendPlugin::registerTypes(const char *uri)
84+{
85+ Q_ASSERT(uri == QLatin1String("org.docviewer.file"));
86+
87+ //@uri org.docviewer.file
88+
89+ qmlRegisterType<DocviewerFile>(uri, 1, 0, "File");
90+ qmlRegisterType<FileReader>(uri, 1, 0, "FileReader");
91+
92+}
93+
94+void BackendPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
95+{
96+ QQmlExtensionPlugin::initializeEngine(engine, uri);
97+}
98
99=== added file 'plugins/file-qml-plugin/backend.h'
100--- plugins/file-qml-plugin/backend.h 1970-01-01 00:00:00 +0000
101+++ plugins/file-qml-plugin/backend.h 2014-10-08 07:04:22 +0000
102@@ -0,0 +1,43 @@
103+#ifndef BACKEND_PLUGIN_H
104+#define BACKEND_PLUGIN_H
105+
106+#include <QtQml/QQmlEngine>
107+#include <QtQml/QQmlExtensionPlugin>
108+
109+/*
110+ ----8<-----
111+
112+ import org.docviewer.file 1.0
113+
114+ Rectangle {
115+ width: 200
116+ height: 200
117+
118+ File {
119+ id: file
120+ path: the/path/of/file
121+
122+ onMimetypeChanged: {
123+ do.something(mimetype);
124+ }
125+ }
126+
127+ Text {
128+ anchors.centerIn: parent
129+ text: helloType.helloworld
130+ }
131+ }
132+
133+ -----8<------
134+*/
135+class BackendPlugin : public QQmlExtensionPlugin
136+{
137+ Q_OBJECT
138+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
139+
140+public:
141+ void registerTypes(const char *uri);
142+ void initializeEngine(QQmlEngine *engine, const char *uri);
143+};
144+#endif // BACKEND_PLUGIN_H
145+
146
147=== added file 'plugins/file-qml-plugin/docviewerFile.cpp'
148--- plugins/file-qml-plugin/docviewerFile.cpp 1970-01-01 00:00:00 +0000
149+++ plugins/file-qml-plugin/docviewerFile.cpp 2014-10-08 07:04:22 +0000
150@@ -0,0 +1,105 @@
151+#include <QProcess>
152+#include <QObject>
153+#include <QDebug>
154+#include <QFileInfo>
155+
156+#include "docviewerFile.h"
157+
158+/*
159+ ----8<-----
160+
161+ import org.docviewer.file 1.0
162+
163+ Rectangle {
164+ width: 200
165+ height: 200
166+
167+ File {
168+ id: file
169+ path: "the/path/of/file"
170+
171+ onMimetypeChanged: {
172+ do.something(mimetype);
173+ }
174+ }
175+
176+ Text {
177+ anchors.centerIn: parent
178+ text: helloType.helloworld
179+ }
180+ }
181+
182+ -----8<------
183+*/
184+
185+DocviewerFile::DocviewerFile(QObject *parent) :
186+ QObject(parent),
187+ path("")
188+{
189+}
190+DocviewerFile::~DocviewerFile() {
191+
192+}
193+
194+void DocviewerFile::setPath(QString p) {
195+ if (p.isEmpty()) {
196+ this->path = "";
197+ }
198+ else {
199+ this->path = p;
200+ }
201+
202+ this->open();
203+
204+ emit pathChanged();
205+}
206+
207+void DocviewerFile::open() {
208+ if (!path.isEmpty())
209+ {
210+ QFileInfo file(path);
211+
212+ if (file.exists()) {
213+
214+ /**Get info of the file**/
215+ size = file.size();
216+ emit sizeChanged();
217+
218+ lastmodified = file.lastModified();
219+ emit lastmodifiedChanged();
220+
221+ /**Get mimetype**/
222+ QStringList mimeTypeCommand;
223+ mimeTypeCommand << "-ib" << path;
224+
225+ mimeTypeProcess = new QProcess();
226+
227+ this->connect(mimeTypeProcess, SIGNAL(readyReadStandardOutput()), SLOT(s_readMimeType()));
228+ this->connect(mimeTypeProcess, SIGNAL(finished(int)), SLOT(s_finished(int)));
229+
230+ mimeTypeProcess->start("file", mimeTypeCommand);
231+
232+ }
233+ else {
234+ error = -1;
235+ emit errorChanged();
236+ }
237+ }
238+
239+
240+}
241+
242+/****SLOT****/
243+
244+void DocviewerFile::s_readMimeType()
245+{
246+ mimetype = mimeTypeProcess->readAllStandardOutput();
247+ mimetype = mimetype.left(mimetype.size()-1);
248+}
249+
250+void DocviewerFile::s_finished(int exitCode)
251+{
252+ if (exitCode != 0)
253+ mimetype = "Unknow";
254+ emit mimetypeChanged();
255+}
256
257=== added file 'plugins/file-qml-plugin/docviewerFile.h'
258--- plugins/file-qml-plugin/docviewerFile.h 1970-01-01 00:00:00 +0000
259+++ plugins/file-qml-plugin/docviewerFile.h 2014-10-08 07:04:22 +0000
260@@ -0,0 +1,56 @@
261+#ifndef DOCVIEWERFILE_H
262+#define DOCVIEWERFILE_H
263+
264+#include <QString>
265+#include <QObject>
266+#include <QProcess>
267+#include <QDateTime>
268+
269+class DocviewerFile : public QObject
270+{
271+ Q_OBJECT
272+ Q_PROPERTY( QString path READ getPath WRITE setPath NOTIFY pathChanged )
273+ Q_PROPERTY( QString mimetype READ getMimetype NOTIFY mimetypeChanged )
274+ Q_PROPERTY( qint64 size READ getSize NOTIFY sizeChanged )
275+ Q_PROPERTY( QDateTime lastModified READ getLastmodified NOTIFY lastmodifiedChanged )
276+ Q_PROPERTY( int error READ getError NOTIFY errorChanged )
277+
278+public:
279+ explicit DocviewerFile(QObject *parent = 0);
280+ ~DocviewerFile();
281+
282+protected:
283+ QString getPath() { return path; }
284+ void setPath(QString p);
285+
286+ QString getMimetype() { return mimetype; }
287+
288+ qint64 getSize() { return size; }
289+
290+ QDateTime getLastmodified() { return lastmodified; }
291+
292+ int getError() { return error; }
293+
294+ QString path;
295+ QString mimetype;
296+ qint64 size;
297+ QDateTime lastmodified;
298+ int error;
299+
300+private:
301+ void open();
302+ QProcess *mimeTypeProcess;
303+
304+public slots:
305+ void s_readMimeType();
306+ void s_finished(int exitCode);
307+
308+Q_SIGNALS:
309+ void pathChanged();
310+ void mimetypeChanged();
311+ void sizeChanged();
312+ void lastmodifiedChanged();
313+ void errorChanged();
314+};
315+
316+#endif // DOCVIEWERFILE_H
317
318=== added file 'plugins/file-qml-plugin/fileReader.cpp'
319--- plugins/file-qml-plugin/fileReader.cpp 1970-01-01 00:00:00 +0000
320+++ plugins/file-qml-plugin/fileReader.cpp 2014-10-08 07:04:22 +0000
321@@ -0,0 +1,82 @@
322+#include <QFile>
323+#include <QObject>
324+#include <QDebug>
325+#include <QTextStream>
326+
327+#include "fileReader.h"
328+
329+/*
330+ ----8<-----
331+
332+ import org.docviewer.file 1.0
333+
334+ Rectangle {
335+ width: 200
336+ height: 200
337+
338+ FileReader {
339+ id: readFile
340+ path: "/path/of/file"
341+ }
342+
343+ Text {
344+ anchors.centerIn: parent
345+ text: readFile.fileString
346+ }
347+ }
348+
349+ -----8<------
350+*/
351+
352+FileReader::FileReader(QObject *parent) :
353+ QObject(parent),
354+ path("")
355+{
356+
357+}
358+
359+FileReader::~FileReader() {
360+
361+}
362+
363+void FileReader::setPath(QString p) {
364+ if (p.isEmpty())
365+ {
366+ this->path = "";
367+ }
368+ else
369+ {
370+ this->path = p;
371+ }
372+
373+ this->readString();
374+
375+ emit pathChanged();
376+}
377+
378+void FileReader::readString() {
379+ if (!path.isEmpty()) {
380+
381+ QFile mfile(path);
382+
383+ if (!mfile.open(QFile::ReadOnly | QFile::Text))
384+ {
385+ qDebug() << "Could not open file for reading";
386+ error = -1;
387+ emit errorChanged();
388+ return;
389+ }
390+
391+ QTextStream in(&mfile);
392+ fileString = in.readAll();
393+ emit fileStringChanged();
394+
395+ mfile.flush();
396+ mfile.close();
397+ }
398+ else
399+ {
400+ error = -1;
401+ emit errorChanged();
402+ }
403+}
404
405=== added file 'plugins/file-qml-plugin/fileReader.h'
406--- plugins/file-qml-plugin/fileReader.h 1970-01-01 00:00:00 +0000
407+++ plugins/file-qml-plugin/fileReader.h 2014-10-08 07:04:22 +0000
408@@ -0,0 +1,39 @@
409+#ifndef FILEREADER_H
410+#define FILEREADER_H
411+
412+#include <QObject>
413+#include <QString>
414+
415+class FileReader: public QObject
416+{
417+ Q_OBJECT
418+ Q_PROPERTY(QString path READ getPath WRITE setPath NOTIFY pathChanged)
419+ Q_PROPERTY(QString fileString READ getfileString NOTIFY fileStringChanged)
420+ Q_PROPERTY(int error READ getError NOTIFY errorChanged)
421+
422+public:
423+ explicit FileReader(QObject *parent = 0);
424+ ~FileReader();
425+
426+protected:
427+ QString getPath() { return path; }
428+ void setPath(QString p);
429+
430+ QString getfileString() { return fileString; }
431+
432+ int getError() { return error; }
433+
434+ QString path;
435+ QString fileString;
436+ int error;
437+
438+private:
439+ void readString();
440+
441+Q_SIGNALS:
442+ void pathChanged();
443+ void fileStringChanged();
444+ void errorChanged();
445+};
446+
447+#endif // FILEREADER_H
448
449=== added file 'plugins/file-qml-plugin/main.pro'
450--- plugins/file-qml-plugin/main.pro 1970-01-01 00:00:00 +0000
451+++ plugins/file-qml-plugin/main.pro 2014-10-08 07:04:22 +0000
452@@ -0,0 +1,38 @@
453+TEMPLATE = lib
454+TARGET = filePlugin
455+QT += qml quick
456+CONFIG += qt plugin
457+
458+#comment in the following line to disable traces
459+DEFINES += QT_NO_DEBUG_OUTPUT
460+
461+TARGET = $$qtLibraryTarget($$TARGET)
462+uri = org.docviewer.file
463+
464+INCLUDEPATH += .
465+
466+# Input
467+HEADERS += backend.h \
468+ docviewerFile.h \
469+ fileReader.h
470+SOURCES += backend.cpp \
471+ docviewerFile.cpp \
472+ fileReader.cpp
473+
474+# Install path for the plugin
475+installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
476+target.path = $$installPath
477+INSTALLS += target
478+
479+# find files
480+QMLDIR_FILE = qmldir
481+
482+# make visible to qt creator
483+OTHER_FILES += $$QMLDIR_FILE
484+
485+# create install targets for files
486+qmldir.path = $$installPath
487+qmldir.files = $$QMLDIR_FILE
488+
489+INSTALLS += qmldir
490+
491
492=== added file 'plugins/file-qml-plugin/qmldir'
493--- plugins/file-qml-plugin/qmldir 1970-01-01 00:00:00 +0000
494+++ plugins/file-qml-plugin/qmldir 2014-10-08 07:04:22 +0000
495@@ -0,0 +1,1 @@
496+plugin filePlugin

Subscribers

People subscribed via source and target branches