home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / klocale.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  40.2 KB  |  1,341 lines

  1. // -*- c-basic-offset: 2 -*-
  2. /* This file is part of the KDE libraries
  3.     Copyright (C) 1997 Stephan Kulow <coolo@kde.org>
  4.     Copyright (C) 1999-2003 Hans Petter Bieker <bieker@kde.org>
  5.     Copyright (c) 2002 Lukas Tinkl <lukas@kde.org>
  6.  
  7.     This library is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU Library General Public
  9.     License as published by the Free Software Foundation; either
  10.     version 2 of the License, or (at your option) any later version.
  11.  
  12.     This library is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     Library General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU Library General Public License
  18.     along with this library; see the file COPYING.LIB.  If not, write to
  19.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20.     Boston, MA 02110-1301, USA.
  21. */
  22. #ifndef _KLOCALE_H
  23. #define _KLOCALE_H
  24.  
  25. #include <qstring.h>
  26. #include <kdelibs_export.h>
  27.  
  28. class QStringList;
  29. class QTextCodec;
  30. class QDate;
  31. class QTime;
  32. class QDateTime;
  33.  
  34. class KGlobal;
  35. class KConfig;
  36. class KConfigBase;
  37. class KLocalePrivate;
  38. class KCatalogue;
  39. class KCalendarSystem;
  40.  
  41. /**
  42.  * \file klocale.h
  43.  */
  44.  
  45. #ifndef I18N_NOOP
  46. /**
  47.  * \relates KLocale
  48.  * I18N_NOOP marks a string to be translated without translating it.
  49.  * Do not use this unless you know you need it.
  50.  * http://developer.kde.org/documentation/other/developer-faq.html#q2.11.2
  51.  */
  52. #define I18N_NOOP(x) x
  53. #endif
  54.  
  55. #ifndef I18N_NOOP2
  56. /**
  57.  * \relates KLocale
  58.  *  If the string is too ambiguous to be translated well to a non-english
  59.  *  language, use this instead of I18N_NOOP to separate lookup string and english.
  60.  * \warning You need to call i18n( comment, stringVar ) later on, not just i18n( stringVar ).
  61.  * \since 3.3
  62.  */
  63. #define I18N_NOOP2(comment,x) x
  64. #endif
  65.  
  66. /**
  67.  * \relates KLocale
  68.  *  i18n is the function that does everything you need to translate
  69.  *  a string. You just wrap around every user visible string a i18n
  70.  *  call to get a QString with the string in the user's preferred
  71.  *  language.
  72.  *
  73.  *  The argument must be an UTF-8 encoded string (If you only use
  74.  *  characters that are in US-ASCII, you're on the safe side. But
  75.  *  for e.g. German umlauts or French accents should be recoded to
  76.  *  UTF-8)
  77.  **/
  78. KDECORE_EXPORT QString i18n(const char *text);
  79.  
  80. /**
  81.  * \relates KLocale
  82.  *  If the string is too ambiguous to be translated well to a non-english
  83.  *  language, use this form of i18n to separate lookup string and english
  84.  *  text.
  85.  *  @see translate
  86.  **/
  87. KDECORE_EXPORT QString i18n(const char *comment, const char *text);
  88.  
  89. /**
  90.  * \relates KLocale
  91.  *  If you want to handle plural forms, use this form of i18n.
  92.  *  @param singular the singular form of the word, for example "file".
  93.   * @param plural the plural form of the word. Must contain a "%n" that will
  94.  *                be replaced by the number @p n, for example "%n files"
  95.  *  @param n the number
  96.  *  @return the correct singular or plural for the selected language,
  97.  *          depending on n
  98.  *  @see translate
  99.  **/
  100. KDECORE_EXPORT QString i18n(const char *singular, const char *plural, unsigned long n);
  101.  
  102. /**
  103.  * \relates KLocale
  104.  * Qt3's uic generates i18n( "msg", "comment" ) calls which conflict
  105.  * with our i18n method. We use uic -tr tr2i18n to redirect
  106.  * to the right i18n() function
  107. **/
  108. inline QString tr2i18n(const char* message, const char* =0) {
  109.   return i18n(message);
  110. }
  111.  
  112. /**
  113.   *
  114.   * KLocale provides support for country specific stuff like
  115.   * the national language.
  116.   *
  117.   * KLocale supports translating, as well as specifying the format
  118.   * for numbers, currency, time, and date.
  119.   *
  120.   * @author Stephan Kulow <coolo@kde.org>, Preston Brown <pbrown@kde.org>,
  121.   * Hans Petter Bieker <bieker@kde.org>, Lukas Tinkl <lukas.tinkl@suse.cz>
  122.   * @short class for supporting locale settings and national language
  123.   */
  124. class KDECORE_EXPORT KLocale
  125. {
  126.   friend class KGlobal; // for initInstance()
  127. public:
  128.   /**
  129.    * Constructs a KLocale with the given catalog name.
  130.    * The constructor looks for an entry Locale/Language in the
  131.    * configuration file.
  132.    * If no config file is specified, it will also look for languages
  133.    * using the environment variables (KDE_LANG, LC_MESSAGES, LC_ALL, LANG),
  134.    * as well as the global configuration file. If KLocale is not able to use
  135.    * any of the specified languages, the default language (en_US) will be
  136.    * used.
  137.    *
  138.    * If you specify a configuration file, it has to be valid until
  139.    * the KLocale object is destroyed.
  140.    *
  141.    * @param catalog The name of the main language file
  142.    * @param config The configuration file to use.
  143.    */
  144.   KLocale( const QString& catalog, KConfig *config = 0 );
  145.  
  146.   /**
  147.    * Copy constructor.
  148.    */
  149.   KLocale( const KLocale & rhs );
  150.  
  151.   /**
  152.    * Assignment operator.
  153.    */
  154.   KLocale& operator= ( const KLocale & rhs );
  155.  
  156.   /**
  157.    * Destructor.
  158.    */
  159.   ~KLocale();
  160.  
  161.   /**
  162.    * Translates the string into the corresponding string in
  163.    * the national language, if available. If not, returns
  164.    * the string itself.
  165.    * There is a KDE wide message file that contains the most
  166.    * often used phrases, so we can avoid duplicating the
  167.    * translation of these phrases. If a phrase is not found
  168.    * in the catalog given to the constructor, it will search
  169.    * in the system catalog. This makes it possible to override
  170.    * some phrases for your needs.
  171.    *
  172.    * The argument must be an UTF-8 encoded string (If you only use
  173.    * characters that are in US-ASCII you're on the safe side. But
  174.    * for e.g. german umlauts or french accents should be recoded to
  175.    * UTF-8)
  176.    *
  177.    * @param index The lookup text and default text, if not found.
  178.    */
  179.   QString translate( const char *index ) const;
  180.  
  181.   /**
  182.    * Translates the string into the corresponding string in the
  183.    * national language, if available.
  184.    *
  185.    * The real contents of the string is in the argument fallback,
  186.    * but the meaning of it is coded into the argument index.
  187.    * In some cases you'll need this function, when english is
  188.    * too ambiguous to express it.
  189.    *
  190.    * Most of the times the translators will tell you if it can't
  191.    * be translated as it, but think of cases as "New", where the
  192.    * translations differs depending on what is New.
  193.    * Or simple cases as "Open", that can be used to express something
  194.    * is open or it can be used to express that you want something to
  195.    * open... There are tons of such examples.
  196.    *
  197.    * If translate("Open") is not enough to translate it well, use
  198.    * translate("To Open", "Open") or translate("Is Open", "Open").
  199.    * The english user will see "Open" in both cases, but the translated
  200.    * version may vary. Of course you can also use i18n()
  201.    *
  202.    * @param comment the comment. The lookup text is made out of comment + @p fallback
  203.    * @param fallback the default text, if not found
  204.    * @return translation
  205.    */
  206.   QString translate( const char *comment, const char *fallback) const;
  207.  
  208.   /**
  209.    * Used to get the correct, translated singular or plural of a
  210.    * word.
  211.    * @param singular the singular form of the word, for example "file".
  212.    * @param plural the plural form of the word. Must contain a "%n" that will
  213.    *               be replaced by the number @p n, for example "%n files"
  214.    * @param n the number
  215.    * @return the correct singular or plural for the selected language,
  216.    *         depending on n
  217.    */
  218.   QString translate( const char *singular, const char *plural,
  219.              unsigned long n) const;
  220.  
  221.   /**
  222.    * Changes the current encoding.
  223.    *
  224.    * @param mibEnum The mib of the preferred codec
  225.    *
  226.    * @return True on success.
  227.    */
  228.   bool setEncoding(int mibEnum);
  229.  
  230.   /**
  231.    * Changes the current language. The current language will be left
  232.    * unchanged if failed. It will force a reload of the country specific
  233.    * configuration as well.
  234.    *
  235.    * @param language The language code.
  236.    *
  237.    * @return True on success.
  238.    */
  239.   bool setLanguage(const QString & language);
  240.  
  241.   /**
  242.    * Changes the list of prefed languages for the locale. The first valid
  243.    * language in the list will be used, or the default (en_US) language
  244.    * will be used if non of the specified languages were available.
  245.    *
  246.    * @param languages The list of language codes.
  247.    *
  248.    * @return True if one of the specified languages were used.
  249.    */
  250.   bool setLanguage(const QStringList & languages);
  251.  
  252.   /**
  253.    * Changes the current country. The current country will be left
  254.    * unchanged if failed. It will force a reload of the country specific
  255.    * configuration.
  256.    *
  257.    * @param country The ISO 3166 country code.
  258.    *
  259.    * @return True on success.
  260.    */
  261.   bool setCountry(const QString & country);
  262.  
  263.   /**
  264.    * Various positions for where to place the positive or negative
  265.    * sign when they are related to a monetary value.
  266.    */
  267.   enum SignPosition { ParensAround = 0, BeforeQuantityMoney = 1,
  268.               AfterQuantityMoney = 2,
  269.               BeforeMoney = 3, AfterMoney = 4 };
  270.  
  271.   /**
  272.    * Returns what a decimal point should look like ("." or "," etc.)
  273.    * according to the current locale or user settings.
  274.    *
  275.    * @return The decimal symbol used by locale.
  276.    */
  277.   QString decimalSymbol() const;
  278.  
  279.   /**
  280.    * Returns what the thousands separator should look
  281.    * like ("," or "." etc.)
  282.    * according to the current locale or user settings.
  283.    *
  284.    * @return The thousands separator used by locale.
  285.    */
  286.   QString thousandsSeparator() const;
  287.  
  288.   /**
  289.    * Returns what the symbol denoting currency in the current locale
  290.    * as as defined by user settings should look like.
  291.    *
  292.    * @return The default currency symbol used by locale.
  293.    */
  294.   QString currencySymbol() const;
  295.  
  296.   /**
  297.    * Returns what a decimal point should look like ("." or "," etc.)
  298.    * for monetary values, according to the current locale or user
  299.    * settings.
  300.    *
  301.    * @return The monetary decimal symbol used by locale.
  302.    */
  303.   QString monetaryDecimalSymbol() const;
  304.  
  305.   /**
  306.    * Returns what a thousands separator for monetary values should
  307.    * look like ("," or " " etc.) according to the current locale or
  308.    * user settings.
  309.    *
  310.    * @return The monetary thousands separator used by locale.
  311.    */
  312.   QString monetaryThousandsSeparator() const;
  313.  
  314.   /**
  315.    * Returns what a positive sign should look like ("+", " ", etc.)
  316.    * according to the current locale or user settings.
  317.    *
  318.    * @return The positive sign used by locale.
  319.    */
  320.   QString positiveSign() const;
  321.  
  322.   /**
  323.    * Returns what a negative sign should look like ("-", etc.)
  324.    * according to the current locale or user settings.
  325.    *
  326.    * @return The negative sign used by locale.
  327.    */
  328.   QString negativeSign() const;
  329.  
  330.   /**
  331.    * The number of fractional digits to include in numeric/monetary
  332.    * values (usually 2).
  333.    *
  334.    * @return Default number of fractional digits used by locale.
  335.    */
  336.   int fracDigits() const;
  337.  
  338.   /**
  339.    * If and only if the currency symbol precedes a positive value,
  340.    * this will be true.
  341.    *
  342.    * @return Where to print the currency symbol for positive numbers.
  343.    */
  344.   bool positivePrefixCurrencySymbol() const;
  345.  
  346.   /**
  347.    * If and only if the currency symbol precedes a negative value,
  348.    * this will be true.
  349.    *
  350.    * @return True if the currency symbol precedes negative numbers.
  351.    */
  352.   bool negativePrefixCurrencySymbol() const;
  353.  
  354.   /**
  355.    * Returns the position of a positive sign in relation to a
  356.    * monetary value.
  357.    *
  358.    * @return Where/how to print the positive sign.
  359.    * @see SignPosition
  360.    */
  361.   SignPosition positiveMonetarySignPosition() const;
  362.  
  363.   /**
  364.    * Denotes where to place a negative sign in relation to a
  365.    * monetary value.
  366.    *
  367.    * @return Where/how to print the negative sign.
  368.    * @see SignPosition
  369.    */
  370.   SignPosition negativeMonetarySignPosition() const;
  371.  
  372.   /**
  373.    * Given a double, converts that to a numeric string containing
  374.    * the localized monetary equivalent.
  375.    *
  376.    * e.g. given 123456, return "$ 123,456.00".
  377.    *
  378.    * @param num The number we want to format
  379.    * @param currency The currency symbol you want.
  380.    * @param digits Number of fractional digits, or -1 for the default
  381.    *               value
  382.    *
  383.    * @return The number of money as a localized string
  384.    * @see fracDigits()
  385.    */
  386.   QString formatMoney(double num,
  387.               const QString & currency = QString::null,
  388.               int digits = -1) const;
  389.  
  390.   /**
  391.    * Given a double, converts that to a numeric string containing
  392.    * the localized numeric equivalent.
  393.    *
  394.    * e.g. given 123456.78F, return "123,456.78" (for some European country).
  395.    * If precision isn't specified, 2 is used.
  396.    *
  397.    * This function is a wrapper that is provided for convenience.
  398.    *
  399.    * @param num The number to convert
  400.    * @param precision Number of fractional digits used.
  401.    *
  402.    * @return The number as a localized string
  403.    * @see formatNumber(const QString, bool, int)
  404.    */
  405.   QString formatNumber(double num, int precision = -1) const;
  406.  
  407.   /**
  408.    * @deprecated
  409.    *
  410.    * KDE 4.0: merge with formatNumber(const QString int)
  411.    *
  412.    * calls formatNumber(numStr, 2)
  413.    */
  414.   QString formatNumber(const QString &numStr) const KDE_DEPRECATED;
  415.  
  416.   /**
  417.    * Given a string representing a number, converts that to a numeric
  418.    * string containing the localized numeric equivalent.
  419.    *
  420.    * e.g. given 123456.78F, return "123,456.78" (for some European country).
  421.    *
  422.    * @param numStr The number to convert
  423.    * @param round Round  fractional digits.
  424.    * @param precision Number of fractional digits used.
  425.    *
  426.    * @return The number as a localized string
  427.    * @since 3.5
  428.    */
  429.   QString formatNumber(const QString &numStr, bool round, int precision) const;
  430.  
  431.   /**
  432.    * Given an integer, converts that to a numeric string containing
  433.    * the localized numeric equivalent.
  434.    *
  435.    * e.g. given 123456L, return "123,456" (for some European country).
  436.    *
  437.    * @param num The number to convert
  438.    *
  439.    * @return The number as a localized string
  440.    * @since 3.2
  441.    */
  442.   QString formatLong(long num) const;
  443.  
  444.   /**
  445.    * Use this to determine whether nouns are declined in
  446.    * locale's language. This property should remain
  447.    * read-only (no setter function)
  448.    *
  449.    * @return If nouns are declined
  450.    * @since 3.1
  451.    */
  452.    bool nounDeclension() const;
  453.  
  454.   /**
  455.    * Returns a string formatted to the current locale's conventions
  456.    * regarding dates.
  457.    *
  458.    * @param pDate The date to be formated.
  459.    * @param shortFormat True for non text dates.
  460.    *
  461.    * @return The date as a string
  462.    */
  463.   QString formatDate(const QDate &pDate, bool shortFormat = false) const;
  464.  
  465.   /**
  466.    * Use this to determine whether in dates a possessive form of month
  467.    * name is preferred ("of January" rather than "January")
  468.    *
  469.    * @return If possessive form should be used
  470.    * @since 3.1
  471.   */
  472.   bool dateMonthNamePossessive() const;
  473.  
  474.   /**
  475.    * Returns a string formatted to the current locale's conventions
  476.    * regarding times.
  477.    *
  478.    * @param pTime The time to be formated.
  479.    * @param includeSecs if true, seconds are included in the output,
  480.    *        otherwise only hours and minutes are formatted.
  481.    * @param isDuration if true, the given time is a duration, not a clock time.
  482.    * This means "am/pm" shouldn't be displayed.
  483.    *
  484.    * @return The time as a string
  485.    */
  486.   QString formatTime(const QTime &pTime, bool includeSecs, bool isDuration /*=false*/) const;
  487.  
  488.   /**
  489.    * Returns a string formatted to the current locale's conventions
  490.    * regarding times.
  491.    *
  492.    * @param pTime The time to be formated.
  493.    * @param includeSecs if true, seconds are included in the output,
  494.    *        otherwise only hours and minutes are formatted.
  495.    *
  496.    * @return The time as a string
  497.    */
  498.   QString formatTime(const QTime &pTime, bool includeSecs = false) const; // BIC: merge with above
  499.  
  500.   /**
  501.    * Use this to determine if the user wants a 12 hour clock.
  502.    *
  503.    * @return If the user wants 12h clock
  504.    */
  505.   bool use12Clock() const;
  506.  
  507.   /**
  508.    * @deprecated
  509.    *
  510.    * Please use the weekStartDay method instead.
  511.    *
  512.    * Use this to determine if the user wants the week to start on Monday.
  513.    *
  514.    * @return true if the week starts on Monday
  515.    */
  516.   bool weekStartsMonday() const KDE_DEPRECATED; //### remove for KDE 4.0
  517.  
  518.   /**
  519.    * Use this to determine which day is the first day of the week.
  520.    *
  521.    * @return an integer (Monday=1..Sunday=7)
  522.    * @since 3.1
  523.    */
  524.   int weekStartDay() const;
  525.  
  526.   /**
  527.    * @deprecated
  528.    *
  529.    * Returns a string containing the name of the month name used in the Gregorian calendar.
  530.    *
  531.    * @param i the month number of the year starting at 1/January.
  532.    * @param shortName we will return the short version of the string.
  533.    *
  534.    * @return The name of the month
  535.    * 
  536.    * Typically the correct replacement for this deprecated class is
  537.    * calendar()->monthString(), which requires a QDate (rather than an
  538.    * integer month) or both a month and a year.
  539.    * This will work across different calendars.
  540.    * Note that you also need to add 
  541.    * \code
  542.    * #include <kcalendarsystem.h>
  543.    * \endcode
  544.    * to the applicable file.
  545.    */
  546.   QString monthName(int i, bool shortName = false) const KDE_DEPRECATED;
  547.  
  548.   /**
  549.    * @deprecated
  550.    *
  551.    * Returns a string containing the possessive form of the month name used in the Gregorian calendar.
  552.    * ("of January", "of February", etc.)
  553.    * It's needed in long format dates in some languages.
  554.    *
  555.    * @param i the month number of the year starting at 1/January.
  556.    * @param shortName we will return the short version of the string.
  557.    *
  558.    * @return The possessive form of the name of the month
  559.    * @since 3.1
  560.    *
  561.    * Typically the correct replacement for this deprecated class is
  562.    * calendar()->monthNamePossessive(), which requires a QDate (rather than
  563.    * an integer month) or both a month and a year.
  564.    * This will work across different calendars.
  565.    * Note that you also need to add 
  566.    * \code
  567.    * #include <kcalendarsystem.h>
  568.    * \endcode
  569.    * to the applicable file.
  570.   */
  571.   QString monthNamePossessive(int i, bool shortName = false) const KDE_DEPRECATED;
  572.  
  573.   /**
  574.    * @deprecated use calendar()->weekDayName
  575.    *
  576.    * Returns a string containing the name of the week day used in the Gregorian calendar.
  577.    *
  578.    * @param i the day number of the week starting at 1/Monday.
  579.    * @param shortName we will return the short version of the string.
  580.    *
  581.    * @return The name of the day
  582.    */
  583.   QString weekDayName(int i, bool shortName = false) const KDE_DEPRECATED;
  584.  
  585.   /**
  586.    * Returns a pointer to the calendar system object.
  587.    *
  588.    * @return the current calendar system instance
  589.    * @since 3.2
  590.    */
  591.   const KCalendarSystem * calendar() const;
  592.  
  593.   /**
  594.    * Returns the name of the calendar system that is currently being
  595.    * used by the system.
  596.    *
  597.    * @return the name of the calendar system
  598.    * @since 3.2
  599.    */
  600.   QString calendarType() const;
  601.  
  602.   /**
  603.    * Changes the current calendar system to the calendar specified.
  604.    * Currently "gregorian" and "hijri" are supported. If the calendar
  605.    * system specified is not found, gregorian will be used.
  606.    *
  607.    * @param calendarType the name of the calendar type
  608.    * @since 3.2
  609.    */
  610.   void setCalendar(const QString & calendarType);
  611.  
  612.   /**
  613.    * Returns a string formated to the current locale's conventions
  614.    * regarding both date and time.
  615.    *
  616.    * @param pDateTime The date and time to be formated.
  617.    * @param shortFormat using the short date format.
  618.    * @param includeSecs using the short date format.
  619.    *
  620.    * @return The date and time as a string
  621.    */
  622.   QString formatDateTime(const QDateTime &pDateTime,
  623.              bool shortFormat = true,
  624.              bool includeSecs = false) const;
  625.  
  626.   /**
  627.    * Converts a localized monetary string to a double.
  628.    *
  629.    * @param numStr the string we want to convert.
  630.    * @param ok the boolean that is set to false if it's not a number.
  631.    *           If @p ok is 0, it will be ignored
  632.    *
  633.    * @return The string converted to a double
  634.    */
  635.   double readMoney(const QString &numStr, bool * ok = 0) const;
  636.  
  637.   /**
  638.    * Converts a localized numeric string to a double.
  639.    *
  640.    * @param numStr the string we want to convert.
  641.    * @param ok the boolean that is set to false if it's not a number.
  642.    *           If @p ok is 0, it will be ignored
  643.    *
  644.    * @return The string converted to a double
  645.    */
  646.   double readNumber(const QString &numStr, bool * ok = 0) const;
  647.  
  648.   /**
  649.    * Converts a localized date string to a QDate.
  650.    * The bool pointed by ok will be invalid if the date entered was not valid.
  651.    *
  652.    * @param str the string we want to convert.
  653.    * @param ok the boolean that is set to false if it's not a valid date.
  654.    *           If @p ok is 0, it will be ignored
  655.    *
  656.    * @return The string converted to a QDate
  657.    */
  658.   QDate readDate(const QString &str, bool* ok = 0) const;
  659.  
  660.   /**
  661.    * Converts a localized date string to a QDate, using the specified format.
  662.    * You will usually not want to use this method.
  663.    */
  664.   QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const;
  665.  
  666.   enum ReadDateFlags {
  667.       NormalFormat = 1,
  668.       ShortFormat = 2
  669.   };
  670.  
  671.   /**
  672.    * Converts a localized date string to a QDate.
  673.    * This method is stricter than readDate(str,&ok): it will either accept
  674.    * a date in full format or a date in short format, depending on @p flags.
  675.    *
  676.    * @param str the string we want to convert.
  677.    * @param flags whether the date string is to be in full format or in short format.
  678.    * @param ok the boolean that is set to false if it's not a valid date.
  679.    *           If @p ok is 0, it will be ignored
  680.    *
  681.    * @return The string converted to a QDate
  682.    * @since 3.2
  683.    */
  684.   QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const;
  685.  
  686.   /**
  687.    * Converts a localized time string to a QTime.
  688.    * This method will try to parse it with seconds, then without seconds.
  689.    * The bool pointed to by @p ok will be set to false if the time entered was 
  690.    * not valid.
  691.    *
  692.    * @param str the string we want to convert.
  693.    * @param ok the boolean that is set to false if it's not a valid time.
  694.    *           If @p ok is 0, it will be ignored
  695.    *
  696.    * @return The string converted to a QTime
  697.    */
  698.   QTime readTime(const QString &str, bool* ok = 0) const;
  699.  
  700.   enum ReadTimeFlags {
  701.       WithSeconds = 0, // default (no flag set)
  702.       WithoutSeconds = 1
  703.   }; // (maybe use this enum as a bitfield, if adding independent features?)
  704.   /**
  705.    * Converts a localized time string to a QTime.
  706.    * This method is stricter than readTime(str,&ok): it will either accept
  707.    * a time with seconds or a time without seconds.
  708.    * Use this method when the format is known by the application.
  709.    *
  710.    * @param str the string we want to convert.
  711.    * @param flags whether the time string is expected to contain seconds or not.
  712.    * @param ok the boolean that is set to false if it's not a valid time.
  713.    *           If @p ok is 0, it will be ignored
  714.    *
  715.    * @return The string converted to a QTime
  716.    * @since 3.2
  717.    */
  718.   QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const;
  719.  
  720.   /**
  721.    * Returns the language used by this object. The domain AND the
  722.    * library translation must be available in this language.
  723.    * defaultLanguage() is returned by default, if no other available.
  724.    *
  725.    * @return The currently used language.
  726.    */
  727.   QString language() const;
  728.  
  729.   /**
  730.    * Returns the country code of the country where the user lives.
  731.    * defaultCountry() is returned by default, if no other available.
  732.    *
  733.    * @return The country code for the user.
  734.    */
  735.   QString country() const;
  736.  
  737.   /**
  738.    * Returns the preferred languages as ISO 639-1 codes. This means
  739.    * that information about country is removed. If the internal language
  740.    * code might be represented by more than one 639-1 code, they will all be
  741.    * listed (but only once).
  742.    *
  743.    * If the selected languages are "nn, nb, pt_BR", you will get:
  744.    * "nn, nb, pt".
  745.    *
  746.    * @return List of language codes
  747.    *
  748.    * @see languageList
  749.    */
  750.   QStringList languagesTwoAlpha() const;
  751.  
  752.   /**
  753.    * Returns the languages selected by user. The codes returned here is the
  754.    * internal language codes.
  755.    *
  756.    * @return List of language codes
  757.    *
  758.    * @see languagesTwoAlpha
  759.    */
  760.   QStringList languageList() const;
  761.  
  762.   /**
  763.    * Returns the user's preferred encoding.
  764.    *
  765.    * @return The name of the preferred encoding
  766.    *
  767.    * @see codecForEncoding
  768.    * @see encodingMib
  769.    */
  770.   const char * encoding() const;
  771.  
  772.   /**
  773.    * Returns the user's preferred encoding.
  774.    *
  775.    * @return The Mib of the preferred encoding
  776.    *
  777.    * @see encoding
  778.    * @see codecForEncoding
  779.    */
  780.   int encodingMib() const;
  781.   /**
  782.    * Returns the user's preferred encoding. Should never be NULL.
  783.    *
  784.    * @return The codec for the preferred encoding
  785.    *
  786.    * @see encoding
  787.    * @see encodingMib
  788.    */
  789.   QTextCodec * codecForEncoding() const;
  790.  
  791.   /**
  792.    * Returns the file encoding.
  793.    *
  794.    * @return The Mib of the file encoding
  795.    *
  796.    * @see QFile::encodeName
  797.    * @see QFile::decodeName
  798.    */
  799.   int fileEncodingMib() const;
  800.  
  801.   /**
  802.    * Changes the current date format.
  803.    *
  804.    * The format of the date is a string which contains variables that will
  805.    * be replaced:
  806.    * @li %Y with the century (e.g. "19" for "1984")
  807.    * @li %y with the lower 2 digits of the year (e.g. "84" for "1984")
  808.    * @li %n with the month (January="1", December="12")
  809.    * @li %m with the month with two digits (January="01", December="12")
  810.    * @li %e with the day of the month (e.g. "1" on the first of march)
  811.    * @li %d with the day of the month with two digits(e.g. "01" on the first of march)
  812.    * @li %b with the short form of the month (e.g. "Jan" for January)
  813.    * @li %B with the long form of the month (e.g. "January")
  814.    * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday)
  815.    * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday)
  816.    *
  817.    * Everything else in the format string will be taken as is.
  818.    * For example, March 20th 1989 with the format "%y:%m:%d" results
  819.    * in "89:03:20".
  820.    *
  821.    * @param format The new date format
  822.    */
  823.   void setDateFormat(const QString & format);
  824.   /**
  825.    * Changes the current short date format.
  826.    *
  827.    * The format of the date is a string which contains variables that will
  828.    * be replaced:
  829.    * @li %Y with the century (e.g. "19" for "1984")
  830.    * @li %y with the lower 2 digits of the year (e.g. "84" for "1984")
  831.    * @li %n with the month (January="1", December="12")
  832.    * @li %m with the month with two digits (January="01", December="12")
  833.    * @li %e with the day of the month (e.g. "1" on the first of march)
  834.    * @li %d with the day of the month with two digits(e.g. "01" on the first of march)
  835.    * @li %b with the short form of the month (e.g. "Jan" for January)
  836.    * @li %B with the long form of the month (e.g. "January")
  837.    * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday)
  838.    * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday)
  839.    *
  840.    * Everything else in the format string will be taken as is.
  841.    * For example, March 20th 1989 with the format "%y:%m:%d" results
  842.    * in "89:03:20".
  843.    *
  844.    * @param format The new short date format
  845.    */
  846.   void setDateFormatShort(const QString & format);
  847.   /**
  848.    * Changes the form of month name used in dates.
  849.    *
  850.    * @param possessive True if possessive forms should be used
  851.    * @since 3.1
  852.    */
  853.   void setDateMonthNamePossessive(bool possessive);
  854.   /**
  855.    * Changes the current time format.
  856.    *
  857.    * The format of the time is string a which contains variables that will
  858.    * be replaced:
  859.    * @li %H with the hour in 24h format and 2 digits (e.g. 5pm is "17", 5am is "05")
  860.    * @li %k with the hour in 24h format and one digits (e.g. 5pm is "17", 5am is "5")
  861.    * @li %I with the hour in 12h format and 2 digits (e.g. 5pm is "05", 5am is "05")
  862.    * @li %l with the hour in 12h format and one digits (e.g. 5pm is "5", 5am is "5")
  863.    * @li %M with the minute with 2 digits (e.g. the minute of 07:02:09 is "02")
  864.    * @li %S with the seconds with 2 digits  (e.g. the minute of 07:02:09 is "09")
  865.    * @li %p with pm or am (e.g. 17.00 is "pm", 05.00 is "am")
  866.    *
  867.    * Everything else in the format string will be taken as is.
  868.    * For example, 5.23pm with the format "%H:%M" results
  869.    * in "17:23".
  870.    *
  871.    * @param format The new time format
  872.    */
  873.   void setTimeFormat(const QString & format);
  874.  
  875.   /**
  876.    * @deprecated
  877.    *
  878.    * Please use setWeekStartDay instead.
  879.    *
  880.    * Changes how KLocale defines the first day in week.
  881.    *
  882.    * @param start True if Monday is the first day in the week
  883.    */
  884.   void setWeekStartsMonday(bool start) KDE_DEPRECATED; //### remove for KDE 4.0
  885.  
  886.   /**
  887.    * Changes how KLocale defines the first day in week.
  888.    *
  889.    * @param day first day of the week (Monday=1..Sunday=7) as integer
  890.    * @since 3.1
  891.    */
  892.   void setWeekStartDay(int day);
  893.   /**
  894.    * Returns the currently selected date format.
  895.    *
  896.    * @return Current date format.
  897.    * @see setDateFormat()
  898.    */
  899.   QString dateFormat() const;
  900.   /**
  901.    * Returns the currently selected short date format.
  902.    *
  903.    * @return Current short date format.
  904.    * @see setDateFormatShort()
  905.    */
  906.   QString dateFormatShort() const;
  907.   /**
  908.    * Returns the currently selected time format.
  909.    *
  910.    * @return Current time format.
  911.    * @see setTimeFormat()
  912.    */
  913.   QString timeFormat() const;
  914.  
  915.   /**
  916.    * Changes the symbol used to identify the decimal pointer.
  917.    *
  918.    * @param symbol The new decimal symbol.
  919.    */
  920.   void setDecimalSymbol(const QString & symbol);
  921.   /**
  922.    * Changes the separator used to group digits when formating numbers.
  923.    *
  924.    * @param separator The new thousands separator.
  925.    */
  926.   void setThousandsSeparator(const QString & separator);
  927.   /**
  928.    * Changes the sign used to identify a positive number. Normally this is
  929.    * left blank.
  930.    *
  931.    * @param sign Sign used for positive numbers.
  932.    */
  933.   void setPositiveSign(const QString & sign);
  934.   /**
  935.    * Changes the sign used to identify a negative number.
  936.    *
  937.    * @param sign Sign used for negative numbers.
  938.    */
  939.   void setNegativeSign(const QString & sign);
  940.   /**
  941.    * Changes the sign position used for positive monetary values.
  942.    *
  943.    * @param signpos The new sign position
  944.    */
  945.   void setPositiveMonetarySignPosition(SignPosition signpos);
  946.   /**
  947.    * Changes the sign position used for negative monetary values.
  948.    *
  949.    * @param signpos The new sign position
  950.    */
  951.   void setNegativeMonetarySignPosition(SignPosition signpos);
  952.   /**
  953.    * Changes the position where the currency symbol should be printed for
  954.    * positive monetary values.
  955.    *
  956.    * @param prefix True if the currency symbol should be prefixed instead of
  957.    * postfixed
  958.    */
  959.   void setPositivePrefixCurrencySymbol(bool prefix);
  960.   /**
  961.    * Changes the position where the currency symbol should be printed for
  962.    * negative monetary values.
  963.    *
  964.    * @param prefix True if the currency symbol should be prefixed instead of
  965.    * postfixed
  966.    */
  967.   void setNegativePrefixCurrencySymbol(bool prefix);
  968.   /**
  969.    * Changes the number of digits used when formating numbers.
  970.    *
  971.    * @param digits The default number of digits to use.
  972.    */
  973.   void setFracDigits(int digits);
  974.   /**
  975.    * Changes the separator used to group digits when formating monetary values.
  976.    *
  977.    * @param separator The new thousands separator.
  978.    */
  979.   void setMonetaryThousandsSeparator(const QString & separator);
  980.   /**
  981.    * Changes the symbol used to identify the decimal pointer for monetary
  982.    * values.
  983.    *
  984.    * @param symbol The new decimal symbol.
  985.    */
  986.   void setMonetaryDecimalSymbol(const QString & symbol);
  987.   /**
  988.    * Changes the current currency symbol.
  989.    *
  990.    * @param symbol The new currency symbol
  991.    */
  992.   void setCurrencySymbol(const QString & symbol);
  993.  
  994.   /**
  995.    * Returns the preferred page size for printing.
  996.    *
  997.    * @return The preferred page size, cast it to QPrinter::PageSize
  998.    */
  999.   int pageSize() const;
  1000.  
  1001.   /**
  1002.    * Changes the preferred page size when printing.
  1003.    *
  1004.    * @param paperFormat the new preferred page size in the format QPrinter::PageSize
  1005.    */
  1006.   void setPageSize(int paperFormat);
  1007.  
  1008.   /**
  1009.    * The Metric system will give you information in mm, while the
  1010.    * Imperial system will give you information in inches.
  1011.    */
  1012.   enum MeasureSystem { Metric, Imperial };
  1013.  
  1014.   /**
  1015.    * Returns which measuring system we use.
  1016.    *
  1017.    * @return The preferred measuring system
  1018.    */
  1019.   MeasureSystem measureSystem() const;
  1020.  
  1021.   /**
  1022.    * Changes the preferred measuring system.
  1023.    *
  1024.    * @return value The preferred measuring system
  1025.    */
  1026.   void setMeasureSystem(MeasureSystem value);
  1027.   
  1028.   /**
  1029.    * Adds another catalog to search for translation lookup.
  1030.    * This function is useful for extern libraries and/or code,
  1031.    * that provide there own messages.
  1032.    *
  1033.    * If the catalog does not exist for the chosen language,
  1034.    * it will be ignored and en_US will be used.
  1035.    *
  1036.    * @param catalog The catalog to add.
  1037.    */
  1038.   void insertCatalogue(const QString& catalog);
  1039.  
  1040.   /**
  1041.    * Removes a catalog for translation lookup.
  1042.    * @param catalog The catalog to remove.
  1043.    * @see insertCatalogue()
  1044.    */
  1045.   void removeCatalogue(const QString &catalog);
  1046.  
  1047.   /**
  1048.    * Sets the active catalog for translation lookup.
  1049.    * @param catalog The catalog to activate.
  1050.    */
  1051.   void setActiveCatalogue(const QString &catalog);
  1052.  
  1053.   /**
  1054.    * Translates a message as a QTranslator is supposed to.
  1055.    * The parameters are similar to i18n(), but the result
  1056.    * value has other semantics (it can be QString::null)
  1057.    * @since 3.1
  1058.    **/
  1059.   QString translateQt(const char *context,
  1060.               const char *sourceText,
  1061.               const char *message) const;
  1062.  
  1063.   /**
  1064.    * Returns list of all known ISO 639-1 codes.
  1065.    * @return a list of all language codes
  1066.    * @since 3.1
  1067.    */
  1068.   QStringList allLanguagesTwoAlpha() const;
  1069.  
  1070.   /**
  1071.    * Convert a ISO 639-1 code to a human readable form.
  1072.    * @param code the language ISO 639-1 code
  1073.    * @return the human readable form
  1074.    * @since 3.1
  1075.    */
  1076.   QString twoAlphaToLanguageName(const QString &code) const;
  1077.  
  1078.   /**
  1079.    * Returns list of all known country codes.
  1080.    * @return a list of all country codes
  1081.    * @since 3.1
  1082.    */
  1083.   QStringList allCountriesTwoAlpha() const;
  1084.  
  1085.   /**
  1086.    * Convert a country code to a human readable form.
  1087.    * @param code the country code
  1088.    * @return the human readable form of the country name
  1089.    * @since 3.1
  1090.    */
  1091.   QString twoAlphaToCountryName(const QString &code) const;
  1092.  
  1093.   /**
  1094.    * Returns the parts of the parameter str understood as language setting
  1095.    * the format is language_COUNTRY.charset
  1096.    *
  1097.    * @param str The string to split.
  1098.    * @param language This will be set to the language part of the string.
  1099.    * @param country This will be set to the country part of the string.
  1100.    * @param charset This will be set to the charset part of the string.
  1101.    */
  1102.   static void splitLocale(const QString & str,
  1103.               QString & language,
  1104.               QString & country,
  1105.               QString & charset);
  1106.  
  1107.   /**
  1108.    * Use this as main catalog for *all* KLocales, if not the appname
  1109.    * will be used. This function is best to be the very first instruction
  1110.    * in your program's main function as it only has an effect before the
  1111.    * first KLocale object is created.
  1112.    *
  1113.    * @param catalog Catalogue to override all other main catalogues.
  1114.    */
  1115.   static void setMainCatalogue(const char *catalog);
  1116.  
  1117.   /**
  1118.    * Finds localized resource in resourceDir( rtype ) + \<lang> + fname.
  1119.    *
  1120.    * @param fname relative path to find
  1121.    * @param rtype resource type to use
  1122.    */
  1123.   static QString langLookup(const QString &fname, const char *rtype = "html");
  1124.  
  1125.   /**
  1126.    * Returns the name of the internal language.
  1127.    *
  1128.    * @return Name of the default language
  1129.    */
  1130.   static QString defaultLanguage();
  1131.  
  1132.   /**
  1133.    * Returns the name of the default country.
  1134.    *
  1135.    * @return Name of the default country
  1136.    */
  1137.   static QString defaultCountry();
  1138.  
  1139.  
  1140.   /**
  1141.    * @internal Called from KConfigBackend to initialize language.
  1142.    */
  1143.   static QString _initLanguage(KConfigBase *config);
  1144.  
  1145. #ifdef KDE_NO_COMPAT
  1146. private:
  1147. #endif
  1148.   /**
  1149.    * @deprecated
  1150.    * use formatMoney(double)
  1151.    */
  1152.   QString formatMoney(const QString &numStr) const KDE_DEPRECATED;
  1153.  
  1154.   /**
  1155.    * @deprecated
  1156.    * Use languageList()
  1157.    *
  1158.    * @return String containing language codes separated by colons
  1159.    */
  1160.   QString languages() const KDE_DEPRECATED;
  1161.  
  1162.   /**
  1163.    * @deprecated
  1164.    * @return True
  1165.    */
  1166.   bool setCharset(const QString & charset) KDE_DEPRECATED;
  1167.  
  1168.   /**
  1169.    * @deprecated
  1170.    * @see encoding
  1171.    */
  1172.   QString charset() const KDE_DEPRECATED;
  1173.  
  1174. protected:
  1175.   /**
  1176.    * @internal Creates a KLocale object for KGlobal and inits the locale
  1177.    * pointer.
  1178.    */
  1179.   static void initInstance();
  1180.  
  1181. private:
  1182.   /**
  1183.    * @internal Inits the localization part of the instance with the config
  1184.    * object.
  1185.    *
  1186.    * @param config The configuration object used for init.
  1187.    */
  1188.   void initFormat(KConfig *config);
  1189.   
  1190.   /**
  1191.    * @internal Initializes the catalogs appname, kdelibs and kio for all chosen languages.
  1192.    *
  1193.    * @param config The configuration object used for init
  1194.    * @param useEnv True if we should use environment variables
  1195.    */
  1196.   void initMainCatalogues(const QString & catalog);
  1197.   
  1198.   /**
  1199.    * @internal Initializes the list of valid languages from the user's point of view. This is the list of
  1200.    * languages that the user picks in kcontrol. The config object should be valid and contain the global
  1201.    * entries.
  1202.    *
  1203.    * @param config The configuration object used for init
  1204.    * @param useEnv True if we should use environment variables
  1205.    */
  1206.   void initLanguageList(KConfig * config, bool useEnv);
  1207.  
  1208.   /**
  1209.    * @internal Figures out which encoding the user prefers.
  1210.    *
  1211.    * @param config The configuration object used for init
  1212.    */
  1213.   void initEncoding(KConfig * config);
  1214.  
  1215.   /**
  1216.    * @internal Figures out which encoding the user prefers for filenames
  1217.    * and sets up the appropriate QFile encoding and decoding functions.
  1218.    */
  1219.   void initFileNameEncoding(KConfig *config);
  1220.  
  1221.   /**
  1222.    * @internal A QFile filename encoding function (QFile::encodeFn).
  1223.    */
  1224.   static QCString encodeFileNameUTF8( const QString & fileName );
  1225.  
  1226.   /**
  1227.    * @internal QFile filename decoding function (QFile::decodeFn).
  1228.    */
  1229.   static QString decodeFileNameUTF8( const QCString & localFileName );
  1230.  
  1231.   /**
  1232.    * @internal Changes the file name of the catalog to the correct
  1233.    * one.
  1234.    */
  1235.   void initCatalogue( KCatalogue & catalog );
  1236.  
  1237.   /**
  1238.    * @internal Ensures that the format configuration is read.
  1239.    */
  1240.   void doFormatInit() const;
  1241.  
  1242.   /**
  1243.    * @internal Reads the format configuration from disk.
  1244.    */
  1245.   void initFormat();
  1246.  
  1247.   /**
  1248.    * @internal function used by the two translate versions
  1249.    */
  1250.   QString translate_priv(const char *index,
  1251.              const char *text,
  1252.              const char ** original = 0,
  1253.              int* pluralType = 0) const;
  1254.  
  1255.   /**
  1256.    * @internal function used to determine if we are using the en_US translation
  1257.    */
  1258.   bool useDefaultLanguage() const;
  1259.  
  1260.   /**
  1261.    * @internal Checks if the specified language is installed
  1262.    */
  1263.   bool isLanguageInstalled(const QString & language) const;
  1264.   
  1265.   /**
  1266.    * @internal evaluate the list of catalogs and check that all instances for all languages are loaded 
  1267.    * and that they are sorted according to the catalog names
  1268.    */
  1269.   void updateCatalogues( );
  1270.   
  1271.   /**
  1272.    * @internal Find the plural type for all loaded catalogs
  1273.    */
  1274.   void initPluralTypes( );
  1275.   /**
  1276.    * @internal Find the plural type for a language. Look this up in the corresponding kdelibs.po.
  1277.    *
  1278.    * @param language The language to examine
  1279.    */
  1280.   int pluralType( const QString & language );
  1281.   
  1282.   /**
  1283.    * @internal Find the plural type information for a given catalog. This catalog will be a kdelibs.mo. Method
  1284.    * just exists to make code more readable.
  1285.    *
  1286.    * @param language The language to examine
  1287.    */
  1288.   int pluralType( const KCatalogue& catalog );
  1289.   /**
  1290.    * @internal Find catalog for given language and given catalog name.
  1291.    *
  1292.    * @param language language of the catalog
  1293.    * @param name name of the catalog
  1294.    */
  1295.   // const KCatalogue * catalog( const QString & language, const QString & name );
  1296.   
  1297.  
  1298.   /**
  1299.    * @internal Retrieves the file name of the catalog, or QString::null
  1300.    *           if not found.
  1301.    */
  1302.   static QString catalogueFileName(const QString & language,
  1303.                    const KCatalogue & catalog);
  1304. public:
  1305.   /**
  1306.    * @internal Checks whether or not theFind catalog for given language and given catalog name.
  1307.    *
  1308.    * @param language language to check
  1309.    */
  1310.    bool isApplicationTranslatedInto( const QString & language);
  1311.    
  1312. private:
  1313.   // Numbers and money
  1314.   QString m_decimalSymbol;
  1315.   QString m_thousandsSeparator;
  1316.   QString m_currencySymbol;
  1317.   QString m_monetaryDecimalSymbol;
  1318.   QString m_monetaryThousandsSeparator;
  1319.   QString m_positiveSign;
  1320.   QString m_negativeSign;
  1321.   int m_fracDigits;
  1322.   SignPosition m_positiveMonetarySignPosition;
  1323.   SignPosition m_negativeMonetarySignPosition;
  1324.  
  1325.   // Date and time
  1326.   QString m_timeFormat;
  1327.   QString m_dateFormat;
  1328.   QString m_dateFormatShort;
  1329.  
  1330.   QString m_language;
  1331.   QString m_country;
  1332.  
  1333.   bool m_weekStartsMonday; //### remove for KDE 4.0
  1334.   bool m_positivePrefixCurrencySymbol;
  1335.   bool m_negativePrefixCurrencySymbol;
  1336.  
  1337.   KLocalePrivate *d;
  1338. };
  1339.  
  1340. #endif
  1341.