From 3b65b5e5cf9ac36af64d0a769985f82255d2b38f Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Sat, 14 Jan 2012 07:58:53 +0200 Subject: [PATCH 001/104] Initial commit for KLocale QML Bindings Branch. Also terietor helped in the coding. --- declarativeimports/core/Locale.cpp | 754 ++++++ declarativeimports/core/Locale.h | 2069 +++++++++++++++++ .../core/corebindingsplugin.cpp | 3 + 3 files changed, 2826 insertions(+) create mode 100644 declarativeimports/core/Locale.cpp create mode 100644 declarativeimports/core/Locale.h diff --git a/declarativeimports/core/Locale.cpp b/declarativeimports/core/Locale.cpp new file mode 100644 index 000000000..0529565f3 --- /dev/null +++ b/declarativeimports/core/Locale.cpp @@ -0,0 +1,754 @@ +/* This file is part of the KDE libraries + Copyright (C) 2012 Giorgos Tsiapaliwkas + Copyright (C) 2012 Antonis Tsiapaliokas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "locale.h" + +/*Locale::Locale(const QString &catalog, KSharedConfig::Ptr config) +#if defined Q_WS_WIN + : d(new LocaleWindowsPrivate(this, catalog, config)) +#elif defined Q_OS_MAC + : d(new LocaleMacPrivate(this, catalog, config)) +#else + : d(new LocaleUnixPrivate(this, catalog, config)) +#endif +{ +} + +Locale::Locale(const QString& catalog, const QString &language, const QString &country, KConfig *config) +#if defined Q_WS_WIN + : d(new LocaleWindowsPrivate(this, catalog, language, country, config)) +#elif defined Q_OS_MAC + : d(new LocaleMacPrivate(this, catalog, language, country, config)) +#else + : d(new LocaleUnixPrivate(this, catalog, language, country, config)) +#endif +{ +}*/ + +Locale::~Locale() +{ + delete d; +} + +bool Locale::setCountry(const QString &country, KConfig *config) +{ + return d->setCountry(country, config); +} + +bool Locale::setCountryDivisionCode(const QString &countryDivisionCode) +{ + return d->setCountryDivisionCode(countryDivisionCode); +} + +bool Locale::setLanguage(const QString &language, KConfig *config) +{ + return d->setLanguage(language, config); +} + +bool Locale::setLanguage(const QStringList &languages) +{ + return d->setLanguage(languages); +} + +void Locale::setCurrencyCode(const QString &newCurrencyCode) +{ + d->setCurrencyCode(newCurrencyCode); +} + +bool Locale::isApplicationTranslatedInto(const QString &lang) +{ + return d->isApplicationTranslatedInto(lang); +} + +void Locale::splitLocale(const QString &locale, QString &language, QString &country, QString &modifier, + QString &charset) +{ + LocalePrivate::splitLocale(locale, language, country, modifier, charset); +} + +QString Locale::language() const +{ + return d->language(); +} + +QString Locale::country() const +{ + return d->country(); +} + +QString Locale::countryDivisionCode() const +{ + return d->countryDivisionCode(); +} + +KCurrencyCode *Locale::currency() const +{ + return d->currency(); +} + +QString Locale::currencyCode() const +{ + return d->currencyCode(); +} + +void Locale::insertCatalog(const QString &catalog) +{ + d->insertCatalog(catalog); +} + +void Locale::removeCatalog(const QString &catalog) +{ + d->removeCatalog(catalog); +} + +void Locale::setActiveCatalog(const QString &catalog) +{ + d->setActiveCatalog(catalog); +} + +void Locale::translateRawFrom(const char *catname, const char *ctxt, const char *singular, const char *plural, + unsigned long n, QString *lang, QString *trans) const +{ + d->translateRawFrom(catname, ctxt, singular, plural, n, lang, trans); +} + +//Convenience versions +void Locale::translateRawFrom(const char *catname, const char *msg, QString *lang, QString *trans) const +{ + d->translateRawFrom(catname, 0, msg, 0, 0, lang, trans); +} + +void Locale::translateRaw(const char *msg, QString *lang, QString *trans) const +{ + d->translateRawFrom(0, 0, msg, 0, 0, lang, trans); +} + +void Locale::translateRawFrom(const char *catname, const char *ctxt, const char *msg, QString *lang, + QString *trans) const +{ + d->translateRawFrom(catname, ctxt, msg, 0, 0, lang, trans); +} + +void Locale::translateRaw(const char *ctxt, const char *msg, QString *lang, QString *trans) const +{ + d->translateRawFrom(0, ctxt, msg, 0, 0, lang, trans); +} + +void Locale::translateRawFrom(const char *catname, const char *singular, const char *plural, + unsigned long n, QString *lang, QString *trans) const +{ + d->translateRawFrom(catname, 0, singular, plural, n, lang, trans); +} + +void Locale::translateRaw(const char *singular, const char *plural, unsigned long n, QString *lang, + QString *trans) const +{ + d->translateRawFrom(0, 0, singular, plural, n, lang, trans); +} + +void Locale::translateRaw(const char *ctxt, const char *singular, const char *plural, + unsigned long n, QString *lang, QString *trans) const +{ + d->translateRawFrom(0, ctxt, singular, plural, n, lang, trans); +} + +QString Locale::translateQt(const char *context, const char *sourceText, const char *comment) const +{ + return d->translateQt(context, sourceText, comment); +} + +QList Locale::allDigitSetsList() const +{ + return d->allDigitSetsList(); +} + +QString Locale::digitSetToName(Locale::DigitSet digitSet, bool withDigits) const +{ + return d->digitSetToName(digitSet, withDigits); +} + +QString Locale::convertDigits(const QString &str, DigitSet digitSet, bool ignoreContext) const +{ + return d->convertDigits(str, digitSet, ignoreContext); +} + +bool Locale::nounDeclension() const +{ + return d->nounDeclension(); +} + +bool Locale::dateMonthNamePossessive() const +{ + return d->dateMonthNamePossessive(); +} + +int Locale::weekStartDay() const +{ + return d->weekStartDay(); +} + +int Locale::workingWeekStartDay() const +{ + return d->workingWeekStartDay(); +} + +int Locale::workingWeekEndDay() const +{ + return d->workingWeekEndDay(); +} + +int Locale::weekDayOfPray() const +{ + return d->weekDayOfPray(); +} + +int Locale::decimalPlaces() const +{ + return d->decimalPlaces(); +} + +QString Locale::decimalSymbol() const +{ + return d->decimalSymbol(); +} + +QString Locale::thousandsSeparator() const +{ + return d->thousandsSeparator(); +} + +QString Locale::currencySymbol() const +{ + return d->currencySymbol(); +} + +QString Locale::monetaryDecimalSymbol() const +{ + return d->monetaryDecimalSymbol(); +} + +QString Locale::monetaryThousandsSeparator() const +{ + return d->monetaryThousandsSeparator(); +} + +QString Locale::positiveSign() const +{ + return d->positiveSign(); +} + +QString Locale::negativeSign() const +{ + return d->negativeSign(); +} + +int Locale::fracDigits() const +{ + return monetaryDecimalPlaces(); +} + +int Locale::monetaryDecimalPlaces() const +{ + return d->monetaryDecimalPlaces(); +} + +bool Locale::positivePrefixCurrencySymbol() const +{ + return d->positivePrefixCurrencySymbol(); +} + +bool Locale::negativePrefixCurrencySymbol() const +{ + return d->negativePrefixCurrencySymbol(); +} + +Locale::SignPosition Locale::positiveMonetarySignPosition() const +{ + return d->positiveMonetarySignPosition(); +} + +Locale::SignPosition Locale::negativeMonetarySignPosition() const +{ + return d->negativeMonetarySignPosition(); +} + +QString Locale::formatMoney(double num, const QString &symbol, int precision) const +{ + return d->formatMoney(num, symbol, precision); +} + +QString Locale::formatNumber(double num, int precision) const +{ + return d->formatNumber(num, precision); +} + +QString Locale::formatLong(long num) const +{ + return d->formatLong(num); +} + +QString Locale::formatNumber(const QString &numStr, bool round, int precision) const +{ + return d->formatNumber(numStr, round, precision); +} + +QString Locale::formatByteSize(double size, int precision, Locale::BinaryUnitDialect dialect, + Locale::BinarySizeUnits specificUnit) const +{ + return d->formatByteSize(size, precision, dialect, specificUnit); +} + +QString Locale::formatByteSize(double size) const +{ + return d->formatByteSize(size); +} + +Locale::BinaryUnitDialect Locale::binaryUnitDialect() const +{ + return d->binaryUnitDialect(); +} + +void Locale::setBinaryUnitDialect(Locale::BinaryUnitDialect newDialect) +{ + d->setBinaryUnitDialect(newDialect); +} + +QString Locale::formatDuration(unsigned long mSec) const +{ + return d->formatDuration(mSec); +} + +QString Locale::prettyFormatDuration(unsigned long mSec) const +{ + return d->prettyFormatDuration(mSec); +} + +QString Locale::formatDate(const QDate &date, Locale::DateFormat format) const +{ + return d->formatDate(date, format); +} + +void Locale::setMainCatalog(const char *catalog) +{ + LocalePrivate::setMainCatalog(catalog); +} + +double Locale::readNumber(const QString &_str, bool * ok) const +{ + return d->readNumber(_str, ok); +} + +double Locale::readMoney(const QString &_str, bool *ok) const +{ + return d->readMoney(_str, ok); +} + +QDate Locale::readDate(const QString &intstr, bool *ok) const +{ + return d->readDate(intstr, ok); +} + +QDate Locale::readDate(const QString &intstr, ReadDateFlags flags, bool *ok) const +{ + return d->readDate(intstr, flags, ok); +} + +QDate Locale::readDate(const QString &intstr, const QString &fmt, bool *ok) const +{ + return d->readDate(intstr, fmt, ok); +} + +QTime Locale::readTime(const QString &intstr, bool *ok) const +{ + return d->readTime(intstr, ok); +} + +QTime Locale::readTime(const QString &intstr, Locale::ReadTimeFlags flags, bool *ok) const +{ + return d->readTime(intstr, flags, ok); +} + +QTime Locale::readLocaleTime(const QString &intstr, bool *ok, TimeFormatOptions options, + TimeProcessingOptions processing) const +{ + return d->readLocaleTime(intstr, ok, options, processing); +} + +QString Locale::formatTime(const QTime &time, bool includeSecs, bool isDuration) const +{ + return d->formatTime(time, includeSecs, isDuration); +} + +QString Locale::formatLocaleTime(const QTime &time, TimeFormatOptions options) const +{ + return d->formatLocaleTime(time, options); +} + +bool Locale::use12Clock() const +{ + return d->use12Clock(); +} + +QString Locale::dayPeriodText(const QTime &time, DateTimeComponentFormat format) const +{ + return d->dayPeriodForTime(time).periodName(format); +} + +QStringList Locale::languageList() const +{ + return d->languageList(); +} + +QStringList Locale::currencyCodeList() const +{ + return d->currencyCodeList(); +} + +/* Just copy in for now to keep diff clean, remove later +QString LocalePrivate::formatDateTime(const Locale *locale, const QDateTime &dateTime, Locale::DateFormat format, + bool includeSeconds, int daysTo, int secsTo) +{ +} +*/ + +QString Locale::formatDateTime(const QDateTime &dateTime, Locale::DateFormat format, bool includeSeconds) const +{ + return d->formatDateTime(dateTime, format, includeSeconds); +} + +QString Locale::formatDateTime(const KDateTime &dateTime, Locale::DateFormat format, DateTimeFormatOptions options) const +{ + return d->formatDateTime(dateTime, format, options); +} + +QString Locale::langLookup(const QString &fname, const char *rtype) +{ + return LocalePrivate::langLookup(fname, rtype); +} +void Locale::setDateFormat(const QString &format) +{ + d->setDateFormat(format); +} + +void Locale::setDateFormatShort(const QString &format) +{ + d->setDateFormatShort(format); +} + +void Locale::setDateMonthNamePossessive(bool possessive) +{ + d->setDateMonthNamePossessive(possessive); +} + +void Locale::setTimeFormat(const QString &format) +{ + d->setTimeFormat(format); +} + +void Locale::setWeekStartDay(int day) +{ + d->setWeekStartDay(day); +} + +void Locale::setWorkingWeekStartDay(int day) +{ + d->setWorkingWeekStartDay(day); +} + +void Locale::setWorkingWeekEndDay(int day) +{ + d->setWorkingWeekEndDay(day); +} + +void Locale::setWeekDayOfPray(int day) +{ + d->setWeekDayOfPray(day); +} + +QString Locale::dateFormat() const +{ + return d->dateFormat(); +} + +QString Locale::dateFormatShort() const +{ + return d->dateFormatShort(); +} + +QString Locale::timeFormat() const +{ + return d->timeFormat(); +} + +void Locale::setDecimalPlaces(int digits) +{ + d->setDecimalPlaces(digits); +} + +void Locale::setDecimalSymbol(const QString &symbol) +{ + d->setDecimalSymbol(symbol); +} + +void Locale::setThousandsSeparator(const QString &separator) +{ + d->setThousandsSeparator(separator); +} + +void Locale::setPositiveSign(const QString &sign) +{ + d->setPositiveSign(sign); +} + +void Locale::setNegativeSign(const QString &sign) +{ + d->setNegativeSign(sign); +} + +void Locale::setPositiveMonetarySignPosition(Locale::SignPosition signpos) +{ + d->setPositiveMonetarySignPosition(signpos); +} + +void Locale::setNegativeMonetarySignPosition(Locale::SignPosition signpos) +{ + d->setNegativeMonetarySignPosition(signpos); +} + +void Locale::setPositivePrefixCurrencySymbol(bool prefix) +{ + d->setPositivePrefixCurrencySymbol(prefix); +} + +void Locale::setNegativePrefixCurrencySymbol(bool prefix) +{ + d->setNegativePrefixCurrencySymbol(prefix); +} + +void Locale::setFracDigits(int digits) +{ + setMonetaryDecimalPlaces(digits); +} + +void Locale::setMonetaryDecimalPlaces(int digits) +{ + d->setMonetaryDecimalPlaces(digits); +} + +void Locale::setMonetaryThousandsSeparator(const QString &separator) +{ + d->setMonetaryThousandsSeparator(separator); +} + +void Locale::setMonetaryDecimalSymbol(const QString &symbol) +{ + d->setMonetaryDecimalSymbol(symbol); +} + +void Locale::setCurrencySymbol(const QString & symbol) +{ + d->setCurrencySymbol(symbol); +} + +int Locale::pageSize() const +{ + return d->pageSize(); +} + +void Locale::setPageSize(int size) +{ + d->setPageSize(size); +} + +Locale::MeasureSystem Locale::measureSystem() const +{ + return d->measureSystem(); +} + +void Locale::setMeasureSystem(Locale::MeasureSystem value) +{ + d->setMeasureSystem(value); +} + +QString Locale::defaultLanguage() +{ + return LocalePrivate::defaultLanguage(); +} + +QString Locale::defaultCountry() +{ + return LocalePrivate::defaultCountry(); +} + +QString Locale::defaultCurrencyCode() +{ + return LocalePrivate::defaultCurrencyCode(); +} + +bool Locale::useTranscript() const +{ + return d->useTranscript(); +} + +const QByteArray Locale::encoding() const +{ + return d->encoding(); +} + +int Locale::encodingMib() const +{ + return d->encodingMib(); +} + +int Locale::fileEncodingMib() const +{ + return d->fileEncodingMib(); +} + +QTextCodec *Locale::codecForEncoding() const +{ + return d->codecForEncoding(); +} + +bool Locale::setEncoding(int mibEnum) +{ + return d->setEncoding(mibEnum); +} + +QStringList Locale::allLanguagesList() const +{ + return d->allLanguagesList(); +} + +QStringList Locale::installedLanguages() const +{ + return d->installedLanguages(); +} + +QString Locale::languageCodeToName(const QString &language) const +{ + return d->languageCodeToName(language); +} + +QStringList Locale::allCountriesList() const +{ + return d->allCountriesList(); +} + +QString Locale::countryCodeToName(const QString &country) const +{ + return d->countryCodeToName(country); +} + +void Locale::setCalendar(const QString &calendarType) +{ + d->setCalendar(calendarType); +} + +void Locale::setCalendarSystem(Locale::CalendarSystem calendarSystem) +{ + d->setCalendarSystem(calendarSystem); +} + +QString Locale::calendarType() const +{ + return d->calendarType(); +} + +Locale::CalendarSystem Locale::calendarSystem() const +{ + return d->calendarSystem(); +} + +const KCalendarSystem * Locale::calendar() const +{ + return d->calendar(); +} + +void Locale::setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem) +{ + d->setWeekNumberSystem(weekNumberSystem); +} + +Locale::WeekNumberSystem Locale::weekNumberSystem() +{ + return d->weekNumberSystem(); +} + +Locale::WeekNumberSystem Locale::weekNumberSystem() const +{ + return d->weekNumberSystem(); +} + +Locale::Locale(const Locale &rhs) + : d(new LocalePrivate(*rhs.d)) +{ + d->q = this; +} + +void Locale::copyCatalogsTo(Locale *locale) +{ + d->copyCatalogsTo(locale); +} + +QString Locale::localizedFilePath(const QString &filePath) const +{ + return d->localizedFilePath(filePath); +} + +QString Locale::removeAcceleratorMarker(const QString &label) const +{ + return d->removeAcceleratorMarker(label); +} + +void Locale::setDigitSet(Locale::DigitSet digitSet) +{ + d->setDigitSet(digitSet); +} + +Locale::DigitSet Locale::digitSet() const +{ + return d->digitSet(); +} + +void Locale::setMonetaryDigitSet(Locale::DigitSet digitSet) +{ + d->setMonetaryDigitSet(digitSet); +} + +Locale::DigitSet Locale::monetaryDigitSet() const +{ + return d->monetaryDigitSet(); +} + +void Locale::setDateTimeDigitSet(Locale::DigitSet digitSet) +{ + d->setDateTimeDigitSet(digitSet); +} + +Locale::DigitSet Locale::dateTimeDigitSet() const +{ + return d->dateTimeDigitSet(); +} + +void Locale::reparseConfiguration() +{ + d->initFormat(); +} diff --git a/declarativeimports/core/Locale.h b/declarativeimports/core/Locale.h new file mode 100644 index 000000000..edebc1779 --- /dev/null +++ b/declarativeimports/core/Locale.h @@ -0,0 +1,2069 @@ +/* This file is part of the KDE libraries + Copyright (C) 2012 Giorgos Tsiapaliwkas + Copyright (C) 2012 Antonis Tsiapaliokas + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +#ifndef LOCALE_H +#define LOCALE_H + +#include +#include + +class QStringList; +class QTextCodec; +class QDate; +class QTime; +class QDateTime; + +class KDateTime; +class KCalendarSystem; +class KCurrencyCode; +class KDayPeriod; + +/** + * \file klocale.h + */ + +/** + * + * KLocale provides support for country specific stuff like + * the national language. + * + * KLocale supports translating, as well as specifying the format + * for numbers, currency, time, and date. + * + * Use KGlobal::locale() to get pointer to the global KLocale object, + * containing the applications current locale settings. + * + * For example, to format the date May 17, 1995 in the current locale, use: + * + * \code + * QString date = KGlobal::locale()->formatDate(QDate(1995,5,17)); + * \endcode + * + * @author Stephan Kulow , Preston Brown , + * Hans Petter Bieker , Lukas Tinkl + * @short class for supporting locale settings and national language + */ +class Locale : public QObject +{ +Q_OBJECT + +//enuns +Q_ENUMS(BinarySizeUnits) +Q_ENUMS(BinaryUnitDialect) +Q_ENUMS(CalendarSystem) +Q_ENUMS(DateFormat) +Q_ENUMS(DateTimeComponent) +Q_ENUMS(DateTimeComponentFormat) +Q_ENUMS(DateTimeFormatOption ) +Q_ENUMS(DateTimeFormatStandard) +Q_ENUMS(DateTimeParseMode) +Q_ENUMS(DigitSet) +Q_ENUMS(MeasureSystem) +Q_ENUMS(ReadDateFlags) +Q_ENUMS(ReadTimeFlags) +Q_ENUMS(SignPosition) +Q_ENUMS(TimeFormatOption) +Q_ENUMS(TimeProcessingOption) +Q_ENUMS(WeekNumberSystem) + +//properties +Q_PROPERTY(BinaryUnitDialect binaryUnitDialect READ binaryUnitDialect WRITE setBinaryUnitDialect NOTIFY binaryUnitDialectChanged) +Q_PROPERTY(KCalendarSystem *calendar READ calendar WRITE setCalendar NOTIFY calendarChanged) +Q_PROPERTY(KLocale::CalendarSystem *calendarSystem READ calendarSystem WRITE setCalendarSystem NOTIFY calendarSystemChanged) +Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) +Q_PROPERTY(QString countryDivisionCode READ countryDivisionCode WRITE setCountryDivisionCode NOTIFY countryDivisionCodeChanged) +Q_PROPERTY(QString currencyCode READ currencyCode WRITE setCurrencyCode NOTIFY currencyCodeChanged) +Q_PROPERTY(QString currencySymbol READ currencySymbol WRITE setCurrencySymbol NOTIFY currencySymbolChanged) +Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat NOTIFY dateFormatChanged) +Q_PROPERTY(QString dateFormatShort READ dateFormatShort WRITE setDateFormat NOTIFY dateFormatShortChanged) +Q_PROPERTY(bool dateMonthNamePossessive READ dateMonthNamePossessive WRITE setDateMonthNamePossessive NOTIFY dateMonthNamePossessiveChanged) +Q_PROPERTY(DigitSet dateTimeDigitSet READ dateTimeDigitSet WRITE setDateTimeDigitSet NOTIFY dateTimeDigitSetChanged) +Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces NOTIFY decimalPlacesChanged) +Q_PROPERTY(QString decimalSymbol READ decimalSymbol WRITE setDecimalSymbol NOTIFY decimalSymbolChanged) +Q_PROPERTY(DigitSet digitSet READ digitSet WRITE setDigitSet NOTIFY digitSetChanged) +Q_PROPERTY(QByteArray encoding READ encoding WRITE setEncoding NOTIFY encodingChanged) +Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged) +Q_PROPERTY(MeasureSystem measureSystem READ measureSystem WRITE setMeasureSystem NOTIFY measureSystemChanged) +Q_PROPERTY(int monetaryDecimalPlaces READ monetaryDecimalPlaces WRITE setMonetaryDecimalPlaces NOTIFY monetaryDecimalPlacesChanged) +Q_PROPERTY(QString monetaryDecimalSymbol READ monetaryDecimalSymbol WRITE setMonetaryDecimalSymbol NOTIFY monetaryDecimalSymbolChanged) +Q_PROPERTY(DigitSet monetaryDigitSet READ monetaryDigitSet WRITE setMonetaryDigitSet NOTIFY monetaryDigitSetChanged) +Q_PROPERTY(QString monetaryThousandsSeparator READ monetaryThousandsSeparator WRITE setMonetaryThousandsSeparator NOTIFY monetaryThousandsSeparatorChanged) +Q_PROPERTY(Signals negativeMonetarySignPosition READ negativeMonetarySignPosition WRITE setNegativeMonetarySignPosition NOTIFY negativeMonetarySignPositionChanged) +Q_PROPERTY(bool negativePrefixCurrencySymbol READ negativePrefixCurrencySymbol WRITE setNegativePrefixCurrencySymbol NOTIFY negativePrefixCurrencySymbolChanged) +Q_PROPERTY(QString negativeSign READ negativeSign WRITE setNegativeSign NOTIFY negativeSignChanged) +Q_PROPERTY(int pageSize READ pageSize WRITE setPageSize NOTIFY pageSizeChanged) +Q_PROPERTY(SignPosition positiveMonetarySignPosition READ positiveMonetarySignPosition WRITE setPositiveMonetarySignPosition NOTIFY positiveMonetarySignPositionChanged) +Q_PROPERTY(bool positivePrefixCurrencySymbol READ positivePrefixCurrencySymbol WRITE setPositivePrefixCurrencySymbol NOTIFY positivePrefixCurrencySymbolChanged) +Q_PROPERTY(QString positiveSign READ positiveSign WRITE setPositiveSign NOTIFY positiveSignChanged) +Q_PROPERTY(QString thousandsSeparator READ thousandsSeparator WRITE setThousandsSeparator NOTIFY thousandsSeparatorChanged) +Q_PROPERTY(int weekDayOfPray READ weekDayOfPray WRITE setWeekDayOfPray NOTIFY weekDayOfPrayChanged) +Q_PROPERTY(KLocale::WeekNumberSystem weekNumberSystem READ weekNumberSystem WRITE setWeekNumberSystem NOTIFY WeekNumberSystemChanged) +Q_PROPERTY(int weekStartDay READ weekStartDay WRITE setWeekStartDay NOTIFY weekStartDayChanged) +Q_PROPERTY(int workingWeekEndDay READ workingWeekEndDay WRITE setWorkingWeekEndDay NOTIFY workingWeekEndDayChanged) +Q_PROPERTY(int workingWeekStartDay READ workingWeekStartDay WRITE setWorkingWeekStartDay NOTIFY workingWeekStartDayChanged) + +public: + /** + * Constructs a KLocale with the given catalog name + * + * The constructor looks for an entry Language in the group Locale in the + * configuration file. + * + * If no configuration file is specified, it will also look for languages + * using the environment variables (KDE_LANG, LC_MESSAGES, LC_ALL, LANG), + * as well as the global configuration file. If KLocale is not able to use + * any of the specified languages, the default language (en_US) will be + * used. + * + * If you specify a configuration file, it has to be valid until the KLocale + * object is destroyed. Note that a setLocale() will be performed on the + * config using the current locale language, which may cause a sync() + * and reparseConfiguration() which will save any changes you have made and + * load any changes other shared copies have made. + * + * @param catalog the name of the main language file + * @param config a configuration file with a Locale group detailing + * locale-related preferences (such as language and + * formatting options). + */ + //explicit KLocale(const QString& catalog, KSharedConfig::Ptr config = KSharedConfig::Ptr()); + + /** + * Constructs a KLocale with the given catalog name + * + * Allows you to override the language and, optionally, the + * country of this locale. + * + * If you specify a configuration file, a setLocale() will be performed on + * the config using the current locale language, which may cause a sync() + * and reparseConfiguration() which will save any changes you have made. + * + * @param catalog the name of the main language file + * @param language the ISO Language Code for the locale, e.g. "en" for English + * @param country the ISO Country Code for the locale, e.g. "us" for USA + * @param config a configuration file with a Locale group detailing + * locale-related preferences (such as language and + * formatting options). + */ + /* KLocale(const QString& catalog, const QString &language, const QString &country = QString(), + KConfig *config = 0); + */ + + /** + * Copy constructor + */ + // KLocale(const KLocale & rhs); + + /** + * Destructor + */ + //virtual ~KLocale(); + + /** + * @since 4.5 + * + * Raw translation from a message catalog. + * If catalog name is null or empty, + * all loaded catalogs are searched for the translation. + * + * Never use this directly to get message translations. See the i18n and ki18n + * family of calls related to KLocalizedString. + * + * @param catname the catalog name. Must be UTF-8 encoded. + * @param msg the message. Must not be null or empty. Must be UTF-8 encoded. + * @param lang language in which the translation was found. If no translation + * was found, KLocale::defaultLanguage() is reported. If null, + * the language is not reported. + * @param trans raw translation, or original if not found. If no translation + * was found, original message is reported. If null, the + * translation is not reported. + * + * @see KLocalizedString + */ + Q_INVOKABLE void translateRawFrom(const char* catname, const char* msg, QString *lang, QString *trans) const; + + /** + * @since 4.5 + * + * Raw translation from a message catalog, with given context. + * Context + message are used as the lookup key in the catalog. + * If catalog name is null or empty, + * all loaded catalogs are searched for the translation. + * + * Never use this directly to get message translations. See i18n* and ki18n* + * calls related to KLocalizedString. + * + * @param catname the catalog name. Must be UTF-8 encoded. + * @param ctxt the context. Must not be null. Must be UTF-8 encoded. + * @param msg the message. Must not be null or empty. Must be UTF-8 encoded. + * @param lang language in which the translation was found. If no translation + * was found, KLocale::defaultLanguage() is reported. If null, + * the language is not reported. + * @param trans raw translation, or original if not found. If no translation + * was found, original message is reported. If null, the + * translation is not reported. + * + * @see KLocalizedString + */ + Q_INVOKABLE void translateRawFrom(const char *catname, const char *ctxt, const char *msg, QString *lang, QString *trans) const; + + /** + * @since 4.5 + * + * Raw translation from a message catalog, with given singular/plural form. + * Singular form is used as the lookup key in the catalog. + * If catalog name is null or empty, + * all loaded catalogs are searched for the translation. + * + * Never use this directly to get message translations. See i18n* and ki18n* + * calls related to KLocalizedString. + * + * @param catname the catalog name. Must be UTF-8 encoded. + * @param singular the singular form. Must not be null or empty. Must be UTF-8 encoded. + * @param plural the plural form. Must not be null. Must be UTF-8 encoded. + * @param n number on which the forms are decided. + * @param lang language in which the translation was found. If no translation + * was found, KLocale::defaultLanguage() is reported. If null, + * the language is not reported. + * @param trans raw translation, or original if not found. If no translation + * was found, original message is reported (either plural or + * singular, as determined by @p n ). If null, the + * translation is not reported. + * + * @see KLocalizedString + */ + Q_INVOKABLE void translateRawFrom(const char *catname, const char *singular, const char *plural, unsigned long n, + QString *lang, QString *trans) const; + + /** + * @since 4.5 + * + * Raw translation from a message catalog, with given context and + * singular/plural form. + * Context + singular form is used as the lookup key in the catalog. + * If catalog name is null or empty, + * all loaded catalogs are searched for the translation. + * + * Never use this directly to get message translations. See i18n* and ki18n* + * calls related to KLocalizedString. + * + * @param catname the catalog name. Must be UTF-8 encoded. + * @param ctxt the context. Must not be null. Must be UTF-8 encoded. + * @param singular the singular form. Must not be null or empty. Must be UTF-8 encoded. + * @param plural the plural form. Must not be null. Must be UTF-8 encoded. + * @param n number on which the forms are decided. + * @param lang language in which the translation was found. If no translation + * was found, KLocale::defaultLanguage() is reported. If null, + * the language is not reported. + * @param trans raw translation, or original if not found. If no translation + * was found, original message is reported (either plural or + * singular, as determined by @p n ). If null, the + * translation is not reported. + * + * @see KLocalizedString + */ + Q_INVOKABLE void translateRawFrom(const char *catname, const char *ctxt, const char *singular, const char *plural, + unsigned long n, QString *lang, QString *trans) const; + + /** + * Changes the current encoding. + * + * @param mibEnum The mib of the preferred codec + * + * @return True on success. + */ + bool setEncoding(int mibEnum); + + /** + * Various positions for where to place the positive or negative + * sign when they are related to a monetary value. + */ + enum SignPosition { + /** + * Put parantheses around the quantity, e.g. "$ (217)" + */ + ParensAround = 0, + /** + * Prefix the quantity with the sign, e.g. "$ -217" + */ + BeforeQuantityMoney = 1, + /** + * Suffix the quanitity with the sign, e.g. "$ 217-" + */ + AfterQuantityMoney = 2, + /** + * Prefix the currency symbol with the sign, e.g. "-$ 217" + */ + BeforeMoney = 3, + /** + * Suffix the currency symbol with the sign, e.g. "$- 217" + */ + AfterMoney = 4 + }; + + /** + * @since 4.3 + * + * The set of digit characters used to display and enter numbers. + */ + enum DigitSet { + ArabicDigits, /**< 0123456789 (European and some Asian + languages and western Arabic dialects) */ + ArabicIndicDigits, /**< ٠١٢٣٤٥٦٧٨٩ (eastern Arabic dialects) */ + EasternArabicIndicDigits, /**< ۰۱۲۳۴۵۶۷۸۹ (Persian and Urdu) */ + DevenagariDigits, /**< ०१२३४५६७८९ (Hindi) */ + BengaliDigits, /**< ০১২৩৪৫৬৭৮৯ (Bengali and Assamese) */ + GujaratiDigits, /**< ૦૧૨૩૪૫૬૭૮૯ (Gujarati) */ + GurmukhiDigits, /**< ੦੧੨੩੪੫੬੭੮੯ (Punjabi) */ + KannadaDigits, /**< ೦೧೨೩೪೫೬೭೮೯ (Kannada) */ + KhmerDigits, /**< ០១២៣៤៥៦៧៨៩ (Khmer) */ + MalayalamDigits, /**< ൦൧൨൩൪൫൬൭൮൯ (Malayalam) */ + OriyaDigits, /**< ୦୧୨୩୪୫୬୭୮୯ (Oriya) */ + TamilDigits, /**< ௦௧௨௩௪௫௬௭௮ (Tamil) */ + TeluguDigits, /**< ౦౧౨౩౪౫౬౭౯ (Telugu) */ + ThaiDigits /**< ๐๑๒๓๔๕๖๗๘๙ (Thai) */ + // The following Decimal Digit Sets are defined in Unicode but the associated + // languages are not yet translated in KDE, so are not yet enabled. + // The script names are taken from the Unicode standard, the associated + // languages from Wikipedia. + // BalineseDigits, /**< ᭐᭑᭒᭓᭔᭕᭖᭗᭘᭙ (Balinese) */ + // ChamDigits, /**< ꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙ (Cham) */ + // JavaneseDigits, /**< ꧐꧑꧒꧓꧔꧕꧖꧗꧘꧙ (Javanese) */ + // KayahLiDigits, /**< ꤀꤁꤂꤃꤄꤅꤆꤇꤈꤉ (Kayah) */ + // LaoDigits, /**< ໐໑໒໓໔໕໖໗໘໙ (Lao) */ + // LepchaDigits, /**< ᱀᱁᱂᱃᱄᱅᱆᱇᱈᱉ (Lepcha) */ + // LimbuDigits, /**< ᥆᥇᥈᥉᥊᥋᥌᥍᥎᥏ (Limbu) */ + // MeeteiMayekDigits, /**< ꯰꯱꯲꯳꯴꯵꯶꯷꯸꯹ (Meitei) */ + // MongolianDigits, /**< ᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙ (Mongolian) */ + // MyanmarDigits, /**< ၀၁၂၃၄၅၆၇၈၉ (Myanmar/Burmese ) */ + // MyanmarShanDigits, /**< ႐႑႒႓႔႕႖႗႘႙ (Shan) */ + // NewTaiLueDigits, /**< ᧐᧑᧒᧓᧔᧕᧖᧗᧘᧙ (Tai Lü) */ + // NKoDigits, /**< ߀߁߂߃߄߅߆߇߈߉ (Mande and N'Ko) */ + // OlChikiDigits, /**< ᱐᱑᱒᱓᱔᱕᱖᱗᱘᱙ (Santali) */ + // OsmanyaDigits, /**< ҠҡҢңҤҥҦҧҨҩ (Somali) */ + // SaurashtraDigits, /**< ꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙ (Saurashtra) */ + // SundaneseDigits, /**< ᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹ (Sundanese) */ + // TaiThamDigits, /**< ᪐᪑᪒᪓᪔᪕᪖᪗᪘᪙ (Tai Lü) */ + // TibetanDigits, /**< ༠༡༢༣༤༥༦༧༨༩ (Tibetan) */ + // VaiDigits, /**< ꘠꘡꘢꘣꘤꘥꘦꘧꘨꘩ (Vai) */ + }; + + /** + * @since 4.3 + * + * Convert a digit set identifier to a human readable, localized name. + * + * @param digitSet the digit set identifier + * @param withDigits whether to add the digits themselves to the name + * + * @return the human readable and localized name of the digit set + * + * @see DigitSet + */ + QString digitSetToName(DigitSet digitSet, bool withDigits = false) const; + + /** + * @since 4.3 + * + * Provides list of all known digit set identifiers. + * + * @return list of all digit set identifiers + * @see DigitSet + * @see digitSetToName + */ + Q_INVOKABLE QList allDigitSetsList() const; + + /** + * Returns what a decimal point should look like ("." or "," etc.) + * according to the current locale or user settings. + * + * @return The decimal symbol used by locale. + */ + QString decimalSymbol() const; + + /** + * Returns what the thousands separator should look + * like ("," or "." etc.) + * according to the current locale or user settings. + * + * @return The thousands separator used by locale. + */ + QString thousandsSeparator() const; + + /** + * @since 4.3 + * + * Returns the identifier of the digit set used to display numbers. + * + * @return the digit set identifier + * @see DigitSet + * @see digitSetToName + */ + DigitSet digitSet() const; + + /** + * @since 4.4 + * + * Returns the ISO 4217 Currency Code for the current locale + * + * @return The default ISO Currency Code used by locale. + */ + QString currencyCode() const; + + /** + * @since 4.4 + * + * Returns the Currency Code object for the current locale + * + * @return The default Currency Code object used by locale. + */ + Q_INVOKABLE KCurrencyCode *currency() const; + + /** + * Returns what the symbol denoting currency in the current locale + * as as defined by user settings should look like. + * + * @return The default currency symbol used by locale. + */ + QString currencySymbol() const; + + /** + * Returns what a decimal point should look like ("." or "," etc.) + * for monetary values, according to the current locale or user + * settings. + * + * @return The monetary decimal symbol used by locale. + */ + QString monetaryDecimalSymbol() const; + + /** + * Returns what a thousands separator for monetary values should + * look like ("," or " " etc.) according to the current locale or + * user settings. + * + * @return The monetary thousands separator used by locale. + */ + QString monetaryThousandsSeparator() const; + + /** + * Returns what a positive sign should look like ("+", " ", etc.) + * according to the current locale or user settings. + * + * @return The positive sign used by locale. + */ + QString positiveSign() const; + + /** + * Returns what a negative sign should look like ("-", etc.) + * according to the current locale or user settings. + * + * @return The negative sign used by locale. + */ + QString negativeSign() const; + + /** + * @since 4.4 + * + * The number of decimal places to include in numeric values (usually 2). + * + * @return Default number of numeric decimal places used by locale. + */ + int decimalPlaces() const; + + /** + * @since 4.4 + * + * The number of decimal places to include in monetary values (usually 2). + * + * @return Default number of monetary decimal places used by locale. + */ + int monetaryDecimalPlaces() const; + + /** + * If and only if the currency symbol precedes a positive value, + * this will be true. + * + * @return Where to print the currency symbol for positive numbers. + */ + bool positivePrefixCurrencySymbol() const; + + /** + * If and only if the currency symbol precedes a negative value, + * this will be true. + * + * @return True if the currency symbol precedes negative numbers. + */ + bool negativePrefixCurrencySymbol() const; + + /** + * Returns the position of a positive sign in relation to a + * monetary value. + * + * @return Where/how to print the positive sign. + * @see SignPosition + */ + SignPosition positiveMonetarySignPosition() const; + + /** + * Denotes where to place a negative sign in relation to a + * monetary value. + * + * @return Where/how to print the negative sign. + * @see SignPosition + */ + SignPosition negativeMonetarySignPosition() const; + + /** + * @since 4.3 + * + * Retuns the digit set used to display monetary values. + * + * @return the digit set identifier + * @see DigitSet + * @see digitSetToName + */ + DigitSet monetaryDigitSet() const; + + /** + * Given a double, converts that to a numeric string containing + * the localized monetary equivalent. + * + * e.g. given 123456, return "$ 123,456.00". + * + * If precision isn't specified or is < 0, then the default monetaryDecimalPlaces() is used. + * + * @param num The number we want to format + * @param currency The currency symbol you want. + * @param precision Number of decimal places displayed + * + * @return The number of money as a localized string + * @see monetaryDecimalPlaces() + */ + Q_INVOKABLE QString formatMoney(double num, const QString ¤cy = QString(), int precision = -1) const; + + /** + * Given a double, converts that to a numeric string containing + * the localized numeric equivalent. + * + * e.g. given 123456.78F, return "123,456.78" (for some European country). + * + * If precision isn't specified or is < 0, then the default decimalPlaces() is used. + * + * This function is a wrapper that is provided for convenience. + * + * @param num The number to convert + * @param precision Number of decimal places used. + * + * @return The number as a localized string + * @see formatNumber(const QString, bool, int) + * @see decimalPlaces() + */ + Q_INVOKABLE QString formatNumber(double num, int precision = -1) const; + + /** + * Given a string representing a number, converts that to a numeric + * string containing the localized numeric equivalent. + * + * e.g. given 123456.78F, return "123,456.78" (for some European country). + * + * If precision isn't specified or is < 0, then the default decimalPlaces() is used. + * + * @param numStr The number to format, as a string. + * @param round Round fractional digits. (default true) + * @param precision Number of fractional digits used for rounding. Unused if round=false. + * + * @return The number as a localized string + */ + Q_INVOKABLE QString formatNumber(const QString &numStr, bool round = true, int precision = -1) const; + + /** + * Given an integer, converts that to a numeric string containing + * the localized numeric equivalent. + * + * e.g. given 123456L, return "123,456" (for some European country). + * + * @param num The number to convert + * + * @return The number as a localized string + */ + Q_INVOKABLE QString formatLong(long num) const; + + /** + * These binary units are used in KDE by the formatByteSize() + * functions. + * + * NOTE: There are several different units standards: + * 1) SI (i.e. metric), powers-of-10. + * 2) IEC, powers-of-2, with specific units KiB, MiB, etc. + * 3) JEDEC, powers-of-2, used for solid state memory sizing which + * is why you see flash cards labels as e.g. 4GB. These (ab)use + * the metric units. Although JEDEC only defines KB, MB, GB, if + * JEDEC is selected all units will be powers-of-2 with metric + * prefixes for clarity in the event of sizes larger than 1024 GB. + * + * Although 3 different dialects are possible this enum only uses + * metric names since adding all 3 different names of essentially the same + * unit would be pointless. Use BinaryUnitDialect to control the exact + * units returned. + * + * @since 4.4 + * @see binaryUnitDialect + */ + enum BinarySizeUnits { + /// Auto-choose a unit such that the result is in the range [0, 1000 or 1024) + DefaultBinaryUnits = -1, + + // The first real unit must be 0 for the current implementation! + UnitByte, ///< B 1 byte + UnitKiloByte, ///< KiB/KB/kB 1024/1000 bytes. + UnitMegaByte, ///< MiB/MB/MB 2^20/10^06 bytes. + UnitGigaByte, ///< GiB/GB/GB 2^30/10^09 bytes. + UnitTeraByte, ///< TiB/TB/TB 2^40/10^12 bytes. + UnitPetaByte, ///< PiB/PB/PB 2^50/10^15 bytes. + UnitExaByte, ///< EiB/EB/EB 2^60/10^18 bytes. + UnitZettaByte, ///< ZiB/ZB/ZB 2^70/10^21 bytes. + UnitYottaByte, ///< YiB/YB/YB 2^80/10^24 bytes. + UnitLastUnit = UnitYottaByte + }; + + /** + * This enum chooses what dialect is used for binary units. + * + * Note: Although JEDEC abuses the metric prefixes and can therefore be + * confusing, it has been used to describe *memory* sizes for quite some time + * and programs should therefore use either Default, JEDEC, or IEC 60027-2 + * for memory sizes. + * + * On the other hand network transmission rates are typically in metric so + * Default, Metric, or IEC (which is unambiguous) should be chosen. + * + * Normally choosing DefaultBinaryUnits is the best option as that uses + * the user's selection for units. + * + * @since 4.4 + * @see binaryUnitDialect + * @see setBinaryUnitDialect + */ + enum BinaryUnitDialect { + DefaultBinaryDialect = -1, ///< Used if no specific preference + IECBinaryDialect, ///< KDE Default, KiB, MiB, etc. 2^(10*n) + JEDECBinaryDialect, ///< KDE 3.5 default, KB, MB, etc. 2^(10*n) + MetricBinaryDialect, ///< SI Units, kB, MB, etc. 10^(3*n) + LastBinaryDialect = MetricBinaryDialect + }; + + /** + * Converts @p size from bytes to the string representation using the + * user's default binary unit dialect. The default unit dialect is + * IEC 60027-2. + * + * Example: + * formatByteSize(1024) returns "1.0 KiB" by default. + * + * @param size size in bytes + * @return converted size as a string - e.g. 123.4 KiB , 12.0 MiB + * @see BinaryUnitDialect + * @todo KDE 5: Remove in favor of overload added in KDE 4.4. + */ + Q_INVOKABLE QString formatByteSize(double size) const; + + /** + * @since 4.4 + * + * Converts @p size from bytes to the appropriate string representation + * using the binary unit dialect @p dialect and the specific units @p specificUnit. + * + * Example: + * formatByteSize(1000, unit, KLocale::BinaryUnitKilo) returns: + * for KLocale::MetricBinaryUnits, "1.0 kB", + * for KLocale::IECBinaryUnits, "0.9 KiB", + * for KLocale::JEDECBinaryUnits, "0.9 KB". + * + * @param size size in bytes + * @param precision number of places after the decimal point to use. KDE uses + * 1 by default so when in doubt use 1. + * @param dialect binary unit standard to use. Use DefaultBinaryUnits to + * use the localized user selection unless you need to use a specific + * unit type (such as displaying a flash memory size in JEDEC). + * @param specificUnit specific unit size to use in result. Use + * DefaultBinarySize to automatically select a unit that will return + * a sanely-sized number. + * @return converted size as a translated string including the units. + * E.g. "1.23 KiB", "2 GB" (JEDEC), "4.2 kB" (Metric). + * @see BinaryUnitDialect + */ + QString formatByteSize(double size, int precision, + BinaryUnitDialect dialect = KLocale::DefaultBinaryDialect, + BinarySizeUnits specificUnit = KLocale::DefaultBinaryUnits) const; + + /** + * Returns the user's configured binary unit dialect. + * e.g. if MetricBinaryDialect is returned then the values + * configured for how much a set of bytes are worth would + * be 10^(3*n) and KB (1000 bytes == 1 KB), in this case. + * + * Will never return DefaultBinaryDialect. + * + * @since 4.4 + * @return User's configured binary unit dialect + * @see BinaryUnitDialect + */ + BinaryUnitDialect binaryUnitDialect() const; + + /** + * Sets @p newDialect to be the default dialect for this locale (and only + * this locale). Newly created KLocale objects will continue to default + * to the user's choice. + * + * @param newDialect the new dialect to set as default for this locale object. + * @since 4.4 + */ + void setBinaryUnitDialect(BinaryUnitDialect newDialect); + + /** + * Given a number of milliseconds, converts that to a string containing + * the localized equivalent + * + * e.g. given formatDuration(60000), returns "1.0 minutes" + * + * @param mSec Time duration in milliseconds + * @return converted duration as a string - e.g. "5.5 seconds" "23.0 minutes" + */ + Q_INVOKABLE QString formatDuration(unsigned long mSec) const; + + /** + * Given a number of milliseconds, converts that to a pretty string containing + * the localized equivalent. + * + * e.g. given prettyFormatDuration(60001) returns "1 minute" + * given prettyFormatDuration(62005) returns "1 minute and 2 seconds" + * given prettyFormatDuration(90060000) returns "1 day and 1 hour" + * + * @param mSec Time duration in milliseconds + * @return converted duration as a string. + * Units not interesting to the user, for example seconds or minutes when the first + * unit is day, are not returned because they are irrelevant. The same applies for + * seconds when the first unit is hour. + * @since 4.2 + */ + Q_INVOKABLE QString prettyFormatDuration(unsigned long mSec) const; + + //KDE5 move to KDateTime namespace + /** + * @since 4.6 + * + * Available Calendar Systems + * + * @see setCalendarSystem() + * @see calendarSystem() + */ + enum CalendarSystem { + QDateCalendar = 1, /**< KDE Default, hybrid of Gregorian and Julian as used by QDate */ + //BahaiCalendar = 2, /**< Baha'i Calendar */ + //BuddhistLunarCalendar = 3, /**< Buddhist Lunar Calendar*/ + //ChineseCalendar = 4, /**< Chinese Calendar */ + CopticCalendar = 5, /**< Coptic Calendar as used Coptic Church and some parts of Egypt */ + EthiopianCalendar = 6, /**< Ethiopian Calendar, aka Ethiopic Calendar */ + //EthiopianAmeteAlemCalendar = 7, /**< Ethiopian Amete Alem version, aka Ethiopic Amete Alem */ + GregorianCalendar = 8, /**< Gregorian Calendar, pure proleptic implementation */ + HebrewCalendar = 9, /**< Hebrew Calendar, aka Jewish Calendar */ + //HinduCalendar = 10, /**< Hindu Lunar Calendar */ + //IslamicLunarCalendar = 11, /**< Islamic Lunar Calendar */ + IslamicCivilCalendar = 12, /**< Islamic Civil Calendar, aka Hijri, not the Lunar Calendar */ + //IslamicUmAlQuraCalendar = 13, /**< Islamic Lunar Calendar, Um Al Qura varient used in Saudi Arabia */ + IndianNationalCalendar = 14, /**< Indian National Calendar, not the Lunar Calendar */ + //Iso8601Calendar = 15, /**< ISO 8601 Standard Calendar */ + JalaliCalendar = 16, /**< Jalali Calendar, aka Persian or Iranian, also used in Afghanistan */ + //JalaliBirashkCalendar = 17, /**< Jalali Calendar, Birashk Algorythm variant */ + //Jalali33YearCalendar = 18, /**< Jalali Calendar, 33 Year cycle variant */ + JapaneseCalendar= 19, /**< Japanese Calendar, Gregorian calculation using Japanese Era (Nengô) */ + //JucheCalendar = 20, /**< Juche Calendar, used in North Korea */ + JulianCalendar = 21, /**< Julian Calendar, as used in Orthodox Churches */ + MinguoCalendar= 22, /**< Minguo Calendar, aka ROC, Republic of China or Taiwanese */ + ThaiCalendar = 23 /**< Thai Calendar, aka Buddhist or Thai Buddhist */ + }; + + //KDE5 move to KDateTime namespace + /** + * @since 4.6 + * + * System used for Week Numbers + * + * @see setWeekNumberSystem() + * @see weekNumberSystem() + */ + enum WeekNumberSystem { + DefaultWeekNumber = -1, /**< The system locale default */ + IsoWeekNumber = 0, /**< ISO Week Number */ + FirstFullWeek = 1, /**< Week 1 starts on the first Week Start Day in year ends after 7 days */ + FirstPartialWeek = 2, /**< Week 1 starts Jan 1st ends day before first Week Start Day in year */ + SimpleWeek = 3 /**< Week 1 starts Jan 1st ends after 7 days */ + }; + + //KDE5 move to KDateTime namespace + /** + * @since 4.4 + * + * Standard used for Date Time Format String + */ + enum DateTimeFormatStandard { + KdeFormat, /**< KDE Standard */ + PosixFormat, /**< POSIX Standard */ + UnicodeFormat /**< UNICODE Standard (Qt/Java/OSX/Windows) */ + }; + + //KDE5 move to KDateTime namespace + /** + * @since 4.6 + * + * Mode to use when parsing a Date Time input string + */ + enum DateTimeParseMode { + LiberalParsing /**< Parse Date/Time liberally. So long as the + input string contains at least a reconizable + month and day the input will be accepted. */ + //ModerateParsing, /**< Parse Date/Time with modeate tolerance. + // The date components in the format must all + // occur in the input and in the same order, + // but the spacing and the componants themselves + // may vary from the strict format. */ + //StrictParsing /**< Parse Date/Time strictly to the format. */ + }; + + //KDE5 move to KDateTime namespace + /** + * @since 4.6 + * + * The various Components that make up a Date / Time + * In the future the Components may be combined as flags for dynamic + * generation of Date Formats. + * + * @see KCalendarSystem + * @see KLocalizedDate + * @see DateTimeComponentFormat + */ + enum DateTimeComponent { + Year = 0x1, /**< The Year portion of a date, may be number or name */ + YearName = 0x2, /**< The Year Name portion of a date */ + Month = 0x4, /**< The Month portion of a date, may be number or name */ + MonthName = 0x8, /**< The Month Name portion of a date */ + Day = 0x10, /**< The Day portion of a date, may be number or name */ + DayName = 0x20, /**< The Day Name portion of a date */ + JulianDay = 0x40, /**< The Julian Day of a date */ + EraName = 0x80, /**< The Era Name portion of a date */ + EraYear = 0x100, /**< The Era and Year portion of a date */ + YearInEra = 0x200, /**< The Year In Era portion of a date */ + DayOfYear = 0x400, /**< The Day Of Year portion of a date, may be number or name */ + DayOfYearName = 0x800, /**< The Day Of Year Name portion of a date */ + DayOfWeek = 0x1000, /**< The Day Of Week / Weekday portion of a date, may be number or name */ + DayOfWeekName = 0x2000, /**< The Day Of Week Name / Weekday Name portion of a date */ + Week = 0x4000, /**< The Week Number portion of a date */ + WeekYear = 0x8000, /**< The Week Year portion of a date */ + MonthsInYear = 0x10000, /**< The Months In Year portion of a date */ + WeeksInYear = 0x20000, /**< The Weeks In Year portion of a date */ + DaysInYear = 0x40000, /**< The Days In Year portion of a date */ + DaysInMonth = 0x80000, /**< The Days In Month portion of a date */ + DaysInWeek = 0x100000, /**< The Days In Week portion of a date */ + Hour = 0x200000, /**< The Hours portion of a date */ + Minute = 0x400000, /**< The Minutes portion of a date */ + Second = 0x800000, /**< The Seconds portion of a date */ + Millisecond = 0x1000000, /**< The Milliseconds portion of a date */ + DayPeriod = 0x2000000, /**< The Day Period portion of a date, e.g. AM/PM */ + DayPeriodHour = 0x4000000, /**< The Day Period Hour portion of a date */ + Timezone = 0x8000000, /**< The Time Zone portion of a date, may be offset or name */ + TimezoneName = 0x10000000, /**< The Time Zone Name portion of a date */ + UnixTime = 0x20000000 /**< The UNIX Time portion of a date */ + }; + + //KDE5 move to KDateTime namespace + /** + * @since 4.6 + * + * Format used for individual Date/Time Components when converted to/from a string + * Largely equivalent to the UNICODE CLDR format width definitions 1..5 + * + * @see DateTimeComponentFormat + */ + enum DateTimeComponentFormat { + DefaultComponentFormat = -1, /**< The system locale default for the componant */ + ShortNumber = 0, /**< Number at its natural width, e.g. 2 for the 2nd*/ + LongNumber, /**< Number padded to a required width, e.g. 02 for the 2nd*/ + //OrdinalNumber /**< Ordinal number format, e.g. "2nd" for the 2nd */ + NarrowName = 3, /**< Narrow text format, may not be unique, e.g. M for Monday */ + ShortName, /**< Short text format, e.g. Mon for Monday */ + LongName /**< Long text format, e.g. Monday for Monday */ + }; + + //KDE5 move to KDateTime namespace + /** + * Format for date string. + */ + enum DateFormat { + ShortDate, /**< Locale Short date format, e.g. 08-04-2007 */ + LongDate, /**< Locale Long date format, e.g. Sunday 08 April 2007 */ + FancyShortDate, /**< Same as ShortDate for dates a week or more ago. For more + recent dates, it is represented as Today, Yesterday, or + the weekday name. */ + FancyLongDate, /**< Same as LongDate for dates a week or more ago. For more + recent dates, it is represented as Today, Yesterday, or + the weekday name. */ + IsoDate, /**< ISO-8601 Date format YYYY-MM-DD, e.g. 2009-12-31 */ + IsoWeekDate, /**< ISO-8601 Week Date format YYYY-Www-D, e.g. 2009-W01-1 */ + IsoOrdinalDate /**< ISO-8601 Ordinal Date format YYYY-DDD, e.g. 2009-001 */ + }; + + //KDE5 move to KDateTime namespace + /** + * Returns a string formatted to the current locale's conventions + * regarding dates. + * + * @param date the date to be formatted + * @param format category of date format to use + * + * @return the date as a string + */ + Q_INVOKABLE QString formatDate(const QDate &date, DateFormat format = LongDate) const; + + //KDE5 move to KDateTime namespace + /** + * Returns a string formatted to the current locale's conventions + * regarding both date and time. + * + * @param dateTime the date and time to be formatted + * @param format category of date format to use + * @param includeSecs if @c true, the string will include the seconds part + * of the time; otherwise, the seconds will be omitted + * + * @return the date and time as a string + */ + Q_INVOKABLE QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate, + bool includeSecs = false) const; + + //KDE5 move to KDateTime namespace + /** + * Options for formatting date-time values. + */ + enum DateTimeFormatOption { + TimeZone = 0x01, /**< Include a time zone string */ + Seconds = 0x02 /**< Include the seconds value */ + }; + + //KDE5 move to KDateTime namespace + /** + * Returns a string formatted to the current locale's conventions + * regarding both date and time. + * + * @param dateTime the date and time to be formatted + * @param format category of date format to use + * @param options additional output options + * + * @return The date and time as a string + */ + Q_INVOKABLE QString formatDateTime(const KDateTime &dateTime, DateFormat format = ShortDate, + DateTimeFormatOptions options = 0) const; + + /** + * Use this to determine whether in dates a possessive form of month + * name is preferred ("of January" rather than "January") + * + * @return If possessive form should be used + */ + bool dateMonthNamePossessive() const; + + /** + * @since 4.4 + * + * Format flags for readLocaleTime() and formatLocaleTime() + */ + enum TimeFormatOption { + TimeDefault = 0x0, ///< Default formatting using seconds and the format + ///< as specified by the locale. + TimeWithoutSeconds = 0x1, ///< Exclude the seconds part of the time from display + TimeWithoutAmPm = 0x2, ///< Read/format time string without am/pm suffix but + ///< keep the 12/24h format as specified by locale time + ///< format, eg. "07.33.05" instead of "07.33.05 pm" for + ///< time format "%I.%M.%S %p". + TimeDuration = 0x6, ///< Read/format time string as duration. This will strip + ///< the am/pm suffix and read/format times with an hour + ///< value of 0-23 hours, eg. "19.33.05" instead of + ///< "07.33.05 pm" for time format "%I.%M.%S %p". + ///< This automatically implies @c TimeWithoutAmPm. + TimeFoldHours = 0xE ///< Read/format time string as duration. This will not + ///< not output the hours part of the duration but will + ///< add the hours (times sixty) to the number of minutes, + ///< eg. "70.23" instead of "01.10.23" for time format + ///< "%I.%M.%S %p". + }; + + //KDE5 move to KDateTime namespace + /** + * @since 4.4 + * + * Returns a string formatted to the current locale's conventions + * regarding times. + * + * @param pTime the time to be formatted + * @param options format option to use when formatting the time + * @return The time as a string + */ + Q_INVOKABLE QString formatLocaleTime(const QTime &pTime, + TimeFormatOptions options = KLocale::TimeDefault) const; + + /** + * @since 4.3 + * + * Returns the identifier of the digit set used to display dates and time. + * + * @return the digit set identifier + * @see DigitSet + * @see digitSetToName + */ + DigitSet dateTimeDigitSet() const; + + /** + * Use this to determine if the user wants a 12 hour clock. + * + * @return If the user wants 12h clock + */ + Q_INVOKABLE bool use12Clock() const; + + /** + * @since 4.6 + * + * Returns the Day Period matching the time given + * + * @param time the time to return the day period for + * @param format the format to return teh day period in + * @return the Day Period for the given time + */ + Q_INVOKABLE QString dayPeriodText(const QTime &time, DateTimeComponentFormat format = DefaultComponentFormat) const; + + /** + * Use this to determine which day is the first day of the week. + * + * @return an integer (Monday=1..Sunday=7) + */ + int weekStartDay() const; + + /** + * Use this to determine which day is the first working day of the week. + * + * @since 4.2 + * @return an integer (Monday=1..Sunday=7) + */ + int workingWeekStartDay() const; + + /** + * Use this to determine which day is the last working day of the week. + * + * @since 4.2 + * @return an integer (Monday=1..Sunday=7) + */ + int workingWeekEndDay() const; + + /** + * Use this to determine which day is reserved for religious observance + * + * @since 4.2 + * @return day number (None = 0, Monday = 1, ..., Sunday = 7) + */ + int weekDayOfPray() const; + + /** + * Returns a pointer to the calendar system object. + * + * @return the current calendar system instance + */ + const KCalendarSystem * calendar() const; + + /** + * @since 4.6 + * + * Returns the type of Calendar System used in this Locale + * + * @see KLocale::CalendarSystem + * @see KCalendarSystem + * @return the type of Calendar System + */ + KLocale::CalendarSystem calendarSystem() const; + + /** + * @since 4.6 + * + * Sets the type of Calendar System to use in this Locale + * + * @see KLocale::CalendarSystem + * @see KCalendarSystem + * @param calendarSystem the Calendar System to use + */ + void setCalendarSystem(KLocale::CalendarSystem calendarSystem); + + /** + * @since 4.6 + * + * Sets the type of Week Number System to use in this Locale + * + * @see Klocale::WeekNumberSystem + * @see weekNumberSystem() + * @param weekNumberSystem the Week Number System to use + */ + void setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem); + + //KDE5 remove in favour of const version + /** + * @since 4.6 + * + * Returns the type of Week Number System used in this Locale + * + * @see Klocale::WeekNumberSystem + * @see setWeekNumberSystem() + * @returns the Week Number System used + */ + KLocale::WeekNumberSystem weekNumberSystem(); + + /** + * @since 4.7 + * + * Returns the type of Week Number System used in this Locale + * + * @see Klocale::WeekNumberSystem + * @see setWeekNumberSystem() + * @returns the Week Number System used + */ + KLocale::WeekNumberSystem weekNumberSystem() const; + + /** + * Converts a localized monetary string to a double. + * + * @param numStr the string we want to convert. + * @param ok the boolean that is set to false if it's not a number. + * If @p ok is 0, it will be ignored + * + * @return The string converted to a double + */ + Q_INVOKABLE double readMoney(const QString &numStr, bool * ok = 0) const; + + /** + * Converts a localized numeric string to a double. + * + * @param numStr the string we want to convert. + * @param ok the boolean that is set to false if it's not a number. + * If @p ok is 0, it will be ignored + * + * @return The string converted to a double + */ + Q_INVOKABLE double readNumber(const QString &numStr, bool * ok = 0) const; + + //KDE5 move to KDateTime namespace + /** + * Converts a localized date string to a QDate. This method will try all + * ReadDateFlag formats in preferred order to read a valid date. + * + * The bool pointed by ok will be invalid if the date entered was not valid. + * + * @param str the string we want to convert. + * @param ok the boolean that is set to false if it's not a valid date. + * If @p ok is 0, it will be ignored + * + * @return The string converted to a QDate + * @see KCalendarSystem::readDate() + */ + Q_INVOKABLE QDate readDate(const QString &str, bool* ok = 0) const; + + //KDE5 move to KDateTime namespace + /** + * Converts a localized date string to a QDate, using the specified format. + * You will usually not want to use this method. + * @see KCalendarSystem::readDate() + */ + Q_INVOKABLE QDate readDate(const QString &intstr, const QString &fmt, bool* ok = 0) const; + + //KDE5 move to KDateTime namespace + /** + * Flags for readDate() + */ + enum ReadDateFlags { + NormalFormat = 1, /**< Only accept a date string in + the locale LongDate format */ + ShortFormat = 2, /**< Only accept a date string in + the locale ShortDate format */ + IsoFormat = 4, /**< Only accept a date string in + ISO date format (YYYY-MM-DD) */ + IsoWeekFormat = 8, /**< Only accept a date string in + ISO Week date format (YYYY-Www-D) */ + IsoOrdinalFormat = 16 /**< Only accept a date string in + ISO Week date format (YYYY-DDD) */ + }; + + //KDE5 move to KDateTime namespace + /** + * Converts a localized date string to a QDate. + * This method is stricter than readDate(str,&ok): it will only accept + * a date in a specific format, depending on @p flags. + * + * @param str the string we want to convert. + * @param flags what format the the date string will be in + * @param ok the boolean that is set to false if it's not a valid date. + * If @p ok is 0, it will be ignored + * + * @return The string converted to a QDate + * @see KCalendarSystem::readDate() + */ + Q_INVOKABLE QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; + + /** + * Converts a localized time string to a QTime. + * This method will try to parse it with seconds, then without seconds. + * The bool pointed to by @p ok will be set to false if the time entered was + * not valid. + * + * @param str the string we want to convert. + * @param ok the boolean that is set to false if it's not a valid time. + * If @p ok is 0, it will be ignored + * + * @return The string converted to a QTime + */ + Q_INVOKABLE QTime readTime(const QString &str, bool* ok = 0) const; + + /** + * Additional processing options for readLocaleTime(). + * + * @remarks This is currently used as an enum but declared as a flag + * to be extensible + */ + enum TimeProcessingOption { + ProcessStrict = 0x1, ///< Process time in a strict manner, ie. + ///< a read time string has to exactly match + ///< the defined time format. + ProcessNonStrict = 0x2 ///< Process time in a lax manner, ie. + ///< allow spaces in the time-format to be + ///< left out when entering a time string. + }; + + /** + * @since 4.4 + * + * Converts a localized time string to a QTime. + * This method is stricter than readTime(str, &ok) in that it will either + * accept a time with seconds or a time without seconds. + * + * @param str the string we want to convert + * @param ok the boolean that is set to false if it's not a valid time. + * If @p ok is 0, it will be ignored. + * @param options format option to apply when formatting the time + * @param processing if set to @c ProcessStrict, checking will be strict + * and the read time string has to have the exact time format + * specified. If set to @c ProcessNonStrict processing the time + * is lax and spaces in the time string can be left out. + * + * @return The string converted to a QTime + */ + Q_INVOKABLE QTime readLocaleTime(const QString &str, bool *ok = 0, + TimeFormatOptions options = KLocale::TimeDefault, + TimeProcessingOptions processing = ProcessNonStrict) const; + + /** + * Returns the language code used by this object. The domain AND the + * library translation must be available in this language. + * defaultLanguage() is returned by default, if no other available. + * + * Use languageCodeToName(language) to get human readable, localized + * language name. + * + * @return the currently used language code + * + * @see languageCodeToName + */ + QString language() const; + + /** + * Returns the country code of the country where the user lives. + * + * The returned code complies with the ISO 3166-1 alpha-2 standard, + * except by KDE convention it is returned in lowercase whereas the + * official standard is uppercase. + * See http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for details. + * + * defaultCountry() is returned by default, if no other available, + * this will always be uppercase 'C'. + * + * Use countryCodeToName(country) to get human readable, localized + * country names. + * + * @return the country code for the user + * + * @see countryCodeToName + */ + QString country() const; + + /** + * @since 4.6 + * + * Returns the Country Division Code of the Country where the user lives. + * When no value is set, then the Country Code will be returned. + * + * The returned code complies with the ISO 3166-2 standard. + * See http://en.wikipedia.org/wiki/ISO_3166-2 for details. + * + * Note that unlike country() this method will return the correct case, + * i.e. normally uppercase.. + * + * In KDE 4.6 it is the apps responsibility to obtain a translation for the + * code, translation and other services will be priovided in KDE 4.7. + * + * @return the Country Division Code for the user + * @see setCountryDivisionCode + */ + QString countryDivisionCode() const; + + /** + * Returns the language codes selected by user, ordered by decreasing + * priority. + * + * Use languageCodeToName(language) to get human readable, localized + * language name. + * + * @return list of language codes + * + * @see languageCodeToName + */ + Q_INVOKABLE QStringList languageList() const; + + /** + * @since 4.4 + * + * Returns the ISO Currency Codes used in the locale, ordered by decreasing + * priority. + * + * Use KCurrency::currencyCodeToName(currencyCode) to get human readable, + * localized language name. + * + * @return list of ISO Currency Codes + * + * @see currencyCodeToName + */ + Q_INVOKABLE QStringList currencyCodeList() const; + + /** + * Returns the user's preferred encoding. + * + * @return The name of the preferred encoding + * + * @see codecForEncoding + * @see encodingMib + */ + const QByteArray encoding() const; + + /** + * Returns the user's preferred encoding. + * + * @return The Mib of the preferred encoding + * + * @see encoding + * @see codecForEncoding + */ + Q_INVOKABLE int encodingMib() const; + + /** + * Returns the user's preferred encoding. Should never be NULL. + * + * @return The codec for the preferred encoding + * + * @see encoding + * @see encodingMib + */ + Q_INVOKABLE QTextCodec *codecForEncoding() const; + + /** + * Returns the file encoding. + * + * @return The Mib of the file encoding + * + * @see QFile::encodeName + * @see QFile::decodeName + */ + Q_INVOKABLE int fileEncodingMib() const; + + /** + * Changes the current date format. + * + * The format of the date is a string which contains variables that will + * be replaced: + * @li %Y with the whole year (e.g. "2004" for "2004") + * @li %y with the lower 2 digits of the year (e.g. "04" for "2004") + * @li %n with the month (January="1", December="12") + * @li %m with the month with two digits (January="01", December="12") + * @li %e with the day of the month (e.g. "1" on the first of march) + * @li %d with the day of the month with two digits (e.g. "01" on the first of march) + * @li %b with the short form of the month (e.g. "Jan" for January) + * @li %B with the long form of the month (e.g. "January") + * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday) + * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday) + * + * Everything else in the format string will be taken as is. + * For example, March 20th 1989 with the format "%y:%m:%d" results + * in "89:03:20". + * + * @param format The new date format + */ + void setDateFormat(const QString & format); + + /** + * Changes the current short date format. + * + * The format of the date is a string which contains variables that will + * be replaced: + * @li %Y with the whole year (e.g. "1984" for "1984") + * @li %y with the lower 2 digits of the year (e.g. "84" for "1984") + * @li %n with the month (January="1", December="12") + * @li %m with the month with two digits (January="01", December="12") + * @li %e with the day of the month (e.g. "1" on the first of march) + * @li %d with the day of the month with two digits(e.g. "01" on the first of march) + * @li %b with the short form of the month (e.g. "Jan" for January) + * @li %B with the long form of the month (e.g. "January") + * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday) + * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday) + * + * Everything else in the format string will be taken as is. + * For example, March 20th 1989 with the format "%y:%m:%d" results + * in "89:03:20". + * + * @param format The new short date format + */ + void setDateFormatShort(const QString & format); + + /** + * Changes the form of month name used in dates. + * + * @param possessive True if possessive forms should be used + */ + void setDateMonthNamePossessive(bool possessive); + + /** + * Changes the current time format. + * + * The format of the time is string a which contains variables that will + * be replaced: + * @li %H with the hour in 24h format and 2 digits (e.g. 5pm is "17", 5am is "05") + * @li %k with the hour in 24h format and one digits (e.g. 5pm is "17", 5am is "5") + * @li %I with the hour in 12h format and 2 digits (e.g. 5pm is "05", 5am is "05") + * @li %l with the hour in 12h format and one digits (e.g. 5pm is "5", 5am is "5") + * @li %M with the minute with 2 digits (e.g. the minute of 07:02:09 is "02") + * @li %S with the seconds with 2 digits (e.g. the minute of 07:02:09 is "09") + * @li %p with pm or am (e.g. 17.00 is "pm", 05.00 is "am") + * + * Everything else in the format string will be taken as is. + * For example, 5.23pm with the format "%H:%M" results + * in "17:23". + * + * @param format The new time format + */ + void setTimeFormat(const QString & format); + + /** + * @since 4.3 + * + * Set digit characters used to display dates and time. + * + * @param digitSet the digit set identifier + * @see DigitSet + */ + void setDateTimeDigitSet(DigitSet digitSet); + + /** + * Changes how KLocale defines the first day in week. + * + * @param day first day of the week (Monday=1..Sunday=7) as integer + */ + void setWeekStartDay(int day); + + /** + * Changes how KLocale defines the first working day in week. + * + * @since 4.2 + * @param day first working day of the week (Monday=1..Sunday=7) as integer + */ + void setWorkingWeekStartDay(int day); + + /** + * Changes how KLocale defines the last working day in week. + * + * @since 4.2 + * @param day last working day of the week (Monday=1..Sunday=7) as integer + */ + void setWorkingWeekEndDay(int day); + + /** + * Changes how KLocale defines the day reserved for religious observance. + * + * @since 4.2 + * @param day day of the week for religious observance (None=0,Monday=1..Sunday=7) as integer + */ + void setWeekDayOfPray(int day); + + /** + * Returns the currently selected date format. + * + * @return Current date format. + * @see setDateFormat() + */ + QString dateFormat() const; + + /** + * Returns the currently selected short date format. + * + * @return Current short date format. + * @see setDateFormatShort() + */ + QString dateFormatShort() const; + + /** + * Returns the currently selected time format. + * + * @return Current time format. + * @see setTimeFormat() + */ + QString timeFormat() const; + + /** + * Changes the symbol used to identify the decimal pointer. + * + * @param symbol The new decimal symbol. + */ + void setDecimalSymbol(const QString & symbol); + + /** + * Changes the separator used to group digits when formating numbers. + * + * @param separator The new thousands separator. + */ + void setThousandsSeparator(const QString & separator); + + /** + * Changes the sign used to identify a positive number. Normally this is + * left blank. + * + * @param sign Sign used for positive numbers. + */ + void setPositiveSign(const QString & sign); + + /** + * Changes the sign used to identify a negative number. + * + * @param sign Sign used for negative numbers. + */ + void setNegativeSign(const QString & sign); + + /** + * @since 4.3 + * + * Changes the set of digit characters used to display numbers. + * + * @param digitSet the digit set identifier + * @see DigitSet + */ + void setDigitSet(DigitSet digitSet); + + /** + * Changes the sign position used for positive monetary values. + * + * @param signpos The new sign position + */ + void setPositiveMonetarySignPosition(SignPosition signpos); + + /** + * Changes the sign position used for negative monetary values. + * + * @param signpos The new sign position + */ + void setNegativeMonetarySignPosition(SignPosition signpos); + + /** + * Changes the position where the currency symbol should be printed for + * positive monetary values. + * + * @param prefix True if the currency symbol should be prefixed instead of + * postfixed + */ + void setPositivePrefixCurrencySymbol(bool prefix); + + /** + * Changes the position where the currency symbol should be printed for + * negative monetary values. + * + * @param prefix True if the currency symbol should be prefixed instead of + * postfixed + */ + void setNegativePrefixCurrencySymbol(bool prefix); + + /** + * @since 4.4 + * + * Changes the number of decimal places used when formating numbers. + * + * @param digits The default number of digits to use. + */ + void setDecimalPlaces(int digits); + + /** + * @since 4.4 + * + * Changes the number of decimal places used when formating money. + * + * @param digits The default number of digits to use. + */ + void setMonetaryDecimalPlaces(int digits); + + /** + * Changes the separator used to group digits when formating monetary values. + * + * @param separator The new thousands separator. + */ + void setMonetaryThousandsSeparator(const QString & separator); + + /** + * Changes the symbol used to identify the decimal pointer for monetary + * values. + * + * @param symbol The new decimal symbol. + */ + void setMonetaryDecimalSymbol(const QString & symbol); + + /** + * @since 4.4 + * + * Changes the current ISO Currency Code. + * + * @param newCurrencyCode The new Currency Code + */ + void setCurrencyCode(const QString &newCurrencyCode); + + /** + * Changes the current currency symbol. + * + * This symbol should be consistant with the selected Currency Code + * + * @param symbol The new currency symbol + * @see currencyCode, KCurrency::currencySymbols + */ + void setCurrencySymbol(const QString & symbol); + + /** + * @since 4.3 + * + * Set digit characters used to display monetary values. + * + * @param digitSet the digit set identifier + * @see DigitSet + */ + void setMonetaryDigitSet(DigitSet digitSet); + + /** + * Returns the preferred page size for printing. + * + * @return The preferred page size, cast it to QPrinter::PageSize + */ + int pageSize() const; + + /** + * Changes the preferred page size when printing. + * + * @param paperFormat the new preferred page size in the format QPrinter::PageSize + */ + void setPageSize(int paperFormat); + + /** + * The Metric system will give you information in mm, while the + * Imperial system will give you information in inches. + */ + enum MeasureSystem { + Metric, ///< Metric system (used e.g. in Europe) + Imperial ///< Imperial system (used e.g. in the United States) + }; + + /** + * Returns which measuring system we use. + * + * @return The preferred measuring system + */ + MeasureSystem measureSystem() const; + + /** + * Changes the preferred measuring system. + * + * @return value The preferred measuring system + */ + void setMeasureSystem(MeasureSystem value); + + /** + * Adds another catalog to search for translation lookup. + * This function is useful for extern libraries and/or code, + * that provide their own messages. + * + * If the catalog does not exist for the chosen language, + * it will be ignored and en_US will be used. + * + * @param catalog The catalog to add. + */ + Q_INVOKABLE void insertCatalog(const QString& catalog); + + /** + * Removes a catalog for translation lookup. + * @param catalog The catalog to remove. + * @see insertCatalog() + */ + Q_INVOKABLE void removeCatalog(const QString &catalog); + + /** + * Sets the active catalog for translation lookup. + * @param catalog The catalog to activate. + */ + Q_INVOKABLE void setActiveCatalog(const QString &catalog); + + /** + * Translates a message as a QTranslator is supposed to. + * The parameters are similar to i18n(), but the result + * value has other semantics (it can be QString()) + */ + Q_INVOKABLE QString translateQt(const char *context, const char *sourceText, const char *comment) const; + + /** + * Provides list of all known language codes. + * + * Use languageCodeToName(language) to get human readable, localized + * language names. + * + * @return list of all language codes + * + * @see languageCodeToName + * @see installedLanguages + */ + Q_INVOKABLE QStringList allLanguagesList() const; + + /** + * @since 4.6 + * + * Provides list of all installed KDE Language Translations. + * + * Use languageCodeToName(language) to get human readable, localized + * language names. + * + * @return list of all installed language codes + * + * @see languageCodeToName + */ + Q_INVOKABLE QStringList installedLanguages() const; + + /** + * Convert a known language code to a human readable, localized form. + * If an unknown language code is supplied, empty string is returned; + * this will never happen if the code has been obtained by one of the + * KLocale methods. + * + * @param language the language code + * + * @return the human readable and localized form if the code is known, + * empty otherwise + * + * @see language + * @see languageList + * @see allLanguagesList + * @see installedLanguages + */ + Q_INVOKABLE QString languageCodeToName(const QString &language) const; + + /** + * Provides list of all known country codes. + * + * Use countryCodeToName(country) to get human readable, localized + * country names. + * + * @return a list of all country codes + * + * @see countryCodeToName + */ + Q_INVOKABLE QStringList allCountriesList() const; + + /** + * Convert a known country code to a human readable, localized form. + * + * If an unknown country code is supplied, empty string is returned; + * this will never happen if the code has been obtained by one of the + * KLocale methods. + * + * @param country the country code + * + * @return the human readable and localized form of the country name + * + * @see country + * @see allCountriesList + */ + Q_INVOKABLE QString countryCodeToName(const QString &country) const; + + /** + * Parses locale string into distinct parts. + * The format of locale is language_COUNTRY@modifier.CHARSET + * + * @param locale the locale string to split + * @param language set to the language part of the locale + * @param country set to the country part of the locale + * @param modifier set to the modifer part of the locale + * @param charset set to the charset part of the locale + */ + Q_INVOKABLE static void splitLocale(const QString &locale, QString &language, QString &country, + QString &modifier, QString &charset); + + /** + * Use this as main catalog for *all* KLocales, if not the appname + * will be used. This function is best to be the very first instruction + * in your program's main function as it only has an effect before the + * first KLocale object is created. + * + * @param catalog Catalog to override all other main Catalogs. + */ + Q_INVOKABLE static void setMainCatalog(const char *catalog); + + /** + * Returns the name of the internal language. + * + * @return Name of the default language + */ + Q_INVOKABLE static QString defaultLanguage(); + + /** + * Returns the code of the default country, i.e. "C" + * + * This function will not provide a sensible value to use in your app, + * please use country() instead. + * + * @see country + * + * @return Name of the default country + */ + Q_INVOKABLE static QString defaultCountry(); + + /** + * @since 4.4 + * + * Returns the ISO Code of the default currency. + * + * @return ISO Currency Code of the default currency + */ + Q_INVOKABLE static QString defaultCurrencyCode(); + + /** + * Reports whether evaluation of translation scripts is enabled. + * + * @return true if script evaluation is enabled, false otherwise. + */ + Q_INVOKABLE bool useTranscript() const; + + /** + * Checks whether or not the active catalog is found for the given language. + * + * @param language language to check + */ + Q_INVOKABLE bool isApplicationTranslatedInto(const QString & language); + + /** + * Copies the catalogs of this object to an other KLocale object. + * + * @param locale the destination KLocale object + */ + Q_INVOKABLE void copyCatalogsTo(KLocale *locale); + + /** + * Changes the current country. The current country will be left + * unchanged if failed. It will force a reload of the country specific + * configuration. + * + * An empty country value will set the country to the system default. + * + * If you specify a configuration file, a setLocale() will be performed on + * the config using the current locale language, which may cause a sync() + * and reparseConfiguration() which will save any changes you have made. + * + * @param country the ISO 3166 country code + * @param config a configuration file with a Locale group detailing + * locale-related preferences (such as language and + * formatting options). + * + * @return @c true on success, @c false on failure + */ + bool setCountry(const QString & country, KConfig *config); + + /** + * @since 4.6 + * + * Sets the Country Division Code of the Country where the user lives. + * + * The code must comply with the ISO 3166-2 standard. + * See http://en.wikipedia.org/wiki/ISO_3166-2 for details. + * + * In KDE 4.6 it is the apps responsibility to validate the input, + * full validation and other services will be provided in KDE 4.7. + * + * @param countryDivision the Country Division Code for the user + * @return @c true on success, @c false on failure + * @see countryDivisionCode + */ + bool setCountryDivisionCode(const QString & countryDivision); + + /** + * Changes the current language. The current language will be left + * unchanged if failed. It will force a reload of the country specific + * configuration as well. + * + * If you specify a configuration file, a setLocale() will be performed on + * the config using the current locale language, which may cause a sync() + * and reparseConfiguration() which will save any changes you have made. + * + * @param language the language code + * @param config a configuration file with a Locale group detailing + * locale-related preferences (such as language and + * formatting options). + * + * @return true on success + */ + bool setLanguage(const QString &language, KConfig *config); + + /** + * Changes the list of preferred languages for the locale. The first valid + * language in the list will be used, or the default language (en_US) + * if none of the specified languages were available. + * + * @param languages the list of language codes + * + * @return true if one of the specified languages were used + */ + bool setLanguage(const QStringList &languages); + + /** + * @since 4.1 + * + * Tries to find a path to the localized file for the given original path. + * This is intended mainly for non-text resources (images, sounds, etc.), + * whereas text resources should be handled in more specific ways. + * + * The possible localized paths are checked in turn by priority of set + * languages, in form of dirname/l10n/ll/basename, where dirname and + * basename are those of the original path, and ll is the language code. + * + * KDE core classes which resolve paths internally (e.g. KStandardDirs) + * will usually perform this lookup behind the scene. + * In general, you should pipe resource paths through this method only + * on explicit translators' request, or when a resource is an obvious + * candidate for localization (e.g. a splash screen or a custom icon + * with some text drawn on it). + * + * @param filePath path to the original file + * + * @return path to the localized file if found, original path otherwise + */ + Q_INVOKABLE QString localizedFilePath(const QString &filePath) const; + + /** + * @since 4.2 + * + * Removes accelerator marker from a UI text label. + * + * Accelerator marker is not always a plain ampersand (&), + * so it is not enough to just remove it by @c QString::remove(). + * The label may contain escaped markers ("&&") which must be resolved + * and skipped, as well as CJK-style markers ("Foo (&F)") where + * the whole parenthesis construct should be removed. + * Therefore always use this function to remove accelerator marker + * from UI labels. + * + * @param label UI label which may contain an accelerator marker + * @return label without the accelerator marker + */ + Q_INVOKABLE QString removeAcceleratorMarker(const QString &label) const; + + /** + * @since 4.3 + * + * Convert all digits in the string to the given digit set. + * + * Conversion is normally not performed if the given digit set + * is not appropriate in the current locale and language context. + * Unconditional conversion may be requested by setting + * @p ignoreContext to @c true. + * + * @param str the string to convert + * @param digitSet the digit set identifier + * @param ignoreContext unconditional conversion if @c true + * + * @return string with converted digits + * + * @see DigitSet + */ + Q_INVOKABLE QString convertDigits(const QString &str, DigitSet digitSet, + bool ignoreContext = false) const; + + /** + * @since 4.8 + * + * Reparse locale configuration files for the current selected + * language. + */ + void reparseConfiguration(); + +private: + KLocale *const d; + +Q_SIGNALS: + void binaryUnitDialectChanged(); + void calendarChanged(); + void calendarSystemChanged(); + void countryChanged(); + void countryDivisionCodeChanged(); + void currencyCodeChanged(); + void currencySymbolChanged(); + void dateFormatChanged(); + void dateFormatShortChanged(); + void dateMonthNamePossessiveChanged(); + void dateTimeDigitSetChanged(); + void decimalPlacesChanged(); + void digitSetChanged(); + void encodingChanged(); + void fracDigitsChanged(); + void languageChanged(); + void measureSystemChanged(); + void monetaryDecimalPlacesChanged(); + void monetaryDecimalSymbolChanged(); + void monetaryDigitSetChanged(); + void monetaryThousandsSeparatorChanged(); + void negativeMonetarySignPositionChanged(); + void negativePrefixCurrencySymbolChanged(); + void negativeSignChanged(); + void pageSizeChanged(); + void positiveMonetarySignPositionChanged(); + void positivePrefixCurrencySymbolChanged(); + void positiveSignChanged(); + void thousandsSeparatorChanged(); + void timeFormatChanged(); + void weekDayOfPrayChanged(); + void WeekNumberSystemChanged(); + void weekStartDayChanged(); + void workingWeekEndDayChanged(); + void workingWeekStartDayChanged(); +}; + +#endif diff --git a/declarativeimports/core/corebindingsplugin.cpp b/declarativeimports/core/corebindingsplugin.cpp index f08d8b36d..4fd65c8ad 100644 --- a/declarativeimports/core/corebindingsplugin.cpp +++ b/declarativeimports/core/corebindingsplugin.cpp @@ -38,6 +38,7 @@ #include "dialog.h" #include "tooltip.h" #include "dataenginebindings_p.h" +#include "Locale.h" void CoreBindingsPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri) { @@ -80,6 +81,8 @@ void CoreBindingsPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 0, 1, "Dialog"); qmlRegisterType(uri, 0, 1, "ToolTip"); + qmlRegisterType(uri, 0, 1, "Locale"); + qmlRegisterInterface("Service"); qRegisterMetaType("Service"); qmlRegisterInterface("ServiceJob"); From de5edc80b1a921556f9242c1e46855ca6047a9da Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 15 Jan 2012 09:38:34 +0200 Subject: [PATCH 002/104] Add emit fooChanged() into the setters,and some small changes --- declarativeimports/core/Locale.cpp | 56 +++++++++++++++++++++++++----- declarativeimports/core/Locale.h | 3 +- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/declarativeimports/core/Locale.cpp b/declarativeimports/core/Locale.cpp index 0529565f3..57d821aeb 100644 --- a/declarativeimports/core/Locale.cpp +++ b/declarativeimports/core/Locale.cpp @@ -18,7 +18,7 @@ Boston, MA 02110-1301, USA. */ -#include "locale.h" +#include "Locale.h" /*Locale::Locale(const QString &catalog, KSharedConfig::Ptr config) #if defined Q_WS_WIN @@ -50,26 +50,31 @@ Locale::~Locale() bool Locale::setCountry(const QString &country, KConfig *config) { return d->setCountry(country, config); + emit countryChanged(); } bool Locale::setCountryDivisionCode(const QString &countryDivisionCode) { return d->setCountryDivisionCode(countryDivisionCode); + emit countryDivisionCodeChanged(); } bool Locale::setLanguage(const QString &language, KConfig *config) { return d->setLanguage(language, config); + emit languageChanged(); } bool Locale::setLanguage(const QStringList &languages) { return d->setLanguage(languages); + emit languageChanged(); } void Locale::setCurrencyCode(const QString &newCurrencyCode) { d->setCurrencyCode(newCurrencyCode); + emit currencyCodeChanged(); } bool Locale::isApplicationTranslatedInto(const QString &lang) @@ -80,7 +85,7 @@ bool Locale::isApplicationTranslatedInto(const QString &lang) void Locale::splitLocale(const QString &locale, QString &language, QString &country, QString &modifier, QString &charset) { - LocalePrivate::splitLocale(locale, language, country, modifier, charset); + Locale::splitLocale(locale, language, country, modifier, charset); } QString Locale::language() const @@ -237,6 +242,7 @@ QString Locale::thousandsSeparator() const QString Locale::currencySymbol() const { return d->currencySymbol(); + emit currencySymbolChanged(); } QString Locale::monetaryDecimalSymbol() const @@ -328,6 +334,7 @@ Locale::BinaryUnitDialect Locale::binaryUnitDialect() const void Locale::setBinaryUnitDialect(Locale::BinaryUnitDialect newDialect) { d->setBinaryUnitDialect(newDialect); + emit binaryUnitDialectChanged(); } QString Locale::formatDuration(unsigned long mSec) const @@ -347,7 +354,7 @@ QString Locale::formatDate(const QDate &date, Locale::DateFormat format) const void Locale::setMainCatalog(const char *catalog) { - LocalePrivate::setMainCatalog(catalog); + Locale::setMainCatalog(catalog); } double Locale::readNumber(const QString &_str, bool * ok) const @@ -422,7 +429,7 @@ QStringList Locale::currencyCodeList() const } /* Just copy in for now to keep diff clean, remove later -QString LocalePrivate::formatDateTime(const Locale *locale, const QDateTime &dateTime, Locale::DateFormat format, +QString Locale::formatDateTime(const Locale *locale, const QDateTime &dateTime, Locale::DateFormat format, bool includeSeconds, int daysTo, int secsTo) { } @@ -440,46 +447,54 @@ QString Locale::formatDateTime(const KDateTime &dateTime, Locale::DateFormat for QString Locale::langLookup(const QString &fname, const char *rtype) { - return LocalePrivate::langLookup(fname, rtype); + return Locale::langLookup(fname, rtype); } void Locale::setDateFormat(const QString &format) { d->setDateFormat(format); + emit dateFormatChanged(); } void Locale::setDateFormatShort(const QString &format) { d->setDateFormatShort(format); + emit dateFormatShortChanged(); } void Locale::setDateMonthNamePossessive(bool possessive) { d->setDateMonthNamePossessive(possessive); + emit dateMonthNamePossessiveChanged(); } void Locale::setTimeFormat(const QString &format) { d->setTimeFormat(format); + emit timeFormatChanged(); } void Locale::setWeekStartDay(int day) { d->setWeekStartDay(day); + emit weekStartDayChanged(); } void Locale::setWorkingWeekStartDay(int day) { d->setWorkingWeekStartDay(day); + emit workingWeekStartDayChanged(); } void Locale::setWorkingWeekEndDay(int day) { d->setWorkingWeekEndDay(day); + emit workingWeekEndDayChanged(); } void Locale::setWeekDayOfPray(int day) { d->setWeekDayOfPray(day); + emit weekDayOfPrayChanged(); } QString Locale::dateFormat() const @@ -500,71 +515,85 @@ QString Locale::timeFormat() const void Locale::setDecimalPlaces(int digits) { d->setDecimalPlaces(digits); + emit decimalPlacesChanged(); } void Locale::setDecimalSymbol(const QString &symbol) { d->setDecimalSymbol(symbol); + emit decimalSymbolChanged(); } void Locale::setThousandsSeparator(const QString &separator) { d->setThousandsSeparator(separator); + emit thousandsSeparatorChanged(); } void Locale::setPositiveSign(const QString &sign) { d->setPositiveSign(sign); + emit positiveSignChanged(); } void Locale::setNegativeSign(const QString &sign) { d->setNegativeSign(sign); + emit negativeSignChanged(); } void Locale::setPositiveMonetarySignPosition(Locale::SignPosition signpos) { d->setPositiveMonetarySignPosition(signpos); + emit positiveMonetarySignPositionChanged(); } void Locale::setNegativeMonetarySignPosition(Locale::SignPosition signpos) { d->setNegativeMonetarySignPosition(signpos); + emit negativeMonetarySignPositionChanged(); } void Locale::setPositivePrefixCurrencySymbol(bool prefix) { d->setPositivePrefixCurrencySymbol(prefix); + emit positivePrefixCurrencySymbolChanged(); } void Locale::setNegativePrefixCurrencySymbol(bool prefix) { d->setNegativePrefixCurrencySymbol(prefix); + emit negativePrefixCurrencySymbolChanged(); } void Locale::setFracDigits(int digits) { setMonetaryDecimalPlaces(digits); + emit monetaryDecimalPlacesChanged(); } void Locale::setMonetaryDecimalPlaces(int digits) { d->setMonetaryDecimalPlaces(digits); + emit monetaryDecimalPlacesChanged(); } void Locale::setMonetaryThousandsSeparator(const QString &separator) { d->setMonetaryThousandsSeparator(separator); + emit monetaryThousandsSeparatorChanged(); } void Locale::setMonetaryDecimalSymbol(const QString &symbol) { d->setMonetaryDecimalSymbol(symbol); + emit monetaryDecimalSymbolChanged(); } void Locale::setCurrencySymbol(const QString & symbol) { d->setCurrencySymbol(symbol); + emit currencySymbolChanged(); } int Locale::pageSize() const @@ -575,6 +604,7 @@ int Locale::pageSize() const void Locale::setPageSize(int size) { d->setPageSize(size); + emit pageSizeChanged(); } Locale::MeasureSystem Locale::measureSystem() const @@ -585,21 +615,22 @@ Locale::MeasureSystem Locale::measureSystem() const void Locale::setMeasureSystem(Locale::MeasureSystem value) { d->setMeasureSystem(value); + emit measureSystemChanged(); } QString Locale::defaultLanguage() { - return LocalePrivate::defaultLanguage(); + return Locale::defaultLanguage(); } QString Locale::defaultCountry() { - return LocalePrivate::defaultCountry(); + return Locale::defaultCountry(); } QString Locale::defaultCurrencyCode() { - return LocalePrivate::defaultCurrencyCode(); + return Locale::defaultCurrencyCode(); } bool Locale::useTranscript() const @@ -630,6 +661,7 @@ QTextCodec *Locale::codecForEncoding() const bool Locale::setEncoding(int mibEnum) { return d->setEncoding(mibEnum); + emit encodingChanged(); } QStringList Locale::allLanguagesList() const @@ -660,11 +692,13 @@ QString Locale::countryCodeToName(const QString &country) const void Locale::setCalendar(const QString &calendarType) { d->setCalendar(calendarType); + emit calendarChanged(); } void Locale::setCalendarSystem(Locale::CalendarSystem calendarSystem) { d->setCalendarSystem(calendarSystem); + emit calendarSystemChanged(); } QString Locale::calendarType() const @@ -685,6 +719,7 @@ const KCalendarSystem * Locale::calendar() const void Locale::setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem) { d->setWeekNumberSystem(weekNumberSystem); + emit WeekNumberSystemChanged(); } Locale::WeekNumberSystem Locale::weekNumberSystem() @@ -698,7 +733,7 @@ Locale::WeekNumberSystem Locale::weekNumberSystem() const } Locale::Locale(const Locale &rhs) - : d(new LocalePrivate(*rhs.d)) + : d(new Locale(*rhs.d)) { d->q = this; } @@ -721,6 +756,7 @@ QString Locale::removeAcceleratorMarker(const QString &label) const void Locale::setDigitSet(Locale::DigitSet digitSet) { d->setDigitSet(digitSet); + emit digitSetChanged(); } Locale::DigitSet Locale::digitSet() const @@ -731,6 +767,7 @@ Locale::DigitSet Locale::digitSet() const void Locale::setMonetaryDigitSet(Locale::DigitSet digitSet) { d->setMonetaryDigitSet(digitSet); + emit monetaryDigitSetChanged(); } Locale::DigitSet Locale::monetaryDigitSet() const @@ -741,6 +778,7 @@ Locale::DigitSet Locale::monetaryDigitSet() const void Locale::setDateTimeDigitSet(Locale::DigitSet digitSet) { d->setDateTimeDigitSet(digitSet); + emit dateTimeDigitSetChanged(); } Locale::DigitSet Locale::dateTimeDigitSet() const diff --git a/declarativeimports/core/Locale.h b/declarativeimports/core/Locale.h index edebc1779..de80abbc8 100644 --- a/declarativeimports/core/Locale.h +++ b/declarativeimports/core/Locale.h @@ -104,7 +104,7 @@ Q_PROPERTY(int monetaryDecimalPlaces READ monetaryDecimalPlaces WRITE setMonetar Q_PROPERTY(QString monetaryDecimalSymbol READ monetaryDecimalSymbol WRITE setMonetaryDecimalSymbol NOTIFY monetaryDecimalSymbolChanged) Q_PROPERTY(DigitSet monetaryDigitSet READ monetaryDigitSet WRITE setMonetaryDigitSet NOTIFY monetaryDigitSetChanged) Q_PROPERTY(QString monetaryThousandsSeparator READ monetaryThousandsSeparator WRITE setMonetaryThousandsSeparator NOTIFY monetaryThousandsSeparatorChanged) -Q_PROPERTY(Signals negativeMonetarySignPosition READ negativeMonetarySignPosition WRITE setNegativeMonetarySignPosition NOTIFY negativeMonetarySignPositionChanged) +Q_PROPERTY(SignPosition negativeMonetarySignPosition READ negativeMonetarySignPosition WRITE setNegativeMonetarySignPosition NOTIFY negativeMonetarySignPositionChanged) Q_PROPERTY(bool negativePrefixCurrencySymbol READ negativePrefixCurrencySymbol WRITE setNegativePrefixCurrencySymbol NOTIFY negativePrefixCurrencySymbolChanged) Q_PROPERTY(QString negativeSign READ negativeSign WRITE setNegativeSign NOTIFY negativeSignChanged) Q_PROPERTY(int pageSize READ pageSize WRITE setPageSize NOTIFY pageSizeChanged) @@ -2035,6 +2035,7 @@ Q_SIGNALS: void countryChanged(); void countryDivisionCodeChanged(); void currencyCodeChanged(); + void decimalSymbolChanged(); void currencySymbolChanged(); void dateFormatChanged(); void dateFormatShortChanged(); From 5477037f6854f2c0b861b408c8c2c384bd210911 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 15 Jan 2012 09:44:24 +0200 Subject: [PATCH 003/104] Add some TODO and remove some comments --- declarativeimports/core/Locale.cpp | 42 +++++++++--------------------- declarativeimports/core/Locale.h | 2 +- 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/declarativeimports/core/Locale.cpp b/declarativeimports/core/Locale.cpp index 57d821aeb..9a3427a3a 100644 --- a/declarativeimports/core/Locale.cpp +++ b/declarativeimports/core/Locale.cpp @@ -20,27 +20,7 @@ #include "Locale.h" -/*Locale::Locale(const QString &catalog, KSharedConfig::Ptr config) -#if defined Q_WS_WIN - : d(new LocaleWindowsPrivate(this, catalog, config)) -#elif defined Q_OS_MAC - : d(new LocaleMacPrivate(this, catalog, config)) -#else - : d(new LocaleUnixPrivate(this, catalog, config)) -#endif -{ -} - -Locale::Locale(const QString& catalog, const QString &language, const QString &country, KConfig *config) -#if defined Q_WS_WIN - : d(new LocaleWindowsPrivate(this, catalog, language, country, config)) -#elif defined Q_OS_MAC - : d(new LocaleMacPrivate(this, catalog, language, country, config)) -#else - : d(new LocaleUnixPrivate(this, catalog, language, country, config)) -#endif -{ -}*/ +//TODO we need some ctors Locale::~Locale() { @@ -413,10 +393,11 @@ bool Locale::use12Clock() const return d->use12Clock(); } -QString Locale::dayPeriodText(const QTime &time, DateTimeComponentFormat format) const +//TODO fix it! +/*QString Locale::dayPeriodText(const QTime &time, DateTimeComponentFormat format) const { return d->dayPeriodForTime(time).periodName(format); -} +}*/ QStringList Locale::languageList() const { @@ -445,10 +426,12 @@ QString Locale::formatDateTime(const KDateTime &dateTime, Locale::DateFormat for return d->formatDateTime(dateTime, format, options); } -QString Locale::langLookup(const QString &fname, const char *rtype) +//TODO fix it +/*QString Locale::langLookup(const QString &fname, const char *rtype) { return Locale::langLookup(fname, rtype); -} +}*/ + void Locale::setDateFormat(const QString &format) { d->setDateFormat(format); @@ -732,11 +715,11 @@ Locale::WeekNumberSystem Locale::weekNumberSystem() const return d->weekNumberSystem(); } -Locale::Locale(const Locale &rhs) +/*Locale::Locale(const Locale &rhs) : d(new Locale(*rhs.d)) { d->q = this; -} +}*/ void Locale::copyCatalogsTo(Locale *locale) { @@ -786,7 +769,8 @@ Locale::DigitSet Locale::dateTimeDigitSet() const return d->dateTimeDigitSet(); } -void Locale::reparseConfiguration() +//TODO fix it! +/*void Locale::reparseConfiguration() { d->initFormat(); -} +}*/ diff --git a/declarativeimports/core/Locale.h b/declarativeimports/core/Locale.h index de80abbc8..c11345bf9 100644 --- a/declarativeimports/core/Locale.h +++ b/declarativeimports/core/Locale.h @@ -173,7 +173,7 @@ public: /** * Destructor */ - //virtual ~KLocale(); + virtual ~Locale(); /** * @since 4.5 From 36faf40a02efa26e0d8479ad62875bf1dc1c7c09 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 16 Jan 2012 19:58:35 +0200 Subject: [PATCH 004/104] fix some of the TODOs --- declarativeimports/core/Locale.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/declarativeimports/core/Locale.cpp b/declarativeimports/core/Locale.cpp index 9a3427a3a..ddd0269d9 100644 --- a/declarativeimports/core/Locale.cpp +++ b/declarativeimports/core/Locale.cpp @@ -393,11 +393,10 @@ bool Locale::use12Clock() const return d->use12Clock(); } -//TODO fix it! -/*QString Locale::dayPeriodText(const QTime &time, DateTimeComponentFormat format) const +QString Locale::dayPeriodText(const QTime &time, DateTimeComponentFormat format) const { - return d->dayPeriodForTime(time).periodName(format); -}*/ + return d->dayPeriodText(time, format); +} QStringList Locale::languageList() const { @@ -426,11 +425,10 @@ QString Locale::formatDateTime(const KDateTime &dateTime, Locale::DateFormat for return d->formatDateTime(dateTime, format, options); } -//TODO fix it -/*QString Locale::langLookup(const QString &fname, const char *rtype) +QString Locale::langLookup(const QString &fname, const char *rtype) { - return Locale::langLookup(fname, rtype); -}*/ + return KLocale::langLookup(fname, rtype); +} void Locale::setDateFormat(const QString &format) { @@ -769,8 +767,7 @@ Locale::DigitSet Locale::dateTimeDigitSet() const return d->dateTimeDigitSet(); } -//TODO fix it! -/*void Locale::reparseConfiguration() +void Locale::reparseConfiguration() { - d->initFormat(); -}*/ + d->reparseConfiguration(); +} From 35e1620759ff0db12ebabcc9ef68f20b4a2e1f8a Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Wed, 18 Jan 2012 18:12:41 +0200 Subject: [PATCH 005/104] remove the "@since" --- declarativeimports/core/Locale.h | 56 -------------------------------- 1 file changed, 56 deletions(-) diff --git a/declarativeimports/core/Locale.h b/declarativeimports/core/Locale.h index c11345bf9..437c9b496 100644 --- a/declarativeimports/core/Locale.h +++ b/declarativeimports/core/Locale.h @@ -176,7 +176,6 @@ public: virtual ~Locale(); /** - * @since 4.5 * * Raw translation from a message catalog. * If catalog name is null or empty, @@ -199,7 +198,6 @@ public: Q_INVOKABLE void translateRawFrom(const char* catname, const char* msg, QString *lang, QString *trans) const; /** - * @since 4.5 * * Raw translation from a message catalog, with given context. * Context + message are used as the lookup key in the catalog. @@ -224,7 +222,6 @@ public: Q_INVOKABLE void translateRawFrom(const char *catname, const char *ctxt, const char *msg, QString *lang, QString *trans) const; /** - * @since 4.5 * * Raw translation from a message catalog, with given singular/plural form. * Singular form is used as the lookup key in the catalog. @@ -252,7 +249,6 @@ public: QString *lang, QString *trans) const; /** - * @since 4.5 * * Raw translation from a message catalog, with given context and * singular/plural form. @@ -318,7 +314,6 @@ public: }; /** - * @since 4.3 * * The set of digit characters used to display and enter numbers. */ @@ -365,7 +360,6 @@ public: }; /** - * @since 4.3 * * Convert a digit set identifier to a human readable, localized name. * @@ -379,7 +373,6 @@ public: QString digitSetToName(DigitSet digitSet, bool withDigits = false) const; /** - * @since 4.3 * * Provides list of all known digit set identifiers. * @@ -407,7 +400,6 @@ public: QString thousandsSeparator() const; /** - * @since 4.3 * * Returns the identifier of the digit set used to display numbers. * @@ -418,7 +410,6 @@ public: DigitSet digitSet() const; /** - * @since 4.4 * * Returns the ISO 4217 Currency Code for the current locale * @@ -427,7 +418,6 @@ public: QString currencyCode() const; /** - * @since 4.4 * * Returns the Currency Code object for the current locale * @@ -478,7 +468,6 @@ public: QString negativeSign() const; /** - * @since 4.4 * * The number of decimal places to include in numeric values (usually 2). * @@ -487,7 +476,6 @@ public: int decimalPlaces() const; /** - * @since 4.4 * * The number of decimal places to include in monetary values (usually 2). * @@ -530,7 +518,6 @@ public: SignPosition negativeMonetarySignPosition() const; /** - * @since 4.3 * * Retuns the digit set used to display monetary values. * @@ -622,7 +609,6 @@ public: * unit would be pointless. Use BinaryUnitDialect to control the exact * units returned. * - * @since 4.4 * @see binaryUnitDialect */ enum BinarySizeUnits { @@ -656,7 +642,6 @@ public: * Normally choosing DefaultBinaryUnits is the best option as that uses * the user's selection for units. * - * @since 4.4 * @see binaryUnitDialect * @see setBinaryUnitDialect */ @@ -684,7 +669,6 @@ public: Q_INVOKABLE QString formatByteSize(double size) const; /** - * @since 4.4 * * Converts @p size from bytes to the appropriate string representation * using the binary unit dialect @p dialect and the specific units @p specificUnit. @@ -720,7 +704,6 @@ public: * * Will never return DefaultBinaryDialect. * - * @since 4.4 * @return User's configured binary unit dialect * @see BinaryUnitDialect */ @@ -732,7 +715,6 @@ public: * to the user's choice. * * @param newDialect the new dialect to set as default for this locale object. - * @since 4.4 */ void setBinaryUnitDialect(BinaryUnitDialect newDialect); @@ -760,13 +742,11 @@ public: * Units not interesting to the user, for example seconds or minutes when the first * unit is day, are not returned because they are irrelevant. The same applies for * seconds when the first unit is hour. - * @since 4.2 */ Q_INVOKABLE QString prettyFormatDuration(unsigned long mSec) const; //KDE5 move to KDateTime namespace /** - * @since 4.6 * * Available Calendar Systems * @@ -801,7 +781,6 @@ public: //KDE5 move to KDateTime namespace /** - * @since 4.6 * * System used for Week Numbers * @@ -818,7 +797,6 @@ public: //KDE5 move to KDateTime namespace /** - * @since 4.4 * * Standard used for Date Time Format String */ @@ -830,7 +808,6 @@ public: //KDE5 move to KDateTime namespace /** - * @since 4.6 * * Mode to use when parsing a Date Time input string */ @@ -848,7 +825,6 @@ public: //KDE5 move to KDateTime namespace /** - * @since 4.6 * * The various Components that make up a Date / Time * In the future the Components may be combined as flags for dynamic @@ -893,7 +869,6 @@ public: //KDE5 move to KDateTime namespace /** - * @since 4.6 * * Format used for individual Date/Time Components when converted to/from a string * Largely equivalent to the UNICODE CLDR format width definitions 1..5 @@ -987,7 +962,6 @@ public: bool dateMonthNamePossessive() const; /** - * @since 4.4 * * Format flags for readLocaleTime() and formatLocaleTime() */ @@ -1013,7 +987,6 @@ public: //KDE5 move to KDateTime namespace /** - * @since 4.4 * * Returns a string formatted to the current locale's conventions * regarding times. @@ -1026,7 +999,6 @@ public: TimeFormatOptions options = KLocale::TimeDefault) const; /** - * @since 4.3 * * Returns the identifier of the digit set used to display dates and time. * @@ -1044,7 +1016,6 @@ public: Q_INVOKABLE bool use12Clock() const; /** - * @since 4.6 * * Returns the Day Period matching the time given * @@ -1064,7 +1035,6 @@ public: /** * Use this to determine which day is the first working day of the week. * - * @since 4.2 * @return an integer (Monday=1..Sunday=7) */ int workingWeekStartDay() const; @@ -1072,7 +1042,6 @@ public: /** * Use this to determine which day is the last working day of the week. * - * @since 4.2 * @return an integer (Monday=1..Sunday=7) */ int workingWeekEndDay() const; @@ -1080,7 +1049,6 @@ public: /** * Use this to determine which day is reserved for religious observance * - * @since 4.2 * @return day number (None = 0, Monday = 1, ..., Sunday = 7) */ int weekDayOfPray() const; @@ -1093,7 +1061,6 @@ public: const KCalendarSystem * calendar() const; /** - * @since 4.6 * * Returns the type of Calendar System used in this Locale * @@ -1104,7 +1071,6 @@ public: KLocale::CalendarSystem calendarSystem() const; /** - * @since 4.6 * * Sets the type of Calendar System to use in this Locale * @@ -1115,7 +1081,6 @@ public: void setCalendarSystem(KLocale::CalendarSystem calendarSystem); /** - * @since 4.6 * * Sets the type of Week Number System to use in this Locale * @@ -1127,7 +1092,6 @@ public: //KDE5 remove in favour of const version /** - * @since 4.6 * * Returns the type of Week Number System used in this Locale * @@ -1138,7 +1102,6 @@ public: KLocale::WeekNumberSystem weekNumberSystem(); /** - * @since 4.7 * * Returns the type of Week Number System used in this Locale * @@ -1257,7 +1220,6 @@ public: }; /** - * @since 4.4 * * Converts a localized time string to a QTime. * This method is stricter than readTime(str, &ok) in that it will either @@ -1313,7 +1275,6 @@ public: QString country() const; /** - * @since 4.6 * * Returns the Country Division Code of the Country where the user lives. * When no value is set, then the Country Code will be returned. @@ -1346,7 +1307,6 @@ public: Q_INVOKABLE QStringList languageList() const; /** - * @since 4.4 * * Returns the ISO Currency Codes used in the locale, ordered by decreasing * priority. @@ -1477,7 +1437,6 @@ public: void setTimeFormat(const QString & format); /** - * @since 4.3 * * Set digit characters used to display dates and time. * @@ -1496,7 +1455,6 @@ public: /** * Changes how KLocale defines the first working day in week. * - * @since 4.2 * @param day first working day of the week (Monday=1..Sunday=7) as integer */ void setWorkingWeekStartDay(int day); @@ -1504,7 +1462,6 @@ public: /** * Changes how KLocale defines the last working day in week. * - * @since 4.2 * @param day last working day of the week (Monday=1..Sunday=7) as integer */ void setWorkingWeekEndDay(int day); @@ -1512,7 +1469,6 @@ public: /** * Changes how KLocale defines the day reserved for religious observance. * - * @since 4.2 * @param day day of the week for religious observance (None=0,Monday=1..Sunday=7) as integer */ void setWeekDayOfPray(int day); @@ -1571,7 +1527,6 @@ public: void setNegativeSign(const QString & sign); /** - * @since 4.3 * * Changes the set of digit characters used to display numbers. * @@ -1613,7 +1568,6 @@ public: void setNegativePrefixCurrencySymbol(bool prefix); /** - * @since 4.4 * * Changes the number of decimal places used when formating numbers. * @@ -1622,7 +1576,6 @@ public: void setDecimalPlaces(int digits); /** - * @since 4.4 * * Changes the number of decimal places used when formating money. * @@ -1646,7 +1599,6 @@ public: void setMonetaryDecimalSymbol(const QString & symbol); /** - * @since 4.4 * * Changes the current ISO Currency Code. * @@ -1665,7 +1617,6 @@ public: void setCurrencySymbol(const QString & symbol); /** - * @since 4.3 * * Set digit characters used to display monetary values. * @@ -1757,7 +1708,6 @@ public: Q_INVOKABLE QStringList allLanguagesList() const; /** - * @since 4.6 * * Provides list of all installed KDE Language Translations. * @@ -1859,7 +1809,6 @@ public: Q_INVOKABLE static QString defaultCountry(); /** - * @since 4.4 * * Returns the ISO Code of the default currency. * @@ -1909,7 +1858,6 @@ public: bool setCountry(const QString & country, KConfig *config); /** - * @since 4.6 * * Sets the Country Division Code of the Country where the user lives. * @@ -1955,7 +1903,6 @@ public: bool setLanguage(const QStringList &languages); /** - * @since 4.1 * * Tries to find a path to the localized file for the given original path. * This is intended mainly for non-text resources (images, sounds, etc.), @@ -1979,7 +1926,6 @@ public: Q_INVOKABLE QString localizedFilePath(const QString &filePath) const; /** - * @since 4.2 * * Removes accelerator marker from a UI text label. * @@ -1997,7 +1943,6 @@ public: Q_INVOKABLE QString removeAcceleratorMarker(const QString &label) const; /** - * @since 4.3 * * Convert all digits in the string to the given digit set. * @@ -2018,7 +1963,6 @@ public: bool ignoreContext = false) const; /** - * @since 4.8 * * Reparse locale configuration files for the current selected * language. From 78a91a7cc9d7acbf6dd42f20b54f877b55d726fa Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Wed, 18 Jan 2012 18:15:07 +0200 Subject: [PATCH 006/104] renamed: core/Locale.cpp -> locale/locale.cpp renamed: core/Locale.h -> locale/locale.h --- declarativeimports/{core/Locale.cpp => locale/locale.cpp} | 0 declarativeimports/{core/Locale.h => locale/locale.h} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename declarativeimports/{core/Locale.cpp => locale/locale.cpp} (100%) rename declarativeimports/{core/Locale.h => locale/locale.h} (100%) diff --git a/declarativeimports/core/Locale.cpp b/declarativeimports/locale/locale.cpp similarity index 100% rename from declarativeimports/core/Locale.cpp rename to declarativeimports/locale/locale.cpp diff --git a/declarativeimports/core/Locale.h b/declarativeimports/locale/locale.h similarity index 100% rename from declarativeimports/core/Locale.h rename to declarativeimports/locale/locale.h From de6ae24554283cf4d2fecd50ae91773653e20aa3 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Wed, 18 Jan 2012 11:32:49 +0200 Subject: [PATCH 007/104] Create localebindingsplugin.{cpp,h},CMakeLists.txt,qmldir --- .../core/corebindingsplugin.cpp | 3 -- declarativeimports/locale/CMakeLists.txt | 23 ++++++++++++ .../locale/localebindingsplugin.cpp | 34 ++++++++++++++++++ .../locale/localebindingsplugin.h | 36 +++++++++++++++++++ declarativeimports/locale/qmldir | 1 + 5 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 declarativeimports/locale/CMakeLists.txt create mode 100644 declarativeimports/locale/localebindingsplugin.cpp create mode 100644 declarativeimports/locale/localebindingsplugin.h create mode 100644 declarativeimports/locale/qmldir diff --git a/declarativeimports/core/corebindingsplugin.cpp b/declarativeimports/core/corebindingsplugin.cpp index 4fd65c8ad..f08d8b36d 100644 --- a/declarativeimports/core/corebindingsplugin.cpp +++ b/declarativeimports/core/corebindingsplugin.cpp @@ -38,7 +38,6 @@ #include "dialog.h" #include "tooltip.h" #include "dataenginebindings_p.h" -#include "Locale.h" void CoreBindingsPlugin::initializeEngine(QDeclarativeEngine *engine, const char *uri) { @@ -81,8 +80,6 @@ void CoreBindingsPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 0, 1, "Dialog"); qmlRegisterType(uri, 0, 1, "ToolTip"); - qmlRegisterType(uri, 0, 1, "Locale"); - qmlRegisterInterface("Service"); qRegisterMetaType("Service"); qmlRegisterInterface("ServiceJob"); diff --git a/declarativeimports/locale/CMakeLists.txt b/declarativeimports/locale/CMakeLists.txt new file mode 100644 index 000000000..24431c7f3 --- /dev/null +++ b/declarativeimports/locale/CMakeLists.txt @@ -0,0 +1,23 @@ +project(localebindings) + +set(localebindings_SRCS + locale.cpp + ) + +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${KDE4_INCLUDES} +) + +qt4_automoc(${localebindings_SRCS}) + + +add_library(localebindingsplugin SHARED ${localebindings_SRCS}) +#FIXME +#Should i remove KDE4_PLASMA_LIBS? +#Should i put something? +target_link_libraries(localebindingsplugin ${KDE4_PLASMA_LIBS} ${QT_QTDECLARATIVE_LIBRARY} kdeclarative) + +install(TARGETS localebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) +install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) diff --git a/declarativeimports/locale/localebindingsplugin.cpp b/declarativeimports/locale/localebindingsplugin.cpp new file mode 100644 index 000000000..e3cb7bc74 --- /dev/null +++ b/declarativeimports/locale/localebindingsplugin.cpp @@ -0,0 +1,34 @@ +/* + * Copyright 2012 by Antonis Tsiapaliokas + * Copyright 2012 by Giorgos Tsiapaliwkas + + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "localebindingsplugin.h" + +#include + +#include "locale.h" + +void LocaleBindingsPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(uri == QLatin1String("org.kde.plasma.locale")); + + qmlRegisterType(uri, 0, 1, "Locale"); +} + +#include "localebindingsplugin.moc" diff --git a/declarativeimports/locale/localebindingsplugin.h b/declarativeimports/locale/localebindingsplugin.h new file mode 100644 index 000000000..9f56d5baa --- /dev/null +++ b/declarativeimports/locale/localebindingsplugin.h @@ -0,0 +1,36 @@ +/* + * Copyright 2012 by Antonis Tsiapaliokas + * Copyright 2012 by Giorgos Tsiapaliwkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef LOCALEBINDINGSPLUGIN_H +#define LOCALEBINDINGSPLUGIN_H + +#include + +class LocaleBindingsPlugin : public QDeclarativeExtensionPlugin +{ + Q_OBJECT + +public: + void registerTypes(const char *uri); +}; + +Q_EXPORT_PLUGIN2(localebindingsplugin, LocaleBindingsPlugin) + +#endif diff --git a/declarativeimports/locale/qmldir b/declarativeimports/locale/qmldir new file mode 100644 index 000000000..4e8428dc7 --- /dev/null +++ b/declarativeimports/locale/qmldir @@ -0,0 +1 @@ +plugin localebindingsplugin From f4fc499a41e0f08549fe98ea4bf461885d8d8b98 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 19 Jan 2012 22:12:26 +0200 Subject: [PATCH 008/104] fix some typos --- declarativeimports/locale/localebindingsplugin.cpp | 4 +--- declarativeimports/locale/qmldir | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/declarativeimports/locale/localebindingsplugin.cpp b/declarativeimports/locale/localebindingsplugin.cpp index e3cb7bc74..98f161f72 100644 --- a/declarativeimports/locale/localebindingsplugin.cpp +++ b/declarativeimports/locale/localebindingsplugin.cpp @@ -19,16 +19,14 @@ */ #include "localebindingsplugin.h" - #include - #include "locale.h" void LocaleBindingsPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.plasma.locale")); - qmlRegisterType(uri, 0, 1, "Locale"); + qmlRegisterType(uri, 0, 1, "Locale"); } #include "localebindingsplugin.moc" diff --git a/declarativeimports/locale/qmldir b/declarativeimports/locale/qmldir index 4e8428dc7..00a5825da 100644 --- a/declarativeimports/locale/qmldir +++ b/declarativeimports/locale/qmldir @@ -1 +1 @@ -plugin localebindingsplugin +plugin localebindingsplugin From 311ab5b82bfb29202d5843452ad4c701df4cc511 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 19 Jan 2012 22:16:14 +0200 Subject: [PATCH 009/104] Add a ctor --- declarativeimports/locale/locale.cpp | 269 ++++++++++++++------------- declarativeimports/locale/locale.h | 9 +- 2 files changed, 138 insertions(+), 140 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index ddd0269d9..f8313e1f1 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -18,48 +18,51 @@ Boston, MA 02110-1301, USA. */ -#include "Locale.h" +#include "locale.h" +#include //TODO we need some ctors -Locale::~Locale() +Locale::Locale(QObject* parent) + : QObject(parent) { - delete d; + m_locale = new KLocale(KGlobal::locale()); } + bool Locale::setCountry(const QString &country, KConfig *config) { - return d->setCountry(country, config); + return m_locale->setCountry(country, config); emit countryChanged(); } bool Locale::setCountryDivisionCode(const QString &countryDivisionCode) { - return d->setCountryDivisionCode(countryDivisionCode); + return m_locale->setCountryDivisionCode(countryDivisionCode); emit countryDivisionCodeChanged(); } bool Locale::setLanguage(const QString &language, KConfig *config) { - return d->setLanguage(language, config); + return m_locale->setLanguage(language, config); emit languageChanged(); } bool Locale::setLanguage(const QStringList &languages) { - return d->setLanguage(languages); + return m_locale->setLanguage(languages); emit languageChanged(); } void Locale::setCurrencyCode(const QString &newCurrencyCode) { - d->setCurrencyCode(newCurrencyCode); + m_locale->setCurrencyCode(newCurrencyCode); emit currencyCodeChanged(); } bool Locale::isApplicationTranslatedInto(const QString &lang) { - return d->isApplicationTranslatedInto(lang); + return m_locale->isApplicationTranslatedInto(lang); } void Locale::splitLocale(const QString &locale, QString &language, QString &country, QString &modifier, @@ -70,179 +73,179 @@ void Locale::splitLocale(const QString &locale, QString &language, QString &coun QString Locale::language() const { - return d->language(); + return m_locale->language(); } QString Locale::country() const { - return d->country(); + return m_locale->country(); } QString Locale::countryDivisionCode() const { - return d->countryDivisionCode(); + return m_locale->countryDivisionCode(); } KCurrencyCode *Locale::currency() const { - return d->currency(); + return m_locale->currency(); } QString Locale::currencyCode() const { - return d->currencyCode(); + return m_locale->currencyCode(); } void Locale::insertCatalog(const QString &catalog) { - d->insertCatalog(catalog); + m_locale->insertCatalog(catalog); } void Locale::removeCatalog(const QString &catalog) { - d->removeCatalog(catalog); + m_locale->removeCatalog(catalog); } void Locale::setActiveCatalog(const QString &catalog) { - d->setActiveCatalog(catalog); + m_locale->setActiveCatalog(catalog); } void Locale::translateRawFrom(const char *catname, const char *ctxt, const char *singular, const char *plural, unsigned long n, QString *lang, QString *trans) const { - d->translateRawFrom(catname, ctxt, singular, plural, n, lang, trans); + m_locale->translateRawFrom(catname, ctxt, singular, plural, n, lang, trans); } //Convenience versions void Locale::translateRawFrom(const char *catname, const char *msg, QString *lang, QString *trans) const { - d->translateRawFrom(catname, 0, msg, 0, 0, lang, trans); + m_locale->translateRawFrom(catname, 0, msg, 0, 0, lang, trans); } void Locale::translateRaw(const char *msg, QString *lang, QString *trans) const { - d->translateRawFrom(0, 0, msg, 0, 0, lang, trans); + m_locale->translateRawFrom(0, 0, msg, 0, 0, lang, trans); } void Locale::translateRawFrom(const char *catname, const char *ctxt, const char *msg, QString *lang, QString *trans) const { - d->translateRawFrom(catname, ctxt, msg, 0, 0, lang, trans); + m_locale->translateRawFrom(catname, ctxt, msg, 0, 0, lang, trans); } void Locale::translateRaw(const char *ctxt, const char *msg, QString *lang, QString *trans) const { - d->translateRawFrom(0, ctxt, msg, 0, 0, lang, trans); + m_locale->translateRawFrom(0, ctxt, msg, 0, 0, lang, trans); } void Locale::translateRawFrom(const char *catname, const char *singular, const char *plural, unsigned long n, QString *lang, QString *trans) const { - d->translateRawFrom(catname, 0, singular, plural, n, lang, trans); + m_locale->translateRawFrom(catname, 0, singular, plural, n, lang, trans); } void Locale::translateRaw(const char *singular, const char *plural, unsigned long n, QString *lang, QString *trans) const { - d->translateRawFrom(0, 0, singular, plural, n, lang, trans); + m_locale->translateRawFrom(0, 0, singular, plural, n, lang, trans); } void Locale::translateRaw(const char *ctxt, const char *singular, const char *plural, unsigned long n, QString *lang, QString *trans) const { - d->translateRawFrom(0, ctxt, singular, plural, n, lang, trans); + m_locale->translateRawFrom(0, ctxt, singular, plural, n, lang, trans); } QString Locale::translateQt(const char *context, const char *sourceText, const char *comment) const { - return d->translateQt(context, sourceText, comment); + return m_locale->translateQt(context, sourceText, comment); } QList Locale::allDigitSetsList() const { - return d->allDigitSetsList(); + return m_locale->allDigitSetsList(); } QString Locale::digitSetToName(Locale::DigitSet digitSet, bool withDigits) const { - return d->digitSetToName(digitSet, withDigits); + return m_locale->digitSetToName(digitSet, withDigits); } QString Locale::convertDigits(const QString &str, DigitSet digitSet, bool ignoreContext) const { - return d->convertDigits(str, digitSet, ignoreContext); + return m_locale->convertDigits(str, digitSet, ignoreContext); } bool Locale::nounDeclension() const { - return d->nounDeclension(); + return m_locale->nounDeclension(); } bool Locale::dateMonthNamePossessive() const { - return d->dateMonthNamePossessive(); + return m_locale->dateMonthNamePossessive(); } int Locale::weekStartDay() const { - return d->weekStartDay(); + return m_locale->weekStartDay(); } int Locale::workingWeekStartDay() const { - return d->workingWeekStartDay(); + return m_locale->workingWeekStartDay(); } int Locale::workingWeekEndDay() const { - return d->workingWeekEndDay(); + return m_locale->workingWeekEndDay(); } int Locale::weekDayOfPray() const { - return d->weekDayOfPray(); + return m_locale->weekDayOfPray(); } int Locale::decimalPlaces() const { - return d->decimalPlaces(); + return m_locale->decimalPlaces(); } QString Locale::decimalSymbol() const { - return d->decimalSymbol(); + return m_locale->decimalSymbol(); } QString Locale::thousandsSeparator() const { - return d->thousandsSeparator(); + return m_locale->thousandsSeparator(); } QString Locale::currencySymbol() const { - return d->currencySymbol(); + return m_locale->currencySymbol(); emit currencySymbolChanged(); } QString Locale::monetaryDecimalSymbol() const { - return d->monetaryDecimalSymbol(); + return m_locale->monetaryDecimalSymbol(); } QString Locale::monetaryThousandsSeparator() const { - return d->monetaryThousandsSeparator(); + return m_locale->monetaryThousandsSeparator(); } QString Locale::positiveSign() const { - return d->positiveSign(); + return m_locale->positiveSign(); } QString Locale::negativeSign() const { - return d->negativeSign(); + return m_locale->negativeSign(); } int Locale::fracDigits() const @@ -252,84 +255,84 @@ int Locale::fracDigits() const int Locale::monetaryDecimalPlaces() const { - return d->monetaryDecimalPlaces(); + return m_locale->monetaryDecimalPlaces(); } bool Locale::positivePrefixCurrencySymbol() const { - return d->positivePrefixCurrencySymbol(); + return m_locale->positivePrefixCurrencySymbol(); } bool Locale::negativePrefixCurrencySymbol() const { - return d->negativePrefixCurrencySymbol(); + return m_locale->negativePrefixCurrencySymbol(); } Locale::SignPosition Locale::positiveMonetarySignPosition() const { - return d->positiveMonetarySignPosition(); + return m_locale->positiveMonetarySignPosition(); } Locale::SignPosition Locale::negativeMonetarySignPosition() const { - return d->negativeMonetarySignPosition(); + return m_locale->negativeMonetarySignPosition(); } QString Locale::formatMoney(double num, const QString &symbol, int precision) const { - return d->formatMoney(num, symbol, precision); + return m_locale->formatMoney(num, symbol, precision); } QString Locale::formatNumber(double num, int precision) const { - return d->formatNumber(num, precision); + return m_locale->formatNumber(num, precision); } QString Locale::formatLong(long num) const { - return d->formatLong(num); + return m_locale->formatLong(num); } QString Locale::formatNumber(const QString &numStr, bool round, int precision) const { - return d->formatNumber(numStr, round, precision); + return m_locale->formatNumber(numStr, round, precision); } QString Locale::formatByteSize(double size, int precision, Locale::BinaryUnitDialect dialect, Locale::BinarySizeUnits specificUnit) const { - return d->formatByteSize(size, precision, dialect, specificUnit); + return m_locale->formatByteSize(size, precision, dialect, specificUnit); } QString Locale::formatByteSize(double size) const { - return d->formatByteSize(size); + return m_locale->formatByteSize(size); } Locale::BinaryUnitDialect Locale::binaryUnitDialect() const { - return d->binaryUnitDialect(); + return m_locale->binaryUnitDialect(); } void Locale::setBinaryUnitDialect(Locale::BinaryUnitDialect newDialect) { - d->setBinaryUnitDialect(newDialect); + m_locale->setBinaryUnitDialect(newDialect); emit binaryUnitDialectChanged(); } QString Locale::formatDuration(unsigned long mSec) const { - return d->formatDuration(mSec); + return m_locale->formatDuration(mSec); } QString Locale::prettyFormatDuration(unsigned long mSec) const { - return d->prettyFormatDuration(mSec); + return m_locale->prettyFormatDuration(mSec); } QString Locale::formatDate(const QDate &date, Locale::DateFormat format) const { - return d->formatDate(date, format); + return m_locale->formatDate(date, format); } void Locale::setMainCatalog(const char *catalog) @@ -339,73 +342,73 @@ void Locale::setMainCatalog(const char *catalog) double Locale::readNumber(const QString &_str, bool * ok) const { - return d->readNumber(_str, ok); + return m_locale->readNumber(_str, ok); } double Locale::readMoney(const QString &_str, bool *ok) const { - return d->readMoney(_str, ok); + return m_locale->readMoney(_str, ok); } QDate Locale::readDate(const QString &intstr, bool *ok) const { - return d->readDate(intstr, ok); + return m_locale->readDate(intstr, ok); } QDate Locale::readDate(const QString &intstr, ReadDateFlags flags, bool *ok) const { - return d->readDate(intstr, flags, ok); + return m_locale->readDate(intstr, flags, ok); } QDate Locale::readDate(const QString &intstr, const QString &fmt, bool *ok) const { - return d->readDate(intstr, fmt, ok); + return m_locale->readDate(intstr, fmt, ok); } QTime Locale::readTime(const QString &intstr, bool *ok) const { - return d->readTime(intstr, ok); + return m_locale->readTime(intstr, ok); } QTime Locale::readTime(const QString &intstr, Locale::ReadTimeFlags flags, bool *ok) const { - return d->readTime(intstr, flags, ok); + return m_locale->readTime(intstr, flags, ok); } QTime Locale::readLocaleTime(const QString &intstr, bool *ok, TimeFormatOptions options, TimeProcessingOptions processing) const { - return d->readLocaleTime(intstr, ok, options, processing); + return m_locale->readLocaleTime(intstr, ok, options, processing); } QString Locale::formatTime(const QTime &time, bool includeSecs, bool isDuration) const { - return d->formatTime(time, includeSecs, isDuration); + return m_locale->formatTime(time, includeSecs, isDuration); } QString Locale::formatLocaleTime(const QTime &time, TimeFormatOptions options) const { - return d->formatLocaleTime(time, options); + return m_locale->formatLocaleTime(time, options); } bool Locale::use12Clock() const { - return d->use12Clock(); + return m_locale->use12Clock(); } QString Locale::dayPeriodText(const QTime &time, DateTimeComponentFormat format) const { - return d->dayPeriodText(time, format); + return m_locale->dayPeriodText(time, format); } QStringList Locale::languageList() const { - return d->languageList(); + return m_locale->languageList(); } QStringList Locale::currencyCodeList() const { - return d->currencyCodeList(); + return m_locale->currencyCodeList(); } /* Just copy in for now to keep diff clean, remove later @@ -417,12 +420,12 @@ QString Locale::formatDateTime(const Locale *locale, const QDateTime &dateTime, QString Locale::formatDateTime(const QDateTime &dateTime, Locale::DateFormat format, bool includeSeconds) const { - return d->formatDateTime(dateTime, format, includeSeconds); + return m_locale->formatDateTime(dateTime, format, includeSeconds); } QString Locale::formatDateTime(const KDateTime &dateTime, Locale::DateFormat format, DateTimeFormatOptions options) const { - return d->formatDateTime(dateTime, format, options); + return m_locale->formatDateTime(dateTime, format, options); } QString Locale::langLookup(const QString &fname, const char *rtype) @@ -432,118 +435,118 @@ QString Locale::langLookup(const QString &fname, const char *rtype) void Locale::setDateFormat(const QString &format) { - d->setDateFormat(format); + m_locale->setDateFormat(format); emit dateFormatChanged(); } void Locale::setDateFormatShort(const QString &format) { - d->setDateFormatShort(format); + m_locale->setDateFormatShort(format); emit dateFormatShortChanged(); } void Locale::setDateMonthNamePossessive(bool possessive) { - d->setDateMonthNamePossessive(possessive); + m_locale->setDateMonthNamePossessive(possessive); emit dateMonthNamePossessiveChanged(); } void Locale::setTimeFormat(const QString &format) { - d->setTimeFormat(format); + m_locale->setTimeFormat(format); emit timeFormatChanged(); } void Locale::setWeekStartDay(int day) { - d->setWeekStartDay(day); + m_locale->setWeekStartDay(day); emit weekStartDayChanged(); } void Locale::setWorkingWeekStartDay(int day) { - d->setWorkingWeekStartDay(day); + m_locale->setWorkingWeekStartDay(day); emit workingWeekStartDayChanged(); } void Locale::setWorkingWeekEndDay(int day) { - d->setWorkingWeekEndDay(day); + m_locale->setWorkingWeekEndDay(day); emit workingWeekEndDayChanged(); } void Locale::setWeekDayOfPray(int day) { - d->setWeekDayOfPray(day); + m_locale->setWeekDayOfPray(day); emit weekDayOfPrayChanged(); } QString Locale::dateFormat() const { - return d->dateFormat(); + return m_locale->dateFormat(); } QString Locale::dateFormatShort() const { - return d->dateFormatShort(); + return m_locale->dateFormatShort(); } QString Locale::timeFormat() const { - return d->timeFormat(); + return m_locale->timeFormat(); } void Locale::setDecimalPlaces(int digits) { - d->setDecimalPlaces(digits); + m_locale->setDecimalPlaces(digits); emit decimalPlacesChanged(); } void Locale::setDecimalSymbol(const QString &symbol) { - d->setDecimalSymbol(symbol); + m_locale->setDecimalSymbol(symbol); emit decimalSymbolChanged(); } void Locale::setThousandsSeparator(const QString &separator) { - d->setThousandsSeparator(separator); + m_locale->setThousandsSeparator(separator); emit thousandsSeparatorChanged(); } void Locale::setPositiveSign(const QString &sign) { - d->setPositiveSign(sign); + m_locale->setPositiveSign(sign); emit positiveSignChanged(); } void Locale::setNegativeSign(const QString &sign) { - d->setNegativeSign(sign); + m_locale->setNegativeSign(sign); emit negativeSignChanged(); } void Locale::setPositiveMonetarySignPosition(Locale::SignPosition signpos) { - d->setPositiveMonetarySignPosition(signpos); + m_locale->setPositiveMonetarySignPosition(signpos); emit positiveMonetarySignPositionChanged(); } void Locale::setNegativeMonetarySignPosition(Locale::SignPosition signpos) { - d->setNegativeMonetarySignPosition(signpos); + m_locale->setNegativeMonetarySignPosition(signpos); emit negativeMonetarySignPositionChanged(); } void Locale::setPositivePrefixCurrencySymbol(bool prefix) { - d->setPositivePrefixCurrencySymbol(prefix); + m_locale->setPositivePrefixCurrencySymbol(prefix); emit positivePrefixCurrencySymbolChanged(); } void Locale::setNegativePrefixCurrencySymbol(bool prefix) { - d->setNegativePrefixCurrencySymbol(prefix); + m_locale->setNegativePrefixCurrencySymbol(prefix); emit negativePrefixCurrencySymbolChanged(); } @@ -555,47 +558,47 @@ void Locale::setFracDigits(int digits) void Locale::setMonetaryDecimalPlaces(int digits) { - d->setMonetaryDecimalPlaces(digits); + m_locale->setMonetaryDecimalPlaces(digits); emit monetaryDecimalPlacesChanged(); } void Locale::setMonetaryThousandsSeparator(const QString &separator) { - d->setMonetaryThousandsSeparator(separator); + m_locale->setMonetaryThousandsSeparator(separator); emit monetaryThousandsSeparatorChanged(); } void Locale::setMonetaryDecimalSymbol(const QString &symbol) { - d->setMonetaryDecimalSymbol(symbol); + m_locale->setMonetaryDecimalSymbol(symbol); emit monetaryDecimalSymbolChanged(); } void Locale::setCurrencySymbol(const QString & symbol) { - d->setCurrencySymbol(symbol); + m_locale->setCurrencySymbol(symbol); emit currencySymbolChanged(); } int Locale::pageSize() const { - return d->pageSize(); + return m_locale->pageSize(); } void Locale::setPageSize(int size) { - d->setPageSize(size); + m_locale->setPageSize(size); emit pageSizeChanged(); } Locale::MeasureSystem Locale::measureSystem() const { - return d->measureSystem(); + return m_locale->measureSystem(); } void Locale::setMeasureSystem(Locale::MeasureSystem value) { - d->setMeasureSystem(value); + m_locale->setMeasureSystem(value); emit measureSystemChanged(); } @@ -616,158 +619,158 @@ QString Locale::defaultCurrencyCode() bool Locale::useTranscript() const { - return d->useTranscript(); + return m_locale->useTranscript(); } const QByteArray Locale::encoding() const { - return d->encoding(); + return m_locale->encoding(); } int Locale::encodingMib() const { - return d->encodingMib(); + return m_locale->encodingMib(); } int Locale::fileEncodingMib() const { - return d->fileEncodingMib(); + return m_locale->fileEncodingMib(); } QTextCodec *Locale::codecForEncoding() const { - return d->codecForEncoding(); + return m_locale->codecForEncoding(); } bool Locale::setEncoding(int mibEnum) { - return d->setEncoding(mibEnum); + return m_locale->setEncoding(mibEnum); emit encodingChanged(); } QStringList Locale::allLanguagesList() const { - return d->allLanguagesList(); + return m_locale->allLanguagesList(); } QStringList Locale::installedLanguages() const { - return d->installedLanguages(); + return m_locale->installedLanguages(); } QString Locale::languageCodeToName(const QString &language) const { - return d->languageCodeToName(language); + return m_locale->languageCodeToName(language); } QStringList Locale::allCountriesList() const { - return d->allCountriesList(); + return m_locale->allCountriesList(); } QString Locale::countryCodeToName(const QString &country) const { - return d->countryCodeToName(country); + return m_locale->countryCodeToName(country); } void Locale::setCalendar(const QString &calendarType) { - d->setCalendar(calendarType); + m_locale->setCalendar(calendarType); emit calendarChanged(); } void Locale::setCalendarSystem(Locale::CalendarSystem calendarSystem) { - d->setCalendarSystem(calendarSystem); + m_locale->setCalendarSystem(calendarSystem); emit calendarSystemChanged(); } QString Locale::calendarType() const { - return d->calendarType(); + return m_locale->calendarType(); } Locale::CalendarSystem Locale::calendarSystem() const { - return d->calendarSystem(); + return m_locale->calendarSystem(); } const KCalendarSystem * Locale::calendar() const { - return d->calendar(); + return m_locale->calendar(); } void Locale::setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem) { - d->setWeekNumberSystem(weekNumberSystem); + m_locale->setWeekNumberSystem(weekNumberSystem); emit WeekNumberSystemChanged(); } Locale::WeekNumberSystem Locale::weekNumberSystem() { - return d->weekNumberSystem(); + return m_locale->weekNumberSystem(); } Locale::WeekNumberSystem Locale::weekNumberSystem() const { - return d->weekNumberSystem(); + return m_locale->weekNumberSystem(); } /*Locale::Locale(const Locale &rhs) : d(new Locale(*rhs.d)) { - d->q = this; + m_locale->q = this; }*/ void Locale::copyCatalogsTo(Locale *locale) { - d->copyCatalogsTo(locale); + m_locale->copyCatalogsTo(locale); } QString Locale::localizedFilePath(const QString &filePath) const { - return d->localizedFilePath(filePath); + return m_locale->localizedFilePath(filePath); } QString Locale::removeAcceleratorMarker(const QString &label) const { - return d->removeAcceleratorMarker(label); + return m_locale->removeAcceleratorMarker(label); } void Locale::setDigitSet(Locale::DigitSet digitSet) { - d->setDigitSet(digitSet); + m_locale->setDigitSet(digitSet); emit digitSetChanged(); } Locale::DigitSet Locale::digitSet() const { - return d->digitSet(); + return m_locale->digitSet(); } void Locale::setMonetaryDigitSet(Locale::DigitSet digitSet) { - d->setMonetaryDigitSet(digitSet); + m_locale->setMonetaryDigitSet(digitSet); emit monetaryDigitSetChanged(); } Locale::DigitSet Locale::monetaryDigitSet() const { - return d->monetaryDigitSet(); + return m_locale->monetaryDigitSet(); } void Locale::setDateTimeDigitSet(Locale::DigitSet digitSet) { - d->setDateTimeDigitSet(digitSet); + m_locale->setDateTimeDigitSet(digitSet); emit dateTimeDigitSetChanged(); } Locale::DigitSet Locale::dateTimeDigitSet() const { - return d->dateTimeDigitSet(); + return m_locale->dateTimeDigitSet(); } void Locale::reparseConfiguration() { - d->reparseConfiguration(); + m_locale->reparseConfiguration(); } diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 437c9b496..35ab9f1bc 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -168,12 +168,7 @@ public: /** * Copy constructor */ - // KLocale(const KLocale & rhs); - - /** - * Destructor - */ - virtual ~Locale(); + Locale(QObject *parent = 0); /** * @@ -1970,7 +1965,7 @@ public: void reparseConfiguration(); private: - KLocale *const d; + KLocale *m_locale; Q_SIGNALS: void binaryUnitDialectChanged(); From 9581c33be21be1608a79281996c4e12834f979f1 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 23 Jan 2012 21:16:14 +0200 Subject: [PATCH 010/104] fix some typos --- declarativeimports/locale/locale.cpp | 18 +++++------------- declarativeimports/locale/locale.h | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index f8313e1f1..9349245f2 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -21,8 +21,6 @@ #include "locale.h" #include -//TODO we need some ctors - Locale::Locale(QObject* parent) : QObject(parent) { @@ -32,32 +30,32 @@ Locale::Locale(QObject* parent) bool Locale::setCountry(const QString &country, KConfig *config) { - return m_locale->setCountry(country, config); emit countryChanged(); + return m_locale->setCountry(country, config); } bool Locale::setCountryDivisionCode(const QString &countryDivisionCode) { - return m_locale->setCountryDivisionCode(countryDivisionCode); emit countryDivisionCodeChanged(); + return m_locale->setCountryDivisionCode(countryDivisionCode); } bool Locale::setLanguage(const QString &language, KConfig *config) { - return m_locale->setLanguage(language, config); emit languageChanged(); + return m_locale->setLanguage(language, config); } bool Locale::setLanguage(const QStringList &languages) { - return m_locale->setLanguage(languages); emit languageChanged(); + return m_locale->setLanguage(languages); } void Locale::setCurrencyCode(const QString &newCurrencyCode) { - m_locale->setCurrencyCode(newCurrencyCode); emit currencyCodeChanged(); + m_locale->setCurrencyCode(newCurrencyCode); } bool Locale::isApplicationTranslatedInto(const QString &lang) @@ -716,12 +714,6 @@ Locale::WeekNumberSystem Locale::weekNumberSystem() const return m_locale->weekNumberSystem(); } -/*Locale::Locale(const Locale &rhs) - : d(new Locale(*rhs.d)) -{ - m_locale->q = this; -}*/ - void Locale::copyCatalogsTo(Locale *locale) { m_locale->copyCatalogsTo(locale); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 35ab9f1bc..ead62c3a8 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -32,7 +32,7 @@ class QDateTime; class KDateTime; class KCalendarSystem; class KCurrencyCode; -class KDayPeriod; +//class KDayPeriod; /** * \file klocale.h From a7098018c56ec4f42c42cc4484be0154ea2d4bcc Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 23 Jan 2012 21:43:42 +0200 Subject: [PATCH 011/104] Add again Q_DECLARE_FLAGS and fix some typos --- declarativeimports/locale/locale.cpp | 24 +----------------------- declarativeimports/locale/locale.h | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 9349245f2..3ca0b187a 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -24,7 +24,7 @@ Locale::Locale(QObject* parent) : QObject(parent) { - m_locale = new KLocale(KGlobal::locale()); + m_locale = new KLocale(*KGlobal::locale()); } @@ -121,40 +121,18 @@ void Locale::translateRawFrom(const char *catname, const char *msg, QString *lan m_locale->translateRawFrom(catname, 0, msg, 0, 0, lang, trans); } -void Locale::translateRaw(const char *msg, QString *lang, QString *trans) const -{ - m_locale->translateRawFrom(0, 0, msg, 0, 0, lang, trans); -} - void Locale::translateRawFrom(const char *catname, const char *ctxt, const char *msg, QString *lang, QString *trans) const { m_locale->translateRawFrom(catname, ctxt, msg, 0, 0, lang, trans); } -void Locale::translateRaw(const char *ctxt, const char *msg, QString *lang, QString *trans) const -{ - m_locale->translateRawFrom(0, ctxt, msg, 0, 0, lang, trans); -} - void Locale::translateRawFrom(const char *catname, const char *singular, const char *plural, unsigned long n, QString *lang, QString *trans) const { m_locale->translateRawFrom(catname, 0, singular, plural, n, lang, trans); } -void Locale::translateRaw(const char *singular, const char *plural, unsigned long n, QString *lang, - QString *trans) const -{ - m_locale->translateRawFrom(0, 0, singular, plural, n, lang, trans); -} - -void Locale::translateRaw(const char *ctxt, const char *singular, const char *plural, - unsigned long n, QString *lang, QString *trans) const -{ - m_locale->translateRawFrom(0, ctxt, singular, plural, n, lang, trans); -} - QString Locale::translateQt(const char *context, const char *sourceText, const char *comment) const { return m_locale->translateQt(context, sourceText, comment); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index ead62c3a8..f23ac18da 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -688,8 +688,8 @@ public: * @see BinaryUnitDialect */ QString formatByteSize(double size, int precision, - BinaryUnitDialect dialect = KLocale::DefaultBinaryDialect, - BinarySizeUnits specificUnit = KLocale::DefaultBinaryUnits) const; + BinaryUnitDialect dialect = Locale::DefaultBinaryDialect, + BinarySizeUnits specificUnit = Locale::DefaultBinaryUnits) const; /** * Returns the user's configured binary unit dialect. @@ -880,6 +880,8 @@ public: LongName /**< Long text format, e.g. Monday for Monday */ }; + Q_DECLARE_FLAGS(DateTimeComponents, DateTimeComponent) + //KDE5 move to KDateTime namespace /** * Format for date string. @@ -934,6 +936,8 @@ public: Seconds = 0x02 /**< Include the seconds value */ }; + Q_DECLARE_FLAGS(DateTimeFormatOptions, DateTimeFormatOption) + //KDE5 move to KDateTime namespace /** * Returns a string formatted to the current locale's conventions @@ -980,6 +984,8 @@ public: ///< "%I.%M.%S %p". }; + Q_DECLARE_FLAGS(TimeFormatOptions, TimeFormatOption) + //KDE5 move to KDateTime namespace /** * @@ -991,7 +997,7 @@ public: * @return The time as a string */ Q_INVOKABLE QString formatLocaleTime(const QTime &pTime, - TimeFormatOptions options = KLocale::TimeDefault) const; + TimeFormatOptions options = Locale::TimeDefault) const; /** * @@ -1214,6 +1220,8 @@ public: ///< left out when entering a time string. }; + Q_DECLARE_FLAGS(TimeProcessingOptions, TimeProcessingOption) + /** * * Converts a localized time string to a QTime. @@ -1232,7 +1240,7 @@ public: * @return The string converted to a QTime */ Q_INVOKABLE QTime readLocaleTime(const QString &str, bool *ok = 0, - TimeFormatOptions options = KLocale::TimeDefault, + TimeFormatOptions options = Locale::TimeDefault, TimeProcessingOptions processing = ProcessNonStrict) const; /** From 7a5880c6a5e049f9a52d76723f2dbc6b8e01cdbc Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 23 Jan 2012 21:44:28 +0200 Subject: [PATCH 012/104] add the locale folder in the cmake --- declarativeimports/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/declarativeimports/CMakeLists.txt b/declarativeimports/CMakeLists.txt index 5774a12b2..f423be071 100644 --- a/declarativeimports/CMakeLists.txt +++ b/declarativeimports/CMakeLists.txt @@ -3,4 +3,5 @@ add_subdirectory(draganddrop) add_subdirectory(graphicslayouts) add_subdirectory(graphicswidgets) add_subdirectory(qtextracomponents) -add_subdirectory(plasmacomponents) \ No newline at end of file +add_subdirectory(plasmacomponents) +add_subdirectory(locale) From 7f5c24018cf42ea9ef69e80f63e2c48f478297e1 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 23 Jan 2012 21:45:04 +0200 Subject: [PATCH 013/104] remove unnecessary linking from the cmake --- declarativeimports/locale/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/declarativeimports/locale/CMakeLists.txt b/declarativeimports/locale/CMakeLists.txt index 24431c7f3..1a06e17f9 100644 --- a/declarativeimports/locale/CMakeLists.txt +++ b/declarativeimports/locale/CMakeLists.txt @@ -17,7 +17,7 @@ add_library(localebindingsplugin SHARED ${localebindings_SRCS}) #FIXME #Should i remove KDE4_PLASMA_LIBS? #Should i put something? -target_link_libraries(localebindingsplugin ${KDE4_PLASMA_LIBS} ${QT_QTDECLARATIVE_LIBRARY} kdeclarative) +target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY}) install(TARGETS localebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) From 7b25bb5b34229a2f264cef943268932c51923322 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 24 Jan 2012 21:01:46 +0200 Subject: [PATCH 014/104] Remove unnecessary signals and replace KLocale with Locale. --- declarativeimports/locale/locale.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index f23ac18da..72cd4818f 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -1069,7 +1069,7 @@ public: * @see KCalendarSystem * @return the type of Calendar System */ - KLocale::CalendarSystem calendarSystem() const; + Locale::CalendarSystem calendarSystem() const; /** * @@ -1079,7 +1079,7 @@ public: * @see KCalendarSystem * @param calendarSystem the Calendar System to use */ - void setCalendarSystem(KLocale::CalendarSystem calendarSystem); + void setCalendarSystem(Locale::CalendarSystem calendarSystem); /** * @@ -1089,7 +1089,7 @@ public: * @see weekNumberSystem() * @param weekNumberSystem the Week Number System to use */ - void setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem); + void setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem); //KDE5 remove in favour of const version /** @@ -1100,7 +1100,7 @@ public: * @see setWeekNumberSystem() * @returns the Week Number System used */ - KLocale::WeekNumberSystem weekNumberSystem(); + Locale::WeekNumberSystem weekNumberSystem(); /** * @@ -1110,7 +1110,7 @@ public: * @see setWeekNumberSystem() * @returns the Week Number System used */ - KLocale::WeekNumberSystem weekNumberSystem() const; + Locale::WeekNumberSystem weekNumberSystem() const; /** * Converts a localized monetary string to a double. @@ -1239,6 +1239,12 @@ public: * * @return The string converted to a QTime */ + + enum ReadTimeFlags { + WithSeconds = 0, ///< Only accept a time string with seconds. Default (no flag set) + WithoutSeconds = 1 ///< Only accept a time string without seconds. + }; // (maybe use this enum as a bitfield, if adding independent features?) + Q_INVOKABLE QTime readLocaleTime(const QString &str, bool *ok = 0, TimeFormatOptions options = Locale::TimeDefault, TimeProcessingOptions processing = ProcessNonStrict) const; @@ -1838,7 +1844,7 @@ public: * * @param locale the destination KLocale object */ - Q_INVOKABLE void copyCatalogsTo(KLocale *locale); + Q_INVOKABLE void copyCatalogsTo(Locale *locale); /** * Changes the current country. The current country will be left @@ -1977,7 +1983,6 @@ private: Q_SIGNALS: void binaryUnitDialectChanged(); - void calendarChanged(); void calendarSystemChanged(); void countryChanged(); void countryDivisionCodeChanged(); @@ -1991,7 +1996,6 @@ Q_SIGNALS: void decimalPlacesChanged(); void digitSetChanged(); void encodingChanged(); - void fracDigitsChanged(); void languageChanged(); void measureSystemChanged(); void monetaryDecimalPlacesChanged(); From 4829d45f95679a92005086bb9f0732c451ed6ab2 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 24 Jan 2012 21:02:33 +0200 Subject: [PATCH 015/104] 1.Fix then enums 2.Place the emit foo() first and then the return foo; --- declarativeimports/locale/locale.cpp | 106 +++++++++------------------ 1 file changed, 36 insertions(+), 70 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 3ca0b187a..80b62c0c3 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -20,6 +20,8 @@ #include "locale.h" #include +#include +#include Locale::Locale(QObject* parent) : QObject(parent) @@ -140,22 +142,18 @@ QString Locale::translateQt(const char *context, const char *sourceText, const c QList Locale::allDigitSetsList() const { + //TODO return m_locale->allDigitSetsList(); } QString Locale::digitSetToName(Locale::DigitSet digitSet, bool withDigits) const { - return m_locale->digitSetToName(digitSet, withDigits); + return m_locale->digitSetToName((KLocale::DigitSet)digitSet, withDigits); } QString Locale::convertDigits(const QString &str, DigitSet digitSet, bool ignoreContext) const { - return m_locale->convertDigits(str, digitSet, ignoreContext); -} - -bool Locale::nounDeclension() const -{ - return m_locale->nounDeclension(); + return m_locale->convertDigits(str, (KLocale::DigitSet)digitSet, ignoreContext); } bool Locale::dateMonthNamePossessive() const @@ -200,8 +198,8 @@ QString Locale::thousandsSeparator() const QString Locale::currencySymbol() const { - return m_locale->currencySymbol(); emit currencySymbolChanged(); + return m_locale->currencySymbol(); } QString Locale::monetaryDecimalSymbol() const @@ -224,11 +222,6 @@ QString Locale::negativeSign() const return m_locale->negativeSign(); } -int Locale::fracDigits() const -{ - return monetaryDecimalPlaces(); -} - int Locale::monetaryDecimalPlaces() const { return m_locale->monetaryDecimalPlaces(); @@ -246,12 +239,12 @@ bool Locale::negativePrefixCurrencySymbol() const Locale::SignPosition Locale::positiveMonetarySignPosition() const { - return m_locale->positiveMonetarySignPosition(); + return (Locale::SignPosition)m_locale->positiveMonetarySignPosition(); } Locale::SignPosition Locale::negativeMonetarySignPosition() const { - return m_locale->negativeMonetarySignPosition(); + return (Locale::SignPosition)m_locale->negativeMonetarySignPosition(); } QString Locale::formatMoney(double num, const QString &symbol, int precision) const @@ -277,7 +270,7 @@ QString Locale::formatNumber(const QString &numStr, bool round, int precision) c QString Locale::formatByteSize(double size, int precision, Locale::BinaryUnitDialect dialect, Locale::BinarySizeUnits specificUnit) const { - return m_locale->formatByteSize(size, precision, dialect, specificUnit); + return m_locale->formatByteSize(size, precision, (KLocale::BinaryUnitDialect)dialect, (KLocale::BinarySizeUnits)specificUnit); } QString Locale::formatByteSize(double size) const @@ -287,12 +280,12 @@ QString Locale::formatByteSize(double size) const Locale::BinaryUnitDialect Locale::binaryUnitDialect() const { - return m_locale->binaryUnitDialect(); + return (Locale::BinaryUnitDialect)m_locale->binaryUnitDialect(); } void Locale::setBinaryUnitDialect(Locale::BinaryUnitDialect newDialect) { - m_locale->setBinaryUnitDialect(newDialect); + m_locale->setBinaryUnitDialect((KLocale::BinaryUnitDialect)newDialect); emit binaryUnitDialectChanged(); } @@ -308,12 +301,12 @@ QString Locale::prettyFormatDuration(unsigned long mSec) const QString Locale::formatDate(const QDate &date, Locale::DateFormat format) const { - return m_locale->formatDate(date, format); + return m_locale->formatDate(date, (KLocale::DateFormat)format); } void Locale::setMainCatalog(const char *catalog) { - Locale::setMainCatalog(catalog); + KLocale::setMainCatalog(catalog); } double Locale::readNumber(const QString &_str, bool * ok) const @@ -333,7 +326,7 @@ QDate Locale::readDate(const QString &intstr, bool *ok) const QDate Locale::readDate(const QString &intstr, ReadDateFlags flags, bool *ok) const { - return m_locale->readDate(intstr, flags, ok); + return m_locale->readDate(intstr, (KLocale::ReadDateFlags)flags, ok); } QDate Locale::readDate(const QString &intstr, const QString &fmt, bool *ok) const @@ -346,15 +339,10 @@ QTime Locale::readTime(const QString &intstr, bool *ok) const return m_locale->readTime(intstr, ok); } -QTime Locale::readTime(const QString &intstr, Locale::ReadTimeFlags flags, bool *ok) const -{ - return m_locale->readTime(intstr, flags, ok); -} - QTime Locale::readLocaleTime(const QString &intstr, bool *ok, TimeFormatOptions options, TimeProcessingOptions processing) const { - return m_locale->readLocaleTime(intstr, ok, options, processing); + return m_locale->readLocaleTime(intstr, ok, (KLocale::TimeFormatOptions)options, (KLocale::TimeProcessingOptions)processing); } QString Locale::formatTime(const QTime &time, bool includeSecs, bool isDuration) const @@ -364,7 +352,7 @@ QString Locale::formatTime(const QTime &time, bool includeSecs, bool isDuration) QString Locale::formatLocaleTime(const QTime &time, TimeFormatOptions options) const { - return m_locale->formatLocaleTime(time, options); + return m_locale->formatLocaleTime(time, (KLocale::TimeFormatOptions)options); } bool Locale::use12Clock() const @@ -374,7 +362,7 @@ bool Locale::use12Clock() const QString Locale::dayPeriodText(const QTime &time, DateTimeComponentFormat format) const { - return m_locale->dayPeriodText(time, format); + return m_locale->dayPeriodText(time, (KLocale::DateTimeComponentFormat)format); } QStringList Locale::languageList() const @@ -396,17 +384,12 @@ QString Locale::formatDateTime(const Locale *locale, const QDateTime &dateTime, QString Locale::formatDateTime(const QDateTime &dateTime, Locale::DateFormat format, bool includeSeconds) const { - return m_locale->formatDateTime(dateTime, format, includeSeconds); + return m_locale->formatDateTime(dateTime, (KLocale::DateFormat)format, (KLocale::DateFormat)includeSeconds); } QString Locale::formatDateTime(const KDateTime &dateTime, Locale::DateFormat format, DateTimeFormatOptions options) const { - return m_locale->formatDateTime(dateTime, format, options); -} - -QString Locale::langLookup(const QString &fname, const char *rtype) -{ - return KLocale::langLookup(fname, rtype); + return m_locale->formatDateTime(dateTime, (KLocale::DateFormat)format, (KLocale::DateTimeFormatOptions)options); } void Locale::setDateFormat(const QString &format) @@ -504,13 +487,13 @@ void Locale::setNegativeSign(const QString &sign) void Locale::setPositiveMonetarySignPosition(Locale::SignPosition signpos) { - m_locale->setPositiveMonetarySignPosition(signpos); + m_locale->setPositiveMonetarySignPosition((KLocale::SignPosition)signpos); emit positiveMonetarySignPositionChanged(); } void Locale::setNegativeMonetarySignPosition(Locale::SignPosition signpos) { - m_locale->setNegativeMonetarySignPosition(signpos); + m_locale->setNegativeMonetarySignPosition((KLocale::SignPosition)signpos); emit negativeMonetarySignPositionChanged(); } @@ -526,12 +509,6 @@ void Locale::setNegativePrefixCurrencySymbol(bool prefix) emit negativePrefixCurrencySymbolChanged(); } -void Locale::setFracDigits(int digits) -{ - setMonetaryDecimalPlaces(digits); - emit monetaryDecimalPlacesChanged(); -} - void Locale::setMonetaryDecimalPlaces(int digits) { m_locale->setMonetaryDecimalPlaces(digits); @@ -569,12 +546,12 @@ void Locale::setPageSize(int size) Locale::MeasureSystem Locale::measureSystem() const { - return m_locale->measureSystem(); + return (Locale::MeasureSystem)m_locale->measureSystem(); } void Locale::setMeasureSystem(Locale::MeasureSystem value) { - m_locale->setMeasureSystem(value); + m_locale->setMeasureSystem((KLocale::MeasureSystem)value); emit measureSystemChanged(); } @@ -649,26 +626,15 @@ QString Locale::countryCodeToName(const QString &country) const return m_locale->countryCodeToName(country); } -void Locale::setCalendar(const QString &calendarType) -{ - m_locale->setCalendar(calendarType); - emit calendarChanged(); -} - void Locale::setCalendarSystem(Locale::CalendarSystem calendarSystem) { - m_locale->setCalendarSystem(calendarSystem); + m_locale->setCalendarSystem((KLocale::CalendarSystem)calendarSystem); emit calendarSystemChanged(); } -QString Locale::calendarType() const -{ - return m_locale->calendarType(); -} - Locale::CalendarSystem Locale::calendarSystem() const { - return m_locale->calendarSystem(); + return (Locale::CalendarSystem)m_locale->calendarSystem(); } const KCalendarSystem * Locale::calendar() const @@ -678,23 +644,23 @@ const KCalendarSystem * Locale::calendar() const void Locale::setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem) { - m_locale->setWeekNumberSystem(weekNumberSystem); + m_locale->setWeekNumberSystem((KLocale::WeekNumberSystem)weekNumberSystem); emit WeekNumberSystemChanged(); } Locale::WeekNumberSystem Locale::weekNumberSystem() { - return m_locale->weekNumberSystem(); + return (Locale::WeekNumberSystem)m_locale->weekNumberSystem(); } Locale::WeekNumberSystem Locale::weekNumberSystem() const { - return m_locale->weekNumberSystem(); + return (Locale::WeekNumberSystem)m_locale->weekNumberSystem(); } void Locale::copyCatalogsTo(Locale *locale) -{ - m_locale->copyCatalogsTo(locale); +{//TODO find a better way to do the cast? + m_locale->copyCatalogsTo((KLocale *)locale); } QString Locale::localizedFilePath(const QString &filePath) const @@ -709,35 +675,35 @@ QString Locale::removeAcceleratorMarker(const QString &label) const void Locale::setDigitSet(Locale::DigitSet digitSet) { - m_locale->setDigitSet(digitSet); + m_locale->setDigitSet((KLocale::DigitSet)digitSet); emit digitSetChanged(); } Locale::DigitSet Locale::digitSet() const { - return m_locale->digitSet(); + return (Locale::DigitSet)m_locale->digitSet(); } void Locale::setMonetaryDigitSet(Locale::DigitSet digitSet) { - m_locale->setMonetaryDigitSet(digitSet); + m_locale->setMonetaryDigitSet((KLocale::DigitSet)digitSet); emit monetaryDigitSetChanged(); } Locale::DigitSet Locale::monetaryDigitSet() const { - return m_locale->monetaryDigitSet(); + return (Locale::DigitSet)m_locale->monetaryDigitSet(); } void Locale::setDateTimeDigitSet(Locale::DigitSet digitSet) { - m_locale->setDateTimeDigitSet(digitSet); + m_locale->setDateTimeDigitSet((KLocale::DigitSet)digitSet); emit dateTimeDigitSetChanged(); } Locale::DigitSet Locale::dateTimeDigitSet() const { - return m_locale->dateTimeDigitSet(); + return (Locale::DigitSet)m_locale->dateTimeDigitSet(); } void Locale::reparseConfiguration() From e9db43b00a0142c6fddeae6695453a96cccf1e3e Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 31 Jan 2012 13:09:22 +0200 Subject: [PATCH 016/104] fix QList and remove an unnecessary emit. --- declarativeimports/locale/locale.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 80b62c0c3..8181dc1be 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -142,8 +142,13 @@ QString Locale::translateQt(const char *context, const char *sourceText, const c QList Locale::allDigitSetsList() const { - //TODO - return m_locale->allDigitSetsList(); + QList digitList; + + foreach(KLocale::DigitSet digit, m_locale->allDigitSetsList()) { + digitList.append((Locale::DigitSet)digit); + } + + return digitList; } QString Locale::digitSetToName(Locale::DigitSet digitSet, bool withDigits) const @@ -198,7 +203,6 @@ QString Locale::thousandsSeparator() const QString Locale::currencySymbol() const { - emit currencySymbolChanged(); return m_locale->currencySymbol(); } From d25d37230231bccfc10714114ff6575424977c18 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 31 Jan 2012 13:28:12 +0200 Subject: [PATCH 017/104] A simple copy of KCalendarSystem. I have just removed the deprecated methods. --- declarativeimports/locale/calendarsystem.cpp | 2506 ++++++++++++++++++ declarativeimports/locale/calendarsystem.h | 1324 +++++++++ 2 files changed, 3830 insertions(+) create mode 100644 declarativeimports/locale/calendarsystem.cpp create mode 100644 declarativeimports/locale/calendarsystem.h diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp new file mode 100644 index 000000000..77ef0e948 --- /dev/null +++ b/declarativeimports/locale/calendarsystem.cpp @@ -0,0 +1,2506 @@ +/* + Copyright (c) 2002 Carlos Moro + Copyright (c) 2002 Hans Petter Bieker + Copyright 2007, 2008, 2009, 2010 John Layt + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kcalendarsystem.h" +#include "kcalendarsystemprivate_p.h" + +#include "kdebug.h" +#include "kconfiggroup.h" + +#include + +#include "kdatetime.h" +#include "kdatetimeformatter_p.h" +#include "kdatetimeparser_p.h" +#include "kcalendarera_p.h" +#include "kcalendarsystemcoptic_p.h" +#include "kcalendarsystemethiopian_p.h" +#include "kcalendarsystemgregorian_p.h" +#include "kcalendarsystemhebrew_p.h" +#include "kcalendarsystemindiannational_p.h" +#include "kcalendarsystemislamiccivil_p.h" +#include "kcalendarsystemjalali_p.h" +#include "kcalendarsystemjapanese_p.h" +#include "kcalendarsystemjulian_p.h" +#include "kcalendarsystemminguo_p.h" +#include "kcalendarsystemqdate_p.h" +#include "kcalendarsystemthai_p.h" + +KCalendarSystem *KCalendarSystem::create(const QString &calendarType, const KLocale *locale) +{ + return create(calendarSystem(calendarType), locale); +} + +KCalendarSystem *KCalendarSystem::create(const QString &calendarType, KSharedConfig::Ptr config, + const KLocale *locale) +{ + return create(calendarSystem(calendarType), config, locale); +} + +QStringList KCalendarSystem::calendarSystems() +{ + QStringList lst; + + lst.append(QLatin1String("coptic")); + lst.append(QLatin1String("ethiopian")); + lst.append(QLatin1String("gregorian")); + lst.append(QLatin1String("gregorian-proleptic")); + lst.append(QLatin1String("hebrew")); + lst.append(QLatin1String("hijri")); + lst.append(QLatin1String("indian-national")); + lst.append(QLatin1String("jalali")); + lst.append(QLatin1String("japanese")); + lst.append(QLatin1String("julian")); + lst.append(QLatin1String("minguo")); + lst.append(QLatin1String("thai")); + + return lst; +} + +QString KCalendarSystem::calendarLabel(const QString &calendarType) +{ + if (calendarSystemsList().contains(calendarSystem(calendarType))) { + return KCalendarSystem::calendarLabel(KCalendarSystem::calendarSystem(calendarType)); + } else { + return ki18nc("@item Calendar system", "Invalid Calendar Type").toString(KGlobal::locale()); + } +} + +KCalendarSystem *KCalendarSystem::create(KLocale::CalendarSystem calendarSystem, const KLocale *locale) +{ + return create(calendarSystem, KSharedConfig::Ptr(), locale); +} + +KCalendarSystem *KCalendarSystem::create(KLocale::CalendarSystem calendarSystem, + KSharedConfig::Ptr config, + const KLocale *locale) +{ + switch (calendarSystem) { + case KLocale::QDateCalendar: + return new KCalendarSystemQDate(config, locale); + case KLocale::CopticCalendar: + return new KCalendarSystemCoptic(config, locale); + case KLocale::EthiopianCalendar: + return new KCalendarSystemEthiopian(config, locale); + case KLocale::GregorianCalendar: + return new KCalendarSystemGregorian(config, locale); + case KLocale::HebrewCalendar: + return new KCalendarSystemHebrew(config, locale); + case KLocale::IndianNationalCalendar: + return new KCalendarSystemIndianNational(config, locale); + case KLocale::IslamicCivilCalendar: + return new KCalendarSystemIslamicCivil(config, locale); + case KLocale::JalaliCalendar: + return new KCalendarSystemJalali(config, locale); + case KLocale::JapaneseCalendar: + return new KCalendarSystemJapanese(config, locale); + case KLocale::JulianCalendar: + return new KCalendarSystemJulian(config, locale); + case KLocale::MinguoCalendar: + return new KCalendarSystemMinguo(config, locale); + case KLocale::ThaiCalendar: + return new KCalendarSystemThai(config, locale); + default: + return new KCalendarSystemQDate(config, locale); + } +} + +QList KCalendarSystem::calendarSystemsList() +{ + QList list; + + list.append(KLocale::QDateCalendar); + list.append(KLocale::CopticCalendar); + list.append(KLocale::EthiopianCalendar); + list.append(KLocale::GregorianCalendar); + list.append(KLocale::HebrewCalendar); + list.append(KLocale::IslamicCivilCalendar); + list.append(KLocale::IndianNationalCalendar); + list.append(KLocale::JalaliCalendar); + list.append(KLocale::JapaneseCalendar); + list.append(KLocale::JulianCalendar); + list.append(KLocale::MinguoCalendar); + list.append(KLocale::ThaiCalendar); + + return list; +} + +QString KCalendarSystem::calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale) +{ + switch (calendarSystem) { + case KLocale::QDateCalendar: + return ki18nc("@item Calendar system", "Gregorian").toString(locale); + case KLocale::CopticCalendar: + return ki18nc("@item Calendar system", "Coptic").toString(locale); + case KLocale::EthiopianCalendar: + return ki18nc("@item Calendar system", "Ethiopian").toString(locale); + case KLocale::GregorianCalendar: + return ki18nc("@item Calendar system", "Gregorian (Proleptic)").toString(locale); + case KLocale::HebrewCalendar: + return ki18nc("@item Calendar system", "Hebrew").toString(locale); + case KLocale::IslamicCivilCalendar: + return ki18nc("@item Calendar system", "Islamic / Hijri (Civil)").toString(locale); + case KLocale::IndianNationalCalendar: + return ki18nc("@item Calendar system", "Indian National").toString(locale); + case KLocale::JalaliCalendar: + return ki18nc("@item Calendar system", "Jalali").toString(locale); + case KLocale::JapaneseCalendar: + return ki18nc("@item Calendar system", "Japanese").toString(locale); + case KLocale::JulianCalendar: + return ki18nc("@item Calendar system", "Julian").toString(locale); + case KLocale::MinguoCalendar: + return ki18nc("@item Calendar system", "Taiwanese").toString(locale); + case KLocale::ThaiCalendar: + return ki18nc("@item Calendar system", "Thai").toString(locale); + } + + return ki18nc("@item Calendar system", "Invalid Calendar Type").toString(locale); +} + +KLocale::CalendarSystem KCalendarSystem::calendarSystemForCalendarType(const QString &calendarType ) +{ + return calendarSystem( calendarType ); +} + +KLocale::CalendarSystem KCalendarSystem::calendarSystem(const QString &calendarType ) +{ + if (calendarType == QLatin1String("coptic")) { + return KLocale::CopticCalendar; + } else if (calendarType == QLatin1String("ethiopian")) { + return KLocale::EthiopianCalendar; + } else if (calendarType == QLatin1String("gregorian")) { + return KLocale::QDateCalendar; + } else if (calendarType == QLatin1String("gregorian-proleptic")) { + return KLocale::GregorianCalendar; + } else if (calendarType == QLatin1String("hebrew")) { + return KLocale::HebrewCalendar; + } else if (calendarType == QLatin1String("hijri")) { + return KLocale::IslamicCivilCalendar; + } else if (calendarType == QLatin1String("indian-national")) { + return KLocale::IndianNationalCalendar; + } else if (calendarType == QLatin1String("jalali")) { + return KLocale::JalaliCalendar; + } else if (calendarType == QLatin1String("japanese")) { + return KLocale::JapaneseCalendar; + } else if (calendarType == QLatin1String("julian")) { + return KLocale::JulianCalendar; + } else if (calendarType == QLatin1String("minguo")) { + return KLocale::MinguoCalendar; + } else if (calendarType == QLatin1String("thai")) { + return KLocale::ThaiCalendar; + } else { + return KLocale::QDateCalendar; + } +} + +QString KCalendarSystem::calendarType(KLocale::CalendarSystem calendarSystem) +{ + if (calendarSystem == KLocale::QDateCalendar) { + return QLatin1String("gregorian"); + } else if (calendarSystem == KLocale::CopticCalendar) { + return QLatin1String("coptic"); + } else if (calendarSystem == KLocale::EthiopianCalendar) { + return QLatin1String("ethiopian"); + } else if (calendarSystem == KLocale::GregorianCalendar) { + return QLatin1String("gregorian-proleptic"); + } else if (calendarSystem == KLocale::HebrewCalendar) { + return QLatin1String("hebrew"); + } else if (calendarSystem == KLocale::IndianNationalCalendar) { + return QLatin1String("indian-national"); + } else if (calendarSystem == KLocale::IslamicCivilCalendar) { + return QLatin1String("hijri"); + } else if (calendarSystem == KLocale::JalaliCalendar) { + return QLatin1String("jalali"); + } else if (calendarSystem == KLocale::JapaneseCalendar) { + return QLatin1String("japanese"); + } else if (calendarSystem == KLocale::JulianCalendar) { + return QLatin1String("julian"); + } else if (calendarSystem == KLocale::MinguoCalendar) { + return QLatin1String("minguo"); + } else if (calendarSystem == KLocale::ThaiCalendar) { + return QLatin1String("thai"); + } else { + return QLatin1String("gregorian"); + } +} + +// Shared d pointer base class definitions + +KCalendarSystemPrivate::KCalendarSystemPrivate(KCalendarSystem *q_ptr) + : q(q_ptr), + m_eraList(0), + m_shortYearWindowStartYear(2000) +{ +} + +KCalendarSystemPrivate::~KCalendarSystemPrivate() +{ + delete m_eraList; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +KLocale::CalendarSystem KCalendarSystemPrivate::calendarSystem() const +{ + return KLocale::QDateCalendar; +} + +// Dummy version as an example, remember to translate (see Gregorian for example) +// Add the Era's in chronological order, from earliest to latest +// This method MUST be re-implemented in any new Calendar System +void KCalendarSystemPrivate::loadDefaultEraList() +{ + addEra('-', 1, q->epoch().addDays(-1), -1, q->earliestValidDate(), QLatin1String("Before KDE"), QLatin1String("BK"), QLatin1String("%Ey %EC")); + addEra('+', 1, q->epoch(), 1, q->latestValidDate(), QLatin1String("Anno KDE"), QLatin1String("AK"), QLatin1String("%Ey %EC")); +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +int KCalendarSystemPrivate::monthsInYear(int year) const +{ + Q_UNUSED(year) + return 12; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +int KCalendarSystemPrivate::daysInMonth(int year, int month) const +{ + if (month == 2) { + if (isLeapYear(year)) { + return 29; + } else { + return 28; + } + } + + if (month == 4 || month == 6 || month == 9 || month == 11) { + return 30; + } + + return 31; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +int KCalendarSystemPrivate::daysInYear(int year) const +{ + if (isLeapYear(year)) { + return 366; + } else { + return 365; + } +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +int KCalendarSystemPrivate::daysInWeek() const +{ + return 7; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +bool KCalendarSystemPrivate::isLeapYear(int year) const +{ + if (year < 1) { + year = year + 1; + } + + if (year % 4 == 0) { + if (year % 100 != 0) { + return true; + } else if (year % 400 == 0) { + return true; + } + } + + return false; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +bool KCalendarSystemPrivate::hasLeapMonths() const +{ + return false; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +bool KCalendarSystemPrivate::hasYearZero() const +{ + return false; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +int KCalendarSystemPrivate::maxDaysInWeek() const +{ + return 7; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +int KCalendarSystemPrivate::maxMonthsInYear() const +{ + return 12; +} + +// Convenince, faster than calling year( ealiestValidDate() ), +// needed in fake-virtual functions so don't remove +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +int KCalendarSystemPrivate::earliestValidYear() const +{ + return -4712; +} + +// Convenince, faster than calling year( latestValidDate() ), +// needed in fake-virtual functions so don't remove +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +int KCalendarSystemPrivate::latestValidYear() const +{ + return 9999; +} + +// Dummy version +// This method MUST be re-implemented in any new Calendar System +QString KCalendarSystemPrivate::monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const +{ + Q_UNUSED(month); + Q_UNUSED(year); + Q_UNUSED(format); + Q_UNUSED(possessive); + return QString(); +} + +// Dummy version +// This method MUST be re-implemented in any new Calendar System +QString KCalendarSystemPrivate::weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const +{ + Q_UNUSED(weekDay); + Q_UNUSED(format); + return QString(); +} + +// Reimplement if special maths handling required, e.g. Hebrew. +int KCalendarSystemPrivate::week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const +{ + int y, m, d; + q->julianDayToDate(date.toJulianDay(), y, m, d); + + switch (weekNumberSystem) { + case KLocale::IsoWeekNumber: + return isoWeekNumber(date, yearNum); + case KLocale::FirstFullWeek: + return regularWeekNumber(date, locale()->weekStartDay(), 0, yearNum); + case KLocale::FirstPartialWeek: + return regularWeekNumber(date, locale()->weekStartDay(), 1, yearNum); + case KLocale::SimpleWeek: + return simpleWeekNumber(date, yearNum); + case KLocale::DefaultWeekNumber: + default: + return week(date, locale()->weekNumberSystem(), yearNum); + } +} + +// Reimplement if special maths handling required, e.g. Hebrew. +int KCalendarSystemPrivate::isoWeekNumber(const QDate &date, int *yearNum) const +{ + int y, m, d; + q->julianDayToDate(date.toJulianDay(), y, m, d); + + QDate firstDayWeek1, lastDay; + int week; + int weekDay1, dayOfWeek1InYear; + + // let's guess 1st day of 1st week + firstDayWeek1 = firstDayOfYear(y); + weekDay1 = dayOfWeek(firstDayWeek1); + + // iso 8601: week 1 is the first containing thursday and week starts on monday + if (weekDay1 > 4 /*Thursday*/) { + firstDayWeek1 = q->addDays(firstDayWeek1 , daysInWeek() - weekDay1 + 1); // next monday + } + + dayOfWeek1InYear = dayOfYear(firstDayWeek1); + + // our date in prev year's week + if (dayOfYear(date) < dayOfWeek1InYear) { + if (yearNum) { + *yearNum = addYears(y, - 1); + } + return isoWeeksInYear(addYears(y, - 1)); + } + + // let's check if its last week belongs to next year + lastDay = lastDayOfYear(y); + + // if our date is in last week && 1st week in next year has thursday + if ((dayOfYear(date) >= daysInYear(y) - dayOfWeek(lastDay) + 1) + && dayOfWeek(lastDay) < 4) { + if (yearNum) { + * yearNum = addYears(y, 1); + } + week = 1; + } else { + // To calculate properly the number of weeks from day a to x let's make a day 1 of week + if (weekDay1 < 5) { + firstDayWeek1 = q->addDays(firstDayWeek1, -(weekDay1 - 1)); + } + + if (yearNum) { + * yearNum = y; + } + + week = firstDayWeek1.daysTo(date) / daysInWeek() + 1; + } + + return week; +} + +// Reimplement if special maths handling required, e.g. Hebrew. +int KCalendarSystemPrivate::regularWeekNumber(const QDate &date, int weekStartDay, int firstWeekNumber, int *weekYear) const +{ + int y, m, d; + q->julianDayToDate(date.toJulianDay(), y, m, d); + + int firstWeekDayOffset = (dayOfWeek(date) - weekStartDay + daysInWeek()) % daysInWeek(); + int dayInYear = date.toJulianDay() - firstDayOfYear(y).toJulianDay(); // 0 indexed + int week = ((dayInYear - firstWeekDayOffset + daysInWeek()) / daysInWeek()); + + if (dayOfWeek(firstDayOfYear(y)) != weekStartDay) { + week = week + firstWeekNumber; + } + + if (week < 1) { + y = y - 1; + week = regularWeeksInYear(y, weekStartDay, firstWeekNumber); + } + + if (weekYear) { + *weekYear = y; + } + + return week; +} + +// Reimplement if special maths handling required, e.g. Hebrew. +int KCalendarSystemPrivate::simpleWeekNumber(const QDate &date, int *yearNum) const +{ + int y, m, d; + q->julianDayToDate(date.toJulianDay(), y, m, d); + if (yearNum) { + *yearNum = y; + } + return ((date.toJulianDay() - firstDayOfYear(y).toJulianDay()) / daysInWeek()) + 1; +} + +// Reimplement if special maths handling required, e.g. Hebrew. +int KCalendarSystemPrivate::weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const +{ + switch (weekNumberSystem) { + case KLocale::IsoWeekNumber: + return isoWeeksInYear(year); + case KLocale::FirstFullWeek: + return regularWeeksInYear(year, locale()->weekStartDay(), 0); + case KLocale::FirstPartialWeek: + return regularWeeksInYear(year, locale()->weekStartDay(), 1); + case KLocale::SimpleWeek: + return simpleWeeksInYear(year); + case KLocale::DefaultWeekNumber: + default: + return weeksInYear(year, locale()->weekNumberSystem()); + } +} + +// Reimplement if special maths handling required, e.g. Hebrew. +int KCalendarSystemPrivate::isoWeeksInYear(int year) const +{ + QDate lastDayOfThisYear = lastDayOfYear(year); + + int weekYear = year; + int lastWeekInThisYear = isoWeekNumber(lastDayOfThisYear, &weekYear); + + // If error, or the last day of the year is in the first week of next year use the week before + if (lastWeekInThisYear < 1 || weekYear != year) { + lastWeekInThisYear = isoWeekNumber(q->addDays(lastDayOfThisYear, -7), &weekYear); + } + + return lastWeekInThisYear; +} + +// Reimplement if special maths handling required, e.g. Hebrew. +int KCalendarSystemPrivate::regularWeeksInYear(int year, int weekStartDay, int firstWeekNumber) const +{ + return regularWeekNumber(lastDayOfYear(year), weekStartDay, firstWeekNumber, 0); +} + +// Reimplement if special maths handling required, e.g. Hebrew. +int KCalendarSystemPrivate::simpleWeeksInYear(int year) const +{ + return simpleWeekNumber(lastDayOfYear(year), 0); +} + +// Reimplement if special maths handling required, e.g. Hebrew. +// Works for calendars with constant number of months, or where leap month is last month of year +// Will not work for Hebrew or others where leap month is inserted in middle of year +void KCalendarSystemPrivate::dateDifference(const QDate &fromDate, const QDate &toDate, + int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const +{ + // This could be optimised a little but is left in full as it's easier to understand + int dy = 0; + int dm = 0; + int dd = 0; + int dir = 1; + + if (toDate < fromDate) { + dateDifference(toDate, fromDate, &dy, &dm, &dd, 0); + dir = -1; + } else if (toDate > fromDate) { + + int fromYear = q->year(fromDate); + int toYear = q->year(toDate); + int fromMonth = q->month(fromDate); + int toMonth = q->month(toDate); + int fromDay = q->day(fromDate); + int toDay = q->day(toDate); + + int monthsInPrevYear = monthsInYear(addYears(toYear, -1)); + int daysInPrevMonth = q->daysInMonth(q->addMonths(toDate, -1)); + int daysInFromMonth = daysInMonth(fromYear, fromMonth); + int daysInToMonth = daysInMonth(toYear, toMonth); + + // Calculate years difference + if (toYear == fromYear) { + dy = 0; + } else if (toMonth > fromMonth) { + dy = differenceYearNumbers(fromYear, toYear); + } else if (toMonth < fromMonth) { + dy = differenceYearNumbers(fromYear, toYear) - 1; + } else { // toMonth == fromMonth + // Allow for last day of month to last day of month and leap days + // e.g. 2000-02-29 to 2001-02-28 is 1 year not 0 years + if ((toDay >= fromDay) || (fromDay == daysInFromMonth && toDay == daysInToMonth)) { + dy = differenceYearNumbers(fromYear, toYear); + } else { + dy = differenceYearNumbers(fromYear, toYear) - 1; + } + } + + // Calculate months and days difference + if (toDay >= fromDay) { + dm = (monthsInPrevYear + toMonth - fromMonth) % monthsInPrevYear; + dd = toDay - fromDay; + } else { // toDay < fromDay + // Allow for last day of month to last day of month and leap days + // e.g. 2010-03-31 to 2010-04-30 is 1 month + // 2000-02-29 to 2001-02-28 is 1 year + // 2000-02-29 to 2001-03-01 is 1 year 1 day + int prevMonth = q->month(q->addMonths(toDate, -1)); + if (fromDay == daysInFromMonth && toDay == daysInToMonth) { + dm = (monthsInPrevYear + toMonth - fromMonth) % monthsInPrevYear; + dd = 0; + } else if (prevMonth == fromMonth && daysInPrevMonth < daysInFromMonth) { + // Special case where fromDate = leap day and toDate in month following but non-leap year + // e.g. 2000-02-29 to 2001-03-01 needs to use 29 to calculate day number not 28 + dm = (monthsInPrevYear + toMonth - fromMonth - 1) % monthsInPrevYear; + dd = (daysInFromMonth + toDay - fromDay) % daysInFromMonth; + } else { + dm = (monthsInPrevYear + toMonth - fromMonth - 1) % monthsInPrevYear; + dd = (daysInPrevMonth + toDay - fromDay) % daysInPrevMonth; + } + } + + } + + // Only return values if we have a valid pointer + if (yearsDiff) { + *yearsDiff = dy; + } + if (monthsDiff) { + *monthsDiff = dm; + } + if (daysDiff) { + *daysDiff = dd; + } + if (direction) { + *direction = dir; + } +} + +// Reimplement if special maths handling required, e.g. Hebrew +// Allows for calendars with leap months at end of year but not during year +int KCalendarSystemPrivate::yearsDifference(const QDate &fromDate, const QDate &toDate) const +{ + // This could be optimised a little but is left in full as it's easier to understand + // Alternatively could just call dateDifference(), but this is slightly more efficient + + if (toDate < fromDate) { + return 0 - yearsDifference(toDate, fromDate); + } + + if (toDate == fromDate) { + return 0; + } + + int fromYear = q->year(fromDate); + int toYear = q->year(toDate); + + if (toYear == fromYear) { + return 0; + } + + int fromMonth = q->month(fromDate); + int toMonth = q->month(toDate); + + if (toMonth > fromMonth) { + return differenceYearNumbers(fromYear, toYear); + } + + if (toMonth < fromMonth) { + return differenceYearNumbers(fromYear, toYear) - 1; + } + + // toMonth == fromMonth + int fromDay = q->day(fromDate); + int toDay = q->day(toDate); + + // Adjust for month numbers in from and to year + // Allow for last day of month to last day of month and leap days + // e.g. 2000-02-29 to 2001-02-28 is 1 year not 0 years + if ((toDay >= fromDay) || + (fromDay == daysInMonth(fromYear, fromMonth) && + toDay == daysInMonth(toYear, toMonth))) { + return differenceYearNumbers(fromYear, toYear); + } else { + return differenceYearNumbers(fromYear, toYear) - 1; + } + +} + +// Reimplement if special maths handling required, e.g. maybe Hebrew? +// Allows for calendars with leap months +int KCalendarSystemPrivate::monthsDifference(const QDate &fromDate, const QDate &toDate) const +{ + if (toDate < fromDate) { + return 0 - monthsDifference(toDate, fromDate); + } + + if (toDate == fromDate) { + return 0; + } + + int fromYear = q->year(fromDate); + int toYear = q->year(toDate); + int fromMonth = q->month(fromDate); + int toMonth = q->month(toDate); + int fromDay = q->day(fromDate); + int toDay = q->day(toDate); + + int monthsInPreceedingYears; + + // Calculate number of months in full years preceding toYear + if (toYear == fromYear) { + monthsInPreceedingYears = 0; + } else if (hasLeapMonths()) { + monthsInPreceedingYears = 0; + for (int y = fromYear; y < toYear; y = addYears(y, 1)) { + monthsInPreceedingYears = monthsInPreceedingYears + monthsInYear(y); + } + } else { + monthsInPreceedingYears = differenceYearNumbers(fromYear, toYear) * monthsInYear(toYear); + } + + // Adjust for months in from and to year + // Allow for last day of month to last day of month and leap days + // e.g. 2010-03-31 to 2010-04-30 is 1 month not 0 months + // also 2000-02-29 to 2001-02-28 is 12 months not 11 months + if ((toDay >= fromDay) || + (fromDay == daysInMonth(fromYear, fromMonth) && + toDay == daysInMonth(toYear, toMonth))) { + return monthsInPreceedingYears + toMonth - fromMonth; + } else { + return monthsInPreceedingYears + toMonth - fromMonth - 1; + } +} + +// Reimplement if special string to integer handling required, e.g. Hebrew. +// Peel a number off the front of a string which may have other trailing chars after the number +// Stop either at either maxLength, eos, or first non-digit char +int KCalendarSystemPrivate::integerFromString(const QString &string, int maxLength, int &readLength) const +{ + int value = -1; + int position = 0; + readLength = 0; + bool ok = false; + + if (maxLength < 0) { + maxLength = string.length(); + } + + while (position < string.length() && + position < maxLength && + string.at(position).isDigit()) { + position++; + } + + if (position > 0) { + value = string.left(position).toInt(&ok); + if (ok) { + readLength = position; + } else { + value = -1; + } + } + + return value; +} + +// Reimplement if special integer to string handling required, e.g. Hebrew. +// Utility to convert an integer into the correct display string form +QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QChar padChar) const +{ + return stringFromInteger(number, padWidth, padChar, q->locale()->dateTimeDigitSet()); +} + +// Reimplement if special integer to string handling required, e.g. Hebrew. +// Utility to convert an integer into the correct display string form +QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QChar padChar, KLocale::DigitSet digitSet) const +{ + if (padChar == QLatin1Char('\0') || padWidth == 0) { + return q->locale()->convertDigits(QString::number(number), digitSet); + } else { + return q->locale()->convertDigits(QString::number(number).rightJustified(padWidth, padChar), digitSet); + } +} + +// Allows us to set dates outside publically valid range, USE WITH CARE!!!! +bool KCalendarSystemPrivate::setAnyDate(QDate &date, int year, int month, int day) const +{ + int jd; + q->dateToJulianDay(year, month, day, jd); + date = QDate::fromJulianDay(jd); + return true; +} + +// Utility to correctly add years to a year number because some systems such as +// Julian and Gregorian calendars don't have a year 0 +int KCalendarSystemPrivate::addYears(int originalYear, int addYears) const +{ + int newYear = originalYear + addYears; + + if (!hasYearZero()) { + if (originalYear > 0 && newYear <= 0) { + newYear = newYear - 1; + } else if (originalYear < 0 && newYear >= 0) { + newYear = newYear + 1; + } + } + + return newYear; +} + +// Utility to correctly return number of years between two year numbers because some systems such as +// Julian and Gregorian calendars don't have a year 0 +int KCalendarSystemPrivate::differenceYearNumbers(int fromYear, int toYear) const +{ + int dy = toYear - fromYear; + + if (!hasYearZero()) { + if (toYear > 0 && fromYear < 0) { + dy = dy - 1; + } else if (toYear < 0 && fromYear > 0) { + dy = dy + 1; + } + } + + return dy; +} + +QDate KCalendarSystemPrivate::invalidDate() const +{ + //Is QDate's way of saying is invalid + return QDate(); +} + +QString KCalendarSystemPrivate::simpleDateString(const QString &str) const +{ + QString newStr; + for (int i = 0; i < str.length(); i++) { + if (str.at(i).isLetterOrNumber()) { + newStr.append(str.at(i)); + } else { + newStr.append(QLatin1Char(' ')); + } + } + newStr.simplified(); + return newStr; +} + +int KCalendarSystemPrivate::dayOfYear(const QDate &date) const +{ + int y, m, d, jdFirstDayOfYear; + q->julianDayToDate(date.toJulianDay(), y, m, d); + q->dateToJulianDay(y, 1, 1, jdFirstDayOfYear); + //Take the jd of the given date, and subtract the jd of the first day of that year + return (date.toJulianDay() - jdFirstDayOfYear + 1); +} + +int KCalendarSystemPrivate::dayOfWeek(const QDate &date) const +{ + // Makes assumption that Julian Day 0 was day 1 of week + // This is true for Julian/Gregorian calendar with jd 0 being Monday + // We add 1 for ISO compliant numbering for 7 day week + // Assumes we've never skipped weekdays + return ((date.toJulianDay() % daysInWeek()) + 1); +} + +QDate KCalendarSystemPrivate::firstDayOfYear(int year) const +{ + int jd; + q->dateToJulianDay(year, 1, 1, jd); + return QDate::fromJulianDay(jd); +} + +QDate KCalendarSystemPrivate::lastDayOfYear(int year) const +{ + int jd; + q->dateToJulianDay(year, 1, 1, jd); + jd = jd + daysInYear(year) - 1; + return QDate::fromJulianDay(jd); +} + +QDate KCalendarSystemPrivate::firstDayOfMonth(int year, int month) const +{ + int jd; + q->dateToJulianDay(year, month, 1, jd); + return QDate::fromJulianDay(jd); +} + +QDate KCalendarSystemPrivate::lastDayOfMonth(int year, int month) const +{ + int jd; + q->dateToJulianDay(year, month, 1, jd); + jd = jd + daysInMonth(year, month) - 1; + return QDate::fromJulianDay(jd); +} + +const KLocale * KCalendarSystemPrivate::locale() const +{ + if (m_locale) { + return m_locale; + } else { + return KGlobal::locale(); + } +} + +QList *KCalendarSystemPrivate::eraList() const +{ + return m_eraList; +} + +KCalendarEra KCalendarSystemPrivate::era(const QDate &eraDate) const +{ + for (int i = m_eraList->count() - 1; i >= 0; --i) { + if (m_eraList->at(i).isInEra(eraDate)) { + return m_eraList->at(i); + } + } + return KCalendarEra(); +} + +KCalendarEra KCalendarSystemPrivate::era(const QString &eraName, int yearInEra) const +{ + Q_UNUSED(yearInEra) + + for (int i = m_eraList->count() - 1; i >= 0; --i) { + KCalendarEra era = m_eraList->at(i); + if (era.name(KLocale::LongName).toLower() == eraName.toLower() || + era.name(KLocale::ShortName).toLower() == eraName.toLower()) { + return era; + } + } + return KCalendarEra(); +} + +void KCalendarSystemPrivate::loadEraList(const KConfigGroup & cg) +{ + delete m_eraList; + m_eraList = new QList; + QString eraKey = QString::fromLatin1("Era1"); + int i = 1; + while (cg.hasKey(eraKey)) { + QString eraEntry = cg.readEntry(eraKey, QString()); + if (!eraEntry.isEmpty()) { + // Based on LC_TIME, but different! + // Includes long and short names, uses ISO fomat dates + // e.g. +:1:0001-01-01:9999-12-31:Anno Domini:AD:%EC %Ey + QChar direction = eraEntry.section(QLatin1Char(':'), 0, 0).at(0); + QDate startDate, endDate; + int startYear; + QString buffer = eraEntry.section(QLatin1Char(':'), 2, 2); + if (buffer.isEmpty()) { + if (direction == QLatin1Char('-')) { + startDate = q->latestValidDate(); + } else { + startDate = q->earliestValidDate(); + } + } else { + startDate = q->readDate(buffer, KLocale::IsoFormat); + } + if (q->isValid(startDate)) { + startYear = q->year(startDate); + } else { + startYear = eraEntry.section(QLatin1Char(':'), 1, 1).toInt(); //Use offset + } + + buffer = eraEntry.section(QLatin1Char(':'), 3, 3); + if (buffer.isEmpty()) { + if (direction == QLatin1Char('-')) { + endDate = q->earliestValidDate(); + } else { + endDate = q->latestValidDate(); + } + } else { + endDate = q->readDate(buffer, KLocale::IsoFormat); + } + addEra(direction.toLatin1(), eraEntry.section(QLatin1Char(':'), 1, 1).toInt(), + startDate, startYear, endDate, eraEntry.section(QLatin1Char(':'), 4, 4), + eraEntry.section(QLatin1Char(':'), 5, 5), eraEntry.section(QLatin1Char(':'), 6)); + } + ++i; + eraKey = QString::fromLatin1("Era%1").arg(i); + } + + if (m_eraList->isEmpty()) { + loadDefaultEraList(); + } +} + +void KCalendarSystemPrivate::addEra(char direction, int offset, + const QDate &startDate, int startYear, const QDate &endDate, + const QString &name, const QString &shortName, + const QString &format) +{ + KCalendarEra newEra; + + newEra.m_sequence = m_eraList->count() + 1; + if (direction == '-') { + newEra.m_direction = -1; + } else { + newEra.m_direction = 1; + } + newEra.m_offset = offset; + newEra.m_startDate = startDate; + newEra.m_startYear = startYear; + newEra.m_endDate = endDate; + newEra.m_longName = name; + newEra.m_shortName = shortName; + newEra.m_format = format; + + m_eraList->append(newEra); +} + +int KCalendarSystemPrivate::shortYearWindowStartYear() const +{ + return m_shortYearWindowStartYear; +} + +int KCalendarSystemPrivate::applyShortYearWindow(int inputYear) const +{ + if (inputYear >= 0 && inputYear <= 99) { + int shortStartYear = m_shortYearWindowStartYear % 100; + int yearOffset = m_shortYearWindowStartYear - shortStartYear; + if (inputYear >= shortStartYear) { + return inputYear + yearOffset; + } else { + return inputYear + yearOffset + 100; + } + } else { + return inputYear; + } +} + +void KCalendarSystemPrivate::loadShortYearWindowStartYear(const KConfigGroup & cg) +{ + // Default to 2000 for backwards compatibility + // as that's the old readDate() default value + int startYear = 2000; + if (cg.exists()) { + startYear = cg.readEntry("ShortYearWindowStartYear", 2000); + } + m_shortYearWindowStartYear = startYear; +} + +KSharedConfig::Ptr KCalendarSystemPrivate::config() +{ + if (m_config == KSharedConfig::Ptr()) { + return KGlobal::config(); + } else { + return m_config; + } +} + +void KCalendarSystemPrivate::loadConfig(const QString & calendarType) +{ + KConfigGroup localeGroup(config(), QString::fromLatin1("Locale")); + KConfigGroup calendarGroup = localeGroup.group(QString::fromLatin1("KCalendarSystem %1").arg(calendarType)); + loadEraList(calendarGroup); + loadShortYearWindowStartYear(calendarGroup); +} + + +KCalendarSystem::KCalendarSystem(const KLocale *locale) + : d_ptr(new KCalendarSystemPrivate(this)) +{ + d_ptr->m_config = KSharedConfig::Ptr(); + d_ptr->m_locale = locale; +} + +KCalendarSystem::KCalendarSystem(const KSharedConfig::Ptr config, const KLocale *locale) + : d_ptr(new KCalendarSystemPrivate(this)) +{ + d_ptr->m_config = config; + d_ptr->m_locale = locale; +} + +KCalendarSystem::KCalendarSystem(KCalendarSystemPrivate &dd, const KSharedConfig::Ptr config, const KLocale *locale) + : d_ptr(&dd) +{ + d_ptr->m_config = config; + d_ptr->m_locale = locale; +} + +KCalendarSystem::~KCalendarSystem() +{ + delete d_ptr; +} + +// NOT VIRTUAL - If override needed use shared-d +KLocale::CalendarSystem KCalendarSystem::calendarSystem() const +{ + Q_D(const KCalendarSystem); + + return d->calendarSystem(); +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::calendarLabel() const +{ + return KCalendarSystem::calendarLabel(calendarSystem()); +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +QDate KCalendarSystem::epoch() const +{ + return QDate::fromJulianDay(38); +} + +QDate KCalendarSystem::earliestValidDate() const +{ + return epoch(); +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +QDate KCalendarSystem::latestValidDate() const +{ + // Default to Gregorian 9999-12-31 + return QDate::fromJulianDay(5373484); +} + +bool KCalendarSystem::isValid(int year, int month, int day) const +{ + Q_D(const KCalendarSystem); + + if (year < d->earliestValidYear() || year > d->latestValidYear() || + (!d->hasYearZero() && year == 0)) { + return false; + } + + if (month < 1 || month > d->monthsInYear(year)) { + return false; + } + + if (day < 1 || day > d->daysInMonth(year, month)) { + return false; + } + + return true; +} + +// NOT VIRTUAL - If override needed use shared-d +bool KCalendarSystem::isValid(int year, int dayOfYear) const +{ + Q_D(const KCalendarSystem); + + return (isValid(year, 1, 1) && dayOfYear > 0 && dayOfYear <= d->daysInYear(year)); +} + +// NOT VIRTUAL - If override needed use shared-d +bool KCalendarSystem::isValid(const QString &eraName, int yearInEra, int month, int day) const +{ + Q_D(const KCalendarSystem); + + KCalendarEra era = d->era(eraName, yearInEra); + return (era.isValid() && isValid(era.year(yearInEra), month, day)); +} + +// NOT VIRTUAL - If override needed use shared-d +bool KCalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const +{ + Q_D(const KCalendarSystem); + + //Tests Year value in standard YMD isValid() + if (!isValid(year, 1, 1)) { + return false; + } + + //Test Week Number falls in valid range for this year + int weeksInThisYear = weeksInYear(year); + if (isoWeekNumber < 1 || isoWeekNumber > weeksInThisYear) { + return false; + } + + //Test Day of Week Number falls in valid range + if (dayOfIsoWeek < 1 || dayOfIsoWeek > d->daysInWeek()) { + return false; + } + + //If not in earliest or latest years then all OK + //Otherwise need to check don't fall into previous or next year that would be invalid + if (year == d->earliestValidYear() && isoWeekNumber == 1) { + //If firstDayOfYear falls on or before Thursday then firstDayOfYear falls in week 1 this + //year and if wanted dayOfIsoWeek falls before firstDayOfYear then falls in previous year + //and so in invalid year + int dowFirstDay = dayOfWeek(d->firstDayOfYear(year)); + if (dowFirstDay <= 4 && dayOfIsoWeek < dowFirstDay) { + return false; + } + } else if (year == d->latestValidYear() && isoWeekNumber == weeksInThisYear) { + //If lastDayOfYear falls on or after Thursday then lastDayOfYear falls in last week this + //year and if wanted dayOfIsoWeek falls after lastDayOfYear then falls in next year + //and so in invalid year + int dowLastDay = dayOfWeek(d->lastDayOfYear(year)); + if (dowLastDay >= 4 && dayOfIsoWeek > dowLastDay) { + return false; + } + } + + return true; +} + +bool KCalendarSystem::isValid(const QDate &date) const +{ + if (date.isNull() || date < earliestValidDate() || date > latestValidDate()) { + return false; + } + return true; +} + +bool KCalendarSystem::setDate(QDate &date, int year, int month, int day) const +{ + Q_D(const KCalendarSystem); + + date = d->invalidDate(); + + if (isValid(year, month, day)) { + int jd; + dateToJulianDay(year, month, day, jd); + QDate calcDate = QDate::fromJulianDay(jd); + + if (isValid(calcDate)) { + date = calcDate; + return true; + } + } + + return false; +} + +// NOT VIRTUAL - If override needed use shared-d +bool KCalendarSystem::setDate(QDate &date, int year, int dayOfYear) const +{ + Q_D(const KCalendarSystem); + + date = d->invalidDate(); + + if (isValid(year, dayOfYear)) { + int jd; + dateToJulianDay(year, 1, 1, jd); + QDate calcDate = QDate::fromJulianDay(jd + dayOfYear - 1); + if (isValid(calcDate)) { + date = calcDate; + return true; + } + } + + return false; +} + +// NOT VIRTUAL - If override needed use shared-d +bool KCalendarSystem::setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const +{ + Q_D(const KCalendarSystem); + + KCalendarEra era = d->era(eraName, yearInEra); + return (era.isValid() && setDate(date, era.year(yearInEra), month, day)); +} + +// NOT VIRTUAL - If override needed use shared-d +bool KCalendarSystem::setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const +{ + Q_D(const KCalendarSystem); + + date = d->invalidDate(); + + if (isValidIsoWeekDate(year, isoWeekNumber, dayOfIsoWeek)) { + + QDate calcDate = d->firstDayOfYear(year); + int dowFirstDayOfYear = dayOfWeek(calcDate); + + int daysToAdd = (d->daysInWeek() * (isoWeekNumber - 1)) + dayOfIsoWeek; + + if (dowFirstDayOfYear <= 4) { + calcDate = calcDate.addDays(daysToAdd - dowFirstDayOfYear); + } else { + calcDate = calcDate.addDays(daysInWeek(calcDate) + daysToAdd - dowFirstDayOfYear); + } + + if (isValid(calcDate)) { + date = calcDate; + return true; + } + } + + return false; +} + +// Deprecated +bool KCalendarSystem::setYMD(QDate &date, int year, int month, int day) const +{ + return setDate(date, year, month, day); +} + +// NOT VIRTUAL - If override needed use shared-d +void KCalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const +{ + int y, m, d; + + if (isValid(date)) { + julianDayToDate(date.toJulianDay(), y, m, d); + } else { + y = 0; // How do you denote invalid year when we support -ve years? + m = 0; + d = 0; + } + + if (year) { + *year = y; + } + if (month) { + *month = m; + } + if (day) { + *day = d; + } + +} + +int KCalendarSystem::year(const QDate &date) const +{ + if (isValid(date)) { + int year, month, day; + + julianDayToDate(date.toJulianDay(), year, month, day); + + return year; + } + + return 0; // How do you denote invalid year when we support -ve years? +} + +int KCalendarSystem::month(const QDate &date) const +{ + if (isValid(date)) { + int year, month, day; + + julianDayToDate(date.toJulianDay(), year, month, day); + + return month; + } + + return 0; +} + +int KCalendarSystem::day(const QDate &date) const +{ + if (isValid(date)) { + int year, month, day; + + julianDayToDate(date.toJulianDay(), year, month, day); + + return day; + } + + return 0; +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::eraName(const QDate &date, StringFormat format) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + if (format == LongFormat) { + return d->era(date).name(KLocale::LongName); + } else { + return d->era(date).name(KLocale::ShortName); + } + } + + return QString(); +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::eraYear(const QDate &date, StringFormat format) const +{ + Q_UNUSED(format) + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return formatDate(date, d->era(date).format()); + } + + return QString(); +} + +// NOT VIRTUAL - If override needed use shared-d +int KCalendarSystem::yearInEra(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->era(date).yearInEra(year(date)); + } + + return -1; +} + +// NOT VIRTUAL - If override needed use shared-d +QList *KCalendarSystem::eraList() const +{ + Q_D(const KCalendarSystem); + + return d->eraList(); +} + +// NOT VIRTUAL - If override needed use shared-d +KCalendarEra KCalendarSystem::era(const QDate &eraDate) const +{ + Q_D(const KCalendarSystem); + + return d->era(eraDate); +} + +// NOT VIRTUAL - If override needed use shared-d +KCalendarEra KCalendarSystem::era(const QString &eraName, int yearInEra) const +{ + Q_D(const KCalendarSystem); + + return d->era(eraName, yearInEra); +} + +QDate KCalendarSystem::addYears(const QDate &date, int numYears) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + + int originalYear, originalMonth, originalDay; + julianDayToDate(date.toJulianDay(), originalYear, originalMonth, originalDay); + + int newYear = d->addYears(originalYear, numYears); + int newMonth = originalMonth; + int newDay = originalDay; + + //Adjust day number if new month has fewer days than old month + int daysInNewMonth = d->daysInMonth(newYear, newMonth); + if (daysInNewMonth < originalDay) { + newDay = daysInNewMonth; + } + + QDate newDate; + setDate(newDate, newYear, newMonth, newDay); + return newDate; + + } + + return d->invalidDate(); +} + +QDate KCalendarSystem::addMonths(const QDate &date, int numMonths) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + + int originalYear, originalMonth, originalDay; + julianDayToDate(date.toJulianDay(), originalYear, originalMonth, originalDay); + + int monthsInOriginalYear = d->monthsInYear(originalYear); + + int newYear = d->addYears(originalYear, (originalMonth + numMonths) / monthsInOriginalYear); + int newMonth = (originalMonth + numMonths) % monthsInOriginalYear; + int newDay = originalDay; + + if (newMonth == 0) { + newYear = d->addYears(newYear, - 1); + newMonth = monthsInOriginalYear; + } + if (newMonth < 0) { + newYear = d->addYears(newYear, - 1); + newMonth = newMonth + monthsInOriginalYear; + } + + //Adjust day number if new month has fewer days than old month + int daysInNewMonth = d->daysInMonth(newYear, newMonth); + if (daysInNewMonth < originalDay) { + newDay = daysInNewMonth; + } + + QDate newDate; + setDate(newDate, newYear, newMonth, newDay); + return newDate; + + } + + return d->invalidDate(); +} + +QDate KCalendarSystem::addDays(const QDate &date, int numDays) const +{ + Q_D(const KCalendarSystem); + + // QDate only holds a uint and has no boundary checking in addDays(), so we need to check + if (isValid(date) && (long) date.toJulianDay() + (long) numDays > 0) { + // QDate adds straight to jd + QDate temp = date.addDays(numDays); + if (isValid(temp)) { + return temp; + } + } + + return d->invalidDate(); +} + +// NOT VIRTUAL - Uses shared-d instead +void KCalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate, + int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const +{ + Q_D(const KCalendarSystem); + + if (isValid(fromDate) && isValid(toDate)) { + d->dateDifference(fromDate, toDate, yearsDiff, monthsDiff, daysDiff, direction); + } +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const +{ + Q_D(const KCalendarSystem); + + if (isValid(fromDate) && isValid(toDate)) { + return d->yearsDifference(fromDate, toDate); + } + + return 0; +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::monthsDifference(const QDate &fromDate, const QDate &toDate) const +{ + Q_D(const KCalendarSystem); + + if (isValid(fromDate) && isValid(toDate)) { + return d->monthsDifference(fromDate, toDate); + } + + return 0; +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) const +{ + if (isValid(fromDate) && isValid(toDate)) { + return toDate.toJulianDay() - fromDate.toJulianDay(); + } + + return 0; +} + +int KCalendarSystem::monthsInYear(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->monthsInYear(year(date)); + } + + return -1; +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::monthsInYear(int year) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, 1, 1)) { + return d->monthsInYear(year); + } + + return -1; +} + +int KCalendarSystem::weeksInYear(const QDate &date) const +{ + return weeksInYear(date, KLocale::DefaultWeekNumber); +} + +int KCalendarSystem::weeksInYear(int year) const +{ + return weeksInYear(year, KLocale::DefaultWeekNumber); +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::weeksInYear(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->weeksInYear(year(date), weekNumberSystem); + } + + return -1; +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, 1, 1)) { + return d->weeksInYear(year, weekNumberSystem); + } + + return -1; +} + +int KCalendarSystem::daysInYear(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->daysInYear(year(date)); + } + + return -1; +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::daysInYear(int year) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, 1, 1)) { + return d->daysInYear(year); + } + + return -1; +} + +int KCalendarSystem::daysInMonth(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + int year, month; + getDate(date, &year, &month, 0); + return d->daysInMonth(year, month); + } + + return -1; +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::daysInMonth(int year, int month) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, 1, 1)) { + return d->daysInMonth(year, month); + } + + return -1; +} + +int KCalendarSystem::daysInWeek(const QDate &date) const +{ + Q_UNUSED(date) + Q_D(const KCalendarSystem); + return d->daysInWeek(); +} + +int KCalendarSystem::dayOfYear(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->dayOfYear(date); + } + + return -1; +} + +int KCalendarSystem::dayOfWeek(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->dayOfWeek(date); + } + + return -1; +} + +int KCalendarSystem::weekNumber(const QDate &date, int *yearNum) const +{ + return week(date, KLocale::IsoWeekNumber, yearNum); +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::week(const QDate &date, int *yearNum) const +{ + return week(date, KLocale::DefaultWeekNumber, yearNum); +} + +// NOT VIRTUAL - Uses shared-d instead +int KCalendarSystem::week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->week(date, weekNumberSystem, yearNum); + } + + return -1; +} + +bool KCalendarSystem::isLeapYear(int year) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, 1, 1)) { + return d->isLeapYear(year); + } + + return false; +} + +bool KCalendarSystem::isLeapYear(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->isLeapYear(year(date)); + } + + return false; +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::firstDayOfYear(int year) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, 1, 1)) { + return d->firstDayOfYear(year); + } + + return QDate(); +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::lastDayOfYear(int year) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, 1, 1)) { + return d->lastDayOfYear(year); + } + + return QDate(); +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::firstDayOfYear(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->firstDayOfYear(year(date)); + } + + return QDate(); +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::lastDayOfYear(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + return d->lastDayOfYear(year(date)); + } + + return QDate(); +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::firstDayOfMonth(int year, int month) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, month, 1)) { + return d->firstDayOfMonth(year, month); + } + + return QDate(); +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::lastDayOfMonth(int year, int month) const +{ + Q_D(const KCalendarSystem); + + if (isValid(year, month, 1)) { + return d->lastDayOfMonth(year, month); + } + + return QDate(); +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::firstDayOfMonth(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + int year, month; + getDate(date, &year, &month, 0); + return d->firstDayOfMonth(year, month); + } + + return QDate(); +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::lastDayOfMonth(const QDate &date) const +{ + Q_D(const KCalendarSystem); + + if (isValid(date)) { + int year, month; + getDate(date, &year, &month, 0); + return d->lastDayOfMonth(year, month); + } + + return QDate(); +} + +QString KCalendarSystem::monthName(int month, int year, KCalendarSystem::MonthNameFormat format) const +{ + Q_D(const KCalendarSystem); + + if (!isValid(year, month, 1)) { + return QString(); + } + + if (format == KCalendarSystem::NarrowName) { + return d->monthName(month, year, KLocale::NarrowName, false); + } + + if (format == KCalendarSystem::ShortNamePossessive) { + return d->monthName(month, year, KLocale::ShortName, true); + } + + if (format == KCalendarSystem::ShortName) { + return d->monthName(month, year, KLocale::ShortName, false); + } + + if (format == KCalendarSystem::LongNamePossessive) { + return d->monthName(month, year, KLocale::LongName, true); + } + + // KCalendarSystem::LongName or any other + return d->monthName(month, year, KLocale::LongName, false); +} + +QString KCalendarSystem::monthName(const QDate &date, MonthNameFormat format) const +{ + if (isValid(date)) { + int year, month; + getDate(date, &year, &month, 0); + return monthName(month, year, format); + } + + return QString(); +} + +QString KCalendarSystem::weekDayName(int weekDay, KCalendarSystem::WeekDayNameFormat format) const +{ + Q_D(const KCalendarSystem); + + if (weekDay < 1 || weekDay > d->daysInWeek()) { + return QString(); + } + + if (format == KCalendarSystem::NarrowDayName) { + return d->weekDayName(weekDay, KLocale::NarrowName); + } + + if (format == KCalendarSystem::ShortDayName) { + return d->weekDayName(weekDay, KLocale::ShortName); + } + + if (format == KCalendarSystem::ShortDayName) { + return d->weekDayName(weekDay, KLocale::ShortName); + } + + return d->weekDayName(weekDay, KLocale::LongName); +} + +QString KCalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format) const +{ + if (isValid(date)) { + return weekDayName(dayOfWeek(date), format); + } + + return QString(); +} + +QString KCalendarSystem::yearString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::Year, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::Year, KLocale::LongNumber); + } +} + +QString KCalendarSystem::monthString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::Month, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::Month, KLocale::LongNumber); + } +} + +QString KCalendarSystem::dayString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::Day, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::Day, KLocale::LongNumber); + } +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::yearInEraString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::YearInEra, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::YearInEra, KLocale::LongNumber); + } +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::dayOfYearString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::DayOfYear, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::DayOfYear, KLocale::LongNumber); + } +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::dayOfWeekString(const QDate &date) const +{ + return formatDate(date, KLocale::DayOfWeek, KLocale::ShortNumber); +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::weekNumberString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::Week, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::Week, KLocale::LongNumber); + } +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::monthsInYearString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::MonthsInYear, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::MonthsInYear, KLocale::LongNumber); + } +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::weeksInYearString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::WeeksInYear, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::WeeksInYear, KLocale::LongNumber); + } +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::daysInYearString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::DaysInYear, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::DaysInYear, KLocale::LongNumber); + } +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::daysInMonthString(const QDate &date, StringFormat format) const +{ + if (format == ShortFormat) { + return formatDate(date, KLocale::DaysInMonth, KLocale::ShortNumber); + } else { + return formatDate(date, KLocale::DaysInMonth, KLocale::LongNumber); + } +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::daysInWeekString(const QDate &date) const +{ + return formatDate(date, KLocale::DaysInWeek, KLocale::ShortNumber); +} + +int KCalendarSystem::yearStringToInteger(const QString &yearString, int &readLength) const +{ + Q_D(const KCalendarSystem); + + QString minus = i18nc("Negative symbol as used for year numbers, e.g. -5 = 5 BC", "-"); + if (yearString.startsWith(minus)) { + int value = d->integerFromString(yearString.mid(minus.length()), 4, readLength); + if (readLength > 0 && value >= 0) { + readLength = readLength + minus.length(); + return value * -1; + } else { + return value; + } + } + + return d->integerFromString(yearString, 4, readLength); +} + +int KCalendarSystem::monthStringToInteger(const QString &monthString, int &readLength) const +{ + Q_D(const KCalendarSystem); + return d->integerFromString(monthString, 2, readLength); +} + +int KCalendarSystem::dayStringToInteger(const QString &dayString, int &readLength) const +{ + Q_D(const KCalendarSystem); + return d->integerFromString(dayString, 2, readLength); +} + +QString KCalendarSystem::formatDate(const QDate &fromDate, KLocale::DateFormat toFormat) const +{ + if (!fromDate.isValid()) { + return QString(); + } + + if (toFormat == KLocale::FancyShortDate || toFormat == KLocale::FancyLongDate) { + QDate now = KDateTime::currentLocalDate(); + int daysToNow = fromDate.daysTo(now); + switch (daysToNow) { + case 0: + return i18n("Today"); + case 1: + return i18n("Yesterday"); + case 2: + case 3: + case 4: + case 5: + case 6: + return weekDayName(fromDate); + default: + break; + } + } + + switch (toFormat) { + case KLocale::LongDate: + case KLocale::FancyLongDate: + return formatDate(fromDate, locale()->dateFormat()); + case KLocale::IsoDate: + return formatDate(fromDate, QLatin1String("%Y-%m-%d")); + case KLocale::IsoWeekDate: + return formatDate(fromDate, QLatin1String("%Y-W%V-%u")); + case KLocale::IsoOrdinalDate: + return formatDate(fromDate, QLatin1String("%Y-%j")); + case KLocale::ShortDate: + case KLocale::FancyShortDate: + default: + return formatDate(fromDate, locale()->dateFormatShort()); + } + +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, + KLocale::DateTimeFormatStandard standard) const +{ + return formatDate(fromDate, toFormat, locale()->dateTimeDigitSet(), standard); +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DigitSet digitSet, + KLocale::DateTimeFormatStandard formatStandard) const +{ + if (!isValid(fromDate) || toFormat.isEmpty()) { + return QString(); + } + + KDateTimeFormatter formatter; + return formatter.formatDate(fromDate, toFormat, this, locale(), digitSet, formatStandard); +} + +// NOT VIRTUAL - If override needed use shared-d +QString KCalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponent component, + KLocale::DateTimeComponentFormat format, + KLocale::WeekNumberSystem weekNumberSystem) const +{ + Q_D(const KCalendarSystem); + + switch (component) { + case KLocale::Year: + case KLocale::YearName: + switch (format) { + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + return formatDate(date, QLatin1String("%y")); + case KLocale::LongNumber: + case KLocale::LongName: + case KLocale::DefaultComponentFormat: + default: + return formatDate(date, QLatin1String("%Y")); + } + case KLocale::Month: + switch (format) { + case KLocale::LongName: + return monthName(date, KCalendarSystem::LongName); + case KLocale::ShortName: + return monthName(date, KCalendarSystem::ShortName); + case KLocale::NarrowName: + return monthName(date, KCalendarSystem::NarrowName); + case KLocale::LongNumber: + return formatDate(date, QLatin1String("%m")); + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return formatDate(date, QLatin1String("%n")); + } + case KLocale::MonthName: + switch (format) { + case KLocale::NarrowName: + return monthName(date, KCalendarSystem::NarrowName); + case KLocale::ShortName: + case KLocale::ShortNumber: + return monthName(date, KCalendarSystem::ShortName); + case KLocale::LongName: + case KLocale::LongNumber: + case KLocale::DefaultComponentFormat: + default: + return monthName(date, KCalendarSystem::LongName); + } + case KLocale::Day: + case KLocale::DayName: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return formatDate(date, QLatin1String("%d")); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return formatDate(date, QLatin1String("%e")); + } + case KLocale::JulianDay: + return d->stringFromInteger(date.toJulianDay(), 0); + case KLocale::EraName: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return eraName(date, KCalendarSystem::LongFormat); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return eraName(date, KCalendarSystem::ShortFormat); + } + case KLocale::EraYear: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return eraYear(date, KCalendarSystem::LongFormat); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return eraYear(date, KCalendarSystem::ShortFormat); + } + case KLocale::YearInEra: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return formatDate(date, QLatin1String("%4Ey")); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return formatDate(date, QLatin1String("%Ey")); + } + case KLocale::DayOfYear: + case KLocale::DayOfYearName: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return formatDate(date, QLatin1String("%j")); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return formatDate(date, QLatin1String("%-j")); + } + case KLocale::DayOfWeek: + switch (format) { + case KLocale::LongName: + return weekDayName(date, KCalendarSystem::LongDayName); + case KLocale::ShortName: + return weekDayName(date, KCalendarSystem::ShortDayName); + case KLocale::NarrowName: + return weekDayName(date, KCalendarSystem::NarrowDayName); + case KLocale::LongNumber: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return formatDate(date, QLatin1String("%-u")); + } + case KLocale::DayOfWeekName: + switch (format) { + case KLocale::NarrowName: + return weekDayName(date, KCalendarSystem::NarrowDayName); + case KLocale::ShortName: + case KLocale::ShortNumber: + return weekDayName(date, KCalendarSystem::ShortDayName); + case KLocale::LongName: + case KLocale::LongNumber: + case KLocale::DefaultComponentFormat: + default: + return weekDayName(date, KCalendarSystem::LongDayName); + } + case KLocale::Week: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return d->stringFromInteger(week(date, weekNumberSystem, 0), 2, QLatin1Char('0')); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return d->stringFromInteger(week(date, weekNumberSystem, 0), 0, QLatin1Char('0')); + } + case KLocale::WeekYear: { + int weekYear; + QDate yearDate; + week(date, weekNumberSystem, &weekYear); + setDate(yearDate, weekYear, 1, 1); + return formatDate(yearDate, KLocale::Year, format); + } + case KLocale::MonthsInYear: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return d->stringFromInteger(monthsInYear(date), 2, QLatin1Char('0')); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return d->stringFromInteger(monthsInYear(date), 0, QLatin1Char('0')); + } + case KLocale::WeeksInYear: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return d->stringFromInteger(weeksInYear(date), 2, QLatin1Char('0')); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return d->stringFromInteger(weeksInYear(date), 0, QLatin1Char('0')); + } + case KLocale::DaysInYear: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return d->stringFromInteger(daysInYear(date), 3, QLatin1Char('0')); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return d->stringFromInteger(daysInYear(date), 0, QLatin1Char('0')); + } + case KLocale::DaysInMonth: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + return d->stringFromInteger(daysInMonth(date), 2, QLatin1Char('0')); + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return d->stringFromInteger(daysInMonth(date), 0, QLatin1Char('0')); + } + case KLocale::DaysInWeek: + switch (format) { + case KLocale::LongNumber: + case KLocale::LongName: + case KLocale::ShortName: + case KLocale::NarrowName: + case KLocale::ShortNumber: + case KLocale::DefaultComponentFormat: + default: + return d->stringFromInteger(d->daysInWeek(), 0); + } + default: + return QString(); + } +} + +QDate KCalendarSystem::readDate(const QString &str, bool *ok) const +{ + //Try each standard format in turn, start with the locale ones, + //then the well defined standards + QDate date = readDate(str, KLocale::ShortFormat, ok); + if (!isValid(date)) { + date = readDate(str, KLocale::NormalFormat, ok); + if (!isValid(date)) { + date = readDate(str, KLocale::IsoFormat, ok); + if (!isValid(date)) { + date = readDate(str, KLocale::IsoWeekFormat, ok); + if (!isValid(date)) { + date = readDate(str, KLocale::IsoOrdinalFormat, ok); + } + } + } + } + + return date; +} + +QDate KCalendarSystem::readDate(const QString &str, KLocale::ReadDateFlags flags, bool *ok) const +{ + Q_D(const KCalendarSystem); + + if (flags & KLocale::ShortFormat) { + return readDate(str, locale()->dateFormatShort(), ok); + } else if (flags & KLocale::NormalFormat) { + return readDate(str, locale()->dateFormat(), ok); + } else if (flags & KLocale::IsoFormat) { + return readDate(str, QLatin1String("%Y-%m-%d"), ok); + } else if (flags & KLocale::IsoWeekFormat) { + return readDate(str, QLatin1String("%Y-W%V-%u"), ok); + } else if (flags & KLocale::IsoOrdinalFormat) { + return readDate(str, QLatin1String("%Y-%j"), ok); + } + return d->invalidDate(); +} + +QDate KCalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok) const +{ + return readDate(inputString, formatString, ok, KLocale::KdeFormat); +} + +// NOT VIRTUAL - If override needed use shared-d +QDate KCalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok, + KLocale::DateTimeFormatStandard formatStandard) const +{ + KDateTimeParser parser; + QDate resultDate = parser.parseDate(inputString, formatString, this, locale(), locale()->dateTimeDigitSet(), formatStandard); + if (ok) { + *ok = resultDate.isValid(); + } + return resultDate; +} + +// NOT VIRTUAL - If override needed use shared-d +int KCalendarSystem::shortYearWindowStartYear() const +{ + Q_D(const KCalendarSystem); + + return d->shortYearWindowStartYear(); +} + +// NOT VIRTUAL - If override needed use shared-d +int KCalendarSystem::applyShortYearWindow(int inputYear) const +{ + Q_D(const KCalendarSystem); + + return d->applyShortYearWindow(inputYear); +} + +int KCalendarSystem::weekStartDay() const +{ + return locale()->weekStartDay(); +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +// The implementation MUST NOT do validity checking on date ranges, all calls to this function MUST +// instead be wrapped in validity checks, as sometimes we want this to work outside the public valid +// range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but +// are required for internal maths +bool KCalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) const +{ + // Formula from The Calendar FAQ by Claus Tondering + // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000 + // NOTE: Coded from scratch from mathematical formulas, not copied from + // the Boost licensed source code + + int a = jd + 32044; + int b = ((4 * a) + 3) / 146097; + int c = a - ((146097 * b) / 4); + int d = ((4 * c) + 3) / 1461; + int e = c - ((1461 * d) / 4); + int m = ((5 * e) + 2) / 153; + day = e - (((153 * m) + 2) / 5) + 1; + month = m + 3 - (12 * (m / 10)); + year = (100 * b) + d - 4800 + (m / 10); + + // If year is -ve then is BC. In Gregorian there is no year 0, but the maths + // is easier if we pretend there is, so internally year of 0 = 1BC = -1 outside + if (year < 1) { + year = year - 1; + } + + return true; +} + +// Dummy version using Gregorian as an example +// This method MUST be re-implemented in any new Calendar System +// The implementation MUST NOT do validity checking on date ranges, all calls to this function MUST +// instead be wrapped in validity checks, as sometimes we want this to work outside the public valid +// range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but +// are required for internal maths +bool KCalendarSystem::dateToJulianDay(int year, int month, int day, int &jd) const +{ + // Formula from The Calendar FAQ by Claus Tondering + // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000 + // NOTE: Coded from scratch from mathematical formulas, not copied from + // the Boost licensed source code + + // If year is -ve then is BC. In Gregorian there is no year 0, but the maths + // is easier if we pretend there is, so internally year of -1 = 1BC = 0 internally + int y; + if (year < 1) { + y = year + 1; + } else { + y = year; + } + + int a = (14 - month) / 12; + y = y + 4800 - a; + int m = month + (12 * a) - 3; + + jd = day + + (((153 * m) + 2) / 5) + + (365 * y) + + (y / 4) + - (y / 100) + + (y / 400) + - 32045; + + return true; +} + +const KLocale * KCalendarSystem::locale() const +{ + Q_D(const KCalendarSystem); + + return d->locale(); +} + +// Deprecated +void KCalendarSystem::setMaxMonthsInYear(int maxMonths) +{ + Q_UNUSED(maxMonths) +} + +// Deprecated +void KCalendarSystem::setMaxDaysInWeek(int maxDays) +{ + Q_UNUSED(maxDays) +} + +// Deprecated +void KCalendarSystem::setHasYear0(bool hasYear0) +{ + Q_UNUSED(hasYear0) +} diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h new file mode 100644 index 000000000..2f96a1cbb --- /dev/null +++ b/declarativeimports/locale/calendarsystem.h @@ -0,0 +1,1324 @@ +/* + Copyright (c) 2002 Carlos Moro + Copyright (c) 2002-2003 Hans Petter Bieker + Copyright 2007, 2009, 2010 John Layt + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KCALENDARSYSTEM_H +#define KCALENDARSYSTEM_H + +#include +#include "klocale.h" // needed for enums +#include "kglobal.h" + +#include +#include + +class KCalendarSystemPrivate; +class KCalendarEra; + +/** + * KCalendarSystem abstract base class, provides support for local Calendar Systems in KDE + * + * Derived classes must be created through the create() static method + */ +class KDECORE_EXPORT KCalendarSystem +{ +public: + + /** + * Format for returned year number / month number / day number as string. + */ + enum StringFormat { + ShortFormat, /**< Short string format, e.g. 2000 = "00" or 6 = "6" */ + LongFormat /**< Long string format, e.g. 2000 = "2000" or 6 = "06" */ + }; + + /** + * Format for returned month / day name. + */ + enum MonthNameFormat { + ShortName, /**< Short name format, e.g. "Dec" */ + LongName, /**< Long name format, e.g. "December" */ + ShortNamePossessive, /**< Short name possessive format, e.g. "of Dec" */ + LongNamePossessive, /**< Long name possessive format, e.g. "of December" */ + NarrowName /**< Narrow name format, e.g. "D". @since 4.7 */ + }; + + /** + * Format for returned month / day name. + */ + enum WeekDayNameFormat { + ShortDayName, /**< Short name format, e.g. "Fri" */ + LongDayName, /**< Long name format, e.g. "Friday" */ + NarrowDayName /**< Narrow name format, e.g. "F". @since 4.7 */ + }; + + //KDE5 add default value to calendarSystem + /** + * @since 4.6 + * + * Creates a KCalendarSystem object for the required Calendar System + * + * @param calendarSystem the Calendar System to create, defaults to QDate compatible + * @param locale locale to use for translations. The global locale is used if null. + * @return a KCalendarSystem object + */ + static KCalendarSystem *create(KLocale::CalendarSystem calendarSystem, + const KLocale *locale = 0); + + /** + * @since 4.6 + * + * Creates a KCalendarSystem object for the required Calendar System + * + * @param calendarSystem the Calendar System to create + * @param config a configuration file with a 'KCalendarSystem %calendarType' group detailing + * locale-related preferences (such as era options). The global config is used + if null. + * @param locale locale to use for translations. The global locale is used if null. + * @return a KCalendarSystem object + */ + static KCalendarSystem *create(KLocale::CalendarSystem calendarSystem, KSharedConfig::Ptr config, + const KLocale *locale = 0); + + /** + * @since 4.6 + * + * Returns a localized label to display for the required Calendar System type. + * + * Use with calendarSystemsList() to populate selection lists of available + * calendar systems. + * + * @param calendarSystem the specific calendar type to return the label for + * @param locale the locale to use for the label, defaults to global + * @return label for calendar + */ + static QString calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale = KGlobal::locale()); + + /** + * @since 4.7 + * + * Returns the Calendar System enum value for a given Calendar Type, + * e.g. KLocale::QDateCalendar for "gregorian" + * + * @param calendarType the calendar type to convert + * @return calendar system for calendar type + */ + static KLocale::CalendarSystem calendarSystem(const QString &calendarType); + + //KDE5 remove + /** + * @since 4.7 + * + * Returns the deprecated Calendar Type for a given Calendar System enum value, + * e.g. "gregorian" for KLocale::QDateCalendar + * + * @param calendarSystem the calendar system to convert + * @return calendar type for calendar system + */ + static QString calendarType(KLocale::CalendarSystem calendarSystem); + + /** + * Constructor of abstract calendar class. This will be called by derived classes. + * + * @param locale locale to use for translations. The global locale is used if null. + */ + explicit KCalendarSystem(const KLocale *locale = 0); + + /** + * Constructor of abstract calendar class. This will be called by derived classes. + * + * @param config a configuration file with a 'KCalendarSystem %calendarName' group detailing + * locale-related preferences (such as era options). The global config is used + if null. + * @param locale locale to use for translations. The global locale is used if null. + */ + explicit KCalendarSystem(const KSharedConfig::Ptr config, const KLocale *locale = 0); + + /** + * Destructor. + */ + virtual ~KCalendarSystem(); + + /** + * @since 4.6 + * + * Returns the Calendar System type of the KCalendarSystem object + * + * @return type of calendar system + */ + KLocale::CalendarSystem calendarSystem() const; + + //KDE5 make virtual? + /** + * @since 4.6 + * + * Returns a localized label to display for the current Calendar System type. + * + * @return localized label for this Calendar System + */ + QString calendarLabel() const; + + /** + * Returns a QDate holding the epoch of the calendar system. Usually YMD + * of 1/1/1, access the returned QDates method toJulianDay() if you + * require the actual Julian day number. Note: a particular calendar + * system implementation may not include the epoch in its supported range, + * or the calendar system may be proleptic in which case it supports dates + * before the epoch. + * + * @see KCalendarSystem::earliestValidDate + * @see KCalendarSystem::latestValidDate + * @see KCalendarSystem::isProleptic + * @see KCalendarSystem::isValid + * + * @return epoch of calendar system + */ + virtual QDate epoch() const; + + /** + * Returns the earliest date valid in this calendar system implementation. + * + * If the calendar system is proleptic then this may be before epoch. + * + * @see KCalendarSystem::epoch + * @see KCalendarSystem::latestValidDate + * + * @return date the earliest valid date + */ + virtual QDate earliestValidDate() const; + + /** + * Returns the latest date valid in this calendar system implementation. + * + * @see KCalendarSystem::epoch + * @see KCalendarSystem::earliestValidDate + * + * @return date the latest valid date + */ + virtual QDate latestValidDate() const; + + /** + * Returns whether a given date is valid in this calendar system. + * + * @param year the year portion of the date to check + * @param month the month portion of the date to check + * @param day the day portion of the date to check + * @return @c true if the date is valid, @c false otherwise + */ + virtual bool isValid(int year, int month, int day) const = 0; + + //KDE5 make virtual? + /** + * @since 4.4 + * + * Returns whether a given date is valid in this calendar system. + * + * @param year the year portion of the date to check + * @param dayOfYear the day of year portion of the date to check + * @return @c true if the date is valid, @c false otherwise + */ + bool isValid(int year, int dayOfYear) const; + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Returns whether a given date is valid in this calendar system. + * + * @param eraName the Era Name portion of the date to check + * @param yearInEra the Year In Era portion of the date to check + * @param month the Month portion of the date to check + * @param day the Day portion of the date to check + * @return @c true if the date is valid, @c false otherwise + */ + bool isValid(const QString &eraName, int yearInEra, int month, int day) const; + + //KDE5 make virtual? + /** + * @since 4.4 + * + * Returns whether a given date is valid in this calendar system. + * + * @param year the year portion of the date to check + * @param isoWeekNumber the ISO week portion of the date to check + * @param dayOfIsoWeek the day of week portion of the date to check + * @return @c true if the date is valid, @c false otherwise + */ + bool isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const; + + /** + * Returns whether a given date is valid in this calendar system. + * + * @param date the date to check + * @return @c true if the date is valid, @c false otherwise + */ + virtual bool isValid(const QDate &date) const; + + /** + * Changes the date's year, month and day. The range of the year, month + * and day depends on which calendar is being used. All years entered + * are treated literally, i.e. no Y2K translation is applied to years + * entered in the range 00 to 99. Replaces setYMD. + * + * @param date date to change + * @param year year + * @param month month number + * @param day day of month + * @return @c true if the date is valid, @c false otherwise + */ + virtual bool setDate(QDate &date, int year, int month, int day) const; + + //KDE5 make virtual? + /** + * @since 4.4 + * + * Set a date using the year number and day of year number only. + * + * @param date date to change + * @param year year + * @param dayOfYear day of year + * @return @c true if the date is valid, @c false otherwise + */ + bool setDate(QDate &date, int year, int dayOfYear) const; + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Set a date using the era, year in era number, month and day + * + * @param date date to change + * @param eraName Era string + * @param yearInEra Year In Era number + * @param month Month number + * @param day Day Of Month number + * @return @c true if the date is valid, @c false otherwise + */ + bool setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const; + + //KDE5 make virtual? + /** + * @since 4.4 + * + * Set a date using the year number, ISO week number and day of week number. + * + * @param date date to change + * @param year year + * @param isoWeekNumber ISO week of year + * @param dayOfIsoWeek day of week Mon..Sun (1..7) + * @return @c true if the date is valid, @c false otherwise + */ + bool setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const; + + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Returns the year, month and day portion of a given date in the current calendar system + * + * @param date date to get year, month and day for + * @param year year number returned in this variable + * @param month month number returned in this variable + * @param day day of month returned in this variable + */ + void getDate(const QDate date, int *year, int *month, int *day) const; + + /** + * Returns the year portion of a given date in the current calendar system + * + * @param date date to return year for + * @return year, 0 if input date is invalid + */ + virtual int year(const QDate &date) const; + + /** + * Returns the month portion of a given date in the current calendar system + * + * @param date date to return month for + * @return month of year, 0 if input date is invalid + */ + virtual int month(const QDate &date) const; + + /** + * Returns the day portion of a given date in the current calendar system + * + * @param date date to return day for + * @return day of the month, 0 if input date is invalid + */ + virtual int day(const QDate &date) const; + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Returns the Era Name portion of a given date in the current calendar system, + * for example "AD" or "Anno Domini" for the Gregorian calendar and Christian Era. + * + * @param date date to return Era Name for + * @param format format to return, either short or long + * @return era name, empty string if input date is invalid + */ + QString eraName(const QDate &date, StringFormat format = ShortFormat) const; + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Returns the Era Year portion of a given date in the current + * calendar system, for example "2000 AD" or "Heisei 22". + * + * @param date date to return Era Year for + * @param format format to return, either short or long + * @return era name, empty string if input date is invalid + */ + QString eraYear(const QDate &date, StringFormat format = ShortFormat) const; + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Returns the Year In Era portion of a given date in the current calendar + * system, for example 1 for "1 BC". + * + * @param date date to return Year In Era for + * @return Year In Era, -1 if input date is invalid + */ + int yearInEra(const QDate &date) const; + + /** + * Returns a QDate containing a date @p nyears years later. + * + * @param date The old date + * @param nyears The number of years to add + * @return The new date, null date if any errors + */ + virtual QDate addYears(const QDate &date, int nyears) const; + + /** + * Returns a QDate containing a date @p nmonths months later. + * + * @param date The old date + * @param nmonths number of months to add + * @return The new date, null date if any errors + */ + virtual QDate addMonths(const QDate &date, int nmonths) const; + + /** + * Returns a QDate containing a date @p ndays days later. + * + * @param date The old date + * @param ndays number of days to add + * @return The new date, null date if any errors + */ + virtual QDate addDays(const QDate &date, int ndays) const; + + //KDE5 make virtual? + /** + * Returns the difference between two dates in years, months and days. + * The difference is always caculated from the earlier date to the later + * date in year, month and day order, with the @p direction parameter + * indicating which direction the difference is applied from the @p toDate. + * + * For example, the difference between 2010-06-10 and 2012-09-5 is 2 years, + * 2 months and 26 days. Note that the difference between two last days of + * the month is always 1 month, e.g. 2010-01-31 to 2010-02-28 is 1 month + * not 28 days. + * + * @param fromDate The date to start from + * @param toDate The date to end at + * @param yearsDiff Returns number of years difference + * @param monthsDiff Returns number of months difference + * @param daysDiff Returns number of days difference + * @param direction Returns direction of difference, 1 if fromDate <= toDate, -1 otherwise + */ + void dateDifference(const QDate &fromDate, const QDate &toDate, + int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const; + + //KDE5 make virtual? + /** + * Returns the difference between two dates in completed calendar years. + * The returned value will be negative if @p fromDate > @p toDate. + * + * For example, the difference between 2010-06-10 and 2012-09-5 is 2 years. + * + * @param fromDate The date to start from + * @param toDate The date to end at + * @return The number of years difference + */ + int yearsDifference(const QDate &fromDate, const QDate &toDate) const; + + //KDE5 make virtual? + /** + * Returns the difference between two dates in completed calendar months + * The returned value will be negative if @p fromDate > @p toDate. + * + * For example, the difference between 2010-06-10 and 2012-09-5 is 26 months. + * Note that the difference between two last days of the month is always 1 + * month, e.g. 2010-01-31 to 2010-02-28 is 1 month not 28 days. + * + * @param fromDate The date to start from + * @param toDate The date to end at + * @return The number of months difference + */ + int monthsDifference(const QDate &fromDate, const QDate &toDate) const; + + //KDE5 make virtual? + /** + * Returns the difference between two dates in days + * The returned value will be negative if @p fromDate > @p toDate. + * + * @param fromDate The date to start from + * @param toDate The date to end at + * @return The number of days difference + */ + int daysDifference(const QDate &fromDate, const QDate &toDate) const; + + /** + * Returns number of months in the given year + * + * @param date the date to obtain year from + * @return number of months in the year, -1 if input date invalid + */ + virtual int monthsInYear(const QDate &date) const; + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Returns number of months in the given year + * + * @param year the required year + * @return number of months in the year, -1 if input date invalid + */ + int monthsInYear(int year) const; + + /** + * Returns the number of localized weeks in the given year. + * + * @param date the date to obtain year from + * @return number of weeks in the year, -1 if input date invalid + */ + virtual int weeksInYear(const QDate &date) const; + + //KDE5 Merge with virtual weeksInYear with default + /** + * @since 4.7 + * + * Returns the number of Weeks in a year using the required Week Number System. + * + * Unless you specifically want a particular Week Number System (e.g. ISO Weeks) + * you should use the localized number of weeks provided by weeksInYear(). + * + * @see week() + * @see formatDate() + * @param date the date to obtain year from + * @param weekNumberSystem the week number system to use + * @return number of weeks in the year, -1 if date invalid + */ + int weeksInYear(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem) const; + + /** + * Returns the number of localized weeks in the given year. + * + * @param year the year + * @return number of weeks in the year, -1 if input date invalid + */ + virtual int weeksInYear(int year) const; + + //KDE5 Merge with virtual weeksInYear with default + /** + * @since 4.7 + * + * Returns the number of Weeks in a year using the required Week Number System. + * + * Unless you specifically want a particular Week Number System (e.g. ISO Weeks) + * you should use the localized number of weeks provided by weeksInYear(). + * + * @see week() + * @see formatDate() + * @param year the year + * @param weekNumberSystem the week number system to use + * @return number of weeks in the year, -1 if date invalid + */ + int weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const; + + /** + * Returns the number of days in the given year. + * + * @param date the date to obtain year from + * @return number of days in year, -1 if input date invalid + */ + virtual int daysInYear(const QDate &date) const; + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Returns the number of days in the given year. + * + * @param year the year + * @return number of days in year, -1 if input date invalid + */ + int daysInYear(int year) const; + + /** + * Returns the number of days in the given month. + * + * @param date the date to obtain month from + * @return number of days in month, -1 if input date invalid + */ + virtual int daysInMonth(const QDate &date) const; + + //KDE5 make virtual? + /** + * @since 4.5 + * + * Returns the number of days in the given month. + * + * @param year the year the month is in + * @param month the month + * @return number of days in month, -1 if input date invalid + */ + int daysInMonth(int year, int month) const; + + /** + * Returns the number of days in the given week. + * + * @param date the date to obtain week from + * @return number of days in week, -1 if input date invalid + */ + virtual int daysInWeek(const QDate &date) const; + + /** + * Returns the day number of year for the given date + * + * The days are numbered 1..daysInYear() + * + * @param date the date to obtain day from + * @return day of year number, -1 if input date not valid + */ + virtual int dayOfYear(const QDate &date) const; + + /** + * Returns the weekday number for the given date + * + * The weekdays are numbered 1..7 for Monday..Sunday. + * + * This value is @em not affected by the value of weekStartDay() + * + * @param date the date to obtain day from + * @return day of week number, -1 if input date not valid + */ + virtual int dayOfWeek(const QDate &date) const; + + //KDE5 Make virtual? + /** + * Returns the localized Week Number for the date. + * + * This may be ISO, US, or any other supported week numbering scheme. If + * you specifically require the ISO Week or any other scheme, you should use + * the week(KLocale::WeekNumberSystem) form. + * + * If the date falls in the last week of the previous year or the first + * week of the following year, then the yearNum returned will be set to the + * appropriate year. + * + * @see weeksInYear() + * @see formatDate() + * @param date the date to obtain week from + * @param yearNum returns the year the date belongs to + * @return localized week number, -1 if input date invalid + */ + int week(const QDate &date, int *yearNum = 0) const; + + //KDE5 Make virtual? + /** + * Returns the Week Number for the date in the required Week Number System. + * + * Unless you want a specific Week Number System (e.g. ISO Week), you should + * use the localized Week Number form of week(). + * + * If the date falls in the last week of the previous year or the first + * week of the following year, then the yearNum returned will be set to the + * appropriate year. + * + * Technically, the ISO Week Number only applies to the ISO/Gregorian Calendar + * System, but the same rules will be applied to the current Calendar System. + * + * @see weeksInYear() + * @see formatDate() + * @param date the date to obtain week from + * @param weekNumberSystem the Week Number System to use + * @param yearNum returns the year the date belongs to + * @return week number, -1 if input date invalid + */ + int week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const; + + /** + * Returns whether a given year is a leap year. + * + * Input year must be checked for validity in current Calendar System prior to calling, no + * validity checking performed in this routine, behaviour is undefined in invalid case. + * + * @param year the year to check + * @return @c true if the year is a leap year, @c false otherwise + */ + virtual bool isLeapYear(int year) const = 0; + + /** + * Returns whether a given date falls in a leap year. + * + * Input date must be checked for validity in current Calendar System prior to calling, no + * validity checking performed in this routine, behaviour is undefined in invalid case. + * + * @param date the date to check + * @return @c true if the date falls in a leap year, @c false otherwise + */ + virtual bool isLeapYear(const QDate &date) const; + + //KDE5 Make virtual? + /** + * @since 4.6 + * + * Returns a QDate containing the first day of the year + * + * @param year The year to return the date for + * @return The first day of the year + */ + QDate firstDayOfYear(int year) const; + + //KDE5 Make virtual? + /** + * @since 4.6 + * + * Returns a QDate containing the last day of the year + * + * @param year The year to return the date for + * @return The last day of the year + */ + QDate lastDayOfYear(int year) const; + + //KDE5 Make virtual? + /** + * @since 4.6 + * + * Returns a QDate containing the first day of the year + * + * @param date The year to return the date for, defaults to today + * @return The first day of the year + */ + QDate firstDayOfYear(const QDate &date = QDate::currentDate()) const; + + //KDE5 Make virtual? + /** + * @since 4.6 + * + * Returns a QDate containing the last day of the year + * + * @param date The year to return the date for, defaults to today + * @return The last day of the year + */ + QDate lastDayOfYear(const QDate &date = QDate::currentDate()) const; + + //KDE5 Make virtual? + /** + * @since 4.6 + * + * Returns a QDate containing the first day of the month + * + * @param year The year to return the date for + * @param month The month to return the date for + * @return The first day of the month + */ + QDate firstDayOfMonth(int year, int month) const; + + //KDE5 Make virtual? + /** + * @since 4.6 + * + * Returns a QDate containing the last day of the month + * + * @param year The year to return the date for + * @param month The month to return the date for + * @return The last day of the month + */ + QDate lastDayOfMonth(int year, int month) const; + + //KDE5 Make virtual? + /** + * @since 4.6 + * + * Returns a QDate containing the first day of the month + * + * @param date The month to return the date for, defaults to today + * @return The first day of the month + */ + QDate firstDayOfMonth(const QDate &date = QDate::currentDate()) const; + + //KDE5 Make virtual? + /** + * @since 4.6 + * + * Returns a QDate containing the last day of the month + * + * @param date The month to return the date for, defaults to today + * @return The last day of the month + */ + QDate lastDayOfMonth(const QDate &date = QDate::currentDate()) const; + + /** + * Gets specific calendar type month name for a given month number + * If an invalid month is specified, QString() is returned. + * + * @param month the month number + * @param year the year the month belongs to + * @param format specifies whether the short month name or long month name should be used + * @return name of the month, empty string if any error + */ + virtual QString monthName(int month, int year, MonthNameFormat format = LongName) const = 0; + + /** + * Gets specific calendar type month name for a given date + * + * @param date date to obtain month from + * @param format specifies whether the short month name or long month name should be used + * @return name of the month, empty string if any error + */ + virtual QString monthName(const QDate &date, MonthNameFormat format = LongName) const; + + /** + * Gets specific calendar type week day name. + * If an invalid week day is specified, QString() is returned. + * + * @param weekDay number of day in week (Monday = 1, ..., Sunday = 7) + * @param format specifies whether the short month name or long month name should be used + * @return day name, empty string if any error + */ + virtual QString weekDayName(int weekDay, WeekDayNameFormat format = LongDayName) const = 0; + + /** + * Gets specific calendar type week day name. + * + * @param date the date + * @param format specifies whether the short month name or long month name should be used + * @return day name, empty string if any error + */ + virtual QString weekDayName(const QDate &date, WeekDayNameFormat format = LongDayName) const; + + /** + * Returns a string formatted to the current locale's conventions + * regarding dates. + * + * Uses the calendar system's internal locale set when the instance was + * created, which ensures that the correct calendar system and locale + * settings are respected, which would not occur in some cases if using + * the global locale. Defaults to global locale. + * + * @see KLocale::formatDate + * + * @param fromDate the date to be formatted + * @param toFormat category of date format to use + * + * @return The date as a string + */ + virtual QString formatDate(const QDate &fromDate, KLocale::DateFormat toFormat = KLocale::LongDate) const; + + //KDE5 Make virtual + /** + * @since 4.4 + * + * Returns a string formatted to the given format and localised to the + * correct language and digit set using the requested format standard. + * + * *** WITH GREAT POWER COMES GREAT RESPONSIBILITY *** + * Please use with care and only in situations where the DateFormat enum + * or locale formats or individual string methods do not provide what you + * need. You should almost always translate your format string as + * documented. Using the standard DateFormat options instead would take + * care of the translation for you. + * + * Warning: The %n element differs from the GNU/POSIX standard where it is + * defined as a newline. KDE currently uses this for short day number. It + * is recommended for compatibility purposes to use %-m instead. + * + * The toFormat parameter is a good candidate to be made translatable, + * so that translators can adapt it to their language's convention. + * There should also be a context using the "kdedt-format" keyword (for + * automatic validation of translations) and stating the format's purpose: + * \code + * QDate reportDate; + * KGlobal::locale()->calendar()->setDate(reportDate, reportYear, reportMonth, 1); + * dateFormat = i18nc("(kdedt-format) Report month and year in report header", "%B %Y")); + * dateString = KGlobal::locale()->calendar()->formatDate(reportDate, dateFormat); + * \endcode + * + * The date format string can be defined using either the KDE or POSIX standards. + * The KDE standard closely follows the POSIX standard but with some exceptions. + * Always use the KDE standard within KDE, but where interaction is required with + * external POSIX compliant systems (e.g. Gnome, glibc, etc) the POSIX standard + * should be used. + * + * Date format strings are made up of date componants and string literals. + * Date componants are prefixed by a % escape character and are made up of + * optional padding and case modifier flags, an optional width value, and a + * compulsary code for the actual date componant: + * %[Flags][Width][Componant] + * e.g. %_^5Y + * No spaces are allowed. + * + * The Flags can modify the padding character and/or case of the Date Componant. + * The Flags are optional and may be combined and/or repeated in any order, + * in which case the last Padding Flag and last Case Flag will be the + * ones used. The Flags must be immediately after the % and before any Width. + * + * The Width can modify how wide the date Componant is padded to. The Width + * is an optional interger value and must be after any Flags but before the + * Componant. If the Width is less than the minimum defined for a Componant + * then the default minimum will be used instead. + * + * By default most numeric Date Componants are right-aligned with leading 0's. + * + * By default all string name fields are capital case and unpadded. + * + * The following Flags may be specified: + * @li - (hyphen) no padding (e.g. 1 Jan and "%-j" = "1") + * @li _ (underscore) pad with spaces (e.g. 1 Jan and "%-j" = " 1") + * @li 0 (zero) pad with 0's (e.g. 1 Jan and "%0j" = "001") + * @li ^ (caret) make uppercase (e.g. 1 Jan and "%^B" = "JANUARY") + * @li # (hash) invert case (e.g. 1 Jan and "%#B" = "???") + * + * The following Date Componants can be specified: + * @li %Y the year to 4 digits (e.g. "1984" for 1984, "0584" for 584, "0084" for 84) + * @li %C the 'century' portion of the year to 2 digits (e.g. "19" for 1984, "05" for 584, "00" for 84) + * @li %y the lower 2 digits of the year to 2 digits (e.g. "84" for 1984, "05" for 2005) + * @li %EY the full local era year (e.g. "2000 AD") + * @li %EC the era name short form (e.g. "AD") + * @li %Ey the year in era to 1 digit (e.g. 1 or 2000) + * @li %m the month number to 2 digits (January="01", December="12") + * @li %n the month number to 1 digit (January="1", December="12"), see notes! + * @li %d the day number of the month to 2 digits (e.g. "01" on the first of March) + * @li %e the day number of the month to 1 digit (e.g. "1" on the first of March) + * @li %B the month name long form (e.g. "January") + * @li %b the month name short form (e.g. "Jan" for January) + * @li %h the month name short form (e.g. "Jan" for January) + * @li %A the weekday name long form (e.g. "Wednesday" for Wednesday) + * @li %a the weekday name short form (e.g. "Wed" for Wednesday) + * @li %j the day of the year number to 3 digits (e.g. "001" for 1 Jan) + * @li %V the ISO week of the year number to 2 digits (e.g. "01" for ISO Week 1) + * @li %G the year number in long form of the ISO week of the year to 4 digits (e.g. "2004" for 1 Jan 2005) + * @li %g the year number in short form of the ISO week of the year to 2 digits (e.g. "04" for 1 Jan 2005) + * @li %u the day of the week number to 1 digit (e.g. "1" for Monday) + * @li %D the US short date format (e.g. "%m/%d/%y") + * @li %F the ISO short date format (e.g. "%Y-%m-%d") + * @li %x the KDE locale short date format + * @li %% the literal "%" + * @li %t a tab character + * + * Everything else in the format string will be taken as literal text. + * + * Examples: + * "%Y-%m-%d" = "2009-01-01" + * "%Y-%-m-%_4d" = "2009-1- 1" + * + * The following format codes behave differently in the KDE and POSIX standards + * @li %e in GNU/POSIX is space padded to 2 digits, in KDE is not padded + * @li %n in GNU/POSIX is newline, in KDE is short month number + * + * The following POSIX format codes are currently not supported: + * @li %U US week number + * @li %w US day of week + * @li %W US week number + * @li %O locale's alternative numeric symbols, in KDE is not supported + * + * %0 is not supported as the returned result is always in the locale's chosen numeric symbol digit set. + * + * @see KLocale::formatDate + * + * @param fromDate the date to be formatted + * @param toFormat the date format to use + * @param formatStandard the standard the date format uses, defaults to KDE Standard + * + * @return The date as a string + */ + QString formatDate(const QDate &fromDate, const QString &toFormat, + KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const; + + //KDE5 Make virtual + /** + * @since 4.4 + * + * Returns a string formatted to the given format string and Digit Set. + * Only use this version if you need control over the Digit Set and do + * not want to use the locale Digit Set. + * + * @see formatDate + * + * @param fromDate the date to be formatted + * @param toFormat the date format to use + * @param digitSet the Digit Set to format the date in + * @param formatStandard the standard the date format uses, defaults to KDE Standard + * + * @return The date as a string + */ + QString formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DigitSet digitSet, + KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const; + + //KDE5 Make virtual + /** + * @since 4.6 + * + * Returns a Date Component as a localized string in the requested format. + * + * For example for 2010-01-01 the KLocale::Month with en_US Locale and Gregorian calendar may return: + * KLocale::ShortNumber = "1" + * KLocale::LongNumber = "01" + * KLocale::NarrowName = "J" + * KLocale::ShortName = "Jan" + * KLocale::LongName = "January" + * + * @param date The date to format + * @param component The date component to return + * @param format The format to return the @p component in + * @param weekNumberSystem To override the default Week Number System to use + * @return The localized string form of the date component + */ + QString formatDate(const QDate &date, KLocale::DateTimeComponent component, + KLocale::DateTimeComponentFormat format = KLocale::DefaultComponentFormat, + KLocale::WeekNumberSystem weekNumberSystem = KLocale::DefaultWeekNumber) const; + + /** + * Converts a localized date string to a QDate. + * The bool pointed by @p ok will be @c false if the date entered was invalid. + * + * Uses the calendar system's internal locale set when the instance was + * created, which ensures that the correct calendar system and locale + * settings are respected, which would not occur in some cases if using + * the global locale. Defaults to global locale. + * + * @see KLocale::readDate + * + * @param str the string to convert + * @param ok if non-null, will be set to @c true if the date is valid, @c false if invalid + * + * @return the string converted to a QDate + */ + virtual QDate readDate(const QString &str, bool *ok = 0) const; + + /** + * Converts a localized date string to a QDate. + * This method is stricter than readDate(str,&ok): it will either accept + * a date in full format or a date in short format, depending on @p flags. + * + * Uses the calendar system's internal locale set when the instance was + * created, which ensures that the correct calendar system and locale + * settings are respected, which would not occur in some cases if using + * the global locale. Defaults to global locale. + * + * @see KLocale::readDate + * + * @param str the string to convert + * @param flags whether the date string is to be in full format or in short format + * @param ok if non-null, will be set to @c true if the date is valid, @c false if invalid + * + * @return the string converted to a QDate + */ + virtual QDate readDate(const QString &str, KLocale::ReadDateFlags flags, bool *ok = 0) const; + + /** + * Converts a localized date string to a QDate, using the specified @p format. + * You will usually not want to use this method. Uses teh KDE format standard. + * + * @param dateString the string to convert + * @param dateFormat the date format to use, in KDE format standard + * @param ok if non-null, will be set to @c true if the date is valid, @c false if invalid + * + * @return the string converted to a QDate + * + * @see formatDate + * @see KLocale::readDate + */ + virtual QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok = 0) const; + + //KDE5 Make virtual + /** + * Converts a localized date string to a QDate, using the specified @p format. + * You will usually not want to use this method. + * + * You must supply a format and string containing at least one of the following combinations to + * create a valid date: + * @li a month and day of month + * @li a day of year + * @li a ISO week number and day of week + * + * If a year number is not supplied then the current year will be assumed. + * + * All date componants must be separated by a non-numeric character. + * + * The format is not applied strictly to the input string: + * @li extra whitespace is ignored + * @li leading 0's on numbers are ignored + * @li capitalisation of literals is ignored + * + * The allowed format componants are almost the same as the formatDate() function. + * The following date componants will be read: + * @li %Y the whole year (e.g. "1984" for 1984) + * @li %y the lower 2 digits of the year (e.g. "84" for 1984) + * @li %EY the full local era year (e.g. "2000 AD") + * @li %EC the era name short form (e.g. "AD") + * @li %Ey the year in era to 1 digit (e.g. 1 or 2000) + * @li %m the month number to two digits (January="01", December="12") + * @li %n the month number (January="1", December="12") + * @li %d the day number of the month to two digits (e.g. "01" on the first of March) + * @li %e the day number of the month (e.g. "1" on the first of March) + * @li %B the month name long form (e.g. "January") + * @li %b the month name short form (e.g. "Jan" for January) + * @li %h the month name short form (e.g. "Jan" for January) + * @li %A the weekday name long form (e.g. "Wednesday" for Wednesday) + * @li %a the weekday name short form (e.g. "Wed" for Wednesday) + * @li %j the day of the year number to three digits (e.g. "001" for 1 Jan) + * @li %V the ISO week of the year number to two digits (e.g. "01" for ISO Week 1) + * @li %u the day of the week number (e.g. "1" for Monday) + * + * The following date componants are NOT supported: + * @li %C the 'century' portion of the year (e.g. "19" for 1984, "5" for 584, "" for 84) + * @li %G the year number in long form of the ISO week of the year (e.g. "2004" for 1 Jan 2005) + * @li %g the year number in short form of the ISO week of the year (e.g. "04" for 1 Jan 2005) + * @li %D the US short date format (e.g. "%m/%d/%y") + * @li %F the ISO short date format (e.g. "%Y-%m-%d") + * @li %x the KDE locale short date format + * @li %% the literal "%" + * @li %t a tab character + * + * @param dateString the string to convert + * @param dateFormat the date format to use + * @param ok if non-null, will be set to @c true if the date is valid, @c false if invalid + * @param formatStandard the standard the date format uses + * + * @return the string converted to a QDate + * + * @see formatDate + * @see KLocale::readDate + */ + QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok, + KLocale::DateTimeFormatStandard formatStandard) const; + + //KDE5 Make virtual + /** + * @since 4.6 + * + * Returns the Short Year Window Start Year for the current Calendar System. + * + * Use this function to get the Start Year for the Short Year Window to be + * applied when 2 digit years are entered for a Short Year input format, + * e.g. if the Short Year Window Start Year is 1930, then the input Short + * Year value of 40 is interpreted as 1940 and the input Short Year value + * of 10 is interpreted as 2010. + * + * The Short Year Window is only ever applied when reading the Short Year + * format and not the Long Year format, i.e. KLocale::ShortFormat or '%y' + * only and not KLocale::LongFormat or '%Y'. + * + * The Start Year 0 effectively means not to use a Short Year Window + * + * Each Calendar System requires a different Short Year Window as they have + * different epochs. The Gregorian Short Year Window usually pivots around + * the year 2000, whereas the Hebrew Short Year Window usually pivots around + * the year 5000. + * + * This value must always be used when evaluating user input Short Year + * strings. + * + * @see KLocale::shortYearWindowStartYear + * @see KLocale::applyShortYearWindow + * @return the short year window start year + */ + int shortYearWindowStartYear() const; + + //KDE5 Make virtual + /** + * @since 4.6 + * + * Returns the Year Number after applying the Year Window. + * + * If the @p inputYear is between 0 and 99, then apply the Year Window and + * return the calculated Year Number. + * + * If the @p inputYear is not between 0 and 99, then the original Year Number + * is returned. + * + * @see KLocale::setYearWindowOffset + * @see KLocale::yearWindowOffset + * @param inputYear the year number to apply the year window to + * @return the year number after applying the year window + */ + int applyShortYearWindow(int inputYear) const; + + /** + * Use this to determine which day is the first day of the week. + * + * Uses the calendar system's internal locale set when the instance was + * created, which ensures that the correct calendar system and locale + * settings are respected, which would not occur in some cases if using + * the global locale. Defaults to global locale. + * + * @see KLocale::weekStartDay + * + * @return an integer (Monday = 1, ..., Sunday = 7) + */ + virtual int weekStartDay() const; + + /** + * Returns whether the calendar is lunar based. + * + * @return @c true if the calendar is lunar based, @c false if not + */ + virtual bool isLunar() const = 0; + + /** + * Returns whether the calendar is lunisolar based. + * + * @return @c true if the calendar is lunisolar based, @c false if not + */ + virtual bool isLunisolar() const = 0; + + /** + * Returns whether the calendar is solar based. + * + * @return @c true if the calendar is solar based, @c false if not + */ + virtual bool isSolar() const = 0; + + /** + * Returns whether the calendar system is proleptic, i.e. whether dates + * before the epoch are supported. + * + * @see KCalendarSystem::epoch + * + * @return @c true if the calendar system is proleptic, @c false if not + */ + virtual bool isProleptic() const = 0; + +protected: + + /** + * Internal method to convert a Julian Day number into the YMD values for + * this calendar system. + * + * All calendar system implementations MUST implement julianDayToDate and + * dateToJulianDay methods as all other methods can be expressed as + * functions of these. Does no internal validity checking. + * + * @see KCalendarSystem::dateToJulianDay + * + * @param jd Julian day number to convert to date + * @param year year number returned in this variable + * @param month month number returned in this variable + * @param day day of month returned in this variable + * @return @c true if the date is valid, @c false otherwise + */ + virtual bool julianDayToDate(int jd, int &year, int &month, int &day) const = 0; + + /** + * Internal method to convert YMD values for this calendar system into a + * Julian Day number. + * + * All calendar system implementations MUST implement julianDayToDate and + * dateToJulianDay methods as all other methods can be expressed as + * functions of these. Does no internal validity checking. + * + * @see KCalendarSystem::julianDayToDate + * + * @param year year number + * @param month month number + * @param day day of month + * @param jd Julian day number returned in this variable + * @return @c true if the date is valid, @c false otherwise + */ + virtual bool dateToJulianDay(int year, int month, int day, int &jd) const = 0; + + /** + * Returns the locale used for translations and formats for this + * calendar system instance. This allows a calendar system instance to be + * independent of the global translations and formats if required. All + * implementations must refer to this locale. + * + * Only for internal calendar system use; if public access is required then + * provide public methods only for those methods actually required. Any + * app that creates an instance with its own locale overriding global will + * have the original handle to the locale and can manipulate it that way if + * required, e.g. to change default date format. Only expose those methods + * that library widgets require access to internally. + * + * @see KCalendarSystem::formatDate + * @see KLocale::formatDate + * @see KCalendarSystem::weekStartDay + * @see KLocale::weekStartDay + * @see KCalendarSystem::readDate + * @see KLocale::readDate + * + * @return locale to use + */ + const KLocale *locale() const; + + /** + * Constructor of abstract calendar class. This will be called by derived classes. + * + * @param dd derived private d-pointer. + * @param config a configuration file with a 'KCalendarSystem %calendarName' group detailing + * locale-related preferences (such as era options). The global config is used + if null. + * @param locale locale to use for translations. The global locale is used if null. + */ + KCalendarSystem(KCalendarSystemPrivate &dd, + const KSharedConfig::Ptr config = KSharedConfig::Ptr(), + const KLocale *locale = 0); + +private: + //Required for shared d-pointer as already private, remove in KDE5 + friend class KCalendarSystemCoptic; + friend class KCalendarSystemEthiopian; + friend class KCalendarSystemGregorian; + friend class KCalendarSystemHebrew; + friend class KCalendarSystemIndianNational; + friend class KCalendarSystemIslamicCivil; + friend class KCalendarSystemJalali; + friend class KCalendarSystemJapanese; + friend class KCalendarSystemJulian; + friend class KCalendarSystemMinguo; + friend class KCalendarSystemQDate; + friend class KCalendarSystemThai; + //Other friends that need access to protected/private functions + friend class KLocalizedDate; + friend class KLocalizedDatePrivate; + friend class KDateTimeParser; + friend class KDateTable; + + // Era functions needed by friends, may be made public later if needed in KCM + QList *eraList() const; + KCalendarEra era(const QDate &eraDate) const; + KCalendarEra era(const QString &eraName, int yearInEra) const; + + Q_DISABLE_COPY(KCalendarSystem) + KCalendarSystemPrivate * const d_ptr; // KDE5 make protected + Q_DECLARE_PRIVATE(KCalendarSystem) +}; + +#endif From 78beca5dac4888ce1a35977fa596f61f194bac09 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 11:27:56 +0200 Subject: [PATCH 018/104] 1.Remove @since foo 2.add Q_INVOKABLE void foo(); --- declarativeimports/locale/calendarsystem.h | 193 +++++++++------------ 1 file changed, 80 insertions(+), 113 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 2f96a1cbb..bae9073a5 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -71,7 +71,6 @@ public: //KDE5 add default value to calendarSystem /** - * @since 4.6 * * Creates a KCalendarSystem object for the required Calendar System * @@ -79,11 +78,10 @@ public: * @param locale locale to use for translations. The global locale is used if null. * @return a KCalendarSystem object */ - static KCalendarSystem *create(KLocale::CalendarSystem calendarSystem, + Q_INVOKABLE static KCalendarSystem *create(KLocale::CalendarSystem calendarSystem, const KLocale *locale = 0); /** - * @since 4.6 * * Creates a KCalendarSystem object for the required Calendar System * @@ -94,11 +92,10 @@ public: * @param locale locale to use for translations. The global locale is used if null. * @return a KCalendarSystem object */ - static KCalendarSystem *create(KLocale::CalendarSystem calendarSystem, KSharedConfig::Ptr config, + Q_INVOKABLE static KCalendarSystem *create(KLocale::CalendarSystem calendarSystem, KSharedConfig::Ptr config, const KLocale *locale = 0); /** - * @since 4.6 * * Returns a localized label to display for the required Calendar System type. * @@ -109,10 +106,9 @@ public: * @param locale the locale to use for the label, defaults to global * @return label for calendar */ - static QString calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale = KGlobal::locale()); + Q_INVOKABLE static QString calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale = KGlobal::locale()); /** - * @since 4.7 * * Returns the Calendar System enum value for a given Calendar Type, * e.g. KLocale::QDateCalendar for "gregorian" @@ -120,11 +116,10 @@ public: * @param calendarType the calendar type to convert * @return calendar system for calendar type */ - static KLocale::CalendarSystem calendarSystem(const QString &calendarType); + Q_INVOKABLE static KLocale::CalendarSystem calendarSystem(const QString &calendarType); //KDE5 remove /** - * @since 4.7 * * Returns the deprecated Calendar Type for a given Calendar System enum value, * e.g. "gregorian" for KLocale::QDateCalendar @@ -132,7 +127,7 @@ public: * @param calendarSystem the calendar system to convert * @return calendar type for calendar system */ - static QString calendarType(KLocale::CalendarSystem calendarSystem); + Q_INVOKABLE static QString calendarType(KLocale::CalendarSystem calendarSystem); /** * Constructor of abstract calendar class. This will be called by derived classes. @@ -157,23 +152,21 @@ public: virtual ~KCalendarSystem(); /** - * @since 4.6 * * Returns the Calendar System type of the KCalendarSystem object * * @return type of calendar system */ - KLocale::CalendarSystem calendarSystem() const; + Q_INVOKABLE KLocale::CalendarSystem calendarSystem() const; //KDE5 make virtual? /** - * @since 4.6 * * Returns a localized label to display for the current Calendar System type. * * @return localized label for this Calendar System */ - QString calendarLabel() const; + Q_INVOKABLE QString calendarLabel() const; /** * Returns a QDate holding the epoch of the calendar system. Usually YMD @@ -190,7 +183,7 @@ public: * * @return epoch of calendar system */ - virtual QDate epoch() const; + Q_INVOKABLE virtual QDate epoch() const; /** * Returns the earliest date valid in this calendar system implementation. @@ -202,7 +195,7 @@ public: * * @return date the earliest valid date */ - virtual QDate earliestValidDate() const; + Q_INVOKABLE virtual QDate earliestValidDate() const; /** * Returns the latest date valid in this calendar system implementation. @@ -212,7 +205,7 @@ public: * * @return date the latest valid date */ - virtual QDate latestValidDate() const; + Q_INVOKABLE virtual QDate latestValidDate() const; /** * Returns whether a given date is valid in this calendar system. @@ -222,11 +215,10 @@ public: * @param day the day portion of the date to check * @return @c true if the date is valid, @c false otherwise */ - virtual bool isValid(int year, int month, int day) const = 0; + Q_INVOKABLE virtual bool isValid(int year, int month, int day) const = 0; //KDE5 make virtual? /** - * @since 4.4 * * Returns whether a given date is valid in this calendar system. * @@ -234,11 +226,10 @@ public: * @param dayOfYear the day of year portion of the date to check * @return @c true if the date is valid, @c false otherwise */ - bool isValid(int year, int dayOfYear) const; + Q_INVOKABLE bool isValid(int year, int dayOfYear) const; //KDE5 make virtual? /** - * @since 4.5 * * Returns whether a given date is valid in this calendar system. * @@ -248,11 +239,10 @@ public: * @param day the Day portion of the date to check * @return @c true if the date is valid, @c false otherwise */ - bool isValid(const QString &eraName, int yearInEra, int month, int day) const; + Q_INVOKABLE bool isValid(const QString &eraName, int yearInEra, int month, int day) const; //KDE5 make virtual? /** - * @since 4.4 * * Returns whether a given date is valid in this calendar system. * @@ -261,7 +251,7 @@ public: * @param dayOfIsoWeek the day of week portion of the date to check * @return @c true if the date is valid, @c false otherwise */ - bool isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const; + Q_INVOKABLE bool isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const; /** * Returns whether a given date is valid in this calendar system. @@ -269,7 +259,7 @@ public: * @param date the date to check * @return @c true if the date is valid, @c false otherwise */ - virtual bool isValid(const QDate &date) const; + Q_INVOKABLE virtual bool isValid(const QDate &date) const; /** * Changes the date's year, month and day. The range of the year, month @@ -283,11 +273,10 @@ public: * @param day day of month * @return @c true if the date is valid, @c false otherwise */ - virtual bool setDate(QDate &date, int year, int month, int day) const; + Q_INVOKABLE virtual bool setDate(QDate &date, int year, int month, int day) const; //KDE5 make virtual? /** - * @since 4.4 * * Set a date using the year number and day of year number only. * @@ -296,11 +285,10 @@ public: * @param dayOfYear day of year * @return @c true if the date is valid, @c false otherwise */ - bool setDate(QDate &date, int year, int dayOfYear) const; + Q_INVOKABLE bool setDate(QDate &date, int year, int dayOfYear) const; //KDE5 make virtual? /** - * @since 4.5 * * Set a date using the era, year in era number, month and day * @@ -311,11 +299,10 @@ public: * @param day Day Of Month number * @return @c true if the date is valid, @c false otherwise */ - bool setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const; + Q_INVOKABLE bool setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const; //KDE5 make virtual? /** - * @since 4.4 * * Set a date using the year number, ISO week number and day of week number. * @@ -325,12 +312,11 @@ public: * @param dayOfIsoWeek day of week Mon..Sun (1..7) * @return @c true if the date is valid, @c false otherwise */ - bool setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const; + Q_INVOKABLE bool setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const; //KDE5 make virtual? /** - * @since 4.5 * * Returns the year, month and day portion of a given date in the current calendar system * @@ -339,7 +325,7 @@ public: * @param month month number returned in this variable * @param day day of month returned in this variable */ - void getDate(const QDate date, int *year, int *month, int *day) const; + Q_INVOKABLE void getDate(const QDate date, int *year, int *month, int *day) const; /** * Returns the year portion of a given date in the current calendar system @@ -347,7 +333,7 @@ public: * @param date date to return year for * @return year, 0 if input date is invalid */ - virtual int year(const QDate &date) const; + Q_INVOKABLE virtual int year(const QDate &date) const; /** * Returns the month portion of a given date in the current calendar system @@ -355,7 +341,7 @@ public: * @param date date to return month for * @return month of year, 0 if input date is invalid */ - virtual int month(const QDate &date) const; + Q_INVOKABLE virtual int month(const QDate &date) const; /** * Returns the day portion of a given date in the current calendar system @@ -363,11 +349,10 @@ public: * @param date date to return day for * @return day of the month, 0 if input date is invalid */ - virtual int day(const QDate &date) const; + Q_INVOKABLE virtual int day(const QDate &date) const; //KDE5 make virtual? /** - * @since 4.5 * * Returns the Era Name portion of a given date in the current calendar system, * for example "AD" or "Anno Domini" for the Gregorian calendar and Christian Era. @@ -376,11 +361,10 @@ public: * @param format format to return, either short or long * @return era name, empty string if input date is invalid */ - QString eraName(const QDate &date, StringFormat format = ShortFormat) const; + Q_INVOKABLE QString eraName(const QDate &date, StringFormat format = ShortFormat) const; //KDE5 make virtual? /** - * @since 4.5 * * Returns the Era Year portion of a given date in the current * calendar system, for example "2000 AD" or "Heisei 22". @@ -389,11 +373,10 @@ public: * @param format format to return, either short or long * @return era name, empty string if input date is invalid */ - QString eraYear(const QDate &date, StringFormat format = ShortFormat) const; + Q_INVOKABLE QString eraYear(const QDate &date, StringFormat format = ShortFormat) const; //KDE5 make virtual? /** - * @since 4.5 * * Returns the Year In Era portion of a given date in the current calendar * system, for example 1 for "1 BC". @@ -401,7 +384,7 @@ public: * @param date date to return Year In Era for * @return Year In Era, -1 if input date is invalid */ - int yearInEra(const QDate &date) const; + Q_INVOKABLE int yearInEra(const QDate &date) const; /** * Returns a QDate containing a date @p nyears years later. @@ -410,7 +393,7 @@ public: * @param nyears The number of years to add * @return The new date, null date if any errors */ - virtual QDate addYears(const QDate &date, int nyears) const; + Q_INVOKABLE virtual QDate addYears(const QDate &date, int nyears) const; /** * Returns a QDate containing a date @p nmonths months later. @@ -419,7 +402,7 @@ public: * @param nmonths number of months to add * @return The new date, null date if any errors */ - virtual QDate addMonths(const QDate &date, int nmonths) const; + Q_INVOKABLE virtual QDate addMonths(const QDate &date, int nmonths) const; /** * Returns a QDate containing a date @p ndays days later. @@ -428,7 +411,7 @@ public: * @param ndays number of days to add * @return The new date, null date if any errors */ - virtual QDate addDays(const QDate &date, int ndays) const; + Q_INVOKABLE virtual QDate addDays(const QDate &date, int ndays) const; //KDE5 make virtual? /** @@ -449,7 +432,7 @@ public: * @param daysDiff Returns number of days difference * @param direction Returns direction of difference, 1 if fromDate <= toDate, -1 otherwise */ - void dateDifference(const QDate &fromDate, const QDate &toDate, + Q_INVOKABLE void dateDifference(const QDate &fromDate, const QDate &toDate, int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const; //KDE5 make virtual? @@ -463,7 +446,7 @@ public: * @param toDate The date to end at * @return The number of years difference */ - int yearsDifference(const QDate &fromDate, const QDate &toDate) const; + Q_INVOKABLE int yearsDifference(const QDate &fromDate, const QDate &toDate) const; //KDE5 make virtual? /** @@ -478,7 +461,7 @@ public: * @param toDate The date to end at * @return The number of months difference */ - int monthsDifference(const QDate &fromDate, const QDate &toDate) const; + Q_INVOKABLE int monthsDifference(const QDate &fromDate, const QDate &toDate) const; //KDE5 make virtual? /** @@ -489,7 +472,7 @@ public: * @param toDate The date to end at * @return The number of days difference */ - int daysDifference(const QDate &fromDate, const QDate &toDate) const; + Q_INVOKABLE int daysDifference(const QDate &fromDate, const QDate &toDate) const; /** * Returns number of months in the given year @@ -497,18 +480,17 @@ public: * @param date the date to obtain year from * @return number of months in the year, -1 if input date invalid */ - virtual int monthsInYear(const QDate &date) const; + Q_INVOKABLE virtual int monthsInYear(const QDate &date) const; //KDE5 make virtual? /** - * @since 4.5 * * Returns number of months in the given year * * @param year the required year * @return number of months in the year, -1 if input date invalid */ - int monthsInYear(int year) const; + Q_INVOKABLE int monthsInYear(int year) const; /** * Returns the number of localized weeks in the given year. @@ -516,11 +498,10 @@ public: * @param date the date to obtain year from * @return number of weeks in the year, -1 if input date invalid */ - virtual int weeksInYear(const QDate &date) const; + Q_INVOKABLE virtual int weeksInYear(const QDate &date) const; //KDE5 Merge with virtual weeksInYear with default /** - * @since 4.7 * * Returns the number of Weeks in a year using the required Week Number System. * @@ -533,7 +514,7 @@ public: * @param weekNumberSystem the week number system to use * @return number of weeks in the year, -1 if date invalid */ - int weeksInYear(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem) const; + Q_INVOKABLE int weeksInYear(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem) const; /** * Returns the number of localized weeks in the given year. @@ -541,11 +522,10 @@ public: * @param year the year * @return number of weeks in the year, -1 if input date invalid */ - virtual int weeksInYear(int year) const; + Q_INVOKABLE virtual int weeksInYear(int year) const; //KDE5 Merge with virtual weeksInYear with default /** - * @since 4.7 * * Returns the number of Weeks in a year using the required Week Number System. * @@ -558,7 +538,7 @@ public: * @param weekNumberSystem the week number system to use * @return number of weeks in the year, -1 if date invalid */ - int weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const; + Q_INVOKABLE int weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const; /** * Returns the number of days in the given year. @@ -566,18 +546,17 @@ public: * @param date the date to obtain year from * @return number of days in year, -1 if input date invalid */ - virtual int daysInYear(const QDate &date) const; + Q_INVOKABLE virtual int daysInYear(const QDate &date) const; //KDE5 make virtual? /** - * @since 4.5 * * Returns the number of days in the given year. * * @param year the year * @return number of days in year, -1 if input date invalid */ - int daysInYear(int year) const; + Q_INVOKABLE int daysInYear(int year) const; /** * Returns the number of days in the given month. @@ -585,11 +564,10 @@ public: * @param date the date to obtain month from * @return number of days in month, -1 if input date invalid */ - virtual int daysInMonth(const QDate &date) const; + Q_INVOKABLE virtual int daysInMonth(const QDate &date) const; //KDE5 make virtual? /** - * @since 4.5 * * Returns the number of days in the given month. * @@ -597,7 +575,7 @@ public: * @param month the month * @return number of days in month, -1 if input date invalid */ - int daysInMonth(int year, int month) const; + Q_INVOKABLE int daysInMonth(int year, int month) const; /** * Returns the number of days in the given week. @@ -605,7 +583,7 @@ public: * @param date the date to obtain week from * @return number of days in week, -1 if input date invalid */ - virtual int daysInWeek(const QDate &date) const; + Q_INVOKABLE virtual int daysInWeek(const QDate &date) const; /** * Returns the day number of year for the given date @@ -615,7 +593,7 @@ public: * @param date the date to obtain day from * @return day of year number, -1 if input date not valid */ - virtual int dayOfYear(const QDate &date) const; + Q_INVOKABLE virtual int dayOfYear(const QDate &date) const; /** * Returns the weekday number for the given date @@ -627,7 +605,7 @@ public: * @param date the date to obtain day from * @return day of week number, -1 if input date not valid */ - virtual int dayOfWeek(const QDate &date) const; + Q_INVOKABLE virtual int dayOfWeek(const QDate &date) const; //KDE5 Make virtual? /** @@ -647,7 +625,7 @@ public: * @param yearNum returns the year the date belongs to * @return localized week number, -1 if input date invalid */ - int week(const QDate &date, int *yearNum = 0) const; + Q_INVOKABLE int week(const QDate &date, int *yearNum = 0) const; //KDE5 Make virtual? /** @@ -670,7 +648,7 @@ public: * @param yearNum returns the year the date belongs to * @return week number, -1 if input date invalid */ - int week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const; + Q_INVOKABLE int week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const; /** * Returns whether a given year is a leap year. @@ -681,7 +659,7 @@ public: * @param year the year to check * @return @c true if the year is a leap year, @c false otherwise */ - virtual bool isLeapYear(int year) const = 0; + Q_INVOKABLE virtual bool isLeapYear(int year) const = 0; /** * Returns whether a given date falls in a leap year. @@ -692,18 +670,17 @@ public: * @param date the date to check * @return @c true if the date falls in a leap year, @c false otherwise */ - virtual bool isLeapYear(const QDate &date) const; + Q_INVOKABLE virtual bool isLeapYear(const QDate &date) const; //KDE5 Make virtual? /** - * @since 4.6 * * Returns a QDate containing the first day of the year * * @param year The year to return the date for * @return The first day of the year */ - QDate firstDayOfYear(int year) const; + Q_INVOKABLE QDate firstDayOfYear(int year) const; //KDE5 Make virtual? /** @@ -714,18 +691,17 @@ public: * @param year The year to return the date for * @return The last day of the year */ - QDate lastDayOfYear(int year) const; + Q_INVOKABLE QDate lastDayOfYear(int year) const; //KDE5 Make virtual? /** - * @since 4.6 * * Returns a QDate containing the first day of the year * * @param date The year to return the date for, defaults to today * @return The first day of the year */ - QDate firstDayOfYear(const QDate &date = QDate::currentDate()) const; + Q_INVOKABLE QDate firstDayOfYear(const QDate &date = QDate::currentDate()) const; //KDE5 Make virtual? /** @@ -736,11 +712,10 @@ public: * @param date The year to return the date for, defaults to today * @return The last day of the year */ - QDate lastDayOfYear(const QDate &date = QDate::currentDate()) const; + Q_INVOKABLE QDate lastDayOfYear(const QDate &date = QDate::currentDate()) const; //KDE5 Make virtual? /** - * @since 4.6 * * Returns a QDate containing the first day of the month * @@ -748,11 +723,10 @@ public: * @param month The month to return the date for * @return The first day of the month */ - QDate firstDayOfMonth(int year, int month) const; + Q_INVOKABLE QDate firstDayOfMonth(int year, int month) const; //KDE5 Make virtual? /** - * @since 4.6 * * Returns a QDate containing the last day of the month * @@ -760,29 +734,27 @@ public: * @param month The month to return the date for * @return The last day of the month */ - QDate lastDayOfMonth(int year, int month) const; + Q_INVOKABLE QDate lastDayOfMonth(int year, int month) const; //KDE5 Make virtual? /** - * @since 4.6 * * Returns a QDate containing the first day of the month * * @param date The month to return the date for, defaults to today * @return The first day of the month */ - QDate firstDayOfMonth(const QDate &date = QDate::currentDate()) const; + Q_INVOKABLE QDate firstDayOfMonth(const QDate &date = QDate::currentDate()) const; //KDE5 Make virtual? /** - * @since 4.6 * * Returns a QDate containing the last day of the month * * @param date The month to return the date for, defaults to today * @return The last day of the month */ - QDate lastDayOfMonth(const QDate &date = QDate::currentDate()) const; + Q_INVOKABLE QDate lastDayOfMonth(const QDate &date = QDate::currentDate()) const; /** * Gets specific calendar type month name for a given month number @@ -793,7 +765,7 @@ public: * @param format specifies whether the short month name or long month name should be used * @return name of the month, empty string if any error */ - virtual QString monthName(int month, int year, MonthNameFormat format = LongName) const = 0; + Q_INVOKABLE virtual QString monthName(int month, int year, MonthNameFormat format = LongName) const = 0; /** * Gets specific calendar type month name for a given date @@ -802,7 +774,7 @@ public: * @param format specifies whether the short month name or long month name should be used * @return name of the month, empty string if any error */ - virtual QString monthName(const QDate &date, MonthNameFormat format = LongName) const; + Q_INVOKABLE virtual QString monthName(const QDate &date, MonthNameFormat format = LongName) const; /** * Gets specific calendar type week day name. @@ -812,7 +784,7 @@ public: * @param format specifies whether the short month name or long month name should be used * @return day name, empty string if any error */ - virtual QString weekDayName(int weekDay, WeekDayNameFormat format = LongDayName) const = 0; + Q_INVOKABLE virtual QString weekDayName(int weekDay, WeekDayNameFormat format = LongDayName) const = 0; /** * Gets specific calendar type week day name. @@ -821,7 +793,7 @@ public: * @param format specifies whether the short month name or long month name should be used * @return day name, empty string if any error */ - virtual QString weekDayName(const QDate &date, WeekDayNameFormat format = LongDayName) const; + Q_INVOKABLE virtual QString weekDayName(const QDate &date, WeekDayNameFormat format = LongDayName) const; /** * Returns a string formatted to the current locale's conventions @@ -839,11 +811,10 @@ public: * * @return The date as a string */ - virtual QString formatDate(const QDate &fromDate, KLocale::DateFormat toFormat = KLocale::LongDate) const; + Q_INVOKABLE virtual QString formatDate(const QDate &fromDate, KLocale::DateFormat toFormat = KLocale::LongDate) const; //KDE5 Make virtual /** - * @since 4.4 * * Returns a string formatted to the given format and localised to the * correct language and digit set using the requested format standard. @@ -958,12 +929,11 @@ public: * * @return The date as a string */ - QString formatDate(const QDate &fromDate, const QString &toFormat, + Q_INVOKABLE QString formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const; //KDE5 Make virtual /** - * @since 4.4 * * Returns a string formatted to the given format string and Digit Set. * Only use this version if you need control over the Digit Set and do @@ -978,12 +948,11 @@ public: * * @return The date as a string */ - QString formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DigitSet digitSet, + Q_INVOKABLE QString formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DigitSet digitSet, KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const; //KDE5 Make virtual /** - * @since 4.6 * * Returns a Date Component as a localized string in the requested format. * @@ -1000,7 +969,7 @@ public: * @param weekNumberSystem To override the default Week Number System to use * @return The localized string form of the date component */ - QString formatDate(const QDate &date, KLocale::DateTimeComponent component, + Q_INVOKABLE QString formatDate(const QDate &date, KLocale::DateTimeComponent component, KLocale::DateTimeComponentFormat format = KLocale::DefaultComponentFormat, KLocale::WeekNumberSystem weekNumberSystem = KLocale::DefaultWeekNumber) const; @@ -1020,7 +989,7 @@ public: * * @return the string converted to a QDate */ - virtual QDate readDate(const QString &str, bool *ok = 0) const; + Q_INVOKABLE virtual QDate readDate(const QString &str, bool *ok = 0) const; /** * Converts a localized date string to a QDate. @@ -1040,7 +1009,7 @@ public: * * @return the string converted to a QDate */ - virtual QDate readDate(const QString &str, KLocale::ReadDateFlags flags, bool *ok = 0) const; + Q_INVOKABLE virtual QDate readDate(const QString &str, KLocale::ReadDateFlags flags, bool *ok = 0) const; /** * Converts a localized date string to a QDate, using the specified @p format. @@ -1055,7 +1024,7 @@ public: * @see formatDate * @see KLocale::readDate */ - virtual QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok = 0) const; + Q_INVOKABLE virtual QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok = 0) const; //KDE5 Make virtual /** @@ -1117,12 +1086,11 @@ public: * @see formatDate * @see KLocale::readDate */ - QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok, + Q_INVOKABLE QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok, KLocale::DateTimeFormatStandard formatStandard) const; //KDE5 Make virtual /** - * @since 4.6 * * Returns the Short Year Window Start Year for the current Calendar System. * @@ -1150,11 +1118,10 @@ public: * @see KLocale::applyShortYearWindow * @return the short year window start year */ - int shortYearWindowStartYear() const; + Q_INVOKABLE int shortYearWindowStartYear() const; //KDE5 Make virtual /** - * @since 4.6 * * Returns the Year Number after applying the Year Window. * @@ -1169,7 +1136,7 @@ public: * @param inputYear the year number to apply the year window to * @return the year number after applying the year window */ - int applyShortYearWindow(int inputYear) const; + Q_INVOKABLE int applyShortYearWindow(int inputYear) const; /** * Use this to determine which day is the first day of the week. @@ -1183,28 +1150,28 @@ public: * * @return an integer (Monday = 1, ..., Sunday = 7) */ - virtual int weekStartDay() const; + Q_INVOKABLE virtual int weekStartDay() const; /** * Returns whether the calendar is lunar based. * * @return @c true if the calendar is lunar based, @c false if not */ - virtual bool isLunar() const = 0; + Q_INVOKABLE virtual bool isLunar() const = 0; /** * Returns whether the calendar is lunisolar based. * * @return @c true if the calendar is lunisolar based, @c false if not */ - virtual bool isLunisolar() const = 0; + Q_INVOKABLE virtual bool isLunisolar() const = 0; /** * Returns whether the calendar is solar based. * * @return @c true if the calendar is solar based, @c false if not */ - virtual bool isSolar() const = 0; + Q_INVOKABLE virtual bool isSolar() const = 0; /** * Returns whether the calendar system is proleptic, i.e. whether dates @@ -1214,7 +1181,7 @@ public: * * @return @c true if the calendar system is proleptic, @c false if not */ - virtual bool isProleptic() const = 0; + Q_INVOKABLE virtual bool isProleptic() const = 0; protected: @@ -1234,7 +1201,7 @@ protected: * @param day day of month returned in this variable * @return @c true if the date is valid, @c false otherwise */ - virtual bool julianDayToDate(int jd, int &year, int &month, int &day) const = 0; + Q_INVOKABLE virtual bool julianDayToDate(int jd, int &year, int &month, int &day) const = 0; /** * Internal method to convert YMD values for this calendar system into a @@ -1252,7 +1219,7 @@ protected: * @param jd Julian day number returned in this variable * @return @c true if the date is valid, @c false otherwise */ - virtual bool dateToJulianDay(int year, int month, int day, int &jd) const = 0; + Q_INVOKABLE virtual bool dateToJulianDay(int year, int month, int day, int &jd) const = 0; /** * Returns the locale used for translations and formats for this @@ -1276,7 +1243,7 @@ protected: * * @return locale to use */ - const KLocale *locale() const; + Q_INVOKABLE const KLocale *locale() const; /** * Constructor of abstract calendar class. This will be called by derived classes. From 31cc381819b27ba3617016cf86151f80c092b1c1 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 11:44:11 +0200 Subject: [PATCH 019/104] Add calendar.cpp to the CMakeLists.txt --- declarativeimports/locale/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/declarativeimports/locale/CMakeLists.txt b/declarativeimports/locale/CMakeLists.txt index 1a06e17f9..f35d2e7a6 100644 --- a/declarativeimports/locale/CMakeLists.txt +++ b/declarativeimports/locale/CMakeLists.txt @@ -2,7 +2,8 @@ project(localebindings) set(localebindings_SRCS locale.cpp - ) + calendarsystem.cpp +) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR} @@ -15,7 +16,6 @@ qt4_automoc(${localebindings_SRCS}) add_library(localebindingsplugin SHARED ${localebindings_SRCS}) #FIXME -#Should i remove KDE4_PLASMA_LIBS? #Should i put something? target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY}) From 7269926c13155c582c99c217ac8f4f03c40f5672 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 11:44:48 +0200 Subject: [PATCH 020/104] Add CalendarSystem to the qmlRegisterType<>() --- declarativeimports/locale/localebindingsplugin.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/declarativeimports/locale/localebindingsplugin.cpp b/declarativeimports/locale/localebindingsplugin.cpp index 98f161f72..f8e292752 100644 --- a/declarativeimports/locale/localebindingsplugin.cpp +++ b/declarativeimports/locale/localebindingsplugin.cpp @@ -21,12 +21,14 @@ #include "localebindingsplugin.h" #include #include "locale.h" +#include "calendarsystem.h" void LocaleBindingsPlugin::registerTypes(const char *uri) { Q_ASSERT(uri == QLatin1String("org.kde.plasma.locale")); qmlRegisterType(uri, 0, 1, "Locale"); + qmlRegisterType(uri, 0, 1, "CalendarSystem"); } #include "localebindingsplugin.moc" From 2c77d052a32b315048c26e495c3c8f22ecc403f5 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 11:46:04 +0200 Subject: [PATCH 021/104] I renamed the class into CalendarSystem and now the class derives from QObject also I added the Q_ENUMS --- declarativeimports/locale/calendarsystem.h | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index bae9073a5..2c4571784 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -19,17 +19,16 @@ Boston, MA 02110-1301, USA. */ -#ifndef KCALENDARSYSTEM_H -#define KCALENDARSYSTEM_H +#ifndef CALENDARSYSTEM_H +#define CALENDARSYSTEM_H -#include #include "klocale.h" // needed for enums #include "kglobal.h" #include #include -class KCalendarSystemPrivate; +class KCalendarSystem; class KCalendarEra; /** @@ -37,8 +36,15 @@ class KCalendarEra; * * Derived classes must be created through the create() static method */ -class KDECORE_EXPORT KCalendarSystem +class CalendarSystem : public QObject { +Q_OBJECT + +//enums +Q_ENUMS(StringFormat) +Q_ENUMS(MonthNameFormat) +Q_ENUMS(WeekDayNameFormat) + public: /** @@ -1283,9 +1289,10 @@ private: KCalendarEra era(const QDate &eraDate) const; KCalendarEra era(const QString &eraName, int yearInEra) const; - Q_DISABLE_COPY(KCalendarSystem) - KCalendarSystemPrivate * const d_ptr; // KDE5 make protected - Q_DECLARE_PRIVATE(KCalendarSystem) + //Q_DISABLE_COPY(KCalendarSystem) + KCalendarSystem *m_calendarSystem; + //FIXME What is Q_DECLARE_PRIVATE + //Q_DECLARE_PRIVATE(KCalendarSystem) }; #endif From 6701ee68c94a2491a0ee06b66e12724325e90c48 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 11:47:40 +0200 Subject: [PATCH 022/104] Replace KCalendarSystem with CalenderSystem in the calendarsystem.cpp --- declarativeimports/locale/calendarsystem.cpp | 271 +++++++++---------- 1 file changed, 135 insertions(+), 136 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 77ef0e948..fd144e4c0 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -20,7 +20,6 @@ */ #include "kcalendarsystem.h" -#include "kcalendarsystemprivate_p.h" #include "kdebug.h" #include "kconfiggroup.h" @@ -44,18 +43,18 @@ #include "kcalendarsystemqdate_p.h" #include "kcalendarsystemthai_p.h" -KCalendarSystem *KCalendarSystem::create(const QString &calendarType, const KLocale *locale) +KCalendarSystem *CalendarSystem::create(const QString &calendarType, const KLocale *locale) { return create(calendarSystem(calendarType), locale); } -KCalendarSystem *KCalendarSystem::create(const QString &calendarType, KSharedConfig::Ptr config, +KCalendarSystem *CalendarSystem::create(const QString &calendarType, KSharedConfig::Ptr config, const KLocale *locale) { return create(calendarSystem(calendarType), config, locale); } -QStringList KCalendarSystem::calendarSystems() +QStringList CalendarSystem::calendarSystems() { QStringList lst; @@ -75,21 +74,21 @@ QStringList KCalendarSystem::calendarSystems() return lst; } -QString KCalendarSystem::calendarLabel(const QString &calendarType) +QString CalendarSystem::calendarLabel(const QString &calendarType) { if (calendarSystemsList().contains(calendarSystem(calendarType))) { - return KCalendarSystem::calendarLabel(KCalendarSystem::calendarSystem(calendarType)); + return CalendarSystem::calendarLabel(CalendarSystem::calendarSystem(calendarType)); } else { return ki18nc("@item Calendar system", "Invalid Calendar Type").toString(KGlobal::locale()); } } -KCalendarSystem *KCalendarSystem::create(KLocale::CalendarSystem calendarSystem, const KLocale *locale) +KCalendarSystem *CalendarSystem::create(KLocale::CalendarSystem calendarSystem, const KLocale *locale) { return create(calendarSystem, KSharedConfig::Ptr(), locale); } -KCalendarSystem *KCalendarSystem::create(KLocale::CalendarSystem calendarSystem, +KCalendarSystem *CalendarSystem::create(KLocale::CalendarSystem calendarSystem, KSharedConfig::Ptr config, const KLocale *locale) { @@ -123,7 +122,7 @@ KCalendarSystem *KCalendarSystem::create(KLocale::CalendarSystem calendarSystem, } } -QList KCalendarSystem::calendarSystemsList() +QList CalendarSystem::calendarSystemsList() { QList list; @@ -143,7 +142,7 @@ QList KCalendarSystem::calendarSystemsList() return list; } -QString KCalendarSystem::calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale) +QString CalendarSystem::calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale) { switch (calendarSystem) { case KLocale::QDateCalendar: @@ -175,12 +174,12 @@ QString KCalendarSystem::calendarLabel(KLocale::CalendarSystem calendarSystem, c return ki18nc("@item Calendar system", "Invalid Calendar Type").toString(locale); } -KLocale::CalendarSystem KCalendarSystem::calendarSystemForCalendarType(const QString &calendarType ) +KLocale::CalendarSystem CalendarSystem::calendarSystemForCalendarType(const QString &calendarType ) { return calendarSystem( calendarType ); } -KLocale::CalendarSystem KCalendarSystem::calendarSystem(const QString &calendarType ) +KLocale::CalendarSystem CalendarSystem::calendarSystem(const QString &calendarType ) { if (calendarType == QLatin1String("coptic")) { return KLocale::CopticCalendar; @@ -211,7 +210,7 @@ KLocale::CalendarSystem KCalendarSystem::calendarSystem(const QString &calendarT } } -QString KCalendarSystem::calendarType(KLocale::CalendarSystem calendarSystem) +QString CalendarSystem::calendarType(KLocale::CalendarSystem calendarSystem) { if (calendarSystem == KLocale::QDateCalendar) { return QLatin1String("gregorian"); @@ -1070,34 +1069,34 @@ void KCalendarSystemPrivate::loadConfig(const QString & calendarType) } -KCalendarSystem::KCalendarSystem(const KLocale *locale) +CalendarSystem::KCalendarSystem(const KLocale *locale) : d_ptr(new KCalendarSystemPrivate(this)) { d_ptr->m_config = KSharedConfig::Ptr(); d_ptr->m_locale = locale; } -KCalendarSystem::KCalendarSystem(const KSharedConfig::Ptr config, const KLocale *locale) +CalendarSystem::KCalendarSystem(const KSharedConfig::Ptr config, const KLocale *locale) : d_ptr(new KCalendarSystemPrivate(this)) { d_ptr->m_config = config; d_ptr->m_locale = locale; } -KCalendarSystem::KCalendarSystem(KCalendarSystemPrivate &dd, const KSharedConfig::Ptr config, const KLocale *locale) +CalendarSystem::KCalendarSystem(KCalendarSystemPrivate &dd, const KSharedConfig::Ptr config, const KLocale *locale) : d_ptr(&dd) { d_ptr->m_config = config; d_ptr->m_locale = locale; } -KCalendarSystem::~KCalendarSystem() +CalendarSystem::~KCalendarSystem() { delete d_ptr; } // NOT VIRTUAL - If override needed use shared-d -KLocale::CalendarSystem KCalendarSystem::calendarSystem() const +KLocale::CalendarSystem CalendarSystem::calendarSystem() const { Q_D(const KCalendarSystem); @@ -1105,32 +1104,32 @@ KLocale::CalendarSystem KCalendarSystem::calendarSystem() const } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::calendarLabel() const +QString CalendarSystem::calendarLabel() const { - return KCalendarSystem::calendarLabel(calendarSystem()); + return CalendarSystem::calendarLabel(calendarSystem()); } // Dummy version using Gregorian as an example // This method MUST be re-implemented in any new Calendar System -QDate KCalendarSystem::epoch() const +QDate CalendarSystem::epoch() const { return QDate::fromJulianDay(38); } -QDate KCalendarSystem::earliestValidDate() const +QDate CalendarSystem::earliestValidDate() const { return epoch(); } // Dummy version using Gregorian as an example // This method MUST be re-implemented in any new Calendar System -QDate KCalendarSystem::latestValidDate() const +QDate CalendarSystem::latestValidDate() const { // Default to Gregorian 9999-12-31 return QDate::fromJulianDay(5373484); } -bool KCalendarSystem::isValid(int year, int month, int day) const +bool CalendarSystem::isValid(int year, int month, int day) const { Q_D(const KCalendarSystem); @@ -1151,7 +1150,7 @@ bool KCalendarSystem::isValid(int year, int month, int day) const } // NOT VIRTUAL - If override needed use shared-d -bool KCalendarSystem::isValid(int year, int dayOfYear) const +bool CalendarSystem::isValid(int year, int dayOfYear) const { Q_D(const KCalendarSystem); @@ -1159,7 +1158,7 @@ bool KCalendarSystem::isValid(int year, int dayOfYear) const } // NOT VIRTUAL - If override needed use shared-d -bool KCalendarSystem::isValid(const QString &eraName, int yearInEra, int month, int day) const +bool CalendarSystem::isValid(const QString &eraName, int yearInEra, int month, int day) const { Q_D(const KCalendarSystem); @@ -1168,7 +1167,7 @@ bool KCalendarSystem::isValid(const QString &eraName, int yearInEra, int month, } // NOT VIRTUAL - If override needed use shared-d -bool KCalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const +bool CalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const { Q_D(const KCalendarSystem); @@ -1211,7 +1210,7 @@ bool KCalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfI return true; } -bool KCalendarSystem::isValid(const QDate &date) const +bool CalendarSystem::isValid(const QDate &date) const { if (date.isNull() || date < earliestValidDate() || date > latestValidDate()) { return false; @@ -1219,7 +1218,7 @@ bool KCalendarSystem::isValid(const QDate &date) const return true; } -bool KCalendarSystem::setDate(QDate &date, int year, int month, int day) const +bool CalendarSystem::setDate(QDate &date, int year, int month, int day) const { Q_D(const KCalendarSystem); @@ -1240,7 +1239,7 @@ bool KCalendarSystem::setDate(QDate &date, int year, int month, int day) const } // NOT VIRTUAL - If override needed use shared-d -bool KCalendarSystem::setDate(QDate &date, int year, int dayOfYear) const +bool CalendarSystem::setDate(QDate &date, int year, int dayOfYear) const { Q_D(const KCalendarSystem); @@ -1260,7 +1259,7 @@ bool KCalendarSystem::setDate(QDate &date, int year, int dayOfYear) const } // NOT VIRTUAL - If override needed use shared-d -bool KCalendarSystem::setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const +bool CalendarSystem::setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const { Q_D(const KCalendarSystem); @@ -1269,7 +1268,7 @@ bool KCalendarSystem::setDate(QDate &date, QString eraName, int yearInEra, int m } // NOT VIRTUAL - If override needed use shared-d -bool KCalendarSystem::setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const +bool CalendarSystem::setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const { Q_D(const KCalendarSystem); @@ -1298,13 +1297,13 @@ bool KCalendarSystem::setDateIsoWeek(QDate &date, int year, int isoWeekNumber, i } // Deprecated -bool KCalendarSystem::setYMD(QDate &date, int year, int month, int day) const +bool CalendarSystem::setYMD(QDate &date, int year, int month, int day) const { return setDate(date, year, month, day); } // NOT VIRTUAL - If override needed use shared-d -void KCalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const +void CalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const { int y, m, d; @@ -1328,7 +1327,7 @@ void KCalendarSystem::getDate(const QDate date, int *year, int *month, int *day) } -int KCalendarSystem::year(const QDate &date) const +int CalendarSystem::year(const QDate &date) const { if (isValid(date)) { int year, month, day; @@ -1341,7 +1340,7 @@ int KCalendarSystem::year(const QDate &date) const return 0; // How do you denote invalid year when we support -ve years? } -int KCalendarSystem::month(const QDate &date) const +int CalendarSystem::month(const QDate &date) const { if (isValid(date)) { int year, month, day; @@ -1354,7 +1353,7 @@ int KCalendarSystem::month(const QDate &date) const return 0; } -int KCalendarSystem::day(const QDate &date) const +int CalendarSystem::day(const QDate &date) const { if (isValid(date)) { int year, month, day; @@ -1368,7 +1367,7 @@ int KCalendarSystem::day(const QDate &date) const } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::eraName(const QDate &date, StringFormat format) const +QString CalendarSystem::eraName(const QDate &date, StringFormat format) const { Q_D(const KCalendarSystem); @@ -1384,7 +1383,7 @@ QString KCalendarSystem::eraName(const QDate &date, StringFormat format) const } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::eraYear(const QDate &date, StringFormat format) const +QString CalendarSystem::eraYear(const QDate &date, StringFormat format) const { Q_UNUSED(format) Q_D(const KCalendarSystem); @@ -1397,7 +1396,7 @@ QString KCalendarSystem::eraYear(const QDate &date, StringFormat format) const } // NOT VIRTUAL - If override needed use shared-d -int KCalendarSystem::yearInEra(const QDate &date) const +int CalendarSystem::yearInEra(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1409,7 +1408,7 @@ int KCalendarSystem::yearInEra(const QDate &date) const } // NOT VIRTUAL - If override needed use shared-d -QList *KCalendarSystem::eraList() const +QList *CalendarSystem::eraList() const { Q_D(const KCalendarSystem); @@ -1417,7 +1416,7 @@ QList *KCalendarSystem::eraList() const } // NOT VIRTUAL - If override needed use shared-d -KCalendarEra KCalendarSystem::era(const QDate &eraDate) const +KCalendarEra CalendarSystem::era(const QDate &eraDate) const { Q_D(const KCalendarSystem); @@ -1425,14 +1424,14 @@ KCalendarEra KCalendarSystem::era(const QDate &eraDate) const } // NOT VIRTUAL - If override needed use shared-d -KCalendarEra KCalendarSystem::era(const QString &eraName, int yearInEra) const +KCalendarEra CalendarSystem::era(const QString &eraName, int yearInEra) const { Q_D(const KCalendarSystem); return d->era(eraName, yearInEra); } -QDate KCalendarSystem::addYears(const QDate &date, int numYears) const +QDate CalendarSystem::addYears(const QDate &date, int numYears) const { Q_D(const KCalendarSystem); @@ -1460,7 +1459,7 @@ QDate KCalendarSystem::addYears(const QDate &date, int numYears) const return d->invalidDate(); } -QDate KCalendarSystem::addMonths(const QDate &date, int numMonths) const +QDate CalendarSystem::addMonths(const QDate &date, int numMonths) const { Q_D(const KCalendarSystem); @@ -1499,7 +1498,7 @@ QDate KCalendarSystem::addMonths(const QDate &date, int numMonths) const return d->invalidDate(); } -QDate KCalendarSystem::addDays(const QDate &date, int numDays) const +QDate CalendarSystem::addDays(const QDate &date, int numDays) const { Q_D(const KCalendarSystem); @@ -1516,7 +1515,7 @@ QDate KCalendarSystem::addDays(const QDate &date, int numDays) const } // NOT VIRTUAL - Uses shared-d instead -void KCalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate, +void CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate, int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const { Q_D(const KCalendarSystem); @@ -1527,7 +1526,7 @@ void KCalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate, } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const +int CalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const { Q_D(const KCalendarSystem); @@ -1539,7 +1538,7 @@ int KCalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::monthsDifference(const QDate &fromDate, const QDate &toDate) const +int CalendarSystem::monthsDifference(const QDate &fromDate, const QDate &toDate) const { Q_D(const KCalendarSystem); @@ -1551,7 +1550,7 @@ int KCalendarSystem::monthsDifference(const QDate &fromDate, const QDate &toDate } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) const +int CalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) const { if (isValid(fromDate) && isValid(toDate)) { return toDate.toJulianDay() - fromDate.toJulianDay(); @@ -1560,7 +1559,7 @@ int KCalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) return 0; } -int KCalendarSystem::monthsInYear(const QDate &date) const +int CalendarSystem::monthsInYear(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1572,7 +1571,7 @@ int KCalendarSystem::monthsInYear(const QDate &date) const } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::monthsInYear(int year) const +int CalendarSystem::monthsInYear(int year) const { Q_D(const KCalendarSystem); @@ -1583,18 +1582,18 @@ int KCalendarSystem::monthsInYear(int year) const return -1; } -int KCalendarSystem::weeksInYear(const QDate &date) const +int CalendarSystem::weeksInYear(const QDate &date) const { return weeksInYear(date, KLocale::DefaultWeekNumber); } -int KCalendarSystem::weeksInYear(int year) const +int CalendarSystem::weeksInYear(int year) const { return weeksInYear(year, KLocale::DefaultWeekNumber); } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::weeksInYear(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem) const +int CalendarSystem::weeksInYear(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem) const { Q_D(const KCalendarSystem); @@ -1606,7 +1605,7 @@ int KCalendarSystem::weeksInYear(const QDate &date, KLocale::WeekNumberSystem we } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const +int CalendarSystem::weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const { Q_D(const KCalendarSystem); @@ -1617,7 +1616,7 @@ int KCalendarSystem::weeksInYear(int year, KLocale::WeekNumberSystem weekNumberS return -1; } -int KCalendarSystem::daysInYear(const QDate &date) const +int CalendarSystem::daysInYear(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1629,7 +1628,7 @@ int KCalendarSystem::daysInYear(const QDate &date) const } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::daysInYear(int year) const +int CalendarSystem::daysInYear(int year) const { Q_D(const KCalendarSystem); @@ -1640,7 +1639,7 @@ int KCalendarSystem::daysInYear(int year) const return -1; } -int KCalendarSystem::daysInMonth(const QDate &date) const +int CalendarSystem::daysInMonth(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1654,7 +1653,7 @@ int KCalendarSystem::daysInMonth(const QDate &date) const } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::daysInMonth(int year, int month) const +int CalendarSystem::daysInMonth(int year, int month) const { Q_D(const KCalendarSystem); @@ -1665,14 +1664,14 @@ int KCalendarSystem::daysInMonth(int year, int month) const return -1; } -int KCalendarSystem::daysInWeek(const QDate &date) const +int CalendarSystem::daysInWeek(const QDate &date) const { Q_UNUSED(date) Q_D(const KCalendarSystem); return d->daysInWeek(); } -int KCalendarSystem::dayOfYear(const QDate &date) const +int CalendarSystem::dayOfYear(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1683,7 +1682,7 @@ int KCalendarSystem::dayOfYear(const QDate &date) const return -1; } -int KCalendarSystem::dayOfWeek(const QDate &date) const +int CalendarSystem::dayOfWeek(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1694,19 +1693,19 @@ int KCalendarSystem::dayOfWeek(const QDate &date) const return -1; } -int KCalendarSystem::weekNumber(const QDate &date, int *yearNum) const +int CalendarSystem::weekNumber(const QDate &date, int *yearNum) const { return week(date, KLocale::IsoWeekNumber, yearNum); } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::week(const QDate &date, int *yearNum) const +int CalendarSystem::week(const QDate &date, int *yearNum) const { return week(date, KLocale::DefaultWeekNumber, yearNum); } // NOT VIRTUAL - Uses shared-d instead -int KCalendarSystem::week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const +int CalendarSystem::week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const { Q_D(const KCalendarSystem); @@ -1717,7 +1716,7 @@ int KCalendarSystem::week(const QDate &date, KLocale::WeekNumberSystem weekNumbe return -1; } -bool KCalendarSystem::isLeapYear(int year) const +bool CalendarSystem::isLeapYear(int year) const { Q_D(const KCalendarSystem); @@ -1728,7 +1727,7 @@ bool KCalendarSystem::isLeapYear(int year) const return false; } -bool KCalendarSystem::isLeapYear(const QDate &date) const +bool CalendarSystem::isLeapYear(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1740,7 +1739,7 @@ bool KCalendarSystem::isLeapYear(const QDate &date) const } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::firstDayOfYear(int year) const +QDate CalendarSystem::firstDayOfYear(int year) const { Q_D(const KCalendarSystem); @@ -1752,7 +1751,7 @@ QDate KCalendarSystem::firstDayOfYear(int year) const } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::lastDayOfYear(int year) const +QDate CalendarSystem::lastDayOfYear(int year) const { Q_D(const KCalendarSystem); @@ -1764,7 +1763,7 @@ QDate KCalendarSystem::lastDayOfYear(int year) const } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::firstDayOfYear(const QDate &date) const +QDate CalendarSystem::firstDayOfYear(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1776,7 +1775,7 @@ QDate KCalendarSystem::firstDayOfYear(const QDate &date) const } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::lastDayOfYear(const QDate &date) const +QDate CalendarSystem::lastDayOfYear(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1788,7 +1787,7 @@ QDate KCalendarSystem::lastDayOfYear(const QDate &date) const } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::firstDayOfMonth(int year, int month) const +QDate CalendarSystem::firstDayOfMonth(int year, int month) const { Q_D(const KCalendarSystem); @@ -1800,7 +1799,7 @@ QDate KCalendarSystem::firstDayOfMonth(int year, int month) const } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::lastDayOfMonth(int year, int month) const +QDate CalendarSystem::lastDayOfMonth(int year, int month) const { Q_D(const KCalendarSystem); @@ -1812,7 +1811,7 @@ QDate KCalendarSystem::lastDayOfMonth(int year, int month) const } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::firstDayOfMonth(const QDate &date) const +QDate CalendarSystem::firstDayOfMonth(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1826,7 +1825,7 @@ QDate KCalendarSystem::firstDayOfMonth(const QDate &date) const } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::lastDayOfMonth(const QDate &date) const +QDate CalendarSystem::lastDayOfMonth(const QDate &date) const { Q_D(const KCalendarSystem); @@ -1839,7 +1838,7 @@ QDate KCalendarSystem::lastDayOfMonth(const QDate &date) const return QDate(); } -QString KCalendarSystem::monthName(int month, int year, KCalendarSystem::MonthNameFormat format) const +QString CalendarSystem::monthName(int month, int year, CalendarSystem::MonthNameFormat format) const { Q_D(const KCalendarSystem); @@ -1847,27 +1846,27 @@ QString KCalendarSystem::monthName(int month, int year, KCalendarSystem::MonthNa return QString(); } - if (format == KCalendarSystem::NarrowName) { + if (format == CalendarSystem::NarrowName) { return d->monthName(month, year, KLocale::NarrowName, false); } - if (format == KCalendarSystem::ShortNamePossessive) { + if (format == CalendarSystem::ShortNamePossessive) { return d->monthName(month, year, KLocale::ShortName, true); } - if (format == KCalendarSystem::ShortName) { + if (format == CalendarSystem::ShortName) { return d->monthName(month, year, KLocale::ShortName, false); } - if (format == KCalendarSystem::LongNamePossessive) { + if (format == CalendarSystem::LongNamePossessive) { return d->monthName(month, year, KLocale::LongName, true); } - // KCalendarSystem::LongName or any other + // CalendarSystem::LongName or any other return d->monthName(month, year, KLocale::LongName, false); } -QString KCalendarSystem::monthName(const QDate &date, MonthNameFormat format) const +QString CalendarSystem::monthName(const QDate &date, MonthNameFormat format) const { if (isValid(date)) { int year, month; @@ -1878,7 +1877,7 @@ QString KCalendarSystem::monthName(const QDate &date, MonthNameFormat format) co return QString(); } -QString KCalendarSystem::weekDayName(int weekDay, KCalendarSystem::WeekDayNameFormat format) const +QString CalendarSystem::weekDayName(int weekDay, CalendarSystem::WeekDayNameFormat format) const { Q_D(const KCalendarSystem); @@ -1886,22 +1885,22 @@ QString KCalendarSystem::weekDayName(int weekDay, KCalendarSystem::WeekDayNameFo return QString(); } - if (format == KCalendarSystem::NarrowDayName) { + if (format == CalendarSystem::NarrowDayName) { return d->weekDayName(weekDay, KLocale::NarrowName); } - if (format == KCalendarSystem::ShortDayName) { + if (format == CalendarSystem::ShortDayName) { return d->weekDayName(weekDay, KLocale::ShortName); } - if (format == KCalendarSystem::ShortDayName) { + if (format == CalendarSystem::ShortDayName) { return d->weekDayName(weekDay, KLocale::ShortName); } return d->weekDayName(weekDay, KLocale::LongName); } -QString KCalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format) const +QString CalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format) const { if (isValid(date)) { return weekDayName(dayOfWeek(date), format); @@ -1910,7 +1909,7 @@ QString KCalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format return QString(); } -QString KCalendarSystem::yearString(const QDate &date, StringFormat format) const +QString CalendarSystem::yearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::Year, KLocale::ShortNumber); @@ -1919,7 +1918,7 @@ QString KCalendarSystem::yearString(const QDate &date, StringFormat format) cons } } -QString KCalendarSystem::monthString(const QDate &date, StringFormat format) const +QString CalendarSystem::monthString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::Month, KLocale::ShortNumber); @@ -1928,7 +1927,7 @@ QString KCalendarSystem::monthString(const QDate &date, StringFormat format) con } } -QString KCalendarSystem::dayString(const QDate &date, StringFormat format) const +QString CalendarSystem::dayString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::Day, KLocale::ShortNumber); @@ -1938,7 +1937,7 @@ QString KCalendarSystem::dayString(const QDate &date, StringFormat format) const } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::yearInEraString(const QDate &date, StringFormat format) const +QString CalendarSystem::yearInEraString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::YearInEra, KLocale::ShortNumber); @@ -1948,7 +1947,7 @@ QString KCalendarSystem::yearInEraString(const QDate &date, StringFormat format) } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::dayOfYearString(const QDate &date, StringFormat format) const +QString CalendarSystem::dayOfYearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::DayOfYear, KLocale::ShortNumber); @@ -1958,13 +1957,13 @@ QString KCalendarSystem::dayOfYearString(const QDate &date, StringFormat format) } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::dayOfWeekString(const QDate &date) const +QString CalendarSystem::dayOfWeekString(const QDate &date) const { return formatDate(date, KLocale::DayOfWeek, KLocale::ShortNumber); } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::weekNumberString(const QDate &date, StringFormat format) const +QString CalendarSystem::weekNumberString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::Week, KLocale::ShortNumber); @@ -1974,7 +1973,7 @@ QString KCalendarSystem::weekNumberString(const QDate &date, StringFormat format } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::monthsInYearString(const QDate &date, StringFormat format) const +QString CalendarSystem::monthsInYearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::MonthsInYear, KLocale::ShortNumber); @@ -1984,7 +1983,7 @@ QString KCalendarSystem::monthsInYearString(const QDate &date, StringFormat form } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::weeksInYearString(const QDate &date, StringFormat format) const +QString CalendarSystem::weeksInYearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::WeeksInYear, KLocale::ShortNumber); @@ -1994,7 +1993,7 @@ QString KCalendarSystem::weeksInYearString(const QDate &date, StringFormat forma } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::daysInYearString(const QDate &date, StringFormat format) const +QString CalendarSystem::daysInYearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::DaysInYear, KLocale::ShortNumber); @@ -2004,7 +2003,7 @@ QString KCalendarSystem::daysInYearString(const QDate &date, StringFormat format } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::daysInMonthString(const QDate &date, StringFormat format) const +QString CalendarSystem::daysInMonthString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { return formatDate(date, KLocale::DaysInMonth, KLocale::ShortNumber); @@ -2014,12 +2013,12 @@ QString KCalendarSystem::daysInMonthString(const QDate &date, StringFormat forma } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::daysInWeekString(const QDate &date) const +QString CalendarSystem::daysInWeekString(const QDate &date) const { return formatDate(date, KLocale::DaysInWeek, KLocale::ShortNumber); } -int KCalendarSystem::yearStringToInteger(const QString &yearString, int &readLength) const +int CalendarSystem::yearStringToInteger(const QString &yearString, int &readLength) const { Q_D(const KCalendarSystem); @@ -2037,19 +2036,19 @@ int KCalendarSystem::yearStringToInteger(const QString &yearString, int &readLen return d->integerFromString(yearString, 4, readLength); } -int KCalendarSystem::monthStringToInteger(const QString &monthString, int &readLength) const +int CalendarSystem::monthStringToInteger(const QString &monthString, int &readLength) const { Q_D(const KCalendarSystem); return d->integerFromString(monthString, 2, readLength); } -int KCalendarSystem::dayStringToInteger(const QString &dayString, int &readLength) const +int CalendarSystem::dayStringToInteger(const QString &dayString, int &readLength) const { Q_D(const KCalendarSystem); return d->integerFromString(dayString, 2, readLength); } -QString KCalendarSystem::formatDate(const QDate &fromDate, KLocale::DateFormat toFormat) const +QString CalendarSystem::formatDate(const QDate &fromDate, KLocale::DateFormat toFormat) const { if (!fromDate.isValid()) { return QString(); @@ -2093,14 +2092,14 @@ QString KCalendarSystem::formatDate(const QDate &fromDate, KLocale::DateFormat t } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, +QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DateTimeFormatStandard standard) const { return formatDate(fromDate, toFormat, locale()->dateTimeDigitSet(), standard); } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DigitSet digitSet, +QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DigitSet digitSet, KLocale::DateTimeFormatStandard formatStandard) const { if (!isValid(fromDate) || toFormat.isEmpty()) { @@ -2112,7 +2111,7 @@ QString KCalendarSystem::formatDate(const QDate &fromDate, const QString &toForm } // NOT VIRTUAL - If override needed use shared-d -QString KCalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponent component, +QString CalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponent component, KLocale::DateTimeComponentFormat format, KLocale::WeekNumberSystem weekNumberSystem) const { @@ -2135,11 +2134,11 @@ QString KCalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponen case KLocale::Month: switch (format) { case KLocale::LongName: - return monthName(date, KCalendarSystem::LongName); + return monthName(date, CalendarSystem::LongName); case KLocale::ShortName: - return monthName(date, KCalendarSystem::ShortName); + return monthName(date, CalendarSystem::ShortName); case KLocale::NarrowName: - return monthName(date, KCalendarSystem::NarrowName); + return monthName(date, CalendarSystem::NarrowName); case KLocale::LongNumber: return formatDate(date, QLatin1String("%m")); case KLocale::ShortNumber: @@ -2150,15 +2149,15 @@ QString KCalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponen case KLocale::MonthName: switch (format) { case KLocale::NarrowName: - return monthName(date, KCalendarSystem::NarrowName); + return monthName(date, CalendarSystem::NarrowName); case KLocale::ShortName: case KLocale::ShortNumber: - return monthName(date, KCalendarSystem::ShortName); + return monthName(date, CalendarSystem::ShortName); case KLocale::LongName: case KLocale::LongNumber: case KLocale::DefaultComponentFormat: default: - return monthName(date, KCalendarSystem::LongName); + return monthName(date, CalendarSystem::LongName); } case KLocale::Day: case KLocale::DayName: @@ -2179,25 +2178,25 @@ QString KCalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponen switch (format) { case KLocale::LongNumber: case KLocale::LongName: - return eraName(date, KCalendarSystem::LongFormat); + return eraName(date, CalendarSystem::LongFormat); case KLocale::ShortName: case KLocale::NarrowName: case KLocale::ShortNumber: case KLocale::DefaultComponentFormat: default: - return eraName(date, KCalendarSystem::ShortFormat); + return eraName(date, CalendarSystem::ShortFormat); } case KLocale::EraYear: switch (format) { case KLocale::LongNumber: case KLocale::LongName: - return eraYear(date, KCalendarSystem::LongFormat); + return eraYear(date, CalendarSystem::LongFormat); case KLocale::ShortName: case KLocale::NarrowName: case KLocale::ShortNumber: case KLocale::DefaultComponentFormat: default: - return eraYear(date, KCalendarSystem::ShortFormat); + return eraYear(date, CalendarSystem::ShortFormat); } case KLocale::YearInEra: switch (format) { @@ -2227,11 +2226,11 @@ QString KCalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponen case KLocale::DayOfWeek: switch (format) { case KLocale::LongName: - return weekDayName(date, KCalendarSystem::LongDayName); + return weekDayName(date, CalendarSystem::LongDayName); case KLocale::ShortName: - return weekDayName(date, KCalendarSystem::ShortDayName); + return weekDayName(date, CalendarSystem::ShortDayName); case KLocale::NarrowName: - return weekDayName(date, KCalendarSystem::NarrowDayName); + return weekDayName(date, CalendarSystem::NarrowDayName); case KLocale::LongNumber: case KLocale::ShortNumber: case KLocale::DefaultComponentFormat: @@ -2241,15 +2240,15 @@ QString KCalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponen case KLocale::DayOfWeekName: switch (format) { case KLocale::NarrowName: - return weekDayName(date, KCalendarSystem::NarrowDayName); + return weekDayName(date, CalendarSystem::NarrowDayName); case KLocale::ShortName: case KLocale::ShortNumber: - return weekDayName(date, KCalendarSystem::ShortDayName); + return weekDayName(date, CalendarSystem::ShortDayName); case KLocale::LongName: case KLocale::LongNumber: case KLocale::DefaultComponentFormat: default: - return weekDayName(date, KCalendarSystem::LongDayName); + return weekDayName(date, CalendarSystem::LongDayName); } case KLocale::Week: switch (format) { @@ -2334,7 +2333,7 @@ QString KCalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponen } } -QDate KCalendarSystem::readDate(const QString &str, bool *ok) const +QDate CalendarSystem::readDate(const QString &str, bool *ok) const { //Try each standard format in turn, start with the locale ones, //then the well defined standards @@ -2355,7 +2354,7 @@ QDate KCalendarSystem::readDate(const QString &str, bool *ok) const return date; } -QDate KCalendarSystem::readDate(const QString &str, KLocale::ReadDateFlags flags, bool *ok) const +QDate CalendarSystem::readDate(const QString &str, KLocale::ReadDateFlags flags, bool *ok) const { Q_D(const KCalendarSystem); @@ -2373,13 +2372,13 @@ QDate KCalendarSystem::readDate(const QString &str, KLocale::ReadDateFlags flags return d->invalidDate(); } -QDate KCalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok) const +QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok) const { return readDate(inputString, formatString, ok, KLocale::KdeFormat); } // NOT VIRTUAL - If override needed use shared-d -QDate KCalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok, +QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok, KLocale::DateTimeFormatStandard formatStandard) const { KDateTimeParser parser; @@ -2391,7 +2390,7 @@ QDate KCalendarSystem::readDate(const QString &inputString, const QString &forma } // NOT VIRTUAL - If override needed use shared-d -int KCalendarSystem::shortYearWindowStartYear() const +int CalendarSystem::shortYearWindowStartYear() const { Q_D(const KCalendarSystem); @@ -2399,14 +2398,14 @@ int KCalendarSystem::shortYearWindowStartYear() const } // NOT VIRTUAL - If override needed use shared-d -int KCalendarSystem::applyShortYearWindow(int inputYear) const +int CalendarSystem::applyShortYearWindow(int inputYear) const { Q_D(const KCalendarSystem); return d->applyShortYearWindow(inputYear); } -int KCalendarSystem::weekStartDay() const +int CalendarSystem::weekStartDay() const { return locale()->weekStartDay(); } @@ -2417,7 +2416,7 @@ int KCalendarSystem::weekStartDay() const // instead be wrapped in validity checks, as sometimes we want this to work outside the public valid // range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but // are required for internal maths -bool KCalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) const +bool CalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) const { // Formula from The Calendar FAQ by Claus Tondering // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000 @@ -2449,7 +2448,7 @@ bool KCalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) c // instead be wrapped in validity checks, as sometimes we want this to work outside the public valid // range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but // are required for internal maths -bool KCalendarSystem::dateToJulianDay(int year, int month, int day, int &jd) const +bool CalendarSystem::dateToJulianDay(int year, int month, int day, int &jd) const { // Formula from The Calendar FAQ by Claus Tondering // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000 @@ -2480,7 +2479,7 @@ bool KCalendarSystem::dateToJulianDay(int year, int month, int day, int &jd) con return true; } -const KLocale * KCalendarSystem::locale() const +const KLocale * CalendarSystem::locale() const { Q_D(const KCalendarSystem); @@ -2488,19 +2487,19 @@ const KLocale * KCalendarSystem::locale() const } // Deprecated -void KCalendarSystem::setMaxMonthsInYear(int maxMonths) +void CalendarSystem::setMaxMonthsInYear(int maxMonths) { Q_UNUSED(maxMonths) } // Deprecated -void KCalendarSystem::setMaxDaysInWeek(int maxDays) +void CalendarSystem::setMaxDaysInWeek(int maxDays) { Q_UNUSED(maxDays) } // Deprecated -void KCalendarSystem::setHasYear0(bool hasYear0) +void CalendarSystem::setHasYear0(bool hasYear0) { Q_UNUSED(hasYear0) } From 0dfe679164c20aa57de3410dc3f3a304d38473c7 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 12:08:11 +0200 Subject: [PATCH 023/104] Replace KLocale with Locale in locale.h --- declarativeimports/locale/locale.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 72cd4818f..37c1ec94b 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -85,7 +85,7 @@ Q_ENUMS(WeekNumberSystem) //properties Q_PROPERTY(BinaryUnitDialect binaryUnitDialect READ binaryUnitDialect WRITE setBinaryUnitDialect NOTIFY binaryUnitDialectChanged) Q_PROPERTY(KCalendarSystem *calendar READ calendar WRITE setCalendar NOTIFY calendarChanged) -Q_PROPERTY(KLocale::CalendarSystem *calendarSystem READ calendarSystem WRITE setCalendarSystem NOTIFY calendarSystemChanged) +Q_PROPERTY(Locale::CalendarSystem *calendarSystem READ calendarSystem WRITE setCalendarSystem NOTIFY calendarSystemChanged) Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) Q_PROPERTY(QString countryDivisionCode READ countryDivisionCode WRITE setCountryDivisionCode NOTIFY countryDivisionCodeChanged) Q_PROPERTY(QString currencyCode READ currencyCode WRITE setCurrencyCode NOTIFY currencyCodeChanged) @@ -113,7 +113,7 @@ Q_PROPERTY(bool positivePrefixCurrencySymbol READ positivePrefixCurrencySymbol W Q_PROPERTY(QString positiveSign READ positiveSign WRITE setPositiveSign NOTIFY positiveSignChanged) Q_PROPERTY(QString thousandsSeparator READ thousandsSeparator WRITE setThousandsSeparator NOTIFY thousandsSeparatorChanged) Q_PROPERTY(int weekDayOfPray READ weekDayOfPray WRITE setWeekDayOfPray NOTIFY weekDayOfPrayChanged) -Q_PROPERTY(KLocale::WeekNumberSystem weekNumberSystem READ weekNumberSystem WRITE setWeekNumberSystem NOTIFY WeekNumberSystemChanged) +Q_PROPERTY(Locale::WeekNumberSystem weekNumberSystem READ weekNumberSystem WRITE setWeekNumberSystem NOTIFY WeekNumberSystemChanged) Q_PROPERTY(int weekStartDay READ weekStartDay WRITE setWeekStartDay NOTIFY weekStartDayChanged) Q_PROPERTY(int workingWeekEndDay READ workingWeekEndDay WRITE setWorkingWeekEndDay NOTIFY workingWeekEndDayChanged) Q_PROPERTY(int workingWeekStartDay READ workingWeekStartDay WRITE setWorkingWeekStartDay NOTIFY workingWeekStartDayChanged) @@ -182,7 +182,7 @@ public: * @param catname the catalog name. Must be UTF-8 encoded. * @param msg the message. Must not be null or empty. Must be UTF-8 encoded. * @param lang language in which the translation was found. If no translation - * was found, KLocale::defaultLanguage() is reported. If null, + * was found, Locale::defaultLanguage() is reported. If null, * the language is not reported. * @param trans raw translation, or original if not found. If no translation * was found, original message is reported. If null, the @@ -206,7 +206,7 @@ public: * @param ctxt the context. Must not be null. Must be UTF-8 encoded. * @param msg the message. Must not be null or empty. Must be UTF-8 encoded. * @param lang language in which the translation was found. If no translation - * was found, KLocale::defaultLanguage() is reported. If null, + * was found, Locale::defaultLanguage() is reported. If null, * the language is not reported. * @param trans raw translation, or original if not found. If no translation * was found, original message is reported. If null, the @@ -231,7 +231,7 @@ public: * @param plural the plural form. Must not be null. Must be UTF-8 encoded. * @param n number on which the forms are decided. * @param lang language in which the translation was found. If no translation - * was found, KLocale::defaultLanguage() is reported. If null, + * was found, Locale::defaultLanguage() is reported. If null, * the language is not reported. * @param trans raw translation, or original if not found. If no translation * was found, original message is reported (either plural or @@ -260,7 +260,7 @@ public: * @param plural the plural form. Must not be null. Must be UTF-8 encoded. * @param n number on which the forms are decided. * @param lang language in which the translation was found. If no translation - * was found, KLocale::defaultLanguage() is reported. If null, + * was found, Locale::defaultLanguage() is reported. If null, * the language is not reported. * @param trans raw translation, or original if not found. If no translation * was found, original message is reported (either plural or @@ -669,10 +669,10 @@ public: * using the binary unit dialect @p dialect and the specific units @p specificUnit. * * Example: - * formatByteSize(1000, unit, KLocale::BinaryUnitKilo) returns: - * for KLocale::MetricBinaryUnits, "1.0 kB", - * for KLocale::IECBinaryUnits, "0.9 KiB", - * for KLocale::JEDECBinaryUnits, "0.9 KB". + * formatByteSize(1000, unit, Locale::BinaryUnitKilo) returns: + * for Locale::MetricBinaryUnits, "1.0 kB", + * for Locale::IECBinaryUnits, "0.9 KiB", + * for Locale::JEDECBinaryUnits, "0.9 KB". * * @param size size in bytes * @param precision number of places after the decimal point to use. KDE uses @@ -1065,7 +1065,7 @@ public: * * Returns the type of Calendar System used in this Locale * - * @see KLocale::CalendarSystem + * @see Locale::CalendarSystem * @see KCalendarSystem * @return the type of Calendar System */ @@ -1075,7 +1075,7 @@ public: * * Sets the type of Calendar System to use in this Locale * - * @see KLocale::CalendarSystem + * @see Locale::CalendarSystem * @see KCalendarSystem * @param calendarSystem the Calendar System to use */ From c65b553a1196eb25f2ca425912e1a7686ad464e3 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 12:09:15 +0200 Subject: [PATCH 024/104] Replace KLocale with Locale in calendarsystem.h --- declarativeimports/locale/calendarsystem.cpp | 6 +- declarativeimports/locale/calendarsystem.h | 97 ++++++++++---------- 2 files changed, 52 insertions(+), 51 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index fd144e4c0..e33e2cc60 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -1,8 +1,6 @@ /* - Copyright (c) 2002 Carlos Moro - Copyright (c) 2002 Hans Petter Bieker - Copyright 2007, 2008, 2009, 2010 John Layt - + Copyright (C) 2012 Giorgos Tsiapaliwkas + Copyright (C) 2012 Antonis Tsiapaliokas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 2c4571784..dbe029bc7 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -1,7 +1,6 @@ /* - Copyright (c) 2002 Carlos Moro - Copyright (c) 2002-2003 Hans Petter Bieker - Copyright 2007, 2009, 2010 John Layt + Copyright (C) 2012 Giorgos Tsiapaliwkas + Copyright (C) 2012 Antonis Tsiapaliokas This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -22,7 +21,7 @@ #ifndef CALENDARSYSTEM_H #define CALENDARSYSTEM_H -#include "klocale.h" // needed for enums +#include "locale.h" // needed for enums #include "kglobal.h" #include @@ -84,7 +83,7 @@ public: * @param locale locale to use for translations. The global locale is used if null. * @return a KCalendarSystem object */ - Q_INVOKABLE static KCalendarSystem *create(KLocale::CalendarSystem calendarSystem, + Q_INVOKABLE static KCalendarSystem *create(Locale::CalendarSystem calendarSystem, const KLocale *locale = 0); /** @@ -98,7 +97,7 @@ public: * @param locale locale to use for translations. The global locale is used if null. * @return a KCalendarSystem object */ - Q_INVOKABLE static KCalendarSystem *create(KLocale::CalendarSystem calendarSystem, KSharedConfig::Ptr config, + Q_INVOKABLE static KCalendarSystem *create(Locale::CalendarSystem calendarSystem, KSharedConfig::Ptr config, const KLocale *locale = 0); /** @@ -112,28 +111,28 @@ public: * @param locale the locale to use for the label, defaults to global * @return label for calendar */ - Q_INVOKABLE static QString calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale = KGlobal::locale()); + Q_INVOKABLE static QString calendarLabel(Locale::CalendarSystem calendarSystem, const KLocale *locale = KGlobal::locale()); /** * * Returns the Calendar System enum value for a given Calendar Type, - * e.g. KLocale::QDateCalendar for "gregorian" + * e.g. Locale::QDateCalendar for "gregorian" * * @param calendarType the calendar type to convert * @return calendar system for calendar type */ - Q_INVOKABLE static KLocale::CalendarSystem calendarSystem(const QString &calendarType); + Q_INVOKABLE static Locale::CalendarSystem calendarSystem(const QString &calendarType); //KDE5 remove /** * * Returns the deprecated Calendar Type for a given Calendar System enum value, - * e.g. "gregorian" for KLocale::QDateCalendar + * e.g. "gregorian" for Locale::QDateCalendar * * @param calendarSystem the calendar system to convert * @return calendar type for calendar system */ - Q_INVOKABLE static QString calendarType(KLocale::CalendarSystem calendarSystem); + Q_INVOKABLE static QString calendarType(Locale::CalendarSystem calendarSystem); /** * Constructor of abstract calendar class. This will be called by derived classes. @@ -163,7 +162,7 @@ public: * * @return type of calendar system */ - Q_INVOKABLE KLocale::CalendarSystem calendarSystem() const; + Q_INVOKABLE Locale::CalendarSystem calendarSystem() const; //KDE5 make virtual? /** @@ -520,7 +519,7 @@ public: * @param weekNumberSystem the week number system to use * @return number of weeks in the year, -1 if date invalid */ - Q_INVOKABLE int weeksInYear(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem) const; + Q_INVOKABLE int weeksInYear(const QDate &date, Locale::WeekNumberSystem weekNumberSystem) const; /** * Returns the number of localized weeks in the given year. @@ -544,7 +543,7 @@ public: * @param weekNumberSystem the week number system to use * @return number of weeks in the year, -1 if date invalid */ - Q_INVOKABLE int weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const; + Q_INVOKABLE int weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const; /** * Returns the number of days in the given year. @@ -619,7 +618,7 @@ public: * * This may be ISO, US, or any other supported week numbering scheme. If * you specifically require the ISO Week or any other scheme, you should use - * the week(KLocale::WeekNumberSystem) form. + * the week(Locale::WeekNumberSystem) form. * * If the date falls in the last week of the previous year or the first * week of the following year, then the yearNum returned will be set to the @@ -654,7 +653,7 @@ public: * @param yearNum returns the year the date belongs to * @return week number, -1 if input date invalid */ - Q_INVOKABLE int week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const; + Q_INVOKABLE int week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const; /** * Returns whether a given year is a leap year. @@ -810,14 +809,14 @@ public: * settings are respected, which would not occur in some cases if using * the global locale. Defaults to global locale. * - * @see KLocale::formatDate + * @see Locale::formatDate * * @param fromDate the date to be formatted * @param toFormat category of date format to use * * @return The date as a string */ - Q_INVOKABLE virtual QString formatDate(const QDate &fromDate, KLocale::DateFormat toFormat = KLocale::LongDate) const; + Q_INVOKABLE virtual QString formatDate(const QDate &fromDate, Locale::DateFormat toFormat = Locale::LongDate) const; //KDE5 Make virtual /** @@ -927,7 +926,7 @@ public: * * %0 is not supported as the returned result is always in the locale's chosen numeric symbol digit set. * - * @see KLocale::formatDate + * @see Locale::formatDate * * @param fromDate the date to be formatted * @param toFormat the date format to use @@ -936,7 +935,7 @@ public: * @return The date as a string */ Q_INVOKABLE QString formatDate(const QDate &fromDate, const QString &toFormat, - KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const; + Locale::DateTimeFormatStandard formatStandard = Locale::KdeFormat) const; //KDE5 Make virtual /** @@ -954,20 +953,20 @@ public: * * @return The date as a string */ - Q_INVOKABLE QString formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DigitSet digitSet, - KLocale::DateTimeFormatStandard formatStandard = KLocale::KdeFormat) const; + Q_INVOKABLE QString formatDate(const QDate &fromDate, const QString &toFormat, Locale::DigitSet digitSet, + Locale::DateTimeFormatStandard formatStandard = Locale::KdeFormat) const; //KDE5 Make virtual /** * * Returns a Date Component as a localized string in the requested format. * - * For example for 2010-01-01 the KLocale::Month with en_US Locale and Gregorian calendar may return: - * KLocale::ShortNumber = "1" - * KLocale::LongNumber = "01" - * KLocale::NarrowName = "J" - * KLocale::ShortName = "Jan" - * KLocale::LongName = "January" + * For example for 2010-01-01 the Locale::Month with en_US Locale and Gregorian calendar may return: + * Locale::ShortNumber = "1" + * Locale::LongNumber = "01" + * Locale::NarrowName = "J" + * Locale::ShortName = "Jan" + * Locale::LongName = "January" * * @param date The date to format * @param component The date component to return @@ -975,9 +974,9 @@ public: * @param weekNumberSystem To override the default Week Number System to use * @return The localized string form of the date component */ - Q_INVOKABLE QString formatDate(const QDate &date, KLocale::DateTimeComponent component, - KLocale::DateTimeComponentFormat format = KLocale::DefaultComponentFormat, - KLocale::WeekNumberSystem weekNumberSystem = KLocale::DefaultWeekNumber) const; + Q_INVOKABLE QString formatDate(const QDate &date, Locale::DateTimeComponent component, + Locale::DateTimeComponentFormat format = Locale::DefaultComponentFormat, + Locale::WeekNumberSystem weekNumberSystem = Locale::DefaultWeekNumber) const; /** * Converts a localized date string to a QDate. @@ -988,7 +987,7 @@ public: * settings are respected, which would not occur in some cases if using * the global locale. Defaults to global locale. * - * @see KLocale::readDate + * @see Locale::readDate * * @param str the string to convert * @param ok if non-null, will be set to @c true if the date is valid, @c false if invalid @@ -1007,7 +1006,7 @@ public: * settings are respected, which would not occur in some cases if using * the global locale. Defaults to global locale. * - * @see KLocale::readDate + * @see Locale::readDate * * @param str the string to convert * @param flags whether the date string is to be in full format or in short format @@ -1015,7 +1014,7 @@ public: * * @return the string converted to a QDate */ - Q_INVOKABLE virtual QDate readDate(const QString &str, KLocale::ReadDateFlags flags, bool *ok = 0) const; + Q_INVOKABLE virtual QDate readDate(const QString &str, Locale::ReadDateFlags flags, bool *ok = 0) const; /** * Converts a localized date string to a QDate, using the specified @p format. @@ -1028,7 +1027,7 @@ public: * @return the string converted to a QDate * * @see formatDate - * @see KLocale::readDate + * @see Locale::readDate */ Q_INVOKABLE virtual QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok = 0) const; @@ -1090,10 +1089,10 @@ public: * @return the string converted to a QDate * * @see formatDate - * @see KLocale::readDate + * @see Locale::readDate */ Q_INVOKABLE QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok, - KLocale::DateTimeFormatStandard formatStandard) const; + Locale::DateTimeFormatStandard formatStandard) const; //KDE5 Make virtual /** @@ -1107,8 +1106,8 @@ public: * of 10 is interpreted as 2010. * * The Short Year Window is only ever applied when reading the Short Year - * format and not the Long Year format, i.e. KLocale::ShortFormat or '%y' - * only and not KLocale::LongFormat or '%Y'. + * format and not the Long Year format, i.e. Locale::ShortFormat or '%y' + * only and not Locale::LongFormat or '%Y'. * * The Start Year 0 effectively means not to use a Short Year Window * @@ -1120,8 +1119,8 @@ public: * This value must always be used when evaluating user input Short Year * strings. * - * @see KLocale::shortYearWindowStartYear - * @see KLocale::applyShortYearWindow + * @see Locale::shortYearWindowStartYear + * @see Locale::applyShortYearWindow * @return the short year window start year */ Q_INVOKABLE int shortYearWindowStartYear() const; @@ -1137,8 +1136,8 @@ public: * If the @p inputYear is not between 0 and 99, then the original Year Number * is returned. * - * @see KLocale::setYearWindowOffset - * @see KLocale::yearWindowOffset + * @see Locale::setYearWindowOffset + * @see Locale::yearWindowOffset * @param inputYear the year number to apply the year window to * @return the year number after applying the year window */ @@ -1152,7 +1151,7 @@ public: * settings are respected, which would not occur in some cases if using * the global locale. Defaults to global locale. * - * @see KLocale::weekStartDay + * @see Locale::weekStartDay * * @return an integer (Monday = 1, ..., Sunday = 7) */ @@ -1241,11 +1240,11 @@ protected: * that library widgets require access to internally. * * @see KCalendarSystem::formatDate - * @see KLocale::formatDate + * @see Locale::formatDate * @see KCalendarSystem::weekStartDay - * @see KLocale::weekStartDay + * @see Locale::weekStartDay * @see KCalendarSystem::readDate - * @see KLocale::readDate + * @see Locale::readDate * * @return locale to use */ @@ -1265,6 +1264,9 @@ protected: const KLocale *locale = 0); private: + //FIXME When it comes the time to create wrappers for the above + //classes will i need the "friend class foo"??? + //Required for shared d-pointer as already private, remove in KDE5 friend class KCalendarSystemCoptic; friend class KCalendarSystemEthiopian; @@ -1284,6 +1286,7 @@ private: friend class KDateTimeParser; friend class KDateTable; + //FIXME era issue.. // Era functions needed by friends, may be made public later if needed in KCM QList *eraList() const; KCalendarEra era(const QDate &eraDate) const; From 5077d77f8f31ce8430f448609e02247859b8fefd Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 12:24:48 +0200 Subject: [PATCH 025/104] Fix includes and replace KLocale with Locale in calendarsystem.cpp --- declarativeimports/locale/calendarsystem.cpp | 574 +++++++++---------- declarativeimports/locale/calendarsystem.h | 1 + 2 files changed, 269 insertions(+), 306 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index e33e2cc60..e57dfe557 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -17,7 +17,7 @@ Boston, MA 02110-1301, USA. */ -#include "kcalendarsystem.h" +#include "calendarsystem.h" #include "kdebug.h" #include "kconfiggroup.h" @@ -41,6 +41,7 @@ #include "kcalendarsystemqdate_p.h" #include "kcalendarsystemthai_p.h" +//FIXME fix all the create static methods KCalendarSystem *CalendarSystem::create(const QString &calendarType, const KLocale *locale) { return create(calendarSystem(calendarType), locale); @@ -52,187 +53,148 @@ KCalendarSystem *CalendarSystem::create(const QString &calendarType, KSharedConf return create(calendarSystem(calendarType), config, locale); } -QStringList CalendarSystem::calendarSystems() -{ - QStringList lst; - - lst.append(QLatin1String("coptic")); - lst.append(QLatin1String("ethiopian")); - lst.append(QLatin1String("gregorian")); - lst.append(QLatin1String("gregorian-proleptic")); - lst.append(QLatin1String("hebrew")); - lst.append(QLatin1String("hijri")); - lst.append(QLatin1String("indian-national")); - lst.append(QLatin1String("jalali")); - lst.append(QLatin1String("japanese")); - lst.append(QLatin1String("julian")); - lst.append(QLatin1String("minguo")); - lst.append(QLatin1String("thai")); - - return lst; -} - QString CalendarSystem::calendarLabel(const QString &calendarType) { - if (calendarSystemsList().contains(calendarSystem(calendarType))) { - return CalendarSystem::calendarLabel(CalendarSystem::calendarSystem(calendarType)); - } else { - return ki18nc("@item Calendar system", "Invalid Calendar Type").toString(KGlobal::locale()); - } + return m_calendarSystem->calendarLabel(calendarType); } -KCalendarSystem *CalendarSystem::create(KLocale::CalendarSystem calendarSystem, const KLocale *locale) +KCalendarSystem *CalendarSystem::create(Locale::CalendarSystem calendarSystem, const KLocale *locale) { return create(calendarSystem, KSharedConfig::Ptr(), locale); } -KCalendarSystem *CalendarSystem::create(KLocale::CalendarSystem calendarSystem, +KCalendarSystem *CalendarSystem::create(Locale::CalendarSystem calendarSystem, KSharedConfig::Ptr config, const KLocale *locale) { switch (calendarSystem) { - case KLocale::QDateCalendar: + case Locale::QDateCalendar: return new KCalendarSystemQDate(config, locale); - case KLocale::CopticCalendar: + case Locale::CopticCalendar: return new KCalendarSystemCoptic(config, locale); - case KLocale::EthiopianCalendar: + case Locale::EthiopianCalendar: return new KCalendarSystemEthiopian(config, locale); - case KLocale::GregorianCalendar: + case Locale::GregorianCalendar: return new KCalendarSystemGregorian(config, locale); - case KLocale::HebrewCalendar: + case Locale::HebrewCalendar: return new KCalendarSystemHebrew(config, locale); - case KLocale::IndianNationalCalendar: + case Locale::IndianNationalCalendar: return new KCalendarSystemIndianNational(config, locale); - case KLocale::IslamicCivilCalendar: + case Locale::IslamicCivilCalendar: return new KCalendarSystemIslamicCivil(config, locale); - case KLocale::JalaliCalendar: + case Locale::JalaliCalendar: return new KCalendarSystemJalali(config, locale); - case KLocale::JapaneseCalendar: + case Locale::JapaneseCalendar: return new KCalendarSystemJapanese(config, locale); - case KLocale::JulianCalendar: + case Locale::JulianCalendar: return new KCalendarSystemJulian(config, locale); - case KLocale::MinguoCalendar: + case Locale::MinguoCalendar: return new KCalendarSystemMinguo(config, locale); - case KLocale::ThaiCalendar: + case Locale::ThaiCalendar: return new KCalendarSystemThai(config, locale); default: return new KCalendarSystemQDate(config, locale); } } -QList CalendarSystem::calendarSystemsList() +QList CalendarSystem::calendarSystemsList() { - QList list; - - list.append(KLocale::QDateCalendar); - list.append(KLocale::CopticCalendar); - list.append(KLocale::EthiopianCalendar); - list.append(KLocale::GregorianCalendar); - list.append(KLocale::HebrewCalendar); - list.append(KLocale::IslamicCivilCalendar); - list.append(KLocale::IndianNationalCalendar); - list.append(KLocale::JalaliCalendar); - list.append(KLocale::JapaneseCalendar); - list.append(KLocale::JulianCalendar); - list.append(KLocale::MinguoCalendar); - list.append(KLocale::ThaiCalendar); - - return list; + return m_calendarSystem->calendarSystemList(); } -QString CalendarSystem::calendarLabel(KLocale::CalendarSystem calendarSystem, const KLocale *locale) +QString CalendarSystem::calendarLabel(Locale::CalendarSystem calendarSystem, const KLocale *locale) { switch (calendarSystem) { - case KLocale::QDateCalendar: + case Locale::QDateCalendar: return ki18nc("@item Calendar system", "Gregorian").toString(locale); - case KLocale::CopticCalendar: + case Locale::CopticCalendar: return ki18nc("@item Calendar system", "Coptic").toString(locale); - case KLocale::EthiopianCalendar: + case Locale::EthiopianCalendar: return ki18nc("@item Calendar system", "Ethiopian").toString(locale); - case KLocale::GregorianCalendar: + case Locale::GregorianCalendar: return ki18nc("@item Calendar system", "Gregorian (Proleptic)").toString(locale); - case KLocale::HebrewCalendar: + case Locale::HebrewCalendar: return ki18nc("@item Calendar system", "Hebrew").toString(locale); - case KLocale::IslamicCivilCalendar: + case Locale::IslamicCivilCalendar: return ki18nc("@item Calendar system", "Islamic / Hijri (Civil)").toString(locale); - case KLocale::IndianNationalCalendar: + case Locale::IndianNationalCalendar: return ki18nc("@item Calendar system", "Indian National").toString(locale); - case KLocale::JalaliCalendar: + case Locale::JalaliCalendar: return ki18nc("@item Calendar system", "Jalali").toString(locale); - case KLocale::JapaneseCalendar: + case Locale::JapaneseCalendar: return ki18nc("@item Calendar system", "Japanese").toString(locale); - case KLocale::JulianCalendar: + case Locale::JulianCalendar: return ki18nc("@item Calendar system", "Julian").toString(locale); - case KLocale::MinguoCalendar: + case Locale::MinguoCalendar: return ki18nc("@item Calendar system", "Taiwanese").toString(locale); - case KLocale::ThaiCalendar: + case Locale::ThaiCalendar: return ki18nc("@item Calendar system", "Thai").toString(locale); } return ki18nc("@item Calendar system", "Invalid Calendar Type").toString(locale); } -KLocale::CalendarSystem CalendarSystem::calendarSystemForCalendarType(const QString &calendarType ) +Locale::CalendarSystem CalendarSystem::calendarSystemForCalendarType(const QString &calendarType ) { return calendarSystem( calendarType ); } -KLocale::CalendarSystem CalendarSystem::calendarSystem(const QString &calendarType ) +Locale::CalendarSystem CalendarSystem::calendarSystem(const QString &calendarType ) { if (calendarType == QLatin1String("coptic")) { - return KLocale::CopticCalendar; + return Locale::CopticCalendar; } else if (calendarType == QLatin1String("ethiopian")) { - return KLocale::EthiopianCalendar; + return Locale::EthiopianCalendar; } else if (calendarType == QLatin1String("gregorian")) { - return KLocale::QDateCalendar; + return Locale::QDateCalendar; } else if (calendarType == QLatin1String("gregorian-proleptic")) { - return KLocale::GregorianCalendar; + return Locale::GregorianCalendar; } else if (calendarType == QLatin1String("hebrew")) { - return KLocale::HebrewCalendar; + return Locale::HebrewCalendar; } else if (calendarType == QLatin1String("hijri")) { - return KLocale::IslamicCivilCalendar; + return Locale::IslamicCivilCalendar; } else if (calendarType == QLatin1String("indian-national")) { - return KLocale::IndianNationalCalendar; + return Locale::IndianNationalCalendar; } else if (calendarType == QLatin1String("jalali")) { - return KLocale::JalaliCalendar; + return Locale::JalaliCalendar; } else if (calendarType == QLatin1String("japanese")) { - return KLocale::JapaneseCalendar; + return Locale::JapaneseCalendar; } else if (calendarType == QLatin1String("julian")) { - return KLocale::JulianCalendar; + return Locale::JulianCalendar; } else if (calendarType == QLatin1String("minguo")) { - return KLocale::MinguoCalendar; + return Locale::MinguoCalendar; } else if (calendarType == QLatin1String("thai")) { - return KLocale::ThaiCalendar; + return Locale::ThaiCalendar; } else { - return KLocale::QDateCalendar; + return Locale::QDateCalendar; } } -QString CalendarSystem::calendarType(KLocale::CalendarSystem calendarSystem) +QString CalendarSystem::calendarType(Locale::CalendarSystem calendarSystem) { - if (calendarSystem == KLocale::QDateCalendar) { + if (calendarSystem == Locale::QDateCalendar) { return QLatin1String("gregorian"); - } else if (calendarSystem == KLocale::CopticCalendar) { + } else if (calendarSystem == Locale::CopticCalendar) { return QLatin1String("coptic"); - } else if (calendarSystem == KLocale::EthiopianCalendar) { + } else if (calendarSystem == Locale::EthiopianCalendar) { return QLatin1String("ethiopian"); - } else if (calendarSystem == KLocale::GregorianCalendar) { + } else if (calendarSystem == Locale::GregorianCalendar) { return QLatin1String("gregorian-proleptic"); - } else if (calendarSystem == KLocale::HebrewCalendar) { + } else if (calendarSystem == Locale::HebrewCalendar) { return QLatin1String("hebrew"); - } else if (calendarSystem == KLocale::IndianNationalCalendar) { + } else if (calendarSystem == Locale::IndianNationalCalendar) { return QLatin1String("indian-national"); - } else if (calendarSystem == KLocale::IslamicCivilCalendar) { + } else if (calendarSystem == Locale::IslamicCivilCalendar) { return QLatin1String("hijri"); - } else if (calendarSystem == KLocale::JalaliCalendar) { + } else if (calendarSystem == Locale::JalaliCalendar) { return QLatin1String("jalali"); - } else if (calendarSystem == KLocale::JapaneseCalendar) { + } else if (calendarSystem == Locale::JapaneseCalendar) { return QLatin1String("japanese"); - } else if (calendarSystem == KLocale::JulianCalendar) { + } else if (calendarSystem == Locale::JulianCalendar) { return QLatin1String("julian"); - } else if (calendarSystem == KLocale::MinguoCalendar) { + } else if (calendarSystem == Locale::MinguoCalendar) { return QLatin1String("minguo"); - } else if (calendarSystem == KLocale::ThaiCalendar) { + } else if (calendarSystem == Locale::ThaiCalendar) { return QLatin1String("thai"); } else { return QLatin1String("gregorian"); @@ -255,9 +217,9 @@ KCalendarSystemPrivate::~KCalendarSystemPrivate() // Dummy version using Gregorian as an example // This method MUST be re-implemented in any new Calendar System -KLocale::CalendarSystem KCalendarSystemPrivate::calendarSystem() const +Locale::CalendarSystem KCalendarSystemPrivate::calendarSystem() const { - return KLocale::QDateCalendar; + return Locale::QDateCalendar; } // Dummy version as an example, remember to translate (see Gregorian for example) @@ -381,7 +343,7 @@ int KCalendarSystemPrivate::latestValidYear() const // Dummy version // This method MUST be re-implemented in any new Calendar System -QString KCalendarSystemPrivate::monthName(int month, int year, KLocale::DateTimeComponentFormat format, bool possessive) const +QString KCalendarSystemPrivate::monthName(int month, int year, Locale::DateTimeComponentFormat format, bool possessive) const { Q_UNUSED(month); Q_UNUSED(year); @@ -392,7 +354,7 @@ QString KCalendarSystemPrivate::monthName(int month, int year, KLocale::DateTime // Dummy version // This method MUST be re-implemented in any new Calendar System -QString KCalendarSystemPrivate::weekDayName(int weekDay, KLocale::DateTimeComponentFormat format) const +QString KCalendarSystemPrivate::weekDayName(int weekDay, Locale::DateTimeComponentFormat format) const { Q_UNUSED(weekDay); Q_UNUSED(format); @@ -400,21 +362,21 @@ QString KCalendarSystemPrivate::weekDayName(int weekDay, KLocale::DateTimeCompon } // Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const +int KCalendarSystemPrivate::week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum) const { int y, m, d; q->julianDayToDate(date.toJulianDay(), y, m, d); switch (weekNumberSystem) { - case KLocale::IsoWeekNumber: + case Locale::IsoWeekNumber: return isoWeekNumber(date, yearNum); - case KLocale::FirstFullWeek: + case Locale::FirstFullWeek: return regularWeekNumber(date, locale()->weekStartDay(), 0, yearNum); - case KLocale::FirstPartialWeek: + case Locale::FirstPartialWeek: return regularWeekNumber(date, locale()->weekStartDay(), 1, yearNum); - case KLocale::SimpleWeek: + case Locale::SimpleWeek: return simpleWeekNumber(date, yearNum); - case KLocale::DefaultWeekNumber: + case Locale::DefaultWeekNumber: default: return week(date, locale()->weekNumberSystem(), yearNum); } @@ -513,18 +475,18 @@ int KCalendarSystemPrivate::simpleWeekNumber(const QDate &date, int *yearNum) co } // Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const +int KCalendarSystemPrivate::weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const { switch (weekNumberSystem) { - case KLocale::IsoWeekNumber: + case Locale::IsoWeekNumber: return isoWeeksInYear(year); - case KLocale::FirstFullWeek: + case Locale::FirstFullWeek: return regularWeeksInYear(year, locale()->weekStartDay(), 0); - case KLocale::FirstPartialWeek: + case Locale::FirstPartialWeek: return regularWeeksInYear(year, locale()->weekStartDay(), 1); - case KLocale::SimpleWeek: + case Locale::SimpleWeek: return simpleWeeksInYear(year); - case KLocale::DefaultWeekNumber: + case Locale::DefaultWeekNumber: default: return weeksInYear(year, locale()->weekNumberSystem()); } @@ -782,7 +744,7 @@ QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QCha // Reimplement if special integer to string handling required, e.g. Hebrew. // Utility to convert an integer into the correct display string form -QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QChar padChar, KLocale::DigitSet digitSet) const +QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QChar padChar, Locale::DigitSet digitSet) const { if (padChar == QLatin1Char('\0') || padWidth == 0) { return q->locale()->convertDigits(QString::number(number), digitSet); @@ -932,8 +894,8 @@ KCalendarEra KCalendarSystemPrivate::era(const QString &eraName, int yearInEra) for (int i = m_eraList->count() - 1; i >= 0; --i) { KCalendarEra era = m_eraList->at(i); - if (era.name(KLocale::LongName).toLower() == eraName.toLower() || - era.name(KLocale::ShortName).toLower() == eraName.toLower()) { + if (era.name(Locale::LongName).toLower() == eraName.toLower() || + era.name(Locale::ShortName).toLower() == eraName.toLower()) { return era; } } @@ -963,7 +925,7 @@ void KCalendarSystemPrivate::loadEraList(const KConfigGroup & cg) startDate = q->earliestValidDate(); } } else { - startDate = q->readDate(buffer, KLocale::IsoFormat); + startDate = q->readDate(buffer, Locale::IsoFormat); } if (q->isValid(startDate)) { startYear = q->year(startDate); @@ -979,7 +941,7 @@ void KCalendarSystemPrivate::loadEraList(const KConfigGroup & cg) endDate = q->latestValidDate(); } } else { - endDate = q->readDate(buffer, KLocale::IsoFormat); + endDate = q->readDate(buffer, Locale::IsoFormat); } addEra(direction.toLatin1(), eraEntry.section(QLatin1Char(':'), 1, 1).toInt(), startDate, startYear, endDate, eraEntry.section(QLatin1Char(':'), 4, 4), @@ -1094,7 +1056,7 @@ CalendarSystem::~KCalendarSystem() } // NOT VIRTUAL - If override needed use shared-d -KLocale::CalendarSystem CalendarSystem::calendarSystem() const +Locale::CalendarSystem CalendarSystem::calendarSystem() const { Q_D(const KCalendarSystem); @@ -1371,9 +1333,9 @@ QString CalendarSystem::eraName(const QDate &date, StringFormat format) const if (isValid(date)) { if (format == LongFormat) { - return d->era(date).name(KLocale::LongName); + return d->era(date).name(Locale::LongName); } else { - return d->era(date).name(KLocale::ShortName); + return d->era(date).name(Locale::ShortName); } } @@ -1582,16 +1544,16 @@ int CalendarSystem::monthsInYear(int year) const int CalendarSystem::weeksInYear(const QDate &date) const { - return weeksInYear(date, KLocale::DefaultWeekNumber); + return weeksInYear(date, Locale::DefaultWeekNumber); } int CalendarSystem::weeksInYear(int year) const { - return weeksInYear(year, KLocale::DefaultWeekNumber); + return weeksInYear(year, Locale::DefaultWeekNumber); } // NOT VIRTUAL - Uses shared-d instead -int CalendarSystem::weeksInYear(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem) const +int CalendarSystem::weeksInYear(const QDate &date, Locale::WeekNumberSystem weekNumberSystem) const { Q_D(const KCalendarSystem); @@ -1603,7 +1565,7 @@ int CalendarSystem::weeksInYear(const QDate &date, KLocale::WeekNumberSystem wee } // NOT VIRTUAL - Uses shared-d instead -int CalendarSystem::weeksInYear(int year, KLocale::WeekNumberSystem weekNumberSystem) const +int CalendarSystem::weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const { Q_D(const KCalendarSystem); @@ -1693,17 +1655,17 @@ int CalendarSystem::dayOfWeek(const QDate &date) const int CalendarSystem::weekNumber(const QDate &date, int *yearNum) const { - return week(date, KLocale::IsoWeekNumber, yearNum); + return week(date, Locale::IsoWeekNumber, yearNum); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::week(const QDate &date, int *yearNum) const { - return week(date, KLocale::DefaultWeekNumber, yearNum); + return week(date, Locale::DefaultWeekNumber, yearNum); } // NOT VIRTUAL - Uses shared-d instead -int CalendarSystem::week(const QDate &date, KLocale::WeekNumberSystem weekNumberSystem, int *yearNum) const +int CalendarSystem::week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum) const { Q_D(const KCalendarSystem); @@ -1845,23 +1807,23 @@ QString CalendarSystem::monthName(int month, int year, CalendarSystem::MonthName } if (format == CalendarSystem::NarrowName) { - return d->monthName(month, year, KLocale::NarrowName, false); + return d->monthName(month, year, Locale::NarrowName, false); } if (format == CalendarSystem::ShortNamePossessive) { - return d->monthName(month, year, KLocale::ShortName, true); + return d->monthName(month, year, Locale::ShortName, true); } if (format == CalendarSystem::ShortName) { - return d->monthName(month, year, KLocale::ShortName, false); + return d->monthName(month, year, Locale::ShortName, false); } if (format == CalendarSystem::LongNamePossessive) { - return d->monthName(month, year, KLocale::LongName, true); + return d->monthName(month, year, Locale::LongName, true); } // CalendarSystem::LongName or any other - return d->monthName(month, year, KLocale::LongName, false); + return d->monthName(month, year, Locale::LongName, false); } QString CalendarSystem::monthName(const QDate &date, MonthNameFormat format) const @@ -1884,18 +1846,18 @@ QString CalendarSystem::weekDayName(int weekDay, CalendarSystem::WeekDayNameForm } if (format == CalendarSystem::NarrowDayName) { - return d->weekDayName(weekDay, KLocale::NarrowName); + return d->weekDayName(weekDay, Locale::NarrowName); } if (format == CalendarSystem::ShortDayName) { - return d->weekDayName(weekDay, KLocale::ShortName); + return d->weekDayName(weekDay, Locale::ShortName); } if (format == CalendarSystem::ShortDayName) { - return d->weekDayName(weekDay, KLocale::ShortName); + return d->weekDayName(weekDay, Locale::ShortName); } - return d->weekDayName(weekDay, KLocale::LongName); + return d->weekDayName(weekDay, Locale::LongName); } QString CalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format) const @@ -1910,27 +1872,27 @@ QString CalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format) QString CalendarSystem::yearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::Year, KLocale::ShortNumber); + return formatDate(date, Locale::Year, Locale::ShortNumber); } else { - return formatDate(date, KLocale::Year, KLocale::LongNumber); + return formatDate(date, Locale::Year, Locale::LongNumber); } } QString CalendarSystem::monthString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::Month, KLocale::ShortNumber); + return formatDate(date, Locale::Month, Locale::ShortNumber); } else { - return formatDate(date, KLocale::Month, KLocale::LongNumber); + return formatDate(date, Locale::Month, Locale::LongNumber); } } QString CalendarSystem::dayString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::Day, KLocale::ShortNumber); + return formatDate(date, Locale::Day, Locale::ShortNumber); } else { - return formatDate(date, KLocale::Day, KLocale::LongNumber); + return formatDate(date, Locale::Day, Locale::LongNumber); } } @@ -1938,9 +1900,9 @@ QString CalendarSystem::dayString(const QDate &date, StringFormat format) const QString CalendarSystem::yearInEraString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::YearInEra, KLocale::ShortNumber); + return formatDate(date, Locale::YearInEra, Locale::ShortNumber); } else { - return formatDate(date, KLocale::YearInEra, KLocale::LongNumber); + return formatDate(date, Locale::YearInEra, Locale::LongNumber); } } @@ -1948,25 +1910,25 @@ QString CalendarSystem::yearInEraString(const QDate &date, StringFormat format) QString CalendarSystem::dayOfYearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::DayOfYear, KLocale::ShortNumber); + return formatDate(date, Locale::DayOfYear, Locale::ShortNumber); } else { - return formatDate(date, KLocale::DayOfYear, KLocale::LongNumber); + return formatDate(date, Locale::DayOfYear, Locale::LongNumber); } } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::dayOfWeekString(const QDate &date) const { - return formatDate(date, KLocale::DayOfWeek, KLocale::ShortNumber); + return formatDate(date, Locale::DayOfWeek, Locale::ShortNumber); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::weekNumberString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::Week, KLocale::ShortNumber); + return formatDate(date, Locale::Week, Locale::ShortNumber); } else { - return formatDate(date, KLocale::Week, KLocale::LongNumber); + return formatDate(date, Locale::Week, Locale::LongNumber); } } @@ -1974,9 +1936,9 @@ QString CalendarSystem::weekNumberString(const QDate &date, StringFormat format) QString CalendarSystem::monthsInYearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::MonthsInYear, KLocale::ShortNumber); + return formatDate(date, Locale::MonthsInYear, Locale::ShortNumber); } else { - return formatDate(date, KLocale::MonthsInYear, KLocale::LongNumber); + return formatDate(date, Locale::MonthsInYear, Locale::LongNumber); } } @@ -1984,9 +1946,9 @@ QString CalendarSystem::monthsInYearString(const QDate &date, StringFormat forma QString CalendarSystem::weeksInYearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::WeeksInYear, KLocale::ShortNumber); + return formatDate(date, Locale::WeeksInYear, Locale::ShortNumber); } else { - return formatDate(date, KLocale::WeeksInYear, KLocale::LongNumber); + return formatDate(date, Locale::WeeksInYear, Locale::LongNumber); } } @@ -1994,9 +1956,9 @@ QString CalendarSystem::weeksInYearString(const QDate &date, StringFormat format QString CalendarSystem::daysInYearString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::DaysInYear, KLocale::ShortNumber); + return formatDate(date, Locale::DaysInYear, Locale::ShortNumber); } else { - return formatDate(date, KLocale::DaysInYear, KLocale::LongNumber); + return formatDate(date, Locale::DaysInYear, Locale::LongNumber); } } @@ -2004,16 +1966,16 @@ QString CalendarSystem::daysInYearString(const QDate &date, StringFormat format) QString CalendarSystem::daysInMonthString(const QDate &date, StringFormat format) const { if (format == ShortFormat) { - return formatDate(date, KLocale::DaysInMonth, KLocale::ShortNumber); + return formatDate(date, Locale::DaysInMonth, Locale::ShortNumber); } else { - return formatDate(date, KLocale::DaysInMonth, KLocale::LongNumber); + return formatDate(date, Locale::DaysInMonth, Locale::LongNumber); } } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::daysInWeekString(const QDate &date) const { - return formatDate(date, KLocale::DaysInWeek, KLocale::ShortNumber); + return formatDate(date, Locale::DaysInWeek, Locale::ShortNumber); } int CalendarSystem::yearStringToInteger(const QString &yearString, int &readLength) const @@ -2046,13 +2008,13 @@ int CalendarSystem::dayStringToInteger(const QString &dayString, int &readLength return d->integerFromString(dayString, 2, readLength); } -QString CalendarSystem::formatDate(const QDate &fromDate, KLocale::DateFormat toFormat) const +QString CalendarSystem::formatDate(const QDate &fromDate, Locale::DateFormat toFormat) const { if (!fromDate.isValid()) { return QString(); } - if (toFormat == KLocale::FancyShortDate || toFormat == KLocale::FancyLongDate) { + if (toFormat == Locale::FancyShortDate || toFormat == Locale::FancyLongDate) { QDate now = KDateTime::currentLocalDate(); int daysToNow = fromDate.daysTo(now); switch (daysToNow) { @@ -2072,17 +2034,17 @@ QString CalendarSystem::formatDate(const QDate &fromDate, KLocale::DateFormat to } switch (toFormat) { - case KLocale::LongDate: - case KLocale::FancyLongDate: + case Locale::LongDate: + case Locale::FancyLongDate: return formatDate(fromDate, locale()->dateFormat()); - case KLocale::IsoDate: + case Locale::IsoDate: return formatDate(fromDate, QLatin1String("%Y-%m-%d")); - case KLocale::IsoWeekDate: + case Locale::IsoWeekDate: return formatDate(fromDate, QLatin1String("%Y-W%V-%u")); - case KLocale::IsoOrdinalDate: + case Locale::IsoOrdinalDate: return formatDate(fromDate, QLatin1String("%Y-%j")); - case KLocale::ShortDate: - case KLocale::FancyShortDate: + case Locale::ShortDate: + case Locale::FancyShortDate: default: return formatDate(fromDate, locale()->dateFormatShort()); } @@ -2091,14 +2053,14 @@ QString CalendarSystem::formatDate(const QDate &fromDate, KLocale::DateFormat to // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, - KLocale::DateTimeFormatStandard standard) const + Locale::DateTimeFormatStandard standard) const { return formatDate(fromDate, toFormat, locale()->dateTimeDigitSet(), standard); } // NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, KLocale::DigitSet digitSet, - KLocale::DateTimeFormatStandard formatStandard) const +QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DigitSet digitSet, + Locale::DateTimeFormatStandard formatStandard) const { if (!isValid(fromDate) || toFormat.isEmpty()) { return QString(); @@ -2109,220 +2071,220 @@ QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toForma } // NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::formatDate(const QDate &date, KLocale::DateTimeComponent component, - KLocale::DateTimeComponentFormat format, - KLocale::WeekNumberSystem weekNumberSystem) const +QString CalendarSystem::formatDate(const QDate &date, Locale::DateTimeComponent component, + Locale::DateTimeComponentFormat format, + Locale::WeekNumberSystem weekNumberSystem) const { Q_D(const KCalendarSystem); switch (component) { - case KLocale::Year: - case KLocale::YearName: + case Locale::Year: + case Locale::YearName: switch (format) { - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: return formatDate(date, QLatin1String("%y")); - case KLocale::LongNumber: - case KLocale::LongName: - case KLocale::DefaultComponentFormat: + case Locale::LongNumber: + case Locale::LongName: + case Locale::DefaultComponentFormat: default: return formatDate(date, QLatin1String("%Y")); } - case KLocale::Month: + case Locale::Month: switch (format) { - case KLocale::LongName: + case Locale::LongName: return monthName(date, CalendarSystem::LongName); - case KLocale::ShortName: + case Locale::ShortName: return monthName(date, CalendarSystem::ShortName); - case KLocale::NarrowName: + case Locale::NarrowName: return monthName(date, CalendarSystem::NarrowName); - case KLocale::LongNumber: + case Locale::LongNumber: return formatDate(date, QLatin1String("%m")); - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return formatDate(date, QLatin1String("%n")); } - case KLocale::MonthName: + case Locale::MonthName: switch (format) { - case KLocale::NarrowName: + case Locale::NarrowName: return monthName(date, CalendarSystem::NarrowName); - case KLocale::ShortName: - case KLocale::ShortNumber: + case Locale::ShortName: + case Locale::ShortNumber: return monthName(date, CalendarSystem::ShortName); - case KLocale::LongName: - case KLocale::LongNumber: - case KLocale::DefaultComponentFormat: + case Locale::LongName: + case Locale::LongNumber: + case Locale::DefaultComponentFormat: default: return monthName(date, CalendarSystem::LongName); } - case KLocale::Day: - case KLocale::DayName: + case Locale::Day: + case Locale::DayName: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return formatDate(date, QLatin1String("%d")); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return formatDate(date, QLatin1String("%e")); } - case KLocale::JulianDay: + case Locale::JulianDay: return d->stringFromInteger(date.toJulianDay(), 0); - case KLocale::EraName: + case Locale::EraName: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return eraName(date, CalendarSystem::LongFormat); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return eraName(date, CalendarSystem::ShortFormat); } - case KLocale::EraYear: + case Locale::EraYear: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return eraYear(date, CalendarSystem::LongFormat); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return eraYear(date, CalendarSystem::ShortFormat); } - case KLocale::YearInEra: + case Locale::YearInEra: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return formatDate(date, QLatin1String("%4Ey")); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return formatDate(date, QLatin1String("%Ey")); } - case KLocale::DayOfYear: - case KLocale::DayOfYearName: + case Locale::DayOfYear: + case Locale::DayOfYearName: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return formatDate(date, QLatin1String("%j")); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return formatDate(date, QLatin1String("%-j")); } - case KLocale::DayOfWeek: + case Locale::DayOfWeek: switch (format) { - case KLocale::LongName: + case Locale::LongName: return weekDayName(date, CalendarSystem::LongDayName); - case KLocale::ShortName: + case Locale::ShortName: return weekDayName(date, CalendarSystem::ShortDayName); - case KLocale::NarrowName: + case Locale::NarrowName: return weekDayName(date, CalendarSystem::NarrowDayName); - case KLocale::LongNumber: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::LongNumber: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return formatDate(date, QLatin1String("%-u")); } - case KLocale::DayOfWeekName: + case Locale::DayOfWeekName: switch (format) { - case KLocale::NarrowName: + case Locale::NarrowName: return weekDayName(date, CalendarSystem::NarrowDayName); - case KLocale::ShortName: - case KLocale::ShortNumber: + case Locale::ShortName: + case Locale::ShortNumber: return weekDayName(date, CalendarSystem::ShortDayName); - case KLocale::LongName: - case KLocale::LongNumber: - case KLocale::DefaultComponentFormat: + case Locale::LongName: + case Locale::LongNumber: + case Locale::DefaultComponentFormat: default: return weekDayName(date, CalendarSystem::LongDayName); } - case KLocale::Week: + case Locale::Week: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return d->stringFromInteger(week(date, weekNumberSystem, 0), 2, QLatin1Char('0')); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return d->stringFromInteger(week(date, weekNumberSystem, 0), 0, QLatin1Char('0')); } - case KLocale::WeekYear: { + case Locale::WeekYear: { int weekYear; QDate yearDate; week(date, weekNumberSystem, &weekYear); setDate(yearDate, weekYear, 1, 1); - return formatDate(yearDate, KLocale::Year, format); + return formatDate(yearDate, Locale::Year, format); } - case KLocale::MonthsInYear: + case Locale::MonthsInYear: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return d->stringFromInteger(monthsInYear(date), 2, QLatin1Char('0')); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return d->stringFromInteger(monthsInYear(date), 0, QLatin1Char('0')); } - case KLocale::WeeksInYear: + case Locale::WeeksInYear: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return d->stringFromInteger(weeksInYear(date), 2, QLatin1Char('0')); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return d->stringFromInteger(weeksInYear(date), 0, QLatin1Char('0')); } - case KLocale::DaysInYear: + case Locale::DaysInYear: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return d->stringFromInteger(daysInYear(date), 3, QLatin1Char('0')); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return d->stringFromInteger(daysInYear(date), 0, QLatin1Char('0')); } - case KLocale::DaysInMonth: + case Locale::DaysInMonth: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: + case Locale::LongNumber: + case Locale::LongName: return d->stringFromInteger(daysInMonth(date), 2, QLatin1Char('0')); - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return d->stringFromInteger(daysInMonth(date), 0, QLatin1Char('0')); } - case KLocale::DaysInWeek: + case Locale::DaysInWeek: switch (format) { - case KLocale::LongNumber: - case KLocale::LongName: - case KLocale::ShortName: - case KLocale::NarrowName: - case KLocale::ShortNumber: - case KLocale::DefaultComponentFormat: + case Locale::LongNumber: + case Locale::LongName: + case Locale::ShortName: + case Locale::NarrowName: + case Locale::ShortNumber: + case Locale::DefaultComponentFormat: default: return d->stringFromInteger(d->daysInWeek(), 0); } @@ -2335,15 +2297,15 @@ QDate CalendarSystem::readDate(const QString &str, bool *ok) const { //Try each standard format in turn, start with the locale ones, //then the well defined standards - QDate date = readDate(str, KLocale::ShortFormat, ok); + QDate date = readDate(str, Locale::ShortFormat, ok); if (!isValid(date)) { - date = readDate(str, KLocale::NormalFormat, ok); + date = readDate(str, Locale::NormalFormat, ok); if (!isValid(date)) { - date = readDate(str, KLocale::IsoFormat, ok); + date = readDate(str, Locale::IsoFormat, ok); if (!isValid(date)) { - date = readDate(str, KLocale::IsoWeekFormat, ok); + date = readDate(str, Locale::IsoWeekFormat, ok); if (!isValid(date)) { - date = readDate(str, KLocale::IsoOrdinalFormat, ok); + date = readDate(str, Locale::IsoOrdinalFormat, ok); } } } @@ -2352,19 +2314,19 @@ QDate CalendarSystem::readDate(const QString &str, bool *ok) const return date; } -QDate CalendarSystem::readDate(const QString &str, KLocale::ReadDateFlags flags, bool *ok) const +QDate CalendarSystem::readDate(const QString &str, Locale::ReadDateFlags flags, bool *ok) const { Q_D(const KCalendarSystem); - if (flags & KLocale::ShortFormat) { + if (flags & Locale::ShortFormat) { return readDate(str, locale()->dateFormatShort(), ok); - } else if (flags & KLocale::NormalFormat) { + } else if (flags & Locale::NormalFormat) { return readDate(str, locale()->dateFormat(), ok); - } else if (flags & KLocale::IsoFormat) { + } else if (flags & Locale::IsoFormat) { return readDate(str, QLatin1String("%Y-%m-%d"), ok); - } else if (flags & KLocale::IsoWeekFormat) { + } else if (flags & Locale::IsoWeekFormat) { return readDate(str, QLatin1String("%Y-W%V-%u"), ok); - } else if (flags & KLocale::IsoOrdinalFormat) { + } else if (flags & Locale::IsoOrdinalFormat) { return readDate(str, QLatin1String("%Y-%j"), ok); } return d->invalidDate(); @@ -2372,12 +2334,12 @@ QDate CalendarSystem::readDate(const QString &str, KLocale::ReadDateFlags flags, QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok) const { - return readDate(inputString, formatString, ok, KLocale::KdeFormat); + return readDate(inputString, formatString, ok, Locale::KdeFormat); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok, - KLocale::DateTimeFormatStandard formatStandard) const + Locale::DateTimeFormatStandard formatStandard) const { KDateTimeParser parser; QDate resultDate = parser.parseDate(inputString, formatString, this, locale(), locale()->dateTimeDigitSet(), formatStandard); diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index dbe029bc7..e341c35db 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -21,6 +21,7 @@ #ifndef CALENDARSYSTEM_H #define CALENDARSYSTEM_H +#include #include "locale.h" // needed for enums #include "kglobal.h" From 4bf016c646476b8f211e2bc36783c81f4e715887 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 1 Feb 2012 14:02:43 +0200 Subject: [PATCH 026/104] Add KCalendar *m_calendar and replace the method's contents with "m_calendar->foo();" --- declarativeimports/locale/calendarsystem.cpp | 2059 +----------------- 1 file changed, 83 insertions(+), 1976 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index e57dfe557..a7ca3d660 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -99,968 +99,29 @@ KCalendarSystem *CalendarSystem::create(Locale::CalendarSystem calendarSystem, QList CalendarSystem::calendarSystemsList() { - return m_calendarSystem->calendarSystemList(); -} + QList list; -QString CalendarSystem::calendarLabel(Locale::CalendarSystem calendarSystem, const KLocale *locale) -{ - switch (calendarSystem) { - case Locale::QDateCalendar: - return ki18nc("@item Calendar system", "Gregorian").toString(locale); - case Locale::CopticCalendar: - return ki18nc("@item Calendar system", "Coptic").toString(locale); - case Locale::EthiopianCalendar: - return ki18nc("@item Calendar system", "Ethiopian").toString(locale); - case Locale::GregorianCalendar: - return ki18nc("@item Calendar system", "Gregorian (Proleptic)").toString(locale); - case Locale::HebrewCalendar: - return ki18nc("@item Calendar system", "Hebrew").toString(locale); - case Locale::IslamicCivilCalendar: - return ki18nc("@item Calendar system", "Islamic / Hijri (Civil)").toString(locale); - case Locale::IndianNationalCalendar: - return ki18nc("@item Calendar system", "Indian National").toString(locale); - case Locale::JalaliCalendar: - return ki18nc("@item Calendar system", "Jalali").toString(locale); - case Locale::JapaneseCalendar: - return ki18nc("@item Calendar system", "Japanese").toString(locale); - case Locale::JulianCalendar: - return ki18nc("@item Calendar system", "Julian").toString(locale); - case Locale::MinguoCalendar: - return ki18nc("@item Calendar system", "Taiwanese").toString(locale); - case Locale::ThaiCalendar: - return ki18nc("@item Calendar system", "Thai").toString(locale); + foreach(KLocale::CalendarSystem calendarSystem, m_calendarSystem->calendarSystemList()) { + list.append((Locale::CalendarSystem)calendarSystem); } - return ki18nc("@item Calendar system", "Invalid Calendar Type").toString(locale); + return list; } -Locale::CalendarSystem CalendarSystem::calendarSystemForCalendarType(const QString &calendarType ) +QString CalendarSystem::calendarLabel(Locale::CalendarSystem calendarSystem, const Locale *locale) { - return calendarSystem( calendarType ); + return m_calendarSystem->calendarLabel((KLocale::CalendarSystem)calendarSystem, (KLocale)locale); } Locale::CalendarSystem CalendarSystem::calendarSystem(const QString &calendarType ) { - if (calendarType == QLatin1String("coptic")) { - return Locale::CopticCalendar; - } else if (calendarType == QLatin1String("ethiopian")) { - return Locale::EthiopianCalendar; - } else if (calendarType == QLatin1String("gregorian")) { - return Locale::QDateCalendar; - } else if (calendarType == QLatin1String("gregorian-proleptic")) { - return Locale::GregorianCalendar; - } else if (calendarType == QLatin1String("hebrew")) { - return Locale::HebrewCalendar; - } else if (calendarType == QLatin1String("hijri")) { - return Locale::IslamicCivilCalendar; - } else if (calendarType == QLatin1String("indian-national")) { - return Locale::IndianNationalCalendar; - } else if (calendarType == QLatin1String("jalali")) { - return Locale::JalaliCalendar; - } else if (calendarType == QLatin1String("japanese")) { - return Locale::JapaneseCalendar; - } else if (calendarType == QLatin1String("julian")) { - return Locale::JulianCalendar; - } else if (calendarType == QLatin1String("minguo")) { - return Locale::MinguoCalendar; - } else if (calendarType == QLatin1String("thai")) { - return Locale::ThaiCalendar; - } else { - return Locale::QDateCalendar; - } -} - -QString CalendarSystem::calendarType(Locale::CalendarSystem calendarSystem) -{ - if (calendarSystem == Locale::QDateCalendar) { - return QLatin1String("gregorian"); - } else if (calendarSystem == Locale::CopticCalendar) { - return QLatin1String("coptic"); - } else if (calendarSystem == Locale::EthiopianCalendar) { - return QLatin1String("ethiopian"); - } else if (calendarSystem == Locale::GregorianCalendar) { - return QLatin1String("gregorian-proleptic"); - } else if (calendarSystem == Locale::HebrewCalendar) { - return QLatin1String("hebrew"); - } else if (calendarSystem == Locale::IndianNationalCalendar) { - return QLatin1String("indian-national"); - } else if (calendarSystem == Locale::IslamicCivilCalendar) { - return QLatin1String("hijri"); - } else if (calendarSystem == Locale::JalaliCalendar) { - return QLatin1String("jalali"); - } else if (calendarSystem == Locale::JapaneseCalendar) { - return QLatin1String("japanese"); - } else if (calendarSystem == Locale::JulianCalendar) { - return QLatin1String("julian"); - } else if (calendarSystem == Locale::MinguoCalendar) { - return QLatin1String("minguo"); - } else if (calendarSystem == Locale::ThaiCalendar) { - return QLatin1String("thai"); - } else { - return QLatin1String("gregorian"); - } -} - -// Shared d pointer base class definitions - -KCalendarSystemPrivate::KCalendarSystemPrivate(KCalendarSystem *q_ptr) - : q(q_ptr), - m_eraList(0), - m_shortYearWindowStartYear(2000) -{ -} - -KCalendarSystemPrivate::~KCalendarSystemPrivate() -{ - delete m_eraList; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -Locale::CalendarSystem KCalendarSystemPrivate::calendarSystem() const -{ - return Locale::QDateCalendar; -} - -// Dummy version as an example, remember to translate (see Gregorian for example) -// Add the Era's in chronological order, from earliest to latest -// This method MUST be re-implemented in any new Calendar System -void KCalendarSystemPrivate::loadDefaultEraList() -{ - addEra('-', 1, q->epoch().addDays(-1), -1, q->earliestValidDate(), QLatin1String("Before KDE"), QLatin1String("BK"), QLatin1String("%Ey %EC")); - addEra('+', 1, q->epoch(), 1, q->latestValidDate(), QLatin1String("Anno KDE"), QLatin1String("AK"), QLatin1String("%Ey %EC")); -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::monthsInYear(int year) const -{ - Q_UNUSED(year) - return 12; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::daysInMonth(int year, int month) const -{ - if (month == 2) { - if (isLeapYear(year)) { - return 29; - } else { - return 28; - } - } - - if (month == 4 || month == 6 || month == 9 || month == 11) { - return 30; - } - - return 31; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::daysInYear(int year) const -{ - if (isLeapYear(year)) { - return 366; - } else { - return 365; - } -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::daysInWeek() const -{ - return 7; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -bool KCalendarSystemPrivate::isLeapYear(int year) const -{ - if (year < 1) { - year = year + 1; - } - - if (year % 4 == 0) { - if (year % 100 != 0) { - return true; - } else if (year % 400 == 0) { - return true; - } - } - - return false; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -bool KCalendarSystemPrivate::hasLeapMonths() const -{ - return false; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -bool KCalendarSystemPrivate::hasYearZero() const -{ - return false; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::maxDaysInWeek() const -{ - return 7; -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::maxMonthsInYear() const -{ - return 12; -} - -// Convenince, faster than calling year( ealiestValidDate() ), -// needed in fake-virtual functions so don't remove -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::earliestValidYear() const -{ - return -4712; -} - -// Convenince, faster than calling year( latestValidDate() ), -// needed in fake-virtual functions so don't remove -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -int KCalendarSystemPrivate::latestValidYear() const -{ - return 9999; -} - -// Dummy version -// This method MUST be re-implemented in any new Calendar System -QString KCalendarSystemPrivate::monthName(int month, int year, Locale::DateTimeComponentFormat format, bool possessive) const -{ - Q_UNUSED(month); - Q_UNUSED(year); - Q_UNUSED(format); - Q_UNUSED(possessive); - return QString(); -} - -// Dummy version -// This method MUST be re-implemented in any new Calendar System -QString KCalendarSystemPrivate::weekDayName(int weekDay, Locale::DateTimeComponentFormat format) const -{ - Q_UNUSED(weekDay); - Q_UNUSED(format); - return QString(); -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum) const -{ - int y, m, d; - q->julianDayToDate(date.toJulianDay(), y, m, d); - - switch (weekNumberSystem) { - case Locale::IsoWeekNumber: - return isoWeekNumber(date, yearNum); - case Locale::FirstFullWeek: - return regularWeekNumber(date, locale()->weekStartDay(), 0, yearNum); - case Locale::FirstPartialWeek: - return regularWeekNumber(date, locale()->weekStartDay(), 1, yearNum); - case Locale::SimpleWeek: - return simpleWeekNumber(date, yearNum); - case Locale::DefaultWeekNumber: - default: - return week(date, locale()->weekNumberSystem(), yearNum); - } -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::isoWeekNumber(const QDate &date, int *yearNum) const -{ - int y, m, d; - q->julianDayToDate(date.toJulianDay(), y, m, d); - - QDate firstDayWeek1, lastDay; - int week; - int weekDay1, dayOfWeek1InYear; - - // let's guess 1st day of 1st week - firstDayWeek1 = firstDayOfYear(y); - weekDay1 = dayOfWeek(firstDayWeek1); - - // iso 8601: week 1 is the first containing thursday and week starts on monday - if (weekDay1 > 4 /*Thursday*/) { - firstDayWeek1 = q->addDays(firstDayWeek1 , daysInWeek() - weekDay1 + 1); // next monday - } - - dayOfWeek1InYear = dayOfYear(firstDayWeek1); - - // our date in prev year's week - if (dayOfYear(date) < dayOfWeek1InYear) { - if (yearNum) { - *yearNum = addYears(y, - 1); - } - return isoWeeksInYear(addYears(y, - 1)); - } - - // let's check if its last week belongs to next year - lastDay = lastDayOfYear(y); - - // if our date is in last week && 1st week in next year has thursday - if ((dayOfYear(date) >= daysInYear(y) - dayOfWeek(lastDay) + 1) - && dayOfWeek(lastDay) < 4) { - if (yearNum) { - * yearNum = addYears(y, 1); - } - week = 1; - } else { - // To calculate properly the number of weeks from day a to x let's make a day 1 of week - if (weekDay1 < 5) { - firstDayWeek1 = q->addDays(firstDayWeek1, -(weekDay1 - 1)); - } - - if (yearNum) { - * yearNum = y; - } - - week = firstDayWeek1.daysTo(date) / daysInWeek() + 1; - } - - return week; -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::regularWeekNumber(const QDate &date, int weekStartDay, int firstWeekNumber, int *weekYear) const -{ - int y, m, d; - q->julianDayToDate(date.toJulianDay(), y, m, d); - - int firstWeekDayOffset = (dayOfWeek(date) - weekStartDay + daysInWeek()) % daysInWeek(); - int dayInYear = date.toJulianDay() - firstDayOfYear(y).toJulianDay(); // 0 indexed - int week = ((dayInYear - firstWeekDayOffset + daysInWeek()) / daysInWeek()); - - if (dayOfWeek(firstDayOfYear(y)) != weekStartDay) { - week = week + firstWeekNumber; - } - - if (week < 1) { - y = y - 1; - week = regularWeeksInYear(y, weekStartDay, firstWeekNumber); - } - - if (weekYear) { - *weekYear = y; - } - - return week; -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::simpleWeekNumber(const QDate &date, int *yearNum) const -{ - int y, m, d; - q->julianDayToDate(date.toJulianDay(), y, m, d); - if (yearNum) { - *yearNum = y; - } - return ((date.toJulianDay() - firstDayOfYear(y).toJulianDay()) / daysInWeek()) + 1; -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const -{ - switch (weekNumberSystem) { - case Locale::IsoWeekNumber: - return isoWeeksInYear(year); - case Locale::FirstFullWeek: - return regularWeeksInYear(year, locale()->weekStartDay(), 0); - case Locale::FirstPartialWeek: - return regularWeeksInYear(year, locale()->weekStartDay(), 1); - case Locale::SimpleWeek: - return simpleWeeksInYear(year); - case Locale::DefaultWeekNumber: - default: - return weeksInYear(year, locale()->weekNumberSystem()); - } -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::isoWeeksInYear(int year) const -{ - QDate lastDayOfThisYear = lastDayOfYear(year); - - int weekYear = year; - int lastWeekInThisYear = isoWeekNumber(lastDayOfThisYear, &weekYear); - - // If error, or the last day of the year is in the first week of next year use the week before - if (lastWeekInThisYear < 1 || weekYear != year) { - lastWeekInThisYear = isoWeekNumber(q->addDays(lastDayOfThisYear, -7), &weekYear); - } - - return lastWeekInThisYear; -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::regularWeeksInYear(int year, int weekStartDay, int firstWeekNumber) const -{ - return regularWeekNumber(lastDayOfYear(year), weekStartDay, firstWeekNumber, 0); -} - -// Reimplement if special maths handling required, e.g. Hebrew. -int KCalendarSystemPrivate::simpleWeeksInYear(int year) const -{ - return simpleWeekNumber(lastDayOfYear(year), 0); -} - -// Reimplement if special maths handling required, e.g. Hebrew. -// Works for calendars with constant number of months, or where leap month is last month of year -// Will not work for Hebrew or others where leap month is inserted in middle of year -void KCalendarSystemPrivate::dateDifference(const QDate &fromDate, const QDate &toDate, - int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const -{ - // This could be optimised a little but is left in full as it's easier to understand - int dy = 0; - int dm = 0; - int dd = 0; - int dir = 1; - - if (toDate < fromDate) { - dateDifference(toDate, fromDate, &dy, &dm, &dd, 0); - dir = -1; - } else if (toDate > fromDate) { - - int fromYear = q->year(fromDate); - int toYear = q->year(toDate); - int fromMonth = q->month(fromDate); - int toMonth = q->month(toDate); - int fromDay = q->day(fromDate); - int toDay = q->day(toDate); - - int monthsInPrevYear = monthsInYear(addYears(toYear, -1)); - int daysInPrevMonth = q->daysInMonth(q->addMonths(toDate, -1)); - int daysInFromMonth = daysInMonth(fromYear, fromMonth); - int daysInToMonth = daysInMonth(toYear, toMonth); - - // Calculate years difference - if (toYear == fromYear) { - dy = 0; - } else if (toMonth > fromMonth) { - dy = differenceYearNumbers(fromYear, toYear); - } else if (toMonth < fromMonth) { - dy = differenceYearNumbers(fromYear, toYear) - 1; - } else { // toMonth == fromMonth - // Allow for last day of month to last day of month and leap days - // e.g. 2000-02-29 to 2001-02-28 is 1 year not 0 years - if ((toDay >= fromDay) || (fromDay == daysInFromMonth && toDay == daysInToMonth)) { - dy = differenceYearNumbers(fromYear, toYear); - } else { - dy = differenceYearNumbers(fromYear, toYear) - 1; - } - } - - // Calculate months and days difference - if (toDay >= fromDay) { - dm = (monthsInPrevYear + toMonth - fromMonth) % monthsInPrevYear; - dd = toDay - fromDay; - } else { // toDay < fromDay - // Allow for last day of month to last day of month and leap days - // e.g. 2010-03-31 to 2010-04-30 is 1 month - // 2000-02-29 to 2001-02-28 is 1 year - // 2000-02-29 to 2001-03-01 is 1 year 1 day - int prevMonth = q->month(q->addMonths(toDate, -1)); - if (fromDay == daysInFromMonth && toDay == daysInToMonth) { - dm = (monthsInPrevYear + toMonth - fromMonth) % monthsInPrevYear; - dd = 0; - } else if (prevMonth == fromMonth && daysInPrevMonth < daysInFromMonth) { - // Special case where fromDate = leap day and toDate in month following but non-leap year - // e.g. 2000-02-29 to 2001-03-01 needs to use 29 to calculate day number not 28 - dm = (monthsInPrevYear + toMonth - fromMonth - 1) % monthsInPrevYear; - dd = (daysInFromMonth + toDay - fromDay) % daysInFromMonth; - } else { - dm = (monthsInPrevYear + toMonth - fromMonth - 1) % monthsInPrevYear; - dd = (daysInPrevMonth + toDay - fromDay) % daysInPrevMonth; - } - } - - } - - // Only return values if we have a valid pointer - if (yearsDiff) { - *yearsDiff = dy; - } - if (monthsDiff) { - *monthsDiff = dm; - } - if (daysDiff) { - *daysDiff = dd; - } - if (direction) { - *direction = dir; - } -} - -// Reimplement if special maths handling required, e.g. Hebrew -// Allows for calendars with leap months at end of year but not during year -int KCalendarSystemPrivate::yearsDifference(const QDate &fromDate, const QDate &toDate) const -{ - // This could be optimised a little but is left in full as it's easier to understand - // Alternatively could just call dateDifference(), but this is slightly more efficient - - if (toDate < fromDate) { - return 0 - yearsDifference(toDate, fromDate); - } - - if (toDate == fromDate) { - return 0; - } - - int fromYear = q->year(fromDate); - int toYear = q->year(toDate); - - if (toYear == fromYear) { - return 0; - } - - int fromMonth = q->month(fromDate); - int toMonth = q->month(toDate); - - if (toMonth > fromMonth) { - return differenceYearNumbers(fromYear, toYear); - } - - if (toMonth < fromMonth) { - return differenceYearNumbers(fromYear, toYear) - 1; - } - - // toMonth == fromMonth - int fromDay = q->day(fromDate); - int toDay = q->day(toDate); - - // Adjust for month numbers in from and to year - // Allow for last day of month to last day of month and leap days - // e.g. 2000-02-29 to 2001-02-28 is 1 year not 0 years - if ((toDay >= fromDay) || - (fromDay == daysInMonth(fromYear, fromMonth) && - toDay == daysInMonth(toYear, toMonth))) { - return differenceYearNumbers(fromYear, toYear); - } else { - return differenceYearNumbers(fromYear, toYear) - 1; - } - -} - -// Reimplement if special maths handling required, e.g. maybe Hebrew? -// Allows for calendars with leap months -int KCalendarSystemPrivate::monthsDifference(const QDate &fromDate, const QDate &toDate) const -{ - if (toDate < fromDate) { - return 0 - monthsDifference(toDate, fromDate); - } - - if (toDate == fromDate) { - return 0; - } - - int fromYear = q->year(fromDate); - int toYear = q->year(toDate); - int fromMonth = q->month(fromDate); - int toMonth = q->month(toDate); - int fromDay = q->day(fromDate); - int toDay = q->day(toDate); - - int monthsInPreceedingYears; - - // Calculate number of months in full years preceding toYear - if (toYear == fromYear) { - monthsInPreceedingYears = 0; - } else if (hasLeapMonths()) { - monthsInPreceedingYears = 0; - for (int y = fromYear; y < toYear; y = addYears(y, 1)) { - monthsInPreceedingYears = monthsInPreceedingYears + monthsInYear(y); - } - } else { - monthsInPreceedingYears = differenceYearNumbers(fromYear, toYear) * monthsInYear(toYear); - } - - // Adjust for months in from and to year - // Allow for last day of month to last day of month and leap days - // e.g. 2010-03-31 to 2010-04-30 is 1 month not 0 months - // also 2000-02-29 to 2001-02-28 is 12 months not 11 months - if ((toDay >= fromDay) || - (fromDay == daysInMonth(fromYear, fromMonth) && - toDay == daysInMonth(toYear, toMonth))) { - return monthsInPreceedingYears + toMonth - fromMonth; - } else { - return monthsInPreceedingYears + toMonth - fromMonth - 1; - } -} - -// Reimplement if special string to integer handling required, e.g. Hebrew. -// Peel a number off the front of a string which may have other trailing chars after the number -// Stop either at either maxLength, eos, or first non-digit char -int KCalendarSystemPrivate::integerFromString(const QString &string, int maxLength, int &readLength) const -{ - int value = -1; - int position = 0; - readLength = 0; - bool ok = false; - - if (maxLength < 0) { - maxLength = string.length(); - } - - while (position < string.length() && - position < maxLength && - string.at(position).isDigit()) { - position++; - } - - if (position > 0) { - value = string.left(position).toInt(&ok); - if (ok) { - readLength = position; - } else { - value = -1; - } - } - - return value; -} - -// Reimplement if special integer to string handling required, e.g. Hebrew. -// Utility to convert an integer into the correct display string form -QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QChar padChar) const -{ - return stringFromInteger(number, padWidth, padChar, q->locale()->dateTimeDigitSet()); -} - -// Reimplement if special integer to string handling required, e.g. Hebrew. -// Utility to convert an integer into the correct display string form -QString KCalendarSystemPrivate::stringFromInteger(int number, int padWidth, QChar padChar, Locale::DigitSet digitSet) const -{ - if (padChar == QLatin1Char('\0') || padWidth == 0) { - return q->locale()->convertDigits(QString::number(number), digitSet); - } else { - return q->locale()->convertDigits(QString::number(number).rightJustified(padWidth, padChar), digitSet); - } -} - -// Allows us to set dates outside publically valid range, USE WITH CARE!!!! -bool KCalendarSystemPrivate::setAnyDate(QDate &date, int year, int month, int day) const -{ - int jd; - q->dateToJulianDay(year, month, day, jd); - date = QDate::fromJulianDay(jd); - return true; -} - -// Utility to correctly add years to a year number because some systems such as -// Julian and Gregorian calendars don't have a year 0 -int KCalendarSystemPrivate::addYears(int originalYear, int addYears) const -{ - int newYear = originalYear + addYears; - - if (!hasYearZero()) { - if (originalYear > 0 && newYear <= 0) { - newYear = newYear - 1; - } else if (originalYear < 0 && newYear >= 0) { - newYear = newYear + 1; - } - } - - return newYear; -} - -// Utility to correctly return number of years between two year numbers because some systems such as -// Julian and Gregorian calendars don't have a year 0 -int KCalendarSystemPrivate::differenceYearNumbers(int fromYear, int toYear) const -{ - int dy = toYear - fromYear; - - if (!hasYearZero()) { - if (toYear > 0 && fromYear < 0) { - dy = dy - 1; - } else if (toYear < 0 && fromYear > 0) { - dy = dy + 1; - } - } - - return dy; -} - -QDate KCalendarSystemPrivate::invalidDate() const -{ - //Is QDate's way of saying is invalid - return QDate(); -} - -QString KCalendarSystemPrivate::simpleDateString(const QString &str) const -{ - QString newStr; - for (int i = 0; i < str.length(); i++) { - if (str.at(i).isLetterOrNumber()) { - newStr.append(str.at(i)); - } else { - newStr.append(QLatin1Char(' ')); - } - } - newStr.simplified(); - return newStr; -} - -int KCalendarSystemPrivate::dayOfYear(const QDate &date) const -{ - int y, m, d, jdFirstDayOfYear; - q->julianDayToDate(date.toJulianDay(), y, m, d); - q->dateToJulianDay(y, 1, 1, jdFirstDayOfYear); - //Take the jd of the given date, and subtract the jd of the first day of that year - return (date.toJulianDay() - jdFirstDayOfYear + 1); -} - -int KCalendarSystemPrivate::dayOfWeek(const QDate &date) const -{ - // Makes assumption that Julian Day 0 was day 1 of week - // This is true for Julian/Gregorian calendar with jd 0 being Monday - // We add 1 for ISO compliant numbering for 7 day week - // Assumes we've never skipped weekdays - return ((date.toJulianDay() % daysInWeek()) + 1); -} - -QDate KCalendarSystemPrivate::firstDayOfYear(int year) const -{ - int jd; - q->dateToJulianDay(year, 1, 1, jd); - return QDate::fromJulianDay(jd); -} - -QDate KCalendarSystemPrivate::lastDayOfYear(int year) const -{ - int jd; - q->dateToJulianDay(year, 1, 1, jd); - jd = jd + daysInYear(year) - 1; - return QDate::fromJulianDay(jd); -} - -QDate KCalendarSystemPrivate::firstDayOfMonth(int year, int month) const -{ - int jd; - q->dateToJulianDay(year, month, 1, jd); - return QDate::fromJulianDay(jd); -} - -QDate KCalendarSystemPrivate::lastDayOfMonth(int year, int month) const -{ - int jd; - q->dateToJulianDay(year, month, 1, jd); - jd = jd + daysInMonth(year, month) - 1; - return QDate::fromJulianDay(jd); -} - -const KLocale * KCalendarSystemPrivate::locale() const -{ - if (m_locale) { - return m_locale; - } else { - return KGlobal::locale(); - } -} - -QList *KCalendarSystemPrivate::eraList() const -{ - return m_eraList; -} - -KCalendarEra KCalendarSystemPrivate::era(const QDate &eraDate) const -{ - for (int i = m_eraList->count() - 1; i >= 0; --i) { - if (m_eraList->at(i).isInEra(eraDate)) { - return m_eraList->at(i); - } - } - return KCalendarEra(); -} - -KCalendarEra KCalendarSystemPrivate::era(const QString &eraName, int yearInEra) const -{ - Q_UNUSED(yearInEra) - - for (int i = m_eraList->count() - 1; i >= 0; --i) { - KCalendarEra era = m_eraList->at(i); - if (era.name(Locale::LongName).toLower() == eraName.toLower() || - era.name(Locale::ShortName).toLower() == eraName.toLower()) { - return era; - } - } - return KCalendarEra(); -} - -void KCalendarSystemPrivate::loadEraList(const KConfigGroup & cg) -{ - delete m_eraList; - m_eraList = new QList; - QString eraKey = QString::fromLatin1("Era1"); - int i = 1; - while (cg.hasKey(eraKey)) { - QString eraEntry = cg.readEntry(eraKey, QString()); - if (!eraEntry.isEmpty()) { - // Based on LC_TIME, but different! - // Includes long and short names, uses ISO fomat dates - // e.g. +:1:0001-01-01:9999-12-31:Anno Domini:AD:%EC %Ey - QChar direction = eraEntry.section(QLatin1Char(':'), 0, 0).at(0); - QDate startDate, endDate; - int startYear; - QString buffer = eraEntry.section(QLatin1Char(':'), 2, 2); - if (buffer.isEmpty()) { - if (direction == QLatin1Char('-')) { - startDate = q->latestValidDate(); - } else { - startDate = q->earliestValidDate(); - } - } else { - startDate = q->readDate(buffer, Locale::IsoFormat); - } - if (q->isValid(startDate)) { - startYear = q->year(startDate); - } else { - startYear = eraEntry.section(QLatin1Char(':'), 1, 1).toInt(); //Use offset - } - - buffer = eraEntry.section(QLatin1Char(':'), 3, 3); - if (buffer.isEmpty()) { - if (direction == QLatin1Char('-')) { - endDate = q->earliestValidDate(); - } else { - endDate = q->latestValidDate(); - } - } else { - endDate = q->readDate(buffer, Locale::IsoFormat); - } - addEra(direction.toLatin1(), eraEntry.section(QLatin1Char(':'), 1, 1).toInt(), - startDate, startYear, endDate, eraEntry.section(QLatin1Char(':'), 4, 4), - eraEntry.section(QLatin1Char(':'), 5, 5), eraEntry.section(QLatin1Char(':'), 6)); - } - ++i; - eraKey = QString::fromLatin1("Era%1").arg(i); - } - - if (m_eraList->isEmpty()) { - loadDefaultEraList(); - } -} - -void KCalendarSystemPrivate::addEra(char direction, int offset, - const QDate &startDate, int startYear, const QDate &endDate, - const QString &name, const QString &shortName, - const QString &format) -{ - KCalendarEra newEra; - - newEra.m_sequence = m_eraList->count() + 1; - if (direction == '-') { - newEra.m_direction = -1; - } else { - newEra.m_direction = 1; - } - newEra.m_offset = offset; - newEra.m_startDate = startDate; - newEra.m_startYear = startYear; - newEra.m_endDate = endDate; - newEra.m_longName = name; - newEra.m_shortName = shortName; - newEra.m_format = format; - - m_eraList->append(newEra); -} - -int KCalendarSystemPrivate::shortYearWindowStartYear() const -{ - return m_shortYearWindowStartYear; -} - -int KCalendarSystemPrivate::applyShortYearWindow(int inputYear) const -{ - if (inputYear >= 0 && inputYear <= 99) { - int shortStartYear = m_shortYearWindowStartYear % 100; - int yearOffset = m_shortYearWindowStartYear - shortStartYear; - if (inputYear >= shortStartYear) { - return inputYear + yearOffset; - } else { - return inputYear + yearOffset + 100; - } - } else { - return inputYear; - } -} - -void KCalendarSystemPrivate::loadShortYearWindowStartYear(const KConfigGroup & cg) -{ - // Default to 2000 for backwards compatibility - // as that's the old readDate() default value - int startYear = 2000; - if (cg.exists()) { - startYear = cg.readEntry("ShortYearWindowStartYear", 2000); - } - m_shortYearWindowStartYear = startYear; -} - -KSharedConfig::Ptr KCalendarSystemPrivate::config() -{ - if (m_config == KSharedConfig::Ptr()) { - return KGlobal::config(); - } else { - return m_config; - } -} - -void KCalendarSystemPrivate::loadConfig(const QString & calendarType) -{ - KConfigGroup localeGroup(config(), QString::fromLatin1("Locale")); - KConfigGroup calendarGroup = localeGroup.group(QString::fromLatin1("KCalendarSystem %1").arg(calendarType)); - loadEraList(calendarGroup); - loadShortYearWindowStartYear(calendarGroup); -} - - -CalendarSystem::KCalendarSystem(const KLocale *locale) - : d_ptr(new KCalendarSystemPrivate(this)) -{ - d_ptr->m_config = KSharedConfig::Ptr(); - d_ptr->m_locale = locale; -} - -CalendarSystem::KCalendarSystem(const KSharedConfig::Ptr config, const KLocale *locale) - : d_ptr(new KCalendarSystemPrivate(this)) -{ - d_ptr->m_config = config; - d_ptr->m_locale = locale; -} - -CalendarSystem::KCalendarSystem(KCalendarSystemPrivate &dd, const KSharedConfig::Ptr config, const KLocale *locale) - : d_ptr(&dd) -{ - d_ptr->m_config = config; - d_ptr->m_locale = locale; -} - -CalendarSystem::~KCalendarSystem() -{ - delete d_ptr; + return (Locale::CalendarSystem)m_calendarSystem->calendarSystem(calendarType); } // NOT VIRTUAL - If override needed use shared-d Locale::CalendarSystem CalendarSystem::calendarSystem() const { - Q_D(const KCalendarSystem); - - return d->calendarSystem(); + return (Locale::CalendarSystem)m_calendarSystem->calendarSystem(); } // NOT VIRTUAL - If override needed use shared-d @@ -1073,7 +134,7 @@ QString CalendarSystem::calendarLabel() const // This method MUST be re-implemented in any new Calendar System QDate CalendarSystem::epoch() const { - return QDate::fromJulianDay(38); + return m_calendarSystem->epoch(); } QDate CalendarSystem::earliestValidDate() const @@ -1086,296 +147,110 @@ QDate CalendarSystem::earliestValidDate() const QDate CalendarSystem::latestValidDate() const { // Default to Gregorian 9999-12-31 - return QDate::fromJulianDay(5373484); + return m_calendarSystem->latestValidDate(); } bool CalendarSystem::isValid(int year, int month, int day) const { - Q_D(const KCalendarSystem); - - if (year < d->earliestValidYear() || year > d->latestValidYear() || - (!d->hasYearZero() && year == 0)) { - return false; - } - - if (month < 1 || month > d->monthsInYear(year)) { - return false; - } - - if (day < 1 || day > d->daysInMonth(year, month)) { - return false; - } - - return true; + return m_calendarSystem->isValid(year, month, day); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::isValid(int year, int dayOfYear) const { - Q_D(const KCalendarSystem); - - return (isValid(year, 1, 1) && dayOfYear > 0 && dayOfYear <= d->daysInYear(year)); + return m_calendarSystem->isValid(year, dayOfYear); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::isValid(const QString &eraName, int yearInEra, int month, int day) const { - Q_D(const KCalendarSystem); - - KCalendarEra era = d->era(eraName, yearInEra); - return (era.isValid() && isValid(era.year(yearInEra), month, day)); + return m_calendarSystem->isValid(eraName, yearInEra, month, day); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const { - Q_D(const KCalendarSystem); - - //Tests Year value in standard YMD isValid() - if (!isValid(year, 1, 1)) { - return false; - } - - //Test Week Number falls in valid range for this year - int weeksInThisYear = weeksInYear(year); - if (isoWeekNumber < 1 || isoWeekNumber > weeksInThisYear) { - return false; - } - - //Test Day of Week Number falls in valid range - if (dayOfIsoWeek < 1 || dayOfIsoWeek > d->daysInWeek()) { - return false; - } - - //If not in earliest or latest years then all OK - //Otherwise need to check don't fall into previous or next year that would be invalid - if (year == d->earliestValidYear() && isoWeekNumber == 1) { - //If firstDayOfYear falls on or before Thursday then firstDayOfYear falls in week 1 this - //year and if wanted dayOfIsoWeek falls before firstDayOfYear then falls in previous year - //and so in invalid year - int dowFirstDay = dayOfWeek(d->firstDayOfYear(year)); - if (dowFirstDay <= 4 && dayOfIsoWeek < dowFirstDay) { - return false; - } - } else if (year == d->latestValidYear() && isoWeekNumber == weeksInThisYear) { - //If lastDayOfYear falls on or after Thursday then lastDayOfYear falls in last week this - //year and if wanted dayOfIsoWeek falls after lastDayOfYear then falls in next year - //and so in invalid year - int dowLastDay = dayOfWeek(d->lastDayOfYear(year)); - if (dowLastDay >= 4 && dayOfIsoWeek > dowLastDay) { - return false; - } - } - - return true; + return m_calendarSystem->isValidIsoWeekDate(year, isoWeekNumber, dayOfIsoWeek); } bool CalendarSystem::isValid(const QDate &date) const { - if (date.isNull() || date < earliestValidDate() || date > latestValidDate()) { - return false; - } - return true; + return m_calendarSystem->isValid(date); } bool CalendarSystem::setDate(QDate &date, int year, int month, int day) const { - Q_D(const KCalendarSystem); - - date = d->invalidDate(); - - if (isValid(year, month, day)) { - int jd; - dateToJulianDay(year, month, day, jd); - QDate calcDate = QDate::fromJulianDay(jd); - - if (isValid(calcDate)) { - date = calcDate; - return true; - } - } - - return false; + return m_calendarSystem->setDate(date, year, month, day); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::setDate(QDate &date, int year, int dayOfYear) const { - Q_D(const KCalendarSystem); - - date = d->invalidDate(); - - if (isValid(year, dayOfYear)) { - int jd; - dateToJulianDay(year, 1, 1, jd); - QDate calcDate = QDate::fromJulianDay(jd + dayOfYear - 1); - if (isValid(calcDate)) { - date = calcDate; - return true; - } - } - - return false; + return m_calendarSystem->setDate(date, year, dayOfYear); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const { - Q_D(const KCalendarSystem); - - KCalendarEra era = d->era(eraName, yearInEra); - return (era.isValid() && setDate(date, era.year(yearInEra), month, day)); + return m_calendarSystem->setDate(date, eraName, yearInEra, month, day); } // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const { - Q_D(const KCalendarSystem); - - date = d->invalidDate(); - - if (isValidIsoWeekDate(year, isoWeekNumber, dayOfIsoWeek)) { - - QDate calcDate = d->firstDayOfYear(year); - int dowFirstDayOfYear = dayOfWeek(calcDate); - - int daysToAdd = (d->daysInWeek() * (isoWeekNumber - 1)) + dayOfIsoWeek; - - if (dowFirstDayOfYear <= 4) { - calcDate = calcDate.addDays(daysToAdd - dowFirstDayOfYear); - } else { - calcDate = calcDate.addDays(daysInWeek(calcDate) + daysToAdd - dowFirstDayOfYear); - } - - if (isValid(calcDate)) { - date = calcDate; - return true; - } - } - - return false; -} - -// Deprecated -bool CalendarSystem::setYMD(QDate &date, int year, int month, int day) const -{ - return setDate(date, year, month, day); + m_calendarSystem->setDateIsoWeek(date, year, isoWeekNumber, dayOfIsoWeek); } // NOT VIRTUAL - If override needed use shared-d void CalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const { - int y, m, d; - - if (isValid(date)) { - julianDayToDate(date.toJulianDay(), y, m, d); - } else { - y = 0; // How do you denote invalid year when we support -ve years? - m = 0; - d = 0; - } - - if (year) { - *year = y; - } - if (month) { - *month = m; - } - if (day) { - *day = d; - } - + return m_calendarSystem->getDate(date, year, month, day); } int CalendarSystem::year(const QDate &date) const { - if (isValid(date)) { - int year, month, day; - - julianDayToDate(date.toJulianDay(), year, month, day); - - return year; - } - - return 0; // How do you denote invalid year when we support -ve years? + return m_calendarSystem->year(date); } int CalendarSystem::month(const QDate &date) const { - if (isValid(date)) { - int year, month, day; - - julianDayToDate(date.toJulianDay(), year, month, day); - - return month; - } - - return 0; + return m_calendarSystem->month(date); } int CalendarSystem::day(const QDate &date) const { - if (isValid(date)) { - int year, month, day; - - julianDayToDate(date.toJulianDay(), year, month, day); - - return day; - } - - return 0; + return m_calendarSystem->day(date); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::eraName(const QDate &date, StringFormat format) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - if (format == LongFormat) { - return d->era(date).name(Locale::LongName); - } else { - return d->era(date).name(Locale::ShortName); - } - } - - return QString(); + return m_calendarSystem->eraName(date, format); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::eraYear(const QDate &date, StringFormat format) const { - Q_UNUSED(format) - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return formatDate(date, d->era(date).format()); - } - - return QString(); + return m_calendarSystem->eraYear(date, format); } // NOT VIRTUAL - If override needed use shared-d int CalendarSystem::yearInEra(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->era(date).yearInEra(year(date)); - } - - return -1; + return m_calendarSystem->yearInEra(date); } // NOT VIRTUAL - If override needed use shared-d -QList *CalendarSystem::eraList() const +//FIXME we need a wrapper for KCalendarEra!! +/*QList *CalendarSystem::eraList() const { Q_D(const KCalendarSystem); return d->eraList(); -} +}*/ // NOT VIRTUAL - If override needed use shared-d +/*FIXME we don't need the above.Correct? KCalendarEra CalendarSystem::era(const QDate &eraDate) const { Q_D(const KCalendarSystem); @@ -1390,156 +265,56 @@ KCalendarEra CalendarSystem::era(const QString &eraName, int yearInEra) const return d->era(eraName, yearInEra); } - +*/ QDate CalendarSystem::addYears(const QDate &date, int numYears) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - - int originalYear, originalMonth, originalDay; - julianDayToDate(date.toJulianDay(), originalYear, originalMonth, originalDay); - - int newYear = d->addYears(originalYear, numYears); - int newMonth = originalMonth; - int newDay = originalDay; - - //Adjust day number if new month has fewer days than old month - int daysInNewMonth = d->daysInMonth(newYear, newMonth); - if (daysInNewMonth < originalDay) { - newDay = daysInNewMonth; - } - - QDate newDate; - setDate(newDate, newYear, newMonth, newDay); - return newDate; - - } - - return d->invalidDate(); + return m_calendarSystem->addYears(date, numYears); } QDate CalendarSystem::addMonths(const QDate &date, int numMonths) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - - int originalYear, originalMonth, originalDay; - julianDayToDate(date.toJulianDay(), originalYear, originalMonth, originalDay); - - int monthsInOriginalYear = d->monthsInYear(originalYear); - - int newYear = d->addYears(originalYear, (originalMonth + numMonths) / monthsInOriginalYear); - int newMonth = (originalMonth + numMonths) % monthsInOriginalYear; - int newDay = originalDay; - - if (newMonth == 0) { - newYear = d->addYears(newYear, - 1); - newMonth = monthsInOriginalYear; - } - if (newMonth < 0) { - newYear = d->addYears(newYear, - 1); - newMonth = newMonth + monthsInOriginalYear; - } - - //Adjust day number if new month has fewer days than old month - int daysInNewMonth = d->daysInMonth(newYear, newMonth); - if (daysInNewMonth < originalDay) { - newDay = daysInNewMonth; - } - - QDate newDate; - setDate(newDate, newYear, newMonth, newDay); - return newDate; - - } - - return d->invalidDate(); + return m_calendarSystem->addMonths(date, numMonths); } QDate CalendarSystem::addDays(const QDate &date, int numDays) const { - Q_D(const KCalendarSystem); - - // QDate only holds a uint and has no boundary checking in addDays(), so we need to check - if (isValid(date) && (long) date.toJulianDay() + (long) numDays > 0) { - // QDate adds straight to jd - QDate temp = date.addDays(numDays); - if (isValid(temp)) { - return temp; - } - } - - return d->invalidDate(); + return m_calendarSystem->addDays(date, numDays); } // NOT VIRTUAL - Uses shared-d instead void CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate, int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const { - Q_D(const KCalendarSystem); - - if (isValid(fromDate) && isValid(toDate)) { - d->dateDifference(fromDate, toDate, yearsDiff, monthsDiff, daysDiff, direction); - } + return m_calendarSystem->dateDifference(fromDate, toDate, yearsDiff, monthsDiff, daysDiff, direction); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const { - Q_D(const KCalendarSystem); - - if (isValid(fromDate) && isValid(toDate)) { - return d->yearsDifference(fromDate, toDate); - } - - return 0; + return m_calendarSystem->yearsDifference(fromDate, toDate); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::monthsDifference(const QDate &fromDate, const QDate &toDate) const { - Q_D(const KCalendarSystem); - - if (isValid(fromDate) && isValid(toDate)) { - return d->monthsDifference(fromDate, toDate); - } - - return 0; + return m_calendarSystem->monthsDifference(fromDate, toDate); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) const { - if (isValid(fromDate) && isValid(toDate)) { - return toDate.toJulianDay() - fromDate.toJulianDay(); - } - - return 0; + return m_calendarSystem->daysDifference(fromDate, toDate); } int CalendarSystem::monthsInYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->monthsInYear(year(date)); - } - - return -1; + return m_calendarSystem->monthsInYear(date); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::monthsInYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->monthsInYear(year); - } - - return -1; + return m_calendarSystem->monthsInYear(year); } int CalendarSystem::weeksInYear(const QDate &date) const @@ -1555,102 +330,50 @@ int CalendarSystem::weeksInYear(int year) const // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::weeksInYear(const QDate &date, Locale::WeekNumberSystem weekNumberSystem) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->weeksInYear(year(date), weekNumberSystem); - } - - return -1; + return m_calendarSystem->weeksInYear(date, (KLocale::WeekNumberSystem)weekNumberSystem); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->weeksInYear(year, weekNumberSystem); - } - - return -1; + return m_calendarSystem->weeksInYear(year, (KLocale::WeekNumberSystem)weekNumberSystem); } int CalendarSystem::daysInYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->daysInYear(year(date)); - } - - return -1; + return m_calendarSystem->daysInYear(date); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysInYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->daysInYear(year); - } - - return -1; + return m_calendarSystem->daysInYear(year); } int CalendarSystem::daysInMonth(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - int year, month; - getDate(date, &year, &month, 0); - return d->daysInMonth(year, month); - } - - return -1; + return m_calendarSystem->daysInMonth(date); } // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysInMonth(int year, int month) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->daysInMonth(year, month); - } - - return -1; + return m_calendarSystem->daysInMonth(year, month); } int CalendarSystem::daysInWeek(const QDate &date) const { - Q_UNUSED(date) - Q_D(const KCalendarSystem); - return d->daysInWeek(); + return m_calendarSystem->daysInWeek(); } int CalendarSystem::dayOfYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->dayOfYear(date); - } - - return -1; + return m_calendarSystem->dayOfYear(date); } int CalendarSystem::dayOfWeek(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->dayOfWeek(date); - } - - return -1; + return m_calendarSystem->dayOfWeek(date); } int CalendarSystem::weekNumber(const QDate &date, int *yearNum) const @@ -1667,407 +390,105 @@ int CalendarSystem::week(const QDate &date, int *yearNum) const // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->week(date, weekNumberSystem, yearNum); - } - - return -1; + return m_calendarSystem->week(date, (KLocale::WeekNumberSystem)weekNumberSystem, yearNum); } bool CalendarSystem::isLeapYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->isLeapYear(year); - } - - return false; + return m_calendarSystem->isLeapYear(year); } bool CalendarSystem::isLeapYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->isLeapYear(year(date)); - } - - return false; + return m_calendarSystem->isLeapYear(date); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->firstDayOfYear(year); - } - - return QDate(); + return m_calendarSystem->firstDayOfYear(year); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfYear(int year) const { - Q_D(const KCalendarSystem); - - if (isValid(year, 1, 1)) { - return d->lastDayOfYear(year); - } - - return QDate(); + return m_calendarSystem->lastDayOfYear(year); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->firstDayOfYear(year(date)); - } - - return QDate(); + return m_calendarSystem->firstDayOfYear(date); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfYear(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - return d->lastDayOfYear(year(date)); - } - - return QDate(); + return m_calendarSystem->lastDayOfYear(date); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfMonth(int year, int month) const { - Q_D(const KCalendarSystem); - - if (isValid(year, month, 1)) { - return d->firstDayOfMonth(year, month); - } - - return QDate(); + return m_calendarSystem->firstDayOfMonth(year, month); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfMonth(int year, int month) const { - Q_D(const KCalendarSystem); - - if (isValid(year, month, 1)) { - return d->lastDayOfMonth(year, month); - } - - return QDate(); + return m_calendarSystem->lastDayOfMonth(year, month); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfMonth(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - int year, month; - getDate(date, &year, &month, 0); - return d->firstDayOfMonth(year, month); - } - - return QDate(); + return m_calendarSystem->firstDayOfMonth(date); } // NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfMonth(const QDate &date) const { - Q_D(const KCalendarSystem); - - if (isValid(date)) { - int year, month; - getDate(date, &year, &month, 0); - return d->lastDayOfMonth(year, month); - } - - return QDate(); + return m_calendarSystem->lastDayOfMonth(date); } QString CalendarSystem::monthName(int month, int year, CalendarSystem::MonthNameFormat format) const { - Q_D(const KCalendarSystem); - - if (!isValid(year, month, 1)) { - return QString(); - } - - if (format == CalendarSystem::NarrowName) { - return d->monthName(month, year, Locale::NarrowName, false); - } - - if (format == CalendarSystem::ShortNamePossessive) { - return d->monthName(month, year, Locale::ShortName, true); - } - - if (format == CalendarSystem::ShortName) { - return d->monthName(month, year, Locale::ShortName, false); - } - - if (format == CalendarSystem::LongNamePossessive) { - return d->monthName(month, year, Locale::LongName, true); - } - - // CalendarSystem::LongName or any other - return d->monthName(month, year, Locale::LongName, false); + return m_calendarSystem->monthName(month, year, (KCalendarSystem::MonthNameFormat)format); } QString CalendarSystem::monthName(const QDate &date, MonthNameFormat format) const { - if (isValid(date)) { - int year, month; - getDate(date, &year, &month, 0); - return monthName(month, year, format); - } - - return QString(); + return m_calendarSystem->monthName(date, (KCalendarSystem::MonthNameFormat)format); } QString CalendarSystem::weekDayName(int weekDay, CalendarSystem::WeekDayNameFormat format) const { - Q_D(const KCalendarSystem); - - if (weekDay < 1 || weekDay > d->daysInWeek()) { - return QString(); - } - - if (format == CalendarSystem::NarrowDayName) { - return d->weekDayName(weekDay, Locale::NarrowName); - } - - if (format == CalendarSystem::ShortDayName) { - return d->weekDayName(weekDay, Locale::ShortName); - } - - if (format == CalendarSystem::ShortDayName) { - return d->weekDayName(weekDay, Locale::ShortName); - } - - return d->weekDayName(weekDay, Locale::LongName); + return m_calendarSystem->weekDayName(weekDay, (KCalendarSystem::WeekDayNameFormat)format); } QString CalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format) const { - if (isValid(date)) { - return weekDayName(dayOfWeek(date), format); - } - - return QString(); -} - -QString CalendarSystem::yearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::Year, Locale::ShortNumber); - } else { - return formatDate(date, Locale::Year, Locale::LongNumber); - } -} - -QString CalendarSystem::monthString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::Month, Locale::ShortNumber); - } else { - return formatDate(date, Locale::Month, Locale::LongNumber); - } -} - -QString CalendarSystem::dayString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::Day, Locale::ShortNumber); - } else { - return formatDate(date, Locale::Day, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::yearInEraString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::YearInEra, Locale::ShortNumber); - } else { - return formatDate(date, Locale::YearInEra, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::dayOfYearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::DayOfYear, Locale::ShortNumber); - } else { - return formatDate(date, Locale::DayOfYear, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::dayOfWeekString(const QDate &date) const -{ - return formatDate(date, Locale::DayOfWeek, Locale::ShortNumber); -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::weekNumberString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::Week, Locale::ShortNumber); - } else { - return formatDate(date, Locale::Week, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::monthsInYearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::MonthsInYear, Locale::ShortNumber); - } else { - return formatDate(date, Locale::MonthsInYear, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::weeksInYearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::WeeksInYear, Locale::ShortNumber); - } else { - return formatDate(date, Locale::WeeksInYear, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::daysInYearString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::DaysInYear, Locale::ShortNumber); - } else { - return formatDate(date, Locale::DaysInYear, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::daysInMonthString(const QDate &date, StringFormat format) const -{ - if (format == ShortFormat) { - return formatDate(date, Locale::DaysInMonth, Locale::ShortNumber); - } else { - return formatDate(date, Locale::DaysInMonth, Locale::LongNumber); - } -} - -// NOT VIRTUAL - If override needed use shared-d -QString CalendarSystem::daysInWeekString(const QDate &date) const -{ - return formatDate(date, Locale::DaysInWeek, Locale::ShortNumber); -} - -int CalendarSystem::yearStringToInteger(const QString &yearString, int &readLength) const -{ - Q_D(const KCalendarSystem); - - QString minus = i18nc("Negative symbol as used for year numbers, e.g. -5 = 5 BC", "-"); - if (yearString.startsWith(minus)) { - int value = d->integerFromString(yearString.mid(minus.length()), 4, readLength); - if (readLength > 0 && value >= 0) { - readLength = readLength + minus.length(); - return value * -1; - } else { - return value; - } - } - - return d->integerFromString(yearString, 4, readLength); -} - -int CalendarSystem::monthStringToInteger(const QString &monthString, int &readLength) const -{ - Q_D(const KCalendarSystem); - return d->integerFromString(monthString, 2, readLength); -} - -int CalendarSystem::dayStringToInteger(const QString &dayString, int &readLength) const -{ - Q_D(const KCalendarSystem); - return d->integerFromString(dayString, 2, readLength); + return m_calendarSystem->weekDayName(date, (KCalendarSystem::WeekDayNameFormat)format); } QString CalendarSystem::formatDate(const QDate &fromDate, Locale::DateFormat toFormat) const { - if (!fromDate.isValid()) { - return QString(); - } - - if (toFormat == Locale::FancyShortDate || toFormat == Locale::FancyLongDate) { - QDate now = KDateTime::currentLocalDate(); - int daysToNow = fromDate.daysTo(now); - switch (daysToNow) { - case 0: - return i18n("Today"); - case 1: - return i18n("Yesterday"); - case 2: - case 3: - case 4: - case 5: - case 6: - return weekDayName(fromDate); - default: - break; - } - } - - switch (toFormat) { - case Locale::LongDate: - case Locale::FancyLongDate: - return formatDate(fromDate, locale()->dateFormat()); - case Locale::IsoDate: - return formatDate(fromDate, QLatin1String("%Y-%m-%d")); - case Locale::IsoWeekDate: - return formatDate(fromDate, QLatin1String("%Y-W%V-%u")); - case Locale::IsoOrdinalDate: - return formatDate(fromDate, QLatin1String("%Y-%j")); - case Locale::ShortDate: - case Locale::FancyShortDate: - default: - return formatDate(fromDate, locale()->dateFormatShort()); - } - + return m_calendarSystem->formatDate(fromDate, (KLocale::DateFormat)toFormat); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DateTimeFormatStandard standard) const { - return formatDate(fromDate, toFormat, locale()->dateTimeDigitSet(), standard); + return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DateTimeFormatStandard)standar); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DigitSet digitSet, Locale::DateTimeFormatStandard formatStandard) const { - if (!isValid(fromDate) || toFormat.isEmpty()) { - return QString(); - } - - KDateTimeFormatter formatter; - return formatter.formatDate(fromDate, toFormat, this, locale(), digitSet, formatStandard); + return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DigitSet)digitSet, + (KLocale::DateTimeFormatStandard)formatStandard); } // NOT VIRTUAL - If override needed use shared-d @@ -2075,261 +496,19 @@ QString CalendarSystem::formatDate(const QDate &date, Locale::DateTimeComponent Locale::DateTimeComponentFormat format, Locale::WeekNumberSystem weekNumberSystem) const { - Q_D(const KCalendarSystem); - - switch (component) { - case Locale::Year: - case Locale::YearName: - switch (format) { - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - return formatDate(date, QLatin1String("%y")); - case Locale::LongNumber: - case Locale::LongName: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%Y")); - } - case Locale::Month: - switch (format) { - case Locale::LongName: - return monthName(date, CalendarSystem::LongName); - case Locale::ShortName: - return monthName(date, CalendarSystem::ShortName); - case Locale::NarrowName: - return monthName(date, CalendarSystem::NarrowName); - case Locale::LongNumber: - return formatDate(date, QLatin1String("%m")); - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%n")); - } - case Locale::MonthName: - switch (format) { - case Locale::NarrowName: - return monthName(date, CalendarSystem::NarrowName); - case Locale::ShortName: - case Locale::ShortNumber: - return monthName(date, CalendarSystem::ShortName); - case Locale::LongName: - case Locale::LongNumber: - case Locale::DefaultComponentFormat: - default: - return monthName(date, CalendarSystem::LongName); - } - case Locale::Day: - case Locale::DayName: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return formatDate(date, QLatin1String("%d")); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%e")); - } - case Locale::JulianDay: - return d->stringFromInteger(date.toJulianDay(), 0); - case Locale::EraName: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return eraName(date, CalendarSystem::LongFormat); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return eraName(date, CalendarSystem::ShortFormat); - } - case Locale::EraYear: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return eraYear(date, CalendarSystem::LongFormat); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return eraYear(date, CalendarSystem::ShortFormat); - } - case Locale::YearInEra: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return formatDate(date, QLatin1String("%4Ey")); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%Ey")); - } - case Locale::DayOfYear: - case Locale::DayOfYearName: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return formatDate(date, QLatin1String("%j")); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%-j")); - } - case Locale::DayOfWeek: - switch (format) { - case Locale::LongName: - return weekDayName(date, CalendarSystem::LongDayName); - case Locale::ShortName: - return weekDayName(date, CalendarSystem::ShortDayName); - case Locale::NarrowName: - return weekDayName(date, CalendarSystem::NarrowDayName); - case Locale::LongNumber: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return formatDate(date, QLatin1String("%-u")); - } - case Locale::DayOfWeekName: - switch (format) { - case Locale::NarrowName: - return weekDayName(date, CalendarSystem::NarrowDayName); - case Locale::ShortName: - case Locale::ShortNumber: - return weekDayName(date, CalendarSystem::ShortDayName); - case Locale::LongName: - case Locale::LongNumber: - case Locale::DefaultComponentFormat: - default: - return weekDayName(date, CalendarSystem::LongDayName); - } - case Locale::Week: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(week(date, weekNumberSystem, 0), 2, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(week(date, weekNumberSystem, 0), 0, QLatin1Char('0')); - } - case Locale::WeekYear: { - int weekYear; - QDate yearDate; - week(date, weekNumberSystem, &weekYear); - setDate(yearDate, weekYear, 1, 1); - return formatDate(yearDate, Locale::Year, format); - } - case Locale::MonthsInYear: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(monthsInYear(date), 2, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(monthsInYear(date), 0, QLatin1Char('0')); - } - case Locale::WeeksInYear: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(weeksInYear(date), 2, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(weeksInYear(date), 0, QLatin1Char('0')); - } - case Locale::DaysInYear: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(daysInYear(date), 3, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(daysInYear(date), 0, QLatin1Char('0')); - } - case Locale::DaysInMonth: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - return d->stringFromInteger(daysInMonth(date), 2, QLatin1Char('0')); - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(daysInMonth(date), 0, QLatin1Char('0')); - } - case Locale::DaysInWeek: - switch (format) { - case Locale::LongNumber: - case Locale::LongName: - case Locale::ShortName: - case Locale::NarrowName: - case Locale::ShortNumber: - case Locale::DefaultComponentFormat: - default: - return d->stringFromInteger(d->daysInWeek(), 0); - } - default: - return QString(); - } + return m_calendarSystem->formatDate(date, (KLocale::DateTimeComponent)component, + (KLocale::DateTimeComponentFormat)format, + (KLocale::WeekNumberSystem)weekNumberSystem); } QDate CalendarSystem::readDate(const QString &str, bool *ok) const { - //Try each standard format in turn, start with the locale ones, - //then the well defined standards - QDate date = readDate(str, Locale::ShortFormat, ok); - if (!isValid(date)) { - date = readDate(str, Locale::NormalFormat, ok); - if (!isValid(date)) { - date = readDate(str, Locale::IsoFormat, ok); - if (!isValid(date)) { - date = readDate(str, Locale::IsoWeekFormat, ok); - if (!isValid(date)) { - date = readDate(str, Locale::IsoOrdinalFormat, ok); - } - } - } - } - - return date; + return m_calendarSystem->readDate(str, ok); } QDate CalendarSystem::readDate(const QString &str, Locale::ReadDateFlags flags, bool *ok) const { - Q_D(const KCalendarSystem); - - if (flags & Locale::ShortFormat) { - return readDate(str, locale()->dateFormatShort(), ok); - } else if (flags & Locale::NormalFormat) { - return readDate(str, locale()->dateFormat(), ok); - } else if (flags & Locale::IsoFormat) { - return readDate(str, QLatin1String("%Y-%m-%d"), ok); - } else if (flags & Locale::IsoWeekFormat) { - return readDate(str, QLatin1String("%Y-W%V-%u"), ok); - } else if (flags & Locale::IsoOrdinalFormat) { - return readDate(str, QLatin1String("%Y-%j"), ok); - } - return d->invalidDate(); + return m_calendarSystem->readDate(str, (KLocale::ReadDateFlags)flags, ok); } QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok) const @@ -2341,33 +520,25 @@ QDate CalendarSystem::readDate(const QString &inputString, const QString &format QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok, Locale::DateTimeFormatStandard formatStandard) const { - KDateTimeParser parser; - QDate resultDate = parser.parseDate(inputString, formatString, this, locale(), locale()->dateTimeDigitSet(), formatStandard); - if (ok) { - *ok = resultDate.isValid(); - } - return resultDate; + return m_calendarSystem->readDate(inputString, formatString, ok, + (KLocale::DateTimeFormatStandard)formatStandard); } // NOT VIRTUAL - If override needed use shared-d int CalendarSystem::shortYearWindowStartYear() const { - Q_D(const KCalendarSystem); - - return d->shortYearWindowStartYear(); + return m_calendarSystem->shortYearWindowStartYear(); } // NOT VIRTUAL - If override needed use shared-d int CalendarSystem::applyShortYearWindow(int inputYear) const { - Q_D(const KCalendarSystem); - - return d->applyShortYearWindow(inputYear); + return m_calendarSystem->applyShortYearWindow(inputYear); } int CalendarSystem::weekStartDay() const { - return locale()->weekStartDay(); + return m_calendarSystem->weekStartDay(); } // Dummy version using Gregorian as an example @@ -2378,28 +549,7 @@ int CalendarSystem::weekStartDay() const // are required for internal maths bool CalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) const { - // Formula from The Calendar FAQ by Claus Tondering - // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000 - // NOTE: Coded from scratch from mathematical formulas, not copied from - // the Boost licensed source code - - int a = jd + 32044; - int b = ((4 * a) + 3) / 146097; - int c = a - ((146097 * b) / 4); - int d = ((4 * c) + 3) / 1461; - int e = c - ((1461 * d) / 4); - int m = ((5 * e) + 2) / 153; - day = e - (((153 * m) + 2) / 5) + 1; - month = m + 3 - (12 * (m / 10)); - year = (100 * b) + d - 4800 + (m / 10); - - // If year is -ve then is BC. In Gregorian there is no year 0, but the maths - // is easier if we pretend there is, so internally year of 0 = 1BC = -1 outside - if (year < 1) { - year = year - 1; - } - - return true; + return m_calendarSystem->julianDayToDate(jd, year, month, day); } // Dummy version using Gregorian as an example @@ -2410,56 +560,13 @@ bool CalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) co // are required for internal maths bool CalendarSystem::dateToJulianDay(int year, int month, int day, int &jd) const { - // Formula from The Calendar FAQ by Claus Tondering - // http://www.tondering.dk/claus/cal/node3.html#SECTION003161000000000000000 - // NOTE: Coded from scratch from mathematical formulas, not copied from - // the Boost licensed source code - - // If year is -ve then is BC. In Gregorian there is no year 0, but the maths - // is easier if we pretend there is, so internally year of -1 = 1BC = 0 internally - int y; - if (year < 1) { - y = year + 1; - } else { - y = year; - } - - int a = (14 - month) / 12; - y = y + 4800 - a; - int m = month + (12 * a) - 3; - - jd = day - + (((153 * m) + 2) / 5) - + (365 * y) - + (y / 4) - - (y / 100) - + (y / 400) - - 32045; - - return true; + return m_calendarSystem->dateToJulianDay(year, month, day, jd); } -const KLocale * CalendarSystem::locale() const +//FIXME what should I do with the above one? +/*const KLocale * CalendarSystem::locale() const { Q_D(const KCalendarSystem); return d->locale(); -} - -// Deprecated -void CalendarSystem::setMaxMonthsInYear(int maxMonths) -{ - Q_UNUSED(maxMonths) -} - -// Deprecated -void CalendarSystem::setMaxDaysInWeek(int maxDays) -{ - Q_UNUSED(maxDays) -} - -// Deprecated -void CalendarSystem::setHasYear0(bool hasYear0) -{ - Q_UNUSED(hasYear0) -} +}*/ From 825af7c0ca366d1ceee3f35d67c2abe00b2ca1a1 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 9 Feb 2012 19:27:48 +0200 Subject: [PATCH 027/104] Add Q_DECLARE_OPERATORS_FOR_FLAGS --- declarativeimports/locale/locale.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 37c1ec94b..c13c175ed 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -22,6 +22,7 @@ #include #include +#include class QStringList; class QTextCodec; @@ -2018,4 +2019,8 @@ Q_SIGNALS: void workingWeekStartDayChanged(); }; +Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) +Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::TimeFormatOptions) +Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::TimeProcessingOptions) + #endif From cca571f430955766d6ed08542aeeb2f1fbce6873 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Fri, 10 Feb 2012 16:04:57 +0200 Subject: [PATCH 028/104] Add some TODO and fix the enums --- declarativeimports/locale/locale.cpp | 16 ++++++++-------- declarativeimports/locale/locale.h | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 8181dc1be..dcfd076f0 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -346,17 +346,15 @@ QTime Locale::readTime(const QString &intstr, bool *ok) const QTime Locale::readLocaleTime(const QString &intstr, bool *ok, TimeFormatOptions options, TimeProcessingOptions processing) const { - return m_locale->readLocaleTime(intstr, ok, (KLocale::TimeFormatOptions)options, (KLocale::TimeProcessingOptions)processing); -} - -QString Locale::formatTime(const QTime &time, bool includeSecs, bool isDuration) const -{ - return m_locale->formatTime(time, includeSecs, isDuration); + Q_UNUSED(options) + Q_UNUSED(processing) + return m_locale->readLocaleTime(intstr, ok); } QString Locale::formatLocaleTime(const QTime &time, TimeFormatOptions options) const { - return m_locale->formatLocaleTime(time, (KLocale::TimeFormatOptions)options); + Q_UNUSED(options) + return m_locale->formatLocaleTime(time); } bool Locale::use12Clock() const @@ -393,7 +391,9 @@ QString Locale::formatDateTime(const QDateTime &dateTime, Locale::DateFormat for QString Locale::formatDateTime(const KDateTime &dateTime, Locale::DateFormat format, DateTimeFormatOptions options) const { - return m_locale->formatDateTime(dateTime, (KLocale::DateFormat)format, (KLocale::DateTimeFormatOptions)options); + Q_UNUSED(format) + Q_UNUSED(options) + return m_locale->formatDateTime(dateTime); } void Locale::setDateFormat(const QString &format) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index c13c175ed..7c4610554 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -22,18 +22,17 @@ #include #include -#include -class QStringList; +class QString; +class QStringList; //TODO will the QStringList invokable methods work in QML? class QTextCodec; class QDate; class QTime; class QDateTime; -class KDateTime; -class KCalendarSystem; -class KCurrencyCode; -//class KDayPeriod; +class KDateTime; //TODO will this work? +class KCalendarSystem;//TODO make it calendarSystem??? +class KCurrencyCode;//TODO will this work? /** * \file klocale.h @@ -1358,6 +1357,7 @@ public: * @see encoding * @see encodingMib */ + //TODO will this work? Q_INVOKABLE QTextCodec *codecForEncoding() const; /** @@ -2018,9 +2018,9 @@ Q_SIGNALS: void workingWeekEndDayChanged(); void workingWeekStartDayChanged(); }; - -Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) -Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::TimeFormatOptions) -Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::TimeProcessingOptions) +//TODO remove the above? +//Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) +//Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::TimeFormatOptions) +//Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::TimeProcessingOptions) #endif From 22cf25386a5776318b605ef3d4d500a96eaa2b0b Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Fri, 10 Feb 2012 22:31:00 +0200 Subject: [PATCH 029/104] fix the includes --- declarativeimports/locale/calendarsystem.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index a7ca3d660..55010057f 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -24,22 +24,7 @@ #include -#include "kdatetime.h" -#include "kdatetimeformatter_p.h" -#include "kdatetimeparser_p.h" -#include "kcalendarera_p.h" -#include "kcalendarsystemcoptic_p.h" -#include "kcalendarsystemethiopian_p.h" -#include "kcalendarsystemgregorian_p.h" -#include "kcalendarsystemhebrew_p.h" -#include "kcalendarsystemindiannational_p.h" -#include "kcalendarsystemislamiccivil_p.h" -#include "kcalendarsystemjalali_p.h" -#include "kcalendarsystemjapanese_p.h" -#include "kcalendarsystemjulian_p.h" -#include "kcalendarsystemminguo_p.h" -#include "kcalendarsystemqdate_p.h" -#include "kcalendarsystemthai_p.h" +#include //FIXME fix all the create static methods KCalendarSystem *CalendarSystem::create(const QString &calendarType, const KLocale *locale) From 399bd464db61adaa9f4dbfbe9449b62426cac0db Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 12 Feb 2012 15:51:55 +0200 Subject: [PATCH 030/104] remove unnecessary code --- declarativeimports/locale/calendarsystem.cpp | 73 ++++---------------- declarativeimports/locale/calendarsystem.h | 57 ++------------- 2 files changed, 17 insertions(+), 113 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 55010057f..5d3ecd358 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -21,86 +21,39 @@ #include "kdebug.h" #include "kconfiggroup.h" +#include #include #include //FIXME fix all the create static methods -KCalendarSystem *CalendarSystem::create(const QString &calendarType, const KLocale *locale) -{ - return create(calendarSystem(calendarType), locale); -} - -KCalendarSystem *CalendarSystem::create(const QString &calendarType, KSharedConfig::Ptr config, - const KLocale *locale) -{ - return create(calendarSystem(calendarType), config, locale); -} - -QString CalendarSystem::calendarLabel(const QString &calendarType) -{ - return m_calendarSystem->calendarLabel(calendarType); -} - -KCalendarSystem *CalendarSystem::create(Locale::CalendarSystem calendarSystem, const KLocale *locale) -{ - return create(calendarSystem, KSharedConfig::Ptr(), locale); -} - -KCalendarSystem *CalendarSystem::create(Locale::CalendarSystem calendarSystem, - KSharedConfig::Ptr config, - const KLocale *locale) -{ - switch (calendarSystem) { - case Locale::QDateCalendar: - return new KCalendarSystemQDate(config, locale); - case Locale::CopticCalendar: - return new KCalendarSystemCoptic(config, locale); - case Locale::EthiopianCalendar: - return new KCalendarSystemEthiopian(config, locale); - case Locale::GregorianCalendar: - return new KCalendarSystemGregorian(config, locale); - case Locale::HebrewCalendar: - return new KCalendarSystemHebrew(config, locale); - case Locale::IndianNationalCalendar: - return new KCalendarSystemIndianNational(config, locale); - case Locale::IslamicCivilCalendar: - return new KCalendarSystemIslamicCivil(config, locale); - case Locale::JalaliCalendar: - return new KCalendarSystemJalali(config, locale); - case Locale::JapaneseCalendar: - return new KCalendarSystemJapanese(config, locale); - case Locale::JulianCalendar: - return new KCalendarSystemJulian(config, locale); - case Locale::MinguoCalendar: - return new KCalendarSystemMinguo(config, locale); - case Locale::ThaiCalendar: - return new KCalendarSystemThai(config, locale); - default: - return new KCalendarSystemQDate(config, locale); - } -} QList CalendarSystem::calendarSystemsList() { QList list; - foreach(KLocale::CalendarSystem calendarSystem, m_calendarSystem->calendarSystemList()) { + foreach(KLocale::CalendarSystem calendarSystem, KCalendarSystem::calendarSystemsList()) { list.append((Locale::CalendarSystem)calendarSystem); } return list; } -QString CalendarSystem::calendarLabel(Locale::CalendarSystem calendarSystem, const Locale *locale) +QString CalendarSystem::calendarLabel(Locale::CalendarSystem calendarSystem, const KLocale *locale) { - return m_calendarSystem->calendarLabel((KLocale::CalendarSystem)calendarSystem, (KLocale)locale); + return KCalendarSystem::calendarLabel((KLocale::CalendarSystem)calendarSystem, locale); } +QString CalendarSystem::calendarType(Locale::CalendarSystem calendarSystem) +{ + return KCalendarSystem::calendarType((KLocale::CalendarSystem)calendarSystem); +} + + Locale::CalendarSystem CalendarSystem::calendarSystem(const QString &calendarType ) { - return (Locale::CalendarSystem)m_calendarSystem->calendarSystem(calendarType); + return (Locale::CalendarSystem)KCalendarSystem::calendarSystem(calendarType); } // NOT VIRTUAL - If override needed use shared-d @@ -112,7 +65,7 @@ Locale::CalendarSystem CalendarSystem::calendarSystem() const // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::calendarLabel() const { - return CalendarSystem::calendarLabel(calendarSystem()); + return m_calendarSystem->calendarLabel(); } // Dummy version using Gregorian as an example @@ -183,7 +136,7 @@ bool CalendarSystem::setDate(QDate &date, QString eraName, int yearInEra, int mo // NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const { - m_calendarSystem->setDateIsoWeek(date, year, isoWeekNumber, dayOfIsoWeek); + return m_calendarSystem->setDateIsoWeek(date, year, isoWeekNumber, dayOfIsoWeek); } // NOT VIRTUAL - If override needed use shared-d diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index e341c35db..c00649c47 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -21,7 +21,6 @@ #ifndef CALENDARSYSTEM_H #define CALENDARSYSTEM_H -#include #include "locale.h" // needed for enums #include "kglobal.h" @@ -75,31 +74,11 @@ public: NarrowDayName /**< Narrow name format, e.g. "F". @since 4.7 */ }; - //KDE5 add default value to calendarSystem /** - * - * Creates a KCalendarSystem object for the required Calendar System - * - * @param calendarSystem the Calendar System to create, defaults to QDate compatible - * @param locale locale to use for translations. The global locale is used if null. - * @return a KCalendarSystem object - */ - Q_INVOKABLE static KCalendarSystem *create(Locale::CalendarSystem calendarSystem, - const KLocale *locale = 0); - - /** - * - * Creates a KCalendarSystem object for the required Calendar System - * - * @param calendarSystem the Calendar System to create - * @param config a configuration file with a 'KCalendarSystem %calendarType' group detailing - * locale-related preferences (such as era options). The global config is used - if null. - * @param locale locale to use for translations. The global locale is used if null. - * @return a KCalendarSystem object - */ - Q_INVOKABLE static KCalendarSystem *create(Locale::CalendarSystem calendarSystem, KSharedConfig::Ptr config, - const KLocale *locale = 0); + * Returns the list of currently supported Calendar Systems + * @return list of Calendar Systems + */ + static QList calendarSystemsList(); /** * @@ -135,28 +114,6 @@ public: */ Q_INVOKABLE static QString calendarType(Locale::CalendarSystem calendarSystem); - /** - * Constructor of abstract calendar class. This will be called by derived classes. - * - * @param locale locale to use for translations. The global locale is used if null. - */ - explicit KCalendarSystem(const KLocale *locale = 0); - - /** - * Constructor of abstract calendar class. This will be called by derived classes. - * - * @param config a configuration file with a 'KCalendarSystem %calendarName' group detailing - * locale-related preferences (such as era options). The global config is used - if null. - * @param locale locale to use for translations. The global locale is used if null. - */ - explicit KCalendarSystem(const KSharedConfig::Ptr config, const KLocale *locale = 0); - - /** - * Destructor. - */ - virtual ~KCalendarSystem(); - /** * * Returns the Calendar System type of the KCalendarSystem object @@ -1260,9 +1217,6 @@ protected: if null. * @param locale locale to use for translations. The global locale is used if null. */ - KCalendarSystem(KCalendarSystemPrivate &dd, - const KSharedConfig::Ptr config = KSharedConfig::Ptr(), - const KLocale *locale = 0); private: //FIXME When it comes the time to create wrappers for the above @@ -1293,10 +1247,7 @@ private: KCalendarEra era(const QDate &eraDate) const; KCalendarEra era(const QString &eraName, int yearInEra) const; - //Q_DISABLE_COPY(KCalendarSystem) KCalendarSystem *m_calendarSystem; - //FIXME What is Q_DECLARE_PRIVATE - //Q_DECLARE_PRIVATE(KCalendarSystem) }; #endif From 82ce5394da173f87ba11c3169986746a680767c8 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 12 Feb 2012 16:00:18 +0200 Subject: [PATCH 031/104] fix the enums and typos --- declarativeimports/locale/calendarsystem.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 5d3ecd358..c05174bf7 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -163,13 +163,13 @@ int CalendarSystem::day(const QDate &date) const // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::eraName(const QDate &date, StringFormat format) const { - return m_calendarSystem->eraName(date, format); + return m_calendarSystem->eraName(date, (KCalendarSystem::StringFormat)format); } // NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::eraYear(const QDate &date, StringFormat format) const { - return m_calendarSystem->eraYear(date, format); + return m_calendarSystem->eraYear(date, (KCalendarSystem::StringFormat)format); } // NOT VIRTUAL - If override needed use shared-d @@ -301,7 +301,7 @@ int CalendarSystem::daysInMonth(int year, int month) const int CalendarSystem::daysInWeek(const QDate &date) const { - return m_calendarSystem->daysInWeek(); + return m_calendarSystem->daysInWeek(date); } int CalendarSystem::dayOfYear(const QDate &date) const @@ -314,11 +314,6 @@ int CalendarSystem::dayOfWeek(const QDate &date) const return m_calendarSystem->dayOfWeek(date); } -int CalendarSystem::weekNumber(const QDate &date, int *yearNum) const -{ - return week(date, Locale::IsoWeekNumber, yearNum); -} - // NOT VIRTUAL - Uses shared-d instead int CalendarSystem::week(const QDate &date, int *yearNum) const { @@ -418,7 +413,7 @@ QString CalendarSystem::formatDate(const QDate &fromDate, Locale::DateFormat toF QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DateTimeFormatStandard standard) const { - return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DateTimeFormatStandard)standar); + return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DateTimeFormatStandard)standard); } // NOT VIRTUAL - If override needed use shared-d From 2bc6afab73f1322a23382a3f2de6d35219833776 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 12 Feb 2012 16:06:12 +0200 Subject: [PATCH 032/104] Remove the internal methods of KCalendarSystem --- declarativeimports/locale/calendarsystem.cpp | 30 -------- declarativeimports/locale/calendarsystem.h | 72 -------------------- 2 files changed, 102 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index c05174bf7..415d963b6 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -473,33 +473,3 @@ int CalendarSystem::weekStartDay() const { return m_calendarSystem->weekStartDay(); } - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -// The implementation MUST NOT do validity checking on date ranges, all calls to this function MUST -// instead be wrapped in validity checks, as sometimes we want this to work outside the public valid -// range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but -// are required for internal maths -bool CalendarSystem::julianDayToDate(int jd, int &year, int &month, int &day) const -{ - return m_calendarSystem->julianDayToDate(jd, year, month, day); -} - -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System -// The implementation MUST NOT do validity checking on date ranges, all calls to this function MUST -// instead be wrapped in validity checks, as sometimes we want this to work outside the public valid -// range, i.e. to allow us to internally set dates of 1/1/10000 which are not publically valid but -// are required for internal maths -bool CalendarSystem::dateToJulianDay(int year, int month, int day, int &jd) const -{ - return m_calendarSystem->dateToJulianDay(year, month, day, jd); -} - -//FIXME what should I do with the above one? -/*const KLocale * CalendarSystem::locale() const -{ - Q_D(const KCalendarSystem); - - return d->locale(); -}*/ diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index c00649c47..9c07aceeb 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -1146,78 +1146,6 @@ public: */ Q_INVOKABLE virtual bool isProleptic() const = 0; -protected: - - /** - * Internal method to convert a Julian Day number into the YMD values for - * this calendar system. - * - * All calendar system implementations MUST implement julianDayToDate and - * dateToJulianDay methods as all other methods can be expressed as - * functions of these. Does no internal validity checking. - * - * @see KCalendarSystem::dateToJulianDay - * - * @param jd Julian day number to convert to date - * @param year year number returned in this variable - * @param month month number returned in this variable - * @param day day of month returned in this variable - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE virtual bool julianDayToDate(int jd, int &year, int &month, int &day) const = 0; - - /** - * Internal method to convert YMD values for this calendar system into a - * Julian Day number. - * - * All calendar system implementations MUST implement julianDayToDate and - * dateToJulianDay methods as all other methods can be expressed as - * functions of these. Does no internal validity checking. - * - * @see KCalendarSystem::julianDayToDate - * - * @param year year number - * @param month month number - * @param day day of month - * @param jd Julian day number returned in this variable - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE virtual bool dateToJulianDay(int year, int month, int day, int &jd) const = 0; - - /** - * Returns the locale used for translations and formats for this - * calendar system instance. This allows a calendar system instance to be - * independent of the global translations and formats if required. All - * implementations must refer to this locale. - * - * Only for internal calendar system use; if public access is required then - * provide public methods only for those methods actually required. Any - * app that creates an instance with its own locale overriding global will - * have the original handle to the locale and can manipulate it that way if - * required, e.g. to change default date format. Only expose those methods - * that library widgets require access to internally. - * - * @see KCalendarSystem::formatDate - * @see Locale::formatDate - * @see KCalendarSystem::weekStartDay - * @see Locale::weekStartDay - * @see KCalendarSystem::readDate - * @see Locale::readDate - * - * @return locale to use - */ - Q_INVOKABLE const KLocale *locale() const; - - /** - * Constructor of abstract calendar class. This will be called by derived classes. - * - * @param dd derived private d-pointer. - * @param config a configuration file with a 'KCalendarSystem %calendarName' group detailing - * locale-related preferences (such as era options). The global config is used - if null. - * @param locale locale to use for translations. The global locale is used if null. - */ - private: //FIXME When it comes the time to create wrappers for the above //classes will i need the "friend class foo"??? From 55ff7f3e0bfb6e83f7d394f387fdd7916a128858 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 12 Feb 2012 16:07:38 +0200 Subject: [PATCH 033/104] Remove friend class foo; --- declarativeimports/locale/calendarsystem.h | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 9c07aceeb..8402e9244 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -1147,28 +1147,6 @@ public: Q_INVOKABLE virtual bool isProleptic() const = 0; private: - //FIXME When it comes the time to create wrappers for the above - //classes will i need the "friend class foo"??? - - //Required for shared d-pointer as already private, remove in KDE5 - friend class KCalendarSystemCoptic; - friend class KCalendarSystemEthiopian; - friend class KCalendarSystemGregorian; - friend class KCalendarSystemHebrew; - friend class KCalendarSystemIndianNational; - friend class KCalendarSystemIslamicCivil; - friend class KCalendarSystemJalali; - friend class KCalendarSystemJapanese; - friend class KCalendarSystemJulian; - friend class KCalendarSystemMinguo; - friend class KCalendarSystemQDate; - friend class KCalendarSystemThai; - //Other friends that need access to protected/private functions - friend class KLocalizedDate; - friend class KLocalizedDatePrivate; - friend class KDateTimeParser; - friend class KDateTable; - //FIXME era issue.. // Era functions needed by friends, may be made public later if needed in KCM QList *eraList() const; From fbb91918def38c2d07c831eea006b128f93e7685 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 12 Feb 2012 16:14:18 +0200 Subject: [PATCH 034/104] Remove the era* internal methods --- declarativeimports/locale/calendarsystem.cpp | 31 +------------------- declarativeimports/locale/calendarsystem.h | 6 ---- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 415d963b6..7921b35c0 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -22,12 +22,9 @@ #include "kdebug.h" #include "kconfiggroup.h" #include - -#include - #include -//FIXME fix all the create static methods +#include QList CalendarSystem::calendarSystemsList() { @@ -178,32 +175,6 @@ int CalendarSystem::yearInEra(const QDate &date) const return m_calendarSystem->yearInEra(date); } -// NOT VIRTUAL - If override needed use shared-d -//FIXME we need a wrapper for KCalendarEra!! -/*QList *CalendarSystem::eraList() const -{ - Q_D(const KCalendarSystem); - - return d->eraList(); -}*/ - -// NOT VIRTUAL - If override needed use shared-d -/*FIXME we don't need the above.Correct? -KCalendarEra CalendarSystem::era(const QDate &eraDate) const -{ - Q_D(const KCalendarSystem); - - return d->era(eraDate); -} - -// NOT VIRTUAL - If override needed use shared-d -KCalendarEra CalendarSystem::era(const QString &eraName, int yearInEra) const -{ - Q_D(const KCalendarSystem); - - return d->era(eraName, yearInEra); -} -*/ QDate CalendarSystem::addYears(const QDate &date, int numYears) const { return m_calendarSystem->addYears(date, numYears); diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 8402e9244..167790e19 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -1147,12 +1147,6 @@ public: Q_INVOKABLE virtual bool isProleptic() const = 0; private: - //FIXME era issue.. - // Era functions needed by friends, may be made public later if needed in KCM - QList *eraList() const; - KCalendarEra era(const QDate &eraDate) const; - KCalendarEra era(const QString &eraName, int yearInEra) const; - KCalendarSystem *m_calendarSystem; }; From de895b36c12c22823fd303a9909ad94de9a93e34 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Tue, 14 Feb 2012 03:03:51 +0200 Subject: [PATCH 035/104] Populate localebindings/CMakeLists.txt --- declarativeimports/locale/CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/declarativeimports/locale/CMakeLists.txt b/declarativeimports/locale/CMakeLists.txt index f35d2e7a6..d74a84869 100644 --- a/declarativeimports/locale/CMakeLists.txt +++ b/declarativeimports/locale/CMakeLists.txt @@ -1,5 +1,7 @@ project(localebindings) +include(KDE4Defaults) + set(localebindings_SRCS locale.cpp calendarsystem.cpp @@ -14,10 +16,10 @@ INCLUDE_DIRECTORIES( qt4_automoc(${localebindings_SRCS}) -add_library(localebindingsplugin SHARED ${localebindings_SRCS}) +kde4_add_library(localebindingsplugin SHARED ${localebindings_SRCS}) #FIXME #Should i put something? -target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY}) +target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KDECORE_LIBRARY}) install(TARGETS localebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) From 69e028bfbddaf8236545f9cb9d5a9db9da406aec Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Tue, 14 Feb 2012 03:05:30 +0200 Subject: [PATCH 036/104] Add a missing signal into locale.h --- declarativeimports/locale/locale.h | 1 + 1 file changed, 1 insertion(+) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 7c4610554..00add2a25 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -2017,6 +2017,7 @@ Q_SIGNALS: void weekStartDayChanged(); void workingWeekEndDayChanged(); void workingWeekStartDayChanged(); + void calendarChanged(); }; //TODO remove the above? //Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) From 461ad73f5849b7e33dc93be7b792ae363a3ba0e6 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Tue, 14 Feb 2012 04:08:46 +0200 Subject: [PATCH 037/104] Add localebindingsplugin.cpp to CMakeLists.txt --- declarativeimports/locale/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/declarativeimports/locale/CMakeLists.txt b/declarativeimports/locale/CMakeLists.txt index d74a84869..5245a7b17 100644 --- a/declarativeimports/locale/CMakeLists.txt +++ b/declarativeimports/locale/CMakeLists.txt @@ -4,6 +4,7 @@ include(KDE4Defaults) set(localebindings_SRCS locale.cpp + localebindingsplugin.cpp calendarsystem.cpp ) From 7877980f2e79e9b21e4373e74393b2e1a8c35b90 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 14 Feb 2012 12:29:21 +0200 Subject: [PATCH 038/104] Add CalendarSystem's ctor --- declarativeimports/locale/calendarsystem.cpp | 7 +++++++ declarativeimports/locale/calendarsystem.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 7921b35c0..00a6dd72b 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -26,6 +26,13 @@ #include +CalendarSystem::CalendarSystem(QObject* parent) + : QObject(parent) +{ + m_calendarSystem = KCalendarSystem::create(KLocale::CalendarSystem, 0); +} + + QList CalendarSystem::calendarSystemsList() { QList list; diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 167790e19..ecb83360c 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -46,6 +46,9 @@ Q_ENUMS(WeekDayNameFormat) public: + //ctor + CalendarSystem(QObject *parent = 0); + /** * Format for returned year number / month number / day number as string. */ From 6b784a98e820c7610b878e17425b20432c239dad Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 14 Feb 2012 12:52:08 +0200 Subject: [PATCH 039/104] Fix a typo,remove a deprecated method add comment the Locale::calendar --- declarativeimports/locale/locale.cpp | 4 ++-- declarativeimports/locale/locale.h | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index dcfd076f0..9ef1ead26 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -641,10 +641,10 @@ Locale::CalendarSystem Locale::calendarSystem() const return (Locale::CalendarSystem)m_locale->calendarSystem(); } -const KCalendarSystem * Locale::calendar() const +/*const KCalendarSystem * Locale::calendar() const { return m_locale->calendar(); -} +}*/ void Locale::setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem) { diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 00add2a25..b6881541a 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -84,8 +84,7 @@ Q_ENUMS(WeekNumberSystem) //properties Q_PROPERTY(BinaryUnitDialect binaryUnitDialect READ binaryUnitDialect WRITE setBinaryUnitDialect NOTIFY binaryUnitDialectChanged) -Q_PROPERTY(KCalendarSystem *calendar READ calendar WRITE setCalendar NOTIFY calendarChanged) -Q_PROPERTY(Locale::CalendarSystem *calendarSystem READ calendarSystem WRITE setCalendarSystem NOTIFY calendarSystemChanged) +Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem WRITE setCalendarSystem NOTIFY calendarSystemChanged) Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) Q_PROPERTY(QString countryDivisionCode READ countryDivisionCode WRITE setCountryDivisionCode NOTIFY countryDivisionCodeChanged) Q_PROPERTY(QString currencyCode READ currencyCode WRITE setCurrencyCode NOTIFY currencyCodeChanged) @@ -1054,12 +1053,17 @@ public: */ int weekDayOfPray() const; + /** + * What should I do with the above? + * It won't work in QML. + **/ + /** * Returns a pointer to the calendar system object. * * @return the current calendar system instance */ - const KCalendarSystem * calendar() const; + //const KCalendarSystem * calendar() const; /** * @@ -2017,7 +2021,6 @@ Q_SIGNALS: void weekStartDayChanged(); void workingWeekEndDayChanged(); void workingWeekStartDayChanged(); - void calendarChanged(); }; //TODO remove the above? //Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) From 1386b6aece32b81671db85ab77609e9440403784 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Wed, 15 Feb 2012 03:22:23 +0200 Subject: [PATCH 040/104] Remove unusable code for qml --- declarativeimports/locale/locale.cpp | 29 ------------ declarativeimports/locale/locale.h | 68 ---------------------------- 2 files changed, 97 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 9ef1ead26..8e79449e5 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -29,31 +29,12 @@ Locale::Locale(QObject* parent) m_locale = new KLocale(*KGlobal::locale()); } - -bool Locale::setCountry(const QString &country, KConfig *config) -{ - emit countryChanged(); - return m_locale->setCountry(country, config); -} - bool Locale::setCountryDivisionCode(const QString &countryDivisionCode) { emit countryDivisionCodeChanged(); return m_locale->setCountryDivisionCode(countryDivisionCode); } -bool Locale::setLanguage(const QString &language, KConfig *config) -{ - emit languageChanged(); - return m_locale->setLanguage(language, config); -} - -bool Locale::setLanguage(const QStringList &languages) -{ - emit languageChanged(); - return m_locale->setLanguage(languages); -} - void Locale::setCurrencyCode(const QString &newCurrencyCode) { emit currencyCodeChanged(); @@ -86,11 +67,6 @@ QString Locale::countryDivisionCode() const return m_locale->countryDivisionCode(); } -KCurrencyCode *Locale::currency() const -{ - return m_locale->currency(); -} - QString Locale::currencyCode() const { return m_locale->currencyCode(); @@ -594,11 +570,6 @@ int Locale::fileEncodingMib() const return m_locale->fileEncodingMib(); } -QTextCodec *Locale::codecForEncoding() const -{ - return m_locale->codecForEncoding(); -} - bool Locale::setEncoding(int mibEnum) { return m_locale->setEncoding(mibEnum); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index b6881541a..27781156e 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -411,14 +411,6 @@ public: */ QString currencyCode() const; - /** - * - * Returns the Currency Code object for the current locale - * - * @return The default Currency Code object used by locale. - */ - Q_INVOKABLE KCurrencyCode *currency() const; - /** * Returns what the symbol denoting currency in the current locale * as as defined by user settings should look like. @@ -1353,17 +1345,6 @@ public: */ Q_INVOKABLE int encodingMib() const; - /** - * Returns the user's preferred encoding. Should never be NULL. - * - * @return The codec for the preferred encoding - * - * @see encoding - * @see encodingMib - */ - //TODO will this work? - Q_INVOKABLE QTextCodec *codecForEncoding() const; - /** * Returns the file encoding. * @@ -1851,26 +1832,6 @@ public: */ Q_INVOKABLE void copyCatalogsTo(Locale *locale); - /** - * Changes the current country. The current country will be left - * unchanged if failed. It will force a reload of the country specific - * configuration. - * - * An empty country value will set the country to the system default. - * - * If you specify a configuration file, a setLocale() will be performed on - * the config using the current locale language, which may cause a sync() - * and reparseConfiguration() which will save any changes you have made. - * - * @param country the ISO 3166 country code - * @param config a configuration file with a Locale group detailing - * locale-related preferences (such as language and - * formatting options). - * - * @return @c true on success, @c false on failure - */ - bool setCountry(const QString & country, KConfig *config); - /** * * Sets the Country Division Code of the Country where the user lives. @@ -1887,35 +1848,6 @@ public: */ bool setCountryDivisionCode(const QString & countryDivision); - /** - * Changes the current language. The current language will be left - * unchanged if failed. It will force a reload of the country specific - * configuration as well. - * - * If you specify a configuration file, a setLocale() will be performed on - * the config using the current locale language, which may cause a sync() - * and reparseConfiguration() which will save any changes you have made. - * - * @param language the language code - * @param config a configuration file with a Locale group detailing - * locale-related preferences (such as language and - * formatting options). - * - * @return true on success - */ - bool setLanguage(const QString &language, KConfig *config); - - /** - * Changes the list of preferred languages for the locale. The first valid - * language in the list will be used, or the default language (en_US) - * if none of the specified languages were available. - * - * @param languages the list of language codes - * - * @return true if one of the specified languages were used - */ - bool setLanguage(const QStringList &languages); - /** * * Tries to find a path to the localized file for the given original path. From 403835a82b43e7dbd53d2269b7424c6f9df3f903 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 16 Feb 2012 12:22:44 +0200 Subject: [PATCH 041/104] Fix the pure virtual methods and the ctor. --- declarativeimports/locale/calendarsystem.cpp | 24 ++++++++++++++++++-- declarativeimports/locale/calendarsystem.h | 16 ++++++------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 00a6dd72b..9b5015882 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -23,13 +23,13 @@ #include "kconfiggroup.h" #include #include - +#include #include CalendarSystem::CalendarSystem(QObject* parent) : QObject(parent) { - m_calendarSystem = KCalendarSystem::create(KLocale::CalendarSystem, 0); + m_calendarSystem = KCalendarSystem::create(KGlobal::locale()->calendarSystem()); } @@ -451,3 +451,23 @@ int CalendarSystem::weekStartDay() const { return m_calendarSystem->weekStartDay(); } + +bool CalendarSystem::isSolar() const +{ + return m_calendarSystem->isSolar(); +} + +bool CalendarSystem::isLunar() const +{ + return m_calendarSystem->isLunar(); +} + +bool CalendarSystem::isLunisolar() const +{ + return m_calendarSystem->isLunisolar(); +} + +bool CalendarSystem::isProleptic() const +{ + return m_calendarSystem->isProleptic(); +} diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index ecb83360c..618f85401 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -181,7 +181,7 @@ public: * @param day the day portion of the date to check * @return @c true if the date is valid, @c false otherwise */ - Q_INVOKABLE virtual bool isValid(int year, int month, int day) const = 0; + Q_INVOKABLE bool isValid(int year, int month, int day) const; //KDE5 make virtual? /** @@ -625,7 +625,7 @@ public: * @param year the year to check * @return @c true if the year is a leap year, @c false otherwise */ - Q_INVOKABLE virtual bool isLeapYear(int year) const = 0; + Q_INVOKABLE bool isLeapYear(int year) const; /** * Returns whether a given date falls in a leap year. @@ -731,7 +731,7 @@ public: * @param format specifies whether the short month name or long month name should be used * @return name of the month, empty string if any error */ - Q_INVOKABLE virtual QString monthName(int month, int year, MonthNameFormat format = LongName) const = 0; + Q_INVOKABLE QString monthName(int month, int year, MonthNameFormat format = LongName) const; /** * Gets specific calendar type month name for a given date @@ -750,7 +750,7 @@ public: * @param format specifies whether the short month name or long month name should be used * @return day name, empty string if any error */ - Q_INVOKABLE virtual QString weekDayName(int weekDay, WeekDayNameFormat format = LongDayName) const = 0; + Q_INVOKABLE QString weekDayName(int weekDay, WeekDayNameFormat format = LongDayName) const; /** * Gets specific calendar type week day name. @@ -1123,21 +1123,21 @@ public: * * @return @c true if the calendar is lunar based, @c false if not */ - Q_INVOKABLE virtual bool isLunar() const = 0; + Q_INVOKABLE bool isLunar() const; /** * Returns whether the calendar is lunisolar based. * * @return @c true if the calendar is lunisolar based, @c false if not */ - Q_INVOKABLE virtual bool isLunisolar() const = 0; + Q_INVOKABLE bool isLunisolar() const; /** * Returns whether the calendar is solar based. * * @return @c true if the calendar is solar based, @c false if not */ - Q_INVOKABLE virtual bool isSolar() const = 0; + Q_INVOKABLE bool isSolar() const; /** * Returns whether the calendar system is proleptic, i.e. whether dates @@ -1147,7 +1147,7 @@ public: * * @return @c true if the calendar system is proleptic, @c false if not */ - Q_INVOKABLE virtual bool isProleptic() const = 0; + Q_INVOKABLE bool isProleptic() const; private: KCalendarSystem *m_calendarSystem; From da194d92466906166e5a8de7f557d00d82f74f30 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 16 Feb 2012 12:23:12 +0200 Subject: [PATCH 042/104] Make the properties country and language read-only --- declarativeimports/locale/locale.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 27781156e..5fa8fd78d 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -85,7 +85,7 @@ Q_ENUMS(WeekNumberSystem) //properties Q_PROPERTY(BinaryUnitDialect binaryUnitDialect READ binaryUnitDialect WRITE setBinaryUnitDialect NOTIFY binaryUnitDialectChanged) Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem WRITE setCalendarSystem NOTIFY calendarSystemChanged) -Q_PROPERTY(QString country READ country WRITE setCountry NOTIFY countryChanged) +Q_PROPERTY(QString country READ country NOTIFY countryChanged) Q_PROPERTY(QString countryDivisionCode READ countryDivisionCode WRITE setCountryDivisionCode NOTIFY countryDivisionCodeChanged) Q_PROPERTY(QString currencyCode READ currencyCode WRITE setCurrencyCode NOTIFY currencyCodeChanged) Q_PROPERTY(QString currencySymbol READ currencySymbol WRITE setCurrencySymbol NOTIFY currencySymbolChanged) @@ -97,7 +97,7 @@ Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces NOTIFY de Q_PROPERTY(QString decimalSymbol READ decimalSymbol WRITE setDecimalSymbol NOTIFY decimalSymbolChanged) Q_PROPERTY(DigitSet digitSet READ digitSet WRITE setDigitSet NOTIFY digitSetChanged) Q_PROPERTY(QByteArray encoding READ encoding WRITE setEncoding NOTIFY encodingChanged) -Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged) +Q_PROPERTY(QString language READ language NOTIFY languageChanged) Q_PROPERTY(MeasureSystem measureSystem READ measureSystem WRITE setMeasureSystem NOTIFY measureSystemChanged) Q_PROPERTY(int monetaryDecimalPlaces READ monetaryDecimalPlaces WRITE setMonetaryDecimalPlaces NOTIFY monetaryDecimalPlacesChanged) Q_PROPERTY(QString monetaryDecimalSymbol READ monetaryDecimalSymbol WRITE setMonetaryDecimalSymbol NOTIFY monetaryDecimalSymbolChanged) From 7a945096466f17e962716a2178dc6d2c570cd51c Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 16 Feb 2012 13:07:03 +0200 Subject: [PATCH 043/104] Make the encoding stuff QVariant, in order to be able to use them as properties. --- declarativeimports/locale/locale.cpp | 12 ++++++------ declarativeimports/locale/locale.h | 11 ++++++----- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 8e79449e5..10d9f2425 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -555,14 +555,14 @@ bool Locale::useTranscript() const return m_locale->useTranscript(); } -const QByteArray Locale::encoding() const +const QVariant Locale::encoding() const { - return m_locale->encoding(); + return QVariant(m_locale->encoding()); } -int Locale::encodingMib() const +QVariant Locale::encodingMib() const { - return m_locale->encodingMib(); + return QVariant(m_locale->encodingMib()); } int Locale::fileEncodingMib() const @@ -570,9 +570,9 @@ int Locale::fileEncodingMib() const return m_locale->fileEncodingMib(); } -bool Locale::setEncoding(int mibEnum) +bool Locale::setEncoding(QVariant mibEnum) { - return m_locale->setEncoding(mibEnum); + return m_locale->setEncoding(mibEnum.toInt()); emit encodingChanged(); } diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 5fa8fd78d..b79f8e8e1 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -21,6 +21,8 @@ #define LOCALE_H #include +#include + #include class QString; @@ -32,7 +34,6 @@ class QDateTime; class KDateTime; //TODO will this work? class KCalendarSystem;//TODO make it calendarSystem??? -class KCurrencyCode;//TODO will this work? /** * \file klocale.h @@ -96,7 +97,7 @@ Q_PROPERTY(DigitSet dateTimeDigitSet READ dateTimeDigitSet WRITE setDateTimeDigi Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces NOTIFY decimalPlacesChanged) Q_PROPERTY(QString decimalSymbol READ decimalSymbol WRITE setDecimalSymbol NOTIFY decimalSymbolChanged) Q_PROPERTY(DigitSet digitSet READ digitSet WRITE setDigitSet NOTIFY digitSetChanged) -Q_PROPERTY(QByteArray encoding READ encoding WRITE setEncoding NOTIFY encodingChanged) +Q_PROPERTY(QVariant encoding READ encoding WRITE setEncoding NOTIFY encodingChanged) Q_PROPERTY(QString language READ language NOTIFY languageChanged) Q_PROPERTY(MeasureSystem measureSystem READ measureSystem WRITE setMeasureSystem NOTIFY measureSystemChanged) Q_PROPERTY(int monetaryDecimalPlaces READ monetaryDecimalPlaces WRITE setMonetaryDecimalPlaces NOTIFY monetaryDecimalPlacesChanged) @@ -278,7 +279,7 @@ public: * * @return True on success. */ - bool setEncoding(int mibEnum); + bool setEncoding(QVariant mibEnum); /** * Various positions for where to place the positive or negative @@ -1333,7 +1334,7 @@ public: * @see codecForEncoding * @see encodingMib */ - const QByteArray encoding() const; + const QVariant encoding() const; /** * Returns the user's preferred encoding. @@ -1343,7 +1344,7 @@ public: * @see encoding * @see codecForEncoding */ - Q_INVOKABLE int encodingMib() const; + Q_INVOKABLE QVariant encodingMib() const; /** * Returns the file encoding. From 4018e79ca263e3ed9aa1a0004ab7b787f23b1ff7 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 16 Feb 2012 13:13:04 +0200 Subject: [PATCH 044/104] Remove unnecessary comments --- declarativeimports/locale/locale.h | 49 +----------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index b79f8e8e1..d84d471dd 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -32,7 +32,6 @@ class QDate; class QTime; class QDateTime; -class KDateTime; //TODO will this work? class KCalendarSystem;//TODO make it calendarSystem??? /** @@ -120,53 +119,7 @@ Q_PROPERTY(int workingWeekStartDay READ workingWeekStartDay WRITE setWorkingWeek public: /** - * Constructs a KLocale with the given catalog name - * - * The constructor looks for an entry Language in the group Locale in the - * configuration file. - * - * If no configuration file is specified, it will also look for languages - * using the environment variables (KDE_LANG, LC_MESSAGES, LC_ALL, LANG), - * as well as the global configuration file. If KLocale is not able to use - * any of the specified languages, the default language (en_US) will be - * used. - * - * If you specify a configuration file, it has to be valid until the KLocale - * object is destroyed. Note that a setLocale() will be performed on the - * config using the current locale language, which may cause a sync() - * and reparseConfiguration() which will save any changes you have made and - * load any changes other shared copies have made. - * - * @param catalog the name of the main language file - * @param config a configuration file with a Locale group detailing - * locale-related preferences (such as language and - * formatting options). - */ - //explicit KLocale(const QString& catalog, KSharedConfig::Ptr config = KSharedConfig::Ptr()); - - /** - * Constructs a KLocale with the given catalog name - * - * Allows you to override the language and, optionally, the - * country of this locale. - * - * If you specify a configuration file, a setLocale() will be performed on - * the config using the current locale language, which may cause a sync() - * and reparseConfiguration() which will save any changes you have made. - * - * @param catalog the name of the main language file - * @param language the ISO Language Code for the locale, e.g. "en" for English - * @param country the ISO Country Code for the locale, e.g. "us" for USA - * @param config a configuration file with a Locale group detailing - * locale-related preferences (such as language and - * formatting options). - */ - /* KLocale(const QString& catalog, const QString &language, const QString &country = QString(), - KConfig *config = 0); - */ - - /** - * Copy constructor + * ctor */ Locale(QObject *parent = 0); From a58d172b2ce254a64394cc9e159840d6f3e8abfc Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 16 Feb 2012 13:36:42 +0200 Subject: [PATCH 045/104] make Q_INVOKABLE something foo() into properties --- declarativeimports/locale/locale.h | 45 +++++++++++++++++------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index d84d471dd..e2672547a 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -116,6 +116,12 @@ Q_PROPERTY(Locale::WeekNumberSystem weekNumberSystem READ weekNumberSystem WRITE Q_PROPERTY(int weekStartDay READ weekStartDay WRITE setWeekStartDay NOTIFY weekStartDayChanged) Q_PROPERTY(int workingWeekEndDay READ workingWeekEndDay WRITE setWorkingWeekEndDay NOTIFY workingWeekEndDayChanged) Q_PROPERTY(int workingWeekStartDay READ workingWeekStartDay WRITE setWorkingWeekStartDay NOTIFY workingWeekStartDayChanged) +Q_PROPERTY(bool use12Clock READ use12Clock NOTIFY use12ClockChanged) +Q_PROPERTY(QString defaultLanguage READ defaultLanguage NOTIFY defaultLanguageChanged) +Q_PROPERTY(QString defaultCountry READ defaultCountry NOTIFY defaultCountryChanged) +Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode NOTIFY defaultCurrencyCodeChanged) +Q_PROPERTY(bool useTranscript READ useTranscript NOTIFY useTranscriptChanged) +Q_PROPERTY(QVariant encodingMib READ encodingMib NOTIFY encodingMibChanged) public: /** @@ -328,7 +334,7 @@ public: * @see DigitSet * @see digitSetToName */ - Q_INVOKABLE QList allDigitSetsList() const; + Q_INVOKABLE QList allDigitSetsList() const; //TODO /** * Returns what a decimal point should look like ("." or "," etc.) @@ -959,7 +965,7 @@ public: * * @return If the user wants 12h clock */ - Q_INVOKABLE bool use12Clock() const; + bool use12Clock() const; /** * @@ -1263,7 +1269,7 @@ public: * * @see languageCodeToName */ - Q_INVOKABLE QStringList languageList() const; + Q_INVOKABLE QStringList languageList() const; //TODO /** * @@ -1277,7 +1283,7 @@ public: * * @see currencyCodeToName */ - Q_INVOKABLE QStringList currencyCodeList() const; + Q_INVOKABLE QStringList currencyCodeList() const; //TODO /** * Returns the user's preferred encoding. @@ -1297,7 +1303,7 @@ public: * @see encoding * @see codecForEncoding */ - Q_INVOKABLE QVariant encodingMib() const; + QVariant encodingMib() const; /** * Returns the file encoding. @@ -1654,7 +1660,7 @@ public: * @see languageCodeToName * @see installedLanguages */ - Q_INVOKABLE QStringList allLanguagesList() const; + Q_INVOKABLE QStringList allLanguagesList() const; //TODO /** * @@ -1667,7 +1673,7 @@ public: * * @see languageCodeToName */ - Q_INVOKABLE QStringList installedLanguages() const; + Q_INVOKABLE QStringList installedLanguages() const; //TODO /** * Convert a known language code to a human readable, localized form. @@ -1697,7 +1703,7 @@ public: * * @see countryCodeToName */ - Q_INVOKABLE QStringList allCountriesList() const; + Q_INVOKABLE QStringList allCountriesList() const; //TODO /** * Convert a known country code to a human readable, localized form. @@ -1743,7 +1749,7 @@ public: * * @return Name of the default language */ - Q_INVOKABLE static QString defaultLanguage(); + static QString defaultLanguage(); /** * Returns the code of the default country, i.e. "C" @@ -1755,7 +1761,7 @@ public: * * @return Name of the default country */ - Q_INVOKABLE static QString defaultCountry(); + static QString defaultCountry(); /** * @@ -1763,14 +1769,14 @@ public: * * @return ISO Currency Code of the default currency */ - Q_INVOKABLE static QString defaultCurrencyCode(); + static QString defaultCurrencyCode(); /** * Reports whether evaluation of translation scripts is enabled. * * @return true if script evaluation is enabled, false otherwise. */ - Q_INVOKABLE bool useTranscript() const; + bool useTranscript() const; /** * Checks whether or not the active catalog is found for the given language. @@ -1779,13 +1785,6 @@ public: */ Q_INVOKABLE bool isApplicationTranslatedInto(const QString & language); - /** - * Copies the catalogs of this object to an other KLocale object. - * - * @param locale the destination KLocale object - */ - Q_INVOKABLE void copyCatalogsTo(Locale *locale); - /** * * Sets the Country Division Code of the Country where the user lives. @@ -1867,7 +1866,7 @@ public: * Reparse locale configuration files for the current selected * language. */ - void reparseConfiguration(); + void reparseConfiguration(); //TODO private: KLocale *m_locale; @@ -1907,6 +1906,12 @@ Q_SIGNALS: void weekStartDayChanged(); void workingWeekEndDayChanged(); void workingWeekStartDayChanged(); + void use12ClockChanged(); + void defaultCountryChanged(); + void defaultCurrencyCodeChanged(); + void defaultLanguageChanged(); + void useTranscriptChanged(); + void encodingMibChanged(); }; //TODO remove the above? //Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) From 94ca0b3a5da39e266daa6a164a01d371d8cee200 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 16 Feb 2012 14:01:14 +0200 Subject: [PATCH 046/104] Remove the definition of Locale::copyCatalogsTo. I forgot to remove it in the previous commit --- declarativeimports/locale/locale.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 10d9f2425..3ea8554a1 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -633,11 +633,6 @@ Locale::WeekNumberSystem Locale::weekNumberSystem() const return (Locale::WeekNumberSystem)m_locale->weekNumberSystem(); } -void Locale::copyCatalogsTo(Locale *locale) -{//TODO find a better way to do the cast? - m_locale->copyCatalogsTo((KLocale *)locale); -} - QString Locale::localizedFilePath(const QString &filePath) const { return m_locale->localizedFilePath(filePath); From 06deb00c62a91c24cd95604bc4f40653c413b3a1 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 16 Feb 2012 14:02:06 +0200 Subject: [PATCH 047/104] Make the Q_INVOKABLE something foo() into properties, for the CalendarSystem class --- declarativeimports/locale/calendarsystem.h | 49 +++++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 618f85401..ee95aea6e 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -44,6 +44,20 @@ Q_ENUMS(StringFormat) Q_ENUMS(MonthNameFormat) Q_ENUMS(WeekDayNameFormat) +//properties +Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem NOTIFY calendarSystemChanged) +Q_PROPERTY(QString calendarLabel READ calendarLabel NOTIFY calendarLabelChanged) +Q_PROPERTY(QDate epoch READ epoch NOTIFY epochChanged) +Q_PROPERTY(QDate earliestValidDate READ earliestValidDate NOTIFY earliestValidDateChanged) +Q_PROPERTY(QDate latestValidDate READ latestValidDate NOTIFY latestValidDateChanged) + +Q_PROPERTY(int shortYearWindowStartYear READ shortYearWindowStartYear NOTIFY shortYearWindowStartYearChanged) +Q_PROPERTY(int weekStartDay READ weekStartDay NOTIFY weekStartDayChanged) +Q_PROPERTY(bool isLunar READ isLunar NOTIFY isLunarChanged) +Q_PROPERTY(bool isLunisolar READ isLunisolar NOTIFY isLunisolarChanged) +Q_PROPERTY(bool isSolar READ isSolar NOTIFY isSolarChanged) +Q_PROPERTY(bool isProleptic READ isProleptic NOTIFY isProlepticChanged) + public: //ctor @@ -123,7 +137,7 @@ public: * * @return type of calendar system */ - Q_INVOKABLE Locale::CalendarSystem calendarSystem() const; + Locale::CalendarSystem calendarSystem() const; //KDE5 make virtual? /** @@ -132,7 +146,7 @@ public: * * @return localized label for this Calendar System */ - Q_INVOKABLE QString calendarLabel() const; + QString calendarLabel() const; /** * Returns a QDate holding the epoch of the calendar system. Usually YMD @@ -149,7 +163,7 @@ public: * * @return epoch of calendar system */ - Q_INVOKABLE virtual QDate epoch() const; + virtual QDate epoch() const; /** * Returns the earliest date valid in this calendar system implementation. @@ -161,7 +175,7 @@ public: * * @return date the earliest valid date */ - Q_INVOKABLE virtual QDate earliestValidDate() const; + virtual QDate earliestValidDate() const; /** * Returns the latest date valid in this calendar system implementation. @@ -171,7 +185,7 @@ public: * * @return date the latest valid date */ - Q_INVOKABLE virtual QDate latestValidDate() const; + virtual QDate latestValidDate() const; /** * Returns whether a given date is valid in this calendar system. @@ -1084,7 +1098,7 @@ public: * @see Locale::applyShortYearWindow * @return the short year window start year */ - Q_INVOKABLE int shortYearWindowStartYear() const; + int shortYearWindowStartYear() const; //KDE5 Make virtual /** @@ -1116,28 +1130,28 @@ public: * * @return an integer (Monday = 1, ..., Sunday = 7) */ - Q_INVOKABLE virtual int weekStartDay() const; + virtual int weekStartDay() const; /** * Returns whether the calendar is lunar based. * * @return @c true if the calendar is lunar based, @c false if not */ - Q_INVOKABLE bool isLunar() const; + bool isLunar() const; /** * Returns whether the calendar is lunisolar based. * * @return @c true if the calendar is lunisolar based, @c false if not */ - Q_INVOKABLE bool isLunisolar() const; + bool isLunisolar() const; /** * Returns whether the calendar is solar based. * * @return @c true if the calendar is solar based, @c false if not */ - Q_INVOKABLE bool isSolar() const; + bool isSolar() const; /** * Returns whether the calendar system is proleptic, i.e. whether dates @@ -1147,7 +1161,20 @@ public: * * @return @c true if the calendar system is proleptic, @c false if not */ - Q_INVOKABLE bool isProleptic() const; + bool isProleptic() const; + +Q_SIGNALS: + void calendarSystemChanged(); + void calendarLabelChanged(); + void epochChanged(); + void earliestValidDateChanged(); + void latestValidDateChanged(); + void shortYearWindowStartYearChanged(); + void weekStartDayChanged(); + void isLunarChanged(); + void isLunisolarChanged(); + void isSolarChanged(); + void isProlepticChanged(); private: KCalendarSystem *m_calendarSystem; From 7980cd0496005bf6abc504a3dbe34eee2c84c43a Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 16 Feb 2012 14:04:09 +0200 Subject: [PATCH 048/104] Add a tests folder --- .../tests/contents/code/klocaleqmltest.qml | 34 +++++++++++++++++++ .../locale/tests/metadata.desktop | 12 +++++++ 2 files changed, 46 insertions(+) create mode 100644 declarativeimports/locale/tests/contents/code/klocaleqmltest.qml create mode 100644 declarativeimports/locale/tests/metadata.desktop diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml new file mode 100644 index 000000000..513ef87c3 --- /dev/null +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -0,0 +1,34 @@ +// -*- coding: iso-8859-1 -*- +/* + * Author: Giorgos Tsiapaliwkas + * Date: Wed Feb 15 2012, 18:28:32 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 1.0 +import org.kde.plasma.graphicswidgets 0.1 as PlasmaWidgets +import org.kde.plasma.core 0.1 as PlasmaCore +import org.kde.plasma.graphicslayouts 4.7 as GraphicsLayouts + +Item { + width: 200 + height: 300 + + Text { + text: i18n("Hello world") + } +} diff --git a/declarativeimports/locale/tests/metadata.desktop b/declarativeimports/locale/tests/metadata.desktop new file mode 100644 index 000000000..bebca09a6 --- /dev/null +++ b/declarativeimports/locale/tests/metadata.desktop @@ -0,0 +1,12 @@ +[Desktop Entry] +Name=klocaleQMLtest +Type=Service +X-KDE-PluginInfo-Author=Giorgos Tsiapaliwkas +X-KDE-PluginInfo-Email=terietor@gmail.com +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Name=klocaleqmltest +X-KDE-PluginInfo-Version=1 +X-KDE-ServiceTypes=Plasma/Applet +X-Plasma-API=declarativeappletscript +X-Plasma-DefaultSize=200,100 +X-Plasma-MainScript=code/klocaleqmltest.qml From a820916926f452f6cd855fb81194e67a8346b3ff Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 21 Feb 2012 13:01:31 +0200 Subject: [PATCH 049/104] Give a proper name to the plasmoid(org.kde.$foo) and add change its ui. --- .../tests/contents/code/klocaleqmltest.qml | 45 ++++++++++++++++--- .../locale/tests/metadata.desktop | 4 +- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 513ef87c3..c194f8744 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -19,16 +19,47 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import QtQuick 1.0 -import org.kde.plasma.graphicswidgets 0.1 as PlasmaWidgets +import QtQuick 1.1 +import org.kde.plasma.components 0.1 as PlasmaComponents import org.kde.plasma.core 0.1 as PlasmaCore -import org.kde.plasma.graphicslayouts 4.7 as GraphicsLayouts +import org.kde.plasma.locale 0.1 Item { - width: 200 - height: 300 - + id: root + property int minimumHeight:200 + property int minimumWidth:500 +Column { + id: column + anchors.horizontalCenter: root.horizontalCenter + spacing: 20 Text { - text: i18n("Hello world") + id: text + anchors.horizontalCenter: column.horizontalCenter + text: "This is a test plasmoid for the locale bindings" + color: "red" + } + PlasmaComponents.Button { + id: bt1 + anchors.horizontalCenter: column.horizontalCenter + text: "click in order to test the Locale component" + onClicked:{ + print("hello"); + } + } + PlasmaComponents.Button { + id: bt2 + anchors.horizontalCenter: column.horizontalCenter + text: "click in order to test the CalendarSystem component" + onClicked:{ + print("hello again"); + } + } + Locale { + id: locale + } + + CalendarSystem { + id: calendar } } +} diff --git a/declarativeimports/locale/tests/metadata.desktop b/declarativeimports/locale/tests/metadata.desktop index bebca09a6..797769bbe 100644 --- a/declarativeimports/locale/tests/metadata.desktop +++ b/declarativeimports/locale/tests/metadata.desktop @@ -1,10 +1,10 @@ [Desktop Entry] -Name=klocaleQMLtest +Name=KLocaleQMLtest Type=Service X-KDE-PluginInfo-Author=Giorgos Tsiapaliwkas X-KDE-PluginInfo-Email=terietor@gmail.com X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-Name=klocaleqmltest +X-KDE-PluginInfo-Name=org.kde.klocaleqmltest X-KDE-PluginInfo-Version=1 X-KDE-ServiceTypes=Plasma/Applet X-Plasma-API=declarativeappletscript From 37dd4360d260b3b3ccc48208288894c45ff03f11 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 21 Feb 2012 20:23:04 +0200 Subject: [PATCH 050/104] Populate the test of locale bindings --- .../tests/contents/code/klocaleqmltest.qml | 137 ++++++++++++++---- 1 file changed, 107 insertions(+), 30 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index c194f8744..d7e2e94d6 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -23,43 +23,120 @@ import QtQuick 1.1 import org.kde.plasma.components 0.1 as PlasmaComponents import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.locale 0.1 - Item { id: root property int minimumHeight:200 property int minimumWidth:500 -Column { - id: column - anchors.horizontalCenter: root.horizontalCenter - spacing: 20 - Text { - id: text - anchors.horizontalCenter: column.horizontalCenter - text: "This is a test plasmoid for the locale bindings" - color: "red" - } - PlasmaComponents.Button { - id: bt1 - anchors.horizontalCenter: column.horizontalCenter - text: "click in order to test the Locale component" - onClicked:{ - print("hello"); + Column { + id: column + anchors.horizontalCenter: root.horizontalCenter + spacing: 20 + Text { + id: text1 + anchors.horizontalCenter: column.horizontalCenter + text: "This is a test plasmoid for the locale bindings" + color: "black" } - } - PlasmaComponents.Button { - id: bt2 - anchors.horizontalCenter: column.horizontalCenter - text: "click in order to test the CalendarSystem component" - onClicked:{ - print("hello again"); + + Text { + id: text2 + anchors.horizontalCenter: column.horizontalCenter + text: "If you see this text,that means that every" + + "non printable property/method has been already set. And it works!!" + color: "black" } - } - Locale { - id: locale + + PlasmaComponents.Button { + id: bt1 + anchors.horizontalCenter: column.horizontalCenter + text: "click in order to test the Locale component" + onClicked:{ + console.log("=====Locale Component====") + console.log("country:" + locale.country) + + // locale.binaryUnitDialect = Locale.BinaryUnitDialect.IECBinaryDialect + // locale.calendarSystem = CalendarSystem.CopticCalendar + + locale.countryDivisionCode = "AL" + console.log("countryDivisionCode:" + locale.countryDivisionCode) + + //locale.currencyCode = "AFN" //TODO add the right value + //console.log("currencyCode:" + locale.currencyCode) + + //locale.currencySymbol = TODO + //console.log("currencySymbol" + locale.currencySymbol) + + locale.dateFormat = "Y" + console.log("dateFormat:" + locale.dateFormat) + + locale.dateFormatShort = "Y" + console.log("dateFormatShort:" + locale.dateFormatShort) + + locale.dateMonthNamePossessive = false + console.log("dateMonthNamePossessive:" + locale.dateMonthNamePossessive) + + console.log("===========end===========") + } + } + + PlasmaComponents.Button { + id: bt2 + anchors.horizontalCenter: column.horizontalCenter + text: "click in order to test the CalendarSystem component" + onClicked:{ + console.log("=====CalendarSystem Component====") + console.log("===============end===============") + } + } + + Locale { + id: locale + binaryUnitDialect: BinaryUnitDialect.DefaultBinaryDialect + onBinaryUnitDialectChanged: { + console.log("the binaryUnitDialect property has been changed") + } + + calendarSystem: Locale.QDateCalendar + onCalendarSystemChanged: { + console.log("the calendarSystem property has been changed") + } + + //TODO:Add the proper value + /*currencyCode: "AED" + onCurrencyCodeChanged: { + console.log("the currencyCode property has been changed") + }*/ + + /*TODO + currencySymbol: "" + onCurrencySymbolChanged: { + console.log("the currencySymbol property has been changed") + }*/ + + countryDivisionCode: "AD" + onCountryDivisionCodeChanged: { + console.log("the countryDivisionCode property has been changed") + } + + dateFormat: "y" + onDateFormatChanged: { + console.log("the dateFormat property has been changed") + } + + dateFormatShort: "y" + onDateFormatShortChanged: { + console.log("the dateFormatShort property has been changed") + } + + dateMonthNamePossessive: true + onDateMonthNamePossessiveChanged: { + console.log("the dateMonthNamePossessive property has been changed") + } + } - CalendarSystem { - id: calendar + CalendarSystem { + id: calendar + } } } -} From a02ae1eb52320d0cf308de164e1e1a1a7787e924 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 21 Feb 2012 20:34:29 +0200 Subject: [PATCH 051/104] Add unitest code for dateTimeDigitSet and decimalPlaces --- .../locale/tests/contents/code/klocaleqmltest.qml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index d7e2e94d6..1e4759a8d 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -66,6 +66,8 @@ Item { //locale.currencySymbol = TODO //console.log("currencySymbol" + locale.currencySymbol) + //locale.dateTimeDigitSet = DigitSet.EasternArabicIndicDigits + locale.dateFormat = "Y" console.log("dateFormat:" + locale.dateFormat) @@ -75,6 +77,9 @@ Item { locale.dateMonthNamePossessive = false console.log("dateMonthNamePossessive:" + locale.dateMonthNamePossessive) + locale.decimalPlaces = 2 + console.log("decimalPlaces:" + locale.decimalPlaces) + console.log("===========end===========") } } @@ -133,6 +138,16 @@ Item { console.log("the dateMonthNamePossessive property has been changed") } + dateTimeDigitSet: Digit.ArabicDigits + onDateTimeDigitSet: { + console.log("the dateTimeDigitSet property has been changed") + } + + decimalPlaces: 1 + onDecimalPlacesChanged: { + console.log("the decimalPlaces property has been changed") + } + } CalendarSystem { From 35f9f7b2993dd27073989f8eb5dbf19be0728f74 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 22 Feb 2012 13:23:30 +0200 Subject: [PATCH 052/104] Add "read-only" comments to read-only properties --- declarativeimports/locale/locale.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index e2672547a..cef6a7034 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -85,7 +85,7 @@ Q_ENUMS(WeekNumberSystem) //properties Q_PROPERTY(BinaryUnitDialect binaryUnitDialect READ binaryUnitDialect WRITE setBinaryUnitDialect NOTIFY binaryUnitDialectChanged) Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem WRITE setCalendarSystem NOTIFY calendarSystemChanged) -Q_PROPERTY(QString country READ country NOTIFY countryChanged) +Q_PROPERTY(QString country READ country NOTIFY countryChanged) //read-only Q_PROPERTY(QString countryDivisionCode READ countryDivisionCode WRITE setCountryDivisionCode NOTIFY countryDivisionCodeChanged) Q_PROPERTY(QString currencyCode READ currencyCode WRITE setCurrencyCode NOTIFY currencyCodeChanged) Q_PROPERTY(QString currencySymbol READ currencySymbol WRITE setCurrencySymbol NOTIFY currencySymbolChanged) @@ -97,7 +97,7 @@ Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces NOTIFY de Q_PROPERTY(QString decimalSymbol READ decimalSymbol WRITE setDecimalSymbol NOTIFY decimalSymbolChanged) Q_PROPERTY(DigitSet digitSet READ digitSet WRITE setDigitSet NOTIFY digitSetChanged) Q_PROPERTY(QVariant encoding READ encoding WRITE setEncoding NOTIFY encodingChanged) -Q_PROPERTY(QString language READ language NOTIFY languageChanged) +Q_PROPERTY(QString language READ language NOTIFY languageChanged) //read-only Q_PROPERTY(MeasureSystem measureSystem READ measureSystem WRITE setMeasureSystem NOTIFY measureSystemChanged) Q_PROPERTY(int monetaryDecimalPlaces READ monetaryDecimalPlaces WRITE setMonetaryDecimalPlaces NOTIFY monetaryDecimalPlacesChanged) Q_PROPERTY(QString monetaryDecimalSymbol READ monetaryDecimalSymbol WRITE setMonetaryDecimalSymbol NOTIFY monetaryDecimalSymbolChanged) @@ -120,8 +120,8 @@ Q_PROPERTY(bool use12Clock READ use12Clock NOTIFY use12ClockChanged) Q_PROPERTY(QString defaultLanguage READ defaultLanguage NOTIFY defaultLanguageChanged) Q_PROPERTY(QString defaultCountry READ defaultCountry NOTIFY defaultCountryChanged) Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode NOTIFY defaultCurrencyCodeChanged) -Q_PROPERTY(bool useTranscript READ useTranscript NOTIFY useTranscriptChanged) -Q_PROPERTY(QVariant encodingMib READ encodingMib NOTIFY encodingMibChanged) +Q_PROPERTY(bool useTranscript READ useTranscript NOTIFY useTranscriptChanged) //read-only +Q_PROPERTY(QVariant encodingMib READ encodingMib NOTIFY encodingMibChanged) //read-only public: /** From 8b665776751ff8af08c594f44b86ff099410793e Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 22 Feb 2012 13:24:41 +0200 Subject: [PATCH 053/104] Add tests for the Locale component Properties: decimalSymbol, digitSet, encoding, language, measureSystem, monetaryDecimalPlaces, monetaryDecimalSymbol, monetaryDigitSet --- .../tests/contents/code/klocaleqmltest.qml | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 1e4759a8d..2b2f55b5f 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -80,6 +80,29 @@ Item { locale.decimalPlaces = 2 console.log("decimalPlaces:" + locale.decimalPlaces) + locale.decimalSymbol = "." + console.log("decimalSymbol:" + locale.decimalSymbol) + + //locale.digitSet = DigitSet.EasternArabicIndicDigits + + //The encoding property takes its value from encodingMib property, and the encodingMib property + //is read-only so there is no need for me to change its value. + for (var i in locale.encoding) { + console.log("encoding:" + locale.encoding[i]) + } + + //the language property is read-only + console.log("language:" + locale.language) + + //locale.measureSystem = MeasureSystem.Imperial + + locale.monetaryDecimalPlaces = 3 + console.log("monetaryDecimalPlaces:" + locale.monetaryDecimalPlaces) + + locale.monetaryDecimalSymbol = "." + console.log("monetaryDecimalSymbol:" + locale.monetaryDecimalSymbol) + + //locale.monetaryDigitSet = DigitSet.EasternArabicIndicDigits console.log("===========end===========") } } @@ -139,7 +162,7 @@ Item { } dateTimeDigitSet: Digit.ArabicDigits - onDateTimeDigitSet: { + onDateTimeDigitSetChanged: { console.log("the dateTimeDigitSet property has been changed") } @@ -148,6 +171,41 @@ Item { console.log("the decimalPlaces property has been changed") } + decimalSymbol: "," + onDecimalSymbolChanged: { + console.log("the decimalSymbol property has been changed") + } + + digitSet: Digit.ArabicDigits + onDigitSetChanged: { + console.log("the digitSet property has been changed") + } + + encoding: encodingMib + onEncodingChanged: { + console.log("the digitSet property has been changed") + } + + measureSystem: MeasureSystem.Metric + onMeasureSysteChanged: { + console.log("the measureSystem property has been changed") + } + + monetaryDecimalPlaces: 2 + onMonetaryDecimalPlacesChanged: { + console.log("the monetaryDecimalPlaces property has been changed") + } + + monetaryDecimalSymbol: "," + onMonetaryDecimalSymbolChanged: { + console.log("the monetaryDecimalSymbol property has been changed") + } + + : DigitSet.ArabicDigits + onMonetaryDigitSetChanged: { + console.log("the monetaryDigitSet property has been changed") + } + } CalendarSystem { From e34130edd08523b9f68506d371355372e39512ec Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 22 Feb 2012 14:17:05 +0200 Subject: [PATCH 054/104] Add tests for the Locale component Properties: monetaryThousandsSeparator, negativeMonetarySignPosition, negativePrefixCurrencySymbol, negativeSign, pageSize, negativeMonetarySignPosition, positiveMonetarySignPosition, positivePrefixCurrencySymbol, positiveSign, thousandsSeparator, weekDayOfPray, weekNumberSystem, weekStartDay, workingWeekEndDay, workingWeekStartDay, use12Clock, defaultLanguage, defaultCountry, defaultCurrencyCode, useTranscript, encodingMib --- .../tests/contents/code/klocaleqmltest.qml | 159 +++++++++++++++++- 1 file changed, 156 insertions(+), 3 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 2b2f55b5f..714efccea 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -103,6 +103,58 @@ Item { console.log("monetaryDecimalSymbol:" + locale.monetaryDecimalSymbol) //locale.monetaryDigitSet = DigitSet.EasternArabicIndicDigits + + locale.monetaryThousandsSeparator = "." + console.log("monetaryThousandsSeparator:" + locale.monetaryThousandsSeparator) + + //locale.negativeMonetarySignPosition = SignPosition.AfterMoney + + locale.negativePrefixCurrencySymbol = false + console.log("negativePrefixCurrencySymbol:" + locale.negativePrefixCurrencySymbol) + + locale.negativeSign = "-" + console.log("negativeSign:" + locale.negativeSign) + + locale.pageSize = 6 + console.log("pageSize:" + locale.pageSize) + + //locale.positiveMonetarySignPosition = SignPosition.AfterMoney + + locale.positivePrefixCurrencySymbol = false + console.log("positivePrefixCurrencySymbol:" + locale.positivePrefixCurrencySymbol) + + locale.positiveSign = "+" + console.log("positiveSign:" + locale.positiveSign) + + locale.thousandsSeparator = "." + console.log("thousandsSeparator:" + locale.thousandsSeparator) + + locale.weekDayOfPray = 10 + console.log("weekDayOfPray:" + locale.weekDayOfPray) + + //locale.weekNumberSystem = WeekNumberSystem.FirstFullWeek + + locale.weekStartDay = 3 + console.log("weekStartDay:" + locale.weekStartDay) + + locale.workingWeekEndDay = 6 + console.log("workingWeekEndDay:" + locale.workingWeekEndDay) + + locale.workingWeekStartDay = 2 + console.log("workingWeekStartDay:" + locale.workingWeekEndDay) + + console.log("use12Clock:" + locale.use12Clock) + + console.log("the defaultLanguage:" + locale.defaultLanguage) + + console.log("the defaultCountry:" + locale.defaultCountry) + + console.log("the defaultCurrencyCode:" + locale.defaultCurrencyCode) + + console.log("the useTranscript:" + locale.useTranscript) + + console.log("the encodingMib:" + locale.encodingMib) + console.log("===========end===========") } } @@ -187,7 +239,7 @@ Item { } measureSystem: MeasureSystem.Metric - onMeasureSysteChanged: { + onMeasureSystemChanged: { console.log("the measureSystem property has been changed") } @@ -200,12 +252,113 @@ Item { onMonetaryDecimalSymbolChanged: { console.log("the monetaryDecimalSymbol property has been changed") } - - : DigitSet.ArabicDigits + + monetaryDigitSet: DigitSet.ArabicDigits onMonetaryDigitSetChanged: { console.log("the monetaryDigitSet property has been changed") } + monetaryThousandsSeparator: "," + onMonetaryThousandsSeparatorChanged: { + console.log("the monetaryThousandsSeparator property has been changed") + } + + negativeMonetarySignPosition: SignPosition.ParensAround + onNegativeMonetarySignPositionChanged: { + console.log("the negativeMonetarySignPosition property has been changed") + } + + negativePrefixCurrencySymbol: true + onNegativePrefixCurrencySymbolChanged: { + console.log("the negativePrefixCurrencySymbol property has been changed") + } + + negativeSign: "-----" + onNegativeSignChanged: { + console.log("the negativeSign property has been changed") + } + + pageSize: 5 + onPageSizeChanged: { + console.log("the pageSign property has been changed") + } + + positiveMonetarySignPosition: SignPosition.ParensAround + onPositiveMonetarySignPositionChanged: { + console.log("the positiveMonetarySignPosition property has been changed") + } + + positivePrefixCurrencySymbol: true + onPositivePrefixCurrencySymbolChanged: { + console.log("the positivePrefixCurrencySymbol property has been changed") + } + + positiveSign: " " + onPositiveSignChanged: { + console.log("the positiveSign property has been changed") + } + + thousandsSeparator: "," + onThousandsSeparatorChanged: { + console.log("the thousandsSeparator property has been changed") + } + + weekDayOfPray: 20 + onweekDayOfPrayChanged: { + console.log("the weekDayOfPray property has been changed") + } + + weekNumberSystem: WeekNumberSystem.DefaultWeekNumber + onweekDayOfPrayChanged: { + console.log("the weekNumberSystem property has been changed") + } + + weekStartDay: 2 + onWeekStartDayChanged: { + console.log("the weekStartDay property has been changed") + } + + workingWeekEndDay: 5 + onWorkingWeekEndDayChanged: { + console.log("the workingWeekEndDay property has been changed") + } + + workingWeekStartDay: 1 + onWorkingWeekStartDayChanged: { + console.log("the workingWeekStartDay property has been changed") + } + + onUse12ClockChanged: { + console.log("the use12Clock property has been changed") + } + + onDefaultLanguageChanged: { + console.log("the defaultLanguage property has been changed") + } + + onDefaultCountryChanged: { + console.log("the defaultCountry property has been changed") + } + + onDefaultCurrencyCodeChanged: { + console.log("the defaultCurrencyCode property has been changed") + } + + onUseTranscriptChanged: { + console.log("the useTranscript property has been changed") + } + + onEncodingMibChanged: { + console.log("the encodingMib property has been changed") + } + + onCountryChanged: { + console.log("the country property has been changed") + } + + onLanguageChanged: { + console.log("the language property has been changed") + } } CalendarSystem { From 39e23de934c3b3a45060e4ea3d6af3cc9ab8bd26 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 22 Feb 2012 14:22:37 +0200 Subject: [PATCH 055/104] Add more "read-only" comments to properties --- declarativeimports/locale/locale.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index cef6a7034..d1494d2a2 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -117,9 +117,9 @@ Q_PROPERTY(int weekStartDay READ weekStartDay WRITE setWeekStartDay NOTIFY weekS Q_PROPERTY(int workingWeekEndDay READ workingWeekEndDay WRITE setWorkingWeekEndDay NOTIFY workingWeekEndDayChanged) Q_PROPERTY(int workingWeekStartDay READ workingWeekStartDay WRITE setWorkingWeekStartDay NOTIFY workingWeekStartDayChanged) Q_PROPERTY(bool use12Clock READ use12Clock NOTIFY use12ClockChanged) -Q_PROPERTY(QString defaultLanguage READ defaultLanguage NOTIFY defaultLanguageChanged) -Q_PROPERTY(QString defaultCountry READ defaultCountry NOTIFY defaultCountryChanged) -Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode NOTIFY defaultCurrencyCodeChanged) +Q_PROPERTY(QString defaultLanguage READ defaultLanguage NOTIFY defaultLanguageChanged)//read-only +Q_PROPERTY(QString defaultCountry READ defaultCountry NOTIFY defaultCountryChanged)//read-only +Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode NOTIFY defaultCurrencyCodeChanged)//read-only Q_PROPERTY(bool useTranscript READ useTranscript NOTIFY useTranscriptChanged) //read-only Q_PROPERTY(QVariant encodingMib READ encodingMib NOTIFY encodingMibChanged) //read-only From 86e5fa1bd050f4d4fba3b82f03e8f69d162a42ce Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 22 Feb 2012 14:41:11 +0200 Subject: [PATCH 056/104] Add tests for the CalendarSystem components. Properties: isProleptic, CalendarLabel, epoch, earliestValidDate, latestValidDate, shortYearWindowStartYear, weekStartDay, isLunar, isLunisolar, isSolar, isProleptic --- .../tests/contents/code/klocaleqmltest.qml | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 714efccea..da75e3d73 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -165,6 +165,27 @@ Item { text: "click in order to test the CalendarSystem component" onClicked:{ console.log("=====CalendarSystem Component====") + + console.log("the CalendarLabel:" + locale.CalendarLabel) + + console.log("epoch:" + locale.epoch + + console.log("earliestValidDate:" + locale.earliestValidDate + + console.log("latestValidDate:" + locale.latestValidDate + + console.log("shortYearWindowStartYear:" + locale.shortYearWindowStartYear + + console.log("weekStartDay:" + locale.weekStartDay + + console.log("isLunar:" + locale.isLunar + + console.log("isLunisolar:" + locale.isLunisolar + + console.log("isSolar:" + locale.isSolar + + console.log("isProleptic:" + locale.isProleptic + console.log("===============end===============") } } @@ -363,6 +384,41 @@ Item { CalendarSystem { id: calendar + + onCalendarSystemChanged: { + console.log("the language property has been changed") + } + + onCalendarLabelChanged: { + console.log("the language property has been changed") + } + onEpochChanged: { + console.log("the language property has been changed") + } + onEarliestValidDateChanged: { + console.log("the language property has been changed") + } + onLatestValidDateChanged: { + console.log("the language property has been changed") + } + onShortYearWindowStartYearChanged: { + console.log("the language property has been changed") + } + onWeekStartDayChanged: { + console.log("the language property has been changed") + } + onIsLunarChanged: { + console.log("the language property has been changed") + } + onIsLunisolarChanged: { + console.log("the language property has been changed") + } + onIsSolarChanged: { + console.log("the language property has been changed") + } + onIsProlepticChanged: { + console.log("the language property has been changed") + } } } } From cba38afc41cb5d13d480967fc9b565f993df2e43 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 22 Feb 2012 14:44:10 +0200 Subject: [PATCH 057/104] Add "read-only" comments to CalendarSystem's properties --- declarativeimports/locale/calendarsystem.h | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index ee95aea6e..c52d84588 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -45,18 +45,17 @@ Q_ENUMS(MonthNameFormat) Q_ENUMS(WeekDayNameFormat) //properties -Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem NOTIFY calendarSystemChanged) -Q_PROPERTY(QString calendarLabel READ calendarLabel NOTIFY calendarLabelChanged) -Q_PROPERTY(QDate epoch READ epoch NOTIFY epochChanged) -Q_PROPERTY(QDate earliestValidDate READ earliestValidDate NOTIFY earliestValidDateChanged) -Q_PROPERTY(QDate latestValidDate READ latestValidDate NOTIFY latestValidDateChanged) - +Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem NOTIFY calendarSystemChanged)//read-only +Q_PROPERTY(QString calendarLabel READ calendarLabel NOTIFY calendarLabelChanged)//read-only +Q_PROPERTY(QDate epoch READ epoch NOTIFY epochChanged)//read-only +Q_PROPERTY(QDate earliestValidDate READ earliestValidDate NOTIFY earliestValidDateChanged)//read-only +Q_PROPERTY(QDate latestValidDate READ latestValidDate NOTIFY latestValidDateChanged)//read-only Q_PROPERTY(int shortYearWindowStartYear READ shortYearWindowStartYear NOTIFY shortYearWindowStartYearChanged) -Q_PROPERTY(int weekStartDay READ weekStartDay NOTIFY weekStartDayChanged) -Q_PROPERTY(bool isLunar READ isLunar NOTIFY isLunarChanged) -Q_PROPERTY(bool isLunisolar READ isLunisolar NOTIFY isLunisolarChanged) -Q_PROPERTY(bool isSolar READ isSolar NOTIFY isSolarChanged) -Q_PROPERTY(bool isProleptic READ isProleptic NOTIFY isProlepticChanged) +Q_PROPERTY(int weekStartDay READ weekStartDay NOTIFY weekStartDayChanged)//read-only +Q_PROPERTY(bool isLunar READ isLunar NOTIFY isLunarChanged)//read-only +Q_PROPERTY(bool isLunisolar READ isLunisolar NOTIFY isLunisolarChanged)//read-only +Q_PROPERTY(bool isSolar READ isSolar NOTIFY isSolarChanged)//read-only +Q_PROPERTY(bool isProleptic READ isProleptic NOTIFY isProlepticChanged)//read-only public: From 86a60e2e2e5517ece52b4d59fba515d51b7fa974 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 22 Feb 2012 14:55:21 +0200 Subject: [PATCH 058/104] fix typos --- .../tests/contents/code/klocaleqmltest.qml | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index da75e3d73..2c587ad07 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -144,8 +144,8 @@ Item { console.log("workingWeekStartDay:" + locale.workingWeekEndDay) console.log("use12Clock:" + locale.use12Clock) - - console.log("the defaultLanguage:" + locale.defaultLanguage) + print("prin t static") + /* console.log("the defaultLanguage:" + locale.defaultLanguage) console.log("the defaultCountry:" + locale.defaultCountry) @@ -153,7 +153,7 @@ Item { console.log("the useTranscript:" + locale.useTranscript) - console.log("the encodingMib:" + locale.encodingMib) + console.log("the encodingMib:" + locale.encodingMib)*/ console.log("===========end===========") } @@ -166,25 +166,25 @@ Item { onClicked:{ console.log("=====CalendarSystem Component====") - console.log("the CalendarLabel:" + locale.CalendarLabel) + console.log("calendarLabel:" + locale.CalendarLabel) - console.log("epoch:" + locale.epoch + console.log("epoch:" + locale.epoch) - console.log("earliestValidDate:" + locale.earliestValidDate + console.log("earliestValidDate:" + locale.earliestValidDate) - console.log("latestValidDate:" + locale.latestValidDate + console.log("latestValidDate:" + locale.latestValidDate) - console.log("shortYearWindowStartYear:" + locale.shortYearWindowStartYear + console.log("shortYearWindowStartYear:" + locale.shortYearWindowStartYear) - console.log("weekStartDay:" + locale.weekStartDay + console.log("weekStartDay:" + locale.weekStartDay) - console.log("isLunar:" + locale.isLunar + console.log("isLunar:" + locale.isLunar) - console.log("isLunisolar:" + locale.isLunisolar + console.log("isLunisolar:" + locale.isLunisolar) - console.log("isSolar:" + locale.isSolar + console.log("isSolar:" + locale.isSolar) - console.log("isProleptic:" + locale.isProleptic + console.log("isProleptic:" + locale.isProleptic) console.log("===============end===============") } @@ -325,12 +325,12 @@ Item { } weekDayOfPray: 20 - onweekDayOfPrayChanged: { + onWeekDayOfPrayChanged: { console.log("the weekDayOfPray property has been changed") } weekNumberSystem: WeekNumberSystem.DefaultWeekNumber - onweekDayOfPrayChanged: { + onWeekNumberSystemChanged: { console.log("the weekNumberSystem property has been changed") } @@ -386,38 +386,38 @@ Item { id: calendar onCalendarSystemChanged: { - console.log("the language property has been changed") + console.log("the calendarSystem property has been changed") } onCalendarLabelChanged: { - console.log("the language property has been changed") + console.log("the calendarLabel property has been changed") } onEpochChanged: { - console.log("the language property has been changed") + console.log("the epoch property has been changed") } onEarliestValidDateChanged: { - console.log("the language property has been changed") + console.log("the earliestValidDate property has been changed") } onLatestValidDateChanged: { - console.log("the language property has been changed") + console.log("the latestValidDate property has been changed") } onShortYearWindowStartYearChanged: { - console.log("the language property has been changed") + console.log("the shortYearWindowStartYear property has been changed") } onWeekStartDayChanged: { - console.log("the language property has been changed") + console.log("the weekStartDay property has been changed") } onIsLunarChanged: { - console.log("the language property has been changed") + console.log("the isLunar property has been changed") } onIsLunisolarChanged: { - console.log("the language property has been changed") + console.log("the isLunisolar property has been changed") } onIsSolarChanged: { - console.log("the language property has been changed") + console.log("the isSolar property has been changed") } onIsProlepticChanged: { - console.log("the language property has been changed") + console.log("the isProleptic property has been changed") } } } From 2a94eda81aaaa85731ba7530f967820e056b1647 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 22 Feb 2012 17:57:31 +0200 Subject: [PATCH 059/104] It is calendar.$foo not locale.$foo --- .../tests/contents/code/klocaleqmltest.qml | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 2c587ad07..994d5e031 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -25,8 +25,8 @@ import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.locale 0.1 Item { id: root - property int minimumHeight:200 - property int minimumWidth:500 + property int minimumHeight: 200 + property int minimumWidth: 500 Column { id: column anchors.horizontalCenter: root.horizontalCenter @@ -144,8 +144,9 @@ Item { console.log("workingWeekStartDay:" + locale.workingWeekEndDay) console.log("use12Clock:" + locale.use12Clock) - print("prin t static") - /* console.log("the defaultLanguage:" + locale.defaultLanguage) + print("before static") + //TODO the plasmoid seg faults + /*console.log("the defaultLanguage:" + locale.defaultLanguage) console.log("the defaultCountry:" + locale.defaultCountry) @@ -166,25 +167,25 @@ Item { onClicked:{ console.log("=====CalendarSystem Component====") - console.log("calendarLabel:" + locale.CalendarLabel) + console.log("calendarLabel:" + calendar.CalendarLabel) - console.log("epoch:" + locale.epoch) + console.log("epoch:" + calendar.epoch) - console.log("earliestValidDate:" + locale.earliestValidDate) + console.log("earliestValidDate:" + calendar.earliestValidDate) - console.log("latestValidDate:" + locale.latestValidDate) + console.log("latestValidDate:" + calendar.latestValidDate) - console.log("shortYearWindowStartYear:" + locale.shortYearWindowStartYear) + console.log("shortYearWindowStartYear:" + calendar.shortYearWindowStartYear) console.log("weekStartDay:" + locale.weekStartDay) - console.log("isLunar:" + locale.isLunar) + console.log("isLunar:" + calendar.isLunar) - console.log("isLunisolar:" + locale.isLunisolar) + console.log("isLunisolar:" + calendar.isLunisolar) - console.log("isSolar:" + locale.isSolar) + console.log("isSolar:" + calendar.isSolar) - console.log("isProleptic:" + locale.isProleptic) + console.log("isProleptic:" + calendar.isProleptic) console.log("===============end===============") } From 36e69304fb94415fab2657d01d1b74e12cced61e Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 26 Feb 2012 16:51:54 +0200 Subject: [PATCH 060/104] Remove the encoding* stuff --- declarativeimports/locale/locale.cpp | 21 ------------------ declarativeimports/locale/locale.h | 33 ---------------------------- 2 files changed, 54 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 3ea8554a1..490aa0a56 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -555,27 +555,11 @@ bool Locale::useTranscript() const return m_locale->useTranscript(); } -const QVariant Locale::encoding() const -{ - return QVariant(m_locale->encoding()); -} - -QVariant Locale::encodingMib() const -{ - return QVariant(m_locale->encodingMib()); -} - int Locale::fileEncodingMib() const { return m_locale->fileEncodingMib(); } -bool Locale::setEncoding(QVariant mibEnum) -{ - return m_locale->setEncoding(mibEnum.toInt()); - emit encodingChanged(); -} - QStringList Locale::allLanguagesList() const { return m_locale->allLanguagesList(); @@ -612,11 +596,6 @@ Locale::CalendarSystem Locale::calendarSystem() const return (Locale::CalendarSystem)m_locale->calendarSystem(); } -/*const KCalendarSystem * Locale::calendar() const -{ - return m_locale->calendar(); -}*/ - void Locale::setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem) { m_locale->setWeekNumberSystem((KLocale::WeekNumberSystem)weekNumberSystem); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index d1494d2a2..2ead1bcd3 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -96,7 +96,6 @@ Q_PROPERTY(DigitSet dateTimeDigitSet READ dateTimeDigitSet WRITE setDateTimeDigi Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces NOTIFY decimalPlacesChanged) Q_PROPERTY(QString decimalSymbol READ decimalSymbol WRITE setDecimalSymbol NOTIFY decimalSymbolChanged) Q_PROPERTY(DigitSet digitSet READ digitSet WRITE setDigitSet NOTIFY digitSetChanged) -Q_PROPERTY(QVariant encoding READ encoding WRITE setEncoding NOTIFY encodingChanged) Q_PROPERTY(QString language READ language NOTIFY languageChanged) //read-only Q_PROPERTY(MeasureSystem measureSystem READ measureSystem WRITE setMeasureSystem NOTIFY measureSystemChanged) Q_PROPERTY(int monetaryDecimalPlaces READ monetaryDecimalPlaces WRITE setMonetaryDecimalPlaces NOTIFY monetaryDecimalPlacesChanged) @@ -121,7 +120,6 @@ Q_PROPERTY(QString defaultLanguage READ defaultLanguage NOTIFY defaultLanguageCh Q_PROPERTY(QString defaultCountry READ defaultCountry NOTIFY defaultCountryChanged)//read-only Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode NOTIFY defaultCurrencyCodeChanged)//read-only Q_PROPERTY(bool useTranscript READ useTranscript NOTIFY useTranscriptChanged) //read-only -Q_PROPERTY(QVariant encodingMib READ encodingMib NOTIFY encodingMibChanged) //read-only public: /** @@ -231,15 +229,6 @@ public: Q_INVOKABLE void translateRawFrom(const char *catname, const char *ctxt, const char *singular, const char *plural, unsigned long n, QString *lang, QString *trans) const; - /** - * Changes the current encoding. - * - * @param mibEnum The mib of the preferred codec - * - * @return True on success. - */ - bool setEncoding(QVariant mibEnum); - /** * Various positions for where to place the positive or negative * sign when they are related to a monetary value. @@ -1285,26 +1274,6 @@ public: */ Q_INVOKABLE QStringList currencyCodeList() const; //TODO - /** - * Returns the user's preferred encoding. - * - * @return The name of the preferred encoding - * - * @see codecForEncoding - * @see encodingMib - */ - const QVariant encoding() const; - - /** - * Returns the user's preferred encoding. - * - * @return The Mib of the preferred encoding - * - * @see encoding - * @see codecForEncoding - */ - QVariant encodingMib() const; - /** * Returns the file encoding. * @@ -1885,7 +1854,6 @@ Q_SIGNALS: void dateTimeDigitSetChanged(); void decimalPlacesChanged(); void digitSetChanged(); - void encodingChanged(); void languageChanged(); void measureSystemChanged(); void monetaryDecimalPlacesChanged(); @@ -1911,7 +1879,6 @@ Q_SIGNALS: void defaultCurrencyCodeChanged(); void defaultLanguageChanged(); void useTranscriptChanged(); - void encodingMibChanged(); }; //TODO remove the above? //Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) From ba409bf600b17514d855593b210319e4f1e350ee Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 26 Feb 2012 16:59:59 +0200 Subject: [PATCH 061/104] Remove the static keyword from defaultLanguage, defaultCountry, defaultCurrencyCode --- declarativeimports/locale/locale.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 2ead1bcd3..341c08fa9 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -1718,7 +1718,7 @@ public: * * @return Name of the default language */ - static QString defaultLanguage(); + QString defaultLanguage(); /** * Returns the code of the default country, i.e. "C" @@ -1730,7 +1730,7 @@ public: * * @return Name of the default country */ - static QString defaultCountry(); + QString defaultCountry(); /** * @@ -1738,7 +1738,7 @@ public: * * @return ISO Currency Code of the default currency */ - static QString defaultCurrencyCode(); + QString defaultCurrencyCode(); /** * Reports whether evaluation of translation scripts is enabled. From 0343a25c8fba42ecc740719fadff5a79a5af8d36 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 26 Feb 2012 17:04:04 +0200 Subject: [PATCH 062/104] Fix typo. typo == s/Locale/KLocale --- declarativeimports/locale/locale.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 490aa0a56..dac4d6aca 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -537,17 +537,17 @@ void Locale::setMeasureSystem(Locale::MeasureSystem value) QString Locale::defaultLanguage() { - return Locale::defaultLanguage(); + return KLocale::defaultLanguage(); } QString Locale::defaultCountry() { - return Locale::defaultCountry(); + return KLocale::defaultCountry(); } QString Locale::defaultCurrencyCode() { - return Locale::defaultCurrencyCode(); + return KLocale::defaultCurrencyCode(); } bool Locale::useTranscript() const From 58bf5c9c8e1355b9028844902a78ebd597ceadea Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 26 Feb 2012 17:24:08 +0200 Subject: [PATCH 063/104] Remove the methods translateRawFrom. In the documentation we are being advised not to use them directly, the same applies for QML. --- declarativeimports/locale/locale.cpp | 24 ------- declarativeimports/locale/locale.h | 102 --------------------------- 2 files changed, 126 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index dac4d6aca..d26347988 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -87,30 +87,6 @@ void Locale::setActiveCatalog(const QString &catalog) m_locale->setActiveCatalog(catalog); } -void Locale::translateRawFrom(const char *catname, const char *ctxt, const char *singular, const char *plural, - unsigned long n, QString *lang, QString *trans) const -{ - m_locale->translateRawFrom(catname, ctxt, singular, plural, n, lang, trans); -} - -//Convenience versions -void Locale::translateRawFrom(const char *catname, const char *msg, QString *lang, QString *trans) const -{ - m_locale->translateRawFrom(catname, 0, msg, 0, 0, lang, trans); -} - -void Locale::translateRawFrom(const char *catname, const char *ctxt, const char *msg, QString *lang, - QString *trans) const -{ - m_locale->translateRawFrom(catname, ctxt, msg, 0, 0, lang, trans); -} - -void Locale::translateRawFrom(const char *catname, const char *singular, const char *plural, - unsigned long n, QString *lang, QString *trans) const -{ - m_locale->translateRawFrom(catname, 0, singular, plural, n, lang, trans); -} - QString Locale::translateQt(const char *context, const char *sourceText, const char *comment) const { return m_locale->translateQt(context, sourceText, comment); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 341c08fa9..a17b10c57 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -127,108 +127,6 @@ public: */ Locale(QObject *parent = 0); - /** - * - * Raw translation from a message catalog. - * If catalog name is null or empty, - * all loaded catalogs are searched for the translation. - * - * Never use this directly to get message translations. See the i18n and ki18n - * family of calls related to KLocalizedString. - * - * @param catname the catalog name. Must be UTF-8 encoded. - * @param msg the message. Must not be null or empty. Must be UTF-8 encoded. - * @param lang language in which the translation was found. If no translation - * was found, Locale::defaultLanguage() is reported. If null, - * the language is not reported. - * @param trans raw translation, or original if not found. If no translation - * was found, original message is reported. If null, the - * translation is not reported. - * - * @see KLocalizedString - */ - Q_INVOKABLE void translateRawFrom(const char* catname, const char* msg, QString *lang, QString *trans) const; - - /** - * - * Raw translation from a message catalog, with given context. - * Context + message are used as the lookup key in the catalog. - * If catalog name is null or empty, - * all loaded catalogs are searched for the translation. - * - * Never use this directly to get message translations. See i18n* and ki18n* - * calls related to KLocalizedString. - * - * @param catname the catalog name. Must be UTF-8 encoded. - * @param ctxt the context. Must not be null. Must be UTF-8 encoded. - * @param msg the message. Must not be null or empty. Must be UTF-8 encoded. - * @param lang language in which the translation was found. If no translation - * was found, Locale::defaultLanguage() is reported. If null, - * the language is not reported. - * @param trans raw translation, or original if not found. If no translation - * was found, original message is reported. If null, the - * translation is not reported. - * - * @see KLocalizedString - */ - Q_INVOKABLE void translateRawFrom(const char *catname, const char *ctxt, const char *msg, QString *lang, QString *trans) const; - - /** - * - * Raw translation from a message catalog, with given singular/plural form. - * Singular form is used as the lookup key in the catalog. - * If catalog name is null or empty, - * all loaded catalogs are searched for the translation. - * - * Never use this directly to get message translations. See i18n* and ki18n* - * calls related to KLocalizedString. - * - * @param catname the catalog name. Must be UTF-8 encoded. - * @param singular the singular form. Must not be null or empty. Must be UTF-8 encoded. - * @param plural the plural form. Must not be null. Must be UTF-8 encoded. - * @param n number on which the forms are decided. - * @param lang language in which the translation was found. If no translation - * was found, Locale::defaultLanguage() is reported. If null, - * the language is not reported. - * @param trans raw translation, or original if not found. If no translation - * was found, original message is reported (either plural or - * singular, as determined by @p n ). If null, the - * translation is not reported. - * - * @see KLocalizedString - */ - Q_INVOKABLE void translateRawFrom(const char *catname, const char *singular, const char *plural, unsigned long n, - QString *lang, QString *trans) const; - - /** - * - * Raw translation from a message catalog, with given context and - * singular/plural form. - * Context + singular form is used as the lookup key in the catalog. - * If catalog name is null or empty, - * all loaded catalogs are searched for the translation. - * - * Never use this directly to get message translations. See i18n* and ki18n* - * calls related to KLocalizedString. - * - * @param catname the catalog name. Must be UTF-8 encoded. - * @param ctxt the context. Must not be null. Must be UTF-8 encoded. - * @param singular the singular form. Must not be null or empty. Must be UTF-8 encoded. - * @param plural the plural form. Must not be null. Must be UTF-8 encoded. - * @param n number on which the forms are decided. - * @param lang language in which the translation was found. If no translation - * was found, Locale::defaultLanguage() is reported. If null, - * the language is not reported. - * @param trans raw translation, or original if not found. If no translation - * was found, original message is reported (either plural or - * singular, as determined by @p n ). If null, the - * translation is not reported. - * - * @see KLocalizedString - */ - Q_INVOKABLE void translateRawFrom(const char *catname, const char *ctxt, const char *singular, const char *plural, - unsigned long n, QString *lang, QString *trans) const; - /** * Various positions for where to place the positive or negative * sign when they are related to a monetary value. From b5bb3bb6e5deccef7b999a1badb17c1c1cac4980 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 26 Feb 2012 18:02:17 +0200 Subject: [PATCH 064/104] Remove unnecessary code --- declarativeimports/locale/locale.cpp | 7 ------- declarativeimports/locale/locale.h | 6 ------ 2 files changed, 13 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index d26347988..daf8990d2 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -329,13 +329,6 @@ QStringList Locale::currencyCodeList() const return m_locale->currencyCodeList(); } -/* Just copy in for now to keep diff clean, remove later -QString Locale::formatDateTime(const Locale *locale, const QDateTime &dateTime, Locale::DateFormat format, - bool includeSeconds, int daysTo, int secsTo) -{ -} -*/ - QString Locale::formatDateTime(const QDateTime &dateTime, Locale::DateFormat format, bool includeSeconds) const { return m_locale->formatDateTime(dateTime, (KLocale::DateFormat)format, (KLocale::DateFormat)includeSeconds); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index a17b10c57..21876a00a 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -21,19 +21,14 @@ #define LOCALE_H #include -#include #include class QString; -class QStringList; //TODO will the QStringList invokable methods work in QML? -class QTextCodec; class QDate; class QTime; class QDateTime; -class KCalendarSystem;//TODO make it calendarSystem??? - /** * \file klocale.h */ @@ -902,7 +897,6 @@ public: * * @return the current calendar system instance */ - //const KCalendarSystem * calendar() const; /** * From 4319d7d0d8f8953fc8774708b429b36f7a6c762f Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sun, 26 Feb 2012 18:05:22 +0200 Subject: [PATCH 065/104] Add test code for the QStringList methods of Locale. --- .../tests/contents/code/klocaleqmltest.qml | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 994d5e031..f40c56517 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -29,6 +29,8 @@ Item { property int minimumWidth: 500 Column { id: column + width: parent.width + height: parent.height anchors.horizontalCenter: root.horizontalCenter spacing: 20 Text { @@ -41,8 +43,8 @@ Item { Text { id: text2 anchors.horizontalCenter: column.horizontalCenter - text: "If you see this text,that means that every" + - "non printable property/method has been already set. And it works!!" + text: "If you see this text,that means that every " + + " non printable property/method has been already set. And it works!!" color: "black" } @@ -85,12 +87,6 @@ Item { //locale.digitSet = DigitSet.EasternArabicIndicDigits - //The encoding property takes its value from encodingMib property, and the encodingMib property - //is read-only so there is no need for me to change its value. - for (var i in locale.encoding) { - console.log("encoding:" + locale.encoding[i]) - } - //the language property is read-only console.log("language:" + locale.language) @@ -144,18 +140,33 @@ Item { console.log("workingWeekStartDay:" + locale.workingWeekEndDay) console.log("use12Clock:" + locale.use12Clock) - print("before static") - //TODO the plasmoid seg faults - /*console.log("the defaultLanguage:" + locale.defaultLanguage) - console.log("the defaultCountry:" + locale.defaultCountry) + console.log("defaultLanguage:" + locale.defaultLanguage) - console.log("the defaultCurrencyCode:" + locale.defaultCurrencyCode) + console.log("defaultCountry:" + locale.defaultCountry) - console.log("the useTranscript:" + locale.useTranscript) + console.log("defaultCurrencyCode:" + locale.defaultCurrencyCode) + + /*console.log("the useTranscript:" + locale.useTranscript) console.log("the encodingMib:" + locale.encodingMib)*/ + for (var i in locale.languageList()) { + console.log("languageList:" + locale.languageList()[i]) + } + + for (var i in locale.currencyCodeList()) { + console.log("currencyCodeList:" + locale.currencyCodeList()[i]) + } + + for (var i in locale.installedLanguages()) { + console.log("installedLanguages:" + locale.installedLanguages()[i]) + } + + for (var i in locale.allCountriesList()) { + console.log("allCountriesList:" + locale.allCountriesList()[i]) + } + console.log("===========end===========") } } @@ -255,11 +266,6 @@ Item { console.log("the digitSet property has been changed") } - encoding: encodingMib - onEncodingChanged: { - console.log("the digitSet property has been changed") - } - measureSystem: MeasureSystem.Metric onMeasureSystemChanged: { console.log("the measureSystem property has been changed") @@ -370,10 +376,6 @@ Item { console.log("the useTranscript property has been changed") } - onEncodingMibChanged: { - console.log("the encodingMib property has been changed") - } - onCountryChanged: { console.log("the country property has been changed") } @@ -381,7 +383,7 @@ Item { onLanguageChanged: { console.log("the language property has been changed") } - } + } CalendarSystem { id: calendar From 860d8ed68fc3d5517d57ea598e0646ba857f4fdf Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 1 Mar 2012 11:06:21 +0200 Subject: [PATCH 066/104] Make fileEncodingMib a property instead of a Q_INVOKABLE --- declarativeimports/locale/locale.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 21876a00a..d75a765df 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -115,6 +115,7 @@ Q_PROPERTY(QString defaultLanguage READ defaultLanguage NOTIFY defaultLanguageCh Q_PROPERTY(QString defaultCountry READ defaultCountry NOTIFY defaultCountryChanged)//read-only Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode NOTIFY defaultCurrencyCodeChanged)//read-only Q_PROPERTY(bool useTranscript READ useTranscript NOTIFY useTranscriptChanged) //read-only +Q_PROPERTY(int fileEncodingMib READ fileEncodingMib NOTIFY fileEncodingMibChanged) //read-only public: /** @@ -783,7 +784,7 @@ public: * @return The date and time as a string */ Q_INVOKABLE QString formatDateTime(const KDateTime &dateTime, DateFormat format = ShortDate, - DateTimeFormatOptions options = 0) const; + DateTimeFormatOptions options = 0) const;//TODO /** * Use this to determine whether in dates a possessive form of month @@ -1164,7 +1165,7 @@ public: * * @see currencyCodeToName */ - Q_INVOKABLE QStringList currencyCodeList() const; //TODO + Q_INVOKABLE QStringList currencyCodeList() const; /** * Returns the file encoding. @@ -1174,7 +1175,7 @@ public: * @see QFile::encodeName * @see QFile::decodeName */ - Q_INVOKABLE int fileEncodingMib() const; + int fileEncodingMib() const; /** * Changes the current date format. @@ -1521,7 +1522,7 @@ public: * @see languageCodeToName * @see installedLanguages */ - Q_INVOKABLE QStringList allLanguagesList() const; //TODO + Q_INVOKABLE QStringList allLanguagesList() const; /** * @@ -1534,7 +1535,7 @@ public: * * @see languageCodeToName */ - Q_INVOKABLE QStringList installedLanguages() const; //TODO + Q_INVOKABLE QStringList installedLanguages() const; /** * Convert a known language code to a human readable, localized form. @@ -1564,7 +1565,7 @@ public: * * @see countryCodeToName */ - Q_INVOKABLE QStringList allCountriesList() const; //TODO + Q_INVOKABLE QStringList allCountriesList() const; /** * Convert a known country code to a human readable, localized form. @@ -1593,7 +1594,7 @@ public: * @param charset set to the charset part of the locale */ Q_INVOKABLE static void splitLocale(const QString &locale, QString &language, QString &country, - QString &modifier, QString &charset); + QString &modifier, QString &charset); //TODO /** * Use this as main catalog for *all* KLocales, if not the appname @@ -1683,7 +1684,7 @@ public: * * @return path to the localized file if found, original path otherwise */ - Q_INVOKABLE QString localizedFilePath(const QString &filePath) const; + Q_INVOKABLE QString localizedFilePath(const QString &filePath) const;//TODO remove /** * @@ -1771,6 +1772,7 @@ Q_SIGNALS: void defaultCurrencyCodeChanged(); void defaultLanguageChanged(); void useTranscriptChanged(); + void fileEncodingMibChanged(); }; //TODO remove the above? //Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) From 557e476c05546be3665be0cae709e9e6346a8de9 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 1 Mar 2012 12:32:01 +0200 Subject: [PATCH 067/104] Make languageList, currencyCodeList, installedLanguages, allCountriesList properties instead of Q_INVOKABLE --- declarativeimports/locale/locale.h | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index d75a765df..52b4de361 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -116,6 +116,11 @@ Q_PROPERTY(QString defaultCountry READ defaultCountry NOTIFY defaultCountryChang Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode NOTIFY defaultCurrencyCodeChanged)//read-only Q_PROPERTY(bool useTranscript READ useTranscript NOTIFY useTranscriptChanged) //read-only Q_PROPERTY(int fileEncodingMib READ fileEncodingMib NOTIFY fileEncodingMibChanged) //read-only +Q_PROPERTY(QStringList languageList READ languageList NOTIFY languageListChanged) //read-only +Q_PROPERTY(QStringList currencyCodeList READ currencyCodeList NOTIFY currencyCodeListChanged) //read-only +Q_PROPERTY(QStringList allLanguagesList READ allLanguagesList NOTIFY allLanguagesListChanged) //read-only +Q_PROPERTY(QStringList installedLanguages READ installedLanguages NOTIFY installedLanguagesChanged) //read-only +Q_PROPERTY(QStringList allCountriesList READ allCountriesList NOTIFY allCountriesListChanged) //read-only public: /** @@ -1151,7 +1156,7 @@ public: * * @see languageCodeToName */ - Q_INVOKABLE QStringList languageList() const; //TODO + QStringList languageList() const; /** * @@ -1165,7 +1170,7 @@ public: * * @see currencyCodeToName */ - Q_INVOKABLE QStringList currencyCodeList() const; + QStringList currencyCodeList() const; /** * Returns the file encoding. @@ -1522,7 +1527,7 @@ public: * @see languageCodeToName * @see installedLanguages */ - Q_INVOKABLE QStringList allLanguagesList() const; + QStringList allLanguagesList() const; /** * @@ -1535,7 +1540,7 @@ public: * * @see languageCodeToName */ - Q_INVOKABLE QStringList installedLanguages() const; + QStringList installedLanguages() const; /** * Convert a known language code to a human readable, localized form. @@ -1565,7 +1570,7 @@ public: * * @see countryCodeToName */ - Q_INVOKABLE QStringList allCountriesList() const; + QStringList allCountriesList() const; /** * Convert a known country code to a human readable, localized form. @@ -1773,10 +1778,11 @@ Q_SIGNALS: void defaultLanguageChanged(); void useTranscriptChanged(); void fileEncodingMibChanged(); + void languageListChanged(); + void currencyCodeListChanged(); + void allLanguagesListChanged(); + void installedLanguagesChanged(); + void allCountriesListChanged(); }; -//TODO remove the above? -//Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::DateTimeFormatOptions) -//Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::TimeFormatOptions) -//Q_DECLARE_OPERATORS_FOR_FLAGS(Locale::TimeProcessingOptions) #endif From 1e8340601b937fb8dda837095baead7eee4ed456 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 1 Mar 2012 12:33:58 +0200 Subject: [PATCH 068/104] Populate the klocaleqmltest.qml --- .../tests/contents/code/klocaleqmltest.qml | 74 +++++++++++++++++-- 1 file changed, 66 insertions(+), 8 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index f40c56517..1e6fc650e 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -151,22 +151,60 @@ Item { console.log("the encodingMib:" + locale.encodingMib)*/ - for (var i in locale.languageList()) { - console.log("languageList:" + locale.languageList()[i]) + for (var i in locale.languageList) { + console.log("languageList:" + locale.languageList[i]) } - for (var i in locale.currencyCodeList()) { - console.log("currencyCodeList:" + locale.currencyCodeList()[i]) + for (var i in locale.currencyCodeList) { + console.log("currencyCodeList:" + locale.currencyCodeList[i]) } - for (var i in locale.installedLanguages()) { - console.log("installedLanguages:" + locale.installedLanguages()[i]) + for (var i in locale.installedLanguages) { + console.log("installedLanguages:" + locale.installedLanguages[i]) } - for (var i in locale.allCountriesList()) { - console.log("allCountriesList:" + locale.allCountriesList()[i]) + for (var i in locale.allCountriesList) { + console.log("allCountriesList:" + locale.allCountriesList[i]) } + console.log("formatDate:" + locale.formatDate("2010-05-05")) + + console.log("formatDateTime:" + locale.formatDateTime("2010-05-05"))//TODO try if the enums are working. + + console.log("formatMoney:" + locale.formatMoney(10)) + + console.log("formatLong:" + locale.formatLong(10)) + + console.log("formatByteSize:" + locale.formatByteSize(10)) + + console.log("formatDuration:" + locale.formatDuration(10)) + + console.log("prettyFormatDuration:" + locale.prettyFormatDuration(10)) + + console.log("formatLocaleTime:" + locale.formatLocaleTime("2010-05-05")) + + console.log("dayPeriodText:" + locale.dayPeriodText("2010-05-05")) + + console.log("readMoney:" + locale.readMoney("one"))//TODO + + console.log("readNumber:" + locale.readNumber("one"))//TODO + + console.log("readDate:" + locale.readDate("one"))//TODO + + console.log("readTime:" + locale.readTime("one"))//TODO + + console.log("readLocaleTime:" + locale.readLocaleTime("one"))//TODO + + console.log("fileEncodingMib:" + locale.fileEncodingMib) + + console.log("languageCodeToName:" + locale.languageCodeToName("en_US")) + + console.log("isApplicationTranslatedInto:" + locale.isApplicationTranslatedInto("en_US")) + + console.log("removeAcceleratorMarker:" + locale.removeAcceleratorMarker("&*hello"))//TODO + + //console.log("convertDigits:" + locale.convertDigits) TODO + console.log("===========end===========") } } @@ -383,6 +421,26 @@ Item { onLanguageChanged: { console.log("the language property has been changed") } + + onFileEncodingMibChanged: { + console.log("the fileEncodingMib property has been changed") + } + + onLanguageListChanged: { + console.log("the languageList property has been changed") + } + + onCurrencyCodeListChanged: { + console.log("the currencyCodeList property has been changed") + } + + onInstalledLanguagesChanged: { + console.log("the installedLanguages property has been changed") + } + + onAllCountriesListChanged: { + console.log("the allCountriesList property has been changed") + } } CalendarSystem { From 3025342e00fbdf68152390a8d5e5c191a3fe8f30 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 1 Mar 2012 15:20:43 +0200 Subject: [PATCH 069/104] Fix the enums in klocaleqmltest --- .../tests/contents/code/klocaleqmltest.qml | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 1e6fc650e..bd6db7c3b 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -56,19 +56,18 @@ Item { console.log("=====Locale Component====") console.log("country:" + locale.country) - // locale.binaryUnitDialect = Locale.BinaryUnitDialect.IECBinaryDialect - // locale.calendarSystem = CalendarSystem.CopticCalendar + locale.binaryUnitDialect = Locale.IECBinaryDialect + locale.calendarSystem = Locale.CopticCalendar locale.countryDivisionCode = "AL" console.log("countryDivisionCode:" + locale.countryDivisionCode) - //locale.currencyCode = "AFN" //TODO add the right value - //console.log("currencyCode:" + locale.currencyCode) + console.log("currencyCode:" + locale.currencyCode) - //locale.currencySymbol = TODO - //console.log("currencySymbol" + locale.currencySymbol) + locale.currencySymbol = "$" + console.log("currencySymbol:" + locale.currencySymbol) - //locale.dateTimeDigitSet = DigitSet.EasternArabicIndicDigits + locale.dateTimeDigitSet = Locale.EasternArabicIndicDigits locale.dateFormat = "Y" console.log("dateFormat:" + locale.dateFormat) @@ -85,12 +84,11 @@ Item { locale.decimalSymbol = "." console.log("decimalSymbol:" + locale.decimalSymbol) - //locale.digitSet = DigitSet.EasternArabicIndicDigits + locale.digitSet = Locale.EasternArabicIndicDigits - //the language property is read-only console.log("language:" + locale.language) - //locale.measureSystem = MeasureSystem.Imperial + locale.measureSystem = Locale.Imperial locale.monetaryDecimalPlaces = 3 console.log("monetaryDecimalPlaces:" + locale.monetaryDecimalPlaces) @@ -98,12 +96,12 @@ Item { locale.monetaryDecimalSymbol = "." console.log("monetaryDecimalSymbol:" + locale.monetaryDecimalSymbol) - //locale.monetaryDigitSet = DigitSet.EasternArabicIndicDigits + locale.monetaryDigitSet = Locale.EasternArabicIndicDigits locale.monetaryThousandsSeparator = "." console.log("monetaryThousandsSeparator:" + locale.monetaryThousandsSeparator) - //locale.negativeMonetarySignPosition = SignPosition.AfterMoney + locale.negativeMonetarySignPosition = Locale.AfterMoney locale.negativePrefixCurrencySymbol = false console.log("negativePrefixCurrencySymbol:" + locale.negativePrefixCurrencySymbol) @@ -114,7 +112,7 @@ Item { locale.pageSize = 6 console.log("pageSize:" + locale.pageSize) - //locale.positiveMonetarySignPosition = SignPosition.AfterMoney + locale.positiveMonetarySignPosition = Locale.AfterMoney locale.positivePrefixCurrencySymbol = false console.log("positivePrefixCurrencySymbol:" + locale.positivePrefixCurrencySymbol) @@ -128,7 +126,7 @@ Item { locale.weekDayOfPray = 10 console.log("weekDayOfPray:" + locale.weekDayOfPray) - //locale.weekNumberSystem = WeekNumberSystem.FirstFullWeek + locale.weekNumberSystem = Locale.FirstFullWeek locale.weekStartDay = 3 console.log("weekStartDay:" + locale.weekStartDay) @@ -147,9 +145,9 @@ Item { console.log("defaultCurrencyCode:" + locale.defaultCurrencyCode) - /*console.log("the useTranscript:" + locale.useTranscript) + console.log("the useTranscript:" + locale.useTranscript) - console.log("the encodingMib:" + locale.encodingMib)*/ + console.log("the encodingMib:" + locale.encodingMib) for (var i in locale.languageList) { console.log("languageList:" + locale.languageList[i]) @@ -169,7 +167,7 @@ Item { console.log("formatDate:" + locale.formatDate("2010-05-05")) - console.log("formatDateTime:" + locale.formatDateTime("2010-05-05"))//TODO try if the enums are working. + console.log("formatDateTime:" + locale.formatDateTime("2010-05-05")) console.log("formatMoney:" + locale.formatMoney(10)) @@ -242,7 +240,8 @@ Item { Locale { id: locale - binaryUnitDialect: BinaryUnitDialect.DefaultBinaryDialect + //TODO enums with negative value(like -1) doesn't work in QML! + binaryUnitDialect: Locale.IECBinaryDialect onBinaryUnitDialectChanged: { console.log("the binaryUnitDialect property has been changed") } @@ -252,17 +251,14 @@ Item { console.log("the calendarSystem property has been changed") } - //TODO:Add the proper value - /*currencyCode: "AED" onCurrencyCodeChanged: { console.log("the currencyCode property has been changed") - }*/ + } - /*TODO - currencySymbol: "" + currencySymbol: "$" onCurrencySymbolChanged: { console.log("the currencySymbol property has been changed") - }*/ + } countryDivisionCode: "AD" onCountryDivisionCodeChanged: { @@ -284,7 +280,7 @@ Item { console.log("the dateMonthNamePossessive property has been changed") } - dateTimeDigitSet: Digit.ArabicDigits + dateTimeDigitSet: Locale.ArabicDigits onDateTimeDigitSetChanged: { console.log("the dateTimeDigitSet property has been changed") } @@ -299,12 +295,12 @@ Item { console.log("the decimalSymbol property has been changed") } - digitSet: Digit.ArabicDigits + digitSet: Locale.ArabicDigits onDigitSetChanged: { console.log("the digitSet property has been changed") } - measureSystem: MeasureSystem.Metric + measureSystem: Locale.Metric onMeasureSystemChanged: { console.log("the measureSystem property has been changed") } @@ -319,7 +315,7 @@ Item { console.log("the monetaryDecimalSymbol property has been changed") } - monetaryDigitSet: DigitSet.ArabicDigits + monetaryDigitSet: Locale.ArabicDigits onMonetaryDigitSetChanged: { console.log("the monetaryDigitSet property has been changed") } @@ -329,7 +325,7 @@ Item { console.log("the monetaryThousandsSeparator property has been changed") } - negativeMonetarySignPosition: SignPosition.ParensAround + negativeMonetarySignPosition: Locale.ParensAround onNegativeMonetarySignPositionChanged: { console.log("the negativeMonetarySignPosition property has been changed") } @@ -349,7 +345,7 @@ Item { console.log("the pageSign property has been changed") } - positiveMonetarySignPosition: SignPosition.ParensAround + positiveMonetarySignPosition: Locale.ParensAround onPositiveMonetarySignPositionChanged: { console.log("the positiveMonetarySignPosition property has been changed") } @@ -374,7 +370,7 @@ Item { console.log("the weekDayOfPray property has been changed") } - weekNumberSystem: WeekNumberSystem.DefaultWeekNumber + weekNumberSystem: Locale.IsoWeekNumber onWeekNumberSystemChanged: { console.log("the weekNumberSystem property has been changed") } From 1118d9ac61ad6d0ed9db4f10c7440e3f7a55d3e1 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 1 Mar 2012 21:59:07 +0200 Subject: [PATCH 070/104] Fix the converDigits method --- .../locale/tests/contents/code/klocaleqmltest.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index bd6db7c3b..9b1c03de9 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -199,9 +199,9 @@ Item { console.log("isApplicationTranslatedInto:" + locale.isApplicationTranslatedInto("en_US")) - console.log("removeAcceleratorMarker:" + locale.removeAcceleratorMarker("&*hello"))//TODO + console.log("removeAcceleratorMarker:" + locale.removeAcceleratorMarker("&*hello")) - //console.log("convertDigits:" + locale.convertDigits) TODO + console.log("convertDigits:" + locale.convertDigits(locale.digitSet, Locale.ArabicDigits)) console.log("===========end===========") } From 9b69f03f5ce7237c345250f057fc22614adb10b0 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Thu, 1 Mar 2012 21:59:43 +0200 Subject: [PATCH 071/104] Make Locale::reparseConfiguration() a Q_INVOKABLE method --- declarativeimports/locale/locale.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 52b4de361..a331d5163 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -1599,7 +1599,7 @@ public: * @param charset set to the charset part of the locale */ Q_INVOKABLE static void splitLocale(const QString &locale, QString &language, QString &country, - QString &modifier, QString &charset); //TODO + QString &modifier, QString &charset); //TODO remove? /** * Use this as main catalog for *all* KLocales, if not the appname @@ -1733,7 +1733,7 @@ public: * Reparse locale configuration files for the current selected * language. */ - void reparseConfiguration(); //TODO + Q_INVOKABLE void reparseConfiguration(); private: KLocale *m_locale; From f2f9fc8fe71ab38188783de8c990c40f464f0729 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sat, 3 Mar 2012 17:03:49 +0200 Subject: [PATCH 072/104] Fix locale.readMoney, locale.readDate,readLocalTime --- .../locale/tests/contents/code/klocaleqmltest.qml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 9b1c03de9..ed66bfd06 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -183,15 +183,15 @@ Item { console.log("dayPeriodText:" + locale.dayPeriodText("2010-05-05")) - console.log("readMoney:" + locale.readMoney("one"))//TODO + console.log("readMoney:" + locale.readMoney("$ 21")) - console.log("readNumber:" + locale.readNumber("one"))//TODO + console.log("readNumber:" + locale.readNumber("12,100"))//TODO - console.log("readDate:" + locale.readDate("one"))//TODO + console.log("readDate:" + locale.readDate("2004-02-01")) - console.log("readTime:" + locale.readTime("one"))//TODO + console.log("readTime:" + locale.readTime("11:22:33"))//TODO - console.log("readLocaleTime:" + locale.readLocaleTime("one"))//TODO + console.log("readLocaleTime:" + locale.readLocaleTime("11:12:13 AM")) console.log("fileEncodingMib:" + locale.fileEncodingMib) From 46c6da3534344786a3d6140ae09debb887a9038f Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Wed, 7 Mar 2012 04:36:08 +0200 Subject: [PATCH 073/104] Add more unit tests --- declarativeimports/locale/CMakeLists.txt | 2 +- declarativeimports/locale/calendarsystem.cpp | 23 ---- declarativeimports/locale/calendarsystem.h | 104 +++++------------- .../tests/contents/code/klocaleqmltest.qml | 72 ++++++++++++ 4 files changed, 98 insertions(+), 103 deletions(-) diff --git a/declarativeimports/locale/CMakeLists.txt b/declarativeimports/locale/CMakeLists.txt index 5245a7b17..59ab9e4b4 100644 --- a/declarativeimports/locale/CMakeLists.txt +++ b/declarativeimports/locale/CMakeLists.txt @@ -20,7 +20,7 @@ qt4_automoc(${localebindings_SRCS}) kde4_add_library(localebindingsplugin SHARED ${localebindings_SRCS}) #FIXME #Should i put something? -target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KDECORE_LIBRARY}) +target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KDECORE_LIBRARY} ${KDE4_KDECORE_INCLUDES}) install(TARGETS localebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 9b5015882..1242ae778 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -120,29 +120,6 @@ bool CalendarSystem::isValid(const QDate &date) const return m_calendarSystem->isValid(date); } -bool CalendarSystem::setDate(QDate &date, int year, int month, int day) const -{ - return m_calendarSystem->setDate(date, year, month, day); -} - -// NOT VIRTUAL - If override needed use shared-d -bool CalendarSystem::setDate(QDate &date, int year, int dayOfYear) const -{ - return m_calendarSystem->setDate(date, year, dayOfYear); -} - -// NOT VIRTUAL - If override needed use shared-d -bool CalendarSystem::setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const -{ - return m_calendarSystem->setDate(date, eraName, yearInEra, month, day); -} - -// NOT VIRTUAL - If override needed use shared-d -bool CalendarSystem::setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const -{ - return m_calendarSystem->setDateIsoWeek(date, year, isoWeekNumber, dayOfIsoWeek); -} - // NOT VIRTUAL - If override needed use shared-d void CalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const { diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index c52d84588..b4ac31069 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -238,61 +238,7 @@ public: * @param date the date to check * @return @c true if the date is valid, @c false otherwise */ - Q_INVOKABLE virtual bool isValid(const QDate &date) const; - - /** - * Changes the date's year, month and day. The range of the year, month - * and day depends on which calendar is being used. All years entered - * are treated literally, i.e. no Y2K translation is applied to years - * entered in the range 00 to 99. Replaces setYMD. - * - * @param date date to change - * @param year year - * @param month month number - * @param day day of month - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE virtual bool setDate(QDate &date, int year, int month, int day) const; - - //KDE5 make virtual? - /** - * - * Set a date using the year number and day of year number only. - * - * @param date date to change - * @param year year - * @param dayOfYear day of year - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE bool setDate(QDate &date, int year, int dayOfYear) const; - - //KDE5 make virtual? - /** - * - * Set a date using the era, year in era number, month and day - * - * @param date date to change - * @param eraName Era string - * @param yearInEra Year In Era number - * @param month Month number - * @param day Day Of Month number - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE bool setDate(QDate &date, QString eraName, int yearInEra, int month, int day) const; - - //KDE5 make virtual? - /** - * - * Set a date using the year number, ISO week number and day of week number. - * - * @param date date to change - * @param year year - * @param isoWeekNumber ISO week of year - * @param dayOfIsoWeek day of week Mon..Sun (1..7) - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE bool setDateIsoWeek(QDate &date, int year, int isoWeekNumber, int dayOfIsoWeek) const; - + Q_INVOKABLE bool isValid(const QDate &date) const; //KDE5 make virtual? /** @@ -304,7 +250,7 @@ public: * @param month month number returned in this variable * @param day day of month returned in this variable */ - Q_INVOKABLE void getDate(const QDate date, int *year, int *month, int *day) const; + Q_INVOKABLE void getDate(const QDate date, int *year, int *month, int *day) const;//TODO should it be part of the QML Wrapper? /** * Returns the year portion of a given date in the current calendar system @@ -312,7 +258,7 @@ public: * @param date date to return year for * @return year, 0 if input date is invalid */ - Q_INVOKABLE virtual int year(const QDate &date) const; + Q_INVOKABLE int year(const QDate &date) const; /** * Returns the month portion of a given date in the current calendar system @@ -320,7 +266,7 @@ public: * @param date date to return month for * @return month of year, 0 if input date is invalid */ - Q_INVOKABLE virtual int month(const QDate &date) const; + Q_INVOKABLE int month(const QDate &date) const; /** * Returns the day portion of a given date in the current calendar system @@ -328,7 +274,7 @@ public: * @param date date to return day for * @return day of the month, 0 if input date is invalid */ - Q_INVOKABLE virtual int day(const QDate &date) const; + Q_INVOKABLE int day(const QDate &date) const; //KDE5 make virtual? /** @@ -372,7 +318,7 @@ public: * @param nyears The number of years to add * @return The new date, null date if any errors */ - Q_INVOKABLE virtual QDate addYears(const QDate &date, int nyears) const; + Q_INVOKABLE QDate addYears(const QDate &date, int nyears) const; /** * Returns a QDate containing a date @p nmonths months later. @@ -381,7 +327,7 @@ public: * @param nmonths number of months to add * @return The new date, null date if any errors */ - Q_INVOKABLE virtual QDate addMonths(const QDate &date, int nmonths) const; + Q_INVOKABLE QDate addMonths(const QDate &date, int nmonths) const; /** * Returns a QDate containing a date @p ndays days later. @@ -390,7 +336,7 @@ public: * @param ndays number of days to add * @return The new date, null date if any errors */ - Q_INVOKABLE virtual QDate addDays(const QDate &date, int ndays) const; + Q_INVOKABLE QDate addDays(const QDate &date, int ndays) const; //KDE5 make virtual? /** @@ -412,7 +358,7 @@ public: * @param direction Returns direction of difference, 1 if fromDate <= toDate, -1 otherwise */ Q_INVOKABLE void dateDifference(const QDate &fromDate, const QDate &toDate, - int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const; + int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;//TODO Does it work? //KDE5 make virtual? /** @@ -459,7 +405,7 @@ public: * @param date the date to obtain year from * @return number of months in the year, -1 if input date invalid */ - Q_INVOKABLE virtual int monthsInYear(const QDate &date) const; + Q_INVOKABLE int monthsInYear(const QDate &date) const; //KDE5 make virtual? /** @@ -477,7 +423,7 @@ public: * @param date the date to obtain year from * @return number of weeks in the year, -1 if input date invalid */ - Q_INVOKABLE virtual int weeksInYear(const QDate &date) const; + Q_INVOKABLE int weeksInYear(const QDate &date) const; //KDE5 Merge with virtual weeksInYear with default /** @@ -501,7 +447,7 @@ public: * @param year the year * @return number of weeks in the year, -1 if input date invalid */ - Q_INVOKABLE virtual int weeksInYear(int year) const; + Q_INVOKABLE int weeksInYear(int year) const; //KDE5 Merge with virtual weeksInYear with default /** @@ -525,7 +471,7 @@ public: * @param date the date to obtain year from * @return number of days in year, -1 if input date invalid */ - Q_INVOKABLE virtual int daysInYear(const QDate &date) const; + Q_INVOKABLE int daysInYear(const QDate &date) const; //KDE5 make virtual? /** @@ -543,7 +489,7 @@ public: * @param date the date to obtain month from * @return number of days in month, -1 if input date invalid */ - Q_INVOKABLE virtual int daysInMonth(const QDate &date) const; + Q_INVOKABLE int daysInMonth(const QDate &date) const; //KDE5 make virtual? /** @@ -562,7 +508,7 @@ public: * @param date the date to obtain week from * @return number of days in week, -1 if input date invalid */ - Q_INVOKABLE virtual int daysInWeek(const QDate &date) const; + Q_INVOKABLE int daysInWeek(const QDate &date) const; /** * Returns the day number of year for the given date @@ -572,7 +518,7 @@ public: * @param date the date to obtain day from * @return day of year number, -1 if input date not valid */ - Q_INVOKABLE virtual int dayOfYear(const QDate &date) const; + Q_INVOKABLE int dayOfYear(const QDate &date) const; /** * Returns the weekday number for the given date @@ -584,7 +530,7 @@ public: * @param date the date to obtain day from * @return day of week number, -1 if input date not valid */ - Q_INVOKABLE virtual int dayOfWeek(const QDate &date) const; + Q_INVOKABLE int dayOfWeek(const QDate &date) const; //KDE5 Make virtual? /** @@ -649,7 +595,7 @@ public: * @param date the date to check * @return @c true if the date falls in a leap year, @c false otherwise */ - Q_INVOKABLE virtual bool isLeapYear(const QDate &date) const; + Q_INVOKABLE bool isLeapYear(const QDate &date) const; //KDE5 Make virtual? /** @@ -753,7 +699,7 @@ public: * @param format specifies whether the short month name or long month name should be used * @return name of the month, empty string if any error */ - Q_INVOKABLE virtual QString monthName(const QDate &date, MonthNameFormat format = LongName) const; + Q_INVOKABLE QString monthName(const QDate &date, MonthNameFormat format = LongName) const; /** * Gets specific calendar type week day name. @@ -772,7 +718,7 @@ public: * @param format specifies whether the short month name or long month name should be used * @return day name, empty string if any error */ - Q_INVOKABLE virtual QString weekDayName(const QDate &date, WeekDayNameFormat format = LongDayName) const; + Q_INVOKABLE QString weekDayName(const QDate &date, WeekDayNameFormat format = LongDayName) const; /** * Returns a string formatted to the current locale's conventions @@ -790,7 +736,7 @@ public: * * @return The date as a string */ - Q_INVOKABLE virtual QString formatDate(const QDate &fromDate, Locale::DateFormat toFormat = Locale::LongDate) const; + Q_INVOKABLE QString formatDate(const QDate &fromDate, Locale::DateFormat toFormat = Locale::LongDate) const; //KDE5 Make virtual /** @@ -968,7 +914,7 @@ public: * * @return the string converted to a QDate */ - Q_INVOKABLE virtual QDate readDate(const QString &str, bool *ok = 0) const; + Q_INVOKABLE QDate readDate(const QString &str, bool *ok = 0) const; /** * Converts a localized date string to a QDate. @@ -988,7 +934,7 @@ public: * * @return the string converted to a QDate */ - Q_INVOKABLE virtual QDate readDate(const QString &str, Locale::ReadDateFlags flags, bool *ok = 0) const; + Q_INVOKABLE QDate readDate(const QString &str, Locale::ReadDateFlags flags, bool *ok = 0) const; /** * Converts a localized date string to a QDate, using the specified @p format. @@ -1003,7 +949,7 @@ public: * @see formatDate * @see Locale::readDate */ - Q_INVOKABLE virtual QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok = 0) const; + Q_INVOKABLE QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok = 0) const; //KDE5 Make virtual /** @@ -1129,7 +1075,7 @@ public: * * @return an integer (Monday = 1, ..., Sunday = 7) */ - virtual int weekStartDay() const; + int weekStartDay() const; /** * Returns whether the calendar is lunar based. diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index ed66bfd06..3fae6c71c 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -233,6 +233,78 @@ Item { console.log("isSolar:" + calendar.isSolar) console.log("isProleptic:" + calendar.isProleptic) + //Q_INVOKABLE methods + console.log("isValid:" + calendar.isValid(2012, 02, 03)) + + console.log("isValid:" + calendar.isValid(2012, 33)) + + //console.log("isValid:" + calendar.isValid(QString &eraName, int yearInEra, int month, int day)) TODO + + console.log("isValidIsoWeekDate:" + calendar.isValidIsoWeekDate(2012, 2, 3) + + console.log("isValid:" + calendar.isValid("2012-02-03")) + + console.log("year:" + calendar.year("2012-02-03")) + + console.log("month:" + calendar.month("2012-02-03")) + + console.log("day:" + calendar.day("2012-02-03")) + + console.log("eraName:" + calendar.eraName("2012-02-03")) + + console.log("eraYear:" + calendar.eraYear("2012-02-03")) + + console.log("yearInEra:" + calendar.yearInEra("2012-02-03")) + + console.log("addYears:" + calendar.addYears("2012-02-03", 3)) + + console.log("addMonthss:" + calendar.addMonths("2012-02-03", 3)) + + console.log("addDays:" + calendar.addDays("2012-02-03", 3)) + + console.log("yearsDifference:" + calendar.yearsDifference("2010-02-03", "2012-02-03")) + + console.log("monthsDifference:" + calendar.monthsDifference("2012-02-03", "2012-04-03")) + + console.log("daysDifference:" + calendar.daysDifference("2012-02-03", "2012-02-13")) + + console.log("monthsInYear:" + calendar.monthsInYear("2012-02-03")) + + console.log("monthsInYear:" + calendar.monthsInYear(2012)) + + console.log("weeksInYear:" + calendar.weeksInYear("2012-02-03")) + + console.log("weeksInYear:" + calendar.weeksInYear(2012)) + + console.log("daysInYear:" + calendar.daysInYear("2012-02-03")) + + console.log("daysInMonth:" + calendar.daysInMonth("2012-02-03")) + + console.log("daysInWeek:" + calendar.daysInWeek("2012-02-03")) + + console.log("dayOfYear:" + calendar.dayOfYear("2012-02-03")) + + console.log("week:" + calendar.week("2012-02-03")) + + console.log("isLeapYear:" + calendar.isLeapYear(2012)) + + console.log("firstDayOfYear:" + calendar.firstDayOfYear(2012)) + + console.log("lastDayOfYear:" + calendar.lastDayOfYear(2012)) + + console.log("firstDayOfMonth:" + calendar.firstDayOfMonth(2012, 02)) + + console.log("lastDayOfMonth:" + calendar.lastDayOfMonth(2012, 02)) + + console.log("monthName:" + calendar.monthName(02, 2012)) + + console.log("weekDayName:" + calendar.weekDayName(3)) + + console.log("formatDate:" + calendar.formatDate("2012-02-03")) + + console.log("readDate:" + calendar.readDate("2012-02-03"))//TODO does it work? + + console.log("applyShortYearWindow:" + calendar.applyShortYearWindow(120))//TODO does it work? console.log("===============end===============") } From 4d40a7dd92e2708910decc1112d8a0d4c86bae7f Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Fri, 9 Mar 2012 10:20:09 +0200 Subject: [PATCH 074/104] Rename KCalendarSystem to CalendarSystem on Api --- declarativeimports/locale/calendarsystem.h | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index b4ac31069..2749971a9 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -27,11 +27,11 @@ #include #include -class KCalendarSystem; +class CalendarSystem; class KCalendarEra; /** - * KCalendarSystem abstract base class, provides support for local Calendar Systems in KDE + * CalendarSystem abstract base class, provides support for local Calendar Systems in KDE * * Derived classes must be created through the create() static method */ @@ -132,7 +132,7 @@ public: /** * - * Returns the Calendar System type of the KCalendarSystem object + * Returns the Calendar System type of the CalendarSystem object * * @return type of calendar system */ @@ -155,10 +155,10 @@ public: * or the calendar system may be proleptic in which case it supports dates * before the epoch. * - * @see KCalendarSystem::earliestValidDate - * @see KCalendarSystem::latestValidDate - * @see KCalendarSystem::isProleptic - * @see KCalendarSystem::isValid + * @see CalendarSystem::earliestValidDate + * @see CalendarSystem::latestValidDate + * @see CalendarSystem::isProleptic + * @see CalendarSystem::isValid * * @return epoch of calendar system */ @@ -169,8 +169,8 @@ public: * * If the calendar system is proleptic then this may be before epoch. * - * @see KCalendarSystem::epoch - * @see KCalendarSystem::latestValidDate + * @see CalendarSystem::epoch + * @see CalendarSystem::latestValidDate * * @return date the earliest valid date */ @@ -179,8 +179,8 @@ public: /** * Returns the latest date valid in this calendar system implementation. * - * @see KCalendarSystem::epoch - * @see KCalendarSystem::earliestValidDate + * @see CalendarSystem::epoch + * @see CalendarSystem::earliestValidDate * * @return date the latest valid date */ @@ -1102,7 +1102,7 @@ public: * Returns whether the calendar system is proleptic, i.e. whether dates * before the epoch are supported. * - * @see KCalendarSystem::epoch + * @see CalendarSystem::epoch * * @return @c true if the calendar system is proleptic, @c false if not */ From b3c089f51c26ac953e3266ca4bd67fd5a627b8aa Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Fri, 9 Mar 2012 13:25:25 +0200 Subject: [PATCH 075/104] Fix the comments and a typo. --- declarativeimports/locale/calendarsystem.cpp | 45 +++---------------- declarativeimports/locale/calendarsystem.h | 2 +- declarativeimports/locale/locale.h | 29 +++--------- .../tests/contents/code/klocaleqmltest.qml | 8 ++-- 4 files changed, 17 insertions(+), 67 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 1242ae778..abe15d9b6 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -32,7 +32,6 @@ CalendarSystem::CalendarSystem(QObject* parent) m_calendarSystem = KCalendarSystem::create(KGlobal::locale()->calendarSystem()); } - QList CalendarSystem::calendarSystemsList() { QList list; @@ -60,20 +59,17 @@ Locale::CalendarSystem CalendarSystem::calendarSystem(const QString &calendarTyp return (Locale::CalendarSystem)KCalendarSystem::calendarSystem(calendarType); } -// NOT VIRTUAL - If override needed use shared-d Locale::CalendarSystem CalendarSystem::calendarSystem() const { return (Locale::CalendarSystem)m_calendarSystem->calendarSystem(); } -// NOT VIRTUAL - If override needed use shared-d + QString CalendarSystem::calendarLabel() const { return m_calendarSystem->calendarLabel(); } -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System QDate CalendarSystem::epoch() const { return m_calendarSystem->epoch(); @@ -84,8 +80,6 @@ QDate CalendarSystem::earliestValidDate() const return epoch(); } -// Dummy version using Gregorian as an example -// This method MUST be re-implemented in any new Calendar System QDate CalendarSystem::latestValidDate() const { // Default to Gregorian 9999-12-31 @@ -97,19 +91,18 @@ bool CalendarSystem::isValid(int year, int month, int day) const return m_calendarSystem->isValid(year, month, day); } -// NOT VIRTUAL - If override needed use shared-d + bool CalendarSystem::isValid(int year, int dayOfYear) const { return m_calendarSystem->isValid(year, dayOfYear); } -// NOT VIRTUAL - If override needed use shared-d + bool CalendarSystem::isValid(const QString &eraName, int yearInEra, int month, int day) const { return m_calendarSystem->isValid(eraName, yearInEra, month, day); } -// NOT VIRTUAL - If override needed use shared-d bool CalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const { return m_calendarSystem->isValidIsoWeekDate(year, isoWeekNumber, dayOfIsoWeek); @@ -120,7 +113,6 @@ bool CalendarSystem::isValid(const QDate &date) const return m_calendarSystem->isValid(date); } -// NOT VIRTUAL - If override needed use shared-d void CalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const { return m_calendarSystem->getDate(date, year, month, day); @@ -141,19 +133,17 @@ int CalendarSystem::day(const QDate &date) const return m_calendarSystem->day(date); } -// NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::eraName(const QDate &date, StringFormat format) const { return m_calendarSystem->eraName(date, (KCalendarSystem::StringFormat)format); } -// NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::eraYear(const QDate &date, StringFormat format) const { return m_calendarSystem->eraYear(date, (KCalendarSystem::StringFormat)format); } -// NOT VIRTUAL - If override needed use shared-d + int CalendarSystem::yearInEra(const QDate &date) const { return m_calendarSystem->yearInEra(date); @@ -174,26 +164,22 @@ QDate CalendarSystem::addDays(const QDate &date, int numDays) const return m_calendarSystem->addDays(date, numDays); } -// NOT VIRTUAL - Uses shared-d instead void CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate, int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const { return m_calendarSystem->dateDifference(fromDate, toDate, yearsDiff, monthsDiff, daysDiff, direction); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const { return m_calendarSystem->yearsDifference(fromDate, toDate); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::monthsDifference(const QDate &fromDate, const QDate &toDate) const { return m_calendarSystem->monthsDifference(fromDate, toDate); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) const { return m_calendarSystem->daysDifference(fromDate, toDate); @@ -204,7 +190,6 @@ int CalendarSystem::monthsInYear(const QDate &date) const return m_calendarSystem->monthsInYear(date); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::monthsInYear(int year) const { return m_calendarSystem->monthsInYear(year); @@ -220,13 +205,11 @@ int CalendarSystem::weeksInYear(int year) const return weeksInYear(year, Locale::DefaultWeekNumber); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::weeksInYear(const QDate &date, Locale::WeekNumberSystem weekNumberSystem) const { return m_calendarSystem->weeksInYear(date, (KLocale::WeekNumberSystem)weekNumberSystem); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const { return m_calendarSystem->weeksInYear(year, (KLocale::WeekNumberSystem)weekNumberSystem); @@ -237,7 +220,6 @@ int CalendarSystem::daysInYear(const QDate &date) const return m_calendarSystem->daysInYear(date); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysInYear(int year) const { return m_calendarSystem->daysInYear(year); @@ -248,7 +230,6 @@ int CalendarSystem::daysInMonth(const QDate &date) const return m_calendarSystem->daysInMonth(date); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::daysInMonth(int year, int month) const { return m_calendarSystem->daysInMonth(year, month); @@ -269,13 +250,11 @@ int CalendarSystem::dayOfWeek(const QDate &date) const return m_calendarSystem->dayOfWeek(date); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::week(const QDate &date, int *yearNum) const { return week(date, Locale::DefaultWeekNumber, yearNum); } -// NOT VIRTUAL - Uses shared-d instead int CalendarSystem::week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum) const { return m_calendarSystem->week(date, (KLocale::WeekNumberSystem)weekNumberSystem, yearNum); @@ -291,49 +270,42 @@ bool CalendarSystem::isLeapYear(const QDate &date) const return m_calendarSystem->isLeapYear(date); } -// NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfYear(int year) const { return m_calendarSystem->firstDayOfYear(year); } -// NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfYear(int year) const { return m_calendarSystem->lastDayOfYear(year); } -// NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfYear(const QDate &date) const { return m_calendarSystem->firstDayOfYear(date); } -// NOT VIRTUAL - If override needed use shared-d + QDate CalendarSystem::lastDayOfYear(const QDate &date) const { return m_calendarSystem->lastDayOfYear(date); } -// NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfMonth(int year, int month) const { return m_calendarSystem->firstDayOfMonth(year, month); } -// NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfMonth(int year, int month) const { return m_calendarSystem->lastDayOfMonth(year, month); } -// NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::firstDayOfMonth(const QDate &date) const { return m_calendarSystem->firstDayOfMonth(date); } -// NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::lastDayOfMonth(const QDate &date) const { return m_calendarSystem->lastDayOfMonth(date); @@ -364,14 +336,13 @@ QString CalendarSystem::formatDate(const QDate &fromDate, Locale::DateFormat toF return m_calendarSystem->formatDate(fromDate, (KLocale::DateFormat)toFormat); } -// NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DateTimeFormatStandard standard) const { return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DateTimeFormatStandard)standard); } -// NOT VIRTUAL - If override needed use shared-d + QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DigitSet digitSet, Locale::DateTimeFormatStandard formatStandard) const { @@ -379,7 +350,6 @@ QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toForma (KLocale::DateTimeFormatStandard)formatStandard); } -// NOT VIRTUAL - If override needed use shared-d QString CalendarSystem::formatDate(const QDate &date, Locale::DateTimeComponent component, Locale::DateTimeComponentFormat format, Locale::WeekNumberSystem weekNumberSystem) const @@ -404,7 +374,6 @@ QDate CalendarSystem::readDate(const QString &inputString, const QString &format return readDate(inputString, formatString, ok, Locale::KdeFormat); } -// NOT VIRTUAL - If override needed use shared-d QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok, Locale::DateTimeFormatStandard formatStandard) const { @@ -412,13 +381,11 @@ QDate CalendarSystem::readDate(const QString &inputString, const QString &format (KLocale::DateTimeFormatStandard)formatStandard); } -// NOT VIRTUAL - If override needed use shared-d int CalendarSystem::shortYearWindowStartYear() const { return m_calendarSystem->shortYearWindowStartYear(); } -// NOT VIRTUAL - If override needed use shared-d int CalendarSystem::applyShortYearWindow(int inputYear) const { return m_calendarSystem->applyShortYearWindow(inputYear); diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 2749971a9..ae9f57b84 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -27,7 +27,7 @@ #include #include -class CalendarSystem; +class KCalendarSystem; class KCalendarEra; /** diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index a331d5163..ceb98da13 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -579,7 +579,6 @@ public: */ Q_INVOKABLE QString prettyFormatDuration(unsigned long mSec) const; - //KDE5 move to KDateTime namespace /** * * Available Calendar Systems @@ -613,7 +612,6 @@ public: ThaiCalendar = 23 /**< Thai Calendar, aka Buddhist or Thai Buddhist */ }; - //KDE5 move to KDateTime namespace /** * * System used for Week Numbers @@ -629,7 +627,6 @@ public: SimpleWeek = 3 /**< Week 1 starts Jan 1st ends after 7 days */ }; - //KDE5 move to KDateTime namespace /** * * Standard used for Date Time Format String @@ -640,7 +637,6 @@ public: UnicodeFormat /**< UNICODE Standard (Qt/Java/OSX/Windows) */ }; - //KDE5 move to KDateTime namespace /** * * Mode to use when parsing a Date Time input string @@ -657,14 +653,13 @@ public: //StrictParsing /**< Parse Date/Time strictly to the format. */ }; - //KDE5 move to KDateTime namespace /** * * The various Components that make up a Date / Time * In the future the Components may be combined as flags for dynamic * generation of Date Formats. * - * @see KCalendarSystem + * @see CalendarSystem * @see KLocalizedDate * @see DateTimeComponentFormat */ @@ -701,7 +696,6 @@ public: UnixTime = 0x20000000 /**< The UNIX Time portion of a date */ }; - //KDE5 move to KDateTime namespace /** * * Format used for individual Date/Time Components when converted to/from a string @@ -721,7 +715,6 @@ public: Q_DECLARE_FLAGS(DateTimeComponents, DateTimeComponent) - //KDE5 move to KDateTime namespace /** * Format for date string. */ @@ -739,7 +732,6 @@ public: IsoOrdinalDate /**< ISO-8601 Ordinal Date format YYYY-DDD, e.g. 2009-001 */ }; - //KDE5 move to KDateTime namespace /** * Returns a string formatted to the current locale's conventions * regarding dates. @@ -751,7 +743,6 @@ public: */ Q_INVOKABLE QString formatDate(const QDate &date, DateFormat format = LongDate) const; - //KDE5 move to KDateTime namespace /** * Returns a string formatted to the current locale's conventions * regarding both date and time. @@ -765,8 +756,6 @@ public: */ Q_INVOKABLE QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate, bool includeSecs = false) const; - - //KDE5 move to KDateTime namespace /** * Options for formatting date-time values. */ @@ -777,7 +766,6 @@ public: Q_DECLARE_FLAGS(DateTimeFormatOptions, DateTimeFormatOption) - //KDE5 move to KDateTime namespace /** * Returns a string formatted to the current locale's conventions * regarding both date and time. @@ -825,7 +813,6 @@ public: Q_DECLARE_FLAGS(TimeFormatOptions, TimeFormatOption) - //KDE5 move to KDateTime namespace /** * * Returns a string formatted to the current locale's conventions @@ -909,7 +896,7 @@ public: * Returns the type of Calendar System used in this Locale * * @see Locale::CalendarSystem - * @see KCalendarSystem + * @see CalendarSystem * @return the type of Calendar System */ Locale::CalendarSystem calendarSystem() const; @@ -919,7 +906,7 @@ public: * Sets the type of Calendar System to use in this Locale * * @see Locale::CalendarSystem - * @see KCalendarSystem + * @see CalendarSystem * @param calendarSystem the Calendar System to use */ void setCalendarSystem(Locale::CalendarSystem calendarSystem); @@ -977,7 +964,6 @@ public: */ Q_INVOKABLE double readNumber(const QString &numStr, bool * ok = 0) const; - //KDE5 move to KDateTime namespace /** * Converts a localized date string to a QDate. This method will try all * ReadDateFlag formats in preferred order to read a valid date. @@ -989,19 +975,17 @@ public: * If @p ok is 0, it will be ignored * * @return The string converted to a QDate - * @see KCalendarSystem::readDate() + * @see CalendarSystem::readDate() */ Q_INVOKABLE QDate readDate(const QString &str, bool* ok = 0) const; - //KDE5 move to KDateTime namespace /** * Converts a localized date string to a QDate, using the specified format. * You will usually not want to use this method. - * @see KCalendarSystem::readDate() + * @see CalendarSystem::readDate() */ Q_INVOKABLE QDate readDate(const QString &intstr, const QString &fmt, bool* ok = 0) const; - //KDE5 move to KDateTime namespace /** * Flags for readDate() */ @@ -1018,7 +1002,6 @@ public: ISO Week date format (YYYY-DDD) */ }; - //KDE5 move to KDateTime namespace /** * Converts a localized date string to a QDate. * This method is stricter than readDate(str,&ok): it will only accept @@ -1030,7 +1013,7 @@ public: * If @p ok is 0, it will be ignored * * @return The string converted to a QDate - * @see KCalendarSystem::readDate() + * @see CalendarSystem::readDate() */ Q_INVOKABLE QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 3fae6c71c..b24632921 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -238,9 +238,9 @@ Item { console.log("isValid:" + calendar.isValid(2012, 33)) - //console.log("isValid:" + calendar.isValid(QString &eraName, int yearInEra, int month, int day)) TODO + console.log("isValid:" + calendar.isValid(calendar.formatDate("2012-02-03"), 2010, 5, 5))//TODO - console.log("isValidIsoWeekDate:" + calendar.isValidIsoWeekDate(2012, 2, 3) + console.log("isValidIsoWeekDate:" + calendar.isValidIsoWeekDate(2012, 2, 3)) console.log("isValid:" + calendar.isValid("2012-02-03")) @@ -302,9 +302,9 @@ Item { console.log("formatDate:" + calendar.formatDate("2012-02-03")) - console.log("readDate:" + calendar.readDate("2012-02-03"))//TODO does it work? + console.log("readDate:" + calendar.readDate("2012-02-03")) - console.log("applyShortYearWindow:" + calendar.applyShortYearWindow(120))//TODO does it work? + console.log("applyShortYearWindow:" + calendar.applyShortYearWindow(50)) console.log("===============end===============") } From b9efdcc1e45a2be6f15705945053e00904e35add Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Fri, 9 Mar 2012 13:37:20 +0200 Subject: [PATCH 076/104] Remove a comment and replace a tab with spaces --- declarativeimports/locale/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/declarativeimports/locale/CMakeLists.txt b/declarativeimports/locale/CMakeLists.txt index 59ab9e4b4..dea3e1e5c 100644 --- a/declarativeimports/locale/CMakeLists.txt +++ b/declarativeimports/locale/CMakeLists.txt @@ -5,7 +5,7 @@ include(KDE4Defaults) set(localebindings_SRCS locale.cpp localebindingsplugin.cpp - calendarsystem.cpp + calendarsystem.cpp ) INCLUDE_DIRECTORIES( @@ -18,9 +18,8 @@ qt4_automoc(${localebindings_SRCS}) kde4_add_library(localebindingsplugin SHARED ${localebindings_SRCS}) -#FIXME -#Should i put something? -target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KDECORE_LIBRARY} ${KDE4_KDECORE_INCLUDES}) + +target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KDECORE_LIBRARY}) install(TARGETS localebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) From 028df24350f180ce323b002a15d570ca23b4438e Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 13 Mar 2012 12:56:27 +0200 Subject: [PATCH 077/104] Remove the methods insert/removeCatalog from the Locale class --- declarativeimports/locale/locale.cpp | 10 ---------- declarativeimports/locale/locale.h | 23 ++--------------------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index daf8990d2..4adb06f57 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -72,16 +72,6 @@ QString Locale::currencyCode() const return m_locale->currencyCode(); } -void Locale::insertCatalog(const QString &catalog) -{ - m_locale->insertCatalog(catalog); -} - -void Locale::removeCatalog(const QString &catalog) -{ - m_locale->removeCatalog(catalog); -} - void Locale::setActiveCatalog(const QString &catalog) { m_locale->setActiveCatalog(catalog); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index ceb98da13..78d7f2b30 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -1467,25 +1467,6 @@ public: */ void setMeasureSystem(MeasureSystem value); - /** - * Adds another catalog to search for translation lookup. - * This function is useful for extern libraries and/or code, - * that provide their own messages. - * - * If the catalog does not exist for the chosen language, - * it will be ignored and en_US will be used. - * - * @param catalog The catalog to add. - */ - Q_INVOKABLE void insertCatalog(const QString& catalog); - - /** - * Removes a catalog for translation lookup. - * @param catalog The catalog to remove. - * @see insertCatalog() - */ - Q_INVOKABLE void removeCatalog(const QString &catalog); - /** * Sets the active catalog for translation lookup. * @param catalog The catalog to activate. @@ -1582,7 +1563,7 @@ public: * @param charset set to the charset part of the locale */ Q_INVOKABLE static void splitLocale(const QString &locale, QString &language, QString &country, - QString &modifier, QString &charset); //TODO remove? + QString &modifier, QString &charset); /** * Use this as main catalog for *all* KLocales, if not the appname @@ -1672,7 +1653,7 @@ public: * * @return path to the localized file if found, original path otherwise */ - Q_INVOKABLE QString localizedFilePath(const QString &filePath) const;//TODO remove + Q_INVOKABLE QString localizedFilePath(const QString &filePath) const; /** * From c67e95a4f348bfd22a364883c553d55320cdf975 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 13 Mar 2012 17:33:26 +0200 Subject: [PATCH 078/104] Remove Locale::localizedFilePath --- declarativeimports/locale/locale.cpp | 5 ----- declarativeimports/locale/locale.h | 23 ----------------------- 2 files changed, 28 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 4adb06f57..2db0bcc70 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -571,11 +571,6 @@ Locale::WeekNumberSystem Locale::weekNumberSystem() const return (Locale::WeekNumberSystem)m_locale->weekNumberSystem(); } -QString Locale::localizedFilePath(const QString &filePath) const -{ - return m_locale->localizedFilePath(filePath); -} - QString Locale::removeAcceleratorMarker(const QString &label) const { return m_locale->removeAcceleratorMarker(label); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 78d7f2b30..5df94ae55 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -1632,29 +1632,6 @@ public: */ bool setCountryDivisionCode(const QString & countryDivision); - /** - * - * Tries to find a path to the localized file for the given original path. - * This is intended mainly for non-text resources (images, sounds, etc.), - * whereas text resources should be handled in more specific ways. - * - * The possible localized paths are checked in turn by priority of set - * languages, in form of dirname/l10n/ll/basename, where dirname and - * basename are those of the original path, and ll is the language code. - * - * KDE core classes which resolve paths internally (e.g. KStandardDirs) - * will usually perform this lookup behind the scene. - * In general, you should pipe resource paths through this method only - * on explicit translators' request, or when a resource is an obvious - * candidate for localization (e.g. a splash screen or a custom icon - * with some text drawn on it). - * - * @param filePath path to the original file - * - * @return path to the localized file if found, original path otherwise - */ - Q_INVOKABLE QString localizedFilePath(const QString &filePath) const; - /** * * Removes accelerator marker from a UI text label. From 48def0fb7218278f72818585589d9791864303b2 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 13 Mar 2012 17:34:16 +0200 Subject: [PATCH 079/104] Fix a property in klocaleqmltest.qml --- .../locale/tests/contents/code/klocaleqmltest.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index b24632921..27426b1d2 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -21,8 +21,8 @@ import QtQuick 1.1 import org.kde.plasma.components 0.1 as PlasmaComponents -import org.kde.plasma.core 0.1 as PlasmaCore import org.kde.plasma.locale 0.1 + Item { id: root property int minimumHeight: 200 @@ -185,7 +185,7 @@ Item { console.log("readMoney:" + locale.readMoney("$ 21")) - console.log("readNumber:" + locale.readNumber("12,100"))//TODO + console.log("readNumber:" + locale.readNumber(locale.convertDigits(locale.digitSet, Locale.ArabicDigits))) console.log("readDate:" + locale.readDate("2004-02-01")) From ee8eadcc805717a4cbc20844014f60c7f1e46898 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Fri, 16 Mar 2012 17:03:18 +0200 Subject: [PATCH 080/104] Fix the negative values of the enums --- declarativeimports/locale/locale.h | 12 ++++++------ .../locale/tests/contents/code/klocaleqmltest.qml | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 5df94ae55..b17f376f0 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -447,10 +447,10 @@ public: */ enum BinarySizeUnits { /// Auto-choose a unit such that the result is in the range [0, 1000 or 1024) - DefaultBinaryUnits = -1, + DefaultBinaryUnits = 1000, // The first real unit must be 0 for the current implementation! - UnitByte, ///< B 1 byte + UnitByte = 0, ///< B 1 byte UnitKiloByte, ///< KiB/KB/kB 1024/1000 bytes. UnitMegaByte, ///< MiB/MB/MB 2^20/10^06 bytes. UnitGigaByte, ///< GiB/GB/GB 2^30/10^09 bytes. @@ -480,8 +480,8 @@ public: * @see setBinaryUnitDialect */ enum BinaryUnitDialect { - DefaultBinaryDialect = -1, ///< Used if no specific preference - IECBinaryDialect, ///< KDE Default, KiB, MiB, etc. 2^(10*n) + DefaultBinaryDialect = 1000, ///< Used if no specific preference + IECBinaryDialect = 0, ///< KDE Default, KiB, MiB, etc. 2^(10*n) JEDECBinaryDialect, ///< KDE 3.5 default, KB, MB, etc. 2^(10*n) MetricBinaryDialect, ///< SI Units, kB, MB, etc. 10^(3*n) LastBinaryDialect = MetricBinaryDialect @@ -620,7 +620,7 @@ public: * @see weekNumberSystem() */ enum WeekNumberSystem { - DefaultWeekNumber = -1, /**< The system locale default */ + DefaultWeekNumber = 1000, /**< The system locale default */ IsoWeekNumber = 0, /**< ISO Week Number */ FirstFullWeek = 1, /**< Week 1 starts on the first Week Start Day in year ends after 7 days */ FirstPartialWeek = 2, /**< Week 1 starts Jan 1st ends day before first Week Start Day in year */ @@ -704,7 +704,7 @@ public: * @see DateTimeComponentFormat */ enum DateTimeComponentFormat { - DefaultComponentFormat = -1, /**< The system locale default for the componant */ + DefaultComponentFormat = 1000, /**< The system locale default for the componant */ ShortNumber = 0, /**< Number at its natural width, e.g. 2 for the 2nd*/ LongNumber, /**< Number padded to a required width, e.g. 02 for the 2nd*/ //OrdinalNumber /**< Ordinal number format, e.g. "2nd" for the 2nd */ diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 27426b1d2..38e9173fb 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -312,10 +312,10 @@ Item { Locale { id: locale - //TODO enums with negative value(like -1) doesn't work in QML! - binaryUnitDialect: Locale.IECBinaryDialect + + binaryUnitDialect: Locale.DefaultBinaryUnits onBinaryUnitDialectChanged: { - console.log("the binaryUnitDialect property has been changed") + console.log("the binaryUnitDialect property has been changed") } calendarSystem: Locale.QDateCalendar From 9cbc32a0782f5d490d4543c3a7a9ffd1c344d219 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 19 Mar 2012 13:32:21 +0200 Subject: [PATCH 081/104] fix the allDigitSetsList method and also make it a method --- declarativeimports/locale/locale.cpp | 6 +++--- declarativeimports/locale/locale.h | 4 +++- .../locale/tests/contents/code/klocaleqmltest.qml | 8 ++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 2db0bcc70..315551426 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -82,12 +82,12 @@ QString Locale::translateQt(const char *context, const char *sourceText, const c return m_locale->translateQt(context, sourceText, comment); } -QList Locale::allDigitSetsList() const +QList Locale::allDigitSetsList() const { - QList digitList; + QList digitList; foreach(KLocale::DigitSet digit, m_locale->allDigitSetsList()) { - digitList.append((Locale::DigitSet)digit); + digitList.append((int)digit); } return digitList; diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index b17f376f0..d60dd2780 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -121,6 +121,7 @@ Q_PROPERTY(QStringList currencyCodeList READ currencyCodeList NOTIFY currencyCod Q_PROPERTY(QStringList allLanguagesList READ allLanguagesList NOTIFY allLanguagesListChanged) //read-only Q_PROPERTY(QStringList installedLanguages READ installedLanguages NOTIFY installedLanguagesChanged) //read-only Q_PROPERTY(QStringList allCountriesList READ allCountriesList NOTIFY allCountriesListChanged) //read-only +Q_PROPERTY(QList allDigitSetsList READ allDigitSetsList NOTIFY allDigitSetsListChanged) //read-only public: /** @@ -222,7 +223,7 @@ public: * @see DigitSet * @see digitSetToName */ - Q_INVOKABLE QList allDigitSetsList() const; //TODO + QList allDigitSetsList() const; /** * Returns what a decimal point should look like ("." or "," etc.) @@ -1724,6 +1725,7 @@ Q_SIGNALS: void allLanguagesListChanged(); void installedLanguagesChanged(); void allCountriesListChanged(); + void allDigitSetsListChanged(); }; #endif diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 38e9173fb..a70ec8a28 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -203,6 +203,10 @@ Item { console.log("convertDigits:" + locale.convertDigits(locale.digitSet, Locale.ArabicDigits)) + for (var i in locale.allDigitSetsList) { + console.log("digia:" + locale.allDigitSetsList[i]) + } + console.log("===========end===========") } } @@ -509,6 +513,10 @@ Item { onAllCountriesListChanged: { console.log("the allCountriesList property has been changed") } + + onAllDigitSetsListChanged: { + console.log("the allDigitSetsList property has been changed") + } } CalendarSystem { From 6844da9ccb8b6293c1e8bc9ef96ff2825064e86a Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 19 Mar 2012 16:20:10 +0200 Subject: [PATCH 082/104] Fix CalendarSystem:getDate and CalendarSystem::dateDifference --- declarativeimports/locale/calendarsystem.cpp | 35 ++++++++++++++++--- declarativeimports/locale/calendarsystem.h | 23 ++++++------ .../tests/contents/code/klocaleqmltest.qml | 15 +++++++- 3 files changed, 55 insertions(+), 18 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index abe15d9b6..c2d595bb4 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -113,9 +113,21 @@ bool CalendarSystem::isValid(const QDate &date) const return m_calendarSystem->isValid(date); } -void CalendarSystem::getDate(const QDate date, int *year, int *month, int *day) const +QVariantHash CalendarSystem::getDate(const QDate date) const { - return m_calendarSystem->getDate(date, year, month, day); + QVariantHash hash; + + int year; + int month; + int day; + + m_calendarSystem->getDate(date, &year, &month, &day); + + hash["year"] = year; + hash["month"] = month; + hash["day"] = day; + + return hash; } int CalendarSystem::year(const QDate &date) const @@ -164,10 +176,23 @@ QDate CalendarSystem::addDays(const QDate &date, int numDays) const return m_calendarSystem->addDays(date, numDays); } -void CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate, - int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const +QVariantHash CalendarSystem::dateDifference(const QDate &fromDate, const QDate &toDate) const { - return m_calendarSystem->dateDifference(fromDate, toDate, yearsDiff, monthsDiff, daysDiff, direction); + QVariantHash hash; + + int yearsDiff; + int monthsDiff; + int daysDiff; + int direction; + + m_calendarSystem->dateDifference(fromDate, toDate, &yearsDiff, &monthsDiff, &daysDiff, &direction); + + hash["years"] = yearsDiff; + hash["months"] = monthsDiff; + hash["days"] = daysDiff; + hash["direction"] = direction; + + return hash; } int CalendarSystem::yearsDifference(const QDate &fromDate, const QDate &toDate) const diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index ae9f57b84..cbd56e8b8 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -244,13 +244,13 @@ public: /** * * Returns the year, month and day portion of a given date in the current calendar system - * + * The values are returned in a hash, the available keys are, + * ["year"] the year of the date + * ["month"] the month of the date + * ["day"] the day of the date * @param date date to get year, month and day for - * @param year year number returned in this variable - * @param month month number returned in this variable - * @param day day of month returned in this variable */ - Q_INVOKABLE void getDate(const QDate date, int *year, int *month, int *day) const;//TODO should it be part of the QML Wrapper? + Q_INVOKABLE QVariantHash getDate(const QDate date) const;//TODO should it be part of the QML Wrapper? /** * Returns the year portion of a given date in the current calendar system @@ -340,7 +340,11 @@ public: //KDE5 make virtual? /** - * Returns the difference between two dates in years, months and days. + * Returns the difference between two dates with a hash, the available keys are + * ["years"] Returns number of years difference + * ["months"] Returns number of months difference + * ["days"] Returns number of days difference + * ["direction"] Returns direction of difference, 1 if fromDate <= toDate, -1 otherwise * The difference is always caculated from the earlier date to the later * date in year, month and day order, with the @p direction parameter * indicating which direction the difference is applied from the @p toDate. @@ -352,13 +356,8 @@ public: * * @param fromDate The date to start from * @param toDate The date to end at - * @param yearsDiff Returns number of years difference - * @param monthsDiff Returns number of months difference - * @param daysDiff Returns number of days difference - * @param direction Returns direction of difference, 1 if fromDate <= toDate, -1 otherwise */ - Q_INVOKABLE void dateDifference(const QDate &fromDate, const QDate &toDate, - int *yearsDiff, int *monthsDiff, int *daysDiff, int *direction) const;//TODO Does it work? + Q_INVOKABLE QVariantHash dateDifference(const QDate &fromDate, const QDate &toDate)const; //KDE5 make virtual? /** diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index a70ec8a28..b0221c455 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -213,6 +213,7 @@ Item { PlasmaComponents.Button { id: bt2 + property variant hash anchors.horizontalCenter: column.horizontalCenter text: "click in order to test the CalendarSystem component" onClicked:{ @@ -242,7 +243,7 @@ Item { console.log("isValid:" + calendar.isValid(2012, 33)) - console.log("isValid:" + calendar.isValid(calendar.formatDate("2012-02-03"), 2010, 5, 5))//TODO + console.log("isValid:" + calendar.isValid(calendar.formatDate("2012-02-03"), 2010, 5, 5)) console.log("isValidIsoWeekDate:" + calendar.isValidIsoWeekDate(2012, 2, 3)) @@ -310,6 +311,18 @@ Item { console.log("applyShortYearWindow:" + calendar.applyShortYearWindow(50)) + console.log("getDate:") + hash = calendar.getDate("2012-02-03") + for (var i in hash) { + console.log(" " + i, "=", hash[i]) + } + + console.log("dateDifference:") + hash = calendar.dateDifference("2012-01-01", "2014-03-03") + for (var i in hash) { + console.log(" " + i, "=", hash[i]) + } + console.log("===============end===============") } } From 5d8ab81119b56e50f9dd9aaf3182ca2c9f1e6b04 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 19 Mar 2012 17:13:31 +0200 Subject: [PATCH 083/104] Remove an unnecessary enum --- declarativeimports/locale/calendarsystem.h | 2 +- declarativeimports/locale/locale.h | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index cbd56e8b8..f23b9aab4 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -250,7 +250,7 @@ public: * ["day"] the day of the date * @param date date to get year, month and day for */ - Q_INVOKABLE QVariantHash getDate(const QDate date) const;//TODO should it be part of the QML Wrapper? + Q_INVOKABLE QVariantHash getDate(const QDate date) const; /** * Returns the year portion of a given date in the current calendar system diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index d60dd2780..27e5ecda3 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -71,7 +71,6 @@ Q_ENUMS(DateTimeParseMode) Q_ENUMS(DigitSet) Q_ENUMS(MeasureSystem) Q_ENUMS(ReadDateFlags) -Q_ENUMS(ReadTimeFlags) Q_ENUMS(SignPosition) Q_ENUMS(TimeFormatOption) Q_ENUMS(TimeProcessingOption) @@ -1067,11 +1066,6 @@ public: * @return The string converted to a QTime */ - enum ReadTimeFlags { - WithSeconds = 0, ///< Only accept a time string with seconds. Default (no flag set) - WithoutSeconds = 1 ///< Only accept a time string without seconds. - }; // (maybe use this enum as a bitfield, if adding independent features?) - Q_INVOKABLE QTime readLocaleTime(const QString &str, bool *ok = 0, TimeFormatOptions options = Locale::TimeDefault, TimeProcessingOptions processing = ProcessNonStrict) const; From 7a206534e3d7d699e0cc792134faea080744a23b Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 19 Mar 2012 17:14:28 +0200 Subject: [PATCH 084/104] add one more line for an overloaded method --- declarativeimports/locale/tests/contents/code/klocaleqmltest.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index b0221c455..14dd61e45 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -186,6 +186,7 @@ Item { console.log("readMoney:" + locale.readMoney("$ 21")) console.log("readNumber:" + locale.readNumber(locale.convertDigits(locale.digitSet, Locale.ArabicDigits))) + console.log("readNumber:" + locale.readNumber(10.0,3)) console.log("readDate:" + locale.readDate("2004-02-01")) From c0cee92b7d980f015402d57f4da423ccbd7db84c Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Fri, 23 Mar 2012 15:31:03 +0200 Subject: [PATCH 085/104] Remove the overloaded methods from CalendarSystem --- declarativeimports/locale/calendarsystem.cpp | 140 +---- declarativeimports/locale/calendarsystem.h | 544 +++--------------- .../tests/contents/code/klocaleqmltest.qml | 21 +- 3 files changed, 103 insertions(+), 602 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index c2d595bb4..116a53314 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -86,23 +86,6 @@ QDate CalendarSystem::latestValidDate() const return m_calendarSystem->latestValidDate(); } -bool CalendarSystem::isValid(int year, int month, int day) const -{ - return m_calendarSystem->isValid(year, month, day); -} - - -bool CalendarSystem::isValid(int year, int dayOfYear) const -{ - return m_calendarSystem->isValid(year, dayOfYear); -} - - -bool CalendarSystem::isValid(const QString &eraName, int yearInEra, int month, int day) const -{ - return m_calendarSystem->isValid(eraName, yearInEra, month, day); -} - bool CalendarSystem::isValidIsoWeekDate(int year, int isoWeekNumber, int dayOfIsoWeek) const { return m_calendarSystem->isValidIsoWeekDate(year, isoWeekNumber, dayOfIsoWeek); @@ -210,51 +193,21 @@ int CalendarSystem::daysDifference(const QDate &fromDate, const QDate &toDate) c return m_calendarSystem->daysDifference(fromDate, toDate); } -int CalendarSystem::monthsInYear(const QDate &date) const -{ - return m_calendarSystem->monthsInYear(date); -} - int CalendarSystem::monthsInYear(int year) const { return m_calendarSystem->monthsInYear(year); } -int CalendarSystem::weeksInYear(const QDate &date) const -{ - return weeksInYear(date, Locale::DefaultWeekNumber); -} - -int CalendarSystem::weeksInYear(int year) const -{ - return weeksInYear(year, Locale::DefaultWeekNumber); -} - -int CalendarSystem::weeksInYear(const QDate &date, Locale::WeekNumberSystem weekNumberSystem) const -{ - return m_calendarSystem->weeksInYear(date, (KLocale::WeekNumberSystem)weekNumberSystem); -} - -int CalendarSystem::weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const +int CalendarSystem::weeksInYear(int year, WeekNumberSystem weekNumberSystem) const { return m_calendarSystem->weeksInYear(year, (KLocale::WeekNumberSystem)weekNumberSystem); } -int CalendarSystem::daysInYear(const QDate &date) const -{ - return m_calendarSystem->daysInYear(date); -} - int CalendarSystem::daysInYear(int year) const { return m_calendarSystem->daysInYear(year); } -int CalendarSystem::daysInMonth(const QDate &date) const -{ - return m_calendarSystem->daysInMonth(date); -} - int CalendarSystem::daysInMonth(int year, int month) const { return m_calendarSystem->daysInMonth(year, month); @@ -275,14 +228,9 @@ int CalendarSystem::dayOfWeek(const QDate &date) const return m_calendarSystem->dayOfWeek(date); } -int CalendarSystem::week(const QDate &date, int *yearNum) const +int CalendarSystem::week(const QDate &date, WeekNumberSystem weekNumberSystem) const { - return week(date, Locale::DefaultWeekNumber, yearNum); -} - -int CalendarSystem::week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum) const -{ - return m_calendarSystem->week(date, (KLocale::WeekNumberSystem)weekNumberSystem, yearNum); + return m_calendarSystem->week(date, (KLocale::WeekNumberSystem)weekNumberSystem); } bool CalendarSystem::isLeapYear(int year) const @@ -290,11 +238,6 @@ bool CalendarSystem::isLeapYear(int year) const return m_calendarSystem->isLeapYear(year); } -bool CalendarSystem::isLeapYear(const QDate &date) const -{ - return m_calendarSystem->isLeapYear(date); -} - QDate CalendarSystem::firstDayOfYear(int year) const { return m_calendarSystem->firstDayOfYear(year); @@ -305,17 +248,6 @@ QDate CalendarSystem::lastDayOfYear(int year) const return m_calendarSystem->lastDayOfYear(year); } -QDate CalendarSystem::firstDayOfYear(const QDate &date) const -{ - return m_calendarSystem->firstDayOfYear(date); -} - - -QDate CalendarSystem::lastDayOfYear(const QDate &date) const -{ - return m_calendarSystem->lastDayOfYear(date); -} - QDate CalendarSystem::firstDayOfMonth(int year, int month) const { return m_calendarSystem->firstDayOfMonth(year, month); @@ -326,84 +258,28 @@ QDate CalendarSystem::lastDayOfMonth(int year, int month) const return m_calendarSystem->lastDayOfMonth(year, month); } -QDate CalendarSystem::firstDayOfMonth(const QDate &date) const -{ - return m_calendarSystem->firstDayOfMonth(date); -} - -QDate CalendarSystem::lastDayOfMonth(const QDate &date) const -{ - return m_calendarSystem->lastDayOfMonth(date); -} - QString CalendarSystem::monthName(int month, int year, CalendarSystem::MonthNameFormat format) const { return m_calendarSystem->monthName(month, year, (KCalendarSystem::MonthNameFormat)format); } -QString CalendarSystem::monthName(const QDate &date, MonthNameFormat format) const -{ - return m_calendarSystem->monthName(date, (KCalendarSystem::MonthNameFormat)format); -} - QString CalendarSystem::weekDayName(int weekDay, CalendarSystem::WeekDayNameFormat format) const { return m_calendarSystem->weekDayName(weekDay, (KCalendarSystem::WeekDayNameFormat)format); } -QString CalendarSystem::weekDayName(const QDate &date, WeekDayNameFormat format) const -{ - return m_calendarSystem->weekDayName(date, (KCalendarSystem::WeekDayNameFormat)format); -} - -QString CalendarSystem::formatDate(const QDate &fromDate, Locale::DateFormat toFormat) const -{ - return m_calendarSystem->formatDate(fromDate, (KLocale::DateFormat)toFormat); -} - -QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, - Locale::DateTimeFormatStandard standard) const -{ - return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DateTimeFormatStandard)standard); -} - - -QString CalendarSystem::formatDate(const QDate &fromDate, const QString &toFormat, Locale::DigitSet digitSet, - Locale::DateTimeFormatStandard formatStandard) const -{ - return m_calendarSystem->formatDate(fromDate, toFormat, (KLocale::DigitSet)digitSet, - (KLocale::DateTimeFormatStandard)formatStandard); -} - -QString CalendarSystem::formatDate(const QDate &date, Locale::DateTimeComponent component, - Locale::DateTimeComponentFormat format, - Locale::WeekNumberSystem weekNumberSystem) const +QString CalendarSystem::formatDate(const QDate &date, DateTimeComponent component, + DateTimeComponentFormat format, + WeekNumberSystem weekNumberSystem) const { return m_calendarSystem->formatDate(date, (KLocale::DateTimeComponent)component, (KLocale::DateTimeComponentFormat)format, (KLocale::WeekNumberSystem)weekNumberSystem); } -QDate CalendarSystem::readDate(const QString &str, bool *ok) const +QDate CalendarSystem::readDate(const QString &str, ReadDateFlags flags) const { - return m_calendarSystem->readDate(str, ok); -} - -QDate CalendarSystem::readDate(const QString &str, Locale::ReadDateFlags flags, bool *ok) const -{ - return m_calendarSystem->readDate(str, (KLocale::ReadDateFlags)flags, ok); -} - -QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok) const -{ - return readDate(inputString, formatString, ok, Locale::KdeFormat); -} - -QDate CalendarSystem::readDate(const QString &inputString, const QString &formatString, bool *ok, - Locale::DateTimeFormatStandard formatStandard) const -{ - return m_calendarSystem->readDate(inputString, formatString, ok, - (KLocale::DateTimeFormatStandard)formatStandard); + return m_calendarSystem->readDate(str, (KLocale::ReadDateFlags)flags); } int CalendarSystem::shortYearWindowStartYear() const diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index f23b9aab4..c80b445c4 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -43,6 +43,10 @@ Q_OBJECT Q_ENUMS(StringFormat) Q_ENUMS(MonthNameFormat) Q_ENUMS(WeekDayNameFormat) +Q_ENUMS(WeekNumberSystem) +Q_ENUMS(ReadDateFlags) +Q_ENUMS(DateTimeComponent) +Q_ENUMS(DateTimeComponentFormat) //properties Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem NOTIFY calendarSystemChanged)//read-only @@ -62,6 +66,80 @@ public: //ctor CalendarSystem(QObject *parent = 0); + //the above are enums which I borrow from the Locale class + /** + * + * System used for Week Numbers + */ + enum WeekNumberSystem { + DefaultWeekNumber = 1000, /**< The system locale default */ + IsoWeekNumber = 0, /**< ISO Week Number */ + FirstFullWeek = 1, /**< Week 1 starts on the first Week Start Day in year ends after 7 days */ + FirstPartialWeek = 2, /**< Week 1 starts Jan 1st ends day before first Week Start Day in year */ + SimpleWeek = 3 /**< Week 1 starts Jan 1st ends after 7 days */ + }; + + enum ReadDateFlags { + NormalFormat = 1, /**< Only accept a date string in + the locale LongDate format */ + shortFormat = 2, /**< Only accept a date string in + the locale ShortDate format */ + IsoFormat = 4, /**< Only accept a date string in + ISO date format (YYYY-MM-DD) */ + IsoWeekFormat = 8, /**< Only accept a date string in + ISO Week date format (YYYY-Www-D) */ + IsoOrdinalFormat = 16 /**< Only accept a date string in + ISO Week date format (YYYY-DDD) */ + }; + + /** + * The various Components that make up a Date / Time + * In the future the Components may be combined as flags for dynamic + * generation of Date Formats. + */ + enum DateTimeComponent { + Year = 0x1, /**< The Year portion of a date, may be number or name */ + YearName = 0x2, /**< The Year Name portion of a date */ + Month = 0x4, /**< The Month portion of a date, may be number or name */ + MonthName = 0x8, /**< The Month Name portion of a date */ + Day = 0x10, /**< The Day portion of a date, may be number or name */ + DayName = 0x20, /**< The Day Name portion of a date */ + JulianDay = 0x40, /**< The Julian Day of a date */ + EraName = 0x80, /**< The Era Name portion of a date */ + EraYear = 0x100, /**< The Era and Year portion of a date */ + YearInEra = 0x200, /**< The Year In Era portion of a date */ + DayOfYear = 0x400, /**< The Day Of Year portion of a date, may be number or name */ + DayOfYearName = 0x800, /**< The Day Of Year Name portion of a date */ + DayOfWeek = 0x1000, /**< The Day Of Week / Weekday portion of a date, may be number or name */ + DayOfWeekName = 0x2000, /**< The Day Of Week Name / Weekday Name portion of a date */ + Week = 0x4000, /**< The Week Number portion of a date */ + WeekYear = 0x8000, /**< The Week Year portion of a date */ + MonthsInYear = 0x10000, /**< The Months In Year portion of a date */ + WeeksInYear = 0x20000, /**< The Weeks In Year portion of a date */ + DaysInYear = 0x40000, /**< The Days In Year portion of a date */ + DaysInMonth = 0x80000, /**< The Days In Month portion of a date */ + DaysInWeek = 0x100000, /**< The Days In Week portion of a date */ + Hour = 0x200000, /**< The Hours portion of a date */ + Minute = 0x400000, /**< The Minutes portion of a date */ + Second = 0x800000, /**< The Seconds portion of a date */ + Millisecond = 0x1000000, /**< The Milliseconds portion of a date */ + DayPeriod = 0x2000000, /**< The Day Period portion of a date, e.g. AM/PM */ + DayPeriodHour = 0x4000000, /**< The Day Period Hour portion of a date */ + Timezone = 0x8000000, /**< The Time Zone portion of a date, may be offset or name */ + TimezoneName = 0x10000000, /**< The Time Zone Name portion of a date */ + UnixTime = 0x20000000 /**< The UNIX Time portion of a date */ + }; + + enum DateTimeComponentFormat { + DefaultComponentFormat = 1000, /**< The system locale default for the componant */ + ShortNumber = 0, /**< Number at its natural width, e.g. 2 for the 2nd*/ + LongNumber, /**< Number padded to a required width, e.g. 02 for the 2nd*/ + narrowName = 3, /**< Narrow text format, may not be unique, e.g. M for Monday */ + shortName, /**< Short text format, e.g. Mon for Monday */ + longName /**< Long text format, e.g. Monday for Monday */ + }; + //end of the borrowing enums + /** * Format for returned year number / month number / day number as string. */ @@ -94,7 +172,7 @@ public: * Returns the list of currently supported Calendar Systems * @return list of Calendar Systems */ - static QList calendarSystemsList(); + static QList calendarSystemsList();//TODO /** * @@ -186,41 +264,6 @@ public: */ virtual QDate latestValidDate() const; - /** - * Returns whether a given date is valid in this calendar system. - * - * @param year the year portion of the date to check - * @param month the month portion of the date to check - * @param day the day portion of the date to check - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE bool isValid(int year, int month, int day) const; - - //KDE5 make virtual? - /** - * - * Returns whether a given date is valid in this calendar system. - * - * @param year the year portion of the date to check - * @param dayOfYear the day of year portion of the date to check - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE bool isValid(int year, int dayOfYear) const; - - //KDE5 make virtual? - /** - * - * Returns whether a given date is valid in this calendar system. - * - * @param eraName the Era Name portion of the date to check - * @param yearInEra the Year In Era portion of the date to check - * @param month the Month portion of the date to check - * @param day the Day portion of the date to check - * @return @c true if the date is valid, @c false otherwise - */ - Q_INVOKABLE bool isValid(const QString &eraName, int yearInEra, int month, int day) const; - - //KDE5 make virtual? /** * * Returns whether a given date is valid in this calendar system. @@ -398,15 +441,6 @@ public: */ Q_INVOKABLE int daysDifference(const QDate &fromDate, const QDate &toDate) const; - /** - * Returns number of months in the given year - * - * @param date the date to obtain year from - * @return number of months in the year, -1 if input date invalid - */ - Q_INVOKABLE int monthsInYear(const QDate &date) const; - - //KDE5 make virtual? /** * * Returns number of months in the given year @@ -416,39 +450,6 @@ public: */ Q_INVOKABLE int monthsInYear(int year) const; - /** - * Returns the number of localized weeks in the given year. - * - * @param date the date to obtain year from - * @return number of weeks in the year, -1 if input date invalid - */ - Q_INVOKABLE int weeksInYear(const QDate &date) const; - - //KDE5 Merge with virtual weeksInYear with default - /** - * - * Returns the number of Weeks in a year using the required Week Number System. - * - * Unless you specifically want a particular Week Number System (e.g. ISO Weeks) - * you should use the localized number of weeks provided by weeksInYear(). - * - * @see week() - * @see formatDate() - * @param date the date to obtain year from - * @param weekNumberSystem the week number system to use - * @return number of weeks in the year, -1 if date invalid - */ - Q_INVOKABLE int weeksInYear(const QDate &date, Locale::WeekNumberSystem weekNumberSystem) const; - - /** - * Returns the number of localized weeks in the given year. - * - * @param year the year - * @return number of weeks in the year, -1 if input date invalid - */ - Q_INVOKABLE int weeksInYear(int year) const; - - //KDE5 Merge with virtual weeksInYear with default /** * * Returns the number of Weeks in a year using the required Week Number System. @@ -462,17 +463,8 @@ public: * @param weekNumberSystem the week number system to use * @return number of weeks in the year, -1 if date invalid */ - Q_INVOKABLE int weeksInYear(int year, Locale::WeekNumberSystem weekNumberSystem) const; + Q_INVOKABLE int weeksInYear(int year, WeekNumberSystem weekNumberSystem) const; - /** - * Returns the number of days in the given year. - * - * @param date the date to obtain year from - * @return number of days in year, -1 if input date invalid - */ - Q_INVOKABLE int daysInYear(const QDate &date) const; - - //KDE5 make virtual? /** * * Returns the number of days in the given year. @@ -482,15 +474,6 @@ public: */ Q_INVOKABLE int daysInYear(int year) const; - /** - * Returns the number of days in the given month. - * - * @param date the date to obtain month from - * @return number of days in month, -1 if input date invalid - */ - Q_INVOKABLE int daysInMonth(const QDate &date) const; - - //KDE5 make virtual? /** * * Returns the number of days in the given month. @@ -531,27 +514,6 @@ public: */ Q_INVOKABLE int dayOfWeek(const QDate &date) const; - //KDE5 Make virtual? - /** - * Returns the localized Week Number for the date. - * - * This may be ISO, US, or any other supported week numbering scheme. If - * you specifically require the ISO Week or any other scheme, you should use - * the week(Locale::WeekNumberSystem) form. - * - * If the date falls in the last week of the previous year or the first - * week of the following year, then the yearNum returned will be set to the - * appropriate year. - * - * @see weeksInYear() - * @see formatDate() - * @param date the date to obtain week from - * @param yearNum returns the year the date belongs to - * @return localized week number, -1 if input date invalid - */ - Q_INVOKABLE int week(const QDate &date, int *yearNum = 0) const; - - //KDE5 Make virtual? /** * Returns the Week Number for the date in the required Week Number System. * @@ -572,7 +534,7 @@ public: * @param yearNum returns the year the date belongs to * @return week number, -1 if input date invalid */ - Q_INVOKABLE int week(const QDate &date, Locale::WeekNumberSystem weekNumberSystem, int *yearNum = 0) const; + Q_INVOKABLE int week(const QDate &date, WeekNumberSystem weekNumberSystem) const; /** * Returns whether a given year is a leap year. @@ -585,18 +547,6 @@ public: */ Q_INVOKABLE bool isLeapYear(int year) const; - /** - * Returns whether a given date falls in a leap year. - * - * Input date must be checked for validity in current Calendar System prior to calling, no - * validity checking performed in this routine, behaviour is undefined in invalid case. - * - * @param date the date to check - * @return @c true if the date falls in a leap year, @c false otherwise - */ - Q_INVOKABLE bool isLeapYear(const QDate &date) const; - - //KDE5 Make virtual? /** * * Returns a QDate containing the first day of the year @@ -617,28 +567,6 @@ public: */ Q_INVOKABLE QDate lastDayOfYear(int year) const; - //KDE5 Make virtual? - /** - * - * Returns a QDate containing the first day of the year - * - * @param date The year to return the date for, defaults to today - * @return The first day of the year - */ - Q_INVOKABLE QDate firstDayOfYear(const QDate &date = QDate::currentDate()) const; - - //KDE5 Make virtual? - /** - * @since 4.6 - * - * Returns a QDate containing the last day of the year - * - * @param date The year to return the date for, defaults to today - * @return The last day of the year - */ - Q_INVOKABLE QDate lastDayOfYear(const QDate &date = QDate::currentDate()) const; - - //KDE5 Make virtual? /** * * Returns a QDate containing the first day of the month @@ -660,26 +588,6 @@ public: */ Q_INVOKABLE QDate lastDayOfMonth(int year, int month) const; - //KDE5 Make virtual? - /** - * - * Returns a QDate containing the first day of the month - * - * @param date The month to return the date for, defaults to today - * @return The first day of the month - */ - Q_INVOKABLE QDate firstDayOfMonth(const QDate &date = QDate::currentDate()) const; - - //KDE5 Make virtual? - /** - * - * Returns a QDate containing the last day of the month - * - * @param date The month to return the date for, defaults to today - * @return The last day of the month - */ - Q_INVOKABLE QDate lastDayOfMonth(const QDate &date = QDate::currentDate()) const; - /** * Gets specific calendar type month name for a given month number * If an invalid month is specified, QString() is returned. @@ -691,15 +599,6 @@ public: */ Q_INVOKABLE QString monthName(int month, int year, MonthNameFormat format = LongName) const; - /** - * Gets specific calendar type month name for a given date - * - * @param date date to obtain month from - * @param format specifies whether the short month name or long month name should be used - * @return name of the month, empty string if any error - */ - Q_INVOKABLE QString monthName(const QDate &date, MonthNameFormat format = LongName) const; - /** * Gets specific calendar type week day name. * If an invalid week day is specified, QString() is returned. @@ -710,182 +609,16 @@ public: */ Q_INVOKABLE QString weekDayName(int weekDay, WeekDayNameFormat format = LongDayName) const; - /** - * Gets specific calendar type week day name. - * - * @param date the date - * @param format specifies whether the short month name or long month name should be used - * @return day name, empty string if any error - */ - Q_INVOKABLE QString weekDayName(const QDate &date, WeekDayNameFormat format = LongDayName) const; - - /** - * Returns a string formatted to the current locale's conventions - * regarding dates. - * - * Uses the calendar system's internal locale set when the instance was - * created, which ensures that the correct calendar system and locale - * settings are respected, which would not occur in some cases if using - * the global locale. Defaults to global locale. - * - * @see Locale::formatDate - * - * @param fromDate the date to be formatted - * @param toFormat category of date format to use - * - * @return The date as a string - */ - Q_INVOKABLE QString formatDate(const QDate &fromDate, Locale::DateFormat toFormat = Locale::LongDate) const; - - //KDE5 Make virtual - /** - * - * Returns a string formatted to the given format and localised to the - * correct language and digit set using the requested format standard. - * - * *** WITH GREAT POWER COMES GREAT RESPONSIBILITY *** - * Please use with care and only in situations where the DateFormat enum - * or locale formats or individual string methods do not provide what you - * need. You should almost always translate your format string as - * documented. Using the standard DateFormat options instead would take - * care of the translation for you. - * - * Warning: The %n element differs from the GNU/POSIX standard where it is - * defined as a newline. KDE currently uses this for short day number. It - * is recommended for compatibility purposes to use %-m instead. - * - * The toFormat parameter is a good candidate to be made translatable, - * so that translators can adapt it to their language's convention. - * There should also be a context using the "kdedt-format" keyword (for - * automatic validation of translations) and stating the format's purpose: - * \code - * QDate reportDate; - * KGlobal::locale()->calendar()->setDate(reportDate, reportYear, reportMonth, 1); - * dateFormat = i18nc("(kdedt-format) Report month and year in report header", "%B %Y")); - * dateString = KGlobal::locale()->calendar()->formatDate(reportDate, dateFormat); - * \endcode - * - * The date format string can be defined using either the KDE or POSIX standards. - * The KDE standard closely follows the POSIX standard but with some exceptions. - * Always use the KDE standard within KDE, but where interaction is required with - * external POSIX compliant systems (e.g. Gnome, glibc, etc) the POSIX standard - * should be used. - * - * Date format strings are made up of date componants and string literals. - * Date componants are prefixed by a % escape character and are made up of - * optional padding and case modifier flags, an optional width value, and a - * compulsary code for the actual date componant: - * %[Flags][Width][Componant] - * e.g. %_^5Y - * No spaces are allowed. - * - * The Flags can modify the padding character and/or case of the Date Componant. - * The Flags are optional and may be combined and/or repeated in any order, - * in which case the last Padding Flag and last Case Flag will be the - * ones used. The Flags must be immediately after the % and before any Width. - * - * The Width can modify how wide the date Componant is padded to. The Width - * is an optional interger value and must be after any Flags but before the - * Componant. If the Width is less than the minimum defined for a Componant - * then the default minimum will be used instead. - * - * By default most numeric Date Componants are right-aligned with leading 0's. - * - * By default all string name fields are capital case and unpadded. - * - * The following Flags may be specified: - * @li - (hyphen) no padding (e.g. 1 Jan and "%-j" = "1") - * @li _ (underscore) pad with spaces (e.g. 1 Jan and "%-j" = " 1") - * @li 0 (zero) pad with 0's (e.g. 1 Jan and "%0j" = "001") - * @li ^ (caret) make uppercase (e.g. 1 Jan and "%^B" = "JANUARY") - * @li # (hash) invert case (e.g. 1 Jan and "%#B" = "???") - * - * The following Date Componants can be specified: - * @li %Y the year to 4 digits (e.g. "1984" for 1984, "0584" for 584, "0084" for 84) - * @li %C the 'century' portion of the year to 2 digits (e.g. "19" for 1984, "05" for 584, "00" for 84) - * @li %y the lower 2 digits of the year to 2 digits (e.g. "84" for 1984, "05" for 2005) - * @li %EY the full local era year (e.g. "2000 AD") - * @li %EC the era name short form (e.g. "AD") - * @li %Ey the year in era to 1 digit (e.g. 1 or 2000) - * @li %m the month number to 2 digits (January="01", December="12") - * @li %n the month number to 1 digit (January="1", December="12"), see notes! - * @li %d the day number of the month to 2 digits (e.g. "01" on the first of March) - * @li %e the day number of the month to 1 digit (e.g. "1" on the first of March) - * @li %B the month name long form (e.g. "January") - * @li %b the month name short form (e.g. "Jan" for January) - * @li %h the month name short form (e.g. "Jan" for January) - * @li %A the weekday name long form (e.g. "Wednesday" for Wednesday) - * @li %a the weekday name short form (e.g. "Wed" for Wednesday) - * @li %j the day of the year number to 3 digits (e.g. "001" for 1 Jan) - * @li %V the ISO week of the year number to 2 digits (e.g. "01" for ISO Week 1) - * @li %G the year number in long form of the ISO week of the year to 4 digits (e.g. "2004" for 1 Jan 2005) - * @li %g the year number in short form of the ISO week of the year to 2 digits (e.g. "04" for 1 Jan 2005) - * @li %u the day of the week number to 1 digit (e.g. "1" for Monday) - * @li %D the US short date format (e.g. "%m/%d/%y") - * @li %F the ISO short date format (e.g. "%Y-%m-%d") - * @li %x the KDE locale short date format - * @li %% the literal "%" - * @li %t a tab character - * - * Everything else in the format string will be taken as literal text. - * - * Examples: - * "%Y-%m-%d" = "2009-01-01" - * "%Y-%-m-%_4d" = "2009-1- 1" - * - * The following format codes behave differently in the KDE and POSIX standards - * @li %e in GNU/POSIX is space padded to 2 digits, in KDE is not padded - * @li %n in GNU/POSIX is newline, in KDE is short month number - * - * The following POSIX format codes are currently not supported: - * @li %U US week number - * @li %w US day of week - * @li %W US week number - * @li %O locale's alternative numeric symbols, in KDE is not supported - * - * %0 is not supported as the returned result is always in the locale's chosen numeric symbol digit set. - * - * @see Locale::formatDate - * - * @param fromDate the date to be formatted - * @param toFormat the date format to use - * @param formatStandard the standard the date format uses, defaults to KDE Standard - * - * @return The date as a string - */ - Q_INVOKABLE QString formatDate(const QDate &fromDate, const QString &toFormat, - Locale::DateTimeFormatStandard formatStandard = Locale::KdeFormat) const; - - //KDE5 Make virtual - /** - * - * Returns a string formatted to the given format string and Digit Set. - * Only use this version if you need control over the Digit Set and do - * not want to use the locale Digit Set. - * - * @see formatDate - * - * @param fromDate the date to be formatted - * @param toFormat the date format to use - * @param digitSet the Digit Set to format the date in - * @param formatStandard the standard the date format uses, defaults to KDE Standard - * - * @return The date as a string - */ - Q_INVOKABLE QString formatDate(const QDate &fromDate, const QString &toFormat, Locale::DigitSet digitSet, - Locale::DateTimeFormatStandard formatStandard = Locale::KdeFormat) const; - - //KDE5 Make virtual /** * * Returns a Date Component as a localized string in the requested format. * * For example for 2010-01-01 the Locale::Month with en_US Locale and Gregorian calendar may return: - * Locale::ShortNumber = "1" - * Locale::LongNumber = "01" - * Locale::NarrowName = "J" - * Locale::ShortName = "Jan" - * Locale::LongName = "January" + * CalendarSystem::ShortNumber = "1" + * CalendarSystem::LongNumber = "01" + * CalendarSystem::NarrowName = "J" + * CalendarSystem::ShortName = "Jan" + * CalendarSystem::LongName = "January" * * @param date The date to format * @param component The date component to return @@ -893,27 +626,8 @@ public: * @param weekNumberSystem To override the default Week Number System to use * @return The localized string form of the date component */ - Q_INVOKABLE QString formatDate(const QDate &date, Locale::DateTimeComponent component, - Locale::DateTimeComponentFormat format = Locale::DefaultComponentFormat, - Locale::WeekNumberSystem weekNumberSystem = Locale::DefaultWeekNumber) const; - - /** - * Converts a localized date string to a QDate. - * The bool pointed by @p ok will be @c false if the date entered was invalid. - * - * Uses the calendar system's internal locale set when the instance was - * created, which ensures that the correct calendar system and locale - * settings are respected, which would not occur in some cases if using - * the global locale. Defaults to global locale. - * - * @see Locale::readDate - * - * @param str the string to convert - * @param ok if non-null, will be set to @c true if the date is valid, @c false if invalid - * - * @return the string converted to a QDate - */ - Q_INVOKABLE QDate readDate(const QString &str, bool *ok = 0) const; + Q_INVOKABLE QString formatDate(const QDate &date, DateTimeComponent component, + DateTimeComponentFormat format, WeekNumberSystem weekNumberSystem) const; /** * Converts a localized date string to a QDate. @@ -933,87 +647,8 @@ public: * * @return the string converted to a QDate */ - Q_INVOKABLE QDate readDate(const QString &str, Locale::ReadDateFlags flags, bool *ok = 0) const; + Q_INVOKABLE QDate readDate(const QString &str, ReadDateFlags flags) const; - /** - * Converts a localized date string to a QDate, using the specified @p format. - * You will usually not want to use this method. Uses teh KDE format standard. - * - * @param dateString the string to convert - * @param dateFormat the date format to use, in KDE format standard - * @param ok if non-null, will be set to @c true if the date is valid, @c false if invalid - * - * @return the string converted to a QDate - * - * @see formatDate - * @see Locale::readDate - */ - Q_INVOKABLE QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok = 0) const; - - //KDE5 Make virtual - /** - * Converts a localized date string to a QDate, using the specified @p format. - * You will usually not want to use this method. - * - * You must supply a format and string containing at least one of the following combinations to - * create a valid date: - * @li a month and day of month - * @li a day of year - * @li a ISO week number and day of week - * - * If a year number is not supplied then the current year will be assumed. - * - * All date componants must be separated by a non-numeric character. - * - * The format is not applied strictly to the input string: - * @li extra whitespace is ignored - * @li leading 0's on numbers are ignored - * @li capitalisation of literals is ignored - * - * The allowed format componants are almost the same as the formatDate() function. - * The following date componants will be read: - * @li %Y the whole year (e.g. "1984" for 1984) - * @li %y the lower 2 digits of the year (e.g. "84" for 1984) - * @li %EY the full local era year (e.g. "2000 AD") - * @li %EC the era name short form (e.g. "AD") - * @li %Ey the year in era to 1 digit (e.g. 1 or 2000) - * @li %m the month number to two digits (January="01", December="12") - * @li %n the month number (January="1", December="12") - * @li %d the day number of the month to two digits (e.g. "01" on the first of March) - * @li %e the day number of the month (e.g. "1" on the first of March) - * @li %B the month name long form (e.g. "January") - * @li %b the month name short form (e.g. "Jan" for January) - * @li %h the month name short form (e.g. "Jan" for January) - * @li %A the weekday name long form (e.g. "Wednesday" for Wednesday) - * @li %a the weekday name short form (e.g. "Wed" for Wednesday) - * @li %j the day of the year number to three digits (e.g. "001" for 1 Jan) - * @li %V the ISO week of the year number to two digits (e.g. "01" for ISO Week 1) - * @li %u the day of the week number (e.g. "1" for Monday) - * - * The following date componants are NOT supported: - * @li %C the 'century' portion of the year (e.g. "19" for 1984, "5" for 584, "" for 84) - * @li %G the year number in long form of the ISO week of the year (e.g. "2004" for 1 Jan 2005) - * @li %g the year number in short form of the ISO week of the year (e.g. "04" for 1 Jan 2005) - * @li %D the US short date format (e.g. "%m/%d/%y") - * @li %F the ISO short date format (e.g. "%Y-%m-%d") - * @li %x the KDE locale short date format - * @li %% the literal "%" - * @li %t a tab character - * - * @param dateString the string to convert - * @param dateFormat the date format to use - * @param ok if non-null, will be set to @c true if the date is valid, @c false if invalid - * @param formatStandard the standard the date format uses - * - * @return the string converted to a QDate - * - * @see formatDate - * @see Locale::readDate - */ - Q_INVOKABLE QDate readDate(const QString &dateString, const QString &dateFormat, bool *ok, - Locale::DateTimeFormatStandard formatStandard) const; - - //KDE5 Make virtual /** * * Returns the Short Year Window Start Year for the current Calendar System. @@ -1044,7 +679,6 @@ public: */ int shortYearWindowStartYear() const; - //KDE5 Make virtual /** * * Returns the Year Number after applying the Year Window. diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 14dd61e45..9b441cc26 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -205,7 +205,7 @@ Item { console.log("convertDigits:" + locale.convertDigits(locale.digitSet, Locale.ArabicDigits)) for (var i in locale.allDigitSetsList) { - console.log("digia:" + locale.allDigitSetsList[i]) + console.log("digits:" + locale.allDigitSetsList[i]) } console.log("===========end===========") @@ -240,11 +240,6 @@ Item { console.log("isProleptic:" + calendar.isProleptic) //Q_INVOKABLE methods - console.log("isValid:" + calendar.isValid(2012, 02, 03)) - - console.log("isValid:" + calendar.isValid(2012, 33)) - - console.log("isValid:" + calendar.isValid(calendar.formatDate("2012-02-03"), 2010, 5, 5)) console.log("isValidIsoWeekDate:" + calendar.isValidIsoWeekDate(2012, 2, 3)) @@ -274,23 +269,19 @@ Item { console.log("daysDifference:" + calendar.daysDifference("2012-02-03", "2012-02-13")) - console.log("monthsInYear:" + calendar.monthsInYear("2012-02-03")) - console.log("monthsInYear:" + calendar.monthsInYear(2012)) - console.log("weeksInYear:" + calendar.weeksInYear("2012-02-03")) - - console.log("weeksInYear:" + calendar.weeksInYear(2012)) + console.log("weeksInYear:" + calendar.weeksInYear(2012, CalendarSystem.SimpleWeek)) console.log("daysInYear:" + calendar.daysInYear("2012-02-03")) - console.log("daysInMonth:" + calendar.daysInMonth("2012-02-03")) + console.log("daysInMonth:" + calendar.daysInMonth(2012, 8)) console.log("daysInWeek:" + calendar.daysInWeek("2012-02-03")) console.log("dayOfYear:" + calendar.dayOfYear("2012-02-03")) - console.log("week:" + calendar.week("2012-02-03")) + console.log("week:" + calendar.week("2012-02-03", CalendarSystem.SimpleWeek)) console.log("isLeapYear:" + calendar.isLeapYear(2012)) @@ -306,9 +297,9 @@ Item { console.log("weekDayName:" + calendar.weekDayName(3)) - console.log("formatDate:" + calendar.formatDate("2012-02-03")) + console.log("formatDate:" + calendar.formatDate("2012-02-03", CalendarSystem.Year, CalendarSystem.ShortNumber, CalendarSystem.SimpleWeek)) - console.log("readDate:" + calendar.readDate("2012-02-03")) + console.log("readDate:" + calendar.readDate("2012-02-03", CalendarSystem.NormalFormat)) console.log("applyShortYearWindow:" + calendar.applyShortYearWindow(50)) From c94a4917c4ba72c08958df535c4b325b3ed595dc Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Fri, 23 Mar 2012 15:46:46 +0200 Subject: [PATCH 086/104] fix the calendarSystemsList list --- declarativeimports/locale/calendarsystem.cpp | 6 +-- declarativeimports/locale/calendarsystem.h | 38 +------------------ .../tests/contents/code/klocaleqmltest.qml | 8 +++- 3 files changed, 12 insertions(+), 40 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 116a53314..d60f982d0 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -32,12 +32,12 @@ CalendarSystem::CalendarSystem(QObject* parent) m_calendarSystem = KCalendarSystem::create(KGlobal::locale()->calendarSystem()); } -QList CalendarSystem::calendarSystemsList() +QList CalendarSystem::calendarSystemsList() { - QList list; + QList list; foreach(KLocale::CalendarSystem calendarSystem, KCalendarSystem::calendarSystemsList()) { - list.append((Locale::CalendarSystem)calendarSystem); + list.append((int)calendarSystem); } return list; diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index c80b445c4..ced4cd829 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -49,6 +49,7 @@ Q_ENUMS(DateTimeComponent) Q_ENUMS(DateTimeComponentFormat) //properties +Q_PROPERTY(QList calendarSystemsList READ calendarSystemsList) Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem NOTIFY calendarSystemChanged)//read-only Q_PROPERTY(QString calendarLabel READ calendarLabel NOTIFY calendarLabelChanged)//read-only Q_PROPERTY(QDate epoch READ epoch NOTIFY epochChanged)//read-only @@ -172,41 +173,7 @@ public: * Returns the list of currently supported Calendar Systems * @return list of Calendar Systems */ - static QList calendarSystemsList();//TODO - - /** - * - * Returns a localized label to display for the required Calendar System type. - * - * Use with calendarSystemsList() to populate selection lists of available - * calendar systems. - * - * @param calendarSystem the specific calendar type to return the label for - * @param locale the locale to use for the label, defaults to global - * @return label for calendar - */ - Q_INVOKABLE static QString calendarLabel(Locale::CalendarSystem calendarSystem, const KLocale *locale = KGlobal::locale()); - - /** - * - * Returns the Calendar System enum value for a given Calendar Type, - * e.g. Locale::QDateCalendar for "gregorian" - * - * @param calendarType the calendar type to convert - * @return calendar system for calendar type - */ - Q_INVOKABLE static Locale::CalendarSystem calendarSystem(const QString &calendarType); - - //KDE5 remove - /** - * - * Returns the deprecated Calendar Type for a given Calendar System enum value, - * e.g. "gregorian" for Locale::QDateCalendar - * - * @param calendarSystem the calendar system to convert - * @return calendar type for calendar system - */ - Q_INVOKABLE static QString calendarType(Locale::CalendarSystem calendarSystem); + static QList calendarSystemsList(); /** * @@ -216,7 +183,6 @@ public: */ Locale::CalendarSystem calendarSystem() const; - //KDE5 make virtual? /** * * Returns a localized label to display for the current Calendar System type. diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 9b441cc26..bac186628 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -85,6 +85,7 @@ Item { console.log("decimalSymbol:" + locale.decimalSymbol) locale.digitSet = Locale.EasternArabicIndicDigits + console.log("digitSet:" + locale.digitSet) console.log("language:" + locale.language) @@ -205,7 +206,7 @@ Item { console.log("convertDigits:" + locale.convertDigits(locale.digitSet, Locale.ArabicDigits)) for (var i in locale.allDigitSetsList) { - console.log("digits:" + locale.allDigitSetsList[i]) + console.log("allDigitSetsList:" + locale.allDigitSetsList[i]) } console.log("===========end===========") @@ -303,6 +304,7 @@ Item { console.log("applyShortYearWindow:" + calendar.applyShortYearWindow(50)) + console.log("calendarSystem:" + calendar.calendarSystem) console.log("getDate:") hash = calendar.getDate("2012-02-03") for (var i in hash) { @@ -315,6 +317,10 @@ Item { console.log(" " + i, "=", hash[i]) } + for (var i in calendar.calendarSystemsList) { + console.log("calendarSystemsList:" + calendar.calendarSystemsList[i]) + } + console.log("===============end===============") } } From 1145d33e593285dc6e4b9433a79424920b217a31 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sat, 24 Mar 2012 19:22:19 +0200 Subject: [PATCH 087/104] Make virtual methods normal --- declarativeimports/locale/calendarsystem.h | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index ced4cd829..a76d44fe8 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -206,7 +206,7 @@ public: * * @return epoch of calendar system */ - virtual QDate epoch() const; + QDate epoch() const; /** * Returns the earliest date valid in this calendar system implementation. @@ -218,7 +218,7 @@ public: * * @return date the earliest valid date */ - virtual QDate earliestValidDate() const; + QDate earliestValidDate() const; /** * Returns the latest date valid in this calendar system implementation. @@ -228,7 +228,7 @@ public: * * @return date the latest valid date */ - virtual QDate latestValidDate() const; + QDate latestValidDate() const; /** * @@ -249,7 +249,6 @@ public: */ Q_INVOKABLE bool isValid(const QDate &date) const; - //KDE5 make virtual? /** * * Returns the year, month and day portion of a given date in the current calendar system @@ -285,7 +284,6 @@ public: */ Q_INVOKABLE int day(const QDate &date) const; - //KDE5 make virtual? /** * * Returns the Era Name portion of a given date in the current calendar system, @@ -297,7 +295,6 @@ public: */ Q_INVOKABLE QString eraName(const QDate &date, StringFormat format = ShortFormat) const; - //KDE5 make virtual? /** * * Returns the Era Year portion of a given date in the current @@ -309,7 +306,6 @@ public: */ Q_INVOKABLE QString eraYear(const QDate &date, StringFormat format = ShortFormat) const; - //KDE5 make virtual? /** * * Returns the Year In Era portion of a given date in the current calendar @@ -347,7 +343,6 @@ public: */ Q_INVOKABLE QDate addDays(const QDate &date, int ndays) const; - //KDE5 make virtual? /** * Returns the difference between two dates with a hash, the available keys are * ["years"] Returns number of years difference @@ -368,7 +363,6 @@ public: */ Q_INVOKABLE QVariantHash dateDifference(const QDate &fromDate, const QDate &toDate)const; - //KDE5 make virtual? /** * Returns the difference between two dates in completed calendar years. * The returned value will be negative if @p fromDate > @p toDate. @@ -381,7 +375,6 @@ public: */ Q_INVOKABLE int yearsDifference(const QDate &fromDate, const QDate &toDate) const; - //KDE5 make virtual? /** * Returns the difference between two dates in completed calendar months * The returned value will be negative if @p fromDate > @p toDate. @@ -396,7 +389,6 @@ public: */ Q_INVOKABLE int monthsDifference(const QDate &fromDate, const QDate &toDate) const; - //KDE5 make virtual? /** * Returns the difference between two dates in days * The returned value will be negative if @p fromDate > @p toDate. @@ -522,7 +514,6 @@ public: */ Q_INVOKABLE QDate firstDayOfYear(int year) const; - //KDE5 Make virtual? /** * @since 4.6 * @@ -543,7 +534,6 @@ public: */ Q_INVOKABLE QDate firstDayOfMonth(int year, int month) const; - //KDE5 Make virtual? /** * * Returns a QDate containing the last day of the month From b503963b40fc8806d6e8f8866d463ac3fef6e398 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sat, 24 Mar 2012 19:22:43 +0200 Subject: [PATCH 088/104] Fix calendar.readDate --- .../locale/tests/contents/code/klocaleqmltest.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index bac186628..6b565295b 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -300,7 +300,7 @@ Item { console.log("formatDate:" + calendar.formatDate("2012-02-03", CalendarSystem.Year, CalendarSystem.ShortNumber, CalendarSystem.SimpleWeek)) - console.log("readDate:" + calendar.readDate("2012-02-03", CalendarSystem.NormalFormat)) + console.log("readDate:" + calendar.readDate("2012-02-03", CalendarSystem.IsoFormat)) console.log("applyShortYearWindow:" + calendar.applyShortYearWindow(50)) From 1bfb4e00832a5e4b8fdc66dd86a1aa3989b72d5f Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sat, 24 Mar 2012 19:29:37 +0200 Subject: [PATCH 089/104] Remove a few more overloaded methods --- declarativeimports/locale/calendarsystem.cpp | 16 ---------------- .../tests/contents/code/klocaleqmltest.qml | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index d60f982d0..7cbd0fb59 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -43,22 +43,6 @@ QList CalendarSystem::calendarSystemsList() return list; } -QString CalendarSystem::calendarLabel(Locale::CalendarSystem calendarSystem, const KLocale *locale) -{ - return KCalendarSystem::calendarLabel((KLocale::CalendarSystem)calendarSystem, locale); -} - -QString CalendarSystem::calendarType(Locale::CalendarSystem calendarSystem) -{ - return KCalendarSystem::calendarType((KLocale::CalendarSystem)calendarSystem); -} - - -Locale::CalendarSystem CalendarSystem::calendarSystem(const QString &calendarType ) -{ - return (Locale::CalendarSystem)KCalendarSystem::calendarSystem(calendarType); -} - Locale::CalendarSystem CalendarSystem::calendarSystem() const { return (Locale::CalendarSystem)m_calendarSystem->calendarSystem(); diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 6b565295b..2dd2496f3 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -221,7 +221,7 @@ Item { onClicked:{ console.log("=====CalendarSystem Component====") - console.log("calendarLabel:" + calendar.CalendarLabel) + console.log("calendarLabel:" + calendar.CalendarLabel) //TODO console.log("epoch:" + calendar.epoch) From df1290b1ec15bfb6511d55d152cda1d2665198ce Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sat, 24 Mar 2012 19:31:35 +0200 Subject: [PATCH 090/104] Remove the @since --- declarativeimports/locale/calendarsystem.cpp | 1 - declarativeimports/locale/calendarsystem.h | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 7cbd0fb59..1fbfb52ad 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -66,7 +66,6 @@ QDate CalendarSystem::earliestValidDate() const QDate CalendarSystem::latestValidDate() const { - // Default to Gregorian 9999-12-31 return m_calendarSystem->latestValidDate(); } diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index a76d44fe8..1b12cd6eb 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -157,7 +157,7 @@ public: LongName, /**< Long name format, e.g. "December" */ ShortNamePossessive, /**< Short name possessive format, e.g. "of Dec" */ LongNamePossessive, /**< Long name possessive format, e.g. "of December" */ - NarrowName /**< Narrow name format, e.g. "D". @since 4.7 */ + NarrowName /**< Narrow name format, e.g. "D" */ }; /** @@ -166,7 +166,7 @@ public: enum WeekDayNameFormat { ShortDayName, /**< Short name format, e.g. "Fri" */ LongDayName, /**< Long name format, e.g. "Friday" */ - NarrowDayName /**< Narrow name format, e.g. "F". @since 4.7 */ + NarrowDayName /**< Narrow name format, e.g. "F" */ }; /** @@ -515,7 +515,6 @@ public: Q_INVOKABLE QDate firstDayOfYear(int year) const; /** - * @since 4.6 * * Returns a QDate containing the last day of the year * From cc54b44fa20cbe7accefeaa0ff08534440c4eae6 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Sat, 24 Mar 2012 19:36:59 +0200 Subject: [PATCH 091/104] Fix the includes in CalendarSystem --- declarativeimports/locale/calendarsystem.cpp | 7 ++++--- declarativeimports/locale/calendarsystem.h | 7 +++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.cpp b/declarativeimports/locale/calendarsystem.cpp index 1fbfb52ad..7ae42ad7f 100644 --- a/declarativeimports/locale/calendarsystem.cpp +++ b/declarativeimports/locale/calendarsystem.cpp @@ -17,13 +17,14 @@ Boston, MA 02110-1301, USA. */ +//own #include "calendarsystem.h" -#include "kdebug.h" -#include "kconfiggroup.h" +//KDE #include -#include #include + +//Qt #include CalendarSystem::CalendarSystem(QObject* parent) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 1b12cd6eb..ea2883c49 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -21,14 +21,13 @@ #ifndef CALENDARSYSTEM_H #define CALENDARSYSTEM_H +//own #include "locale.h" // needed for enums -#include "kglobal.h" -#include +//Qt #include class KCalendarSystem; -class KCalendarEra; /** * CalendarSystem abstract base class, provides support for local Calendar Systems in KDE @@ -49,7 +48,7 @@ Q_ENUMS(DateTimeComponent) Q_ENUMS(DateTimeComponentFormat) //properties -Q_PROPERTY(QList calendarSystemsList READ calendarSystemsList) +Q_PROPERTY(QList calendarSystemsList READ calendarSystemsList) //read-only Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem NOTIFY calendarSystemChanged)//read-only Q_PROPERTY(QString calendarLabel READ calendarLabel NOTIFY calendarLabelChanged)//read-only Q_PROPERTY(QDate epoch READ epoch NOTIFY epochChanged)//read-only From ee1ce0dca9c77e5e903854e3a44d29749074d735 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 26 Mar 2012 11:06:00 +0300 Subject: [PATCH 092/104] Make the static methods normal ones --- declarativeimports/locale/calendarsystem.h | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index ea2883c49..184a37e38 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -29,11 +29,6 @@ class KCalendarSystem; -/** - * CalendarSystem abstract base class, provides support for local Calendar Systems in KDE - * - * Derived classes must be created through the create() static method - */ class CalendarSystem : public QObject { Q_OBJECT @@ -169,10 +164,10 @@ public: }; /** - * Returns the list of currently supported Calendar Systems - * @return list of Calendar Systems - */ - static QList calendarSystemsList(); + * Returns the list of currently supported Calendar Systems + * @return list of Calendar Systems + */ + QList calendarSystemsList(); /** * @@ -188,7 +183,7 @@ public: * * @return localized label for this Calendar System */ - QString calendarLabel() const; + QString calendarLabel() const; //TODO, it returns undefined /** * Returns a QDate holding the epoch of the calendar system. Usually YMD From feefca269bc5ec61144adc8ca0a4b0dad5d965aa Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 26 Mar 2012 11:27:36 +0300 Subject: [PATCH 093/104] Remove the overloaded methods from Locale --- declarativeimports/locale/locale.cpp | 35 ++------ declarativeimports/locale/locale.h | 80 +------------------ .../tests/contents/code/klocaleqmltest.qml | 6 +- 3 files changed, 13 insertions(+), 108 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 315551426..5add0f504 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -198,11 +198,6 @@ QString Locale::formatMoney(double num, const QString &symbol, int precision) co return m_locale->formatMoney(num, symbol, precision); } -QString Locale::formatNumber(double num, int precision) const -{ - return m_locale->formatNumber(num, precision); -} - QString Locale::formatLong(long num) const { return m_locale->formatLong(num); @@ -265,23 +260,15 @@ double Locale::readMoney(const QString &_str, bool *ok) const return m_locale->readMoney(_str, ok); } -QDate Locale::readDate(const QString &intstr, bool *ok) const +QDate Locale::readDate(const QString &intstr, ReadDateFlags flags) const { - return m_locale->readDate(intstr, ok); + bool *ok; + return m_locale->readDate(intstr, (KLocale::ReadDateFlags)flags, ok); } -QDate Locale::readDate(const QString &intstr, ReadDateFlags flags, bool *ok) const -{ - return m_locale->readDate(intstr, (KLocale::ReadDateFlags)flags, ok); -} - -QDate Locale::readDate(const QString &intstr, const QString &fmt, bool *ok) const -{ - return m_locale->readDate(intstr, fmt, ok); -} - -QTime Locale::readTime(const QString &intstr, bool *ok) const +QTime Locale::readTime(const QString &intstr) const { + bool *ok; return m_locale->readTime(intstr, ok); } @@ -319,12 +306,7 @@ QStringList Locale::currencyCodeList() const return m_locale->currencyCodeList(); } -QString Locale::formatDateTime(const QDateTime &dateTime, Locale::DateFormat format, bool includeSeconds) const -{ - return m_locale->formatDateTime(dateTime, (KLocale::DateFormat)format, (KLocale::DateFormat)includeSeconds); -} - -QString Locale::formatDateTime(const KDateTime &dateTime, Locale::DateFormat format, DateTimeFormatOptions options) const +QString Locale::formatDateTime(const QDateTime &dateTime, Locale::DateFormat format, DateTimeFormatOptions options) const { Q_UNUSED(format) Q_UNUSED(options) @@ -561,11 +543,6 @@ void Locale::setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem) emit WeekNumberSystemChanged(); } -Locale::WeekNumberSystem Locale::weekNumberSystem() -{ - return (Locale::WeekNumberSystem)m_locale->weekNumberSystem(); -} - Locale::WeekNumberSystem Locale::weekNumberSystem() const { return (Locale::WeekNumberSystem)m_locale->weekNumberSystem(); diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 27e5ecda3..d45e9831b 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -378,25 +378,6 @@ public: */ Q_INVOKABLE QString formatMoney(double num, const QString ¤cy = QString(), int precision = -1) const; - /** - * Given a double, converts that to a numeric string containing - * the localized numeric equivalent. - * - * e.g. given 123456.78F, return "123,456.78" (for some European country). - * - * If precision isn't specified or is < 0, then the default decimalPlaces() is used. - * - * This function is a wrapper that is provided for convenience. - * - * @param num The number to convert - * @param precision Number of decimal places used. - * - * @return The number as a localized string - * @see formatNumber(const QString, bool, int) - * @see decimalPlaces() - */ - Q_INVOKABLE QString formatNumber(double num, int precision = -1) const; - /** * Given a string representing a number, converts that to a numeric * string containing the localized numeric equivalent. @@ -743,19 +724,6 @@ public: */ Q_INVOKABLE QString formatDate(const QDate &date, DateFormat format = LongDate) const; - /** - * Returns a string formatted to the current locale's conventions - * regarding both date and time. - * - * @param dateTime the date and time to be formatted - * @param format category of date format to use - * @param includeSecs if @c true, the string will include the seconds part - * of the time; otherwise, the seconds will be omitted - * - * @return the date and time as a string - */ - Q_INVOKABLE QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate, - bool includeSecs = false) const; /** * Options for formatting date-time values. */ @@ -776,7 +744,7 @@ public: * * @return The date and time as a string */ - Q_INVOKABLE QString formatDateTime(const KDateTime &dateTime, DateFormat format = ShortDate, + Q_INVOKABLE QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate, DateTimeFormatOptions options = 0) const;//TODO /** @@ -921,17 +889,6 @@ public: */ void setWeekNumberSystem(Locale::WeekNumberSystem weekNumberSystem); - //KDE5 remove in favour of const version - /** - * - * Returns the type of Week Number System used in this Locale - * - * @see Klocale::WeekNumberSystem - * @see setWeekNumberSystem() - * @returns the Week Number System used - */ - Locale::WeekNumberSystem weekNumberSystem(); - /** * * Returns the type of Week Number System used in this Locale @@ -964,28 +921,6 @@ public: */ Q_INVOKABLE double readNumber(const QString &numStr, bool * ok = 0) const; - /** - * Converts a localized date string to a QDate. This method will try all - * ReadDateFlag formats in preferred order to read a valid date. - * - * The bool pointed by ok will be invalid if the date entered was not valid. - * - * @param str the string we want to convert. - * @param ok the boolean that is set to false if it's not a valid date. - * If @p ok is 0, it will be ignored - * - * @return The string converted to a QDate - * @see CalendarSystem::readDate() - */ - Q_INVOKABLE QDate readDate(const QString &str, bool* ok = 0) const; - - /** - * Converts a localized date string to a QDate, using the specified format. - * You will usually not want to use this method. - * @see CalendarSystem::readDate() - */ - Q_INVOKABLE QDate readDate(const QString &intstr, const QString &fmt, bool* ok = 0) const; - /** * Flags for readDate() */ @@ -1009,27 +944,20 @@ public: * * @param str the string we want to convert. * @param flags what format the the date string will be in - * @param ok the boolean that is set to false if it's not a valid date. - * If @p ok is 0, it will be ignored - * * @return The string converted to a QDate * @see CalendarSystem::readDate() */ - Q_INVOKABLE QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; + Q_INVOKABLE QDate readDate(const QString &str, ReadDateFlags flags) const; /** * Converts a localized time string to a QTime. * This method will try to parse it with seconds, then without seconds. - * The bool pointed to by @p ok will be set to false if the time entered was - * not valid. * * @param str the string we want to convert. - * @param ok the boolean that is set to false if it's not a valid time. - * If @p ok is 0, it will be ignored * * @return The string converted to a QTime */ - Q_INVOKABLE QTime readTime(const QString &str, bool* ok = 0) const; + Q_INVOKABLE QTime readTime(const QString &str) const; /** * Additional processing options for readLocaleTime(). @@ -1158,7 +1086,7 @@ public: * @see QFile::encodeName * @see QFile::decodeName */ - int fileEncodingMib() const; + int fileEncodingMib() const; //TODO returns undefined /** * Changes the current date format. diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 2dd2496f3..441713d1d 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -182,16 +182,16 @@ Item { console.log("formatLocaleTime:" + locale.formatLocaleTime("2010-05-05")) - console.log("dayPeriodText:" + locale.dayPeriodText("2010-05-05")) + console.log("dayPeriodText:" + locale.dayPeriodText("11:22:33")) console.log("readMoney:" + locale.readMoney("$ 21")) console.log("readNumber:" + locale.readNumber(locale.convertDigits(locale.digitSet, Locale.ArabicDigits))) console.log("readNumber:" + locale.readNumber(10.0,3)) - console.log("readDate:" + locale.readDate("2004-02-01")) + console.log("readDate:" + locale.readDate("2004-02-01", Locale.IsoFormat)) - console.log("readTime:" + locale.readTime("11:22:33"))//TODO + console.log("readTime:" + locale.readTime("11:22:33"))//TODO its value in nothing(blank) console.log("readLocaleTime:" + locale.readLocaleTime("11:12:13 AM")) From f84c3642a68edc226cf57607a012ca205e234002 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 26 Mar 2012 11:30:33 +0300 Subject: [PATCH 094/104] Fix the includes in locale.h/cpp --- declarativeimports/locale/locale.cpp | 5 +++++ declarativeimports/locale/locale.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 5add0f504..534521dc9 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -18,8 +18,13 @@ Boston, MA 02110-1301, USA. */ +//own #include "locale.h" + +//KDE #include + +//Qt #include #include diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index d45e9831b..0ec758cdc 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -20,8 +20,10 @@ #ifndef LOCALE_H #define LOCALE_H +//Qt #include +//KDE #include class QString; From 0c62466b9924d5e248fbd1b84e779f9e55ad6732 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Mon, 26 Mar 2012 11:41:26 +0300 Subject: [PATCH 095/104] Remove some parameters --- declarativeimports/locale/locale.cpp | 6 ++++-- declarativeimports/locale/locale.h | 7 ++----- .../locale/tests/contents/code/klocaleqmltest.qml | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 534521dc9..f8bd19437 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -255,13 +255,15 @@ void Locale::setMainCatalog(const char *catalog) KLocale::setMainCatalog(catalog); } -double Locale::readNumber(const QString &_str, bool * ok) const +double Locale::readNumber(const QString &_str) const { + bool *ok; return m_locale->readNumber(_str, ok); } -double Locale::readMoney(const QString &_str, bool *ok) const +double Locale::readMoney(const QString &_str) const { + bool *ok; return m_locale->readMoney(_str, ok); } diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 0ec758cdc..4fbcaeb64 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -910,18 +910,15 @@ public: * * @return The string converted to a double */ - Q_INVOKABLE double readMoney(const QString &numStr, bool * ok = 0) const; + Q_INVOKABLE double readMoney(const QString &numStr) const; /** * Converts a localized numeric string to a double. * * @param numStr the string we want to convert. - * @param ok the boolean that is set to false if it's not a number. - * If @p ok is 0, it will be ignored - * * @return The string converted to a double */ - Q_INVOKABLE double readNumber(const QString &numStr, bool * ok = 0) const; + Q_INVOKABLE double readNumber(const QString &numStr) const; /** * Flags for readDate() diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 441713d1d..a77c6778a 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -186,7 +186,6 @@ Item { console.log("readMoney:" + locale.readMoney("$ 21")) - console.log("readNumber:" + locale.readNumber(locale.convertDigits(locale.digitSet, Locale.ArabicDigits))) console.log("readNumber:" + locale.readNumber(10.0,3)) console.log("readDate:" + locale.readDate("2004-02-01", Locale.IsoFormat)) From 0e702d85f58576f918802963525a079be6db8ff8 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Thu, 29 Mar 2012 23:14:19 +0300 Subject: [PATCH 096/104] Fix the Q_DECLARE_FLAGS parameters --- declarativeimports/locale/locale.cpp | 14 +++++--------- declarativeimports/locale/locale.h | 2 +- .../locale/tests/contents/code/klocaleqmltest.qml | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index f8bd19437..63213b297 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -279,18 +279,16 @@ QTime Locale::readTime(const QString &intstr) const return m_locale->readTime(intstr, ok); } -QTime Locale::readLocaleTime(const QString &intstr, bool *ok, TimeFormatOptions options, +QTime Locale::readLocaleTime(const QString &intstr, TimeFormatOptions options, TimeProcessingOptions processing) const { - Q_UNUSED(options) - Q_UNUSED(processing) - return m_locale->readLocaleTime(intstr, ok); + bool *ok; + return m_locale->readLocaleTime(intstr, ok, (KLocale::TimeFormatOptions)(int)options, (KLocale::TimeProcessingOptions)(int)processing); } QString Locale::formatLocaleTime(const QTime &time, TimeFormatOptions options) const { - Q_UNUSED(options) - return m_locale->formatLocaleTime(time); + return m_locale->formatLocaleTime(time, (KLocale::TimeFormatOptions)(int)options); } bool Locale::use12Clock() const @@ -315,9 +313,7 @@ QStringList Locale::currencyCodeList() const QString Locale::formatDateTime(const QDateTime &dateTime, Locale::DateFormat format, DateTimeFormatOptions options) const { - Q_UNUSED(format) - Q_UNUSED(options) - return m_locale->formatDateTime(dateTime); + return m_locale->formatDateTime(dateTime, (KLocale::DateFormat)format, (KLocale::DateTimeFormatOptions)(int)options); } void Locale::setDateFormat(const QString &format) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 4fbcaeb64..f52761e4c 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -993,7 +993,7 @@ public: * @return The string converted to a QTime */ - Q_INVOKABLE QTime readLocaleTime(const QString &str, bool *ok = 0, + Q_INVOKABLE QTime readLocaleTime(const QString &str, TimeFormatOptions options = Locale::TimeDefault, TimeProcessingOptions processing = ProcessNonStrict) const; diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index a77c6778a..0e61bb326 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -180,7 +180,7 @@ Item { console.log("prettyFormatDuration:" + locale.prettyFormatDuration(10)) - console.log("formatLocaleTime:" + locale.formatLocaleTime("2010-05-05")) + console.log("formatLocaleTime:" + locale.formatLocaleTime("11:12:13")) console.log("dayPeriodText:" + locale.dayPeriodText("11:22:33")) @@ -192,7 +192,7 @@ Item { console.log("readTime:" + locale.readTime("11:22:33"))//TODO its value in nothing(blank) - console.log("readLocaleTime:" + locale.readLocaleTime("11:12:13 AM")) + console.log("readLocaleTime:" + locale.readLocaleTime("11:12:13")) console.log("fileEncodingMib:" + locale.fileEncodingMib) From d1f8e46a3e8ce733e7979b038100eb4ffecf2f41 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Fri, 13 Apr 2012 19:51:07 +0300 Subject: [PATCH 097/104] Remove the signals and make the properties constants --- declarativeimports/locale/calendarsystem.h | 37 +++----- declarativeimports/locale/locale.h | 42 +++------ .../tests/contents/code/klocaleqmltest.qml | 87 ------------------- 3 files changed, 26 insertions(+), 140 deletions(-) diff --git a/declarativeimports/locale/calendarsystem.h b/declarativeimports/locale/calendarsystem.h index 184a37e38..3f25f0f8a 100644 --- a/declarativeimports/locale/calendarsystem.h +++ b/declarativeimports/locale/calendarsystem.h @@ -43,18 +43,18 @@ Q_ENUMS(DateTimeComponent) Q_ENUMS(DateTimeComponentFormat) //properties -Q_PROPERTY(QList calendarSystemsList READ calendarSystemsList) //read-only -Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem NOTIFY calendarSystemChanged)//read-only -Q_PROPERTY(QString calendarLabel READ calendarLabel NOTIFY calendarLabelChanged)//read-only -Q_PROPERTY(QDate epoch READ epoch NOTIFY epochChanged)//read-only -Q_PROPERTY(QDate earliestValidDate READ earliestValidDate NOTIFY earliestValidDateChanged)//read-only -Q_PROPERTY(QDate latestValidDate READ latestValidDate NOTIFY latestValidDateChanged)//read-only -Q_PROPERTY(int shortYearWindowStartYear READ shortYearWindowStartYear NOTIFY shortYearWindowStartYearChanged) -Q_PROPERTY(int weekStartDay READ weekStartDay NOTIFY weekStartDayChanged)//read-only -Q_PROPERTY(bool isLunar READ isLunar NOTIFY isLunarChanged)//read-only -Q_PROPERTY(bool isLunisolar READ isLunisolar NOTIFY isLunisolarChanged)//read-only -Q_PROPERTY(bool isSolar READ isSolar NOTIFY isSolarChanged)//read-only -Q_PROPERTY(bool isProleptic READ isProleptic NOTIFY isProlepticChanged)//read-only +Q_PROPERTY(QList calendarSystemsList READ calendarSystemsList CONSTANT) //read-only +Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem CONSTANT)//read-only +Q_PROPERTY(QString calendarLabel READ calendarLabel CONSTANT)//read-only +Q_PROPERTY(QDate epoch READ epoch CONSTANT)//read-only +Q_PROPERTY(QDate earliestValidDate READ earliestValidDate CONSTANT)//read-only +Q_PROPERTY(QDate latestValidDate READ latestValidDate CONSTANT)//read-only +Q_PROPERTY(int shortYearWindowStartYear READ shortYearWindowStartYear CONSTANT) +Q_PROPERTY(int weekStartDay READ weekStartDay CONSTANT)//read-only +Q_PROPERTY(bool isLunar READ isLunar CONSTANT)//read-only +Q_PROPERTY(bool isLunisolar READ isLunisolar CONSTANT)//read-only +Q_PROPERTY(bool isSolar READ isSolar CONSTANT)//read-only +Q_PROPERTY(bool isProleptic READ isProleptic CONSTANT)//read-only public: @@ -690,19 +690,6 @@ public: */ bool isProleptic() const; -Q_SIGNALS: - void calendarSystemChanged(); - void calendarLabelChanged(); - void epochChanged(); - void earliestValidDateChanged(); - void latestValidDateChanged(); - void shortYearWindowStartYearChanged(); - void weekStartDayChanged(); - void isLunarChanged(); - void isLunisolarChanged(); - void isSolarChanged(); - void isProlepticChanged(); - private: KCalendarSystem *m_calendarSystem; }; diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index f52761e4c..1fd739c5a 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -81,7 +81,7 @@ Q_ENUMS(WeekNumberSystem) //properties Q_PROPERTY(BinaryUnitDialect binaryUnitDialect READ binaryUnitDialect WRITE setBinaryUnitDialect NOTIFY binaryUnitDialectChanged) Q_PROPERTY(Locale::CalendarSystem calendarSystem READ calendarSystem WRITE setCalendarSystem NOTIFY calendarSystemChanged) -Q_PROPERTY(QString country READ country NOTIFY countryChanged) //read-only +Q_PROPERTY(QString country READ country CONSTANT) //read-only Q_PROPERTY(QString countryDivisionCode READ countryDivisionCode WRITE setCountryDivisionCode NOTIFY countryDivisionCodeChanged) Q_PROPERTY(QString currencyCode READ currencyCode WRITE setCurrencyCode NOTIFY currencyCodeChanged) Q_PROPERTY(QString currencySymbol READ currencySymbol WRITE setCurrencySymbol NOTIFY currencySymbolChanged) @@ -92,7 +92,7 @@ Q_PROPERTY(DigitSet dateTimeDigitSet READ dateTimeDigitSet WRITE setDateTimeDigi Q_PROPERTY(int decimalPlaces READ decimalPlaces WRITE setDecimalPlaces NOTIFY decimalPlacesChanged) Q_PROPERTY(QString decimalSymbol READ decimalSymbol WRITE setDecimalSymbol NOTIFY decimalSymbolChanged) Q_PROPERTY(DigitSet digitSet READ digitSet WRITE setDigitSet NOTIFY digitSetChanged) -Q_PROPERTY(QString language READ language NOTIFY languageChanged) //read-only +Q_PROPERTY(QString language READ language CONSTANT) //read-only Q_PROPERTY(MeasureSystem measureSystem READ measureSystem WRITE setMeasureSystem NOTIFY measureSystemChanged) Q_PROPERTY(int monetaryDecimalPlaces READ monetaryDecimalPlaces WRITE setMonetaryDecimalPlaces NOTIFY monetaryDecimalPlacesChanged) Q_PROPERTY(QString monetaryDecimalSymbol READ monetaryDecimalSymbol WRITE setMonetaryDecimalSymbol NOTIFY monetaryDecimalSymbolChanged) @@ -111,18 +111,18 @@ Q_PROPERTY(Locale::WeekNumberSystem weekNumberSystem READ weekNumberSystem WRITE Q_PROPERTY(int weekStartDay READ weekStartDay WRITE setWeekStartDay NOTIFY weekStartDayChanged) Q_PROPERTY(int workingWeekEndDay READ workingWeekEndDay WRITE setWorkingWeekEndDay NOTIFY workingWeekEndDayChanged) Q_PROPERTY(int workingWeekStartDay READ workingWeekStartDay WRITE setWorkingWeekStartDay NOTIFY workingWeekStartDayChanged) -Q_PROPERTY(bool use12Clock READ use12Clock NOTIFY use12ClockChanged) -Q_PROPERTY(QString defaultLanguage READ defaultLanguage NOTIFY defaultLanguageChanged)//read-only -Q_PROPERTY(QString defaultCountry READ defaultCountry NOTIFY defaultCountryChanged)//read-only -Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode NOTIFY defaultCurrencyCodeChanged)//read-only -Q_PROPERTY(bool useTranscript READ useTranscript NOTIFY useTranscriptChanged) //read-only -Q_PROPERTY(int fileEncodingMib READ fileEncodingMib NOTIFY fileEncodingMibChanged) //read-only -Q_PROPERTY(QStringList languageList READ languageList NOTIFY languageListChanged) //read-only -Q_PROPERTY(QStringList currencyCodeList READ currencyCodeList NOTIFY currencyCodeListChanged) //read-only -Q_PROPERTY(QStringList allLanguagesList READ allLanguagesList NOTIFY allLanguagesListChanged) //read-only -Q_PROPERTY(QStringList installedLanguages READ installedLanguages NOTIFY installedLanguagesChanged) //read-only -Q_PROPERTY(QStringList allCountriesList READ allCountriesList NOTIFY allCountriesListChanged) //read-only -Q_PROPERTY(QList allDigitSetsList READ allDigitSetsList NOTIFY allDigitSetsListChanged) //read-only +Q_PROPERTY(bool use12Clock READ use12Clock CONSTANT) +Q_PROPERTY(QString defaultLanguage READ defaultLanguage CONSTANT)//read-only +Q_PROPERTY(QString defaultCountry READ defaultCountry CONSTANT)//read-only +Q_PROPERTY(QString defaultCurrencyCode READ defaultCurrencyCode CONSTANT)//read-only +Q_PROPERTY(bool useTranscript READ useTranscript CONSTANT) //read-only +Q_PROPERTY(int fileEncodingMib READ fileEncodingMib CONSTANT) //read-only +Q_PROPERTY(QStringList languageList READ languageList CONSTANT) //read-only +Q_PROPERTY(QStringList currencyCodeList READ currencyCodeList CONSTANT) //read-only +Q_PROPERTY(QStringList allLanguagesList READ allLanguagesList CONSTANT) //read-only +Q_PROPERTY(QStringList installedLanguages READ installedLanguages CONSTANT) //read-only +Q_PROPERTY(QStringList allCountriesList READ allCountriesList CONSTANT) //read-only +Q_PROPERTY(QList allDigitSetsList READ allDigitSetsList CONSTANT) //read-only public: /** @@ -1604,7 +1604,6 @@ private: Q_SIGNALS: void binaryUnitDialectChanged(); void calendarSystemChanged(); - void countryChanged(); void countryDivisionCodeChanged(); void currencyCodeChanged(); void decimalSymbolChanged(); @@ -1615,7 +1614,6 @@ Q_SIGNALS: void dateTimeDigitSetChanged(); void decimalPlacesChanged(); void digitSetChanged(); - void languageChanged(); void measureSystemChanged(); void monetaryDecimalPlacesChanged(); void monetaryDecimalSymbolChanged(); @@ -1635,18 +1633,6 @@ Q_SIGNALS: void weekStartDayChanged(); void workingWeekEndDayChanged(); void workingWeekStartDayChanged(); - void use12ClockChanged(); - void defaultCountryChanged(); - void defaultCurrencyCodeChanged(); - void defaultLanguageChanged(); - void useTranscriptChanged(); - void fileEncodingMibChanged(); - void languageListChanged(); - void currencyCodeListChanged(); - void allLanguagesListChanged(); - void installedLanguagesChanged(); - void allCountriesListChanged(); - void allDigitSetsListChanged(); }; #endif diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index 0e61bb326..bab15a873 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -475,97 +475,10 @@ Item { onWorkingWeekStartDayChanged: { console.log("the workingWeekStartDay property has been changed") } - - onUse12ClockChanged: { - console.log("the use12Clock property has been changed") - } - - onDefaultLanguageChanged: { - console.log("the defaultLanguage property has been changed") - } - - onDefaultCountryChanged: { - console.log("the defaultCountry property has been changed") - } - - onDefaultCurrencyCodeChanged: { - console.log("the defaultCurrencyCode property has been changed") - } - - onUseTranscriptChanged: { - console.log("the useTranscript property has been changed") - } - - onCountryChanged: { - console.log("the country property has been changed") - } - - onLanguageChanged: { - console.log("the language property has been changed") - } - - onFileEncodingMibChanged: { - console.log("the fileEncodingMib property has been changed") - } - - onLanguageListChanged: { - console.log("the languageList property has been changed") - } - - onCurrencyCodeListChanged: { - console.log("the currencyCodeList property has been changed") - } - - onInstalledLanguagesChanged: { - console.log("the installedLanguages property has been changed") - } - - onAllCountriesListChanged: { - console.log("the allCountriesList property has been changed") - } - - onAllDigitSetsListChanged: { - console.log("the allDigitSetsList property has been changed") - } } CalendarSystem { id: calendar - - onCalendarSystemChanged: { - console.log("the calendarSystem property has been changed") - } - - onCalendarLabelChanged: { - console.log("the calendarLabel property has been changed") - } - onEpochChanged: { - console.log("the epoch property has been changed") - } - onEarliestValidDateChanged: { - console.log("the earliestValidDate property has been changed") - } - onLatestValidDateChanged: { - console.log("the latestValidDate property has been changed") - } - onShortYearWindowStartYearChanged: { - console.log("the shortYearWindowStartYear property has been changed") - } - onWeekStartDayChanged: { - console.log("the weekStartDay property has been changed") - } - onIsLunarChanged: { - console.log("the isLunar property has been changed") - } - onIsLunisolarChanged: { - console.log("the isLunisolar property has been changed") - } - onIsSolarChanged: { - console.log("the isSolar property has been changed") - } - onIsProlepticChanged: { - console.log("the isProleptic property has been changed") - } } } } From 17265ad14c90001a9079155c7cf266485297e27b Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 24 Apr 2012 23:10:29 +0300 Subject: [PATCH 098/104] Fix compile warnings --- declarativeimports/locale/locale.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 63213b297..33b003ada 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -31,7 +31,7 @@ Locale::Locale(QObject* parent) : QObject(parent) { - m_locale = new KLocale(*KGlobal::locale()); + m_locale = KGlobal::locale(); } bool Locale::setCountryDivisionCode(const QString &countryDivisionCode) @@ -257,33 +257,33 @@ void Locale::setMainCatalog(const char *catalog) double Locale::readNumber(const QString &_str) const { - bool *ok; - return m_locale->readNumber(_str, ok); + bool ok; + return m_locale->readNumber(_str, &ok); } double Locale::readMoney(const QString &_str) const { - bool *ok; - return m_locale->readMoney(_str, ok); + bool ok; + return m_locale->readMoney(_str, &ok); } QDate Locale::readDate(const QString &intstr, ReadDateFlags flags) const { - bool *ok; - return m_locale->readDate(intstr, (KLocale::ReadDateFlags)flags, ok); + bool ok; + return m_locale->readDate(intstr, (KLocale::ReadDateFlags)flags, &ok); } QTime Locale::readTime(const QString &intstr) const { - bool *ok; - return m_locale->readTime(intstr, ok); + bool ok; + return m_locale->readTime(intstr, &ok); } QTime Locale::readLocaleTime(const QString &intstr, TimeFormatOptions options, TimeProcessingOptions processing) const { - bool *ok; - return m_locale->readLocaleTime(intstr, ok, (KLocale::TimeFormatOptions)(int)options, (KLocale::TimeProcessingOptions)(int)processing); + bool ok; + return m_locale->readLocaleTime(intstr, &ok, (KLocale::TimeFormatOptions)(int)options, (KLocale::TimeProcessingOptions)(int)processing); } QString Locale::formatLocaleTime(const QTime &time, TimeFormatOptions options) const From 2bf1971ad43a88b767434a02c5135e9bf16422bd Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 24 Apr 2012 23:14:30 +0300 Subject: [PATCH 099/104] Fix the emit --- declarativeimports/locale/locale.cpp | 5 +++-- declarativeimports/locale/locale.h | 11 ----------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 33b003ada..21fad1bae 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -36,14 +36,15 @@ Locale::Locale(QObject* parent) bool Locale::setCountryDivisionCode(const QString &countryDivisionCode) { + bool ok = m_locale->setCountryDivisionCode(countryDivisionCode); emit countryDivisionCodeChanged(); - return m_locale->setCountryDivisionCode(countryDivisionCode); + return ok; } void Locale::setCurrencyCode(const QString &newCurrencyCode) { - emit currencyCodeChanged(); m_locale->setCurrencyCode(newCurrencyCode); + emit currencyCodeChanged(); } bool Locale::isApplicationTranslatedInto(const QString &lang) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 1fd739c5a..c9bb86b53 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -850,17 +850,6 @@ public: */ int weekDayOfPray() const; - /** - * What should I do with the above? - * It won't work in QML. - **/ - - /** - * Returns a pointer to the calendar system object. - * - * @return the current calendar system instance - */ - /** * * Returns the type of Calendar System used in this Locale From 5c890b1ba0ec0ffe394d0faacd5a446a4b7732ab Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Tue, 24 Apr 2012 13:25:00 +0300 Subject: [PATCH 100/104] fix the wrong format type from the readTime and readLocaleTime --- .../locale/tests/contents/code/klocaleqmltest.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index bab15a873..aa20c7b89 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -190,9 +190,9 @@ Item { console.log("readDate:" + locale.readDate("2004-02-01", Locale.IsoFormat)) - console.log("readTime:" + locale.readTime("11:22:33"))//TODO its value in nothing(blank) + console.log("readTime:" + locale.readTime("11:22:33 AM")) - console.log("readLocaleTime:" + locale.readLocaleTime("11:12:13")) + console.log("readLocaleTime:" + locale.readLocaleTime("11:12:13 AM")) console.log("fileEncodingMib:" + locale.fileEncodingMib) From bbc19904db40a98a48c7b25000b3c957bb5df643 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Mon, 30 Apr 2012 06:03:35 +0300 Subject: [PATCH 101/104] Remove unused enumenators --- declarativeimports/locale/locale.h | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index c9bb86b53..c64ec0b46 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -68,8 +68,6 @@ Q_ENUMS(DateFormat) Q_ENUMS(DateTimeComponent) Q_ENUMS(DateTimeComponentFormat) Q_ENUMS(DateTimeFormatOption ) -Q_ENUMS(DateTimeFormatStandard) -Q_ENUMS(DateTimeParseMode) Q_ENUMS(DigitSet) Q_ENUMS(MeasureSystem) Q_ENUMS(ReadDateFlags) @@ -610,32 +608,6 @@ public: SimpleWeek = 3 /**< Week 1 starts Jan 1st ends after 7 days */ }; - /** - * - * Standard used for Date Time Format String - */ - enum DateTimeFormatStandard { - KdeFormat, /**< KDE Standard */ - PosixFormat, /**< POSIX Standard */ - UnicodeFormat /**< UNICODE Standard (Qt/Java/OSX/Windows) */ - }; - - /** - * - * Mode to use when parsing a Date Time input string - */ - enum DateTimeParseMode { - LiberalParsing /**< Parse Date/Time liberally. So long as the - input string contains at least a reconizable - month and day the input will be accepted. */ - //ModerateParsing, /**< Parse Date/Time with modeate tolerance. - // The date components in the format must all - // occur in the input and in the same order, - // but the spacing and the componants themselves - // may vary from the strict format. */ - //StrictParsing /**< Parse Date/Time strictly to the format. */ - }; - /** * * The various Components that make up a Date / Time From 1d8b0c0714ec83043ab1aa12c9e4cc2555d204e2 Mon Sep 17 00:00:00 2001 From: Antonis Tsiapaliokas Date: Mon, 30 Apr 2012 06:17:33 +0300 Subject: [PATCH 102/104] Fix a typo for klocaleqmltest.qml and remove unnecessary TODOs --- declarativeimports/locale/locale.h | 4 ++-- .../locale/tests/contents/code/klocaleqmltest.qml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index c64ec0b46..4fe68087f 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -719,7 +719,7 @@ public: * @return The date and time as a string */ Q_INVOKABLE QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate, - DateTimeFormatOptions options = 0) const;//TODO + DateTimeFormatOptions options = 0) const; /** * Use this to determine whether in dates a possessive form of month @@ -1046,7 +1046,7 @@ public: * @see QFile::encodeName * @see QFile::decodeName */ - int fileEncodingMib() const; //TODO returns undefined + int fileEncodingMib() const; /** * Changes the current date format. diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml index aa20c7b89..3110e914a 100644 --- a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml +++ b/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml @@ -220,7 +220,7 @@ Item { onClicked:{ console.log("=====CalendarSystem Component====") - console.log("calendarLabel:" + calendar.CalendarLabel) //TODO + console.log("calendarLabel:" + calendar.calendarLabel) console.log("epoch:" + calendar.epoch) From 920a7a0649a5607ee7203c031639b3369dba28db Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Tue, 1 May 2012 22:16:42 +0300 Subject: [PATCH 103/104] Rename the test into org.kde.example.localetest --- declarativeimports/locale/CMakeLists.txt | 2 +- declarativeimports/locale/locale.cpp | 10 ---------- declarativeimports/locale/locale.h | 18 +----------------- .../locale/localebindingsplugin.cpp | 2 +- .../klocaleqmltest.qml => ui/localetest.qml} | 0 .../locale/tests/metadata.desktop | 6 +++--- 6 files changed, 6 insertions(+), 32 deletions(-) rename declarativeimports/locale/tests/contents/{code/klocaleqmltest.qml => ui/localetest.qml} (100%) diff --git a/declarativeimports/locale/CMakeLists.txt b/declarativeimports/locale/CMakeLists.txt index dea3e1e5c..e36f2c97f 100644 --- a/declarativeimports/locale/CMakeLists.txt +++ b/declarativeimports/locale/CMakeLists.txt @@ -21,5 +21,5 @@ kde4_add_library(localebindingsplugin SHARED ${localebindings_SRCS}) target_link_libraries(localebindingsplugin ${QT_QTDECLARATIVE_LIBRARY} ${KDE4_KDECORE_LIBRARY}) -install(TARGETS localebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) +install(TARGETS localebindingsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/locale) install(FILES qmldir DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/locale) diff --git a/declarativeimports/locale/locale.cpp b/declarativeimports/locale/locale.cpp index 21fad1bae..17bbfc603 100644 --- a/declarativeimports/locale/locale.cpp +++ b/declarativeimports/locale/locale.cpp @@ -78,11 +78,6 @@ QString Locale::currencyCode() const return m_locale->currencyCode(); } -void Locale::setActiveCatalog(const QString &catalog) -{ - m_locale->setActiveCatalog(catalog); -} - QString Locale::translateQt(const char *context, const char *sourceText, const char *comment) const { return m_locale->translateQt(context, sourceText, comment); @@ -251,11 +246,6 @@ QString Locale::formatDate(const QDate &date, Locale::DateFormat format) const return m_locale->formatDate(date, (KLocale::DateFormat)format); } -void Locale::setMainCatalog(const char *catalog) -{ - KLocale::setMainCatalog(catalog); -} - double Locale::readNumber(const QString &_str) const { bool ok; diff --git a/declarativeimports/locale/locale.h b/declarativeimports/locale/locale.h index 4fe68087f..7103ffebc 100644 --- a/declarativeimports/locale/locale.h +++ b/declarativeimports/locale/locale.h @@ -1350,12 +1350,6 @@ public: */ void setMeasureSystem(MeasureSystem value); - /** - * Sets the active catalog for translation lookup. - * @param catalog The catalog to activate. - */ - Q_INVOKABLE void setActiveCatalog(const QString &catalog); - /** * Translates a message as a QTranslator is supposed to. * The parameters are similar to i18n(), but the result @@ -1445,19 +1439,9 @@ public: * @param modifier set to the modifer part of the locale * @param charset set to the charset part of the locale */ - Q_INVOKABLE static void splitLocale(const QString &locale, QString &language, QString &country, + Q_INVOKABLE void splitLocale(const QString &locale, QString &language, QString &country, QString &modifier, QString &charset); - /** - * Use this as main catalog for *all* KLocales, if not the appname - * will be used. This function is best to be the very first instruction - * in your program's main function as it only has an effect before the - * first KLocale object is created. - * - * @param catalog Catalog to override all other main Catalogs. - */ - Q_INVOKABLE static void setMainCatalog(const char *catalog); - /** * Returns the name of the internal language. * diff --git a/declarativeimports/locale/localebindingsplugin.cpp b/declarativeimports/locale/localebindingsplugin.cpp index f8e292752..bee644682 100644 --- a/declarativeimports/locale/localebindingsplugin.cpp +++ b/declarativeimports/locale/localebindingsplugin.cpp @@ -25,7 +25,7 @@ void LocaleBindingsPlugin::registerTypes(const char *uri) { - Q_ASSERT(uri == QLatin1String("org.kde.plasma.locale")); + Q_ASSERT(uri == QLatin1String("org.kde.locale")); qmlRegisterType(uri, 0, 1, "Locale"); qmlRegisterType(uri, 0, 1, "CalendarSystem"); diff --git a/declarativeimports/locale/tests/contents/code/klocaleqmltest.qml b/declarativeimports/locale/tests/contents/ui/localetest.qml similarity index 100% rename from declarativeimports/locale/tests/contents/code/klocaleqmltest.qml rename to declarativeimports/locale/tests/contents/ui/localetest.qml diff --git a/declarativeimports/locale/tests/metadata.desktop b/declarativeimports/locale/tests/metadata.desktop index 797769bbe..f42171738 100644 --- a/declarativeimports/locale/tests/metadata.desktop +++ b/declarativeimports/locale/tests/metadata.desktop @@ -1,12 +1,12 @@ [Desktop Entry] -Name=KLocaleQMLtest +Name=org.kde.example.localetest Type=Service X-KDE-PluginInfo-Author=Giorgos Tsiapaliwkas X-KDE-PluginInfo-Email=terietor@gmail.com X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-Name=org.kde.klocaleqmltest +X-KDE-PluginInfo-Name=org.kde.example.localetest X-KDE-PluginInfo-Version=1 X-KDE-ServiceTypes=Plasma/Applet X-Plasma-API=declarativeappletscript X-Plasma-DefaultSize=200,100 -X-Plasma-MainScript=code/klocaleqmltest.qml +X-Plasma-MainScript=ui/localetest.qml From 835cd63c723533317736cc00ee1e4d9a9f65e782 Mon Sep 17 00:00:00 2001 From: Giorgos Tsiapaliwkas Date: Wed, 2 May 2012 12:34:28 +0300 Subject: [PATCH 104/104] Move declarativeimports/locale/test to declarativeimports/test and make the declarativeimports/test a plasmoid --- declarativeimports/test/{gallery => contents/ui}/Busy.qml | 0 .../test/{gallery => contents/ui}/Buttons.qml | 0 .../test/{gallery => contents/ui}/CheckableButtons.qml | 0 .../test/{gallery => contents/ui}/Gallery.qml | 6 +++++- .../ui/localetest.qml => test/contents/ui/Locale.qml} | 0 declarativeimports/test/{gallery => contents/ui}/Misc.qml | 0 .../test/{gallery => contents/ui}/Scrollers.qml | 0 .../test/{gallery => contents/ui}/Sliders.qml | 0 .../test/{gallery => contents/ui}/TextEditing.qml | 0 declarativeimports/test/{gallery => contents/ui}/Texts.qml | 0 declarativeimports/{locale/tests => test}/metadata.desktop | 6 +++--- 11 files changed, 8 insertions(+), 4 deletions(-) rename declarativeimports/test/{gallery => contents/ui}/Busy.qml (100%) rename declarativeimports/test/{gallery => contents/ui}/Buttons.qml (100%) rename declarativeimports/test/{gallery => contents/ui}/CheckableButtons.qml (100%) rename declarativeimports/test/{gallery => contents/ui}/Gallery.qml (96%) rename declarativeimports/{locale/tests/contents/ui/localetest.qml => test/contents/ui/Locale.qml} (100%) rename declarativeimports/test/{gallery => contents/ui}/Misc.qml (100%) rename declarativeimports/test/{gallery => contents/ui}/Scrollers.qml (100%) rename declarativeimports/test/{gallery => contents/ui}/Sliders.qml (100%) rename declarativeimports/test/{gallery => contents/ui}/TextEditing.qml (100%) rename declarativeimports/test/{gallery => contents/ui}/Texts.qml (100%) rename declarativeimports/{locale/tests => test}/metadata.desktop (68%) diff --git a/declarativeimports/test/gallery/Busy.qml b/declarativeimports/test/contents/ui/Busy.qml similarity index 100% rename from declarativeimports/test/gallery/Busy.qml rename to declarativeimports/test/contents/ui/Busy.qml diff --git a/declarativeimports/test/gallery/Buttons.qml b/declarativeimports/test/contents/ui/Buttons.qml similarity index 100% rename from declarativeimports/test/gallery/Buttons.qml rename to declarativeimports/test/contents/ui/Buttons.qml diff --git a/declarativeimports/test/gallery/CheckableButtons.qml b/declarativeimports/test/contents/ui/CheckableButtons.qml similarity index 100% rename from declarativeimports/test/gallery/CheckableButtons.qml rename to declarativeimports/test/contents/ui/CheckableButtons.qml diff --git a/declarativeimports/test/gallery/Gallery.qml b/declarativeimports/test/contents/ui/Gallery.qml similarity index 96% rename from declarativeimports/test/gallery/Gallery.qml rename to declarativeimports/test/contents/ui/Gallery.qml index b4f9f807e..d0aadb102 100644 --- a/declarativeimports/test/gallery/Gallery.qml +++ b/declarativeimports/test/contents/ui/Gallery.qml @@ -35,7 +35,6 @@ Rectangle { } } - ListView { id: pageSelector width: 200 @@ -77,6 +76,11 @@ Rectangle { page: "Misc.qml" title: "Misc stuff" } + + ListElement { + page: "Locale.qml" + title: "Locale stuff" + } } delegate: ListItem { enabled: true diff --git a/declarativeimports/locale/tests/contents/ui/localetest.qml b/declarativeimports/test/contents/ui/Locale.qml similarity index 100% rename from declarativeimports/locale/tests/contents/ui/localetest.qml rename to declarativeimports/test/contents/ui/Locale.qml diff --git a/declarativeimports/test/gallery/Misc.qml b/declarativeimports/test/contents/ui/Misc.qml similarity index 100% rename from declarativeimports/test/gallery/Misc.qml rename to declarativeimports/test/contents/ui/Misc.qml diff --git a/declarativeimports/test/gallery/Scrollers.qml b/declarativeimports/test/contents/ui/Scrollers.qml similarity index 100% rename from declarativeimports/test/gallery/Scrollers.qml rename to declarativeimports/test/contents/ui/Scrollers.qml diff --git a/declarativeimports/test/gallery/Sliders.qml b/declarativeimports/test/contents/ui/Sliders.qml similarity index 100% rename from declarativeimports/test/gallery/Sliders.qml rename to declarativeimports/test/contents/ui/Sliders.qml diff --git a/declarativeimports/test/gallery/TextEditing.qml b/declarativeimports/test/contents/ui/TextEditing.qml similarity index 100% rename from declarativeimports/test/gallery/TextEditing.qml rename to declarativeimports/test/contents/ui/TextEditing.qml diff --git a/declarativeimports/test/gallery/Texts.qml b/declarativeimports/test/contents/ui/Texts.qml similarity index 100% rename from declarativeimports/test/gallery/Texts.qml rename to declarativeimports/test/contents/ui/Texts.qml diff --git a/declarativeimports/locale/tests/metadata.desktop b/declarativeimports/test/metadata.desktop similarity index 68% rename from declarativeimports/locale/tests/metadata.desktop rename to declarativeimports/test/metadata.desktop index f42171738..7e0e2dbec 100644 --- a/declarativeimports/locale/tests/metadata.desktop +++ b/declarativeimports/test/metadata.desktop @@ -1,12 +1,12 @@ [Desktop Entry] -Name=org.kde.example.localetest +Name=org.kde.example.widgetgallery Type=Service X-KDE-PluginInfo-Author=Giorgos Tsiapaliwkas X-KDE-PluginInfo-Email=terietor@gmail.com X-KDE-PluginInfo-License=GPL -X-KDE-PluginInfo-Name=org.kde.example.localetest +X-KDE-PluginInfo-Name=org.kde.example.widgetgallery X-KDE-PluginInfo-Version=1 X-KDE-ServiceTypes=Plasma/Applet X-Plasma-API=declarativeappletscript X-Plasma-DefaultSize=200,100 -X-Plasma-MainScript=ui/localetest.qml +X-Plasma-MainScript=ui/Gallery.qml