Ticket #1746: virtualmemory-fixes.diff
File virtualmemory-fixes.diff, 6.6 KB (added by , 13 years ago) |
---|
-
Settings.cpp
203 203 fSwapVolume.SetTo(fInitialSwapVolume); 204 204 } 205 205 206 206 // This function makes no sense... 207 // Why should defaultable depend on whether the settings have 208 // changed or not? 207 209 bool 208 210 Settings::IsDefaultable() 209 211 { -
SettingsWindow.cpp
127 127 fSwapEnabledCheckBox = new BCheckBox("enable swap", 128 128 B_TRANSLATE("Enable virtual memory"), 129 129 new BMessage(kMsgSwapEnabledUpdate)); 130 fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled());131 130 132 131 BBox* box = new BBox("box", B_FOLLOW_LEFT_RIGHT); 133 132 box->SetLabel(fSwapEnabledCheckBox); … … 163 162 item->SetMarked(true); 164 163 } 165 164 166 BMenuField* field = new BMenuField("devices", B_TRANSLATE("Use volume:"), 167 menu); 168 field->SetEnabled(false); 169 170 off_t minSize, maxSize; 171 _GetSwapFileLimits(minSize, maxSize); 172 173 fSizeSlider = new SizeSlider("size slider", 174 B_TRANSLATE("Requested swap file size:"), 175 new BMessage(kMsgSliderUpdate), minSize / kMegaByte, maxSize / kMegaByte, 176 B_WILL_DRAW | B_FRAME_EVENTS); 177 fSizeSlider->SetLimitLabels(B_TRANSLATE("999 MB"), B_TRANSLATE("999 MB")); 165 fVolumeMenuField = new BMenuField("devices", B_TRANSLATE("Use volume:"), menu); 166 167 // When swap volume changing support is implemeneted, remove me: 168 fVolumeMenuField->SetEnabled(false); 169 170 fSizeSlider = new SizeSlider("size slider", 171 B_TRANSLATE("Requested swap file size:"), new BMessage(kMsgSliderUpdate), 172 0, 0, B_WILL_DRAW | B_FRAME_EVENTS); 178 173 fSizeSlider->SetViewColor(255, 0, 255); 179 174 180 175 fWarningStringView = new BStringView("", ""); … … 191 186 .AddGlue() 192 187 .End() 193 188 .AddGroup(B_HORIZONTAL) 194 .Add(f ield)189 .Add(fVolumeMenuField) 195 190 .AddGlue() 196 191 .End() 197 192 .Add(fSizeSlider) … … 226 221 BScreen screen; 227 222 BRect screenFrame = screen.Frame(); 228 223 229 if (!screenFrame.Contains(fSettings.WindowPosition())) { 230 // move on screen, centered 224 if (!screenFrame.Contains(fSettings.WindowPosition())) 231 225 CenterOnScreen(); 232 }else226 else 233 227 MoveTo(fSettings.WindowPosition()); 234 228 } 235 229 … … 239 233 } 240 234 241 235 242 236 void 243 237 SettingsWindow::_Update() 244 238 { 245 239 if ((fSwapEnabledCheckBox->Value() != 0) != fSettings.SwapEnabled()) 246 240 fSwapEnabledCheckBox->SetValue(fSettings.SwapEnabled()); 241 242 if (fSizeSlider->IsEnabled() != fSettings.SwapEnabled()) 243 fSizeSlider->SetEnabled(fSettings.SwapEnabled()); 244 245 #ifdef SWAP_VOLUME_IMPLEMENTED 246 if (fVolumeMenuField->IsEnabled() != fSettings.SwapEnabled()) 247 fVolumeMenuField->SetEnabled(fSettings.SwapEnabled()); 248 #endif 247 249 248 250 off_t minSize, maxSize; 249 251 if (_GetSwapFileLimits(minSize, maxSize) == B_OK) { … … 251 253 minLabel << byte_string(minSize); 252 254 maxLabel << byte_string(maxSize); 253 255 if (minLabel != fSizeSlider->MinLimitLabel() 254 256 || maxLabel != fSizeSlider->MaxLimitLabel()) { 255 257 fSizeSlider->SetLimitLabels(minLabel.String(), maxLabel.String()); 256 258 #ifdef __HAIKU__ 257 259 fSizeSlider->SetLimits(minSize / kMegaByte, maxSize / kMegaByte); … … 260 262 261 263 if (fSizeSlider->Value() != fSettings.SwapSize() / kMegaByte) 262 264 fSizeSlider->SetValue(fSettings.SwapSize() / kMegaByte); 263 264 fSizeSlider->SetEnabled(true);265 265 } else { 266 fSizeSlider->SetValue(minSize); 266 // Not enough space on volume for a swap file. Make UI inoperable. 267 fWarningStringView->SetText( 268 B_TRANSLATE("Insufficient space for a swap file.")); 269 fSwapEnabledCheckBox->SetEnabled(false); 267 270 fSizeSlider->SetEnabled(false); 271 // When swap volume is implemented, we'll want to keep the volume 272 // menu field enabled so the user can get around the space issue 273 // by selecting a different volume. 274 #ifdef SWAP_VOLUME_IMPLEMENTED 275 fVolumeMenuField->SetEnabled(true); 276 #endif 268 277 } 269 278 270 279 // ToDo: set volume … … 283 292 } 284 293 285 294 286 295 status_t 287 296 SettingsWindow::_GetSwapFileLimits(off_t& minSize, off_t& maxSize) 288 297 { 289 // minimum size is an arbitrarily chosen MB290 298 minSize = kMegaByte; 291 299 292 300 // maximum size is the free space on the current volume 293 301 // (minus some safety offset, depending on the disk size) 294 295 302 off_t freeSpace = fSettings.SwapVolume().FreeBytes(); 296 303 off_t safetyFreeSpace = fSettings.SwapVolume().Capacity() / 100; 297 304 if (safetyFreeSpace > 1024 * kMegaByte) … … 299 306 300 307 // check if there already is a page file on this disk and 301 308 // adjust the free space accordingly 302 303 309 BPath path; 304 310 if (find_directory(B_COMMON_VAR_DIRECTORY, &path, false, 305 311 &fSettings.SwapVolume()) == B_OK) { 306 312 path.Append("swap"); 307 313 BEntry swap(path.Path()); 308 314 309 315 off_t size; 310 if (swap.GetSize(&size) == B_OK) 316 if (swap.GetSize(&size) == B_OK) { 317 // If swap file exists, forget about safety space; 318 // disk may have filled after creation of swap file. 319 safetyFreeSpace = 0; 311 320 freeSpace += size; 321 } 312 322 } 313 323 314 324 maxSize = freeSpace - safetyFreeSpace; 315 316 325 if (maxSize < minSize) { 317 maxSize = minSize ;326 maxSize = minSize = 0; 318 327 return B_ERROR; 319 328 } 320 329 … … 347 356 if (value == 0) { 348 357 // print out warning, give the user the time to think about it :) 349 358 // ToDo: maybe we want to remove this possibility in the GUI 350 // 351 // 359 // as Be did, but I thought a proper warning could be helpful 360 // (for those that want to change that anyway) 352 361 int32 choice = (new BAlert("VirtualMemory", 353 362 B_TRANSLATE( 354 363 "Disabling virtual memory will have unwanted effects on " … … 365 374 } 366 375 367 376 fSettings.SetSwapEnabled(value != 0); 377 if (value == 1 && fSettings.SwapSize() == 0) 378 { 379 off_t min, max; 380 _GetSwapFileLimits(min, max); 381 fSettings.SetSwapSize(min); 382 } 368 383 _Update(); 369 384 break; 370 385 } -
SettingsWindow.h
14 14 class BCheckBox; 15 15 class BSlider; 16 16 class BButton; 17 class BMenuField; 17 18 18 19 19 class SettingsWindow : public BWindow { 20 20 public: 21 21 SettingsWindow(); … … 33 33 BButton* fDefaultsButton; 34 34 BButton* fRevertButton; 35 35 BStringView* fWarningStringView; 36 36 BMenuField* fVolumeMenuField; 37 37 Settings fSettings; 38 38 }; 39 39