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