[haiku-commits] r37628 - in haiku/trunk/src: kits/locale preferences/locale

  • From: pulkomandy@xxxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 20 Jul 2010 19:44:14 +0200 (CEST)

Author: pulkomandy
Date: 2010-07-20 19:44:14 +0200 (Tue, 20 Jul 2010)
New Revision: 37628
Changeset: http://dev.haiku-os.org/changeset/37628

Modified:
   haiku/trunk/src/kits/locale/LocaleRoster.cpp
   haiku/trunk/src/preferences/locale/TimeFormatSettingsView.cpp
   haiku/trunk/src/preferences/locale/TimeFormatSettingsView.h
Log:
Locale preflet : make the 12/24hr switching system more robust and lossless
 * When selecting chinese, the AM/PM stays at the beginning of the string
 * When clicking multiple times on the 12 hours button, the AM/PM indicator is 
added only once.
 * Only regression : the default format for cherokee (US) uses a 12hour clock 
without AM/PM indicator, so it is not possible 
to switch it to a 24Hr clock scheme.


Modified: haiku/trunk/src/kits/locale/LocaleRoster.cpp
===================================================================
--- haiku/trunk/src/kits/locale/LocaleRoster.cpp        2010-07-20 17:22:02 UTC 
(rev 37627)
+++ haiku/trunk/src/kits/locale/LocaleRoster.cpp        2010-07-20 17:44:14 UTC 
(rev 37628)
@@ -617,8 +617,8 @@
 
 
 status_t
-BLocaleRoster::GetInstalledCatalogs(BMessage * languageList, const char* 
sigPattern,
-       const char* langPattern, int32 fingerprint) const
+BLocaleRoster::GetInstalledCatalogs(BMessage * languageList,
+       const char* sigPattern, const char* langPattern, int32 fingerprint) 
const
 {
        if (languageList == NULL)
                return B_BAD_VALUE;

Modified: haiku/trunk/src/preferences/locale/TimeFormatSettingsView.cpp
===================================================================
--- haiku/trunk/src/preferences/locale/TimeFormatSettingsView.cpp       
2010-07-20 17:22:02 UTC (rev 37627)
+++ haiku/trunk/src/preferences/locale/TimeFormatSettingsView.cpp       
2010-07-20 17:44:14 UTC (rev 37628)
@@ -30,7 +30,9 @@
 #include <TextControl.h>
 #include <Window.h>
 
+#include <iostream.h>
 
+
 #undef B_TRANSLATE_CONTEXT
 #define B_TRANSLATE_CONTEXT "TimeFormatSettings"
 
@@ -181,12 +183,15 @@
        f12HrRadioButton = new BRadioButton("", B_TRANSLATE("12 hour"),
                new BMessage(kClockFormatChange));
 
-       BString timeFormat;
-       fCountry->TimeFormat(timeFormat, false);
-       if (timeFormat.FindFirst("a") != B_ERROR)
-               f12HrRadioButton->SetValue(1);
-       else
-               f24HrRadioButton->SetValue(1);
+       fCountry->TimeFormat(fOriginalTimeFormat, false);
+       fCountry->TimeFormat(fOriginalLongTimeFormat, true);
+       if (fOriginalTimeFormat.FindFirst("a") != B_ERROR) {
+               f12HrRadioButton->SetValue(B_CONTROL_ON);
+               fCountryIs24Hr = false;
+       } else {
+               f24HrRadioButton->SetValue(B_CONTROL_ON);
+               fCountryIs24Hr = true;
+       }
 
        float spacing = be_control_look->DefaultItemSpacing();
 
@@ -376,11 +381,11 @@
                {
                        // Update one of the dropdown menus
                        void* pointerFromMessage;
-                       message->FindPointer("dest",&pointerFromMessage);
+                       message->FindPointer("dest", &pointerFromMessage);
                        BMenuField* menuField
                        = static_cast<BMenuField*>(pointerFromMessage);
                        BString format;
-                       message->FindString("format",&format);
+                       message->FindString("format", &format);
 
                        for (int i = 0; i < 4; i++) {
                                if (fLongDateMenu[i]==menuField) {
@@ -437,30 +442,37 @@
                case kClockFormatChange:
                {
                        BString timeFormat;
-                       fCountry->TimeFormat(timeFormat, false);
+                       timeFormat = fOriginalTimeFormat;
                        if (f24HrRadioButton->Value() == 1) {
-                               timeFormat.ReplaceAll("k", "h");
-                               timeFormat.ReplaceAll("K", "H");
-                               timeFormat.RemoveAll(" a");
+                               if (!fCountryIs24Hr) {
+                                       timeFormat.ReplaceAll("h", "H");
+                                       timeFormat.ReplaceAll("k", "K");
+                                       timeFormat.RemoveAll(" a");
+                                       timeFormat.RemoveAll("a");
+                               }
                        } else {
-                               timeFormat.ReplaceAll("h", "k");
-                               timeFormat.ReplaceAll("H", "K");
-                               timeFormat.Append(" a");
-                               f12HrRadioButton->SetValue(true);
+                               if (fCountryIs24Hr && timeFormat.FindFirst("a") 
== B_ERROR) {
+                                       timeFormat.ReplaceAll("K", "k");
+                                       timeFormat.ReplaceAll("H", "h");
+                                       timeFormat.Append(" a");
+                               }
                        }
                        fCountry->SetTimeFormat(timeFormat.String(), false);
 
-                       timeFormat.Truncate(0);
-
-                       fCountry->TimeFormat(timeFormat, true);
+                       timeFormat = fOriginalLongTimeFormat;
                        if (f24HrRadioButton->Value() == 1) {
-                               timeFormat.ReplaceAll("k", "h");
-                               timeFormat.ReplaceAll("K", "H");
-                               timeFormat.RemoveAll(" a");
+                               if (!fCountryIs24Hr) {
+                                       timeFormat.ReplaceAll("h", "H");
+                                       timeFormat.ReplaceAll("k", "K");
+                                       timeFormat.RemoveAll(" a");
+                                       timeFormat.RemoveAll("a");
+                               }
                        } else {
-                               timeFormat.ReplaceAll("h", "k");
-                               timeFormat.ReplaceAll("H", "K");
-                               timeFormat.Append(" a");
+                               if (fCountryIs24Hr && timeFormat.FindFirst("a") 
== B_ERROR) {
+                                       timeFormat.ReplaceAll("K", "k");
+                                       timeFormat.ReplaceAll("H", "h");
+                                       timeFormat.Append(" a");
+                               }
                        }
                        fCountry->SetTimeFormat(timeFormat.String(), true);
                        _UpdateExamples();
@@ -528,13 +540,19 @@
        delete fCountry;
        fCountry = country;
 
-       BString timeFormat;
-       fCountry->TimeFormat(timeFormat, false);
-       if (timeFormat.FindFirst("a") != B_ERROR)
-               f12HrRadioButton->SetValue(1);
-       else
-               f24HrRadioButton->SetValue(1);
+       fOriginalTimeFormat.Truncate(0);
+       fCountry->TimeFormat(fOriginalTimeFormat, false);
+       fOriginalLongTimeFormat.Truncate(0);
+       fCountry->TimeFormat(fOriginalLongTimeFormat, true);
 
+       if (fOriginalTimeFormat.FindFirst("a") != B_ERROR) {
+               f12HrRadioButton->SetValue(B_CONTROL_ON);
+               fCountryIs24Hr = false;
+       } else {
+               f24HrRadioButton->SetValue(B_CONTROL_ON);
+               fCountryIs24Hr = true;
+       }
+
        /*
        FormatSeparator separator = settings.TimeFormatSeparator();
 

Modified: haiku/trunk/src/preferences/locale/TimeFormatSettingsView.h
===================================================================
--- haiku/trunk/src/preferences/locale/TimeFormatSettingsView.h 2010-07-20 
17:22:02 UTC (rev 37627)
+++ haiku/trunk/src/preferences/locale/TimeFormatSettingsView.h 2010-07-20 
17:44:14 UTC (rev 37628)
@@ -77,6 +77,10 @@
                        FormatSeparator         fSeparator;
                        BString                         fDateFormat;
 
+                       BString                         fOriginalTimeFormat;
+                       BString                         fOriginalLongTimeFormat;
+                       bool                            fCountryIs24Hr;
+
                        BCountry*                       fCountry;
 
                        BBox*                           fDateBox;


Other related posts:

  • » [haiku-commits] r37628 - in haiku/trunk/src: kits/locale preferences/locale - pulkomandy