Updated
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10825 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
d0733791ae
commit
ea932d8aee
@ -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 ;
|
||||
|
@ -6,7 +6,11 @@
|
||||
*/
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "Pref_Utils.h"
|
||||
|
||||
#include <String.h>
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -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 <Application.h>
|
||||
|
||||
#endif
|
||||
#ifndef _WINDOW_H
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
#endif
|
||||
#ifndef _STRING_VIEW_H
|
||||
|
||||
#include <StringView.h>
|
||||
|
||||
#endif
|
||||
#ifndef _BOX_H
|
||||
|
||||
#include <Box.h>
|
||||
|
||||
#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"
|
||||
/*!
|
||||
* 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 <Application.h>
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <Slider.h>
|
||||
#include <stdio.h>
|
||||
#include <StringView.h>
|
||||
#include <Window.h>
|
||||
|
||||
#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
|
||||
|
30
src/prefs/virtualmemory/Pref_Utils.cpp
Normal file
30
src/prefs/virtualmemory/Pref_Utils.cpp
Normal 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
src/prefs/virtualmemory/Pref_Utils.h
Normal file
10
src/prefs/virtualmemory/Pref_Utils.h
Normal 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.
@ -1,19 +1,9 @@
|
||||
#ifndef VM_SETTINGS_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>
|
||||
|
||||
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
|
||||
|
@ -1,8 +1,8 @@
|
||||
#ifndef VM_SETTINGS_H_
|
||||
#define VM_SETTINGS_H_
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <Screen.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
class VMSettings{
|
||||
public :
|
||||
|
@ -8,7 +8,9 @@
|
||||
|
||||
#include "MainWindow.h"
|
||||
#include "main.h"
|
||||
|
||||
#include <iostream>
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -4,68 +4,37 @@
|
||||
*/
|
||||
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#define MAIN_H
|
||||
|
||||
#ifndef _APPLICATION_H
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _VOLUME_H
|
||||
|
||||
#include <Volume.h>
|
||||
|
||||
#endif
|
||||
#ifndef _VOLUME_ROSTER_H
|
||||
|
||||
#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;
|
||||
|
||||
#include <Application.h>
|
||||
#include <Volume.h>
|
||||
#include <VolumeRoster.h>
|
||||
#include <stdio.h>
|
||||
#include "VMSettings.h"
|
||||
#include <OS.h>
|
||||
#include <Entry.h>
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user