diff --git a/krusader/FileSystem/filesystem.h b/krusader/FileSystem/filesystem.h --- a/krusader/FileSystem/filesystem.h +++ b/krusader/FileSystem/filesystem.h @@ -44,6 +44,7 @@ #include #include +#include #include "fileitem.h" #include "krquery.h" @@ -233,8 +234,8 @@ FileItemDict _fileItems; // the list of files in the current dictionary // used in the calcSpace function - bool *_calcKdsBusy; - bool _calcStatBusy; + KIO::DirectorySizeJob *_dirSizeJob; + QTimer *_dirSizeUpdateTimer; KIO::UDSEntry _calcEntry; KIO::filesize_t *_calcKdsTotalSize; unsigned long *_calcKdsTotalFiles; diff --git a/krusader/FileSystem/filesystem.cpp b/krusader/FileSystem/filesystem.cpp --- a/krusader/FileSystem/filesystem.cpp +++ b/krusader/FileSystem/filesystem.cpp @@ -43,7 +43,6 @@ #include #include -#include #include #include "../defaults.h" @@ -269,27 +268,22 @@ } } -// TODO called from another thread, creating KIO jobs does not work here void FileSystem::calcSpaceKIO(const QUrl &url, KIO::filesize_t *totalSize, unsigned long *totalFiles, unsigned long *totalDirs, bool *stop) { - return; - if (stop && *stop) return; - _calcKdsBusy = stop; _calcKdsTotalSize = totalSize; _calcKdsTotalFiles = totalFiles; _calcKdsTotalDirs = totalDirs; - _calcStatBusy = true; - KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo); // thread problem here + KIO::StatJob *statJob = KIO::stat(url, KIO::HideProgressInfo); connect(statJob, &KIO::Job::result, this, &FileSystem::slotCalcStatResult); - while (!(*stop) && _calcStatBusy) { - usleep(1000); - } + QEventLoop eventLoop; + connect(statJob, &KJob::finished, &eventLoop, &QEventLoop::quit); + eventLoop.exec(); // blocking until quit() if (_calcEntry.count() == 0) return; // statJob failed @@ -301,13 +295,13 @@ return; } + // URL should be a directory + KIO::DirectorySizeJob *directorySizeJob = KIO::directorySize(url); connect(directorySizeJob, &KIO::Job::result, this, &FileSystem::slotCalcKdsResult); - while (!(*stop)) { - // we are in a separate thread - so sleeping is OK - usleep(1000); - } + connect(directorySizeJob, &KJob::finished, &eventLoop, &QEventLoop::quit); + eventLoop.exec(); // blocking until quit() } FileItem *FileSystem::createLocalFileItem(const QString &name, const QString &directory, bool virt) @@ -406,13 +400,11 @@ *_calcKdsTotalFiles += kds->totalFiles(); *_calcKdsTotalDirs += kds->totalSubdirs(); } - *_calcKdsBusy = true; } void FileSystem::slotCalcStatResult(KJob *job) { _calcEntry = job->error() ? KIO::UDSEntry() : static_cast(job)->statResult(); - _calcStatBusy = false; } // ==== private ====