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