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