Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 0314542545c510025849223a700080a5cadb8dd4 Mon Sep 17 00:00:00 2001
- From: Denis Dzyubenko <denis.dzyubenko@nokia.com>
- Date: Mon, 21 Feb 2011 18:35:07 +0100
- Subject: [PATCH] WIP: Supporting multiple locale categories on Unix.
- This patch adds support for LC_* environment variables on Unix.
- Reviewed-by: pending
- ---
- src/corelib/tools/qlocale.cpp | 118 +++++++++++++++++++++++++++++++++++++----
- src/corelib/tools/qlocale.h | 2 +-
- 2 files changed, 108 insertions(+), 12 deletions(-)
- diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp
- index 46fef5b..7782989 100644
- --- a/src/corelib/tools/qlocale.cpp
- +++ b/src/corelib/tools/qlocale.cpp
- @@ -43,8 +43,8 @@
- #ifndef QT_NO_SYSTEMLOCALE
- QT_BEGIN_NAMESPACE
- -class QSystemLocale;
- -static QSystemLocale *QSystemLocale_globalSystemLocale();
- +class QSystemLocaleData;
- +static QSystemLocaleData *QSystemLocale_globalSystemLocale();
- QT_END_NAMESPACE
- #endif
- @@ -135,6 +135,33 @@ void qt_symbianUpdateSystemPrivate();
- void qt_symbianInitSystemLocale();
- #endif
- +#ifndef QT_NO_SYSTEMLOCALE
- +static QSystemLocale *_systemLocale = 0;
- +
- +struct QSystemLocaleData
- +{
- + QSystemLocaleData()
- + : locale(true)
- + #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
- + ,lc_numeric(QLocale(QLatin1String(qgetenv("LC_NUMERIC"))))
- + ,lc_time(QLocale(QLatin1String(qgetenv("LC_TIME"))))
- + ,lc_monetary(QLocale(QLatin1String(qgetenv("LC_MONETARY"))))
- + #endif
- + {
- + }
- + QSystemLocale locale;
- +#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
- + QLocale lc_numeric;
- + QLocale lc_time;
- + QLocale lc_monetary;
- +#endif
- +};
- +
- +Q_GLOBAL_STATIC(QSystemLocaleData, QSystemLocale_globalSystemLocale)
- +static QLocalePrivate *system_lp = 0;
- +Q_GLOBAL_STATIC(QLocalePrivate, globalLocalePrivate)
- +#endif
- +
- /******************************************************************************
- ** Helpers for accessing Qt locale database
- */
- @@ -1515,8 +1542,84 @@ QLocale QSystemLocale::fallbackLocale() const
- /*!
- \internal
- */
- -QVariant QSystemLocale::query(QueryType type, QVariant /* in */) const
- +QVariant QSystemLocale::query(QueryType type, QVariant in) const
- {
- + QSystemLocaleData *d = QSystemLocale_globalSystemLocale();
- + const QLocale &lc_numeric = d->lc_numeric;
- + const QLocale &lc_time = d->lc_time;
- + const QLocale &lc_monetary = d->lc_monetary;
- +
- + switch (type) {
- + case DecimalPoint:
- + return lc_numeric.decimalPoint();
- + case GroupSeparator:
- + return lc_numeric.groupSeparator();
- + case ZeroDigit:
- + return lc_numeric.zeroDigit();
- + case NegativeSign:
- + return lc_numeric.negativeSign();
- + case DateFormatLong:
- + return lc_time.dateFormat(QLocale::LongFormat);
- + case DateFormatShort:
- + return lc_time.dateFormat(QLocale::ShortFormat);
- + case TimeFormatLong:
- + return lc_time.timeFormat(QLocale::LongFormat);
- + case TimeFormatShort:
- + return lc_time.timeFormat(QLocale::ShortFormat);
- + case DayNameLong:
- + return lc_time.dayName(in.toInt(), QLocale::LongFormat);
- + case DayNameShort:
- + return lc_time.dayName(in.toInt(), QLocale::ShortFormat);
- + case MonthNameLong:
- + return lc_time.monthName(in.toInt(), QLocale::LongFormat);
- + case MonthNameShort:
- + return lc_time.monthName(in.toInt(), QLocale::ShortFormat);
- + case DateToStringLong:
- + return lc_time.toString(in.toDate(), QLocale::LongFormat);
- + case DateToStringShort:
- + return lc_time.toString(in.toDate(), QLocale::ShortFormat);
- + case TimeToStringLong:
- + return lc_time.toString(in.toTime(), QLocale::LongFormat);
- + case TimeToStringShort:
- + return lc_time.toString(in.toTime(), QLocale::ShortFormat);
- + case DateTimeFormatLong:
- + return lc_time.dateTimeFormat(QLocale::LongFormat);
- + case DateTimeFormatShort:
- + return lc_time.dateTimeFormat(QLocale::ShortFormat);
- + case DateTimeToStringLong:
- + return lc_time.toString(in.toDateTime(), QLocale::LongFormat);
- + case DateTimeToStringShort:
- + return lc_time.toString(in.toDateTime(), QLocale::ShortFormat);
- + case PositiveSign:
- + return lc_numeric.positiveSign();
- + case AMText:
- + return lc_time.amText();
- + case PMText:
- + return lc_time.pmText();
- + case FirstDayOfWeek:
- + return lc_time.firstDayOfWeek();
- + case CurrencySymbol:
- + return lc_monetary.currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt()));
- + case FormatCurrency: {
- + switch (in.type()) {
- + case QVariant::Int:
- + return lc_monetary.toCurrencyString(in.toInt());
- + case QVariant::UInt:
- + return lc_monetary.toCurrencyString(in.toUInt());
- + case QVariant::Double:
- + return lc_monetary.toCurrencyString(in.toDouble());
- + case QVariant::LongLong:
- + return lc_monetary.toCurrencyString(in.toLongLong());
- + case QVariant::ULongLong:
- + return lc_monetary.toCurrencyString(in.toULongLong());
- + default:
- + return QString();
- + }
- + }
- + default:
- + break;
- + }
- +
- if (type == MeasurementSystem) {
- return QVariant(unixGetSystemMeasurementSystem());
- } else if (type == UILanguages) {
- @@ -1581,13 +1684,6 @@ QVariant QSystemLocale::query(QueryType /* type */, QVariant /* in */) const
- #endif
- -#ifndef QT_NO_SYSTEMLOCALE
- -static QSystemLocale *_systemLocale = 0;
- -Q_GLOBAL_STATIC_WITH_ARGS(QSystemLocale, QSystemLocale_globalSystemLocale, (true))
- -static QLocalePrivate *system_lp = 0;
- -Q_GLOBAL_STATIC(QLocalePrivate, globalLocalePrivate)
- -#endif
- -
- /******************************************************************************
- ** Default system locale behavior
- */
- @@ -1683,7 +1779,7 @@ static const QSystemLocale *systemLocale()
- #if defined(Q_OS_SYMBIAN)
- qt_symbianInitSystemLocale();
- #endif
- - return QSystemLocale_globalSystemLocale();
- + return &QSystemLocale_globalSystemLocale()->locale;
- }
- void QLocalePrivate::updateSystemPrivate()
- diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h
- index 7a6591c..79866be 100644
- --- a/src/corelib/tools/qlocale.h
- +++ b/src/corelib/tools/qlocale.h
- @@ -105,7 +105,7 @@ public:
- private:
- QSystemLocale(bool);
- - friend QSystemLocale *QSystemLocale_globalSystemLocale();
- + friend class QSystemLocaleData;
- };
- #endif
- --
- 1.7.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement