RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / kits / tracker / TrackerSettings.cpp
blobe956df7d7383eccb4bc4a91e2fd92c81d57a5301
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
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:
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.
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.
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.
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.
36 #include "TrackerSettings.h"
38 #include <Debug.h>
40 #include "Tracker.h"
41 #include "WidgetAttributeText.h"
44 class TTrackerState : public Settings {
45 public:
46 static TTrackerState* Get();
47 void Release();
49 void LoadSettingsIfNeeded();
50 void SaveSettings(bool onlyIfNonDefault = true);
52 TTrackerState();
53 ~TTrackerState();
55 private:
56 friend class BPrivate::TrackerSettings;
58 static void InitIfNeeded();
59 TTrackerState(const TTrackerState&);
61 BooleanValueSetting* fShowDisksIcon;
62 BooleanValueSetting* fMountVolumesOntoDesktop;
63 BooleanValueSetting* fDesktopFilePanelRoot;
64 BooleanValueSetting* fMountSharedVolumesOntoDesktop;
65 BooleanValueSetting* fEjectWhenUnmounting;
67 BooleanValueSetting* fShowFullPathInTitleBar;
68 BooleanValueSetting* fSingleWindowBrowse;
69 BooleanValueSetting* fShowNavigator;
70 BooleanValueSetting* fShowSelectionWhenInactive;
71 BooleanValueSetting* fTransparentSelection;
72 BooleanValueSetting* fSortFolderNamesFirst;
73 BooleanValueSetting* fHideDotFiles;
74 BooleanValueSetting* fTypeAheadFiltering;
76 ScalarValueSetting* fRecentApplicationsCount;
77 ScalarValueSetting* fRecentDocumentsCount;
78 ScalarValueSetting* fRecentFoldersCount;
80 BooleanValueSetting* fShowVolumeSpaceBar;
81 HexScalarValueSetting* fUsedSpaceColor;
82 HexScalarValueSetting* fFreeSpaceColor;
83 HexScalarValueSetting* fWarningSpaceColor;
85 BooleanValueSetting* fDontMoveFilesToTrash;
86 BooleanValueSetting* fAskBeforeDeleteFile;
88 Benaphore fInitLock;
89 bool fInited;
90 bool fSettingsLoaded;
92 int32 fUseCounter;
94 typedef Settings _inherited;
98 static TTrackerState gTrackerState;
101 rgb_color ValueToColor(int32 value)
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);
109 return color;
113 int32 ColorToValue(rgb_color color)
115 return color.alpha << 24L | color.red << 16L | color.green << 8L
116 | color.blue;
120 // #pragma mark - TTrackerState
123 TTrackerState::TTrackerState()
125 Settings("TrackerSettings", "Tracker"),
126 fShowDisksIcon(NULL),
127 fMountVolumesOntoDesktop(NULL),
128 fDesktopFilePanelRoot(NULL),
129 fMountSharedVolumesOntoDesktop(NULL),
130 fEjectWhenUnmounting(NULL),
131 fShowFullPathInTitleBar(NULL),
132 fSingleWindowBrowse(NULL),
133 fShowNavigator(NULL),
134 fShowSelectionWhenInactive(NULL),
135 fTransparentSelection(NULL),
136 fSortFolderNamesFirst(NULL),
137 fHideDotFiles(NULL),
138 fTypeAheadFiltering(NULL),
139 fRecentApplicationsCount(NULL),
140 fRecentDocumentsCount(NULL),
141 fRecentFoldersCount(NULL),
142 fShowVolumeSpaceBar(NULL),
143 fUsedSpaceColor(NULL),
144 fFreeSpaceColor(NULL),
145 fWarningSpaceColor(NULL),
146 fDontMoveFilesToTrash(NULL),
147 fAskBeforeDeleteFile(NULL),
148 fInited(false),
149 fSettingsLoaded(false)
154 TTrackerState::TTrackerState(const TTrackerState&)
156 Settings("", ""),
157 fShowDisksIcon(NULL),
158 fMountVolumesOntoDesktop(NULL),
159 fDesktopFilePanelRoot(NULL),
160 fMountSharedVolumesOntoDesktop(NULL),
161 fEjectWhenUnmounting(NULL),
162 fShowFullPathInTitleBar(NULL),
163 fSingleWindowBrowse(NULL),
164 fShowNavigator(NULL),
165 fShowSelectionWhenInactive(NULL),
166 fTransparentSelection(NULL),
167 fSortFolderNamesFirst(NULL),
168 fHideDotFiles(NULL),
169 fTypeAheadFiltering(NULL),
170 fRecentApplicationsCount(NULL),
171 fRecentDocumentsCount(NULL),
172 fRecentFoldersCount(NULL),
173 fShowVolumeSpaceBar(NULL),
174 fUsedSpaceColor(NULL),
175 fFreeSpaceColor(NULL),
176 fWarningSpaceColor(NULL),
177 fDontMoveFilesToTrash(NULL),
178 fAskBeforeDeleteFile(NULL),
179 fInited(false),
180 fSettingsLoaded(false)
182 // Placeholder copy constructor to prevent others from accidentally using
183 // the default copy constructor. Note, the DEBUGGER call is for the off
184 // chance that a TTrackerState method (or friend) tries to make a copy.
185 DEBUGGER("Don't make a copy of this!");
189 TTrackerState::~TTrackerState()
194 void
195 TTrackerState::SaveSettings(bool onlyIfNonDefault)
197 if (fSettingsLoaded)
198 _inherited::SaveSettings(onlyIfNonDefault);
202 void
203 TTrackerState::LoadSettingsIfNeeded()
205 if (fSettingsLoaded)
206 return;
208 // Set default settings before reading from disk
210 Add(fShowDisksIcon = new BooleanValueSetting("ShowDisksIcon", false));
211 Add(fMountVolumesOntoDesktop
212 = new BooleanValueSetting("MountVolumesOntoDesktop", true));
213 Add(fMountSharedVolumesOntoDesktop =
214 new BooleanValueSetting("MountSharedVolumesOntoDesktop", true));
215 Add(fEjectWhenUnmounting
216 = new BooleanValueSetting("EjectWhenUnmounting", true));
218 Add(fDesktopFilePanelRoot
219 = new BooleanValueSetting("DesktopFilePanelRoot", true));
220 Add(fShowFullPathInTitleBar
221 = new BooleanValueSetting("ShowFullPathInTitleBar", false));
222 Add(fShowSelectionWhenInactive
223 = new BooleanValueSetting("ShowSelectionWhenInactive", true));
224 Add(fTransparentSelection
225 = new BooleanValueSetting("TransparentSelection", true));
226 Add(fSortFolderNamesFirst
227 = new BooleanValueSetting("SortFolderNamesFirst", true));
228 Add(fHideDotFiles = new BooleanValueSetting("HideDotFiles", false));
229 Add(fTypeAheadFiltering
230 = new BooleanValueSetting("TypeAheadFiltering", false));
231 Add(fSingleWindowBrowse
232 = new BooleanValueSetting("SingleWindowBrowse", false));
233 Add(fShowNavigator = new BooleanValueSetting("ShowNavigator", false));
235 Add(fRecentApplicationsCount
236 = new ScalarValueSetting("RecentApplications", 10, "", ""));
237 Add(fRecentDocumentsCount
238 = new ScalarValueSetting("RecentDocuments", 10, "", ""));
239 Add(fRecentFoldersCount
240 = new ScalarValueSetting("RecentFolders", 10, "", ""));
242 Add(fShowVolumeSpaceBar
243 = new BooleanValueSetting("ShowVolumeSpaceBar", true));
245 Add(fUsedSpaceColor
246 = new HexScalarValueSetting("UsedSpaceColor", 0xc000cb00, "", ""));
247 Add(fFreeSpaceColor
248 = new HexScalarValueSetting("FreeSpaceColor", 0xc0ffffff, "", ""));
249 Add(fWarningSpaceColor
250 = new HexScalarValueSetting("WarningSpaceColor", 0xc0cb0000, "", ""));
252 Add(fDontMoveFilesToTrash
253 = new BooleanValueSetting("DontMoveFilesToTrash", false));
254 Add(fAskBeforeDeleteFile
255 = new BooleanValueSetting("AskBeforeDeleteFile", true));
257 TryReadingSettings();
259 NameAttributeText::SetSortFolderNamesFirst(
260 fSortFolderNamesFirst->Value());
261 RealNameAttributeText::SetSortFolderNamesFirst(
262 fSortFolderNamesFirst->Value());
264 fSettingsLoaded = true;
268 // #pragma mark - TrackerSettings
271 TrackerSettings::TrackerSettings()
273 gTrackerState.LoadSettingsIfNeeded();
277 void
278 TrackerSettings::SaveSettings(bool onlyIfNonDefault)
280 gTrackerState.SaveSettings(onlyIfNonDefault);
284 bool
285 TrackerSettings::ShowDisksIcon()
287 return gTrackerState.fShowDisksIcon->Value();
291 void
292 TrackerSettings::SetShowDisksIcon(bool enabled)
294 gTrackerState.fShowDisksIcon->SetValue(enabled);
298 bool
299 TrackerSettings::DesktopFilePanelRoot()
301 return gTrackerState.fDesktopFilePanelRoot->Value();
305 void
306 TrackerSettings::SetDesktopFilePanelRoot(bool enabled)
308 gTrackerState.fDesktopFilePanelRoot->SetValue(enabled);
312 bool
313 TrackerSettings::MountVolumesOntoDesktop()
315 return gTrackerState.fMountVolumesOntoDesktop->Value();
319 void
320 TrackerSettings::SetMountVolumesOntoDesktop(bool enabled)
322 gTrackerState.fMountVolumesOntoDesktop->SetValue(enabled);
326 bool
327 TrackerSettings::MountSharedVolumesOntoDesktop()
329 return gTrackerState.fMountSharedVolumesOntoDesktop->Value();
333 void
334 TrackerSettings::SetMountSharedVolumesOntoDesktop(bool enabled)
336 gTrackerState.fMountSharedVolumesOntoDesktop->SetValue(enabled);
340 bool
341 TrackerSettings::EjectWhenUnmounting()
343 return gTrackerState.fEjectWhenUnmounting->Value();
347 void
348 TrackerSettings::SetEjectWhenUnmounting(bool enabled)
350 gTrackerState.fEjectWhenUnmounting->SetValue(enabled);
354 bool
355 TrackerSettings::ShowVolumeSpaceBar()
357 return gTrackerState.fShowVolumeSpaceBar->Value();
361 void
362 TrackerSettings::SetShowVolumeSpaceBar(bool enabled)
364 gTrackerState.fShowVolumeSpaceBar->SetValue(enabled);
368 rgb_color
369 TrackerSettings::UsedSpaceColor()
371 return ValueToColor(gTrackerState.fUsedSpaceColor->Value());
375 void
376 TrackerSettings::SetUsedSpaceColor(rgb_color color)
378 gTrackerState.fUsedSpaceColor->ValueChanged(ColorToValue(color));
382 rgb_color
383 TrackerSettings::FreeSpaceColor()
385 return ValueToColor(gTrackerState.fFreeSpaceColor->Value());
389 void
390 TrackerSettings::SetFreeSpaceColor(rgb_color color)
392 gTrackerState.fFreeSpaceColor->ValueChanged(ColorToValue(color));
396 rgb_color
397 TrackerSettings::WarningSpaceColor()
399 return ValueToColor(gTrackerState.fWarningSpaceColor->Value());
403 void
404 TrackerSettings::SetWarningSpaceColor(rgb_color color)
406 gTrackerState.fWarningSpaceColor->ValueChanged(ColorToValue(color));
410 bool
411 TrackerSettings::ShowFullPathInTitleBar()
413 return gTrackerState.fShowFullPathInTitleBar->Value();
417 void
418 TrackerSettings::SetShowFullPathInTitleBar(bool enabled)
420 gTrackerState.fShowFullPathInTitleBar->SetValue(enabled);
424 bool
425 TrackerSettings::SortFolderNamesFirst()
427 return gTrackerState.fSortFolderNamesFirst->Value();
431 void
432 TrackerSettings::SetSortFolderNamesFirst(bool enabled)
434 gTrackerState.fSortFolderNamesFirst->SetValue(enabled);
435 NameAttributeText::SetSortFolderNamesFirst(enabled);
436 RealNameAttributeText::SetSortFolderNamesFirst(enabled);
440 bool
441 TrackerSettings::HideDotFiles()
443 return gTrackerState.fHideDotFiles->Value();
447 void
448 TrackerSettings::SetHideDotFiles(bool hide)
450 gTrackerState.fHideDotFiles->SetValue(hide);
454 bool
455 TrackerSettings::TypeAheadFiltering()
457 return gTrackerState.fTypeAheadFiltering->Value();
461 void
462 TrackerSettings::SetTypeAheadFiltering(bool enabled)
464 gTrackerState.fTypeAheadFiltering->SetValue(enabled);
468 bool
469 TrackerSettings::ShowSelectionWhenInactive()
471 return gTrackerState.fShowSelectionWhenInactive->Value();
475 void
476 TrackerSettings::SetShowSelectionWhenInactive(bool enabled)
478 gTrackerState.fShowSelectionWhenInactive->SetValue(enabled);
482 bool
483 TrackerSettings::TransparentSelection()
485 return gTrackerState.fTransparentSelection->Value();
489 void
490 TrackerSettings::SetTransparentSelection(bool enabled)
492 gTrackerState.fTransparentSelection->SetValue(enabled);
496 bool
497 TrackerSettings::SingleWindowBrowse()
499 return gTrackerState.fSingleWindowBrowse->Value();
503 void
504 TrackerSettings::SetSingleWindowBrowse(bool enabled)
506 gTrackerState.fSingleWindowBrowse->SetValue(enabled);
510 bool
511 TrackerSettings::ShowNavigator()
513 return gTrackerState.fShowNavigator->Value();
517 void
518 TrackerSettings::SetShowNavigator(bool enabled)
520 gTrackerState.fShowNavigator->SetValue(enabled);
524 void
525 TrackerSettings::RecentCounts(int32* applications, int32* documents,
526 int32* folders)
528 if (applications != NULL)
529 *applications = gTrackerState.fRecentApplicationsCount->Value();
531 if (documents != NULL)
532 *documents = gTrackerState.fRecentDocumentsCount->Value();
534 if (folders != NULL)
535 *folders = gTrackerState.fRecentFoldersCount->Value();
539 void
540 TrackerSettings::SetRecentApplicationsCount(int32 count)
542 gTrackerState.fRecentApplicationsCount->ValueChanged(count);
546 void
547 TrackerSettings::SetRecentDocumentsCount(int32 count)
549 gTrackerState.fRecentDocumentsCount->ValueChanged(count);
553 void
554 TrackerSettings::SetRecentFoldersCount(int32 count)
556 gTrackerState.fRecentFoldersCount->ValueChanged(count);
560 bool
561 TrackerSettings::DontMoveFilesToTrash()
563 return gTrackerState.fDontMoveFilesToTrash->Value();
567 void
568 TrackerSettings::SetDontMoveFilesToTrash(bool enabled)
570 gTrackerState.fDontMoveFilesToTrash->SetValue(enabled);
574 bool
575 TrackerSettings::AskBeforeDeleteFile()
577 return gTrackerState.fAskBeforeDeleteFile->Value();
581 void
582 TrackerSettings::SetAskBeforeDeleteFile(bool enabled)
584 gTrackerState.fAskBeforeDeleteFile->SetValue(enabled);