[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Re: Patch for kcontrol/locale
From: Antonio Larrosa =?iso-8859-1?q?Jim=E9nez?= <larrosa () kde ! org>
Date: 2002-02-25 0:50:39
[Download RAW message or body]
El Sáb 23 Feb 2002 21:36, Antonio Larrosa Jiménez escribió:
> Hi,
Someone called dfaure told me that it's better to be completely generic or
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.
["locale2.diff" (text/x-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 <qlayout.h>
#include <qwhatsthis.h>
#include <qcombobox.h>
+#include <qtl.h>
#include <klocale.h>
#include <kglobal.h>
@@ -40,40 +41,93 @@
#include "localetime.h"
#include "localetime.moc"
-QMap<QChar, QString> KLocaleConfigTime::timeMap() const
+class StringPair
{
- QMap<QChar, QString> map;
+public:
+ QChar storeName;
+ QString userName;
+
+ static StringPair find( const QValueList <StringPair> &list, const QChar &c)
+ {
+ for ( QValueList<StringPair>::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<p2.userName);
+}
+
+bool operator<= (const StringPair &p1, const StringPair &p2)
+{
+ return ! (p1.userName<=p2.userName);
+}
+
+bool operator> (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<StringPair> 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<QChar, QString> KLocaleConfigTime::dateMap() const
+QValueList <StringPair> KLocaleConfigTime::dateMap() const
{
- QMap <QChar, QString> 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<QChar, QString> & map,
+QString KLocaleConfigTime::userToStore(const QValueList<StringPair> & 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<QChar, QString>::ConstIterator it = map.begin();
- it != map.end() && !bFound;
+ for ( QValueList<StringPair>::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<QChar, QString> & map,
+QString KLocaleConfigTime::storeToUser(const QValueList<StringPair> & list,
const QString & storeFormat) const
{
QString result;
@@ -122,9 +176,9 @@ QString KLocaleConfigTime::storeToUser(c
QChar c = storeFormat.at(pos);
if ( escaped )
{
- QMap<QChar, QString>::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<QChar, QString> timeMap() const;
- QMap<QChar, QString> dateMap() const;
+ QValueList<StringPair> timeMap() const;
+ QValueList<StringPair> dateMap() const;
- QString storeToUser(const QMap<QChar, QString> & map,
+ QString storeToUser(const QValueList<StringPair> & map,
const QString & storeFormat) const;
- QString userToStore(const QMap<QChar, QString> & map,
+ QString userToStore(const QValueList<StringPair> & map,
const QString & userFormat) const;
+ StringPair buildStringPair(const QChar &storeName, const QString &userName) const;
+
KLocale *m_locale;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic