1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 35 #include <Alert.h> 36 37 #include "Commands.h" 38 #include "DeskWindow.h" 39 #include "Model.h" 40 #include "SettingsViews.h" 41 #include "Tracker.h" 42 #include "WidgetAttributeText.h" 43 44 #include <Box.h> 45 #include <Button.h> 46 #include <MenuField.h> 47 #include <ColorControl.h> 48 #include <NodeMonitor.h> 49 #include <StringView.h> 50 51 52 static const uint32 kSpaceBarSwitchColor = 'SBsc'; 53 static const float kItemExtraSpacing = 2.0f; 54 static const float kIndentSpacing = 12.0f; 55 56 57 static void 58 send_bool_notices(uint32 what, const char *name, bool value) 59 { 60 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 61 if (!tracker) 62 return; 63 64 BMessage message; 65 message.AddBool(name, value); 66 tracker->SendNotices(what, &message); 67 } 68 69 70 // #pragma mark - 71 72 73 SettingsView::SettingsView(BRect rect, const char *name) 74 : BView(rect, name, B_FOLLOW_ALL, 0) 75 { 76 } 77 78 79 SettingsView::~SettingsView() 80 { 81 } 82 83 84 /*! 85 The inherited functions should set the default values 86 and update the UI gadgets. The latter can by done by 87 calling ShowCurrentSettings(). 88 */ 89 void 90 SettingsView::SetDefaults() 91 { 92 } 93 94 95 /*! 96 The inherited functions should set the values that was 97 active when the settings window opened. It should also 98 update the UI widgets accordingly, preferrable by calling 99 ShowCurrentSettings(). 100 */ 101 void 102 SettingsView::Revert() 103 { 104 } 105 106 107 /*! 108 This function is called when the window is shown to let 109 the settings views record the state to revert to. 110 */ 111 void 112 SettingsView::RecordRevertSettings() 113 { 114 } 115 116 117 /*! 118 This function is used by the window to tell the view 119 to display the current settings in the tracker. 120 */ 121 void 122 SettingsView::ShowCurrentSettings() 123 { 124 } 125 126 127 /*! 128 This function is used by the window to tell whether 129 it can ghost the revert button or not. It it shows the 130 reverted settings, this function should return true. 131 */ 132 bool 133 SettingsView::IsRevertable() const 134 { 135 return true; 136 } 137 138 139 // #pragma mark - 140 141 142 DesktopSettingsView::DesktopSettingsView(BRect rect) 143 : SettingsView(rect, "DesktopSettingsView") 144 { 145 rect.OffsetTo(B_ORIGIN); 146 fShowDisksIconRadioButton = new BRadioButton(rect, "", "Show Disks Icon", 147 new BMessage(kShowDisksIconChanged)); 148 fShowDisksIconRadioButton->ResizeToPreferred(); 149 AddChild(fShowDisksIconRadioButton); 150 151 const float itemSpacing = fShowDisksIconRadioButton->Bounds().Height() + kItemExtraSpacing; 152 rect.OffsetBy(0, itemSpacing); 153 154 fMountVolumesOntoDesktopRadioButton = new BRadioButton(rect, "", 155 "Show Volumes On Desktop", new BMessage(kVolumesOnDesktopChanged)); 156 AddChild(fMountVolumesOntoDesktopRadioButton); 157 fMountVolumesOntoDesktopRadioButton->ResizeToPreferred(); 158 159 rect.OffsetBy(20, itemSpacing); 160 161 fMountSharedVolumesOntoDesktopCheckBox = new BCheckBox(rect, "", 162 "Show Shared Volumes On Desktop", new BMessage(kVolumesOnDesktopChanged)); 163 AddChild(fMountSharedVolumesOntoDesktopCheckBox); 164 fMountSharedVolumesOntoDesktopCheckBox->ResizeToPreferred(); 165 166 rect.OffsetBy(-20, 2 * itemSpacing); 167 168 fIntegrateNonBootBeOSDesktopsCheckBox = new BCheckBox(rect, "", 169 "Integrate Non-Boot BeOS Desktops", new BMessage(kDesktopIntegrationChanged)); 170 AddChild(fIntegrateNonBootBeOSDesktopsCheckBox); 171 fIntegrateNonBootBeOSDesktopsCheckBox->ResizeToPreferred(); 172 173 rect.OffsetBy(0, itemSpacing); 174 175 fEjectWhenUnmountingCheckBox = new BCheckBox(rect, "", "Eject When Unmounting", 176 new BMessage(kEjectWhenUnmountingChanged)); 177 AddChild(fEjectWhenUnmountingCheckBox); 178 fEjectWhenUnmountingCheckBox->ResizeToPreferred(); 179 180 rect = Bounds(); 181 rect.top = rect.bottom; 182 fMountButton = new BButton(rect, "", "Mount Settings" B_UTF8_ELLIPSIS, 183 new BMessage(kRunAutomounterSettings), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); 184 fMountButton->ResizeToPreferred(); 185 fMountButton->MoveBy(0, -fMountButton->Bounds().Height()); 186 AddChild(fMountButton); 187 188 fMountButton->SetTarget(be_app); 189 } 190 191 192 void 193 DesktopSettingsView::GetPreferredSize(float *_width, float *_height) 194 { 195 if (_width != NULL) { 196 *_width = max_c(fIntegrateNonBootBeOSDesktopsCheckBox->Frame().right, 197 fMountSharedVolumesOntoDesktopCheckBox->Frame().right); 198 } 199 200 if (_height != NULL) { 201 *_height = fEjectWhenUnmountingCheckBox->Frame().bottom + 8 202 + fMountButton->Bounds().Height(); 203 } 204 } 205 206 207 void 208 DesktopSettingsView::AttachedToWindow() 209 { 210 fShowDisksIconRadioButton->SetTarget(this); 211 fMountVolumesOntoDesktopRadioButton->SetTarget(this); 212 fMountSharedVolumesOntoDesktopCheckBox->SetTarget(this); 213 fIntegrateNonBootBeOSDesktopsCheckBox->SetTarget(this); 214 fEjectWhenUnmountingCheckBox->SetTarget(this); 215 } 216 217 218 void 219 DesktopSettingsView::MessageReceived(BMessage *message) 220 { 221 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 222 if (!tracker) 223 return; 224 225 TrackerSettings settings; 226 227 switch (message->what) { 228 case kShowDisksIconChanged: 229 { 230 // Turn on and off related settings: 231 fMountVolumesOntoDesktopRadioButton->SetValue( 232 !fShowDisksIconRadioButton->Value() == 1); 233 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( 234 fMountVolumesOntoDesktopRadioButton->Value() == 1); 235 236 // Set the new settings in the tracker: 237 settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1); 238 settings.SetMountVolumesOntoDesktop( 239 fMountVolumesOntoDesktopRadioButton->Value() == 1); 240 settings.SetMountSharedVolumesOntoDesktop( 241 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 242 243 // Construct the notification message: 244 BMessage notificationMessage; 245 notificationMessage.AddBool("ShowDisksIcon", 246 fShowDisksIconRadioButton->Value() == 1); 247 notificationMessage.AddBool("MountVolumesOntoDesktop", 248 fMountVolumesOntoDesktopRadioButton->Value() == 1); 249 notificationMessage.AddBool("MountSharedVolumesOntoDesktop", 250 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 251 252 // Send the notification message: 253 tracker->SendNotices(kVolumesOnDesktopChanged, ¬ificationMessage); 254 255 // Tell the settings window the contents have changed: 256 Window()->PostMessage(kSettingsContentsModified); 257 break; 258 } 259 260 case kVolumesOnDesktopChanged: 261 { 262 // Turn on and off related settings: 263 fShowDisksIconRadioButton->SetValue( 264 !fMountVolumesOntoDesktopRadioButton->Value() == 1); 265 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( 266 fMountVolumesOntoDesktopRadioButton->Value() == 1); 267 268 // Set the new settings in the tracker: 269 settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1); 270 settings.SetMountVolumesOntoDesktop( 271 fMountVolumesOntoDesktopRadioButton->Value() == 1); 272 settings.SetMountSharedVolumesOntoDesktop( 273 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 274 275 // Construct the notification message: 276 BMessage notificationMessage; 277 notificationMessage.AddBool("ShowDisksIcon", 278 fShowDisksIconRadioButton->Value() == 1); 279 notificationMessage.AddBool("MountVolumesOntoDesktop", 280 fMountVolumesOntoDesktopRadioButton->Value() == 1); 281 notificationMessage.AddBool("MountSharedVolumesOntoDesktop", 282 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 283 284 // Send the notification message: 285 tracker->SendNotices(kVolumesOnDesktopChanged, ¬ificationMessage); 286 287 // Tell the settings window the contents have changed: 288 Window()->PostMessage(kSettingsContentsModified); 289 break; 290 } 291 292 case kDesktopIntegrationChanged: 293 { 294 // Set the new settings in the tracker: 295 settings.SetIntegrateNonBootBeOSDesktops( 296 fIntegrateNonBootBeOSDesktopsCheckBox->Value() == 1); 297 298 // Construct the notification message: 299 BMessage notificationMessage; 300 notificationMessage.AddBool("MountVolumesOntoDesktop", 301 fMountVolumesOntoDesktopRadioButton->Value() == 1); 302 notificationMessage.AddBool("MountSharedVolumesOntoDesktop", 303 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 304 notificationMessage.AddBool("IntegrateNonBootBeOSDesktops", 305 fIntegrateNonBootBeOSDesktopsCheckBox->Value() == 1); 306 307 // Send the notification message 308 tracker->SendNotices(kDesktopIntegrationChanged, ¬ificationMessage); 309 310 // Tell the settings window the contents have changed 311 Window()->PostMessage(kSettingsContentsModified); 312 break; 313 } 314 315 case kEjectWhenUnmountingChanged: 316 { 317 settings.SetEjectWhenUnmounting( 318 fEjectWhenUnmountingCheckBox->Value() == 1); 319 320 // Send the notification message 321 send_bool_notices(kEjectWhenUnmountingChanged, 322 "EjectWhenUnmounting", fEjectWhenUnmountingCheckBox->Value() == 1); 323 324 // Tell the settings window the contents have changed 325 Window()->PostMessage(kSettingsContentsModified); 326 break; 327 } 328 329 default: 330 _inherited::MessageReceived(message); 331 } 332 } 333 334 335 void 336 DesktopSettingsView::SetDefaults() 337 { 338 // ToDo: Avoid the duplication of the default values. 339 TrackerSettings settings; 340 341 settings.SetShowDisksIcon(false); 342 settings.SetMountVolumesOntoDesktop(true); 343 settings.SetMountSharedVolumesOntoDesktop(false); 344 settings.SetIntegrateNonBootBeOSDesktops(false); 345 settings.SetEjectWhenUnmounting(true); 346 347 ShowCurrentSettings(); 348 _SendNotices(); 349 } 350 351 352 void 353 DesktopSettingsView::Revert() 354 { 355 TrackerSettings settings; 356 357 settings.SetShowDisksIcon(fShowDisksIcon); 358 settings.SetMountVolumesOntoDesktop(fMountVolumesOntoDesktop); 359 settings.SetMountSharedVolumesOntoDesktop(fMountSharedVolumesOntoDesktop); 360 settings.SetIntegrateNonBootBeOSDesktops(fIntegrateNonBootBeOSDesktops); 361 settings.SetEjectWhenUnmounting(fEjectWhenUnmounting); 362 363 ShowCurrentSettings(); 364 _SendNotices(); 365 } 366 367 368 void 369 DesktopSettingsView::_SendNotices() 370 { 371 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 372 if (!tracker) 373 return; 374 375 // Construct the notification message: 376 BMessage notificationMessage; 377 notificationMessage.AddBool("ShowDisksIcon", 378 fShowDisksIconRadioButton->Value() == 1); 379 notificationMessage.AddBool("MountVolumesOntoDesktop", 380 fMountVolumesOntoDesktopRadioButton->Value() == 1); 381 notificationMessage.AddBool("MountSharedVolumesOntoDesktop", 382 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 383 notificationMessage.AddBool("IntegrateNonBootBeOSDesktops", 384 fIntegrateNonBootBeOSDesktopsCheckBox->Value() == 1); 385 notificationMessage.AddBool("EjectWhenUnmounting", 386 fEjectWhenUnmountingCheckBox->Value() == 1); 387 388 // Send notices to the tracker about the change: 389 tracker->SendNotices(kVolumesOnDesktopChanged, ¬ificationMessage); 390 tracker->SendNotices(kDesktopIntegrationChanged, ¬ificationMessage); 391 } 392 393 394 void 395 DesktopSettingsView::ShowCurrentSettings() 396 { 397 TrackerSettings settings; 398 399 fShowDisksIconRadioButton->SetValue(settings.ShowDisksIcon()); 400 fMountVolumesOntoDesktopRadioButton->SetValue(settings.MountVolumesOntoDesktop()); 401 402 fMountSharedVolumesOntoDesktopCheckBox->SetValue(settings.MountSharedVolumesOntoDesktop()); 403 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(settings.MountVolumesOntoDesktop()); 404 405 fIntegrateNonBootBeOSDesktopsCheckBox->SetValue(settings.IntegrateNonBootBeOSDesktops()); 406 407 fEjectWhenUnmountingCheckBox->SetValue(settings.EjectWhenUnmounting()); 408 } 409 410 411 void 412 DesktopSettingsView::RecordRevertSettings() 413 { 414 TrackerSettings settings; 415 416 fShowDisksIcon = settings.ShowDisksIcon(); 417 fMountVolumesOntoDesktop = settings.MountVolumesOntoDesktop(); 418 fMountSharedVolumesOntoDesktop = settings.MountSharedVolumesOntoDesktop(); 419 fIntegrateNonBootBeOSDesktops = settings.IntegrateNonBootBeOSDesktops(); 420 fEjectWhenUnmounting = settings.EjectWhenUnmounting(); 421 } 422 423 424 bool 425 DesktopSettingsView::IsRevertable() const 426 { 427 return fShowDisksIcon != (fShowDisksIconRadioButton->Value() > 0) 428 || fMountVolumesOntoDesktop != 429 (fMountVolumesOntoDesktopRadioButton->Value() > 0) 430 || fMountSharedVolumesOntoDesktop != 431 (fMountSharedVolumesOntoDesktopCheckBox->Value() > 0) 432 || fIntegrateNonBootBeOSDesktops != 433 (fIntegrateNonBootBeOSDesktopsCheckBox->Value() > 0) 434 || fEjectWhenUnmounting != 435 (fEjectWhenUnmountingCheckBox->Value() > 0); 436 } 437 438 439 // #pragma mark - 440 441 442 WindowsSettingsView::WindowsSettingsView(BRect rect) 443 : SettingsView(rect, "WindowsSettingsView") 444 { 445 rect.OffsetTo(B_ORIGIN); 446 fShowFullPathInTitleBarCheckBox = new BCheckBox(rect, "", "Show Full Path In Title Bar", 447 new BMessage(kWindowsShowFullPathChanged)); 448 fShowFullPathInTitleBarCheckBox->ResizeToPreferred(); 449 AddChild(fShowFullPathInTitleBarCheckBox); 450 451 const float itemSpacing = fShowFullPathInTitleBarCheckBox->Bounds().Height() + kItemExtraSpacing; 452 rect.OffsetBy(0, itemSpacing); 453 454 fSingleWindowBrowseCheckBox = new BCheckBox(rect, "", "Single Window Browse", 455 new BMessage(kSingleWindowBrowseChanged)); 456 fSingleWindowBrowseCheckBox->ResizeToPreferred(); 457 AddChild(fSingleWindowBrowseCheckBox); 458 459 rect.OffsetBy(20, itemSpacing); 460 461 fShowNavigatorCheckBox = new BCheckBox(rect, "", "Show Navigator", 462 new BMessage(kShowNavigatorChanged)); 463 fShowNavigatorCheckBox->ResizeToPreferred(); 464 AddChild(fShowNavigatorCheckBox); 465 466 rect.OffsetBy(-20, itemSpacing); 467 468 fOutlineSelectionCheckBox = new BCheckBox(rect, "", "Outline Selection Rectangle Only", 469 new BMessage(kTransparentSelectionChanged)); 470 fOutlineSelectionCheckBox->ResizeToPreferred(); 471 AddChild(fOutlineSelectionCheckBox); 472 473 rect.OffsetBy(0, itemSpacing); 474 475 fSortFolderNamesFirstCheckBox = new BCheckBox(rect, "", "Sort Folder Names First", 476 new BMessage(kSortFolderNamesFirstChanged)); 477 fSortFolderNamesFirstCheckBox->ResizeToPreferred(); 478 AddChild(fSortFolderNamesFirstCheckBox); 479 } 480 481 482 void 483 WindowsSettingsView::GetPreferredSize(float *_width, float *_height) 484 { 485 if (_width != NULL) 486 *_width = fOutlineSelectionCheckBox->Frame().right; 487 488 if (_height != NULL) 489 *_height = fSortFolderNamesFirstCheckBox->Frame().bottom; 490 } 491 492 493 void 494 WindowsSettingsView::AttachedToWindow() 495 { 496 fSingleWindowBrowseCheckBox->SetTarget(this); 497 fShowNavigatorCheckBox->SetTarget(this); 498 fShowFullPathInTitleBarCheckBox->SetTarget(this); 499 fOutlineSelectionCheckBox->SetTarget(this); 500 fSortFolderNamesFirstCheckBox->SetTarget(this); 501 } 502 503 504 void 505 WindowsSettingsView::MessageReceived(BMessage *message) 506 { 507 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 508 if (!tracker) 509 return; 510 TrackerSettings settings; 511 512 switch (message->what) { 513 case kWindowsShowFullPathChanged: 514 settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBarCheckBox->Value() == 1); 515 tracker->SendNotices(kWindowsShowFullPathChanged); 516 Window()->PostMessage(kSettingsContentsModified); 517 break; 518 519 case kSingleWindowBrowseChanged: 520 settings.SetSingleWindowBrowse(fSingleWindowBrowseCheckBox->Value() == 1); 521 if (fSingleWindowBrowseCheckBox->Value() == 0) { 522 fShowNavigatorCheckBox->SetEnabled(false); 523 settings.SetShowNavigator(0); 524 } else { 525 fShowNavigatorCheckBox->SetEnabled(true); 526 settings.SetShowNavigator(fShowNavigatorCheckBox->Value() != 0); 527 } 528 tracker->SendNotices(kShowNavigatorChanged); 529 tracker->SendNotices(kSingleWindowBrowseChanged); 530 Window()->PostMessage(kSettingsContentsModified); 531 break; 532 533 case kShowNavigatorChanged: 534 settings.SetShowNavigator(fShowNavigatorCheckBox->Value() == 1); 535 tracker->SendNotices(kShowNavigatorChanged); 536 Window()->PostMessage(kSettingsContentsModified); 537 break; 538 539 case kTransparentSelectionChanged: 540 { 541 settings.SetTransparentSelection( 542 fOutlineSelectionCheckBox->Value() == B_CONTROL_OFF); 543 544 // Make the notification message and send it to the tracker: 545 send_bool_notices(kTransparentSelectionChanged, 546 "TransparentSelection", settings.TransparentSelection()); 547 548 Window()->PostMessage(kSettingsContentsModified); 549 break; 550 } 551 552 case kSortFolderNamesFirstChanged: 553 { 554 settings.SetSortFolderNamesFirst(fSortFolderNamesFirstCheckBox->Value() == 1); 555 556 // Make the notification message and send it to the tracker: 557 send_bool_notices(kSortFolderNamesFirstChanged, "SortFolderNamesFirst", 558 fSortFolderNamesFirstCheckBox->Value() == 1); 559 560 Window()->PostMessage(kSettingsContentsModified); 561 break; 562 } 563 564 default: 565 _inherited::MessageReceived(message); 566 break; 567 } 568 } 569 570 571 void 572 WindowsSettingsView::SetDefaults() 573 { 574 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 575 if (!tracker) 576 return; 577 578 TrackerSettings settings; 579 580 if (settings.ShowFullPathInTitleBar()) { 581 settings.SetShowFullPathInTitleBar(false); 582 tracker->SendNotices(kWindowsShowFullPathChanged); 583 } 584 585 if (settings.SingleWindowBrowse()) { 586 settings.SetSingleWindowBrowse(false); 587 tracker->SendNotices(kSingleWindowBrowseChanged); 588 } 589 590 if (settings.ShowNavigator()) { 591 settings.SetShowNavigator(false); 592 tracker->SendNotices(kShowNavigatorChanged); 593 } 594 595 if (!settings.TransparentSelection()) { 596 settings.SetTransparentSelection(true); 597 send_bool_notices(kTransparentSelectionChanged, 598 "TransparentSelection", true); 599 } 600 601 if (settings.SortFolderNamesFirst()) { 602 settings.SetSortFolderNamesFirst(false); 603 send_bool_notices(kSortFolderNamesFirstChanged, 604 "SortFolderNamesFirst", false); 605 } 606 607 ShowCurrentSettings(); 608 } 609 610 611 void 612 WindowsSettingsView::Revert() 613 { 614 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 615 if (!tracker) 616 return; 617 618 TrackerSettings settings; 619 620 if (settings.ShowFullPathInTitleBar() != fShowFullPathInTitleBar) { 621 settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBar); 622 tracker->SendNotices(kWindowsShowFullPathChanged); 623 } 624 625 if (settings.SingleWindowBrowse() != fSingleWindowBrowse) { 626 settings.SetSingleWindowBrowse(fSingleWindowBrowse); 627 tracker->SendNotices(kSingleWindowBrowseChanged); 628 } 629 630 if (settings.ShowNavigator() != fShowNavigator) { 631 settings.SetShowNavigator(fShowNavigator); 632 tracker->SendNotices(kShowNavigatorChanged); 633 } 634 635 if (settings.TransparentSelection() != fTransparentSelection) { 636 settings.SetTransparentSelection(fTransparentSelection); 637 send_bool_notices(kTransparentSelectionChanged, 638 "TransparentSelection", fTransparentSelection); 639 } 640 641 if (settings.SortFolderNamesFirst() != fSortFolderNamesFirst) { 642 settings.SetSortFolderNamesFirst(fSortFolderNamesFirst); 643 send_bool_notices(kSortFolderNamesFirstChanged, 644 "SortFolderNamesFirst", fSortFolderNamesFirst); 645 } 646 647 ShowCurrentSettings(); 648 } 649 650 651 void 652 WindowsSettingsView::ShowCurrentSettings() 653 { 654 TrackerSettings settings; 655 656 fShowFullPathInTitleBarCheckBox->SetValue(settings.ShowFullPathInTitleBar()); 657 fSingleWindowBrowseCheckBox->SetValue(settings.SingleWindowBrowse()); 658 fShowNavigatorCheckBox->SetEnabled(settings.SingleWindowBrowse()); 659 fShowNavigatorCheckBox->SetValue(settings.ShowNavigator()); 660 fOutlineSelectionCheckBox->SetValue(settings.TransparentSelection() 661 ? B_CONTROL_OFF : B_CONTROL_ON); 662 fSortFolderNamesFirstCheckBox->SetValue(settings.SortFolderNamesFirst()); 663 } 664 665 666 void 667 WindowsSettingsView::RecordRevertSettings() 668 { 669 TrackerSettings settings; 670 671 fShowFullPathInTitleBar = settings.ShowFullPathInTitleBar(); 672 fSingleWindowBrowse = settings.SingleWindowBrowse(); 673 fShowNavigator = settings.ShowNavigator(); 674 fTransparentSelection = settings.TransparentSelection(); 675 fSortFolderNamesFirst = settings.SortFolderNamesFirst(); 676 } 677 678 679 bool 680 WindowsSettingsView::IsRevertable() const 681 { 682 TrackerSettings settings; 683 684 return fShowFullPathInTitleBar != settings.ShowFullPathInTitleBar() 685 || fSingleWindowBrowse != settings.SingleWindowBrowse() 686 || fShowNavigator != settings.ShowNavigator() 687 || fTransparentSelection != settings.TransparentSelection() 688 || fSortFolderNamesFirst != settings.SortFolderNamesFirst(); 689 } 690 691 692 // #pragma mark - 693 694 695 TimeFormatSettingsView::TimeFormatSettingsView(BRect rect) 696 : SettingsView(rect, "WindowsSettingsView") 697 { 698 rect.OffsetTo(B_ORIGIN); 699 700 font_height fontHeight; 701 be_bold_font->GetHeight(&fontHeight); 702 703 rect.bottom = ceilf(fontHeight.ascent + fontHeight.descent) + 10; 704 BBox *clockBox = new BBox(rect, "Clock"); 705 clockBox->SetLabel("Clock"); 706 AddChild(clockBox); 707 708 rect.left = 8; 709 rect.top = rect.bottom - 8; 710 f24HrRadioButton = new BRadioButton(rect, "", "24 Hour", 711 new BMessage(kSettingsContentsModified)); 712 f24HrRadioButton->ResizeToPreferred(); 713 clockBox->AddChild(f24HrRadioButton); 714 715 const float itemSpacing = f24HrRadioButton->Bounds().Height() + kItemExtraSpacing; 716 rect.OffsetBy(0, itemSpacing); 717 718 f12HrRadioButton = new BRadioButton(rect, "", "12 Hour", 719 new BMessage(kSettingsContentsModified)); 720 f12HrRadioButton->ResizeToPreferred(); 721 clockBox->AddChild(f12HrRadioButton); 722 723 float width = max_c(f12HrRadioButton->Frame().right, f24HrRadioButton->Frame().right) + 8.0f; 724 clockBox->ResizeTo(width, clockBox->Bounds().Height() 725 + 3 * f12HrRadioButton->Frame().Height()); 726 727 rect = clockBox->Frame(); 728 rect.OffsetBy(rect.Width() + 8, 0); 729 BBox *dateFormatBox = new BBox(rect, "Date Order"); 730 dateFormatBox->SetLabel("Date Order"); 731 AddChild(dateFormatBox); 732 733 rect = f24HrRadioButton->Frame(); 734 fYMDRadioButton = new BRadioButton(rect, "", "Year-Month-Day", 735 new BMessage(kSettingsContentsModified)); 736 fYMDRadioButton->ResizeToPreferred(); 737 dateFormatBox->AddChild(fYMDRadioButton); 738 739 rect.OffsetBy(0, itemSpacing); 740 741 fDMYRadioButton = new BRadioButton(rect, "", "Day-Month-Year", 742 new BMessage(kSettingsContentsModified)); 743 fDMYRadioButton->ResizeToPreferred(); 744 dateFormatBox->AddChild(fDMYRadioButton); 745 746 rect.OffsetBy(0, itemSpacing); 747 748 fMDYRadioButton = new BRadioButton(rect, "", "Month-Day-Year", 749 new BMessage(kSettingsContentsModified)); 750 fMDYRadioButton->ResizeToPreferred(); 751 dateFormatBox->AddChild(fMDYRadioButton); 752 753 dateFormatBox->ResizeTo(fYMDRadioButton->Bounds().Width() + 16, 754 dateFormatBox->Bounds().Height()); 755 756 BPopUpMenu *menu = new BPopUpMenu("Separator"); 757 menu->AddItem(new BMenuItem("None", new BMessage(kSettingsContentsModified))); 758 menu->AddItem(new BMenuItem("Space", new BMessage(kSettingsContentsModified))); 759 menu->AddItem(new BMenuItem("-", new BMessage(kSettingsContentsModified))); 760 menu->AddItem(new BMenuItem("/", new BMessage(kSettingsContentsModified))); 761 menu->AddItem(new BMenuItem("\\", new BMessage(kSettingsContentsModified))); 762 menu->AddItem(new BMenuItem(".", new BMessage(kSettingsContentsModified))); 763 764 rect.left = 0; 765 rect.top = clockBox->Frame().bottom + 8; 766 rect.right = Bounds().Width() - 8; 767 rect.bottom = rect.top + itemSpacing; 768 fSeparatorMenuField = new BMenuField(rect, "Separator", "Separator:", menu); 769 fSeparatorMenuField->SetDivider(fSeparatorMenuField->StringWidth(fSeparatorMenuField->Label()) + 8.0f); 770 fSeparatorMenuField->SetAlignment(B_ALIGN_LEFT); 771 fSeparatorMenuField->ResizeToPreferred(); 772 AddChild(fSeparatorMenuField); 773 774 rect.OffsetBy(0, itemSpacing + 10); 775 776 BStringView *exampleView = new BStringView(rect, "", "Examples:"); 777 exampleView->ResizeToPreferred(); 778 AddChild(exampleView); 779 780 rect.OffsetBy(0, itemSpacing); 781 782 fLongDateExampleView = new BStringView(rect, "", ""); 783 fLongDateExampleView->ResizeToPreferred(); 784 AddChild(fLongDateExampleView); 785 786 rect.OffsetBy(0, itemSpacing); 787 788 fShortDateExampleView = new BStringView(rect, "", ""); 789 fShortDateExampleView->ResizeToPreferred(); 790 AddChild(fShortDateExampleView); 791 792 _UpdateExamples(); 793 } 794 795 796 void 797 TimeFormatSettingsView::GetPreferredSize(float *_width, float *_height) 798 { 799 if (_width != NULL) { 800 BView* view = fMDYRadioButton->Parent(); 801 if (view != NULL) 802 *_width = view->Frame().right; 803 else 804 *_width = Bounds().Width(); 805 } 806 807 if (_height != NULL) 808 *_height = fShortDateExampleView->Frame().bottom; 809 } 810 811 812 void 813 TimeFormatSettingsView::AttachedToWindow() 814 { 815 f24HrRadioButton->SetTarget(this); 816 f12HrRadioButton->SetTarget(this); 817 fYMDRadioButton->SetTarget(this); 818 fDMYRadioButton->SetTarget(this); 819 fMDYRadioButton->SetTarget(this); 820 821 fSeparatorMenuField->Menu()->SetTargetForItems(this); 822 } 823 824 825 void 826 TimeFormatSettingsView::MessageReceived(BMessage *message) 827 { 828 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 829 if (!tracker) 830 return; 831 TrackerSettings settings; 832 833 switch (message->what) { 834 case kSettingsContentsModified: 835 { 836 int32 separator = 0; 837 BMenuItem *item = fSeparatorMenuField->Menu()->FindMarked(); 838 if (item) { 839 separator = fSeparatorMenuField->Menu()->IndexOf(item); 840 if (separator >= 0) 841 settings.SetTimeFormatSeparator((FormatSeparator)separator); 842 } 843 844 DateOrder format = 845 fYMDRadioButton->Value() ? kYMDFormat : 846 fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat; 847 848 settings.SetDateOrderFormat(format); 849 settings.SetClockTo24Hr(f24HrRadioButton->Value() == 1); 850 851 // Make the notification message and send it to the tracker: 852 BMessage notificationMessage; 853 notificationMessage.AddInt32("TimeFormatSeparator", separator); 854 notificationMessage.AddInt32("DateOrderFormat", format); 855 notificationMessage.AddBool("24HrClock", f24HrRadioButton->Value() == 1); 856 tracker->SendNotices(kDateFormatChanged, ¬ificationMessage); 857 858 _UpdateExamples(); 859 860 Window()->PostMessage(kSettingsContentsModified); 861 break; 862 } 863 864 default: 865 _inherited::MessageReceived(message); 866 } 867 } 868 869 870 void 871 TimeFormatSettingsView::SetDefaults() 872 { 873 TrackerSettings settings; 874 875 settings.SetTimeFormatSeparator(kSlashSeparator); 876 settings.SetDateOrderFormat(kMDYFormat); 877 settings.SetClockTo24Hr(false); 878 879 ShowCurrentSettings(); 880 _SendNotices(); 881 } 882 883 884 void 885 TimeFormatSettingsView::Revert() 886 { 887 TrackerSettings settings; 888 889 settings.SetTimeFormatSeparator(fSeparator); 890 settings.SetDateOrderFormat(fFormat); 891 settings.SetClockTo24Hr(f24HrClock); 892 893 ShowCurrentSettings(); 894 _SendNotices(); 895 } 896 897 898 void 899 TimeFormatSettingsView::_SendNotices() 900 { 901 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 902 if (!tracker) 903 return; 904 905 TrackerSettings settings; 906 907 // Make the notification message and send it to the tracker: 908 BMessage notificationMessage; 909 notificationMessage.AddInt32("TimeFormatSeparator", (int32)settings.TimeFormatSeparator()); 910 notificationMessage.AddInt32("DateOrderFormat", (int32)settings.DateOrderFormat()); 911 notificationMessage.AddBool("24HrClock", settings.ClockIs24Hr()); 912 tracker->SendNotices(kDateFormatChanged, ¬ificationMessage); 913 } 914 915 916 void 917 TimeFormatSettingsView::ShowCurrentSettings() 918 { 919 TrackerSettings settings; 920 921 f24HrRadioButton->SetValue(settings.ClockIs24Hr()); 922 f12HrRadioButton->SetValue(!settings.ClockIs24Hr()); 923 924 switch (settings.DateOrderFormat()) { 925 case kYMDFormat: 926 fYMDRadioButton->SetValue(1); 927 break; 928 929 case kMDYFormat: 930 fMDYRadioButton->SetValue(1); 931 break; 932 933 default: 934 case kDMYFormat: 935 fDMYRadioButton->SetValue(1); 936 break; 937 } 938 939 FormatSeparator separator = settings.TimeFormatSeparator(); 940 941 if (separator >= kNoSeparator && separator < kSeparatorsEnd) 942 fSeparatorMenuField->Menu()->ItemAt((int32)separator)->SetMarked(true); 943 944 _UpdateExamples(); 945 } 946 947 948 void 949 TimeFormatSettingsView::RecordRevertSettings() 950 { 951 TrackerSettings settings; 952 953 f24HrClock = settings.ClockIs24Hr(); 954 fSeparator = settings.TimeFormatSeparator(); 955 fFormat = settings.DateOrderFormat(); 956 } 957 958 959 bool 960 TimeFormatSettingsView::IsRevertable() const 961 { 962 FormatSeparator separator; 963 964 BMenuItem *item = fSeparatorMenuField->Menu()->FindMarked(); 965 if (item) { 966 int32 index = fSeparatorMenuField->Menu()->IndexOf(item); 967 if (index >= 0) 968 separator = (FormatSeparator)index; 969 else 970 return true; 971 } else 972 return true; 973 974 DateOrder format = 975 fYMDRadioButton->Value() ? kYMDFormat : 976 (fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat); 977 978 return f24HrClock != (f24HrRadioButton->Value() > 0) 979 || separator != fSeparator 980 || format != fFormat; 981 } 982 983 984 void 985 TimeFormatSettingsView::_UpdateExamples() 986 { 987 time_t timeValue = (time_t)time(NULL); 988 tm timeData; 989 localtime_r(&timeValue, &timeData); 990 BString timeFormat = "Internal Error!"; 991 char buffer[256]; 992 993 FormatSeparator separator; 994 995 BMenuItem *item = fSeparatorMenuField->Menu()->FindMarked(); 996 if (item) { 997 int32 index = fSeparatorMenuField->Menu()->IndexOf(item); 998 if (index >= 0) 999 separator = (FormatSeparator)index; 1000 else 1001 separator = kSlashSeparator; 1002 } else 1003 separator = kSlashSeparator; 1004 1005 DateOrder order = 1006 fYMDRadioButton->Value() ? kYMDFormat : 1007 (fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat); 1008 1009 bool clockIs24hr = (f24HrRadioButton->Value() > 0); 1010 1011 TimeFormat(timeFormat, 0, separator, order, clockIs24hr); 1012 strftime(buffer, 256, timeFormat.String(), &timeData); 1013 1014 fLongDateExampleView->SetText(buffer); 1015 fLongDateExampleView->ResizeToPreferred(); 1016 1017 TimeFormat(timeFormat, 4, separator, order, clockIs24hr); 1018 strftime(buffer, 256, timeFormat.String(), &timeData); 1019 1020 fShortDateExampleView->SetText(buffer); 1021 fShortDateExampleView->ResizeToPreferred(); 1022 } 1023 1024 1025 // #pragma mark - 1026 1027 1028 SpaceBarSettingsView::SpaceBarSettingsView(BRect rect) 1029 : SettingsView(rect, "SpaceBarSettingsView") 1030 { 1031 rect.OffsetTo(B_ORIGIN); 1032 fSpaceBarShowCheckBox = new BCheckBox(rect, "", "Show Space Bars On Volumes", 1033 new BMessage(kUpdateVolumeSpaceBar)); 1034 fSpaceBarShowCheckBox->ResizeToPreferred(); 1035 AddChild(fSpaceBarShowCheckBox); 1036 1037 rect = fSpaceBarShowCheckBox->Frame(); 1038 rect.OffsetBy(0, fSpaceBarShowCheckBox->Bounds().Height() + kItemExtraSpacing); 1039 1040 BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING); 1041 menu->SetFont(be_plain_font); 1042 1043 BMenuItem *item; 1044 menu->AddItem(item = new BMenuItem("Used Space Color", new BMessage(kSpaceBarSwitchColor))); 1045 item->SetMarked(true); 1046 fCurrentColor = 0; 1047 menu->AddItem(new BMenuItem("Free Space Color", new BMessage(kSpaceBarSwitchColor))); 1048 menu->AddItem(new BMenuItem("Warning Space Color", new BMessage(kSpaceBarSwitchColor))); 1049 1050 BBox *box = new BBox(rect); 1051 box->SetLabel(fColorPicker = new BMenuField(rect, NULL, NULL, menu)); 1052 AddChild(box); 1053 1054 fColorControl = new BColorControl(BPoint(8, fColorPicker->Bounds().Height() 1055 + 8 + kItemExtraSpacing), 1056 B_CELLS_16x16, 1, "SpaceColorControl", new BMessage(kSpaceBarColorChanged)); 1057 fColorControl->SetValue(TrackerSettings().UsedSpaceColor()); 1058 fColorControl->ResizeToPreferred(); 1059 box->AddChild(fColorControl); 1060 1061 box->ResizeTo(fColorControl->Bounds().Width() + 16, 1062 fColorControl->Frame().bottom + 8); 1063 } 1064 1065 1066 SpaceBarSettingsView::~SpaceBarSettingsView() 1067 { 1068 } 1069 1070 1071 void 1072 SpaceBarSettingsView::GetPreferredSize(float *_width, float *_height) 1073 { 1074 BView* view = fColorControl->Parent(); 1075 if (view == NULL) 1076 BView::GetPreferredSize(_width, _height); 1077 1078 if (_width != NULL) { 1079 float width = fSpaceBarShowCheckBox->Bounds().Width(); 1080 if (view->Bounds().Width() > width) 1081 width = view->Bounds().Width(); 1082 1083 *_width = width; 1084 } 1085 1086 if (_height != NULL) 1087 *_height = view->Frame().bottom; 1088 } 1089 1090 1091 void 1092 SpaceBarSettingsView::AttachedToWindow() 1093 { 1094 fSpaceBarShowCheckBox->SetTarget(this); 1095 fColorControl->SetTarget(this); 1096 fColorPicker->Menu()->SetTargetForItems(this); 1097 } 1098 1099 1100 void 1101 SpaceBarSettingsView::MessageReceived(BMessage *message) 1102 { 1103 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 1104 if (!tracker) 1105 return; 1106 TrackerSettings settings; 1107 1108 switch (message->what) { 1109 case kUpdateVolumeSpaceBar: 1110 { 1111 settings.SetShowVolumeSpaceBar(fSpaceBarShowCheckBox->Value() == 1); 1112 Window()->PostMessage(kSettingsContentsModified); 1113 BMessage notificationMessage; 1114 notificationMessage.AddBool("ShowVolumeSpaceBar", settings.ShowVolumeSpaceBar()); 1115 tracker->SendNotices(kShowVolumeSpaceBar, ¬ificationMessage); 1116 break; 1117 } 1118 1119 case kSpaceBarSwitchColor: 1120 { 1121 fCurrentColor = message->FindInt32("index"); 1122 switch (fCurrentColor) { 1123 case 0: 1124 fColorControl->SetValue(settings.UsedSpaceColor()); 1125 break; 1126 case 1: 1127 fColorControl->SetValue(settings.FreeSpaceColor()); 1128 break; 1129 case 2: 1130 fColorControl->SetValue(settings.WarningSpaceColor()); 1131 break; 1132 } 1133 break; 1134 } 1135 case kSpaceBarColorChanged: 1136 { 1137 switch (fCurrentColor) { 1138 case 0: 1139 settings.SetUsedSpaceColor(fColorControl->ValueAsColor()); 1140 break; 1141 case 1: 1142 settings.SetFreeSpaceColor(fColorControl->ValueAsColor()); 1143 break; 1144 case 2: 1145 settings.SetWarningSpaceColor(fColorControl->ValueAsColor()); 1146 break; 1147 } 1148 1149 Window()->PostMessage(kSettingsContentsModified); 1150 BMessage notificationMessage; 1151 tracker->SendNotices(kSpaceBarColorChanged, ¬ificationMessage); 1152 break; 1153 } 1154 1155 default: 1156 _inherited::MessageReceived(message); 1157 break; 1158 } 1159 } 1160 1161 1162 void 1163 SpaceBarSettingsView::SetDefaults() 1164 { 1165 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 1166 if (!tracker) 1167 return; 1168 1169 TrackerSettings settings; 1170 1171 if (settings.ShowVolumeSpaceBar()) { 1172 settings.SetShowVolumeSpaceBar(false); 1173 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", false); 1174 } 1175 1176 if (settings.UsedSpaceColor() != Color(0, 203, 0, 192) 1177 || settings.FreeSpaceColor() != Color(255, 255, 255, 192) 1178 || settings.WarningSpaceColor() != Color(203, 0, 0, 192)) { 1179 settings.SetUsedSpaceColor(Color(0, 203, 0, 192)); 1180 settings.SetFreeSpaceColor(Color(255, 255, 255, 192)); 1181 settings.SetWarningSpaceColor(Color(203, 0, 0, 192)); 1182 tracker->SendNotices(kSpaceBarColorChanged); 1183 } 1184 1185 ShowCurrentSettings(); 1186 } 1187 1188 1189 void 1190 SpaceBarSettingsView::Revert() 1191 { 1192 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 1193 if (!tracker) 1194 return; 1195 1196 TrackerSettings settings; 1197 1198 if (settings.ShowVolumeSpaceBar() != fSpaceBarShow) { 1199 settings.SetShowVolumeSpaceBar(fSpaceBarShow); 1200 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", fSpaceBarShow); 1201 } 1202 1203 if (settings.UsedSpaceColor() != fUsedSpaceColor 1204 || settings.FreeSpaceColor() != fFreeSpaceColor 1205 || settings.WarningSpaceColor() != fWarningSpaceColor) { 1206 settings.SetUsedSpaceColor(fUsedSpaceColor); 1207 settings.SetFreeSpaceColor(fFreeSpaceColor); 1208 settings.SetWarningSpaceColor(fWarningSpaceColor); 1209 tracker->SendNotices(kSpaceBarColorChanged); 1210 } 1211 1212 ShowCurrentSettings(); 1213 } 1214 1215 1216 void 1217 SpaceBarSettingsView::ShowCurrentSettings() 1218 { 1219 TrackerSettings settings; 1220 1221 fSpaceBarShowCheckBox->SetValue(settings.ShowVolumeSpaceBar()); 1222 1223 switch (fCurrentColor) { 1224 case 0: 1225 fColorControl->SetValue(settings.UsedSpaceColor()); 1226 break; 1227 case 1: 1228 fColorControl->SetValue(settings.FreeSpaceColor()); 1229 break; 1230 case 2: 1231 fColorControl->SetValue(settings.WarningSpaceColor()); 1232 break; 1233 } 1234 } 1235 1236 1237 void 1238 SpaceBarSettingsView::RecordRevertSettings() 1239 { 1240 TrackerSettings settings; 1241 1242 fSpaceBarShow = settings.ShowVolumeSpaceBar(); 1243 fUsedSpaceColor = settings.UsedSpaceColor(); 1244 fFreeSpaceColor = settings.FreeSpaceColor(); 1245 fWarningSpaceColor = settings.WarningSpaceColor(); 1246 } 1247 1248 1249 bool 1250 SpaceBarSettingsView::IsRevertable() const 1251 { 1252 TrackerSettings settings; 1253 1254 return fSpaceBarShow != (fSpaceBarShowCheckBox->Value() == B_CONTROL_ON) 1255 || fUsedSpaceColor != settings.UsedSpaceColor() 1256 || fFreeSpaceColor != settings.FreeSpaceColor() 1257 || fWarningSpaceColor != settings.WarningSpaceColor(); 1258 } 1259 1260 1261 // #pragma mark - 1262 1263 1264 TrashSettingsView::TrashSettingsView(BRect rect) 1265 : SettingsView(rect, "TrashSettingsView") 1266 { 1267 rect.OffsetTo(B_ORIGIN); 1268 fDontMoveFilesToTrashCheckBox = new BCheckBox(rect, "", "Don't Move Files To Trash", 1269 new BMessage(kDontMoveFilesToTrashChanged)); 1270 fDontMoveFilesToTrashCheckBox->ResizeToPreferred(); 1271 AddChild(fDontMoveFilesToTrashCheckBox); 1272 1273 rect = fDontMoveFilesToTrashCheckBox->Frame(); 1274 rect.OffsetBy(0, fDontMoveFilesToTrashCheckBox->Bounds().Height() + kItemExtraSpacing); 1275 1276 fAskBeforeDeleteFileCheckBox = new BCheckBox(rect, "", "Ask Before Delete", 1277 new BMessage(kAskBeforeDeleteFileChanged)); 1278 fAskBeforeDeleteFileCheckBox->ResizeToPreferred(); 1279 AddChild(fAskBeforeDeleteFileCheckBox); 1280 } 1281 1282 1283 void 1284 TrashSettingsView::GetPreferredSize(float *_width, float *_height) 1285 { 1286 if (_width != NULL) { 1287 float width = fDontMoveFilesToTrashCheckBox->Bounds().Width(); 1288 if (width < fAskBeforeDeleteFileCheckBox->Bounds().Width()) 1289 width = fAskBeforeDeleteFileCheckBox->Bounds().Width(); 1290 1291 *_width = width; 1292 } 1293 1294 if (_height != NULL) 1295 *_height = fAskBeforeDeleteFileCheckBox->Frame().bottom; 1296 } 1297 1298 1299 void 1300 TrashSettingsView::AttachedToWindow() 1301 { 1302 fDontMoveFilesToTrashCheckBox->SetTarget(this); 1303 fAskBeforeDeleteFileCheckBox->SetTarget(this); 1304 } 1305 1306 1307 void 1308 TrashSettingsView::MessageReceived(BMessage *message) 1309 { 1310 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 1311 if (!tracker) 1312 return; 1313 TrackerSettings settings; 1314 1315 switch (message->what) { 1316 case kDontMoveFilesToTrashChanged: 1317 settings.SetDontMoveFilesToTrash(fDontMoveFilesToTrashCheckBox->Value() == 1); 1318 1319 tracker->SendNotices(kDontMoveFilesToTrashChanged); 1320 Window()->PostMessage(kSettingsContentsModified); 1321 break; 1322 1323 case kAskBeforeDeleteFileChanged: 1324 settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFileCheckBox->Value() == 1); 1325 1326 tracker->SendNotices(kAskBeforeDeleteFileChanged); 1327 Window()->PostMessage(kSettingsContentsModified); 1328 break; 1329 1330 default: 1331 _inherited::MessageReceived(message); 1332 break; 1333 } 1334 } 1335 1336 1337 void 1338 TrashSettingsView::SetDefaults() 1339 { 1340 TrackerSettings settings; 1341 1342 settings.SetDontMoveFilesToTrash(false); 1343 settings.SetAskBeforeDeleteFile(true); 1344 1345 ShowCurrentSettings(); 1346 _SendNotices(); 1347 } 1348 1349 1350 void 1351 TrashSettingsView::Revert() 1352 { 1353 TrackerSettings settings; 1354 1355 settings.SetDontMoveFilesToTrash(fDontMoveFilesToTrash); 1356 settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFile); 1357 1358 ShowCurrentSettings(); 1359 _SendNotices(); 1360 } 1361 1362 1363 void 1364 TrashSettingsView::_SendNotices() 1365 { 1366 TTracker *tracker = dynamic_cast<TTracker *>(be_app); 1367 if (!tracker) 1368 return; 1369 1370 tracker->SendNotices(kDontMoveFilesToTrashChanged); 1371 tracker->SendNotices(kAskBeforeDeleteFileChanged); 1372 } 1373 1374 1375 void 1376 TrashSettingsView::ShowCurrentSettings() 1377 { 1378 TrackerSettings settings; 1379 1380 fDontMoveFilesToTrashCheckBox->SetValue(settings.DontMoveFilesToTrash()); 1381 fAskBeforeDeleteFileCheckBox->SetValue(settings.AskBeforeDeleteFile()); 1382 } 1383 1384 1385 void 1386 TrashSettingsView::RecordRevertSettings() 1387 { 1388 TrackerSettings settings; 1389 1390 fDontMoveFilesToTrash = settings.DontMoveFilesToTrash(); 1391 fAskBeforeDeleteFile = settings.AskBeforeDeleteFile(); 1392 } 1393 1394 1395 bool 1396 TrashSettingsView::IsRevertable() const 1397 { 1398 return fDontMoveFilesToTrash != (fDontMoveFilesToTrashCheckBox->Value() > 0) 1399 || fAskBeforeDeleteFile != (fAskBeforeDeleteFileCheckBox->Value() > 0); 1400 } 1401 1402