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
This commit is contained in:
Philippe Saint-Pierre
2009-05-28 14:02:41 +00:00
parent 2cdc24e4ad
commit de81e90c0b
2 changed files with 46 additions and 21 deletions
+43 -21
View File
@@ -55,7 +55,7 @@ All rights reserved.
#include <MenuField.h> #include <MenuField.h>
#include <Mime.h> #include <Mime.h>
#include <NodeInfo.h> #include <NodeInfo.h>
#include <NodeMonitor.h> #include <PathMonitor.h>
#include <Path.h> #include <Path.h>
#include <PopUpMenu.h> #include <PopUpMenu.h>
#include <Region.h> #include <Region.h>
@@ -295,7 +295,7 @@ BInfoWindow::BInfoWindow(Model *model, int32 group_index, LockingList<BWindow> *
{ {
SetPulseRate(1000000); // we use pulse to check freebytes on volume 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 // window list is Locked by Tracker around this constructor
if (list) if (list)
@@ -388,9 +388,7 @@ BInfoWindow::Show()
if (!TargetModel()->IsVolume() && !TargetModel()->IsRoot()) { if (!TargetModel()->IsVolume() && !TargetModel()->IsRoot()) {
if (TargetModel()->IsDirectory()) { if (TargetModel()->IsDirectory()) {
// if this is a folder then spawn thread to calculate size // if this is a folder then spawn thread to calculate size
SetSizeStr("calculating" B_UTF8_ELLIPSIS); StartCalcSizeThread();
fCalcThreadID = spawn_thread(BInfoWindow::CalcSize, "CalcSize", B_NORMAL_PRIORITY, this);
resume_thread(fCalcThreadID);
} else { } else {
fAttributeView->SetLastSize(TargetModel()->StatBuf()->st_size); fAttributeView->SetLastSize(TargetModel()->StatBuf()->st_size);
@@ -451,19 +449,7 @@ BInfoWindow::MessageReceived(BMessage *message)
case kRecalculateSize: case kRecalculateSize:
{ {
fStopCalc = true; StartCalcSizeThread();
// 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);
break; break;
} }
@@ -537,11 +523,12 @@ BInfoWindow::MessageReceived(BMessage *message)
AttributeStreamFileNode newNode(TargetModel()->Node()); AttributeStreamFileNode newNode(TargetModel()->Node());
newNode << memoryNode; 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 // Tell the attribute view about this new model
fAttributeView->ReLinkTargetModel(TargetModel()); fAttributeView->ReLinkTargetModel(TargetModel());
// Start watching this again
StartWatchingNode();
} }
break; break;
} }
@@ -576,7 +563,14 @@ BInfoWindow::MessageReceived(BMessage *message)
FSEmptyTrash(); FSEmptyTrash();
break; break;
case B_NODE_MONITOR: case B_PATH_MONITOR:
if (!TargetModel()->IsVolume() && !TargetModel()->IsRoot()) {
if (TargetModel()->IsDirectory()) {
StartCalcSizeThread();
}
}
switch (message->FindInt32("opcode")) { switch (message->FindInt32("opcode")) {
case B_ENTRY_REMOVED: 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 int32
BInfoWindow::CalcSize(void *castToWindow) BInfoWindow::CalcSize(void *castToWindow)
{ {
+3
View File
@@ -71,6 +71,9 @@ class BInfoWindow : public BWindow {
virtual void Show(); virtual void Show();
private: private:
void StartWatchingNode();
void StartCalcSizeThread();
static BRect InfoWindowRect(bool displayingSymlink); static BRect InfoWindowRect(bool displayingSymlink);
static int32 CalcSize(void *); static int32 CalcSize(void *);