Imported InfoWindow.cpp 1.14 from the OT repository: the "Disks" info window no

longer calculates the size by iterating over all files - it now just adds up the
disk capacities.
This fixes the userland part of bug #210 - the kernel part has already been
fixed earlier.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16599 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-03-06 10:58:05 +00:00
parent 3e3c4ddcce
commit 0cf867048b
+59 -43
View File
@@ -133,7 +133,8 @@ OpenParentAndSelectOriginal(const entry_ref *ref)
static BWindow * static BWindow *
OpenToolTipWindow(BRect rect, const char *name, const char *string, BMessenger target, BFont &font, BMessage *message) OpenToolTipWindow(BRect rect, const char *name, const char *string,
BMessenger target, BFont &font, BMessage *message)
{ {
BWindow *window = new BWindow(rect, name, B_BORDERED_WINDOW_LOOK, BWindow *window = new BWindow(rect, name, B_BORDERED_WINDOW_LOOK,
B_FLOATING_ALL_WINDOW_FEEL, B_FLOATING_ALL_WINDOW_FEEL,
@@ -157,17 +158,17 @@ OpenToolTipWindow(BRect rect, const char *name, const char *string, BMessenger t
BInfoWindow::BInfoWindow(Model *model, int32 group_index, LockingList<BWindow> *list) BInfoWindow::BInfoWindow(Model *model, int32 group_index, LockingList<BWindow> *list)
: BWindow(BInfoWindow::InfoWindowRect(false), : BWindow(BInfoWindow::InfoWindowRect(false),
"InfoWindow", B_TITLED_WINDOW, "InfoWindow", B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_CURRENT_WORKSPACE), B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_CURRENT_WORKSPACE),
fModel(model), fModel(model),
fStopCalc(false), fStopCalc(false),
fIndex(group_index), fIndex(group_index),
fCalcThreadID(-1), fCalcThreadID(-1),
fWindowList(list), fWindowList(list),
fPermissionsView(NULL), fPermissionsView(NULL),
fFilePanel(NULL), fFilePanel(NULL),
fFilePanelOpen(false) fFilePanelOpen(false)
{ {
SetPulseRate(1000000); // we use pulse to check freebytes on volume SetPulseRate(1000000); // we use pulse to check freebytes on volume
@@ -261,7 +262,7 @@ BInfoWindow::Show()
ResizeTo(windRect.Width(), windRect.Height()); ResizeTo(windRect.Width(), windRect.Height());
// volume case is handled by view // volume case is handled by view
if (!TargetModel()->IsVolume()) { 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); SetSizeStr("calculating" B_UTF8_ELLIPSIS);
@@ -586,7 +587,6 @@ BInfoWindow::CalcSize(void *castToWindow)
return B_ERROR; return B_ERROR;
window->SetSizeStr("Error calculating folder size."); window->SetSizeStr("Error calculating folder size.");
return B_ERROR; return B_ERROR;
} }
@@ -692,20 +692,20 @@ BInfoWindow::OpenFilePanel(const entry_ref *ref)
AttributeView::AttributeView(BRect rect, Model *model) AttributeView::AttributeView(BRect rect, Model *model)
: BView(rect, "attr_view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_PULSE_NEEDED), : BView(rect, "attr_view", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_PULSE_NEEDED),
fDivider(0), fDivider(0),
fPreferredAppMenu(NULL), fPreferredAppMenu(NULL),
fModel(model), fModel(model),
fIconModel(model), fIconModel(model),
fMouseDown(false), fMouseDown(false),
fDragging(false), fDragging(false),
fDoubleClick(false), fDoubleClick(false),
fTrackingState(no_track), fTrackingState(no_track),
fIsDropTarget(false), fIsDropTarget(false),
fTitleEditView(NULL), fTitleEditView(NULL),
fPathWindow(NULL), fPathWindow(NULL),
fLinkWindow(NULL), fLinkWindow(NULL),
fDescWindow(NULL) fDescWindow(NULL)
{ {
// Set view color to standard background grey // Set view color to standard background grey
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -1102,7 +1102,7 @@ AttributeView::MouseDown(BPoint point)
} else if (fTitleEditView) { } else if (fTitleEditView) {
FinishEditingTitle(true); FinishEditingTitle(true);
} else if (fSizeRect.Contains(point)) { } else if (fSizeRect.Contains(point)) {
if (fModel->IsDirectory() && !fModel->IsVolume()) { if (fModel->IsDirectory() && !fModel->IsVolume() && !fModel->IsRoot()) {
InvertRect(fSizeRect); InvertRect(fSizeRect);
fTrackingState = size_track; fTrackingState = size_track;
} else } else
@@ -1356,7 +1356,6 @@ AttributeView::OpenLinkTarget()
BInfoWindow *window = dynamic_cast<BInfoWindow *>(Window()); BInfoWindow *window = dynamic_cast<BInfoWindow *>(Window());
if (window) if (window)
window->OpenFilePanel(fModel->EntryRef()); window->OpenFilePanel(fModel->EntryRef());
} else { } else {
entry_ref ref; entry_ref ref;
entry.GetRef(&ref); entry.GetRef(&ref);
@@ -1409,14 +1408,28 @@ AttributeView::MouseUp(BPoint point)
void void
AttributeView::CheckAndSetSize() AttributeView::CheckAndSetSize()
{ {
if (fModel->IsVolume()) { if (fModel->IsVolume() || fModel->IsRoot()) {
BVolume volume(fModel->NodeRef()->device); off_t freeBytes = 0;
off_t freeBytes = volume.FreeBytes(); off_t capacity = 0;
if (fModel->IsVolume()) {
BVolume volume(fModel->NodeRef()->device);
freeBytes = volume.FreeBytes();
capacity = volume.Capacity();
} else {
// iterate over all volumes
BVolumeRoster volumeRoster;
BVolume volume;
while (volumeRoster.GetNextVolume(&volume) == B_OK) {
freeBytes += volume.FreeBytes();
capacity += volume.Capacity();
}
}
if (fFreeBytes == freeBytes) if (fFreeBytes == freeBytes)
return; return;
fFreeBytes = freeBytes; fFreeBytes = freeBytes;
off_t capacity = volume.Capacity();
char buffer[500]; char buffer[500];
if (capacity >= kGBSize) if (capacity >= kGBSize)
sprintf(buffer, "%.1f G", (float)capacity / kGBSize); sprintf(buffer, "%.1f G", (float)capacity / kGBSize);
@@ -1478,7 +1491,6 @@ AttributeView::MessageReceived(BMessage *message)
fModel->SetPreferredAppSignature(newSignature); fModel->SetPreferredAppSignature(newSignature);
nodeInfo.SetPreferredApp(newSignature); nodeInfo.SetPreferredApp(newSignature);
break; break;
} }
@@ -1557,7 +1569,7 @@ AttributeView::Draw(BRect)
// Capacity/size // Capacity/size
SetHighColor(kAttrTitleColor); SetHighColor(kAttrTitleColor);
if (fModel->IsVolume()) { if (fModel->IsVolume() || fModel->IsRoot()) {
MovePenTo(BPoint(fDivider - (StringWidth("Capacity:")), lineBase)); MovePenTo(BPoint(fDivider - (StringWidth("Capacity:")), lineBase));
DrawString("Capacity:"); DrawString("Capacity:");
} else { } else {
@@ -1909,13 +1921,15 @@ AttributeView::BuildContextMenu(BMenu *parent)
parent->AddItem(new BMenuItem("Empty Trash", new BMessage(kEmptyTrash))); parent->AddItem(new BMenuItem("Empty Trash", new BMessage(kEmptyTrash)));
BMenuItem *sizeItem = NULL; BMenuItem *sizeItem = NULL;
if (model.IsDirectory() && !model.IsVolume()) if (model.IsDirectory() && !model.IsVolume() && !model.IsRoot()) {
parent->AddItem(sizeItem = new BMenuItem("Recalculate Folder Size", parent->AddItem(sizeItem = new BMenuItem("Recalculate Folder Size",
new BMessage(kRecalculateSize))); new BMessage(kRecalculateSize)));
}
if (model.IsSymLink()) if (model.IsSymLink()) {
parent->AddItem(sizeItem = new BMenuItem("Set new link target", parent->AddItem(sizeItem = new BMenuItem("Set new link target",
new BMessage(kSetLinkTarget))); new BMessage(kSetLinkTarget)));
}
parent->AddItem(new BSeparatorItem()); parent->AddItem(new BSeparatorItem());
parent->AddItem(new BMenuItem("Permissions", new BMessage(kPermissionsSelected), 'P')); parent->AddItem(new BMenuItem("Permissions", new BMessage(kPermissionsSelected), 'P'));
@@ -1997,10 +2011,10 @@ AttributeView::SetSizeStr(const char *sizeStr)
TrackingView::TrackingView(BRect frame, const char *str, const BFont *font, BMessage *message) TrackingView::TrackingView(BRect frame, const char *str, const BFont *font, BMessage *message)
: BControl(frame, "trackingView", str, message, B_FOLLOW_ALL, B_WILL_DRAW), : BControl(frame, "trackingView", str, message, B_FOLLOW_ALL, B_WILL_DRAW),
fMouseDown(false), fMouseDown(false),
fMouseInView(false), fMouseInView(false),
fFont(*font) fFont(*font)
{ {
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
SetEventMask(B_POINTER_EVENTS, 0); SetEventMask(B_POINTER_EVENTS, 0);
@@ -2035,7 +2049,9 @@ void
TrackingView::MouseUp(BPoint) TrackingView::MouseUp(BPoint)
{ {
if (Message() != NULL) { if (Message() != NULL) {
if (fMouseInView) Invoke(); if (fMouseInView)
Invoke();
fMouseDown = false; fMouseDown = false;
Window()->Close(); Window()->Close();
} }