Localize virtualmemory preflet.

Patch done by mt, with some changes by me following sentence-casing of the preflet.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@35007 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-01-11 13:39:27 +00:00
parent 7a2f113eaf
commit eb7157a4b6
4 changed files with 94 additions and 92 deletions
+9 -7
View File
@@ -1,18 +1,12 @@
SubDir HAIKU_TOP src preferences virtualmemory ; SubDir HAIKU_TOP src preferences virtualmemory ;
SetSubDirSupportedPlatformsBeOSCompatible ;
if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
DRIVER_SETTINGS = driver_settings.c ;
}
Preference VirtualMemory : Preference VirtualMemory :
VirtualMemory.cpp VirtualMemory.cpp
SettingsWindow.cpp SettingsWindow.cpp
Settings.cpp Settings.cpp
$(DRIVER_SETTINGS) $(DRIVER_SETTINGS)
: be $(TARGET_LIBSTDC++) : be $(TARGET_LIBSTDC++) liblocale.so
: VirtualMemory.rdef : VirtualMemory.rdef
; ;
@@ -20,3 +14,11 @@ if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
SEARCH on [ FGristFiles driver_settings.c ] += SEARCH on [ FGristFiles driver_settings.c ] +=
[ FDirName $(HAIKU_TOP) src system libroot os ] ; [ FDirName $(HAIKU_TOP) src system libroot os ] ;
} }
DoCatalogs VirtualMemory :
x-vnd.Haiku-VirtualMemory
:
VirtualMemory.cpp
SettingsWindow.cpp
: en.catalog
;
@@ -11,7 +11,11 @@
#include <Alert.h> #include <Alert.h>
#include <Box.h> #include <Box.h>
#include <Button.h> #include <Button.h>
#include <Catalog.h>
#include <CheckBox.h> #include <CheckBox.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <Locale.h>
#include <StringView.h> #include <StringView.h>
#include <String.h> #include <String.h>
#include <Slider.h> #include <Slider.h>
@@ -27,6 +31,10 @@
#include <stdio.h> #include <stdio.h>
#undef TR_CONTEXT
#define TR_CONTEXT "SettingsWindow"
static const uint32 kMsgDefaults = 'dflt'; static const uint32 kMsgDefaults = 'dflt';
static const uint32 kMsgRevert = 'rvrt'; static const uint32 kMsgRevert = 'rvrt';
static const uint32 kMsgSliderUpdate = 'slup'; static const uint32 kMsgSliderUpdate = 'slup';
@@ -35,8 +43,8 @@ static const uint32 kMsgSwapEnabledUpdate = 'swen';
class SizeSlider : public BSlider { class SizeSlider : public BSlider {
public: public:
SizeSlider(BRect rect, const char* name, const char* label, SizeSlider(const char* name, const char* label,
BMessage* message, int32 min, int32 max, uint32 resizingMode); BMessage* message, int32 min, int32 max, uint32 flags);
virtual ~SizeSlider(); virtual ~SizeSlider();
virtual const char* UpdateText() const; virtual const char* UpdateText() const;
@@ -53,12 +61,12 @@ const char *
byte_string(int64 size) byte_string(int64 size)
{ {
double value = 1. * size; double value = 1. * size;
static char string[64]; static char string[256];
if (value < 1024) if (value < 1024)
snprintf(string, sizeof(string), "%Ld B", size); snprintf(string, sizeof(string), TR("%Ld B"), size);
else { else {
const char *units[] = {"K", "M", "G", NULL}; static const char *units[] = {TR_MARK("KB"), TR_MARK("MB"), TR_MARK("GB"), NULL};
int32 i = -1; int32 i = -1;
do { do {
@@ -67,7 +75,7 @@ byte_string(int64 size)
} while (value >= 1024 && units[i + 1]); } while (value >= 1024 && units[i + 1]);
off_t rounded = off_t(value * 100LL); off_t rounded = off_t(value * 100LL);
sprintf(string, "%g %sB", rounded / 100.0, units[i]); sprintf(string, "%g %sB", rounded / 100.0, TR(units[i]));
} }
return string; return string;
@@ -77,9 +85,9 @@ byte_string(int64 size)
// #pragma mark - // #pragma mark -
SizeSlider::SizeSlider(BRect rect, const char* name, const char* label, SizeSlider::SizeSlider(const char* name, const char* label,
BMessage* message, int32 min, int32 max, uint32 resizingMode) BMessage* message, int32 min, int32 max, uint32 flags)
: BSlider(rect, name, label, message, min, max, B_BLOCK_THUMB, resizingMode) : BSlider(name, label, message, min, max, B_HORIZONTAL, B_BLOCK_THUMB, flags)
{ {
rgb_color color = ui_color(B_CONTROL_HIGHLIGHT_COLOR); rgb_color color = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
UseFillColor(true, &color); UseFillColor(true, &color);
@@ -104,53 +112,36 @@ SizeSlider::UpdateText() const
SettingsWindow::SettingsWindow() SettingsWindow::SettingsWindow()
: BWindow(BRect(0, 0, 269, 172), "VirtualMemory", B_TITLED_WINDOW, : BWindow(BRect(0, 0, 269, 172), TR("VirtualMemory"), B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS)
{ {
BRect rect = Bounds(); BView* view = new BGroupView();
BView* view = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW);
view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
font_height fontHeight; fSwapEnabledCheckBox = new BCheckBox("enable swap",
be_plain_font->GetHeight(&fontHeight); TR("Enable virtual memory"),
float lineHeight = ceil(fontHeight.ascent + fontHeight.descent + fontHeight.ascent);
fSwapEnabledCheckBox = new BCheckBox(rect, "enable swap", "Enable virtual memory",
new BMessage(kMsgSwapEnabledUpdate)); new BMessage(kMsgSwapEnabledUpdate));
fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled()); fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
fSwapEnabledCheckBox->ResizeToPreferred();
rect.InsetBy(10, 10); BBox* box = new BBox("box", B_FOLLOW_LEFT_RIGHT);
BBox* box = new BBox(rect, "box", B_FOLLOW_LEFT_RIGHT);
box->SetLabel(fSwapEnabledCheckBox); box->SetLabel(fSwapEnabledCheckBox);
view->AddChild(box);
system_info info; system_info info;
get_system_info(&info); get_system_info(&info);
rect.right -= 20; BString string = TR("Physical memory: ");
rect.top = lineHeight;
BString string = "Physical memory: ";
string << byte_string((off_t)info.max_pages * B_PAGE_SIZE); string << byte_string((off_t)info.max_pages * B_PAGE_SIZE);
BStringView* stringView = new BStringView(rect, "physical memory", string.String(), BStringView* memoryView = new BStringView("physical memory", string.String());
B_FOLLOW_NONE);
stringView->ResizeToPreferred();
box->AddChild(stringView);
rect.OffsetBy(0, lineHeight); string = TR("Current swap file size: ");
string = "Current swap file size: ";
string << byte_string(fSettings.SwapSize()); string << byte_string(fSettings.SwapSize());
stringView = new BStringView(rect, "current swap size", string.String(), BStringView* swapfileView = new BStringView("current swap size", string.String());
B_FOLLOW_NONE);
stringView->ResizeToPreferred();
box->AddChild(stringView);
BPopUpMenu* menu = new BPopUpMenu("volumes"); BPopUpMenu* menu = new BPopUpMenu("volumes");
// collect volumes // collect volumes
// ToDo: listen to volume changes! // TODO: listen to volume changes!
// ToDo: accept dropped volumes // TODO: accept dropped volumes
BVolumeRoster volumeRoster; BVolumeRoster volumeRoster;
BVolume volume; BVolume volume;
@@ -166,58 +157,60 @@ SettingsWindow::SettingsWindow()
item->SetMarked(true); item->SetMarked(true);
} }
rect.OffsetBy(0, lineHeight); BMenuField* field = new BMenuField("devices", TR("Use volume:"), menu);
BMenuField* field = new BMenuField(rect, "devices", "Use volume:", menu);
field->SetDivider(field->StringWidth(field->Label()) + 8);
field->ResizeToPreferred();
field->SetEnabled(false); field->SetEnabled(false);
box->AddChild(field);
off_t minSize, maxSize; off_t minSize, maxSize;
_GetSwapFileLimits(minSize, maxSize); _GetSwapFileLimits(minSize, maxSize);
rect.OffsetBy(0, lineHeight + 8); fSizeSlider = new SizeSlider("size slider", TR("Requested swap file size:"),
fSizeSlider = new SizeSlider(rect, "size slider", "Requested swap file size:",
new BMessage(kMsgSliderUpdate), minSize / kMegaByte, maxSize / kMegaByte, new BMessage(kMsgSliderUpdate), minSize / kMegaByte, maxSize / kMegaByte,
B_FOLLOW_LEFT_RIGHT); B_WILL_DRAW | B_FRAME_EVENTS);
fSizeSlider->SetLimitLabels("999 MB", "999 MB"); fSizeSlider->SetLimitLabels(TR("999 MB"), TR("999 MB"));
fSizeSlider->ResizeToPreferred();
fSizeSlider->SetViewColor(255, 0, 255); fSizeSlider->SetViewColor(255, 0, 255);
box->AddChild(fSizeSlider); box->AddChild(fSizeSlider);
rect.OffsetBy(0, fSizeSlider->Frame().Height() + 5); fWarningStringView = new BStringView("", "");
rect.bottom = rect.top + stringView->Frame().Height();
fWarningStringView = new BStringView(rect, "", "", B_FOLLOW_ALL);
fWarningStringView->SetAlignment(B_ALIGN_CENTER); fWarningStringView->SetAlignment(B_ALIGN_CENTER);
box->AddChild(fWarningStringView);
box->ResizeTo(box->Frame().Width(), fWarningStringView->Frame().bottom + 10); view->SetLayout(new BGroupLayout(B_HORIZONTAL));
view->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
.AddGroup(B_HORIZONTAL)
.Add(memoryView)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL)
.Add(swapfileView)
.AddGlue()
.End()
.AddGroup(B_HORIZONTAL)
.Add(field)
.AddGlue()
.End()
.Add(fSizeSlider)
.Add(fWarningStringView)
.SetInsets(10, 10, 10, 10)
);
box->AddChild(view);
// Add "Defaults" and "Revert" buttons // Add "Defaults" and "Revert" buttons
rect.top = box->Frame().bottom + 10; fDefaultsButton = new BButton("defaults", TR("Defaults"), new BMessage(kMsgDefaults));
fDefaultsButton = new BButton(rect, "defaults", "Defaults", new BMessage(kMsgDefaults));
fDefaultsButton->ResizeToPreferred();
fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
view->AddChild(fDefaultsButton);
rect = fDefaultsButton->Frame(); fRevertButton = new BButton("revert", TR("Revert"), new BMessage(kMsgRevert));
rect.OffsetBy(rect.Width() + 10, 0);
fRevertButton = new BButton(rect, "revert", "Revert", new BMessage(kMsgRevert));
fRevertButton->ResizeToPreferred();
fRevertButton->SetEnabled(false); fRevertButton->SetEnabled(false);
view->AddChild(fRevertButton);
view->ResizeTo(view->Frame().Width(), fRevertButton->Frame().bottom + 10); SetLayout(new BGroupLayout(B_HORIZONTAL));
ResizeTo(view->Bounds().Width(), view->Bounds().Height()); AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
AddChild(view); .Add(box)
// add view after resizing the window, so that the view's resizing .AddGroup(B_HORIZONTAL, 10)
// mode is not used (we already layed out the views for the new height) .Add(fDefaultsButton)
.Add(fRevertButton)
// if the strings don't fit on screen, we enlarge the window now - the .AddGlue()
// views are already added to the window and will resize automatically .End()
if (Bounds().Width() < view->StringWidth(fSizeSlider->Label()) * 2) .SetInsets(10, 10, 10, 10)
ResizeTo(view->StringWidth(fSizeSlider->Label()) * 2, Bounds().Height()); );
_Update(); _Update();
@@ -226,8 +219,7 @@ SettingsWindow::SettingsWindow()
if (!screenFrame.Contains(fSettings.WindowPosition())) { if (!screenFrame.Contains(fSettings.WindowPosition())) {
// move on screen, centered // move on screen, centered
MoveTo(screenFrame.left + (screenFrame.Width() - Bounds().Width()) / 2, CenterOnScreen();
screenFrame.top + (screenFrame.Height() - Bounds().Height()) / 2);
} else } else
MoveTo(fSettings.WindowPosition()); MoveTo(fSettings.WindowPosition());
} }
@@ -238,7 +230,7 @@ SettingsWindow::~SettingsWindow()
} }
void void
SettingsWindow::_Update() SettingsWindow::_Update()
{ {
if ((fSwapEnabledCheckBox->Value() != 0) != fSettings.SwapEnabled()) if ((fSwapEnabledCheckBox->Value() != 0) != fSettings.SwapEnabled())
@@ -250,7 +242,7 @@ SettingsWindow::_Update()
minLabel << byte_string(minSize); minLabel << byte_string(minSize);
maxLabel << byte_string(maxSize); maxLabel << byte_string(maxSize);
if (minLabel != fSizeSlider->MinLimitLabel() if (minLabel != fSizeSlider->MinLimitLabel()
|| maxLabel != fSizeSlider->MaxLimitLabel()) { || maxLabel != fSizeSlider->MaxLimitLabel()) {
fSizeSlider->SetLimitLabels(minLabel.String(), maxLabel.String()); fSizeSlider->SetLimitLabels(minLabel.String(), maxLabel.String());
#ifdef __HAIKU__ #ifdef __HAIKU__
fSizeSlider->SetLimits(minSize / kMegaByte, maxSize / kMegaByte); fSizeSlider->SetLimits(minSize / kMegaByte, maxSize / kMegaByte);
@@ -274,14 +266,14 @@ SettingsWindow::_Update()
if (fRevertButton->IsEnabled() != changed) { if (fRevertButton->IsEnabled() != changed) {
fRevertButton->SetEnabled(changed); fRevertButton->SetEnabled(changed);
if (changed) if (changed)
fWarningStringView->SetText("Changes will take effect on restart!"); fWarningStringView->SetText(TR("Changes will take effect on restart!"));
else else
fWarningStringView->SetText(""); fWarningStringView->SetText("");
} }
} }
status_t status_t
SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize) SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
{ {
// minimum size is an arbitrarily chosen MB // minimum size is an arbitrarily chosen MB
@@ -348,12 +340,12 @@ SettingsWindow::MessageReceived(BMessage* message)
// as Be did, but I thought a proper warning could be helpful // as Be did, but I thought a proper warning could be helpful
// (for those that want to change that anyway) // (for those that want to change that anyway)
int32 choice = (new BAlert("VirtualMemory", int32 choice = (new BAlert("VirtualMemory",
"Disabling virtual memory will have unwanted effects on " TR("Disabling virtual memory will have unwanted effects on "
"system stability once the memory is used up.\n" "system stability once the memory is used up.\n"
"Virtual memory does not affect system performance " "Virtual memory does not affect system performance "
"until this point is reached.\n\n" "until this point is reached.\n\n"
"Are you really sure you want to turn it off?", "Are you really sure you want to turn it off?"),
"Turn off", "Keep enabled", NULL, TR("Turn off"), TR("Keep enabled"), NULL,
B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
if (choice == 1) { if (choice == 1) {
fSwapEnabledCheckBox->SetValue(1); fSwapEnabledCheckBox->SetValue(1);
@@ -11,9 +11,14 @@
#include <TextView.h> #include <TextView.h>
#undef TR_CONTEXT
#define TR_CONTEXT "VirtualMemoryApp"
VirtualMemory::VirtualMemory() VirtualMemory::VirtualMemory()
: BApplication("application/x-vnd.Haiku-VirtualMemory") : BApplication("application/x-vnd.Haiku-VirtualMemory")
{ {
be_locale->GetAppCatalog(&fCatalog);
} }
@@ -33,10 +38,10 @@ VirtualMemory::ReadyToRun()
void void
VirtualMemory::AboutRequested() VirtualMemory::AboutRequested()
{ {
BAlert *alert = new BAlert("about", "VirtualMemory\n" BAlert* alert = new BAlert("about", TR("VirtualMemory\n"
"\twritten by Axel Dörfler\n" "\twritten by Axel Dörfler\n"
"\tCopyright 2005, Haiku.\n", "OK"); "\tCopyright 2005, Haiku.\n"), TR("OK"));
BTextView *view = alert->TextView(); BTextView* view = alert->TextView();
BFont font; BFont font;
view->SetStylable(true); view->SetStylable(true);
@@ -7,6 +7,8 @@
#include <Application.h> #include <Application.h>
#include <Catalog.h>
#include <Locale.h>
class VMSettings; class VMSettings;
@@ -23,6 +25,7 @@ class VirtualMemory : public BApplication {
void GetCurrentSettings(bool& enabled, off_t& size); void GetCurrentSettings(bool& enabled, off_t& size);
VMSettings *fSettings; VMSettings *fSettings;
BCatalog fCatalog;
}; };
#endif /* VIRTUAL_MEMORY_H */ #endif /* VIRTUAL_MEMORY_H */