Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/foldermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,13 @@ void FolderModel::summarize(Entry &entry, bool showHidden) {
}
}

int FolderModel::itemCount(const QString &folder, bool showHidden) {
int FolderModel::itemCount(const QString &folder, bool showHidden, const std::function<bool()> &stop) {
int count = 0;
for (QDirIterator it(folder, entryFilters(showHidden)); it.hasNext(); it.next())
for (QDirIterator it(folder, entryFilters(showHidden)); it.hasNext(); it.next()) {
if (stop && stop())
return -1;
++count;
}
return count;
}

Expand Down Expand Up @@ -527,10 +530,11 @@ void FolderModel::countFolders(quint64 generation) {
watcher->setFuture(QtConcurrent::run([folders, showHidden, latest, generation]() mutable {
// Overtaken (another folder, or a re-read), the counts would be
// thrown away, so it stops instead of listing every subfolder.
const auto overtaken = [&] { return *latest != generation; };
for (auto &folder : folders) {
if (*latest != generation)
if (overtaken())
break;
folder.second.itemCount = itemCount(folder.second.path, showHidden);
folder.second.itemCount = itemCount(folder.second.path, showHidden, overtaken);
}
return folders;
}));
Expand Down
4 changes: 2 additions & 2 deletions src/foldermodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ class FolderModel : public QAbstractListModel {
// A folder's item count and first pictures, for the preview window.
static void summarize(Entry &entry, bool showHidden);
// Only how many items a folder holds, for the folder counts, which have
// no use for its pictures or their order.
static int itemCount(const QString &folder, bool showHidden);
// no use for its pictures or their order. Stopped partway, it's -1 (unknown).
static int itemCount(const QString &folder, bool showHidden, const std::function<bool()> &stop = {});
static QStringList sortModes();
static void sortEntries(QVector<Entry> &entries, const QString &sort, const QLocale &locale = QLocale());
// The Recents view: a path that isn't a folder, listing recently used files.
Expand Down
3 changes: 3 additions & 0 deletions tests/folio_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ private slots:
// The folder counts just count, the hidden only when they show.
QCOMPARE(FolderModel::itemCount(dir.path(), false), 4);
QCOMPARE(FolderModel::itemCount(dir.path(), true), 5);
// Stopped partway through, a count is unknown rather than partial.
int checks = 0;
QCOMPARE(FolderModel::itemCount(dir.path(), false, [&] { return ++checks > 1; }), -1);
}

void folderModelLoadsInTheBackground()
Expand Down
Loading