Ticket #5017: VirtualMemory.patch

File VirtualMemory.patch, 11.1 KB (added by mt, 15 years ago)

patch file

  • VirtualMemory.cpp

     
    1010#include <Alert.h>
    1111#include <TextView.h>
    1212
     13#undef TR_CONTEXT
     14#define TR_CONTEXT "VirtualMemoryApp"
    1315
    1416VirtualMemory::VirtualMemory()
    1517    : BApplication("application/x-vnd.Haiku-VirtualMemory")
    1618{
     19    be_locale->GetAppCatalog(&fCatalog);
    1720}
    1821
    1922
     
    3336void
    3437VirtualMemory::AboutRequested()
    3538{
    36     BAlert *alert = new BAlert("about", "VirtualMemory\n"
     39    BAlert* alert = new BAlert("about", TR("VirtualMemory\n"
    3740        "\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();
    4043    BFont font;
    4144
    4245    view->SetStylable(true);
  • VirtualMemory.h

     
    77
    88
    99#include <Application.h>
     10#include <Catalog.h>
     11#include <Locale.h>
    1012
    1113class VMSettings;
    1214
     
    2325        void GetCurrentSettings(bool& enabled, off_t& size);
    2426
    2527        VMSettings *fSettings; 
     28        BCatalog fCatalog;
    2629};
    2730   
    2831#endif  /* VIRTUAL_MEMORY_H */
  • Jamfile

     
    11SubDir HAIKU_TOP src preferences virtualmemory ;
    22
    3 SetSubDirSupportedPlatformsBeOSCompatible ;
    4 
    5 if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
    6     DRIVER_SETTINGS = driver_settings.c ;
    7 }
    8 
    93Preference VirtualMemory :
    104    VirtualMemory.cpp
    115    SettingsWindow.cpp
    126    Settings.cpp
    137    $(DRIVER_SETTINGS)
    148
    15     : be $(TARGET_LIBSTDC++)
     9    : be $(TARGET_LIBSTDC++) liblocale.so
    1610    : VirtualMemory.rdef
    1711    ;
    1812
    19 if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
    20     SEARCH on [ FGristFiles driver_settings.c ] +=
    21         [ FDirName $(HAIKU_TOP) src system libroot os ] ;
    22 }
     13DoCatalogs VirtualMemory :
     14    x-vnd.Haiku-VirtualMemory
     15    :
     16    VirtualMemory.cpp
     17    SettingsWindow.cpp
     18    : en.catalog
     19    ;
  • SettingsWindow.cpp

     
    1111#include <Alert.h>
    1212#include <Box.h>
    1313#include <Button.h>
     14#include <Catalog.h>
    1415#include <CheckBox.h>
     16#include <GroupLayout.h>
     17#include <GroupLayoutBuilder.h>
     18#include <Locale.h>
    1519#include <StringView.h>
    1620#include <String.h>
    1721#include <Slider.h>
     
    3236static const uint32 kMsgSliderUpdate = 'slup';
    3337static const uint32 kMsgSwapEnabledUpdate = 'swen';
    3438
     39#undef TR_CONTEXT
     40#define TR_CONTEXT "SettingsWindow"
    3541
    3642class SizeSlider : public BSlider {
    3743    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);
    4046        virtual ~SizeSlider();
    4147
    4248        virtual const char* UpdateText() const;
     
    5359byte_string(int64 size)
    5460{
    5561    double value = 1. * size;
    56     static char string[64];
     62    static char string[256];
    5763
    5864    if (value < 1024)
    59         snprintf(string, sizeof(string), "%Ld B", size);
     65        snprintf(string, sizeof(string), TR("%Ld B"), size);
    6066    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)};
    6268        int32 i = -1;
    6369
    6470        do {
     
    6773        } while (value >= 1024 && units[i + 1]);
    6874
    6975        off_t rounded = off_t(value * 100LL);
    70         sprintf(string, "%g %sB", rounded / 100.0, units[i]);
     76        sprintf(string, "%g %s", rounded / 100.0, TR(units[i]));
    7177    }
    7278
    7379    return string;
     
    7783//  #pragma mark -
    7884
    7985
    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)
     86SizeSlider::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)
    8389{
    8490    rgb_color color = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
    8591    UseFillColor(true, &color);
     
    102108
    103109//  #pragma mark -
    104110
    105 
    106111SettingsWindow::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)
    109115{
    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();
    113117
    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"),
    120120        new BMessage(kMsgSwapEnabledUpdate));
    121121    fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
    122     fSwapEnabledCheckBox->ResizeToPreferred();
    123122
    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);
    126124    box->SetLabel(fSwapEnabledCheckBox);
    127     view->AddChild(box);
    128125
    129126    system_info info;
    130127    get_system_info(&info);
    131128
    132     rect.right -= 20;
    133     rect.top = lineHeight;
    134     BString string = "Physical Memory: ";
     129    BString string = TR("Physical Memory: ");
    135130    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());
    140132
    141     rect.OffsetBy(0, lineHeight);
    142     string = "Current Swap File Size: ";
     133    string = TR("Current Swap File Size: ");
    143134    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());
    148137
    149138    BPopUpMenu* menu = new BPopUpMenu("volumes");
    150139
     
    166155            item->SetMarked(true);
    167156    }
    168157
    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);
    173159    field->SetEnabled(false);
    174     box->AddChild(field);
    175160
    176161    off_t minSize, maxSize;
    177162    _GetSwapFileLimits(minSize, maxSize);
    178163
    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:"),
    181165        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"));
    185168    fSizeSlider->SetViewColor(255, 0, 255);
    186     box->AddChild(fSizeSlider);
    187169
    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("", "");
    191171    fWarningStringView->SetAlignment(B_ALIGN_CENTER);
    192     box->AddChild(fWarningStringView);
    193172
    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);
    195192
    196193    // Add "Defaults" and "Revert" buttons
    197194
    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));
    201196    fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
    202     view->AddChild(fDefaultsButton);
    203197
    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));
    208199    fRevertButton->SetEnabled(false);
    209     view->AddChild(fRevertButton);
    210200
    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    );
    216211
    217     // if the strings don't fit on screen, we enlarge the window now - the
    218     // views are already added to the window and will resize automatically
    219     if (Bounds().Width() < view->StringWidth(fSizeSlider->Label()) * 2)
    220         ResizeTo(view->StringWidth(fSizeSlider->Label()) * 2, Bounds().Height());
    221 
    222212    _Update();
    223213
    224214    BScreen screen;
     
    226216
    227217    if (!screenFrame.Contains(fSettings.WindowPosition())) {
    228218        // move on screen, centered
    229         MoveTo(screenFrame.left + (screenFrame.Width() - Bounds().Width()) / 2,
    230             screenFrame.top + (screenFrame.Height() - Bounds().Height()) / 2);
     219        CenterOnScreen();
    231220    } else
    232221        MoveTo(fSettings.WindowPosition());
    233222}
     
    274263    if (fRevertButton->IsEnabled() != changed) {
    275264        fRevertButton->SetEnabled(changed);
    276265        if (changed)
    277             fWarningStringView->SetText("Changes will take effect on restart!");
     266            fWarningStringView->SetText(TR("Changes will take effect on restart!"));
    278267        else
    279268            fWarningStringView->SetText("");
    280269    }
     
    348337                //  as Be did, but I thought a proper warning could be helpful
    349338                //  (for those that want to change that anyway)
    350339                int32 choice = (new BAlert("VirtualMemory",
    351                     "Disabling virtual memory will have unwanted effects on "
     340                    TR("Disabling virtual memory will have unwanted effects on "
    352341                    "system stability once the memory is used up.\n"
    353342                    "Virtual memory does not affect system performance "
    354343                    "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,
    357346                    B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
    358347                if (choice == 1) {
    359348                    fSwapEnabledCheckBox->SetValue(1);