[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdecore
From:       John Layt <john () layt ! net>
Date:       2010-12-13 1:41:13
Message-ID: 20101213014113.4724CAC8A7 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1205924 by jlayt:

KLocale fixes to make AM/PM symbols work properly

1) Fix spelling Meridian => Meridiem
2) Allow setting of null country meaning system country
3) Make sure Day Period config is read in with millisecond accuracy
4) Rework the saving of the config file, turns out taking a copy is a bad idea
   as the existing code has a number of implicit sync() call that write the 
   config out, but calling markAsClean() is equally as bad, so instead keep a
   pointer in the original form provided and operate on the config exactly as
   previously to maintain consistant behaviour.  Document the implicit sync().

CCMAIL: kde-i18n-doc@kde.org



 M  +28 -18    localization/klocale.h  
 M  +32 -35    localization/klocale_kde.cpp  
 M  +3 -2      localization/klocale_p.h  
 M  +5 -5      tests/klocaletest.cpp  


--- trunk/KDE/kdelibs/kdecore/localization/klocale.h #1205923:1205924
@@ -81,13 +81,15 @@
      * 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.
+     * 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, causing 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)
+     *                formatting options).
      */
     explicit KLocale(const QString& catalog, KSharedConfig::Ptr config = \
KSharedConfig::Ptr());  
@@ -97,15 +99,17 @@
      * Allows you to override the language and, optionally, the
      * country of this locale.
      *
+     * 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, causing 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 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 date and time
-     *                 formatting).  A copy of this config will be taken,
-     *                 any updates made to the config will not affect this
-     *                 KLocale object.  If a null pointer the global config
-     *                 will be used.
+     *                 locale-related preferences (such as language and
+     *                 formatting options).
      */
     KLocale(const QString& catalog, const QString &language, const QString &country \
= QString(),  KConfig *config = 0);
@@ -2007,13 +2011,17 @@
      * 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, it has to be valid until the KLocale
+     * object is destroyed.  Note that a setLocale() will be performed on the
+     * config, causing a sync() and reparseConfiguration() which will save any
+     * changes you have made and load any changes other shared copies have made.
+     *
      * @param country the ISO 3166 country code
      * @param config  a configuration file with a Locale group detailing
-     *                locale-related preferences (such as date and time
-     *                formatting).  A copy of this config will be taken,
-     *                any updates made to the config will not affect this
-     *                KLocale object.  If a null pointer the global config
-     *                will be used.
+     *                locale-related preferences (such as language and
+     *                formatting options).
      *
      * @return @c true on success, @c false on failure
      */
@@ -2041,13 +2049,15 @@
      * unchanged if failed. It will force a reload of the country specific
      * configuration as well.
      *
+     * 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, causing a sync() and reparseConfiguration() which will save any
+     * changes you have made and load any changes other shared copies have made.
+     *
      * @param language the language code
      * @param config  a configuration file with a Locale group detailing
-     *                locale-related preferences (such as date and time
-     *                formatting).  A copy of this config will be taken,
-     *                any updates made to the config will not affect this
-     *                KLocale object.  If a null pointer the global config
-     *                will be used.
+     *                 locale-related preferences (such as language and
+     *                 formatting options).
      *
      * @return true on success
      */
--- trunk/KDE/kdelibs/kdecore/localization/klocale_kde.cpp #1205923:1205924
@@ -103,7 +103,8 @@
 
 KLocalePrivate::KLocalePrivate(KLocale *q_ptr, const QString &catalog, \
KSharedConfig::Ptr config)  : q(q_ptr),
-                 m_config(config),
+                 m_config(0),
+                 m_sharedConfig(config),
                  m_country(QString()),
                  m_language(QString()),
                  m_languages(0),
@@ -117,6 +118,8 @@
 KLocalePrivate::KLocalePrivate(KLocale *q_ptr, const QString &catalog,
                                const QString &language, const QString &country, \
KConfig *config)  : q(q_ptr),
+                 m_config(config),
+                 m_sharedConfig(KSharedConfig::Ptr()),
                  m_country(country.toLower()),
                  m_language(language.toLower()),
                  m_languages(0),
@@ -125,14 +128,7 @@
                  m_currency(0),
                  m_codecForEncoding(0)
 {
-    if (config) {
-        //Copy config to a new shared config
-        m_config = KSharedConfig::openConfig();
-        config->copyTo(QString(), m_config.data());
-    } else {
-        m_config = KSharedConfig::Ptr();
     }
-}
 
 KLocalePrivate::KLocalePrivate(const KLocalePrivate &rhs)
 {
@@ -145,12 +141,14 @@
     return *this;
 }
 
-KSharedConfig::Ptr KLocalePrivate::config()
+KConfig *KLocalePrivate::config()
 {
-    if (m_config == KSharedConfig::Ptr()) {
-        return KGlobal::config();
-    } else {
+    if (m_config) {
         return m_config;
+    } else if (m_sharedConfig != KSharedConfig::Ptr()) {
+        return m_sharedConfig.data();
+    } else {
+        return KGlobal::config().data();
     }
 }
 
@@ -237,10 +235,7 @@
     delete m_currency;
     delete m_calendar;
     delete m_languages;
-    if (m_config != KSharedConfig::Ptr()) {
-        m_config->markAsClean();
     }
-}
 
 void KLocalePrivate::init()
 {
@@ -378,7 +373,10 @@
         list += m_language;
     }
 
-    bool useEnv = (m_config == KSharedConfig::Ptr());
+    // If the Locale object was created with a specific config file, then do not use \
the +    // environmental variables.  If the locale object was created with the \
global config, then +    // do use the environmental variables.
+    bool useEnv = (m_config == 0 && m_sharedConfig == KSharedConfig::Ptr());
     if (useEnv) {
         // KDE_LANG contains list of language codes, not locale string.
         getLanguagesFromVariable(list, "KDE_LANG", true);
@@ -537,7 +535,8 @@
         QStringList period = cg.readEntry(periodKey, QStringList());
         if (period.count() == 8) {
             m_dayPeriods.append(KDayPeriod(period[0], period[1], period[2], \
                period[3],
-                                           QTime::fromString(period[4]), \
QTime::fromString(period[5]), +                                           \
QTime::fromString(period[4], QString::fromLatin1("HH:mm:ss.zzz")), +                  \
                QTime::fromString(period[5], QString::fromLatin1("HH:mm:ss.zzz")),
                                            period[6].toInt(), period[7].toInt()));
         }
         i = i + 1;
@@ -551,17 +550,13 @@
     // Add the default C as it is valid to use but is not in the list
     validCountries.append( defaultCountry() );
 
-    if ( country.isEmpty() || !validCountries.contains( country, Qt::CaseInsensitive \
) ) { +    // If the country is empty it means to use the system default, otherwise \
check is a country we support +    if ( !country.isEmpty() && \
!validCountries.contains( country, Qt::CaseInsensitive ) ) {  return false;
     }
 
-    if (config) {
-        //Copy config to a new shared config
-        m_config = KSharedConfig::openConfig();
-        config->copyTo(QString(), m_config.data());
-    } else {
-        m_config = KSharedConfig::Ptr();
-    }
+    m_config = config;
+    m_sharedConfig = KSharedConfig::Ptr();
 
     // Always save as lowercase, unless it's C when we want it uppercase
     if ( country.toLower() == defaultCountry().toLower() ) {
@@ -570,6 +565,7 @@
         m_country = country.toLower();
     }
 
+    initCountry();
     initFormat();
     return true;
 }
@@ -582,13 +578,8 @@
 
 bool KLocalePrivate::setLanguage(const QString &language, KConfig *config)
 {
-    if (config) {
-        //Copy config to a new shared config
-        m_config = KSharedConfig::openConfig();
-        config->copyTo(QString(), m_config.data());
-    } else {
-        m_config = KSharedConfig::Ptr();
-    }
+    m_config = config;
+    m_sharedConfig = KSharedConfig::Ptr();
 
     QMutexLocker lock(kLocaleMutex());
     m_languageList.removeAll(language);
@@ -2283,12 +2274,12 @@
     // valid loacle constructed.
     if (m_dayPeriods.isEmpty()) {
         m_dayPeriods.append(KDayPeriod(QString::fromLatin1("am"),
-                                       i18nc( "Before Noon KLocale::LongName", "Ante \
Meridian" ), +                                       i18nc( "Before Noon \
                KLocale::LongName", "Ante Meridiem" ),
                                        i18nc( "Before Noon KLocale::ShortName", "AM" \
                ),
                                        i18nc( "Before Noon KLocale::NarrowName", "A" \
                ),
                                        QTime( 0, 0, 0 ), QTime( 11, 59, 59, 999 ), \
0, 12 ));  m_dayPeriods.append(KDayPeriod(QString::fromLatin1("pm"),
-                                       i18nc( "After Noon KLocale::LongName", "Post \
Meridian" ), +                                       i18nc( "After Noon \
                KLocale::LongName", "Post Meridiem" ),
                                        i18nc( "After Noon KLocale::ShortName", "PM" \
                ),
                                        i18nc( "After Noon KLocale::NarrowName", "P" \
                ),
                                        QTime( 12, 0, 0 ), QTime( 23, 59, 59, 999 ), \
0, 12 )); @@ -2853,8 +2844,14 @@
 const KCalendarSystem * KLocalePrivate::calendar()
 {
     if (!m_calendar) {
-        m_calendar = KCalendarSystem::create(m_calendarSystem, m_config, q);
+        if (m_config) {
+            KSharedConfig::Ptr sharedConfig = \
KSharedConfig::openConfig(QString::fromLatin1("klocaletmp"), KConfig::SimpleConfig); \
+            m_config->copyTo(QString(), sharedConfig.data()); +            \
m_calendar = KCalendarSystem::create(m_calendarSystem, sharedConfig, q); +        } \
else { +            m_calendar = KCalendarSystem::create(m_calendarSystem, \
m_sharedConfig, q);  }
+    }
 
     return m_calendar;
 }
--- trunk/KDE/kdelibs/kdecore/localization/klocale_p.h #1205923:1205924
@@ -71,7 +71,7 @@
     /**
      * @internal Returns config object
      */
-    KSharedConfig::Ptr config();
+    KConfig *config();
 
     /**
      * @internal Copies object members
@@ -1096,7 +1096,8 @@
 
 private:
     // Config file containing locale config
-    KSharedConfig::Ptr m_config;
+    KConfig *m_config;
+    KSharedConfig::Ptr m_sharedConfig;
 
     // Country settings
     QString m_country;
--- trunk/KDE/kdelibs/kdecore/tests/klocaletest.cpp #1205923:1205924
@@ -343,7 +343,7 @@
     QCOMPARE( testPeriod.isValid(), false );
     testPeriod = locale.dayPeriodForTime( QTime( 03, 00, 00 ) );
     QCOMPARE( testPeriod.isValid(), true );
-    QCOMPARE( testPeriod.periodName(KLocale::LongName), QString( "Ante Meridian" ) \
); +    QCOMPARE( testPeriod.periodName(KLocale::LongName), QString( "Ante Meridiem" \
                ) );
     QCOMPARE( testPeriod.periodName(KLocale::ShortName), QString( "AM" ) );
     QCOMPARE( testPeriod.periodName(KLocale::NarrowName), QString( "A" ) );
     QCOMPARE( testPeriod.periodStart(), QTime( 0, 0, 0 ) );
@@ -361,7 +361,7 @@
 
     testPeriod = locale.dayPeriodForTime( QTime( 13, 00, 00 ) );
     QCOMPARE( testPeriod.isValid(), true );
-    QCOMPARE( testPeriod.periodName(KLocale::LongName), QString( "Post Meridian" ) \
); +    QCOMPARE( testPeriod.periodName(KLocale::LongName), QString( "Post Meridiem" \
                ) );
     QCOMPARE( testPeriod.periodName(KLocale::ShortName), QString( "PM" ) );
     QCOMPARE( testPeriod.periodName(KLocale::NarrowName), QString( "P" ) );
     QCOMPARE( testPeriod.periodStart(), QTime( 12, 0, 0 ) );
@@ -478,15 +478,15 @@
     KConfigGroup testGroup( testConfig, "Locale" );
     testGroup.writeEntry( "DayPeriod1",
                           QStringList() << "third1" << "First Third" << "T1" << "T" \
                <<
-                          QTime( 0, 0, 0 ).toString() << QTime( 7, 59, 59, 999 \
).toString() << +                          QTime( 0, 0, 0 ).toString("HH:mm:ss.zzz") \
<< QTime( 7, 59, 59, 999 ).toString("HH:mm:ss.zzz") <<  QString::number(0) << \
QString::number(12) );  testGroup.writeEntry( "DayPeriod2",
                           QStringList() << "third2" << "Second Third" << "T2" << "S" \
                <<
-                          QTime( 8, 0, 0 ).toString() << QTime( 15, 59, 59, 999 \
).toString() << +                          QTime( 8, 0, 0 ).toString("HH:mm:ss.zzz") \
<< QTime( 15, 59, 59, 999 ).toString("HH:mm:ss.zzz") <<  QString::number(8) << \
QString::number(12) );  testGroup.writeEntry( "DayPeriod3",
                           QStringList() << "third3" << "First Third" << "T3" << "R" \
                <<
-                          QTime( 16, 0, 0 ).toString() << QTime( 23, 59, 59, 999 \
).toString() << +                          QTime( 16, 0, 0 ).toString("HH:mm:ss.zzz") \
<< QTime( 23, 59, 59, 999 ).toString("HH:mm:ss.zzz") <<  QString::number(4) << \
QString::number(12) );  locale = KLocale("klocaletest", "en_us", "us", testConfig);
     QCOMPARE( locale.dayPeriodForTime( QTime( 1, 0, 0 ) ).periodName( \
KLocale::ShortName ), QString( "T1" ) );


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic