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 <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
30BCountry::BCountry(const char* countryCode)
31	:
32	fICULocale(new icu::Locale("", countryCode))
33{
34}
35
36
37BCountry::BCountry(const BCountry& other)
38	:
39	fICULocale(new icu::Locale(*other.fICULocale))
40{
41}
42
43
44BCountry&
45BCountry::operator=(const BCountry& other)
46{
47	if (this == &other)
48		return *this;
49
50	*fICULocale = *other.fICULocale;
51
52	return *this;
53}
54
55
56BCountry::~BCountry()
57{
58	delete fICULocale;
59}
60
61
62status_t
63BCountry::GetNativeName(BString& name) const
64{
65	UnicodeString string;
66	fICULocale->getDisplayName(*fICULocale, string);
67	string.toTitle(NULL, *fICULocale);
68
69	name.Truncate(0);
70	BStringByteSink converter(&name);
71	string.toUTF8(converter);
72
73	return B_OK;
74}
75
76
77status_t
78BCountry::GetName(BString& name, const BLanguage* displayLanguage) const
79{
80	status_t status = B_OK;
81	BString appLanguage;
82	if (displayLanguage == NULL) {
83		BMessage preferredLanguages;
84		status = BLocaleRoster::Default()->GetPreferredLanguages(
85			&preferredLanguages);
86		if (status == B_OK)
87			status = preferredLanguages.FindString("language", 0, &appLanguage);
88	} else {
89		appLanguage = displayLanguage->Code();
90	}
91
92	if (status == B_OK) {
93		UnicodeString uString;
94		fICULocale->getDisplayName(Locale(appLanguage), uString);
95		name.Truncate(0);
96		BStringByteSink stringConverter(&name);
97		uString.toUTF8(stringConverter);
98	}
99
100	return status;
101}
102
103
104const char*
105BCountry::Code() const
106{
107	return fICULocale->getCountry();
108}
109
110
111status_t
112BCountry::GetIcon(BBitmap* result) const
113{
114	return BLocaleRoster::Default()->GetFlagIconForCountry(result, Code());
115}
116
117
118status_t
119BCountry::GetAvailableTimeZones(BMessage* timeZones) const
120{
121	return BLocaleRoster::Default()->GetAvailableTimeZonesForCountry(timeZones,
122		Code());
123}
124
125