File indexing completed on 2024-04-28 04:37:03

0001 /*
0002     SPDX-FileCopyrightText: 2009 Radu Benea <radub82@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_FILEMANAGERLISTJOB_H
0008 #define KDEVPLATFORM_FILEMANAGERLISTJOB_H
0009 
0010 #include <KIO/UDSEntry>
0011 #include <KJob>
0012 
0013 #include <QFuture>
0014 #include <QQueue>
0015 
0016 #include <atomic>
0017 
0018 // uncomment to time import jobs
0019 // #define TIME_IMPORT_JOB
0020 
0021 #ifdef TIME_IMPORT_JOB
0022 #include <QElapsedTimer>
0023 #endif
0024 
0025 
0026 namespace KDevelop
0027 {
0028 class ProjectFolderItem;
0029 class ProjectBaseItem;
0030 
0031 class FileManagerListJob : public KJob
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     explicit FileManagerListJob(ProjectFolderItem* item);
0037     virtual ~FileManagerListJob();
0038 
0039     void addSubDir(ProjectFolderItem* item);
0040     void handleRemovedItem(ProjectBaseItem* item);
0041 
0042     void start() override;
0043 
0044 Q_SIGNALS:
0045     void entries(FileManagerListJob* job, ProjectFolderItem* baseItem,
0046                  const KIO::UDSEntryList& entries);
0047     void nextJob();
0048 
0049 protected:
0050     bool doKill() override;
0051 
0052 private Q_SLOTS:
0053     void remoteFolderSubjobEntriesFound(KJob* job, const KIO::UDSEntryList& foundEntries);
0054     void remoteFolderSubjobFinished(KJob* job);
0055     void handleResults(const KIO::UDSEntryList& entries);
0056     void startNextJob();
0057 
0058 private:
0059     bool isCanceled() const;
0060 
0061     QQueue<ProjectFolderItem*> m_listQueue;
0062     /// current base dir
0063     ProjectFolderItem* m_item;
0064 
0065     std::atomic<bool> m_canceled = false;
0066 
0067     // This data is used when the currently processed folder is remote.
0068     KJob* m_remoteFolderSubjob = nullptr;
0069     KIO::UDSEntryList entryList;
0070 
0071     // This data is used when the currently processed folder is local.
0072     QFuture<void> m_localFolderFuture;
0073 
0074 #ifdef TIME_IMPORT_JOB
0075     QElapsedTimer m_timer;
0076     QElapsedTimer m_subTimer;
0077     qint64 m_subWaited = 0;
0078 #endif
0079 };
0080 
0081 }
0082 
0083 #endif // KDEVPLATFORM_FILEMANAGERLISTJOB_H