Fix style violations and a few other issues that were pointed out. Thanks!
Also moved private methods to the bottom of source files. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40108 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
59eb31ce66
commit
bdb262352e
@ -22,27 +22,81 @@
|
||||
|
||||
static const char* kWindowSettingsFile = "VM_data";
|
||||
static const char* kVirtualMemorySettings = "virtual_memory";
|
||||
static const int64 kMegaByte = 1048576;
|
||||
static const int64 kMegaByte = 1024 * 1024;
|
||||
|
||||
|
||||
Settings::Settings()
|
||||
:
|
||||
fPositionUpdated(false)
|
||||
{
|
||||
ReadWindowSettings();
|
||||
ReadSwapSettings();
|
||||
_ReadWindowSettings();
|
||||
_ReadSwapSettings();
|
||||
}
|
||||
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
WriteWindowSettings();
|
||||
WriteSwapSettings();
|
||||
_WriteWindowSettings();
|
||||
_WriteSwapSettings();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::ReadWindowSettings()
|
||||
Settings::SetWindowPosition(BPoint position)
|
||||
{
|
||||
if (position == fWindowPosition)
|
||||
return;
|
||||
|
||||
fWindowPosition = position;
|
||||
fPositionUpdated = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapEnabled(bool enabled)
|
||||
{
|
||||
fSwapEnabled = enabled;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapSize(off_t size)
|
||||
{
|
||||
fSwapSize = size;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapVolume(BVolume &volume)
|
||||
{
|
||||
if (volume.Device() == SwapVolume().Device()
|
||||
|| volume.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
fSwapVolume.SetTo(volume.Device());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::RevertSwapChanges()
|
||||
{
|
||||
fSwapEnabled = fInitialSwapEnabled;
|
||||
fSwapSize = fInitialSwapSize;
|
||||
fSwapVolume.SetTo(fInitialSwapVolume);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Settings::IsRevertible()
|
||||
{
|
||||
return fSwapEnabled != fInitialSwapEnabled
|
||||
|| fSwapSize != fInitialSwapSize
|
||||
|| fSwapVolume.Device() != fInitialSwapVolume;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::_ReadWindowSettings()
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
@ -61,7 +115,7 @@ Settings::ReadWindowSettings()
|
||||
|
||||
|
||||
void
|
||||
Settings::WriteWindowSettings()
|
||||
Settings::_WriteWindowSettings()
|
||||
{
|
||||
if (!fPositionUpdated)
|
||||
return;
|
||||
@ -79,18 +133,7 @@ Settings::WriteWindowSettings()
|
||||
|
||||
|
||||
void
|
||||
Settings::SetWindowPosition(BPoint position)
|
||||
{
|
||||
if (position == fWindowPosition)
|
||||
return;
|
||||
|
||||
fWindowPosition = position;
|
||||
fPositionUpdated = true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::ReadSwapSettings()
|
||||
Settings::_ReadSwapSettings()
|
||||
{
|
||||
void* settings = load_driver_settings(kVirtualMemorySettings);
|
||||
if (settings != NULL) {
|
||||
@ -122,7 +165,7 @@ Settings::ReadSwapSettings()
|
||||
#endif
|
||||
unload_driver_settings(settings);
|
||||
} else
|
||||
SetSwapNull();
|
||||
_SetSwapNull();
|
||||
|
||||
#ifndef SWAP_VOLUME_IMPLEMENTED
|
||||
BVolumeRoster volumeRoster;
|
||||
@ -136,7 +179,7 @@ Settings::ReadSwapSettings()
|
||||
|
||||
|
||||
void
|
||||
Settings::WriteSwapSettings()
|
||||
Settings::_WriteSwapSettings()
|
||||
{
|
||||
if (!IsRevertible())
|
||||
return;
|
||||
@ -173,32 +216,7 @@ Settings::WriteSwapSettings()
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapEnabled(bool enabled)
|
||||
{
|
||||
fSwapEnabled = enabled;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapSize(off_t size)
|
||||
{
|
||||
fSwapSize = size;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapVolume(BVolume &volume)
|
||||
{
|
||||
if (volume.Device() == SwapVolume().Device()
|
||||
|| volume.InitCheck() != B_OK)
|
||||
return;
|
||||
|
||||
fSwapVolume.SetTo(volume.Device());
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::SetSwapNull()
|
||||
Settings::_SetSwapNull()
|
||||
{
|
||||
SetSwapEnabled(false);
|
||||
BVolumeRoster volumeRoster;
|
||||
@ -209,19 +227,3 @@ Settings::SetSwapNull()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Settings::RevertSwapChanges()
|
||||
{
|
||||
fSwapEnabled = fInitialSwapEnabled;
|
||||
fSwapSize = fInitialSwapSize;
|
||||
fSwapVolume.SetTo(fInitialSwapVolume);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
Settings::IsRevertible()
|
||||
{
|
||||
return fSwapEnabled != fInitialSwapEnabled
|
||||
|| fSwapSize != fInitialSwapSize
|
||||
|| fSwapVolume.Device() != fInitialSwapVolume;
|
||||
}
|
||||
|
@ -29,12 +29,13 @@ class Settings {
|
||||
bool IsRevertible();
|
||||
|
||||
private:
|
||||
void SetSwapNull();
|
||||
void ReadWindowSettings();
|
||||
void WriteWindowSettings();
|
||||
void _ReadWindowSettings();
|
||||
void _WriteWindowSettings();
|
||||
|
||||
void ReadSwapSettings();
|
||||
void WriteSwapSettings();
|
||||
void _ReadSwapSettings();
|
||||
void _WriteSwapSettings();
|
||||
|
||||
void _SetSwapNull();
|
||||
|
||||
BPoint fWindowPosition;
|
||||
|
||||
|
@ -40,7 +40,7 @@ static const uint32 kMsgRevert = 'rvrt';
|
||||
static const uint32 kMsgSliderUpdate = 'slup';
|
||||
static const uint32 kMsgSwapEnabledUpdate = 'swen';
|
||||
static const uint32 kMsgVolumeSelected = 'vlsl';
|
||||
static const int64 kMegaByte = 1048576;
|
||||
static const int64 kMegaByte = 1024 * 1024;
|
||||
|
||||
|
||||
class SizeSlider : public BSlider {
|
||||
@ -112,7 +112,9 @@ SizeSlider::UpdateText() const
|
||||
class VolumeMenuItem : public BMenuItem {
|
||||
public:
|
||||
VolumeMenuItem(const char* label, BMessage* message, BVolume* volume);
|
||||
virtual ~VolumeMenuItem();
|
||||
BVolume* Volume() { return fVolume; }
|
||||
|
||||
private:
|
||||
BVolume* fVolume;
|
||||
};
|
||||
|
||||
@ -125,11 +127,6 @@ VolumeMenuItem::VolumeMenuItem(const char* label, BMessage* message,
|
||||
}
|
||||
|
||||
|
||||
VolumeMenuItem::~VolumeMenuItem()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SettingsWindow::SettingsWindow()
|
||||
:
|
||||
BWindow(BRect(0, 0, 269, 172), B_TRANSLATE("VirtualMemory"),
|
||||
@ -239,8 +236,8 @@ SettingsWindow::SettingsWindow()
|
||||
// Validate the volume specified in settings file
|
||||
status_t result = fSettings.SwapVolume().InitCheck();
|
||||
|
||||
if (result == B_NO_INIT) {
|
||||
int32 choice = (new BAlert("VirtualMemory", B_TRANSLATE(
|
||||
if (result != B_OK) {
|
||||
int32 choice = (new BAlert("VirtualMemory", B_TRANSLATE(
|
||||
"The swap volume specified in the settings file is invalid.\n"
|
||||
"You can keep the current setting or switch to the "
|
||||
"default swap volume."),
|
||||
@ -264,6 +261,73 @@ SettingsWindow::~SettingsWindow()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsWindow::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case kMsgRevert:
|
||||
fSettings.RevertSwapChanges();
|
||||
_Update();
|
||||
break;
|
||||
case kMsgDefaults:
|
||||
_SetSwapDefaults();
|
||||
_Update();
|
||||
break;
|
||||
case kMsgSliderUpdate:
|
||||
fSettings.SetSwapSize((off_t)fSizeSlider->Value() * kMegaByte);
|
||||
_Update();
|
||||
break;
|
||||
case kMsgVolumeSelected:
|
||||
fSettings.SetSwapVolume(*((VolumeMenuItem*)fVolumeMenuField->Menu()
|
||||
->FindMarked())->Volume());
|
||||
_Update();
|
||||
break;
|
||||
case kMsgSwapEnabledUpdate:
|
||||
{
|
||||
int32 value;
|
||||
if (message->FindInt32("be:value", &value) != B_OK)
|
||||
break;
|
||||
|
||||
if (value == 0) {
|
||||
// print out warning, give the user the time to think about it :)
|
||||
// ToDo: maybe we want to remove this possibility in the GUI
|
||||
// as Be did, but I thought a proper warning could be helpful
|
||||
// (for those that want to change that anyway)
|
||||
int32 choice = (new BAlert("VirtualMemory",
|
||||
B_TRANSLATE(
|
||||
"Disabling virtual memory will have unwanted effects on "
|
||||
"system stability once the memory is used up.\n"
|
||||
"Virtual memory does not affect system performance "
|
||||
"until this point is reached.\n\n"
|
||||
"Are you really sure you want to turn it off?"),
|
||||
B_TRANSLATE("Turn off"), B_TRANSLATE("Keep enabled"), NULL,
|
||||
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
|
||||
if (choice == 1) {
|
||||
fSwapEnabledCheckBox->SetValue(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fSettings.SetSwapEnabled(value != 0);
|
||||
_Update();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SettingsWindow::QuitRequested()
|
||||
{
|
||||
fSettings.SetWindowPosition(Frame().LeftTop());
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsWindow::_Update()
|
||||
{
|
||||
@ -376,7 +440,7 @@ SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
|
||||
|
||||
|
||||
void
|
||||
SettingsWindow::SetSwapDefaults()
|
||||
SettingsWindow::_SetSwapDefaults()
|
||||
{
|
||||
fSettings.SetSwapEnabled(true);
|
||||
|
||||
@ -398,70 +462,3 @@ SettingsWindow::SetSwapDefaults()
|
||||
fSettings.SetSwapSize(defaultSize);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SettingsWindow::MessageReceived(BMessage* message)
|
||||
{
|
||||
switch (message->what) {
|
||||
case kMsgRevert:
|
||||
fSettings.RevertSwapChanges();
|
||||
_Update();
|
||||
break;
|
||||
case kMsgDefaults:
|
||||
SetSwapDefaults();
|
||||
_Update();
|
||||
break;
|
||||
case kMsgSliderUpdate:
|
||||
fSettings.SetSwapSize((off_t)fSizeSlider->Value() * kMegaByte);
|
||||
_Update();
|
||||
break;
|
||||
case kMsgVolumeSelected:
|
||||
fSettings.SetSwapVolume(*((VolumeMenuItem*)fVolumeMenuField->Menu()
|
||||
->FindMarked())->fVolume);
|
||||
_Update();
|
||||
break;
|
||||
case kMsgSwapEnabledUpdate:
|
||||
{
|
||||
int32 value;
|
||||
if (message->FindInt32("be:value", &value) != B_OK)
|
||||
break;
|
||||
|
||||
if (value == 0) {
|
||||
// print out warning, give the user the time to think about it :)
|
||||
// ToDo: maybe we want to remove this possibility in the GUI
|
||||
// as Be did, but I thought a proper warning could be helpful
|
||||
// (for those that want to change that anyway)
|
||||
int32 choice = (new BAlert("VirtualMemory",
|
||||
B_TRANSLATE(
|
||||
"Disabling virtual memory will have unwanted effects on "
|
||||
"system stability once the memory is used up.\n"
|
||||
"Virtual memory does not affect system performance "
|
||||
"until this point is reached.\n\n"
|
||||
"Are you really sure you want to turn it off?"),
|
||||
B_TRANSLATE("Turn off"), B_TRANSLATE("Keep enabled"), NULL,
|
||||
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
|
||||
if (choice == 1) {
|
||||
fSwapEnabledCheckBox->SetValue(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fSettings.SetSwapEnabled(value != 0);
|
||||
_Update();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BWindow::MessageReceived(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
SettingsWindow::QuitRequested()
|
||||
{
|
||||
fSettings.SetWindowPosition(Frame().LeftTop());
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ class SettingsWindow : public BWindow {
|
||||
private:
|
||||
void _Update();
|
||||
status_t _GetSwapFileLimits(off_t& minSize, off_t& maxSize);
|
||||
void SetSwapDefaults();
|
||||
void _SetSwapDefaults();
|
||||
|
||||
BCheckBox* fSwapEnabledCheckBox;
|
||||
BSlider* fSizeSlider;
|
||||
@ -37,7 +37,7 @@ class SettingsWindow : public BWindow {
|
||||
BMenuField* fVolumeMenuField;
|
||||
Settings fSettings;
|
||||
|
||||
bool fLocked;
|
||||
bool fLocked;
|
||||
};
|
||||
|
||||
#endif /* SETTINGS_WINDOW_H */
|
||||
|
Loading…
x
Reference in New Issue
Block a user