Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/project/filemanagerlistjob.cpp
Show All 12 Lines | 1 | /* This file is part of KDevelop | |||
---|---|---|---|---|---|
13 | 13 | | |||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "filemanagerlistjob.h" | 20 | #include "filemanagerlistjob.h" | ||
21 | #include "projectwatcher.h" | ||||
21 | 22 | | |||
22 | #include <interfaces/iproject.h> | 23 | #include <interfaces/iproject.h> | ||
23 | #include <project/projectmodel.h> | 24 | #include <project/projectmodel.h> | ||
24 | 25 | | |||
25 | #include "path.h" | 26 | #include "path.h" | ||
26 | #include "debug.h" | 27 | #include "debug.h" | ||
27 | 28 | | |||
28 | #include <QtConcurrentRun> | 29 | #include <QtConcurrentRun> | ||
29 | #include <QDir> | 30 | #include <QDir> | ||
30 | 31 | | |||
32 | #include <KDirWatch> | ||||
33 | | ||||
31 | using namespace KDevelop; | 34 | using namespace KDevelop; | ||
32 | 35 | | |||
33 | FileManagerListJob::FileManagerListJob(ProjectFolderItem* item) | 36 | FileManagerListJob::FileManagerListJob(ProjectFolderItem* item, ProjectWatcher* watcher) | ||
34 | : KIO::Job(), m_item(item), m_aborted(false) | 37 | : KIO::Job(), m_item(item), m_aborted(false), m_watcher(watcher) | ||
35 | { | 38 | { | ||
36 | qRegisterMetaType<KIO::UDSEntryList>("KIO::UDSEntryList"); | 39 | qRegisterMetaType<KIO::UDSEntryList>("KIO::UDSEntryList"); | ||
37 | qRegisterMetaType<KIO::Job*>(); | 40 | qRegisterMetaType<KIO::Job*>(); | ||
38 | qRegisterMetaType<KJob*>(); | 41 | qRegisterMetaType<KJob*>(); | ||
39 | 42 | | |||
mwolff: allocates memory for no apparent gain, remove? or just use the project name, that and the class… | |||||
it doesn't even have the intended effect (I hoped to be able identify the thread by name). I guess I forgot to remove it. rjvbb: it doesn't even have the intended effect (I hoped to be able identify the thread by name). I… | |||||
40 | /* the following line is not an error in judgment, apparently starting a | 43 | /* the following line is not an error in judgment, apparently starting a | ||
41 | * listJob while the previous one hasn't self-destructed takes a lot of time, | 44 | * listJob while the previous one hasn't self-destructed takes a lot of time, | ||
42 | * so we give the job a chance to selfdestruct first */ | 45 | * so we give the job a chance to selfdestruct first */ | ||
43 | connect( this, &FileManagerListJob::nextJob, this, &FileManagerListJob::startNextJob, Qt::QueuedConnection ); | 46 | connect( this, &FileManagerListJob::nextJob, this, &FileManagerListJob::startNextJob, Qt::QueuedConnection ); | ||
44 | 47 | | |||
45 | addSubDir(item); | 48 | addSubDir(item); | ||
46 | 49 | | |||
47 | #ifdef TIME_IMPORT_JOB | 50 | #ifdef TIME_IMPORT_JOB | ||
Show All 20 Lines | |||||
68 | } | 71 | } | ||
69 | 72 | | |||
70 | void FileManagerListJob::slotEntries(KIO::Job* job, const KIO::UDSEntryList& entriesIn) | 73 | void FileManagerListJob::slotEntries(KIO::Job* job, const KIO::UDSEntryList& entriesIn) | ||
71 | { | 74 | { | ||
72 | Q_UNUSED(job); | 75 | Q_UNUSED(job); | ||
73 | entryList.append(entriesIn); | 76 | entryList.append(entriesIn); | ||
74 | } | 77 | } | ||
75 | 78 | | |||
76 | void FileManagerListJob::startNextJob() | 79 | void FileManagerListJob::startNextJob() | ||
mwolff: remove, always watch dirs | |||||
77 | { | 80 | { | ||
78 | if ( m_listQueue.isEmpty() || m_aborted ) { | 81 | if ( m_listQueue.isEmpty() || m_aborted ) { | ||
79 | return; | 82 | return; | ||
80 | } | 83 | } | ||
81 | 84 | | |||
82 | #ifdef TIME_IMPORT_JOB | 85 | #ifdef TIME_IMPORT_JOB | ||
83 | m_subTimer.start(); | 86 | m_subTimer.start(); | ||
84 | #endif | 87 | #endif | ||
85 | 88 | | |||
86 | m_item = m_listQueue.dequeue(); | 89 | m_item = m_listQueue.dequeue(); | ||
87 | if (m_item->path().isLocalFile()) { | 90 | if (m_item->path().isLocalFile()) { | ||
88 | // optimized version for local projects using QDir directly | 91 | // optimized version for local projects using QDir directly | ||
89 | QtConcurrent::run([this] (const Path& path) { | 92 | QtConcurrent::run([this] (const Path& path) { | ||
90 | if (m_aborted) { | 93 | if (m_aborted) { | ||
91 | return; | 94 | return; | ||
92 | } | 95 | } | ||
93 | QDir dir(path.toLocalFile()); | 96 | QDir dir(path.toLocalFile()); | ||
94 | const auto entries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden); | 97 | const auto entries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden); | ||
95 | if (m_aborted) { | 98 | if (m_aborted) { | ||
96 | return; | 99 | return; | ||
97 | } | 100 | } | ||
101 | m_watcher->addDir(path.toLocalFile()); | ||||
98 | KIO::UDSEntryList results; | 102 | KIO::UDSEntryList results; | ||
99 | std::transform(entries.begin(), entries.end(), std::back_inserter(results), [] (const QFileInfo& info) -> KIO::UDSEntry { | 103 | std::transform(entries.begin(), entries.end(), std::back_inserter(results), [this] (const QFileInfo& info) -> KIO::UDSEntry { | ||
100 | KIO::UDSEntry entry; | 104 | KIO::UDSEntry entry; | ||
101 | entry.insert(KIO::UDSEntry::UDS_NAME, info.fileName()); | 105 | entry.insert(KIO::UDSEntry::UDS_NAME, info.fileName()); | ||
102 | if (info.isDir()) { | 106 | if (info.isDir()) { | ||
103 | entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, QT_STAT_DIR); | 107 | entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, QT_STAT_DIR); | ||
108 | m_watcher->addDir(info.absoluteFilePath()); | ||||
aren't you adding the same dir twice now? i.e. once here, and once above when the dir gets listed itself? mwolff: aren't you adding the same dir twice now? i.e. once here, and once above when the dir gets… | |||||
Did I misunderstand, doesn't this loop add the contents of the folder at path? rjvbb: Did I misunderstand, doesn't this loop add the contents of the folder at `path`? | |||||
Yes, you did. This is a std::transform. It just creates an UDSEntry from a QFileInfo. The former is then handled from handleResults. mwolff: Yes, you did. This is a `std::transform`. It just creates an `UDSEntry` from a `QFileInfo`. The… | |||||
104 | } | 109 | } | ||
105 | if (info.isSymLink()) { | 110 | if (info.isSymLink()) { | ||
106 | entry.insert(KIO::UDSEntry::UDS_LINK_DEST, info.symLinkTarget()); | 111 | entry.insert(KIO::UDSEntry::UDS_LINK_DEST, info.symLinkTarget()); | ||
107 | } | 112 | } | ||
108 | return entry; | 113 | return entry; | ||
109 | }); | 114 | }); | ||
110 | QMetaObject::invokeMethod(this, "handleResults", Q_ARG(KIO::UDSEntryList, results)); | 115 | QMetaObject::invokeMethod(this, "handleResults", Q_ARG(KIO::UDSEntryList, results)); | ||
111 | }, m_item->path()); | 116 | }, m_item->path()); | ||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |
allocates memory for no apparent gain, remove? or just use the project name, that and the class name is enough debug info