git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10825 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Phil Greenway
2005-01-18 09:31:50 +00:00
parent d0733791ae
commit ea932d8aee
10 changed files with 329 additions and 421 deletions
+1 -1
View File
@@ -2,6 +2,6 @@ SubDir OBOS_TOP src prefs virtualmemory ;
AddResources VirtualMemory : <$(SOURCE_GRIST)>Resource.rsrc ; 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 ; LinkSharedOSLibs VirtualMemory : be root ;
+109 -124
View File
@@ -6,7 +6,11 @@
*/ */
#include "MainWindow.h" #include "MainWindow.h"
#include "Pref_Utils.h"
#include <String.h>
const char *kRequestStr = "Requested swap file size: ";
/** /**
* Constructor. * Constructor.
* @param frame The size to make the window. * @param frame The size to make the window.
@@ -16,107 +20,111 @@
* @param maxSwapVal The maximum value of the swap file. * @param maxSwapVal The maximum value of the swap file.
*/ */
MainWindow::MainWindow(BRect frame, int physMemVal, int currSwapVal, int minVal, int maxSwapVal, VMSettings *Settings) 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; fSettings = Settings;
/** /**
* Sets the fill color for the "used" portion of the slider. * Sets the fill color for the "used" portion of the slider.
*/ */
rgb_color fillColor; rgb_color fillColor = { 0, 102, 152, 255 };
fillColor.red = 0;
fillColor.blue = 152;
fillColor.green = 102;
/** /**
* Set up variables to help handle font sensitivity * Set up variables to help handle font sensitivity
*/ */
font_height fontHeightStruct; float fontheight = FontHeight(true, NULL);
be_plain_font->GetHeight(&fontHeightStruct);
float fontheight=fontHeightStruct.ascent+fontHeightStruct.descent+fontHeightStruct.leading;
/** /**
* 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. * the slider.
*/ */
BRect boxRect=Bounds(); BRect boxRect = Bounds();
boxRect.left=boxRect.left+10; boxRect.InsetBy(11, 11);
boxRect.top=boxRect.top+10; boxRect.bottom -= 25;
boxRect.bottom=boxRect.bottom-45;
boxRect.right=boxRect.right-10;
char labels[50];
char sliderMinLabel[10];
char sliderMaxLabel[10];
origMemSize = currSwapVal; BString labels;
minSwapVal = minVal; forigMemSize = currSwapVal;
fminSwapVal = minVal;
BRect rect(10,10,210,10+fontheight+2);
BRect rect(0.0, 0.0, boxRect.Width() -20.0, fontheight);
rect.OffsetTo(10.0, 10.0);
/** /**
* Set up the "Physical Memory" label. * Set up the "Physical Memory" label.
*/ */
sprintf(labels, "Physical Memory: %d MB", physMemVal); BStringView *physMem;
physMem = new BStringView(rect, "PhysicalMemory", labels, B_FOLLOW_ALL, B_WILL_DRAW); 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. * Set up the "Current Swap File Size" label.
*/ */
rect.OffsetBy(0,rect.Height()); BStringView *currSwap;
sprintf(labels, "Current Swap File Size: %d MB", currSwapVal); rect.OffsetBy(0, rect.Height() +5);
currSwap = new BStringView(rect, "CurrentSwapSize", labels, B_FOLLOW_ALL, B_WILL_DRAW); 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. * Set up the "Requested Swap File Size" label.
*/ */
rect.OffsetBy(0,rect.Height()); rect.OffsetBy(0, rect.Height() +5);
sprintf(labels, "Requested Swap File Size: %d MB", currSwapVal); labels = kRequestStr;
reqSwap = new BStringView(rect, "RequestedSwapSize", labels, B_FOLLOW_ALL, B_WILL_DRAW); labels << currSwapVal << " MB";
/** /**
* Set up the slider. * Set up the slider.
*/ */
sprintf(sliderMinLabel, "%d MB", minSwapVal); BString sliderMinLabel;
sprintf(sliderMaxLabel, "%d MB", maxSwapVal); BString sliderMaxLabel;
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); sliderMinLabel << fminSwapVal << " MB";
reqSizeSlider->SetLimitLabels(sliderMinLabel, sliderMaxLabel); sliderMaxLabel << maxSwapVal << " MB";
reqSizeSlider->UseFillColor(TRUE, &fillColor);
reqSizeSlider->SetModificationMessage(new BMessage(SLIDER_UPDATE_MSG));
reqSizeSlider->SetValue(currSwapVal); 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));
freqSizeSlider->SetValue(currSwapVal);
/** /**
* Initializes the restart notice view. * 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. * 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 = new BBox(boxRect, "BoxView", B_FOLLOW_ALL, B_WILL_DRAW, B_FANCY_BORDER);
boxView->AddChild(reqSizeSlider); boxView->AddChild(freqSizeSlider);
boxView->AddChild(physMem); boxView->AddChild(physMem);
boxView->AddChild(currSwap); boxView->AddChild(currSwap);
boxView->AddChild(reqSwap); boxView->AddChild(frestart);
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); rect.Set(0.0, 0.0, 75.0, 20.0);
revertButton = new BButton(*(new BRect(95, 138, 170, 158)), "RevertButton", "Revert", new BMessage(REVERT_BUTTON_MSG), B_FOLLOW_ALL, B_WILL_DRAW); BButton *defaultButton;
revertButton->SetEnabled(false); 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 = new BBox(Bounds(), "TopLevelView", B_FOLLOW_ALL, B_WILL_DRAW, B_PLAIN_BORDER);
topLevelView->AddChild(boxView); topLevelView->AddChild(boxView);
topLevelView->AddChild(defaultButton); topLevelView->AddChild(defaultButton);
topLevelView->AddChild(revertButton); topLevelView->AddChild(frevertButton);
AddChild(topLevelView); AddChild(topLevelView);
} }
/** /**
@@ -125,20 +133,15 @@ MainWindow::MainWindow(BRect frame, int physMemVal, int currSwapVal, int minVal,
*/ */
void MainWindow::toggleChangedMessage(bool setTo){ void MainWindow::toggleChangedMessage(bool setTo){
char msg[100]; BString message = B_EMPTY_STRING;
if(setTo){ if (setTo) {
frevertButton->SetEnabled(true);
revertButton->SetEnabled(true); message << "Changes will take effect on restart.";
sprintf(msg, "Changes will take effect on restart."); } else {
restart->SetText(msg); frevertButton->SetEnabled(false);
}
}//if
else{
restart->SetText("");
}//else
frestart->SetText(message.String());
}//toggleChangedMessage }//toggleChangedMessage
/** /**
@@ -147,58 +150,44 @@ void MainWindow::toggleChangedMessage(bool setTo){
*/ */
void MainWindow::MessageReceived(BMessage *message){ void MainWindow::MessageReceived(BMessage *message){
char msg[100];
switch(message->what){ switch(message->what){
int currVal;
/** /**
* Updates the requested swap file size during a drag. * Updates the requested swap file size during a drag.
*/ */
case SLIDER_UPDATE_MSG: case SLIDER_UPDATE_MSG:
{
int32 currVal = freqSizeSlider->Value();
BString label(kRequestStr);
label << currVal << " MB";
freqSizeSlider->SetLabel(label.String());
currVal = int(reqSizeSlider->Value()); if (currVal != forigMemSize)
sprintf(msg, "Requested Swap File Size: %d MB", currVal);
reqSwap->SetText(msg);
if(currVal != origMemSize){
toggleChangedMessage(true); toggleChangedMessage(true);
else
}//if
else{
revertButton->SetEnabled(false);
toggleChangedMessage(false); toggleChangedMessage(false);
}//else
break; break;
}
/** /**
* Case where the slider was moved. * Case where the slider was moved.
* Resets the "Requested Swap File Size" label to the new value. * Resets the "Requested Swap File Size" label to the new value.
*/ */
case MEMORY_SLIDER_MSG: case MEMORY_SLIDER_MSG:
{
int32 currVal = freqSizeSlider->Value();
BString label(kRequestStr);
label << currVal << " MB";
freqSizeSlider->SetLabel(label.String());
currVal = int(reqSizeSlider->Value()); if (currVal != forigMemSize)
sprintf(msg, "Requested Swap File Size: %d MB", currVal);
reqSwap->SetText(msg);
if(currVal != origMemSize){
toggleChangedMessage(true); toggleChangedMessage(true);
else
}//if
else{
revertButton->SetEnabled(false);
toggleChangedMessage(false); toggleChangedMessage(false);
}//else
break; break;
}
/** /**
* Case where the default button was pressed. * Case where the default button was pressed.
@@ -207,46 +196,41 @@ void MainWindow::MessageReceived(BMessage *message){
* do that). * do that).
*/ */
case DEFAULT_BUTTON_MSG: case DEFAULT_BUTTON_MSG:
{
freqSizeSlider->SetValue(fminSwapVal);
BString label(kRequestStr);
label << fminSwapVal << " MB";
freqSizeSlider->SetLabel(label.String());
reqSizeSlider->SetValue(minSwapVal); if(fminSwapVal != forigMemSize)
sprintf(msg, "Requested Swap File Size: %d MB", minSwapVal);
reqSwap->SetText(msg);
if(minSwapVal != origMemSize){
toggleChangedMessage(true); toggleChangedMessage(true);
else
}//if
else{
revertButton->SetEnabled(false);
toggleChangedMessage(false); toggleChangedMessage(false);
}//else
break; break;
}
/** /**
* Case where the revert button was pressed. * Case where the revert button was pressed.
* Returns things to the way they were when the app was started, * Returns things to the way they were when the app was started,
* which is not necessarily the default size. * which is not necessarily the default size.
*/ */
case REVERT_BUTTON_MSG: case REVERT_BUTTON_MSG:
{
revertButton->SetEnabled(false); frevertButton->SetEnabled(false);
sprintf(msg, "Requested Swap File Size: %d MB", origMemSize); BString label(kRequestStr);
reqSwap->SetText(msg); label << forigMemSize << " MB";
reqSizeSlider->SetValue(origMemSize); freqSizeSlider->SetLabel(label.String());
freqSizeSlider->SetValue(forigMemSize);
toggleChangedMessage(false); toggleChangedMessage(false);
break;
break;
}
/** /**
* Unhandled messages get passed to BWindow. * Unhandled messages get passed to BWindow.
*/ */
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
} }
} }
/** /**
@@ -256,19 +240,20 @@ void MainWindow::MessageReceived(BMessage *message){
*/ */
bool MainWindow::QuitRequested(){ bool MainWindow::QuitRequested(){
FILE *settingsFile = if (freqSizeSlider->Value() != forigMemSize) {
fopen("/boot/home/config/settings/kernel/drivers/virtual_memory", "w"); FILE *settingsFile = fopen("/boot/home/config/settings/kernel/drivers/virtual_memory", "w");
fprintf(settingsFile, "vm on\n"); fprintf(settingsFile, "vm on\n");
fprintf(settingsFile, "swap_size %d\n", (int(reqSizeSlider->Value()) * 1048576)); fprintf(settingsFile, "swap_size %d\n", (int(freqSizeSlider->Value()) * 1048576));
fclose(settingsFile); fclose(settingsFile);
}
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
return(true); return true;
} }
void MainWindow::FrameMoved(BPoint origin) void MainWindow::FrameMoved(BPoint origin)
{//MainWindow::FrameMoved {
fSettings->SetWindowPosition(Frame()); fSettings->SetWindowPosition(Frame());
}//MainWindow::FrameMoved }
+63 -104
View File
@@ -4,124 +4,83 @@
*/ */
#ifndef MAIN_WINDOW_H #ifndef MAIN_WINDOW_H
#define MAIN_WINDOW_H
/*!
* Default button message.
*/
#define DEFAULT_BUTTON_MSG 'dflt'
#define MAIN_WINDOW_H /*!
* Revert button message.
*/
#define REVERT_BUTTON_MSG 'rvrt'
/*! /*!
* Default button message. * Slider message.
*/ */
#define DEFAULT_BUTTON_MSG 'dflt' #define MEMORY_SLIDER_MSG 'sldr'
/*! /*!
* Revert button message. * Slider dragging message.
*/ */
#define REVERT_BUTTON_MSG 'rvrt' #define SLIDER_UPDATE_MSG 'sldu'
/*! #include <Application.h>
* Slider message. #include <Box.h>
*/ #include <Button.h>
#define MEMORY_SLIDER_MSG 'sldr' #include <Slider.h>
#include <stdio.h>
#include <StringView.h>
#include <Window.h>
/*! #include "VMSettings.h"
* Slider dragging message.
*/
#define SLIDER_UPDATE_MSG 'sldu'
#ifndef _APPLICATION_H /**
* The main window of the app.
*
* Sets up and displays everything you need for the app.
*/
class MainWindow : public BWindow{
private:
#include <Application.h> /**
* Saves the size of the swap file when the app is started
* so that it can be restored later if need be.
*/
int forigMemSize;
#endif /**
#ifndef _WINDOW_H * Saves the minimum virtual memory value;
*/
int fminSwapVal;
#include <Window.h> /**
* The slider that lets you adjust the size of the swap file.
*/
BSlider *freqSizeSlider;
#endif /**
#ifndef _STRING_VIEW_H * The button that returns the swap file to the original
* size.
*/
BButton *frevertButton;
#include <StringView.h> /**
* The BStringView that informs you that you need to
* restart.
*/
BStringView *frestart;
#endif VMSettings *fSettings;
#ifndef _BOX_H
#include <Box.h> 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 };
#ifndef _SLIDER_H
#include <Slider.h>
#endif
#ifndef _BUTTON_H
#include <Button.h>
#endif
#ifndef _STDIO_H
#include <stdio.h>
#endif
#ifndef VM_SETTINGS_H
#include "VMSettings.h"
#endif
/**
* 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 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:
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 #endif
+30
View File
@@ -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;
}
+10
View File
@@ -0,0 +1,10 @@
#ifndef SHARED_PREF_UTILS
#define SHARED_PREF_UTILS
#include <Screen.h>
#include <View.h>
float FontHeight(bool full, BView* view = NULL);
color_map* ColorMap();
#endif
Binary file not shown.
+14 -24
View File
@@ -1,19 +1,9 @@
#ifndef VM_SETTINGS_H
#include "VMSettings.h" #include "VMSettings.h"
#endif
#ifndef _APPLICATION_H
#include <Application.h>
#endif
#ifndef _FILE_H
#include <File.h>
#endif
#ifndef _PATH_H
#include <Path.h>
#endif
#ifndef _FINDDIRECTORY_H
#include <FindDirectory.h>
#endif
#include <Application.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
#include <stdio.h> #include <stdio.h>
const char VMSettings::kVMSettingsFile[] = "VM_data"; const char VMSettings::kVMSettingsFile[] = "VM_data";
@@ -37,22 +27,22 @@ VMSettings::VMSettings()
printf("fcorner read in as "); printf("fcorner read in as ");
fcorner.PrintToStream(); fcorner.PrintToStream();
fWindowFrame.left=fcorner.x; fWindowFrame.left = fcorner.x;
fWindowFrame.top=fcorner.y; fWindowFrame.top = fcorner.y;
fWindowFrame.right=fWindowFrame.left+269; fWindowFrame.right = fWindowFrame.left+269;
fWindowFrame.bottom=fWindowFrame.top+172; fWindowFrame.bottom = fWindowFrame.top+172;
//Check to see if the co-ords of the window are in the range of the Screen //Check to see if the co-ords of the window are in the range of the Screen
BScreen screen; BScreen screen;
if (screen.Frame().right >= fWindowFrame.right if (screen.Frame().right >= fWindowFrame.right
&& screen.Frame().bottom >= fWindowFrame.bottom) && screen.Frame().bottom >= fWindowFrame.bottom)
return; return;
// If they are not, lets just stick the window in the middle // If they are not, lets just stick the window in the middle
// of the screen. // of the screen.
fWindowFrame = screen.Frame(); fWindowFrame = screen.Frame();
fWindowFrame.left = (fWindowFrame.right-269)/2; fWindowFrame.left = (fWindowFrame.right -269)/2;
fWindowFrame.right = fWindowFrame.left + 269; fWindowFrame.right = fWindowFrame.left + 269;
fWindowFrame.top = (fWindowFrame.bottom-172)/2; fWindowFrame.top = (fWindowFrame.bottom -172)/2;
fWindowFrame.bottom = fWindowFrame.top + 172; fWindowFrame.bottom = fWindowFrame.top + 172;
}//VMSettings::VMSettings }//VMSettings::VMSettings
@@ -74,6 +64,6 @@ VMSettings::~VMSettings()
void VMSettings::SetWindowPosition(BRect f) void VMSettings::SetWindowPosition(BRect f)
{//VMSettings::SetWindowFrame {//VMSettings::SetWindowFrame
fcorner.x=f.left; fcorner.x = f.left;
fcorner.y=f.top; fcorner.y = f.top;
}//VMSettings::SetWindowFrame }//VMSettings::SetWindowFrame
+1 -1
View File
@@ -1,8 +1,8 @@
#ifndef VM_SETTINGS_H_ #ifndef VM_SETTINGS_H_
#define VM_SETTINGS_H_ #define VM_SETTINGS_H_
#include <SupportDefs.h>
#include <Screen.h> #include <Screen.h>
#include <SupportDefs.h>
class VMSettings{ class VMSettings{
public : public :
+51 -86
View File
@@ -8,7 +8,9 @@
#include "MainWindow.h" #include "MainWindow.h"
#include "main.h" #include "main.h"
#include <iostream>
using namespace std;
#define MEGABITE 1048576
/** /**
* Main method. * Main method.
* *
@@ -19,12 +21,10 @@ int main(int, char**){
/** /**
* An instance of the application. * An instance of the application.
*/ */
VM_pref vmApp; new VM_pref();
be_app->Run();
vmApp.Run(); delete be_app;
return 0;
return(0);
} }
/* /*
@@ -33,112 +33,77 @@ int main(int, char**){
* Provides a contstructor for the application. * Provides a contstructor for the application.
*/ */
VM_pref::VM_pref() VM_pref::VM_pref()
:BApplication("application/x-vnd.MSM-VirtualMemoryPrefPanel"){ :BApplication("application/x-vnd.Haiku-MEM$") {
FILE *settingsFile = // read current swap settings
fopen("/boot/home/config/settings/kernel/drivers/virtual_memory", "r"); FILE *settingsFile = fopen("/boot/home/config/settings/kernel/drivers/virtual_memory", "r");
// FILE *ptr; char dummy[80];
char dummy[80];
BVolume bootVol;
BVolumeRoster *vol_rost = new BVolumeRoster();
fSettings = new VMSettings();
/* int physMem; //The amount of physical memory in the machine.
* The main interface window. int currSwap; //The current size of the swap file.
*/ int setSwap; //The set size of the swap file.
MainWindow *Main; 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";
* 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";
BEntry swap(swap_file); BEntry swap(swap_file);
off_t swapsize; off_t swapsize;
swap.GetSize(&swapsize); swap.GetSize(&swapsize);
currSwap = swapsize / 1048576; currSwap = swapsize / MEGABITE;
system_info info;
get_system_info(&info); get_system_info(&info);
physMem = (info.max_pages * 4096) / 1048576; physMem = (info.max_pages * 4096) / MEGABITE;
minSwap = physMem + (int)(physMem / 3.0); float memcalc = (physMem +(int)(physMem/3.0));
cout << memcalc << endl;
if(settingsFile != NULL){ modf(memcalc/128.0, &minSwap);
cout << minSwap << endl;
minSwap*= 128;
if (settingsFile != NULL) {
fscanf(settingsFile, "%s %s\n", dummy, dummy); fscanf(settingsFile, "%s %s\n", dummy, dummy);
fscanf(settingsFile, "%s %d\n", dummy, &setSwap); fscanf(settingsFile, "%s %d\n", dummy, &setSwap);
setSwap = setSwap / 1048576; setSwap = setSwap / MEGABITE;
} else {
setSwap = (int)minSwap;
}
}//if
else{
setSwap = minSwap;
}//else
fclose(settingsFile); fclose(settingsFile);
BVolume bootVol;
BVolumeRoster *vol_rost = new BVolumeRoster();
vol_rost->GetBootVolume(&bootVol); vol_rost->GetBootVolume(&bootVol);
/* maxSwap is defined by the amount of free space on your boot /* maxSwap is defined by the amount of free space on your boot
* volume, plus the current swap file size, minus an arbitrary * volume, plus the current swap file size, minus an arbitrary
* amount of space, just so you don't fill up your drive completly. * amount of space, just so you don't fill up your drive completly.
*/ */
maxSwap = (bootVol.FreeBytes() / 1048576) + currSwap - 16; maxSwap = (bootVol.FreeBytes() / MEGABITE) + currSwap - 16;
if(currSwap != setSwap){
bool changeMsg = false;
if (currSwap != setSwap) {
currSwap = setSwap; currSwap = setSwap;
changeMsg = true; changeMsg = true;
}
}//if fSettings = new VMSettings();
window = new MainWindow(fSettings->WindowPosition(), physMem, currSwap, minSwap, maxSwap, fSettings);
Main = new MainWindow(fSettings->WindowPosition(), physMem, currSwap, minSwap, maxSwap, fSettings); if (changeMsg) {
window->toggleChangedMessage(true);
if(changeMsg){ }
Main->toggleChangedMessage(true);
}//if
Main->Show();
} }
VM_pref::~VM_pref() VM_pref::~VM_pref()
{//VM_pref::~VM_pref {
delete fSettings; delete fSettings;
}//VM_pref::~VM_pref }
void
VM_pref::ReadyToRun()
{
window->Show();
}
+28 -59
View File
@@ -4,68 +4,37 @@
*/ */
#ifndef MAIN_H #ifndef MAIN_H
#define MAIN_H
#define MAIN_H #include <Application.h>
#include <Volume.h>
#include <VolumeRoster.h>
#include <stdio.h>
#include "VMSettings.h"
#include <OS.h>
#include <Entry.h>
#ifndef _APPLICATION_H class MainWindow;
/**
#include <Application.h> * Main class.
*
#endif * Gets everything going.
*/
#ifndef _VOLUME_H class VM_pref : public BApplication{
public:
#include <Volume.h> /**
* Constructor.
#endif */
#ifndef _VOLUME_ROSTER_H VM_pref();
#include <VolumeRoster.h>
#endif
#ifndef _STDIO_H
#include <stdio.h>
#endif
#ifndef VM_SETTINGS_H
#include "VMSettings.h"
#endif
#ifndef _OS_H
#include <OS.h>
#endif
#ifndef _ENTRY_H
#include <Entry.h>
#endif
/**
* Main class.
*
* Gets everything going.
*/
class VM_pref : public BApplication{
public:
/**
* Constructor.
*/
VM_pref();
/**
* Destructor.
*/
virtual ~VM_pref();
private:
VMSettings *fSettings;
/**
* Destructor.
*/
virtual ~VM_pref();
virtual void ReadyToRun();
private:
VMSettings *fSettings;
MainWindow *window;
}; };
#endif #endif