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