Changeset View
Changeset View
Standalone View
Standalone View
krusader/VFS/virt_vfs.cpp
Context not available. | |||||
23 | #include <QDir> | 23 | #include <QDir> | ||
---|---|---|---|---|---|
24 | #include <QEventLoop> | 24 | #include <QEventLoop> | ||
25 | #include <QUrl> | 25 | #include <QUrl> | ||
26 | #include <QTimer> | ||||
26 | // QtWidgets | 27 | // QtWidgets | ||
27 | #include <QApplication> | 28 | #include <QApplication> | ||
28 | 29 | | |||
Context not available. | |||||
36 | #include <KIOCore/KFileItem> | 37 | #include <KIOCore/KFileItem> | ||
37 | #include <KWidgetsAddons/KMessageBox> | 38 | #include <KWidgetsAddons/KMessageBox> | ||
38 | 39 | | |||
40 | #include <cassert> | ||||
41 | | ||||
39 | #include "../defaults.h" | 42 | #include "../defaults.h" | ||
40 | #include "../krglobal.h" | 43 | #include "../krglobal.h" | ||
41 | #include "../krservices.h" | 44 | #include "../krservices.h" | ||
Context not available. | |||||
43 | 46 | | |||
44 | #define VIRT_VFS_DB "virt_vfs.db" | 47 | #define VIRT_VFS_DB "virt_vfs.db" | ||
45 | 48 | | |||
49 | class virt_vfs::StatJob : public KIO::Job | ||||
50 | { | ||||
51 | public: | ||||
52 | StatJob(const QList<QUrl> &urls) : _it(urls) { | ||||
53 | timer.setSingleShot(true); | ||||
54 | connect(&timer, &QTimer::timeout, this, &StatJob::process); | ||||
55 | timer.start(); | ||||
56 | } | ||||
57 | | ||||
58 | const KIO::UDSEntryList &results() { return _results; } | ||||
59 | | ||||
60 | protected: | ||||
61 | bool doKill() Q_DECL_OVERRIDE { | ||||
62 | timer.stop(); | ||||
63 | return Job::doKill(); | ||||
64 | } | ||||
65 | | ||||
66 | private: | ||||
67 | void process() { | ||||
68 | if (!_it.hasNext()) | ||||
69 | emitResult(); | ||||
70 | QUrl url = _it.next(); | ||||
71 | | ||||
72 | if (url.scheme() == "virt") { // return a virtual directory in root | ||||
73 | //FIXME | ||||
74 | abort(); | ||||
75 | // QString path = url.path().mid(1); | ||||
76 | // if (path.isEmpty()) | ||||
77 | // path = '/'; | ||||
78 | // return new vfile(path, 0, "drwxr-xr-x", time(0), false, false, getuid(), getgid(), | ||||
79 | // "inode/directory", "", 0, -1, url); | ||||
80 | } | ||||
81 | | ||||
82 | const QUrl directory = url.adjusted(QUrl::RemoveFilename); | ||||
83 | | ||||
84 | //FIXME | ||||
85 | // if (url.isLocalFile()) { | ||||
86 | // QFileInfo file(url.path()); | ||||
87 | // return file.exists() ? vfs::createLocalVFile(url.fileName(), directory.path(), true) : 0; | ||||
88 | // } | ||||
89 | | ||||
90 | KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo); | ||||
91 | bool res = addSubjob(statJob); | ||||
92 | assert(res); | ||||
93 | | ||||
94 | connect(statJob, &KIO::Job::result, this, [=] (KJob*) { | ||||
95 | if (!statJob->error()) | ||||
96 | _results << statJob->statResult(); | ||||
97 | if (_it.hasNext()) | ||||
98 | timer.start(); | ||||
99 | else | ||||
100 | emitResult(); | ||||
101 | }); | ||||
102 | } | ||||
103 | | ||||
104 | QListIterator<QUrl> _it; | ||||
105 | KIO::UDSEntryList _results; | ||||
106 | QTimer timer; | ||||
107 | }; | ||||
108 | | ||||
46 | QHash<QString, QList<QUrl> *> virt_vfs::_virtVfsDict; | 109 | QHash<QString, QList<QUrl> *> virt_vfs::_virtVfsDict; | ||
47 | QHash<QString, QString> virt_vfs::_metaInfoDict; | 110 | QHash<QString, QString> virt_vfs::_metaInfoDict; | ||
48 | 111 | | |||
Context not available. | |||||
258 | return true; | 321 | return true; | ||
259 | } | 322 | } | ||
260 | 323 | | |||
324 | bool virt_vfs::startRefreshInternal(const QUrl &directory, bool /*showHidden*/) | ||||
325 | { | ||||
326 | _currentDirectory = cleanUrl(directory); | ||||
327 | _currentDirectory.setHost(""); | ||||
328 | // remove invalid subdirectories | ||||
329 | _currentDirectory.setPath("/" + _currentDirectory.path().remove('/')); | ||||
330 | | ||||
331 | if (!_virtVfsDict.contains(currentDir())) { | ||||
332 | //FIXME | ||||
333 | abort(); | ||||
334 | #if 0 | ||||
335 | // NOTE: silently creating non-existing directories here. The search and locate tools expect | ||||
336 | // this. (And user can enter some directory and it will be created). | ||||
337 | mkDirInternal(currentDir()); | ||||
338 | save(); | ||||
339 | // infinite loop possible | ||||
340 | //emit filesystemChanged(currentDirectory()); | ||||
341 | return true; | ||||
342 | #endif | ||||
343 | } | ||||
344 | | ||||
345 | QList<QUrl> *urlList = _virtVfsDict[currentDir()]; | ||||
346 | _metaInfo = _metaInfoDict[currentDir()]; | ||||
347 | | ||||
348 | StatJob *statJob = new StatJob(*urlList); | ||||
349 | connect(statJob, &KIO::Job::result, this, [=] (KJob*) { | ||||
350 | if (!statJob->error()) { | ||||
351 | for (const KIO::UDSEntry &entry : statJob->results()) { | ||||
352 | vfile *vfile = vfs::createVFileFromKIO(entry, _currentDirectory); | ||||
353 | if (vfile) | ||||
354 | addVfile(vfile); | ||||
355 | } | ||||
356 | refreshResult(true); | ||||
357 | save(); | ||||
358 | } | ||||
359 | else | ||||
360 | refreshResult(false); | ||||
361 | }); | ||||
362 | emit refreshJobStarted(statJob); | ||||
363 | | ||||
364 | return true; | ||||
365 | } | ||||
366 | | ||||
261 | // ==== private ==== | 367 | // ==== private ==== | ||
262 | 368 | | |||
263 | void virt_vfs::mkDirInternal(const QString &name) | 369 | void virt_vfs::mkDirInternal(const QString &name) | ||
Context not available. |