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