Merge lp:~verzegnassi-stefano/ubuntu-docviewer-app/fix-1387651-1387023 into lp:ubuntu-docviewer-app/trunk

Proposed by Stefano Verzegnassi
Status: Merged
Approved by: David Planella
Approved revision: 41
Merged at revision: 38
Proposed branch: lp:~verzegnassi-stefano/ubuntu-docviewer-app/fix-1387651-1387023
Merge into: lp:ubuntu-docviewer-app/trunk
Diff against target: 232 lines (+42/-50)
7 files modified
manifest.json.in (+1/-1)
src/app/qml/PdfView.qml (+12/-4)
src/app/qml/loadComponent.js (+0/-10)
src/app/qml/ubuntu-docviewer-app.qml (+0/-1)
src/plugin/file-qml-plugin/docviewerFile.cpp (+21/-26)
src/plugin/file-qml-plugin/docviewerFile.h (+6/-5)
src/plugin/poppler-qml-plugin/pdfModel.cpp (+2/-3)
To merge this branch: bzr merge lp:~verzegnassi-stefano/ubuntu-docviewer-app/fix-1387651-1387023
Reviewer Review Type Date Requested Status
David Planella Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+240304@code.launchpad.net

Commit message

* Fixed a problem with AppArmor while trying to get mime type for a file with QProcess and /usr/bin/file. (lp:1387651)
* Added creation date property in file-qml-plugin (lp:1387023)
* Workaround for an issue in poppler-qml-plugin (PDF pages were loaded twice)
* Now 'architecture' field value in manifest.json.in is set by CMake while building the project.

Description of the change

Fixed a problem with AppArmor while trying to get mime type for a file with QProcess and /usr/bin/file. Now we use QMineType instead. (lp:1387651)

Added creation date property in file-qml-plugin, so that we don't have an empty field in Details page (lp:1387023)

Workaround for an issue in poppler-qml-plugin (PDF pages were loaded twice)

Now 'architecture' field value in manifest.json.in is set by CMake while building the project (I used 3 revisions to do that, because QtCreator/Ubuntu-SDK decided to overwrite the file with its own values)

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
David Planella (dpm) wrote :

Works as expected, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'manifest.json.in'
2--- manifest.json.in 2014-09-24 05:06:10 +0000
3+++ manifest.json.in 2014-10-31 16:43:26 +0000
4@@ -1,7 +1,7 @@
5 {
6 "description": "Document Viewer application for Ubuntu devices",
7 "framework": "ubuntu-sdk-14.10-qml-dev3",
8- "architecture": "all",
9+ "architecture": "@CLICK_ARCH@",
10 "hooks": {
11 "docviewer": {
12 "apparmor": "docviewer.apparmor",
13
14=== modified file 'src/app/qml/PdfView.qml'
15--- src/app/qml/PdfView.qml 2014-10-28 22:10:16 +0000
16+++ src/app/qml/PdfView.qml 2014-10-31 16:43:26 +0000
17@@ -16,10 +16,10 @@
18 id: pdfView
19 anchors {
20 fill: parent
21- leftMargin: units.gu(2)
22- rightMargin: units.gu(2)
23+ leftMargin: units.gu(1)
24+ rightMargin: units.gu(1)
25 }
26- spacing: units.gu(4)
27+ spacing: units.gu(2)
28
29 clip: true
30 focus: false
31@@ -43,7 +43,15 @@
32
33 model: Poppler {
34 id: poppler
35- path: file.path
36+
37+ /* FIXME: Don't set 'path' property directly, but set it through onCompleted signal.
38+ By doing otherwise, PDF pages are loaded two times, but only
39+ the first delegates are working. Asking to the image provider
40+ to get the second ones makes the app instable.
41+ (e.g. We have a PDF document with 10 pages. The plugin loads
42+ them twice - 2x10 = 20 pages - but only the first 10 are shown.
43+ While trying to get the 11th, the app crashes). */
44+ Component.onCompleted: path = file.path
45
46 onPagesLoaded: {
47 activity.running = false;
48
49=== modified file 'src/app/qml/loadComponent.js'
50--- src/app/qml/loadComponent.js 2014-10-20 20:31:41 +0000
51+++ src/app/qml/loadComponent.js 2014-10-31 16:43:26 +0000
52@@ -1,14 +1,4 @@
53-function getSimpleMimetype(longMimetype)
54-{
55- var str = longMimetype;
56- str = str.substring(0, str.indexOf(";"));
57- return str;
58-}
59-
60 function load(mimetype) {
61- if (mimetype.indexOf(";") !== -1)
62- mimetype = getSimpleMimetype(mimetype);
63-
64 var qmlToLoad = "";
65
66 // Open all text files in text editor
67
68=== modified file 'src/app/qml/ubuntu-docviewer-app.qml'
69--- src/app/qml/ubuntu-docviewer-app.qml 2014-10-28 22:01:16 +0000
70+++ src/app/qml/ubuntu-docviewer-app.qml 2014-10-31 16:43:26 +0000
71@@ -1,7 +1,6 @@
72 import QtQuick 2.3
73 import Ubuntu.Components 1.1
74 import Ubuntu.Components.Popups 1.0
75-import Ubuntu.Components.ListItems 1.0 as ListItem
76 import com.ubuntu.fileqmlplugin 1.0
77
78 import "loadComponent.js" as LoadComponent
79
80=== modified file 'src/plugin/file-qml-plugin/docviewerFile.cpp'
81--- src/plugin/file-qml-plugin/docviewerFile.cpp 2014-10-20 18:45:09 +0000
82+++ src/plugin/file-qml-plugin/docviewerFile.cpp 2014-10-31 16:43:26 +0000
83@@ -1,8 +1,8 @@
84-#include <QProcess>
85 #include <QObject>
86 #include <QDebug>
87 #include <QFileInfo>
88 #include <QDir>
89+#include <QMimeDatabase>
90
91 #include "docviewerFile.h"
92
93@@ -50,6 +50,8 @@
94 this->path = QFileInfo(QDir::currentPath(), p).absoluteFilePath();
95 }
96
97+ qDebug() << "[FILE] Path parsed as:" << this->path;
98+
99 this->open();
100
101 emit pathChanged();
102@@ -61,6 +63,7 @@
103 QFileInfo file(path);
104
105 if (file.exists()) {
106+ qDebug() << "[FILE] Extracting informations from the file...";
107
108 /**Get info of the file**/
109 size = file.size();
110@@ -69,38 +72,30 @@
111 lastmodified = file.lastModified();
112 emit lastmodifiedChanged();
113
114+ creationTime = file.created();
115+ emit creationTimeChanged();
116+
117 /**Get mimetype**/
118- QStringList mimeTypeCommand;
119- mimeTypeCommand << "-ib" << path;
120-
121- mimeTypeProcess = new QProcess();
122-
123- this->connect(mimeTypeProcess, SIGNAL(readyReadStandardOutput()), SLOT(s_readMimeType()));
124- this->connect(mimeTypeProcess, SIGNAL(finished(int)), SLOT(s_finished(int)));
125-
126- mimeTypeProcess->start("file", mimeTypeCommand);
127-
128+ this->readMimeType();
129 }
130 else {
131+ qDebug() << "[FILE] ERROR: Requested file does not exist!";
132 error = -1;
133 emit errorChanged();
134 }
135 }
136-
137-
138-}
139-
140-/****SLOT****/
141-
142-void DocviewerFile::s_readMimeType()
143-{
144- mimetype = mimeTypeProcess->readAllStandardOutput();
145- mimetype = mimetype.left(mimetype.size()-1);
146-}
147-
148-void DocviewerFile::s_finished(int exitCode)
149-{
150- if (exitCode != 0)
151+}
152+
153+void DocviewerFile::readMimeType()
154+{
155+ QMimeDatabase db;
156+ mimetype = db.mimeTypeForFile(this->path).name();
157+
158+ if (mimetype == "application/octet-stream") {
159+ // Returned by Qt when it cannot determinate the mime type
160 mimetype = "Unknown";
161+ }
162+
163+ qDebug() << "[FILE] Mime type for the requested file is" << mimetype;
164 emit mimetypeChanged();
165 }
166
167=== modified file 'src/plugin/file-qml-plugin/docviewerFile.h'
168--- src/plugin/file-qml-plugin/docviewerFile.h 2014-09-26 11:47:46 +0000
169+++ src/plugin/file-qml-plugin/docviewerFile.h 2014-10-31 16:43:26 +0000
170@@ -13,6 +13,7 @@
171 Q_PROPERTY( QString mimetype READ getMimetype NOTIFY mimetypeChanged )
172 Q_PROPERTY( qint64 size READ getSize NOTIFY sizeChanged )
173 Q_PROPERTY( QDateTime lastModified READ getLastmodified NOTIFY lastmodifiedChanged )
174+ Q_PROPERTY( QDateTime creationTime READ getCreationTime NOTIFY creationTimeChanged )
175 Q_PROPERTY( int error READ getError NOTIFY errorChanged )
176
177 public:
178@@ -29,27 +30,27 @@
179
180 QDateTime getLastmodified() { return lastmodified; }
181
182+ QDateTime getCreationTime() { return creationTime; }
183+
184 int getError() { return error; }
185
186 QString path;
187 QString mimetype;
188 qint64 size;
189 QDateTime lastmodified;
190+ QDateTime creationTime;
191 int error;
192
193 private:
194 void open();
195- QProcess *mimeTypeProcess;
196-
197-public slots:
198- void s_readMimeType();
199- void s_finished(int exitCode);
200+ void readMimeType();
201
202 Q_SIGNALS:
203 void pathChanged();
204 void mimetypeChanged();
205 void sizeChanged();
206 void lastmodifiedChanged();
207+ void creationTimeChanged();
208 void errorChanged();
209 };
210
211
212=== modified file 'src/plugin/poppler-qml-plugin/pdfModel.cpp'
213--- src/plugin/poppler-qml-plugin/pdfModel.cpp 2014-10-20 21:38:36 +0000
214+++ src/plugin/poppler-qml-plugin/pdfModel.cpp 2014-10-31 16:43:26 +0000
215@@ -30,7 +30,7 @@
216 PdfModel::PdfModel(QAbstractListModel *parent):
217 QAbstractListModel(parent)
218 {
219- int metatype_id = qRegisterMetaType<PdfPagesList>("PdfPagesList");
220+ qRegisterMetaType<PdfPagesList>("PdfPagesList");
221 }
222
223 QHash<int, QByteArray> PdfModel::roleNames() const
224@@ -65,8 +65,7 @@
225
226 void PdfModel::setPath(QString &pathName)
227 {
228- if (pathName.isEmpty())
229- {
230+ if (pathName.isEmpty()) {
231 return;
232 }
233

Subscribers

People subscribed via source and target branches