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