[haiku-commits] r38380 - in haiku/trunk: headers/os/locale src/kits/locale

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 27 Aug 2010 00:16:40 +0200 (CEST)

Author: zooey
Date: 2010-08-27 00:16:40 +0200 (Fri, 27 Aug 2010)
New Revision: 38380
Changeset: http://dev.haiku-os.org/changeset/38380

Modified:
   haiku/trunk/headers/os/locale/Country.h
   haiku/trunk/headers/os/locale/LocaleRoster.h
   haiku/trunk/src/kits/locale/Country.cpp
   haiku/trunk/src/kits/locale/LocaleRoster.cpp
Log:
* 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.

Modified: haiku/trunk/headers/os/locale/Country.h
===================================================================
--- haiku/trunk/headers/os/locale/Country.h     2010-08-26 20:28:54 UTC (rev 
38379)
+++ haiku/trunk/headers/os/locale/Country.h     2010-08-26 22:16:40 UTC (rev 
38380)
@@ -47,10 +47,6 @@
 
                        int8                            Measurement() const;
 
-                                                               // timezones
-
-                       int                                     
GetTimeZones(BList& timezones) const;
-
 private:
                        icu_44::Locale*         fICULocale;
 };

Modified: haiku/trunk/headers/os/locale/LocaleRoster.h
===================================================================
--- haiku/trunk/headers/os/locale/LocaleRoster.h        2010-08-26 20:28:54 UTC 
(rev 38379)
+++ haiku/trunk/headers/os/locale/LocaleRoster.h        2010-08-26 22:16:40 UTC 
(rev 38380)
@@ -44,8 +44,13 @@
                                                                        // 
'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,

Modified: haiku/trunk/src/kits/locale/Country.cpp
===================================================================
--- haiku/trunk/src/kits/locale/Country.cpp     2010-08-26 20:28:54 UTC (rev 
38379)
+++ haiku/trunk/src/kits/locale/Country.cpp     2010-08-26 22:16:40 UTC (rev 
38380)
@@ -123,39 +123,3 @@
                        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();
-}
-
-

Modified: haiku/trunk/src/kits/locale/LocaleRoster.cpp
===================================================================
--- haiku/trunk/src/kits/locale/LocaleRoster.cpp        2010-08-26 20:28:54 UTC 
(rev 38379)
+++ haiku/trunk/src/kits/locale/LocaleRoster.cpp        2010-08-26 22:16:40 UTC 
(rev 38380)
@@ -237,13 +237,12 @@
 
        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;
@@ -261,6 +260,38 @@
 
 
 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;
+                               break;
+                       }
+                       timeZones->AddString("timeZone", zoneID);
+               }
+       } else
+               status = B_ERROR;
+
+       delete zoneList;
+
+       return status;
+}
+
+
+status_t
 BLocaleRoster::GetInstalledCatalogs(BMessage*  languageList,
                const char* sigPattern, const char* langPattern, int32 
fingerprint) const
 {


Other related posts: