xref: /haiku/src/kits/tracker/TrackerSettings.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
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 	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)
150 {
151 }
152 
153 
154 TTrackerState::TTrackerState(const TTrackerState&)
155 	:
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)
181 {
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!");
186 }
187 
188 
189 TTrackerState::~TTrackerState()
190 {
191 }
192 
193 
194 void
195 TTrackerState::SaveSettings(bool onlyIfNonDefault)
196 {
197 	if (fSettingsLoaded)
198 		_inherited::SaveSettings(onlyIfNonDefault);
199 }
200 
201 
202 void
203 TTrackerState::LoadSettingsIfNeeded()
204 {
205 	if (fSettingsLoaded)
206 		return;
207 
208 	// Set default settings before reading from disk
209 
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));
217 
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));
234 
235 	Add(fRecentApplicationsCount
236 		= new ScalarValueSetting("RecentApplications", 10, "", ""));
237 	Add(fRecentDocumentsCount
238 		= new ScalarValueSetting("RecentDocuments", 10, "", ""));
239 	Add(fRecentFoldersCount
240 		= new ScalarValueSetting("RecentFolders", 10, "", ""));
241 
242 	Add(fShowVolumeSpaceBar
243 		= new BooleanValueSetting("ShowVolumeSpaceBar", true));
244 
245 	Add(fUsedSpaceColor
246 		= new HexScalarValueSetting("UsedSpaceColor", 0xc000cb00, "", ""));
247 	Add(fFreeSpaceColor
248 		= new HexScalarValueSetting("FreeSpaceColor", 0xc0ffffff, "", ""));
249 	Add(fWarningSpaceColor
250 		= new HexScalarValueSetting("WarningSpaceColor", 0xc0cb0000, "", ""));
251 
252 	Add(fDontMoveFilesToTrash
253 		= new BooleanValueSetting("DontMoveFilesToTrash", false));
254 	Add(fAskBeforeDeleteFile
255 		= new BooleanValueSetting("AskBeforeDeleteFile", true));
256 
257 	TryReadingSettings();
258 
259 	NameAttributeText::SetSortFolderNamesFirst(
260 		fSortFolderNamesFirst->Value());
261 	RealNameAttributeText::SetSortFolderNamesFirst(
262 		fSortFolderNamesFirst->Value());
263 
264 	fSettingsLoaded = true;
265 }
266 
267 
268 //	#pragma mark - TrackerSettings
269 
270 
271 TrackerSettings::TrackerSettings()
272 {
273 	gTrackerState.LoadSettingsIfNeeded();
274 }
275 
276 
277 void
278 TrackerSettings::SaveSettings(bool onlyIfNonDefault)
279 {
280 	gTrackerState.SaveSettings(onlyIfNonDefault);
281 }
282 
283 
284 bool
285 TrackerSettings::ShowDisksIcon()
286 {
287 	return gTrackerState.fShowDisksIcon->Value();
288 }
289 
290 
291 void
292 TrackerSettings::SetShowDisksIcon(bool enabled)
293 {
294 	gTrackerState.fShowDisksIcon->SetValue(enabled);
295 }
296 
297 
298 bool
299 TrackerSettings::DesktopFilePanelRoot()
300 {
301 	return gTrackerState.fDesktopFilePanelRoot->Value();
302 }
303 
304 
305 void
306 TrackerSettings::SetDesktopFilePanelRoot(bool enabled)
307 {
308 	gTrackerState.fDesktopFilePanelRoot->SetValue(enabled);
309 }
310 
311 
312 bool
313 TrackerSettings::MountVolumesOntoDesktop()
314 {
315 	return gTrackerState.fMountVolumesOntoDesktop->Value();
316 }
317 
318 
319 void
320 TrackerSettings::SetMountVolumesOntoDesktop(bool enabled)
321 {
322 	gTrackerState.fMountVolumesOntoDesktop->SetValue(enabled);
323 }
324 
325 
326 bool
327 TrackerSettings::MountSharedVolumesOntoDesktop()
328 {
329 	return gTrackerState.fMountSharedVolumesOntoDesktop->Value();
330 }
331 
332 
333 void
334 TrackerSettings::SetMountSharedVolumesOntoDesktop(bool enabled)
335 {
336 	gTrackerState.fMountSharedVolumesOntoDesktop->SetValue(enabled);
337 }
338 
339 
340 bool
341 TrackerSettings::EjectWhenUnmounting()
342 {
343 	return gTrackerState.fEjectWhenUnmounting->Value();
344 }
345 
346 
347 void
348 TrackerSettings::SetEjectWhenUnmounting(bool enabled)
349 {
350 	gTrackerState.fEjectWhenUnmounting->SetValue(enabled);
351 }
352 
353 
354 bool
355 TrackerSettings::ShowVolumeSpaceBar()
356 {
357 	return gTrackerState.fShowVolumeSpaceBar->Value();
358 }
359 
360 
361 void
362 TrackerSettings::SetShowVolumeSpaceBar(bool enabled)
363 {
364 	gTrackerState.fShowVolumeSpaceBar->SetValue(enabled);
365 }
366 
367 
368 rgb_color
369 TrackerSettings::UsedSpaceColor()
370 {
371 	return ValueToColor(gTrackerState.fUsedSpaceColor->Value());
372 }
373 
374 
375 void
376 TrackerSettings::SetUsedSpaceColor(rgb_color color)
377 {
378 	gTrackerState.fUsedSpaceColor->ValueChanged(ColorToValue(color));
379 }
380 
381 
382 rgb_color
383 TrackerSettings::FreeSpaceColor()
384 {
385 	return ValueToColor(gTrackerState.fFreeSpaceColor->Value());
386 }
387 
388 
389 void
390 TrackerSettings::SetFreeSpaceColor(rgb_color color)
391 {
392 	gTrackerState.fFreeSpaceColor->ValueChanged(ColorToValue(color));
393 }
394 
395 
396 rgb_color
397 TrackerSettings::WarningSpaceColor()
398 {
399 	return ValueToColor(gTrackerState.fWarningSpaceColor->Value());
400 }
401 
402 
403 void
404 TrackerSettings::SetWarningSpaceColor(rgb_color color)
405 {
406 	gTrackerState.fWarningSpaceColor->ValueChanged(ColorToValue(color));
407 }
408 
409 
410 bool
411 TrackerSettings::ShowFullPathInTitleBar()
412 {
413 	return gTrackerState.fShowFullPathInTitleBar->Value();
414 }
415 
416 
417 void
418 TrackerSettings::SetShowFullPathInTitleBar(bool enabled)
419 {
420 	gTrackerState.fShowFullPathInTitleBar->SetValue(enabled);
421 }
422 
423 
424 bool
425 TrackerSettings::SortFolderNamesFirst()
426 {
427 	return gTrackerState.fSortFolderNamesFirst->Value();
428 }
429 
430 
431 void
432 TrackerSettings::SetSortFolderNamesFirst(bool enabled)
433 {
434 	gTrackerState.fSortFolderNamesFirst->SetValue(enabled);
435 	NameAttributeText::SetSortFolderNamesFirst(enabled);
436 	RealNameAttributeText::SetSortFolderNamesFirst(enabled);
437 }
438 
439 
440 bool
441 TrackerSettings::HideDotFiles()
442 {
443 	return gTrackerState.fHideDotFiles->Value();
444 }
445 
446 
447 void
448 TrackerSettings::SetHideDotFiles(bool hide)
449 {
450 	gTrackerState.fHideDotFiles->SetValue(hide);
451 }
452 
453 
454 bool
455 TrackerSettings::TypeAheadFiltering()
456 {
457 	return gTrackerState.fTypeAheadFiltering->Value();
458 }
459 
460 
461 void
462 TrackerSettings::SetTypeAheadFiltering(bool enabled)
463 {
464 	gTrackerState.fTypeAheadFiltering->SetValue(enabled);
465 }
466 
467 
468 bool
469 TrackerSettings::ShowSelectionWhenInactive()
470 {
471 	return gTrackerState.fShowSelectionWhenInactive->Value();
472 }
473 
474 
475 void
476 TrackerSettings::SetShowSelectionWhenInactive(bool enabled)
477 {
478 	gTrackerState.fShowSelectionWhenInactive->SetValue(enabled);
479 }
480 
481 
482 bool
483 TrackerSettings::TransparentSelection()
484 {
485 	return gTrackerState.fTransparentSelection->Value();
486 }
487 
488 
489 void
490 TrackerSettings::SetTransparentSelection(bool enabled)
491 {
492 	gTrackerState.fTransparentSelection->SetValue(enabled);
493 }
494 
495 
496 bool
497 TrackerSettings::SingleWindowBrowse()
498 {
499 	return gTrackerState.fSingleWindowBrowse->Value();
500 }
501 
502 
503 void
504 TrackerSettings::SetSingleWindowBrowse(bool enabled)
505 {
506 	gTrackerState.fSingleWindowBrowse->SetValue(enabled);
507 }
508 
509 
510 bool
511 TrackerSettings::ShowNavigator()
512 {
513 	return gTrackerState.fShowNavigator->Value();
514 }
515 
516 
517 void
518 TrackerSettings::SetShowNavigator(bool enabled)
519 {
520 	gTrackerState.fShowNavigator->SetValue(enabled);
521 }
522 
523 
524 void
525 TrackerSettings::RecentCounts(int32* applications, int32* documents,
526 	int32* folders)
527 {
528 	if (applications != NULL)
529 		*applications = gTrackerState.fRecentApplicationsCount->Value();
530 
531 	if (documents != NULL)
532 		*documents = gTrackerState.fRecentDocumentsCount->Value();
533 
534 	if (folders != NULL)
535 		*folders = gTrackerState.fRecentFoldersCount->Value();
536 }
537 
538 
539 void
540 TrackerSettings::SetRecentApplicationsCount(int32 count)
541 {
542 	gTrackerState.fRecentApplicationsCount->ValueChanged(count);
543 }
544 
545 
546 void
547 TrackerSettings::SetRecentDocumentsCount(int32 count)
548 {
549 	gTrackerState.fRecentDocumentsCount->ValueChanged(count);
550 }
551 
552 
553 void
554 TrackerSettings::SetRecentFoldersCount(int32 count)
555 {
556 	gTrackerState.fRecentFoldersCount->ValueChanged(count);
557 }
558 
559 
560 bool
561 TrackerSettings::DontMoveFilesToTrash()
562 {
563 	return gTrackerState.fDontMoveFilesToTrash->Value();
564 }
565 
566 
567 void
568 TrackerSettings::SetDontMoveFilesToTrash(bool enabled)
569 {
570 	gTrackerState.fDontMoveFilesToTrash->SetValue(enabled);
571 }
572 
573 
574 bool
575 TrackerSettings::AskBeforeDeleteFile()
576 {
577 	return gTrackerState.fAskBeforeDeleteFile->Value();
578 }
579 
580 
581 void
582 TrackerSettings::SetAskBeforeDeleteFile(bool enabled)
583 {
584 	gTrackerState.fAskBeforeDeleteFile->SetValue(enabled);
585 }
586