summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qlocale.cpp
diff options
context:
space:
mode:
authordka <darpan.k-a@nokia.com>2009-10-12 13:25:23 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-12-15 09:36:33 (GMT)
commit44f7c1e097582a704a06ccbbf516536b88ddcd3a (patch)
tree1444e29341ecd5d02d78ee66bd056f432680fed0 /src/corelib/tools/qlocale.cpp
parent1f4a4cca0067b1d4a9784f00e41c3fc1aca1f712 (diff)
downloadQt-44f7c1e097582a704a06ccbbf516536b88ddcd3a.zip
Qt-44f7c1e097582a704a06ccbbf516536b88ddcd3a.tar.gz
Qt-44f7c1e097582a704a06ccbbf516536b88ddcd3a.tar.bz2
Changes to support locale change event for symbian platform
Subscribing to the locale change notification to be able to update the system locale whenever the user changes the current system locale. Also changed the initialization of the system locale to make construction of the QLocale object as lightweight as possible. So now the default contructor just creates a QLocale and QSystemLocale objects, but doesn't try to fill the cache in the latter with data from the system and postpones it until it is actually requested (most applications create QLocale objects on the stack and might not even use the data from the system locale, so we don't need to initialize system locale right away). Modified-by: axis Modified-by: Denis Dzyubenko Reviewed-by: Denis Dzyubenko Reviewed-by: axis
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r--src/corelib/tools/qlocale.cpp43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
index 4a66b92..22114c2 100644
--- a/src/corelib/tools/qlocale.cpp
+++ b/src/corelib/tools/qlocale.cpp
@@ -129,6 +129,10 @@ inline bool isascii(int c)
}
#endif
+#if defined(Q_OS_SYMBIAN)
+void symbianUpdateSystemPrivate();
+#endif
+
/******************************************************************************
** Helpers for accessing Qt locale database
*/
@@ -1388,7 +1392,8 @@ QSystemLocale::QSystemLocale()
/*! \internal */
QSystemLocale::QSystemLocale(bool)
-{ }
+{
+}
/*!
Deletes the object.
@@ -1407,16 +1412,29 @@ static const QSystemLocale *systemLocale()
{
if (_systemLocale)
return _systemLocale;
+#if defined(Q_OS_SYMBIAN)
+ symbianInitSystemLocale();
+#endif
return QSystemLocale_globalSystemLocale();
}
-void QLocalePrivate::updateSystemPrivate()
+void QLocalePrivate::updateSystemPrivate(bool initialize)
{
const QSystemLocale *sys_locale = systemLocale();
if (!system_lp)
system_lp = globalLocalePrivate();
*system_lp = *sys_locale->fallbackLocale().d();
+ system_lp->m_language_id = 0;
+#if defined(Q_OS_SYMBIAN)
+ RDebug::Print(_L("updateSystemPrivate"));
+#endif
+ if (!initialize)
+ return;
+
+#if defined(Q_OS_SYMBIAN)
+ symbianUpdateSystemPrivate();
+#endif
QVariant res = sys_locale->query(QSystemLocale::LanguageId, QVariant());
if (!res.isNull())
system_lp->m_language_id = res.toInt();
@@ -1446,12 +1464,12 @@ void QLocalePrivate::updateSystemPrivate()
}
#endif
-static const QLocalePrivate *systemPrivate()
+static const QLocalePrivate *systemPrivate(bool initialize = true)
{
#ifndef QT_NO_SYSTEMLOCALE
// copy over the information from the fallback locale and modify
if (!system_lp || system_lp->m_language_id == 0)
- QLocalePrivate::updateSystemPrivate();
+ QLocalePrivate::updateSystemPrivate(initialize);
return system_lp;
#else
@@ -1459,10 +1477,10 @@ static const QLocalePrivate *systemPrivate()
#endif
}
-static const QLocalePrivate *defaultPrivate()
+static const QLocalePrivate *defaultPrivate(bool initialize = true)
{
if (!default_lp)
- default_lp = systemPrivate();
+ default_lp = systemPrivate(initialize);
return default_lp;
}
@@ -2169,7 +2187,7 @@ QLocale::QLocale()
: v(0)
{
p.numberOptions = default_number_options;
- p.index = localePrivateIndex(defaultPrivate());
+ p.index = localePrivateIndex(defaultPrivate(false));
}
/*!
@@ -2199,7 +2217,7 @@ QLocale::QLocale(Language language, Country country)
// If not found, should default to system
if (d->languageId() == QLocale::C && language != QLocale::C) {
p.numberOptions = default_number_options;
- p.index = localePrivateIndex(defaultPrivate());
+ p.index = localePrivateIndex(defaultPrivate(false));
} else {
p.numberOptions = 0;
p.index = localePrivateIndex(d);
@@ -2283,6 +2301,7 @@ void QLocale::setDefault(const QLocale &locale)
*/
QLocale::Language QLocale::language() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return Language(d()->languageId());
}
@@ -2293,6 +2312,7 @@ QLocale::Language QLocale::language() const
*/
QLocale::Country QLocale::country() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return Country(d()->countryId());
}
@@ -3021,6 +3041,7 @@ QDateTime QLocale::toDateTime(const QString &string, const QString &format) cons
*/
QChar QLocale::decimalPoint() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return d()->decimal();
}
@@ -3031,6 +3052,7 @@ QChar QLocale::decimalPoint() const
*/
QChar QLocale::groupSeparator() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return d()->group();
}
@@ -3041,6 +3063,7 @@ QChar QLocale::groupSeparator() const
*/
QChar QLocale::percent() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return d()->percent();
}
@@ -3051,6 +3074,7 @@ QChar QLocale::percent() const
*/
QChar QLocale::zeroDigit() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return d()->zero();
}
@@ -3061,6 +3085,7 @@ QChar QLocale::zeroDigit() const
*/
QChar QLocale::negativeSign() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return d()->minus();
}
@@ -3071,6 +3096,7 @@ QChar QLocale::negativeSign() const
*/
QChar QLocale::positiveSign() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return d()->plus();
}
@@ -3081,6 +3107,7 @@ QChar QLocale::positiveSign() const
*/
QChar QLocale::exponential() const
{
+ systemPrivate(); // make sure inline data is initialized from the system.
return d()->exponential();
}