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