summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNick Ratelle <nratelle@qnx.com>2012-01-17 23:05:54 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-03-12 06:54:42 (GMT)
commit25c4ce6deef20c69d00fe1197a60e8b7587c81cb (patch)
tree4ab2fdd19e5313db6e37951ea703af5885007d40 /src
parent5a7619a459bce4fe0011044e7a1a2cff1297f800 (diff)
downloadQt-25c4ce6deef20c69d00fe1197a60e8b7587c81cb.zip
Qt-25c4ce6deef20c69d00fe1197a60e8b7587c81cb.tar.gz
Qt-25c4ce6deef20c69d00fe1197a60e8b7587c81cb.tar.bz2
Support changing locales at runtime in QPA plugins.
Change-Id: Id65798b81db2fa9fb5b1d929e4a94103995c6707 Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'src')
-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 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 <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 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<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 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 <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 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<WindowSystemEvent *> windowSystemEventQueue;
static QMutex queueMutex;