[haiku-commits] r40108 - haiku/trunk/src/preferences/virtualmemory

  • From: leavengood@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 4 Jan 2011 16:46:47 +0100 (CET)

Author: leavengood
Date: 2011-01-04 16:46:45 +0100 (Tue, 04 Jan 2011)
New Revision: 40108
Changeset: http://dev.haiku-os.org/changeset/40108

Modified:
   haiku/trunk/src/preferences/virtualmemory/Settings.cpp
   haiku/trunk/src/preferences/virtualmemory/Settings.h
   haiku/trunk/src/preferences/virtualmemory/SettingsWindow.cpp
   haiku/trunk/src/preferences/virtualmemory/SettingsWindow.h
Log:
Fix style violations and a few other issues that were pointed out. Thanks!

Also moved private methods to the bottom of source files.


Modified: haiku/trunk/src/preferences/virtualmemory/Settings.cpp
===================================================================
--- haiku/trunk/src/preferences/virtualmemory/Settings.cpp      2011-01-04 
11:03:31 UTC (rev 40107)
+++ haiku/trunk/src/preferences/virtualmemory/Settings.cpp      2011-01-04 
15:46:45 UTC (rev 40108)
@@ -22,28 +22,82 @@
 
 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;
 
        BPath path;
@@ -61,7 +115,7 @@
 
 
 void
-Settings::WriteWindowSettings()
+Settings::_WriteWindowSettings()
 {
        if (!fPositionUpdated)
                return;
@@ -79,19 +133,8 @@
 
 
 void
-Settings::SetWindowPosition(BPoint position)
+Settings::_ReadSwapSettings()
 {
-       if (position == fWindowPosition)
-               return;
-
-       fWindowPosition = position;
-       fPositionUpdated = true;
-}
-
-
-void
-Settings::ReadSwapSettings()
-{
        void* settings = load_driver_settings(kVirtualMemorySettings);
        if (settings != NULL) {
                SetSwapEnabled(get_driver_boolean_parameter(settings, "vm", 
false, false));
@@ -122,7 +165,7 @@
 #endif
                unload_driver_settings(settings);
        } else
-               SetSwapNull();
+               _SetSwapNull();
 
 #ifndef SWAP_VOLUME_IMPLEMENTED
        BVolumeRoster volumeRoster;
@@ -136,7 +179,7 @@
 
 
 void
-Settings::WriteSwapSettings()
+Settings::_WriteSwapSettings()
 {      
        if (!IsRevertible())
                return;
@@ -173,33 +216,8 @@
 
 
 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);
        BVolumeRoster volumeRoster;
        BVolume temporaryVolume;
@@ -209,19 +227,3 @@
 }
 
 
-void
-Settings::RevertSwapChanges()
-{
-       fSwapEnabled = fInitialSwapEnabled;
-       fSwapSize = fInitialSwapSize;
-       fSwapVolume.SetTo(fInitialSwapVolume);
-}
-
-
-bool
-Settings::IsRevertible()
-{
-       return fSwapEnabled != fInitialSwapEnabled
-               || fSwapSize != fInitialSwapSize
-               || fSwapVolume.Device() != fInitialSwapVolume;
-}

Modified: haiku/trunk/src/preferences/virtualmemory/Settings.h
===================================================================
--- haiku/trunk/src/preferences/virtualmemory/Settings.h        2011-01-04 
11:03:31 UTC (rev 40107)
+++ haiku/trunk/src/preferences/virtualmemory/Settings.h        2011-01-04 
15:46:45 UTC (rev 40108)
@@ -29,13 +29,14 @@
                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;
 
                bool            fSwapEnabled;

Modified: haiku/trunk/src/preferences/virtualmemory/SettingsWindow.cpp
===================================================================
--- haiku/trunk/src/preferences/virtualmemory/SettingsWindow.cpp        
2011-01-04 11:03:31 UTC (rev 40107)
+++ haiku/trunk/src/preferences/virtualmemory/SettingsWindow.cpp        
2011-01-04 15:46:45 UTC (rev 40108)
@@ -40,7 +40,7 @@
 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 @@
 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()
-{
-}
-
-
 SettingsWindow::SettingsWindow()
        :
        BWindow(BRect(0, 0, 269, 172), B_TRANSLATE("VirtualMemory"),
@@ -239,8 +236,8 @@
        // 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."),
@@ -265,6 +262,73 @@
 
 
 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()
 {
        if ((fSwapEnabledCheckBox->Value() != 0) != fSettings.SwapEnabled())
@@ -376,7 +440,7 @@
 
 
 void
-SettingsWindow::SetSwapDefaults()
+SettingsWindow::_SetSwapDefaults()
 {
        fSettings.SetSwapEnabled(true);
 
@@ -398,70 +462,3 @@
        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;
-}
-

Modified: haiku/trunk/src/preferences/virtualmemory/SettingsWindow.h
===================================================================
--- haiku/trunk/src/preferences/virtualmemory/SettingsWindow.h  2011-01-04 
11:03:31 UTC (rev 40107)
+++ haiku/trunk/src/preferences/virtualmemory/SettingsWindow.h  2011-01-04 
15:46:45 UTC (rev 40108)
@@ -27,7 +27,7 @@
        private:
                void _Update();
                status_t _GetSwapFileLimits(off_t& minSize, off_t& maxSize);
-               void SetSwapDefaults();
+               void _SetSwapDefaults();
 
                BCheckBox*              fSwapEnabledCheckBox;
                BSlider*                fSizeSlider;
@@ -37,7 +37,7 @@
                BMenuField*             fVolumeMenuField;
                Settings                fSettings;
                
-               bool fLocked;
+               bool                    fLocked;
 };
 
 #endif /* SETTINGS_WINDOW_H */


Other related posts:

  • » [haiku-commits] r40108 - haiku/trunk/src/preferences/virtualmemory - leavengood