summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormfekari <mfekari@rim.com>2012-11-16 11:12:41 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-23 09:20:20 (GMT)
commit58384f346b13b27c58a2efb3ba8b6be98ab54fbf (patch)
treefa34a49ff40d7b1b722e79ac2edfe15c7c157a54 /src
parent169ba759c536fcd807ee061e1831e4502a5f1416 (diff)
downloadQt-58384f346b13b27c58a2efb3ba8b6be98ab54fbf.zip
Qt-58384f346b13b27c58a2efb3ba8b6be98ab54fbf.tar.gz
Qt-58384f346b13b27c58a2efb3ba8b6be98ab54fbf.tar.bz2
Qnx: Handle the MeasurementSystem in QNX
This is a back port from: 3853035a45abb87c94314ac9f61f0c454a7f0262 Change-Id: If31252555406cb7347e6f7b676cda3938c420f78 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com> Reviewed-by: Nicolas Arnaud-Cormos <nicolas@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/tools/qlocale_p.h23
-rw-r--r--src/corelib/tools/qlocale_unix.cpp77
2 files changed, 100 insertions, 0 deletions
diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h
index 237517a..38710ec 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
+
#if defined(Q_OS_SYMBIAN) && !defined(QT_NO_SYSTEMLOCALE)
class CEnvironmentChangeNotifier;
#endif
@@ -271,6 +275,25 @@ private:
};
#endif
+#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 abf2a68..174d739 100644
--- a/src/corelib/tools/qlocale_unix.cpp
+++ b/src/corelib/tools/qlocale_unix.cpp
@@ -47,11 +47,78 @@
#include "qvariant.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
+
static QByteArray getSystemLocale()
{
#if defined(Q_OS_QNX)
@@ -118,6 +185,10 @@ struct QSystemLocaleData
Q_GLOBAL_STATIC(QSystemLocaleData, qSystemLocaleData)
#endif
+#if defined(Q_OS_QNX)
+ Q_GLOBAL_STATIC(QBBLocaleData, qbbLocaleData)
+#endif
+
#ifndef QT_NO_SYSTEMLOCALE
QLocale QSystemLocale::fallbackLocale() const
{
@@ -134,6 +205,9 @@ QLocale QSystemLocale::fallbackLocale() const
QVariant QSystemLocale::query(QueryType type, QVariant in) const
{
QSystemLocaleData *d = qSystemLocaleData();
+#if defined(Q_OS_QNX)
+ QBBLocaleData *bbd = qbbLocaleData();
+#endif
const QLocale &lc_numeric = d->lc_numeric;
const QLocale &lc_time = d->lc_time;
const QLocale &lc_monetary = d->lc_monetary;
@@ -213,6 +287,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: {