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:
@@ -22,27 +22,81 @@
|
|||||||
|
|
||||||
static const char* kWindowSettingsFile = "VM_data";
|
static const char* kWindowSettingsFile = "VM_data";
|
||||||
static const char* kVirtualMemorySettings = "virtual_memory";
|
static const char* kVirtualMemorySettings = "virtual_memory";
|
||||||
static const int64 kMegaByte = 1048576;
|
static const int64 kMegaByte = 1024 * 1024;
|
||||||
|
|
||||||
|
|
||||||
Settings::Settings()
|
Settings::Settings()
|
||||||
:
|
:
|
||||||
fPositionUpdated(false)
|
fPositionUpdated(false)
|
||||||
{
|
{
|
||||||
ReadWindowSettings();
|
_ReadWindowSettings();
|
||||||
ReadSwapSettings();
|
_ReadSwapSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Settings::~Settings()
|
Settings::~Settings()
|
||||||
{
|
{
|
||||||
WriteWindowSettings();
|
_WriteWindowSettings();
|
||||||
WriteSwapSettings();
|
_WriteSwapSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
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;
|
bool success = false;
|
||||||
|
|
||||||
@@ -61,7 +115,7 @@ Settings::ReadWindowSettings()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Settings::WriteWindowSettings()
|
Settings::_WriteWindowSettings()
|
||||||
{
|
{
|
||||||
if (!fPositionUpdated)
|
if (!fPositionUpdated)
|
||||||
return;
|
return;
|
||||||
@@ -79,18 +133,7 @@ Settings::WriteWindowSettings()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Settings::SetWindowPosition(BPoint position)
|
Settings::_ReadSwapSettings()
|
||||||
{
|
|
||||||
if (position == fWindowPosition)
|
|
||||||
return;
|
|
||||||
|
|
||||||
fWindowPosition = position;
|
|
||||||
fPositionUpdated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Settings::ReadSwapSettings()
|
|
||||||
{
|
{
|
||||||
void* settings = load_driver_settings(kVirtualMemorySettings);
|
void* settings = load_driver_settings(kVirtualMemorySettings);
|
||||||
if (settings != NULL) {
|
if (settings != NULL) {
|
||||||
@@ -122,7 +165,7 @@ Settings::ReadSwapSettings()
|
|||||||
#endif
|
#endif
|
||||||
unload_driver_settings(settings);
|
unload_driver_settings(settings);
|
||||||
} else
|
} else
|
||||||
SetSwapNull();
|
_SetSwapNull();
|
||||||
|
|
||||||
#ifndef SWAP_VOLUME_IMPLEMENTED
|
#ifndef SWAP_VOLUME_IMPLEMENTED
|
||||||
BVolumeRoster volumeRoster;
|
BVolumeRoster volumeRoster;
|
||||||
@@ -136,7 +179,7 @@ Settings::ReadSwapSettings()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Settings::WriteSwapSettings()
|
Settings::_WriteSwapSettings()
|
||||||
{
|
{
|
||||||
if (!IsRevertible())
|
if (!IsRevertible())
|
||||||
return;
|
return;
|
||||||
@@ -173,32 +216,7 @@ Settings::WriteSwapSettings()
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Settings::SetSwapEnabled(bool enabled)
|
Settings::_SetSwapNull()
|
||||||
{
|
|
||||||
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()
|
|
||||||
{
|
{
|
||||||
SetSwapEnabled(false);
|
SetSwapEnabled(false);
|
||||||
BVolumeRoster volumeRoster;
|
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();
|
bool IsRevertible();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void SetSwapNull();
|
void _ReadWindowSettings();
|
||||||
void ReadWindowSettings();
|
void _WriteWindowSettings();
|
||||||
void WriteWindowSettings();
|
|
||||||
|
|
||||||
void ReadSwapSettings();
|
void _ReadSwapSettings();
|
||||||
void WriteSwapSettings();
|
void _WriteSwapSettings();
|
||||||
|
|
||||||
|
void _SetSwapNull();
|
||||||
|
|
||||||
BPoint fWindowPosition;
|
BPoint fWindowPosition;
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ static const uint32 kMsgRevert = 'rvrt';
|
|||||||
static const uint32 kMsgSliderUpdate = 'slup';
|
static const uint32 kMsgSliderUpdate = 'slup';
|
||||||
static const uint32 kMsgSwapEnabledUpdate = 'swen';
|
static const uint32 kMsgSwapEnabledUpdate = 'swen';
|
||||||
static const uint32 kMsgVolumeSelected = 'vlsl';
|
static const uint32 kMsgVolumeSelected = 'vlsl';
|
||||||
static const int64 kMegaByte = 1048576;
|
static const int64 kMegaByte = 1024 * 1024;
|
||||||
|
|
||||||
|
|
||||||
class SizeSlider : public BSlider {
|
class SizeSlider : public BSlider {
|
||||||
@@ -112,7 +112,9 @@ SizeSlider::UpdateText() const
|
|||||||
class VolumeMenuItem : public BMenuItem {
|
class VolumeMenuItem : public BMenuItem {
|
||||||
public:
|
public:
|
||||||
VolumeMenuItem(const char* label, BMessage* message, BVolume* volume);
|
VolumeMenuItem(const char* label, BMessage* message, BVolume* volume);
|
||||||
virtual ~VolumeMenuItem();
|
BVolume* Volume() { return fVolume; }
|
||||||
|
|
||||||
|
private:
|
||||||
BVolume* fVolume;
|
BVolume* fVolume;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -125,11 +127,6 @@ VolumeMenuItem::VolumeMenuItem(const char* label, BMessage* message,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
VolumeMenuItem::~VolumeMenuItem()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
SettingsWindow::SettingsWindow()
|
SettingsWindow::SettingsWindow()
|
||||||
:
|
:
|
||||||
BWindow(BRect(0, 0, 269, 172), B_TRANSLATE("VirtualMemory"),
|
BWindow(BRect(0, 0, 269, 172), B_TRANSLATE("VirtualMemory"),
|
||||||
@@ -239,8 +236,8 @@ SettingsWindow::SettingsWindow()
|
|||||||
// Validate the volume specified in settings file
|
// Validate the volume specified in settings file
|
||||||
status_t result = fSettings.SwapVolume().InitCheck();
|
status_t result = fSettings.SwapVolume().InitCheck();
|
||||||
|
|
||||||
if (result == B_NO_INIT) {
|
if (result != B_OK) {
|
||||||
int32 choice = (new BAlert("VirtualMemory", B_TRANSLATE(
|
int32 choice = (new BAlert("VirtualMemory", B_TRANSLATE(
|
||||||
"The swap volume specified in the settings file is invalid.\n"
|
"The swap volume specified in the settings file is invalid.\n"
|
||||||
"You can keep the current setting or switch to the "
|
"You can keep the current setting or switch to the "
|
||||||
"default swap volume."),
|
"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
|
void
|
||||||
SettingsWindow::_Update()
|
SettingsWindow::_Update()
|
||||||
{
|
{
|
||||||
@@ -376,7 +440,7 @@ SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SettingsWindow::SetSwapDefaults()
|
SettingsWindow::_SetSwapDefaults()
|
||||||
{
|
{
|
||||||
fSettings.SetSwapEnabled(true);
|
fSettings.SetSwapEnabled(true);
|
||||||
|
|
||||||
@@ -398,70 +462,3 @@ SettingsWindow::SetSwapDefaults()
|
|||||||
fSettings.SetSwapSize(defaultSize);
|
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:
|
private:
|
||||||
void _Update();
|
void _Update();
|
||||||
status_t _GetSwapFileLimits(off_t& minSize, off_t& maxSize);
|
status_t _GetSwapFileLimits(off_t& minSize, off_t& maxSize);
|
||||||
void SetSwapDefaults();
|
void _SetSwapDefaults();
|
||||||
|
|
||||||
BCheckBox* fSwapEnabledCheckBox;
|
BCheckBox* fSwapEnabledCheckBox;
|
||||||
BSlider* fSizeSlider;
|
BSlider* fSizeSlider;
|
||||||
@@ -37,7 +37,7 @@ class SettingsWindow : public BWindow {
|
|||||||
BMenuField* fVolumeMenuField;
|
BMenuField* fVolumeMenuField;
|
||||||
Settings fSettings;
|
Settings fSettings;
|
||||||
|
|
||||||
bool fLocked;
|
bool fLocked;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* SETTINGS_WINDOW_H */
|
#endif /* SETTINGS_WINDOW_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user