Add BLocaleRoster::GetAvailableTimeZonesWithRegionInfo()

* allow locale kit clients to get all timezones with their corresponding
  country/region ID piecemeal
This commit is contained in:
Oliver Tappe 2012-04-07 20:44:39 +02:00
parent 3c1afd351d
commit 635df64352
2 changed files with 43 additions and 0 deletions

View File

@ -45,6 +45,8 @@ public:
BMessage* timeZones) const;
status_t GetAvailableTimeZones(
BMessage* timeZones) const;
status_t GetAvailableTimeZonesWithRegionInfo(
BMessage* timeZonesWithRegonInfo) const;
status_t GetAvailableTimeZonesForCountry(
BMessage* message,
const char* countryCode) const;

View File

@ -279,6 +279,47 @@ BLocaleRoster::GetAvailableTimeZones(BMessage* timeZones) const
}
status_t
BLocaleRoster::GetAvailableTimeZonesWithRegionInfo(BMessage* timeZones) const
{
if (!timeZones)
return B_BAD_VALUE;
status_t status = B_OK;
UErrorCode icuStatus = U_ZERO_ERROR;
StringEnumeration* zoneList = TimeZone::createTimeZoneIDEnumeration(
UCAL_ZONE_TYPE_CANONICAL, NULL, NULL, icuStatus);
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;
break;
}
timeZones->AddString("timeZone", zoneID);
char region[5];
icuStatus = U_ZERO_ERROR;
TimeZone::getRegion(zoneID, region, 5, icuStatus);
if (!U_SUCCESS(icuStatus)) {
status = B_ERROR;
break;
}
timeZones->AddString("region", region);
}
} else
status = B_ERROR;
delete zoneList;
return status;
}
status_t
BLocaleRoster::GetAvailableTimeZonesForCountry(BMessage* timeZones,
const char* countryCode) const