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