haiku/src/kits/locale/Country.cpp
Oliver Tappe 6fd2f4a0d1 One more monster commit (sorry ...) concerning the Locale Kit:
* extracted new class BFormattingConventions from BCountry, which
  manages the formatting conventions from a given locale and 
  allows to get/set the four different date/time formats supported
  by ICU-locales as well as number and monetary formats
* overhauled the Locale preflet:
  + drop editing features for all formats, since I don't think
    they do not make much sense to have in a prefs GUI - being
    able to select from the existing locales should be good
    enough. Please note that you can still change the formats
    programmatically in an application.
  + renamed the 'Countries' tab to 'Formatting'
  + the locale formatting conventions list in the 'Formatting'
    tab is now hierarchical for easier access (less scrolling)
  + fixed functionality of 'Revert' and 'Defaults' buttons
  + added support for using the month/day-names of your preferred
    language during date formatting
* adjusted BLocale to ask BFormattingConventions for the current
  formats when formatting dates and times and to offer 4
  different format styles (full, long, medium and short).
* adjust all classes formatting dates/times to pick the 
  appropriate format style
* BLocaleRoster no longer directly archives/unarchives the 
  individual formatting conventions but delegates that to
  BFormattingConventions
    

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39123 a95241bf-73f2-0310-859d-f6bbb57e9c96
2010-10-24 12:57:55 +00:00

125 lines
2.2 KiB
C++

/*
* Copyright 2003-2009, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2009-2010, Adrien Destugues, pulkomandy@gmail.com.
* Distributed under the terms of the MIT License.
*/
#include <Country.h>
#include <AutoDeleter.h>
#include <IconUtils.h>
#include <List.h>
#include <Language.h>
#include <LocaleRoster.h>
#include <Resources.h>
#include <String.h>
#include <unicode/locid.h>
#include <unicode/ulocdata.h>
#include <ICUWrapper.h>
#include <iostream>
#include <map>
#include <monetary.h>
#include <new>
#include <stdarg.h>
#include <stdlib.h>
#define ICU_VERSION icu_44
BCountry::BCountry(const char* countryCode)
:
fICULocale(new ICU_VERSION::Locale("", countryCode))
{
}
BCountry::BCountry(const BCountry& other)
:
fICULocale(new ICU_VERSION::Locale(*other.fICULocale))
{
}
BCountry&
BCountry::operator=(const BCountry& other)
{
if (this == &other)
return *this;
*fICULocale = *other.fICULocale;
return *this;
}
BCountry::~BCountry()
{
delete fICULocale;
}
status_t
BCountry::GetNativeName(BString& name) const
{
UnicodeString string;
fICULocale->getDisplayName(*fICULocale, string);
string.toTitle(NULL, *fICULocale);
name.Truncate(0);
BStringByteSink converter(&name);
string.toUTF8(converter);
return B_OK;
}
status_t
BCountry::GetName(BString& name, const BLanguage* displayLanguage) const
{
BString appLanguage;
if (displayLanguage == NULL) {
BMessage preferredLanguage;
be_locale_roster->GetPreferredLanguages(&preferredLanguage);
preferredLanguage.FindString("language", 0, &appLanguage);
} else {
appLanguage = displayLanguage->Code();
}
UnicodeString uString;
fICULocale->getDisplayName(Locale(appLanguage), uString);
name.Truncate(0);
BStringByteSink stringConverter(&name);
uString.toUTF8(stringConverter);
return B_OK;
}
const char*
BCountry::Code() const
{
return fICULocale->getCountry();
}
status_t
BCountry::GetIcon(BBitmap* result) const
{
const char* code = fICULocale->getCountry();
if (code == NULL)
return B_ERROR;
return be_locale_roster->GetFlagIconForCountry(result, code);
}
status_t
BCountry::GetAvailableTimeZones(BMessage* timeZones) const
{
return be_locale_roster->GetAvailableTimeZonesForCountry(timeZones, Code());
}