Skip to content

Commit

Permalink
BrowseFeature: ensure we show the real dir tree for removable devices…
Browse files Browse the repository at this point in the history
… ...

when Devices is expanded, not the cached state.
  • Loading branch information
ronso0 committed Mar 3, 2024
1 parent 83b4513 commit e6e66e1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/library/browse/browsefeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ void BrowseFeature::onLazyChildExpandation(const QModelIndex& index) {

// If we are on the special device node
if (path == DEVICE_NODE) {
#if defined(__LINUX__)
// Tell the model to remove the cached 'hasChildren' states of all sub-
// directories when we expand the Device node.
// This ensures we show the real dir tree. This is relevant when devices
// were unmounted, changed and mounted again.
m_pSidebarModel->removeChildDirsFromCache(removableDriveRootPaths());
#endif
folders = createRemovableDevices();
} else {
// we assume that the path refers to a folder in the file system
Expand Down
35 changes: 35 additions & 0 deletions src/library/browse/foldertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,38 @@ bool FolderTreeModel::directoryHasChildren(const QString& path) const {
m_directoryCache[path] = has_children;
return has_children;
}

void FolderTreeModel::removeChildDirsFromCache(const QStringList& rootPaths) {
// PerformanceTimer time;
// const auto start = time.elapsed();
if (rootPaths.isEmpty()) {
return;
}

// Just a quick check that prevents iterating the cache pointlessly
for (const auto& rootPath : rootPaths) {
VERIFY_OR_DEBUG_ASSERT(!rootPath.isEmpty()) {
// List contains at least one non-empty path
break;
}
}

// int checked = 0;
// int removed = 0;
QHashIterator<QString, bool> it(m_directoryCache);
while (it.hasNext()) {
it.next();
// checked++;
const QString cachedPath = it.key();
for (const auto& rootPath : rootPaths) {
if (!rootPath.isEmpty() && cachedPath.startsWith(rootPath)) {
m_directoryCache.remove(cachedPath);
// removed++;
}
}
}

// qWarning() << " checked:" << checked << "| removed:" << removed;
// qWarning() << " elapsed:" << mixxx::Duration(time.elapsed() -
// start).debugMicrosWithUnit();
}
1 change: 1 addition & 0 deletions src/library/browse/foldertreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ class FolderTreeModel : public TreeItemModel {
// Note: this means we won't see directory tree changes after the initial
// tree population after first expansion. I.e. newly added directories won't
// be displayed and removed dirs will remain in the sidebar tree.
// removeChildDirsFromCache() can be used to reset selected directories.
mutable QHash<QString, bool> m_directoryCache;
};

0 comments on commit e6e66e1

Please sign in to comment.