xref: /haiku/src/kits/tracker/SettingsViews.cpp (revision 16d5c24e533eb14b7b8a99ee9f3ec9ba66335b1e)
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 <MenuField.h>
47 #include <ColorControl.h>
48 #include <NodeMonitor.h>
49 #include <StringView.h>
50 
51 
52 static const uint32 kSpaceBarSwitchColor = 'SBsc';
53 static const float kItemExtraSpacing = 2.0f;
54 static const float kIndentSpacing = 12.0f;
55 
56 //TODO: defaults should be set in one place only (TrackerSettings.cpp) while
57 //		being accessible from here.
58 //      What about adding DefaultValue(), IsDefault() etc... methods to xxxValueSetting ?
59 static const uint8 kSpaceBarAlpha = 192;
60 static const rgb_color kDefaultUsedSpaceColor = {0, 203, 0, kSpaceBarAlpha};
61 static const rgb_color kDefaultFreeSpaceColor = {255, 255, 255, kSpaceBarAlpha};
62 static const rgb_color kDefaultWarningSpaceColor = {203, 0, 0, kSpaceBarAlpha};
63 
64 
65 static void
66 send_bool_notices(uint32 what, const char *name, bool value)
67 {
68 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
69 	if (!tracker)
70 		return;
71 
72 	BMessage message;
73 	message.AddBool(name, value);
74 	tracker->SendNotices(what, &message);
75 }
76 
77 
78 //	#pragma mark -
79 
80 
81 SettingsView::SettingsView(BRect rect, const char *name)
82 	: BView(rect, name, B_FOLLOW_ALL, 0)
83 {
84 }
85 
86 
87 SettingsView::~SettingsView()
88 {
89 }
90 
91 
92 /*!
93 	The inherited functions should set the default values
94 	and update the UI gadgets. The latter can by done by
95 	calling ShowCurrentSettings().
96 */
97 void
98 SettingsView::SetDefaults()
99 {
100 }
101 
102 
103 /*!
104 	This function is used by the window to tell whether
105 	it can ghost the defaults button or not. It doesn't
106 	shows the default settings, this function should
107 	return true.
108 */
109 bool
110 SettingsView::IsDefaultable() const
111 {
112 	return true;
113 }
114 
115 
116 /*!
117 	The inherited functions should set the values that was
118 	active when the settings window opened. It should also
119 	update the UI widgets accordingly, preferrable by calling
120 	ShowCurrentSettings().
121 */
122 void
123 SettingsView::Revert()
124 {
125 }
126 
127 
128 /*!
129 	This function is called when the window is shown to let
130 	the settings views record the state to revert to.
131 */
132 void
133 SettingsView::RecordRevertSettings()
134 {
135 }
136 
137 
138 /*!
139 	This function is used by the window to tell the view
140 	to display the current settings in the tracker.
141 */
142 void
143 SettingsView::ShowCurrentSettings()
144 {
145 }
146 
147 
148 /*!
149 	This function is used by the window to tell whether
150 	it can ghost the revert button or not. It it shows the
151 	reverted settings, this function should return true.
152 */
153 bool
154 SettingsView::IsRevertable() const
155 {
156 	return true;
157 }
158 
159 
160 // #pragma mark -
161 
162 
163 DesktopSettingsView::DesktopSettingsView(BRect rect)
164 	: SettingsView(rect, "DesktopSettingsView")
165 {
166 	rect.OffsetTo(B_ORIGIN);
167 	fShowDisksIconRadioButton = new BRadioButton(rect, "", "Show Disks Icon",
168 		new BMessage(kShowDisksIconChanged));
169 	fShowDisksIconRadioButton->ResizeToPreferred();
170 	AddChild(fShowDisksIconRadioButton);
171 
172 	const float itemSpacing = fShowDisksIconRadioButton->Bounds().Height() + kItemExtraSpacing;
173 	rect.OffsetBy(0, itemSpacing);
174 
175 	fMountVolumesOntoDesktopRadioButton = new BRadioButton(rect, "",
176 		"Show Volumes on Desktop", new BMessage(kVolumesOnDesktopChanged));
177 	AddChild(fMountVolumesOntoDesktopRadioButton);
178 	fMountVolumesOntoDesktopRadioButton->ResizeToPreferred();
179 
180 	rect.OffsetBy(20, itemSpacing);
181 
182 	fMountSharedVolumesOntoDesktopCheckBox = new BCheckBox(rect, "",
183 		"Show Shared Volumes On Desktop", new BMessage(kVolumesOnDesktopChanged));
184 	AddChild(fMountSharedVolumesOntoDesktopCheckBox);
185 	fMountSharedVolumesOntoDesktopCheckBox->ResizeToPreferred();
186 
187 	rect.OffsetBy(-20, itemSpacing);
188 
189 	fEjectWhenUnmountingCheckBox = new BCheckBox(rect, "", "Eject When Unmounting",
190 		new BMessage(kEjectWhenUnmountingChanged));
191 	AddChild(fEjectWhenUnmountingCheckBox);
192 	fEjectWhenUnmountingCheckBox->ResizeToPreferred();
193 
194 	rect = Bounds();
195 	rect.top = rect.bottom;
196 	fMountButton = new BButton(rect, "", "Mount Settings" B_UTF8_ELLIPSIS,
197 		new BMessage(kRunAutomounterSettings), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
198 	fMountButton->ResizeToPreferred();
199 	fMountButton->MoveBy(0, -fMountButton->Bounds().Height());
200 	AddChild(fMountButton);
201 
202 	fMountButton->SetTarget(be_app);
203 }
204 
205 
206 void
207 DesktopSettingsView::GetPreferredSize(float *_width, float *_height)
208 {
209 	if (_width != NULL) {
210 		*_width = fMountSharedVolumesOntoDesktopCheckBox->Frame().right;
211 	}
212 
213 	if (_height != NULL) {
214 		*_height = fEjectWhenUnmountingCheckBox->Frame().bottom + 8
215 			+ fMountButton->Bounds().Height();
216 	}
217 }
218 
219 
220 void
221 DesktopSettingsView::AttachedToWindow()
222 {
223 	fShowDisksIconRadioButton->SetTarget(this);
224 	fMountVolumesOntoDesktopRadioButton->SetTarget(this);
225 	fMountSharedVolumesOntoDesktopCheckBox->SetTarget(this);
226 	fEjectWhenUnmountingCheckBox->SetTarget(this);
227 }
228 
229 
230 void
231 DesktopSettingsView::MessageReceived(BMessage *message)
232 {
233 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
234 	if (!tracker)
235 		return;
236 
237 	TrackerSettings settings;
238 
239 	switch (message->what) {
240 		case kShowDisksIconChanged:
241 		{
242 			// Turn on and off related settings:
243 			fMountVolumesOntoDesktopRadioButton->SetValue(
244 				!fShowDisksIconRadioButton->Value() == 1);
245 			fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(
246 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
247 
248 			// Set the new settings in the tracker:
249 			settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1);
250 			settings.SetMountVolumesOntoDesktop(
251 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
252 			settings.SetMountSharedVolumesOntoDesktop(
253 				fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
254 
255 			// Construct the notification message:
256 			BMessage notificationMessage;
257 			notificationMessage.AddBool("ShowDisksIcon",
258 				fShowDisksIconRadioButton->Value() == 1);
259 			notificationMessage.AddBool("MountVolumesOntoDesktop",
260 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
261 			notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
262 				fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
263 
264 			// Send the notification message:
265 			tracker->SendNotices(kVolumesOnDesktopChanged, &notificationMessage);
266 
267 			// Tell the settings window the contents have changed:
268 			Window()->PostMessage(kSettingsContentsModified);
269 			break;
270 		}
271 
272 		case kVolumesOnDesktopChanged:
273 		{
274 			// Turn on and off related settings:
275 			fShowDisksIconRadioButton->SetValue(
276 				!fMountVolumesOntoDesktopRadioButton->Value() == 1);
277 			fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(
278 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
279 
280 			// Set the new settings in the tracker:
281 			settings.SetShowDisksIcon(fShowDisksIconRadioButton->Value() == 1);
282 			settings.SetMountVolumesOntoDesktop(
283 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
284 			settings.SetMountSharedVolumesOntoDesktop(
285 				fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
286 
287 			// Construct the notification message:
288 			BMessage notificationMessage;
289 			notificationMessage.AddBool("ShowDisksIcon",
290 				fShowDisksIconRadioButton->Value() == 1);
291 			notificationMessage.AddBool("MountVolumesOntoDesktop",
292 				fMountVolumesOntoDesktopRadioButton->Value() == 1);
293 			notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
294 				fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
295 
296 			// Send the notification message:
297 			tracker->SendNotices(kVolumesOnDesktopChanged, &notificationMessage);
298 
299 			// Tell the settings window the contents have changed:
300 			Window()->PostMessage(kSettingsContentsModified);
301 			break;
302 		}
303 
304 		case kEjectWhenUnmountingChanged:
305 		{
306 			settings.SetEjectWhenUnmounting(
307 				fEjectWhenUnmountingCheckBox->Value() == 1);
308 
309 			// Send the notification message
310 			send_bool_notices(kEjectWhenUnmountingChanged,
311 				"EjectWhenUnmounting", fEjectWhenUnmountingCheckBox->Value() == 1);
312 
313 			// Tell the settings window the contents have changed
314 			Window()->PostMessage(kSettingsContentsModified);
315 			break;
316 		}
317 
318 		default:
319 			_inherited::MessageReceived(message);
320 	}
321 }
322 
323 
324 void
325 DesktopSettingsView::SetDefaults()
326 {
327 	// ToDo: Avoid the duplication of the default values.
328 	TrackerSettings settings;
329 
330 	settings.SetShowDisksIcon(false);
331 	settings.SetMountVolumesOntoDesktop(true);
332 	settings.SetMountSharedVolumesOntoDesktop(true);
333 	settings.SetIntegrateNonBootBeOSDesktops(false);
334 	settings.SetEjectWhenUnmounting(true);
335 
336 	ShowCurrentSettings();
337 	_SendNotices();
338 }
339 
340 
341 bool
342 DesktopSettingsView::IsDefaultable() const
343 {
344 	TrackerSettings settings;
345 
346 	return settings.ShowDisksIcon() != false
347 		|| settings.MountVolumesOntoDesktop() != true
348 		|| settings.MountSharedVolumesOntoDesktop() != true
349 		|| settings.IntegrateNonBootBeOSDesktops() != false
350 		|| settings.EjectWhenUnmounting() != true;
351 }
352 
353 
354 void
355 DesktopSettingsView::Revert()
356 {
357 	TrackerSettings settings;
358 
359 	settings.SetShowDisksIcon(fShowDisksIcon);
360 	settings.SetMountVolumesOntoDesktop(fMountVolumesOntoDesktop);
361 	settings.SetMountSharedVolumesOntoDesktop(fMountSharedVolumesOntoDesktop);
362 	settings.SetIntegrateNonBootBeOSDesktops(fIntegrateNonBootBeOSDesktops);
363 	settings.SetEjectWhenUnmounting(fEjectWhenUnmounting);
364 
365 	ShowCurrentSettings();
366 	_SendNotices();
367 }
368 
369 
370 void
371 DesktopSettingsView::_SendNotices()
372 {
373 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
374 	if (!tracker)
375 		return;
376 
377 	// Construct the notification message:
378 	BMessage notificationMessage;
379 	notificationMessage.AddBool("ShowDisksIcon",
380 		fShowDisksIconRadioButton->Value() == 1);
381 	notificationMessage.AddBool("MountVolumesOntoDesktop",
382 		fMountVolumesOntoDesktopRadioButton->Value() == 1);
383 	notificationMessage.AddBool("MountSharedVolumesOntoDesktop",
384 		fMountSharedVolumesOntoDesktopCheckBox->Value() == 1);
385 	notificationMessage.AddBool("EjectWhenUnmounting",
386 		fEjectWhenUnmountingCheckBox->Value() == 1);
387 
388 	// Send notices to the tracker about the change:
389 	tracker->SendNotices(kVolumesOnDesktopChanged, &notificationMessage);
390 	tracker->SendNotices(kDesktopIntegrationChanged, &notificationMessage);
391 }
392 
393 
394 void
395 DesktopSettingsView::ShowCurrentSettings()
396 {
397 	TrackerSettings settings;
398 
399 	fShowDisksIconRadioButton->SetValue(settings.ShowDisksIcon());
400 	fMountVolumesOntoDesktopRadioButton->SetValue(settings.MountVolumesOntoDesktop());
401 
402 	fMountSharedVolumesOntoDesktopCheckBox->SetValue(settings.MountSharedVolumesOntoDesktop());
403 	fMountSharedVolumesOntoDesktopCheckBox->SetEnabled(settings.MountVolumesOntoDesktop());
404 
405 	fEjectWhenUnmountingCheckBox->SetValue(settings.EjectWhenUnmounting());
406 }
407 
408 
409 void
410 DesktopSettingsView::RecordRevertSettings()
411 {
412 	TrackerSettings settings;
413 
414 	fShowDisksIcon = settings.ShowDisksIcon();
415 	fMountVolumesOntoDesktop = settings.MountVolumesOntoDesktop();
416 	fMountSharedVolumesOntoDesktop = settings.MountSharedVolumesOntoDesktop();
417 	fIntegrateNonBootBeOSDesktops = settings.IntegrateNonBootBeOSDesktops();
418 	fEjectWhenUnmounting = settings.EjectWhenUnmounting();
419 }
420 
421 
422 bool
423 DesktopSettingsView::IsRevertable() const
424 {
425 	return fShowDisksIcon != (fShowDisksIconRadioButton->Value() > 0)
426 		|| fMountVolumesOntoDesktop !=
427 			(fMountVolumesOntoDesktopRadioButton->Value() > 0)
428 		|| fMountSharedVolumesOntoDesktop !=
429 			(fMountSharedVolumesOntoDesktopCheckBox->Value() > 0)
430 		|| fEjectWhenUnmounting !=
431 			(fEjectWhenUnmountingCheckBox->Value() > 0);
432 }
433 
434 
435 // #pragma mark -
436 
437 
438 WindowsSettingsView::WindowsSettingsView(BRect rect)
439 	: SettingsView(rect, "WindowsSettingsView")
440 {
441 	rect.OffsetTo(B_ORIGIN);
442 	fShowFullPathInTitleBarCheckBox = new BCheckBox(rect, "", "Show Folder Location in Title Bar",
443 		new BMessage(kWindowsShowFullPathChanged));
444 	fShowFullPathInTitleBarCheckBox->ResizeToPreferred();
445 	AddChild(fShowFullPathInTitleBarCheckBox);
446 
447 	const float itemSpacing = fShowFullPathInTitleBarCheckBox->Bounds().Height() + kItemExtraSpacing;
448 	rect.OffsetBy(0, itemSpacing);
449 
450 	fSingleWindowBrowseCheckBox = new BCheckBox(rect, "", "Single Window Navigation",
451 		new BMessage(kSingleWindowBrowseChanged));
452 	fSingleWindowBrowseCheckBox->ResizeToPreferred();
453 	AddChild(fSingleWindowBrowseCheckBox);
454 
455 	rect.OffsetBy(20, itemSpacing);
456 
457 	fShowNavigatorCheckBox = new BCheckBox(rect, "", "Show Navigator",
458 		new BMessage(kShowNavigatorChanged));
459 	fShowNavigatorCheckBox->ResizeToPreferred();
460 	AddChild(fShowNavigatorCheckBox);
461 
462 	rect.OffsetBy(-20, itemSpacing);
463 
464 	fOutlineSelectionCheckBox = new BCheckBox(rect, "", "Outline Selection Rectangle Only",
465 		new BMessage(kTransparentSelectionChanged));
466 	fOutlineSelectionCheckBox->ResizeToPreferred();
467 	AddChild(fOutlineSelectionCheckBox);
468 
469 	rect.OffsetBy(0, itemSpacing);
470 
471 	fSortFolderNamesFirstCheckBox = new BCheckBox(rect, "", "List Folders First",
472 		new BMessage(kSortFolderNamesFirstChanged));
473 	fSortFolderNamesFirstCheckBox->ResizeToPreferred();
474 	AddChild(fSortFolderNamesFirstCheckBox);
475 }
476 
477 
478 void
479 WindowsSettingsView::GetPreferredSize(float *_width, float *_height)
480 {
481 	if (_width != NULL)
482 		*_width = fOutlineSelectionCheckBox->Frame().right;
483 
484 	if (_height != NULL)
485 		*_height = fSortFolderNamesFirstCheckBox->Frame().bottom;
486 }
487 
488 
489 void
490 WindowsSettingsView::AttachedToWindow()
491 {
492 	fSingleWindowBrowseCheckBox->SetTarget(this);
493 	fShowNavigatorCheckBox->SetTarget(this);
494 	fShowFullPathInTitleBarCheckBox->SetTarget(this);
495 	fOutlineSelectionCheckBox->SetTarget(this);
496 	fSortFolderNamesFirstCheckBox->SetTarget(this);
497 }
498 
499 
500 void
501 WindowsSettingsView::MessageReceived(BMessage *message)
502 {
503 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
504 	if (!tracker)
505 		return;
506 	TrackerSettings settings;
507 
508 	switch (message->what) {
509 		case kWindowsShowFullPathChanged:
510 			settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBarCheckBox->Value() == 1);
511 			tracker->SendNotices(kWindowsShowFullPathChanged);
512 			Window()->PostMessage(kSettingsContentsModified);
513 			break;
514 
515 		case kSingleWindowBrowseChanged:
516 			settings.SetSingleWindowBrowse(fSingleWindowBrowseCheckBox->Value() == 1);
517 			if (fSingleWindowBrowseCheckBox->Value() == 0) {
518 				fShowNavigatorCheckBox->SetEnabled(false);
519 				settings.SetShowNavigator(0);
520 			} else {
521 				fShowNavigatorCheckBox->SetEnabled(true);
522 				settings.SetShowNavigator(fShowNavigatorCheckBox->Value() != 0);
523 			}
524 			tracker->SendNotices(kShowNavigatorChanged);
525 			tracker->SendNotices(kSingleWindowBrowseChanged);
526 			Window()->PostMessage(kSettingsContentsModified);
527 			break;
528 
529 		case kShowNavigatorChanged:
530 			settings.SetShowNavigator(fShowNavigatorCheckBox->Value() == 1);
531 			tracker->SendNotices(kShowNavigatorChanged);
532 			Window()->PostMessage(kSettingsContentsModified);
533 			break;
534 
535 		case kTransparentSelectionChanged:
536 		{
537 			settings.SetTransparentSelection(
538 				fOutlineSelectionCheckBox->Value() == B_CONTROL_OFF);
539 
540 			// Make the notification message and send it to the tracker:
541 			send_bool_notices(kTransparentSelectionChanged,
542 				"TransparentSelection", settings.TransparentSelection());
543 
544 			Window()->PostMessage(kSettingsContentsModified);
545 			break;
546 		}
547 
548 		case kSortFolderNamesFirstChanged:
549 		{
550 			settings.SetSortFolderNamesFirst(fSortFolderNamesFirstCheckBox->Value() == 1);
551 
552 			// Make the notification message and send it to the tracker:
553 			send_bool_notices(kSortFolderNamesFirstChanged, "SortFolderNamesFirst",
554 				fSortFolderNamesFirstCheckBox->Value() == 1);
555 
556 			Window()->PostMessage(kSettingsContentsModified);
557 			break;
558 		}
559 
560 		default:
561 			_inherited::MessageReceived(message);
562 			break;
563 	}
564 }
565 
566 
567 void
568 WindowsSettingsView::SetDefaults()
569 {
570 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
571 	if (!tracker)
572 		return;
573 
574 	TrackerSettings settings;
575 
576 	if (settings.ShowFullPathInTitleBar()) {
577 		settings.SetShowFullPathInTitleBar(false);
578 		tracker->SendNotices(kWindowsShowFullPathChanged);
579 	}
580 
581 	if (settings.SingleWindowBrowse()) {
582 		settings.SetSingleWindowBrowse(false);
583 		tracker->SendNotices(kSingleWindowBrowseChanged);
584 	}
585 
586 	if (settings.ShowNavigator()) {
587 		settings.SetShowNavigator(false);
588 		tracker->SendNotices(kShowNavigatorChanged);
589 	}
590 
591 	if (!settings.TransparentSelection()) {
592 		settings.SetTransparentSelection(true);
593 		send_bool_notices(kTransparentSelectionChanged,
594 			"TransparentSelection", true);
595 	}
596 
597 	if (settings.SortFolderNamesFirst()) {
598 		settings.SetSortFolderNamesFirst(true);
599 		send_bool_notices(kSortFolderNamesFirstChanged,
600 			"SortFolderNamesFirst", true);
601 	}
602 
603 	ShowCurrentSettings();
604 }
605 
606 
607 bool
608 WindowsSettingsView::IsDefaultable() const
609 {
610 	TrackerSettings settings;
611 
612 	return settings.ShowFullPathInTitleBar() != false
613 		|| settings.SingleWindowBrowse() != false
614 		|| settings.ShowNavigator() != false
615 		|| settings.TransparentSelection() != true
616 		|| settings.SortFolderNamesFirst() != true;
617 }
618 
619 
620 void
621 WindowsSettingsView::Revert()
622 {
623 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
624 	if (!tracker)
625 		return;
626 
627 	TrackerSettings settings;
628 
629 	if (settings.ShowFullPathInTitleBar() != fShowFullPathInTitleBar) {
630 		settings.SetShowFullPathInTitleBar(fShowFullPathInTitleBar);
631 		tracker->SendNotices(kWindowsShowFullPathChanged);
632 	}
633 
634 	if (settings.SingleWindowBrowse() != fSingleWindowBrowse) {
635 		settings.SetSingleWindowBrowse(fSingleWindowBrowse);
636 		tracker->SendNotices(kSingleWindowBrowseChanged);
637 	}
638 
639 	if (settings.ShowNavigator() != fShowNavigator) {
640 		settings.SetShowNavigator(fShowNavigator);
641 		tracker->SendNotices(kShowNavigatorChanged);
642 	}
643 
644 	if (settings.TransparentSelection() != fTransparentSelection) {
645 		settings.SetTransparentSelection(fTransparentSelection);
646 		send_bool_notices(kTransparentSelectionChanged,
647 			"TransparentSelection", fTransparentSelection);
648 	}
649 
650 	if (settings.SortFolderNamesFirst() != fSortFolderNamesFirst) {
651 		settings.SetSortFolderNamesFirst(fSortFolderNamesFirst);
652 		send_bool_notices(kSortFolderNamesFirstChanged,
653 			"SortFolderNamesFirst", fSortFolderNamesFirst);
654 	}
655 
656 	ShowCurrentSettings();
657 }
658 
659 
660 void
661 WindowsSettingsView::ShowCurrentSettings()
662 {
663 	TrackerSettings settings;
664 
665 	fShowFullPathInTitleBarCheckBox->SetValue(settings.ShowFullPathInTitleBar());
666 	fSingleWindowBrowseCheckBox->SetValue(settings.SingleWindowBrowse());
667 	fShowNavigatorCheckBox->SetEnabled(settings.SingleWindowBrowse());
668 	fShowNavigatorCheckBox->SetValue(settings.ShowNavigator());
669 	fOutlineSelectionCheckBox->SetValue(settings.TransparentSelection()
670 		? B_CONTROL_OFF : B_CONTROL_ON);
671 	fSortFolderNamesFirstCheckBox->SetValue(settings.SortFolderNamesFirst());
672 }
673 
674 
675 void
676 WindowsSettingsView::RecordRevertSettings()
677 {
678 	TrackerSettings settings;
679 
680 	fShowFullPathInTitleBar = settings.ShowFullPathInTitleBar();
681 	fSingleWindowBrowse = settings.SingleWindowBrowse();
682 	fShowNavigator = settings.ShowNavigator();
683 	fTransparentSelection = settings.TransparentSelection();
684 	fSortFolderNamesFirst = settings.SortFolderNamesFirst();
685 }
686 
687 
688 bool
689 WindowsSettingsView::IsRevertable() const
690 {
691 	TrackerSettings settings;
692 
693 	return fShowFullPathInTitleBar != settings.ShowFullPathInTitleBar()
694 		|| fSingleWindowBrowse != settings.SingleWindowBrowse()
695 		|| fShowNavigator != settings.ShowNavigator()
696 		|| fTransparentSelection != settings.TransparentSelection()
697 		|| fSortFolderNamesFirst != settings.SortFolderNamesFirst();
698 }
699 
700 
701 // #pragma mark -
702 
703 
704 TimeFormatSettingsView::TimeFormatSettingsView(BRect rect)
705 	: SettingsView(rect, "WindowsSettingsView")
706 {
707 	rect.OffsetTo(B_ORIGIN);
708 
709 	font_height fontHeight;
710 	be_bold_font->GetHeight(&fontHeight);
711 
712 	rect.bottom = ceilf(fontHeight.ascent + fontHeight.descent) + 10;
713 	BBox *clockBox = new BBox(rect, "Clock");
714 	clockBox->SetLabel("Clock");
715 	AddChild(clockBox);
716 
717 	rect.left = 8;
718 	rect.top = rect.bottom - 8;
719 	f24HrRadioButton = new BRadioButton(rect, "", "24 Hour",
720 		new BMessage(kSettingsContentsModified));
721 	f24HrRadioButton->ResizeToPreferred();
722 	clockBox->AddChild(f24HrRadioButton);
723 
724 	const float itemSpacing = f24HrRadioButton->Bounds().Height() + kItemExtraSpacing;
725 	rect.OffsetBy(0, itemSpacing);
726 
727 	f12HrRadioButton = new BRadioButton(rect, "", "12 Hour",
728 		new BMessage(kSettingsContentsModified));
729 	f12HrRadioButton->ResizeToPreferred();
730 	clockBox->AddChild(f12HrRadioButton);
731 
732 	float width = max_c(f12HrRadioButton->Frame().right, f24HrRadioButton->Frame().right) + 8.0f;
733 	clockBox->ResizeTo(width, clockBox->Bounds().Height()
734 		+ 3 * f12HrRadioButton->Frame().Height());
735 
736 	rect = clockBox->Frame();
737 	rect.OffsetBy(rect.Width() + 8, 0);
738 	BBox *dateFormatBox = new BBox(rect, "Date Order");
739 	dateFormatBox->SetLabel("Date Order");
740 	AddChild(dateFormatBox);
741 
742 	rect = f24HrRadioButton->Frame();
743 	fYMDRadioButton = new BRadioButton(rect, "", "Year-Month-Day",
744 		new BMessage(kSettingsContentsModified));
745 	fYMDRadioButton->ResizeToPreferred();
746 	dateFormatBox->AddChild(fYMDRadioButton);
747 
748 	rect.OffsetBy(0, itemSpacing);
749 
750 	fDMYRadioButton = new BRadioButton(rect, "", "Day-Month-Year",
751 		new BMessage(kSettingsContentsModified));
752 	fDMYRadioButton->ResizeToPreferred();
753 	dateFormatBox->AddChild(fDMYRadioButton);
754 
755 	rect.OffsetBy(0, itemSpacing);
756 
757 	fMDYRadioButton = new BRadioButton(rect, "", "Month-Day-Year",
758 		new BMessage(kSettingsContentsModified));
759 	fMDYRadioButton->ResizeToPreferred();
760 	dateFormatBox->AddChild(fMDYRadioButton);
761 
762 	dateFormatBox->ResizeTo(fYMDRadioButton->Bounds().Width() + 16,
763 		dateFormatBox->Bounds().Height());
764 
765 	BPopUpMenu *menu = new BPopUpMenu("Separator");
766 	menu->AddItem(new BMenuItem("None", new BMessage(kSettingsContentsModified)));
767 	menu->AddItem(new BMenuItem("Space", new BMessage(kSettingsContentsModified)));
768 	menu->AddItem(new BMenuItem("-", new BMessage(kSettingsContentsModified)));
769 	menu->AddItem(new BMenuItem("/", new BMessage(kSettingsContentsModified)));
770 	menu->AddItem(new BMenuItem("\\", new BMessage(kSettingsContentsModified)));
771 	menu->AddItem(new BMenuItem(".", new BMessage(kSettingsContentsModified)));
772 
773 	rect.left = 0;
774 	rect.top = clockBox->Frame().bottom + 8;
775 	rect.right = Bounds().Width() - 8;
776 	rect.bottom = rect.top + itemSpacing;
777 	fSeparatorMenuField = new BMenuField(rect, "Separator", "Separator:", menu);
778 	fSeparatorMenuField->SetDivider(fSeparatorMenuField->StringWidth(fSeparatorMenuField->Label()) + 8.0f);
779 	fSeparatorMenuField->SetAlignment(B_ALIGN_LEFT);
780 	fSeparatorMenuField->ResizeToPreferred();
781 	AddChild(fSeparatorMenuField);
782 
783 	rect.OffsetBy(0, itemSpacing + 10);
784 
785 	BStringView *exampleView = new BStringView(rect, "", "Examples:");
786 	exampleView->ResizeToPreferred();
787 	AddChild(exampleView);
788 
789 	rect.OffsetBy(0, itemSpacing);
790 
791 	fLongDateExampleView = new BStringView(rect, "", "");
792 	fLongDateExampleView->ResizeToPreferred();
793 	AddChild(fLongDateExampleView);
794 
795 	rect.OffsetBy(0, itemSpacing);
796 
797 	fShortDateExampleView = new BStringView(rect, "", "");
798 	fShortDateExampleView->ResizeToPreferred();
799 	AddChild(fShortDateExampleView);
800 
801 	_UpdateExamples();
802 }
803 
804 
805 void
806 TimeFormatSettingsView::GetPreferredSize(float *_width, float *_height)
807 {
808 	if (_width != NULL) {
809 		BView* view = fMDYRadioButton->Parent();
810 		if (view != NULL)
811 			*_width = view->Frame().right;
812 		else
813 			*_width = Bounds().Width();
814 	}
815 
816 	if (_height != NULL)
817 		*_height = fShortDateExampleView->Frame().bottom;
818 }
819 
820 
821 void
822 TimeFormatSettingsView::AttachedToWindow()
823 {
824 	f24HrRadioButton->SetTarget(this);
825 	f12HrRadioButton->SetTarget(this);
826 	fYMDRadioButton->SetTarget(this);
827 	fDMYRadioButton->SetTarget(this);
828 	fMDYRadioButton->SetTarget(this);
829 
830 	fSeparatorMenuField->Menu()->SetTargetForItems(this);
831 }
832 
833 
834 void
835 TimeFormatSettingsView::MessageReceived(BMessage *message)
836 {
837 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
838 	if (!tracker)
839 		return;
840 	TrackerSettings settings;
841 
842 	switch (message->what) {
843 		case kSettingsContentsModified:
844 			{
845 				int32 separator = 0;
846 				BMenuItem *item = fSeparatorMenuField->Menu()->FindMarked();
847 				if (item) {
848 					separator = fSeparatorMenuField->Menu()->IndexOf(item);
849 					if (separator >= 0)
850 						settings.SetTimeFormatSeparator((FormatSeparator)separator);
851 				}
852 
853 				DateOrder format =
854 					fYMDRadioButton->Value() ? kYMDFormat :
855 					fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat;
856 
857 				settings.SetDateOrderFormat(format);
858 				settings.SetClockTo24Hr(f24HrRadioButton->Value() == 1);
859 
860 				// Make the notification message and send it to the tracker:
861 				BMessage notificationMessage;
862 				notificationMessage.AddInt32("TimeFormatSeparator", separator);
863 				notificationMessage.AddInt32("DateOrderFormat", format);
864 				notificationMessage.AddBool("24HrClock", f24HrRadioButton->Value() == 1);
865 				tracker->SendNotices(kDateFormatChanged, &notificationMessage);
866 
867 				_UpdateExamples();
868 
869 				Window()->PostMessage(kSettingsContentsModified);
870 				break;
871 			}
872 
873 		default:
874 			_inherited::MessageReceived(message);
875 	}
876 }
877 
878 
879 void
880 TimeFormatSettingsView::SetDefaults()
881 {
882 	TrackerSettings settings;
883 
884 	settings.SetTimeFormatSeparator(kSlashSeparator);
885 	settings.SetDateOrderFormat(kMDYFormat);
886 	settings.SetClockTo24Hr(false);
887 
888 	ShowCurrentSettings();
889 	_SendNotices();
890 }
891 
892 
893 bool
894 TimeFormatSettingsView::IsDefaultable() const
895 {
896 	TrackerSettings settings;
897 
898 	return settings.TimeFormatSeparator() != kSlashSeparator
899 		|| settings.DateOrderFormat() != kMDYFormat
900 		|| settings.ClockIs24Hr() != false;
901 }
902 
903 
904 void
905 TimeFormatSettingsView::Revert()
906 {
907 	TrackerSettings settings;
908 
909 	settings.SetTimeFormatSeparator(fSeparator);
910 	settings.SetDateOrderFormat(fFormat);
911 	settings.SetClockTo24Hr(f24HrClock);
912 
913 	ShowCurrentSettings();
914 	_SendNotices();
915 }
916 
917 
918 void
919 TimeFormatSettingsView::_SendNotices()
920 {
921 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
922 	if (!tracker)
923 		return;
924 
925 	TrackerSettings settings;
926 
927 	// Make the notification message and send it to the tracker:
928 	BMessage notificationMessage;
929 	notificationMessage.AddInt32("TimeFormatSeparator", (int32)settings.TimeFormatSeparator());
930 	notificationMessage.AddInt32("DateOrderFormat", (int32)settings.DateOrderFormat());
931 	notificationMessage.AddBool("24HrClock", settings.ClockIs24Hr());
932 	tracker->SendNotices(kDateFormatChanged, &notificationMessage);
933 }
934 
935 
936 void
937 TimeFormatSettingsView::ShowCurrentSettings()
938 {
939 	TrackerSettings settings;
940 
941 	f24HrRadioButton->SetValue(settings.ClockIs24Hr());
942 	f12HrRadioButton->SetValue(!settings.ClockIs24Hr());
943 
944 	switch (settings.DateOrderFormat()) {
945 		case kYMDFormat:
946 			fYMDRadioButton->SetValue(1);
947 			break;
948 
949 		case kMDYFormat:
950 			fMDYRadioButton->SetValue(1);
951 			break;
952 
953 		default:
954 		case kDMYFormat:
955 			fDMYRadioButton->SetValue(1);
956 			break;
957 	}
958 
959 	FormatSeparator separator = settings.TimeFormatSeparator();
960 
961 	if (separator >= kNoSeparator && separator < kSeparatorsEnd)
962 		fSeparatorMenuField->Menu()->ItemAt((int32)separator)->SetMarked(true);
963 
964 	_UpdateExamples();
965 }
966 
967 
968 void
969 TimeFormatSettingsView::RecordRevertSettings()
970 {
971 	TrackerSettings settings;
972 
973 	f24HrClock = settings.ClockIs24Hr();
974 	fSeparator = settings.TimeFormatSeparator();
975 	fFormat = settings.DateOrderFormat();
976 }
977 
978 
979 bool
980 TimeFormatSettingsView::IsRevertable() const
981 {
982 	FormatSeparator separator;
983 
984 	BMenuItem *item = fSeparatorMenuField->Menu()->FindMarked();
985 	if (item) {
986 		int32 index = fSeparatorMenuField->Menu()->IndexOf(item);
987 		if (index >= 0)
988 			separator = (FormatSeparator)index;
989 		else
990 			return true;
991 	} else
992 		return true;
993 
994 	DateOrder format =
995 		fYMDRadioButton->Value() ? kYMDFormat :
996 		(fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat);
997 
998 	return f24HrClock != (f24HrRadioButton->Value() > 0)
999 		|| separator != fSeparator
1000 		|| format != fFormat;
1001 }
1002 
1003 
1004 void
1005 TimeFormatSettingsView::_UpdateExamples()
1006 {
1007 	time_t timeValue = (time_t)time(NULL);
1008 	tm timeData;
1009 	localtime_r(&timeValue, &timeData);
1010 	BString timeFormat = "Internal Error!";
1011 	char buffer[256];
1012 
1013 	FormatSeparator separator;
1014 
1015 	BMenuItem *item = fSeparatorMenuField->Menu()->FindMarked();
1016 	if (item) {
1017 		int32 index = fSeparatorMenuField->Menu()->IndexOf(item);
1018 		if (index >= 0)
1019 			separator = (FormatSeparator)index;
1020 		else
1021 			separator = kSlashSeparator;
1022 	} else
1023 		separator = kSlashSeparator;
1024 
1025 	DateOrder order =
1026 		fYMDRadioButton->Value() ? kYMDFormat :
1027 		(fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat);
1028 
1029 	bool clockIs24hr = (f24HrRadioButton->Value() > 0);
1030 
1031 	TimeFormat(timeFormat, 0, separator, order, clockIs24hr);
1032 	strftime(buffer, 256, timeFormat.String(), &timeData);
1033 
1034 	fLongDateExampleView->SetText(buffer);
1035 	fLongDateExampleView->ResizeToPreferred();
1036 
1037 	TimeFormat(timeFormat, 4, separator, order, clockIs24hr);
1038 	strftime(buffer, 256, timeFormat.String(), &timeData);
1039 
1040 	fShortDateExampleView->SetText(buffer);
1041 	fShortDateExampleView->ResizeToPreferred();
1042 }
1043 
1044 
1045 // #pragma mark -
1046 
1047 
1048 SpaceBarSettingsView::SpaceBarSettingsView(BRect rect)
1049 	: SettingsView(rect, "SpaceBarSettingsView")
1050 {
1051 	rect.OffsetTo(B_ORIGIN);
1052 	fSpaceBarShowCheckBox = new BCheckBox(rect, "", "Show Space Bars on Volumes",
1053 		new BMessage(kUpdateVolumeSpaceBar));
1054 	fSpaceBarShowCheckBox->ResizeToPreferred();
1055 	AddChild(fSpaceBarShowCheckBox);
1056 
1057 	rect = fSpaceBarShowCheckBox->Frame();
1058 	rect.OffsetBy(0, fSpaceBarShowCheckBox->Bounds().Height() + kItemExtraSpacing);
1059 
1060 	BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING);
1061 	menu->SetFont(be_plain_font);
1062 
1063 	BMenuItem *item;
1064 	menu->AddItem(item = new BMenuItem("Used Space Color", new BMessage(kSpaceBarSwitchColor)));
1065 	item->SetMarked(true);
1066 	fCurrentColor = 0;
1067 	menu->AddItem(new BMenuItem("Free Space Color", new BMessage(kSpaceBarSwitchColor)));
1068 	menu->AddItem(new BMenuItem("Warning Space Color", new BMessage(kSpaceBarSwitchColor)));
1069 
1070 	BBox *box = new BBox(rect);
1071 	box->SetLabel(fColorPicker = new BMenuField(rect, NULL, NULL, menu));
1072 	AddChild(box);
1073 
1074 	fColorControl = new BColorControl(BPoint(8, fColorPicker->Bounds().Height()
1075 			+ 8 + kItemExtraSpacing),
1076 		B_CELLS_16x16, 1, "SpaceColorControl", new BMessage(kSpaceBarColorChanged));
1077 	fColorControl->SetValue(TrackerSettings().UsedSpaceColor());
1078 	fColorControl->ResizeToPreferred();
1079 	box->AddChild(fColorControl);
1080 
1081 	box->ResizeTo(fColorControl->Bounds().Width() + 16,
1082 		fColorControl->Frame().bottom + 8);
1083 }
1084 
1085 
1086 SpaceBarSettingsView::~SpaceBarSettingsView()
1087 {
1088 }
1089 
1090 
1091 void
1092 SpaceBarSettingsView::GetPreferredSize(float *_width, float *_height)
1093 {
1094 	BView* view = fColorControl->Parent();
1095 	if (view == NULL)
1096 		BView::GetPreferredSize(_width, _height);
1097 
1098 	if (_width != NULL) {
1099 		float width = fSpaceBarShowCheckBox->Bounds().Width();
1100 		if (view->Bounds().Width() > width)
1101 			width = view->Bounds().Width();
1102 
1103 		*_width = width;
1104 	}
1105 
1106 	if (_height != NULL)
1107 		*_height = view->Frame().bottom;
1108 }
1109 
1110 
1111 void
1112 SpaceBarSettingsView::AttachedToWindow()
1113 {
1114 	fSpaceBarShowCheckBox->SetTarget(this);
1115 	fColorControl->SetTarget(this);
1116 	fColorPicker->Menu()->SetTargetForItems(this);
1117 }
1118 
1119 
1120 void
1121 SpaceBarSettingsView::MessageReceived(BMessage *message)
1122 {
1123 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
1124 	if (!tracker)
1125 		return;
1126 	TrackerSettings settings;
1127 
1128 	switch (message->what) {
1129 		case kUpdateVolumeSpaceBar:
1130 		{
1131 			settings.SetShowVolumeSpaceBar(fSpaceBarShowCheckBox->Value() == 1);
1132 			Window()->PostMessage(kSettingsContentsModified);
1133 			tracker->PostMessage(kShowVolumeSpaceBar);
1134 			break;
1135 		}
1136 
1137 		case kSpaceBarSwitchColor:
1138 		{
1139 			fCurrentColor = message->FindInt32("index");
1140 			switch (fCurrentColor) {
1141 				case 0:
1142 					fColorControl->SetValue(settings.UsedSpaceColor());
1143 					break;
1144 				case 1:
1145 					fColorControl->SetValue(settings.FreeSpaceColor());
1146 					break;
1147 				case 2:
1148 					fColorControl->SetValue(settings.WarningSpaceColor());
1149 					break;
1150 			}
1151 			break;
1152 		}
1153 
1154 		case kSpaceBarColorChanged:
1155 		{
1156 			rgb_color color = fColorControl->ValueAsColor();
1157 			color.alpha = kSpaceBarAlpha;
1158 				//alpha is ignored by BColorControl but is checked in equalities
1159 
1160 			switch (fCurrentColor) {
1161 				case 0:
1162 					settings.SetUsedSpaceColor(color);
1163 					break;
1164 				case 1:
1165 					settings.SetFreeSpaceColor(color);
1166 					break;
1167 				case 2:
1168 					settings.SetWarningSpaceColor(color);
1169 					break;
1170 			}
1171 
1172 			Window()->PostMessage(kSettingsContentsModified);
1173 			tracker->PostMessage(kSpaceBarColorChanged);
1174 			break;
1175 		}
1176 
1177 		default:
1178 			_inherited::MessageReceived(message);
1179 			break;
1180 	}
1181 }
1182 
1183 
1184 void
1185 SpaceBarSettingsView::SetDefaults()
1186 {
1187 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
1188 	if (!tracker)
1189 		return;
1190 
1191 	TrackerSettings settings;
1192 
1193 	if (settings.ShowVolumeSpaceBar()) {
1194 		settings.SetShowVolumeSpaceBar(false);
1195 		send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", false);
1196 	}
1197 
1198 	if (settings.UsedSpaceColor() != kDefaultUsedSpaceColor
1199 		|| settings.FreeSpaceColor() != kDefaultFreeSpaceColor
1200 		|| settings.WarningSpaceColor() != kDefaultWarningSpaceColor) {
1201 		settings.SetUsedSpaceColor(kDefaultUsedSpaceColor);
1202 		settings.SetFreeSpaceColor(kDefaultFreeSpaceColor);
1203 		settings.SetWarningSpaceColor(kDefaultWarningSpaceColor);
1204 		tracker->SendNotices(kSpaceBarColorChanged);
1205 	}
1206 
1207 	ShowCurrentSettings();
1208 }
1209 
1210 
1211 bool
1212 SpaceBarSettingsView::IsDefaultable() const
1213 {
1214 	TrackerSettings settings;
1215 
1216 	return settings.ShowVolumeSpaceBar() != false
1217 		|| settings.UsedSpaceColor() != kDefaultUsedSpaceColor
1218 		|| settings.FreeSpaceColor() != kDefaultFreeSpaceColor
1219 		|| settings.WarningSpaceColor() != kDefaultWarningSpaceColor;
1220 }
1221 
1222 
1223 void
1224 SpaceBarSettingsView::Revert()
1225 {
1226 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
1227 	if (!tracker)
1228 		return;
1229 
1230 	TrackerSettings settings;
1231 
1232 	if (settings.ShowVolumeSpaceBar() != fSpaceBarShow) {
1233 		settings.SetShowVolumeSpaceBar(fSpaceBarShow);
1234 		send_bool_notices(kShowVolumeSpaceBar, "ShowVolumeSpaceBar", fSpaceBarShow);
1235 	}
1236 
1237 	if (settings.UsedSpaceColor() != fUsedSpaceColor
1238 		|| settings.FreeSpaceColor() != fFreeSpaceColor
1239 		|| settings.WarningSpaceColor() != fWarningSpaceColor) {
1240 		settings.SetUsedSpaceColor(fUsedSpaceColor);
1241 		settings.SetFreeSpaceColor(fFreeSpaceColor);
1242 		settings.SetWarningSpaceColor(fWarningSpaceColor);
1243 		tracker->SendNotices(kSpaceBarColorChanged);
1244 	}
1245 
1246 	ShowCurrentSettings();
1247 }
1248 
1249 
1250 void
1251 SpaceBarSettingsView::ShowCurrentSettings()
1252 {
1253 	TrackerSettings settings;
1254 
1255 	fSpaceBarShowCheckBox->SetValue(settings.ShowVolumeSpaceBar());
1256 
1257 	switch (fCurrentColor) {
1258 		case 0:
1259 			fColorControl->SetValue(settings.UsedSpaceColor());
1260 			break;
1261 		case 1:
1262 			fColorControl->SetValue(settings.FreeSpaceColor());
1263 			break;
1264 		case 2:
1265 			fColorControl->SetValue(settings.WarningSpaceColor());
1266 			break;
1267 	}
1268 }
1269 
1270 
1271 void
1272 SpaceBarSettingsView::RecordRevertSettings()
1273 {
1274 	TrackerSettings settings;
1275 
1276 	fSpaceBarShow = settings.ShowVolumeSpaceBar();
1277 	fUsedSpaceColor = settings.UsedSpaceColor();
1278 	fFreeSpaceColor = settings.FreeSpaceColor();
1279 	fWarningSpaceColor = settings.WarningSpaceColor();
1280 }
1281 
1282 
1283 bool
1284 SpaceBarSettingsView::IsRevertable() const
1285 {
1286 	TrackerSettings settings;
1287 
1288 	return fSpaceBarShow != settings.ShowVolumeSpaceBar()
1289 		|| fUsedSpaceColor != settings.UsedSpaceColor()
1290 		|| fFreeSpaceColor != settings.FreeSpaceColor()
1291 		|| fWarningSpaceColor != settings.WarningSpaceColor();
1292 }
1293 
1294 
1295 // #pragma mark -
1296 
1297 
1298 TrashSettingsView::TrashSettingsView(BRect rect)
1299 	: SettingsView(rect, "TrashSettingsView")
1300 {
1301 	rect.OffsetTo(B_ORIGIN);
1302 	fDontMoveFilesToTrashCheckBox = new BCheckBox(rect, "", "Don't Move Files to Trash",
1303 			new BMessage(kDontMoveFilesToTrashChanged));
1304 	fDontMoveFilesToTrashCheckBox->ResizeToPreferred();
1305 	AddChild(fDontMoveFilesToTrashCheckBox);
1306 
1307 	rect = fDontMoveFilesToTrashCheckBox->Frame();
1308 	rect.OffsetBy(0, fDontMoveFilesToTrashCheckBox->Bounds().Height() + kItemExtraSpacing);
1309 
1310 	fAskBeforeDeleteFileCheckBox = new BCheckBox(rect, "", "Ask Before Delete",
1311 			new BMessage(kAskBeforeDeleteFileChanged));
1312 	fAskBeforeDeleteFileCheckBox->ResizeToPreferred();
1313 	AddChild(fAskBeforeDeleteFileCheckBox);
1314 }
1315 
1316 
1317 void
1318 TrashSettingsView::GetPreferredSize(float *_width, float *_height)
1319 {
1320 	if (_width != NULL) {
1321 		float width = fDontMoveFilesToTrashCheckBox->Bounds().Width();
1322 		if (width < fAskBeforeDeleteFileCheckBox->Bounds().Width())
1323 			width = fAskBeforeDeleteFileCheckBox->Bounds().Width();
1324 
1325 		*_width = width;
1326 	}
1327 
1328 	if (_height != NULL)
1329 		*_height = fAskBeforeDeleteFileCheckBox->Frame().bottom;
1330 }
1331 
1332 
1333 void
1334 TrashSettingsView::AttachedToWindow()
1335 {
1336 	fDontMoveFilesToTrashCheckBox->SetTarget(this);
1337 	fAskBeforeDeleteFileCheckBox->SetTarget(this);
1338 }
1339 
1340 
1341 void
1342 TrashSettingsView::MessageReceived(BMessage *message)
1343 {
1344 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
1345 	if (!tracker)
1346 		return;
1347 	TrackerSettings settings;
1348 
1349 	switch (message->what) {
1350 		case kDontMoveFilesToTrashChanged:
1351 			settings.SetDontMoveFilesToTrash(fDontMoveFilesToTrashCheckBox->Value() == 1);
1352 
1353 			tracker->SendNotices(kDontMoveFilesToTrashChanged);
1354 			Window()->PostMessage(kSettingsContentsModified);
1355 			break;
1356 
1357 		case kAskBeforeDeleteFileChanged:
1358 			settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFileCheckBox->Value() == 1);
1359 
1360 			tracker->SendNotices(kAskBeforeDeleteFileChanged);
1361 			Window()->PostMessage(kSettingsContentsModified);
1362 			break;
1363 
1364 		default:
1365 			_inherited::MessageReceived(message);
1366 			break;
1367 	}
1368 }
1369 
1370 
1371 void
1372 TrashSettingsView::SetDefaults()
1373 {
1374 	TrackerSettings settings;
1375 
1376 	settings.SetDontMoveFilesToTrash(false);
1377 	settings.SetAskBeforeDeleteFile(true);
1378 
1379 	ShowCurrentSettings();
1380 	_SendNotices();
1381 }
1382 
1383 
1384 bool
1385 TrashSettingsView::IsDefaultable() const
1386 {
1387 	TrackerSettings settings;
1388 
1389 	return settings.DontMoveFilesToTrash() != false
1390 		|| settings.AskBeforeDeleteFile() != true;
1391 }
1392 
1393 
1394 void
1395 TrashSettingsView::Revert()
1396 {
1397 	TrackerSettings settings;
1398 
1399 	settings.SetDontMoveFilesToTrash(fDontMoveFilesToTrash);
1400 	settings.SetAskBeforeDeleteFile(fAskBeforeDeleteFile);
1401 
1402 	ShowCurrentSettings();
1403 	_SendNotices();
1404 }
1405 
1406 
1407 void
1408 TrashSettingsView::_SendNotices()
1409 {
1410 	TTracker *tracker = dynamic_cast<TTracker *>(be_app);
1411 	if (!tracker)
1412 		return;
1413 
1414 	tracker->SendNotices(kDontMoveFilesToTrashChanged);
1415 	tracker->SendNotices(kAskBeforeDeleteFileChanged);
1416 }
1417 
1418 
1419 void
1420 TrashSettingsView::ShowCurrentSettings()
1421 {
1422 	TrackerSettings settings;
1423 
1424 	fDontMoveFilesToTrashCheckBox->SetValue(settings.DontMoveFilesToTrash());
1425 	fAskBeforeDeleteFileCheckBox->SetValue(settings.AskBeforeDeleteFile());
1426 }
1427 
1428 
1429 void
1430 TrashSettingsView::RecordRevertSettings()
1431 {
1432 	TrackerSettings settings;
1433 
1434 	fDontMoveFilesToTrash = settings.DontMoveFilesToTrash();
1435 	fAskBeforeDeleteFile = settings.AskBeforeDeleteFile();
1436 }
1437 
1438 
1439 bool
1440 TrashSettingsView::IsRevertable() const
1441 {
1442 	return fDontMoveFilesToTrash != (fDontMoveFilesToTrashCheckBox->Value() > 0)
1443 		|| fAskBeforeDeleteFile != (fAskBeforeDeleteFileCheckBox->Value() > 0);
1444 }
1445 
1446