summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcon <qtc-committer@nokia.com>2009-09-14 12:59:45 (GMT)
committercon <qtc-committer@nokia.com>2009-09-14 13:03:24 (GMT)
commitadb6eea3a135707a220c0b1c1cf8266321af9309 (patch)
treee4f639fc4b95aff56fd5b454756ed18e551968b6
parentc72eaee91136bbe1a9fa99cdb0a7593bec60264b (diff)
downloadQt-adb6eea3a135707a220c0b1c1cf8266321af9309.zip
Qt-adb6eea3a135707a220c0b1c1cf8266321af9309.tar.gz
Qt-adb6eea3a135707a220c0b1c1cf8266321af9309.tar.bz2
System locale on Mac returns preferred language/country from sys prefs.
Previously it always returned the C locale's language, which is of not much help for an application. Reviewed-by: Morten Sorvig <msorvig@trolltech.com>
-rw-r--r--src/corelib/tools/qlocale.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 619c08c..a1f0712 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -125,7 +125,7 @@ static qulonglong qstrtoull(const char *nptr, const char **endptr, register int
#if defined(Q_CC_MWERKS) && defined(Q_OS_WIN32)
inline bool isascii(int c)
{
- return (c >= 0 && c <=127);
+ return (c >= 0 && c <=127);
}
#endif
@@ -1149,6 +1149,23 @@ static QLocale::MeasurementSystem macMeasurementSystem()
}
}
+static void getMacPreferredLanguageAndCountry(QString *language, QString *country)
+{
+ QCFType<CFArrayRef> languages = (CFArrayRef)CFPreferencesCopyValue(
+ CFSTR("AppleLanguages"),
+ kCFPreferencesAnyApplication,
+ kCFPreferencesCurrentUser,
+ kCFPreferencesAnyHost);
+ if (CFArrayGetCount(languages) > 0) {
+ QCFType<CFLocaleRef> locale = CFLocaleCreate(kCFAllocatorDefault,
+ CFStringRef(CFArrayGetValueAtIndex(languages, 0)));
+ if (language)
+ *language = QCFString::toQString(CFStringRef(CFLocaleGetValue(locale, kCFLocaleLanguageCode)));
+ if (country)
+ *country = QCFString::toQString(CFStringRef(CFLocaleGetValue(locale, kCFLocaleCountryCode)));
+ }
+}
+
QLocale QSystemLocale::fallbackLocale() const
{
return QLocale(QString::fromUtf8(getMacLocaleName().constData()));
@@ -1193,9 +1210,16 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const
case NegativeSign:
case PositiveSign:
case ZeroDigit:
- case LanguageId:
- case CountryId:
break;
+ case LanguageId:
+ case CountryId: {
+ QString preferredLanguage;
+ QString preferredCountry;
+ getMacPreferredLanguageAndCountry(&preferredLanguage, &preferredCountry);
+ if (type == LanguageId)
+ return codeToLanguage(preferredLanguage.data());
+ return codeToCountry(preferredCountry.data());
+ }
case MeasurementSystem:
return QVariant(static_cast<int>(macMeasurementSystem()));
@@ -7181,8 +7205,8 @@ Q_CORE_EXPORT double qstrtod(const char *s00, const char **se, bool *ok)
double ret = strtod((char*)s00, (char**)se);
if (ok) {
if((ret == 0.0l && errno == ERANGE)
- || ret == HUGE_VAL || ret == -HUGE_VAL)
- *ok = false;
+ || ret == HUGE_VAL || ret == -HUGE_VAL)
+ *ok = false;
else
*ok = true; // the result will be that we don't report underflow in this case
}