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