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

View File

@ -55,7 +55,7 @@ All rights reserved.
#include <MenuField.h>
#include <Mime.h>
#include <NodeInfo.h>
#include <NodeMonitor.h>
#include <PathMonitor.h>
#include <Path.h>
#include <PopUpMenu.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
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)
{

View File

@ -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 *);