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.
36 #include "TrackerSettings.h"
41 #include "WidgetAttributeText.h"
44 class TTrackerState
: public Settings
{
46 static TTrackerState
* Get();
49 void LoadSettingsIfNeeded();
50 void SaveSettings(bool onlyIfNonDefault
= true);
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
;
94 typedef Settings _inherited
;
98 static TTrackerState gTrackerState
;
101 rgb_color
ValueToColor(int32 value
)
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);
113 int32
ColorToValue(rgb_color color
)
115 return color
.alpha
<< 24L | color
.red
<< 16L | color
.green
<< 8L
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
),
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
),
149 fSettingsLoaded(false)
154 TTrackerState::TTrackerState(const TTrackerState
&)
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
),
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
),
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()
195 TTrackerState::SaveSettings(bool onlyIfNonDefault
)
198 _inherited::SaveSettings(onlyIfNonDefault
);
203 TTrackerState::LoadSettingsIfNeeded()
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));
246 = new HexScalarValueSetting("UsedSpaceColor", 0xc000cb00, "", ""));
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();
278 TrackerSettings::SaveSettings(bool onlyIfNonDefault
)
280 gTrackerState
.SaveSettings(onlyIfNonDefault
);
285 TrackerSettings::ShowDisksIcon()
287 return gTrackerState
.fShowDisksIcon
->Value();
292 TrackerSettings::SetShowDisksIcon(bool enabled
)
294 gTrackerState
.fShowDisksIcon
->SetValue(enabled
);
299 TrackerSettings::DesktopFilePanelRoot()
301 return gTrackerState
.fDesktopFilePanelRoot
->Value();
306 TrackerSettings::SetDesktopFilePanelRoot(bool enabled
)
308 gTrackerState
.fDesktopFilePanelRoot
->SetValue(enabled
);
313 TrackerSettings::MountVolumesOntoDesktop()
315 return gTrackerState
.fMountVolumesOntoDesktop
->Value();
320 TrackerSettings::SetMountVolumesOntoDesktop(bool enabled
)
322 gTrackerState
.fMountVolumesOntoDesktop
->SetValue(enabled
);
327 TrackerSettings::MountSharedVolumesOntoDesktop()
329 return gTrackerState
.fMountSharedVolumesOntoDesktop
->Value();
334 TrackerSettings::SetMountSharedVolumesOntoDesktop(bool enabled
)
336 gTrackerState
.fMountSharedVolumesOntoDesktop
->SetValue(enabled
);
341 TrackerSettings::EjectWhenUnmounting()
343 return gTrackerState
.fEjectWhenUnmounting
->Value();
348 TrackerSettings::SetEjectWhenUnmounting(bool enabled
)
350 gTrackerState
.fEjectWhenUnmounting
->SetValue(enabled
);
355 TrackerSettings::ShowVolumeSpaceBar()
357 return gTrackerState
.fShowVolumeSpaceBar
->Value();
362 TrackerSettings::SetShowVolumeSpaceBar(bool enabled
)
364 gTrackerState
.fShowVolumeSpaceBar
->SetValue(enabled
);
369 TrackerSettings::UsedSpaceColor()
371 return ValueToColor(gTrackerState
.fUsedSpaceColor
->Value());
376 TrackerSettings::SetUsedSpaceColor(rgb_color color
)
378 gTrackerState
.fUsedSpaceColor
->ValueChanged(ColorToValue(color
));
383 TrackerSettings::FreeSpaceColor()
385 return ValueToColor(gTrackerState
.fFreeSpaceColor
->Value());
390 TrackerSettings::SetFreeSpaceColor(rgb_color color
)
392 gTrackerState
.fFreeSpaceColor
->ValueChanged(ColorToValue(color
));
397 TrackerSettings::WarningSpaceColor()
399 return ValueToColor(gTrackerState
.fWarningSpaceColor
->Value());
404 TrackerSettings::SetWarningSpaceColor(rgb_color color
)
406 gTrackerState
.fWarningSpaceColor
->ValueChanged(ColorToValue(color
));
411 TrackerSettings::ShowFullPathInTitleBar()
413 return gTrackerState
.fShowFullPathInTitleBar
->Value();
418 TrackerSettings::SetShowFullPathInTitleBar(bool enabled
)
420 gTrackerState
.fShowFullPathInTitleBar
->SetValue(enabled
);
425 TrackerSettings::SortFolderNamesFirst()
427 return gTrackerState
.fSortFolderNamesFirst
->Value();
432 TrackerSettings::SetSortFolderNamesFirst(bool enabled
)
434 gTrackerState
.fSortFolderNamesFirst
->SetValue(enabled
);
435 NameAttributeText::SetSortFolderNamesFirst(enabled
);
436 RealNameAttributeText::SetSortFolderNamesFirst(enabled
);
441 TrackerSettings::HideDotFiles()
443 return gTrackerState
.fHideDotFiles
->Value();
448 TrackerSettings::SetHideDotFiles(bool hide
)
450 gTrackerState
.fHideDotFiles
->SetValue(hide
);
455 TrackerSettings::TypeAheadFiltering()
457 return gTrackerState
.fTypeAheadFiltering
->Value();
462 TrackerSettings::SetTypeAheadFiltering(bool enabled
)
464 gTrackerState
.fTypeAheadFiltering
->SetValue(enabled
);
469 TrackerSettings::ShowSelectionWhenInactive()
471 return gTrackerState
.fShowSelectionWhenInactive
->Value();
476 TrackerSettings::SetShowSelectionWhenInactive(bool enabled
)
478 gTrackerState
.fShowSelectionWhenInactive
->SetValue(enabled
);
483 TrackerSettings::TransparentSelection()
485 return gTrackerState
.fTransparentSelection
->Value();
490 TrackerSettings::SetTransparentSelection(bool enabled
)
492 gTrackerState
.fTransparentSelection
->SetValue(enabled
);
497 TrackerSettings::SingleWindowBrowse()
499 return gTrackerState
.fSingleWindowBrowse
->Value();
504 TrackerSettings::SetSingleWindowBrowse(bool enabled
)
506 gTrackerState
.fSingleWindowBrowse
->SetValue(enabled
);
511 TrackerSettings::ShowNavigator()
513 return gTrackerState
.fShowNavigator
->Value();
518 TrackerSettings::SetShowNavigator(bool enabled
)
520 gTrackerState
.fShowNavigator
->SetValue(enabled
);
525 TrackerSettings::RecentCounts(int32
* applications
, int32
* documents
,
528 if (applications
!= NULL
)
529 *applications
= gTrackerState
.fRecentApplicationsCount
->Value();
531 if (documents
!= NULL
)
532 *documents
= gTrackerState
.fRecentDocumentsCount
->Value();
535 *folders
= gTrackerState
.fRecentFoldersCount
->Value();
540 TrackerSettings::SetRecentApplicationsCount(int32 count
)
542 gTrackerState
.fRecentApplicationsCount
->ValueChanged(count
);
547 TrackerSettings::SetRecentDocumentsCount(int32 count
)
549 gTrackerState
.fRecentDocumentsCount
->ValueChanged(count
);
554 TrackerSettings::SetRecentFoldersCount(int32 count
)
556 gTrackerState
.fRecentFoldersCount
->ValueChanged(count
);
561 TrackerSettings::DontMoveFilesToTrash()
563 return gTrackerState
.fDontMoveFilesToTrash
->Value();
568 TrackerSettings::SetDontMoveFilesToTrash(bool enabled
)
570 gTrackerState
.fDontMoveFilesToTrash
->SetValue(enabled
);
575 TrackerSettings::AskBeforeDeleteFile()
577 return gTrackerState
.fAskBeforeDeleteFile
->Value();
582 TrackerSettings::SetAskBeforeDeleteFile(bool enabled
)
584 gTrackerState
.fAskBeforeDeleteFile
->SetValue(enabled
);