1 /* 2 * Copyright 2003-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Copyright 2009-2010, Adrien Destugues, pulkomandy@gmail.com. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include <Country.h> 9 10 #include <AutoDeleter.h> 11 #include <IconUtils.h> 12 #include <List.h> 13 #include <Language.h> 14 #include <LocaleRoster.h> 15 #include <Resources.h> 16 #include <String.h> 17 18 #include <unicode/locid.h> 19 #include <unicode/ulocdata.h> 20 #include <ICUWrapper.h> 21 22 #include <iostream> 23 #include <map> 24 #include <monetary.h> 25 #include <new> 26 #include <stdarg.h> 27 #include <stdlib.h> 28 29 30 #define ICU_VERSION icu_44 31 32 33 BCountry::BCountry(const char* countryCode) 34 : 35 fICULocale(new ICU_VERSION::Locale("", countryCode)) 36 { 37 } 38 39 40 BCountry::BCountry(const BCountry& other) 41 : 42 fICULocale(new ICU_VERSION::Locale(*other.fICULocale)) 43 { 44 } 45 46 47 BCountry& 48 BCountry::operator=(const BCountry& other) 49 { 50 if (this == &other) 51 return *this; 52 53 *fICULocale = *other.fICULocale; 54 55 return *this; 56 } 57 58 59 BCountry::~BCountry() 60 { 61 delete fICULocale; 62 } 63 64 65 status_t 66 BCountry::GetNativeName(BString& name) const 67 { 68 UnicodeString string; 69 fICULocale->getDisplayName(*fICULocale, string); 70 string.toTitle(NULL, *fICULocale); 71 72 name.Truncate(0); 73 BStringByteSink converter(&name); 74 string.toUTF8(converter); 75 76 return B_OK; 77 } 78 79 80 status_t 81 BCountry::GetName(BString& name, const BLanguage* displayLanguage) const 82 { 83 BString appLanguage; 84 if (displayLanguage == NULL) { 85 BMessage preferredLanguage; 86 be_locale_roster->GetPreferredLanguages(&preferredLanguage); 87 preferredLanguage.FindString("language", 0, &appLanguage); 88 } else { 89 appLanguage = displayLanguage->Code(); 90 } 91 92 UnicodeString uString; 93 fICULocale->getDisplayName(Locale(appLanguage), uString); 94 name.Truncate(0); 95 BStringByteSink stringConverter(&name); 96 uString.toUTF8(stringConverter); 97 98 return B_OK; 99 } 100 101 102 const char* 103 BCountry::Code() const 104 { 105 return fICULocale->getCountry(); 106 } 107 108 109 status_t 110 BCountry::GetIcon(BBitmap* result) const 111 { 112 const char* code = fICULocale->getCountry(); 113 if (code == NULL) 114 return B_ERROR; 115 return be_locale_roster->GetFlagIconForCountry(result, code); 116 } 117 118 119 status_t 120 BCountry::GetAvailableTimeZones(BMessage* timeZones) const 121 { 122 return be_locale_roster->GetAvailableTimeZonesForCountry(timeZones, Code()); 123 } 124 125