BPicture: Fix archive constructor.
[haiku.git] / src / kits / locale / Country.cpp
blobe95711d5f04aba1f873a17e4fb0a87553fb1f5d1
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 */
8 #include <unicode/uversion.h>
9 #include <Country.h>
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>
19 #include <unicode/locid.h>
20 #include <unicode/ulocdata.h>
21 #include <ICUWrapper.h>
23 #include <iostream>
24 #include <map>
25 #include <monetary.h>
26 #include <new>
27 #include <stdarg.h>
28 #include <stdlib.h>
31 BCountry::BCountry(const char* countryCode)
33 fICULocale(new icu::Locale("", countryCode))
38 BCountry::BCountry(const BCountry& other)
40 fICULocale(new icu::Locale(*other.fICULocale))
45 BCountry&
46 BCountry::operator=(const BCountry& other)
48 if (this == &other)
49 return *this;
51 *fICULocale = *other.fICULocale;
53 return *this;
57 BCountry::~BCountry()
59 delete fICULocale;
63 status_t
64 BCountry::GetNativeName(BString& name) const
66 UnicodeString string;
67 fICULocale->getDisplayName(*fICULocale, string);
68 string.toTitle(NULL, *fICULocale);
70 name.Truncate(0);
71 BStringByteSink converter(&name);
72 string.toUTF8(converter);
74 return B_OK;
78 status_t
79 BCountry::GetName(BString& name, const BLanguage* displayLanguage) const
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();
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);
101 return status;
105 const char*
106 BCountry::Code() const
108 return fICULocale->getCountry();
112 status_t
113 BCountry::GetIcon(BBitmap* result) const
115 return BLocaleRoster::Default()->GetFlagIconForCountry(result, Code());
119 status_t
120 BCountry::GetAvailableTimeZones(BMessage* timeZones) const
122 return BLocaleRoster::Default()->GetAvailableTimeZonesForCountry(timeZones,
123 Code());