--------------Boundary-00=_F0D29IMQGGH5WDCEYB6P Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable El S=E1b 23 Feb 2002 21:36, Antonio Larrosa Jim=E9nez escribi=F3: > Hi, Someone called dfaure told me that it's better to be completely generic o= r=20 not generic at all, so I rewrote the patch in a simpler way. Is it ok now to commit ? Greetings, -- Antonio Larrosa Jimenez KDE Core developer - larrosa@kde.org http://perso.wanadoo.es/antlarr KDE - The development framework of the future, today. --------------Boundary-00=_F0D29IMQGGH5WDCEYB6P Content-Type: text/x-diff; charset="iso-8859-1"; name="locale2.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="locale2.diff" Index: localetime.cpp =================================================================== RCS file: /home/kde/kdebase/kcontrol/locale/localetime.cpp,v retrieving revision 1.44 diff -u -p -r1.44 localetime.cpp --- localetime.cpp 2001/09/16 11:58:10 1.44 +++ localetime.cpp 2002/02/25 00:50:21 @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -40,40 +41,93 @@ #include "localetime.h" #include "localetime.moc" -QMap KLocaleConfigTime::timeMap() const +class StringPair { - QMap map; +public: + QChar storeName; + QString userName; + + static StringPair find( const QValueList &list, const QChar &c) + { + for ( QValueList::ConstIterator it = list.begin(); + it != list.end(); + ++it ) + if ((*it).storeName==c) return (*it); + + StringPair r; + return r; + } + +}; + +/* Note that these operators aren't meant to be generic at all ! + But they should be that way to be able to sort the string pairs + with qHeapSort in the order we want. */ +bool operator< (const StringPair &p1, const StringPair &p2) +{ + return ! (p1.userName (const StringPair &p1, const StringPair &p2) +{ + return ! (p1.userName>p2.userName); +} + +bool operator>= (const StringPair &p1, const StringPair &p2) +{ + return ! (p1.userName>=p2.userName); +} + + +StringPair KLocaleConfigTime::buildStringPair(const QChar &c, const QString &s) const +{ + StringPair pair; + pair.storeName=c; + pair.userName=s; + return pair; +} + +QValueList KLocaleConfigTime::timeMap() const +{ + QValueList < StringPair > list; + list+=buildStringPair('H',m_locale->translate("HH")); + list+=buildStringPair('k',m_locale->translate("hH")); + list+=buildStringPair('I',m_locale->translate("PH")); + list+=buildStringPair('l',m_locale->translate("pH")); + list+=buildStringPair('M',m_locale->translate("MM")); + list+=buildStringPair('S',m_locale->translate("SS")); + list+=buildStringPair('p',m_locale->translate("AMPM")); - map['H'] = m_locale->translate("HH"); - map['k'] = m_locale->translate("hH"); - map['I'] = m_locale->translate("PH"); - map['l'] = m_locale->translate("pH"); - map['M'] = m_locale->translate("MM"); - map['S'] = m_locale->translate("SS"); - map['p'] = m_locale->translate("AMPM"); + qHeapSort( list ); - return map; + return list; } -QMap KLocaleConfigTime::dateMap() const +QValueList KLocaleConfigTime::dateMap() const { - QMap map; + QValueList < StringPair > list; + list+=buildStringPair('Y',m_locale->translate("YYYY")); + list+=buildStringPair('y',m_locale->translate("YY")); + list+=buildStringPair('n',m_locale->translate("mM")); + list+=buildStringPair('m',m_locale->translate("MM")); + list+=buildStringPair('b',m_locale->translate("SHORTMONTH")); + list+=buildStringPair('B',m_locale->translate("MONTH")); + list+=buildStringPair('e',m_locale->translate("dD")); + list+=buildStringPair('d',m_locale->translate("DD")); + list+=buildStringPair('a',m_locale->translate("SHORTWEEKDAY")); + list+=buildStringPair('A',m_locale->translate("WEEKDAY")); - map['Y'] = m_locale->translate("YYYY"); - map['y'] = m_locale->translate("YY"); - map['n'] = m_locale->translate("mM"); - map['m'] = m_locale->translate("MM"); - map['b'] = m_locale->translate("SHORTMONTH"); - map['B'] = m_locale->translate("MONTH"); - map['e'] = m_locale->translate("dD"); - map['d'] = m_locale->translate("DD"); - map['a'] = m_locale->translate("SHORTWEEKDAY"); - map['A'] = m_locale->translate("WEEKDAY"); + qHeapSort( list ); - return map; + return list; } -QString KLocaleConfigTime::userToStore(const QMap & map, +QString KLocaleConfigTime::userToStore(const QValueList & list, const QString & userFormat) const { QString result; @@ -81,16 +135,16 @@ QString KLocaleConfigTime::userToStore(c for ( uint pos = 0; pos < userFormat.length(); ++pos ) { bool bFound = false; - for ( QMap::ConstIterator it = map.begin(); - it != map.end() && !bFound; + for ( QValueList::ConstIterator it = list.begin(); + it != list.end() && !bFound; ++it ) { - QString s = it.data(); + QString s = (*it).userName; if ( userFormat.mid( pos, s.length() ) == s ) { result += '%'; - result += it.key(); + result += (*it).storeName; pos += s.length() - 1; @@ -111,7 +165,7 @@ QString KLocaleConfigTime::userToStore(c return result; } -QString KLocaleConfigTime::storeToUser(const QMap & map, +QString KLocaleConfigTime::storeToUser(const QValueList & list, const QString & storeFormat) const { QString result; @@ -122,9 +176,9 @@ QString KLocaleConfigTime::storeToUser(c QChar c = storeFormat.at(pos); if ( escaped ) { - QMap::ConstIterator it = map.find( c ); - if ( it != map.end() ) - result += it.data(); + StringPair it = StringPair::find( list, c ); + if ( !it.userName.isEmpty() ) + result += it.userName; else result += c; Index: localetime.h =================================================================== RCS file: /home/kde/kdebase/kcontrol/locale/localetime.h,v retrieving revision 1.12 diff -u -p -r1.12 localetime.h --- localetime.h 2001/08/17 13:39:22 1.12 +++ localetime.h 2002/02/25 00:50:21 @@ -36,6 +36,8 @@ class QLineEdit; class KLocale; class KLanguageCombo; +class StringPair; + class KLocaleConfigTime : public QWidget { Q_OBJECT @@ -67,13 +69,15 @@ private slots: void slotWeekStartsMondayChanged(); private: - QMap timeMap() const; - QMap dateMap() const; + QValueList timeMap() const; + QValueList dateMap() const; - QString storeToUser(const QMap & map, + QString storeToUser(const QValueList & map, const QString & storeFormat) const; - QString userToStore(const QMap & map, + QString userToStore(const QValueList & map, const QString & userFormat) const; + StringPair buildStringPair(const QChar &storeName, const QString &userName) const; + KLocale *m_locale; --------------Boundary-00=_F0D29IMQGGH5WDCEYB6P--