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 fHideDotFilesCheckBox(NULL), 422 fTypeAheadFilteringCheckBox(NULL), 423 fGenerateImageThumbnailsCheckBox(NULL), 424 fShowFullPathInTitleBar(false), 425 fSingleWindowBrowse(false), 426 fShowNavigator(false), 427 fTransparentSelection(false), 428 fSortFolderNamesFirst(false), 429 fHideDotFiles(false), 430 fTypeAheadFiltering(false) 431 { 432 fShowFullPathInTitleBarCheckBox = new BCheckBox("", 433 B_TRANSLATE("Show folder location in title tab"), 434 new BMessage(kWindowsShowFullPathChanged)); 435 436 fSingleWindowBrowseCheckBox = new BCheckBox("", 437 B_TRANSLATE("Single window navigation"), 438 new BMessage(kSingleWindowBrowseChanged)); 439 440 fShowNavigatorCheckBox = new BCheckBox("", 441 B_TRANSLATE("Show navigator"), 442 new BMessage(kShowNavigatorChanged)); 443 444 fOutlineSelectionCheckBox = new BCheckBox("", 445 B_TRANSLATE("Outline selection rectangle only"), 446 new BMessage(kTransparentSelectionChanged)); 447 448 fSortFolderNamesFirstCheckBox = new BCheckBox("", 449 B_TRANSLATE("List folders first"), 450 new BMessage(kSortFolderNamesFirstChanged)); 451 452 fHideDotFilesCheckBox = new BCheckBox("", 453 B_TRANSLATE("Hide dotfiles"), 454 new BMessage(kHideDotFilesChanged)); 455 456 fTypeAheadFilteringCheckBox = new BCheckBox("", 457 B_TRANSLATE("Enable type-ahead filtering"), 458 new BMessage(kTypeAheadFilteringChanged)); 459 460 fGenerateImageThumbnailsCheckBox = new BCheckBox("", 461 B_TRANSLATE("Generate image thumbnails"), 462 new BMessage(kGenerateImageThumbnailsChanged)); 463 464 const float spacing = be_control_look->DefaultItemSpacing(); 465 466 BLayoutBuilder::Group<>(this, B_VERTICAL, 0) 467 .AddGroup(B_VERTICAL, 0) 468 .Add(fShowFullPathInTitleBarCheckBox) 469 .Add(fSingleWindowBrowseCheckBox) 470 .End() 471 .AddGroup(B_VERTICAL) 472 .Add(fShowNavigatorCheckBox) 473 .SetInsets(spacing * 2, 0, 0, 0) 474 .End() 475 .AddGroup(B_VERTICAL, 0) 476 .Add(fOutlineSelectionCheckBox) 477 .Add(fSortFolderNamesFirstCheckBox) 478 .Add(fHideDotFilesCheckBox) 479 .Add(fTypeAheadFilteringCheckBox) 480 .Add(fGenerateImageThumbnailsCheckBox) 481 .End() 482 .AddGlue() 483 .SetInsets(spacing); 484 } 485 486 487 void 488 WindowsSettingsView::AttachedToWindow() 489 { 490 fSingleWindowBrowseCheckBox->SetTarget(this); 491 fShowNavigatorCheckBox->SetTarget(this); 492 fShowFullPathInTitleBarCheckBox->SetTarget(this); 493 fOutlineSelectionCheckBox->SetTarget(this); 494 fSortFolderNamesFirstCheckBox->SetTarget(this); 495 fHideDotFilesCheckBox->SetTarget(this); 496 fTypeAheadFilteringCheckBox->SetTarget(this); 497 fGenerateImageThumbnailsCheckBox->SetTarget(this); 498 } 499 500 501 void 502 WindowsSettingsView::MessageReceived(BMessage* message) 503 { 504 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 505 if (tracker == NULL) 506 return; 507 508 TrackerSettings settings; 509 510 switch (message->what) { 511 case kWindowsShowFullPathChanged: 512 settings.SetShowFullPathInTitleBar( 513 fShowFullPathInTitleBarCheckBox->Value() == 1); 514 tracker->SendNotices(kWindowsShowFullPathChanged); 515 Window()->PostMessage(kSettingsContentsModified); 516 break; 517 518 case kSingleWindowBrowseChanged: 519 settings.SetSingleWindowBrowse( 520 fSingleWindowBrowseCheckBox->Value() == 1); 521 if (fSingleWindowBrowseCheckBox->Value() == 0) { 522 fShowNavigatorCheckBox->SetEnabled(false); 523 settings.SetShowNavigator(0); 524 } else { 525 fShowNavigatorCheckBox->SetEnabled(true); 526 settings.SetShowNavigator( 527 fShowNavigatorCheckBox->Value() != 0); 528 } 529 tracker->SendNotices(kShowNavigatorChanged); 530 tracker->SendNotices(kSingleWindowBrowseChanged); 531 Window()->PostMessage(kSettingsContentsModified); 532 break; 533 534 case kShowNavigatorChanged: 535 settings.SetShowNavigator(fShowNavigatorCheckBox->Value() == 1); 536 tracker->SendNotices(kShowNavigatorChanged); 537 Window()->PostMessage(kSettingsContentsModified); 538 break; 539 540 case kTransparentSelectionChanged: 541 { 542 settings.SetTransparentSelection( 543 fOutlineSelectionCheckBox->Value() == B_CONTROL_OFF); 544 545 // Make the notification message and send it to the tracker: 546 send_bool_notices(kTransparentSelectionChanged, 547 "TransparentSelection", settings.TransparentSelection()); 548 549 Window()->PostMessage(kSettingsContentsModified); 550 break; 551 } 552 553 case kSortFolderNamesFirstChanged: 554 { 555 settings.SetSortFolderNamesFirst( 556 fSortFolderNamesFirstCheckBox->Value() == 1); 557 558 // Make the notification message and send it to the tracker: 559 send_bool_notices(kSortFolderNamesFirstChanged, 560 "SortFolderNamesFirst", 561 fSortFolderNamesFirstCheckBox->Value() == 1); 562 563 Window()->PostMessage(kSettingsContentsModified); 564 break; 565 } 566 567 case kHideDotFilesChanged: 568 { 569 settings.SetHideDotFiles( 570 fHideDotFilesCheckBox->Value() == 1); 571 572 // Make the notification message and send it to the tracker: 573 send_bool_notices(kHideDotFilesChanged, 574 "HideDotFiles", 575 fHideDotFilesCheckBox->Value() == 1); 576 577 Window()->PostMessage(kSettingsContentsModified); 578 break; 579 } 580 581 case kTypeAheadFilteringChanged: 582 { 583 settings.SetTypeAheadFiltering( 584 fTypeAheadFilteringCheckBox->Value() == 1); 585 send_bool_notices(kTypeAheadFilteringChanged, 586 "TypeAheadFiltering", 587 fTypeAheadFilteringCheckBox->Value() == 1); 588 Window()->PostMessage(kSettingsContentsModified); 589 break; 590 } 591 592 case kGenerateImageThumbnailsChanged: 593 { 594 settings.SetGenerateImageThumbnails( 595 fGenerateImageThumbnailsCheckBox->Value() == 1); 596 send_bool_notices(kGenerateImageThumbnailsChanged, 597 "GenerateImageThumbnails", 598 fGenerateImageThumbnailsCheckBox->Value() == 1); 599 Window()->PostMessage(kSettingsContentsModified); 600 break; 601 } 602 603 default: 604 _inherited::MessageReceived(message); 605 break; 606 } 607 } 608 609 610 void 611 WindowsSettingsView::SetDefaults() 612 { 613 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 614 if (tracker == NULL) 615 return; 616 617 TrackerSettings settings; 618 619 if (settings.ShowFullPathInTitleBar()) { 620 settings.SetShowFullPathInTitleBar(false); 621 tracker->SendNotices(kWindowsShowFullPathChanged); 622 } 623 624 if (settings.SingleWindowBrowse()) { 625 settings.SetSingleWindowBrowse(false); 626 tracker->SendNotices(kSingleWindowBrowseChanged); 627 } 628 629 if (settings.ShowNavigator()) { 630 settings.SetShowNavigator(false); 631 tracker->SendNotices(kShowNavigatorChanged); 632 } 633 634 if (!settings.TransparentSelection()) { 635 settings.SetTransparentSelection(true); 636 send_bool_notices(kTransparentSelectionChanged, 637 "TransparentSelection", true); 638 } 639 640 if (!settings.SortFolderNamesFirst()) { 641 settings.SetSortFolderNamesFirst(true); 642 send_bool_notices(kSortFolderNamesFirstChanged, 643 "SortFolderNamesFirst", true); 644 } 645 646 if (!settings.HideDotFiles()) { 647 settings.SetHideDotFiles(true); 648 send_bool_notices(kHideDotFilesChanged, 649 "HideDotFiles", true); 650 } 651 652 if (settings.TypeAheadFiltering()) { 653 settings.SetTypeAheadFiltering(false); 654 send_bool_notices(kTypeAheadFilteringChanged, 655 "TypeAheadFiltering", true); 656 } 657 658 if (settings.GenerateImageThumbnails()) { 659 settings.SetGenerateImageThumbnails(false); 660 send_bool_notices(kGenerateImageThumbnailsChanged, 661 "GenerateImageThumbnails", true); 662 } 663 664 ShowCurrentSettings(); 665 } 666 667 668 bool 669 WindowsSettingsView::IsDefaultable() const 670 { 671 TrackerSettings settings; 672 673 return settings.ShowFullPathInTitleBar() != false 674 || settings.SingleWindowBrowse() != false 675 || settings.ShowNavigator() != false 676 || settings.TransparentSelection() != true 677 || settings.SortFolderNamesFirst() != true 678 || settings.TypeAheadFiltering() != false 679 || settings.GenerateImageThumbnails() != false; 680 } 681 682 683 void 684 WindowsSettingsView::Revert() 685 { 686 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 687 if (tracker == NULL) 688 return; 689 690 TrackerSettings settings; 691 692 if (settings.ShowFullPathInTitleBar() != fShowFullPathInTitleBar) { 693 settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBar); 694 tracker->SendNotices(kWindowsShowFullPathChanged); 695 } 696 697 if (settings.SingleWindowBrowse() != fSingleWindowBrowse) { 698 settings.SetSingleWindowBrowse(fSingleWindowBrowse); 699 tracker->SendNotices(kSingleWindowBrowseChanged); 700 } 701 702 if (settings.ShowNavigator() != fShowNavigator) { 703 settings.SetShowNavigator(fShowNavigator); 704 tracker->SendNotices(kShowNavigatorChanged); 705 } 706 707 if (settings.TransparentSelection() != fTransparentSelection) { 708 settings.SetTransparentSelection(fTransparentSelection); 709 send_bool_notices(kTransparentSelectionChanged, 710 "TransparentSelection", fTransparentSelection); 711 } 712 713 if (settings.SortFolderNamesFirst() != fSortFolderNamesFirst) { 714 settings.SetSortFolderNamesFirst(fSortFolderNamesFirst); 715 send_bool_notices(kSortFolderNamesFirstChanged, 716 "SortFolderNamesFirst", fSortFolderNamesFirst); 717 } 718 719 if (settings.HideDotFiles() != fHideDotFiles) { 720 settings.SetSortFolderNamesFirst(fHideDotFiles); 721 send_bool_notices(kHideDotFilesChanged, 722 "HideDotFiles", fHideDotFiles); 723 } 724 725 if (settings.TypeAheadFiltering() != fTypeAheadFiltering) { 726 settings.SetTypeAheadFiltering(fTypeAheadFiltering); 727 send_bool_notices(kTypeAheadFilteringChanged, 728 "TypeAheadFiltering", fTypeAheadFiltering); 729 } 730 731 if (settings.GenerateImageThumbnails() != fGenerateImageThumbnails) { 732 settings.SetGenerateImageThumbnails(fGenerateImageThumbnails); 733 send_bool_notices(kGenerateImageThumbnailsChanged, 734 "GenerateImageThumbnails", fGenerateImageThumbnails); 735 } 736 737 ShowCurrentSettings(); 738 } 739 740 741 void 742 WindowsSettingsView::ShowCurrentSettings() 743 { 744 TrackerSettings settings; 745 746 fShowFullPathInTitleBarCheckBox->SetValue( 747 settings.ShowFullPathInTitleBar()); 748 fSingleWindowBrowseCheckBox->SetValue(settings.SingleWindowBrowse()); 749 fShowNavigatorCheckBox->SetEnabled(settings.SingleWindowBrowse()); 750 fShowNavigatorCheckBox->SetValue(settings.ShowNavigator()); 751 fOutlineSelectionCheckBox->SetValue(settings.TransparentSelection() 752 ? B_CONTROL_OFF : B_CONTROL_ON); 753 fSortFolderNamesFirstCheckBox->SetValue(settings.SortFolderNamesFirst()); 754 fHideDotFilesCheckBox->SetValue(settings.HideDotFiles()); 755 fTypeAheadFilteringCheckBox->SetValue(settings.TypeAheadFiltering()); 756 fGenerateImageThumbnailsCheckBox->SetValue( 757 settings.GenerateImageThumbnails()); 758 } 759 760 761 void 762 WindowsSettingsView::RecordRevertSettings() 763 { 764 TrackerSettings settings; 765 766 fShowFullPathInTitleBar = settings.ShowFullPathInTitleBar(); 767 fSingleWindowBrowse = settings.SingleWindowBrowse(); 768 fShowNavigator = settings.ShowNavigator(); 769 fTransparentSelection = settings.TransparentSelection(); 770 fSortFolderNamesFirst = settings.SortFolderNamesFirst(); 771 fHideDotFiles = settings.HideDotFiles(); 772 fTypeAheadFiltering = settings.TypeAheadFiltering(); 773 fGenerateImageThumbnails = settings.GenerateImageThumbnails(); 774 } 775 776 777 bool 778 WindowsSettingsView::IsRevertable() const 779 { 780 TrackerSettings settings; 781 782 return fShowFullPathInTitleBar != settings.ShowFullPathInTitleBar() 783 || fSingleWindowBrowse != settings.SingleWindowBrowse() 784 || fShowNavigator != settings.ShowNavigator() 785 || fTransparentSelection != settings.TransparentSelection() 786 || fSortFolderNamesFirst != settings.SortFolderNamesFirst() 787 || fHideDotFiles != settings.HideDotFiles() 788 || fTypeAheadFiltering != settings.TypeAheadFiltering() 789 || fGenerateImageThumbnails != settings.GenerateImageThumbnails(); 790 } 791 792 793 // #pragma mark - SpaceBarSettingsView 794 795 796 SpaceBarSettingsView::SpaceBarSettingsView() 797 : 798 SettingsView("SpaceBarSettingsView") 799 { 800 fSpaceBarShowCheckBox = new BCheckBox("", 801 B_TRANSLATE("Show space bars on volumes"), 802 new BMessage(kUpdateVolumeSpaceBar)); 803 804 BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING); 805 menu->SetFont(be_plain_font); 806 807 BMenuItem* item; 808 menu->AddItem(item = new BMenuItem( 809 B_TRANSLATE("Used space color"), 810 new BMessage(kSpaceBarSwitchColor))); 811 item->SetMarked(true); 812 fCurrentColor = 0; 813 menu->AddItem(new BMenuItem( 814 B_TRANSLATE("Free space color"), 815 new BMessage(kSpaceBarSwitchColor))); 816 menu->AddItem(new BMenuItem( 817 B_TRANSLATE("Warning space color"), 818 new BMessage(kSpaceBarSwitchColor))); 819 820 fColorPicker = new BMenuField("menu", NULL, menu); 821 822 fColorControl = new BColorControl(BPoint(0, 0), 823 B_CELLS_16x16, 1, "SpaceColorControl", 824 new BMessage(kSpaceBarColorChanged)); 825 fColorControl->SetValue(TrackerSettings().UsedSpaceColor()); 826 827 BBox* box = new BBox("box"); 828 box->SetLabel(fColorPicker); 829 box->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL) 830 .Add(fColorControl) 831 .SetInsets(B_USE_DEFAULT_SPACING) 832 .View()); 833 834 BLayoutBuilder::Group<>(this, B_VERTICAL) 835 .Add(fSpaceBarShowCheckBox) 836 .Add(box) 837 .AddGlue() 838 .SetInsets(B_USE_DEFAULT_SPACING); 839 } 840 841 842 SpaceBarSettingsView::~SpaceBarSettingsView() 843 { 844 } 845 846 847 void 848 SpaceBarSettingsView::AttachedToWindow() 849 { 850 fSpaceBarShowCheckBox->SetTarget(this); 851 fColorControl->SetTarget(this); 852 fColorPicker->Menu()->SetTargetForItems(this); 853 } 854 855 856 void 857 SpaceBarSettingsView::MessageReceived(BMessage* message) 858 { 859 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 860 if (tracker == NULL) 861 return; 862 863 TrackerSettings settings; 864 865 switch (message->what) { 866 case kUpdateVolumeSpaceBar: 867 { 868 settings.SetShowVolumeSpaceBar( 869 fSpaceBarShowCheckBox->Value() == 1); 870 Window()->PostMessage(kSettingsContentsModified); 871 tracker->PostMessage(kShowVolumeSpaceBar); 872 break; 873 } 874 875 case kSpaceBarSwitchColor: 876 { 877 fCurrentColor = message->FindInt32("index"); 878 switch (fCurrentColor) { 879 case 0: 880 fColorControl->SetValue(settings.UsedSpaceColor()); 881 break; 882 883 case 1: 884 fColorControl->SetValue(settings.FreeSpaceColor()); 885 break; 886 887 case 2: 888 fColorControl->SetValue(settings.WarningSpaceColor()); 889 break; 890 } 891 break; 892 } 893 894 case kSpaceBarColorChanged: 895 { 896 rgb_color color = fColorControl->ValueAsColor(); 897 color.alpha = kSpaceBarAlpha; 898 // alpha is ignored by BColorControl but is checked 899 // in equalities 900 901 switch (fCurrentColor) { 902 case 0: 903 settings.SetUsedSpaceColor(color); 904 break; 905 906 case 1: 907 settings.SetFreeSpaceColor(color); 908 break; 909 910 case 2: 911 settings.SetWarningSpaceColor(color); 912 break; 913 } 914 915 BWindow* window = Window(); 916 if (window != NULL) 917 window->PostMessage(kSettingsContentsModified); 918 919 tracker->PostMessage(kSpaceBarColorChanged); 920 break; 921 } 922 923 default: 924 _inherited::MessageReceived(message); 925 break; 926 } 927 } 928 929 930 void 931 SpaceBarSettingsView::SetDefaults() 932 { 933 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 934 if (tracker == NULL) 935 return; 936 937 TrackerSettings settings; 938 939 if (!settings.ShowVolumeSpaceBar()) { 940 settings.SetShowVolumeSpaceBar(true); 941 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", true); 942 } 943 944 if (settings.UsedSpaceColor() != kDefaultUsedSpaceColor 945 || settings.FreeSpaceColor() != kDefaultFreeSpaceColor 946 || settings.WarningSpaceColor() != kDefaultWarningSpaceColor) { 947 settings.SetUsedSpaceColor(kDefaultUsedSpaceColor); 948 settings.SetFreeSpaceColor(kDefaultFreeSpaceColor); 949 settings.SetWarningSpaceColor(kDefaultWarningSpaceColor); 950 tracker->SendNotices(kSpaceBarColorChanged); 951 } 952 953 ShowCurrentSettings(); 954 } 955 956 957 bool 958 SpaceBarSettingsView::IsDefaultable() const 959 { 960 TrackerSettings settings; 961 962 return settings.ShowVolumeSpaceBar() != true 963 || settings.UsedSpaceColor() != kDefaultUsedSpaceColor 964 || settings.FreeSpaceColor() != kDefaultFreeSpaceColor 965 || settings.WarningSpaceColor() != kDefaultWarningSpaceColor; 966 } 967 968 969 void 970 SpaceBarSettingsView::Revert() 971 { 972 TTracker* tracker = dynamic_cast<TTracker*>(be_app); 973 if (tracker == NULL) 974 return; 975 976 TrackerSettings settings; 977 978 if (settings.ShowVolumeSpaceBar() != fSpaceBarShow) { 979 settings.SetShowVolumeSpaceBar(fSpaceBarShow); 980 send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", 981 fSpaceBarShow); 982 } 983 984 if (settings.UsedSpaceColor() != fUsedSpaceColor 985 || settings.FreeSpaceColor() != fFreeSpaceColor 986 || settings.WarningSpaceColor() != fWarningSpaceColor) { 987 settings.SetUsedSpaceColor(fUsedSpaceColor); 988 settings.SetFreeSpaceColor(fFreeSpaceColor); 989 settings.SetWarningSpaceColor(fWarningSpaceColor); 990 tracker->SendNotices(kSpaceBarColorChanged); 991 } 992 993 ShowCurrentSettings(); 994 } 995 996 997 void 998 SpaceBarSettingsView::ShowCurrentSettings() 999 { 1000 TrackerSettings settings; 1001 1002 fSpaceBarShowCheckBox->SetValue(settings.ShowVolumeSpaceBar()); 1003 1004 switch (fCurrentColor) { 1005 case 0: 1006 fColorControl->SetValue(settings.UsedSpaceColor()); 1007 break; 1008 case 1: 1009 fColorControl->SetValue(settings.FreeSpaceColor()); 1010 break; 1011 case 2: 1012 fColorControl->SetValue(settings.WarningSpaceColor()); 1013 break; 1014 } 1015 } 1016 1017 1018 void 1019 SpaceBarSettingsView::RecordRevertSettings() 1020 { 1021 TrackerSettings settings; 1022 1023 fSpaceBarShow = settings.ShowVolumeSpaceBar(); 1024 fUsedSpaceColor = settings.UsedSpaceColor(); 1025 fFreeSpaceColor = settings.FreeSpaceColor(); 1026 fWarningSpaceColor = settings.WarningSpaceColor(); 1027 } 1028 1029 1030 bool 1031 SpaceBarSettingsView::IsRevertable() const 1032 { 1033 TrackerSettings settings; 1034 1035 return fSpaceBarShow != settings.ShowVolumeSpaceBar() 1036 || fUsedSpaceColor != settings.UsedSpaceColor() 1037 || fFreeSpaceColor != settings.FreeSpaceColor() 1038 || fWarningSpaceColor != settings.WarningSpaceColor(); 1039 } 1040