From ea932d8aee23182a9896da1a3c42eac43d3e0a52 Mon Sep 17 00:00:00 2001 From: Phil Greenway Date: Tue, 18 Jan 2005 09:31:50 +0000 Subject: [PATCH] Updated git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10825 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/prefs/virtualmemory/Jamfile | 2 +- src/prefs/virtualmemory/MainWindow.cpp | 247 ++++++++++++------------- src/prefs/virtualmemory/MainWindow.h | 187 ++++++++----------- src/prefs/virtualmemory/Pref_Utils.cpp | 30 +++ src/prefs/virtualmemory/Pref_Utils.h | 10 + src/prefs/virtualmemory/Resource.rsrc | Bin 4228 -> 4212 bytes src/prefs/virtualmemory/VMSettings.cpp | 38 ++-- src/prefs/virtualmemory/VMSettings.h | 2 +- src/prefs/virtualmemory/main.cpp | 143 ++++++-------- src/prefs/virtualmemory/main.h | 91 +++------ 10 files changed, 329 insertions(+), 421 deletions(-) create mode 100644 src/prefs/virtualmemory/Pref_Utils.cpp create mode 100644 src/prefs/virtualmemory/Pref_Utils.h diff --git a/src/prefs/virtualmemory/Jamfile b/src/prefs/virtualmemory/Jamfile index 3474803b8f..0d1fc15f5b 100644 --- a/src/prefs/virtualmemory/Jamfile +++ b/src/prefs/virtualmemory/Jamfile @@ -2,6 +2,6 @@ SubDir OBOS_TOP src prefs virtualmemory ; AddResources VirtualMemory : <$(SOURCE_GRIST)>Resource.rsrc ; -Preference VirtualMemory : main.cpp MainWindow.cpp VMSettings.cpp ; +Preference VirtualMemory : main.cpp Pref_Utils.cpp MainWindow.cpp VMSettings.cpp ; LinkSharedOSLibs VirtualMemory : be root ; diff --git a/src/prefs/virtualmemory/MainWindow.cpp b/src/prefs/virtualmemory/MainWindow.cpp index 1e6a5b8682..fc969bac65 100644 --- a/src/prefs/virtualmemory/MainWindow.cpp +++ b/src/prefs/virtualmemory/MainWindow.cpp @@ -6,7 +6,11 @@ */ #include "MainWindow.h" +#include "Pref_Utils.h" +#include + +const char *kRequestStr = "Requested swap file size: "; /** * Constructor. * @param frame The size to make the window. @@ -16,107 +20,111 @@ * @param maxSwapVal The maximum value of the swap file. */ MainWindow::MainWindow(BRect frame, int physMemVal, int currSwapVal, int minVal, int maxSwapVal, VMSettings *Settings) - :BWindow(frame, "Virtual Memory", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE){ + :BWindow(frame, "VirtualMemory", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE){ - BStringView *physMem; - BStringView *currSwap; - BButton *defaultButton; - BBox *topLevelView; - BBox *boxView; - fSettings = Settings; /** * Sets the fill color for the "used" portion of the slider. */ - rgb_color fillColor; - fillColor.red = 0; - fillColor.blue = 152; - fillColor.green = 102; - + rgb_color fillColor = { 0, 102, 152, 255 }; + /** * Set up variables to help handle font sensitivity */ - font_height fontHeightStruct; - be_plain_font->GetHeight(&fontHeightStruct); - float fontheight=fontHeightStruct.ascent+fontHeightStruct.descent+fontHeightStruct.leading; + float fontheight = FontHeight(true, NULL); /** - * This var sets the size of the visible box around the string views and + * boxRect sets the size of the visible box around the string views and * the slider. */ - BRect boxRect=Bounds(); - boxRect.left=boxRect.left+10; - boxRect.top=boxRect.top+10; - boxRect.bottom=boxRect.bottom-45; - boxRect.right=boxRect.right-10; - char labels[50]; - char sliderMinLabel[10]; - char sliderMaxLabel[10]; + BRect boxRect = Bounds(); + boxRect.InsetBy(11, 11); + boxRect.bottom -= 25; - origMemSize = currSwapVal; - minSwapVal = minVal; - - BRect rect(10,10,210,10+fontheight+2); + BString labels; + forigMemSize = currSwapVal; + fminSwapVal = minVal; + BRect rect(0.0, 0.0, boxRect.Width() -20.0, fontheight); + rect.OffsetTo(10.0, 10.0); /** * Set up the "Physical Memory" label. */ - sprintf(labels, "Physical Memory: %d MB", physMemVal); - physMem = new BStringView(rect, "PhysicalMemory", labels, B_FOLLOW_ALL, B_WILL_DRAW); + BStringView *physMem; + labels << "Physical memory: " << physMemVal << " MB"; + physMem = new BStringView(rect, "PhysicalMemory", labels.String(), B_FOLLOW_ALL, B_WILL_DRAW); /** * Set up the "Current Swap File Size" label. */ - rect.OffsetBy(0,rect.Height()); - sprintf(labels, "Current Swap File Size: %d MB", currSwapVal); - currSwap = new BStringView(rect, "CurrentSwapSize", labels, B_FOLLOW_ALL, B_WILL_DRAW); + BStringView *currSwap; + rect.OffsetBy(0, rect.Height() +5); + labels = "Current swap file size: "; + labels << currSwapVal << " MB"; + currSwap = new BStringView(rect, "CurrentSwapSize", labels.String(), B_FOLLOW_ALL, B_WILL_DRAW); /** * Set up the "Requested Swap File Size" label. */ - rect.OffsetBy(0,rect.Height()); - sprintf(labels, "Requested Swap File Size: %d MB", currSwapVal); - reqSwap = new BStringView(rect, "RequestedSwapSize", labels, B_FOLLOW_ALL, B_WILL_DRAW); - + rect.OffsetBy(0, rect.Height() +5); + labels = kRequestStr; + labels << currSwapVal << " MB"; /** * Set up the slider. */ - sprintf(sliderMinLabel, "%d MB", minSwapVal); - sprintf(sliderMaxLabel, "%d MB", maxSwapVal); - reqSizeSlider = new BSlider(*(new BRect(10, 51, 240, 75)), "ReqSwapSizeSlider", "", new BMessage(MEMORY_SLIDER_MSG), minSwapVal, maxSwapVal, B_TRIANGLE_THUMB, B_FOLLOW_LEFT, B_WILL_DRAW); - reqSizeSlider->SetLimitLabels(sliderMinLabel, sliderMaxLabel); - reqSizeSlider->UseFillColor(TRUE, &fillColor); - reqSizeSlider->SetModificationMessage(new BMessage(SLIDER_UPDATE_MSG)); + BString sliderMinLabel; + BString sliderMaxLabel; + sliderMinLabel << fminSwapVal << " MB"; + sliderMaxLabel << maxSwapVal << " MB"; + + rect.bottom = rect.top+2; + freqSizeSlider = new BSlider(rect, "ReqSwapSizeSlider", labels.String(), + new BMessage(MEMORY_SLIDER_MSG), fminSwapVal, maxSwapVal, B_TRIANGLE_THUMB, B_FOLLOW_LEFT, B_WILL_DRAW); + + freqSizeSlider->SetLimitLabels(sliderMinLabel.String(), sliderMaxLabel.String()); + freqSizeSlider->UseFillColor(true, &fillColor); + freqSizeSlider->SetModificationMessage(new BMessage(SLIDER_UPDATE_MSG)); - reqSizeSlider->SetValue(currSwapVal); + freqSizeSlider->SetValue(currSwapVal); /** * Initializes the restart notice view. */ - restart = new BStringView(*(new BRect(40, 100, 210, 110)), "RestartMessage", "", B_FOLLOW_ALL, B_WILL_DRAW); + rect = freqSizeSlider->Frame(); + rect.top = rect.bottom +2; + rect.bottom = rect.top +fontheight; + frestart = new BStringView(rect, "RestartMessage", B_EMPTY_STRING, B_FOLLOW_ALL, B_WILL_DRAW); + frestart->SetAlignment(B_ALIGN_CENTER); /** * This view holds the three labels and the slider. */ + + BBox *boxView; boxView = new BBox(boxRect, "BoxView", B_FOLLOW_ALL, B_WILL_DRAW, B_FANCY_BORDER); - boxView->AddChild(reqSizeSlider); + boxView->AddChild(freqSizeSlider); boxView->AddChild(physMem); boxView->AddChild(currSwap); - boxView->AddChild(reqSwap); - boxView->AddChild(restart); - - defaultButton = new BButton(*(new BRect(10, 138, 85, 158)), "DefaultButton", "Default", new BMessage(DEFAULT_BUTTON_MSG), B_FOLLOW_ALL, B_WILL_DRAW); - revertButton = new BButton(*(new BRect(95, 138, 170, 158)), "RevertButton", "Revert", new BMessage(REVERT_BUTTON_MSG), B_FOLLOW_ALL, B_WILL_DRAW); - revertButton->SetEnabled(false); + boxView->AddChild(frestart); + rect.Set(0.0, 0.0, 75.0, 20.0); + BButton *defaultButton; + rect.OffsetTo(10, boxRect.bottom +5); + defaultButton = new BButton(rect, "DefaultButton", "Default", + new BMessage(DEFAULT_BUTTON_MSG), B_FOLLOW_ALL, B_WILL_DRAW); + rect.OffsetBy(85, 0); + frevertButton = new BButton(rect, "RevertButton", "Revert", + new BMessage(REVERT_BUTTON_MSG), B_FOLLOW_ALL, B_WILL_DRAW); + frevertButton->SetEnabled(false); + + BBox *topLevelView; topLevelView = new BBox(Bounds(), "TopLevelView", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER); topLevelView->AddChild(boxView); topLevelView->AddChild(defaultButton); - topLevelView->AddChild(revertButton); + topLevelView->AddChild(frevertButton); AddChild(topLevelView); - } /** @@ -124,21 +132,16 @@ MainWindow::MainWindow(BRect frame, int physMemVal, int currSwapVal, int minVal, * @param setTo If true, displays the message If false, un-displays it. */ void MainWindow::toggleChangedMessage(bool setTo){ + + BString message = B_EMPTY_STRING; + if (setTo) { + frevertButton->SetEnabled(true); + message << "Changes will take effect on restart."; + } else { + frevertButton->SetEnabled(false); + } - char msg[100]; - if(setTo){ - - revertButton->SetEnabled(true); - sprintf(msg, "Changes will take effect on restart."); - restart->SetText(msg); - - }//if - else{ - - restart->SetText(""); - - }//else - + frestart->SetText(message.String()); }//toggleChangedMessage /** @@ -147,58 +150,44 @@ void MainWindow::toggleChangedMessage(bool setTo){ */ void MainWindow::MessageReceived(BMessage *message){ - char msg[100]; - switch(message->what){ - - int currVal; - + /** * Updates the requested swap file size during a drag. */ case SLIDER_UPDATE_MSG: + { + int32 currVal = freqSizeSlider->Value(); + BString label(kRequestStr); + label << currVal << " MB"; + freqSizeSlider->SetLabel(label.String()); - currVal = int(reqSizeSlider->Value()); - sprintf(msg, "Requested Swap File Size: %d MB", currVal); - reqSwap->SetText(msg); - - if(currVal != origMemSize){ - + if (currVal != forigMemSize) toggleChangedMessage(true); - - }//if - else{ - - revertButton->SetEnabled(false); + else toggleChangedMessage(false); - - }//else - + break; + } /** * Case where the slider was moved. * Resets the "Requested Swap File Size" label to the new value. */ case MEMORY_SLIDER_MSG: - - currVal = int(reqSizeSlider->Value()); - sprintf(msg, "Requested Swap File Size: %d MB", currVal); - reqSwap->SetText(msg); - - if(currVal != origMemSize){ + { + int32 currVal = freqSizeSlider->Value(); + BString label(kRequestStr); + label << currVal << " MB"; + freqSizeSlider->SetLabel(label.String()); + if (currVal != forigMemSize) toggleChangedMessage(true); - - }//if - else{ - - revertButton->SetEnabled(false); + else toggleChangedMessage(false); - - }//else break; + } /** * Case where the default button was pressed. @@ -207,46 +196,41 @@ void MainWindow::MessageReceived(BMessage *message){ * do that). */ case DEFAULT_BUTTON_MSG: - - reqSizeSlider->SetValue(minSwapVal); - sprintf(msg, "Requested Swap File Size: %d MB", minSwapVal); - reqSwap->SetText(msg); - if(minSwapVal != origMemSize){ - - toggleChangedMessage(true); - - }//if - else{ - - revertButton->SetEnabled(false); + { + freqSizeSlider->SetValue(fminSwapVal); + BString label(kRequestStr); + label << fminSwapVal << " MB"; + freqSizeSlider->SetLabel(label.String()); + + if(fminSwapVal != forigMemSize) + toggleChangedMessage(true); + else toggleChangedMessage(false); - }//else break; - + } /** * Case where the revert button was pressed. * Returns things to the way they were when the app was started, * which is not necessarily the default size. */ case REVERT_BUTTON_MSG: - - revertButton->SetEnabled(false); - sprintf(msg, "Requested Swap File Size: %d MB", origMemSize); - reqSwap->SetText(msg); - reqSizeSlider->SetValue(origMemSize); + { + frevertButton->SetEnabled(false); + BString label(kRequestStr); + label << forigMemSize << " MB"; + freqSizeSlider->SetLabel(label.String()); + freqSizeSlider->SetValue(forigMemSize); toggleChangedMessage(false); - break; + break; + } /** * Unhandled messages get passed to BWindow. */ default: - BWindow::MessageReceived(message); - } - } /** @@ -256,19 +240,20 @@ void MainWindow::MessageReceived(BMessage *message){ */ bool MainWindow::QuitRequested(){ - FILE *settingsFile = - fopen("/boot/home/config/settings/kernel/drivers/virtual_memory", "w"); - fprintf(settingsFile, "vm on\n"); - fprintf(settingsFile, "swap_size %d\n", (int(reqSizeSlider->Value()) * 1048576)); - fclose(settingsFile); + if (freqSizeSlider->Value() != forigMemSize) { + FILE *settingsFile = fopen("/boot/home/config/settings/kernel/drivers/virtual_memory", "w"); + fprintf(settingsFile, "vm on\n"); + fprintf(settingsFile, "swap_size %d\n", (int(freqSizeSlider->Value()) * 1048576)); + fclose(settingsFile); + } be_app->PostMessage(B_QUIT_REQUESTED); - return(true); + return true; } void MainWindow::FrameMoved(BPoint origin) -{//MainWindow::FrameMoved +{ fSettings->SetWindowPosition(Frame()); -}//MainWindow::FrameMoved +} diff --git a/src/prefs/virtualmemory/MainWindow.h b/src/prefs/virtualmemory/MainWindow.h index 5ceb13622b..47dbdf9540 100644 --- a/src/prefs/virtualmemory/MainWindow.h +++ b/src/prefs/virtualmemory/MainWindow.h @@ -4,124 +4,83 @@ */ #ifndef MAIN_WINDOW_H +#define MAIN_WINDOW_H - - #define MAIN_WINDOW_H - - /*! - * Default button message. - */ - #define DEFAULT_BUTTON_MSG 'dflt' - - /*! - * Revert button message. - */ - #define REVERT_BUTTON_MSG 'rvrt' - - /*! - * Slider message. - */ - #define MEMORY_SLIDER_MSG 'sldr' - - /*! - * Slider dragging message. - */ - #define SLIDER_UPDATE_MSG 'sldu' - - #ifndef _APPLICATION_H +/*! + * Default button message. + */ +#define DEFAULT_BUTTON_MSG 'dflt' - #include - - #endif - #ifndef _WINDOW_H - - #include - - #endif - #ifndef _STRING_VIEW_H - - #include - - #endif - #ifndef _BOX_H - - #include - - #endif - #ifndef _SLIDER_H - - #include - - #endif - #ifndef _BUTTON_H - - #include - - #endif - #ifndef _STDIO_H - - #include - - #endif - #ifndef VM_SETTINGS_H - - #include "VMSettings.h" +/*! + * Revert button message. + */ +#define REVERT_BUTTON_MSG 'rvrt' - #endif +/*! + * Slider message. + */ +#define MEMORY_SLIDER_MSG 'sldr' + +/*! + * Slider dragging message. + */ +#define SLIDER_UPDATE_MSG 'sldu' + +#include +#include +#include +#include +#include +#include +#include + +#include "VMSettings.h" + +/** + * The main window of the app. + * + * Sets up and displays everything you need for the app. + */ +class MainWindow : public BWindow{ + private: - /** - * The main window of the app. - * - * Sets up and displays everything you need for the app. - */ - class MainWindow : public BWindow{ - - private: + /** + * Saves the size of the swap file when the app is started + * so that it can be restored later if need be. + */ + int forigMemSize; - /** - * Saves the size of the swap file when the app is started - * so that it can be restored later if need be. - */ - int origMemSize; - - /** - * Saves the minimum virtual memory value; - */ - int minSwapVal; - - /** - * The BStringView that shows the requested swap file - * size. - */ - BStringView *reqSwap; - - /** - * The slider that lets you adjust the size of the swap file. - */ - BSlider *reqSizeSlider; - - /** - * The button that returns the swap file to the original - * size. - */ - BButton *revertButton; - - /** - * The BStringView that informs you that you need to - * restart. - */ - BStringView *restart; - - VMSettings *fSettings; - - public: + /** + * Saves the minimum virtual memory value; + */ + int fminSwapVal; - MainWindow(BRect frame, int physMem, int currSwp, int sliderMin, int sliderMax, VMSettings *fSettings); - virtual bool QuitRequested(); - virtual void MessageReceived(BMessage *message); - virtual void FrameMoved(BPoint origin); - virtual void toggleChangedMessage(bool setTo); - - }; - + /** + * The slider that lets you adjust the size of the swap file. + */ + BSlider *freqSizeSlider; + + /** + * The button that returns the swap file to the original + * size. + */ + BButton *frevertButton; + + /** + * The BStringView that informs you that you need to + * restart. + */ + BStringView *frestart; + + VMSettings *fSettings; + + public: + MainWindow(BRect frame, int physMem, int currSwp, int sliderMin, int sliderMax, VMSettings *fSettings); + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage *message); + virtual void FrameMoved(BPoint origin); + virtual void toggleChangedMessage(bool setTo); + +}; + #endif diff --git a/src/prefs/virtualmemory/Pref_Utils.cpp b/src/prefs/virtualmemory/Pref_Utils.cpp new file mode 100644 index 0000000000..ff1a08cbf9 --- /dev/null +++ b/src/prefs/virtualmemory/Pref_Utils.cpp @@ -0,0 +1,30 @@ +#include "Pref_Utils.h" + +float +FontHeight(bool full, BView* target) +{ + font_height finfo; + if (target != NULL) + target->GetFontHeight(&finfo); + else + be_plain_font->GetHeight(&finfo); + + float height = ceil(finfo.ascent) + ceil(finfo.descent); + + if (full) + height += ceil(finfo.leading); + + return height; +} + +color_map* +ColorMap() +{ + color_map* cmap; + + BScreen screen(B_MAIN_SCREEN_ID); + cmap = (color_map*)screen.ColorMap(); + + return cmap; +} + diff --git a/src/prefs/virtualmemory/Pref_Utils.h b/src/prefs/virtualmemory/Pref_Utils.h new file mode 100644 index 0000000000..4379a1d3d4 --- /dev/null +++ b/src/prefs/virtualmemory/Pref_Utils.h @@ -0,0 +1,10 @@ +#ifndef SHARED_PREF_UTILS +#define SHARED_PREF_UTILS + +#include +#include + +float FontHeight(bool full, BView* view = NULL); +color_map* ColorMap(); + +#endif diff --git a/src/prefs/virtualmemory/Resource.rsrc b/src/prefs/virtualmemory/Resource.rsrc index 7c2e55cc91d18775419347ee1b0732288aca75ee..fea205f8212bb2b512da23ac6f27733f3bbe7dbd 100644 GIT binary patch delta 253 zcmZos{Gu@7fNwiL1H(%OAZBJ@Si{c1zyf50zy=_D1rvlF!3CtD5)phrHX~FVs8<%k zWGDr)g*NjtE@qoJfo1c1o)t`+53vies(B=4W|!*vy85ax7&`g80d)!qLA5Y4xCI0_ zg3Mx^oFE{>83yGsO|}$}CW&U3f$d;eL+UC0kHr?iJPa7YkWv#fNL;Zl`*60G@t?o0C##gnE(I) delta 252 zcmeyO(4siufbVpE28NdmK+Md*u!fz1K?ukOfqg(W0}GhRu#X!^GeX%s3=FyuCc|qW zdj%7OGZ|gp+PJTIEHzW@ diff --git a/src/prefs/virtualmemory/VMSettings.cpp b/src/prefs/virtualmemory/VMSettings.cpp index c3dbe533cf..ebfd69be77 100644 --- a/src/prefs/virtualmemory/VMSettings.cpp +++ b/src/prefs/virtualmemory/VMSettings.cpp @@ -1,19 +1,9 @@ -#ifndef VM_SETTINGS_H #include "VMSettings.h" -#endif -#ifndef _APPLICATION_H -#include -#endif -#ifndef _FILE_H -#include -#endif -#ifndef _PATH_H -#include -#endif -#ifndef _FINDDIRECTORY_H -#include -#endif +#include +#include +#include +#include #include const char VMSettings::kVMSettingsFile[] = "VM_data"; @@ -37,22 +27,22 @@ VMSettings::VMSettings() printf("fcorner read in as "); fcorner.PrintToStream(); - fWindowFrame.left=fcorner.x; - fWindowFrame.top=fcorner.y; - fWindowFrame.right=fWindowFrame.left+269; - fWindowFrame.bottom=fWindowFrame.top+172; + fWindowFrame.left = fcorner.x; + fWindowFrame.top = fcorner.y; + fWindowFrame.right = fWindowFrame.left+269; + fWindowFrame.bottom = fWindowFrame.top+172; //Check to see if the co-ords of the window are in the range of the Screen BScreen screen; - if (screen.Frame().right >= fWindowFrame.right - && screen.Frame().bottom >= fWindowFrame.bottom) + if (screen.Frame().right >= fWindowFrame.right + && screen.Frame().bottom >= fWindowFrame.bottom) return; // If they are not, lets just stick the window in the middle // of the screen. fWindowFrame = screen.Frame(); - fWindowFrame.left = (fWindowFrame.right-269)/2; + fWindowFrame.left = (fWindowFrame.right -269)/2; fWindowFrame.right = fWindowFrame.left + 269; - fWindowFrame.top = (fWindowFrame.bottom-172)/2; + fWindowFrame.top = (fWindowFrame.bottom -172)/2; fWindowFrame.bottom = fWindowFrame.top + 172; }//VMSettings::VMSettings @@ -74,6 +64,6 @@ VMSettings::~VMSettings() void VMSettings::SetWindowPosition(BRect f) {//VMSettings::SetWindowFrame - fcorner.x=f.left; - fcorner.y=f.top; + fcorner.x = f.left; + fcorner.y = f.top; }//VMSettings::SetWindowFrame diff --git a/src/prefs/virtualmemory/VMSettings.h b/src/prefs/virtualmemory/VMSettings.h index 0738248ee3..60c8c77f66 100644 --- a/src/prefs/virtualmemory/VMSettings.h +++ b/src/prefs/virtualmemory/VMSettings.h @@ -1,8 +1,8 @@ #ifndef VM_SETTINGS_H_ #define VM_SETTINGS_H_ -#include #include +#include class VMSettings{ public : diff --git a/src/prefs/virtualmemory/main.cpp b/src/prefs/virtualmemory/main.cpp index 216a0ffec0..3e5e20a908 100644 --- a/src/prefs/virtualmemory/main.cpp +++ b/src/prefs/virtualmemory/main.cpp @@ -8,7 +8,9 @@ #include "MainWindow.h" #include "main.h" - +#include +using namespace std; +#define MEGABITE 1048576 /** * Main method. * @@ -19,12 +21,10 @@ int main(int, char**){ /** * An instance of the application. */ - VM_pref vmApp; - - vmApp.Run(); - - return(0); - + new VM_pref(); + be_app->Run(); + delete be_app; + return 0; } /* @@ -33,112 +33,77 @@ int main(int, char**){ * Provides a contstructor for the application. */ VM_pref::VM_pref() - :BApplication("application/x-vnd.MSM-VirtualMemoryPrefPanel"){ + :BApplication("application/x-vnd.Haiku-MEM$") { - FILE *settingsFile = - fopen("/boot/home/config/settings/kernel/drivers/virtual_memory", "r"); -// FILE *ptr; - char dummy[80]; - BVolume bootVol; - BVolumeRoster *vol_rost = new BVolumeRoster(); - fSettings = new VMSettings(); + // read current swap settings + FILE *settingsFile = fopen("/boot/home/config/settings/kernel/drivers/virtual_memory", "r"); + char dummy[80]; - /* - * The main interface window. - */ - MainWindow *Main; - - /* - * The amount of physical memory in the machine. - */ - int physMem; - - /* - * The current size of the swap file. - */ - int currSwap; - - /* - * The set size of the swap file. - */ - int setSwap; - - /* - * The minimum size the swap file can be. - */ - int minSwap; - - /* - * The maximum size the swap file can be. - */ - int maxSwap; - - /* - * System info - */ - system_info info; - - /* - * Swap file - */ - const char *swap_file; - - bool changeMsg = false; - - swap_file = "/boot/var/swap"; + int physMem; //The amount of physical memory in the machine. + int currSwap; //The current size of the swap file. + int setSwap; //The set size of the swap file. + double minSwap; //The minimum size the swap file can be. + int maxSwap; //The maximum size the swap file can be. + + const char *swap_file= "/boot/var/swap"; BEntry swap(swap_file); off_t swapsize; swap.GetSize(&swapsize); - currSwap = swapsize / 1048576; + currSwap = swapsize / MEGABITE; + system_info info; get_system_info(&info); - physMem = (info.max_pages * 4096) / 1048576; - - minSwap = physMem + (int)(physMem / 3.0); - - if(settingsFile != NULL){ + physMem = (info.max_pages * 4096) / MEGABITE; + float memcalc = (physMem +(int)(physMem/3.0)); + cout << memcalc << endl; + modf(memcalc/128.0, &minSwap); + cout << minSwap << endl; + minSwap*= 128; + + if (settingsFile != NULL) { fscanf(settingsFile, "%s %s\n", dummy, dummy); fscanf(settingsFile, "%s %d\n", dummy, &setSwap); - setSwap = setSwap / 1048576; + setSwap = setSwap / MEGABITE; + } else { + setSwap = (int)minSwap; + } - }//if - else{ - - setSwap = minSwap; - - }//else fclose(settingsFile); + BVolume bootVol; + BVolumeRoster *vol_rost = new BVolumeRoster(); vol_rost->GetBootVolume(&bootVol); /* maxSwap is defined by the amount of free space on your boot * volume, plus the current swap file size, minus an arbitrary * amount of space, just so you don't fill up your drive completly. */ - maxSwap = (bootVol.FreeBytes() / 1048576) + currSwap - 16; - - if(currSwap != setSwap){ + maxSwap = (bootVol.FreeBytes() / MEGABITE) + currSwap - 16; + bool changeMsg = false; + if (currSwap != setSwap) { currSwap = setSwap; changeMsg = true; - - }//if - - Main = new MainWindow(fSettings->WindowPosition(), physMem, currSwap, minSwap, maxSwap, fSettings); - - if(changeMsg){ - - Main->toggleChangedMessage(true); - - }//if - - Main->Show(); + } + + fSettings = new VMSettings(); + window = new MainWindow(fSettings->WindowPosition(), physMem, currSwap, minSwap, maxSwap, fSettings); + if (changeMsg) { + window->toggleChangedMessage(true); + } } VM_pref::~VM_pref() -{//VM_pref::~VM_pref - delete fSettings; -}//VM_pref::~VM_pref +{ + delete fSettings; +} + + +void +VM_pref::ReadyToRun() +{ + window->Show(); +} diff --git a/src/prefs/virtualmemory/main.h b/src/prefs/virtualmemory/main.h index 88b988572a..418dcb6f38 100644 --- a/src/prefs/virtualmemory/main.h +++ b/src/prefs/virtualmemory/main.h @@ -4,68 +4,37 @@ */ #ifndef MAIN_H +#define MAIN_H - #define MAIN_H - - #ifndef _APPLICATION_H - - #include - - #endif - - #ifndef _VOLUME_H - - #include - - #endif - #ifndef _VOLUME_ROSTER_H - - #include - - #endif - #ifndef _STDIO_H - - #include - - #endif - #ifndef VM_SETTINGS_H - - #include "VMSettings.h" - - #endif - #ifndef _OS_H - - #include - - #endif - #ifndef _ENTRY_H - - #include - - #endif - - /** - * Main class. - * - * Gets everything going. - */ - class VM_pref : public BApplication{ - - public: - - /** - * Constructor. - */ - VM_pref(); - - /** - * Destructor. - */ - virtual ~VM_pref(); - - private: - VMSettings *fSettings; - +#include +#include +#include +#include +#include "VMSettings.h" +#include +#include + +class MainWindow; +/** + * Main class. + * + * Gets everything going. + */ +class VM_pref : public BApplication{ + public: + /** + * Constructor. + */ + VM_pref(); + + /** + * Destructor. + */ + virtual ~VM_pref(); + virtual void ReadyToRun(); + private: + VMSettings *fSettings; + MainWindow *window; }; #endif