Ticket #3723: vm_preflet_29102011.patch

File vm_preflet_29102011.patch, 36.8 KB (added by hamish, 12 years ago)
  • src/preferences/virtualmemory/VirtualMemory.cpp

     
    88#include "SettingsWindow.h"
    99
    1010#include <Alert.h>
     11#include <Catalog.h>
    1112#include <TextView.h>
    1213
    1314
  • src/preferences/virtualmemory/Settings.cpp

     
    77
    88#include "Settings.h"
    99
     10#include <stdio.h>
     11#include <stdlib.h>
     12
    1013#include <File.h>
    11 #include <Entry.h>
    1214#include <FindDirectory.h>
    1315#include <Path.h>
    14 #include <Volume.h>
    1516#include <VolumeRoster.h>
     17
    1618#include <driver_settings.h>
    1719
    18 #include <stdio.h>
    19 #include <stdlib.h>
    20 #include <string.h>
    2120
     21static const char* const kWindowSettingsFile = "VM_data";
     22static const char* const kVirtualMemorySettings = "virtual_memory";
     23static const off_t kMegaByte = 1024 * 1024;
    2224
    23 static const char* kWindowSettingsFile = "VM_data";
    24 static const char* kVirtualMemorySettings = "virtual_memory";
    25 static const int64 kMegaByte = 1024 * 1024;
    2625
    27 
    2826Settings::Settings()
    29     :
    30     fPositionUpdated(false)
    3127{
    32     _ReadWindowSettings();
    33     _ReadSwapSettings();
    34 }
     28    fDefaultSettings.enabled = true;
    3529
    36 
    37 Settings::~Settings()
    38 {
    39     _WriteWindowSettings();
    40     _WriteSwapSettings();
     30    system_info sysInfo;
     31    get_system_info(&sysInfo);
     32    fDefaultSettings.size = (off_t)sysInfo.max_pages * B_PAGE_SIZE * 2;
     33    fDefaultSettings.volume = dev_for_path("/boot");
    4134}
    4235
    4336
    4437void
    45 Settings::SetWindowPosition(BPoint position)
     38Settings::SetSwapEnabled(bool enabled, bool revertable)
    4639{
    47     if (position == fWindowPosition)
    48         return;
    49 
    50     fWindowPosition = position;
    51     fPositionUpdated = true;
     40    fCurrentSettings.enabled = enabled;
     41    if (!revertable)
     42        fInitialSettings.enabled = enabled;
    5243}
    5344
    5445
    5546void
    56 Settings::SetSwapEnabled(bool enabled)
     47Settings::SetSwapSize(off_t size, bool revertable)
    5748{
    58     fSwapEnabled = enabled;
     49    fCurrentSettings.size = size;
     50    if (!revertable)
     51        fInitialSettings.size = size;
    5952}
    6053
    6154
    6255void
    63 Settings::SetSwapSize(off_t size)
     56Settings::SetSwapVolume(dev_t volume, bool revertable)
    6457{
    65     fSwapSize = size;
    66 }
     58    fCurrentSettings.volume = volume;
     59    if (!revertable)
     60        fInitialSettings.volume = volume;
    6761
    68 
    69 void
    70 Settings::SetSwapVolume(BVolume &volume)
    71 {
    72     if (volume.Device() == SwapVolume().Device()
    73         || volume.InitCheck() != B_OK)
    74         return;
    75 
    76     fSwapVolume.SetTo(volume.Device());
    7762}
    7863
    7964
    8065void
    81 Settings::RevertSwapChanges()
     66Settings::SetWindowPosition(BPoint position)
    8267{
    83     fSwapEnabled = fInitialSwapEnabled;
    84     fSwapSize = fInitialSwapSize;
    85     fSwapVolume.SetTo(fInitialSwapVolume);
     68    fWindowPosition = position;
    8669}
    8770
    8871
    89 bool
    90 Settings::IsRevertible()
     72status_t
     73Settings::ReadWindowSettings()
    9174{
    92     return fSwapEnabled != fInitialSwapEnabled
    93         || fSwapSize != fInitialSwapSize
    94         || fSwapVolume.Device() != fInitialSwapVolume;
    95 }
     75    BPath path;
     76    if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
     77        return B_ERROR;
    9678
     79    path.Append(kWindowSettingsFile);
     80    BFile file;
     81    if (file.SetTo(path.Path(), B_READ_ONLY) != B_OK)
     82        return B_ERROR;
    9783
    98 void
    99 Settings::_ReadWindowSettings()
    100 {
    101     bool success = false;
    102 
    103     BPath path;
    104     if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
    105         path.Append(kWindowSettingsFile);
    106         BFile file;
    107         if (file.SetTo(path.Path(), B_READ_ONLY) == B_OK)
    108             if (file.Read(&fWindowPosition, sizeof(BPoint)) == sizeof(BPoint))
    109                 success = true;
    110     }
    111 
    112     if (!success)
    113         fWindowPosition.Set(-1, -1);
     84    if (file.Read(&fWindowPosition, sizeof(BPoint)) == sizeof(BPoint))
     85        return B_OK;
     86    else
     87        return B_ERROR;
    11488}
    11589
    11690
    117 void
    118 Settings::_WriteWindowSettings()
     91status_t
     92Settings::WriteWindowSettings()
    11993{
    120     if (!fPositionUpdated)
    121         return;
    122 
    12394    BPath path;
    12495    if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) < B_OK)
    125         return;
     96        return B_ERROR;
    12697
    12798    path.Append(kWindowSettingsFile);
    12899
    129100    BFile file;
    130     if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE) == B_OK)
    131         file.Write(&fWindowPosition, sizeof(BPoint));
     101    if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)
     102        != B_OK)
     103        return B_ERROR;
     104
     105    file.Write(&fWindowPosition, sizeof(BPoint));
     106    return B_OK;
    132107}
    133108
    134109
    135 void
    136 Settings::_ReadSwapSettings()
     110status_t
     111Settings::ReadSwapSettings()
    137112{
    138113    void* settings = load_driver_settings(kVirtualMemorySettings);
    139     if (settings != NULL) {
    140         SetSwapEnabled(get_driver_boolean_parameter(settings, "vm", false, false));
    141         const char* swapSize = get_driver_parameter(settings, "swap_size", NULL, NULL);
    142         SetSwapSize(swapSize ? atoll(swapSize) : 0);
    143        
    144 #ifdef SWAP_VOLUME_IMPLEMENTED
    145         // we need to hang onto this one
    146         fBadVolName = strdup(get_driver_parameter(settings, "swap_volume", NULL, NULL));
    147        
    148         BVolumeRoster volumeRoster;
    149         BVolume temporaryVolume;
    150        
    151         if (fBadVolName != NULL) {
    152             status_t result = volumeRoster.GetNextVolume(&temporaryVolume);
    153             char volumeName[B_FILE_NAME_LENGTH];
    154             while (result != B_BAD_VALUE) {
    155                 temporaryVolume.GetName(volumeName);
    156                 if (strcmp(volumeName, fBadVolName) == 0
    157                     && temporaryVolume.IsPersistent() && volumeName[0]) {
    158                     SetSwapVolume(temporaryVolume);
    159                     break;
    160                 }
    161                 result = volumeRoster.GetNextVolume(&temporaryVolume);
     114    if (settings == NULL)
     115        return kErrorSettingsNotFound;
     116
     117    const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL);
     118    const char* size = get_driver_parameter(settings, "swap_size", NULL, NULL);
     119    const char* volume = get_driver_parameter(settings, "swap_volume_name",
     120        NULL, NULL);
     121    const char* device = get_driver_parameter(settings,
     122        "swap_volume_device", NULL, NULL);
     123    const char* filesystem = get_driver_parameter(settings,
     124        "swap_volume_filesystem", NULL, NULL);
     125    const char* capacity = get_driver_parameter(settings,
     126        "swap_volume_capacity", NULL, NULL);
     127
     128    if (enabled == NULL || size == NULL || device == NULL || volume == NULL
     129        || capacity == NULL || filesystem == NULL)
     130        return kErrorSettingsInvalid;
     131
     132    off_t volCapacity = atoll(capacity);
     133
     134    SetSwapEnabled(get_driver_boolean_parameter(settings,
     135        "vm", false, false));
     136    SetSwapSize(atoll(size));
     137    unload_driver_settings(settings);
     138
     139    int32 bestScore = -1;
     140    dev_t bestVol = -1;
     141
     142    BVolume vol;
     143    fs_info volStat;
     144    BVolumeRoster roster;
     145    while (roster.GetNextVolume(&vol) == B_OK) {
     146        if (!vol.IsPersistent() || vol.IsReadOnly() || vol.IsRemovable()
     147            || vol.IsShared())
     148            continue;
     149        if (fs_stat_dev(vol.Device(), &volStat) == 0) {
     150            int32 score = 0;
     151            if (strcmp(volume, volStat.volume_name) == 0)
     152                score += 4;
     153            if (strcmp(device, volStat.device_name) == 0)
     154                score += 3;
     155            if (volCapacity == volStat.total_blocks * volStat.block_size)
     156                score += 2;
     157            if (strcmp(filesystem, volStat.fsh_name) == 0)
     158                score += 1;
     159            if (score >= 4 && score > bestScore) {
     160                bestVol = vol.Device();
     161                bestScore = score;
    162162            }
    163         } else
    164             volumeRoster.GetBootVolume(&fSwapVolume);
    165 #endif
    166         unload_driver_settings(settings);
    167     } else
    168         _SetSwapNull();
     163        }
     164    }
    169165
    170 #ifndef SWAP_VOLUME_IMPLEMENTED
    171     BVolumeRoster volumeRoster;
    172     volumeRoster.GetBootVolume(&fSwapVolume);
    173 #endif
     166    SetSwapVolume(bestVol);
     167    fInitialSettings = fCurrentSettings;
    174168
    175     fInitialSwapEnabled = fSwapEnabled;
    176     fInitialSwapSize = fSwapSize;
    177     fInitialSwapVolume = fSwapVolume.Device();
     169    if (bestVol < 0)
     170        return kErrorVolumeNotFound;
     171    else
     172        return B_OK;
    178173}
    179174
    180175
    181 void
    182 Settings::_WriteSwapSettings()
    183 {   
    184     if (!IsRevertible())
    185         return;
    186 
     176status_t
     177Settings::WriteSwapSettings()
     178{
    187179    BPath path;
    188180    if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
    189         return;
     181        return B_ERROR;
    190182
    191183    path.Append("kernel/drivers");
    192184    path.Append(kVirtualMemorySettings);
     
    194186    BFile file;
    195187    if (file.SetTo(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE)
    196188        != B_OK)
    197         return;
    198    
    199     char buffer[256];
    200 #ifdef SWAP_VOLUME_IMPLEMENTED
    201     char volumeName[B_FILE_NAME_LENGTH] = {0};
    202     if (SwapVolume().InitCheck() != B_NO_INIT)
    203         SwapVolume().GetName(volumeName);
    204     else if (fBadVolName)
    205         strcpy(volumeName, fBadVolName);
    206     snprintf(buffer, sizeof(buffer), "vm %s\nswap_size %Ld\nswap_volume %s\n",
    207         SwapEnabled() ? "on" : "off", SwapSize(),
    208         volumeName[0] ? volumeName : NULL);
    209 #else
    210     snprintf(buffer, sizeof(buffer), "vm %s\nswap_size %Ld\n",
    211         fSwapEnabled ? "on" : "off", fSwapSize);
    212 #endif
     189        return B_ERROR;
    213190
     191    fs_info info;
     192    fs_stat_dev(SwapVolume(), &info);
     193
     194    char buffer[1024];
     195    snprintf(buffer, sizeof(buffer), "vm %s\nswap_size %lld\n"
     196        "swap_volume_name %s\nswap_volume_device %s\n"
     197        "swap_volume_filesystem %s\nswap_volume_capacity %lld\n",
     198        SwapEnabled() ? "on" : "off", SwapSize(), info.volume_name,
     199        info.device_name, info.fsh_name, info.total_blocks * info.block_size);
     200
    214201    file.Write(buffer, strlen(buffer));
     202    return B_OK;
    215203}
    216204
    217205
     206bool
     207Settings::IsRevertable()
     208{
     209    return SwapEnabled() != fInitialSettings.enabled
     210        || SwapSize() != fInitialSettings.size
     211        || SwapVolume() != fInitialSettings.volume;
     212}
     213
     214
    218215void
    219 Settings::_SetSwapNull()
     216Settings::RevertSwapSettings()
    220217{
    221     SetSwapEnabled(false);
    222     BVolumeRoster volumeRoster;
    223     BVolume temporaryVolume;
    224     volumeRoster.GetBootVolume(&temporaryVolume);
    225     SetSwapVolume(temporaryVolume);
    226     SetSwapSize(0);
     218    SetSwapEnabled(fInitialSettings.enabled);
     219    SetSwapSize(fInitialSettings.size);
     220    SetSwapVolume(fInitialSettings.volume);
    227221}
    228222
    229223
     224bool
     225Settings::IsDefaultable()
     226{
     227    return SwapEnabled() != fDefaultSettings.enabled
     228        || SwapSize() != fDefaultSettings.size
     229        || SwapVolume() != fDefaultSettings.volume;
     230}
     231
     232
     233void
     234Settings::DefaultSwapSettings(bool revertable)
     235{
     236    SetSwapEnabled(fDefaultSettings.enabled);
     237    SetSwapSize(fDefaultSettings.size);
     238    SetSwapVolume(fDefaultSettings.volume);
     239    if (!revertable)
     240        fInitialSettings = fDefaultSettings;
     241}
  • src/preferences/virtualmemory/VirtualMemory.h

     
    77
    88
    99#include <Application.h>
    10 #include <Catalog.h>
    11 #include <Locale.h>
    1210
    13 class VMSettings;
    1411
    15 
    1612class VirtualMemory : public BApplication {
    17     public:
    18         VirtualMemory();
    19         virtual ~VirtualMemory();
     13public:
     14                    VirtualMemory();
     15    virtual         ~VirtualMemory();
    2016
    21         virtual void ReadyToRun();
    22         virtual void AboutRequested();
    23 
    24     private:
    25         void GetCurrentSettings(bool& enabled, off_t& size);
    26 
    27         VMSettings *fSettings; 
     17    virtual void    ReadyToRun();
     18    virtual void    AboutRequested();
    2819};
    29    
     20
    3021#endif  /* VIRTUAL_MEMORY_H */
  • src/preferences/virtualmemory/Settings.h

     
    11/*
    2  * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
    3  * Distributed under the terms of the MIT License.
     2 * Copyright 2011, Hamish Morrison, hamish@lavabit.com
     3 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de
     4 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56#ifndef SETTINGS_H
    67#define SETTINGS_H
    78
    89
    910#include <Point.h>
    10 #include <Volume.h>
    1111
    1212
    13 class Settings {
    14     public :
    15         Settings();
    16         virtual ~Settings();
     13static const int32 kErrorSettingsNotFound = B_ERRORS_END + 1;
     14static const int32 kErrorSettingsInvalid = B_ERRORS_END + 2;
     15static const int32 kErrorVolumeNotFound = B_ERRORS_END + 3;
    1716
    18         BPoint WindowPosition() const { return fWindowPosition; }
    19         void SetWindowPosition(BPoint position);
    2017
    21         bool SwapEnabled() const { return fSwapEnabled; }
    22         off_t SwapSize() const { return fSwapSize; }
    23         BVolume& SwapVolume() { return fSwapVolume; }
    24         void SetSwapEnabled(bool enabled);
    25         void SetSwapSize(off_t size);
    26         void SetSwapVolume(BVolume& volume);
    2718
    28         void RevertSwapChanges();
    29         bool IsRevertible();
     19class Settings {
     20public:
     21                            Settings();
    3022
    31     private:
    32         void _ReadWindowSettings();
    33         void _WriteWindowSettings();
     23            bool            SwapEnabled() const
     24                                { return fCurrentSettings.enabled; }
     25            off_t           SwapSize() const { return fCurrentSettings.size; }
     26            dev_t           SwapVolume() { return fCurrentSettings.volume; }
     27            BPoint          WindowPosition() const { return fWindowPosition; }
    3428
    35         void _ReadSwapSettings();
    36         void _WriteSwapSettings();
     29            void            SetSwapEnabled(bool enabled,
     30                                bool revertable = true);
     31            void            SetSwapSize(off_t size, bool revertable = true);
     32            void            SetSwapVolume(dev_t volume,
     33                                bool revertable = true);
     34            void            SetWindowPosition(BPoint position);
    3735
    38         void _SetSwapNull();
     36            status_t        ReadWindowSettings();
     37            status_t        WriteWindowSettings();
     38            status_t        ReadSwapSettings();
     39            status_t        WriteSwapSettings();
    3940
    40         BPoint      fWindowPosition;
     41            bool            IsRevertable();
     42            void            RevertSwapSettings();
    4143
    42         bool        fSwapEnabled;
    43         off_t       fSwapSize;
    44         BVolume     fSwapVolume;
     44            bool            IsDefaultable();
     45            void            DefaultSwapSettings(bool revertable = true);
     46private:
     47            struct SwapSettings {
     48                bool enabled;
     49                off_t size;
     50                dev_t volume;
     51            };
    4552
    46         bool        fInitialSwapEnabled;
    47         off_t       fInitialSwapSize;
    48         dev_t       fInitialSwapVolume;
     53            BPoint          fWindowPosition;
    4954
    50         bool        fPositionUpdated;
    51         const char* fBadVolName;
     55            SwapSettings    fCurrentSettings;
     56            SwapSettings    fInitialSettings;
     57            SwapSettings    fDefaultSettings;
    5258};
    5359
    5460#endif  /* SETTINGS_H */
  • src/preferences/virtualmemory/Jamfile

     
    11SubDir HAIKU_TOP src preferences virtualmemory ;
    22
    3 Preference VirtualMemory :
     3UsePrivateHeaders shared system ;
     4
     5Preference VirtualMemory :
    46    VirtualMemory.cpp
    57    SettingsWindow.cpp
    68    Settings.cpp
    79    $(DRIVER_SETTINGS)
    810
    9     : be $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS)
     11    : be libshared.a $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS)
    1012    : VirtualMemory.rdef
    11     ;
     13;
    1214
    1315if ! $(TARGET_PLATFORM_HAIKU_COMPATIBLE) {
    14     SEARCH on [ FGristFiles driver_settings.c ] += 
     16    SEARCH on [ FGristFiles driver_settings.c ] +=
    1517        [ FDirName $(HAIKU_TOP) src system libroot os ] ;
    1618}
    1719
    18 DoCatalogs VirtualMemory : 
    19     x-vnd.Haiku-VirtualMemory 
    20     : 
    21     VirtualMemory.cpp 
    22     SettingsWindow.cpp 
    23 ; 
     20DoCatalogs VirtualMemory :
     21    x-vnd.Haiku-VirtualMemory
     22    :
     23    VirtualMemory.cpp
     24    SettingsWindow.cpp
     25;
  • src/preferences/virtualmemory/SettingsWindow.cpp

     
    11/*
    2  * Copyright 2010-2011, Hamish Morrison, hamish@lavabit.com 
     2 * Copyright 2010-2011, Hamish Morrison, hamish@lavabit.com
    33 * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de
    44 * All rights reserved. Distributed under the terms of the MIT License.
    55 */
    66
    77
    88#include "SettingsWindow.h"
    9 #include "Settings.h"
    109
    11 #include <Application.h>
    1210#include <Alert.h>
    1311#include <Box.h>
    1412#include <Button.h>
    1513#include <Catalog.h>
    1614#include <CheckBox.h>
    17 #include <GroupLayout.h>
    18 #include <GroupLayoutBuilder.h>
    19 #include <Locale.h>
     15#include <Directory.h>
     16#include <FindDirectory.h>
     17#include <LayoutBuilder.h>
     18#include <MenuField.h>
     19#include <NodeMonitor.h>
     20#include <PopUpMenu.h>
     21#include <Path.h>
    2022#include <StringView.h>
    2123#include <String.h>
    2224#include <Slider.h>
    23 #include <PopUpMenu.h>
    24 #include <MenuItem.h>
    25 #include <MenuField.h>
    26 #include <Screen.h>
    27 #include <FindDirectory.h>
    28 #include <Path.h>
    29 #include <Volume.h>
    3025#include <VolumeRoster.h>
    3126
    32 #include <stdio.h>
     27#include <StringForSize.h>
     28#include <system_info.h>
    3329
     30#include "Settings.h"
     31
     32
    3433#undef B_TRANSLATE_CONTEXT
    3534#define B_TRANSLATE_CONTEXT "SettingsWindow"
    3635
     
    4039static const uint32 kMsgSliderUpdate = 'slup';
    4140static const uint32 kMsgSwapEnabledUpdate = 'swen';
    4241static const uint32 kMsgVolumeSelected = 'vlsl';
    43 static const int64 kMegaByte = 1024 * 1024;
     42static const off_t kMegaByte = 1024 * 1024;
     43static dev_t bootDev = -1;
    4444
    4545
    46 class SizeSlider : public BSlider {
    47     public:
    48         SizeSlider(const char* name, const char* label,
    49             BMessage* message, int32 min, int32 max, uint32 flags);
    50         virtual ~SizeSlider();
    51 
    52         virtual const char* UpdateText() const;
    53 
    54     private:
    55         mutable BString fText;
    56 };
    57 
    58 
    5946SizeSlider::SizeSlider(const char* name, const char* label,
    6047    BMessage* message, int32 min, int32 max, uint32 flags)
    61     : BSlider(name, label, message, min, max, B_HORIZONTAL, B_BLOCK_THUMB, flags)
     48    :
     49    BSlider(name, label, message, min, max, B_HORIZONTAL,
     50        B_BLOCK_THUMB, flags)
    6251{
    6352    rgb_color color = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
    6453    UseFillColor(true, &color);
    6554}
    6655
    6756
    68 SizeSlider::~SizeSlider()
     57const char*
     58SizeSlider::UpdateText() const
    6959{
     60    return string_for_size(Value() * kMegaByte, fText, sizeof(fText));
    7061}
    7162
    7263
    73 const char*
    74 byte_string(int64 size)
     64VolumeMenuItem::VolumeMenuItem(BVolume volume, BMessage* message)
     65    :
     66    BMenuItem("", message),
     67    fVolume(volume)
    7568{
    76     double value = 1. * size;
    77     static char string[256];
     69    GenerateLabel();
     70}
    7871
    79     if (value < 1024)
    80         snprintf(string, sizeof(string), B_TRANSLATE("%Ld B"), size);
    81     else {
    82         static const char *units[] = {
    83             B_TRANSLATE_MARK("KB"),
    84             B_TRANSLATE_MARK("MB"),
    85             B_TRANSLATE_MARK("GB"),
    86             NULL
    87         };
    88         int32 i = -1;
    8972
    90         do {
    91             value /= 1024.0;
    92             i++;
    93         } while (value >= 1024 && units[i + 1]);
    94 
    95         off_t rounded = off_t(value * 100LL);
    96         snprintf(string, sizeof(string), "%g %s", rounded / 100.0,
    97             B_TRANSLATE_NOCOLLECT(units[i]));
     73void
     74VolumeMenuItem::MessageReceived(BMessage* message)
     75{
     76    if (message->what == B_NODE_MONITOR) {
     77        int32 code;
     78        if (message->FindInt32("opcode", &code) == B_OK)
     79            if (code == B_ENTRY_MOVED)
     80                GenerateLabel();
    9881    }
    99 
    100     return string;
    10182}
    10283
    10384
    104 const char*
    105 SizeSlider::UpdateText() const
     85void
     86VolumeMenuItem::GenerateLabel()
    10687{
    107     fText = byte_string(Value() * kMegaByte);
    108     return fText.String();
    109 }
     88    char name[B_FILE_NAME_LENGTH + 1];
     89    fVolume.GetName(name);
    11090
     91    BDirectory dir;
     92    if (fVolume.GetRootDirectory(&dir) == B_OK) {
     93        BEntry entry;
     94        if (dir.GetEntry(&entry) == B_OK) {
     95            BPath path;
     96            if (entry.GetPath(&path) == B_OK) {
     97                BString label;
     98                label << name << " (" << path.Path() << ")";
     99                SetLabel(label);
     100                return;
     101            }
     102        }
     103    }
    111104
    112 class VolumeMenuItem : public BMenuItem {
    113     public:
    114         VolumeMenuItem(const char* label, BMessage* message, BVolume* volume);
    115         BVolume* Volume() { return fVolume; }
    116 
    117     private:
    118         BVolume* fVolume;
    119 };
    120 
    121 
    122 VolumeMenuItem::VolumeMenuItem(const char* label, BMessage* message,
    123     BVolume* volume)
    124     : BMenuItem(label, message)
    125 {
    126     fVolume = volume;
     105    SetLabel(name);
    127106}
    128107
    129108
     
    131110    :
    132111    BWindow(BRect(0, 0, 269, 172), B_TRANSLATE_SYSTEM_NAME("VirtualMemory"),
    133112        B_TITLED_WINDOW, B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS
    134         | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
    135     fLocked(false)
    136    
     113        | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
     114
    137115{
    138     BView* view = new BGroupView();
     116    bootDev = dev_for_path("/boot");
     117    BAlignment align(B_ALIGN_LEFT, B_ALIGN_MIDDLE);
    139118
     119    if (fSettings.ReadWindowSettings() == B_OK)
     120        MoveTo(fSettings.WindowPosition());
     121    else
     122        CenterOnScreen();
     123
     124    status_t result = fSettings.ReadSwapSettings();
     125    if (result == kErrorSettingsNotFound)
     126        fSettings.DefaultSwapSettings(false);
     127    else if (result == kErrorSettingsInvalid) {
     128        int32 choice = (new BAlert("VirtualMemory",
     129            B_TRANSLATE("The settings specified in the settings file "
     130            "are invalid. You can load the defaults or quit."),
     131            B_TRANSLATE("Load defaults"), B_TRANSLATE("Quit")))->Go();
     132        if (choice == 1) {
     133            be_app->PostMessage(B_QUIT_REQUESTED);
     134            return;
     135        }
     136        fSettings.DefaultSwapSettings(false);
     137    } else if (result == kErrorVolumeNotFound) {
     138        int32 choice = (new BAlert("VirtualMemory",
     139            B_TRANSLATE("The volume specified in the settings file "
     140            "could not be found. You can use the boot volume or quit."),
     141            B_TRANSLATE("Use boot volume"), B_TRANSLATE("Quit")))->Go();
     142        if (choice == 1) {
     143            be_app->PostMessage(B_QUIT_REQUESTED);
     144            return;
     145        }
     146        fSettings.SetSwapVolume(bootDev, false);
     147    }
     148
    140149    fSwapEnabledCheckBox = new BCheckBox("enable swap",
    141150        B_TRANSLATE("Enable virtual memory"),
    142151        new BMessage(kMsgSwapEnabledUpdate));
     152    fSwapEnabledCheckBox->SetExplicitAlignment(align);
    143153
    144     BBox* box = new BBox("box", B_FOLLOW_LEFT_RIGHT);
    145     box->SetLabel(fSwapEnabledCheckBox);
    146 
     154    char sizeStr[16];
    147155    system_info info;
    148156    get_system_info(&info);
    149 
    150157    BString string = B_TRANSLATE("Physical memory: ");
    151     string << byte_string((off_t)info.max_pages * B_PAGE_SIZE);
    152     BStringView* memoryView = new BStringView("physical memory", string.String());
     158    string << string_for_size(info.max_pages * B_PAGE_SIZE, sizeStr,
     159        sizeof(sizeStr));
     160    BStringView* memoryView = new BStringView("physical memory",
     161        string.String());
     162    memoryView->SetExplicitAlignment(align);
    153163
     164    system_memory_info memInfo = {};
     165    __get_system_info_etc(B_MEMORY_INFO, &memInfo, sizeof(memInfo));
    154166    string = B_TRANSLATE("Current swap file size: ");
    155     string << byte_string(fSettings.SwapSize());
    156     BStringView* swapfileView = new BStringView("current swap size", string.String());
     167    string << string_for_size(memInfo.max_swap_space, sizeStr,
     168        sizeof(sizeStr));
     169    BStringView* swapFileView = new BStringView("current swap size",
     170        string.String());
     171    swapFileView->SetExplicitAlignment(align);
    157172
    158     BPopUpMenu* menu = new BPopUpMenu("invalid");
     173    BPopUpMenu* menu = new BPopUpMenu("volume menu");
     174    fVolumeMenuField = new BMenuField("volume menu field",
     175        B_TRANSLATE("Use volume:"), menu);
     176    fVolumeMenuField->SetExplicitAlignment(align);
    159177
    160     // collect volumes
    161     // TODO: listen to volume changes!
    162     // TODO: accept dropped volumes
    163 
    164     BVolumeRoster volumeRoster;
    165     BVolume* volume = new BVolume();
    166     char name[B_FILE_NAME_LENGTH];
    167     while (volumeRoster.GetNextVolume(volume) == B_OK) {   
    168         if (!volume->IsPersistent() || volume->GetName(name) != B_OK || !name[0])
     178    BVolumeRoster roster;
     179    BVolume vol;
     180    while (roster.GetNextVolume(&vol) == B_OK) {
     181        if (!vol.IsPersistent() || vol.IsReadOnly() || vol.IsRemovable()
     182            || vol.IsShared())
    169183            continue;
    170         VolumeMenuItem* item = new VolumeMenuItem(name,
    171             new BMessage(kMsgVolumeSelected), volume);
    172         menu->AddItem(item);
    173         volume = new BVolume();
     184        _AddVolumeMenuItem(vol.Device());
    174185    }
    175186
    176     fVolumeMenuField = new BMenuField("volumes", B_TRANSLATE("Use volume:"), menu);
    177    
    178     fSizeSlider = new SizeSlider("size slider", 
    179         B_TRANSLATE("Requested swap file size:"), new BMessage(kMsgSliderUpdate),
    180         1, 1, B_WILL_DRAW | B_FRAME_EVENTS);
     187    watch_node(NULL, B_WATCH_MOUNT, this, this);
     188
     189    fSizeSlider = new SizeSlider("size slider",
     190        B_TRANSLATE("Requested swap file size:"),
     191        new BMessage(kMsgSliderUpdate), 0, 0, B_WILL_DRAW | B_FRAME_EVENTS);
    181192    fSizeSlider->SetViewColor(255, 0, 255);
     193    fSizeSlider->SetExplicitAlignment(align);
    182194
    183     fWarningStringView = new BStringView("", "");
    184     fWarningStringView->SetAlignment(B_ALIGN_CENTER);
     195    fWarningStringView = new BStringView("warning",
     196        B_TRANSLATE("Changes will take effect upon reboot."));
    185197
    186     view->SetLayout(new BGroupLayout(B_HORIZONTAL));
    187     view->AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
    188         .AddGroup(B_HORIZONTAL)
    189             .Add(memoryView)
    190             .AddGlue()
    191         .End()
    192         .AddGroup(B_HORIZONTAL)
    193             .Add(swapfileView)
    194             .AddGlue()
    195         .End()
    196 #ifdef SWAP_VOLUME_IMPLEMENTED
    197         .AddGroup(B_HORIZONTAL)
    198             .Add(fVolumeMenuField)
    199             .AddGlue()
    200         .End()
    201 #else
    202         .AddGlue()
    203 #endif
     198    BBox* box = new BBox("box");
     199    box->SetLabel(fSwapEnabledCheckBox);
     200
     201    box->AddChild(BLayoutBuilder::Group<>(B_VERTICAL, B_USE_DEFAULT_SPACING)
     202        .Add(memoryView)
     203        .Add(swapFileView)
     204        .Add(fVolumeMenuField)
    204205        .Add(fSizeSlider)
    205206        .Add(fWarningStringView)
    206         .SetInsets(10, 10, 10, 10)
    207     );
    208     box->AddChild(view);
     207        .SetInsets(10)
     208        .View());
    209209
    210210    fDefaultsButton = new BButton("defaults", B_TRANSLATE("Defaults"),
    211211        new BMessage(kMsgDefaults));
     
    214214        new BMessage(kMsgRevert));
    215215    fRevertButton->SetEnabled(false);
    216216
    217     SetLayout(new BGroupLayout(B_HORIZONTAL));
    218     AddChild(BGroupLayoutBuilder(B_VERTICAL, 10)
     217    BLayoutBuilder::Group<>(this, B_VERTICAL, B_USE_DEFAULT_SPACING)
    219218        .Add(box)
    220219        .AddGroup(B_HORIZONTAL, 10)
    221220            .Add(fDefaultsButton)
    222221            .Add(fRevertButton)
    223222            .AddGlue()
    224223        .End()
    225         .SetInsets(10, 10, 10, 10)
    226     );
    227 
    228     BScreen screen;
    229     BRect screenFrame = screen.Frame();
    230     if (!screenFrame.Contains(fSettings.WindowPosition()))
    231         CenterOnScreen();
    232     else
    233         MoveTo(fSettings.WindowPosition());
    234 
    235 #ifdef SWAP_VOLUME_IMPLEMENTED
    236     // Validate the volume specified in settings file
    237     status_t result = fSettings.SwapVolume().InitCheck();
    238 
    239     if (result != B_OK) {
    240         int32 choice = (new BAlert("VirtualMemory", B_TRANSLATE(
    241             "The swap volume specified in the settings file is invalid.\n"
    242             "You can keep the current setting or switch to the "
    243             "default swap volume."),
    244             B_TRANSLATE("Keep"), B_TRANSLATE("Switch"), NULL,
    245             B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
    246         if (choice == 1) {
    247             BVolumeRoster volumeRoster;
    248             BVolume bootVolume;
    249             volumeRoster.GetBootVolume(&bootVolume);
    250             fSettings.SetSwapVolume(bootVolume);
    251         }
    252     }
    253 #endif
    254 
     224        .SetInsets(10);
    255225    _Update();
    256226}
    257227
    258228
    259 SettingsWindow::~SettingsWindow()
    260 {
    261 }
    262 
    263 
    264229void
    265230SettingsWindow::MessageReceived(BMessage* message)
    266231{
    267232    switch (message->what) {
     233        case B_NODE_MONITOR:
     234        {
     235            int32 opcode;
     236            if (message->FindInt32("opcode", &opcode) != B_OK)
     237                break;
     238            dev_t device;
     239            if (opcode == B_DEVICE_MOUNTED
     240                && message->FindInt32("new device", &device) == B_OK) {
     241                BVolume vol(device);
     242                if (!vol.IsPersistent() || vol.IsReadOnly()
     243                    || vol.IsRemovable() || vol.IsShared())
     244                    break;
     245                _AddVolumeMenuItem(device);
     246            } else if (opcode == B_DEVICE_UNMOUNTED
     247                && message->FindInt32("device", &device) == B_OK)
     248                _RemoveVolumeMenuItem(device);
     249            _Update();
     250            break;
     251        }
    268252        case kMsgRevert:
    269             fSettings.RevertSwapChanges();
     253            fSettings.RevertSwapSettings();
    270254            _Update();
    271255            break;
    272256        case kMsgDefaults:
    273             _SetSwapDefaults();
     257            fSettings.DefaultSwapSettings();
    274258            _Update();
    275259            break;
    276260        case kMsgSliderUpdate:
     
    278262            _Update();
    279263            break;
    280264        case kMsgVolumeSelected:
    281             fSettings.SetSwapVolume(*((VolumeMenuItem*)fVolumeMenuField->Menu()
    282                 ->FindMarked())->Volume());
     265            fSettings.SetSwapVolume(((VolumeMenuItem*)fVolumeMenuField
     266                ->Menu()->FindMarked())->Volume().Device());
    283267            _Update();
    284268            break;
    285269        case kMsgSwapEnabledUpdate:
    286270        {
    287             int32 value;
    288             if (message->FindInt32("be:value", &value) != B_OK)
    289                 break;
    290 
    291             if (value == 0) {
    292                 // print out warning, give the user the time to think about it :)
     271            if (fSwapEnabledCheckBox->Value() == 0) {
     272                // print out warning, give the user the
     273                // time to think about it :)
    293274                // ToDo: maybe we want to remove this possibility in the GUI
    294275                // as Be did, but I thought a proper warning could be helpful
    295276                // (for those that want to change that anyway)
     
    300281                    "Virtual memory does not affect system performance "
    301282                    "until this point is reached.\n\n"
    302283                    "Are you really sure you want to turn it off?"),
    303                     B_TRANSLATE("Turn off"), B_TRANSLATE("Keep enabled"), NULL,
    304                     B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
     284                    B_TRANSLATE("Turn off"), B_TRANSLATE("Keep enabled"),
     285                    NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT))->Go();
    305286                if (choice == 1) {
    306287                    fSwapEnabledCheckBox->SetValue(1);
    307288                    break;
    308289                }
    309290            }
    310 
    311             fSettings.SetSwapEnabled(value != 0);
     291            fSettings.SetSwapEnabled(fSwapEnabledCheckBox->Value());
    312292            _Update();
    313293            break;
    314294        }
     
    323303SettingsWindow::QuitRequested()
    324304{
    325305    fSettings.SetWindowPosition(Frame().LeftTop());
     306    fSettings.WriteWindowSettings();
     307    fSettings.WriteSwapSettings();
    326308    be_app->PostMessage(B_QUIT_REQUESTED);
    327309    return true;
    328310}
    329311
    330312
    331 void
    332 SettingsWindow::_Update()
     313status_t
     314SettingsWindow::_AddVolumeMenuItem(dev_t device)
    333315{
    334     if ((fSwapEnabledCheckBox->Value() != 0) != fSettings.SwapEnabled())
    335         fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
     316    if (_FindVolumeMenuItem(device) != NULL)
     317        return B_ERROR;
    336318
    337 #ifdef SWAP_VOLUME_IMPLEMENTED 
    338     if (fVolumeMenuField->IsEnabled() != fSettings.SwapEnabled())
    339         fVolumeMenuField->SetEnabled(fSettings.SwapEnabled());
    340     VolumeMenuItem* selectedVolumeItem =
    341         (VolumeMenuItem*)fVolumeMenuField->Menu()->FindMarked();
    342     if (selectedVolumeItem == NULL) {
    343         VolumeMenuItem* currentVolumeItem;
    344         int32 items = fVolumeMenuField->Menu()->CountItems();
    345         for (int32 index = 0; index < items; ++index) {
    346             currentVolumeItem = ((VolumeMenuItem*)fVolumeMenuField->Menu()->ItemAt(index));
    347             if (*(currentVolumeItem->fVolume) == fSettings.SwapVolume()) {
    348                 currentVolumeItem->SetMarked(true);
    349                 break;
    350             }
    351         }
    352     } else if (*selectedVolumeItem->fVolume != fSettings.SwapVolume()) {
    353         VolumeMenuItem* currentVolumeItem;
    354         int32 items = fVolumeMenuField->Menu()->CountItems();
    355         for (int32 index = 0; index < items; ++index) {
    356             currentVolumeItem = ((VolumeMenuItem*)fVolumeMenuField->Menu()->ItemAt(index));
    357             if (*(currentVolumeItem->fVolume) == fSettings.SwapVolume()) {
    358                 currentVolumeItem->SetMarked(true);
    359                 break;
    360             }
    361         }
    362     }
    363 #endif
     319    VolumeMenuItem* item = new VolumeMenuItem(device,
     320        new BMessage(kMsgVolumeSelected));
    364321
    365     fWarningStringView->SetText("");
    366     fLocked = false;
    367    
    368     if (fSettings.IsRevertible())
    369             fWarningStringView->SetText(
    370                 B_TRANSLATE("Changes will take effect on restart!"));
    371     if (fRevertButton->IsEnabled() != fSettings.IsRevertible())
    372         fRevertButton->SetEnabled(fSettings.IsRevertible());
    373    
    374     off_t minSize, maxSize;
    375     if (_GetSwapFileLimits(minSize, maxSize) == B_OK) {
    376         // round to nearest MB -- slider steps in whole MBs
    377         (minSize >>= 20) <<= 20;
    378         (maxSize >>= 20) <<= 20;
    379         BString minLabel, maxLabel;
    380         minLabel << byte_string(minSize);
    381         maxLabel << byte_string(maxSize);
    382         if (minLabel != fSizeSlider->MinLimitLabel()
    383             || maxLabel != fSizeSlider->MaxLimitLabel()) {
    384             fSizeSlider->SetLimitLabels(minLabel.String(), maxLabel.String());
    385             fSizeSlider->SetLimits(minSize / kMegaByte, maxSize / kMegaByte);
    386         }
    387     } else if (fSettings.SwapEnabled()) {
    388         fWarningStringView->SetText(
    389             B_TRANSLATE("Insufficient space for a swap file."));
    390         fLocked = true;
     322    fs_info info;
     323    if (fs_stat_dev(device, &info) == 0) {
     324        node_ref node;
     325        node.device = info.dev;
     326        node.node = info.root;
     327        AddHandler(item);
     328        watch_node(&node, B_WATCH_NAME, item);
    391329    }
    392     if (fSizeSlider->Value() != fSettings.SwapSize() / kMegaByte)
    393         fSizeSlider->SetValue(fSettings.SwapSize() / kMegaByte);
    394     if (fSizeSlider->IsEnabled() != fSettings.SwapEnabled() || fLocked)
    395     {
    396         fSizeSlider->SetEnabled(fSettings.SwapEnabled() && !fLocked);
    397         fSettings.SetSwapSize((off_t)fSizeSlider->Value() * kMegaByte);
    398     }
     330
     331    fVolumeMenuField->Menu()->AddItem(item);
     332    return B_OK;
    399333}
    400334
    401335
    402336status_t
    403 SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize)
     337SettingsWindow::_RemoveVolumeMenuItem(dev_t device)
    404338{
    405     minSize = kMegaByte;
     339    VolumeMenuItem* item = _FindVolumeMenuItem(device);
     340    if (item != NULL) {
     341        fVolumeMenuField->Menu()->RemoveItem(item);
     342        delete item;
     343        return B_OK;
     344    } else
     345        return B_ERROR;
     346}
    406347
    407     // maximum size is the free space on the current volume
    408     // (minus some safety offset, depending on the disk size)
    409     off_t freeSpace = fSettings.SwapVolume().FreeBytes();
    410     off_t safetyFreeSpace = fSettings.SwapVolume().Capacity() / 100;
    411     if (safetyFreeSpace > 1024 * kMegaByte)
    412         safetyFreeSpace = 1024 * kMegaByte;
    413348
    414     // check if there already is a page file on this disk and
    415     // adjust the free space accordingly
    416     BPath path;
    417     if (find_directory(B_COMMON_VAR_DIRECTORY, &path, false,
    418         &fSettings.SwapVolume()) == B_OK) {
    419         path.Append("swap");
    420         BEntry swap(path.Path());
    421 
    422         off_t size;
    423         if (swap.GetSize(&size) == B_OK) {
    424             // If swap file exists, forget about safety space;
    425             // disk may have filled after creation of swap file.
    426             safetyFreeSpace = 0;
    427             freeSpace += size;
    428         }
     349VolumeMenuItem*
     350SettingsWindow::_FindVolumeMenuItem(dev_t device)
     351{
     352    VolumeMenuItem* item = NULL;
     353    int32 count = fVolumeMenuField->Menu()->CountItems();
     354    for (int i = 0; i < count; i++) {
     355        item = (VolumeMenuItem*)fVolumeMenuField->Menu()->ItemAt(i);
     356        if (item->Volume().Device() == device)
     357            return item;
    429358    }
    430359
    431     maxSize = freeSpace - safetyFreeSpace;
    432     if (maxSize < minSize) {
    433         maxSize = 0;
    434         minSize = 0;
    435         return B_ERROR;
    436     }
    437 
    438     return B_OK;
     360    return NULL;
    439361}
    440362
    441363
    442364void
    443 SettingsWindow::_SetSwapDefaults()
     365SettingsWindow::_Update()
    444366{
    445     fSettings.SetSwapEnabled(true);
     367    fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());
    446368
    447     BVolumeRoster volumeRoster;
    448     BVolume temporaryVolume;
    449     volumeRoster.GetBootVolume(&temporaryVolume);
    450     fSettings.SetSwapVolume(temporaryVolume);
     369    VolumeMenuItem* item = _FindVolumeMenuItem(fSettings.SwapVolume());
     370    if (item != NULL) {
     371        fSizeSlider->SetEnabled(true);
     372        item->SetMarked(true);
     373        BEntry swapFile;
     374        if (bootDev == item->Volume().Device())
     375            swapFile.SetTo("/var/swap");
     376        else {
     377            BDirectory root;
     378            item->Volume().GetRootDirectory(&root);
     379            swapFile.SetTo(&root, "swap");
     380        }
    451381
    452     system_info info;
    453     get_system_info(&info);
    454    
    455     off_t defaultSize = (off_t)info.max_pages * B_PAGE_SIZE;
    456     off_t minSize, maxSize;
    457     _GetSwapFileLimits(minSize, maxSize);
    458    
    459     if (defaultSize > maxSize / 2)
    460         defaultSize = maxSize / 2;
    461        
    462     fSettings.SetSwapSize(defaultSize);
    463 }
     382        off_t swapFileSize = 0;
     383        swapFile.GetSize(&swapFileSize);
    464384
     385        char sizeStr[16];
     386
     387        off_t freeSpace = item->Volume().FreeBytes() + swapFileSize;
     388        off_t safeSpace = freeSpace - (off_t)(0.15 * freeSpace);
     389        (safeSpace >>= 20) <<= 20;
     390        off_t minSize = B_PAGE_SIZE + kMegaByte;
     391        (minSize >>= 20) <<= 20;
     392        BString minLabel, maxLabel;
     393        minLabel << string_for_size(minSize, sizeStr, sizeof(sizeStr));
     394        maxLabel << string_for_size(safeSpace, sizeStr, sizeof(sizeStr));
     395
     396        fSizeSlider->SetLimitLabels(minLabel.String(), maxLabel.String());
     397        fSizeSlider->SetLimits(minSize / kMegaByte, safeSpace / kMegaByte);
     398        fSizeSlider->SetValue(fSettings.SwapSize() / kMegaByte);
     399    } else
     400        fSizeSlider->SetEnabled(false);
     401
     402    bool revertable = fSettings.IsRevertable();
     403    if (revertable)
     404        fWarningStringView->Show();
     405    else
     406        fWarningStringView->Hide();
     407    fRevertButton->SetEnabled(revertable);
     408    fDefaultsButton->SetEnabled(fSettings.IsDefaultable());
     409}
  • src/preferences/virtualmemory/SettingsWindow.h

     
    11/*
    2  * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
    3  * Distributed under the terms of the MIT License.
     2 * Copyright 2011, Hamish Morrison, hamish@lavabit.com
     3 * Copyright 2005-2006, Axel Dörfler, axeld@pinc-software.de
     4 * All rights reserved. Distributed under the terms of the MIT License.
    45 */
    56#ifndef SETTINGS_WINDOW_H
    67#define SETTINGS_WINDOW_H
    78
    89
     10#include <MenuItem.h>
     11#include <Slider.h>
     12#include <Volume.h>
    913#include <Window.h>
    1014
    1115#include "Settings.h"
    1216
     17
    1318class BStringView;
    1419class BCheckBox;
    1520class BSlider;
    1621class BButton;
    1722class BMenuField;
    1823
     24
     25class SizeSlider : public BSlider {
     26public:
     27                            SizeSlider(const char* name, const char* label,
     28                                BMessage* message, int32 min, int32 max,
     29                                uint32 flags);
     30    virtual                 ~SizeSlider() {};
     31
     32    virtual const char*     UpdateText() const;
     33
     34private:
     35    mutable char            fText[128];
     36};
     37
     38
     39class VolumeMenuItem : public BMenuItem, public BHandler {
     40public:
     41                            VolumeMenuItem(BVolume volume, BMessage* message);
     42    virtual                 ~VolumeMenuItem() {}
     43
     44    virtual BVolume         Volume() { return fVolume; }
     45    virtual void            MessageReceived(BMessage* message);
     46    virtual void            GenerateLabel();
     47
     48private:
     49            BVolume         fVolume;
     50};
     51
     52
    1953class SettingsWindow : public BWindow {
    20     public:
    21         SettingsWindow();
    22         virtual ~SettingsWindow();
     54public:
     55                            SettingsWindow();
     56    virtual                 ~SettingsWindow() {};
    2357
    24         virtual bool QuitRequested();
    25         virtual void MessageReceived(BMessage* message);
     58    virtual void            MessageReceived(BMessage* message);
     59    virtual bool            QuitRequested();
    2660
    27     private:
    28         void _Update();
    29         status_t _GetSwapFileLimits(off_t& minSize, off_t& maxSize);
    30         void _SetSwapDefaults();
     61private:
     62            status_t        _AddVolumeMenuItem(dev_t device);
     63            status_t        _RemoveVolumeMenuItem(dev_t device);
     64            VolumeMenuItem* _FindVolumeMenuItem(dev_t device);
    3165
    32         BCheckBox*      fSwapEnabledCheckBox;
    33         BSlider*        fSizeSlider;
    34         BButton*        fDefaultsButton;
    35         BButton*        fRevertButton;
    36         BStringView*    fWarningStringView;
    37         BMenuField*     fVolumeMenuField;
    38         Settings        fSettings;
    39        
    40         bool            fLocked;
     66            void            _Update();
     67
     68            BCheckBox*      fSwapEnabledCheckBox;
     69            BSlider*        fSizeSlider;
     70            BButton*        fDefaultsButton;
     71            BButton*        fRevertButton;
     72            BStringView*    fWarningStringView;
     73            BMenuField*     fVolumeMenuField;
     74            Settings        fSettings;
    4175};
    4276
    4377#endif  /* SETTINGS_WINDOW_H */