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 36 #include "SettingsViews.h" 37 38 #include <Box.h> 39 #include <Button.h> 40 #include <Catalog.h> 41 #include <CheckBox.h> 42 #include <ColorControl.h> 43 #include <ControlLook.h> 44 #include <LayoutBuilder.h> 45 #include <Locale.h> 46 #include <MenuField.h> 47 #include <NodeMonitor.h> 48 #include <Point.h> 49 #include <RadioButton.h> 50 #include <StringView.h> 51 52 #include "Commands.h" 53 #include "DeskWindow.h" 54 #include "Model.h" 55 #include "Tracker.h" 56 #include "WidgetAttributeText.h" 57 58 59 static const uint32 kSpaceBarSwitchColor = 'SBsc'; 60 61 //TODO: defaults should be set in one place only (TrackerSettings.cpp) while 62 // being accessible from here. 63 // What about adding DefaultValue(), IsDefault() etc... methods to 64 // xxxValueSetting ? 65 static const uint8 kSpaceBarAlpha = 192; 66 static const rgb_color kDefaultUsedSpaceColor = { 0, 203, 0, kSpaceBarAlpha }; 67 static const rgb_color kDefaultFreeSpaceColor 68 = { 255, 255, 255, kSpaceBarAlpha }; 69 static const rgb_color kDefaultWarningSpaceColor 70 = { 203, 0, 0, kSpaceBarAlpha }; 71 72 73 static void 74 send_bool_notices(uint32 what, const char* name, bool value) 75 { 76 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 77 if (tracker == NULL) 78 return; 79 80 BMessage message; 81 message.AddBool(name, value); 82 tracker->SendNotices(what, &message); 83 } 84 85 86 #undef B_TRANSLATION_CONTEXT 87 #define B_TRANSLATION_CONTEXT "SettingsView" 88 89 90 // #pragma mark - SettingsView 91 92 93 SettingsView::SettingsView(const char* name) 94 : 95 BGroupView(name) 96 { 97 } 98 99 100 SettingsView::~SettingsView() 101 { 102 } 103 104 105 /*! 106 The inherited functions should set the default values 107 and update the UI gadgets. The latter can by done by 108 calling ShowCurrentSettings(). 109 */ 110 void 111 SettingsView::SetDefaults() 112 { 113 } 114 115 116 /*! 117 This function is used by the window to tell whether 118 it can ghost the defaults button or not. It doesn't 119 shows the default settings, this function should 120 return true. 121 */ 122 bool 123 SettingsView::IsDefaultable() const 124 { 125 return true; 126 } 127 128 129 /*! 130 The inherited functions should set the values that was 131 active when the settings window opened. It should also 132 update the UI widgets accordingly, preferrable by calling 133 ShowCurrentSettings(). 134 */ 135 void 136 SettingsView::Revert() 137 { 138 } 139 140 141 /*! 142 This function is called when the window is shown to let 143 the settings views record the state to revert to. 144 */ 145 void 146 SettingsView::RecordRevertSettings() 147 { 148 } 149 150 151 /*! 152 This function is used by the window to tell the view 153 to display the current settings in the tracker. 154 */ 155 void 156 SettingsView::ShowCurrentSettings() 157 { 158 } 159 160 161 /*! 162 This function is used by the window to tell whether 163 it can ghost the revert button or not. It it shows the 164 reverted settings, this function should return true. 165 */ 166 bool 167 SettingsView::IsRevertable() const 168 { 169 return true; 170 } 171 172 173 // #pragma mark - DesktopSettingsView 174 175 176 DesktopSettingsView::DesktopSettingsView() 177 : 178 SettingsView("DesktopSettingsView"), 179 fShowDisksIconRadioButton(NULL), 180 fMountVolumesOntoDesktopRadioButton(NULL), 181 fMountSharedVolumesOntoDesktopCheckBox(NULL), 182 fShowDisksIcon(false), 183 fMountVolumesOntoDesktop(false), 184 fMountSharedVolumesOntoDesktop(false), 185 fIntegrateNonBootBeOSDesktops(false), 186 fEjectWhenUnmounting(false) 187 { 188 fShowDisksIconRadioButton = new BRadioButton("", 189 B_TRANSLATE("Show Disks icon"), 190 new BMessage(kShowDisksIconChanged)); 191 192 fMountVolumesOntoDesktopRadioButton = new BRadioButton("", 193 B_TRANSLATE("Show volumes on Desktop"), 194 new BMessage(kVolumesOnDesktopChanged)); 195 196 fMountSharedVolumesOntoDesktopCheckBox = new BCheckBox("", 197 B_TRANSLATE("Show shared volumes on Desktop"), 198 new BMessage(kVolumesOnDesktopChanged)); 199 200 const float spacing = be_control_look->DefaultItemSpacing(); 201 202 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 203 .Add(fShowDisksIconRadioButton) 204 .Add(fMountVolumesOntoDesktopRadioButton) 205 .AddGroup(B_VERTICAL, 0) 206 .Add(fMountSharedVolumesOntoDesktopCheckBox) 207 .SetInsets(spacing * 2, 0, 0, 0) 208 .End() 209 .AddGlue() 210 .SetInsets(spacing); 211 } 212 213 214 void 215 DesktopSettingsView::AttachedToWindow() 216 { 217 fShowDisksIconRadioButton->SetTarget(this); 218 fMountVolumesOntoDesktopRadioButton->SetTarget(this); 219 fMountSharedVolumesOntoDesktopCheckBox->SetTarget(this); 220 } 221 222 223 void 224 DesktopSettingsView::MessageReceived(BMessage* message) 225 { 226 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 227 if (tracker == NULL) 228 return; 229 230 TrackerSettings settings; 231 232 switch (message->what) { 233 case kShowDisksIconChanged: 234 { 235 // Turn on and off related settings: 236 fMountVolumesOntoDesktopRadioButton->SetValue( 237 !fShowDisksIconRadioButton->Value() == 1); 238 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( 239 fMountVolumesOntoDesktopRadioButton->Value() == 1); 240 241 // Set the new settings in the tracker: 242 settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1); 243 settings.SetMountVolumesOntoDesktop( 244 fMountVolumesOntoDesktopRadioButton->Value() == 1); 245 settings.SetMountSharedVolumesOntoDesktop( 246 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 247 248 // Construct the notification message: 249 BMessage notificationMessage; 250 notificationMessage.AddBool("ShowDisksIcon", 251 fShowDisksIconRadioButton->Value() == 1); 252 notificationMessage.AddBool("MountVolumesOntoDesktop", 253 fMountVolumesOntoDesktopRadioButton->Value() == 1); 254 notificationMessage.AddBool("MountSharedVolumesOntoDesktop", 255 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 256 257 // Send the notification message: 258 tracker->SendNotices(kVolumesOnDesktopChanged, 259 ¬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,\ 292 ¬ificationMessage); 293 294 // Tell the settings window the contents have changed: 295 Window()->PostMessage(kSettingsContentsModified); 296 break; 297 } 298 299 default: 300 _inherited::MessageReceived(message); 301 break; 302 } 303 } 304 305 306 void 307 DesktopSettingsView::SetDefaults() 308 { 309 // ToDo: Avoid the duplication of the default values. 310 TrackerSettings settings; 311 312 settings.SetShowDisksIcon(false); 313 settings.SetMountVolumesOntoDesktop(true); 314 settings.SetMountSharedVolumesOntoDesktop(true); 315 settings.SetEjectWhenUnmounting(true); 316 317 ShowCurrentSettings(); 318 _SendNotices(); 319 } 320 321 322 bool 323 DesktopSettingsView::IsDefaultable() const 324 { 325 TrackerSettings settings; 326 327 return settings.ShowDisksIcon() != false 328 || settings.MountVolumesOntoDesktop() != true 329 || settings.MountSharedVolumesOntoDesktop() != true 330 || settings.EjectWhenUnmounting() != true; 331 } 332 333 334 void 335 DesktopSettingsView::Revert() 336 { 337 TrackerSettings settings; 338 339 settings.SetShowDisksIcon(fShowDisksIcon); 340 settings.SetMountVolumesOntoDesktop(fMountVolumesOntoDesktop); 341 settings.SetMountSharedVolumesOntoDesktop(fMountSharedVolumesOntoDesktop); 342 settings.SetEjectWhenUnmounting(fEjectWhenUnmounting); 343 344 ShowCurrentSettings(); 345 _SendNotices(); 346 } 347 348 349 void 350 DesktopSettingsView::_SendNotices() 351 { 352 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 353 if (tracker == NULL) 354 return; 355 356 // Construct the notification message: 357 BMessage notificationMessage; 358 notificationMessage.AddBool("ShowDisksIcon", 359 fShowDisksIconRadioButton->Value() == 1); 360 notificationMessage.AddBool("MountVolumesOntoDesktop", 361 fMountVolumesOntoDesktopRadioButton->Value() == 1); 362 notificationMessage.AddBool("MountSharedVolumesOntoDesktop", 363 fMountSharedVolumesOntoDesktopCheckBox->Value() == 1); 364 365 // Send notices to the tracker about the change: 366 tracker->SendNotices(kVolumesOnDesktopChanged, ¬ificationMessage); 367 tracker->SendNotices(kDesktopIntegrationChanged, ¬ificationMessage); 368 } 369 370 371 void 372 DesktopSettingsView::ShowCurrentSettings() 373 { 374 TrackerSettings settings; 375 376 fShowDisksIconRadioButton->SetValue(settings.ShowDisksIcon()); 377 fMountVolumesOntoDesktopRadioButton->SetValue( 378 settings.MountVolumesOntoDesktop()); 379 380 fMountSharedVolumesOntoDesktopCheckBox->SetValue( 381 settings.MountSharedVolumesOntoDesktop()); 382 fMountSharedVolumesOntoDesktopCheckBox->SetEnabled( 383 settings.MountVolumesOntoDesktop()); 384 } 385 386 387 void 388 DesktopSettingsView::RecordRevertSettings() 389 { 390 TrackerSettings settings; 391 392 fShowDisksIcon = settings.ShowDisksIcon(); 393 fMountVolumesOntoDesktop = settings.MountVolumesOntoDesktop(); 394 fMountSharedVolumesOntoDesktop = settings.MountSharedVolumesOntoDesktop(); 395 fEjectWhenUnmounting = settings.EjectWhenUnmounting(); 396 } 397 398 399 bool 400 DesktopSettingsView::IsRevertable() const 401 { 402 return fShowDisksIcon != (fShowDisksIconRadioButton->Value() > 0) 403 || fMountVolumesOntoDesktop != 404 (fMountVolumesOntoDesktopRadioButton->Value() > 0) 405 || fMountSharedVolumesOntoDesktop != 406 (fMountSharedVolumesOntoDesktopCheckBox->Value() > 0); 407 } 408 409 410 // #pragma mark - WindowsSettingsView 411 412 413 WindowsSettingsView::WindowsSettingsView() 414 : 415 SettingsView("WindowsSettingsView"), 416 fShowFullPathInTitleBarCheckBox(NULL), 417 fSingleWindowBrowseCheckBox(NULL), 418 fShowNavigatorCheckBox(NULL), 419 fOutlineSelectionCheckBox(NULL), 420 fSortFolderNamesFirstCheckBox(NULL), 421 fTypeAheadFilteringCheckBox(NULL), 422 fShowFullPathInTitleBar(false), 423 fSingleWindowBrowse(false), 424 fShowNavigator(false), 425 fTransparentSelection(false), 426 fSortFolderNamesFirst(false), 427 fTypeAheadFiltering(false) 428 { 429 fShowFullPathInTitleBarCheckBox = new BCheckBox("", 430 B_TRANSLATE("Show folder location in title tab"), 431 new BMessage(kWindowsShowFullPathChanged)); 432 433 fSingleWindowBrowseCheckBox = new BCheckBox("", 434 B_TRANSLATE("Single window navigation"), 435 new BMessage(kSingleWindowBrowseChanged)); 436 437 fShowNavigatorCheckBox = new BCheckBox("", 438 B_TRANSLATE("Show navigator"), 439 new BMessage(kShowNavigatorChanged)); 440 441 fOutlineSelectionCheckBox = new BCheckBox("", 442 B_TRANSLATE("Outline selection rectangle only"), 443 new BMessage(kTransparentSelectionChanged)); 444 445 fSortFolderNamesFirstCheckBox = new BCheckBox("", 446 B_TRANSLATE("List folders first"), 447 new BMessage(kSortFolderNamesFirstChanged)); 448 449 fTypeAheadFilteringCheckBox = new BCheckBox("", 450 B_TRANSLATE("Enable type-ahead filtering"), 451 new BMessage(kTypeAheadFilteringChanged)); 452 453 const float spacing = be_control_look->DefaultItemSpacing(); 454 455 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 456 .AddGroup(B_VERTICAL, 0) 457 .Add(fShowFullPathInTitleBarCheckBox) 458 .Add(fSingleWindowBrowseCheckBox) 459 .End() 460 .AddGroup(B_VERTICAL) 461 .Add(fShowNavigatorCheckBox) 462 .SetInsets(spacing * 2, 0, 0, 0) 463 .End() 464 .AddGroup(B_VERTICAL, 0) 465 .Add(fOutlineSelectionCheckBox) 466 .Add(fSortFolderNamesFirstCheckBox) 467 .Add(fTypeAheadFilteringCheckBox) 468 .End() 469 .AddGlue() 470 .SetInsets(spacing); 471 } 472 473 474 void 475 WindowsSettingsView::AttachedToWindow() 476 { 477 fSingleWindowBrowseCheckBox->SetTarget(this); 478 fShowNavigatorCheckBox->SetTarget(this); 479 fShowFullPathInTitleBarCheckBox->SetTarget(this); 480 fOutlineSelectionCheckBox->SetTarget(this); 481 fSortFolderNamesFirstCheckBox->SetTarget(this); 482 fTypeAheadFilteringCheckBox->SetTarget(this); 483 } 484 485 486 void 487 WindowsSettingsView::MessageReceived(BMessage* message) 488 { 489 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 490 if (tracker == NULL) 491 return; 492 493 TrackerSettings settings; 494 495 switch (message->what) { 496 case kWindowsShowFullPathChanged: 497 settings.SetShowFullPathInTitleBar( 498 fShowFullPathInTitleBarCheckBox->Value() == 1); 499 tracker->SendNotices(kWindowsShowFullPathChanged); 500 Window()->PostMessage(kSettingsContentsModified); 501 break; 502 503 case kSingleWindowBrowseChanged: 504 settings.SetSingleWindowBrowse( 505 fSingleWindowBrowseCheckBox->Value() == 1); 506 if (fSingleWindowBrowseCheckBox->Value() == 0) { 507 fShowNavigatorCheckBox->SetEnabled(false); 508 settings.SetShowNavigator(0); 509 } else { 510 fShowNavigatorCheckBox->SetEnabled(true); 511 settings.SetShowNavigator( 512 fShowNavigatorCheckBox->Value() != 0); 513 } 514 tracker->SendNotices(kShowNavigatorChanged); 515 tracker->SendNotices(kSingleWindowBrowseChanged); 516 Window()->PostMessage(kSettingsContentsModified); 517 break; 518 519 case kShowNavigatorChanged: 520 settings.SetShowNavigator(fShowNavigatorCheckBox->Value() == 1); 521 tracker->SendNotices(kShowNavigatorChanged); 522 Window()->PostMessage(kSettingsContentsModified); 523 break; 524 525 case kTransparentSelectionChanged: 526 { 527 settings.SetTransparentSelection( 528 fOutlineSelectionCheckBox->Value() == B_CONTROL_OFF); 529 530 // Make the notification message and send it to the tracker: 531 send_bool_notices(kTransparentSelectionChanged, 532 "TransparentSelection", settings.TransparentSelection()); 533 534 Window()->PostMessage(kSettingsContentsModified); 535 break; 536 } 537 538 case kSortFolderNamesFirstChanged: 539 { 540 settings.SetSortFolderNamesFirst( 541 fSortFolderNamesFirstCheckBox->Value() == 1); 542 543 // Make the notification message and send it to the tracker: 544 send_bool_notices(kSortFolderNamesFirstChanged, 545 "SortFolderNamesFirst", 546 fSortFolderNamesFirstCheckBox->Value() == 1); 547 548 Window()->PostMessage(kSettingsContentsModified); 549 break; 550 } 551 552 case kTypeAheadFilteringChanged: 553 { 554 settings.SetTypeAheadFiltering( 555 fTypeAheadFilteringCheckBox->Value() == 1); 556 send_bool_notices(kTypeAheadFilteringChanged, 557 "TypeAheadFiltering", 558 fTypeAheadFilteringCheckBox->Value() == 1); 559 Window()->PostMessage(kSettingsContentsModified); 560 break; 561 } 562 563 default: 564 _inherited::MessageReceived(message); 565 break; 566 } 567 } 568 569 570 void 571 WindowsSettingsView::SetDefaults() 572 { 573 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 574 if (tracker == NULL) 575 return; 576 577 TrackerSettings settings; 578 579 if (settings.ShowFullPathInTitleBar()) { 580 settings.SetShowFullPathInTitleBar(false); 581 tracker->SendNotices(kWindowsShowFullPathChanged); 582 } 583 584 if (settings.SingleWindowBrowse()) { 585 settings.SetSingleWindowBrowse(false); 586 tracker->SendNotices(kSingleWindowBrowseChanged); 587 } 588 589 if (settings.ShowNavigator()) { 590 settings.SetShowNavigator(false); 591 tracker->SendNotices(kShowNavigatorChanged); 592 } 593 594 if (!settings.TransparentSelection()) { 595 settings.SetTransparentSelection(true); 596 send_bool_notices(kTransparentSelectionChanged, 597 "TransparentSelection", true); 598 } 599 600 if (!settings.SortFolderNamesFirst()) { 601 settings.SetSortFolderNamesFirst(true); 602 send_bool_notices(kSortFolderNamesFirstChanged, 603 "SortFolderNamesFirst", true); 604 } 605 606 if (settings.TypeAheadFiltering()) { 607 settings.SetTypeAheadFiltering(false); 608 send_bool_notices(kTypeAheadFilteringChanged, 609 "TypeAheadFiltering", true); 610 } 611 612 ShowCurrentSettings(); 613 } 614 615 616 bool 617 WindowsSettingsView::IsDefaultable() const 618 { 619 TrackerSettings settings; 620 621 return settings.ShowFullPathInTitleBar() != false 622 || settings.SingleWindowBrowse() != false 623 || settings.ShowNavigator() != false 624 || settings.TransparentSelection() != true 625 || settings.SortFolderNamesFirst() != true 626 || settings.TypeAheadFiltering() != false; 627 } 628 629 630 void 631 WindowsSettingsView::Revert() 632 { 633 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 634 if (tracker == NULL) 635 return; 636 637 TrackerSettings settings; 638 639 if (settings.ShowFullPathInTitleBar() != fShowFullPathInTitleBar) { 640 settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBar); 641 tracker->SendNotices(kWindowsShowFullPathChanged); 642 } 643 644 if (settings.SingleWindowBrowse() != fSingleWindowBrowse) { 645 settings.SetSingleWindowBrowse(fSingleWindowBrowse); 646 tracker->SendNotices(kSingleWindowBrowseChanged); 647 } 648 649 if (settings.ShowNavigator() != fShowNavigator) { 650 settings.SetShowNavigator(fShowNavigator); 651 tracker->SendNotices(kShowNavigatorChanged); 652 } 653 654 if (settings.TransparentSelection() != fTransparentSelection) { 655 settings.SetTransparentSelection(fTransparentSelection); 656 send_bool_notices(kTransparentSelectionChanged, 657 "TransparentSelection", fTransparentSelection); 658 } 659 660 if (settings.SortFolderNamesFirst() != fSortFolderNamesFirst) { 661 settings.SetSortFolderNamesFirst(fSortFolderNamesFirst); 662 send_bool_notices(kSortFolderNamesFirstChanged, 663 "SortFolderNamesFirst", fSortFolderNamesFirst); 664 } 665 666 if (settings.TypeAheadFiltering() != fTypeAheadFiltering) { 667 settings.SetTypeAheadFiltering(fTypeAheadFiltering); 668 send_bool_notices(kTypeAheadFilteringChanged, 669 "TypeAheadFiltering", fTypeAheadFiltering); 670 } 671 672 ShowCurrentSettings(); 673 } 674 675 676 void 677 WindowsSettingsView::ShowCurrentSettings() 678 { 679 TrackerSettings settings; 680 681 fShowFullPathInTitleBarCheckBox->SetValue( 682 settings.ShowFullPathInTitleBar()); 683 fSingleWindowBrowseCheckBox->SetValue(settings.SingleWindowBrowse()); 684 fShowNavigatorCheckBox->SetEnabled(settings.SingleWindowBrowse()); 685 fShowNavigatorCheckBox->SetValue(settings.ShowNavigator()); 686 fOutlineSelectionCheckBox->SetValue(settings.TransparentSelection() 687 ? B_CONTROL_OFF : B_CONTROL_ON); 688 fSortFolderNamesFirstCheckBox->SetValue(settings.SortFolderNamesFirst()); 689 fTypeAheadFilteringCheckBox->SetValue(settings.TypeAheadFiltering()); 690 } 691 692 693 void 694 WindowsSettingsView::RecordRevertSettings() 695 { 696 TrackerSettings settings; 697 698 fShowFullPathInTitleBar = settings.ShowFullPathInTitleBar(); 699 fSingleWindowBrowse = settings.SingleWindowBrowse(); 700 fShowNavigator = settings.ShowNavigator(); 701 fTransparentSelection = settings.TransparentSelection(); 702 fSortFolderNamesFirst = settings.SortFolderNamesFirst(); 703 fTypeAheadFiltering = settings.TypeAheadFiltering(); 704 } 705 706 707 bool 708 WindowsSettingsView::IsRevertable() const 709 { 710 TrackerSettings settings; 711 712 return fShowFullPathInTitleBar != settings.ShowFullPathInTitleBar() 713 || fSingleWindowBrowse != settings.SingleWindowBrowse() 714 || fShowNavigator != settings.ShowNavigator() 715 || fTransparentSelection != settings.TransparentSelection() 716 || fSortFolderNamesFirst != settings.SortFolderNamesFirst() 717 || fTypeAheadFiltering != settings.TypeAheadFiltering(); 718 } 719 720 721 // #pragma mark - SpaceBarSettingsView 722 723 724 SpaceBarSettingsView::SpaceBarSettingsView() 725 : 726 SettingsView("SpaceBarSettingsView") 727 { 728 fSpaceBarShowCheckBox = new BCheckBox("", 729 B_TRANSLATE("Show space bars on volumes"), 730 new BMessage(kUpdateVolumeSpaceBar)); 731 732 BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING); 733 menu->SetFont(be_plain_font); 734 735 BMenuItem* item; 736 menu->AddItem(item = new BMenuItem( 737 B_TRANSLATE("Used space color"), 738 new BMessage(kSpaceBarSwitchColor))); 739 item->SetMarked(true); 740 fCurrentColor = 0; 741 menu->AddItem(new BMenuItem( 742 B_TRANSLATE("Free space color"), 743 new BMessage(kSpaceBarSwitchColor))); 744 menu->AddItem(new BMenuItem( 745 B_TRANSLATE("Warning space color"), 746 new BMessage(kSpaceBarSwitchColor))); 747 748 fColorPicker = new BMenuField("menu", NULL, menu); 749 750 fColorControl = new BColorControl(BPoint(0, 0), 751 B_CELLS_16x16, 1, "SpaceColorControl", 752 new BMessage(kSpaceBarColorChanged)); 753 fColorControl->SetValue(TrackerSettings().UsedSpaceColor()); 754 755 BBox* box = new BBox("box"); 756 box->SetLabel(fColorPicker); 757 box->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL) 758 .Add(fColorControl) 759 .SetInsets(B_USE_DEFAULT_SPACING) 760 .View()); 761 762 BLayoutBuilder::Group<>(this, B_VERTICAL) 763 .Add(fSpaceBarShowCheckBox) 764 .Add(box) 765 .AddGlue() 766 .SetInsets(B_USE_DEFAULT_SPACING); 767 } 768 769 770 SpaceBarSettingsView::~SpaceBarSettingsView() 771 { 772 } 773 774 775 void 776 SpaceBarSettingsView::AttachedToWindow() 777 { 778 fSpaceBarShowCheckBox->SetTarget(this); 779 fColorControl->SetTarget(this); 780 fColorPicker->Menu()->SetTargetForItems(this); 781 } 782 783 784 void 785 SpaceBarSettingsView::MessageReceived(BMessage* message) 786 { 787 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 788 if (tracker == NULL) 789 return; 790 791 TrackerSettings settings; 792 793 switch (message->what) { 794 case kUpdateVolumeSpaceBar: 795 { 796 settings.SetShowVolumeSpaceBar( 797 fSpaceBarShowCheckBox->Value() == 1); 798 Window()->PostMessage(kSettingsContentsModified); 799 tracker->PostMessage(kShowVolumeSpaceBar); 800 break; 801 } 802 803 case kSpaceBarSwitchColor: 804 { 805 fCurrentColor = message->FindInt32("index"); 806 switch (fCurrentColor) { 807 case 0: 808 fColorControl->SetValue(settings.UsedSpaceColor()); 809 break; 810 811 case 1: 812 fColorControl->SetValue(settings.FreeSpaceColor()); 813 break; 814 815 case 2: 816 fColorControl->SetValue(settings.WarningSpaceColor()); 817 break; 818 } 819 break; 820 } 821 822 case kSpaceBarColorChanged: 823 { 824 rgb_color color = fColorControl->ValueAsColor(); 825 color.alpha = kSpaceBarAlpha; 826 // alpha is ignored by BColorControl but is checked 827 // in equalities 828 829 switch (fCurrentColor) { 830 case 0: 831 settings.SetUsedSpaceColor(color); 832 break; 833 834 case 1: 835 settings.SetFreeSpaceColor(color); 836 break; 837 838 case 2: 839 settings.SetWarningSpaceColor(color); 840 break; 841 } 842 843 BWindow* window = Window(); 844 if (window != NULL) 845 window->PostMessage(kSettingsContentsModified); 846 847 tracker->PostMessage(kSpaceBarColorChanged); 848 break; 849 } 850 851 default: 852 _inherited::MessageReceived(message); 853 break; 854 } 855 } 856 857 858 void 859 SpaceBarSettingsView::SetDefaults() 860 { 861 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 862 if (tracker == NULL) 863 return; 864 865 TrackerSettings settings; 866 867 if (!settings.ShowVolumeSpaceBar()) { 868 settings.SetShowVolumeSpaceBar(true); 869 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", true); 870 } 871 872 if (settings.UsedSpaceColor() != kDefaultUsedSpaceColor 873 || settings.FreeSpaceColor() != kDefaultFreeSpaceColor 874 || settings.WarningSpaceColor() != kDefaultWarningSpaceColor) { 875 settings.SetUsedSpaceColor(kDefaultUsedSpaceColor); 876 settings.SetFreeSpaceColor(kDefaultFreeSpaceColor); 877 settings.SetWarningSpaceColor(kDefaultWarningSpaceColor); 878 tracker->SendNotices(kSpaceBarColorChanged); 879 } 880 881 ShowCurrentSettings(); 882 } 883 884 885 bool 886 SpaceBarSettingsView::IsDefaultable() const 887 { 888 TrackerSettings settings; 889 890 return settings.ShowVolumeSpaceBar() != true 891 || settings.UsedSpaceColor() != kDefaultUsedSpaceColor 892 || settings.FreeSpaceColor() != kDefaultFreeSpaceColor 893 || settings.WarningSpaceColor() != kDefaultWarningSpaceColor; 894 } 895 896 897 void 898 SpaceBarSettingsView::Revert() 899 { 900 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 901 if (tracker == NULL) 902 return; 903 904 TrackerSettings settings; 905 906 if (settings.ShowVolumeSpaceBar() != fSpaceBarShow) { 907 settings.SetShowVolumeSpaceBar(fSpaceBarShow); 908 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", 909 fSpaceBarShow); 910 } 911 912 if (settings.UsedSpaceColor() != fUsedSpaceColor 913 || settings.FreeSpaceColor() != fFreeSpaceColor 914 || settings.WarningSpaceColor() != fWarningSpaceColor) { 915 settings.SetUsedSpaceColor(fUsedSpaceColor); 916 settings.SetFreeSpaceColor(fFreeSpaceColor); 917 settings.SetWarningSpaceColor(fWarningSpaceColor); 918 tracker->SendNotices(kSpaceBarColorChanged); 919 } 920 921 ShowCurrentSettings(); 922 } 923 924 925 void 926 SpaceBarSettingsView::ShowCurrentSettings() 927 { 928 TrackerSettings settings; 929 930 fSpaceBarShowCheckBox->SetValue(settings.ShowVolumeSpaceBar()); 931 932 switch (fCurrentColor) { 933 case 0: 934 fColorControl->SetValue(settings.UsedSpaceColor()); 935 break; 936 case 1: 937 fColorControl->SetValue(settings.FreeSpaceColor()); 938 break; 939 case 2: 940 fColorControl->SetValue(settings.WarningSpaceColor()); 941 break; 942 } 943 } 944 945 946 void 947 SpaceBarSettingsView::RecordRevertSettings() 948 { 949 TrackerSettings settings; 950 951 fSpaceBarShow = settings.ShowVolumeSpaceBar(); 952 fUsedSpaceColor = settings.UsedSpaceColor(); 953 fFreeSpaceColor = settings.FreeSpaceColor(); 954 fWarningSpaceColor = settings.WarningSpaceColor(); 955 } 956 957 958 bool 959 SpaceBarSettingsView::IsRevertable() const 960 { 961 TrackerSettings settings; 962 963 return fSpaceBarShow != settings.ShowVolumeSpaceBar() 964 || fUsedSpaceColor != settings.UsedSpaceColor() 965 || fFreeSpaceColor != settings.FreeSpaceColor() 966 || fWarningSpaceColor != settings.WarningSpaceColor(); 967 } 968