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