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