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