From de81e90c0bdc04e5b59e55218d085b923edd7172 Mon Sep 17 00:00:00 2001 From: Philippe Saint-Pierre Date: Thu, 28 May 2009 14:02:41 +0000 Subject: [PATCH] Replaces NodeMonitor by PathMonitor in the InfoWindow to update the calculated size of the directory when a change happen. This implement the suggestion in ticket #2868. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30894 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/tracker/InfoWindow.cpp | 64 ++++++++++++++++++++++----------- src/kits/tracker/InfoWindow.h | 3 ++ 2 files changed, 46 insertions(+), 21 deletions(-) diff --git a/src/kits/tracker/InfoWindow.cpp b/src/kits/tracker/InfoWindow.cpp index 285e8dfb35..d9300168eb 100644 --- a/src/kits/tracker/InfoWindow.cpp +++ b/src/kits/tracker/InfoWindow.cpp @@ -55,7 +55,7 @@ All rights reserved. #include #include #include -#include +#include #include #include #include @@ -295,7 +295,7 @@ BInfoWindow::BInfoWindow(Model *model, int32 group_index, LockingList * { SetPulseRate(1000000); // we use pulse to check freebytes on volume - TTracker::WatchNode(model->NodeRef(), B_WATCH_ALL | B_WATCH_MOUNT, this); + StartWatchingNode(); // window list is Locked by Tracker around this constructor if (list) @@ -388,9 +388,7 @@ BInfoWindow::Show() if (!TargetModel()->IsVolume() && !TargetModel()->IsRoot()) { if (TargetModel()->IsDirectory()) { // if this is a folder then spawn thread to calculate size - SetSizeStr("calculating" B_UTF8_ELLIPSIS); - fCalcThreadID = spawn_thread(BInfoWindow::CalcSize, "CalcSize", B_NORMAL_PRIORITY, this); - resume_thread(fCalcThreadID); + StartCalcSizeThread(); } else { fAttributeView->SetLastSize(TargetModel()->StatBuf()->st_size); @@ -451,19 +449,7 @@ BInfoWindow::MessageReceived(BMessage *message) case kRecalculateSize: { - fStopCalc = true; - - // Wait until any current CalcSize thread has terminated before - // starting a new one - status_t result; - wait_for_thread(fCalcThreadID, &result); - - // Start recalculating.. - fStopCalc = false; - SetSizeStr("calculating" B_UTF8_ELLIPSIS); - fCalcThreadID = spawn_thread(BInfoWindow::CalcSize, "CalcSize", B_NORMAL_PRIORITY, this); - resume_thread(fCalcThreadID); - + StartCalcSizeThread(); break; } @@ -537,11 +523,12 @@ BInfoWindow::MessageReceived(BMessage *message) AttributeStreamFileNode newNode(TargetModel()->Node()); newNode << memoryNode; - // Start watching this again - TTracker::WatchNode(TargetModel()->NodeRef(), B_WATCH_ALL | B_WATCH_MOUNT, this); // Tell the attribute view about this new model fAttributeView->ReLinkTargetModel(TargetModel()); + + // Start watching this again + StartWatchingNode(); } break; } @@ -576,7 +563,14 @@ BInfoWindow::MessageReceived(BMessage *message) FSEmptyTrash(); break; - case B_NODE_MONITOR: + case B_PATH_MONITOR: + + if (!TargetModel()->IsVolume() && !TargetModel()->IsRoot()) { + if (TargetModel()->IsDirectory()) { + StartCalcSizeThread(); + } + } + switch (message->FindInt32("opcode")) { case B_ENTRY_REMOVED: { @@ -694,6 +688,34 @@ BInfoWindow::GetSizeString(BString &result, off_t size, int32 fileCount) } +void +BInfoWindow::StartWatchingNode() +{ + BPath path; + fModel->GetPath(&path); + BPrivate::BPathMonitor::StartWatching(path.Path(), + B_WATCH_ALL | B_WATCH_RECURSIVELY | B_WATCH_MOUNT, this); +} + + +void +BInfoWindow::StartCalcSizeThread() +{ + fStopCalc = true; + // Wait until any current CalcSize thread has terminated before + // starting a new one + status_t result; + wait_for_thread(fCalcThreadID, &result); + + // Start recalculating.. + fStopCalc = false; + SetSizeStr("calculating" B_UTF8_ELLIPSIS); + fCalcThreadID = spawn_thread(BInfoWindow::CalcSize, "CalcSize", + B_NORMAL_PRIORITY, this); + resume_thread(fCalcThreadID); +} + + int32 BInfoWindow::CalcSize(void *castToWindow) { diff --git a/src/kits/tracker/InfoWindow.h b/src/kits/tracker/InfoWindow.h index b5d1df85bb..81f84318da 100644 --- a/src/kits/tracker/InfoWindow.h +++ b/src/kits/tracker/InfoWindow.h @@ -71,6 +71,9 @@ class BInfoWindow : public BWindow { virtual void Show(); private: + void StartWatchingNode(); + void StartCalcSizeThread(); + static BRect InfoWindowRect(bool displayingSymlink); static int32 CalcSize(void *);