mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 03:27:40 +01:00
Make the LibraryWatcher report on its progresss. Fixes issue #436
This commit is contained in:
parent
eb830051c8
commit
44d58482f0
@ -57,7 +57,7 @@ void TaskManager::SetTaskProgress(int id, int progress, int max) {
|
|||||||
|
|
||||||
Task& t = tasks_[id];
|
Task& t = tasks_[id];
|
||||||
t.progress = progress;
|
t.progress = progress;
|
||||||
if (max != -1)
|
if (max)
|
||||||
t.progress_max = max;
|
t.progress_max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +58,9 @@ LibraryWatcher::LibraryWatcher(QObject* parent)
|
|||||||
|
|
||||||
LibraryWatcher::ScanTransaction::ScanTransaction(LibraryWatcher* watcher,
|
LibraryWatcher::ScanTransaction::ScanTransaction(LibraryWatcher* watcher,
|
||||||
int dir, bool incremental)
|
int dir, bool incremental)
|
||||||
: dir_(dir),
|
: progress_(0),
|
||||||
|
progress_max_(0),
|
||||||
|
dir_(dir),
|
||||||
incremental_(incremental),
|
incremental_(incremental),
|
||||||
watcher_(watcher),
|
watcher_(watcher),
|
||||||
cached_songs_dirty_(true),
|
cached_songs_dirty_(true),
|
||||||
@ -94,6 +96,16 @@ LibraryWatcher::ScanTransaction::~ScanTransaction() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibraryWatcher::ScanTransaction::AddToProgress(int n) {
|
||||||
|
progress_ += n;
|
||||||
|
watcher_->task_manager_->SetTaskProgress(task_id_, progress_, progress_max_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryWatcher::ScanTransaction::AddToProgressMax(int n) {
|
||||||
|
progress_max_ += n;
|
||||||
|
watcher_->task_manager_->SetTaskProgress(task_id_, progress_, progress_max_);
|
||||||
|
}
|
||||||
|
|
||||||
SongList LibraryWatcher::ScanTransaction::FindSongsInSubdirectory(const QString &path) {
|
SongList LibraryWatcher::ScanTransaction::FindSongsInSubdirectory(const QString &path) {
|
||||||
if (cached_songs_dirty_) {
|
if (cached_songs_dirty_) {
|
||||||
cached_songs_ = watcher_->backend_->FindSongsInDirectory(dir_);
|
cached_songs_ = watcher_->backend_->FindSongsInDirectory(dir_);
|
||||||
@ -158,12 +170,14 @@ void LibraryWatcher::AddDirectory(const Directory& dir, const SubdirectoryList&
|
|||||||
// Scan it fully.
|
// Scan it fully.
|
||||||
ScanTransaction transaction(this, dir.id, false);
|
ScanTransaction transaction(this, dir.id, false);
|
||||||
transaction.SetKnownSubdirs(subdirs);
|
transaction.SetKnownSubdirs(subdirs);
|
||||||
|
transaction.AddToProgressMax(1);
|
||||||
ScanSubdirectory(dir.path, Subdirectory(), &transaction);
|
ScanSubdirectory(dir.path, Subdirectory(), &transaction);
|
||||||
} else {
|
} else {
|
||||||
// We can do an incremental scan - looking at the mtimes of each
|
// We can do an incremental scan - looking at the mtimes of each
|
||||||
// subdirectory and only rescan if the directory has changed.
|
// subdirectory and only rescan if the directory has changed.
|
||||||
ScanTransaction transaction(this, dir.id, true);
|
ScanTransaction transaction(this, dir.id, true);
|
||||||
transaction.SetKnownSubdirs(subdirs);
|
transaction.SetKnownSubdirs(subdirs);
|
||||||
|
transaction.AddToProgressMax(subdirs.count());
|
||||||
foreach (const Subdirectory& subdir, subdirs) {
|
foreach (const Subdirectory& subdir, subdirs) {
|
||||||
if (stop_requested_) return;
|
if (stop_requested_) return;
|
||||||
|
|
||||||
@ -184,6 +198,7 @@ void LibraryWatcher::ScanSubdirectory(
|
|||||||
if (!force_noincremental && t->is_incremental() &&
|
if (!force_noincremental && t->is_incremental() &&
|
||||||
subdir.mtime == path_info.lastModified().toTime_t()) {
|
subdir.mtime == path_info.lastModified().toTime_t()) {
|
||||||
// The directory hasn't changed since last time
|
// The directory hasn't changed since last time
|
||||||
|
t->AddToProgress(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,6 +212,7 @@ void LibraryWatcher::ScanSubdirectory(
|
|||||||
SubdirectoryList previous_subdirs = t->GetImmediateSubdirs(path);
|
SubdirectoryList previous_subdirs = t->GetImmediateSubdirs(path);
|
||||||
foreach (const Subdirectory& subdir, previous_subdirs) {
|
foreach (const Subdirectory& subdir, previous_subdirs) {
|
||||||
if (!QFile::exists(subdir.path) && subdir.path != path) {
|
if (!QFile::exists(subdir.path) && subdir.path != path) {
|
||||||
|
t->AddToProgressMax(1);
|
||||||
ScanSubdirectory(subdir.path, subdir, t, true);
|
ScanSubdirectory(subdir.path, subdir, t, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,7 +335,10 @@ void LibraryWatcher::ScanSubdirectory(
|
|||||||
else
|
else
|
||||||
t->touched_subdirs << updated_subdir;
|
t->touched_subdirs << updated_subdir;
|
||||||
|
|
||||||
|
t->AddToProgress(1);
|
||||||
|
|
||||||
// Recurse into the new subdirs that we found
|
// Recurse into the new subdirs that we found
|
||||||
|
t->AddToProgressMax(my_new_subdirs.count());
|
||||||
foreach (const Subdirectory& my_new_subdir, my_new_subdirs) {
|
foreach (const Subdirectory& my_new_subdir, my_new_subdirs) {
|
||||||
if (stop_requested_) return;
|
if (stop_requested_) return;
|
||||||
ScanSubdirectory(my_new_subdir.path, my_new_subdir, t, true);
|
ScanSubdirectory(my_new_subdir.path, my_new_subdir, t, true);
|
||||||
@ -378,6 +397,7 @@ void LibraryWatcher::RescanPathsNow() {
|
|||||||
foreach (int dir, rescan_queue_.keys()) {
|
foreach (int dir, rescan_queue_.keys()) {
|
||||||
if (stop_requested_) return;
|
if (stop_requested_) return;
|
||||||
ScanTransaction transaction(this, dir, false);
|
ScanTransaction transaction(this, dir, false);
|
||||||
|
transaction.AddToProgressMax(rescan_queue_[dir].count());
|
||||||
|
|
||||||
foreach (const QString& path, rescan_queue_[dir]) {
|
foreach (const QString& path, rescan_queue_[dir]) {
|
||||||
if (stop_requested_) return;
|
if (stop_requested_) return;
|
||||||
@ -445,6 +465,8 @@ void LibraryWatcher::IncrementalScanNow() {
|
|||||||
foreach (const DirData& data, watched_dirs_.values()) {
|
foreach (const DirData& data, watched_dirs_.values()) {
|
||||||
ScanTransaction transaction(this, data.dir.id, true);
|
ScanTransaction transaction(this, data.dir.id, true);
|
||||||
SubdirectoryList subdirs(transaction.GetAllSubdirs());
|
SubdirectoryList subdirs(transaction.GetAllSubdirs());
|
||||||
|
transaction.AddToProgressMax(subdirs.count());
|
||||||
|
|
||||||
foreach (const Subdirectory& subdir, subdirs) {
|
foreach (const Subdirectory& subdir, subdirs) {
|
||||||
if (stop_requested_) return;
|
if (stop_requested_) return;
|
||||||
|
|
||||||
|
@ -78,6 +78,9 @@ class LibraryWatcher : public QObject {
|
|||||||
SubdirectoryList GetImmediateSubdirs(const QString& path);
|
SubdirectoryList GetImmediateSubdirs(const QString& path);
|
||||||
SubdirectoryList GetAllSubdirs();
|
SubdirectoryList GetAllSubdirs();
|
||||||
|
|
||||||
|
void AddToProgress(int n = 1);
|
||||||
|
void AddToProgressMax(int n);
|
||||||
|
|
||||||
int dir() const { return dir_; }
|
int dir() const { return dir_; }
|
||||||
bool is_incremental() const { return incremental_; }
|
bool is_incremental() const { return incremental_; }
|
||||||
|
|
||||||
@ -92,6 +95,8 @@ class LibraryWatcher : public QObject {
|
|||||||
ScanTransaction& operator =(const ScanTransaction&) { return *this; }
|
ScanTransaction& operator =(const ScanTransaction&) { return *this; }
|
||||||
|
|
||||||
int task_id_;
|
int task_id_;
|
||||||
|
int progress_;
|
||||||
|
int progress_max_;
|
||||||
|
|
||||||
int dir_;
|
int dir_;
|
||||||
bool incremental_;
|
bool incremental_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user