Support for setting 12/24Hr mode in locale preflet.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37427 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -45,6 +45,8 @@ class BCountry {
|
|||||||
bool DateFormat(BString&, bool longFormat) const;
|
bool DateFormat(BString&, bool longFormat) const;
|
||||||
void SetDateFormat(const char* formatString,
|
void SetDateFormat(const char* formatString,
|
||||||
bool longFormat = true);
|
bool longFormat = true);
|
||||||
|
void SetTimeFormat(const char* formatString,
|
||||||
|
bool longFormat = true);
|
||||||
bool TimeFormat(BString&, bool longFormat) const;
|
bool TimeFormat(BString&, bool longFormat) const;
|
||||||
const char* DateSeparator() const;
|
const char* DateSeparator() const;
|
||||||
const char* TimeSeparator() const;
|
const char* TimeSeparator() const;
|
||||||
@@ -85,6 +87,8 @@ class BCountry {
|
|||||||
private:
|
private:
|
||||||
icu_4_2::DateFormat* fICULongDateFormatter;
|
icu_4_2::DateFormat* fICULongDateFormatter;
|
||||||
icu_4_2::DateFormat* fICUShortDateFormatter;
|
icu_4_2::DateFormat* fICUShortDateFormatter;
|
||||||
|
icu_4_2::DateFormat* fICULongTimeFormatter;
|
||||||
|
icu_4_2::DateFormat* fICUShortTimeFormatter;
|
||||||
const char** fStrings;
|
const char** fStrings;
|
||||||
icu_4_2::Locale* fICULocale;
|
icu_4_2::Locale* fICULocale;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -54,6 +54,14 @@ BCountry::BCountry(const char* languageCode, const char* countryCode)
|
|||||||
fStrings(gStrings)
|
fStrings(gStrings)
|
||||||
{
|
{
|
||||||
fICULocale = new icu_4_2::Locale(languageCode, countryCode);
|
fICULocale = new icu_4_2::Locale(languageCode, countryCode);
|
||||||
|
fICULongDateFormatter = DateFormat::createDateInstance(
|
||||||
|
DateFormat::FULL, *fICULocale);
|
||||||
|
fICUShortDateFormatter = DateFormat::createDateInstance(
|
||||||
|
DateFormat::SHORT, *fICULocale);
|
||||||
|
fICULongTimeFormatter = DateFormat::createTimeInstance(
|
||||||
|
DateFormat::MEDIUM, *fICULocale);
|
||||||
|
fICUShortTimeFormatter = DateFormat::createTimeInstance(
|
||||||
|
DateFormat::SHORT, *fICULocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,11 +74,19 @@ BCountry::BCountry(const char* languageAndCountryCode)
|
|||||||
DateFormat::FULL, *fICULocale);
|
DateFormat::FULL, *fICULocale);
|
||||||
fICUShortDateFormatter = DateFormat::createDateInstance(
|
fICUShortDateFormatter = DateFormat::createDateInstance(
|
||||||
DateFormat::SHORT, *fICULocale);
|
DateFormat::SHORT, *fICULocale);
|
||||||
|
fICULongTimeFormatter = DateFormat::createTimeInstance(
|
||||||
|
DateFormat::MEDIUM, *fICULocale);
|
||||||
|
fICUShortTimeFormatter = DateFormat::createTimeInstance(
|
||||||
|
DateFormat::SHORT, *fICULocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BCountry::~BCountry()
|
BCountry::~BCountry()
|
||||||
{
|
{
|
||||||
|
delete fICULongTimeFormatter;
|
||||||
|
delete fICUShortTimeFormatter;
|
||||||
|
delete fICULongDateFormatter;
|
||||||
|
delete fICUShortDateFormatter;
|
||||||
delete fICULocale;
|
delete fICULocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,9 +184,7 @@ BCountry::FormatTime(BString* string, time_t time, bool longFormat)
|
|||||||
// TODO: ICU allows for 4 different levels of expansion :
|
// TODO: ICU allows for 4 different levels of expansion :
|
||||||
// short, medium, long, and full. Our bool parameter is not enough...
|
// short, medium, long, and full. Our bool parameter is not enough...
|
||||||
icu_4_2::DateFormat* timeFormatter;
|
icu_4_2::DateFormat* timeFormatter;
|
||||||
timeFormatter = DateFormat::createTimeInstance(
|
timeFormatter = longFormat ? fICULongTimeFormatter : fICUShortTimeFormatter;
|
||||||
longFormat ? DateFormat::MEDIUM : DateFormat::SHORT,
|
|
||||||
*fICULocale);
|
|
||||||
UnicodeString ICUString;
|
UnicodeString ICUString;
|
||||||
ICUString = timeFormatter->format((UDate)time * 1000, ICUString);
|
ICUString = timeFormatter->format((UDate)time * 1000, ICUString);
|
||||||
|
|
||||||
@@ -178,8 +192,6 @@ BCountry::FormatTime(BString* string, time_t time, bool longFormat)
|
|||||||
BStringByteSink stringConverter(string);
|
BStringByteSink stringConverter(string);
|
||||||
|
|
||||||
ICUString.toUTF8(stringConverter);
|
ICUString.toUTF8(stringConverter);
|
||||||
|
|
||||||
delete timeFormatter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -215,13 +227,24 @@ BCountry::SetDateFormat(const char* formatString, bool longFormat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BCountry::SetTimeFormat(const char* formatString, bool longFormat)
|
||||||
|
{
|
||||||
|
icu_4_2::DateFormat* dateFormatter
|
||||||
|
= longFormat ? fICULongTimeFormatter : fICUShortTimeFormatter;
|
||||||
|
SimpleDateFormat* dateFormatterImpl
|
||||||
|
= static_cast<SimpleDateFormat*>(dateFormatter);
|
||||||
|
|
||||||
|
UnicodeString pattern(formatString);
|
||||||
|
dateFormatterImpl->applyPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BCountry::TimeFormat(BString& format, bool longFormat) const
|
BCountry::TimeFormat(BString& format, bool longFormat) const
|
||||||
{
|
{
|
||||||
icu_4_2::DateFormat* dateFormatter;
|
icu_4_2::DateFormat* dateFormatter;
|
||||||
dateFormatter = DateFormat::createTimeInstance(
|
dateFormatter = longFormat ? fICULongTimeFormatter : fICUShortTimeFormatter;
|
||||||
longFormat ? DateFormat::FULL : DateFormat::SHORT,
|
|
||||||
*fICULocale);
|
|
||||||
SimpleDateFormat* dateFormatterImpl
|
SimpleDateFormat* dateFormatterImpl
|
||||||
= static_cast<SimpleDateFormat*>(dateFormatter);
|
= static_cast<SimpleDateFormat*>(dateFormatter);
|
||||||
|
|
||||||
|
|||||||
@@ -38,8 +38,5 @@ BLocale::GetString(uint32 id)
|
|||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if (id >= B_LANGUAGE_STRINGS_BASE)
|
return fLanguage->GetString(id);
|
||||||
return fLanguage->GetString(id);
|
|
||||||
|
|
||||||
return fCountry->GetString(id);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include "TimeFormatSettingsView.h"
|
#include "TimeFormatSettingsView.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include <Alert.h>
|
#include <Alert.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <CheckBox.h>
|
#include <CheckBox.h>
|
||||||
@@ -139,7 +141,6 @@ IsSpecialDateChar(char charToTest)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -182,10 +183,17 @@ FormatView::FormatView(BCountry* country)
|
|||||||
clockBox->SetLabel(B_TRANSLATE("Clock"));
|
clockBox->SetLabel(B_TRANSLATE("Clock"));
|
||||||
|
|
||||||
f24HrRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
|
f24HrRadioButton = new BRadioButton("", B_TRANSLATE("24 hour"),
|
||||||
new BMessage(kSettingsContentsModified));
|
new BMessage(kClockFormatChange));
|
||||||
|
|
||||||
f12HrRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
|
f12HrRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
|
||||||
new BMessage(kSettingsContentsModified));
|
new BMessage(kClockFormatChange));
|
||||||
|
|
||||||
|
BString timeFormat;
|
||||||
|
fCountry->TimeFormat(timeFormat, false);
|
||||||
|
if (timeFormat.FindFirst(" a"))
|
||||||
|
f12HrRadioButton->SetValue(1);
|
||||||
|
else
|
||||||
|
f24HrRadioButton->SetValue(1);
|
||||||
|
|
||||||
float spacing = be_control_look->DefaultItemSpacing();
|
float spacing = be_control_look->DefaultItemSpacing();
|
||||||
|
|
||||||
@@ -414,7 +422,8 @@ FormatView::MessageReceived(BMessage* message)
|
|||||||
if (item) {
|
if (item) {
|
||||||
separator = fSeparatorMenuField->Menu()->IndexOf(item);
|
separator = fSeparatorMenuField->Menu()->IndexOf(item);
|
||||||
if (separator >= 0)
|
if (separator >= 0)
|
||||||
//settings.SetTimeFormatSeparator((FormatSeparator)separator);
|
//settings.SetTimeFormatSeparator(
|
||||||
|
// (FormatSeparator)separator);
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -427,7 +436,8 @@ FormatView::MessageReceived(BMessage* message)
|
|||||||
notificationMessage.AddInt32("TimeFormatSeparator", separator);
|
notificationMessage.AddInt32("TimeFormatSeparator", separator);
|
||||||
notificationMessage.AddBool("24HrClock",
|
notificationMessage.AddBool("24HrClock",
|
||||||
f24HrRadioButton->Value() == 1);
|
f24HrRadioButton->Value() == 1);
|
||||||
// tracker->SendNotices(kDateFormatChanged, ¬ificationMessage);
|
// tracker->SendNotices(kDateFormatChanged,
|
||||||
|
// ¬ificationMessage);
|
||||||
|
|
||||||
_UpdateExamples();
|
_UpdateExamples();
|
||||||
|
|
||||||
@@ -435,6 +445,41 @@ FormatView::MessageReceived(BMessage* message)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case kClockFormatChange:
|
||||||
|
{
|
||||||
|
BString timeFormat;
|
||||||
|
fCountry->TimeFormat(timeFormat, false);
|
||||||
|
if (f24HrRadioButton->Value() == 1) {
|
||||||
|
timeFormat.ReplaceAll("k","h");
|
||||||
|
timeFormat.ReplaceAll("K","H");
|
||||||
|
timeFormat.RemoveAll(" a");
|
||||||
|
} else {
|
||||||
|
timeFormat.ReplaceAll("h","k");
|
||||||
|
timeFormat.ReplaceAll("H","K");
|
||||||
|
timeFormat.Append(" a");
|
||||||
|
f12HrRadioButton->SetValue(true);
|
||||||
|
}
|
||||||
|
std::cout << timeFormat.String() << std::endl;
|
||||||
|
fCountry->SetTimeFormat(timeFormat.String(), false);
|
||||||
|
|
||||||
|
timeFormat.Truncate(0);
|
||||||
|
|
||||||
|
fCountry->TimeFormat(timeFormat, true);
|
||||||
|
if (f24HrRadioButton->Value() == 1) {
|
||||||
|
timeFormat.ReplaceAll("k","h");
|
||||||
|
timeFormat.ReplaceAll("K","H");
|
||||||
|
timeFormat.RemoveAll(" a");
|
||||||
|
} else {
|
||||||
|
timeFormat.ReplaceAll("h","k");
|
||||||
|
timeFormat.ReplaceAll("H","K");
|
||||||
|
timeFormat.Append(" a");
|
||||||
|
}
|
||||||
|
fCountry->SetTimeFormat(timeFormat.String(), true);
|
||||||
|
_UpdateExamples();
|
||||||
|
Window()->PostMessage(kSettingsContentsModified);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ enum FormatSeparator {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const uint32 kSettingsContentsModified = 'Scmo';
|
const uint32 kSettingsContentsModified = 'Scmo';
|
||||||
|
const uint32 kClockFormatChange = 'cfmc';
|
||||||
const uint32 kMenuMessage = 'FRMT';
|
const uint32 kMenuMessage = 'FRMT';
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user