Locale preflet : make the 12/24hr switching system more robust and lossless

* When selecting chinese, the AM/PM stays at the beginning of the string
 * When clicking multiple times on the 12 hours button, the AM/PM indicator is added only once.
 * Only regression : the default format for cherokee (US) uses a 12hour clock without AM/PM indicator, so it is not possible 
to switch it to a 24Hr clock scheme.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37628 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-07-20 17:44:14 +00:00
parent ce873ef04f
commit 2d67f5fcd6
3 changed files with 55 additions and 33 deletions
+2 -2
View File
@@ -617,8 +617,8 @@ BLocaleRoster::GetInstalledLanguages(BMessage *languages) const
status_t status_t
BLocaleRoster::GetInstalledCatalogs(BMessage * languageList, const char* sigPattern, BLocaleRoster::GetInstalledCatalogs(BMessage * languageList,
const char* langPattern, int32 fingerprint) const const char* sigPattern, const char* langPattern, int32 fingerprint) const
{ {
if (languageList == NULL) if (languageList == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -30,6 +30,8 @@
#include <TextControl.h> #include <TextControl.h>
#include <Window.h> #include <Window.h>
#include <iostream.h>
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "TimeFormatSettings" #define B_TRANSLATE_CONTEXT "TimeFormatSettings"
@@ -181,12 +183,15 @@ FormatView::FormatView(BCountry* country)
f12HrRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"), f12HrRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
new BMessage(kClockFormatChange)); new BMessage(kClockFormatChange));
BString timeFormat; fCountry->TimeFormat(fOriginalTimeFormat, false);
fCountry->TimeFormat(timeFormat, false); fCountry->TimeFormat(fOriginalLongTimeFormat, true);
if (timeFormat.FindFirst("a") != B_ERROR) if (fOriginalTimeFormat.FindFirst("a") != B_ERROR) {
f12HrRadioButton->SetValue(1); f12HrRadioButton->SetValue(B_CONTROL_ON);
else fCountryIs24Hr = false;
f24HrRadioButton->SetValue(1); } else {
f24HrRadioButton->SetValue(B_CONTROL_ON);
fCountryIs24Hr = true;
}
float spacing = be_control_look->DefaultItemSpacing(); float spacing = be_control_look->DefaultItemSpacing();
@@ -376,11 +381,11 @@ FormatView::MessageReceived(BMessage* message)
{ {
// Update one of the dropdown menus // Update one of the dropdown menus
void* pointerFromMessage; void* pointerFromMessage;
message->FindPointer("dest",&pointerFromMessage); message->FindPointer("dest", &pointerFromMessage);
BMenuField* menuField BMenuField* menuField
= static_cast<BMenuField*>(pointerFromMessage); = static_cast<BMenuField*>(pointerFromMessage);
BString format; BString format;
message->FindString("format",&format); message->FindString("format", &format);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
if (fLongDateMenu[i]==menuField) { if (fLongDateMenu[i]==menuField) {
@@ -437,30 +442,37 @@ FormatView::MessageReceived(BMessage* message)
case kClockFormatChange: case kClockFormatChange:
{ {
BString timeFormat; BString timeFormat;
fCountry->TimeFormat(timeFormat, false); timeFormat = fOriginalTimeFormat;
if (f24HrRadioButton->Value() == 1) { if (f24HrRadioButton->Value() == 1) {
timeFormat.ReplaceAll("k", "h"); if (!fCountryIs24Hr) {
timeFormat.ReplaceAll("K", "H"); timeFormat.ReplaceAll("h", "H");
timeFormat.RemoveAll(" a"); timeFormat.ReplaceAll("k", "K");
timeFormat.RemoveAll(" a");
timeFormat.RemoveAll("a");
}
} else { } else {
timeFormat.ReplaceAll("h", "k"); if (fCountryIs24Hr && timeFormat.FindFirst("a") == B_ERROR) {
timeFormat.ReplaceAll("H", "K"); timeFormat.ReplaceAll("K", "k");
timeFormat.Append(" a"); timeFormat.ReplaceAll("H", "h");
f12HrRadioButton->SetValue(true); timeFormat.Append(" a");
}
} }
fCountry->SetTimeFormat(timeFormat.String(), false); fCountry->SetTimeFormat(timeFormat.String(), false);
timeFormat.Truncate(0); timeFormat = fOriginalLongTimeFormat;
fCountry->TimeFormat(timeFormat, true);
if (f24HrRadioButton->Value() == 1) { if (f24HrRadioButton->Value() == 1) {
timeFormat.ReplaceAll("k", "h"); if (!fCountryIs24Hr) {
timeFormat.ReplaceAll("K", "H"); timeFormat.ReplaceAll("h", "H");
timeFormat.RemoveAll(" a"); timeFormat.ReplaceAll("k", "K");
timeFormat.RemoveAll(" a");
timeFormat.RemoveAll("a");
}
} else { } else {
timeFormat.ReplaceAll("h", "k"); if (fCountryIs24Hr && timeFormat.FindFirst("a") == B_ERROR) {
timeFormat.ReplaceAll("H", "K"); timeFormat.ReplaceAll("K", "k");
timeFormat.Append(" a"); timeFormat.ReplaceAll("H", "h");
timeFormat.Append(" a");
}
} }
fCountry->SetTimeFormat(timeFormat.String(), true); fCountry->SetTimeFormat(timeFormat.String(), true);
_UpdateExamples(); _UpdateExamples();
@@ -528,12 +540,18 @@ FormatView::SetCountry(BCountry* country)
delete fCountry; delete fCountry;
fCountry = country; fCountry = country;
BString timeFormat; fOriginalTimeFormat.Truncate(0);
fCountry->TimeFormat(timeFormat, false); fCountry->TimeFormat(fOriginalTimeFormat, false);
if (timeFormat.FindFirst("a") != B_ERROR) fOriginalLongTimeFormat.Truncate(0);
f12HrRadioButton->SetValue(1); fCountry->TimeFormat(fOriginalLongTimeFormat, true);
else
f24HrRadioButton->SetValue(1); if (fOriginalTimeFormat.FindFirst("a") != B_ERROR) {
f12HrRadioButton->SetValue(B_CONTROL_ON);
fCountryIs24Hr = false;
} else {
f24HrRadioButton->SetValue(B_CONTROL_ON);
fCountryIs24Hr = true;
}
/* /*
FormatSeparator separator = settings.TimeFormatSeparator(); FormatSeparator separator = settings.TimeFormatSeparator();
@@ -77,6 +77,10 @@ private:
FormatSeparator fSeparator; FormatSeparator fSeparator;
BString fDateFormat; BString fDateFormat;
BString fOriginalTimeFormat;
BString fOriginalLongTimeFormat;
bool fCountryIs24Hr;
BCountry* fCountry; BCountry* fCountry;
BBox* fDateBox; BBox* fDateBox;