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