summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kconfig.cpp26
-rw-r--r--microkde/kconfig.h3
-rw-r--r--microkde/kdecore/klocale.cpp51
-rw-r--r--microkde/kdecore/klocale.h11
4 files changed, 76 insertions, 15 deletions
diff --git a/microkde/kconfig.cpp b/microkde/kconfig.cpp
index 4cbec94..ba41f6c 100644
--- a/microkde/kconfig.cpp
+++ b/microkde/kconfig.cpp
@@ -48,241 +48,267 @@ void KConfig::setGroup( const QString &group )
48} 48}
49 49
50//US 50//US
51QString KConfig::group() const { 51QString KConfig::group() const {
52 return mGroup; 52 return mGroup;
53} 53}
54 54
55//US added method 55//US added method
56QValueList<int> KConfig::readIntListEntry( const QString & key) 56QValueList<int> KConfig::readIntListEntry( const QString & key)
57{ 57{
58// qDebug("KConfig::readIntListEntry key=%s:", key.latin1()); 58// qDebug("KConfig::readIntListEntry key=%s:", key.latin1());
59 59
60 QValueList<int> result; 60 QValueList<int> result;
61 61
62 QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key ); 62 QMap<QString,QString>::ConstIterator mit = mStringMap.find( mGroup + key );
63 63
64 if ( mit == mStringMap.end() ) { 64 if ( mit == mStringMap.end() ) {
65 return result; 65 return result;
66 } 66 }
67 67
68 QStringList valuesAsStrings = QStringList::split(":", *mit ); 68 QStringList valuesAsStrings = QStringList::split(":", *mit );
69 bool ok = false; 69 bool ok = false;
70 bool ok2 = true; 70 bool ok2 = true;
71 int val; 71 int val;
72 72
73 for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) { 73 for ( QStringList::Iterator sit = valuesAsStrings.begin(); sit != valuesAsStrings.end(); ++sit ) {
74 val = (*sit).toInt(&ok); 74 val = (*sit).toInt(&ok);
75 result << val; 75 result << val;
76 if (ok == false) { 76 if (ok == false) {
77 qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val); 77 qDebug("KConfig::readIntListEntry str=%s , int=%n:", (*sit).latin1(), &val);
78 ok2 = false; 78 ok2 = false;
79 } 79 }
80 } 80 }
81 81
82 if (ok2 == false) 82 if (ok2 == false)
83 { 83 {
84 84
85 qDebug("KConfig::readIntListEntry: error while reading one of the intvalues."); 85 qDebug("KConfig::readIntListEntry: error while reading one of the intvalues.");
86 } 86 }
87 87
88 return result; 88 return result;
89} 89}
90 90
91int KConfig::readNumEntry( const QString & key, int def ) 91int KConfig::readNumEntry( const QString & key, int def )
92{ 92{
93 QString res = readEntry(key, QString::number(def ) ); 93 QString res = readEntry(key, QString::number(def ) );
94 bool ok = false; 94 bool ok = false;
95 int result = res.toInt(&ok); 95 int result = res.toInt(&ok);
96 if ( ok ) 96 if ( ok )
97 return result; 97 return result;
98 return def; 98 return def;
99} 99}
100 100
101QString KConfig::readEntry( const QString &key, const QString &def ) 101QString KConfig::readEntry( const QString &key, const QString &def )
102{ 102{
103 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); 103 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key );
104 104
105 if ( it == mStringMap.end() ) { 105 if ( it == mStringMap.end() ) {
106 return def; 106 return def;
107 } 107 }
108 108
109 return *it; 109 return *it;
110} 110}
111 111
112QSize KConfig::readSizeEntry( const QString &key, QSize* def )
113{
114 QValueList<int> intlist = readIntListEntry(key);
115
116 if (intlist.count() < 2)
117 {
118 if (def)
119 return *def;
120 else
121 return QSize();
122 }
123
124 QSize ret;
125 ret.setWidth(intlist[0]);
126 ret.setHeight(intlist[1]);
127
128 return ret;
129}
130
112QStringList KConfig::readListEntry( const QString &key ) 131QStringList KConfig::readListEntry( const QString &key )
113{ 132{
114 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key ); 133 QMap<QString,QString>::ConstIterator it = mStringMap.find( mGroup + key );
115 134
116 if ( it == mStringMap.end() ) { 135 if ( it == mStringMap.end() ) {
117 return QStringList(); 136 return QStringList();
118 } 137 }
119 return QStringList::split(":", *it ); 138 return QStringList::split(":", *it );
120 139
121} 140}
122 141
123bool KConfig::readBoolEntry( const QString &key, bool def ) 142bool KConfig::readBoolEntry( const QString &key, bool def )
124{ 143{
125 QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key ); 144 QMap<QString,bool>::ConstIterator it = mBoolMap.find( mGroup + key );
126 145
127 if ( it == mBoolMap.end() ) { 146 if ( it == mBoolMap.end() ) {
128 return def; 147 return def;
129 } 148 }
130 149
131 return *it; 150 return *it;
132} 151}
133 152
134QColor KConfig::readColorEntry( const QString & e, QColor *def ) 153QColor KConfig::readColorEntry( const QString & e, QColor *def )
135{ 154{
136 155
137 QStringList l; 156 QStringList l;
138 l = readListEntry( e ); 157 l = readListEntry( e );
139 if (l.count() != 3 ) { 158 if (l.count() != 3 ) {
140 if ( def ) 159 if ( def )
141 return *def; 160 return *def;
142 else 161 else
143 return QColor(); 162 return QColor();
144 } 163 }
145 QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() ); 164 QColor c ( l[0].toInt(), l[1].toInt(), l[2].toInt() );
146 return c; 165 return c;
147} 166}
148 167
149QFont KConfig::readFontEntry( const QString & e, QFont *def ) 168QFont KConfig::readFontEntry( const QString & e, QFont *def )
150{ 169{
151 QStringList font = readListEntry( e ); 170 QStringList font = readListEntry( e );
152 if ( font.isEmpty() ) 171 if ( font.isEmpty() )
153 return *def; 172 return *def;
154 QFont f; 173 QFont f;
155 f.setFamily( font[0]); 174 f.setFamily( font[0]);
156 f.setBold ( font[1] == "bold"); 175 f.setBold ( font[1] == "bold");
157 f.setPointSize ( font[2].toInt()); 176 f.setPointSize ( font[2].toInt());
158 f.setItalic( font[3] == "italic" ); 177 f.setItalic( font[3] == "italic" );
159 return f; 178 return f;
160} 179}
161 180
162QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def ) 181QDateTime KConfig::readDateTimeEntry( const QString &key, const QDateTime *def )
163{ 182{
164 QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key ); 183 QMap<QString,QDateTime>::ConstIterator it = mDateTimeMap.find( mGroup + key );
165 184
166 if ( it == mDateTimeMap.end() ) { 185 if ( it == mDateTimeMap.end() ) {
167 if ( def ) return *def; 186 if ( def ) return *def;
168 else return QDateTime(); 187 else return QDateTime();
169 } 188 }
170 189
171 return *it; 190 return *it;
172} 191}
173 192
174//US added method 193//US added method
175void KConfig::writeEntry( const QString &key, const QValueList<int> &value) 194void KConfig::writeEntry( const QString &key, const QValueList<int> &value)
176{ 195{
177 QStringList valuesAsStrings; 196 QStringList valuesAsStrings;
178 197
179 QValueList<int>::ConstIterator it; 198 QValueList<int>::ConstIterator it;
180 199
181 for( it = value.begin(); it != value.end(); ++it ) 200 for( it = value.begin(); it != value.end(); ++it )
182 { 201 {
183 valuesAsStrings << QString::number(*it); 202 valuesAsStrings << QString::number(*it);
184 } 203 }
185 204
186 mStringMap.insert( mGroup + key, valuesAsStrings.join(":") ); 205 mStringMap.insert( mGroup + key, valuesAsStrings.join(":") );
187 mDirty = true; 206 mDirty = true;
188} 207}
189 208
190void KConfig::writeEntry( const QString & key , int num ) 209void KConfig::writeEntry( const QString & key , int num )
191{ 210{
192 writeEntry( key, QString::number ( num ) ); 211 writeEntry( key, QString::number ( num ) );
193} 212}
194 213
195void KConfig::writeEntry( const QString &key, const QString &value ) 214void KConfig::writeEntry( const QString &key, const QString &value )
196{ 215{
197 mStringMap.insert( mGroup + key, value ); 216 mStringMap.insert( mGroup + key, value );
198 217
199 mDirty = true; 218 mDirty = true;
200} 219}
201 220
202void KConfig::writeEntry( const QString &key, const QStringList &value ) 221void KConfig::writeEntry( const QString &key, const QStringList &value )
203{ 222{
204 mStringMap.insert( mGroup + key, value.join(":") ); 223 mStringMap.insert( mGroup + key, value.join(":") );
205 224
206 mDirty = true; 225 mDirty = true;
207} 226}
208 227
209void KConfig::writeEntry( const QString &key, bool value) 228void KConfig::writeEntry( const QString &key, bool value)
210{ 229{
211 mBoolMap.insert( mGroup + key, value ); 230 mBoolMap.insert( mGroup + key, value );
212 231
213 mDirty = true; 232 mDirty = true;
214} 233}
215 234
216void KConfig::writeEntry( const QString & e, const QColor & c ) 235void KConfig::writeEntry( const QString & e, const QColor & c )
217{ 236{
218 QStringList l; 237 QStringList l;
219 l.append( QString::number ( c.red() ) ); 238 l.append( QString::number ( c.red() ) );
220 l.append( QString::number ( c.green() ) ); 239 l.append( QString::number ( c.green() ) );
221 l.append( QString::number ( c.blue() ) ); 240 l.append( QString::number ( c.blue() ) );
222 writeEntry( e, l ); 241 writeEntry( e, l );
223} 242}
224 243
244void KConfig::writeEntry( const QString & e, const QSize & s )
245{
246 QValueList<int> intlist;
247 intlist << s.width() << s.height();
248 writeEntry( e, intlist );
249}
250
225void KConfig::writeEntry( const QString & e , const QFont & f ) 251void KConfig::writeEntry( const QString & e , const QFont & f )
226{ 252{
227 QStringList font; 253 QStringList font;
228 font.append( f.family()); 254 font.append( f.family());
229 font.append( (!f.bold ()?"nonbold":"bold") ); 255 font.append( (!f.bold ()?"nonbold":"bold") );
230 font.append( QString::number ( f.pointSize () ) ); 256 font.append( QString::number ( f.pointSize () ) );
231 font.append( !f.italic ()?"nonitalic":"italic" ); 257 font.append( !f.italic ()?"nonitalic":"italic" );
232 writeEntry( e, font ); 258 writeEntry( e, font );
233} 259}
234 260
235void KConfig::writeEntry( const QString &key, const QDateTime &dt ) 261void KConfig::writeEntry( const QString &key, const QDateTime &dt )
236{ 262{
237 mDateTimeMap.insert( mGroup + key, dt ); 263 mDateTimeMap.insert( mGroup + key, dt );
238} 264}
239 265
240void KConfig::load() 266void KConfig::load()
241{ 267{
242 268
243 269
244 QFile f( mFileName ); 270 QFile f( mFileName );
245 if ( !f.open( IO_ReadOnly ) ) { 271 if ( !f.open( IO_ReadOnly ) ) {
246 qDebug("KConfig: could not open file %s ",mFileName.latin1() ); 272 qDebug("KConfig: could not open file %s ",mFileName.latin1() );
247 return; 273 return;
248 } 274 }
249 275
250 mBoolMap.clear(); 276 mBoolMap.clear();
251 mStringMap.clear(); 277 mStringMap.clear();
252 278
253 QTextStream t( &f ); 279 QTextStream t( &f );
254 280
255 QString line = t.readLine(); 281 QString line = t.readLine();
256 282
257 while ( !line.isNull() ) { 283 while ( !line.isNull() ) {
258 QStringList tokens = QStringList::split( ",", line ); 284 QStringList tokens = QStringList::split( ",", line );
259 if ( tokens[0] == "bool" ) { 285 if ( tokens[0] == "bool" ) {
260 bool value = false; 286 bool value = false;
261 if ( tokens[2] == "1" ) value = true; 287 if ( tokens[2] == "1" ) value = true;
262 mBoolMap.insert( tokens[1], value ); 288 mBoolMap.insert( tokens[1], value );
263 } else if ( tokens[0] == "QString" ) { 289 } else if ( tokens[0] == "QString" ) {
264 QString value = tokens[2]; 290 QString value = tokens[2];
265 mStringMap.insert( tokens[1], value ); 291 mStringMap.insert( tokens[1], value );
266 } else if ( tokens[0] == "QDateTime" ) { 292 } else if ( tokens[0] == "QDateTime" ) {
267#if 0 293#if 0
268 int year = tokens[2].toInt(); 294 int year = tokens[2].toInt();
269 QDateTime dt( QDate( year, 295 QDateTime dt( QDate( year,
270 tokens[3].toInt(), 296 tokens[3].toInt(),
271 tokens[4].toInt() ), 297 tokens[4].toInt() ),
272 QTime( tokens[5].toInt(), tokens[6].toInt(), 298 QTime( tokens[5].toInt(), tokens[6].toInt(),
273 tokens[7].toInt() ) ); 299 tokens[7].toInt() ) );
274 mDateTimeMap.insert( tokens[1], dt ); 300 mDateTimeMap.insert( tokens[1], dt );
275#endif 301#endif
276 } 302 }
277 303
278 line = t.readLine(); 304 line = t.readLine();
279 } 305 }
280} 306}
281 307
282void KConfig::sync() 308void KConfig::sync()
283{ 309{
284 310
285 if ( !mDirty ) return; 311 if ( !mDirty ) return;
286 //qDebug("KConfig::sync() %s ",mFileName.latin1() ); 312 //qDebug("KConfig::sync() %s ",mFileName.latin1() );
287 //kdDebug() << "KConfig::sync(): " << mFileName << endl; 313 //kdDebug() << "KConfig::sync(): " << mFileName << endl;
288 314
diff --git a/microkde/kconfig.h b/microkde/kconfig.h
index a01b1a5..1a1038f 100644
--- a/microkde/kconfig.h
+++ b/microkde/kconfig.h
@@ -5,100 +5,101 @@
5#include <qstringlist.h> 5#include <qstringlist.h>
6#include <qvaluelist.h> 6#include <qvaluelist.h>
7#include <qcolor.h> 7#include <qcolor.h>
8#include <qfont.h> 8#include <qfont.h>
9#include <qmap.h> 9#include <qmap.h>
10#include <qdatetime.h> 10#include <qdatetime.h>
11 11
12class KConfig 12class KConfig
13{ 13{
14 public: 14 public:
15 KConfig( const QString & ); 15 KConfig( const QString & );
16 ~KConfig(); 16 ~KConfig();
17 17
18 void setTempGroup( const QString &group ); 18 void setTempGroup( const QString &group );
19 QString tempGroup() const; 19 QString tempGroup() const;
20 20
21 void setGroup( const QString & ); 21 void setGroup( const QString & );
22 22
23//US 23//US
24 /** 24 /**
25 * Returns the name of the group in which we are 25 * Returns the name of the group in which we are
26 * searching for keys and from which we are retrieving entries. 26 * searching for keys and from which we are retrieving entries.
27 * 27 *
28 * @return The current group. 28 * @return The current group.
29 */ 29 */
30 QString group() const; 30 QString group() const;
31 31
32//US I took the following deleteGroup method from a newer version from KDE. 32//US I took the following deleteGroup method from a newer version from KDE.
33/** 33/**
34 * Deletes a configuration entry group 34 * Deletes a configuration entry group
35 * 35 *
36 * If the group is not empty and bDeep is false, nothing gets 36 * If the group is not empty and bDeep is false, nothing gets
37 * deleted and false is returned. 37 * deleted and false is returned.
38 * If this group is the current group and it is deleted, the 38 * If this group is the current group and it is deleted, the
39 * current group is undefined and should be set with setGroup() 39 * current group is undefined and should be set with setGroup()
40 * before the next operation on the configuration object. 40 * before the next operation on the configuration object.
41 * 41 *
42 * @param group The name of the group 42 * @param group The name of the group
43 * returns true if we deleted at least one entry. 43 * returns true if we deleted at least one entry.
44 */ 44 */
45 bool deleteGroup( const QString& group); 45 bool deleteGroup( const QString& group);
46 46
47//US I took the following hasGroup method from a newer version from KDE. 47//US I took the following hasGroup method from a newer version from KDE.
48 /** 48 /**
49 * Returns true if the specified group is known about. 49 * Returns true if the specified group is known about.
50 * 50 *
51 * @param group The group to search for. 51 * @param group The group to search for.
52 * @return Whether the group exists. 52 * @return Whether the group exists.
53 */ 53 */
54 bool hasGroup(const QString &group) const; 54 bool hasGroup(const QString &group) const;
55 55
56 56
57 QString getFileName(); 57 QString getFileName();
58 58
59//US added method readIntListEntry 59//US added method readIntListEntry
60 QValueList<int> readIntListEntry( const QString &); 60 QValueList<int> readIntListEntry( const QString &);
61 61
62 int readNumEntry( const QString &, int def=0 ); 62 int readNumEntry( const QString &, int def=0 );
63 QString readEntry( const QString &, const QString &def=QString::null ); 63 QString readEntry( const QString &, const QString &def=QString::null );
64 QStringList readListEntry( const QString & ); 64 QStringList readListEntry( const QString & );
65 bool readBoolEntry( const QString &, bool def=false ); 65 bool readBoolEntry( const QString &, bool def=false );
66 QColor readColorEntry( const QString &, QColor * ); 66 QColor readColorEntry( const QString &, QColor * );
67 QFont readFontEntry( const QString &, QFont * ); 67 QFont readFontEntry( const QString &, QFont * );
68 QDateTime readDateTimeEntry( const QString &, const QDateTime *pDefault = 0 ); 68 QDateTime readDateTimeEntry( const QString &, const QDateTime *pDefault = 0 );
69 69 QSize readSizeEntry(const QString &, QSize* );
70 bool hasKey( const QString &); 70 bool hasKey( const QString &);
71 71
72 void writeEntry( const QString &, const QValueList<int>& ); 72 void writeEntry( const QString &, const QValueList<int>& );
73 void writeEntry( const QString &, int ); 73 void writeEntry( const QString &, int );
74 void writeEntry( const QString &key , unsigned int value) { writeEntry( key, int( value ) ); } 74 void writeEntry( const QString &key , unsigned int value) { writeEntry( key, int( value ) ); }
75 void writeEntry( const char *key , unsigned int value) { writeEntry( QString( key ), value ); } 75 void writeEntry( const char *key , unsigned int value) { writeEntry( QString( key ), value ); }
76 void writeEntry( const char *key, int value ) { writeEntry( QString( key ), value ); } 76 void writeEntry( const char *key, int value ) { writeEntry( QString( key ), value ); }
77 void writeEntry( const QString &, const QString & ); 77 void writeEntry( const QString &, const QString & );
78 void writeEntry( const char *key, const QString &value ) { writeEntry( QString( key ), value ); } 78 void writeEntry( const char *key, const QString &value ) { writeEntry( QString( key ), value ); }
79 void writeEntry( const QString &, const QStringList & ); 79 void writeEntry( const QString &, const QStringList & );
80 void writeEntry( const QString &, bool ); 80 void writeEntry( const QString &, bool );
81 void writeEntry( const char *key, bool value ) { writeEntry( QString( key ), value ); } 81 void writeEntry( const char *key, bool value ) { writeEntry( QString( key ), value ); }
82 void writeEntry( const QString &, const QColor & ); 82 void writeEntry( const QString &, const QColor & );
83 void writeEntry( const QString &, const QFont & ); 83 void writeEntry( const QString &, const QFont & );
84 void writeEntry( const QString &, const QDateTime & ); 84 void writeEntry( const QString &, const QDateTime & );
85 void writeEntry( const QString &, const QSize & );
85 86
86 void deleteEntry( const QString &); 87 void deleteEntry( const QString &);
87 88
88 void load(); 89 void load();
89 void sync(); 90 void sync();
90 91
91 private: 92 private:
92 static QString mGroup; 93 static QString mGroup;
93 QString mTempGroup; 94 QString mTempGroup;
94 95
95 QString mFileName; 96 QString mFileName;
96 97
97 QMap<QString,bool> mBoolMap; 98 QMap<QString,bool> mBoolMap;
98 QMap<QString,QString> mStringMap; 99 QMap<QString,QString> mStringMap;
99 QMap<QString,QDateTime> mDateTimeMap; 100 QMap<QString,QDateTime> mDateTimeMap;
100 101
101 bool mDirty; 102 bool mDirty;
102}; 103};
103 104
104#endif 105#endif
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index 9d7e60b..4960b9a 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -26,206 +26,218 @@ QString i18n(const char *text)
26 if ( (*ret).isEmpty() ) 26 if ( (*ret).isEmpty() )
27 return QString( text ); 27 return QString( text );
28 else 28 else
29 return (*ret); 29 return (*ret);
30 } 30 }
31 } 31 }
32 32
33} 33}
34 34
35QString i18n(const char *,const char *text) 35QString i18n(const char *,const char *text)
36{ 36{
37 return i18n( text ); 37 return i18n( text );
38} 38}
39 39
40QString i18n(const char *text1, const char *textn, int num) 40QString i18n(const char *text1, const char *textn, int num)
41{ 41{
42 if ( num == 1 ) return i18n( text1 ); 42 if ( num == 1 ) return i18n( text1 );
43 else { 43 else {
44 QString text = i18n( textn ); 44 QString text = i18n( textn );
45 int pos = text.find( "%n" ); 45 int pos = text.find( "%n" );
46 if ( pos >= 0 ) text.replace( pos, 2, QString::number( num ) ); 46 if ( pos >= 0 ) text.replace( pos, 2, QString::number( num ) );
47 return text; 47 return text;
48 } 48 }
49} 49}
50 50
51inline void put_it_in( QChar *buffer, uint& index, const QString &s ) 51inline void put_it_in( QChar *buffer, uint& index, const QString &s )
52{ 52{
53 for ( uint l = 0; l < s.length(); l++ ) 53 for ( uint l = 0; l < s.length(); l++ )
54 buffer[index++] = s.at( l ); 54 buffer[index++] = s.at( l );
55} 55}
56 56
57inline void put_it_in( QChar *buffer, uint& index, int number ) 57inline void put_it_in( QChar *buffer, uint& index, int number )
58{ 58{
59 buffer[index++] = number / 10 + '0'; 59 buffer[index++] = number / 10 + '0';
60 buffer[index++] = number % 10 + '0'; 60 buffer[index++] = number % 10 + '0';
61} 61}
62 62
63static int readInt(const QString &str, uint &pos) 63static int readInt(const QString &str, uint &pos)
64{ 64{
65 if (!str.at(pos).isDigit()) return -1; 65 if (!str.at(pos).isDigit()) return -1;
66 int result = 0; 66 int result = 0;
67 for (; str.length() > pos && str.at(pos).isDigit(); pos++) 67 for (; str.length() > pos && str.at(pos).isDigit(); pos++)
68 { 68 {
69 result *= 10; 69 result *= 10;
70 result += str.at(pos).digitValue(); 70 result += str.at(pos).digitValue();
71 } 71 }
72 72
73 return result; 73 return result;
74} 74}
75 75
76KLocale::KLocale() : mCalendarSystem( 0 ) 76KLocale::KLocale() : mCalendarSystem( 0 )
77{ 77{
78 78
79 m_decimalSymbol = "."; 79 m_decimalSymbol = ".";
80 m_positiveSign = ""; 80 m_positiveSign = "";
81 m_negativeSign = "-"; 81 m_negativeSign = "-";
82 m_thousandsSeparator = ","; 82 m_thousandsSeparator = ",";
83 83
84 84
85 85
86 86
87 mWeekStartsMonday = true; 87 mWeekStartsMonday = true;
88 mHourF24Format = true; 88 mHourF24Format = true;
89 mIntDateFormat = Default; 89 mIntDateFormat = Default;
90 mIntTimeFormat = Default;
90 mLanguage = 0; 91 mLanguage = 0;
91 mDateFormat = "%a %Y %b %d"; 92 mDateFormat = "%a %Y %b %d";
92 mDateFormatShort = "%Y-%m-%d"; 93 mDateFormatShort = "%Y-%m-%d";
93 mTimeZoneList << i18n ("-11:00 US/Samoa") 94 mTimeZoneList << i18n ("-11:00 US/Samoa")
94 << i18n ("-10:00 US/Hawaii") 95 << i18n ("-10:00 US/Hawaii")
95 << i18n ("-09:00 US/Alaska") 96 << i18n ("-09:00 US/Alaska")
96 << i18n ("-08:00 US/Pacific") 97 << i18n ("-08:00 US/Pacific")
97 << i18n ("-07:00 US/Mountain") 98 << i18n ("-07:00 US/Mountain")
98 << i18n ("-06:00 US/Central") 99 << i18n ("-06:00 US/Central")
99 << i18n ("-05:00 US/Eastern") 100 << i18n ("-05:00 US/Eastern")
100 << i18n ("-04:00 Brazil/West") 101 << i18n ("-04:00 Brazil/West")
101 << i18n ("-03:00 Brazil/East") 102 << i18n ("-03:00 Brazil/East")
102 << i18n ("-02:00 Brazil/DeNoronha") 103 << i18n ("-02:00 Brazil/DeNoronha")
103 << i18n ("-01:00 Atlantic/Azores") 104 << i18n ("-01:00 Atlantic/Azores")
104 << i18n (" 00:00 Europe/London(UTC)") 105 << i18n (" 00:00 Europe/London(UTC)")
105 << i18n ("+01:00 Europe/Oslo(CET)") 106 << i18n ("+01:00 Europe/Oslo(CET)")
106 << i18n ("+02:00 Europe/Helsinki") 107 << i18n ("+02:00 Europe/Helsinki")
107 << i18n ("+03:00 Europe/Moscow") 108 << i18n ("+03:00 Europe/Moscow")
108 << i18n ("+04:00 Indian/Mauritius") 109 << i18n ("+04:00 Indian/Mauritius")
109 << i18n ("+05:00 Indian/Maldives") 110 << i18n ("+05:00 Indian/Maldives")
110 << i18n ("+06:00 Indian/Chagos") 111 << i18n ("+06:00 Indian/Chagos")
111 << i18n ("+07:00 Asia/Bangkok") 112 << i18n ("+07:00 Asia/Bangkok")
112 << i18n ("+08:00 Asia/Hongkong") 113 << i18n ("+08:00 Asia/Hongkong")
113 << i18n ("+09:00 Asia/Tokyo") 114 << i18n ("+09:00 Asia/Tokyo")
114 << i18n ("+10:00 Asia/Vladivostok") 115 << i18n ("+10:00 Asia/Vladivostok")
115 << i18n ("+11:00 Asia/Magadan") 116 << i18n ("+11:00 Asia/Magadan")
116 << i18n ("+12:00 Asia/Kamchatka") 117 << i18n ("+12:00 Asia/Kamchatka")
117 // << i18n (" xx:xx User defined offset") 118 // << i18n (" xx:xx User defined offset")
118 << i18n (" Local Time"); 119 << i18n (" Local Time");
119 mSouthDaylight = false; 120 mSouthDaylight = false;
120 mTimeZoneOffset = 0; 121 mTimeZoneOffset = 0;
121 daylightEnabled = false; 122 daylightEnabled = false;
122} 123}
123 124
124void KLocale::setDateFormat( QString s ) 125void KLocale::setDateFormat( QString s )
125{ 126{
126 mDateFormat = s; 127 mDateFormat = s;
127} 128}
128 129
129void KLocale::setDateFormatShort( QString s ) 130void KLocale::setDateFormatShort( QString s )
130{ 131{
131 mDateFormatShort = s; 132 mDateFormatShort = s;
132} 133}
133 134
134void KLocale::setHore24Format ( bool b ) 135void KLocale::setHore24Format ( bool b )
135{ 136{
136 mHourF24Format = b; 137 mHourF24Format = b;
137} 138}
138void KLocale::setWeekStartMonday( bool b ) 139void KLocale::setWeekStartMonday( bool b )
139{ 140{
140 mWeekStartsMonday = b; 141 mWeekStartsMonday = b;
141} 142}
143
142KLocale::IntDateFormat KLocale::getIntDateFormat( ) 144KLocale::IntDateFormat KLocale::getIntDateFormat( )
143{ 145{
144 return mIntDateFormat; 146 return mIntDateFormat;
145 147
146} 148}
147void KLocale::setIntDateFormat( KLocale::IntDateFormat i ) 149void KLocale::setIntDateFormat( KLocale::IntDateFormat i )
148{ 150{
149 mIntDateFormat = i; 151 mIntDateFormat = i;
150} 152}
153KLocale::IntDateFormat KLocale::getIntTimeFormat( )
154{
155 return mIntTimeFormat;
156
157}
158void KLocale::setIntTimeFormat( KLocale::IntDateFormat i )
159{
160 mIntTimeFormat = i;
161}
162
151void KLocale::setLanguage( int i ) 163void KLocale::setLanguage( int i )
152{ 164{
153 mLanguage = i; 165 mLanguage = i;
154} 166}
155QString KLocale::translate( const char *index ) const 167QString KLocale::translate( const char *index ) const
156{ 168{
157 return i18n( index ); 169 return i18n( index );
158} 170}
159 171
160QString KLocale::translate( const char *, const char *fallback) const 172QString KLocale::translate( const char *, const char *fallback) const
161{ 173{
162 return i18n( fallback ); 174 return i18n( fallback );
163} 175}
164 176
165QString KLocale::formatTime(const QTime &pTime, bool includeSecs) const 177QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const
166{ 178{
167 const QString rst = timeFormat(); 179 const QString rst = timeFormat(intIntDateFormat);
168 180
169 // only "pm/am" here can grow, the rest shrinks, but 181 // only "pm/am" here can grow, the rest shrinks, but
170 // I'm rather safe than sorry 182 // I'm rather safe than sorry
171 QChar *buffer = new QChar[rst.length() * 3 / 2 + 30]; 183 QChar *buffer = new QChar[rst.length() * 3 / 2 + 30];
172 184
173 uint index = 0; 185 uint index = 0;
174 bool escape = false; 186 bool escape = false;
175 int number = 0; 187 int number = 0;
176 188
177 for ( uint format_index = 0; format_index < rst.length(); format_index++ ) 189 for ( uint format_index = 0; format_index < rst.length(); format_index++ )
178 { 190 {
179 if ( !escape ) 191 if ( !escape )
180 { 192 {
181 if ( rst.at( format_index ).unicode() == '%' ) 193 if ( rst.at( format_index ).unicode() == '%' )
182 escape = true; 194 escape = true;
183 else 195 else
184 buffer[index++] = rst.at( format_index ); 196 buffer[index++] = rst.at( format_index );
185 } 197 }
186 else 198 else
187 { 199 {
188 switch ( rst.at( format_index ).unicode() ) 200 switch ( rst.at( format_index ).unicode() )
189 { 201 {
190 case '%': 202 case '%':
191 buffer[index++] = '%'; 203 buffer[index++] = '%';
192 break; 204 break;
193 case 'H': 205 case 'H':
194 put_it_in( buffer, index, pTime.hour() ); 206 put_it_in( buffer, index, pTime.hour() );
195 break; 207 break;
196 case 'I': 208 case 'I':
197 put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 ); 209 put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 );
198 break; 210 break;
199 case 'M': 211 case 'M':
200 put_it_in( buffer, index, pTime.minute() ); 212 put_it_in( buffer, index, pTime.minute() );
201 break; 213 break;
202 case 'S': 214 case 'S':
203 if (includeSecs) 215 if (includeSecs)
204 put_it_in( buffer, index, pTime.second() ); 216 put_it_in( buffer, index, pTime.second() );
205 else 217 else
206 { 218 {
207 // we remove the seperator sign before the seconds and 219 // we remove the seperator sign before the seconds and
208 // assume that works everywhere 220 // assume that works everywhere
209 --index; 221 --index;
210 break; 222 break;
211 } 223 }
212 break; 224 break;
213 case 'k': 225 case 'k':
214 number = pTime.hour(); 226 number = pTime.hour();
215 case 'l': 227 case 'l':
216 // to share the code 228 // to share the code
217 if ( rst.at( format_index ).unicode() == 'l' ) 229 if ( rst.at( format_index ).unicode() == 'l' )
218 number = (pTime.hour() + 11) % 12 + 1; 230 number = (pTime.hour() + 11) % 12 + 1;
219 if ( number / 10 ) 231 if ( number / 10 )
220 buffer[index++] = number / 10 + '0'; 232 buffer[index++] = number / 10 + '0';
221 buffer[index++] = number % 10 + '0'; 233 buffer[index++] = number % 10 + '0';
222 break; 234 break;
223 case 'p': 235 case 'p':
224 { 236 {
225 QString s; 237 QString s;
226 if ( pTime.hour() >= 12 ) 238 if ( pTime.hour() >= 12 )
227 put_it_in( buffer, index, i18n("pm") ); 239 put_it_in( buffer, index, i18n("pm") );
228 else 240 else
229 put_it_in( buffer, index, i18n("am") ); 241 put_it_in( buffer, index, i18n("am") );
230 break; 242 break;
231 } 243 }
@@ -254,138 +266,139 @@ QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat
254 266
255 for ( uint format_index = 0; format_index < rst.length(); ++format_index ) 267 for ( uint format_index = 0; format_index < rst.length(); ++format_index )
256 { 268 {
257 if ( !escape ) 269 if ( !escape )
258 { 270 {
259 if ( rst.at( format_index ).unicode() == '%' ) 271 if ( rst.at( format_index ).unicode() == '%' )
260 escape = true; 272 escape = true;
261 else 273 else
262 buffer[index++] = rst.at( format_index ); 274 buffer[index++] = rst.at( format_index );
263 } 275 }
264 else 276 else
265 { 277 {
266 switch ( rst.at( format_index ).unicode() ) 278 switch ( rst.at( format_index ).unicode() )
267 { 279 {
268 case '%': 280 case '%':
269 buffer[index++] = '%'; 281 buffer[index++] = '%';
270 break; 282 break;
271 case 'Y': 283 case 'Y':
272 put_it_in( buffer, index, pDate.year() / 100 ); 284 put_it_in( buffer, index, pDate.year() / 100 );
273 case 'y': 285 case 'y':
274 put_it_in( buffer, index, pDate.year() % 100 ); 286 put_it_in( buffer, index, pDate.year() % 100 );
275 break; 287 break;
276 case 'n': 288 case 'n':
277 number = pDate.month(); 289 number = pDate.month();
278 case 'e': 290 case 'e':
279 // to share the code 291 // to share the code
280 if ( rst.at( format_index ).unicode() == 'e' ) 292 if ( rst.at( format_index ).unicode() == 'e' )
281 number = pDate.day(); 293 number = pDate.day();
282 if ( number / 10 ) 294 if ( number / 10 )
283 buffer[index++] = number / 10 + '0'; 295 buffer[index++] = number / 10 + '0';
284 buffer[index++] = number % 10 + '0'; 296 buffer[index++] = number % 10 + '0';
285 break; 297 break;
286 case 'm': 298 case 'm':
287 put_it_in( buffer, index, pDate.month() ); 299 put_it_in( buffer, index, pDate.month() );
288 break; 300 break;
289 case 'b': 301 case 'b':
290 put_it_in( buffer, index, monthName(pDate.month(), true) ); 302 put_it_in( buffer, index, monthName(pDate.month(), true) );
291 break; 303 break;
292 case 'B': 304 case 'B':
293 put_it_in( buffer, index, monthName(pDate.month(), false) ); 305 put_it_in( buffer, index, monthName(pDate.month(), false) );
294 break; 306 break;
295 case 'd': 307 case 'd':
296 put_it_in( buffer, index, pDate.day() ); 308 put_it_in( buffer, index, pDate.day() );
297 break; 309 break;
298 case 'a': 310 case 'a':
299 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); 311 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) );
300 break; 312 break;
301 case 'A': 313 case 'A':
302 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); 314 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) );
303 break; 315 break;
304 default: 316 default:
305 buffer[index++] = rst.at( format_index ); 317 buffer[index++] = rst.at( format_index );
306 break; 318 break;
307 } 319 }
308 escape = false; 320 escape = false;
309 } 321 }
310 } 322 }
311 QString ret( buffer, index ); 323 QString ret( buffer, index );
312 delete [] buffer; 324 delete [] buffer;
313 return ret; 325 return ret;
314} 326}
315 327
316QString KLocale::formatDateTime(const QDateTime &pDateTime, 328QString KLocale::formatDateTime(const QDateTime &pDateTime,
317 bool shortFormat, 329 bool shortFormat,
318 bool includeSeconds) const 330 bool includeSeconds,
331 IntDateFormat intIntDateFormat) const
319{ 332{
320 return QString( "%1 %2") 333 return QString( "%1 %2")
321 .arg( formatDate( pDateTime.date(), shortFormat ) ) 334 .arg( formatDate( pDateTime.date(), shortFormat, intIntDateFormat ) )
322 .arg( formatTime( pDateTime.time(), includeSeconds ) ); 335 .arg( formatTime( pDateTime.time(), includeSeconds , intIntDateFormat ) );
323} 336}
324 337
325QString KLocale::formatDateTime(const QDateTime &pDateTime) const 338QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const
326{ 339{
327 return formatDateTime(pDateTime, true); 340 return formatDateTime(pDateTime, true, intIntDateFormat);
328} 341}
329 342
330QDate KLocale::readDate(const QString &intstr, bool* ok) const 343QDate KLocale::readDate(const QString &intstr, bool* ok) const
331{ 344{
332 QDate date; 345 QDate date;
333 date = readDate(intstr, true, ok); 346 date = readDate(intstr, true, ok);
334 if (date.isValid()) return date; 347 if (date.isValid()) return date;
335 return readDate(intstr, false, ok); 348 return readDate(intstr, false, ok);
336} 349}
337 350
338QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const 351QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const
339{ 352{
340 QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); 353 QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace();
341 return readDate( intstr, fmt, ok ); 354 return readDate( intstr, fmt, ok );
342} 355}
343 356
344QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const 357QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const
345{ 358{
346 //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; 359 //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl;
347 QString str = intstr.simplifyWhiteSpace().lower(); 360 QString str = intstr.simplifyWhiteSpace().lower();
348 int day = -1, month = -1; 361 int day = -1, month = -1;
349 // allow the year to be omitted if not in the format 362 // allow the year to be omitted if not in the format
350 int year = QDate::currentDate().year(); 363 int year = QDate::currentDate().year();
351 uint strpos = 0; 364 uint strpos = 0;
352 uint fmtpos = 0; 365 uint fmtpos = 0;
353 366
354 while (fmt.length() > fmtpos || str.length() > strpos) 367 while (fmt.length() > fmtpos || str.length() > strpos)
355 { 368 {
356 if ( !(fmt.length() > fmtpos && str.length() > strpos) ) 369 if ( !(fmt.length() > fmtpos && str.length() > strpos) )
357 goto error; 370 goto error;
358 371
359 QChar c = fmt.at(fmtpos++); 372 QChar c = fmt.at(fmtpos++);
360 373
361 if (c != '%') { 374 if (c != '%') {
362 if (c.isSpace()) 375 if (c.isSpace())
363 strpos++; 376 strpos++;
364 else if (c != str.at(strpos++)) 377 else if (c != str.at(strpos++))
365 goto error; 378 goto error;
366 continue; 379 continue;
367 } 380 }
368 381
369 // remove space at the begining 382 // remove space at the begining
370 if (str.length() > strpos && str.at(strpos).isSpace()) 383 if (str.length() > strpos && str.at(strpos).isSpace())
371 strpos++; 384 strpos++;
372 385
373 c = fmt.at(fmtpos++); 386 c = fmt.at(fmtpos++);
374 switch (c) 387 switch (c)
375 { 388 {
376 case 'a': 389 case 'a':
377 case 'A': 390 case 'A':
378 // this will just be ignored 391 // this will just be ignored
379 { // Cristian Tache: porting to Win: Block added because of "j" redefinition 392 { // Cristian Tache: porting to Win: Block added because of "j" redefinition
380 for (int j = 1; j < 8; j++) { 393 for (int j = 1; j < 8; j++) {
381 QString s = weekDayName(j, c == 'a').lower(); 394 QString s = weekDayName(j, c == 'a').lower();
382 int len = s.length(); 395 int len = s.length();
383 if (str.mid(strpos, len) == s) 396 if (str.mid(strpos, len) == s)
384 strpos += len; 397 strpos += len;
385 } 398 }
386 break; 399 break;
387 } 400 }
388 case 'b': 401 case 'b':
389 case 'B': 402 case 'B':
390 { // Cristian Tache: porting to Win: Block added because of "j" redefinition 403 { // Cristian Tache: porting to Win: Block added because of "j" redefinition
391 for (int j = 1; j < 13; j++) { 404 for (int j = 1; j < 13; j++) {
@@ -395,128 +408,129 @@ QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) con
395 month = j; 408 month = j;
396 strpos += len; 409 strpos += len;
397 } 410 }
398 } 411 }
399 break; 412 break;
400 } 413 }
401 case 'd': 414 case 'd':
402 case 'e': 415 case 'e':
403 day = readInt(str, strpos); 416 day = readInt(str, strpos);
404 if (day < 1 || day > 31) 417 if (day < 1 || day > 31)
405 goto error; 418 goto error;
406 419
407 break; 420 break;
408 421
409 case 'n': 422 case 'n':
410 case 'm': 423 case 'm':
411 month = readInt(str, strpos); 424 month = readInt(str, strpos);
412 if (month < 1 || month > 12) 425 if (month < 1 || month > 12)
413 goto error; 426 goto error;
414 427
415 break; 428 break;
416 429
417 case 'Y': 430 case 'Y':
418 case 'y': 431 case 'y':
419 year = readInt(str, strpos); 432 year = readInt(str, strpos);
420 if (year < 0) 433 if (year < 0)
421 goto error; 434 goto error;
422 // Qt treats a year in the range 0-100 as 1900-1999. 435 // Qt treats a year in the range 0-100 as 1900-1999.
423 // It is nicer for the user if we treat 0-68 as 2000-2068 436 // It is nicer for the user if we treat 0-68 as 2000-2068
424 if (year < 69) 437 if (year < 69)
425 year += 2000; 438 year += 2000;
426 else if (c == 'y') 439 else if (c == 'y')
427 year += 1900; 440 year += 1900;
428 441
429 break; 442 break;
430 } 443 }
431 } 444 }
432 //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; 445 //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl;
433 if ( year != -1 && month != -1 && day != -1 ) 446 if ( year != -1 && month != -1 && day != -1 )
434 { 447 {
435 if (ok) *ok = true; 448 if (ok) *ok = true;
436 return QDate(year, month, day); 449 return QDate(year, month, day);
437 } 450 }
438 error: 451 error:
439 if (ok) *ok = false; 452 if (ok) *ok = false;
440 return QDate(); // invalid date 453 return QDate(); // invalid date
441} 454}
442 455
443QTime KLocale::readTime(const QString &intstr, bool *ok) const 456QTime KLocale::readTime(const QString &intstr, bool *ok) const
444{ 457{
445 QTime _time; 458 QTime _time;
446 _time = readTime(intstr, true, ok); 459 _time = readTime(intstr, true, ok);
447 if (_time.isValid()) return _time; 460 if (_time.isValid()) return _time;
448 return readTime(intstr, false, ok); 461 return readTime(intstr, false, ok);
449} 462}
450 463
451QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const 464QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
452{ 465{
453 QString str = intstr.simplifyWhiteSpace().lower(); 466 QString str = intstr.simplifyWhiteSpace().lower();
454 QString Format = timeFormat().simplifyWhiteSpace(); 467 QString Format = timeFormat().simplifyWhiteSpace();
455 if (!seconds) 468 if (!seconds)
456 Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); 469 Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null);
457 470
458 int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds 471 int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds
472
459 bool g_12h = false; 473 bool g_12h = false;
460 bool pm = false; 474 bool pm = false;
461 uint strpos = 0; 475 uint strpos = 0;
462 uint Formatpos = 0; 476 uint Formatpos = 0;
463 477
464 while (Format.length() > Formatpos || str.length() > strpos) 478 while (Format.length() > Formatpos || str.length() > strpos)
465 { 479 {
466 if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; 480 if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error;
467 481
468 QChar c = Format.at(Formatpos++); 482 QChar c = Format.at(Formatpos++);
469 483
470 if (c != '%') 484 if (c != '%')
471 { 485 {
472 if (c.isSpace()) 486 if (c.isSpace())
473 strpos++; 487 strpos++;
474 else if (c != str.at(strpos++)) 488 else if (c != str.at(strpos++))
475 goto error; 489 goto error;
476 continue; 490 continue;
477 } 491 }
478 492
479 // remove space at the begining 493 // remove space at the begining
480 if (str.length() > strpos && str.at(strpos).isSpace()) 494 if (str.length() > strpos && str.at(strpos).isSpace())
481 strpos++; 495 strpos++;
482 496
483 c = Format.at(Formatpos++); 497 c = Format.at(Formatpos++);
484 switch (c) 498 switch (c)
485 { 499 {
486 case 'p': 500 case 'p':
487 { 501 {
488 QString s; 502 QString s;
489 s = i18n("pm").lower(); 503 s = i18n("pm").lower();
490 int len = s.length(); 504 int len = s.length();
491 if (str.mid(strpos, len) == s) 505 if (str.mid(strpos, len) == s)
492 { 506 {
493 pm = true; 507 pm = true;
494 strpos += len; 508 strpos += len;
495 } 509 }
496 else 510 else
497 { 511 {
498 s = i18n("am").lower(); 512 s = i18n("am").lower();
499 len = s.length(); 513 len = s.length();
500 if (str.mid(strpos, len) == s) { 514 if (str.mid(strpos, len) == s) {
501 pm = false; 515 pm = false;
502 strpos += len; 516 strpos += len;
503 } 517 }
504 else 518 else
505 goto error; 519 goto error;
506 } 520 }
507 } 521 }
508 break; 522 break;
509 523
510 case 'k': 524 case 'k':
511 case 'H': 525 case 'H':
512 g_12h = false; 526 g_12h = false;
513 hour = readInt(str, strpos); 527 hour = readInt(str, strpos);
514 if (hour < 0 || hour > 23) 528 if (hour < 0 || hour > 23)
515 goto error; 529 goto error;
516 530
517 break; 531 break;
518 532
519 case 'l': 533 case 'l':
520 case 'I': 534 case 'I':
521 g_12h = true; 535 g_12h = true;
522 hour = readInt(str, strpos); 536 hour = readInt(str, strpos);
@@ -621,133 +635,150 @@ QString KLocale::monthName(int i,bool shortName) const
621 } 635 }
622 else 636 else
623 switch (i) 637 switch (i)
624 { 638 {
625 case 1: return i18n("January"); 639 case 1: return i18n("January");
626 case 2: return i18n("February"); 640 case 2: return i18n("February");
627 case 3: return i18n("March"); 641 case 3: return i18n("March");
628 case 4: return i18n("April"); 642 case 4: return i18n("April");
629 case 5: return i18n("May long", "May"); 643 case 5: return i18n("May long", "May");
630 case 6: return i18n("June"); 644 case 6: return i18n("June");
631 case 7: return i18n("July"); 645 case 7: return i18n("July");
632 case 8: return i18n("August"); 646 case 8: return i18n("August");
633 case 9: return i18n("September"); 647 case 9: return i18n("September");
634 case 10: return i18n("October"); 648 case 10: return i18n("October");
635 case 11: return i18n("November"); 649 case 11: return i18n("November");
636 case 12: return i18n("December"); 650 case 12: return i18n("December");
637 } 651 }
638 652
639 return QString::null; 653 return QString::null;
640} 654}
641 655
642QString KLocale::country() const 656QString KLocale::country() const
643{ 657{
644 return QString::null; 658 return QString::null;
645} 659}
646 660
647QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const 661QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const
648{ 662{
649 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; 663 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
650 664
651 if ( QApplication::desktop()->width() < 480 ) { 665 if ( QApplication::desktop()->width() < 480 ) {
652 if ( dformat == Default ) 666 if ( dformat == Default )
653 return "%a %d %b %Y"; 667 return "%a %d %b %Y";
654 else if ( dformat == Format1 ) 668 else if ( dformat == Format1 )
655 return "%a %b %d %Y"; 669 return "%a %b %d %Y";
656 else if ( dformat == ISODate ) 670 else if ( dformat == ISODate )
657 return "%a %Y %b %d"; 671 return "%a %Y %b %d";
658 } else { 672 } else {
659 673
660 if ( dformat == Default ) 674 if ( dformat == Default )
661 return "%A %d %B %Y"; 675 return "%A %d %B %Y";
662 else if ( dformat == Format1 ) 676 else if ( dformat == Format1 )
663 return "%A %B %d %Y"; 677 return "%A %B %d %Y";
664 else if ( dformat == ISODate ) 678 else if ( dformat == ISODate )
665 return "%A %Y %B %d"; 679 return "%A %Y %B %d";
666 } 680 }
667 return mDateFormat ; 681 return mDateFormat ;
668} 682}
669 683
670QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const 684QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const
671{ 685{
672 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; 686 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
673 687
674 if ( dformat == Default ) 688 if ( dformat == Default )
675 return "%d.%m.%Y"; 689 return "%d.%m.%Y";
676 else if ( dformat == Format1 ) 690 else if ( dformat == Format1 )
677 return "%m.%d.%Y"; 691 return "%m.%d.%Y";
678 else if ( dformat == ISODate ) // = Qt::ISODate 692 else if ( dformat == ISODate ) // = Qt::ISODate
679 return "%Y-%m-%d"; 693 return "%Y-%m-%d";
680 return mDateFormatShort ; 694 return mDateFormatShort ;
681 695
682} 696}
683 697
684 698
685QString KLocale::timeFormat() const 699QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const
686{ 700{
687 if ( mHourF24Format) 701 const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat;
702
703 if ( tformat == Default )
704 if ( mHourF24Format)
705 return "%H:%M:%S";
706 else
707 return "%I:%M:%S%p";
708
709 else if ( tformat == Format1 )
710 if ( mHourF24Format)
711 return "%H:%M:%S";
712 else
713 return "%I:%M:%S%p";
714
715 else if ( tformat == ISODate ) // = Qt::ISODate
716 if ( mHourF24Format)
688 return "%H:%M:%S"; 717 return "%H:%M:%S";
689 return "%I:%M:%S%p"; 718 else
719 return "%I:%M:%S%p";
720
690} 721}
691 722
692void KLocale::insertCatalogue ( const QString & ) 723void KLocale::insertCatalogue ( const QString & )
693{ 724{
694} 725}
695 726
696KCalendarSystem *KLocale::calendar() 727KCalendarSystem *KLocale::calendar()
697{ 728{
698 if ( !mCalendarSystem ) { 729 if ( !mCalendarSystem ) {
699 mCalendarSystem = new KCalendarSystemGregorian; 730 mCalendarSystem = new KCalendarSystemGregorian;
700 } 731 }
701 732
702 return mCalendarSystem; 733 return mCalendarSystem;
703} 734}
704 735
705int KLocale::timezoneOffset( QString timeZone ) 736int KLocale::timezoneOffset( QString timeZone )
706{ 737{
707 int ret = 1001; 738 int ret = 1001;
708 int index = mTimeZoneList.findIndex( timeZone ); 739 int index = mTimeZoneList.findIndex( timeZone );
709 if ( index < 24 ) 740 if ( index < 24 )
710 ret = ( index-11 ) * 60 ; 741 ret = ( index-11 ) * 60 ;
711 return ret; 742 return ret;
712} 743}
713 744
714QStringList KLocale::timeZoneList() const 745QStringList KLocale::timeZoneList() const
715{ 746{
716 return mTimeZoneList; 747 return mTimeZoneList;
717} 748}
718void KLocale::setTimezone( const QString &timeZone ) 749void KLocale::setTimezone( const QString &timeZone )
719{ 750{
720 mTimeZoneOffset = timezoneOffset( timeZone ); 751 mTimeZoneOffset = timezoneOffset( timeZone );
721} 752}
722 753
723void KLocale::setDaylightSaving( bool b, int start , int end ) 754void KLocale::setDaylightSaving( bool b, int start , int end )
724{ 755{
725 daylightEnabled = b; 756 daylightEnabled = b;
726 daylightStart = start; 757 daylightStart = start;
727 daylightEnd = end; 758 daylightEnd = end;
728 mSouthDaylight = (end < start); 759 mSouthDaylight = (end < start);
729 // qDebug("klocale daylight %d %d %d ", b, start , end ); 760 // qDebug("klocale daylight %d %d %d ", b, start , end );
730} 761}
731 762
732int KLocale::localTimeOffset( const QDateTime &dt ) 763int KLocale::localTimeOffset( const QDateTime &dt )
733{ 764{
734 bool addDaylight = false; 765 bool addDaylight = false;
735 if ( daylightEnabled ) { 766 if ( daylightEnabled ) {
736 int d_end, d_start; 767 int d_end, d_start;
737 int dayofyear = dt.date().dayOfYear(); 768 int dayofyear = dt.date().dayOfYear();
738 int year = dt.date().year(); 769 int year = dt.date().year();
739 int add = 0; 770 int add = 0;
740 if ( QDate::leapYear(year) ) 771 if ( QDate::leapYear(year) )
741 add = 1; 772 add = 1;
742 QDate date ( year,1,1 ); 773 QDate date ( year,1,1 );
743 if ( daylightEnd > 59 ) 774 if ( daylightEnd > 59 )
744 d_end = daylightEnd +add; 775 d_end = daylightEnd +add;
745 else 776 else
746 d_end = daylightEnd; 777 d_end = daylightEnd;
747 if ( daylightStart > 59 ) 778 if ( daylightStart > 59 )
748 d_start = daylightStart +add; 779 d_start = daylightStart +add;
749 else 780 else
750 d_start = daylightStart; 781 d_start = daylightStart;
751 QDate s_date = date.addDays( d_start -1 ); 782 QDate s_date = date.addDays( d_start -1 );
752 QDate e_date = date.addDays( d_end -1 ); 783 QDate e_date = date.addDays( d_end -1 );
753 int dof = s_date.dayOfWeek(); 784 int dof = s_date.dayOfWeek();
diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h
index f6c0253..153b12a 100644
--- a/microkde/kdecore/klocale.h
+++ b/microkde/kdecore/klocale.h
@@ -1,112 +1,115 @@
1#ifndef MINIKDE_KLOCALE_H 1#ifndef MINIKDE_KLOCALE_H
2#define MINIKDE_KLOCALE_H 2#define MINIKDE_KLOCALE_H
3 3
4#include <qstring.h> 4#include <qstring.h>
5#include <qstringlist.h> 5#include <qstringlist.h>
6#include <qdatetime.h> 6#include <qdatetime.h>
7#include <qdict.h> 7#include <qdict.h>
8 8
9#ifndef I18N_NOOP 9#ifndef I18N_NOOP
10#define I18N_NOOP(x) (x) 10#define I18N_NOOP(x) (x)
11#endif 11#endif
12 12
13class KCalendarSystem; 13class KCalendarSystem;
14void setLocaleDict( QDict<QString> * dict ); 14void setLocaleDict( QDict<QString> * dict );
15QString i18n(const char *text); 15QString i18n(const char *text);
16QString i18n(const char *hint, const char *text); 16QString i18n(const char *hint, const char *text);
17QString i18n(const char *text1, const char *textn, int num); 17QString i18n(const char *text1, const char *textn, int num);
18 18
19// Qt3's uic generates i18n( "msg", "comment" ) calls which conflict 19// Qt3's uic generates i18n( "msg", "comment" ) calls which conflict
20// with our i18n method. we use uic -tr tr2i18n to redirect 20// with our i18n method. we use uic -tr tr2i18n to redirect
21// to the right i18n() function 21// to the right i18n() function
22inline QString tr2i18n(const char* message, const char* =0) { 22inline QString tr2i18n(const char* message, const char* =0) {
23 return i18n( message); 23 return i18n( message);
24} 24}
25 25
26class KLocale 26class KLocale
27{ 27{
28 public: 28 public:
29 KLocale(); 29 KLocale();
30 30
31 QString formatNumber(double num, int precision = -1) const; 31 QString formatNumber(double num, int precision = -1) const;
32 QString formatNumber(const QString &numStr) const; 32 QString formatNumber(const QString &numStr) const;
33 double readNumber(const QString &numStr, bool * ok = 0) const; 33 double readNumber(const QString &numStr, bool * ok = 0) const;
34 34
35 QString decimalSymbol() const; 35 QString decimalSymbol() const;
36 QString thousandsSeparator() const; 36 QString thousandsSeparator() const;
37 QString positiveSign() const; 37 QString positiveSign() const;
38 QString negativeSign() const; 38 QString negativeSign() const;
39 39
40 40
41 QString translate( const char *index ) const; 41 QString translate( const char *index ) const;
42 QString translate( const char *index, const char *fallback) const; 42 QString translate( const char *index, const char *fallback) const;
43 43
44 enum IntDateFormat { Undefined=-1, Default=0, Format1=1, ISODate=2, Userdefined=3 }; 44 enum IntDateFormat { Undefined=-1, Default=0, Format1=1, ISODate=2, Userdefined=3 };
45 45
46 QString formatDate(const QDate &pDate, bool shortFormat = false, IntDateFormat intIntDateFormat = Undefined) const; 46 QString formatDate(const QDate &pDate, bool shortFormat = false, IntDateFormat intIntDateFormat = Undefined) const;
47 QString formatTime(const QTime &pTime, bool includeSecs = false) const; 47 QString formatTime(const QTime &pTime, bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const;
48 QString formatDateTime(const QDateTime &pDateTime) const; 48 QString formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat = Undefined) const;
49 QString formatDateTime(const QDateTime &pDateTime, 49 QString formatDateTime(const QDateTime &pDateTime,
50 bool shortFormat, 50 bool shortFormat,
51 bool includeSecs = false) const; 51 bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const;
52 52
53 QDate readDate(const QString &str, bool* ok = 0) const; 53 QDate readDate(const QString &str, bool* ok = 0) const;
54 QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const; 54 QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const;
55 QTime readTime(const QString &str, bool* ok = 0) const; 55 QTime readTime(const QString &str, bool* ok = 0) const;
56 56
57 bool use12Clock() const; 57 bool use12Clock() const;
58 bool weekStartsMonday() const; 58 bool weekStartsMonday() const;
59 int weekStartDay() const; 59 int weekStartDay() const;
60 60
61 QString weekDayName(int,bool=false) const; 61 QString weekDayName(int,bool=false) const;
62 QString monthName(int,bool=false) const; 62 QString monthName(int,bool=false) const;
63 63
64 QString country() const; 64 QString country() const;
65 65
66 QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; 66 QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const;
67 QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; 67 QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const;
68 QString timeFormat() const; 68 QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const;
69 69
70 void insertCatalogue ( const QString & ); 70 void insertCatalogue ( const QString & );
71 71
72 KCalendarSystem *calendar(); 72 KCalendarSystem *calendar();
73 void setHore24Format ( bool ); 73 void setHore24Format ( bool );
74 void setWeekStartMonday( bool ); 74 void setWeekStartMonday( bool );
75 void setIntDateFormat( IntDateFormat ); 75 void setIntDateFormat( IntDateFormat );
76 void setIntTimeFormat( IntDateFormat );
76 IntDateFormat getIntDateFormat( ); 77 IntDateFormat getIntDateFormat( );
78 IntDateFormat getIntTimeFormat( );
77 void setLanguage( int ); 79 void setLanguage( int );
78 void setDateFormat( QString ); 80 void setDateFormat( QString );
79 void setDateFormatShort( QString ); 81 void setDateFormatShort( QString );
80 82
81 QString m_decimalSymbol; 83 QString m_decimalSymbol;
82 QString m_thousandsSeparator; 84 QString m_thousandsSeparator;
83 QString m_currencySymbol; 85 QString m_currencySymbol;
84 QString m_monetaryDecimalSymbol; 86 QString m_monetaryDecimalSymbol;
85 QString m_monetaryThousandsSeparator; 87 QString m_monetaryThousandsSeparator;
86 QString m_positiveSign; 88 QString m_positiveSign;
87 QString m_negativeSign; 89 QString m_negativeSign;
88 90
89 int timezoneOffset( QString ); 91 int timezoneOffset( QString );
90 QStringList timeZoneList() const; 92 QStringList timeZoneList() const;
91 void setDaylightSaving( bool, int , int ); 93 void setDaylightSaving( bool, int , int );
92 int localTimeOffset(const QDateTime &); 94 int localTimeOffset(const QDateTime &);
93 void setTimezone( const QString &timeZone ); 95 void setTimezone( const QString &timeZone );
94 private: 96 private:
95 QTime readTime(const QString &str, bool seconds, bool *ok) const; 97 QTime readTime(const QString &str, bool seconds, bool *ok) const;
96 QDate readDate(const QString &str, bool shortFormat, bool *ok) const; 98 QDate readDate(const QString &str, bool shortFormat, bool *ok) const;
97 KCalendarSystem *mCalendarSystem; 99 KCalendarSystem *mCalendarSystem;
98 bool mWeekStartsMonday; 100 bool mWeekStartsMonday;
99 bool mHourF24Format; 101 bool mHourF24Format;
100 IntDateFormat mIntDateFormat; 102 IntDateFormat mIntDateFormat;
103 IntDateFormat mIntTimeFormat;
101 int mLanguage; 104 int mLanguage;
102 QString mDateFormat; 105 QString mDateFormat;
103 QString mDateFormatShort; 106 QString mDateFormatShort;
104 QStringList mTimeZoneList; 107 QStringList mTimeZoneList;
105 bool daylightEnabled; 108 bool daylightEnabled;
106 int mDaylightTZoffset; 109 int mDaylightTZoffset;
107 int mNondaylightTZoffset; 110 int mNondaylightTZoffset;
108 bool mSouthDaylight; 111 bool mSouthDaylight;
109 int daylightStart, daylightEnd, mTimeZoneOffset; 112 int daylightStart, daylightEnd, mTimeZoneOffset;
110}; 113};
111 114
112#endif 115#endif