summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Ratelle <nratelle@qnx.com>2012-01-17 18:05:54 -0500
committerQt by Nokia <qt-info@nokia.com>2012-03-12 07:54:42 +0100
commit25c4ce6deef20c69d00fe1197a60e8b7587c81cb (patch)
tree4ab2fdd19e5313db6e37951ea703af5885007d40
parent5a7619a459bce4fe0011044e7a1a2cff1297f800 (diff)
Support changing locales at runtime in QPA plugins.
Change-Id: Id65798b81db2fa9fb5b1d929e4a94103995c6707 Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
-rw-r--r--src/corelib/tools/qlocale_unix.cpp35
-rw-r--r--src/gui/kernel/qapplication_p.h2
-rw-r--r--src/gui/kernel/qapplication_qpa.cpp8
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.cpp11
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa.h2
-rw-r--r--src/gui/kernel/qwindowsysteminterface_qpa_p.h10
6 files changed, 64 insertions, 4 deletions
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp
index 5839a80e00..dd99792cc5 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 <unistd.h>
+#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<QStringRef>(), QLocale::AlternateQuotation);
case ListToSeparatedString:
return lc_messages.createSeparatedList(in.value<QStringList>());
+ case LocaleChanged:
+ d->updateLocale();
+ break;
default:
break;
}
diff --git a/src/gui/kernel/qapplication_p.h b/src/gui/kernel/qapplication_p.h
index 31d0b75684..74b0ee58da 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 6b00258504..242b5ef5e2 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<QWindowSystemInterfacePrivate::ScreenAvailableGeometryEvent *>(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 97e4e653e5..24fc664cdb 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 <QAbstractEventDispatcher>
+#include <private/qlocale_p.h>
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 064b68c352..c8f660d3c1 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 f26b8ee609..4ff65f9f5a 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<WindowSystemEvent *> windowSystemEventQueue;
static QMutex queueMutex;