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