Author: pulkomandy Date: 2010-07-23 18:25:43 +0200 (Fri, 23 Jul 2010) New Revision: 37719 Changeset: http://dev.haiku-os.org/changeset/37719 Modified: haiku/trunk/headers/os/locale/Country.h haiku/trunk/headers/os/locale/TimeZone.h haiku/trunk/src/kits/locale/Country.cpp haiku/trunk/src/kits/locale/TimeZone.cpp Log: * Bcountry : private methods start with underscore. The timezone list isnow actually a list of BTimeZone objects, that holdsall the needed info, not only the code. Also tweak the listing code to remove duplicatesfromthe list generated by ICU. * BTimeZone : remove Code, rename Name to GetName. The class is likely to change again for further optimization. Modified: haiku/trunk/headers/os/locale/Country.h =================================================================== --- haiku/trunk/headers/os/locale/Country.h 2010-07-23 13:19:33 UTC (rev 37718) +++ haiku/trunk/headers/os/locale/Country.h 2010-07-23 16:25:43 UTC (rev 37719) @@ -2,10 +2,11 @@ #define _COUNTRY_H_ -#include <SupportDefs.h> +#include <List.h> #include <LocaleStrings.h> #include <Locker.h> #include <String.h> +#include <SupportDefs.h> class BBitmap; @@ -112,13 +113,13 @@ virtual int32 MonFracDigits() const; // timezones - status_t GetTimeZones(BMessage* timezones); + int GetTimeZones(BList& timezones); private: - icu_44::DateFormat* LockDateFormatter(bool longFormat); - icu_44::DateFormat* LockTimeFormatter(bool longFormat); - void UnlockDateFormatter(bool longFormat); - void UnlockTimeFormatter(bool longFormat); + icu_44::DateFormat* _LockDateFormatter(bool longFormat); + icu_44::DateFormat* _LockTimeFormatter(bool longFormat); + void _UnlockDateFormatter(bool longFormat); + void _UnlockTimeFormatter(bool longFormat); icu_44::DateFormat* fICULongDateFormatter; icu_44::DateFormat* fICUShortDateFormatter; Modified: haiku/trunk/headers/os/locale/TimeZone.h =================================================================== --- haiku/trunk/headers/os/locale/TimeZone.h 2010-07-23 13:19:33 UTC (rev 37718) +++ haiku/trunk/headers/os/locale/TimeZone.h 2010-07-23 16:25:43 UTC (rev 37719) @@ -19,8 +19,7 @@ BTimeZone(const char* zoneCode); ~BTimeZone(); - void Name(BString& name); - void Code(BString& code); + void GetName(BString& name); int OffsetFromGMT(); private: Modified: haiku/trunk/src/kits/locale/Country.cpp =================================================================== --- haiku/trunk/src/kits/locale/Country.cpp 2010-07-23 13:19:33 UTC (rev 37718) +++ haiku/trunk/src/kits/locale/Country.cpp 2010-07-23 16:25:43 UTC (rev 37719) @@ -7,15 +7,12 @@ #include <Country.h> -#include <assert.h> -#include <iostream> -#include <stdlib.h> -#include <vector> - #include <CalendarView.h> #include <IconUtils.h> +#include <List.h> #include <Resources.h> #include <String.h> +#include <TimeZone.h> #include <unicode/datefmt.h> #include <unicode/dcfmtsym.h> @@ -24,8 +21,13 @@ #include <unicode/smpdtfmt.h> #include <ICUWrapper.h> +#include <assert.h> +#include <iostream> +#include <map> #include <monetary.h> #include <stdarg.h> +#include <stdlib.h> +#include <vector> #define ICU_VERSION icu_44 @@ -195,7 +197,7 @@ DateFormat* -BCountry::LockDateFormatter(bool longFormat) +BCountry::_LockDateFormatter(bool longFormat) { // TODO: ICU allows for 4 different levels of expansion : // short, medium, long, and full. Our bool parameter is not enough... @@ -218,7 +220,7 @@ void -BCountry::UnlockDateFormatter(bool longFormat) +BCountry::_UnlockDateFormatter(bool longFormat) { if (longFormat) { fLongDateLock.Unlock(); @@ -229,7 +231,7 @@ DateFormat* -BCountry::LockTimeFormatter(bool longFormat) +BCountry::_LockTimeFormatter(bool longFormat) { // TODO: ICU allows for 4 different levels of expansion : // short, medium, long, and full. Our bool parameter is not enough... @@ -252,7 +254,7 @@ void -BCountry::UnlockTimeFormatter(bool longFormat) +BCountry::_UnlockTimeFormatter(bool longFormat) { if (longFormat) { fLongTimeLock.Unlock(); @@ -265,16 +267,16 @@ status_t BCountry::FormatDate(char* string, size_t maxSize, time_t time, bool longFormat) { - ICU_VERSION::DateFormat* dateFormatter = LockDateFormatter(longFormat); + ICU_VERSION::DateFormat* dateFormatter = _LockDateFormatter(longFormat); if (dateFormatter == NULL) { - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); return B_NO_MEMORY; } UnicodeString ICUString; ICUString = dateFormatter->format((UDate)time * 1000, ICUString); - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); CheckedArrayByteSink stringConverter(string, maxSize); @@ -293,15 +295,15 @@ string->Truncate(0); // We make the string empty, this way even in cases where ICU fail we at // least return something sane - ICU_VERSION::DateFormat* dateFormatter = LockDateFormatter(longFormat); + ICU_VERSION::DateFormat* dateFormatter = _LockDateFormatter(longFormat); if (dateFormatter == NULL) { - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); return B_NO_MEMORY; } UnicodeString ICUString; ICUString = dateFormatter->format((UDate)time * 1000, ICUString); - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); BStringByteSink stringConverter(string); @@ -317,9 +319,9 @@ { string->Truncate(0); - ICU_VERSION::DateFormat* dateFormatter = LockDateFormatter(longFormat); + ICU_VERSION::DateFormat* dateFormatter = _LockDateFormatter(longFormat); if (dateFormatter == NULL) { - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); return B_NO_MEMORY; } @@ -329,7 +331,7 @@ UnicodeString ICUString; ICUString = dateFormatter->format((UDate)time * 1000, ICUString, &positionIterator, error); - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); if (error != U_ZERO_ERROR) return B_ERROR; @@ -361,9 +363,9 @@ { format.Truncate(0); - ICU_VERSION::DateFormat* dateFormatter = LockDateFormatter(longFormat); + ICU_VERSION::DateFormat* dateFormatter = _LockDateFormatter(longFormat); if (dateFormatter == NULL) { - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); return B_NO_MEMORY; } @@ -372,7 +374,7 @@ UnicodeString ICUString; ICUString = dateFormatterImpl->toPattern(ICUString); - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); BStringByteSink stringConverter(&format); @@ -385,9 +387,9 @@ status_t BCountry::SetDateFormat(const char* formatString, bool longFormat) { - ICU_VERSION::DateFormat* dateFormatter = LockDateFormatter(longFormat); + ICU_VERSION::DateFormat* dateFormatter = _LockDateFormatter(longFormat); if (dateFormatter == NULL) { - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); return B_NO_MEMORY; } @@ -396,7 +398,7 @@ UnicodeString pattern(formatString); dateFormatterImpl->applyPattern(pattern); - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); return B_OK; } @@ -405,9 +407,9 @@ status_t BCountry::DateFields(BDateElement*& fields, int& fieldCount, bool longFormat) { - ICU_VERSION::DateFormat* dateFormatter = LockDateFormatter(longFormat); + ICU_VERSION::DateFormat* dateFormatter = _LockDateFormatter(longFormat); if (dateFormatter == NULL) { - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); return B_NO_MEMORY; } @@ -418,7 +420,7 @@ time_t now; ICUString = dateFormatter->format((UDate)time(&now) * 1000, ICUString, &positionIterator, error); - UnlockDateFormatter(longFormat); + _UnlockDateFormatter(longFormat); if (error != U_ZERO_ERROR) return B_ERROR; @@ -477,15 +479,15 @@ status_t BCountry::FormatTime(char* string, size_t maxSize, time_t time, bool longFormat) { - ICU_VERSION::DateFormat* timeFormatter = LockTimeFormatter(longFormat); + ICU_VERSION::DateFormat* timeFormatter = _LockTimeFormatter(longFormat); if (timeFormatter == NULL) { - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); return B_NO_MEMORY; } UnicodeString ICUString; ICUString = timeFormatter->format((UDate)time * 1000, ICUString); - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); CheckedArrayByteSink stringConverter(string, maxSize); @@ -503,15 +505,15 @@ { string->Truncate(0); - ICU_VERSION::DateFormat* timeFormatter = LockTimeFormatter(longFormat); + ICU_VERSION::DateFormat* timeFormatter = _LockTimeFormatter(longFormat); if (timeFormatter == NULL) { - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); return B_NO_MEMORY; } UnicodeString ICUString; ICUString = timeFormatter->format((UDate)time * 1000, ICUString); - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); BStringByteSink stringConverter(string); @@ -527,9 +529,9 @@ { string->Truncate(0); - ICU_VERSION::DateFormat* timeFormatter = LockTimeFormatter(longFormat); + ICU_VERSION::DateFormat* timeFormatter = _LockTimeFormatter(longFormat); if (timeFormatter == NULL) { - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); return B_NO_MEMORY; } @@ -539,7 +541,7 @@ UnicodeString ICUString; ICUString = timeFormatter->format((UDate)time * 1000, ICUString, &positionIterator, error); - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); if (error != U_ZERO_ERROR) return B_ERROR; @@ -569,9 +571,9 @@ status_t BCountry::TimeFields(BDateElement*& fields, int& fieldCount, bool longFormat) { - ICU_VERSION::DateFormat* timeFormatter = LockTimeFormatter(longFormat); + ICU_VERSION::DateFormat* timeFormatter = _LockTimeFormatter(longFormat); if (timeFormatter == NULL) { - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); return B_NO_MEMORY; } @@ -582,7 +584,7 @@ time_t now; ICUString = timeFormatter->format((UDate)time(&now) * 1000, ICUString, &positionIterator, error); - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); if (error != U_ZERO_ERROR) return B_ERROR; @@ -627,9 +629,9 @@ status_t BCountry::SetTimeFormat(const char* formatString, bool longFormat) { - ICU_VERSION::DateFormat* timeFormatter = LockTimeFormatter(longFormat); + ICU_VERSION::DateFormat* timeFormatter = _LockTimeFormatter(longFormat); if (timeFormatter == NULL) { - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); return B_NO_MEMORY; } @@ -638,7 +640,7 @@ UnicodeString pattern(formatString); dateFormatterImpl->applyPattern(pattern); - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); return B_OK; } @@ -647,9 +649,9 @@ status_t BCountry::TimeFormat(BString& format, bool longFormat) { - ICU_VERSION::DateFormat* timeFormatter = LockTimeFormatter(longFormat); + ICU_VERSION::DateFormat* timeFormatter = _LockTimeFormatter(longFormat); if (timeFormatter == NULL) { - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); return B_NO_MEMORY; } @@ -658,7 +660,7 @@ UnicodeString ICUString; ICUString = dateFormatterImpl->toPattern(ICUString); - UnlockTimeFormatter(longFormat); + _UnlockTimeFormatter(longFormat); BStringByteSink stringConverter(&format); @@ -1050,26 +1052,35 @@ // #pragma mark - Timezones -status_t -BCountry::GetTimeZones(BMessage* timezones) +int +BCountry::GetTimeZones(BList& timezones) { - if (timezones == NULL) - return B_BAD_DATA; - - StringEnumeration* icuTimeZoneList = TimeZone::createEnumeration( fICULocale->getCountry()); 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)) { - if (error == U_ZERO_ERROR) - timezones->AddString("zones", tzName); - else + if (error == U_ZERO_ERROR) { + BString readableName; + BTimeZone* timeZone = new BTimeZone(tzName); + timeZone->GetName(readableName); + timeZoneMap.insert(std::pair<BString, BTimeZone*>(readableName, + timeZone)); + } else error = U_ZERO_ERROR; } delete icuTimeZoneList; - return B_OK; + + for (std::map<BString, BTimeZone*>::const_iterator timeZoneIterator + = timeZoneMap.begin(); timeZoneIterator != timeZoneMap.end(); + timeZoneIterator++) + timezones.AddItem((*timeZoneIterator).second); + + return timeZoneMap.size(); } Modified: haiku/trunk/src/kits/locale/TimeZone.cpp =================================================================== --- haiku/trunk/src/kits/locale/TimeZone.cpp 2010-07-23 13:19:33 UTC (rev 37718) +++ haiku/trunk/src/kits/locale/TimeZone.cpp 2010-07-23 16:25:43 UTC (rev 37719) @@ -25,7 +25,7 @@ void -BTimeZone::Name(BString& name) +BTimeZone::GetName(BString& name) { UnicodeString unicodeName; fICUTimeZone->getDisplayName(unicodeName); @@ -35,17 +35,6 @@ } -void -BTimeZone::Code(BString& code) -{ - UnicodeString unicodeName; - fICUTimeZone->getID(unicodeName); - - BStringByteSink converter(&code); - unicodeName.toUTF8(converter); -} - - int BTimeZone::OffsetFromGMT() {