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

  • From: pulkomandy@xxxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 22 Jul 2010 14:47:01 +0200 (CEST)

Author: pulkomandy
Date: 2010-07-22 14:47:00 +0200 (Thu, 22 Jul 2010)
New Revision: 37690
Changeset: http://dev.haiku-os.org/changeset/37690

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
   haiku/trunk/src/preferences/locale/LocaleWindow.cpp
Log:
WIP Timezone support
 * BCountry can list the timezones applicable for the country
 * BCountry can give its name (for example France), or LocaleName (french 
(France)). The second one will later be moved to BLocale class along with 
most of the locale settings ; but this needs a bit of refactoring.
 * The Locale preflet now uses LocaleName instead of Name, since it deals with 
locales. The time preflet will want only country names, without te 
language information, for example.


Modified: haiku/trunk/headers/os/locale/Country.h
===================================================================
--- haiku/trunk/headers/os/locale/Country.h     2010-07-22 12:35:44 UTC (rev 
37689)
+++ haiku/trunk/headers/os/locale/Country.h     2010-07-22 12:47:00 UTC (rev 
37690)
@@ -8,6 +8,7 @@
 
 
 class BBitmap;
+class BMessage;
 
 namespace icu_44 {
        class DateFormat;
@@ -41,6 +42,7 @@
                virtual                 ~BCountry();
 
                virtual bool    Name(BString&) const;
+               bool                    LocaleName(BString&) const;
                const char*             Code() const;
                status_t                GetIcon(BBitmap* result);
 
@@ -106,6 +108,9 @@
                bool            MonGrouping(BString&) const;
                virtual int32   MonFracDigits() const;
 
+               // timezones
+               status_t GetTimeZones(BMessage* timezones);
+
        private:
                icu_44::DateFormat* fICULongDateFormatter;
                icu_44::DateFormat* fICUShortDateFormatter;

Modified: haiku/trunk/headers/os/locale/LocaleRoster.h
===================================================================
--- haiku/trunk/headers/os/locale/LocaleRoster.h        2010-07-22 12:35:44 UTC 
(rev 37689)
+++ haiku/trunk/headers/os/locale/LocaleRoster.h        2010-07-22 12:47:00 UTC 
(rev 37690)
@@ -53,6 +53,8 @@
                        // the message contains one or more 
'language'-string-fields
                        // which contain the language-name(s)
 
+               status_t GetAvailableCountries(BMessage *) const;
+
                status_t GetInstalledCatalogs(BMessage *, const char* 
sigPattern = NULL,
                        const char* langPattern = NULL, int32 fingerprint = 0) 
const;
                        // the message contains...

Modified: haiku/trunk/src/kits/locale/Country.cpp
===================================================================
--- haiku/trunk/src/kits/locale/Country.cpp     2010-07-22 12:35:44 UTC (rev 
37689)
+++ haiku/trunk/src/kits/locale/Country.cpp     2010-07-22 12:47:00 UTC (rev 
37690)
@@ -117,6 +117,17 @@
 BCountry::Name(BString& name) const
 {
        UnicodeString uString;
+       fICULocale->getDisplayCountry(uString);
+       BStringByteSink stringConverter(&name);
+       uString.toUTF8(stringConverter);
+       return true;
+}
+
+
+bool
+BCountry::LocaleName(BString& name) const
+{
+       UnicodeString uString;
        fICULocale->getDisplayName(uString);
        BStringByteSink stringConverter(&name);
        uString.toUTF8(stringConverter);
@@ -139,18 +150,18 @@
        // TODO: a proper way to locate the library being used ?
        BResources storage("/boot/system/lib/liblocale.so");
        if (storage.InitCheck() != B_OK)
-               return B_ERROR;
-       size_t size;
-       const char* code = fICULocale->getCountry();
+               return B_ERROR;
+       size_t size;
+       const char* code = fICULocale->getCountry();
        if (code != NULL) {
-               const void* buffer = storage.LoadResource(B_VECTOR_ICON_TYPE, 
code,
-                       &size);
-               if (buffer != NULL && size != 0) {
+               const void* buffer = storage.LoadResource(B_VECTOR_ICON_TYPE, 
code,
+                       &size);
+               if (buffer != NULL && size != 0) {
                        return BIconUtils::GetVectorIcon(static_cast<const 
uint8*>(buffer),
                                size, result);
-               }
+               }
        }
-       return B_BAD_DATA;
+       return B_BAD_DATA;
 }
 
 
@@ -840,3 +851,30 @@
        return 2;
 }
 
+
+// #pragma mark - Timezones
+
+
+status_t
+BCountry::GetTimeZones(BMessage* timezones)
+{
+       if (timezones == NULL)
+               return B_BAD_DATA;
+
+
+       StringEnumeration* icuTimeZoneList = TimeZone::createEnumeration(
+               fICULocale->getCountry());
+       UErrorCode error = U_ZERO_ERROR;
+
+       const char* tzName;
+       while (tzName = icuTimeZoneList->next(NULL, error)) {
+               if (error == U_ZERO_ERROR)
+                       timezones->AddString("zones", tzName);
+               else
+                       error = U_ZERO_ERROR;
+       }
+
+       delete icuTimeZoneList;
+
+       return B_OK;
+}

Modified: haiku/trunk/src/kits/locale/LocaleRoster.cpp
===================================================================
--- haiku/trunk/src/kits/locale/LocaleRoster.cpp        2010-07-22 12:35:44 UTC 
(rev 37689)
+++ haiku/trunk/src/kits/locale/LocaleRoster.cpp        2010-07-22 12:47:00 UTC 
(rev 37690)
@@ -641,7 +641,25 @@
 }
 
 
+// Get all the available countries from ICU
 status_t
+BLocaleRoster::GetAvailableCountries(BMessage *countries) const
+{
+       if (!countries)
+               return B_BAD_VALUE;
+
+       int32 i;
+       const char* const* countryList = uloc_getISOCountries();
+
+       for (i = 0; countryList[i] != NULL; i++) {
+               countries->AddString("countries", countryList[i]);
+       }
+
+       return B_OK;
+}
+
+
+status_t
 BLocaleRoster::GetInstalledCatalogs(BMessage * languageList,
                const char* sigPattern, const char* langPattern, int32 
fingerprint) const
 {

Modified: haiku/trunk/src/preferences/locale/LocaleWindow.cpp
===================================================================
--- haiku/trunk/src/preferences/locale/LocaleWindow.cpp 2010-07-22 12:35:44 UTC 
(rev 37689)
+++ haiku/trunk/src/preferences/locale/LocaleWindow.cpp 2010-07-22 12:47:00 UTC 
(rev 37690)
@@ -168,9 +168,7 @@
                B_WILL_DRAW | B_FRAME_EVENTS, false, true);
        listView->SetSelectionMessage(new BMessage(kMsgCountrySelection));
 
-       // get all available countries from ICU
-       // Use DateFormat::getAvailableLocale so we get only the one we can
-       // use. Maybe check the NumberFormat one and see if there is more.
+       // get all available countries
        BMessage countryList;
        be_locale_roster->GetInstalledLanguages(&countryList);
        BString countryCode;
@@ -180,7 +178,7 @@
                BCountry country(countryCode);
                BString countryName;
 
-               country.Name(countryName);
+               country.LocaleName(countryName);
 
                LanguageListItem* item
                        = new LanguageListItem(countryName, countryCode,
@@ -189,25 +187,7 @@
                if (!strcmp(countryCode, defaultCountry->Code()))
                        listView->Select(listView->CountItems() - 1);
        }
-       /*
-       int32_t localeCount;
-       const Locale* currentLocale = Locale::getAvailableLocales(localeCount);
 
-       for (int index = 0; index < localeCount; index++) {
-               UnicodeString countryFullName;
-               BString string;
-               BStringByteSink sink(&string);
-               currentLocale[index].getDisplayName(countryFullName);
-               countryFullName.toUTF8(sink);
-
-               LanguageListItem* item
-                       = new LanguageListItem(string, 
currentLocale[index].getName(),
-                               NULL);
-               listView->AddItem(item);
-               if (!strcmp(currentLocale[index].getName(), 
defaultCountry->Code()))
-                       listView->Select(listView->CountItems() - 1);
-       }*/
-
        // TODO: find a real solution intead of this hack
        listView->SetExplicitMinSize(
                BSize(25 * be_plain_font->Size(), B_SIZE_UNSET));


Other related posts:

  • » [haiku-commits] r37690 - in haiku/trunk: headers/os/locale src/kits/locale src/preferences/locale - pulkomandy