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