Merge lp:~ajalkane/ubuntu-filemanager-app/updates-to-carlos-model into lp:~carlos-mazieri/ubuntu-filemanager-app/model

Proposed by Arto Jalkanen
Status: Merged
Approved by: Carlos Jose Mazieri
Approved revision: 9
Merge reported by: Arto Jalkanen
Merged at revision: not available
Proposed branch: lp:~ajalkane/ubuntu-filemanager-app/updates-to-carlos-model
Merge into: lp:~carlos-mazieri/ubuntu-filemanager-app/model
Diff against target: 323 lines (+87/-77)
4 files modified
folderlistmodel/dirmodel.cpp (+52/-37)
folderlistmodel/dirmodel.h (+9/-12)
folderlistmodel/plugin.cpp (+4/-9)
folderlistmodel/plugin.h (+22/-19)
To merge this branch: bzr merge lp:~ajalkane/ubuntu-filemanager-app/updates-to-carlos-model
Reviewer Review Type Date Requested Status
David Planella (community) Needs Information
Carlos Jose Mazieri Approve
Review via email: mp+158229@code.launchpad.net

Commit message

Updating changes from upstream and ajalkane's branch. With these updates is usable with FileManager QML UI.

Description of the change

Updating changes from upstream and ajalkane's branch. With these updates is usable with FileManager QML UI.

To post a comment you must log in.
9. By Arto Jalkanen

Upstream preferred parentPath to be property, so that's what it is now.

Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

Looks good. Merged into Carlos branch.

review: Approve
Revision history for this message
David Planella (dpm) wrote :

Has this already been merged into the plugin code in trunk? And if so, could someone change the status to Merged so that it doesn't appear in the list of branches to review? Thanks!

review: Needs Information
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Yeah this has been merged a long time ago. I fixed the status.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'folderlistmodel/dirmodel.cpp'
2--- folderlistmodel/dirmodel.cpp 2013-04-10 23:27:08 +0000
3+++ folderlistmodel/dirmodel.cpp 2013-04-11 15:19:40 +0000
4@@ -50,6 +50,9 @@
5
6 Q_GLOBAL_STATIC(IOWorkerThread, ioWorkerThread)
7
8+namespace {
9+ QHash<QByteArray, int> roleMapping;
10+}
11
12 class DirListWorker : public IORequest
13 {
14@@ -84,12 +87,13 @@
15
16 // last batch
17 emit itemsAdded(directoryContents);
18-
19+ emit workerFinished();
20 //std::sort(directoryContents.begin(), directoryContents.end(), DirModel::fileCompare);
21 }
22
23 signals:
24 void itemsAdded(const QVector<QFileInfo> &files);
25+ void workerFinished();
26
27 private:
28 QString mPathName;
29@@ -106,18 +110,12 @@
30 mNameFilters = QStringList() << "*";
31
32 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
33- // There's no virtual in Qt4.
34- setRoleNames(proxyRoleNames());
35+ // There's no setRoleNames in Qt5.
36+ setRoleNames(buildRoleNames());
37 #else
38 // In Qt5, the roleNames() is virtual and will work just fine.
39 #endif
40
41- // populate reverse mapping
42- const QHash<int, QByteArray> &roles = roleNames();
43- QHash<int, QByteArray>::ConstIterator it = roles.constBegin();
44- for (;it != roles.constEnd(); ++it)
45- mRoleMapping.insert(it.value(), it.key());
46-
47 connect(m_fsAction, SIGNAL(progress(int,int,int)),
48 this, SIGNAL(progress(int,int,int)));
49
50@@ -145,27 +143,43 @@
51 {
52 }
53
54-// roleNames has changed between Qt4 and Qt5. In Qt5 it is a virtual
55-// function and you can not call setRoleNames. same code base. Oh well.
56-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
57-QHash<int, QByteArray> DirModel::proxyRoleNames() const
58-#else
59+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
60+ // roleNames has changed between Qt4 and Qt5. In Qt5 it is a virtual
61+ // function and setRoleNames should not be used.
62 QHash<int, QByteArray> DirModel::roleNames() const
63+{
64+ static QHash<int, QByteArray> roles;
65+ if (roles.isEmpty()) {
66+ roles = buildRoleNames();
67+ }
68+
69+ return roles;
70+}
71 #endif
72+
73+QHash<int, QByteArray> DirModel::buildRoleNames() const
74 {
75- static QHash<int, QByteArray> roles;
76- if (roles.isEmpty()) {
77- roles.insert(FileNameRole, QByteArray("fileName"));
78- roles.insert(CreationDateRole, QByteArray("creationDate"));
79- roles.insert(ModifiedDateRole, QByteArray("modifiedDate"));
80- roles.insert(FileSizeRole, QByteArray("fileSize"));
81- roles.insert(IconSourceRole, QByteArray("iconSource"));
82- roles.insert(FilePathRole, QByteArray("filePath"));
83- roles.insert(IsDirRole, QByteArray("isDir"));
84- roles.insert(IsFileRole, QByteArray("isFile"));
85- roles.insert(IsReadableRole, QByteArray("isReadable"));
86- roles.insert(IsWritableRole, QByteArray("isWritable"));
87- roles.insert(IsExecutableRole, QByteArray("isExecutable"));
88+ QHash<int, QByteArray> roles;
89+ roles.insert(FileNameRole, QByteArray("fileName"));
90+ roles.insert(CreationDateRole, QByteArray("creationDate"));
91+ roles.insert(ModifiedDateRole, QByteArray("modifiedDate"));
92+ roles.insert(FileSizeRole, QByteArray("fileSize"));
93+ roles.insert(IconSourceRole, QByteArray("iconSource"));
94+ roles.insert(FilePathRole, QByteArray("filePath"));
95+ roles.insert(IsDirRole, QByteArray("isDir"));
96+ roles.insert(IsFileRole, QByteArray("isFile"));
97+ roles.insert(IsReadableRole, QByteArray("isReadable"));
98+ roles.insert(IsWritableRole, QByteArray("isWritable"));
99+ roles.insert(IsExecutableRole, QByteArray("isExecutable"));
100+
101+ // populate reverse mapping
102+ if (roleMapping.isEmpty()) {
103+ QHash<int, QByteArray>::ConstIterator it = roles.constBegin();
104+ for (;it != roles.constEnd(); ++it)
105+ roleMapping.insert(it.value(), it.key());
106+
107+ // make sure we cover all roles
108+ // Q_ASSERT(roles.count() == IsFileRole - FileNameRole);
109 }
110
111 return roles;
112@@ -173,9 +187,9 @@
113
114 QVariant DirModel::data(int row, const QByteArray &stringRole) const
115 {
116- QHash<QByteArray, int>::ConstIterator it = mRoleMapping.constFind(stringRole);
117+ QHash<QByteArray, int>::ConstIterator it = roleMapping.constFind(stringRole);
118
119- if (it == mRoleMapping.constEnd())
120+ if (it == roleMapping.constEnd())
121 return QVariant();
122
123 return data(index(row, 0), *it);
124@@ -293,6 +307,7 @@
125 // TODO: we need to set a spinner active before we start getting results from DirListWorker
126 DirListWorker *dlw = new DirListWorker(pathName, dirFilter);
127 connect(dlw, SIGNAL(itemsAdded(QVector<QFileInfo>)), SLOT(onItemsAdded(QVector<QFileInfo>)));
128+ connect(dlw, SIGNAL(workerFinished()), SLOT(onResultsFetched()));
129 ioWorkerThread()->addRequest(dlw);
130
131 mCurrentDir = pathName;
132@@ -310,20 +325,20 @@
133 return QString::localeAwareCompare(a.fileName(), b.fileName()) < 0;
134 }
135
136+void DirModel::onResultsFetched() {
137+ if (mAwaitingResults) {
138+ qDebug() << Q_FUNC_INFO << "No longer awaiting results";
139+ mAwaitingResults = false;
140+ emit awaitingResultsChanged();
141+ }
142+}
143+
144 void DirModel::onItemsAdded(const QVector<QFileInfo> &newFiles)
145 {
146 #if DEBUG_MESSAGES
147 qDebug() << Q_FUNC_INFO << "Got new files: " << newFiles.count();
148 #endif
149
150- if (mAwaitingResults) {
151-#if DEBUG_MESSAGES
152- qDebug() << Q_FUNC_INFO << "No longer awaiting results";
153-#endif
154- mAwaitingResults = false;
155- emit awaitingResultsChanged();
156- }
157-
158 foreach (const QFileInfo &fi, newFiles) {
159
160 bool doAdd = true;
161
162=== modified file 'folderlistmodel/dirmodel.h'
163--- folderlistmodel/dirmodel.h 2013-04-10 23:27:08 +0000
164+++ folderlistmodel/dirmodel.h 2013-04-11 15:19:40 +0000
165@@ -103,6 +103,7 @@
166
167 public slots:
168 void onItemsAdded(const QVector<QFileInfo> &newFiles);
169+ void onResultsFetched();
170
171 signals:
172 void awaitingResultsChanged();
173@@ -112,24 +113,20 @@
174 void error(const QString &errorTitle, const QString &errorMessage);
175
176 private:
177+ QHash<int, QByteArray> buildRoleNames() const;
178+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
179+ // In Qt5, the roleNames() is virtual and will work just fine. On qt4 setRoleNames must be used with buildRoleNames.
180+ QHash<int, QByteArray> roleNames() const;
181+#endif
182+
183 QStringList mNameFilters;
184 bool mShowDirectories;
185 bool mAwaitingResults;
186 QString mCurrentDir;
187 QVector<QFileInfo> mDirectoryContents;
188- QHash<QByteArray, int> mRoleMapping;
189
190-//[0] new stuff Ubuntu File Manager
191 public:
192-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
193- // There's no virtual roleNames in Qt4. Proxy returns the role names
194- // that are initialized in constructor.
195- QHash<int, QByteArray> proxyRoleNames() const;
196-#else
197- // In Qt5, the roleNames() is virtual and will work just fine.
198- QHash<int, QByteArray> roleNames() const;
199-#endif
200-
201+ //[0] new stuff Ubuntu File Manager
202 #if defined(REGRESSION_TEST_FOLDERLISTMODEL)
203 //make this work with tables
204 virtual int columnCount(const QModelIndex &) const
205@@ -140,7 +137,7 @@
206 #endif
207
208 Q_PROPERTY(QString parentPath READ parentPath NOTIFY pathChanged)
209- Q_INVOKABLE QString parentPath() const;
210+ QString parentPath() const;
211
212 Q_PROPERTY(bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles NOTIFY showHiddenFilesChanged)
213 bool showHiddenFiles() const;
214
215=== modified file 'folderlistmodel/plugin.cpp'
216--- folderlistmodel/plugin.cpp 2013-04-02 22:57:23 +0000
217+++ folderlistmodel/plugin.cpp 2013-04-11 15:19:40 +0000
218@@ -29,21 +29,20 @@
219 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
220 */
221
222+#include <QVector>
223+#include <QFileInfo>
224+
225 #include "plugin.h"
226
227 NemoFolderListModelPlugin::NemoFolderListModelPlugin() { }
228
229 NemoFolderListModelPlugin::~NemoFolderListModelPlugin() { }
230
231-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
232-void NemoFolderListModelPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri)
233-#else
234-void NemoFolderListModelPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
235+void NemoFolderListModelPlugin::initializeEngine(QmlEngine *engine, const char *uri)
236 {
237 Q_UNUSED(engine)
238 Q_ASSERT(uri == QLatin1String(QUOTES(PLUGIN_URI)));
239 }
240-#endif
241
242 void NemoFolderListModelPlugin::registerTypes(const char *uri)
243 {
244@@ -52,7 +51,3 @@
245 qmlRegisterType<DirModel>(uri, 1, 0, "FolderListModel");
246 }
247
248-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
249-Q_EXPORT_PLUGIN2(nemofolderlistmodel, NemoFolderListModelPlugin);
250-#endif
251-
252
253=== modified file 'folderlistmodel/plugin.h'
254--- folderlistmodel/plugin.h 2013-04-02 22:57:23 +0000
255+++ folderlistmodel/plugin.h 2013-04-11 15:19:40 +0000
256@@ -37,11 +37,29 @@
257 #include <QtDeclarative>
258 #include <QDeclarativeEngine>
259 #include <QDeclarativeExtensionPlugin>
260+#include <QVector>
261+#include <QFileInfo>
262+
263+#define PLUGIN_CLASS_EXPORT
264+#define PLUGIN_CLASS_EXTERNAL_EXPORT Q_EXPORT_PLUGIN2(nemofolderlistmodel, NemoFolderListModelPlugin);
265+#define PLUGIN_CLASS_EXTEND
266+typedef QDeclarativeExtensionPlugin QmlPluginParent;
267+typedef QDeclarativeEngine QmlEngine;
268+Q_DECLARE_METATYPE(QVector<QFileInfo>)
269+
270 #else
271 #include <QQmlComponent>
272 #include <QQmlEngine>
273 #include <QQmlContext>
274 #include <QQmlExtensionPlugin>
275+
276+#define PLUGIN_CLASS_EXPORT Q_DECL_EXPORT
277+#define PLUGIN_CLASS_EXTERNAL_EXPORT
278+#define PLUGIN_CLASS_EXTEND \
279+ Q_OBJECT \
280+ Q_PLUGIN_METADATA(IID "org.nemomobile.folderlistmodel")
281+typedef QQmlExtensionPlugin QmlPluginParent;
282+typedef QQmlEngine QmlEngine;
283 #endif
284
285 #include "dirmodel.h"
286@@ -49,33 +67,18 @@
287 #define QUOTES(x) #x
288
289
290-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
291-class Q_DECL_EXPORT NemoFolderListModelPlugin
292- : public QDeclarativeExtensionPlugin
293-#else
294-class NemoFolderListModelPlugin
295- : public QQmlExtensionPlugin
296-#endif
297+class PLUGIN_CLASS_EXPORT NemoFolderListModelPlugin : public QmlPluginParent
298 {
299-#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
300- Q_OBJECT
301- Q_PLUGIN_METADATA(IID QUOTES(PLUGIN_URI))
302-#endif
303+ PLUGIN_CLASS_EXTEND
304
305 public:
306 NemoFolderListModelPlugin();
307 virtual ~NemoFolderListModelPlugin();
308
309-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
310- void initializeEngine(QDeclarativeEngine *engine, const char *uri);
311-#else
312- void initializeEngine(QQmlEngine *engine, const char *uri);
313-#endif
314+ void initializeEngine(QmlEngine *engine, const char *uri);
315 void registerTypes(const char *uri);
316 };
317
318-#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
319-Q_EXPORT_PLUGIN2(nemofolderlistmodel, NemoFolderListModelPlugin);
320-#endif
321+PLUGIN_CLASS_EXTERNAL_EXPORT
322
323 #endif // NEMO_QML_PLUGINS_FOLDERLISTMODEL

Subscribers

People subscribed via source and target branches