* Move the locale-related stuff away from BCountry to BLocale.

* Remove the be_locale global object and go through the be_locale_roster instead
 * Rework the storage of data for the be_locale_roster, since BLocale already holds a BCountry and a BLanguage.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37907 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adrien Destugues
2010-08-04 18:45:06 +00:00
parent afbbc97abf
commit 5c3a303486
21 changed files with 870 additions and 808 deletions
-53
View File
@@ -55,69 +55,16 @@ public:
const char* GetLocalizedString(uint32 id) const;
// Date
status_t FormatDate(char* string, size_t maxSize,
time_t time, bool longFormat);
status_t FormatDate(BString* string, time_t time,
bool longFormat);
status_t FormatDate(BString* string,
int*& fieldPositions, int& fieldCount,
time_t time, bool longFormat);
status_t GetDateFields(BDateElement*& fields,
int& fieldCount, bool longFormat) const;
status_t GetDateFormat(BString&, bool longFormat) const;
status_t SetDateFormat(const char* formatString,
bool longFormat = true);
int StartOfWeek() const;
// Time
status_t FormatTime(char* string, size_t maxSize,
time_t time, bool longFormat);
status_t FormatTime(BString* string, time_t time,
bool longFormat);
status_t FormatTime(BString* string,
int*& fieldPositions, int& fieldCount,
time_t time, bool longFormat);
status_t GetTimeFields(BDateElement*& fields,
int& fieldCount, bool longFormat) const;
status_t SetTimeFormat(const char* formatString,
bool longFormat = true);
status_t GetTimeFormat(BString& out,
bool longFormat) const;
// numbers
status_t FormatNumber(char* string, size_t maxSize,
double value);
status_t FormatNumber(BString* string, double value);
status_t FormatNumber(char* string, size_t maxSize,
int32 value);
status_t FormatNumber(BString* string, int32 value);
// measurements
int8 Measurement() const;
// monetary
ssize_t FormatMonetary(char* string, size_t maxSize,
double value);
ssize_t FormatMonetary(BString* string, double value);
// timezones
int GetTimeZones(BList& timezones) const;
private:
icu_44::Locale* fICULocale;
BString fLongDateFormat;
BString fShortDateFormat;
BString fLongTimeFormat;
BString fShortTimeFormat;
};
+62 -44
View File
@@ -17,12 +17,20 @@ class BString;
class BLocale {
public:
BLocale();
BLocale(const char* languageAndCountryCode
= "en_US");
BLocale(const BLocale& other);
BLocale& operator=(const BLocale& other);
~BLocale();
const BCollator* Collator() const { return &fCollator; }
const BCountry* Country() const { return &fCountry; }
const BLanguage* Language() const { return &fLanguage; }
const char* Code() const;
void SetCountry(const BCountry& newCountry);
void SetCollator(const BCollator& newCollator);
void SetLanguage(const char* languageCode);
// see definitions in LocaleStrings.h
const char* GetString(uint32 id);
@@ -35,16 +43,54 @@ public:
void FormatDateTime(BString* buffer, const char* fmt,
time_t value);
// Country short-hands, TODO: all these should go, once the
// Date...Format classes are done
void FormatDate(char* target, size_t maxSize,
time_t value, bool longFormat);
void FormatDate(BString* target, time_t value,
// Date
status_t FormatDate(char* string, size_t maxSize,
time_t time, bool longFormat);
status_t FormatDate(BString* string, time_t time,
bool longFormat);
void FormatTime(char* target, size_t maxSize,
time_t value, bool longFormat);
void FormatTime(BString* target, time_t value,
status_t FormatDate(BString* string,
int*& fieldPositions, int& fieldCount,
time_t time, bool longFormat);
status_t GetDateFields(BDateElement*& fields,
int& fieldCount, bool longFormat) const;
status_t GetDateFormat(BString&, bool longFormat) const;
status_t SetDateFormat(const char* formatString,
bool longFormat = true);
int StartOfWeek() const;
// Time
status_t FormatTime(char* string, size_t maxSize,
time_t time, bool longFormat);
status_t FormatTime(BString* string, time_t time,
bool longFormat);
status_t FormatTime(BString* string,
int*& fieldPositions, int& fieldCount,
time_t time, bool longFormat);
status_t GetTimeFields(BDateElement*& fields,
int& fieldCount, bool longFormat) const;
status_t SetTimeFormat(const char* formatString,
bool longFormat = true);
status_t GetTimeFormat(BString& out,
bool longFormat) const;
// numbers
status_t FormatNumber(char* string, size_t maxSize,
double value);
status_t FormatNumber(BString* string, double value);
status_t FormatNumber(char* string, size_t maxSize,
int32 value);
status_t FormatNumber(BString* string, int32 value);
// monetary
ssize_t FormatMonetary(char* string, size_t maxSize,
double value);
ssize_t FormatMonetary(BString* string, double value);
// Collator short-hands
int StringCompare(const char* s1,
@@ -59,44 +105,16 @@ protected:
BCollator fCollator;
BCountry fCountry;
BLanguage fLanguage;
icu_44::Locale* fICULocale;
BString fLongDateFormat;
BString fShortDateFormat;
BString fLongTimeFormat;
BString fShortTimeFormat;
};
// global objects
extern BLocale* be_locale;
//----------------------------------------------------------------------
//--- country short-hands inlines ---
inline void
BLocale::FormatDate(char* target, size_t maxSize, time_t timer, bool longFormat)
{
fCountry.FormatDate(target, maxSize, timer, longFormat);
}
inline void
BLocale::FormatDate(BString* target, time_t timer, bool longFormat)
{
fCountry.FormatDate(target, timer, longFormat);
}
inline void
BLocale::FormatTime(char* target, size_t maxSize, time_t timer, bool longFormat)
{
fCountry.FormatTime(target, maxSize, timer, longFormat);
}
inline void
BLocale::FormatTime(BString* target, time_t timer, bool longFormat)
{
fCountry.FormatTime(target, timer, longFormat);
}
//--- locale short-hands inlines ---
//--- collator short-hands inlines ---
// #pragma mark -
inline int
+1
View File
@@ -31,6 +31,7 @@ public:
status_t GetDefaultCollator(BCollator* collator) const;
status_t GetDefaultLanguage(BLanguage* language) const;
status_t GetDefaultCountry(BCountry* country) const;
status_t GetDefaultLocale(BLocale* locale) const;
status_t GetDefaultTimeZone(BTimeZone* timezone) const;
status_t GetLanguage(const char* languageCode,
+5 -3
View File
@@ -11,6 +11,7 @@
#include <image.h>
#include <Language.h>
#include <List.h>
#include <Locale.h>
#include <Locker.h>
#include <LocaleRoster.h>
#include <Message.h>
@@ -33,6 +34,7 @@ public:
~MutableLocaleRoster();
status_t SetDefaultCountry(const BCountry& country);
status_t SetDefaultLocale(const BLocale& locale);
status_t SetDefaultTimeZone(const BTimeZone& zone);
status_t SetPreferredLanguages(const BMessage* message);
@@ -106,9 +108,7 @@ struct RosterData {
BList fCatalogAddOnInfos;
BMessage fPreferredLanguages;
BCollator fDefaultCollator;
BCountry fDefaultCountry;
BLanguage fDefaultLanguage;
BLocale fDefaultLocale;
BTimeZone fDefaultTimeZone;
RosterData();
@@ -122,6 +122,7 @@ struct RosterData {
const void* right);
status_t SetDefaultCountry(const BCountry& country);
status_t SetDefaultLocale(const BLocale& locale);
status_t SetDefaultTimeZone(const BTimeZone& zone);
status_t SetPreferredLanguages(const BMessage* msg);
private:
@@ -132,6 +133,7 @@ private:
status_t _SaveTimeSettings();
status_t _SetDefaultCountry(const BCountry& country);
status_t _SetDefaultLocale(const BLocale& locale);
status_t _SetDefaultTimeZone(const BTimeZone& zone);
status_t _SetPreferredLanguages(const BMessage* msg);