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