1fb816644SAdrien Destugues /*
2fb816644SAdrien Destugues * Copyright 2009, Adrien Destugues, pulkomandy@gmail.com. All rights reserved.
3fb816644SAdrien Destugues * Distributed under the terms of the MIT License.
4fb816644SAdrien Destugues */
5fb816644SAdrien Destugues
6fb816644SAdrien Destugues
7fb816644SAdrien Destugues #include "FormatSettingsView.h"
86bb481c7SOliver Tappe
96bb481c7SOliver Tappe #include <stdlib.h>
10fb816644SAdrien Destugues
11fb816644SAdrien Destugues #include <Alert.h>
12fb816644SAdrien Destugues #include <Application.h>
13fb816644SAdrien Destugues #include <Catalog.h>
14fb816644SAdrien Destugues #include <CheckBox.h>
15fb816644SAdrien Destugues #include <ControlLook.h>
162a5e33a9SAdrien Destugues #include <DateFormat.h>
176fd2f4a0SOliver Tappe #include <GridLayout.h>
186fd2f4a0SOliver Tappe #include <GridLayoutBuilder.h>
19fb816644SAdrien Destugues #include <GroupLayout.h>
20fb816644SAdrien Destugues #include <GroupLayoutBuilder.h>
21fb816644SAdrien Destugues #include <LayoutBuilder.h>
22fb816644SAdrien Destugues #include <Locale.h>
23fb816644SAdrien Destugues #include <MutableLocaleRoster.h>
24fb816644SAdrien Destugues #include <Message.h>
25fb816644SAdrien Destugues #include <Menu.h>
26fb816644SAdrien Destugues #include <MenuField.h>
27fb816644SAdrien Destugues #include <MenuItem.h>
28e3857211SAdrien Destugues #include <NumberFormat.h>
29fb816644SAdrien Destugues #include <PopUpMenu.h>
30fb816644SAdrien Destugues #include <RadioButton.h>
31fb816644SAdrien Destugues #include <ScrollView.h>
32fb816644SAdrien Destugues #include <ScrollBar.h>
33fb816644SAdrien Destugues #include <SeparatorView.h>
346fd2f4a0SOliver Tappe #include <SpaceLayoutItem.h>
35fb816644SAdrien Destugues #include <String.h>
36fb816644SAdrien Destugues #include <StringView.h>
37fb816644SAdrien Destugues #include <TextControl.h>
3803b2550eSAdrien Destugues #include <TimeFormat.h>
39fb816644SAdrien Destugues #include <Window.h>
40fb816644SAdrien Destugues
416bb481c7SOliver Tappe #include "LocalePreflet.h"
42bca1690bSAdrien Destugues
43fb816644SAdrien Destugues
4425dc253dSIngo Weinhold using BPrivate::MutableLocaleRoster;
45fb816644SAdrien Destugues
46fb816644SAdrien Destugues
47546208a5SOliver Tappe #undef B_TRANSLATION_CONTEXT
48546208a5SOliver Tappe #define B_TRANSLATION_CONTEXT "TimeFormatSettings"
49fb816644SAdrien Destugues
50fb816644SAdrien Destugues
51fb816644SAdrien Destugues // #pragma mark -
52fb816644SAdrien Destugues
53fb816644SAdrien Destugues
FormatSettingsView()546fd2f4a0SOliver Tappe FormatSettingsView::FormatSettingsView()
55fb816644SAdrien Destugues :
566fd2f4a0SOliver Tappe BView("WindowsSettingsView", B_FRAME_EVENTS)
57fb816644SAdrien Destugues {
586fd2f4a0SOliver Tappe fUseLanguageStringsCheckBox = new BCheckBox(
596fd2f4a0SOliver Tappe B_TRANSLATE("Use month/day-names from preferred language"),
606fd2f4a0SOliver Tappe new BMessage(kStringsLanguageChange));
616fd2f4a0SOliver Tappe
6298e5fab3SAdrien Destugues fFilesystemTranslationCheckbox = new BCheckBox("filesystemTranslation",
6398e5fab3SAdrien Destugues B_TRANSLATE("Translate application and folder names"),
6498e5fab3SAdrien Destugues new BMessage(kMsgFilesystemTranslationChanged));
6598e5fab3SAdrien Destugues fFilesystemTranslationCheckbox->SetValue(
6698e5fab3SAdrien Destugues BLocaleRoster::Default()->IsFilesystemTranslationPreferred());
6798e5fab3SAdrien Destugues
686fd2f4a0SOliver Tappe BStringView* fullDateLabel
696fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Full format:"));
706fd2f4a0SOliver Tappe fullDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
716fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
726fd2f4a0SOliver Tappe BStringView* longDateLabel
736fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Long format:"));
746fd2f4a0SOliver Tappe longDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
756fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
766fd2f4a0SOliver Tappe BStringView* mediumDateLabel
776fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Medium format:"));
786fd2f4a0SOliver Tappe mediumDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
796fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
806fd2f4a0SOliver Tappe BStringView* shortDateLabel
816fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Short format:"));
826fd2f4a0SOliver Tappe shortDateLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
836fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
846fd2f4a0SOliver Tappe
856fd2f4a0SOliver Tappe fFullDateExampleView = new BStringView("", "");
866fd2f4a0SOliver Tappe fFullDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
876fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
88fb816644SAdrien Destugues fLongDateExampleView = new BStringView("", "");
896fd2f4a0SOliver Tappe fLongDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
906fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
916fd2f4a0SOliver Tappe fMediumDateExampleView = new BStringView("", "");
926fd2f4a0SOliver Tappe fMediumDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
936fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
94fb816644SAdrien Destugues fShortDateExampleView = new BStringView("", "");
956fd2f4a0SOliver Tappe fShortDateExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
966fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
97fb816644SAdrien Destugues
986fd2f4a0SOliver Tappe f24HourRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
99fb816644SAdrien Destugues new BMessage(kClockFormatChange));
1006fd2f4a0SOliver Tappe f12HourRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
101fb816644SAdrien Destugues new BMessage(kClockFormatChange));
102fb816644SAdrien Destugues
103fb816644SAdrien Destugues float spacing = be_control_look->DefaultItemSpacing();
104fb816644SAdrien Destugues
1056fd2f4a0SOliver Tappe BStringView* fullTimeLabel
1066fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Full format:"));
1076fd2f4a0SOliver Tappe fullTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1086fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1096fd2f4a0SOliver Tappe BStringView* longTimeLabel
1106fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Long format:"));
1116fd2f4a0SOliver Tappe longTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1126fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1136fd2f4a0SOliver Tappe BStringView* mediumTimeLabel
1146fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Medium format:"));
1156fd2f4a0SOliver Tappe mediumTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1166fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1176fd2f4a0SOliver Tappe BStringView* shortTimeLabel
1186fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Short format:"));
1196fd2f4a0SOliver Tappe shortTimeLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1206fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1216fd2f4a0SOliver Tappe
1226fd2f4a0SOliver Tappe fFullTimeExampleView = new BStringView("", "");
1236fd2f4a0SOliver Tappe fFullTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1246fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
125fb816644SAdrien Destugues fLongTimeExampleView = new BStringView("", "");
1266fd2f4a0SOliver Tappe fLongTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1276fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1286fd2f4a0SOliver Tappe fMediumTimeExampleView = new BStringView("", "");
1296fd2f4a0SOliver Tappe fMediumTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1306fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
131fb816644SAdrien Destugues fShortTimeExampleView = new BStringView("", "");
1326fd2f4a0SOliver Tappe fShortTimeExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1336fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
134fb816644SAdrien Destugues
1356fd2f4a0SOliver Tappe BStringView* positiveNumberLabel
1366fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Positive:"));
1376fd2f4a0SOliver Tappe positiveNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1386fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1396fd2f4a0SOliver Tappe BStringView* negativeNumberLabel
1406fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Negative:"));
1416fd2f4a0SOliver Tappe negativeNumberLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1426fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
143fb816644SAdrien Destugues
1446fd2f4a0SOliver Tappe fPositiveNumberExampleView = new BStringView("", "");
1456fd2f4a0SOliver Tappe fPositiveNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1466fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1476fd2f4a0SOliver Tappe fNegativeNumberExampleView = new BStringView("", "");
1486fd2f4a0SOliver Tappe fNegativeNumberExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1496fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
150fb816644SAdrien Destugues
1516fd2f4a0SOliver Tappe BStringView* positiveMonetaryLabel
1526fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Positive:"));
1536fd2f4a0SOliver Tappe positiveMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1546fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1556fd2f4a0SOliver Tappe BStringView* negativeMonetaryLabel
1566fd2f4a0SOliver Tappe = new BStringView("", B_TRANSLATE("Negative:"));
1576fd2f4a0SOliver Tappe negativeMonetaryLabel->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT,
1586fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
159fb816644SAdrien Destugues
1606fd2f4a0SOliver Tappe fPositiveMonetaryExampleView = new BStringView("", "");
1616fd2f4a0SOliver Tappe fPositiveMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1626fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
1636fd2f4a0SOliver Tappe fNegativeMonetaryExampleView = new BStringView("", "");
1646fd2f4a0SOliver Tappe fNegativeMonetaryExampleView->SetExplicitAlignment(BAlignment(B_ALIGN_RIGHT,
1656fd2f4a0SOliver Tappe B_ALIGN_VERTICAL_UNSET));
166fb816644SAdrien Destugues
1676fd2f4a0SOliver Tappe Refresh(true);
168fb816644SAdrien Destugues
169fb816644SAdrien Destugues fDateBox = new BBox(B_TRANSLATE("Date"));
170fb816644SAdrien Destugues fTimeBox = new BBox(B_TRANSLATE("Time"));
1716fd2f4a0SOliver Tappe fNumberBox = new BBox(B_TRANSLATE("Numbers"));
1726fd2f4a0SOliver Tappe fMonetaryBox = new BBox(B_TRANSLATE("Currency"));
173fb816644SAdrien Destugues
174fb816644SAdrien Destugues fDateBox->SetLabel(B_TRANSLATE("Date"));
175fb816644SAdrien Destugues fTimeBox->SetLabel(B_TRANSLATE("Time"));
1766fd2f4a0SOliver Tappe fNumberBox->SetLabel(B_TRANSLATE("Numbers"));
1776fd2f4a0SOliver Tappe fMonetaryBox->SetLabel(B_TRANSLATE("Currency"));
178fb816644SAdrien Destugues
1796fd2f4a0SOliver Tappe fDateBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
18025fd5c7bSAlex Wilson .SetInsets(spacing, spacing, spacing, spacing)
1816fd2f4a0SOliver Tappe .Add(fullDateLabel, 0, 0)
1826fd2f4a0SOliver Tappe .Add(fFullDateExampleView, 1, 0)
1836fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
1846fd2f4a0SOliver Tappe .Add(longDateLabel, 0, 1)
1856fd2f4a0SOliver Tappe .Add(fLongDateExampleView, 1, 1)
1866fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
1876fd2f4a0SOliver Tappe .Add(mediumDateLabel, 0, 2)
1886fd2f4a0SOliver Tappe .Add(fMediumDateExampleView, 1, 2)
1896fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
1906fd2f4a0SOliver Tappe .Add(shortDateLabel, 0, 3)
1916fd2f4a0SOliver Tappe .Add(fShortDateExampleView, 1, 3)
1926fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
19325fd5c7bSAlex Wilson .View());
194fb816644SAdrien Destugues
1956fd2f4a0SOliver Tappe fTimeBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
19625fd5c7bSAlex Wilson .SetInsets(spacing, spacing, spacing, spacing)
1976fd2f4a0SOliver Tappe .AddGroup(B_HORIZONTAL, spacing, 0, 0, 2)
1986fd2f4a0SOliver Tappe .Add(f24HourRadioButton, 0)
1996fd2f4a0SOliver Tappe .Add(f12HourRadioButton, 0)
200fb816644SAdrien Destugues .AddGlue()
201fb816644SAdrien Destugues .End()
2026fd2f4a0SOliver Tappe .Add(fullTimeLabel, 0, 1)
2036fd2f4a0SOliver Tappe .Add(fFullTimeExampleView, 1, 1)
2046fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
2056fd2f4a0SOliver Tappe .Add(longTimeLabel, 0, 2)
2066fd2f4a0SOliver Tappe .Add(fLongTimeExampleView, 1, 2)
2076fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 2)
2086fd2f4a0SOliver Tappe .Add(mediumTimeLabel, 0, 3)
2096fd2f4a0SOliver Tappe .Add(fMediumTimeExampleView, 1, 3)
2106fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 3)
2116fd2f4a0SOliver Tappe .Add(shortTimeLabel, 0, 4)
2126fd2f4a0SOliver Tappe .Add(fShortTimeExampleView, 1, 4)
2136fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 4)
21425fd5c7bSAlex Wilson .View());
215fb816644SAdrien Destugues
2166fd2f4a0SOliver Tappe fNumberBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
21725fd5c7bSAlex Wilson .SetInsets(spacing, spacing, spacing, spacing)
2186fd2f4a0SOliver Tappe .Add(positiveNumberLabel, 0, 0)
2196fd2f4a0SOliver Tappe .Add(fPositiveNumberExampleView, 1, 0)
2206fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2216fd2f4a0SOliver Tappe .Add(negativeNumberLabel, 0, 1)
2226fd2f4a0SOliver Tappe .Add(fNegativeNumberExampleView, 1, 1)
2236fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
22425fd5c7bSAlex Wilson .View());
225fb816644SAdrien Destugues
2266fd2f4a0SOliver Tappe fMonetaryBox->AddChild(BLayoutBuilder::Grid<>(spacing, spacing / 2)
22725fd5c7bSAlex Wilson .SetInsets(spacing, spacing, spacing, spacing)
2286fd2f4a0SOliver Tappe .Add(positiveMonetaryLabel, 0, 0)
2296fd2f4a0SOliver Tappe .Add(fPositiveMonetaryExampleView, 1, 0)
2306fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 0)
2316fd2f4a0SOliver Tappe .Add(negativeMonetaryLabel, 0, 1)
2326fd2f4a0SOliver Tappe .Add(fNegativeMonetaryExampleView, 1, 1)
2336fd2f4a0SOliver Tappe .Add(BSpaceLayoutItem::CreateGlue(), 2, 1)
23425fd5c7bSAlex Wilson .View());
235fb816644SAdrien Destugues
236f0650dc9Slooncraz SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
237f0650dc9Slooncraz
238ad926b25SHumdinger BLayoutBuilder::Group<>(this, B_VERTICAL)
23998e5fab3SAdrien Destugues .Add(fFilesystemTranslationCheckbox)
2406fd2f4a0SOliver Tappe .Add(fUseLanguageStringsCheckBox)
241fb816644SAdrien Destugues .Add(fDateBox)
242fb816644SAdrien Destugues .Add(fTimeBox)
2436fd2f4a0SOliver Tappe .AddGroup(B_HORIZONTAL, spacing)
2446fd2f4a0SOliver Tappe .Add(fNumberBox)
2456fd2f4a0SOliver Tappe .Add(fMonetaryBox)
246fb816644SAdrien Destugues .End()
24725fd5c7bSAlex Wilson .AddGlue();
248fb816644SAdrien Destugues }
249fb816644SAdrien Destugues
250fb816644SAdrien Destugues
~FormatSettingsView()2516fd2f4a0SOliver Tappe FormatSettingsView::~FormatSettingsView()
252fb816644SAdrien Destugues {
253fb816644SAdrien Destugues }
254fb816644SAdrien Destugues
255fb816644SAdrien Destugues
256fb816644SAdrien Destugues void
AttachedToWindow()2576fd2f4a0SOliver Tappe FormatSettingsView::AttachedToWindow()
258fb816644SAdrien Destugues {
25998e5fab3SAdrien Destugues fFilesystemTranslationCheckbox->SetTarget(Window());
2606fd2f4a0SOliver Tappe fUseLanguageStringsCheckBox->SetTarget(this);
2616fd2f4a0SOliver Tappe f24HourRadioButton->SetTarget(this);
2626fd2f4a0SOliver Tappe f12HourRadioButton->SetTarget(this);
263fb816644SAdrien Destugues }
264fb816644SAdrien Destugues
265fb816644SAdrien Destugues
266fb816644SAdrien Destugues void
MessageReceived(BMessage * message)2676fd2f4a0SOliver Tappe FormatSettingsView::MessageReceived(BMessage* message)
268fb816644SAdrien Destugues {
269fb816644SAdrien Destugues switch (message->what) {
27031c0024dSJohn Scipione case B_LOCALE_CHANGED:
27131c0024dSJohn Scipione {
27231c0024dSJohn Scipione // Time updated 12/24 hour clock
27331c0024dSJohn Scipione BFormattingConventions conventions;
27431c0024dSJohn Scipione BLocale::Default()->GetFormattingConventions(&conventions);
27531c0024dSJohn Scipione if (conventions.Use24HourClock())
27631c0024dSJohn Scipione f24HourRadioButton->SetValue(B_CONTROL_ON);
27731c0024dSJohn Scipione else
27831c0024dSJohn Scipione f12HourRadioButton->SetValue(B_CONTROL_ON);
27931c0024dSJohn Scipione
28031c0024dSJohn Scipione _UpdateExamples();
28131c0024dSJohn Scipione Window()->PostMessage(kMsgSettingsChanged);
28231c0024dSJohn Scipione break;
28331c0024dSJohn Scipione }
28431c0024dSJohn Scipione
285fb816644SAdrien Destugues case kClockFormatChange:
286fb816644SAdrien Destugues {
2876fd2f4a0SOliver Tappe BFormattingConventions conventions;
28825dc253dSIngo Weinhold BLocale::Default()->GetFormattingConventions(&conventions);
2896fd2f4a0SOliver Tappe conventions.SetExplicitUse24HourClock(
29031c0024dSJohn Scipione f24HourRadioButton->Value() == B_CONTROL_ON);
29125dc253dSIngo Weinhold MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
29225dc253dSIngo Weinhold conventions);
293fb816644SAdrien Destugues
294fb816644SAdrien Destugues _UpdateExamples();
2956fd2f4a0SOliver Tappe Window()->PostMessage(kMsgSettingsChanged);
2966fd2f4a0SOliver Tappe break;
2976fd2f4a0SOliver Tappe }
2986fd2f4a0SOliver Tappe
2996fd2f4a0SOliver Tappe case kStringsLanguageChange:
3006fd2f4a0SOliver Tappe {
3016fd2f4a0SOliver Tappe BFormattingConventions conventions;
30225dc253dSIngo Weinhold BLocale::Default()->GetFormattingConventions(&conventions);
3036fd2f4a0SOliver Tappe conventions.SetUseStringsFromPreferredLanguage(
3046fd2f4a0SOliver Tappe fUseLanguageStringsCheckBox->Value() ? true : false);
30525dc253dSIngo Weinhold MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
30625dc253dSIngo Weinhold conventions);
3076fd2f4a0SOliver Tappe
3086fd2f4a0SOliver Tappe _UpdateExamples();
3096fd2f4a0SOliver Tappe
3106fd2f4a0SOliver Tappe Window()->PostMessage(kMsgSettingsChanged);
311fb816644SAdrien Destugues break;
312fb816644SAdrien Destugues }
313fb816644SAdrien Destugues
314fb816644SAdrien Destugues default:
315fb816644SAdrien Destugues BView::MessageReceived(message);
316fb816644SAdrien Destugues }
317fb816644SAdrien Destugues }
318fb816644SAdrien Destugues
319fb816644SAdrien Destugues
320fb816644SAdrien Destugues void
Revert()3216fd2f4a0SOliver Tappe FormatSettingsView::Revert()
322fb816644SAdrien Destugues {
32325dc253dSIngo Weinhold MutableLocaleRoster::Default()->SetDefaultFormattingConventions(
32425dc253dSIngo Weinhold fInitialConventions);
325bca1690bSAdrien Destugues
32698e5fab3SAdrien Destugues fFilesystemTranslationCheckbox->SetValue(fInitialTranslateNames);
32798e5fab3SAdrien Destugues
328fb816644SAdrien Destugues _UpdateExamples();
329fb816644SAdrien Destugues }
330fb816644SAdrien Destugues
331fb816644SAdrien Destugues
332fb816644SAdrien Destugues void
Refresh(bool setInitial)3336fd2f4a0SOliver Tappe FormatSettingsView::Refresh(bool setInitial)
334fb816644SAdrien Destugues {
3356fd2f4a0SOliver Tappe BFormattingConventions conventions;
33625dc253dSIngo Weinhold BLocale::Default()->GetFormattingConventions(&conventions);
33798e5fab3SAdrien Destugues if (setInitial) {
3386fd2f4a0SOliver Tappe fInitialConventions = conventions;
33998e5fab3SAdrien Destugues fInitialTranslateNames
34098e5fab3SAdrien Destugues = BLocaleRoster::Default()->IsFilesystemTranslationPreferred();
34198e5fab3SAdrien Destugues }
3426fd2f4a0SOliver Tappe
3436fd2f4a0SOliver Tappe if (!conventions.Use24HourClock()) {
3446fd2f4a0SOliver Tappe f12HourRadioButton->SetValue(B_CONTROL_ON);
3456fd2f4a0SOliver Tappe fLocaleIs24Hour = false;
3466fd2f4a0SOliver Tappe } else {
3476fd2f4a0SOliver Tappe f24HourRadioButton->SetValue(B_CONTROL_ON);
3486fd2f4a0SOliver Tappe fLocaleIs24Hour = true;
3496fd2f4a0SOliver Tappe }
3506fd2f4a0SOliver Tappe
3516fd2f4a0SOliver Tappe fUseLanguageStringsCheckBox->SetValue(
3526fd2f4a0SOliver Tappe conventions.UseStringsFromPreferredLanguage()
3536fd2f4a0SOliver Tappe ? B_CONTROL_ON : B_CONTROL_OFF);
3546fd2f4a0SOliver Tappe
3556fd2f4a0SOliver Tappe _UpdateExamples();
356fb816644SAdrien Destugues }
357fb816644SAdrien Destugues
358fb816644SAdrien Destugues
3596fd2f4a0SOliver Tappe // Return true if the Revert button should be enabled (i.e. something has been
360fb816644SAdrien Destugues // changed)
361fb816644SAdrien Destugues bool
IsReversible() const3626fd2f4a0SOliver Tappe FormatSettingsView::IsReversible() const
363fb816644SAdrien Destugues {
3646fd2f4a0SOliver Tappe BFormattingConventions conventions;
36525dc253dSIngo Weinhold BLocale::Default()->GetFormattingConventions(&conventions);
366fb816644SAdrien Destugues
36798e5fab3SAdrien Destugues return (conventions != fInitialConventions)
36898e5fab3SAdrien Destugues || (fFilesystemTranslationCheckbox->Value() != fInitialTranslateNames);
369fb816644SAdrien Destugues }
370fb816644SAdrien Destugues
371fb816644SAdrien Destugues
372fb816644SAdrien Destugues void
_UpdateExamples()3736fd2f4a0SOliver Tappe FormatSettingsView::_UpdateExamples()
374fb816644SAdrien Destugues {
375fb816644SAdrien Destugues time_t timeValue = (time_t)time(NULL);
3766fd2f4a0SOliver Tappe BString result;
377fb816644SAdrien Destugues
37803b2550eSAdrien Destugues // Do NOT make these class members. We do want to recreate it everytime, as
3790a925409SAdrien Destugues // to get the updated settings from the locale roster.
3800a925409SAdrien Destugues BDateFormat dateFormat;
381e3857211SAdrien Destugues BNumberFormat numberFormat;
382*e523bfebSEmir SARI BString errorString = B_TRANSLATE("ERROR");
383*e523bfebSEmir SARI BTimeFormat timeFormat;
3840a925409SAdrien Destugues
3850a925409SAdrien Destugues dateFormat.Format(result, timeValue, B_FULL_DATE_FORMAT);
3866fd2f4a0SOliver Tappe fFullDateExampleView->SetText(result);
387fb816644SAdrien Destugues
3880a925409SAdrien Destugues dateFormat.Format(result, timeValue, B_LONG_DATE_FORMAT);
3896fd2f4a0SOliver Tappe fLongDateExampleView->SetText(result);
390fb816644SAdrien Destugues
3910a925409SAdrien Destugues dateFormat.Format(result, timeValue, B_MEDIUM_DATE_FORMAT);
3926fd2f4a0SOliver Tappe fMediumDateExampleView->SetText(result);
393fb816644SAdrien Destugues
3940a925409SAdrien Destugues dateFormat.Format(result, timeValue, B_SHORT_DATE_FORMAT);
3956fd2f4a0SOliver Tappe fShortDateExampleView->SetText(result);
396fb816644SAdrien Destugues
39703b2550eSAdrien Destugues timeFormat.Format(result, timeValue, B_FULL_TIME_FORMAT);
3986fd2f4a0SOliver Tappe fFullTimeExampleView->SetText(result);
3996fd2f4a0SOliver Tappe
40003b2550eSAdrien Destugues timeFormat.Format(result, timeValue, B_LONG_TIME_FORMAT);
4016fd2f4a0SOliver Tappe fLongTimeExampleView->SetText(result);
4026fd2f4a0SOliver Tappe
40303b2550eSAdrien Destugues timeFormat.Format(result, timeValue, B_MEDIUM_TIME_FORMAT);
4046fd2f4a0SOliver Tappe fMediumTimeExampleView->SetText(result);
4056fd2f4a0SOliver Tappe
40603b2550eSAdrien Destugues timeFormat.Format(result, timeValue, B_SHORT_TIME_FORMAT);
4076fd2f4a0SOliver Tappe fShortTimeExampleView->SetText(result);
4086fd2f4a0SOliver Tappe
409*e523bfebSEmir SARI status_t status = numberFormat.Format(result, 1234.56);
4106fd2f4a0SOliver Tappe if (status == B_OK)
4116fd2f4a0SOliver Tappe fPositiveNumberExampleView->SetText(result);
412fb816644SAdrien Destugues else
413*e523bfebSEmir SARI fPositiveNumberExampleView->SetText(errorString);
414fb816644SAdrien Destugues
415*e523bfebSEmir SARI status = numberFormat.Format(result, -1234.56);
4166fd2f4a0SOliver Tappe if (status == B_OK)
4176fd2f4a0SOliver Tappe fNegativeNumberExampleView->SetText(result);
4189e773899SAdrien Destugues else
419*e523bfebSEmir SARI fNegativeNumberExampleView->SetText(errorString);
420bca1690bSAdrien Destugues
421e3857211SAdrien Destugues status = numberFormat.FormatMonetary(result, 1234.56);
4226fd2f4a0SOliver Tappe if (status == B_OK)
4236fd2f4a0SOliver Tappe fPositiveMonetaryExampleView->SetText(result);
4246fd2f4a0SOliver Tappe else
425*e523bfebSEmir SARI fPositiveMonetaryExampleView->SetText(errorString);
426bca1690bSAdrien Destugues
427e3857211SAdrien Destugues status = numberFormat.FormatMonetary(result, -1234.56);
4286fd2f4a0SOliver Tappe if (status == B_OK)
4296fd2f4a0SOliver Tappe fNegativeMonetaryExampleView->SetText(result);
4306fd2f4a0SOliver Tappe else
431*e523bfebSEmir SARI fNegativeMonetaryExampleView->SetText(errorString);
432fb816644SAdrien Destugues }
433