WIP Timezone support
* BCountry can list the timezones applicable for the country * BCountry can give its name (for example France), or LocaleName (french (France)). The second one will later be moved to BLocale class along with most of the locale settings ; but this needs a bit of refactoring. * The Locale preflet now uses LocaleName instead of Name, since it deals with locales. The time preflet will want only country names, without te language information, for example. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37690 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
|
||||
class BBitmap;
|
||||
class BMessage;
|
||||
|
||||
namespace icu_44 {
|
||||
class DateFormat;
|
||||
@@ -41,6 +42,7 @@ class BCountry {
|
||||
virtual ~BCountry();
|
||||
|
||||
virtual bool Name(BString&) const;
|
||||
bool LocaleName(BString&) const;
|
||||
const char* Code() const;
|
||||
status_t GetIcon(BBitmap* result);
|
||||
|
||||
@@ -106,6 +108,9 @@ class BCountry {
|
||||
bool MonGrouping(BString&) const;
|
||||
virtual int32 MonFracDigits() const;
|
||||
|
||||
// timezones
|
||||
status_t GetTimeZones(BMessage* timezones);
|
||||
|
||||
private:
|
||||
icu_44::DateFormat* fICULongDateFormatter;
|
||||
icu_44::DateFormat* fICUShortDateFormatter;
|
||||
|
||||
@@ -53,6 +53,8 @@ class BLocaleRoster {
|
||||
// the message contains one or more 'language'-string-fields
|
||||
// which contain the language-name(s)
|
||||
|
||||
status_t GetAvailableCountries(BMessage *) const;
|
||||
|
||||
status_t GetInstalledCatalogs(BMessage *, const char* sigPattern = NULL,
|
||||
const char* langPattern = NULL, int32 fingerprint = 0) const;
|
||||
// the message contains...
|
||||
|
||||
@@ -115,6 +115,17 @@ BCountry::~BCountry()
|
||||
|
||||
bool
|
||||
BCountry::Name(BString& name) const
|
||||
{
|
||||
UnicodeString uString;
|
||||
fICULocale->getDisplayCountry(uString);
|
||||
BStringByteSink stringConverter(&name);
|
||||
uString.toUTF8(stringConverter);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BCountry::LocaleName(BString& name) const
|
||||
{
|
||||
UnicodeString uString;
|
||||
fICULocale->getDisplayName(uString);
|
||||
@@ -139,18 +150,18 @@ BCountry::GetIcon(BBitmap* result)
|
||||
// TODO: a proper way to locate the library being used ?
|
||||
BResources storage("/boot/system/lib/liblocale.so");
|
||||
if (storage.InitCheck() != B_OK)
|
||||
return B_ERROR;
|
||||
size_t size;
|
||||
const char* code = fICULocale->getCountry();
|
||||
return B_ERROR;
|
||||
size_t size;
|
||||
const char* code = fICULocale->getCountry();
|
||||
if (code != NULL) {
|
||||
const void* buffer = storage.LoadResource(B_VECTOR_ICON_TYPE, code,
|
||||
&size);
|
||||
if (buffer != NULL && size != 0) {
|
||||
const void* buffer = storage.LoadResource(B_VECTOR_ICON_TYPE, code,
|
||||
&size);
|
||||
if (buffer != NULL && size != 0) {
|
||||
return BIconUtils::GetVectorIcon(static_cast<const uint8*>(buffer),
|
||||
size, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return B_BAD_DATA;
|
||||
return B_BAD_DATA;
|
||||
}
|
||||
|
||||
|
||||
@@ -840,3 +851,30 @@ BCountry::MonFracDigits() const
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - Timezones
|
||||
|
||||
|
||||
status_t
|
||||
BCountry::GetTimeZones(BMessage* timezones)
|
||||
{
|
||||
if (timezones == NULL)
|
||||
return B_BAD_DATA;
|
||||
|
||||
|
||||
StringEnumeration* icuTimeZoneList = TimeZone::createEnumeration(
|
||||
fICULocale->getCountry());
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
|
||||
const char* tzName;
|
||||
while (tzName = icuTimeZoneList->next(NULL, error)) {
|
||||
if (error == U_ZERO_ERROR)
|
||||
timezones->AddString("zones", tzName);
|
||||
else
|
||||
error = U_ZERO_ERROR;
|
||||
}
|
||||
|
||||
delete icuTimeZoneList;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
@@ -641,6 +641,24 @@ BLocaleRoster::GetInstalledLanguages(BMessage *languages) const
|
||||
}
|
||||
|
||||
|
||||
// Get all the available countries from ICU
|
||||
status_t
|
||||
BLocaleRoster::GetAvailableCountries(BMessage *countries) const
|
||||
{
|
||||
if (!countries)
|
||||
return B_BAD_VALUE;
|
||||
|
||||
int32 i;
|
||||
const char* const* countryList = uloc_getISOCountries();
|
||||
|
||||
for (i = 0; countryList[i] != NULL; i++) {
|
||||
countries->AddString("countries", countryList[i]);
|
||||
}
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BLocaleRoster::GetInstalledCatalogs(BMessage * languageList,
|
||||
const char* sigPattern, const char* langPattern, int32 fingerprint) const
|
||||
|
||||
@@ -168,9 +168,7 @@ LocaleWindow::LocaleWindow()
|
||||
B_WILL_DRAW | B_FRAME_EVENTS, false, true);
|
||||
listView->SetSelectionMessage(new BMessage(kMsgCountrySelection));
|
||||
|
||||
// get all available countries from ICU
|
||||
// Use DateFormat::getAvailableLocale so we get only the one we can
|
||||
// use. Maybe check the NumberFormat one and see if there is more.
|
||||
// get all available countries
|
||||
BMessage countryList;
|
||||
be_locale_roster->GetInstalledLanguages(&countryList);
|
||||
BString countryCode;
|
||||
@@ -180,7 +178,7 @@ LocaleWindow::LocaleWindow()
|
||||
BCountry country(countryCode);
|
||||
BString countryName;
|
||||
|
||||
country.Name(countryName);
|
||||
country.LocaleName(countryName);
|
||||
|
||||
LanguageListItem* item
|
||||
= new LanguageListItem(countryName, countryCode,
|
||||
@@ -189,24 +187,6 @@ LocaleWindow::LocaleWindow()
|
||||
if (!strcmp(countryCode, defaultCountry->Code()))
|
||||
listView->Select(listView->CountItems() - 1);
|
||||
}
|
||||
/*
|
||||
int32_t localeCount;
|
||||
const Locale* currentLocale = Locale::getAvailableLocales(localeCount);
|
||||
|
||||
for (int index = 0; index < localeCount; index++) {
|
||||
UnicodeString countryFullName;
|
||||
BString string;
|
||||
BStringByteSink sink(&string);
|
||||
currentLocale[index].getDisplayName(countryFullName);
|
||||
countryFullName.toUTF8(sink);
|
||||
|
||||
LanguageListItem* item
|
||||
= new LanguageListItem(string, currentLocale[index].getName(),
|
||||
NULL);
|
||||
listView->AddItem(item);
|
||||
if (!strcmp(currentLocale[index].getName(), defaultCountry->Code()))
|
||||
listView->Select(listView->CountItems() - 1);
|
||||
}*/
|
||||
|
||||
// TODO: find a real solution intead of this hack
|
||||
listView->SetExplicitMinSize(
|
||||
|
||||
Reference in New Issue
Block a user