From b0dbd12ce5cfe3b0bcb4c589dddeb16b217fd064 Mon Sep 17 00:00:00 2001 From: David Sansome Date: Fri, 23 Apr 2010 13:29:11 +0000 Subject: [PATCH] Notice when a directory is renamed within the collection while Clementine is running. Fixes issue #240 --- src/librarywatcher.cpp | 25 +++++++++++++++++++++++++ src/librarywatcher.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/librarywatcher.cpp b/src/librarywatcher.cpp index 6328512e8..ff600ba48 100644 --- a/src/librarywatcher.cpp +++ b/src/librarywatcher.cpp @@ -118,6 +118,21 @@ bool LibraryWatcher::ScanTransaction::HasSeenSubdir(const QString &path) { return false; } +SubdirectoryList LibraryWatcher::ScanTransaction::GetImmediateSubdirs(const QString &path) { + if (known_subdirs_dirty_) + SetKnownSubdirs(watcher_->backend_->SubdirsInDirectory(dir_)); + + SubdirectoryList ret; + foreach (const Subdirectory& subdir, known_subdirs_) { + if (subdir.path.left(subdir.path.lastIndexOf(QDir::separator())) == path && + subdir.mtime != 0) { + ret << subdir; + } + } + + return ret; +} + void LibraryWatcher::AddDirectory(const Directory& dir, const SubdirectoryList& subdirs) { DirData data; data.dir = dir; @@ -160,6 +175,16 @@ void LibraryWatcher::ScanSubdirectory( QStringList files_on_disk; SubdirectoryList my_new_subdirs; + // If a directory is moved then only its parent gets a changed notification, + // so we need to look and see if any of our children don't exist any more. + // If one has been removed, "rescan" it to get the deleted songs + SubdirectoryList previous_subdirs = t->GetImmediateSubdirs(path); + foreach (const Subdirectory& subdir, previous_subdirs) { + if (!QFile::exists(subdir.path)) { + ScanSubdirectory(subdir.path, subdir, t, true); + } + } + // First we "quickly" get a list of the files in the directory that we // think might be music. While we're here, we also look for new subdirectories // and possible album artwork. diff --git a/src/librarywatcher.h b/src/librarywatcher.h index 6822a14cc..88021e176 100644 --- a/src/librarywatcher.h +++ b/src/librarywatcher.h @@ -75,6 +75,7 @@ class LibraryWatcher : public QObject { SongList FindSongsInSubdirectory(const QString& path); bool HasSeenSubdir(const QString& path); void SetKnownSubdirs(const SubdirectoryList& subdirs); + SubdirectoryList GetImmediateSubdirs(const QString& path); int dir() const { return dir_; } bool is_incremental() const { return incremental_; }