summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qlocale_p.h23
-rw-r--r--src/corelib/tools/qlocale_unix.cpp80
2 files changed, 103 insertions, 0 deletions
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index ee2c7f5bee..42ef00f821 100644
--- a/src/corelib/tools/qlocale_p.h
+++ b/src/corelib/tools/qlocale_p.h
@@ -59,6 +59,10 @@
#include "qlocale.h"
+#if defined(Q_OS_QNX)
+#include "qsocketnotifier.h"
+#endif
+
QT_BEGIN_NAMESPACE
#ifndef QT_NO_SYSTEMLOCALE
@@ -347,6 +351,25 @@ inline char QLocalePrivate::digitToCLocale(QChar in) const
return 0;
}
+#if defined(Q_OS_QNX)
+class QBBLocaleData: public QObject
+{
+ Q_OBJECT
+public:
+ QBBLocaleData();
+ virtual ~QBBLocaleData();
+ void readPPSLocale();
+
+public Q_SLOTS:
+ void updateMesurementSystem();
+
+public:
+ uint ppsMeasurement;
+ QSocketNotifier *ppsNotifier;
+ int ppsFd;
+};
+#endif
+
QString qt_readEscapedFormatString(const QString &format, int *idx);
bool qt_splitLocaleName(const QString &name, QString &lang, QString &script, QString &cntry);
int qt_repeatCount(const QString &s, int i);
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp
index fef30c9daa..f43065239e 100644
--- a/src/corelib/tools/qlocale_unix.cpp
+++ b/src/corelib/tools/qlocale_unix.cpp
@@ -47,8 +47,79 @@
#include "qvariant.h"
#include "qreadwritelock.h"
+#if defined(Q_OS_QNX)
+#include <QtCore/private/qcore_unix_p.h>
+
+#include <unistd.h>
+#include <errno.h>
+#include <sys/pps.h>
+#endif
+
QT_BEGIN_NAMESPACE
+#if defined(Q_OS_QNX)
+static const char ppsServicePath[] = "/pps/services/locale/uom";
+static const size_t ppsBufferSize = 256;
+
+QBBLocaleData::QBBLocaleData()
+ :ppsNotifier(0)
+ ,ppsFd(-1)
+{
+ readPPSLocale();
+}
+
+QBBLocaleData::~QBBLocaleData()
+{
+ if (ppsFd != -1)
+ qt_safe_close(ppsFd);
+}
+
+void QBBLocaleData::updateMesurementSystem()
+{
+ char buffer[ppsBufferSize];
+
+ errno = 0;
+ int bytes = qt_safe_read(ppsFd, buffer, ppsBufferSize - 1);
+ if (bytes == -1) {
+ qWarning("Failed to read Locale pps, errno=%d", errno);
+ return;
+ }
+ // ensure data is null terminated
+ buffer[bytes] = '\0';
+
+ pps_decoder_t ppsDecoder;
+ pps_decoder_initialize(&ppsDecoder, 0);
+ if (pps_decoder_parse_pps_str(&ppsDecoder, buffer) == PPS_DECODER_OK) {
+ pps_decoder_push(&ppsDecoder, 0);
+ const char *measurementBuff;
+ if (pps_decoder_get_string(&ppsDecoder, "uom", &measurementBuff) == PPS_DECODER_OK) {
+ if (qstrcmp(measurementBuff, "imperial") == 0) {
+ pps_decoder_cleanup(&ppsDecoder);
+ ppsMeasurement = QLocale::ImperialSystem;
+ return;
+ }
+ }
+ }
+
+ pps_decoder_cleanup(&ppsDecoder);
+ ppsMeasurement = QLocale::MetricSystem;
+}
+
+void QBBLocaleData::readPPSLocale()
+{
+ errno = 0;
+ ppsFd = qt_safe_open(ppsServicePath, O_RDONLY);
+ if (ppsFd == -1) {
+ qWarning("Failed to open Locale pps, errno=%d", errno);
+ return;
+ }
+
+ ppsNotifier = new QSocketNotifier(ppsFd, QSocketNotifier::Read, this);
+ updateMesurementSystem();
+ QObject::connect(ppsNotifier, SIGNAL(activated(int)), this, SLOT(updateMesurementSystem()));
+}
+#endif
+
#ifndef QT_NO_SYSTEMLOCALE
struct QSystemLocaleData
{
@@ -105,6 +176,9 @@ void QSystemLocaleData::readEnvironment()
Q_GLOBAL_STATIC(QSystemLocaleData, qSystemLocaleData)
+#if defined(Q_OS_QNX)
+ Q_GLOBAL_STATIC(QBBLocaleData, qbbLocaleData)
+#endif
#endif
@@ -136,6 +210,9 @@ QLocale QSystemLocale::fallbackUiLocale() const
QVariant QSystemLocale::query(QueryType type, QVariant in) const
{
QSystemLocaleData *d = qSystemLocaleData();
+#if defined(Q_OS_QNX)
+ QBBLocaleData *bbd = qbbLocaleData();
+#endif
if (type == LocaleChanged) {
d->readEnvironment();
@@ -223,6 +300,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
return QLocale::MetricSystem;
if (meas_locale.compare(QLatin1String("Other"), Qt::CaseInsensitive) == 0)
return QLocale::MetricSystem;
+#if defined(Q_OS_QNX)
+ return bbd->ppsMeasurement;
+#endif
return QVariant((int)QLocale(meas_locale).measurementSystem());
}
case UILanguages: {