File indexing completed on 2024-04-21 14:55:35

0001 /* This file is part of the KDE libraries
0002    Copyright (c) 1997,2001 Stephan Kulow <coolo@kde.org>
0003    Copyright (c) 1999 Preston Brown <pbrown@kde.org>
0004    Copyright (c) 1999-2002 Hans Petter Bieker <bieker@kde.org>
0005    Copyright (c) 2002 Lukas Tinkl <lukas@kde.org>
0006    Copyright (C) 2007 Bernhard Loos <nhuh.put@web.de>
0007    Copyright (C) 2009, 2010 John Layt <john@layt.net>
0008 
0009    This library is free software; you can redistribute it and/or
0010    modify it under the terms of the GNU Library General Public
0011    License as published by the Free Software Foundation; either
0012    version 2 of the License, or (at your option) any later version.
0013 
0014    This library is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017    Library General Public License for more details.
0018 
0019    You should have received a copy of the GNU Library General Public License
0020    along with this library; see the file COPYING.LIB.  If not, write to
0021    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0022    Boston, MA 02110-1301, USA.
0023 */
0024 
0025 #include "klocale.h"
0026 #if defined Q_OS_WIN
0027 #include "klocale_win_p.h"
0028 #elif defined Q_OS_MAC
0029 #include "klocale_mac_p.h"
0030 #else
0031 #include "klocale_unix_p.h"
0032 #endif
0033 
0034 #include <QDateTime>
0035 
0036 #include "kconfig.h"
0037 #include "kdatetime.h"
0038 #include "kcalendarsystem.h"
0039 #include "kdayperiod_p.h"
0040 #include "kcurrencycode.h"
0041 
0042 KLocale::KLocale(KSharedConfig::Ptr config)
0043 #if defined Q_OS_WIN
0044     : d(new KLocaleWindowsPrivate(this, config))
0045 #elif defined Q_OS_MAC
0046     : d(new KLocaleMacPrivate(this, config))
0047 #else
0048     : d(new KLocaleUnixPrivate(this, config))
0049 #endif
0050 {
0051 }
0052 
0053 KLocale::KLocale(const QString &language, const QString &country, KConfig *config)
0054 #if defined Q_OS_WIN
0055     : d(new KLocaleWindowsPrivate(this, language, country, config))
0056 #elif defined Q_OS_MAC
0057     : d(new KLocaleMacPrivate(this, language, country, config))
0058 #else
0059     : d(new KLocaleUnixPrivate(this, language, country, config))
0060 #endif
0061 {
0062 }
0063 
0064 KLocale::~KLocale()
0065 {
0066     delete d;
0067 }
0068 
0069 bool KLocale::setCountry(const QString &country, KConfig *config)
0070 {
0071     return d->setCountry(country, config);
0072 }
0073 
0074 bool KLocale::setCountryDivisionCode(const QString &countryDivisionCode)
0075 {
0076     return d->setCountryDivisionCode(countryDivisionCode);
0077 }
0078 
0079 bool KLocale::setLanguage(const QString &language, KConfig *config)
0080 {
0081     return d->setLanguage(language, config);
0082 }
0083 
0084 bool KLocale::setLanguage(const QStringList &languages)
0085 {
0086     return d->setLanguage(languages);
0087 }
0088 
0089 void KLocale::setCurrencyCode(const QString &newCurrencyCode)
0090 {
0091     d->setCurrencyCode(newCurrencyCode);
0092 }
0093 
0094 void KLocale::splitLocale(const QString &locale, QString &language, QString &country, QString &modifier,
0095                           QString &charset)
0096 {
0097     KLocalePrivate::splitLocale(locale, language, country, modifier, charset);
0098 }
0099 
0100 QString KLocale::language() const
0101 {
0102     return d->language();
0103 }
0104 
0105 QString KLocale::country() const
0106 {
0107     return d->country();
0108 }
0109 
0110 QString KLocale::countryDivisionCode() const
0111 {
0112     return d->countryDivisionCode();
0113 }
0114 
0115 KCurrencyCode *KLocale::currency() const
0116 {
0117     return d->currency();
0118 }
0119 
0120 QString KLocale::currencyCode() const
0121 {
0122     return d->currencyCode();
0123 }
0124 
0125 QList<KLocale::DigitSet> KLocale::allDigitSetsList() const
0126 {
0127     return d->allDigitSetsList();
0128 }
0129 
0130 QString KLocale::digitSetToName(KLocale::DigitSet digitSet, bool withDigits) const
0131 {
0132     return d->digitSetToName(digitSet, withDigits);
0133 }
0134 
0135 QString KLocale::convertDigits(const QString &str, DigitSet digitSet, bool ignoreContext) const
0136 {
0137     return d->convertDigits(str, digitSet, ignoreContext);
0138 }
0139 
0140 bool KLocale::nounDeclension() const
0141 {
0142     return d->nounDeclension();
0143 }
0144 
0145 bool KLocale::dateMonthNamePossessive() const
0146 {
0147     return d->dateMonthNamePossessive();
0148 }
0149 
0150 int KLocale::weekStartDay() const
0151 {
0152     return d->weekStartDay();
0153 }
0154 
0155 int KLocale::workingWeekStartDay() const
0156 {
0157     return d->workingWeekStartDay();
0158 }
0159 
0160 int KLocale::workingWeekEndDay() const
0161 {
0162     return d->workingWeekEndDay();
0163 }
0164 
0165 int KLocale::weekDayOfPray() const
0166 {
0167     return d->weekDayOfPray();
0168 }
0169 
0170 int KLocale::decimalPlaces() const
0171 {
0172     return d->decimalPlaces();
0173 }
0174 
0175 QString KLocale::decimalSymbol() const
0176 {
0177     return d->decimalSymbol();
0178 }
0179 
0180 QString KLocale::thousandsSeparator() const
0181 {
0182     return d->thousandsSeparator();
0183 }
0184 
0185 QString KLocale::currencySymbol() const
0186 {
0187     return d->currencySymbol();
0188 }
0189 
0190 QString KLocale::monetaryDecimalSymbol() const
0191 {
0192     return d->monetaryDecimalSymbol();
0193 }
0194 
0195 QString KLocale::monetaryThousandsSeparator() const
0196 {
0197     return d->monetaryThousandsSeparator();
0198 }
0199 
0200 QString KLocale::positiveSign() const
0201 {
0202     return d->positiveSign();
0203 }
0204 
0205 QString KLocale::negativeSign() const
0206 {
0207     return d->negativeSign();
0208 }
0209 
0210 int KLocale::fracDigits() const
0211 {
0212     return monetaryDecimalPlaces();
0213 }
0214 
0215 int KLocale::monetaryDecimalPlaces() const
0216 {
0217     return d->monetaryDecimalPlaces();
0218 }
0219 
0220 bool KLocale::positivePrefixCurrencySymbol() const
0221 {
0222     return d->positivePrefixCurrencySymbol();
0223 }
0224 
0225 bool KLocale::negativePrefixCurrencySymbol() const
0226 {
0227     return d->negativePrefixCurrencySymbol();
0228 }
0229 
0230 KLocale::SignPosition KLocale::positiveMonetarySignPosition() const
0231 {
0232     return d->positiveMonetarySignPosition();
0233 }
0234 
0235 KLocale::SignPosition KLocale::negativeMonetarySignPosition() const
0236 {
0237     return d->negativeMonetarySignPosition();
0238 }
0239 
0240 QString KLocale::formatMoney(double num, const QString &symbol, int precision) const
0241 {
0242     return d->formatMoney(num, symbol, precision);
0243 }
0244 
0245 QString KLocale::formatNumber(double num, int precision) const
0246 {
0247     return d->formatNumber(num, precision);
0248 }
0249 
0250 QString KLocale::formatLong(long num) const
0251 {
0252     return d->formatLong(num);
0253 }
0254 
0255 QString KLocale::formatNumber(const QString &numStr, bool round, int precision) const
0256 {
0257     return d->formatNumber(numStr, round, precision);
0258 }
0259 
0260 QString KLocale::formatByteSize(double size, int precision, KLocale::BinaryUnitDialect dialect,
0261                                 KLocale::BinarySizeUnits specificUnit) const
0262 {
0263     return d->formatByteSize(size, precision, dialect, specificUnit);
0264 }
0265 
0266 QString KLocale::formatByteSize(double size) const
0267 {
0268     return d->formatByteSize(size);
0269 }
0270 
0271 KLocale::BinaryUnitDialect KLocale::binaryUnitDialect() const
0272 {
0273     return d->binaryUnitDialect();
0274 }
0275 
0276 void KLocale::setBinaryUnitDialect(KLocale::BinaryUnitDialect newDialect)
0277 {
0278     d->setBinaryUnitDialect(newDialect);
0279 }
0280 
0281 QString KLocale::formatDuration(unsigned long mSec) const
0282 {
0283     return d->formatDuration(mSec);
0284 }
0285 
0286 QString KLocale::prettyFormatDuration(unsigned long mSec) const
0287 {
0288     return d->prettyFormatDuration(mSec);
0289 }
0290 
0291 QString KLocale::formatDate(const QDate &date, KLocale::DateFormat format) const
0292 {
0293     return d->formatDate(date, format);
0294 }
0295 
0296 class KGlobalLocaleStatic
0297 {
0298 public:
0299     KGlobalLocaleStatic()
0300         : locale()
0301     {
0302     }
0303 
0304     KLocale locale;
0305 };
0306 
0307 Q_GLOBAL_STATIC(KGlobalLocaleStatic, s_globalLocale)
0308 
0309 KLocale *KLocale::global()
0310 {
0311     KGlobalLocaleStatic *glob = s_globalLocale();
0312     return &glob->locale;
0313 }
0314 
0315 double KLocale::readNumber(const QString &_str, bool *ok) const
0316 {
0317     return d->readNumber(_str, ok);
0318 }
0319 
0320 double KLocale::readMoney(const QString &_str, bool *ok) const
0321 {
0322     return d->readMoney(_str, ok);
0323 }
0324 
0325 QDate KLocale::readDate(const QString &intstr, bool *ok) const
0326 {
0327     return d->readDate(intstr, ok);
0328 }
0329 
0330 QDate KLocale::readDate(const QString &intstr, ReadDateFlags flags, bool *ok) const
0331 {
0332     return d->readDate(intstr, flags, ok);
0333 }
0334 
0335 QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool *ok) const
0336 {
0337     return d->readDate(intstr, fmt, ok);
0338 }
0339 
0340 QTime KLocale::readTime(const QString &intstr, bool *ok) const
0341 {
0342     return d->readTime(intstr, ok);
0343 }
0344 
0345 QTime KLocale::readTime(const QString &intstr, KLocale::ReadTimeFlags flags, bool *ok) const
0346 {
0347     return d->readTime(intstr, flags, ok);
0348 }
0349 
0350 QTime KLocale::readLocaleTime(const QString &intstr, bool *ok, TimeFormatOptions options,
0351                               TimeProcessingOptions processing) const
0352 {
0353     return d->readLocaleTime(intstr, ok, options, processing);
0354 }
0355 
0356 QString KLocale::formatTime(const QTime &time, bool includeSecs, bool isDuration) const
0357 {
0358     return d->formatTime(time, includeSecs, isDuration);
0359 }
0360 
0361 QString KLocale::formatLocaleTime(const QTime &time, TimeFormatOptions options) const
0362 {
0363     return d->formatLocaleTime(time, options);
0364 }
0365 
0366 bool KLocale::use12Clock() const
0367 {
0368     return d->use12Clock();
0369 }
0370 
0371 QString KLocale::dayPeriodText(const QTime &time, DateTimeComponentFormat format) const
0372 {
0373     return d->dayPeriodForTime(time).periodName(format);
0374 }
0375 
0376 QStringList KLocale::languageList() const
0377 {
0378     return d->languageList();
0379 }
0380 
0381 QStringList KLocale::currencyCodeList() const
0382 {
0383     return d->currencyCodeList();
0384 }
0385 
0386 QString KLocale::formatDateTime(const QDateTime &dateTime, KLocale::DateFormat format, bool includeSeconds) const
0387 {
0388     return d->formatDateTime(dateTime, format, includeSeconds);
0389 }
0390 
0391 QString KLocale::formatDateTime(const KDateTime &dateTime, KLocale::DateFormat format, DateTimeFormatOptions options) const
0392 {
0393     return d->formatDateTime(dateTime, format, options);
0394 }
0395 
0396 void KLocale::setDateFormat(const QString &format)
0397 {
0398     d->setDateFormat(format);
0399 }
0400 
0401 void KLocale::setDateFormatShort(const QString &format)
0402 {
0403     d->setDateFormatShort(format);
0404 }
0405 
0406 void KLocale::setDateMonthNamePossessive(bool possessive)
0407 {
0408     d->setDateMonthNamePossessive(possessive);
0409 }
0410 
0411 void KLocale::setTimeFormat(const QString &format)
0412 {
0413     d->setTimeFormat(format);
0414 }
0415 
0416 void KLocale::setWeekStartDay(int day)
0417 {
0418     d->setWeekStartDay(day);
0419 }
0420 
0421 void KLocale::setWorkingWeekStartDay(int day)
0422 {
0423     d->setWorkingWeekStartDay(day);
0424 }
0425 
0426 void KLocale::setWorkingWeekEndDay(int day)
0427 {
0428     d->setWorkingWeekEndDay(day);
0429 }
0430 
0431 void KLocale::setWeekDayOfPray(int day)
0432 {
0433     d->setWeekDayOfPray(day);
0434 }
0435 
0436 QString KLocale::dateFormat() const
0437 {
0438     return d->dateFormat();
0439 }
0440 
0441 QString KLocale::dateFormatShort() const
0442 {
0443     return d->dateFormatShort();
0444 }
0445 
0446 QString KLocale::timeFormat() const
0447 {
0448     return d->timeFormat();
0449 }
0450 
0451 void KLocale::setDecimalPlaces(int digits)
0452 {
0453     d->setDecimalPlaces(digits);
0454 }
0455 
0456 void KLocale::setDecimalSymbol(const QString &symbol)
0457 {
0458     d->setDecimalSymbol(symbol);
0459 }
0460 
0461 void KLocale::setThousandsSeparator(const QString &separator)
0462 {
0463     d->setThousandsSeparator(separator);
0464 }
0465 
0466 void KLocale::setPositiveSign(const QString &sign)
0467 {
0468     d->setPositiveSign(sign);
0469 }
0470 
0471 void KLocale::setNegativeSign(const QString &sign)
0472 {
0473     d->setNegativeSign(sign);
0474 }
0475 
0476 void KLocale::setPositiveMonetarySignPosition(KLocale::SignPosition signpos)
0477 {
0478     d->setPositiveMonetarySignPosition(signpos);
0479 }
0480 
0481 void KLocale::setNegativeMonetarySignPosition(KLocale::SignPosition signpos)
0482 {
0483     d->setNegativeMonetarySignPosition(signpos);
0484 }
0485 
0486 void KLocale::setPositivePrefixCurrencySymbol(bool prefix)
0487 {
0488     d->setPositivePrefixCurrencySymbol(prefix);
0489 }
0490 
0491 void KLocale::setNegativePrefixCurrencySymbol(bool prefix)
0492 {
0493     d->setNegativePrefixCurrencySymbol(prefix);
0494 }
0495 
0496 void KLocale::setFracDigits(int digits)
0497 {
0498     setMonetaryDecimalPlaces(digits);
0499 }
0500 
0501 void KLocale::setMonetaryDecimalPlaces(int digits)
0502 {
0503     d->setMonetaryDecimalPlaces(digits);
0504 }
0505 
0506 void KLocale::setMonetaryThousandsSeparator(const QString &separator)
0507 {
0508     d->setMonetaryThousandsSeparator(separator);
0509 }
0510 
0511 void KLocale::setMonetaryDecimalSymbol(const QString &symbol)
0512 {
0513     d->setMonetaryDecimalSymbol(symbol);
0514 }
0515 
0516 void KLocale::setCurrencySymbol(const QString &symbol)
0517 {
0518     d->setCurrencySymbol(symbol);
0519 }
0520 
0521 int KLocale::pageSize() const
0522 {
0523     return d->pageSize();
0524 }
0525 
0526 void KLocale::setPageSize(int size)
0527 {
0528     d->setPageSize(size);
0529 }
0530 
0531 KLocale::MeasureSystem KLocale::measureSystem() const
0532 {
0533     return d->measureSystem();
0534 }
0535 
0536 void KLocale::setMeasureSystem(KLocale::MeasureSystem value)
0537 {
0538     d->setMeasureSystem(value);
0539 }
0540 
0541 QString KLocale::defaultLanguage()
0542 {
0543     return KLocalePrivate::defaultLanguage();
0544 }
0545 
0546 QString KLocale::defaultCountry()
0547 {
0548     return KLocalePrivate::defaultCountry();
0549 }
0550 
0551 QString KLocale::defaultCurrencyCode()
0552 {
0553     return KLocalePrivate::defaultCurrencyCode();
0554 }
0555 
0556 const QByteArray KLocale::encoding() const
0557 {
0558     return d->encoding();
0559 }
0560 
0561 int KLocale::encodingMib() const
0562 {
0563     return d->encodingMib();
0564 }
0565 
0566 int KLocale::fileEncodingMib() const
0567 {
0568     return d->fileEncodingMib();
0569 }
0570 
0571 QTextCodec *KLocale::codecForEncoding() const
0572 {
0573     return d->codecForEncoding();
0574 }
0575 
0576 bool KLocale::setEncoding(int mibEnum)
0577 {
0578     return d->setEncoding(mibEnum);
0579 }
0580 
0581 QStringList KLocale::allLanguagesList() const
0582 {
0583     return d->allLanguagesList();
0584 }
0585 
0586 QStringList KLocale::installedLanguages() const
0587 {
0588     return d->installedLanguages();
0589 }
0590 
0591 QString KLocale::languageCodeToName(const QString &language) const
0592 {
0593     return d->languageCodeToName(language);
0594 }
0595 
0596 QStringList KLocale::allCountriesList() const
0597 {
0598     return d->allCountriesList();
0599 }
0600 
0601 QString KLocale::countryCodeToName(const QString &country) const
0602 {
0603     return d->countryCodeToName(country);
0604 }
0605 
0606 void KLocale::setCalendar(const QString &calendarType)
0607 {
0608     d->setCalendar(calendarType);
0609 }
0610 
0611 void KLocale::setCalendarSystem(KLocale::CalendarSystem calendarSystem)
0612 {
0613     d->setCalendarSystem(calendarSystem);
0614 }
0615 
0616 QString KLocale::calendarType() const
0617 {
0618     return d->calendarType();
0619 }
0620 
0621 KLocale::CalendarSystem KLocale::calendarSystem() const
0622 {
0623     return d->calendarSystem();
0624 }
0625 
0626 const KCalendarSystem *KLocale::calendar() const
0627 {
0628     return d->calendar();
0629 }
0630 
0631 void KLocale::setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem)
0632 {
0633     d->setWeekNumberSystem(weekNumberSystem);
0634 }
0635 
0636 KLocale::WeekNumberSystem KLocale::weekNumberSystem()
0637 {
0638     return d->weekNumberSystem();
0639 }
0640 
0641 KLocale::WeekNumberSystem KLocale::weekNumberSystem() const
0642 {
0643     return d->weekNumberSystem();
0644 }
0645 
0646 KLocale::KLocale(const KLocale &rhs)
0647     : d(new KLocalePrivate(*rhs.d))
0648 {
0649     d->q = this;
0650 }
0651 
0652 KLocale &KLocale::operator=(const KLocale &rhs)
0653 {
0654     // the assignment operator works here
0655     *d = *rhs.d;
0656     d->q = this;
0657     return *this;
0658 }
0659 
0660 void KLocale::setDigitSet(KLocale::DigitSet digitSet)
0661 {
0662     d->setDigitSet(digitSet);
0663 }
0664 
0665 KLocale::DigitSet KLocale::digitSet() const
0666 {
0667     return d->digitSet();
0668 }
0669 
0670 void KLocale::setMonetaryDigitSet(KLocale::DigitSet digitSet)
0671 {
0672     d->setMonetaryDigitSet(digitSet);
0673 }
0674 
0675 KLocale::DigitSet KLocale::monetaryDigitSet() const
0676 {
0677     return d->monetaryDigitSet();
0678 }
0679 
0680 void KLocale::setDateTimeDigitSet(KLocale::DigitSet digitSet)
0681 {
0682     d->setDateTimeDigitSet(digitSet);
0683 }
0684 
0685 KLocale::DigitSet KLocale::dateTimeDigitSet() const
0686 {
0687     return d->dateTimeDigitSet();
0688 }
0689 
0690 void KLocale::reparseConfiguration()
0691 {
0692     d->initFormat();
0693 }