xref: /haiku/src/kits/tracker/SettingsViews.cpp (revision e7d5c75dce28921de0dc981ed840205a67a0c0e5)
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 "libtracker"
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)
195 			.Add(fShowDisksIconRadioButton)
196 			.Add(fMountVolumesOntoDesktopRadioButton)
197 			.AddGroup(B_VERTICAL)
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)
438 			.AddGroup(B_VERTICAL)
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)
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 	BGroupLayoutBuilder(this)
734 		.AddGroup(B_VERTICAL)
735 			.Add(fSpaceBarShowCheckBox)
736 			.Add(box)
737 		.AddGlue()
738 		.End()
739 		.SetInsets(spacing, spacing, spacing, spacing);
740 
741 }
742 
743 
744 SpaceBarSettingsView::~SpaceBarSettingsView()
745 {
746 }
747 
748 
749 void
750 SpaceBarSettingsView::AttachedToWindow()
751 {
752 	fSpaceBarShowCheckBox->SetTarget(this);
753 	fColorControl->SetTarget(this);
754 	fColorPicker->Menu()->SetTargetForItems(this);
755 }
756 
757 
758 void
759 SpaceBarSettingsView::MessageReceived(BMessage *message)
760 {
761 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
762 	if (!tracker)
763 		return;
764 	TrackerSettings settings;
765 
766 	switch (message->what) {
767 		case kUpdateVolumeSpaceBar:
768 		{
769 			settings.SetShowVolumeSpaceBar(fSpaceBarShowCheckBox->Value() == 1);
770 			Window()->PostMessage(kSettingsContentsModified);
771 			tracker->PostMessage(kShowVolumeSpaceBar);
772 			break;
773 		}
774 
775 		case kSpaceBarSwitchColor:
776 		{
777 			fCurrentColor = message->FindInt32("index");
778 			switch (fCurrentColor) {
779 				case 0:
780 					fColorControl->SetValue(settings.UsedSpaceColor());
781 					break;
782 				case 1:
783 					fColorControl->SetValue(settings.FreeSpaceColor());
784 					break;
785 				case 2:
786 					fColorControl->SetValue(settings.WarningSpaceColor());
787 					break;
788 			}
789 			break;
790 		}
791 
792 		case kSpaceBarColorChanged:
793 		{
794 			rgb_color color = fColorControl->ValueAsColor();
795 			color.alpha = kSpaceBarAlpha;
796 				//alpha is ignored by BColorControl but is checked in equalities
797 
798 			switch (fCurrentColor) {
799 				case 0:
800 					settings.SetUsedSpaceColor(color);
801 					break;
802 				case 1:
803 					settings.SetFreeSpaceColor(color);
804 					break;
805 				case 2:
806 					settings.SetWarningSpaceColor(color);
807 					break;
808 			}
809 
810 			Window()->PostMessage(kSettingsContentsModified);
811 			tracker->PostMessage(kSpaceBarColorChanged);
812 			break;
813 		}
814 
815 		default:
816 			_inherited::MessageReceived(message);
817 			break;
818 	}
819 }
820 
821 
822 void
823 SpaceBarSettingsView::SetDefaults()
824 {
825 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
826 	if (!tracker)
827 		return;
828 
829 	TrackerSettings settings;
830 
831 	if (!settings.ShowVolumeSpaceBar()) {
832 		settings.SetShowVolumeSpaceBar(true);
833 		send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", true);
834 	}
835 
836 	if (settings.UsedSpaceColor() != kDefaultUsedSpaceColor
837 		|| settings.FreeSpaceColor() != kDefaultFreeSpaceColor
838 		|| settings.WarningSpaceColor() != kDefaultWarningSpaceColor) {
839 		settings.SetUsedSpaceColor(kDefaultUsedSpaceColor);
840 		settings.SetFreeSpaceColor(kDefaultFreeSpaceColor);
841 		settings.SetWarningSpaceColor(kDefaultWarningSpaceColor);
842 		tracker->SendNotices(kSpaceBarColorChanged);
843 	}
844 
845 	ShowCurrentSettings();
846 }
847 
848 
849 bool
850 SpaceBarSettingsView::IsDefaultable() const
851 {
852 	TrackerSettings settings;
853 
854 	return settings.ShowVolumeSpaceBar() != true
855 		|| settings.UsedSpaceColor() != kDefaultUsedSpaceColor
856 		|| settings.FreeSpaceColor() != kDefaultFreeSpaceColor
857 		|| settings.WarningSpaceColor() != kDefaultWarningSpaceColor;
858 }
859 
860 
861 void
862 SpaceBarSettingsView::Revert()
863 {
864 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
865 	if (!tracker)
866 		return;
867 
868 	TrackerSettings settings;
869 
870 	if (settings.ShowVolumeSpaceBar() != fSpaceBarShow) {
871 		settings.SetShowVolumeSpaceBar(fSpaceBarShow);
872 		send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", fSpaceBarShow);
873 	}
874 
875 	if (settings.UsedSpaceColor() != fUsedSpaceColor
876 		|| settings.FreeSpaceColor() != fFreeSpaceColor
877 		|| settings.WarningSpaceColor() != fWarningSpaceColor) {
878 		settings.SetUsedSpaceColor(fUsedSpaceColor);
879 		settings.SetFreeSpaceColor(fFreeSpaceColor);
880 		settings.SetWarningSpaceColor(fWarningSpaceColor);
881 		tracker->SendNotices(kSpaceBarColorChanged);
882 	}
883 
884 	ShowCurrentSettings();
885 }
886 
887 
888 void
889 SpaceBarSettingsView::ShowCurrentSettings()
890 {
891 	TrackerSettings settings;
892 
893 	fSpaceBarShowCheckBox->SetValue(settings.ShowVolumeSpaceBar());
894 
895 	switch (fCurrentColor) {
896 		case 0:
897 			fColorControl->SetValue(settings.UsedSpaceColor());
898 			break;
899 		case 1:
900 			fColorControl->SetValue(settings.FreeSpaceColor());
901 			break;
902 		case 2:
903 			fColorControl->SetValue(settings.WarningSpaceColor());
904 			break;
905 	}
906 }
907 
908 
909 void
910 SpaceBarSettingsView::RecordRevertSettings()
911 {
912 	TrackerSettings settings;
913 
914 	fSpaceBarShow = settings.ShowVolumeSpaceBar();
915 	fUsedSpaceColor = settings.UsedSpaceColor();
916 	fFreeSpaceColor = settings.FreeSpaceColor();
917 	fWarningSpaceColor = settings.WarningSpaceColor();
918 }
919 
920 
921 bool
922 SpaceBarSettingsView::IsRevertable() const
923 {
924 	TrackerSettings settings;
925 
926 	return fSpaceBarShow != settings.ShowVolumeSpaceBar()
927 		|| fUsedSpaceColor != settings.UsedSpaceColor()
928 		|| fFreeSpaceColor != settings.FreeSpaceColor()
929 		|| fWarningSpaceColor != settings.WarningSpaceColor();
930 }
931 
932 
933 // #pragma mark -
934 
935 
936 TrashSettingsView::TrashSettingsView()
937 	:
938 	SettingsView("TrashSettingsView")
939 {
940 	fDontMoveFilesToTrashCheckBox = new BCheckBox("",
941 		B_TRANSLATE("Don't move files to Trash"),
942 			new BMessage(kDontMoveFilesToTrashChanged));
943 
944 	fAskBeforeDeleteFileCheckBox = new BCheckBox("",
945 		B_TRANSLATE("Ask before delete"),
946 			new BMessage(kAskBeforeDeleteFileChanged));
947 
948 	const float spacing = be_control_look->DefaultItemSpacing();
949 
950 	BGroupLayoutBuilder(this)
951 		.AddGroup(B_VERTICAL)
952 			.Add(fDontMoveFilesToTrashCheckBox)
953 			.Add(fAskBeforeDeleteFileCheckBox)
954 			.AddGlue()
955 		.End()
956 		.SetInsets(spacing, spacing, spacing, spacing);
957 
958 }
959 
960 
961 void
962 TrashSettingsView::AttachedToWindow()
963 {
964 	fDontMoveFilesToTrashCheckBox->SetTarget(this);
965 	fAskBeforeDeleteFileCheckBox->SetTarget(this);
966 }
967 
968 
969 void
970 TrashSettingsView::MessageReceived(BMessage *message)
971 {
972 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
973 	if (!tracker)
974 		return;
975 	TrackerSettings settings;
976 
977 	switch (message->what) {
978 		case kDontMoveFilesToTrashChanged:
979 			settings.SetDontMoveFilesToTrash(fDontMoveFilesToTrashCheckBox->Value() == 1);
980 
981 			tracker->SendNotices(kDontMoveFilesToTrashChanged);
982 			Window()->PostMessage(kSettingsContentsModified);
983 			break;
984 
985 		case kAskBeforeDeleteFileChanged:
986 			settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFileCheckBox->Value() == 1);
987 
988 			tracker->SendNotices(kAskBeforeDeleteFileChanged);
989 			Window()->PostMessage(kSettingsContentsModified);
990 			break;
991 
992 		default:
993 			_inherited::MessageReceived(message);
994 			break;
995 	}
996 }
997 
998 
999 void
1000 TrashSettingsView::SetDefaults()
1001 {
1002 	TrackerSettings settings;
1003 
1004 	settings.SetDontMoveFilesToTrash(false);
1005 	settings.SetAskBeforeDeleteFile(true);
1006 
1007 	ShowCurrentSettings();
1008 	_SendNotices();
1009 }
1010 
1011 
1012 bool
1013 TrashSettingsView::IsDefaultable() const
1014 {
1015 	TrackerSettings settings;
1016 
1017 	return settings.DontMoveFilesToTrash() != false
1018 		|| settings.AskBeforeDeleteFile() != true;
1019 }
1020 
1021 
1022 void
1023 TrashSettingsView::Revert()
1024 {
1025 	TrackerSettings settings;
1026 
1027 	settings.SetDontMoveFilesToTrash(fDontMoveFilesToTrash);
1028 	settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFile);
1029 
1030 	ShowCurrentSettings();
1031 	_SendNotices();
1032 }
1033 
1034 
1035 void
1036 TrashSettingsView::_SendNotices()
1037 {
1038 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
1039 	if (!tracker)
1040 		return;
1041 
1042 	tracker->SendNotices(kDontMoveFilesToTrashChanged);
1043 	tracker->SendNotices(kAskBeforeDeleteFileChanged);
1044 }
1045 
1046 
1047 void
1048 TrashSettingsView::ShowCurrentSettings()
1049 {
1050 	TrackerSettings settings;
1051 
1052 	fDontMoveFilesToTrashCheckBox->SetValue(settings.DontMoveFilesToTrash());
1053 	fAskBeforeDeleteFileCheckBox->SetValue(settings.AskBeforeDeleteFile());
1054 }
1055 
1056 
1057 void
1058 TrashSettingsView::RecordRevertSettings()
1059 {
1060 	TrackerSettings settings;
1061 
1062 	fDontMoveFilesToTrash = settings.DontMoveFilesToTrash();
1063 	fAskBeforeDeleteFile = settings.AskBeforeDeleteFile();
1064 }
1065 
1066 
1067 bool
1068 TrashSettingsView::IsRevertable() const
1069 {
1070 	return fDontMoveFilesToTrash != (fDontMoveFilesToTrashCheckBox->Value() > 0)
1071 		|| fAskBeforeDeleteFile != (fAskBeforeDeleteFileCheckBox->Value() > 0);
1072 }
1073 
1074