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