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