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