[haiku-commits] haiku: hrev47932 - src/kits/locale headers/os/locale

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 30 Sep 2014 11:53:40 +0200 (CEST)

hrev47932 adds 1 changeset to branch 'master'
old head: f188c1defa3ffef28c2a76b1b21fa7dc017f3e5b
new head: 526d4839991d4dcbb0dc361e7a9f6721481a3ebe
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=526d483+%5Ef188c1d

----------------------------------------------------------------------------

526d483: Make BDateFormat mutable
  
  * Add setters for the language and formatting conventions
  * Add shortcut getter and setter for the date format
  * Use those in the locale roster to make the BDateFormat actually use
  the system preferred language and format.
  * Applications can also use this to extract specific information from
  the system format (eg. set date format to "LLLL" to extract month
  names), or define specific formats more easily (eg. for parsing and
  generating e-mail headers or HTTP cookies).

                                 [ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev47932
Commit:      526d4839991d4dcbb0dc361e7a9f6721481a3ebe
URL:         http://cgit.haiku-os.org/haiku/commit/?id=526d483
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Tue Sep 30 09:49:47 2014 UTC

----------------------------------------------------------------------------

3 files changed, 52 insertions(+)
headers/os/locale/DateFormat.h       |  8 +++++++
src/kits/locale/DateFormat.cpp       | 39 ++++++++++++++++++++++++++++++++
src/kits/locale/LocaleRosterData.cpp |  5 ++++

----------------------------------------------------------------------------

diff --git a/headers/os/locale/DateFormat.h b/headers/os/locale/DateFormat.h
index ec11d7f..d0b1325 100644
--- a/headers/os/locale/DateFormat.h
+++ b/headers/os/locale/DateFormat.h
@@ -37,6 +37,14 @@ public:
 
        static  const BDateFormat*      Default();
 
+                       void                            SetLanguage(const 
BLanguage& newLanguage);
+                       void                            
SetFormattingConventions(
+                                                                       const 
BFormattingConventions& conventions);
+                       status_t                        
GetDateFormat(BDateFormatStyle style,
+                                                                       
BString& outFormat) const;
+                       void                            
SetDateFormat(BDateFormatStyle style,
+                                                                       const 
BString& format);
+
                                                                // formatting
 
                        ssize_t                         Format(char* string, 
const size_t maxSize,
diff --git a/src/kits/locale/DateFormat.cpp b/src/kits/locale/DateFormat.cpp
index 8521a42..bf1542f 100644
--- a/src/kits/locale/DateFormat.cpp
+++ b/src/kits/locale/DateFormat.cpp
@@ -4,6 +4,7 @@
  *
  * Authors:
  *             Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
+ *             Adrien Desutugues <pulkomandy@xxxxxxxxxxxxx>
  */
 
 #include <DateFormat.h>
@@ -58,6 +59,44 @@ BDateFormat::~BDateFormat()
 }
 
 
+void
+BDateFormat::SetFormattingConventions(const BFormattingConventions& 
conventions)
+{
+       BAutolock lock(fLock);
+       if (!lock.IsLocked())
+               return;
+
+       fConventions = conventions;
+}
+
+
+void
+BDateFormat::SetLanguage(const BLanguage& newLanguage)
+{
+       BAutolock lock(fLock);
+       if (!lock.IsLocked())
+               return;
+
+       fLanguage = newLanguage;
+}
+
+
+status_t
+BDateFormat::GetDateFormat(BDateFormatStyle style,
+       BString& outFormat) const
+{
+       return fConventions.GetDateFormat(style, outFormat);
+}
+
+
+void
+BDateFormat::SetDateFormat(BDateFormatStyle style,
+       const BString& format)
+{
+       fConventions.SetExplicitDateFormat(style, format);
+}
+
+
 ssize_t
 BDateFormat::Format(char* string, const size_t maxSize, const time_t time,
        const BDateFormatStyle style) const
diff --git a/src/kits/locale/LocaleRosterData.cpp 
b/src/kits/locale/LocaleRosterData.cpp
index 7aa72e2..a632540 100644
--- a/src/kits/locale/LocaleRosterData.cpp
+++ b/src/kits/locale/LocaleRosterData.cpp
@@ -467,6 +467,7 @@ LocaleRosterData::_LoadLocaleSettings()
        if (status == B_OK) {
                BFormattingConventions conventions(&settings);
                fDefaultLocale.SetFormattingConventions(conventions);
+               fDefaultDateFormat.SetFormattingConventions(conventions);
 
                _SetPreferredLanguages(&settings);
 
@@ -485,8 +486,10 @@ LocaleRosterData::_LoadLocaleSettings()
        fPreferredLanguages.AddString(kLanguageField, "en");
        BLanguage defaultLanguage("en_US");
        fDefaultLocale.SetLanguage(defaultLanguage);
+       fDefaultDateFormat.SetLanguage(defaultLanguage);
        BFormattingConventions conventions("en_US");
        fDefaultLocale.SetFormattingConventions(conventions);
+       fDefaultDateFormat.SetFormattingConventions(conventions);
 
        return status;
 }
@@ -582,6 +585,7 @@ LocaleRosterData::_SetDefaultFormattingConventions(
        const BFormattingConventions& newFormattingConventions)
 {
        fDefaultLocale.SetFormattingConventions(newFormattingConventions);
+       fDefaultDateFormat.SetFormattingConventions(newFormattingConventions);
 
        UErrorCode icuError = U_ZERO_ERROR;
        Locale icuLocale = 
Locale::createCanonical(newFormattingConventions.ID());
@@ -618,6 +622,7 @@ LocaleRosterData::_SetPreferredLanguages(const BMessage* 
languages)
                && languages->FindString(kLanguageField, &langName) == B_OK) {
                fDefaultLocale.SetCollator(BCollator(langName.String()));
                fDefaultLocale.SetLanguage(BLanguage(langName.String()));
+               fDefaultDateFormat.SetLanguage(BLanguage(langName.String()));
 
                fPreferredLanguages.RemoveName(kLanguageField);
                for (int i = 0; languages->FindString(kLanguageField, i, 
&langName)


Other related posts:

  • » [haiku-commits] haiku: hrev47932 - src/kits/locale headers/os/locale - pulkomandy