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