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