Merge lp:~vthompson/ubuntu-filemanager-app/qml-folderlistmodel into lp:ubuntu-filemanager-app
- qml-folderlistmodel
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~vthompson/ubuntu-filemanager-app/qml-folderlistmodel |
Merge into: | lp:ubuntu-filemanager-app |
Diff against target: |
1171 lines (+1106/-0) (has conflicts) 13 files modified
README (+6/-0) dirmodel.cpp (+431/-0) dirmodel.h (+136/-0) iorequest.cpp (+36/-0) iorequest.h (+51/-0) iorequestworker.cpp (+92/-0) iorequestworker.h (+61/-0) ioworkerthread.cpp (+64/-0) ioworkerthread.h (+52/-0) plugin.cpp (+53/-0) plugin.h (+82/-0) qml-folderlistmodel.pro (+39/-0) qmldir (+3/-0) Conflict adding file README. Moved existing file to README.moved. |
To merge this branch: | bzr merge lp:~vthompson/ubuntu-filemanager-app/qml-folderlistmodel |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Arto Jalkanen | Pending | ||
Review via email: mp+153700@code.launchpad.net |
This proposal has been superseded by a proposal from 2013-03-18.
Commit message
Description of the change
This fixes Bug #1154369 by using the QT_INSTALL_QML (qmldir) directory for installation rather than the QT_INSTALL_IMPORTS (importsdir).
- 10. By Victor Thompson
-
Fix name filtering so if the filter has more than entry any one of the entries will match the filename. Also, added a filterDirectories bool, which defaults to false, so a user can choose to filter directories. Qt labs version did not filter directories, while this version did. Typical use case is to filter filename extensions which do not apply to directories.
- 11. By Victor Thompson
-
Add TagLib to the building of the plugin and use TagLib to read metadata
Unmerged revisions
- 11. By Victor Thompson
-
Add TagLib to the building of the plugin and use TagLib to read metadata
- 10. By Victor Thompson
-
Fix name filtering so if the filter has more than entry any one of the entries will match the filename. Also, added a filterDirectories bool, which defaults to false, so a user can choose to filter directories. Qt labs version did not filter directories, while this version did. Typical use case is to filter filename extensions which do not apply to directories.
- 9. By Victor Thompson
-
fix install path to correctly use qmldir.
- 8. By Arto Jalkanen
-
Added homePath function. ParentPath property is refreshed when path changes.
- 7. By Arto Jalkanen
-
Added parentPath property.
- 6. By Arto Jalkanen
-
Some small cleanup between separation of Qt4 and Qt5 code.
- 5. By Arto Jalkanen
-
Made the code a bit cleaner, separating qt4/qt5 code into one block.
- 4. By Arto Jalkanen
-
Restored metatype registration that was removed during testing.
- 3. By Arto Jalkanen
-
Added basic README
- 2. By Arto Jalkanen
-
Corrections by Carlos J Mazieri to build files to make the library importable.
Preview Diff
1 | === added file 'README' |
2 | --- README 1970-01-01 00:00:00 +0000 |
3 | +++ README 2013-03-18 00:30:30 +0000 |
4 | @@ -0,0 +1,6 @@ |
5 | +Building and installing |
6 | +======================= |
7 | + |
8 | +qmake && make |
9 | +sudo make install |
10 | + |
11 | |
12 | === renamed file 'README' => 'README.moved' |
13 | === added file 'dirmodel.cpp' |
14 | --- dirmodel.cpp 1970-01-01 00:00:00 +0000 |
15 | +++ dirmodel.cpp 2013-03-18 00:30:30 +0000 |
16 | @@ -0,0 +1,431 @@ |
17 | +/* |
18 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
19 | + * |
20 | + * You may use this file under the terms of the BSD license as follows: |
21 | + * |
22 | + * "Redistribution and use in source and binary forms, with or without |
23 | + * modification, are permitted provided that the following conditions are |
24 | + * met: |
25 | + * * Redistributions of source code must retain the above copyright |
26 | + * notice, this list of conditions and the following disclaimer. |
27 | + * * Redistributions in binary form must reproduce the above copyright |
28 | + * notice, this list of conditions and the following disclaimer in |
29 | + * the documentation and/or other materials provided with the |
30 | + * distribution. |
31 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
32 | + * may be used to endorse or promote products derived from this |
33 | + * software without specific prior written permission. |
34 | + * |
35 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
36 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
37 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
38 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
39 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
40 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
41 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
42 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
43 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
44 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
45 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
46 | + */ |
47 | + |
48 | +#include <QDirIterator> |
49 | +#include <QDir> |
50 | +#include <QDebug> |
51 | +#include <QDateTime> |
52 | +#include <QUrl> |
53 | + |
54 | +#include <errno.h> |
55 | +#include <string.h> |
56 | + |
57 | +#include "dirmodel.h" |
58 | +#include "ioworkerthread.h" |
59 | + |
60 | +Q_GLOBAL_STATIC(IOWorkerThread, ioWorkerThread); |
61 | + |
62 | +class DirListWorker : public IORequest |
63 | +{ |
64 | + Q_OBJECT |
65 | +public: |
66 | + DirListWorker(const QString &pathName) |
67 | + : mPathName(pathName) |
68 | + { } |
69 | + |
70 | + void run() |
71 | + { |
72 | + qDebug() << Q_FUNC_INFO << "Running on: " << QThread::currentThreadId(); |
73 | + |
74 | + QDir tmpDir = QDir(mPathName); |
75 | + QDirIterator it(tmpDir); |
76 | + QVector<QFileInfo> directoryContents; |
77 | + |
78 | + while (it.hasNext()) { |
79 | + it.next(); |
80 | + |
81 | + // skip hidden files |
82 | + if (it.fileName()[0] == QLatin1Char('.')) |
83 | + continue; |
84 | + |
85 | + directoryContents.append(it.fileInfo()); |
86 | + if (directoryContents.count() >= 50) { |
87 | + emit itemsAdded(directoryContents); |
88 | + |
89 | + // clear() would force a deallocation, micro-optimisation |
90 | + directoryContents.erase(directoryContents.begin(), directoryContents.end()); |
91 | + } |
92 | + } |
93 | + |
94 | + // last batch |
95 | + emit itemsAdded(directoryContents); |
96 | + |
97 | + //std::sort(directoryContents.begin(), directoryContents.end(), DirModel::fileCompare); |
98 | + } |
99 | + |
100 | +signals: |
101 | + void itemsAdded(const QVector<QFileInfo> &files); |
102 | + |
103 | +private: |
104 | + QString mPathName; |
105 | +}; |
106 | + |
107 | +DirModel::DirModel(QObject *parent) |
108 | + : QAbstractListModel(parent) |
109 | + , mAwaitingResults(false) |
110 | + , mShowDirectories(true) |
111 | +{ |
112 | + mNameFilters = QStringList() << "*"; |
113 | + |
114 | +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
115 | + // There's no setRoleNames in Qt5. |
116 | + setRoleNames(buildRoleNames()); |
117 | +#endif |
118 | + |
119 | + // populate reverse mapping |
120 | + const QHash<int, QByteArray> &roles = roleNames(); |
121 | + QHash<int, QByteArray>::ConstIterator it = roles.constBegin(); |
122 | + for (;it != roles.constEnd(); ++it) |
123 | + mRoleMapping.insert(it.value(), it.key()); |
124 | + |
125 | + // make sure we cover all roles |
126 | +// Q_ASSERT(roles.count() == IsFileRole - FileNameRole); |
127 | +} |
128 | + |
129 | +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
130 | +// roleNames has changed between Qt4 and Qt5. In Qt5 it is a virtual |
131 | +// function and setRoleNames should not be used. |
132 | +QHash<int, QByteArray> DirModel::roleNames() const |
133 | +{ |
134 | + static QHash<int, QByteArray> roles; |
135 | + if (roles.isEmpty()) { |
136 | + roles = buildRoleNames(); |
137 | + } |
138 | + |
139 | + return roles; |
140 | +} |
141 | +#endif |
142 | + |
143 | +QHash<int, QByteArray> DirModel::buildRoleNames() const |
144 | +{ |
145 | + QHash<int, QByteArray> roles; |
146 | + roles.insert(FileNameRole, QByteArray("fileName")); |
147 | + roles.insert(CreationDateRole, QByteArray("creationDate")); |
148 | + roles.insert(ModifiedDateRole, QByteArray("modifiedDate")); |
149 | + roles.insert(FileSizeRole, QByteArray("fileSize")); |
150 | + roles.insert(IconSourceRole, QByteArray("iconSource")); |
151 | + roles.insert(FilePathRole, QByteArray("filePath")); |
152 | + roles.insert(IsDirRole, QByteArray("isDir")); |
153 | + roles.insert(IsFileRole, QByteArray("isFile")); |
154 | + roles.insert(IsReadableRole, QByteArray("isReadable")); |
155 | + roles.insert(IsWritableRole, QByteArray("isWritable")); |
156 | + roles.insert(IsExecutableRole, QByteArray("isExecutable")); |
157 | + |
158 | + return roles; |
159 | +} |
160 | + |
161 | +QVariant DirModel::data(int row, const QByteArray &stringRole) const |
162 | +{ |
163 | + QHash<QByteArray, int>::ConstIterator it = mRoleMapping.constFind(stringRole); |
164 | + |
165 | + if (it == mRoleMapping.constEnd()) |
166 | + return QVariant(); |
167 | + |
168 | + return data(index(row, 0), *it); |
169 | +} |
170 | + |
171 | +QVariant DirModel::data(const QModelIndex &index, int role) const |
172 | +{ |
173 | + if (role < FileNameRole || role > IsExecutableRole) { |
174 | + qWarning() << Q_FUNC_INFO << "Got an out of range role: " << role; |
175 | + return QVariant(); |
176 | + } |
177 | + |
178 | + if (index.row() < 0 || index.row() >= mDirectoryContents.count()) { |
179 | + qWarning() << "Attempted to access out of range row: " << index.row(); |
180 | + return QVariant(); |
181 | + } |
182 | + |
183 | + if (index.column() != 0) |
184 | + return QVariant(); |
185 | + |
186 | + const QFileInfo &fi = mDirectoryContents.at(index.row()); |
187 | + |
188 | + switch (role) { |
189 | + case FileNameRole: |
190 | + return fi.fileName(); |
191 | + case CreationDateRole: |
192 | + return fi.created(); |
193 | + case ModifiedDateRole: |
194 | + return fi.lastModified(); |
195 | + case FileSizeRole: { |
196 | + qint64 kb = fi.size() / 1024; |
197 | + if (kb < 1) |
198 | + return QString::number(fi.size()) + " bytes"; |
199 | + else if (kb < 1024) |
200 | + return QString::number(kb) + " kb"; |
201 | + |
202 | + kb /= 1024; |
203 | + return QString::number(kb) + "mb"; |
204 | + } |
205 | + case IconSourceRole: { |
206 | + const QString &fileName = fi.fileName(); |
207 | + |
208 | + if (fi.isDir()) |
209 | + return "image://theme/icon-m-common-directory"; |
210 | + |
211 | + if (fileName.endsWith(".jpg", Qt::CaseInsensitive) || |
212 | + fileName.endsWith(".png", Qt::CaseInsensitive)) { |
213 | + return "image://nemoThumbnail/" + fi.filePath(); |
214 | + } |
215 | + |
216 | + return "image://theme/icon-m-content-document"; |
217 | + } |
218 | + case FilePathRole: |
219 | + return fi.filePath(); |
220 | + case IsDirRole: |
221 | + return fi.isDir(); |
222 | + case IsFileRole: |
223 | + return !fi.isDir(); |
224 | + case IsReadableRole: |
225 | + return fi.isReadable(); |
226 | + case IsWritableRole: |
227 | + return fi.isWritable(); |
228 | + case IsExecutableRole: |
229 | + return fi.isExecutable(); |
230 | + default: |
231 | + // this should not happen, ever |
232 | + Q_ASSERT(false); |
233 | + qWarning() << Q_FUNC_INFO << "Got an unknown role: " << role; |
234 | + return QVariant(); |
235 | + } |
236 | +} |
237 | + |
238 | +void DirModel::setPath(const QString &pathName) |
239 | +{ |
240 | + if (pathName.isEmpty()) |
241 | + return; |
242 | + |
243 | + if (mAwaitingResults) { |
244 | + // TODO: handle the case where pathName != our current path, cancel old |
245 | + // request, start a new one |
246 | + qDebug() << Q_FUNC_INFO << "Ignoring path change request, request already running"; |
247 | + return; |
248 | + } |
249 | + |
250 | + mAwaitingResults = true; |
251 | + emit awaitingResultsChanged(); |
252 | + qDebug() << Q_FUNC_INFO << "Changing to " << pathName << " on " << QThread::currentThreadId(); |
253 | + |
254 | + beginResetModel(); |
255 | + mDirectoryContents.clear(); |
256 | + endResetModel(); |
257 | + |
258 | + // TODO: we need to set a spinner active before we start getting results from DirListWorker |
259 | + DirListWorker *dlw = new DirListWorker(pathName); |
260 | + connect(dlw, SIGNAL(itemsAdded(QVector<QFileInfo>)), SLOT(onItemsAdded(QVector<QFileInfo>))); |
261 | + ioWorkerThread()->addRequest(dlw); |
262 | + |
263 | + mCurrentDir = pathName; |
264 | + emit pathChanged(); |
265 | +} |
266 | + |
267 | +static bool fileCompare(const QFileInfo &a, const QFileInfo &b) |
268 | +{ |
269 | + if (a.isDir() && !b.isDir()) |
270 | + return true; |
271 | + |
272 | + if (b.isDir() && !a.isDir()) |
273 | + return false; |
274 | + |
275 | + return QString::localeAwareCompare(a.fileName(), b.fileName()) < 0; |
276 | +} |
277 | + |
278 | +void DirModel::onItemsAdded(const QVector<QFileInfo> &newFiles) |
279 | +{ |
280 | + qDebug() << Q_FUNC_INFO << "Got new files: " << newFiles.count(); |
281 | + |
282 | + if (mAwaitingResults) { |
283 | + qDebug() << Q_FUNC_INFO << "No longer awaiting results"; |
284 | + mAwaitingResults = false; |
285 | + emit awaitingResultsChanged(); |
286 | + } |
287 | + |
288 | + foreach (const QFileInfo &fi, newFiles) { |
289 | + if (!mShowDirectories && fi.isDir()) |
290 | + continue; |
291 | + |
292 | + bool doAdd = true; |
293 | + foreach (const QString &nameFilter, mNameFilters) { |
294 | + // TODO: using QRegExp for wildcard matching is slow |
295 | + QRegExp re(nameFilter, Qt::CaseInsensitive, QRegExp::Wildcard); |
296 | + if (!re.exactMatch(fi.fileName())) { |
297 | + doAdd = false; |
298 | + break; |
299 | + } |
300 | + } |
301 | + |
302 | + if (!doAdd) |
303 | + continue; |
304 | + |
305 | + QVector<QFileInfo>::Iterator it = qLowerBound(mDirectoryContents.begin(), |
306 | + mDirectoryContents.end(), |
307 | + fi, |
308 | + fileCompare); |
309 | + |
310 | + if (it == mDirectoryContents.end()) { |
311 | + beginInsertRows(QModelIndex(), mDirectoryContents.count(), mDirectoryContents.count()); |
312 | + mDirectoryContents.append(fi); |
313 | + endInsertRows(); |
314 | + } else { |
315 | + int idx = it - mDirectoryContents.begin(); |
316 | + beginInsertRows(QModelIndex(), idx, idx); |
317 | + mDirectoryContents.insert(it, fi); |
318 | + endInsertRows(); |
319 | + } |
320 | + } |
321 | +} |
322 | + |
323 | +void DirModel::rm(const QStringList &paths) |
324 | +{ |
325 | + // TODO: handle directory deletions? |
326 | + bool error = false; |
327 | + |
328 | + foreach (const QString &path, paths) { |
329 | + error |= QFile::remove(path); |
330 | + |
331 | + if (error) { |
332 | + qWarning() << Q_FUNC_INFO << "Failed to remove " << path; |
333 | + error = false; |
334 | + } |
335 | + } |
336 | + |
337 | + // TODO: just remove removed items; don't reload the entire model |
338 | + refresh(); |
339 | +} |
340 | + |
341 | +bool DirModel::rename(int row, const QString &newName) |
342 | +{ |
343 | + qDebug() << Q_FUNC_INFO << "Renaming " << row << " to " << newName; |
344 | + Q_ASSERT(row >= 0 && row < mDirectoryContents.count()); |
345 | + if (row < 0 || row >= mDirectoryContents.count()) { |
346 | + qWarning() << Q_FUNC_INFO << "Out of bounds access"; |
347 | + return false; |
348 | + } |
349 | + |
350 | + const QFileInfo &fi = mDirectoryContents.at(row); |
351 | + |
352 | + if (!fi.isDir()) { |
353 | + QFile f(fi.absoluteFilePath()); |
354 | + bool retval = f.rename(fi.absolutePath() + QDir::separator() + newName); |
355 | + |
356 | + if (!retval) |
357 | + qDebug() << Q_FUNC_INFO << "Rename returned error code: " << f.error() << f.errorString(); |
358 | + else |
359 | + refresh(); |
360 | + // TODO: just change the affected item... ^^ |
361 | + |
362 | + return retval; |
363 | + } else { |
364 | + QDir d(fi.absoluteFilePath()); |
365 | + bool retval = d.rename(fi.absoluteFilePath(), fi.absolutePath() + QDir::separator() + newName); |
366 | + |
367 | + // QDir has no way to detect what went wrong. woohoo! |
368 | + |
369 | + // TODO: just change the affected item... |
370 | + refresh(); |
371 | + |
372 | + return retval; |
373 | + } |
374 | + |
375 | + // unreachable (we hope) |
376 | + Q_ASSERT(false); |
377 | + return false; |
378 | +} |
379 | + |
380 | +void DirModel::mkdir(const QString &newDir) |
381 | +{ |
382 | + qDebug() << Q_FUNC_INFO << "Creating new folder " << newDir << " to " << mCurrentDir; |
383 | + |
384 | + QDir dir(mCurrentDir); |
385 | + bool retval = dir.mkdir(newDir); |
386 | + if (!retval) { |
387 | + const char *errorStr = strerror(errno); |
388 | + qDebug() << Q_FUNC_INFO << "Error creating new directory: " << errno << " (" << errorStr << ")"; |
389 | + emit error("Error creating new folder", errorStr); |
390 | + } else { |
391 | + refresh(); |
392 | + } |
393 | +} |
394 | + |
395 | +bool DirModel::showDirectories() const |
396 | +{ |
397 | + return mShowDirectories; |
398 | +} |
399 | + |
400 | +void DirModel::setShowDirectories(bool showDirectories) |
401 | +{ |
402 | + mShowDirectories = showDirectories; |
403 | + refresh(); |
404 | + emit showDirectoriesChanged(); |
405 | +} |
406 | + |
407 | +QStringList DirModel::nameFilters() const |
408 | +{ |
409 | + return mNameFilters; |
410 | +} |
411 | + |
412 | +void DirModel::setNameFilters(const QStringList &nameFilters) |
413 | +{ |
414 | + mNameFilters = nameFilters; |
415 | + refresh(); |
416 | + emit nameFiltersChanged(); |
417 | +} |
418 | + |
419 | +bool DirModel::awaitingResults() const |
420 | +{ |
421 | + return mAwaitingResults; |
422 | +} |
423 | + |
424 | +QString DirModel::parentPath() const |
425 | +{ |
426 | + QDir dir(mCurrentDir); |
427 | + if (dir.isRoot()) { |
428 | + qDebug() << Q_FUNC_INFO << "already at root"; |
429 | + return mCurrentDir; |
430 | + } |
431 | + |
432 | + bool success = dir.cdUp(); |
433 | + if (!success) { |
434 | + qWarning() << Q_FUNC_INFO << "Failed to to go to parent of " << mCurrentDir; |
435 | + return mCurrentDir; |
436 | + } |
437 | + qDebug() << Q_FUNC_INFO << "returning" << dir.absolutePath(); |
438 | + return dir.absolutePath(); |
439 | +} |
440 | + |
441 | +QString DirModel::homePath() const |
442 | +{ |
443 | + return QDir::homePath(); |
444 | +} |
445 | + |
446 | +// for dirlistworker |
447 | +#include "dirmodel.moc" |
448 | |
449 | === added file 'dirmodel.h' |
450 | --- dirmodel.h 1970-01-01 00:00:00 +0000 |
451 | +++ dirmodel.h 2013-03-18 00:30:30 +0000 |
452 | @@ -0,0 +1,136 @@ |
453 | +/* |
454 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
455 | + * |
456 | + * You may use this file under the terms of the BSD license as follows: |
457 | + * |
458 | + * "Redistribution and use in source and binary forms, with or without |
459 | + * modification, are permitted provided that the following conditions are |
460 | + * met: |
461 | + * * Redistributions of source code must retain the above copyright |
462 | + * notice, this list of conditions and the following disclaimer. |
463 | + * * Redistributions in binary form must reproduce the above copyright |
464 | + * notice, this list of conditions and the following disclaimer in |
465 | + * the documentation and/or other materials provided with the |
466 | + * distribution. |
467 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
468 | + * may be used to endorse or promote products derived from this |
469 | + * software without specific prior written permission. |
470 | + * |
471 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
472 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
473 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
474 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
475 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
476 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
477 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
478 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
479 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
480 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
481 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
482 | + */ |
483 | + |
484 | +#ifndef DIRMODEL_H |
485 | +#define DIRMODEL_H |
486 | + |
487 | +#include <QAbstractListModel> |
488 | +#include <QFileInfo> |
489 | +#include <QVector> |
490 | +#include <QStringList> |
491 | + |
492 | +#include "iorequest.h" |
493 | + |
494 | +class DirModel : public QAbstractListModel |
495 | +{ |
496 | + Q_OBJECT |
497 | + |
498 | + enum Roles { |
499 | + FileNameRole = Qt::UserRole, |
500 | + CreationDateRole, |
501 | + ModifiedDateRole, |
502 | + FileSizeRole, |
503 | + IconSourceRole, |
504 | + FilePathRole, |
505 | + IsDirRole, |
506 | + IsFileRole, |
507 | + IsReadableRole, |
508 | + IsWritableRole, |
509 | + IsExecutableRole |
510 | + }; |
511 | + |
512 | +public: |
513 | + DirModel(QObject *parent = 0); |
514 | + |
515 | + int rowCount(const QModelIndex &index) const |
516 | + { |
517 | + if (index.parent() != QModelIndex()) |
518 | + return 0; |
519 | + |
520 | + return mDirectoryContents.count(); |
521 | + } |
522 | + |
523 | + // TODO: this won't be safe if the model can change under the holder of the row |
524 | + Q_INVOKABLE QVariant data(int row, const QByteArray &stringRole) const; |
525 | + |
526 | + QVariant data(const QModelIndex &index, int role) const; |
527 | + |
528 | + Q_INVOKABLE void refresh() |
529 | + { |
530 | + // just some syntactical sugar really |
531 | + setPath(path()); |
532 | + } |
533 | + |
534 | + Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged); |
535 | + inline QString path() const { return mCurrentDir; } |
536 | + |
537 | + Q_PROPERTY(QString parentPath READ parentPath NOTIFY pathChanged); |
538 | + Q_INVOKABLE QString parentPath() const; |
539 | + |
540 | + Q_INVOKABLE QString homePath() const; |
541 | + |
542 | + Q_PROPERTY(bool awaitingResults READ awaitingResults NOTIFY awaitingResultsChanged); |
543 | + bool awaitingResults() const; |
544 | + |
545 | + void setPath(const QString &pathName); |
546 | + |
547 | + Q_INVOKABLE void rm(const QStringList &paths); |
548 | + |
549 | + Q_INVOKABLE bool rename(int row, const QString &newName); |
550 | + |
551 | + Q_INVOKABLE void mkdir(const QString &newdir); |
552 | + |
553 | + Q_PROPERTY(bool showDirectories READ showDirectories WRITE setShowDirectories NOTIFY showDirectoriesChanged) |
554 | + bool showDirectories() const; |
555 | + void setShowDirectories(bool showDirectories); |
556 | + |
557 | + Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters NOTIFY nameFiltersChanged) |
558 | + QStringList nameFilters() const; |
559 | + void setNameFilters(const QStringList &nameFilters); |
560 | + |
561 | +public slots: |
562 | + void onItemsAdded(const QVector<QFileInfo> &newFiles); |
563 | + |
564 | +signals: |
565 | + void awaitingResultsChanged(); |
566 | + void nameFiltersChanged(); |
567 | + void showDirectoriesChanged(); |
568 | + void pathChanged(); |
569 | + void error(const QString &errorTitle, const QString &errorMessage); |
570 | + |
571 | +private: |
572 | + QHash<int, QByteArray> buildRoleNames() const; |
573 | + |
574 | +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
575 | + // In Qt5, the roleNames() is virtual and will work just fine. On qt4 setRoleNames must be used with buildRoleNames. |
576 | + QHash<int, QByteArray> roleNames() const; |
577 | +#endif |
578 | + |
579 | + QStringList mNameFilters; |
580 | + bool mShowDirectories; |
581 | + bool mAwaitingResults; |
582 | + QString mCurrentDir; |
583 | + QVector<QFileInfo> mDirectoryContents; |
584 | + QHash<QByteArray, int> mRoleMapping; |
585 | +}; |
586 | + |
587 | + |
588 | +#endif // DIRMODEL_H |
589 | |
590 | === added file 'iorequest.cpp' |
591 | --- iorequest.cpp 1970-01-01 00:00:00 +0000 |
592 | +++ iorequest.cpp 2013-03-18 00:30:30 +0000 |
593 | @@ -0,0 +1,36 @@ |
594 | +/* |
595 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
596 | + * |
597 | + * You may use this file under the terms of the BSD license as follows: |
598 | + * |
599 | + * "Redistribution and use in source and binary forms, with or without |
600 | + * modification, are permitted provided that the following conditions are |
601 | + * met: |
602 | + * * Redistributions of source code must retain the above copyright |
603 | + * notice, this list of conditions and the following disclaimer. |
604 | + * * Redistributions in binary form must reproduce the above copyright |
605 | + * notice, this list of conditions and the following disclaimer in |
606 | + * the documentation and/or other materials provided with the |
607 | + * distribution. |
608 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
609 | + * may be used to endorse or promote products derived from this |
610 | + * software without specific prior written permission. |
611 | + * |
612 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
613 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
614 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
615 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
616 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
617 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
618 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
619 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
620 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
621 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
622 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
623 | + */ |
624 | + |
625 | +#include "iorequest.h" |
626 | + |
627 | +IORequest::IORequest() : QObject() |
628 | +{ |
629 | +} |
630 | |
631 | === added file 'iorequest.h' |
632 | --- iorequest.h 1970-01-01 00:00:00 +0000 |
633 | +++ iorequest.h 2013-03-18 00:30:30 +0000 |
634 | @@ -0,0 +1,51 @@ |
635 | +/* |
636 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
637 | + * |
638 | + * You may use this file under the terms of the BSD license as follows: |
639 | + * |
640 | + * "Redistribution and use in source and binary forms, with or without |
641 | + * modification, are permitted provided that the following conditions are |
642 | + * met: |
643 | + * * Redistributions of source code must retain the above copyright |
644 | + * notice, this list of conditions and the following disclaimer. |
645 | + * * Redistributions in binary form must reproduce the above copyright |
646 | + * notice, this list of conditions and the following disclaimer in |
647 | + * the documentation and/or other materials provided with the |
648 | + * distribution. |
649 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
650 | + * may be used to endorse or promote products derived from this |
651 | + * software without specific prior written permission. |
652 | + * |
653 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
654 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
655 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
656 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
657 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
658 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
659 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
660 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
661 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
662 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
663 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
664 | + */ |
665 | + |
666 | +#ifndef IOREQUEST_H |
667 | +#define IOREQUEST_H |
668 | + |
669 | +#include <QObject> |
670 | + |
671 | +class IORequest : public QObject |
672 | +{ |
673 | + Q_OBJECT |
674 | +public: |
675 | + explicit IORequest(); |
676 | + |
677 | +public: |
678 | + virtual void run() = 0; |
679 | + |
680 | +private: |
681 | + // hide this because IORequest should *NOT* be parented directly |
682 | + using QObject::setParent; |
683 | +}; |
684 | + |
685 | +#endif // IOREQUEST_H |
686 | |
687 | === added file 'iorequestworker.cpp' |
688 | --- iorequestworker.cpp 1970-01-01 00:00:00 +0000 |
689 | +++ iorequestworker.cpp 2013-03-18 00:30:30 +0000 |
690 | @@ -0,0 +1,92 @@ |
691 | +/* |
692 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
693 | + * |
694 | + * You may use this file under the terms of the BSD license as follows: |
695 | + * |
696 | + * "Redistribution and use in source and binary forms, with or without |
697 | + * modification, are permitted provided that the following conditions are |
698 | + * met: |
699 | + * * Redistributions of source code must retain the above copyright |
700 | + * notice, this list of conditions and the following disclaimer. |
701 | + * * Redistributions in binary form must reproduce the above copyright |
702 | + * notice, this list of conditions and the following disclaimer in |
703 | + * the documentation and/or other materials provided with the |
704 | + * distribution. |
705 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
706 | + * may be used to endorse or promote products derived from this |
707 | + * software without specific prior written permission. |
708 | + * |
709 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
710 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
711 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
712 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
713 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
714 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
715 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
716 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
717 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
718 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
719 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
720 | + */ |
721 | + |
722 | +#include <QMutexLocker> |
723 | +#include <QDebug> |
724 | + |
725 | +#include "iorequestworker.h" |
726 | +#include "iorequest.h" |
727 | + |
728 | +/*! |
729 | + Lives on an IOWorkerThread. |
730 | + |
731 | + Responsible for running IORequest jobs on the thread instance, and |
732 | + disposing of their resources once they are done. |
733 | + */ |
734 | +IORequestWorker::IORequestWorker() |
735 | + : QThread() |
736 | + , mTimeToQuit(false) |
737 | +{ |
738 | +} |
739 | + |
740 | +void IORequestWorker::addRequest(IORequest *request) |
741 | +{ |
742 | + request->moveToThread(this); |
743 | + |
744 | + // TODO: queue requests so we run the most important one first |
745 | + QMutexLocker lock(&mMutex); |
746 | + mRequests.append(request); |
747 | + |
748 | + // wake run() |
749 | + mWaitCondition.wakeOne(); |
750 | +} |
751 | + |
752 | +void IORequestWorker::run() |
753 | +{ |
754 | + forever { |
755 | + QMutexLocker lock(&mMutex); |
756 | + |
757 | + if (mTimeToQuit) |
758 | + return; |
759 | + |
760 | + if (mRequests.empty()) |
761 | + mWaitCondition.wait(&mMutex); |
762 | + |
763 | + while (!mRequests.isEmpty()) { |
764 | + IORequest *request = mRequests.takeFirst(); |
765 | + |
766 | + lock.unlock(); |
767 | + |
768 | + request->run(); |
769 | + request->deleteLater(); |
770 | + |
771 | + lock.relock(); |
772 | + } |
773 | + } |
774 | +} |
775 | + |
776 | +void IORequestWorker::exit() |
777 | +{ |
778 | + qDebug() << Q_FUNC_INFO << "Quitting"; |
779 | + QMutexLocker lock(&mMutex); |
780 | + mTimeToQuit = true; |
781 | + mWaitCondition.wakeOne(); |
782 | +} |
783 | |
784 | === added file 'iorequestworker.h' |
785 | --- iorequestworker.h 1970-01-01 00:00:00 +0000 |
786 | +++ iorequestworker.h 2013-03-18 00:30:30 +0000 |
787 | @@ -0,0 +1,61 @@ |
788 | +/* |
789 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
790 | + * |
791 | + * You may use this file under the terms of the BSD license as follows: |
792 | + * |
793 | + * "Redistribution and use in source and binary forms, with or without |
794 | + * modification, are permitted provided that the following conditions are |
795 | + * met: |
796 | + * * Redistributions of source code must retain the above copyright |
797 | + * notice, this list of conditions and the following disclaimer. |
798 | + * * Redistributions in binary form must reproduce the above copyright |
799 | + * notice, this list of conditions and the following disclaimer in |
800 | + * the documentation and/or other materials provided with the |
801 | + * distribution. |
802 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
803 | + * may be used to endorse or promote products derived from this |
804 | + * software without specific prior written permission. |
805 | + * |
806 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
807 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
808 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
809 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
810 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
811 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
812 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
813 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
814 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
815 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
816 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
817 | + */ |
818 | + |
819 | +#ifndef IOREQUESTWORKER_H |
820 | +#define IOREQUESTWORKER_H |
821 | + |
822 | +#include <QObject> |
823 | +#include <QThread> |
824 | +#include <QMutex> |
825 | +#include <QWaitCondition> |
826 | + |
827 | +#include "iorequest.h" |
828 | + |
829 | +class IORequestWorker : public QThread |
830 | +{ |
831 | + Q_OBJECT |
832 | +public: |
833 | + explicit IORequestWorker(); |
834 | + |
835 | + void addRequest(IORequest *request); |
836 | + |
837 | + void run(); |
838 | + |
839 | + void exit(); |
840 | + |
841 | +private: |
842 | + QMutex mMutex; |
843 | + QWaitCondition mWaitCondition; |
844 | + QList<IORequest *> mRequests; |
845 | + bool mTimeToQuit; |
846 | +}; |
847 | + |
848 | +#endif // IOREQUESTWORKER_H |
849 | |
850 | === added file 'ioworkerthread.cpp' |
851 | --- ioworkerthread.cpp 1970-01-01 00:00:00 +0000 |
852 | +++ ioworkerthread.cpp 2013-03-18 00:30:30 +0000 |
853 | @@ -0,0 +1,64 @@ |
854 | +/* |
855 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
856 | + * |
857 | + * You may use this file under the terms of the BSD license as follows: |
858 | + * |
859 | + * "Redistribution and use in source and binary forms, with or without |
860 | + * modification, are permitted provided that the following conditions are |
861 | + * met: |
862 | + * * Redistributions of source code must retain the above copyright |
863 | + * notice, this list of conditions and the following disclaimer. |
864 | + * * Redistributions in binary form must reproduce the above copyright |
865 | + * notice, this list of conditions and the following disclaimer in |
866 | + * the documentation and/or other materials provided with the |
867 | + * distribution. |
868 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
869 | + * may be used to endorse or promote products derived from this |
870 | + * software without specific prior written permission. |
871 | + * |
872 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
873 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
874 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
875 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
876 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
877 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
878 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
879 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
880 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
881 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
882 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
883 | + */ |
884 | + |
885 | +#include "ioworkerthread.h" |
886 | + |
887 | + |
888 | +/*! |
889 | + Hosts a thread, lives on the main thread. |
890 | + |
891 | + Responsible for relaying interaction between the main thread and an IOWorkerThread. |
892 | + */ |
893 | +IOWorkerThread::IOWorkerThread(QObject *parent) : |
894 | + QObject(parent) |
895 | +{ |
896 | + mWorker.start(QThread::IdlePriority); |
897 | +} |
898 | + |
899 | +/*! |
900 | + Destroys an IOWorkerThread instance. |
901 | + */ |
902 | +IOWorkerThread::~IOWorkerThread() |
903 | +{ |
904 | + mWorker.exit(); |
905 | + mWorker.wait(); |
906 | +} |
907 | + |
908 | +/*! |
909 | + Attempts an asynchronous attempt to start a \a request. |
910 | + |
911 | + If the request may be run, it is queued, and true is returned, otherwise, false. |
912 | + */ |
913 | +bool IOWorkerThread::addRequest(IORequest *request) |
914 | +{ |
915 | + mWorker.addRequest(request); |
916 | + return true; |
917 | +} |
918 | |
919 | === added file 'ioworkerthread.h' |
920 | --- ioworkerthread.h 1970-01-01 00:00:00 +0000 |
921 | +++ ioworkerthread.h 2013-03-18 00:30:30 +0000 |
922 | @@ -0,0 +1,52 @@ |
923 | +/* |
924 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
925 | + * |
926 | + * You may use this file under the terms of the BSD license as follows: |
927 | + * |
928 | + * "Redistribution and use in source and binary forms, with or without |
929 | + * modification, are permitted provided that the following conditions are |
930 | + * met: |
931 | + * * Redistributions of source code must retain the above copyright |
932 | + * notice, this list of conditions and the following disclaimer. |
933 | + * * Redistributions in binary form must reproduce the above copyright |
934 | + * notice, this list of conditions and the following disclaimer in |
935 | + * the documentation and/or other materials provided with the |
936 | + * distribution. |
937 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
938 | + * may be used to endorse or promote products derived from this |
939 | + * software without specific prior written permission. |
940 | + * |
941 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
942 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
943 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
944 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
945 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
946 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
947 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
948 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
949 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
950 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
951 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
952 | + */ |
953 | + |
954 | +#ifndef IOWORKERTHREAD_H |
955 | +#define IOWORKERTHREAD_H |
956 | + |
957 | +#include <QObject> |
958 | +#include <QThread> |
959 | + |
960 | +#include "iorequestworker.h" |
961 | + |
962 | +class IOWorkerThread : public QObject |
963 | +{ |
964 | + Q_OBJECT |
965 | +public: |
966 | + explicit IOWorkerThread(QObject *parent = 0); |
967 | + virtual ~IOWorkerThread(); |
968 | + bool addRequest(IORequest *request); |
969 | + |
970 | +private: |
971 | + IORequestWorker mWorker; |
972 | +}; |
973 | + |
974 | +#endif // IOWORKERTHREAD_H |
975 | |
976 | === added file 'plugin.cpp' |
977 | --- plugin.cpp 1970-01-01 00:00:00 +0000 |
978 | +++ plugin.cpp 2013-03-18 00:30:30 +0000 |
979 | @@ -0,0 +1,53 @@ |
980 | +/* |
981 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
982 | + * |
983 | + * You may use this file under the terms of the BSD license as follows: |
984 | + * |
985 | + * "Redistribution and use in source and binary forms, with or without |
986 | + * modification, are permitted provided that the following conditions are |
987 | + * met: |
988 | + * * Redistributions of source code must retain the above copyright |
989 | + * notice, this list of conditions and the following disclaimer. |
990 | + * * Redistributions in binary form must reproduce the above copyright |
991 | + * notice, this list of conditions and the following disclaimer in |
992 | + * the documentation and/or other materials provided with the |
993 | + * distribution. |
994 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
995 | + * may be used to endorse or promote products derived from this |
996 | + * software without specific prior written permission. |
997 | + * |
998 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
999 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
1000 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
1001 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
1002 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
1003 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
1004 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
1005 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
1006 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
1007 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
1008 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
1009 | + */ |
1010 | + |
1011 | +#include <QVector> |
1012 | +#include <QFileInfo> |
1013 | + |
1014 | +#include "plugin.h" |
1015 | + |
1016 | +NemoFolderListModelPlugin::NemoFolderListModelPlugin() { } |
1017 | + |
1018 | +NemoFolderListModelPlugin::~NemoFolderListModelPlugin() { } |
1019 | + |
1020 | +void NemoFolderListModelPlugin::initializeEngine(QmlEngine *engine, const char *uri) |
1021 | +{ |
1022 | + Q_UNUSED(engine) |
1023 | + Q_ASSERT(uri == QLatin1String("org.nemomobile.folderlistmodel")); |
1024 | +} |
1025 | + |
1026 | +void NemoFolderListModelPlugin::registerTypes(const char *uri) |
1027 | +{ |
1028 | + Q_ASSERT(uri == QLatin1String("org.nemomobile.folderlistmodel")); |
1029 | + qRegisterMetaType<QVector<QFileInfo> >(); |
1030 | + qmlRegisterType<DirModel>(uri, 1, 0, "FolderListModel"); |
1031 | +} |
1032 | + |
1033 | |
1034 | === added file 'plugin.h' |
1035 | --- plugin.h 1970-01-01 00:00:00 +0000 |
1036 | +++ plugin.h 2013-03-18 00:30:30 +0000 |
1037 | @@ -0,0 +1,82 @@ |
1038 | +/* |
1039 | + * Copyright (C) 2012 Robin Burchell <robin+nemo@viroteck.net> |
1040 | + * |
1041 | + * You may use this file under the terms of the BSD license as follows: |
1042 | + * |
1043 | + * "Redistribution and use in source and binary forms, with or without |
1044 | + * modification, are permitted provided that the following conditions are |
1045 | + * met: |
1046 | + * * Redistributions of source code must retain the above copyright |
1047 | + * notice, this list of conditions and the following disclaimer. |
1048 | + * * Redistributions in binary form must reproduce the above copyright |
1049 | + * notice, this list of conditions and the following disclaimer in |
1050 | + * the documentation and/or other materials provided with the |
1051 | + * distribution. |
1052 | + * * Neither the name of Nemo Mobile nor the names of its contributors |
1053 | + * may be used to endorse or promote products derived from this |
1054 | + * software without specific prior written permission. |
1055 | + * |
1056 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
1057 | + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
1058 | + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
1059 | + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
1060 | + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
1061 | + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
1062 | + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
1063 | + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
1064 | + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
1065 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
1066 | + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
1067 | + */ |
1068 | + |
1069 | +#ifndef NEMO_QML_PLUGINS_FOLDERLISTMODEL |
1070 | +#define NEMO_QML_PLUGINS_FOLDERLISTMODEL |
1071 | + |
1072 | +#include <QtGlobal> |
1073 | + |
1074 | +#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) |
1075 | +#include <QtDeclarative> |
1076 | +#include <QDeclarativeEngine> |
1077 | +#include <QDeclarativeExtensionPlugin> |
1078 | +#include <QVector> |
1079 | +#include <QFileInfo> |
1080 | + |
1081 | +#define PLUGIN_CLASS_EXPORT |
1082 | +#define PLUGIN_CLASS_EXTERNAL_EXPORT Q_EXPORT_PLUGIN2(nemofolderlistmodel, NemoFolderListModelPlugin); |
1083 | +#define PLUGIN_CLASS_EXTEND |
1084 | +typedef QDeclarativeExtensionPlugin QmlPluginParent; |
1085 | +typedef QDeclarativeEngine QmlEngine; |
1086 | +Q_DECLARE_METATYPE(QVector<QFileInfo>) |
1087 | + |
1088 | +#else |
1089 | +#include <QQmlComponent> |
1090 | +#include <QQmlEngine> |
1091 | +#include <QQmlContext> |
1092 | +#include <QQmlExtensionPlugin> |
1093 | + |
1094 | +#define PLUGIN_CLASS_EXPORT Q_DECL_EXPORT |
1095 | +#define PLUGIN_CLASS_EXTERNAL_EXPORT |
1096 | +#define PLUGIN_CLASS_EXTEND \ |
1097 | + Q_OBJECT \ |
1098 | + Q_PLUGIN_METADATA(IID "org.nemomobile.folderlistmodel") |
1099 | +typedef QQmlExtensionPlugin QmlPluginParent; |
1100 | +typedef QQmlEngine QmlEngine; |
1101 | +#endif |
1102 | + |
1103 | +#include "dirmodel.h" |
1104 | + |
1105 | +class PLUGIN_CLASS_EXPORT NemoFolderListModelPlugin : public QmlPluginParent |
1106 | +{ |
1107 | + PLUGIN_CLASS_EXTEND |
1108 | + |
1109 | +public: |
1110 | + NemoFolderListModelPlugin(); |
1111 | + virtual ~NemoFolderListModelPlugin(); |
1112 | + |
1113 | + void initializeEngine(QmlEngine *engine, const char *uri); |
1114 | + void registerTypes(const char *uri); |
1115 | +}; |
1116 | + |
1117 | +PLUGIN_CLASS_EXTERNAL_EXPORT |
1118 | + |
1119 | +#endif // NEMO_QML_PLUGINS_FOLDERLISTMODEL |
1120 | |
1121 | === added file 'qml-folderlistmodel.pro' |
1122 | --- qml-folderlistmodel.pro 1970-01-01 00:00:00 +0000 |
1123 | +++ qml-folderlistmodel.pro 2013-03-18 00:30:30 +0000 |
1124 | @@ -0,0 +1,39 @@ |
1125 | +TEMPLATE = lib |
1126 | +TARGET = folderlistmodel |
1127 | +QT += qml quick |
1128 | +CONFIG += qt plugin |
1129 | + |
1130 | +TARGET = $$qtLibraryTarget($$TARGET) |
1131 | +uri = org.nemomobile.folderlistmodel |
1132 | + |
1133 | +# Input |
1134 | +SOURCES += plugin.cpp \ |
1135 | + dirmodel.cpp \ |
1136 | + iorequest.cpp \ |
1137 | + iorequestworker.cpp \ |
1138 | + ioworkerthread.cpp |
1139 | + |
1140 | +HEADERS += plugin.h \ |
1141 | + dirmodel.h \ |
1142 | + iorequest.h \ |
1143 | + iorequestworker.h \ |
1144 | + ioworkerthread.h |
1145 | + |
1146 | +OTHER_FILES = qmldir |
1147 | + |
1148 | +!equals(_PRO_FILE_PWD_, $$OUT_PWD) { |
1149 | + copy_qmldir.target = $$OUT_PWD/qmldir |
1150 | + copy_qmldir.depends = $$_PRO_FILE_PWD_/qmldir |
1151 | + copy_qmldir.commands = $(COPY_FILE) \"$$replace(copy_qmldir.depends, /, $$QMAKE_DIR_SEP)\" \"$$replace(copy_qmldir.target, /, $$QMAKE_DIR_SEP)\" |
1152 | + QMAKE_EXTRA_TARGETS += copy_qmldir |
1153 | + PRE_TARGETDEPS += $$copy_qmldir.target |
1154 | +} |
1155 | + |
1156 | +qmldir.files = qmldir |
1157 | +unix { |
1158 | + installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /) |
1159 | + qmldir.path = $$installPath |
1160 | + target.path = $$installPath |
1161 | + INSTALLS += target qmldir |
1162 | +} |
1163 | + |
1164 | |
1165 | === added file 'qmldir' |
1166 | --- qmldir 1970-01-01 00:00:00 +0000 |
1167 | +++ qmldir 2013-03-18 00:30:30 +0000 |
1168 | @@ -0,0 +1,3 @@ |
1169 | +module org.nemomobile.folderlistmodel |
1170 | +plugin folderlistmodel |
1171 | + |