xref: /haiku/src/preferences/locale/FormatSettingsView.cpp (revision fb816644a7e35901ffa240385f652c02e782f28e)
1*fb816644SAdrien Destugues /*
2*fb816644SAdrien Destugues  * Copyright 2009, Adrien Destugues, pulkomandy@gmail.com. All rights reserved.
3*fb816644SAdrien Destugues  * Distributed under the terms of the MIT License.
4*fb816644SAdrien Destugues  */
5*fb816644SAdrien Destugues 
6*fb816644SAdrien Destugues 
7*fb816644SAdrien Destugues #include "FormatSettingsView.h"
8*fb816644SAdrien Destugues #include "Locale.h"
9*fb816644SAdrien Destugues 
10*fb816644SAdrien Destugues #include <Alert.h>
11*fb816644SAdrien Destugues #include <Application.h>
12*fb816644SAdrien Destugues #include <Catalog.h>
13*fb816644SAdrien Destugues #include <CheckBox.h>
14*fb816644SAdrien Destugues #include <ControlLook.h>
15*fb816644SAdrien Destugues #include <Country.h>
16*fb816644SAdrien Destugues #include <GroupLayout.h>
17*fb816644SAdrien Destugues #include <GroupLayoutBuilder.h>
18*fb816644SAdrien Destugues #include <LayoutBuilder.h>
19*fb816644SAdrien Destugues #include <Locale.h>
20*fb816644SAdrien Destugues #include <MutableLocaleRoster.h>
21*fb816644SAdrien Destugues #include <Message.h>
22*fb816644SAdrien Destugues #include <Menu.h>
23*fb816644SAdrien Destugues #include <MenuField.h>
24*fb816644SAdrien Destugues #include <MenuItem.h>
25*fb816644SAdrien Destugues #include <PopUpMenu.h>
26*fb816644SAdrien Destugues #include <RadioButton.h>
27*fb816644SAdrien Destugues #include <ScrollView.h>
28*fb816644SAdrien Destugues #include <ScrollBar.h>
29*fb816644SAdrien Destugues #include <SeparatorView.h>
30*fb816644SAdrien Destugues #include <String.h>
31*fb816644SAdrien Destugues #include <StringView.h>
32*fb816644SAdrien Destugues #include <TextControl.h>
33*fb816644SAdrien Destugues #include <Window.h>
34*fb816644SAdrien Destugues 
35*fb816644SAdrien Destugues #include <iostream>
36*fb816644SAdrien Destugues 
37*fb816644SAdrien Destugues #include <stdio.h>
38*fb816644SAdrien Destugues 
39*fb816644SAdrien Destugues using BPrivate::mutable_locale_roster;
40*fb816644SAdrien Destugues 
41*fb816644SAdrien Destugues 
42*fb816644SAdrien Destugues #undef B_TRANSLATE_CONTEXT
43*fb816644SAdrien Destugues #define B_TRANSLATE_CONTEXT "TimeFormatSettings"
44*fb816644SAdrien Destugues 
45*fb816644SAdrien Destugues 
46*fb816644SAdrien Destugues class DateMenuItem: public BMenuItem {
47*fb816644SAdrien Destugues public:
48*fb816644SAdrien Destugues 	DateMenuItem(const char* label, const char* code, BMenuField* field)
49*fb816644SAdrien Destugues 		:
50*fb816644SAdrien Destugues 		BMenuItem(label, _MenuMessage(code, field))
51*fb816644SAdrien Destugues 	{
52*fb816644SAdrien Destugues 		fIcuCode = code;
53*fb816644SAdrien Destugues 	}
54*fb816644SAdrien Destugues 
55*fb816644SAdrien Destugues 	const BString& ICUCode() const
56*fb816644SAdrien Destugues 	{
57*fb816644SAdrien Destugues 		return fIcuCode;
58*fb816644SAdrien Destugues 	}
59*fb816644SAdrien Destugues 
60*fb816644SAdrien Destugues private:
61*fb816644SAdrien Destugues 	static BMessage* _MenuMessage(const char* format, BMenuField* field)
62*fb816644SAdrien Destugues 	{
63*fb816644SAdrien Destugues 		BMessage* msg = new BMessage(kMenuMessage);
64*fb816644SAdrien Destugues 		msg->AddPointer("dest", field);
65*fb816644SAdrien Destugues 		msg->AddString("format", format);
66*fb816644SAdrien Destugues 
67*fb816644SAdrien Destugues 		return msg;
68*fb816644SAdrien Destugues 	}
69*fb816644SAdrien Destugues 
70*fb816644SAdrien Destugues private:
71*fb816644SAdrien Destugues 	BString			fIcuCode;
72*fb816644SAdrien Destugues };
73*fb816644SAdrien Destugues 
74*fb816644SAdrien Destugues 
75*fb816644SAdrien Destugues void
76*fb816644SAdrien Destugues CreateDateMenu(BMenuField** field, bool longFormat = true)
77*fb816644SAdrien Destugues {
78*fb816644SAdrien Destugues 	BMenu* menu = new BMenu("");
79*fb816644SAdrien Destugues 	*field = new BMenuField("", menu);
80*fb816644SAdrien Destugues 
81*fb816644SAdrien Destugues 	BPopUpMenu* dayMenu = new BPopUpMenu(B_TRANSLATE("Day"));
82*fb816644SAdrien Destugues 	// Not all available ICU settings are listed here. It's possible to add some
83*fb816644SAdrien Destugues 	// other things if you ever need.
84*fb816644SAdrien Destugues 	menu->AddItem(dayMenu);
85*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
86*fb816644SAdrien Destugues 			B_TRANSLATE("Day in month"), "d", *field));
87*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
88*fb816644SAdrien Destugues 			B_TRANSLATE("Day in month (2 digits)"), "dd", *field));
89*fb816644SAdrien Destugues 		/*
90*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(B_TRANSLATE("Day in year"),
91*fb816644SAdrien Destugues 			"D", *field));
92*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(B_TRANSLATE("Day in year (2 digits)"),
93*fb816644SAdrien Destugues 			 "DD", *field));
94*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(B_TRANSLATE("Day in year (3 digits)"),
95*fb816644SAdrien Destugues 			"DDD", *field));
96*fb816644SAdrien Destugues 		*/
97*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
98*fb816644SAdrien Destugues 			B_TRANSLATE("Day of week"), "e", *field));
99*fb816644SAdrien Destugues 		// dayMenu->AddItem(new DateMenuItem("Day of week (short text)", "eee",
100*fb816644SAdrien Destugues 		//	*field));
101*fb816644SAdrien Destugues 		// dayMenu->AddItem(new DateMenuItem("Day of week (full text)", "eeee",
102*fb816644SAdrien Destugues 		//	*field));
103*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
104*fb816644SAdrien Destugues 			B_TRANSLATE("Day of week (short name)"), "E", *field));
105*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
106*fb816644SAdrien Destugues 			B_TRANSLATE("Day of week (name)"), "EEEE", *field));
107*fb816644SAdrien Destugues 		dayMenu->AddItem(new DateMenuItem(
108*fb816644SAdrien Destugues 			B_TRANSLATE("Day of week in month"), "F", *field));
109*fb816644SAdrien Destugues 		// dayMenu->AddItem(new DateMenuItem(
110*fb816644SAdrien Destugues 		//	B_TRANSLATE("julian day"), "g", *field));
111*fb816644SAdrien Destugues 		// dayMenu->AddItem(new BMenuItem("c", msg));
112*fb816644SAdrien Destugues 	BPopUpMenu* monthMenu = new BPopUpMenu(B_TRANSLATE("Month"));
113*fb816644SAdrien Destugues 	menu->AddItem(monthMenu);
114*fb816644SAdrien Destugues 		monthMenu->AddItem(new DateMenuItem(
115*fb816644SAdrien Destugues 			B_TRANSLATE("Month number"), "M", *field));
116*fb816644SAdrien Destugues 		monthMenu->AddItem(new DateMenuItem(
117*fb816644SAdrien Destugues 			B_TRANSLATE("Month number (2 digits)"), "MM", *field));
118*fb816644SAdrien Destugues 		monthMenu->AddItem(new DateMenuItem(
119*fb816644SAdrien Destugues 			B_TRANSLATE("Month name"), "MMMM", *field));
120*fb816644SAdrien Destugues 		// monthMenu->AddItem(new DateMenuItem("L", "L", *field));
121*fb816644SAdrien Destugues 	BPopUpMenu* yearMenu = new BPopUpMenu(B_TRANSLATE("Year"));
122*fb816644SAdrien Destugues 	menu->AddItem(yearMenu);
123*fb816644SAdrien Destugues 		// And here is some ICU kludge... sorry about that.
124*fb816644SAdrien Destugues 		if (longFormat)
125*fb816644SAdrien Destugues 			yearMenu->AddItem(new DateMenuItem(
126*fb816644SAdrien Destugues 				B_TRANSLATE("Year"), "y", *field));
127*fb816644SAdrien Destugues 		else {
128*fb816644SAdrien Destugues 			yearMenu->AddItem(new DateMenuItem(
129*fb816644SAdrien Destugues 				B_TRANSLATE("Year (4 digits)"), "yyyy", *field));
130*fb816644SAdrien Destugues 		}
131*fb816644SAdrien Destugues 		yearMenu->AddItem(new DateMenuItem(
132*fb816644SAdrien Destugues 			B_TRANSLATE("Year (2 digits)"), "yy", *field));
133*fb816644SAdrien Destugues 		// yearMenu->AddItem(new DateMenuItem("Y", "Y", *field));
134*fb816644SAdrien Destugues 		// yearMenu->AddItem(new DateMenuItem("u", "u", *field));
135*fb816644SAdrien Destugues }
136*fb816644SAdrien Destugues 
137*fb816644SAdrien Destugues 
138*fb816644SAdrien Destugues bool
139*fb816644SAdrien Destugues IsSpecialDateChar(char charToTest)
140*fb816644SAdrien Destugues {
141*fb816644SAdrien Destugues 	static const char* specials = "dDeEFgMLyYu";
142*fb816644SAdrien Destugues 	for (int i = 0; i < 11; i++)
143*fb816644SAdrien Destugues 		if (charToTest == specials[i])
144*fb816644SAdrien Destugues 			return true;
145*fb816644SAdrien Destugues 	return false;
146*fb816644SAdrien Destugues }
147*fb816644SAdrien Destugues 
148*fb816644SAdrien Destugues // #pragma mark -
149*fb816644SAdrien Destugues 
150*fb816644SAdrien Destugues 
151*fb816644SAdrien Destugues FormatView::FormatView(const BCountry& country)
152*fb816644SAdrien Destugues 	:
153*fb816644SAdrien Destugues 	BView("WindowsSettingsView", B_FRAME_EVENTS),
154*fb816644SAdrien Destugues 	fCountry(country)
155*fb816644SAdrien Destugues {
156*fb816644SAdrien Destugues 	SetLayout(new BGroupLayout(B_HORIZONTAL));
157*fb816644SAdrien Destugues 
158*fb816644SAdrien Destugues 	fLongDateExampleView = new BStringView("", "");
159*fb816644SAdrien Destugues 
160*fb816644SAdrien Destugues 	for (int i = 0; i < 4; i++) {
161*fb816644SAdrien Destugues 		CreateDateMenu(&fLongDateMenu[i]);
162*fb816644SAdrien Destugues 		fLongDateSeparator[i] = new BTextControl("", "", "",
163*fb816644SAdrien Destugues 			new BMessage(kSettingsContentsModified));
164*fb816644SAdrien Destugues 		fLongDateSeparator[i]->SetModificationMessage(
165*fb816644SAdrien Destugues 			new BMessage(kSettingsContentsModified));
166*fb816644SAdrien Destugues 	}
167*fb816644SAdrien Destugues 
168*fb816644SAdrien Destugues 	fShortDateExampleView = new BStringView("", "");
169*fb816644SAdrien Destugues 
170*fb816644SAdrien Destugues 	for (int i = 0; i < 3; i++) {
171*fb816644SAdrien Destugues 		CreateDateMenu(&fDateMenu[i], false);
172*fb816644SAdrien Destugues 	}
173*fb816644SAdrien Destugues 
174*fb816644SAdrien Destugues 	BPopUpMenu* menu = new BPopUpMenu(B_TRANSLATE("Separator"));
175*fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem(B_TRANSLATE("None"),
176*fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified)));
177*fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem(B_TRANSLATE("Space"),
178*fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified)));
179*fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("-", new BMessage(kSettingsContentsModified)));
180*fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("/", new BMessage(kSettingsContentsModified)));
181*fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("\\", new BMessage(kSettingsContentsModified)));
182*fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem(".", new BMessage(kSettingsContentsModified)));
183*fb816644SAdrien Destugues 
184*fb816644SAdrien Destugues 	fSeparatorMenuField = new BMenuField(B_TRANSLATE("Separator:"), menu);
185*fb816644SAdrien Destugues 
186*fb816644SAdrien Destugues 	f24HrRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
187*fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
188*fb816644SAdrien Destugues 
189*fb816644SAdrien Destugues 	f12HrRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
190*fb816644SAdrien Destugues 		new BMessage(kClockFormatChange));
191*fb816644SAdrien Destugues 
192*fb816644SAdrien Destugues 	fCountry.GetTimeFormat(fOriginalTimeFormat, false);
193*fb816644SAdrien Destugues 	fCountry.GetTimeFormat(fOriginalLongTimeFormat, true);
194*fb816644SAdrien Destugues 	if (fOriginalTimeFormat.FindFirst("a") != B_ERROR) {
195*fb816644SAdrien Destugues 		f12HrRadioButton->SetValue(B_CONTROL_ON);
196*fb816644SAdrien Destugues 		fCountryIs24Hr = false;
197*fb816644SAdrien Destugues 	} else {
198*fb816644SAdrien Destugues 		f24HrRadioButton->SetValue(B_CONTROL_ON);
199*fb816644SAdrien Destugues 		fCountryIs24Hr = true;
200*fb816644SAdrien Destugues 	}
201*fb816644SAdrien Destugues 
202*fb816644SAdrien Destugues 	float spacing = be_control_look->DefaultItemSpacing();
203*fb816644SAdrien Destugues 
204*fb816644SAdrien Destugues 	fLongTimeExampleView = new BStringView("", "");
205*fb816644SAdrien Destugues 	fShortTimeExampleView = new BStringView("", "");
206*fb816644SAdrien Destugues 
207*fb816644SAdrien Destugues 	fNumberFormatExampleView = new BStringView("", "");
208*fb816644SAdrien Destugues 
209*fb816644SAdrien Destugues 	BTextControl* numberThousand = new BTextControl("",
210*fb816644SAdrien Destugues 		B_TRANSLATE("Thousand separator: "), "",
211*fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
212*fb816644SAdrien Destugues 	BTextControl* numberDecimal = new BTextControl("",
213*fb816644SAdrien Destugues 		B_TRANSLATE("Decimal separator: "),	"",
214*fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
215*fb816644SAdrien Destugues 	// TODO number of decimal digits (spinbox ?)
216*fb816644SAdrien Destugues 	BCheckBox* numberLeadingZero = new BCheckBox("", B_TRANSLATE("Leading 0"),
217*fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
218*fb816644SAdrien Destugues 	BTextControl* numberList = new BTextControl("",
219*fb816644SAdrien Destugues 		B_TRANSLATE("List separator: "), "",
220*fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
221*fb816644SAdrien Destugues 	// Unit system (US/Metric) (radio)
222*fb816644SAdrien Destugues 
223*fb816644SAdrien Destugues 	BTextControl* currencySymbol = new BTextControl("",
224*fb816644SAdrien Destugues 		B_TRANSLATE("Currency symbol:"), "",
225*fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
226*fb816644SAdrien Destugues 	menu = new BPopUpMenu(B_TRANSLATE("Negative marker"));
227*fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("-", new BMessage(kSettingsContentsModified)));
228*fb816644SAdrien Destugues 	menu->AddItem(new BMenuItem("()", new BMessage(kSettingsContentsModified)));
229*fb816644SAdrien Destugues 
230*fb816644SAdrien Destugues 	BMenuField* currencyNegative = new BMenuField(
231*fb816644SAdrien Destugues 		B_TRANSLATE("Negative marker:"), menu);
232*fb816644SAdrien Destugues 
233*fb816644SAdrien Destugues 	BTextControl* currencyDecimal = new BTextControl("",
234*fb816644SAdrien Destugues 		B_TRANSLATE("Decimal separator: "), "",
235*fb816644SAdrien Destugues 		new BMessage(kSettingsContentsModified));
236*fb816644SAdrien Destugues 	BCheckBox* currencyLeadingZero = new BCheckBox("",
237*fb816644SAdrien Destugues 		B_TRANSLATE("Leading 0"), new BMessage(kSettingsContentsModified));
238*fb816644SAdrien Destugues 
239*fb816644SAdrien Destugues 	BBox* formatBox = new BBox("Symbol position");
240*fb816644SAdrien Destugues 	formatBox->SetLabel(B_TRANSLATE("Symbol position"));
241*fb816644SAdrien Destugues 
242*fb816644SAdrien Destugues 	BRadioButton* beforeRadioButton = new BRadioButton("",
243*fb816644SAdrien Destugues 		B_TRANSLATE("Before"), new BMessage(kSettingsContentsModified));
244*fb816644SAdrien Destugues 
245*fb816644SAdrien Destugues 	BRadioButton* afterRadioButton = new BRadioButton("",
246*fb816644SAdrien Destugues 		B_TRANSLATE("After"), new BMessage(kSettingsContentsModified));
247*fb816644SAdrien Destugues 
248*fb816644SAdrien Destugues 	formatBox->AddChild(BGroupLayoutBuilder(B_VERTICAL)
249*fb816644SAdrien Destugues 		.Add(beforeRadioButton)
250*fb816644SAdrien Destugues 		.Add(afterRadioButton)
251*fb816644SAdrien Destugues 		.SetInsets(spacing, 0, spacing, 0));
252*fb816644SAdrien Destugues 
253*fb816644SAdrien Destugues 	_UpdateExamples();
254*fb816644SAdrien Destugues 	_ParseDateFormat();
255*fb816644SAdrien Destugues 
256*fb816644SAdrien Destugues 	fDateBox = new BBox(B_TRANSLATE("Date"));
257*fb816644SAdrien Destugues 	fTimeBox = new BBox(B_TRANSLATE("Time"));
258*fb816644SAdrien Destugues 	fNumbersBox = new BBox(B_TRANSLATE("Numbers"));
259*fb816644SAdrien Destugues 	fCurrencyBox = new BBox(B_TRANSLATE("Currency"));
260*fb816644SAdrien Destugues 
261*fb816644SAdrien Destugues 	fDateBox->SetLabel(B_TRANSLATE("Date"));
262*fb816644SAdrien Destugues 	fTimeBox->SetLabel(B_TRANSLATE("Time"));
263*fb816644SAdrien Destugues 	fNumbersBox->SetLabel(B_TRANSLATE("Numbers"));
264*fb816644SAdrien Destugues 	fCurrencyBox->SetLabel(B_TRANSLATE("Currency"));
265*fb816644SAdrien Destugues 
266*fb816644SAdrien Destugues 	fDateBox->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL)
267*fb816644SAdrien Destugues 		.AddGroup(B_VERTICAL, spacing / 2)
268*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
269*fb816644SAdrien Destugues 				.Add(new BStringView("", B_TRANSLATE("Long format:")))
270*fb816644SAdrien Destugues 				.Add(fLongDateExampleView)
271*fb816644SAdrien Destugues 				.AddGlue()
272*fb816644SAdrien Destugues 				.End()
273*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
274*fb816644SAdrien Destugues 				.Add(fLongDateMenu[0])
275*fb816644SAdrien Destugues 				.Add(fLongDateSeparator[0])
276*fb816644SAdrien Destugues 				.End()
277*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
278*fb816644SAdrien Destugues 				.Add(fLongDateMenu[1])
279*fb816644SAdrien Destugues 				.Add(fLongDateSeparator[1])
280*fb816644SAdrien Destugues 				.End()
281*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
282*fb816644SAdrien Destugues 				.Add(fLongDateMenu[2])
283*fb816644SAdrien Destugues 				.Add(fLongDateSeparator[2])
284*fb816644SAdrien Destugues 				.End()
285*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
286*fb816644SAdrien Destugues 				.Add(fLongDateMenu[3])
287*fb816644SAdrien Destugues 				.Add(fLongDateSeparator[3])
288*fb816644SAdrien Destugues 				.End()
289*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
290*fb816644SAdrien Destugues 				.Add(new BStringView("", B_TRANSLATE("Short format:")))
291*fb816644SAdrien Destugues 				.Add(fShortDateExampleView)
292*fb816644SAdrien Destugues 				.AddGlue()
293*fb816644SAdrien Destugues 				.End()
294*fb816644SAdrien Destugues 			.Add(fDateMenu[0])
295*fb816644SAdrien Destugues 			.Add(fDateMenu[1])
296*fb816644SAdrien Destugues 			.Add(fDateMenu[2])
297*fb816644SAdrien Destugues 			.End()
298*fb816644SAdrien Destugues 		.SetInsets(spacing, spacing, spacing, spacing));
299*fb816644SAdrien Destugues 
300*fb816644SAdrien Destugues 	fTimeBox->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, spacing)
301*fb816644SAdrien Destugues 		.AddGroup(B_VERTICAL, spacing / 2)
302*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
303*fb816644SAdrien Destugues 				.Add(new BStringView("", B_TRANSLATE("Long format:")))
304*fb816644SAdrien Destugues 				.Add(fLongTimeExampleView)
305*fb816644SAdrien Destugues 				.AddGlue()
306*fb816644SAdrien Destugues 				.End()
307*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
308*fb816644SAdrien Destugues 				.Add(new BStringView("", B_TRANSLATE("Short format:")))
309*fb816644SAdrien Destugues 				.Add(fShortTimeExampleView)
310*fb816644SAdrien Destugues 				.AddGlue()
311*fb816644SAdrien Destugues 				.End()
312*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
313*fb816644SAdrien Destugues 				.Add(f24HrRadioButton)
314*fb816644SAdrien Destugues 				.Add(f12HrRadioButton)
315*fb816644SAdrien Destugues 				.AddGlue()
316*fb816644SAdrien Destugues 				.End()
317*fb816644SAdrien Destugues 			.End()
318*fb816644SAdrien Destugues 		.SetInsets(spacing, spacing, spacing, spacing));
319*fb816644SAdrien Destugues 
320*fb816644SAdrien Destugues 	fNumbersBox->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, spacing)
321*fb816644SAdrien Destugues 		.AddGroup(B_VERTICAL, spacing / 2)
322*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
323*fb816644SAdrien Destugues 				.Add(new BStringView("", B_TRANSLATE("Example:")))
324*fb816644SAdrien Destugues 				.Add(fNumberFormatExampleView)
325*fb816644SAdrien Destugues 				.AddGlue()
326*fb816644SAdrien Destugues 				.End()
327*fb816644SAdrien Destugues 			.Add(numberThousand)
328*fb816644SAdrien Destugues 			.Add(numberDecimal)
329*fb816644SAdrien Destugues 			.Add(numberLeadingZero)
330*fb816644SAdrien Destugues 			.Add(numberList)
331*fb816644SAdrien Destugues 			.End()
332*fb816644SAdrien Destugues 		.SetInsets(spacing, spacing, spacing, spacing));
333*fb816644SAdrien Destugues 
334*fb816644SAdrien Destugues 	fCurrencyBox->AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, spacing)
335*fb816644SAdrien Destugues 		.AddGroup(B_VERTICAL, spacing / 2)
336*fb816644SAdrien Destugues 			.Add(currencySymbol)
337*fb816644SAdrien Destugues 			.Add(currencyNegative)
338*fb816644SAdrien Destugues 			.Add(currencyDecimal)
339*fb816644SAdrien Destugues 			.Add(currencyLeadingZero)
340*fb816644SAdrien Destugues 			.AddGroup(B_HORIZONTAL, spacing)
341*fb816644SAdrien Destugues 				.Add(formatBox)
342*fb816644SAdrien Destugues 				.AddGlue()
343*fb816644SAdrien Destugues 				.End()
344*fb816644SAdrien Destugues 			.End()
345*fb816644SAdrien Destugues 		.SetInsets(spacing, spacing, spacing, spacing));
346*fb816644SAdrien Destugues 
347*fb816644SAdrien Destugues 	AddChild(BLayoutBuilder::Group<>(B_HORIZONTAL, spacing)
348*fb816644SAdrien Destugues 		.AddGroup(B_VERTICAL, spacing)
349*fb816644SAdrien Destugues 			.Add(fDateBox)
350*fb816644SAdrien Destugues 			.Add(fTimeBox)
351*fb816644SAdrien Destugues 			.AddGlue()
352*fb816644SAdrien Destugues 			.End()
353*fb816644SAdrien Destugues 		.AddGroup(B_VERTICAL, spacing)
354*fb816644SAdrien Destugues 			.Add(fNumbersBox)
355*fb816644SAdrien Destugues 			.Add(fCurrencyBox)
356*fb816644SAdrien Destugues 			.AddGlue()
357*fb816644SAdrien Destugues 			.End());
358*fb816644SAdrien Destugues }
359*fb816644SAdrien Destugues 
360*fb816644SAdrien Destugues 
361*fb816644SAdrien Destugues FormatView::~FormatView()
362*fb816644SAdrien Destugues {
363*fb816644SAdrien Destugues 	mutable_locale_roster->SetDefaultCountry(fCountry);
364*fb816644SAdrien Destugues }
365*fb816644SAdrien Destugues 
366*fb816644SAdrien Destugues 
367*fb816644SAdrien Destugues void
368*fb816644SAdrien Destugues FormatView::AttachedToWindow()
369*fb816644SAdrien Destugues {
370*fb816644SAdrien Destugues 	f24HrRadioButton->SetTarget(this);
371*fb816644SAdrien Destugues 	f12HrRadioButton->SetTarget(this);
372*fb816644SAdrien Destugues 
373*fb816644SAdrien Destugues 	for (int j = 0; j < 4; j++) {
374*fb816644SAdrien Destugues 		for (int i = 0; i < fLongDateMenu[j]->Menu()->CountItems(); i++)
375*fb816644SAdrien Destugues 			fLongDateMenu[j]->Menu()->SubmenuAt(i)->SetTargetForItems(this);
376*fb816644SAdrien Destugues 		fLongDateSeparator[j]->SetTarget(this);
377*fb816644SAdrien Destugues 	}
378*fb816644SAdrien Destugues 
379*fb816644SAdrien Destugues 	for (int j = 0; j < 3; j++) {
380*fb816644SAdrien Destugues 		for (int i = 0; i < fDateMenu[j]->Menu()->CountItems(); i++)
381*fb816644SAdrien Destugues 			fDateMenu[j]->Menu()->SubmenuAt(i)->SetTargetForItems(this);
382*fb816644SAdrien Destugues 	}
383*fb816644SAdrien Destugues 
384*fb816644SAdrien Destugues 	fSeparatorMenuField->Menu()->SetTargetForItems(this);
385*fb816644SAdrien Destugues }
386*fb816644SAdrien Destugues 
387*fb816644SAdrien Destugues 
388*fb816644SAdrien Destugues void
389*fb816644SAdrien Destugues FormatView::MessageReceived(BMessage* message)
390*fb816644SAdrien Destugues {
391*fb816644SAdrien Destugues 	switch (message->what) {
392*fb816644SAdrien Destugues 		case kMenuMessage:
393*fb816644SAdrien Destugues 		{
394*fb816644SAdrien Destugues 			// Update one of the dropdown menus
395*fb816644SAdrien Destugues 			void* pointerFromMessage;
396*fb816644SAdrien Destugues 			message->FindPointer("dest", &pointerFromMessage);
397*fb816644SAdrien Destugues 			BMenuField* menuField
398*fb816644SAdrien Destugues 			= static_cast<BMenuField*>(pointerFromMessage);
399*fb816644SAdrien Destugues 			BString format;
400*fb816644SAdrien Destugues 			message->FindString("format", &format);
401*fb816644SAdrien Destugues 
402*fb816644SAdrien Destugues 			for (int i = 0; i < 4; i++) {
403*fb816644SAdrien Destugues 				if (fLongDateMenu[i]==menuField) {
404*fb816644SAdrien Destugues 					fLongDateString[i] = format;
405*fb816644SAdrien Destugues 					break;
406*fb816644SAdrien Destugues 				}
407*fb816644SAdrien Destugues 			}
408*fb816644SAdrien Destugues 
409*fb816644SAdrien Destugues 			for (int i = 0; i < 3; i++) {
410*fb816644SAdrien Destugues 				if (fDateMenu[i]==menuField) {
411*fb816644SAdrien Destugues 					fDateString[i] = format;
412*fb816644SAdrien Destugues 					break;
413*fb816644SAdrien Destugues 				}
414*fb816644SAdrien Destugues 			}
415*fb816644SAdrien Destugues 
416*fb816644SAdrien Destugues 			message->FindPointer("source", &pointerFromMessage);
417*fb816644SAdrien Destugues 			BMenuItem* menuItem = static_cast<BMenuItem*>(pointerFromMessage);
418*fb816644SAdrien Destugues 
419*fb816644SAdrien Destugues 			menuField->MenuItem()->SetLabel(menuItem->Label());
420*fb816644SAdrien Destugues 
421*fb816644SAdrien Destugues 			_UpdateLongDateFormatString();
422*fb816644SAdrien Destugues 		}
423*fb816644SAdrien Destugues 		// pass trough
424*fb816644SAdrien Destugues 		case kSettingsContentsModified:
425*fb816644SAdrien Destugues 			{
426*fb816644SAdrien Destugues 				int32 separator = 0;
427*fb816644SAdrien Destugues 				BMenuItem* item = fSeparatorMenuField->Menu()->FindMarked();
428*fb816644SAdrien Destugues 				if (item) {
429*fb816644SAdrien Destugues 					separator = fSeparatorMenuField->Menu()->IndexOf(item);
430*fb816644SAdrien Destugues 					if (separator >= 0)
431*fb816644SAdrien Destugues 						// settings.SetTimeFormatSeparator(
432*fb816644SAdrien Destugues 						//	(FormatSeparator)separator);
433*fb816644SAdrien Destugues 						;
434*fb816644SAdrien Destugues 				}
435*fb816644SAdrien Destugues 
436*fb816644SAdrien Destugues 				// TODO send that to our Settings class
437*fb816644SAdrien Destugues 				// settings.SetDateOrderFormat(format);
438*fb816644SAdrien Destugues 				// settings.SetClockTo24Hr(f24HrRadioButton->Value() == 1);
439*fb816644SAdrien Destugues 
440*fb816644SAdrien Destugues 				// Make the notification message and send it to the tracker:
441*fb816644SAdrien Destugues 				BMessage notificationMessage;
442*fb816644SAdrien Destugues 				notificationMessage.AddInt32("TimeFormatSeparator", separator);
443*fb816644SAdrien Destugues 				notificationMessage.AddBool("24HrClock",
444*fb816644SAdrien Destugues 					f24HrRadioButton->Value() == 1);
445*fb816644SAdrien Destugues 				// tracker->SendNotices(kDateFormatChanged,
446*fb816644SAdrien Destugues 				// 	&notificationMessage);
447*fb816644SAdrien Destugues 
448*fb816644SAdrien Destugues 				_UpdateExamples();
449*fb816644SAdrien Destugues 
450*fb816644SAdrien Destugues 				Window()->PostMessage(kSettingsContentsModified);
451*fb816644SAdrien Destugues 				break;
452*fb816644SAdrien Destugues 			}
453*fb816644SAdrien Destugues 
454*fb816644SAdrien Destugues 		case kClockFormatChange:
455*fb816644SAdrien Destugues 		{
456*fb816644SAdrien Destugues 			BMessage newMessage(kMsgSettingsChanged);
457*fb816644SAdrien Destugues 
458*fb816644SAdrien Destugues 			BString timeFormat;
459*fb816644SAdrien Destugues 			timeFormat = fOriginalTimeFormat;
460*fb816644SAdrien Destugues 			if (f24HrRadioButton->Value() == 1) {
461*fb816644SAdrien Destugues 				if (!fCountryIs24Hr) {
462*fb816644SAdrien Destugues 					timeFormat.ReplaceAll("h", "H");
463*fb816644SAdrien Destugues 					timeFormat.ReplaceAll("k", "K");
464*fb816644SAdrien Destugues 					timeFormat.RemoveAll(" a");
465*fb816644SAdrien Destugues 					timeFormat.RemoveAll("a");
466*fb816644SAdrien Destugues 				}
467*fb816644SAdrien Destugues 			} else {
468*fb816644SAdrien Destugues 				if (fCountryIs24Hr && timeFormat.FindFirst("a") == B_ERROR) {
469*fb816644SAdrien Destugues 					timeFormat.ReplaceAll("K", "k");
470*fb816644SAdrien Destugues 					timeFormat.ReplaceAll("H", "h");
471*fb816644SAdrien Destugues 					timeFormat.Append(" a");
472*fb816644SAdrien Destugues 				}
473*fb816644SAdrien Destugues 			}
474*fb816644SAdrien Destugues 			fCountry.SetTimeFormat(timeFormat.String(), false);
475*fb816644SAdrien Destugues 			newMessage.AddString("shortTimeFormat", timeFormat);
476*fb816644SAdrien Destugues 
477*fb816644SAdrien Destugues 			timeFormat = fOriginalLongTimeFormat;
478*fb816644SAdrien Destugues 			if (f24HrRadioButton->Value() == 1) {
479*fb816644SAdrien Destugues 				if (!fCountryIs24Hr) {
480*fb816644SAdrien Destugues 					timeFormat.ReplaceAll("h", "H");
481*fb816644SAdrien Destugues 					timeFormat.ReplaceAll("k", "K");
482*fb816644SAdrien Destugues 					timeFormat.RemoveAll(" a");
483*fb816644SAdrien Destugues 					timeFormat.RemoveAll("a");
484*fb816644SAdrien Destugues 				}
485*fb816644SAdrien Destugues 			} else {
486*fb816644SAdrien Destugues 				if (fCountryIs24Hr && timeFormat.FindFirst("a") == B_ERROR) {
487*fb816644SAdrien Destugues 					timeFormat.ReplaceAll("K", "k");
488*fb816644SAdrien Destugues 					timeFormat.ReplaceAll("H", "h");
489*fb816644SAdrien Destugues 					timeFormat.Append(" a");
490*fb816644SAdrien Destugues 				}
491*fb816644SAdrien Destugues 			}
492*fb816644SAdrien Destugues 			fCountry.SetTimeFormat(timeFormat.String(), true);
493*fb816644SAdrien Destugues 			newMessage.AddString("longTimeFormat", timeFormat);
494*fb816644SAdrien Destugues 			_UpdateExamples();
495*fb816644SAdrien Destugues 			Window()->PostMessage(kSettingsContentsModified);
496*fb816644SAdrien Destugues 			be_app_messenger.SendMessage(&newMessage);
497*fb816644SAdrien Destugues 			break;
498*fb816644SAdrien Destugues 		}
499*fb816644SAdrien Destugues 
500*fb816644SAdrien Destugues 		default:
501*fb816644SAdrien Destugues 			BView::MessageReceived(message);
502*fb816644SAdrien Destugues 	}
503*fb816644SAdrien Destugues }
504*fb816644SAdrien Destugues 
505*fb816644SAdrien Destugues 
506*fb816644SAdrien Destugues void
507*fb816644SAdrien Destugues FormatView::SetDefaults()
508*fb816644SAdrien Destugues {
509*fb816644SAdrien Destugues 	/*
510*fb816644SAdrien Destugues 	TrackerSettings settings;
511*fb816644SAdrien Destugues 
512*fb816644SAdrien Destugues 	settings.SetTimeFormatSeparator(kSlashSeparator);
513*fb816644SAdrien Destugues 	settings.SetDateOrderFormat(kMDYFormat);
514*fb816644SAdrien Destugues 	settings.SetClockTo24Hr(false);
515*fb816644SAdrien Destugues 	*/
516*fb816644SAdrien Destugues 
517*fb816644SAdrien Destugues 	BCountry defaultCountry;
518*fb816644SAdrien Destugues 	be_locale_roster->GetDefaultCountry(&defaultCountry);
519*fb816644SAdrien Destugues 	fCountry = defaultCountry;
520*fb816644SAdrien Destugues 		// We work on a copy of the default country and set the changes when
521*fb816644SAdrien Destugues 		// closing the preflet
522*fb816644SAdrien Destugues 	_UpdateExamples();
523*fb816644SAdrien Destugues 	_SendNotices();
524*fb816644SAdrien Destugues }
525*fb816644SAdrien Destugues 
526*fb816644SAdrien Destugues 
527*fb816644SAdrien Destugues bool
528*fb816644SAdrien Destugues FormatView::IsDefaultable() const
529*fb816644SAdrien Destugues {
530*fb816644SAdrien Destugues 	/*
531*fb816644SAdrien Destugues 	TrackerSettings settings;
532*fb816644SAdrien Destugues 
533*fb816644SAdrien Destugues 	return settings.TimeFormatSeparator() != kSlashSeparator
534*fb816644SAdrien Destugues 		|| settings.DateOrderFormat() != kMDYFormat
535*fb816644SAdrien Destugues 		|| settings.ClockIs24Hr() != false;
536*fb816644SAdrien Destugues 	*/
537*fb816644SAdrien Destugues 	return true;
538*fb816644SAdrien Destugues }
539*fb816644SAdrien Destugues 
540*fb816644SAdrien Destugues 
541*fb816644SAdrien Destugues void
542*fb816644SAdrien Destugues FormatView::Revert()
543*fb816644SAdrien Destugues {
544*fb816644SAdrien Destugues 	/*
545*fb816644SAdrien Destugues 	TrackerSettings settings;
546*fb816644SAdrien Destugues 
547*fb816644SAdrien Destugues 	settings.SetTimeFormatSeparator(fSeparator);
548*fb816644SAdrien Destugues 	settings.SetDateOrderFormat(fFormat);
549*fb816644SAdrien Destugues 	settings.SetClockTo24Hr(f24HrClock);
550*fb816644SAdrien Destugues 	*/
551*fb816644SAdrien Destugues 
552*fb816644SAdrien Destugues 	// ShowCurrentSettings();
553*fb816644SAdrien Destugues 	_SendNotices();
554*fb816644SAdrien Destugues }
555*fb816644SAdrien Destugues 
556*fb816644SAdrien Destugues 
557*fb816644SAdrien Destugues void
558*fb816644SAdrien Destugues FormatView::SetCountry(const BCountry& country)
559*fb816644SAdrien Destugues {
560*fb816644SAdrien Destugues 	fCountry = country;
561*fb816644SAdrien Destugues 
562*fb816644SAdrien Destugues 	fCountry.GetTimeFormat(fOriginalTimeFormat, false);
563*fb816644SAdrien Destugues 	fCountry.GetTimeFormat(fOriginalLongTimeFormat, true);
564*fb816644SAdrien Destugues 
565*fb816644SAdrien Destugues 	if (fOriginalTimeFormat.FindFirst("a") != B_ERROR) {
566*fb816644SAdrien Destugues 		f12HrRadioButton->SetValue(B_CONTROL_ON);
567*fb816644SAdrien Destugues 		fCountryIs24Hr = false;
568*fb816644SAdrien Destugues 	} else {
569*fb816644SAdrien Destugues 		f24HrRadioButton->SetValue(B_CONTROL_ON);
570*fb816644SAdrien Destugues 		fCountryIs24Hr = true;
571*fb816644SAdrien Destugues 	}
572*fb816644SAdrien Destugues 
573*fb816644SAdrien Destugues 	/*
574*fb816644SAdrien Destugues 	FormatSeparator separator = settings.TimeFormatSeparator();
575*fb816644SAdrien Destugues 
576*fb816644SAdrien Destugues 	if (separator >= kNoSeparator && separator < kSeparatorsEnd)
577*fb816644SAdrien Destugues 		fSeparatorMenuField->Menu()->ItemAt((int32)separator)->SetMarked(true);
578*fb816644SAdrien Destugues 	*/
579*fb816644SAdrien Destugues 	_UpdateExamples();
580*fb816644SAdrien Destugues 	_ParseDateFormat();
581*fb816644SAdrien Destugues }
582*fb816644SAdrien Destugues 
583*fb816644SAdrien Destugues 
584*fb816644SAdrien Destugues void
585*fb816644SAdrien Destugues FormatView::RecordRevertSettings()
586*fb816644SAdrien Destugues {
587*fb816644SAdrien Destugues 	/*
588*fb816644SAdrien Destugues 	f24HrClock = settings.ClockIs24Hr();
589*fb816644SAdrien Destugues 	fSeparator = settings.TimeFormatSeparator();
590*fb816644SAdrien Destugues 	fFormat = settings.DateOrderFormat();
591*fb816644SAdrien Destugues 	*/
592*fb816644SAdrien Destugues }
593*fb816644SAdrien Destugues 
594*fb816644SAdrien Destugues 
595*fb816644SAdrien Destugues // Return true if the Revert button should be enabled (ie some setting was
596*fb816644SAdrien Destugues // changed)
597*fb816644SAdrien Destugues bool
598*fb816644SAdrien Destugues FormatView::IsRevertable() const
599*fb816644SAdrien Destugues {
600*fb816644SAdrien Destugues 	FormatSeparator separator;
601*fb816644SAdrien Destugues 
602*fb816644SAdrien Destugues 	BMenuItem* item = fSeparatorMenuField->Menu()->FindMarked();
603*fb816644SAdrien Destugues 	if (item) {
604*fb816644SAdrien Destugues 		int32 index = fSeparatorMenuField->Menu()->IndexOf(item);
605*fb816644SAdrien Destugues 		if (index >= 0)
606*fb816644SAdrien Destugues 			separator = (FormatSeparator)index;
607*fb816644SAdrien Destugues 		else
608*fb816644SAdrien Destugues 			return true;
609*fb816644SAdrien Destugues 	} else
610*fb816644SAdrien Destugues 		return true;
611*fb816644SAdrien Destugues 
612*fb816644SAdrien Destugues 	// TODO generate ICU string and compare to the initial one
613*fb816644SAdrien Destugues 	BString dateFormat ;
614*fb816644SAdrien Destugues 		// fYMDRadioButton->Value() ? kYMDFormat :
615*fb816644SAdrien Destugues 		//(fDMYRadioButton->Value() ? kDMYFormat : kMDYFormat);
616*fb816644SAdrien Destugues 
617*fb816644SAdrien Destugues 	return f24HrClock != (f24HrRadioButton->Value() > 0)
618*fb816644SAdrien Destugues 		|| separator != fSeparator
619*fb816644SAdrien Destugues 		|| dateFormat != fDateFormat;
620*fb816644SAdrien Destugues }
621*fb816644SAdrien Destugues 
622*fb816644SAdrien Destugues 
623*fb816644SAdrien Destugues void
624*fb816644SAdrien Destugues FormatView::_UpdateExamples()
625*fb816644SAdrien Destugues {
626*fb816644SAdrien Destugues 	time_t timeValue = (time_t)time(NULL);
627*fb816644SAdrien Destugues 	BString timeFormat;
628*fb816644SAdrien Destugues 
629*fb816644SAdrien Destugues 	fCountry.FormatDate(&timeFormat, timeValue, true);
630*fb816644SAdrien Destugues 	fLongDateExampleView->SetText(timeFormat);
631*fb816644SAdrien Destugues 
632*fb816644SAdrien Destugues 	fCountry.FormatDate(&timeFormat, timeValue, false);
633*fb816644SAdrien Destugues 	fShortDateExampleView->SetText(timeFormat);
634*fb816644SAdrien Destugues 
635*fb816644SAdrien Destugues 	fCountry.FormatTime(&timeFormat, timeValue, true);
636*fb816644SAdrien Destugues 	fLongTimeExampleView->SetText(timeFormat);
637*fb816644SAdrien Destugues 
638*fb816644SAdrien Destugues 	fCountry.FormatTime(&timeFormat, timeValue, false);
639*fb816644SAdrien Destugues 	fShortTimeExampleView->SetText(timeFormat);
640*fb816644SAdrien Destugues 
641*fb816644SAdrien Destugues 	status_t Error = fCountry.FormatNumber(&timeFormat, 1234.5678);
642*fb816644SAdrien Destugues 	if (Error == B_OK)
643*fb816644SAdrien Destugues 		fNumberFormatExampleView->SetText(timeFormat);
644*fb816644SAdrien Destugues 	else
645*fb816644SAdrien Destugues 		fNumberFormatExampleView->SetText("ERROR");
646*fb816644SAdrien Destugues }
647*fb816644SAdrien Destugues 
648*fb816644SAdrien Destugues 
649*fb816644SAdrien Destugues void
650*fb816644SAdrien Destugues FormatView::_SendNotices()
651*fb816644SAdrien Destugues {
652*fb816644SAdrien Destugues 	// Make the notification message and send it to the tracker:
653*fb816644SAdrien Destugues 	/*
654*fb816644SAdrien Destugues 	BMessage notificationMessage;
655*fb816644SAdrien Destugues 	notificationMessage.AddInt32("TimeFormatSeparator",
656*fb816644SAdrien Destugues 		(int32)settings.TimeFormatSeparator());
657*fb816644SAdrien Destugues 	notificationMessage.AddInt32("DateOrderFormat",
658*fb816644SAdrien Destugues 		(int32)settings.DateOrderFormat());
659*fb816644SAdrien Destugues 	notificationMessage.AddBool("24HrClock", settings.ClockIs24Hr());
660*fb816644SAdrien Destugues 	tracker->SendNotices(kDateFormatChanged, &notificationMessage);
661*fb816644SAdrien Destugues 	*/
662*fb816644SAdrien Destugues }
663*fb816644SAdrien Destugues 
664*fb816644SAdrien Destugues 
665*fb816644SAdrien Destugues //! Get the date format from ICU and set the date fields accordingly
666*fb816644SAdrien Destugues void
667*fb816644SAdrien Destugues FormatView::_ParseDateFormat()
668*fb816644SAdrien Destugues {
669*fb816644SAdrien Destugues 	// TODO parse the short date too
670*fb816644SAdrien Destugues 	BString dateFormatString;
671*fb816644SAdrien Destugues 	fCountry.GetDateFormat(dateFormatString, true);
672*fb816644SAdrien Destugues 	const char* dateFormat = dateFormatString.String();
673*fb816644SAdrien Destugues 
674*fb816644SAdrien Destugues printf("FV::_ParseDateFormat: df='%s'\n", dateFormat);
675*fb816644SAdrien Destugues 
676*fb816644SAdrien Destugues 	// Travel through the string and parse it
677*fb816644SAdrien Destugues 	const char* parsePointer = dateFormat;
678*fb816644SAdrien Destugues 	const char* fieldBegin = dateFormat;
679*fb816644SAdrien Destugues 
680*fb816644SAdrien Destugues 	for (int i = 0; i < 4; i++)
681*fb816644SAdrien Destugues 	{
682*fb816644SAdrien Destugues 		fieldBegin = parsePointer;
683*fb816644SAdrien Destugues 		while (*parsePointer == *(parsePointer + 1)) parsePointer++ ;
684*fb816644SAdrien Destugues 		parsePointer++;
685*fb816644SAdrien Destugues 		BString str;
686*fb816644SAdrien Destugues 		str.Append(fieldBegin, parsePointer - fieldBegin);
687*fb816644SAdrien Destugues 
688*fb816644SAdrien Destugues 		fLongDateString[i] = str;
689*fb816644SAdrien Destugues 
690*fb816644SAdrien Destugues 		BMenu* subMenu;
691*fb816644SAdrien Destugues 		bool isFound = false;
692*fb816644SAdrien Destugues 		for (int subMenuIndex = 0; subMenuIndex < 3; subMenuIndex++) {
693*fb816644SAdrien Destugues 			subMenu = fLongDateMenu[i]->Menu()->SubmenuAt(subMenuIndex);
694*fb816644SAdrien Destugues 			BMenuItem* item;
695*fb816644SAdrien Destugues 			for (int itemIndex = 0; (item = subMenu->ItemAt(itemIndex)) != NULL;
696*fb816644SAdrien Destugues 					itemIndex++) {
697*fb816644SAdrien Destugues 				if (static_cast<DateMenuItem*>(item)->ICUCode() == str) {
698*fb816644SAdrien Destugues 					item->SetMarked(true);
699*fb816644SAdrien Destugues 					fLongDateMenu[i]->MenuItem()->SetLabel(item->Label());
700*fb816644SAdrien Destugues 					isFound = true;
701*fb816644SAdrien Destugues 				} else
702*fb816644SAdrien Destugues 					item->SetMarked(false);
703*fb816644SAdrien Destugues 			}
704*fb816644SAdrien Destugues 		}
705*fb816644SAdrien Destugues 
706*fb816644SAdrien Destugues 		if (!isFound)
707*fb816644SAdrien Destugues 			fLongDateMenu[i]->MenuItem()->SetLabel(str.Append("*"));
708*fb816644SAdrien Destugues 
709*fb816644SAdrien Destugues 		fieldBegin = parsePointer;
710*fb816644SAdrien Destugues 		while ((!IsSpecialDateChar(*parsePointer)) && *parsePointer != '\0'
711*fb816644SAdrien Destugues 				&& *(parsePointer - 1) >= 0) {
712*fb816644SAdrien Destugues 			if (*parsePointer == '\'') {
713*fb816644SAdrien Destugues 				parsePointer++;
714*fb816644SAdrien Destugues 				while (*parsePointer != '\'') parsePointer++;
715*fb816644SAdrien Destugues 			}
716*fb816644SAdrien Destugues 			parsePointer++;
717*fb816644SAdrien Destugues 		}
718*fb816644SAdrien Destugues 		str.Truncate(0);
719*fb816644SAdrien Destugues 		str.Append(fieldBegin, parsePointer - fieldBegin);
720*fb816644SAdrien Destugues 		fLongDateSeparator[i]->SetText(str);
721*fb816644SAdrien Destugues 	}
722*fb816644SAdrien Destugues 
723*fb816644SAdrien Destugues 	// Short date is a bit more tricky, we want to extract the separator
724*fb816644SAdrien Destugues 	fCountry.GetDateFormat(dateFormatString, false);
725*fb816644SAdrien Destugues 	dateFormat = dateFormatString.String();
726*fb816644SAdrien Destugues 
727*fb816644SAdrien Destugues 	// Travel trough the string and parse it
728*fb816644SAdrien Destugues 	parsePointer = dateFormat;
729*fb816644SAdrien Destugues 	fieldBegin = dateFormat;
730*fb816644SAdrien Destugues 
731*fb816644SAdrien Destugues 	for (int i = 0; i < 3; i++) {
732*fb816644SAdrien Destugues 		fieldBegin = parsePointer;
733*fb816644SAdrien Destugues 		while (*parsePointer == *(parsePointer + 1)) parsePointer++ ;
734*fb816644SAdrien Destugues 		parsePointer++;
735*fb816644SAdrien Destugues 		BString str;
736*fb816644SAdrien Destugues 		str.Append(fieldBegin, parsePointer - fieldBegin);
737*fb816644SAdrien Destugues 
738*fb816644SAdrien Destugues 		fLongDateString[i] = str;
739*fb816644SAdrien Destugues 
740*fb816644SAdrien Destugues 		BMenu* subMenu;
741*fb816644SAdrien Destugues 		bool isFound = false;
742*fb816644SAdrien Destugues 		for (int subMenuIndex = 0; subMenuIndex < 3; subMenuIndex++) {
743*fb816644SAdrien Destugues 			subMenu = fDateMenu[i]->Menu()->SubmenuAt(subMenuIndex);
744*fb816644SAdrien Destugues 			BMenuItem* item;
745*fb816644SAdrien Destugues 			for (int itemIndex = 0; (item = subMenu->ItemAt(itemIndex)) != NULL;
746*fb816644SAdrien Destugues 					itemIndex++) {
747*fb816644SAdrien Destugues 				if (static_cast<DateMenuItem*>(item)->ICUCode() == str) {
748*fb816644SAdrien Destugues 					item->SetMarked(true);
749*fb816644SAdrien Destugues 					fDateMenu[i]->MenuItem()->SetLabel(item->Label());
750*fb816644SAdrien Destugues 					isFound = true;
751*fb816644SAdrien Destugues 				} else
752*fb816644SAdrien Destugues 					item->SetMarked(false);
753*fb816644SAdrien Destugues 			}
754*fb816644SAdrien Destugues 		}
755*fb816644SAdrien Destugues 
756*fb816644SAdrien Destugues 		if (!isFound) {
757*fb816644SAdrien Destugues 			fDateMenu[i]->MenuItem()->SetLabel(
758*fb816644SAdrien Destugues 				str.Append(B_TRANSLATE(" (unknown format)")));
759*fb816644SAdrien Destugues 		}
760*fb816644SAdrien Destugues 
761*fb816644SAdrien Destugues 		fieldBegin = parsePointer;
762*fb816644SAdrien Destugues 		while ((!IsSpecialDateChar(*parsePointer)) && *parsePointer != '\0'
763*fb816644SAdrien Destugues 				&& *(parsePointer - 1) >= 0) {
764*fb816644SAdrien Destugues 			if (*parsePointer == '\'') {
765*fb816644SAdrien Destugues 				parsePointer++;
766*fb816644SAdrien Destugues 				while (*parsePointer != '\'') parsePointer++;
767*fb816644SAdrien Destugues 			}
768*fb816644SAdrien Destugues 			parsePointer++;
769*fb816644SAdrien Destugues 		}
770*fb816644SAdrien Destugues 		if (parsePointer - fieldBegin > 0) {
771*fb816644SAdrien Destugues 			str.Truncate(0);
772*fb816644SAdrien Destugues 			str.Append(fieldBegin, parsePointer - fieldBegin);
773*fb816644SAdrien Destugues 			fSeparatorMenuField->MenuItem()->SetLabel(str);
774*fb816644SAdrien Destugues 		}
775*fb816644SAdrien Destugues 	}
776*fb816644SAdrien Destugues }
777*fb816644SAdrien Destugues 
778*fb816644SAdrien Destugues 
779*fb816644SAdrien Destugues void
780*fb816644SAdrien Destugues FormatView::_UpdateLongDateFormatString()
781*fb816644SAdrien Destugues {
782*fb816644SAdrien Destugues 	BString newDateFormat;
783*fb816644SAdrien Destugues 
784*fb816644SAdrien Destugues 	for (int i = 0; i < 4; i++) {
785*fb816644SAdrien Destugues 		newDateFormat.Append(fLongDateString[i]);
786*fb816644SAdrien Destugues 		newDateFormat.Append(fLongDateSeparator[i]->Text());
787*fb816644SAdrien Destugues 	}
788*fb816644SAdrien Destugues 
789*fb816644SAdrien Destugues 	// TODO save this in the settings preflet and make the roster load it back
790*fb816644SAdrien Destugues 	fCountry.SetDateFormat(newDateFormat.String());
791*fb816644SAdrien Destugues 
792*fb816644SAdrien Destugues 	newDateFormat.Truncate(0);
793*fb816644SAdrien Destugues 
794*fb816644SAdrien Destugues 	newDateFormat.Append(fDateString[0]);
795*fb816644SAdrien Destugues 	newDateFormat.Append(fSeparatorMenuField->MenuItem()->Label());
796*fb816644SAdrien Destugues 	newDateFormat.Append(fDateString[1]);
797*fb816644SAdrien Destugues 	newDateFormat.Append(fSeparatorMenuField->MenuItem()->Label());
798*fb816644SAdrien Destugues 	newDateFormat.Append(fDateString[2]);
799*fb816644SAdrien Destugues 
800*fb816644SAdrien Destugues 	// TODO save this in the settings preflet and make the roster load it back
801*fb816644SAdrien Destugues 	fCountry.SetDateFormat(newDateFormat.String(), false);
802*fb816644SAdrien Destugues }
803