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