From 25c4ce6deef20c69d00fe1197a60e8b7587c81cb Mon Sep 17 00:00:00 2001 From: Nick Ratelle Date: Tue, 17 Jan 2012 18:05:54 -0500 Subject: Support changing locales at runtime in QPA plugins. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id65798b81db2fa9fb5b1d929e4a94103995c6707 Reviewed-by: Jørgen Lind --- src/corelib/tools/qlocale_unix.cpp | 35 +++++++++++++++++++++++++-- src/gui/kernel/qapplication_p.h | 2 +- src/gui/kernel/qapplication_qpa.cpp | 8 ++++++ src/gui/kernel/qwindowsysteminterface_qpa.cpp | 11 +++++++++ src/gui/kernel/qwindowsysteminterface_qpa.h | 2 ++ src/gui/kernel/qwindowsysteminterface_qpa_p.h | 10 +++++++- 6 files changed, 64 insertions(+), 4 deletions(-) diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp index 5839a80..dd99792 100644 --- a/src/corelib/tools/qlocale_unix.cpp +++ b/src/corelib/tools/qlocale_unix.cpp @@ -46,8 +46,28 @@ #include "qstringlist.h" #include "qvariant.h" +#if defined(Q_OS_QNX) +#include +#endif + QT_BEGIN_NAMESPACE +static const char *getSystemLocale() +{ +#if defined(Q_OS_QNX) + static char buff[257]; + + memset(buff, 0, sizeof buff); + + if (confstr(_CS_LOCALE, buff, 257) > 0) + return buff; + else + return qgetenv("LC_ALL"); +#else + return qgetenv("LC_ALL"); +#endif +} + #ifndef QT_NO_SYSTEMLOCALE struct QSystemLocaleData { @@ -57,12 +77,18 @@ struct QSystemLocaleData ,lc_monetary(QLocale::C) ,lc_messages(QLocale::C) { - QByteArray all = qgetenv("LC_ALL"); + updateLocale(); + } + + void updateLocale() + { + QByteArray all = getSystemLocale(); QByteArray numeric = all.isEmpty() ? qgetenv("LC_NUMERIC") : all; QByteArray time = all.isEmpty() ? qgetenv("LC_TIME") : all; QByteArray monetary = all.isEmpty() ? qgetenv("LC_MONETARY") : all; lc_messages_var = all.isEmpty() ? qgetenv("LC_MESSAGES") : all; lc_measurement_var = all.isEmpty() ? qgetenv("LC_MEASUREMENT") : all; + QByteArray lang = qgetenv("LANG"); if (lang.isEmpty()) lang = QByteArray("C"); @@ -93,7 +119,9 @@ Q_GLOBAL_STATIC(QSystemLocaleData, qSystemLocaleData) #ifndef QT_NO_SYSTEMLOCALE QLocale QSystemLocale::fallbackLocale() const { - QByteArray lang = qgetenv("LC_ALL"); + + QByteArray lang = getSystemLocale(); + if (lang.isEmpty()) lang = qgetenv("LC_NUMERIC"); if (lang.isEmpty()) @@ -216,6 +244,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const return lc_messages.quoteString(in.value(), QLocale::AlternateQuotation); case ListToSeparatedString: return lc_messages.createSeparatedList(in.value()); + case LocaleChanged: + d->updateLocale(); + break; default: break; } diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h index 31d0b75..74b0ee5 100644 --- a/src/gui/kernel/qapplication_p.h +++ b/src/gui/kernel/qapplication_p.h @@ -507,7 +507,7 @@ public: static void reportGeometryChange(QWindowSystemInterfacePrivate::ScreenGeometryEvent *e); // static void reportAvailableGeometryChange(int screenIndex); static void reportAvailableGeometryChange(QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *e); - + static void reportLocaleChange(); #endif #ifdef Q_WS_QWS diff --git a/src/gui/kernel/qapplication_qpa.cpp b/src/gui/kernel/qapplication_qpa.cpp index 6b00258..242b5ef 100644 --- a/src/gui/kernel/qapplication_qpa.cpp +++ b/src/gui/kernel/qapplication_qpa.cpp @@ -130,6 +130,9 @@ void QApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePrivate QApplicationPrivate::reportAvailableGeometryChange( static_cast(e)); break; + case QWindowSystemInterfacePrivate::LocaleChange: + QApplicationPrivate::reportLocaleChange(); + break; default: qWarning() << "Unknown user input event type:" << e->type; break; @@ -981,4 +984,9 @@ void QApplicationPrivate::reportAvailableGeometryChange( } } +void QApplicationPrivate::reportLocaleChange() +{ + QApplication::sendSpontaneousEvent( qApp, new QEvent( QEvent::LocaleChange ) ); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.cpp b/src/gui/kernel/qwindowsysteminterface_qpa.cpp index 97e4e65..24fc664 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.cpp +++ b/src/gui/kernel/qwindowsysteminterface_qpa.cpp @@ -42,6 +42,7 @@ #include "qwindowsysteminterface_qpa_p.h" #include "qapplication_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -288,4 +289,14 @@ void QWindowSystemInterface::handleScreenCountChange(int count) QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); } +void QWindowSystemInterface::handleLocaleChange() +{ + QWindowSystemInterfacePrivate::LocaleChangeEvent *e = + new QWindowSystemInterfacePrivate::LocaleChangeEvent(); + + QLocalePrivate::updateSystemPrivate(); + QWindowSystemInterfacePrivate::queueWindowSystemEvent(e); +} + + QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindowsysteminterface_qpa.h b/src/gui/kernel/qwindowsysteminterface_qpa.h index 064b68c..c8f660d 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa.h @@ -100,6 +100,8 @@ public: static void handleScreenGeometryChange(int screenIndex); static void handleScreenAvailableGeometryChange(int screenIndex); static void handleScreenCountChange(int count); + + static void handleLocaleChange(); }; QT_END_NAMESPACE diff --git a/src/gui/kernel/qwindowsysteminterface_qpa_p.h b/src/gui/kernel/qwindowsysteminterface_qpa_p.h index f26b8ee..4ff65f9 100644 --- a/src/gui/kernel/qwindowsysteminterface_qpa_p.h +++ b/src/gui/kernel/qwindowsysteminterface_qpa_p.h @@ -61,7 +61,8 @@ public: Touch, ScreenGeometry, ScreenAvailableGeometry, - ScreenCountChange + ScreenCountChange, + LocaleChange }; class WindowSystemEvent { @@ -193,6 +194,13 @@ public: int index; }; + class LocaleChangeEvent : public WindowSystemEvent { + public: + LocaleChangeEvent() + : WindowSystemEvent(LocaleChange) { } + }; + + static QList windowSystemEventQueue; static QMutex queueMutex; -- cgit v0.12