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
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <Format.h>
|
||||
#include <FormatImpl.h>
|
||||
#include <FormatParameters.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <GenericNumberFormat.h>
|
||||
#include <IntegerFormat.h>
|
||||
#include <IntegerFormatImpl.h>
|
||||
|
||||
@@ -22,18 +22,9 @@ namespace icu_44 {
|
||||
}
|
||||
|
||||
|
||||
enum {
|
||||
B_METRIC = 0,
|
||||
B_US
|
||||
};
|
||||
|
||||
|
||||
class BCountry {
|
||||
public:
|
||||
BCountry(const char* languageCode,
|
||||
const char* countryCode);
|
||||
BCountry(const char* languageAndCountryCode
|
||||
= "en_US");
|
||||
BCountry(const char* countryCode = NULL);
|
||||
BCountry(const BCountry& other);
|
||||
BCountry& operator=(const BCountry& other);
|
||||
~BCountry();
|
||||
@@ -44,15 +35,12 @@ public:
|
||||
) const;
|
||||
|
||||
const char* Code() const;
|
||||
// ISO-3166
|
||||
status_t GetIcon(BBitmap* result) const;
|
||||
|
||||
const char* GetLocalizedString(uint32 id) const;
|
||||
|
||||
status_t GetAvailableTimeZones(
|
||||
BMessage* timeZones) const;
|
||||
|
||||
int8 Measurement() const;
|
||||
|
||||
class Private;
|
||||
private:
|
||||
friend class Private;
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2003-2010, Haiku, Inc.
|
||||
* Distributed under the terms of the MIT Licence.
|
||||
*/
|
||||
#ifndef _FORMATTING_CONVENTIONS_H_
|
||||
#define _FORMATTING_CONVENTIONS_H_
|
||||
|
||||
|
||||
#include <Archivable.h>
|
||||
#include <List.h>
|
||||
#include <LocaleStrings.h>
|
||||
#include <String.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
class BBitmap;
|
||||
class BLanguage;
|
||||
class BMessage;
|
||||
|
||||
namespace icu_44 {
|
||||
class DateFormat;
|
||||
class Locale;
|
||||
}
|
||||
|
||||
|
||||
enum BMeasurementKind {
|
||||
B_METRIC = 0,
|
||||
B_US
|
||||
};
|
||||
|
||||
|
||||
enum BDateFormatStyle {
|
||||
B_FULL_DATE_FORMAT = 0,
|
||||
B_LONG_DATE_FORMAT,
|
||||
B_MEDIUM_DATE_FORMAT,
|
||||
B_SHORT_DATE_FORMAT,
|
||||
|
||||
B_DATE_FORMAT_STYLE_COUNT
|
||||
};
|
||||
|
||||
|
||||
enum BTimeFormatStyle {
|
||||
B_FULL_TIME_FORMAT = 0,
|
||||
B_LONG_TIME_FORMAT,
|
||||
B_MEDIUM_TIME_FORMAT,
|
||||
B_SHORT_TIME_FORMAT,
|
||||
|
||||
B_TIME_FORMAT_STYLE_COUNT
|
||||
};
|
||||
|
||||
|
||||
class BFormattingConventions : public BArchivable {
|
||||
public:
|
||||
BFormattingConventions(const char* id = NULL);
|
||||
BFormattingConventions(
|
||||
const BFormattingConventions& other);
|
||||
BFormattingConventions(const BMessage* archive);
|
||||
|
||||
BFormattingConventions& operator=(
|
||||
const BFormattingConventions& other);
|
||||
|
||||
~BFormattingConventions();
|
||||
|
||||
bool operator==(
|
||||
const BFormattingConventions& other) const;
|
||||
bool operator!=(
|
||||
const BFormattingConventions& other) const;
|
||||
|
||||
const char* ID() const;
|
||||
const char* LanguageCode() const;
|
||||
const char* CountryCode() const;
|
||||
|
||||
status_t GetNativeName(BString& name) const;
|
||||
status_t GetName(BString& name,
|
||||
const BLanguage* displayLanguage = NULL
|
||||
) const;
|
||||
|
||||
const char* GetString(uint32 id) const;
|
||||
|
||||
status_t GetDateFormat(BDateFormatStyle style,
|
||||
BString& outFormat) const;
|
||||
status_t GetTimeFormat(BTimeFormatStyle style,
|
||||
BString& outFormat) const;
|
||||
status_t GetNumericFormat(BString& outFormat) const;
|
||||
status_t GetMonetaryFormat(BString& outFormat) const;
|
||||
|
||||
void SetExplicitDateFormat(BDateFormatStyle style,
|
||||
const BString& format);
|
||||
void SetExplicitTimeFormat(BTimeFormatStyle style,
|
||||
const BString& format);
|
||||
void SetExplicitNumericFormat(const BString& format);
|
||||
void SetExplicitMonetaryFormat(
|
||||
const BString& format);
|
||||
|
||||
BMeasurementKind MeasurementKind() const;
|
||||
|
||||
bool UseStringsFromPreferredLanguage() const;
|
||||
void SetUseStringsFromPreferredLanguage(bool value);
|
||||
|
||||
bool Use24HourClock() const;
|
||||
void SetExplicitUse24HourClock(bool value);
|
||||
void UnsetExplicitUse24HourClock();
|
||||
|
||||
virtual status_t Archive(BMessage* archive,
|
||||
bool deep = true) const;
|
||||
|
||||
class Private;
|
||||
private:
|
||||
friend class Private;
|
||||
|
||||
mutable BString fCachedDateFormats[B_DATE_FORMAT_STYLE_COUNT];
|
||||
mutable BString fCachedTimeFormats[B_TIME_FORMAT_STYLE_COUNT];
|
||||
mutable BString fCachedNumericFormat;
|
||||
mutable BString fCachedMonetaryFormat;
|
||||
mutable int8 fCachedUse24HourClock;
|
||||
|
||||
BString fExplicitDateFormats[B_DATE_FORMAT_STYLE_COUNT];
|
||||
BString fExplicitTimeFormats[B_TIME_FORMAT_STYLE_COUNT];
|
||||
BString fExplicitNumericFormat;
|
||||
BString fExplicitMonetaryFormat;
|
||||
int8 fExplicitUse24HourClock;
|
||||
|
||||
bool fUseStringsFromPreferredLanguage;
|
||||
|
||||
icu_44::Locale* fICULocale;
|
||||
};
|
||||
|
||||
|
||||
#endif /* _FORMATTING_CONVENTIONS_H_ */
|
||||
+45
-46
@@ -7,11 +7,16 @@
|
||||
|
||||
|
||||
#include <Collator.h>
|
||||
#include <Country.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <Language.h>
|
||||
#include <Locker.h>
|
||||
|
||||
|
||||
namespace icu_44 {
|
||||
class DateFormat;
|
||||
}
|
||||
|
||||
|
||||
class BCatalog;
|
||||
class BString;
|
||||
class BTimeZone;
|
||||
@@ -39,7 +44,8 @@ typedef enum {
|
||||
class BLocale {
|
||||
public:
|
||||
BLocale(const BLanguage* language = NULL,
|
||||
const BCountry* country = NULL);
|
||||
const BFormattingConventions* conventions
|
||||
= NULL);
|
||||
BLocale(const BLocale& other);
|
||||
~BLocale();
|
||||
|
||||
@@ -47,14 +53,14 @@ public:
|
||||
|
||||
status_t GetCollator(BCollator* collator) const;
|
||||
status_t GetLanguage(BLanguage* language) const;
|
||||
status_t GetCountry(BCountry* country) const;
|
||||
status_t GetFormattingConventions(
|
||||
BFormattingConventions* conventions) const;
|
||||
|
||||
void SetCountry(const BCountry& newCountry);
|
||||
void SetFormattingConventions(
|
||||
const BFormattingConventions& conventions);
|
||||
void SetCollator(const BCollator& newCollator);
|
||||
void SetLanguage(const BLanguage& newLanguage);
|
||||
|
||||
bool GetName(BString& name) const;
|
||||
|
||||
// see definitions in LocaleStrings.h
|
||||
const char* GetString(uint32 id) const;
|
||||
|
||||
@@ -62,29 +68,34 @@ public:
|
||||
char* fmt, ...) const;
|
||||
void FormatString(BString* buffer, char* fmt,
|
||||
...) const;
|
||||
status_t FormatDateTime(char* target, size_t maxSize,
|
||||
time_t time, bool longFormat) const;
|
||||
|
||||
// DateTime
|
||||
|
||||
// TODO: drop some of these once BDateTimeFormat
|
||||
// has been implemented!
|
||||
ssize_t FormatDateTime(char* target, size_t maxSize,
|
||||
time_t time, BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle) const;
|
||||
status_t FormatDateTime(BString* buffer, time_t time,
|
||||
bool longFormat,
|
||||
BDateFormatStyle dateStyle,
|
||||
BTimeFormatStyle timeStyle,
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
|
||||
// Date
|
||||
|
||||
// TODO: drop some of these once BDateFormat
|
||||
// has been implemented!
|
||||
status_t FormatDate(char* string, size_t maxSize,
|
||||
time_t time, bool longFormat) const;
|
||||
ssize_t FormatDate(char* string, size_t maxSize,
|
||||
time_t time, BDateFormatStyle style) const;
|
||||
status_t FormatDate(BString* string, time_t time,
|
||||
bool longFormat,
|
||||
BDateFormatStyle style,
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
status_t FormatDate(BString* string,
|
||||
int*& fieldPositions, int& fieldCount,
|
||||
time_t time, bool longFormat) const;
|
||||
time_t time, BDateFormatStyle style) const;
|
||||
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& fieldCount, BDateFormatStyle style
|
||||
) const;
|
||||
|
||||
int StartOfWeek() const;
|
||||
|
||||
@@ -92,29 +103,25 @@ public:
|
||||
|
||||
// TODO: drop some of these once BTimeFormat
|
||||
// has been implemented!
|
||||
status_t FormatTime(char* string, size_t maxSize,
|
||||
time_t time, bool longFormat) const;
|
||||
ssize_t FormatTime(char* string, size_t maxSize,
|
||||
time_t time, BTimeFormatStyle style) const;
|
||||
status_t FormatTime(BString* string, time_t time,
|
||||
bool longFormat,
|
||||
BTimeFormatStyle style,
|
||||
const BTimeZone* timeZone = NULL) const;
|
||||
status_t FormatTime(BString* string,
|
||||
int*& fieldPositions, int& fieldCount,
|
||||
time_t time, bool longFormat) const;
|
||||
time_t time, BTimeFormatStyle style) const;
|
||||
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;
|
||||
int& fieldCount, BTimeFormatStyle style
|
||||
) const;
|
||||
|
||||
// numbers
|
||||
|
||||
status_t FormatNumber(char* string, size_t maxSize,
|
||||
ssize_t FormatNumber(char* string, size_t maxSize,
|
||||
double value) const;
|
||||
status_t FormatNumber(BString* string,
|
||||
double value) const;
|
||||
status_t FormatNumber(char* string, size_t maxSize,
|
||||
ssize_t FormatNumber(char* string, size_t maxSize,
|
||||
int32 value) const;
|
||||
status_t FormatNumber(BString* string,
|
||||
int32 value) const;
|
||||
@@ -123,13 +130,8 @@ public:
|
||||
|
||||
ssize_t FormatMonetary(char* string, size_t maxSize,
|
||||
double value) const;
|
||||
ssize_t FormatMonetary(BString* string,
|
||||
double value) const;
|
||||
status_t FormatMonetary(BString* string,
|
||||
int*& fieldPositions,
|
||||
BNumberElement*& fieldTypes,
|
||||
int& fieldCount, double value) const;
|
||||
status_t GetCurrencySymbol(BString& result) const;
|
||||
double value) const;
|
||||
|
||||
// Collator short-hands
|
||||
int StringCompare(const char* s1,
|
||||
@@ -138,21 +140,18 @@ public:
|
||||
const BString* s2) const;
|
||||
|
||||
void GetSortKey(const char* string,
|
||||
BString* key) const;
|
||||
BString* sortKey) const;
|
||||
|
||||
private:
|
||||
void _UpdateFormats();
|
||||
icu_44::DateFormat* _CreateDateFormatter(
|
||||
const BString& format) const;
|
||||
icu_44::DateFormat* _CreateTimeFormatter(
|
||||
const BString& format) const;
|
||||
|
||||
mutable BLocker fLock;
|
||||
BCollator fCollator;
|
||||
BCountry fCountry;
|
||||
BFormattingConventions fConventions;
|
||||
BLanguage fLanguage;
|
||||
|
||||
BString fLongDateFormat;
|
||||
BString fShortDateFormat;
|
||||
BString fLongTimeFormat;
|
||||
BString fShortTimeFormat;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -178,9 +177,9 @@ BLocale::StringCompare(const BString* s1, const BString* s2) const
|
||||
|
||||
|
||||
inline void
|
||||
BLocale::GetSortKey(const char* string, BString* key) const
|
||||
BLocale::GetSortKey(const char* string, BString* sortKey) const
|
||||
{
|
||||
fCollator.GetSortKey(string, key);
|
||||
fCollator.GetSortKey(string, sortKey);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ class BBitmap;
|
||||
class BCatalog;
|
||||
class BCollator;
|
||||
class BCountry;
|
||||
class BFormattingConventions;
|
||||
class BLanguage;
|
||||
class BLocale;
|
||||
class BMessage;
|
||||
@@ -37,7 +38,6 @@ public:
|
||||
status_t GetPreferredLanguages(BMessage* message) const;
|
||||
|
||||
status_t GetAvailableLanguages(BMessage* message) const;
|
||||
|
||||
status_t GetAvailableCountries(
|
||||
BMessage* timeZones) const;
|
||||
status_t GetAvailableTimeZones(
|
||||
@@ -49,7 +49,7 @@ public:
|
||||
status_t GetFlagIconForCountry(BBitmap* flagIcon,
|
||||
const char* countryCode);
|
||||
|
||||
status_t GetInstalledCatalogs(BMessage* message,
|
||||
status_t GetAvailableCatalogs(BMessage* message,
|
||||
const char* sigPattern = NULL,
|
||||
const char* langPattern = NULL,
|
||||
int32 fingerprint = 0) const;
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010, Oliver Tappe <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _COUNTRY_PRIVATE_H
|
||||
#define _COUNTRY_PRIVATE_H
|
||||
|
||||
|
||||
#include <Country.h>
|
||||
|
||||
|
||||
class BCountry::Private {
|
||||
public:
|
||||
Private(const BCountry* country = NULL)
|
||||
:
|
||||
fCountry(country)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SetTo(const BCountry* country)
|
||||
{
|
||||
fCountry = country;
|
||||
}
|
||||
|
||||
icu_44::Locale*
|
||||
ICULocale()
|
||||
{
|
||||
return fCountry->fICULocale;
|
||||
}
|
||||
|
||||
private:
|
||||
const BCountry* fCountry;
|
||||
};
|
||||
|
||||
|
||||
#endif // _COUNTRY_PRIVATE_H
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010, Oliver Tappe <[email protected]>
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _FORMATTING_CONVENTIONS_PRIVATE_H
|
||||
#define _FORMATTING_CONVENTIONS_PRIVATE_H
|
||||
|
||||
|
||||
#include <FormattingConventions.h>
|
||||
|
||||
|
||||
class BFormattingConventions::Private {
|
||||
public:
|
||||
Private(const BFormattingConventions* conventions = NULL)
|
||||
:
|
||||
fFormattingConventions(conventions)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
SetTo(const BFormattingConventions* conventions)
|
||||
{
|
||||
fFormattingConventions = conventions;
|
||||
}
|
||||
|
||||
icu_44::Locale*
|
||||
ICULocale()
|
||||
{
|
||||
return fFormattingConventions->fICULocale;
|
||||
}
|
||||
|
||||
private:
|
||||
const BFormattingConventions* fFormattingConventions;
|
||||
};
|
||||
|
||||
|
||||
#endif // _FORMATTING_CONVENTIONS_PRIVATE_H
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
#include <Collator.h>
|
||||
#include <Country.h>
|
||||
#include <FormattingConventions.h>
|
||||
#include <image.h>
|
||||
#include <Language.h>
|
||||
#include <List.h>
|
||||
@@ -34,10 +34,8 @@ public:
|
||||
MutableLocaleRoster();
|
||||
~MutableLocaleRoster();
|
||||
|
||||
status_t GetDefaultLocale(BLocale* locale) const;
|
||||
|
||||
status_t SetDefaultCountry(const BCountry& country);
|
||||
status_t SetDefaultLocale(const BLocale& locale);
|
||||
status_t SetDefaultFormattingConventions(
|
||||
const BFormattingConventions& conventions);
|
||||
status_t SetDefaultTimeZone(const BTimeZone& zone);
|
||||
|
||||
status_t SetPreferredLanguages(const BMessage* message);
|
||||
@@ -127,8 +125,8 @@ struct RosterData {
|
||||
static int CompareInfos(const void* left,
|
||||
const void* right);
|
||||
|
||||
status_t SetDefaultCountry(const BCountry& country);
|
||||
status_t SetDefaultLocale(const BLocale& locale);
|
||||
status_t SetDefaultFormattingConventions(
|
||||
const BFormattingConventions& convetions);
|
||||
status_t SetDefaultTimeZone(const BTimeZone& zone);
|
||||
status_t SetPreferredLanguages(const BMessage* msg);
|
||||
private:
|
||||
@@ -138,12 +136,12 @@ private:
|
||||
status_t _LoadTimeSettings();
|
||||
status_t _SaveTimeSettings();
|
||||
|
||||
status_t _SetDefaultCountry(const BCountry& country);
|
||||
status_t _SetDefaultLocale(const BLocale& locale);
|
||||
status_t _SetDefaultFormattingConventions(
|
||||
const BFormattingConventions& conventions);
|
||||
status_t _SetDefaultTimeZone(const BTimeZone& zone);
|
||||
status_t _SetPreferredLanguages(const BMessage* msg);
|
||||
|
||||
status_t _AddDefaultCountryToMessage(
|
||||
status_t _AddDefaultFormattingConventionsToMessage(
|
||||
BMessage* message) const;
|
||||
status_t _AddDefaultTimeZoneToMessage(
|
||||
BMessage* message) const;
|
||||
|
||||
Reference in New Issue
Block a user