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