diff --git a/headers/os/locale/Country.h b/headers/os/locale/Country.h index 4bb572291a..0e73c969f7 100644 --- a/headers/os/locale/Country.h +++ b/headers/os/locale/Country.h @@ -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; diff --git a/headers/os/locale/LocaleRoster.h b/headers/os/locale/LocaleRoster.h index 89b6537742..32deba1d23 100644 --- a/headers/os/locale/LocaleRoster.h +++ b/headers/os/locale/LocaleRoster.h @@ -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... diff --git a/src/kits/locale/Country.cpp b/src/kits/locale/Country.cpp index efe06b79ec..2a6928bb45 100644 --- a/src/kits/locale/Country.cpp +++ b/src/kits/locale/Country.cpp @@ -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(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; +} diff --git a/src/kits/locale/LocaleRoster.cpp b/src/kits/locale/LocaleRoster.cpp index 6cdefe7a7d..128d9504c6 100644 --- a/src/kits/locale/LocaleRoster.cpp +++ b/src/kits/locale/LocaleRoster.cpp @@ -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 diff --git a/src/preferences/locale/LocaleWindow.cpp b/src/preferences/locale/LocaleWindow.cpp index ed535fcfea..dc4f4c90e3 100644 --- a/src/preferences/locale/LocaleWindow.cpp +++ b/src/preferences/locale/LocaleWindow.cpp @@ -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(