More changes for #1746 from hamish with a few small changes by me.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40062 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -127,7 +127,6 @@ SettingsWindow::SettingsWindow()
|
|||||||
fSwapEnabledCheckBox = new BCheckBox("enable swap",
|
fSwapEnabledCheckBox = new BCheckBox("enable swap",
|
||||||
B_TRANSLATE("Enable virtual memory"),
|
B_TRANSLATE("Enable virtual memory"),
|
||||||
new BMessage(kMsgSwapEnabledUpdate));
|
new BMessage(kMsgSwapEnabledUpdate));
|
||||||
fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
|
|
||||||
|
|
||||||
BBox* box = new BBox("box", B_FOLLOW_LEFT_RIGHT);
|
BBox* box = new BBox("box", B_FOLLOW_LEFT_RIGHT);
|
||||||
box->SetLabel(fSwapEnabledCheckBox);
|
box->SetLabel(fSwapEnabledCheckBox);
|
||||||
@@ -163,18 +162,14 @@ SettingsWindow::SettingsWindow()
|
|||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
BMenuField* field = new BMenuField("devices", B_TRANSLATE("Use volume:"),
|
fVolumeMenuField = new BMenuField("devices", B_TRANSLATE("Use volume:"), menu);
|
||||||
menu);
|
|
||||||
field->SetEnabled(false);
|
|
||||||
|
|
||||||
off_t minSize, maxSize;
|
// When swap volume changing support is implemeneted, remove me:
|
||||||
_GetSwapFileLimits(minSize, maxSize);
|
fVolumeMenuField->SetEnabled(false);
|
||||||
|
|
||||||
fSizeSlider = new SizeSlider("size slider",
|
fSizeSlider = new SizeSlider("size slider",
|
||||||
B_TRANSLATE("Requested swap file size:"),
|
B_TRANSLATE("Requested swap file size:"), new BMessage(kMsgSliderUpdate),
|
||||||
new BMessage(kMsgSliderUpdate), minSize / kMegaByte, maxSize / kMegaByte,
|
0, 0, B_WILL_DRAW | B_FRAME_EVENTS);
|
||||||
B_WILL_DRAW | B_FRAME_EVENTS);
|
|
||||||
fSizeSlider->SetLimitLabels(B_TRANSLATE("999 MB"), B_TRANSLATE("999 MB"));
|
|
||||||
fSizeSlider->SetViewColor(255, 0, 255);
|
fSizeSlider->SetViewColor(255, 0, 255);
|
||||||
|
|
||||||
fWarningStringView = new BStringView("", "");
|
fWarningStringView = new BStringView("", "");
|
||||||
@@ -191,7 +186,7 @@ SettingsWindow::SettingsWindow()
|
|||||||
.AddGlue()
|
.AddGlue()
|
||||||
.End()
|
.End()
|
||||||
.AddGroup(B_HORIZONTAL)
|
.AddGroup(B_HORIZONTAL)
|
||||||
.Add(field)
|
.Add(fVolumeMenuField)
|
||||||
.AddGlue()
|
.AddGlue()
|
||||||
.End()
|
.End()
|
||||||
.Add(fSizeSlider)
|
.Add(fSizeSlider)
|
||||||
@@ -226,10 +221,9 @@ SettingsWindow::SettingsWindow()
|
|||||||
BScreen screen;
|
BScreen screen;
|
||||||
BRect screenFrame = screen.Frame();
|
BRect screenFrame = screen.Frame();
|
||||||
|
|
||||||
if (!screenFrame.Contains(fSettings.WindowPosition())) {
|
if (!screenFrame.Contains(fSettings.WindowPosition()))
|
||||||
// move on screen, centered
|
|
||||||
CenterOnScreen();
|
CenterOnScreen();
|
||||||
} else
|
else
|
||||||
MoveTo(fSettings.WindowPosition());
|
MoveTo(fSettings.WindowPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,12 +233,20 @@ SettingsWindow::~SettingsWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SettingsWindow::_Update()
|
SettingsWindow::_Update()
|
||||||
{
|
{
|
||||||
if ((fSwapEnabledCheckBox->Value() != 0) != fSettings.SwapEnabled())
|
if ((fSwapEnabledCheckBox->Value() != 0) != fSettings.SwapEnabled())
|
||||||
fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
|
fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
|
||||||
|
|
||||||
|
if (fSizeSlider->IsEnabled() != fSettings.SwapEnabled())
|
||||||
|
fSizeSlider->SetEnabled(fSettings.SwapEnabled());
|
||||||
|
|
||||||
|
#ifdef SWAP_VOLUME_IMPLEMENTED
|
||||||
|
if (fVolumeMenuField->IsEnabled() != fSettings.SwapEnabled())
|
||||||
|
fVolumeMenuField->SetEnabled(fSettings.SwapEnabled());
|
||||||
|
#endif
|
||||||
|
|
||||||
off_t minSize, maxSize;
|
off_t minSize, maxSize;
|
||||||
if (_GetSwapFileLimits(minSize, maxSize) == B_OK) {
|
if (_GetSwapFileLimits(minSize, maxSize) == B_OK) {
|
||||||
BString minLabel, maxLabel;
|
BString minLabel, maxLabel;
|
||||||
@@ -260,11 +262,18 @@ SettingsWindow::_Update()
|
|||||||
|
|
||||||
if (fSizeSlider->Value() != fSettings.SwapSize() / kMegaByte)
|
if (fSizeSlider->Value() != fSettings.SwapSize() / kMegaByte)
|
||||||
fSizeSlider->SetValue(fSettings.SwapSize() / kMegaByte);
|
fSizeSlider->SetValue(fSettings.SwapSize() / kMegaByte);
|
||||||
|
|
||||||
fSizeSlider->SetEnabled(true);
|
|
||||||
} else {
|
} else {
|
||||||
fSizeSlider->SetValue(minSize);
|
// Not enough space on volume for a swap file. Make UI inoperable.
|
||||||
|
fWarningStringView->SetText(
|
||||||
|
B_TRANSLATE("Insufficient space for a swap file."));
|
||||||
|
fSwapEnabledCheckBox->SetEnabled(false);
|
||||||
fSizeSlider->SetEnabled(false);
|
fSizeSlider->SetEnabled(false);
|
||||||
|
// When swap volume is implemented, we'll want to keep the volume
|
||||||
|
// menu field enabled so the user can get around the space issue
|
||||||
|
// by selecting a different volume.
|
||||||
|
#ifdef SWAP_VOLUME_IMPLEMENTED
|
||||||
|
fVolumeMenuField->SetEnabled(true);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: set volume
|
// ToDo: set volume
|
||||||
@@ -283,15 +292,13 @@ SettingsWindow::_Update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
|
SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
|
||||||
{
|
{
|
||||||
// minimum size is an arbitrarily chosen MB
|
|
||||||
minSize = kMegaByte;
|
minSize = kMegaByte;
|
||||||
|
|
||||||
// maximum size is the free space on the current volume
|
// maximum size is the free space on the current volume
|
||||||
// (minus some safety offset, depending on the disk size)
|
// (minus some safety offset, depending on the disk size)
|
||||||
|
|
||||||
off_t freeSpace = fSettings.SwapVolume().FreeBytes();
|
off_t freeSpace = fSettings.SwapVolume().FreeBytes();
|
||||||
off_t safetyFreeSpace = fSettings.SwapVolume().Capacity() / 100;
|
off_t safetyFreeSpace = fSettings.SwapVolume().Capacity() / 100;
|
||||||
if (safetyFreeSpace > 1024 * kMegaByte)
|
if (safetyFreeSpace > 1024 * kMegaByte)
|
||||||
@@ -299,7 +306,6 @@ SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
|
|||||||
|
|
||||||
// check if there already is a page file on this disk and
|
// check if there already is a page file on this disk and
|
||||||
// adjust the free space accordingly
|
// adjust the free space accordingly
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_COMMON_VAR_DIRECTORY, &path, false,
|
if (find_directory(B_COMMON_VAR_DIRECTORY, &path, false,
|
||||||
&fSettings.SwapVolume()) == B_OK) {
|
&fSettings.SwapVolume()) == B_OK) {
|
||||||
@@ -307,14 +313,18 @@ SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
|
|||||||
BEntry swap(path.Path());
|
BEntry swap(path.Path());
|
||||||
|
|
||||||
off_t size;
|
off_t size;
|
||||||
if (swap.GetSize(&size) == B_OK)
|
if (swap.GetSize(&size) == B_OK) {
|
||||||
|
// If swap file exists, forget about safety space;
|
||||||
|
// disk may have filled after creation of swap file.
|
||||||
|
safetyFreeSpace = 0;
|
||||||
freeSpace += size;
|
freeSpace += size;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
maxSize = freeSpace - safetyFreeSpace;
|
maxSize = freeSpace - safetyFreeSpace;
|
||||||
|
|
||||||
if (maxSize < minSize) {
|
if (maxSize < minSize) {
|
||||||
maxSize = minSize;
|
maxSize = 0;
|
||||||
|
minSize = 0;
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class BStringView;
|
|||||||
class BCheckBox;
|
class BCheckBox;
|
||||||
class BSlider;
|
class BSlider;
|
||||||
class BButton;
|
class BButton;
|
||||||
|
class BMenuField;
|
||||||
|
|
||||||
class SettingsWindow : public BWindow {
|
class SettingsWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
@@ -33,7 +33,7 @@ class SettingsWindow : public BWindow {
|
|||||||
BButton* fDefaultsButton;
|
BButton* fDefaultsButton;
|
||||||
BButton* fRevertButton;
|
BButton* fRevertButton;
|
||||||
BStringView* fWarningStringView;
|
BStringView* fWarningStringView;
|
||||||
|
BMenuField* fVolumeMenuField;
|
||||||
Settings fSettings;
|
Settings fSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user