[haiku-commits] haiku: hrev44621 - src/preferences/virtualmemory

  • From: kallisti5@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 7 Sep 2012 19:59:06 +0200 (CEST)

hrev44621 adds 2 changesets to branch 'master'
old head: f18cace156ce13abb2d7b2e74f8760372fdc7fe0
new head: 59c595739c6e9469a43529aac8434646902f30a3

----------------------------------------------------------------------------

5e7287f: VM Preflet: Style cleanup; check for success of fs_stat_dev
  
  * Cleanup as per Axel on the ML
  * Remove superfluous else statements

59c5957: VM Preflet: Add a BStatusBar to show swap file usage
  
  * Correct a situation where disabling the auto swap without
    adjusting the swap size would result in an invalid swap
    size getting written to the configuration

                          [ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

3 files changed, 58 insertions(+), 32 deletions(-)
src/preferences/virtualmemory/Settings.cpp       |   11 +--
src/preferences/virtualmemory/SettingsWindow.cpp |   75 +++++++++++-------
src/preferences/virtualmemory/SettingsWindow.h   |    4 +

############################################################################

Commit:      5e7287f9871d70f007b386c00fcbe5563b3898f5
URL:         http://cgit.haiku-os.org/haiku/commit/?id=5e7287f
Author:      Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date:        Fri Sep  7 12:18:20 2012 UTC

VM Preflet: Style cleanup; check for success of fs_stat_dev

* Cleanup as per Axel on the ML
* Remove superfluous else statements

----------------------------------------------------------------------------

diff --git a/src/preferences/virtualmemory/Settings.cpp 
b/src/preferences/virtualmemory/Settings.cpp
index bb143f1..08f6102 100644
--- a/src/preferences/virtualmemory/Settings.cpp
+++ b/src/preferences/virtualmemory/Settings.cpp
@@ -108,8 +108,8 @@ Settings::ReadWindowSettings()
 
        if (file.Read(&fWindowPosition, sizeof(BPoint)) == sizeof(BPoint))
                return B_OK;
-       else
-               return B_ERROR;
+
+       return B_ERROR;
 }
 
 
@@ -197,8 +197,8 @@ Settings::ReadSwapSettings()
 
        if (bestVol < 0)
                return kErrorVolumeNotFound;
-       else
-               return B_OK;
+
+       return B_OK;
 }
 
 
@@ -218,7 +218,8 @@ Settings::WriteSwapSettings()
                return B_ERROR;
 
        fs_info info;
-       fs_stat_dev(SwapVolume(), &info);
+       if (fs_stat_dev(SwapVolume(), &info) != 0)
+               return B_ERROR;
 
        char buffer[1024];
        snprintf(buffer, sizeof(buffer), "vm %s\nswap_auto %s\nswap_size %lld\n"
diff --git a/src/preferences/virtualmemory/SettingsWindow.cpp 
b/src/preferences/virtualmemory/SettingsWindow.cpp
index 6cae509..bddbe04 100644
--- a/src/preferences/virtualmemory/SettingsWindow.cpp
+++ b/src/preferences/virtualmemory/SettingsWindow.cpp
@@ -397,8 +397,8 @@ SettingsWindow::_RemoveVolumeMenuItem(dev_t device)
                fVolumeMenuField->Menu()->RemoveItem(item);
                delete item;
                return B_OK;
-       } else
-               return B_ERROR;
+       }
+       return B_ERROR;
 }
 
 
@@ -461,6 +461,7 @@ SettingsWindow::_Update()
                fWarningStringView->Show();
        else
                fWarningStringView->Hide();
+
        fRevertButton->SetEnabled(revertable);
        fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
 

############################################################################

Revision:    hrev44621
Commit:      59c595739c6e9469a43529aac8434646902f30a3
URL:         http://cgit.haiku-os.org/haiku/commit/?id=59c5957
Author:      Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date:        Fri Sep  7 17:40:56 2012 UTC

VM Preflet: Add a BStatusBar to show swap file usage

* Correct a situation where disabling the auto swap without
  adjusting the swap size would result in an invalid swap
  size getting written to the configuration

----------------------------------------------------------------------------

diff --git a/src/preferences/virtualmemory/SettingsWindow.cpp 
b/src/preferences/virtualmemory/SettingsWindow.cpp
index bddbe04..d02f6e6 100644
--- a/src/preferences/virtualmemory/SettingsWindow.cpp
+++ b/src/preferences/virtualmemory/SettingsWindow.cpp
@@ -166,24 +166,7 @@ SettingsWindow::SettingsWindow()
                new BMessage(kMsgSwapAutomaticUpdate));
        fSwapEnabledCheckBox->SetExplicitAlignment(align);
 
-       char sizeStr[16];
-       system_info info;
-       get_system_info(&info);
-       BString string = B_TRANSLATE("Physical memory: ");
-       string << string_for_size(info.max_pages * B_PAGE_SIZE, sizeStr,
-               sizeof(sizeStr));
-       BStringView* memoryView = new BStringView("physical memory",
-               string.String());
-       memoryView->SetExplicitAlignment(align);
-
-       system_memory_info memInfo = {};
-       __get_system_info_etc(B_MEMORY_INFO, &memInfo, sizeof(memInfo));
-       string = B_TRANSLATE("Current swap file size: ");
-       string << string_for_size(memInfo.max_swap_space, sizeStr,
-               sizeof(sizeStr));
-       BStringView* swapFileView = new BStringView("current swap size",
-               string.String());
-       swapFileView->SetExplicitAlignment(align);
+       fSwapUsageBar = new BStatusBar("swap usage");
 
        BPopUpMenu* menu = new BPopUpMenu("volume menu");
        fVolumeMenuField = new BMenuField("volume menu field",
@@ -214,8 +197,7 @@ SettingsWindow::SettingsWindow()
        box->SetLabel(fSwapEnabledCheckBox);
 
        box->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_DEFAULT_SPACING)
-               .Add(memoryView)
-               .Add(swapFileView)
+               .Add(fSwapUsageBar)
                .Add(fSwapAutomaticCheckBox)
                .Add(fVolumeMenuField)
                .Add(fSizeSlider)
@@ -268,6 +250,9 @@ SettingsWindow::SettingsWindow()
 #endif
 
        _Update();
+
+       // TODO: We may want to run this at an interval
+       _UpdateSwapInfo();
 }
 
 
@@ -305,12 +290,11 @@ SettingsWindow::MessageReceived(BMessage* message)
                        _Update();
                        break;
                case kMsgSliderUpdate:
-                       fSettings.SetSwapSize((off_t)fSizeSlider->Value() * 
kMegaByte);
+                       _RecordChoices();
                        _Update();
                        break;
                case kMsgVolumeSelected:
-                       
fSettings.SetSwapVolume(((VolumeMenuItem*)fVolumeMenuField
-                               ->Menu()->FindMarked())->Volume().Device());
+                       _RecordChoices();
                        _Update();
                        break;
                case kMsgSwapEnabledUpdate:
@@ -338,13 +322,13 @@ SettingsWindow::MessageReceived(BMessage* message)
                                }
                        }
 
-                       fSettings.SetSwapEnabled(fSwapEnabledCheckBox->Value());
+                       _RecordChoices();
                        _Update();
                        break;
                }
                case kMsgSwapAutomaticUpdate:
                {
-                       
fSettings.SetSwapAutomatic(fSwapAutomaticCheckBox->Value());
+                       _RecordChoices();
                        _Update();
                        break;
                }
@@ -359,6 +343,8 @@ bool
 SettingsWindow::QuitRequested()
 {
        fSettings.SetWindowPosition(Frame().LeftTop());
+
+       _RecordChoices();
        fSettings.WriteWindowSettings();
        fSettings.WriteSwapSettings();
        be_app->PostMessage(B_QUIT_REQUESTED);
@@ -418,6 +404,17 @@ SettingsWindow::_FindVolumeMenuItem(dev_t device)
 
 
 void
+SettingsWindow::_RecordChoices()
+{
+       fSettings.SetSwapAutomatic(fSwapAutomaticCheckBox->Value());
+       fSettings.SetSwapEnabled(fSwapEnabledCheckBox->Value());
+       fSettings.SetSwapSize((off_t)fSizeSlider->Value() * kMegaByte);
+       fSettings.SetSwapVolume(((VolumeMenuItem*)fVolumeMenuField
+               ->Menu()->FindMarked())->Volume().Device());
+}
+
+
+void
 SettingsWindow::_Update()
 {
        fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
@@ -475,3 +472,26 @@ SettingsWindow::_Update()
        fVolumeMenuField->SetEnabled(fSettings.SwapEnabled()
                && !fSwapAutomaticCheckBox->Value());
 }
+
+
+void
+SettingsWindow::_UpdateSwapInfo()
+{
+       system_memory_info memInfo = {};
+       __get_system_info_etc(B_MEMORY_INFO, &memInfo, sizeof(memInfo));
+
+       off_t currentSwapSize = memInfo.max_swap_space;
+       off_t currentSwapUsed = (memInfo.max_swap_space - 
memInfo.free_swap_space);
+
+       char sizeStr[16];
+       BString swapSizeStr = string_for_size(currentSwapSize, sizeStr,
+               sizeof(sizeStr));
+       BString swapUsedStr = string_for_size(currentSwapUsed, sizeStr,
+               sizeof(sizeStr));
+
+       BString string = swapUsedStr << " / " << swapSizeStr;
+
+       fSwapUsageBar->SetMaxValue(currentSwapSize / kMegaByte);
+       fSwapUsageBar->Update(currentSwapUsed / kMegaByte,
+               B_TRANSLATE("Current Swap:"), string.String());
+}
diff --git a/src/preferences/virtualmemory/SettingsWindow.h 
b/src/preferences/virtualmemory/SettingsWindow.h
index 2a14e21..d5df854 100644
--- a/src/preferences/virtualmemory/SettingsWindow.h
+++ b/src/preferences/virtualmemory/SettingsWindow.h
@@ -15,6 +15,7 @@
 
 #include <MenuItem.h>
 #include <Slider.h>
+#include <StatusBar.h>
 #include <Volume.h>
 #include <Window.h>
 
@@ -69,7 +70,9 @@ private:
                        status_t                _RemoveVolumeMenuItem(dev_t 
device);
                        VolumeMenuItem* _FindVolumeMenuItem(dev_t device);
 
+                       void                    _RecordChoices();
                        void                    _Update();
+                       void                    _UpdateSwapInfo();
 
                        BCheckBox*              fSwapEnabledCheckBox;
                        BCheckBox*              fSwapAutomaticCheckBox;
@@ -78,6 +81,7 @@ private:
                        BButton*                fRevertButton;
                        BStringView*    fWarningStringView;
                        BMenuField*             fVolumeMenuField;
+                       BStatusBar*             fSwapUsageBar;
                        Settings                fSettings;
 };
 


Other related posts:

  • » [haiku-commits] haiku: hrev44621 - src/preferences/virtualmemory - kallisti5