From c91aa9f4e626eae5e737b74cc173526ccab6ac7c Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 26 Aug 2010 22:16:40 +0000 Subject: [PATCH] * moved support for getting timezones-by-country from BCountry to LocaleRoster, since we'd like to be able to get the timezones of the global (i.e. empty) country, too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38380 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/locale/Country.h | 4 ---- headers/os/locale/LocaleRoster.h | 9 ++++++-- src/kits/locale/Country.cpp | 36 -------------------------------- src/kits/locale/LocaleRoster.cpp | 35 +++++++++++++++++++++++++++++-- 4 files changed, 40 insertions(+), 44 deletions(-) diff --git a/headers/os/locale/Country.h b/headers/os/locale/Country.h index 734fd6c48a..a9a5c7f396 100644 --- a/headers/os/locale/Country.h +++ b/headers/os/locale/Country.h @@ -47,10 +47,6 @@ public: int8 Measurement() const; - // timezones - - int GetTimeZones(BList& timezones) const; - private: icu_44::Locale* fICULocale; }; diff --git a/headers/os/locale/LocaleRoster.h b/headers/os/locale/LocaleRoster.h index 45492b3701..a9c5ebf27a 100644 --- a/headers/os/locale/LocaleRoster.h +++ b/headers/os/locale/LocaleRoster.h @@ -44,8 +44,13 @@ public: // 'language'-string-fields which // contain the language-name(s) - status_t GetAvailableCountries(BMessage* message) const; - status_t GetAvailableTimeZones(BMessage* message) const; + status_t GetAvailableCountries( + BMessage* timeZones) const; + status_t GetAvailableTimeZones( + BMessage* timeZones) const; + status_t GetAvailableTimeZonesForCountry( + BMessage* message, + const char* countryCode) const; status_t GetInstalledCatalogs(BMessage* message, const char* sigPattern = NULL, diff --git a/src/kits/locale/Country.cpp b/src/kits/locale/Country.cpp index 333a616402..720441c484 100644 --- a/src/kits/locale/Country.cpp +++ b/src/kits/locale/Country.cpp @@ -123,39 +123,3 @@ BCountry::Measurement() const return B_METRIC; } } - - -// #pragma mark - Timezones - - -int -BCountry::GetTimeZones(BList& timezones) const -{ - ObjectDeleter icuTimeZoneList - = TimeZone::createEnumeration(fICULocale->getCountry()); - if (icuTimeZoneList.Get() == NULL) - return 0; - - UErrorCode error = U_ZERO_ERROR; - - const char* tzName; - std::map timeZoneMap; - // The map allows us to remove duplicates and get a count of the - // remaining zones after that - while ((tzName = icuTimeZoneList->next(NULL, error)) != NULL) { - if (error == U_ZERO_ERROR) { - BTimeZone* timeZone = new(std::nothrow) BTimeZone(tzName); - timeZoneMap.insert(std::pair(timeZone->Name(), - timeZone)); - } else - error = U_ZERO_ERROR; - } - - std::map::const_iterator tzIter; - for (tzIter = timeZoneMap.begin(); tzIter != timeZoneMap.end(); ++tzIter) - timezones.AddItem(tzIter->second); - - return timezones.CountItems(); -} - - diff --git a/src/kits/locale/LocaleRoster.cpp b/src/kits/locale/LocaleRoster.cpp index 40a4e1e025..a4eee6ef72 100644 --- a/src/kits/locale/LocaleRoster.cpp +++ b/src/kits/locale/LocaleRoster.cpp @@ -237,13 +237,44 @@ BLocaleRoster::GetAvailableTimeZones(BMessage* timeZones) const status_t status = B_OK; - int32 i; StringEnumeration* zoneList = TimeZone::createEnumeration(); UErrorCode icuStatus = U_ZERO_ERROR; int32 count = zoneList->count(icuStatus); if (U_SUCCESS(icuStatus)) { - for (i = 0; i < count; ++i) { + for (int i = 0; i < count; ++i) { + const char* zoneID = zoneList->next(NULL, icuStatus); + if (zoneID == NULL || !U_SUCCESS(icuStatus)) { + status = B_ERROR; + break; + } + timeZones->AddString("timeZone", zoneID); + } + } else + status = B_ERROR; + + delete zoneList; + + return status; +} + + +status_t +BLocaleRoster::GetAvailableTimeZonesForCountry(BMessage* timeZones, + const char* countryCode) const +{ + if (!timeZones) + return B_BAD_VALUE; + + status_t status = B_OK; + + StringEnumeration* zoneList = TimeZone::createEnumeration(countryCode); + // countryCode == NULL will yield all timezones not bound to a country + + UErrorCode icuStatus = U_ZERO_ERROR; + int32 count = zoneList->count(icuStatus); + if (U_SUCCESS(icuStatus)) { + for (int i = 0; i < count; ++i) { const char* zoneID = zoneList->next(NULL, icuStatus); if (zoneID == NULL || !U_SUCCESS(icuStatus)) { status = B_ERROR;