xref: /haiku/src/kits/tracker/SettingsViews.cpp (revision 7eab6b486ebadb54ca3c306601f4b04dd92359fa)
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 "SettingsViews.h"
37 
38 #include <Box.h>
39 #include <Button.h>
40 #include <Catalog.h>
41 #include <CheckBox.h>
42 #include <ColorControl.h>
43 #include <ControlLook.h>
44 #include <LayoutBuilder.h>
45 #include <Locale.h>
46 #include <MenuField.h>
47 #include <NodeMonitor.h>
48 #include <Point.h>
49 #include <PopUpMenu.h>
50 #include <RadioButton.h>
51 #include <StringView.h>
52 
53 #include "Commands.h"
54 #include "DeskWindow.h"
55 #include "Model.h"
56 #include "Tracker.h"
57 #include "TrackerDefaults.h"
58 #include "WidgetAttributeText.h"
59 
60 
61 static const uint32 kSpaceBarSwitchColor = 'SBsc';
62 
63 
64 static void
65 send_bool_notices(uint32 what, const char* name, bool value)
66 {
67 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
68 	if (tracker == NULL)
69 		return;
70 
71 	BMessage message;
72 	message.AddBool(name, value);
73 	tracker->SendNotices(what, &message);
74 }
75 
76 
77 #undef B_TRANSLATION_CONTEXT
78 #define B_TRANSLATION_CONTEXT "SettingsView"
79 
80 
81 //	#pragma mark - SettingsView
82 
83 
84 SettingsView::SettingsView(const char* name)
85 	:
86 	BGroupView(name)
87 {
88 }
89 
90 
91 SettingsView::~SettingsView()
92 {
93 }
94 
95 
96 /*!
97 	The inherited functions should set the default values
98 	and update the UI gadgets. The latter can by done by
99 	calling ShowCurrentSettings().
100 */
101 void
102 SettingsView::SetDefaults()
103 {
104 }
105 
106 
107 /*!
108 	This function is used by the window to tell whether
109 	it can ghost the defaults button or not. It doesn't
110 	shows the default settings, this function should
111 	return true.
112 */
113 bool
114 SettingsView::IsDefaultable() const
115 {
116 	return true;
117 }
118 
119 
120 /*!
121 	The inherited functions should set the values that was
122 	active when the settings window opened. It should also
123 	update the UI widgets accordingly, preferrable by calling
124 	ShowCurrentSettings().
125 */
126 void
127 SettingsView::Revert()
128 {
129 }
130 
131 
132 /*!
133 	This function is called when the window is shown to let
134 	the settings views record the state to revert to.
135 */
136 void
137 SettingsView::RecordRevertSettings()
138 {
139 }
140 
141 
142 /*!
143 	This function is used by the window to tell the view
144 	to display the current settings in the tracker.
145 */
146 void
147 SettingsView::ShowCurrentSettings()
148 {
149 }
150 
151 
152 /*!
153 	This function is used by the window to tell whether
154 	it can ghost the revert button or not. It it shows the
155 	reverted settings, this function should return true.
156 */
157 bool
158 SettingsView::IsRevertable() const
159 {
160 	return true;
161 }
162 
163 
164 // #pragma mark - DesktopSettingsView
165 
166 
167 DesktopSettingsView::DesktopSettingsView()
168 	:
169 	SettingsView("DesktopSettingsView"),
170 	fShowDisksIconRadioButton(NULL),
171 	fMountVolumesOntoDesktopRadioButton(NULL),
172 	fMountSharedVolumesOntoDesktopCheckBox(NULL),
173 	fShowDisksIcon(kDefaultShowDisksIcon),
174 	fMountVolumesOntoDesktop(kDefaultMountVolumesOntoDesktop),
175 	fMountSharedVolumesOntoDesktop(kDefaultMountSharedVolumesOntoDesktop),
176 	fIntegrateNonBootBeOSDesktops(false),
177 	fEjectWhenUnmounting(kDefaultEjectWhenUnmounting)
178 {
179 	fShowDisksIconRadioButton = new BRadioButton("",
180 		B_TRANSLATE("Show Disks icon"),
181 		new BMessage(kShowDisksIconChanged));
182 
183 	fMountVolumesOntoDesktopRadioButton = new BRadioButton("",
184 		B_TRANSLATE("Show volumes on Desktop"),
185 		new BMessage(kVolumesOnDesktopChanged));
186 
187 	fMountSharedVolumesOntoDesktopCheckBox = new BCheckBox("",
188 		B_TRANSLATE("Show shared volumes on Desktop"),
189 		new BMessage(kVolumesOnDesktopChanged));
190 
191 	const float spacing = be_control_look->DefaultItemSpacing();
192 
193 	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
194 		.Add(fShowDisksIconRadioButton)
195 		.Add(fMountVolumesOntoDesktopRadioButton)
196 		.AddGroup(B_VERTICAL, 0)
197 			.Add(fMountSharedVolumesOntoDesktopCheckBox)
198 			.SetInsets(spacing * 2, 0, 0, 0)
199 			.End()
200 		.AddGlue()
201 		.SetInsets(spacing);
202 }
203 
204 
205 void
206 DesktopSettingsView::AttachedToWindow()
207 {
208 	fShowDisksIconRadioButton->SetTarget(this);
209 	fMountVolumesOntoDesktopRadioButton->SetTarget(this);
210 	fMountSharedVolumesOntoDesktopCheckBox->SetTarget(this);
211 }
212 
213 
214 void
215 DesktopSettingsView::MessageReceived(BMessage* message)
216 {
217 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
218 	if (tracker == NULL)
219 		return;
220 
221 	TrackerSettings settings;
222 
223 	switch (message->what) {
224 		case kShowDisksIconChanged:
225 		{
226 			// Turn on and off related settings:
227 			fMountVolumesOntoDesktopRadioButton->SetValue(
228 				!(fShowDisksIconRadioButton->Value() == 1));
229 			fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(
230 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
231 
232 			// Set the new settings in the tracker:
233 			settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1);
234 			settings.SetMountVolumesOntoDesktop(
235 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
236 			settings.SetMountSharedVolumesOntoDesktop(
237 				fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
238 
239 			// Construct the notification message:
240 			BMessage notificationMessage;
241 			notificationMessage.AddBool("ShowDisksIcon",
242 				fShowDisksIconRadioButton->Value() == 1);
243 			notificationMessage.AddBool("MountVolumesOntoDesktop",
244 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
245 			notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
246 				fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
247 
248 			// Send the notification message:
249 			tracker->SendNotices(kVolumesOnDesktopChanged,
250 				&notificationMessage);
251 
252 			// Tell the settings window the contents have changed:
253 			Window()->PostMessage(kSettingsContentsModified);
254 			break;
255 		}
256 
257 		case kVolumesOnDesktopChanged:
258 		{
259 			// Turn on and off related settings:
260 			fShowDisksIconRadioButton->SetValue(
261 				!(fMountVolumesOntoDesktopRadioButton->Value() == 1));
262 			fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(
263 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
264 
265 			// Set the new settings in the tracker:
266 			settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1);
267 			settings.SetMountVolumesOntoDesktop(
268 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
269 			settings.SetMountSharedVolumesOntoDesktop(
270 				fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
271 
272 			// Construct the notification message:
273 			BMessage notificationMessage;
274 			notificationMessage.AddBool("ShowDisksIcon",
275 				fShowDisksIconRadioButton->Value() == 1);
276 			notificationMessage.AddBool("MountVolumesOntoDesktop",
277 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
278 			notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
279 				fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
280 
281 			// Send the notification message:
282 			tracker->SendNotices(kVolumesOnDesktopChanged, &notificationMessage);
283 
284 			// Tell the settings window the contents have changed:
285 			Window()->PostMessage(kSettingsContentsModified);
286 			break;
287 		}
288 
289 		default:
290 			_inherited::MessageReceived(message);
291 			break;
292 	}
293 }
294 
295 
296 void
297 DesktopSettingsView::SetDefaults()
298 {
299 	// ToDo: Avoid the duplication of the default values.
300 	TrackerSettings settings;
301 
302 	settings.SetShowDisksIcon(kDefaultShowDisksIcon);
303 	settings.SetMountVolumesOntoDesktop(kDefaultMountVolumesOntoDesktop);
304 	settings.SetMountSharedVolumesOntoDesktop(kDefaultMountSharedVolumesOntoDesktop);
305 	settings.SetEjectWhenUnmounting(kDefaultEjectWhenUnmounting);
306 
307 	ShowCurrentSettings();
308 	_SendNotices();
309 }
310 
311 
312 bool
313 DesktopSettingsView::IsDefaultable() const
314 {
315 	TrackerSettings settings;
316 
317 	return settings.ShowDisksIcon() != kDefaultShowDisksIcon
318 		|| settings.MountVolumesOntoDesktop() != kDefaultMountVolumesOntoDesktop
319 		|| settings.MountSharedVolumesOntoDesktop() != kDefaultMountSharedVolumesOntoDesktop
320 		|| settings.EjectWhenUnmounting() != kDefaultEjectWhenUnmounting;
321 }
322 
323 
324 void
325 DesktopSettingsView::Revert()
326 {
327 	TrackerSettings settings;
328 
329 	settings.SetShowDisksIcon(fShowDisksIcon);
330 	settings.SetMountVolumesOntoDesktop(fMountVolumesOntoDesktop);
331 	settings.SetMountSharedVolumesOntoDesktop(fMountSharedVolumesOntoDesktop);
332 	settings.SetEjectWhenUnmounting(fEjectWhenUnmounting);
333 
334 	ShowCurrentSettings();
335 	_SendNotices();
336 }
337 
338 
339 void
340 DesktopSettingsView::_SendNotices()
341 {
342 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
343 	if (tracker == NULL)
344 		return;
345 
346 	// Construct the notification message:
347 	BMessage notificationMessage;
348 	notificationMessage.AddBool("ShowDisksIcon",
349 		fShowDisksIconRadioButton->Value() == 1);
350 	notificationMessage.AddBool("MountVolumesOntoDesktop",
351 		fMountVolumesOntoDesktopRadioButton->Value() == 1);
352 	notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
353 		fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
354 
355 	// Send notices to the tracker about the change:
356 	tracker->SendNotices(kVolumesOnDesktopChanged, &notificationMessage);
357 	tracker->SendNotices(kDesktopIntegrationChanged, &notificationMessage);
358 }
359 
360 
361 void
362 DesktopSettingsView::ShowCurrentSettings()
363 {
364 	TrackerSettings settings;
365 
366 	fShowDisksIconRadioButton->SetValue(settings.ShowDisksIcon());
367 	fMountVolumesOntoDesktopRadioButton->SetValue(
368 		settings.MountVolumesOntoDesktop());
369 
370 	fMountSharedVolumesOntoDesktopCheckBox->SetValue(
371 		settings.MountSharedVolumesOntoDesktop());
372 	fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(
373 		settings.MountVolumesOntoDesktop());
374 }
375 
376 
377 void
378 DesktopSettingsView::RecordRevertSettings()
379 {
380 	TrackerSettings settings;
381 
382 	fShowDisksIcon = settings.ShowDisksIcon();
383 	fMountVolumesOntoDesktop = settings.MountVolumesOntoDesktop();
384 	fMountSharedVolumesOntoDesktop = settings.MountSharedVolumesOntoDesktop();
385 	fEjectWhenUnmounting = settings.EjectWhenUnmounting();
386 }
387 
388 
389 bool
390 DesktopSettingsView::IsRevertable() const
391 {
392 	return fShowDisksIcon != (fShowDisksIconRadioButton->Value() > 0)
393 		|| fMountVolumesOntoDesktop !=
394 			(fMountVolumesOntoDesktopRadioButton->Value() > 0)
395 		|| fMountSharedVolumesOntoDesktop !=
396 			(fMountSharedVolumesOntoDesktopCheckBox->Value() > 0);
397 }
398 
399 
400 // #pragma mark - WindowsSettingsView
401 
402 
403 WindowsSettingsView::WindowsSettingsView()
404 	:
405 	SettingsView("WindowsSettingsView"),
406 	fShowFullPathInTitleBarCheckBox(NULL),
407 	fSingleWindowBrowseCheckBox(NULL),
408 	fShowNavigatorCheckBox(NULL),
409 	fOutlineSelectionCheckBox(NULL),
410 	fSortFolderNamesFirstCheckBox(NULL),
411 	fHideDotFilesCheckBox(NULL),
412 	fTypeAheadFilteringCheckBox(NULL),
413 	fGenerateImageThumbnailsCheckBox(NULL),
414 	fShowFullPathInTitleBar(kDefaultShowFullPathInTitleBar),
415 	fSingleWindowBrowse(kDefaultSingleWindowBrowse),
416 	fShowNavigator(kDefaultShowNavigator),
417 	fTransparentSelection(kDefaultTransparentSelection),
418 	fSortFolderNamesFirst(kDefaultSortFolderNamesFirst),
419 	fHideDotFiles(kDefaultHideDotFiles),
420 	fTypeAheadFiltering(kDefaultTypeAheadFiltering),
421 	fGenerateImageThumbnails(kDefaultGenerateImageThumbnails)
422 {
423 	fShowFullPathInTitleBarCheckBox = new BCheckBox("",
424 		B_TRANSLATE("Show folder location in title tab"),
425 		new BMessage(kWindowsShowFullPathChanged));
426 
427 	fSingleWindowBrowseCheckBox = new BCheckBox("",
428 		B_TRANSLATE("Single window navigation"),
429 		new BMessage(kSingleWindowBrowseChanged));
430 
431 	fShowNavigatorCheckBox = new BCheckBox("",
432 		B_TRANSLATE("Show navigator"),
433 		new BMessage(kShowNavigatorChanged));
434 
435 	fOutlineSelectionCheckBox = new BCheckBox("",
436 		B_TRANSLATE("Outline selection rectangle only"),
437 		new BMessage(kTransparentSelectionChanged));
438 
439 	fSortFolderNamesFirstCheckBox = new BCheckBox("",
440 		B_TRANSLATE("List folders first"),
441 		new BMessage(kSortFolderNamesFirstChanged));
442 
443 	fHideDotFilesCheckBox = new BCheckBox("",
444 		B_TRANSLATE("Hide dotfiles"),
445 		new BMessage(kHideDotFilesChanged));
446 
447 	fTypeAheadFilteringCheckBox = new BCheckBox("",
448 		B_TRANSLATE("Enable type-ahead filtering"),
449 		new BMessage(kTypeAheadFilteringChanged));
450 
451 	fGenerateImageThumbnailsCheckBox = new BCheckBox("",
452 		B_TRANSLATE("Generate image thumbnails"),
453 		new BMessage(kGenerateImageThumbnailsChanged));
454 
455 	const float spacing = be_control_look->DefaultItemSpacing();
456 
457 	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
458 		.AddGroup(B_VERTICAL, 0)
459 			.Add(fShowFullPathInTitleBarCheckBox)
460 			.Add(fSingleWindowBrowseCheckBox)
461 			.End()
462 		.AddGroup(B_VERTICAL)
463 			.Add(fShowNavigatorCheckBox)
464 			.SetInsets(spacing * 2, 0, 0, 0)
465 			.End()
466 		.AddGroup(B_VERTICAL, 0)
467 			.Add(fOutlineSelectionCheckBox)
468 			.Add(fSortFolderNamesFirstCheckBox)
469 			.Add(fHideDotFilesCheckBox)
470 			.Add(fTypeAheadFilteringCheckBox)
471 			.Add(fGenerateImageThumbnailsCheckBox)
472 			.End()
473 		.AddGlue()
474 		.SetInsets(spacing);
475 }
476 
477 
478 void
479 WindowsSettingsView::AttachedToWindow()
480 {
481 	fSingleWindowBrowseCheckBox->SetTarget(this);
482 	fShowNavigatorCheckBox->SetTarget(this);
483 	fShowFullPathInTitleBarCheckBox->SetTarget(this);
484 	fOutlineSelectionCheckBox->SetTarget(this);
485 	fSortFolderNamesFirstCheckBox->SetTarget(this);
486 	fHideDotFilesCheckBox->SetTarget(this);
487 	fTypeAheadFilteringCheckBox->SetTarget(this);
488 	fGenerateImageThumbnailsCheckBox->SetTarget(this);
489 }
490 
491 
492 void
493 WindowsSettingsView::MessageReceived(BMessage* message)
494 {
495 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
496 	if (tracker == NULL)
497 		return;
498 
499 	TrackerSettings settings;
500 
501 	switch (message->what) {
502 		case kWindowsShowFullPathChanged:
503 			settings.SetShowFullPathInTitleBar(
504 				fShowFullPathInTitleBarCheckBox->Value() == 1);
505 			tracker->SendNotices(kWindowsShowFullPathChanged);
506 			Window()->PostMessage(kSettingsContentsModified);
507 			break;
508 
509 		case kSingleWindowBrowseChanged:
510 			settings.SetSingleWindowBrowse(
511 				fSingleWindowBrowseCheckBox->Value() == 1);
512 			if (fSingleWindowBrowseCheckBox->Value() == 0) {
513 				fShowNavigatorCheckBox->SetEnabled(false);
514 				settings.SetShowNavigator(0);
515 			} else {
516 				fShowNavigatorCheckBox->SetEnabled(true);
517 				settings.SetShowNavigator(
518 					fShowNavigatorCheckBox->Value() != 0);
519 			}
520 			tracker->SendNotices(kShowNavigatorChanged);
521 			tracker->SendNotices(kSingleWindowBrowseChanged);
522 			Window()->PostMessage(kSettingsContentsModified);
523 			break;
524 
525 		case kShowNavigatorChanged:
526 			settings.SetShowNavigator(fShowNavigatorCheckBox->Value() == 1);
527 			tracker->SendNotices(kShowNavigatorChanged);
528 			Window()->PostMessage(kSettingsContentsModified);
529 			break;
530 
531 		case kTransparentSelectionChanged:
532 		{
533 			settings.SetTransparentSelection(
534 				fOutlineSelectionCheckBox->Value() == B_CONTROL_OFF);
535 
536 			// Make the notification message and send it to the tracker:
537 			send_bool_notices(kTransparentSelectionChanged,
538 				"TransparentSelection", settings.TransparentSelection());
539 
540 			Window()->PostMessage(kSettingsContentsModified);
541 			break;
542 		}
543 
544 		case kSortFolderNamesFirstChanged:
545 		{
546 			settings.SetSortFolderNamesFirst(
547 				fSortFolderNamesFirstCheckBox->Value() == 1);
548 
549 			// Make the notification message and send it to the tracker:
550 			send_bool_notices(kSortFolderNamesFirstChanged,
551 				"SortFolderNamesFirst",
552 				fSortFolderNamesFirstCheckBox->Value() == 1);
553 
554 			Window()->PostMessage(kSettingsContentsModified);
555 			break;
556 		}
557 
558 		case kHideDotFilesChanged:
559 		{
560 			settings.SetHideDotFiles(
561 				fHideDotFilesCheckBox->Value() == 1);
562 			send_bool_notices(kHideDotFilesChanged,
563 				"HideDotFiles",
564 				fHideDotFilesCheckBox->Value() == 1);
565 			Window()->PostMessage(kSettingsContentsModified);
566 			break;
567 		}
568 
569 		case kTypeAheadFilteringChanged:
570 		{
571 			settings.SetTypeAheadFiltering(
572 				fTypeAheadFilteringCheckBox->Value() == 1);
573 			send_bool_notices(kTypeAheadFilteringChanged,
574 				"TypeAheadFiltering",
575 				fTypeAheadFilteringCheckBox->Value() == 1);
576 			Window()->PostMessage(kSettingsContentsModified);
577 			break;
578 		}
579 
580 		case kGenerateImageThumbnailsChanged:
581 		{
582 			settings.SetGenerateImageThumbnails(
583 				fGenerateImageThumbnailsCheckBox->Value() == 1);
584 			send_bool_notices(kGenerateImageThumbnailsChanged,
585 				"GenerateImageThumbnails",
586 				fGenerateImageThumbnailsCheckBox->Value() == 1);
587 			Window()->PostMessage(kSettingsContentsModified);
588 			break;
589 		}
590 
591 		default:
592 			_inherited::MessageReceived(message);
593 			break;
594 	}
595 }
596 
597 
598 void
599 WindowsSettingsView::SetDefaults()
600 {
601 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
602 	if (tracker == NULL)
603 		return;
604 
605 	TrackerSettings settings;
606 
607 	if (settings.ShowFullPathInTitleBar() != kDefaultShowFullPathInTitleBar) {
608 		settings.SetShowFullPathInTitleBar(kDefaultShowFullPathInTitleBar);
609 		tracker->SendNotices(kWindowsShowFullPathChanged);
610 	}
611 
612 	if (settings.SingleWindowBrowse() != kDefaultSingleWindowBrowse) {
613 		settings.SetSingleWindowBrowse(kDefaultSingleWindowBrowse);
614 		tracker->SendNotices(kSingleWindowBrowseChanged);
615 	}
616 
617 	if (settings.ShowNavigator() != kDefaultShowNavigator) {
618 		settings.SetShowNavigator(kDefaultShowNavigator);
619 		tracker->SendNotices(kShowNavigatorChanged);
620 	}
621 
622 	if (settings.TransparentSelection() != kDefaultTransparentSelection) {
623 		settings.SetTransparentSelection(kDefaultTransparentSelection);
624 		send_bool_notices(kTransparentSelectionChanged,
625 			"TransparentSelection", kDefaultTransparentSelection);
626 	}
627 
628 	if (settings.SortFolderNamesFirst() != kDefaultSortFolderNamesFirst) {
629 		settings.SetSortFolderNamesFirst(kDefaultSortFolderNamesFirst);
630 		send_bool_notices(kSortFolderNamesFirstChanged,
631 			"SortFolderNamesFirst", kDefaultSortFolderNamesFirst);
632 	}
633 
634 	if (settings.HideDotFiles() != kDefaultHideDotFiles) {
635 		settings.SetHideDotFiles(kDefaultHideDotFiles);
636 		send_bool_notices(kHideDotFilesChanged,
637 			"HideDotFiles", kDefaultHideDotFiles);
638 	}
639 
640 	if (settings.TypeAheadFiltering() != kDefaultTypeAheadFiltering) {
641 		settings.SetTypeAheadFiltering(kDefaultTypeAheadFiltering);
642 		send_bool_notices(kTypeAheadFilteringChanged,
643 			"TypeAheadFiltering", kDefaultTypeAheadFiltering);
644 	}
645 
646 	if (settings.GenerateImageThumbnails() != kDefaultGenerateImageThumbnails) {
647 		settings.SetGenerateImageThumbnails(kDefaultGenerateImageThumbnails);
648 		send_bool_notices(kGenerateImageThumbnailsChanged,
649 			"GenerateImageThumbnails", kDefaultGenerateImageThumbnails);
650 	}
651 
652 	ShowCurrentSettings();
653 }
654 
655 
656 bool
657 WindowsSettingsView::IsDefaultable() const
658 {
659 	TrackerSettings settings;
660 
661 	return settings.ShowFullPathInTitleBar() != kDefaultShowFullPathInTitleBar
662 		|| settings.SingleWindowBrowse() != kDefaultSingleWindowBrowse
663 		|| settings.ShowNavigator() != kDefaultShowNavigator
664 		|| settings.TransparentSelection() != kDefaultTransparentSelection
665 		|| settings.SortFolderNamesFirst() != kDefaultSortFolderNamesFirst
666 		|| settings.HideDotFiles() != kDefaultHideDotFiles
667 		|| settings.TypeAheadFiltering() != kDefaultTypeAheadFiltering
668 		|| settings.GenerateImageThumbnails() != kDefaultGenerateImageThumbnails;
669 }
670 
671 
672 void
673 WindowsSettingsView::Revert()
674 {
675 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
676 	if (tracker == NULL)
677 		return;
678 
679 	TrackerSettings settings;
680 
681 	if (settings.ShowFullPathInTitleBar() != fShowFullPathInTitleBar) {
682 		settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBar);
683 		tracker->SendNotices(kWindowsShowFullPathChanged);
684 	}
685 
686 	if (settings.SingleWindowBrowse() != fSingleWindowBrowse) {
687 		settings.SetSingleWindowBrowse(fSingleWindowBrowse);
688 		tracker->SendNotices(kSingleWindowBrowseChanged);
689 	}
690 
691 	if (settings.ShowNavigator() != fShowNavigator) {
692 		settings.SetShowNavigator(fShowNavigator);
693 		tracker->SendNotices(kShowNavigatorChanged);
694 	}
695 
696 	if (settings.TransparentSelection() != fTransparentSelection) {
697 		settings.SetTransparentSelection(fTransparentSelection);
698 		send_bool_notices(kTransparentSelectionChanged,
699 			"TransparentSelection", fTransparentSelection);
700 	}
701 
702 	if (settings.SortFolderNamesFirst() != fSortFolderNamesFirst) {
703 		settings.SetSortFolderNamesFirst(fSortFolderNamesFirst);
704 		send_bool_notices(kSortFolderNamesFirstChanged,
705 			"SortFolderNamesFirst", fSortFolderNamesFirst);
706 	}
707 
708 	if (settings.HideDotFiles() != fHideDotFiles) {
709 		settings.SetSortFolderNamesFirst(fHideDotFiles);
710 		send_bool_notices(kHideDotFilesChanged,
711 			"HideDotFiles", fHideDotFiles);
712 	}
713 
714 	if (settings.TypeAheadFiltering() != fTypeAheadFiltering) {
715 		settings.SetTypeAheadFiltering(fTypeAheadFiltering);
716 		send_bool_notices(kTypeAheadFilteringChanged,
717 			"TypeAheadFiltering", fTypeAheadFiltering);
718 	}
719 
720 	if (settings.GenerateImageThumbnails() != fGenerateImageThumbnails) {
721 		settings.SetGenerateImageThumbnails(fGenerateImageThumbnails);
722 		send_bool_notices(kGenerateImageThumbnailsChanged,
723 			"GenerateImageThumbnails", fGenerateImageThumbnails);
724 	}
725 
726 	ShowCurrentSettings();
727 }
728 
729 
730 void
731 WindowsSettingsView::ShowCurrentSettings()
732 {
733 	TrackerSettings settings;
734 
735 	fShowFullPathInTitleBarCheckBox->SetValue(
736 		settings.ShowFullPathInTitleBar());
737 	fSingleWindowBrowseCheckBox->SetValue(settings.SingleWindowBrowse());
738 	fShowNavigatorCheckBox->SetEnabled(settings.SingleWindowBrowse());
739 	fShowNavigatorCheckBox->SetValue(settings.ShowNavigator());
740 	fOutlineSelectionCheckBox->SetValue(settings.TransparentSelection()
741 		? B_CONTROL_OFF : B_CONTROL_ON);
742 	fSortFolderNamesFirstCheckBox->SetValue(settings.SortFolderNamesFirst());
743 	fHideDotFilesCheckBox->SetValue(settings.HideDotFiles());
744 	fTypeAheadFilteringCheckBox->SetValue(settings.TypeAheadFiltering());
745 	fGenerateImageThumbnailsCheckBox->SetValue(
746 		settings.GenerateImageThumbnails());
747 }
748 
749 
750 void
751 WindowsSettingsView::RecordRevertSettings()
752 {
753 	TrackerSettings settings;
754 
755 	fShowFullPathInTitleBar = settings.ShowFullPathInTitleBar();
756 	fSingleWindowBrowse = settings.SingleWindowBrowse();
757 	fShowNavigator = settings.ShowNavigator();
758 	fTransparentSelection = settings.TransparentSelection();
759 	fSortFolderNamesFirst = settings.SortFolderNamesFirst();
760 	fHideDotFiles = settings.HideDotFiles();
761 	fTypeAheadFiltering = settings.TypeAheadFiltering();
762 	fGenerateImageThumbnails = settings.GenerateImageThumbnails();
763 }
764 
765 
766 bool
767 WindowsSettingsView::IsRevertable() const
768 {
769 	TrackerSettings settings;
770 
771 	return fShowFullPathInTitleBar != settings.ShowFullPathInTitleBar()
772 		|| fSingleWindowBrowse != settings.SingleWindowBrowse()
773 		|| fShowNavigator != settings.ShowNavigator()
774 		|| fTransparentSelection != settings.TransparentSelection()
775 		|| fSortFolderNamesFirst != settings.SortFolderNamesFirst()
776 		|| fHideDotFiles != settings.HideDotFiles()
777 		|| fTypeAheadFiltering != settings.TypeAheadFiltering()
778 		|| fGenerateImageThumbnails != settings.GenerateImageThumbnails();
779 }
780 
781 
782 // #pragma mark - SpaceBarSettingsView
783 
784 
785 SpaceBarSettingsView::SpaceBarSettingsView()
786 	:
787 	SettingsView("SpaceBarSettingsView")
788 {
789 	fSpaceBarShowCheckBox = new BCheckBox("",
790 		B_TRANSLATE("Show space bars on volumes"),
791 		new BMessage(kUpdateVolumeSpaceBar));
792 
793 	BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING);
794 	menu->SetFont(be_plain_font);
795 
796 	BMenuItem* item;
797 	menu->AddItem(item = new BMenuItem(
798 		B_TRANSLATE("Used space color"),
799 		new BMessage(kSpaceBarSwitchColor)));
800 	item->SetMarked(true);
801 	fCurrentColor = 0;
802 	menu->AddItem(new BMenuItem(
803 		B_TRANSLATE("Free space color"),
804 		new BMessage(kSpaceBarSwitchColor)));
805 	menu->AddItem(new BMenuItem(
806 		B_TRANSLATE("Warning space color"),
807 		new BMessage(kSpaceBarSwitchColor)));
808 
809 	fColorPicker = new BMenuField("menu", NULL, menu);
810 
811 	fColorControl = new BColorControl(BPoint(0, 0),
812 		B_CELLS_16x16, 1, "SpaceColorControl",
813 		new BMessage(kSpaceBarColorChanged));
814 	fColorControl->SetValue(TrackerSettings().UsedSpaceColor());
815 
816 	BBox* box = new BBox("box");
817 	box->SetLabel(fColorPicker);
818 	box->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL)
819 		.Add(fColorControl)
820 		.SetInsets(B_USE_DEFAULT_SPACING)
821 		.View());
822 
823 	BLayoutBuilder::Group<>(this, B_VERTICAL)
824 		.Add(fSpaceBarShowCheckBox)
825 		.Add(box)
826 		.AddGlue()
827 		.SetInsets(B_USE_DEFAULT_SPACING);
828 }
829 
830 
831 SpaceBarSettingsView::~SpaceBarSettingsView()
832 {
833 }
834 
835 
836 void
837 SpaceBarSettingsView::AttachedToWindow()
838 {
839 	fSpaceBarShowCheckBox->SetTarget(this);
840 	fColorControl->SetTarget(this);
841 	fColorPicker->Menu()->SetTargetForItems(this);
842 }
843 
844 
845 void
846 SpaceBarSettingsView::MessageReceived(BMessage* message)
847 {
848 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
849 	if (tracker == NULL)
850 		return;
851 
852 	TrackerSettings settings;
853 
854 	switch (message->what) {
855 		case kUpdateVolumeSpaceBar:
856 		{
857 			settings.SetShowVolumeSpaceBar(
858 				fSpaceBarShowCheckBox->Value() == 1);
859 			Window()->PostMessage(kSettingsContentsModified);
860 			tracker->PostMessage(kShowVolumeSpaceBar);
861 			break;
862 		}
863 
864 		case kSpaceBarSwitchColor:
865 		{
866 			fCurrentColor = message->FindInt32("index");
867 			switch (fCurrentColor) {
868 				case 0:
869 					fColorControl->SetValue(settings.UsedSpaceColor());
870 					break;
871 
872 				case 1:
873 					fColorControl->SetValue(settings.FreeSpaceColor());
874 					break;
875 
876 				case 2:
877 					fColorControl->SetValue(settings.WarningSpaceColor());
878 					break;
879 			}
880 			break;
881 		}
882 
883 		case kSpaceBarColorChanged:
884 		{
885 			rgb_color color = fColorControl->ValueAsColor();
886 			color.alpha = kDefaultSpaceBarAlpha;
887 				// alpha is ignored by BColorControl but is checked
888 				// in equalities
889 
890 			switch (fCurrentColor) {
891 				case 0:
892 					settings.SetUsedSpaceColor(color);
893 					break;
894 
895 				case 1:
896 					settings.SetFreeSpaceColor(color);
897 					break;
898 
899 				case 2:
900 					settings.SetWarningSpaceColor(color);
901 					break;
902 			}
903 
904 			BWindow* window = Window();
905 			if (window != NULL)
906 				window->PostMessage(kSettingsContentsModified);
907 
908 			tracker->PostMessage(kSpaceBarColorChanged);
909 			break;
910 		}
911 
912 		default:
913 			_inherited::MessageReceived(message);
914 			break;
915 	}
916 }
917 
918 
919 void
920 SpaceBarSettingsView::SetDefaults()
921 {
922 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
923 	if (tracker == NULL)
924 		return;
925 
926 	TrackerSettings settings;
927 
928 	if (!settings.ShowVolumeSpaceBar()) {
929 		settings.SetShowVolumeSpaceBar(true);
930 		send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", kDefaultShowVolumeSpaceBar);
931 	}
932 
933 	if (settings.UsedSpaceColor() != kDefaultUsedSpaceColor
934 		|| settings.FreeSpaceColor() != kDefaultFreeSpaceColor
935 		|| settings.WarningSpaceColor() != kDefaultWarningSpaceColor) {
936 		settings.SetUsedSpaceColor(kDefaultUsedSpaceColor);
937 		settings.SetFreeSpaceColor(kDefaultFreeSpaceColor);
938 		settings.SetWarningSpaceColor(kDefaultWarningSpaceColor);
939 		tracker->SendNotices(kSpaceBarColorChanged);
940 	}
941 
942 	ShowCurrentSettings();
943 }
944 
945 
946 bool
947 SpaceBarSettingsView::IsDefaultable() const
948 {
949 	TrackerSettings settings;
950 
951 	return settings.ShowVolumeSpaceBar() != kDefaultShowVolumeSpaceBar
952 		|| settings.UsedSpaceColor() != kDefaultUsedSpaceColor
953 		|| settings.FreeSpaceColor() != kDefaultFreeSpaceColor
954 		|| settings.WarningSpaceColor() != kDefaultWarningSpaceColor;
955 }
956 
957 
958 void
959 SpaceBarSettingsView::Revert()
960 {
961 	TTracker* tracker = dynamic_cast<TTracker*>(be_app);
962 	if (tracker == NULL)
963 		return;
964 
965 	TrackerSettings settings;
966 
967 	if (settings.ShowVolumeSpaceBar() != fSpaceBarShow) {
968 		settings.SetShowVolumeSpaceBar(fSpaceBarShow);
969 		send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar",
970 			fSpaceBarShow);
971 	}
972 
973 	if (settings.UsedSpaceColor() != fUsedSpaceColor
974 		|| settings.FreeSpaceColor() != fFreeSpaceColor
975 		|| settings.WarningSpaceColor() != fWarningSpaceColor) {
976 		settings.SetUsedSpaceColor(fUsedSpaceColor);
977 		settings.SetFreeSpaceColor(fFreeSpaceColor);
978 		settings.SetWarningSpaceColor(fWarningSpaceColor);
979 		tracker->SendNotices(kSpaceBarColorChanged);
980 	}
981 
982 	ShowCurrentSettings();
983 }
984 
985 
986 void
987 SpaceBarSettingsView::ShowCurrentSettings()
988 {
989 	TrackerSettings settings;
990 
991 	fSpaceBarShowCheckBox->SetValue(settings.ShowVolumeSpaceBar());
992 
993 	switch (fCurrentColor) {
994 		case 0:
995 			fColorControl->SetValue(settings.UsedSpaceColor());
996 			break;
997 		case 1:
998 			fColorControl->SetValue(settings.FreeSpaceColor());
999 			break;
1000 		case 2:
1001 			fColorControl->SetValue(settings.WarningSpaceColor());
1002 			break;
1003 	}
1004 }
1005 
1006 
1007 void
1008 SpaceBarSettingsView::RecordRevertSettings()
1009 {
1010 	TrackerSettings settings;
1011 
1012 	fSpaceBarShow = settings.ShowVolumeSpaceBar();
1013 	fUsedSpaceColor = settings.UsedSpaceColor();
1014 	fFreeSpaceColor = settings.FreeSpaceColor();
1015 	fWarningSpaceColor = settings.WarningSpaceColor();
1016 }
1017 
1018 
1019 bool
1020 SpaceBarSettingsView::IsRevertable() const
1021 {
1022 	TrackerSettings settings;
1023 
1024 	return fSpaceBarShow != settings.ShowVolumeSpaceBar()
1025 		|| fUsedSpaceColor != settings.UsedSpaceColor()
1026 		|| fFreeSpaceColor != settings.FreeSpaceColor()
1027 		|| fWarningSpaceColor != settings.WarningSpaceColor();
1028 }
1029