Ticket #5017: VirtualMemory.patch
File VirtualMemory.patch, 11.1 KB (added by , 15 years ago) |
---|
-
VirtualMemory.cpp
10 10 #include <Alert.h> 11 11 #include <TextView.h> 12 12 13 #undef TR_CONTEXT 14 #define TR_CONTEXT "VirtualMemoryApp" 13 15 14 16 VirtualMemory::VirtualMemory() 15 17 : BApplication("application/x-vnd.Haiku-VirtualMemory") 16 18 { 19 be_locale->GetAppCatalog(&fCatalog); 17 20 } 18 21 19 22 … … 33 36 void 34 37 VirtualMemory::AboutRequested() 35 38 { 36 BAlert *alert = new BAlert("about","VirtualMemory\n"39 BAlert* alert = new BAlert("about", TR("VirtualMemory\n" 37 40 "\twritten by Axel Dörfler\n" 38 "\tCopyright 2005, Haiku.\n" , "Ok");39 BTextView *view = alert->TextView();41 "\tCopyright 2005, Haiku.\n"), TR("Ok")); 42 BTextView* view = alert->TextView(); 40 43 BFont font; 41 44 42 45 view->SetStylable(true); -
VirtualMemory.h
7 7 8 8 9 9 #include <Application.h> 10 #include <Catalog.h> 11 #include <Locale.h> 10 12 11 13 class VMSettings; 12 14 … … 23 25 void GetCurrentSettings(bool& enabled, off_t& size); 24 26 25 27 VMSettings *fSettings; 28 BCatalog fCatalog; 26 29 }; 27 30 28 31 #endif /* VIRTUAL_MEMORY_H */ -
Jamfile
1 1 SubDir HAIKU_TOP src preferences virtualmemory ; 2 2 3 SetSubDirSupportedPlatformsBeOSCompatible ;4 5 if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {6 DRIVER_SETTINGS = driver_settings.c ;7 }8 9 3 Preference VirtualMemory : 10 4 VirtualMemory.cpp 11 5 SettingsWindow.cpp 12 6 Settings.cpp 13 7 $(DRIVER_SETTINGS) 14 8 15 : be $(TARGET_LIBSTDC++) 9 : be $(TARGET_LIBSTDC++) liblocale.so 16 10 : VirtualMemory.rdef 17 11 ; 18 12 19 if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) { 20 SEARCH on [ FGristFiles driver_settings.c ] += 21 [ FDirName $(HAIKU_TOP) src system libroot os ] ; 22 } 13 DoCatalogs VirtualMemory : 14 x-vnd.Haiku-VirtualMemory 15 : 16 VirtualMemory.cpp 17 SettingsWindow.cpp 18 : en.catalog 19 ; -
SettingsWindow.cpp
11 11 #include <Alert.h> 12 12 #include <Box.h> 13 13 #include <Button.h> 14 #include <Catalog.h> 14 15 #include <CheckBox.h> 16 #include <GroupLayout.h> 17 #include <GroupLayoutBuilder.h> 18 #include <Locale.h> 15 19 #include <StringView.h> 16 20 #include <String.h> 17 21 #include <Slider.h> … … 32 36 static const uint32 kMsgSliderUpdate = 'slup'; 33 37 static const uint32 kMsgSwapEnabledUpdate = 'swen'; 34 38 39 #undef TR_CONTEXT 40 #define TR_CONTEXT "SettingsWindow" 35 41 36 42 class SizeSlider : public BSlider { 37 43 public: 38 SizeSlider( BRect rect,const char* name, const char* label,39 BMessage* message, int32 min, int32 max, uint32 resizingMode);44 SizeSlider(const char* name, const char* label, 45 BMessage* message, int32 min, int32 max, uint32 flags); 40 46 virtual ~SizeSlider(); 41 47 42 48 virtual const char* UpdateText() const; … … 53 59 byte_string(int64 size) 54 60 { 55 61 double value = 1. * size; 56 static char string[ 64];62 static char string[256]; 57 63 58 64 if (value < 1024) 59 snprintf(string, sizeof(string), "%Ld B", size);65 snprintf(string, sizeof(string), TR("%Ld B"), size); 60 66 else { 61 const char *units[] = {"K", "M", "G", NULL};67 static const char* units[] = {TR_MARK("KB"), TR_MARK("MB"), TR_MARK("GB"), TR_MARK(NULL)}; 62 68 int32 i = -1; 63 69 64 70 do { … … 67 73 } while (value >= 1024 && units[i + 1]); 68 74 69 75 off_t rounded = off_t(value * 100LL); 70 sprintf(string, "%g %s B", rounded / 100.0, units[i]);76 sprintf(string, "%g %s", rounded / 100.0, TR(units[i])); 71 77 } 72 78 73 79 return string; … … 77 83 // #pragma mark - 78 84 79 85 80 SizeSlider::SizeSlider( BRect rect,const char* name, const char* label,81 BMessage* message, int32 min, int32 max, uint32 resizingMode)82 : BSlider( rect, name, label, message, min, max, B_BLOCK_THUMB, resizingMode)86 SizeSlider::SizeSlider(const char* name, const char* label, 87 BMessage* message, int32 min, int32 max, uint32 flags) 88 : BSlider(name, label, message, min, max, B_HORIZONTAL, B_BLOCK_THUMB, flags) 83 89 { 84 90 rgb_color color = ui_color(B_CONTROL_HIGHLIGHT_COLOR); 85 91 UseFillColor(true, &color); … … 102 108 103 109 // #pragma mark - 104 110 105 106 111 SettingsWindow::SettingsWindow() 107 : BWindow(BRect(0, 0, 269, 172), "VirtualMemory", B_TITLED_WINDOW, 108 B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) 112 : BWindow(BRect(0, 0, 269, 172), TR("VirtualMemory"), B_TITLED_WINDOW, 113 B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE 114 | B_AUTO_UPDATE_SIZE_LIMITS) 109 115 { 110 BRect rect = Bounds(); 111 BView* view = new BView(rect, "background", B_FOLLOW_ALL, B_WILL_DRAW); 112 view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 116 BView* view = new BGroupView(); 113 117 114 font_height fontHeight; 115 be_plain_font->GetHeight(&fontHeight); 116 117 float lineHeight = ceil(fontHeight.ascent + fontHeight.descent + fontHeight.ascent); 118 119 fSwapEnabledCheckBox = new BCheckBox(rect, "enable swap", "Enable Virtual Memory", 118 fSwapEnabledCheckBox = new BCheckBox("enable swap", 119 TR("Enable Virtual Memory"), 120 120 new BMessage(kMsgSwapEnabledUpdate)); 121 121 fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled()); 122 fSwapEnabledCheckBox->ResizeToPreferred();123 122 124 rect.InsetBy(10, 10); 125 BBox* box = new BBox(rect, "box", B_FOLLOW_LEFT_RIGHT); 123 BBox* box = new BBox("box", B_FOLLOW_LEFT_RIGHT); 126 124 box->SetLabel(fSwapEnabledCheckBox); 127 view->AddChild(box);128 125 129 126 system_info info; 130 127 get_system_info(&info); 131 128 132 rect.right -= 20; 133 rect.top = lineHeight; 134 BString string = "Physical Memory: "; 129 BString string = TR("Physical Memory: "); 135 130 string << byte_string((off_t)info.max_pages * B_PAGE_SIZE); 136 BStringView* stringView = new BStringView(rect, "physical memory", string.String(), 137 B_FOLLOW_NONE); 138 stringView->ResizeToPreferred(); 139 box->AddChild(stringView); 131 BStringView* memoryView = new BStringView("physical memory", string.String()); 140 132 141 rect.OffsetBy(0, lineHeight); 142 string = "Current Swap File Size: "; 133 string = TR("Current Swap File Size: "); 143 134 string << byte_string(fSettings.SwapSize()); 144 stringView = new BStringView(rect, "current swap size", string.String(), 145 B_FOLLOW_NONE); 146 stringView->ResizeToPreferred(); 147 box->AddChild(stringView); 135 BStringView* swapfileView = new BStringView("current swap size", 136 string.String()); 148 137 149 138 BPopUpMenu* menu = new BPopUpMenu("volumes"); 150 139 … … 166 155 item->SetMarked(true); 167 156 } 168 157 169 rect.OffsetBy(0, lineHeight); 170 BMenuField* field = new BMenuField(rect, "devices", "Use Volume:", menu); 171 field->SetDivider(field->StringWidth(field->Label()) + 8); 172 field->ResizeToPreferred(); 158 BMenuField* field = new BMenuField(TR("Use Volume:"), menu); 173 159 field->SetEnabled(false); 174 box->AddChild(field);175 160 176 161 off_t minSize, maxSize; 177 162 _GetSwapFileLimits(minSize, maxSize); 178 163 179 rect.OffsetBy(0, lineHeight + 8); 180 fSizeSlider = new SizeSlider(rect, "size slider", "Requested Swap File Size:", 164 fSizeSlider = new SizeSlider("size slider", TR("Requested Swap File Size:"), 181 165 new BMessage(kMsgSliderUpdate), minSize / kMegaByte, maxSize / kMegaByte, 182 B_FOLLOW_LEFT_RIGHT); 183 fSizeSlider->SetLimitLabels("999 MB", "999 MB"); 184 fSizeSlider->ResizeToPreferred(); 166 B_WILL_DRAW | B_FRAME_EVENTS); 167 fSizeSlider->SetLimitLabels(TR("999 MB"), TR("999 MB")); 185 168 fSizeSlider->SetViewColor(255, 0, 255); 186 box->AddChild(fSizeSlider);187 169 188 rect.OffsetBy(0, fSizeSlider->Frame().Height() + 5); 189 rect.bottom = rect.top + stringView->Frame().Height(); 190 fWarningStringView = new BStringView(rect, "", "", B_FOLLOW_ALL); 170 fWarningStringView = new BStringView("", ""); 191 171 fWarningStringView->SetAlignment(B_ALIGN_CENTER); 192 box->AddChild(fWarningStringView);193 172 194 box->ResizeTo(box->Frame().Width(), fWarningStringView->Frame().bottom + 10); 173 view->SetLayout(new BGroupLayout(B_HORIZONTAL)); 174 view->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 175 .AddGroup(B_HORIZONTAL) 176 .Add(memoryView) 177 .AddGlue() 178 .End() 179 .AddGroup(B_HORIZONTAL) 180 .Add(swapfileView) 181 .AddGlue() 182 .End() 183 .AddGroup(B_HORIZONTAL) 184 .Add(field) 185 .AddGlue() 186 .End() 187 .Add(fSizeSlider) 188 .Add(fWarningStringView) 189 .SetInsets(10, 10, 10, 10) 190 ); 191 box->AddChild(view); 195 192 196 193 // Add "Defaults" and "Revert" buttons 197 194 198 rect.top = box->Frame().bottom + 10; 199 fDefaultsButton = new BButton(rect, "defaults", "Defaults", new BMessage(kMsgDefaults)); 200 fDefaultsButton->ResizeToPreferred(); 195 fDefaultsButton = new BButton(TR("Defaults"), new BMessage(kMsgDefaults)); 201 196 fDefaultsButton->SetEnabled(fSettings.IsDefaultable()); 202 view->AddChild(fDefaultsButton);203 197 204 rect = fDefaultsButton->Frame(); 205 rect.OffsetBy(rect.Width() + 10, 0); 206 fRevertButton = new BButton(rect, "revert", "Revert", new BMessage(kMsgRevert)); 207 fRevertButton->ResizeToPreferred(); 198 fRevertButton = new BButton(TR("Revert"), new BMessage(kMsgRevert)); 208 199 fRevertButton->SetEnabled(false); 209 view->AddChild(fRevertButton);210 200 211 view->ResizeTo(view->Frame().Width(), fRevertButton->Frame().bottom + 10); 212 ResizeTo(view->Bounds().Width(), view->Bounds().Height()); 213 AddChild(view); 214 // add view after resizing the window, so that the view's resizing 215 // mode is not used (we already layed out the views for the new height) 201 SetLayout(new BGroupLayout(B_HORIZONTAL)); 202 AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 203 .Add(box) 204 .AddGroup(B_HORIZONTAL, 10) 205 .Add(fDefaultsButton) 206 .Add(fRevertButton) 207 .AddGlue() 208 .End() 209 .SetInsets(10, 10, 10, 10) 210 ); 216 211 217 // if the strings don't fit on screen, we enlarge the window now - the218 // views are already added to the window and will resize automatically219 if (Bounds().Width() < view->StringWidth(fSizeSlider->Label()) * 2)220 ResizeTo(view->StringWidth(fSizeSlider->Label()) * 2, Bounds().Height());221 222 212 _Update(); 223 213 224 214 BScreen screen; … … 226 216 227 217 if (!screenFrame.Contains(fSettings.WindowPosition())) { 228 218 // move on screen, centered 229 MoveTo(screenFrame.left + (screenFrame.Width() - Bounds().Width()) / 2, 230 screenFrame.top + (screenFrame.Height() - Bounds().Height()) / 2); 219 CenterOnScreen(); 231 220 } else 232 221 MoveTo(fSettings.WindowPosition()); 233 222 } … … 274 263 if (fRevertButton->IsEnabled() != changed) { 275 264 fRevertButton->SetEnabled(changed); 276 265 if (changed) 277 fWarningStringView->SetText( "Changes will take effect on restart!");266 fWarningStringView->SetText(TR("Changes will take effect on restart!")); 278 267 else 279 268 fWarningStringView->SetText(""); 280 269 } … … 348 337 // as Be did, but I thought a proper warning could be helpful 349 338 // (for those that want to change that anyway) 350 339 int32 choice = (new BAlert("VirtualMemory", 351 "Disabling virtual memory will have unwanted effects on "340 TR("Disabling virtual memory will have unwanted effects on " 352 341 "system stability once the memory is used up.\n" 353 342 "Virtual memory does not affect system performance " 354 343 "until this point is reached.\n\n" 355 "Are you really sure you want to turn it off?" ,356 "Turn Off", "Keep Enabled", NULL,344 "Are you really sure you want to turn it off?"), 345 TR("Turn Off"), TR("Keep Enabled"), NULL, 357 346 B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go(); 358 347 if (choice == 1) { 359 348 fSwapEnabledCheckBox->SetValue(1);