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 "TrackerSettings.h" 37 38 #include <Debug.h> 39 40 #include "Tracker.h" 41 #include "WidgetAttributeText.h" 42 43 44 class TTrackerState : public Settings { 45 public: 46 static TTrackerState* Get(); 47 void Release(); 48 49 void LoadSettingsIfNeeded(); 50 void SaveSettings(bool onlyIfNonDefault = true); 51 52 TTrackerState(); 53 ~TTrackerState(); 54 55 private: 56 friend class BPrivate::TrackerSettings; 57 58 static void InitIfNeeded(); 59 TTrackerState(const TTrackerState&); 60 61 BooleanValueSetting* fShowDisksIcon; 62 BooleanValueSetting* fMountVolumesOntoDesktop; 63 BooleanValueSetting* fDesktopFilePanelRoot; 64 BooleanValueSetting* fMountSharedVolumesOntoDesktop; 65 BooleanValueSetting* fEjectWhenUnmounting; 66 67 BooleanValueSetting* fShowFullPathInTitleBar; 68 BooleanValueSetting* fSingleWindowBrowse; 69 BooleanValueSetting* fShowNavigator; 70 BooleanValueSetting* fShowSelectionWhenInactive; 71 BooleanValueSetting* fTransparentSelection; 72 BooleanValueSetting* fSortFolderNamesFirst; 73 BooleanValueSetting* fHideDotFiles; 74 BooleanValueSetting* fTypeAheadFiltering; 75 BooleanValueSetting* fGenerateImageThumbnails; 76 77 ScalarValueSetting* fRecentApplicationsCount; 78 ScalarValueSetting* fRecentDocumentsCount; 79 ScalarValueSetting* fRecentFoldersCount; 80 81 BooleanValueSetting* fShowVolumeSpaceBar; 82 HexScalarValueSetting* fUsedSpaceColor; 83 HexScalarValueSetting* fFreeSpaceColor; 84 HexScalarValueSetting* fWarningSpaceColor; 85 86 BooleanValueSetting* fDontMoveFilesToTrash; 87 BooleanValueSetting* fAskBeforeDeleteFile; 88 89 Benaphore fInitLock; 90 bool fInited; 91 bool fSettingsLoaded; 92 93 int32 fUseCounter; 94 95 typedef Settings _inherited; 96 }; 97 98 99 static TTrackerState gTrackerState; 100 101 102 rgb_color ValueToColor(int32 value) 103 { 104 rgb_color color; 105 color.alpha = static_cast<uchar>((value >> 24L) & 0xff); 106 color.red = static_cast<uchar>((value >> 16L) & 0xff); 107 color.green = static_cast<uchar>((value >> 8L) & 0xff); 108 color.blue = static_cast<uchar>(value & 0xff); 109 110 return color; 111 } 112 113 114 int32 ColorToValue(rgb_color color) 115 { 116 return color.alpha << 24L | color.red << 16L | color.green << 8L 117 | color.blue; 118 } 119 120 121 // #pragma mark - TTrackerState 122 123 124 TTrackerState::TTrackerState() 125 : 126 Settings("TrackerSettings", "Tracker"), 127 fShowDisksIcon(NULL), 128 fMountVolumesOntoDesktop(NULL), 129 fDesktopFilePanelRoot(NULL), 130 fMountSharedVolumesOntoDesktop(NULL), 131 fEjectWhenUnmounting(NULL), 132 fShowFullPathInTitleBar(NULL), 133 fSingleWindowBrowse(NULL), 134 fShowNavigator(NULL), 135 fShowSelectionWhenInactive(NULL), 136 fTransparentSelection(NULL), 137 fSortFolderNamesFirst(NULL), 138 fHideDotFiles(NULL), 139 fTypeAheadFiltering(NULL), 140 fGenerateImageThumbnails(NULL), 141 fRecentApplicationsCount(NULL), 142 fRecentDocumentsCount(NULL), 143 fRecentFoldersCount(NULL), 144 fShowVolumeSpaceBar(NULL), 145 fUsedSpaceColor(NULL), 146 fFreeSpaceColor(NULL), 147 fWarningSpaceColor(NULL), 148 fDontMoveFilesToTrash(NULL), 149 fAskBeforeDeleteFile(NULL), 150 fInited(false), 151 fSettingsLoaded(false) 152 { 153 } 154 155 156 TTrackerState::TTrackerState(const TTrackerState&) 157 : 158 Settings("", ""), 159 fShowDisksIcon(NULL), 160 fMountVolumesOntoDesktop(NULL), 161 fDesktopFilePanelRoot(NULL), 162 fMountSharedVolumesOntoDesktop(NULL), 163 fEjectWhenUnmounting(NULL), 164 fShowFullPathInTitleBar(NULL), 165 fSingleWindowBrowse(NULL), 166 fShowNavigator(NULL), 167 fShowSelectionWhenInactive(NULL), 168 fTransparentSelection(NULL), 169 fSortFolderNamesFirst(NULL), 170 fHideDotFiles(NULL), 171 fTypeAheadFiltering(NULL), 172 fGenerateImageThumbnails(NULL), 173 fRecentApplicationsCount(NULL), 174 fRecentDocumentsCount(NULL), 175 fRecentFoldersCount(NULL), 176 fShowVolumeSpaceBar(NULL), 177 fUsedSpaceColor(NULL), 178 fFreeSpaceColor(NULL), 179 fWarningSpaceColor(NULL), 180 fDontMoveFilesToTrash(NULL), 181 fAskBeforeDeleteFile(NULL), 182 fInited(false), 183 fSettingsLoaded(false) 184 { 185 // Placeholder copy constructor to prevent others from accidentally using 186 // the default copy constructor. Note, the DEBUGGER call is for the off 187 // chance that a TTrackerState method (or friend) tries to make a copy. 188 DEBUGGER("Don't make a copy of this!"); 189 } 190 191 192 TTrackerState::~TTrackerState() 193 { 194 } 195 196 197 void 198 TTrackerState::SaveSettings(bool onlyIfNonDefault) 199 { 200 if (fSettingsLoaded) 201 _inherited::SaveSettings(onlyIfNonDefault); 202 } 203 204 205 void 206 TTrackerState::LoadSettingsIfNeeded() 207 { 208 if (fSettingsLoaded) 209 return; 210 211 // Set default settings before reading from disk 212 213 Add(fShowDisksIcon = new BooleanValueSetting("ShowDisksIcon", false)); 214 Add(fMountVolumesOntoDesktop 215 = new BooleanValueSetting("MountVolumesOntoDesktop", true)); 216 Add(fMountSharedVolumesOntoDesktop = 217 new BooleanValueSetting("MountSharedVolumesOntoDesktop", true)); 218 Add(fEjectWhenUnmounting 219 = new BooleanValueSetting("EjectWhenUnmounting", true)); 220 221 Add(fDesktopFilePanelRoot 222 = new BooleanValueSetting("DesktopFilePanelRoot", true)); 223 Add(fShowFullPathInTitleBar 224 = new BooleanValueSetting("ShowFullPathInTitleBar", false)); 225 Add(fShowSelectionWhenInactive 226 = new BooleanValueSetting("ShowSelectionWhenInactive", true)); 227 Add(fTransparentSelection 228 = new BooleanValueSetting("TransparentSelection", true)); 229 Add(fSortFolderNamesFirst 230 = new BooleanValueSetting("SortFolderNamesFirst", true)); 231 Add(fHideDotFiles = new BooleanValueSetting("HideDotFiles", false)); 232 Add(fTypeAheadFiltering 233 = new BooleanValueSetting("TypeAheadFiltering", false)); 234 Add(fGenerateImageThumbnails 235 = new BooleanValueSetting("GenerateImageThumbnails", false)); 236 Add(fSingleWindowBrowse 237 = new BooleanValueSetting("SingleWindowBrowse", false)); 238 Add(fShowNavigator = new BooleanValueSetting("ShowNavigator", false)); 239 240 Add(fRecentApplicationsCount 241 = new ScalarValueSetting("RecentApplications", 10, "", "")); 242 Add(fRecentDocumentsCount 243 = new ScalarValueSetting("RecentDocuments", 10, "", "")); 244 Add(fRecentFoldersCount 245 = new ScalarValueSetting("RecentFolders", 10, "", "")); 246 247 Add(fShowVolumeSpaceBar 248 = new BooleanValueSetting("ShowVolumeSpaceBar", true)); 249 250 Add(fUsedSpaceColor 251 = new HexScalarValueSetting("UsedSpaceColor", 0xc000cb00, "", "")); 252 Add(fFreeSpaceColor 253 = new HexScalarValueSetting("FreeSpaceColor", 0xc0ffffff, "", "")); 254 Add(fWarningSpaceColor 255 = new HexScalarValueSetting("WarningSpaceColor", 0xc0cb0000, "", "")); 256 257 Add(fDontMoveFilesToTrash 258 = new BooleanValueSetting("DontMoveFilesToTrash", false)); 259 Add(fAskBeforeDeleteFile 260 = new BooleanValueSetting("AskBeforeDeleteFile", true)); 261 262 TryReadingSettings(); 263 264 NameAttributeText::SetSortFolderNamesFirst( 265 fSortFolderNamesFirst->Value()); 266 RealNameAttributeText::SetSortFolderNamesFirst( 267 fSortFolderNamesFirst->Value()); 268 269 fSettingsLoaded = true; 270 } 271 272 273 // #pragma mark - TrackerSettings 274 275 276 TrackerSettings::TrackerSettings() 277 { 278 gTrackerState.LoadSettingsIfNeeded(); 279 } 280 281 282 void 283 TrackerSettings::SaveSettings(bool onlyIfNonDefault) 284 { 285 gTrackerState.SaveSettings(onlyIfNonDefault); 286 } 287 288 289 bool 290 TrackerSettings::ShowDisksIcon() 291 { 292 return gTrackerState.fShowDisksIcon->Value(); 293 } 294 295 296 void 297 TrackerSettings::SetShowDisksIcon(bool enabled) 298 { 299 gTrackerState.fShowDisksIcon->SetValue(enabled); 300 } 301 302 303 bool 304 TrackerSettings::DesktopFilePanelRoot() 305 { 306 return gTrackerState.fDesktopFilePanelRoot->Value(); 307 } 308 309 310 void 311 TrackerSettings::SetDesktopFilePanelRoot(bool enabled) 312 { 313 gTrackerState.fDesktopFilePanelRoot->SetValue(enabled); 314 } 315 316 317 bool 318 TrackerSettings::MountVolumesOntoDesktop() 319 { 320 return gTrackerState.fMountVolumesOntoDesktop->Value(); 321 } 322 323 324 void 325 TrackerSettings::SetMountVolumesOntoDesktop(bool enabled) 326 { 327 gTrackerState.fMountVolumesOntoDesktop->SetValue(enabled); 328 } 329 330 331 bool 332 TrackerSettings::MountSharedVolumesOntoDesktop() 333 { 334 return gTrackerState.fMountSharedVolumesOntoDesktop->Value(); 335 } 336 337 338 void 339 TrackerSettings::SetMountSharedVolumesOntoDesktop(bool enabled) 340 { 341 gTrackerState.fMountSharedVolumesOntoDesktop->SetValue(enabled); 342 } 343 344 345 bool 346 TrackerSettings::EjectWhenUnmounting() 347 { 348 return gTrackerState.fEjectWhenUnmounting->Value(); 349 } 350 351 352 void 353 TrackerSettings::SetEjectWhenUnmounting(bool enabled) 354 { 355 gTrackerState.fEjectWhenUnmounting->SetValue(enabled); 356 } 357 358 359 bool 360 TrackerSettings::ShowVolumeSpaceBar() 361 { 362 return gTrackerState.fShowVolumeSpaceBar->Value(); 363 } 364 365 366 void 367 TrackerSettings::SetShowVolumeSpaceBar(bool enabled) 368 { 369 gTrackerState.fShowVolumeSpaceBar->SetValue(enabled); 370 } 371 372 373 rgb_color 374 TrackerSettings::UsedSpaceColor() 375 { 376 return ValueToColor(gTrackerState.fUsedSpaceColor->Value()); 377 } 378 379 380 void 381 TrackerSettings::SetUsedSpaceColor(rgb_color color) 382 { 383 gTrackerState.fUsedSpaceColor->ValueChanged(ColorToValue(color)); 384 } 385 386 387 rgb_color 388 TrackerSettings::FreeSpaceColor() 389 { 390 return ValueToColor(gTrackerState.fFreeSpaceColor->Value()); 391 } 392 393 394 void 395 TrackerSettings::SetFreeSpaceColor(rgb_color color) 396 { 397 gTrackerState.fFreeSpaceColor->ValueChanged(ColorToValue(color)); 398 } 399 400 401 rgb_color 402 TrackerSettings::WarningSpaceColor() 403 { 404 return ValueToColor(gTrackerState.fWarningSpaceColor->Value()); 405 } 406 407 408 void 409 TrackerSettings::SetWarningSpaceColor(rgb_color color) 410 { 411 gTrackerState.fWarningSpaceColor->ValueChanged(ColorToValue(color)); 412 } 413 414 415 bool 416 TrackerSettings::ShowFullPathInTitleBar() 417 { 418 return gTrackerState.fShowFullPathInTitleBar->Value(); 419 } 420 421 422 void 423 TrackerSettings::SetShowFullPathInTitleBar(bool enabled) 424 { 425 gTrackerState.fShowFullPathInTitleBar->SetValue(enabled); 426 } 427 428 429 bool 430 TrackerSettings::SortFolderNamesFirst() 431 { 432 return gTrackerState.fSortFolderNamesFirst->Value(); 433 } 434 435 436 void 437 TrackerSettings::SetSortFolderNamesFirst(bool enabled) 438 { 439 gTrackerState.fSortFolderNamesFirst->SetValue(enabled); 440 NameAttributeText::SetSortFolderNamesFirst(enabled); 441 RealNameAttributeText::SetSortFolderNamesFirst(enabled); 442 } 443 444 445 bool 446 TrackerSettings::HideDotFiles() 447 { 448 return gTrackerState.fHideDotFiles->Value(); 449 } 450 451 452 void 453 TrackerSettings::SetHideDotFiles(bool hide) 454 { 455 gTrackerState.fHideDotFiles->SetValue(hide); 456 } 457 458 459 bool 460 TrackerSettings::TypeAheadFiltering() 461 { 462 return gTrackerState.fTypeAheadFiltering->Value(); 463 } 464 465 466 void 467 TrackerSettings::SetTypeAheadFiltering(bool enabled) 468 { 469 gTrackerState.fTypeAheadFiltering->SetValue(enabled); 470 } 471 472 473 bool 474 TrackerSettings::GenerateImageThumbnails() 475 { 476 return gTrackerState.fGenerateImageThumbnails->Value(); 477 } 478 479 480 void 481 TrackerSettings::SetGenerateImageThumbnails(bool enabled) 482 { 483 gTrackerState.fGenerateImageThumbnails->SetValue(enabled); 484 } 485 486 487 bool 488 TrackerSettings::ShowSelectionWhenInactive() 489 { 490 return gTrackerState.fShowSelectionWhenInactive->Value(); 491 } 492 493 494 void 495 TrackerSettings::SetShowSelectionWhenInactive(bool enabled) 496 { 497 gTrackerState.fShowSelectionWhenInactive->SetValue(enabled); 498 } 499 500 501 bool 502 TrackerSettings::TransparentSelection() 503 { 504 return gTrackerState.fTransparentSelection->Value(); 505 } 506 507 508 void 509 TrackerSettings::SetTransparentSelection(bool enabled) 510 { 511 gTrackerState.fTransparentSelection->SetValue(enabled); 512 } 513 514 515 bool 516 TrackerSettings::SingleWindowBrowse() 517 { 518 return gTrackerState.fSingleWindowBrowse->Value(); 519 } 520 521 522 void 523 TrackerSettings::SetSingleWindowBrowse(bool enabled) 524 { 525 gTrackerState.fSingleWindowBrowse->SetValue(enabled); 526 } 527 528 529 bool 530 TrackerSettings::ShowNavigator() 531 { 532 return gTrackerState.fShowNavigator->Value(); 533 } 534 535 536 void 537 TrackerSettings::SetShowNavigator(bool enabled) 538 { 539 gTrackerState.fShowNavigator->SetValue(enabled); 540 } 541 542 543 void 544 TrackerSettings::RecentCounts(int32* applications, int32* documents, 545 int32* folders) 546 { 547 if (applications != NULL) 548 *applications = gTrackerState.fRecentApplicationsCount->Value(); 549 550 if (documents != NULL) 551 *documents = gTrackerState.fRecentDocumentsCount->Value(); 552 553 if (folders != NULL) 554 *folders = gTrackerState.fRecentFoldersCount->Value(); 555 } 556 557 558 void 559 TrackerSettings::SetRecentApplicationsCount(int32 count) 560 { 561 gTrackerState.fRecentApplicationsCount->ValueChanged(count); 562 } 563 564 565 void 566 TrackerSettings::SetRecentDocumentsCount(int32 count) 567 { 568 gTrackerState.fRecentDocumentsCount->ValueChanged(count); 569 } 570 571 572 void 573 TrackerSettings::SetRecentFoldersCount(int32 count) 574 { 575 gTrackerState.fRecentFoldersCount->ValueChanged(count); 576 } 577 578 579 bool 580 TrackerSettings::DontMoveFilesToTrash() 581 { 582 return gTrackerState.fDontMoveFilesToTrash->Value(); 583 } 584 585 586 void 587 TrackerSettings::SetDontMoveFilesToTrash(bool enabled) 588 { 589 gTrackerState.fDontMoveFilesToTrash->SetValue(enabled); 590 } 591 592 593 bool 594 TrackerSettings::AskBeforeDeleteFile() 595 { 596 return gTrackerState.fAskBeforeDeleteFile->Value(); 597 } 598 599 600 void 601 TrackerSettings::SetAskBeforeDeleteFile(bool enabled) 602 { 603 gTrackerState.fAskBeforeDeleteFile->SetValue(enabled); 604 } 605