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