* 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
This commit is contained in:
Oliver Tappe 2010-08-26 22:16:40 +00:00
parent bbdb55154d
commit c91aa9f4e6
4 changed files with 40 additions and 44 deletions

View File

@ -47,10 +47,6 @@ public:
int8 Measurement() const;
// timezones
int GetTimeZones(BList& timezones) const;
private:
icu_44::Locale* fICULocale;
};

View File

@ -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,

View File

@ -123,39 +123,3 @@ BCountry::Measurement() const
return B_METRIC;
}
}
// #pragma mark - Timezones
int
BCountry::GetTimeZones(BList& timezones) const
{
ObjectDeleter<StringEnumeration> icuTimeZoneList
= TimeZone::createEnumeration(fICULocale->getCountry());
if (icuTimeZoneList.Get() == NULL)
return 0;
UErrorCode error = U_ZERO_ERROR;
const char* tzName;
std::map<BString, BTimeZone*> 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<BString, BTimeZone*>(timeZone->Name(),
timeZone));
} else
error = U_ZERO_ERROR;
}
std::map<BString, BTimeZone*>::const_iterator tzIter;
for (tzIter = timeZoneMap.begin(); tzIter != timeZoneMap.end(); ++tzIter)
timezones.AddItem(tzIter->second);
return timezones.CountItems();
}

View File

@ -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;