Largish cleanup sweep concerning the Locale Kit (sorry it got so big):
* refactored private/mutable stuff out of LocaleRoster into MutableLocaleRoster * moved management of Locale/Time settings file and broadcasting of any changes out of preflets and into MutableLocaleRoster * added proper sorting to the listviews of the Locale preflet * the Time preflet no longer overlaps long timezone names into the actual time * several fixes with respect to leaking ICU objects, esp. in BCountry * the locale roster no longer passes out references to its own BCountry object, but uses copies, instead - this makes locking superfluous, as the clients' BCountry objects can no longer be changed by the setting a new default country in the locale roster * removed pretty useless POSIX-style symbol fetching from BCountry - if we need that at all, it should live in the dedicated formatter classes * adjusted readonlybootprompt, dstcheck and Deskbar to the changed Locale API * refactored existing Time-formatter into TimeUnitFormat and DurationFormat (the latter of which is now used by AboutSystem) * added stubs for Date, DateTime and Time formatters * lots of coding style fixes throughout the Locale Kit and the Locale and Time preflets This will probably break most external apps making use of the Locale Kit - it does break WebPositive. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37831 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -220,7 +220,6 @@ class BCatalog {
|
||||
// For BCatalog add-on implementations:
|
||||
|
||||
class BCatalogAddOn {
|
||||
friend class BLocaleRoster;
|
||||
public:
|
||||
BCatalogAddOn(const char *signature, const char *language,
|
||||
uint32 fingerprint);
|
||||
@@ -269,6 +268,8 @@ class BCatalogAddOn {
|
||||
const char *cmt);
|
||||
static int32 MarkForTranslation(int32 id);
|
||||
|
||||
void SetNext(BCatalogAddOn *next);
|
||||
|
||||
protected:
|
||||
virtual void UpdateFingerprint();
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
* Copyright 2003-2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
*/
|
||||
#ifndef _COLLATOR_H_
|
||||
#define _COLLATOR_H_
|
||||
|
||||
|
||||
#include <SupportDefs.h>
|
||||
#include <Archivable.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
namespace icu_44 {
|
||||
@@ -33,62 +33,72 @@ enum collator_strengths {
|
||||
};
|
||||
|
||||
|
||||
// N.B.: This class is not multithread-safe, as Compare() and GetKey() change
|
||||
// the ICUCollator (the strength). So if you want to use a BCollator from
|
||||
// more than one thread, you need to protect it with a lock
|
||||
class BCollator : public BArchivable {
|
||||
public:
|
||||
BCollator();
|
||||
BCollator(const char *locale, int8 strength, bool ignorePunctuation);
|
||||
BCollator(BMessage *archive);
|
||||
~BCollator();
|
||||
public:
|
||||
BCollator();
|
||||
BCollator(const char* locale,
|
||||
int8 strength = B_COLLATE_PRIMARY,
|
||||
bool ignorePunctuation = false);
|
||||
BCollator(BMessage* archive);
|
||||
|
||||
void SetDefaultStrength(int8 strength);
|
||||
int8 DefaultStrength() const;
|
||||
BCollator(const BCollator& other);
|
||||
|
||||
void SetIgnorePunctuation(bool ignore);
|
||||
bool IgnorePunctuation() const;
|
||||
~BCollator();
|
||||
|
||||
status_t GetSortKey(const char *string, BString *key,
|
||||
int8 strength = B_COLLATE_DEFAULT);
|
||||
BCollator& operator=(const BCollator& source);
|
||||
|
||||
int Compare(const char *, const char *, int32 len = -1,
|
||||
int8 strength = B_COLLATE_DEFAULT);
|
||||
bool Equal(const char *, const char *, int32 len = -1,
|
||||
int8 strength = B_COLLATE_DEFAULT);
|
||||
bool Greater(const char *, const char *, int32 len = -1,
|
||||
int8 strength = B_COLLATE_DEFAULT);
|
||||
bool GreaterOrEqual(const char *, const char *, int32 len = -1,
|
||||
int8 strength = B_COLLATE_DEFAULT);
|
||||
void SetDefaultStrength(int8 strength);
|
||||
int8 DefaultStrength() const;
|
||||
|
||||
// (un-)archiving API
|
||||
status_t Archive(BMessage *archive, bool deep) const;
|
||||
static BArchivable *Instantiate(BMessage *archive);
|
||||
void SetIgnorePunctuation(bool ignore);
|
||||
bool IgnorePunctuation() const;
|
||||
|
||||
private:
|
||||
icu_44::Collator* fICUCollator;
|
||||
icu_44::RuleBasedCollator* fFallbackICUCollator;
|
||||
int8 fStrength;
|
||||
bool fIgnorePunctuation;
|
||||
status_t GetSortKey(const char* string, BString* key,
|
||||
int8 strength = B_COLLATE_DEFAULT) const;
|
||||
|
||||
int Compare(const char* s1, const char* s2,
|
||||
int8 strength = B_COLLATE_DEFAULT) const;
|
||||
bool Equal(const char* s1, const char* s2,
|
||||
int8 strength = B_COLLATE_DEFAULT) const;
|
||||
bool Greater(const char* s1, const char* s2,
|
||||
int8 strength = B_COLLATE_DEFAULT) const;
|
||||
bool GreaterOrEqual(const char* s1, const char* s2,
|
||||
int8 strength = B_COLLATE_DEFAULT) const;
|
||||
|
||||
// (un-)archiving API
|
||||
status_t Archive(BMessage* archive, bool deep) const;
|
||||
static BArchivable* Instantiate(BMessage* archive);
|
||||
|
||||
private:
|
||||
status_t _SetStrength(int8 strength) const;
|
||||
|
||||
mutable icu_44::Collator* fICUCollator;
|
||||
int8 fDefaultStrength;
|
||||
bool fIgnorePunctuation;
|
||||
};
|
||||
|
||||
|
||||
inline bool
|
||||
BCollator::Equal(const char *s1, const char *s2, int32 len, int8 strength)
|
||||
BCollator::Equal(const char *s1, const char *s2, int8 strength) const
|
||||
{
|
||||
return Compare(s1, s2, len, strength) == 0;
|
||||
return Compare(s1, s2, strength) == 0;
|
||||
}
|
||||
|
||||
|
||||
inline bool
|
||||
BCollator::Greater(const char *s1, const char *s2, int32 len, int8 strength)
|
||||
BCollator::Greater(const char *s1, const char *s2, int8 strength) const
|
||||
{
|
||||
return Compare(s1, s2, len, strength) > 0;
|
||||
return Compare(s1, s2, strength) > 0;
|
||||
}
|
||||
|
||||
|
||||
inline bool
|
||||
BCollator::GreaterOrEqual(const char *s1, const char *s2, int32 len,
|
||||
int8 strength)
|
||||
BCollator::GreaterOrEqual(const char *s1, const char *s2, int8 strength) const
|
||||
{
|
||||
return Compare(s1, s2, len, strength) >= 0;
|
||||
return Compare(s1, s2, strength) >= 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+67
-79
@@ -1,10 +1,13 @@
|
||||
/*
|
||||
* Copyright 2003-2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
#ifndef _COUNTRY_H_
|
||||
#define _COUNTRY_H_
|
||||
|
||||
|
||||
#include <List.h>
|
||||
#include <LocaleStrings.h>
|
||||
#include <Locker.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
@@ -36,101 +39,86 @@ typedef enum {
|
||||
|
||||
|
||||
class BCountry {
|
||||
public:
|
||||
BCountry(const char* languageCode, const char* countryCode);
|
||||
BCountry(const char* languageAndCountryCode = "en_US");
|
||||
BCountry(const BCountry& other);
|
||||
BCountry& operator=(const BCountry& other);
|
||||
virtual ~BCountry();
|
||||
public:
|
||||
BCountry(const char* languageCode,
|
||||
const char* countryCode);
|
||||
BCountry(const char* languageAndCountryCode
|
||||
= "en_US");
|
||||
BCountry(const BCountry& other);
|
||||
BCountry& operator=(const BCountry& other);
|
||||
~BCountry();
|
||||
|
||||
bool Name(BString& name) const;
|
||||
bool LocaleName(BString& name) const;
|
||||
const char* Code() const;
|
||||
status_t GetIcon(BBitmap* result);
|
||||
bool GetName(BString& name) const;
|
||||
bool GetLocaleName(BString& name) const;
|
||||
const char* Code() const;
|
||||
status_t GetIcon(BBitmap* result) const;
|
||||
|
||||
const char* GetString(uint32 id) const;
|
||||
const char* GetLocalizedString(uint32 id) const;
|
||||
|
||||
// Date
|
||||
// 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 DateFields(BDateElement*& fields, int& fieldCount,
|
||||
bool longFormat);
|
||||
status_t DateFormat(BString&, bool longFormat);
|
||||
status_t SetDateFormat(const char* formatString,
|
||||
bool longFormat = true);
|
||||
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();
|
||||
int StartOfWeek() const;
|
||||
|
||||
// Time
|
||||
// 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 TimeFields(BDateElement*& fields, int& fieldCount,
|
||||
bool longFormat);
|
||||
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 TimeFormat(BString&, bool longFormat);
|
||||
status_t SetTimeFormat(const char* formatString,
|
||||
bool longFormat = true);
|
||||
status_t GetTimeFormat(BString& out,
|
||||
bool longFormat) const;
|
||||
|
||||
// numbers
|
||||
// numbers
|
||||
|
||||
virtual void FormatNumber(char* string, size_t maxSize, double value);
|
||||
virtual status_t FormatNumber(BString* string, double value);
|
||||
virtual void FormatNumber(char* string, size_t maxSize, int32 value);
|
||||
virtual void FormatNumber(BString* string, int32 value);
|
||||
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);
|
||||
|
||||
bool DecimalPoint(BString&) const;
|
||||
bool ThousandsSeparator(BString&) const;
|
||||
bool Grouping(BString&) const;
|
||||
// measurements
|
||||
|
||||
bool PositiveSign(BString&) const;
|
||||
bool NegativeSign(BString&) const;
|
||||
int8 Measurement() const;
|
||||
|
||||
// measurements
|
||||
// monetary
|
||||
|
||||
virtual int8 Measurement() const;
|
||||
ssize_t FormatMonetary(char* string, size_t maxSize,
|
||||
double value);
|
||||
ssize_t FormatMonetary(BString* string, double value);
|
||||
|
||||
// monetary
|
||||
// timezones
|
||||
|
||||
virtual ssize_t FormatMonetary(char* string, size_t maxSize,
|
||||
double value);
|
||||
virtual ssize_t FormatMonetary(BString* string, double value);
|
||||
int GetTimeZones(BList& timezones) const;
|
||||
|
||||
bool CurrencySymbol(BString&) const;
|
||||
bool InternationalCurrencySymbol(BString&) const;
|
||||
bool MonDecimalPoint(BString&) const;
|
||||
bool MonThousandsSeparator(BString&) const;
|
||||
bool MonGrouping(BString&) const;
|
||||
virtual int32 MonFracDigits() const;
|
||||
|
||||
// timezones
|
||||
int GetTimeZones(BList& timezones);
|
||||
|
||||
private:
|
||||
icu_44::DateFormat* _LockDateFormatter(bool longFormat);
|
||||
icu_44::DateFormat* _LockTimeFormatter(bool longFormat);
|
||||
void _UnlockDateFormatter(bool longFormat);
|
||||
void _UnlockTimeFormatter(bool longFormat);
|
||||
|
||||
icu_44::DateFormat* fICULongDateFormatter;
|
||||
icu_44::DateFormat* fICUShortDateFormatter;
|
||||
icu_44::DateFormat* fICULongTimeFormatter;
|
||||
icu_44::DateFormat* fICUShortTimeFormatter;
|
||||
icu_44::Locale* fICULocale;
|
||||
|
||||
BLocker fLongDateLock;
|
||||
BLocker fShortDateLock;
|
||||
BLocker fLongTimeLock;
|
||||
BLocker fShortTimeLock;
|
||||
private:
|
||||
icu_44::Locale* fICULocale;
|
||||
BString fLongDateFormat;
|
||||
BString fShortDateFormat;
|
||||
BString fLongTimeFormat;
|
||||
BString fShortTimeFormat;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _COUNTRY_H_ */
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
#ifndef _B_DATE_FORMAT_H_
|
||||
#define _B_DATE_FORMAT_H_
|
||||
|
||||
#include <DateTimeFormat.h>
|
||||
|
||||
|
||||
class BString;
|
||||
|
||||
class BDateFormat : public BDateTimeFormat {
|
||||
public:
|
||||
BDateFormat();
|
||||
BDateFormat(const BDateFormat &other);
|
||||
virtual ~BDateFormat();
|
||||
|
||||
// formatting
|
||||
|
||||
// no-frills version: Simply appends the
|
||||
// formatted date to the string buffer.
|
||||
// Can fail only with B_NO_MEMORY or B_BAD_VALUE.
|
||||
virtual status_t Format(bigtime_t value, BString* buffer) const;
|
||||
|
||||
// TODO: ... all, basically!
|
||||
};
|
||||
|
||||
|
||||
#endif // _B_DATE_FORMAT_H_
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
#ifndef _B_DATE_TIME_FORMAT_H_
|
||||
#define _B_DATE_TIME_FORMAT_H_
|
||||
|
||||
#include <Format.h>
|
||||
#include <FormatParameters.h>
|
||||
|
||||
|
||||
class BString;
|
||||
|
||||
class BDateTimeFormat : public BFormat {
|
||||
public:
|
||||
BDateTimeFormat();
|
||||
BDateTimeFormat(const BDateTimeFormat &other);
|
||||
virtual ~BDateTimeFormat();
|
||||
|
||||
// formatting
|
||||
|
||||
// no-frills version: Simply appends the
|
||||
// formatted date to the string buffer.
|
||||
// Can fail only with B_NO_MEMORY or B_BAD_VALUE.
|
||||
virtual status_t Format(bigtime_t value, BString* buffer) const;
|
||||
|
||||
// TODO: ... basically, all of it!
|
||||
};
|
||||
|
||||
|
||||
#endif // _B_DATE_TIME_FORMAT_H_
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_DURATION_FORMAT_H_
|
||||
#define _B_DURATION_FORMAT_H_
|
||||
|
||||
|
||||
#include <DateTimeFormat.h>
|
||||
#include <String.h>
|
||||
#include <TimeUnitFormat.h>
|
||||
|
||||
|
||||
class BDurationFormat : public BFormat {
|
||||
public:
|
||||
status_t Format(bigtime_t startValue,
|
||||
bigtime_t stopValue, BString* buffer,
|
||||
time_unit_style style = B_TIME_UNIT_FULL,
|
||||
const BString& separator = ", "
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,9 +1,14 @@
|
||||
/*
|
||||
* Copyright 2003-2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
#ifndef _B_FORMAT_H_
|
||||
#define _B_FORMAT_H_
|
||||
|
||||
#include <FormatParameters.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
// types of fields contained in formatted strings
|
||||
enum {
|
||||
// number format fields
|
||||
@@ -30,16 +35,18 @@ struct format_field_position {
|
||||
int32 length;
|
||||
};
|
||||
|
||||
|
||||
class BFormatImpl;
|
||||
|
||||
class BFormat {
|
||||
protected:
|
||||
BFormat(const BFormat &other);
|
||||
~BFormat();
|
||||
protected:
|
||||
BFormat(const BFormat& other);
|
||||
virtual ~BFormat();
|
||||
|
||||
BFormat &operator=(const BFormat &other);
|
||||
BFormat& operator=(const BFormat& other);
|
||||
|
||||
BFormat();
|
||||
BFormat();
|
||||
};
|
||||
|
||||
|
||||
#endif // _B_FORMAT_H_
|
||||
|
||||
@@ -27,8 +27,13 @@ enum script_direction {
|
||||
|
||||
class BLanguage {
|
||||
public:
|
||||
BLanguage();
|
||||
BLanguage(const char* language);
|
||||
BLanguage(const BLanguage& other);
|
||||
~BLanguage();
|
||||
|
||||
BLanguage& operator=(const BLanguage& source);
|
||||
|
||||
status_t GetName(BString& name) const;
|
||||
status_t GetTranslatedName(BString& name) const;
|
||||
|
||||
@@ -43,19 +48,15 @@ public:
|
||||
|
||||
uint8 Direction() const;
|
||||
|
||||
status_t SetTo(const char* language);
|
||||
|
||||
// see definitions below
|
||||
const char* GetString(uint32 id) const;
|
||||
|
||||
private:
|
||||
friend class BLocaleRoster;
|
||||
|
||||
BLanguage(const char *language);
|
||||
void Default();
|
||||
|
||||
private:
|
||||
char* fStrings[B_NUM_LANGUAGE_STRINGS];
|
||||
// BString fStrings[B_NUM_LANGUAGE_STRINGS];
|
||||
uint8 fDirection;
|
||||
icu_44::Locale* fICULocale;
|
||||
icu_44::Locale* fICULocale;
|
||||
};
|
||||
|
||||
|
||||
|
||||
+56
-49
@@ -7,86 +7,92 @@
|
||||
|
||||
|
||||
#include <Collator.h>
|
||||
#include <Language.h>
|
||||
#include <Country.h>
|
||||
#include <Language.h>
|
||||
|
||||
|
||||
class BCatalog;
|
||||
class BLocaleRoster;
|
||||
class BString;
|
||||
|
||||
|
||||
class BLocale {
|
||||
public:
|
||||
BLocale();
|
||||
~BLocale();
|
||||
public:
|
||||
BLocale();
|
||||
~BLocale();
|
||||
|
||||
BCollator *Collator() const { return fCollator; }
|
||||
BCountry *Country() const { return fCountry; }
|
||||
BLanguage *Language() const { return fLanguage; }
|
||||
const BCollator* Collator() const { return &fCollator; }
|
||||
const BCountry* Country() const { return &fCountry; }
|
||||
const BLanguage* Language() const { return &fLanguage; }
|
||||
|
||||
// see definitions in LocaleStrings.h
|
||||
const char *GetString(uint32 id);
|
||||
// see definitions in LocaleStrings.h
|
||||
const char* GetString(uint32 id);
|
||||
|
||||
void FormatString(char *target, size_t maxSize, char *fmt, ...);
|
||||
void FormatString(BString *, char *fmt, ...);
|
||||
void FormatDateTime(char *target, size_t maxSize, const char *fmt,
|
||||
time_t);
|
||||
void FormatDateTime(BString *, const char *fmt, time_t);
|
||||
void FormatString(char* target, size_t maxSize,
|
||||
char* fmt, ...);
|
||||
void FormatString(BString* buffer, char* fmt, ...);
|
||||
void FormatDateTime(char* target, size_t maxSize,
|
||||
const char* fmt, time_t value);
|
||||
void FormatDateTime(BString* buffer, const char* fmt,
|
||||
time_t value);
|
||||
|
||||
// Country short-hands
|
||||
// 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,
|
||||
bool longFormat);
|
||||
void FormatTime(char* target, size_t maxSize,
|
||||
time_t value, bool longFormat);
|
||||
void FormatTime(BString* target, time_t value,
|
||||
bool longFormat);
|
||||
|
||||
void FormatDate(char *target, size_t maxSize, time_t, bool longFormat);
|
||||
void FormatDate(BString *target, time_t, bool longFormat);
|
||||
void FormatTime(char *target, size_t maxSize, time_t, bool longFormat);
|
||||
void FormatTime(BString *target, time_t, bool longFormat);
|
||||
// Collator short-hands
|
||||
int StringCompare(const char* s1,
|
||||
const char* s2) const;
|
||||
int StringCompare(const BString* s1,
|
||||
const BString* s2) const;
|
||||
|
||||
// Collator short-hands
|
||||
void GetSortKey(const char* string,
|
||||
BString* key) const;
|
||||
|
||||
int StringCompare(const char *, const char *, int32 len = -1,
|
||||
int8 strength = B_COLLATE_DEFAULT) const;
|
||||
int StringCompare(const BString *, const BString *,
|
||||
int32 len = -1, int8 strength = B_COLLATE_DEFAULT) const;
|
||||
|
||||
void GetSortKey(const char *string, BString *key);
|
||||
|
||||
protected:
|
||||
BCollator *fCollator;
|
||||
BLanguage *fLanguage;
|
||||
BCountry *fCountry;
|
||||
protected:
|
||||
BCollator fCollator;
|
||||
BCountry fCountry;
|
||||
BLanguage fLanguage;
|
||||
};
|
||||
|
||||
|
||||
// global objects
|
||||
extern BLocale *be_locale;
|
||||
extern BLocaleRoster *be_locale_roster;
|
||||
extern BLocale* be_locale;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//--- country short-hands inlines ---
|
||||
|
||||
inline void
|
||||
BLocale::FormatDate(char *target, size_t maxSize, time_t timer, bool longFormat)
|
||||
BLocale::FormatDate(char* target, size_t maxSize, time_t timer, bool longFormat)
|
||||
{
|
||||
fCountry->FormatDate(target, maxSize, timer, longFormat);
|
||||
fCountry.FormatDate(target, maxSize, timer, longFormat);
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
BLocale::FormatDate(BString *target, time_t timer, bool longFormat)
|
||||
BLocale::FormatDate(BString* target, time_t timer, bool longFormat)
|
||||
{
|
||||
fCountry->FormatDate(target, timer, longFormat);
|
||||
fCountry.FormatDate(target, timer, longFormat);
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
BLocale::FormatTime(char *target, size_t maxSize, time_t timer, bool longFormat)
|
||||
BLocale::FormatTime(char* target, size_t maxSize, time_t timer, bool longFormat)
|
||||
{
|
||||
fCountry->FormatTime(target, maxSize, timer, longFormat);
|
||||
fCountry.FormatTime(target, maxSize, timer, longFormat);
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
BLocale::FormatTime(BString *target, time_t timer, bool longFormat)
|
||||
BLocale::FormatTime(BString* target, time_t timer, bool longFormat)
|
||||
{
|
||||
fCountry->FormatTime(target, timer, longFormat);
|
||||
fCountry.FormatTime(target, timer, longFormat);
|
||||
}
|
||||
|
||||
|
||||
@@ -94,23 +100,24 @@ BLocale::FormatTime(BString *target, time_t timer, bool longFormat)
|
||||
// #pragma mark -
|
||||
|
||||
inline int
|
||||
BLocale::StringCompare(const char *string1, const char *string2, int32 length, int8 strength) const
|
||||
BLocale::StringCompare(const char* s1, const char* s2) const
|
||||
{
|
||||
return fCollator->Compare(string1, string2, length, strength);
|
||||
return fCollator.Compare(s1, s2);
|
||||
}
|
||||
|
||||
|
||||
inline int
|
||||
BLocale::StringCompare(const BString *string1, const BString *string2, int32 length, int8 strength) const
|
||||
BLocale::StringCompare(const BString* s1, const BString* s2) const
|
||||
{
|
||||
return fCollator->Compare(string1->String(), string2->String(), length, strength);
|
||||
return fCollator.Compare(s1->String(), s2->String());
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
BLocale::GetSortKey(const char *string, BString *key)
|
||||
BLocale::GetSortKey(const char* string, BString* key) const
|
||||
{
|
||||
fCollator->GetSortKey(string, key);
|
||||
fCollator.GetSortKey(string, key);
|
||||
}
|
||||
|
||||
|
||||
#endif /* _B_LOCALE_H_ */
|
||||
|
||||
@@ -9,89 +9,70 @@
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class BLanguage;
|
||||
class BLocale;
|
||||
class BCatalog;
|
||||
class BCollator;
|
||||
class BCountry;
|
||||
class BCatalog;
|
||||
class BCatalogAddOn;
|
||||
class BLanguage;
|
||||
class BLocale;
|
||||
class BMessage;
|
||||
class BTimeZone;
|
||||
|
||||
struct entry_ref;
|
||||
|
||||
namespace BPrivate {
|
||||
class EditableCatalog;
|
||||
}
|
||||
|
||||
|
||||
enum {
|
||||
B_LOCALE_CHANGED = '_LCC',
|
||||
B_LOCALE_CHANGED = '_LCC',
|
||||
};
|
||||
|
||||
|
||||
class BLocaleRoster {
|
||||
public:
|
||||
BLocaleRoster();
|
||||
~BLocaleRoster();
|
||||
public:
|
||||
BLocaleRoster();
|
||||
~BLocaleRoster();
|
||||
|
||||
status_t GetSystemCatalog(BCatalogAddOn **catalog) const;
|
||||
status_t GetDefaultCollator(BCollator **collator) const;
|
||||
status_t GetDefaultLanguage(BLanguage **language) const;
|
||||
status_t GetDefaultCountry(BCountry **contry) const;
|
||||
status_t GetDefaultTimeZone(BTimeZone**timezone) const;
|
||||
status_t GetDefaultCollator(BCollator* collator) const;
|
||||
status_t GetDefaultLanguage(BLanguage* language) const;
|
||||
status_t GetDefaultCountry(BCountry* country) const;
|
||||
status_t GetDefaultTimeZone(BTimeZone* timezone) const;
|
||||
|
||||
void SetDefaultCountry(BCountry *) const;
|
||||
void SetDefaultTimeZone(const char* zone) const;
|
||||
void UpdateSettings(BMessage* newSettings);
|
||||
status_t GetLanguage(const char* languageCode,
|
||||
BLanguage** _language) const;
|
||||
|
||||
status_t GetLanguage(const char* languageCode, BLanguage** _language)
|
||||
const;
|
||||
status_t GetPreferredLanguages(BMessage* message) const;
|
||||
|
||||
status_t GetPreferredLanguages(BMessage *) const;
|
||||
status_t SetPreferredLanguages(BMessage *);
|
||||
// the message contains one or more 'language'-string-fields
|
||||
// which contain the language-name(s)
|
||||
status_t GetInstalledLanguages(BMessage* message) const;
|
||||
// the message contains one or more
|
||||
// 'language'-string-fields which
|
||||
// contain the language-name(s)
|
||||
|
||||
status_t GetInstalledLanguages(BMessage *) const;
|
||||
// the message contains one or more 'language'-string-fields
|
||||
// which contain the language-name(s)
|
||||
status_t GetAvailableCountries(BMessage* message) const;
|
||||
|
||||
status_t GetAvailableCountries(BMessage *) const;
|
||||
status_t GetInstalledCatalogs(BMessage* message,
|
||||
const char* sigPattern = NULL,
|
||||
const char* langPattern = NULL,
|
||||
int32 fingerprint = 0) const;
|
||||
// the message contains...
|
||||
|
||||
status_t GetInstalledCatalogs(BMessage *, const char* sigPattern = NULL,
|
||||
const char* langPattern = NULL, int32 fingerprint = 0) const;
|
||||
// the message contains...
|
||||
status_t Refresh();
|
||||
// Refresh the internal data from the
|
||||
// settings file(s)
|
||||
|
||||
BCatalog* GetCatalog();
|
||||
// Get the catalog for the calling image (that needs to link with
|
||||
// liblocalestub.a)
|
||||
BCatalog* GetCatalog();
|
||||
// Get the catalog for the calling image
|
||||
// (that needs to link with liblocalestub.a)
|
||||
|
||||
static const char *kCatLangAttr;
|
||||
static const char *kCatSigAttr;
|
||||
static const char *kCatFingerprintAttr;
|
||||
static const char* kCatLangAttr;
|
||||
static const char* kCatSigAttr;
|
||||
static const char* kCatFingerprintAttr;
|
||||
|
||||
static const char *kCatManagerMimeType;
|
||||
static const char *kCatEditorMimeType;
|
||||
static const char* kEmbeddedCatAttr;
|
||||
static int32 kEmbeddedCatResId;
|
||||
|
||||
static const char *kEmbeddedCatAttr;
|
||||
static int32 kEmbeddedCatResId;
|
||||
|
||||
private:
|
||||
BCatalog* GetCatalog(BCatalog* catalog, vint32* catalogInitStatus);
|
||||
|
||||
BCatalogAddOn* LoadCatalog(const char *signature,
|
||||
const char *language = NULL, int32 fingerprint = 0);
|
||||
BCatalogAddOn* LoadEmbeddedCatalog(entry_ref *appOrAddOnRef);
|
||||
status_t UnloadCatalog(BCatalogAddOn *addOn);
|
||||
|
||||
BCatalogAddOn* CreateCatalog(const char *type,
|
||||
const char *signature, const char *language);
|
||||
|
||||
friend class BCatalog;
|
||||
friend class BCatalogStub;
|
||||
friend class BPrivate::EditableCatalog;
|
||||
friend status_t get_add_on_catalog(BCatalog*, const char *);
|
||||
private:
|
||||
static BCatalog* _GetCatalog(BCatalog* catalog,
|
||||
vint32* catalogInitStatus);
|
||||
};
|
||||
|
||||
#endif /* _LOCALE_ROSTER_H_ */
|
||||
|
||||
extern BLocaleRoster* be_locale_roster;
|
||||
|
||||
|
||||
#endif // _LOCALE_ROSTER_H_
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
#ifndef _B_TIME_FORMAT_H_
|
||||
#define _B_TIME_FORMAT_H_
|
||||
|
||||
|
||||
#include <NumberFormat.h>
|
||||
#include <SupportDefs.h>
|
||||
#include <DateTimeFormat.h>
|
||||
|
||||
|
||||
class BString;
|
||||
|
||||
class BTimeFormat : public BDateTimeFormat {
|
||||
public:
|
||||
BTimeFormat(const BTimeFormat &other);
|
||||
virtual ~BTimeFormat();
|
||||
|
||||
class BTimeFormat : public BNumberFormat {
|
||||
public:
|
||||
status_t Format(int64 number, BString *buffer) const;
|
||||
// formatting
|
||||
|
||||
// TODO : version for char* buffer, size_t bufferSize
|
||||
// TODO : parsing ?
|
||||
// no-frills version: Simply appends the
|
||||
// formatted date to the string buffer.
|
||||
// Can fail only with B_NO_MEMORY or B_BAD_VALUE.
|
||||
virtual status_t Format(bigtime_t value, BString* buffer) const;
|
||||
|
||||
// TODO: ... basically, all of it!
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif // _B_TIME_FORMAT_H_
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _B_TIME_UNIT_FORMAT_H_
|
||||
#define _B_TIME_UNIT_FORMAT_H_
|
||||
|
||||
|
||||
#include <DateTimeFormat.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
class BString;
|
||||
|
||||
|
||||
enum time_unit_style {
|
||||
B_TIME_UNIT_ABBREVIATED, // e.g. '5 hrs.'
|
||||
B_TIME_UNIT_FULL, // e.g. '5 hours'
|
||||
};
|
||||
|
||||
|
||||
enum time_unit_element {
|
||||
B_TIME_UNIT_YEAR,
|
||||
B_TIME_UNIT_MONTH,
|
||||
B_TIME_UNIT_WEEK,
|
||||
B_TIME_UNIT_DAY,
|
||||
B_TIME_UNIT_HOUR,
|
||||
B_TIME_UNIT_MINUTE,
|
||||
B_TIME_UNIT_SECOND,
|
||||
|
||||
B_TIME_UNIT_LAST = B_TIME_UNIT_SECOND
|
||||
};
|
||||
|
||||
|
||||
class BTimeUnitFormat : public BFormat {
|
||||
public:
|
||||
status_t Format(int32 value, time_unit_element unit,
|
||||
BString* buffer,
|
||||
time_unit_style style = B_TIME_UNIT_FULL
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
@@ -20,9 +20,11 @@ public:
|
||||
|
||||
status_t InitCheck() const;
|
||||
|
||||
private:
|
||||
void _Init(const char* zoneCode);
|
||||
status_t SetTo(const char* zoneCode);
|
||||
|
||||
static const char* kNameOfGmtZone;
|
||||
|
||||
private:
|
||||
BString fCode;
|
||||
BString fName;
|
||||
int fOffsetFromGMT;
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright 2010, Haiku. All rights reserved.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
#ifndef _MUTABLE_LOCALE_ROSTER_H_
|
||||
#define _MUTABLE_LOCALE_ROSTER_H_
|
||||
|
||||
|
||||
#include <Collator.h>
|
||||
#include <Country.h>
|
||||
#include <image.h>
|
||||
#include <Language.h>
|
||||
#include <List.h>
|
||||
#include <Locker.h>
|
||||
#include <LocaleRoster.h>
|
||||
#include <Message.h>
|
||||
#include <TimeZone.h>
|
||||
|
||||
|
||||
class BLocale;
|
||||
class BCatalog;
|
||||
class BCatalogAddOn;
|
||||
|
||||
struct entry_ref;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class MutableLocaleRoster : public BLocaleRoster {
|
||||
public:
|
||||
MutableLocaleRoster();
|
||||
~MutableLocaleRoster();
|
||||
|
||||
status_t SetDefaultCountry(const BCountry& country);
|
||||
status_t SetDefaultTimeZone(const BTimeZone& zone);
|
||||
|
||||
status_t SetPreferredLanguages(const BMessage* message);
|
||||
// the message contains one or more
|
||||
// 'language'-string-fields which
|
||||
// contain the language-name(s)
|
||||
|
||||
status_t GetSystemCatalog(BCatalogAddOn** catalog) const;
|
||||
|
||||
BCatalogAddOn* LoadCatalog(const char* signature,
|
||||
const char* language = NULL,
|
||||
int32 fingerprint = 0) const;
|
||||
BCatalogAddOn* LoadEmbeddedCatalog(entry_ref* appOrAddOnRef);
|
||||
status_t UnloadCatalog(BCatalogAddOn* addOn);
|
||||
|
||||
BCatalogAddOn* CreateCatalog(const char* type,
|
||||
const char* signature,
|
||||
const char* language);
|
||||
};
|
||||
|
||||
|
||||
extern MutableLocaleRoster* mutable_locale_roster;
|
||||
|
||||
|
||||
typedef BCatalogAddOn* (*InstantiateCatalogFunc)(const char* name,
|
||||
const char* language, uint32 fingerprint);
|
||||
|
||||
typedef BCatalogAddOn* (*CreateCatalogFunc)(const char* name,
|
||||
const char* language);
|
||||
|
||||
typedef BCatalogAddOn* (*InstantiateEmbeddedCatalogFunc)(
|
||||
entry_ref* appOrAddOnRef);
|
||||
|
||||
typedef status_t (*GetAvailableLanguagesFunc)(BMessage*, const char*,
|
||||
const char*, int32);
|
||||
|
||||
/*
|
||||
* info about a single catalog-add-on (representing a catalog type):
|
||||
*/
|
||||
struct CatalogAddOnInfo {
|
||||
InstantiateCatalogFunc fInstantiateFunc;
|
||||
InstantiateEmbeddedCatalogFunc fInstantiateEmbeddedFunc;
|
||||
CreateCatalogFunc fCreateFunc;
|
||||
GetAvailableLanguagesFunc fLanguagesFunc;
|
||||
|
||||
BString fName;
|
||||
BString fPath;
|
||||
image_id fAddOnImage;
|
||||
uint8 fPriority;
|
||||
BList fLoadedCatalogs;
|
||||
bool fIsEmbedded;
|
||||
// an embedded add-on actually isn't an
|
||||
// add-on, it is included as part of the
|
||||
// library.
|
||||
// The DefaultCatalog is such a beast!
|
||||
|
||||
CatalogAddOnInfo(const BString& name,
|
||||
const BString& path, uint8 priority);
|
||||
~CatalogAddOnInfo();
|
||||
|
||||
bool MakeSureItsLoaded();
|
||||
void UnloadIfPossible();
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The global data that is shared between all roster-objects of a process.
|
||||
*/
|
||||
struct RosterData {
|
||||
BLocker fLock;
|
||||
BList fCatalogAddOnInfos;
|
||||
BMessage fPreferredLanguages;
|
||||
|
||||
BCollator fDefaultCollator;
|
||||
BCountry fDefaultCountry;
|
||||
BLanguage fDefaultLanguage;
|
||||
BTimeZone fDefaultTimeZone;
|
||||
|
||||
RosterData();
|
||||
~RosterData();
|
||||
|
||||
void InitializeCatalogAddOns();
|
||||
void CleanupCatalogAddOns();
|
||||
status_t Refresh();
|
||||
|
||||
static int CompareInfos(const void* left,
|
||||
const void* right);
|
||||
|
||||
status_t SetDefaultCountry(const BCountry& country);
|
||||
status_t SetDefaultTimeZone(const BTimeZone& zone);
|
||||
status_t SetPreferredLanguages(const BMessage* msg);
|
||||
private:
|
||||
status_t _LoadLocaleSettings();
|
||||
status_t _SaveLocaleSettings();
|
||||
|
||||
status_t _LoadTimeSettings();
|
||||
status_t _SaveTimeSettings();
|
||||
|
||||
status_t _SetDefaultCountry(const BCountry& country);
|
||||
status_t _SetDefaultTimeZone(const BTimeZone& zone);
|
||||
status_t _SetPreferredLanguages(const BMessage* msg);
|
||||
|
||||
status_t _AddDefaultCountryToMessage(
|
||||
BMessage* message) const;
|
||||
status_t _AddDefaultTimeZoneToMessage(
|
||||
BMessage* message) const;
|
||||
status_t _AddPreferredLanguagesToMessage(
|
||||
BMessage* message) const;
|
||||
};
|
||||
|
||||
|
||||
extern RosterData gRosterData;
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
|
||||
#endif // _MUTABLE_LOCALE_ROSTER_H_
|
||||
Reference in New Issue
Block a user