summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2005-02-09 21:01:05 (UTC)
committer zautrix <zautrix>2005-02-09 21:01:05 (UTC)
commit38c6a7b6ae1e98cba0fdf2d0fba59ad4b9060940 (patch) (unidiff)
tree1c171d9b0d4477810e68576e1954db0c8b68c668
parentab7725c4517a1f6c145075edcff0bdafe105f0ea (diff)
downloadkdepimpi-38c6a7b6ae1e98cba0fdf2d0fba59ad4b9060940.zip
kdepimpi-38c6a7b6ae1e98cba0fdf2d0fba59ad4b9060940.tar.gz
kdepimpi-38c6a7b6ae1e98cba0fdf2d0fba59ad4b9060940.tar.bz2
fix of fix
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/klocale.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index aec74fa..7f31ab1 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -1,1035 +1,1035 @@
1#include <qregexp.h> 1#include <qregexp.h>
2#include <qapplication.h> 2#include <qapplication.h>
3 3
4#include "kdebug.h" 4#include "kdebug.h"
5#include "kcalendarsystemgregorian.h" 5#include "kcalendarsystemgregorian.h"
6 6
7#include "klocale.h" 7#include "klocale.h"
8 8
9#include <qstringlist.h> 9#include <qstringlist.h>
10 10
11#define COLLECT_TRANSLATION 11//#define COLLECT_TRANSLATION
12 12
13 13
14QDict<QString> *mLocaleDict = 0; 14QDict<QString> *mLocaleDict = 0;
15void setLocaleDict( QDict<QString> * dict ) 15void setLocaleDict( QDict<QString> * dict )
16{ 16{
17 mLocaleDict = dict; 17 mLocaleDict = dict;
18 18
19} 19}
20 20
21#ifdef COLLECT_TRANSLATION 21#ifdef COLLECT_TRANSLATION
22 22
23QStringList missingTrans; 23QStringList missingTrans;
24QStringList existingTrans1; 24QStringList existingTrans1;
25QStringList existingTrans2; 25QStringList existingTrans2;
26 26
27void addMissing(const char *text) 27void addMissing(const char *text)
28{ 28{
29 29
30 QString mis ( text ); 30 QString mis ( text );
31 if ( !missingTrans.contains( mis ) ) 31 if ( !missingTrans.contains( mis ) )
32 missingTrans.append(mis); 32 missingTrans.append(mis);
33 33
34} 34}
35void addExist(const char *text,QString trans ) 35void addExist(const char *text,QString trans )
36{ 36{
37 //return; 37 //return;
38 QString mis ( text ); 38 QString mis ( text );
39 if ( !existingTrans1.contains( mis ) ) { 39 if ( !existingTrans1.contains( mis ) ) {
40 existingTrans1.append(mis); 40 existingTrans1.append(mis);
41 existingTrans2.append(trans); 41 existingTrans2.append(trans);
42 42
43 } 43 }
44 44
45} 45}
46 46
47#include <qfile.h> 47#include <qfile.h>
48#include <qtextstream.h> 48#include <qtextstream.h>
49#include <qtextcodec.h> 49#include <qtextcodec.h>
50#endif 50#endif
51void dumpMissing() 51void dumpMissing()
52{ 52{
53#ifdef COLLECT_TRANSLATION 53#ifdef COLLECT_TRANSLATION
54 QString fileName = "/tmp/usernewtrans.txt"; 54 QString fileName = "/tmp/usernewtrans.txt";
55 QFile file( fileName ); 55 QFile file( fileName );
56 if (!file.open( IO_WriteOnly ) ) { 56 if (!file.open( IO_WriteOnly ) ) {
57 return ; 57 return ;
58 } 58 }
59 QTextStream ts( &file ); 59 QTextStream ts( &file );
60 ts.setCodec( QTextCodec::codecForName("utf8") ); 60 ts.setCodec( QTextCodec::codecForName("utf8") );
61 61
62 int i; 62 int i;
63 for ( i = 0; i< missingTrans.count(); ++i ) { 63 for ( i = 0; i< missingTrans.count(); ++i ) {
64 64
65 QString text = missingTrans[i].replace( QRegExp("\n"),"\\n" ); 65 QString text = missingTrans[i].replace( QRegExp("\n"),"\\n" );
66 ts << "{ \""<<text<< "\",\""<< text <<"\" },\n"; 66 ts << "{ \""<<text<< "\",\""<< text <<"\" },\n";
67 67
68 } 68 }
69 file.close(); 69 file.close();
70 { 70 {
71 QString fileName = "/tmp/usertrans.txt"; 71 QString fileName = "/tmp/usertrans.txt";
72 QFile file( fileName ); 72 QFile file( fileName );
73 if (!file.open( IO_WriteOnly ) ) { 73 if (!file.open( IO_WriteOnly ) ) {
74 return ; 74 return ;
75 } 75 }
76 QTextStream ts( &file ); 76 QTextStream ts( &file );
77 ts.setCodec( QTextCodec::codecForName("utf8") ); 77 ts.setCodec( QTextCodec::codecForName("utf8") );
78 78
79 int i; 79 int i;
80 for ( i = 0; i< existingTrans1.count(); ++i ) { 80 for ( i = 0; i< existingTrans1.count(); ++i ) {
81 81
82 QString text = existingTrans1[i].replace( QRegExp("\n"),"\\n" ); 82 QString text = existingTrans1[i].replace( QRegExp("\n"),"\\n" );
83 QString text2 = existingTrans2[i].replace( QRegExp("\n"),"\\n" ); 83 QString text2 = existingTrans2[i].replace( QRegExp("\n"),"\\n" );
84 ts << "{ \""<<text<< "\",\""<< text2 <<"\" },\n"; 84 ts << "{ \""<<text<< "\",\""<< text2 <<"\" },\n";
85 85
86 } 86 }
87 file.close(); 87 file.close();
88 } 88 }
89#endif 89#endif
90} 90}
91QString i18n(const char *text) 91QString i18n(const char *text)
92{ 92{
93 if ( ! mLocaleDict ) { 93 if ( ! mLocaleDict ) {
94#ifdef COLLECT_TRANSLATION 94#ifdef COLLECT_TRANSLATION
95 addMissing( text ); 95 addMissing( text );
96#endif 96#endif
97 return QString( text ); 97 return QString( text );
98 } 98 }
99 else { 99 else {
100 QString* ret = mLocaleDict->find(QString(text)) ; 100 QString* ret = mLocaleDict->find(QString(text)) ;
101 if ( ret == 0 ) { 101 if ( ret == 0 ) {
102#ifdef COLLECT_TRANSLATION 102#ifdef COLLECT_TRANSLATION
103 addMissing( text ); 103 addMissing( text );
104#endif 104#endif
105 return QString( text ); 105 return QString( text );
106 } 106 }
107 else { 107 else {
108 if ( (*ret).isEmpty() ) { 108 if ( (*ret).isEmpty() ) {
109#ifdef COLLECT_TRANSLATION 109#ifdef COLLECT_TRANSLATION
110 addMissing( text ); 110 addMissing( text );
111#endif 111#endif
112 return QString( text ); 112 return QString( text );
113 } 113 }
114 else { 114 else {
115#ifdef COLLECT_TRANSLATION 115#ifdef COLLECT_TRANSLATION
116 addExist( text, *ret ); 116 addExist( text, *ret );
117#endif 117#endif
118 return (*ret); 118 return (*ret);
119 } 119 }
120 } 120 }
121 } 121 }
122 122
123} 123}
124 124
125QString i18n(const char *,const char *text) 125QString i18n(const char *,const char *text)
126{ 126{
127 return i18n( text ); 127 return i18n( text );
128} 128}
129 129
130QString i18n(const char *text1, const char *textn, int num) 130QString i18n(const char *text1, const char *textn, int num)
131{ 131{
132 if ( num == 1 ) return i18n( text1 ); 132 if ( num == 1 ) return i18n( text1 );
133 else { 133 else {
134 QString text = i18n( textn ); 134 QString text = i18n( textn );
135 int pos = text.find( "%n" ); 135 int pos = text.find( "%n" );
136 if ( pos >= 0 ) text.replace( pos, 2, QString::number( num ) ); 136 if ( pos >= 0 ) text.replace( pos, 2, QString::number( num ) );
137 return text; 137 return text;
138 } 138 }
139} 139}
140 140
141inline void put_it_in( QChar *buffer, uint& index, const QString &s ) 141inline void put_it_in( QChar *buffer, uint& index, const QString &s )
142{ 142{
143 for ( uint l = 0; l < s.length(); l++ ) 143 for ( uint l = 0; l < s.length(); l++ )
144 buffer[index++] = s.at( l ); 144 buffer[index++] = s.at( l );
145} 145}
146 146
147inline void put_it_in( QChar *buffer, uint& index, int number ) 147inline void put_it_in( QChar *buffer, uint& index, int number )
148{ 148{
149 buffer[index++] = number / 10 + '0'; 149 buffer[index++] = number / 10 + '0';
150 buffer[index++] = number % 10 + '0'; 150 buffer[index++] = number % 10 + '0';
151} 151}
152 152
153static int readInt(const QString &str, uint &pos) 153static int readInt(const QString &str, uint &pos)
154{ 154{
155 if (!str.at(pos).isDigit()) return -1; 155 if (!str.at(pos).isDigit()) return -1;
156 int result = 0; 156 int result = 0;
157 for (; str.length() > pos && str.at(pos).isDigit(); pos++) 157 for (; str.length() > pos && str.at(pos).isDigit(); pos++)
158 { 158 {
159 result *= 10; 159 result *= 10;
160 result += str.at(pos).digitValue(); 160 result += str.at(pos).digitValue();
161 } 161 }
162 162
163 return result; 163 return result;
164} 164}
165 165
166KLocale::KLocale() : mCalendarSystem( 0 ) 166KLocale::KLocale() : mCalendarSystem( 0 )
167{ 167{
168 168
169 m_decimalSymbol = "."; 169 m_decimalSymbol = ".";
170 m_positiveSign = ""; 170 m_positiveSign = "";
171 m_negativeSign = "-"; 171 m_negativeSign = "-";
172 m_thousandsSeparator = ","; 172 m_thousandsSeparator = ",";
173 173
174 174
175 175
176 176
177 mWeekStartsMonday = true; 177 mWeekStartsMonday = true;
178 mHourF24Format = true; 178 mHourF24Format = true;
179 mIntDateFormat = Default; 179 mIntDateFormat = Default;
180 mIntTimeFormat = Default; 180 mIntTimeFormat = Default;
181 mLanguage = 0; 181 mLanguage = 0;
182 mDateFormat = "%a %Y %b %d"; 182 mDateFormat = "%a %Y %b %d";
183 mDateFormatShort = "%Y-%m-%d"; 183 mDateFormatShort = "%Y-%m-%d";
184 mTimeZoneList << ("-11:00 US/Samoa") 184 mTimeZoneList << ("-11:00 US/Samoa")
185 << ("-10:00 US/Hawaii") 185 << ("-10:00 US/Hawaii")
186 << ("-09:00 US/Alaska") 186 << ("-09:00 US/Alaska")
187 << ("-08:00 US/Pacific") 187 << ("-08:00 US/Pacific")
188 << ("-07:00 US/Mountain") 188 << ("-07:00 US/Mountain")
189 << ("-06:00 US/Central") 189 << ("-06:00 US/Central")
190 << ("-05:00 US/Eastern") 190 << ("-05:00 US/Eastern")
191 << ("-04:00 Brazil/West") 191 << ("-04:00 Brazil/West")
192 << ("-03:00 Brazil/East") 192 << ("-03:00 Brazil/East")
193 << ("-02:00 Brazil/DeNoronha") 193 << ("-02:00 Brazil/DeNoronha")
194 << ("-01:00 Atlantic/Azores") 194 << ("-01:00 Atlantic/Azores")
195 << (" 00:00 Europe/London(UTC)") 195 << (" 00:00 Europe/London(UTC)")
196 << ("+01:00 Europe/Oslo(CET)") 196 << ("+01:00 Europe/Oslo(CET)")
197 << ("+02:00 Europe/Helsinki") 197 << ("+02:00 Europe/Helsinki")
198 << ("+03:00 Europe/Moscow") 198 << ("+03:00 Europe/Moscow")
199 << ("+04:00 Indian/Mauritius") 199 << ("+04:00 Indian/Mauritius")
200 << ("+05:00 Indian/Maldives") 200 << ("+05:00 Indian/Maldives")
201 << ("+06:00 Indian/Chagos") 201 << ("+06:00 Indian/Chagos")
202 << ("+07:00 Asia/Bangkok") 202 << ("+07:00 Asia/Bangkok")
203 << ("+08:00 Asia/Hongkong") 203 << ("+08:00 Asia/Hongkong")
204 << ("+09:00 Asia/Tokyo") 204 << ("+09:00 Asia/Tokyo")
205 << ("+10:00 Asia/Vladivostok") 205 << ("+10:00 Asia/Vladivostok")
206 << ("+11:00 Asia/Magadan") 206 << ("+11:00 Asia/Magadan")
207 << ("+12:00 Asia/Kamchatka") 207 << ("+12:00 Asia/Kamchatka")
208 // << (" xx:xx User defined offset") 208 // << (" xx:xx User defined offset")
209 << i18n (" Local Time"); 209 << i18n (" Local Time");
210 mSouthDaylight = false; 210 mSouthDaylight = false;
211 mTimeZoneOffset = 0; 211 mTimeZoneOffset = 0;
212 daylightEnabled = false; 212 daylightEnabled = false;
213} 213}
214 214
215void KLocale::setDateFormat( QString s ) 215void KLocale::setDateFormat( QString s )
216{ 216{
217 mDateFormat = s; 217 mDateFormat = s;
218} 218}
219 219
220void KLocale::setDateFormatShort( QString s ) 220void KLocale::setDateFormatShort( QString s )
221{ 221{
222 mDateFormatShort = s; 222 mDateFormatShort = s;
223} 223}
224 224
225void KLocale::setHore24Format ( bool b ) 225void KLocale::setHore24Format ( bool b )
226{ 226{
227 mHourF24Format = b; 227 mHourF24Format = b;
228} 228}
229void KLocale::setWeekStartMonday( bool b ) 229void KLocale::setWeekStartMonday( bool b )
230{ 230{
231 mWeekStartsMonday = b; 231 mWeekStartsMonday = b;
232} 232}
233 233
234KLocale::IntDateFormat KLocale::getIntDateFormat( ) 234KLocale::IntDateFormat KLocale::getIntDateFormat( )
235{ 235{
236 return mIntDateFormat; 236 return mIntDateFormat;
237 237
238} 238}
239void KLocale::setIntDateFormat( KLocale::IntDateFormat i ) 239void KLocale::setIntDateFormat( KLocale::IntDateFormat i )
240{ 240{
241 mIntDateFormat = i; 241 mIntDateFormat = i;
242} 242}
243KLocale::IntDateFormat KLocale::getIntTimeFormat( ) 243KLocale::IntDateFormat KLocale::getIntTimeFormat( )
244{ 244{
245 return mIntTimeFormat; 245 return mIntTimeFormat;
246 246
247} 247}
248void KLocale::setIntTimeFormat( KLocale::IntDateFormat i ) 248void KLocale::setIntTimeFormat( KLocale::IntDateFormat i )
249{ 249{
250 mIntTimeFormat = i; 250 mIntTimeFormat = i;
251} 251}
252 252
253void KLocale::setLanguage( int i ) 253void KLocale::setLanguage( int i )
254{ 254{
255 mLanguage = i; 255 mLanguage = i;
256} 256}
257int KLocale::language( ) 257int KLocale::language( )
258{ 258{
259 return mLanguage; 259 return mLanguage;
260} 260}
261QString KLocale::translate( const char *index ) const 261QString KLocale::translate( const char *index ) const
262{ 262{
263 return i18n( index ); 263 return i18n( index );
264} 264}
265 265
266QString KLocale::translate( const char *, const char *fallback) const 266QString KLocale::translate( const char *, const char *fallback) const
267{ 267{
268 return i18n( fallback ); 268 return i18n( fallback );
269} 269}
270 270
271QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const 271QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const
272{ 272{
273 const QString rst = timeFormat(intIntDateFormat); 273 const QString rst = timeFormat(intIntDateFormat);
274 274
275 // only "pm/am" here can grow, the rest shrinks, but 275 // only "pm/am" here can grow, the rest shrinks, but
276 // I'm rather safe than sorry 276 // I'm rather safe than sorry
277 QChar *buffer = new QChar[rst.length() * 3 / 2 + 30]; 277 QChar *buffer = new QChar[rst.length() * 3 / 2 + 30];
278 278
279 uint index = 0; 279 uint index = 0;
280 bool escape = false; 280 bool escape = false;
281 int number = 0; 281 int number = 0;
282 282
283 for ( uint format_index = 0; format_index < rst.length(); format_index++ ) 283 for ( uint format_index = 0; format_index < rst.length(); format_index++ )
284 { 284 {
285 if ( !escape ) 285 if ( !escape )
286 { 286 {
287 if ( rst.at( format_index ).unicode() == '%' ) 287 if ( rst.at( format_index ).unicode() == '%' )
288 escape = true; 288 escape = true;
289 else 289 else
290 buffer[index++] = rst.at( format_index ); 290 buffer[index++] = rst.at( format_index );
291 } 291 }
292 else 292 else
293 { 293 {
294 switch ( rst.at( format_index ).unicode() ) 294 switch ( rst.at( format_index ).unicode() )
295 { 295 {
296 case '%': 296 case '%':
297 buffer[index++] = '%'; 297 buffer[index++] = '%';
298 break; 298 break;
299 case 'H': 299 case 'H':
300 put_it_in( buffer, index, pTime.hour() ); 300 put_it_in( buffer, index, pTime.hour() );
301 break; 301 break;
302 case 'I': 302 case 'I':
303 put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 ); 303 put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 );
304 break; 304 break;
305 case 'M': 305 case 'M':
306 put_it_in( buffer, index, pTime.minute() ); 306 put_it_in( buffer, index, pTime.minute() );
307 break; 307 break;
308 case 'S': 308 case 'S':
309 if (includeSecs) 309 if (includeSecs)
310 put_it_in( buffer, index, pTime.second() ); 310 put_it_in( buffer, index, pTime.second() );
311 else 311 else
312 { 312 {
313 // we remove the seperator sign before the seconds and 313 // we remove the seperator sign before the seconds and
314 // assume that works everywhere 314 // assume that works everywhere
315 --index; 315 --index;
316 break; 316 break;
317 } 317 }
318 break; 318 break;
319 case 'k': 319 case 'k':
320 number = pTime.hour(); 320 number = pTime.hour();
321 case 'l': 321 case 'l':
322 // to share the code 322 // to share the code
323 if ( rst.at( format_index ).unicode() == 'l' ) 323 if ( rst.at( format_index ).unicode() == 'l' )
324 number = (pTime.hour() + 11) % 12 + 1; 324 number = (pTime.hour() + 11) % 12 + 1;
325 if ( number / 10 ) 325 if ( number / 10 )
326 buffer[index++] = number / 10 + '0'; 326 buffer[index++] = number / 10 + '0';
327 buffer[index++] = number % 10 + '0'; 327 buffer[index++] = number % 10 + '0';
328 break; 328 break;
329 case 'p': 329 case 'p':
330 { 330 {
331 QString s; 331 QString s;
332 if ( pTime.hour() >= 12 ) 332 if ( pTime.hour() >= 12 )
333 put_it_in( buffer, index, i18n("pm") ); 333 put_it_in( buffer, index, i18n("pm") );
334 else 334 else
335 put_it_in( buffer, index, i18n("am") ); 335 put_it_in( buffer, index, i18n("am") );
336 break; 336 break;
337 } 337 }
338 default: 338 default:
339 buffer[index++] = rst.at( format_index ); 339 buffer[index++] = rst.at( format_index );
340 break; 340 break;
341 } 341 }
342 escape = false; 342 escape = false;
343 } 343 }
344 } 344 }
345 QString ret( buffer, index ); 345 QString ret( buffer, index );
346 delete [] buffer; 346 delete [] buffer;
347 return ret; 347 return ret;
348} 348}
349 349
350QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const 350QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const
351{ 351{
352 const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); 352 const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat);
353 353
354 // I'm rather safe than sorry 354 // I'm rather safe than sorry
355 QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; 355 QChar *buffer = new QChar[rst.length() * 3 / 2 + 50];
356 356
357 unsigned int index = 0; 357 unsigned int index = 0;
358 bool escape = false; 358 bool escape = false;
359 int number = 0; 359 int number = 0;
360 360
361 for ( uint format_index = 0; format_index < rst.length(); ++format_index ) 361 for ( uint format_index = 0; format_index < rst.length(); ++format_index )
362 { 362 {
363 if ( !escape ) 363 if ( !escape )
364 { 364 {
365 if ( rst.at( format_index ).unicode() == '%' ) 365 if ( rst.at( format_index ).unicode() == '%' )
366 escape = true; 366 escape = true;
367 else 367 else
368 buffer[index++] = rst.at( format_index ); 368 buffer[index++] = rst.at( format_index );
369 } 369 }
370 else 370 else
371 { 371 {
372 switch ( rst.at( format_index ).unicode() ) 372 switch ( rst.at( format_index ).unicode() )
373 { 373 {
374 case '%': 374 case '%':
375 buffer[index++] = '%'; 375 buffer[index++] = '%';
376 break; 376 break;
377 case 'Y': 377 case 'Y':
378 put_it_in( buffer, index, pDate.year() / 100 ); 378 put_it_in( buffer, index, pDate.year() / 100 );
379 case 'y': 379 case 'y':
380 put_it_in( buffer, index, pDate.year() % 100 ); 380 put_it_in( buffer, index, pDate.year() % 100 );
381 break; 381 break;
382 case 'n': 382 case 'n':
383 number = pDate.month(); 383 number = pDate.month();
384 case 'e': 384 case 'e':
385 // to share the code 385 // to share the code
386 if ( rst.at( format_index ).unicode() == 'e' ) 386 if ( rst.at( format_index ).unicode() == 'e' )
387 number = pDate.day(); 387 number = pDate.day();
388 if ( number / 10 ) 388 if ( number / 10 )
389 buffer[index++] = number / 10 + '0'; 389 buffer[index++] = number / 10 + '0';
390 buffer[index++] = number % 10 + '0'; 390 buffer[index++] = number % 10 + '0';
391 break; 391 break;
392 case 'm': 392 case 'm':
393 put_it_in( buffer, index, pDate.month() ); 393 put_it_in( buffer, index, pDate.month() );
394 break; 394 break;
395 case 'b': 395 case 'b':
396 put_it_in( buffer, index, monthName(pDate.month(), true) ); 396 put_it_in( buffer, index, monthName(pDate.month(), true) );
397 break; 397 break;
398 case 'B': 398 case 'B':
399 put_it_in( buffer, index, monthName(pDate.month(), false) ); 399 put_it_in( buffer, index, monthName(pDate.month(), false) );
400 break; 400 break;
401 case 'd': 401 case 'd':
402 put_it_in( buffer, index, pDate.day() ); 402 put_it_in( buffer, index, pDate.day() );
403 break; 403 break;
404 case 'a': 404 case 'a':
405 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); 405 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) );
406 break; 406 break;
407 case 'A': 407 case 'A':
408 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); 408 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) );
409 break; 409 break;
410 default: 410 default:
411 buffer[index++] = rst.at( format_index ); 411 buffer[index++] = rst.at( format_index );
412 break; 412 break;
413 } 413 }
414 escape = false; 414 escape = false;
415 } 415 }
416 } 416 }
417 QString ret( buffer, index ); 417 QString ret( buffer, index );
418 delete [] buffer; 418 delete [] buffer;
419 return ret; 419 return ret;
420} 420}
421 421
422QString KLocale::formatDateTime(const QDateTime &pDateTime, 422QString KLocale::formatDateTime(const QDateTime &pDateTime,
423 bool shortFormat, 423 bool shortFormat,
424 bool includeSeconds, 424 bool includeSeconds,
425 IntDateFormat intIntDateFormat) const 425 IntDateFormat intIntDateFormat) const
426{ 426{
427 QString format("%1 %2"); 427 QString format("%1 %2");
428 428
429 if ( intIntDateFormat == Default ) 429 if ( intIntDateFormat == Default )
430 format = "%1 %2"; 430 format = "%1 %2";
431 else if ( intIntDateFormat == Format1 ) 431 else if ( intIntDateFormat == Format1 )
432 format = "%1 %2"; 432 format = "%1 %2";
433 else if ( intIntDateFormat == ISODate ) 433 else if ( intIntDateFormat == ISODate )
434 format = "%1T%2"; 434 format = "%1T%2";
435 435
436 QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat )) 436 QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat ))
437 .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat )); 437 .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat ));
438 438
439 //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() ); 439 //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() );
440 440
441 return res; 441 return res;
442} 442}
443 443
444QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const 444QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const
445{ 445{
446 return formatDateTime(pDateTime, true, true, intIntDateFormat); 446 return formatDateTime(pDateTime, true, true, intIntDateFormat);
447} 447}
448 448
449QDate KLocale::readDate(const QString &intstr, bool* ok) const 449QDate KLocale::readDate(const QString &intstr, bool* ok) const
450{ 450{
451 QDate date; 451 QDate date;
452 date = readDate(intstr, true, ok); 452 date = readDate(intstr, true, ok);
453 if (date.isValid()) return date; 453 if (date.isValid()) return date;
454 return readDate(intstr, false, ok); 454 return readDate(intstr, false, ok);
455} 455}
456 456
457QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const 457QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const
458{ 458{
459 QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); 459 QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace();
460 return readDate( intstr, fmt, ok ); 460 return readDate( intstr, fmt, ok );
461} 461}
462 462
463QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const 463QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const
464{ 464{
465 //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; 465 //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl;
466 QString str = intstr.simplifyWhiteSpace().lower(); 466 QString str = intstr.simplifyWhiteSpace().lower();
467 int day = -1, month = -1; 467 int day = -1, month = -1;
468 // allow the year to be omitted if not in the format 468 // allow the year to be omitted if not in the format
469 int year = QDate::currentDate().year(); 469 int year = QDate::currentDate().year();
470 uint strpos = 0; 470 uint strpos = 0;
471 uint fmtpos = 0; 471 uint fmtpos = 0;
472 472
473 while (fmt.length() > fmtpos || str.length() > strpos) 473 while (fmt.length() > fmtpos || str.length() > strpos)
474 { 474 {
475 if ( !(fmt.length() > fmtpos && str.length() > strpos) ) 475 if ( !(fmt.length() > fmtpos && str.length() > strpos) )
476 goto error; 476 goto error;
477 477
478 QChar c = fmt.at(fmtpos++); 478 QChar c = fmt.at(fmtpos++);
479 479
480 if (c != '%') { 480 if (c != '%') {
481 if (c.isSpace()) 481 if (c.isSpace())
482 strpos++; 482 strpos++;
483 else if (c != str.at(strpos++)) 483 else if (c != str.at(strpos++))
484 goto error; 484 goto error;
485 continue; 485 continue;
486 } 486 }
487 487
488 // remove space at the begining 488 // remove space at the begining
489 if (str.length() > strpos && str.at(strpos).isSpace()) 489 if (str.length() > strpos && str.at(strpos).isSpace())
490 strpos++; 490 strpos++;
491 491
492 c = fmt.at(fmtpos++); 492 c = fmt.at(fmtpos++);
493 switch (c) 493 switch (c)
494 { 494 {
495 case 'a': 495 case 'a':
496 case 'A': 496 case 'A':
497 // this will just be ignored 497 // this will just be ignored
498 { // Cristian Tache: porting to Win: Block added because of "j" redefinition 498 { // Cristian Tache: porting to Win: Block added because of "j" redefinition
499 for (int j = 1; j < 8; j++) { 499 for (int j = 1; j < 8; j++) {
500 QString s = weekDayName(j, c == 'a').lower(); 500 QString s = weekDayName(j, c == 'a').lower();
501 int len = s.length(); 501 int len = s.length();
502 if (str.mid(strpos, len) == s) 502 if (str.mid(strpos, len) == s)
503 strpos += len; 503 strpos += len;
504 } 504 }
505 break; 505 break;
506 } 506 }
507 case 'b': 507 case 'b':
508 case 'B': 508 case 'B':
509 { // Cristian Tache: porting to Win: Block added because of "j" redefinition 509 { // Cristian Tache: porting to Win: Block added because of "j" redefinition
510 for (int j = 1; j < 13; j++) { 510 for (int j = 1; j < 13; j++) {
511 QString s = monthName(j, c == 'b').lower(); 511 QString s = monthName(j, c == 'b').lower();
512 int len = s.length(); 512 int len = s.length();
513 if (str.mid(strpos, len) == s) { 513 if (str.mid(strpos, len) == s) {
514 month = j; 514 month = j;
515 strpos += len; 515 strpos += len;
516 } 516 }
517 } 517 }
518 break; 518 break;
519 } 519 }
520 case 'd': 520 case 'd':
521 case 'e': 521 case 'e':
522 day = readInt(str, strpos); 522 day = readInt(str, strpos);
523 if (day < 1 || day > 31) 523 if (day < 1 || day > 31)
524 goto error; 524 goto error;
525 525
526 break; 526 break;
527 527
528 case 'n': 528 case 'n':
529 case 'm': 529 case 'm':
530 month = readInt(str, strpos); 530 month = readInt(str, strpos);
531 if (month < 1 || month > 12) 531 if (month < 1 || month > 12)
532 goto error; 532 goto error;
533 533
534 break; 534 break;
535 535
536 case 'Y': 536 case 'Y':
537 case 'y': 537 case 'y':
538 year = readInt(str, strpos); 538 year = readInt(str, strpos);
539 if (year < 0) 539 if (year < 0)
540 goto error; 540 goto error;
541 // Qt treats a year in the range 0-100 as 1900-1999. 541 // Qt treats a year in the range 0-100 as 1900-1999.
542 // It is nicer for the user if we treat 0-68 as 2000-2068 542 // It is nicer for the user if we treat 0-68 as 2000-2068
543 if (year < 69) 543 if (year < 69)
544 year += 2000; 544 year += 2000;
545 else if (c == 'y') 545 else if (c == 'y')
546 year += 1900; 546 year += 1900;
547 547
548 break; 548 break;
549 } 549 }
550 } 550 }
551 //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; 551 //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl;
552 if ( year != -1 && month != -1 && day != -1 ) 552 if ( year != -1 && month != -1 && day != -1 )
553 { 553 {
554 if (ok) *ok = true; 554 if (ok) *ok = true;
555 return QDate(year, month, day); 555 return QDate(year, month, day);
556 } 556 }
557 error: 557 error:
558 if (ok) *ok = false; 558 if (ok) *ok = false;
559 return QDate(); // invalid date 559 return QDate(); // invalid date
560} 560}
561 561
562QTime KLocale::readTime(const QString &intstr, bool *ok) const 562QTime KLocale::readTime(const QString &intstr, bool *ok) const
563{ 563{
564 QTime _time; 564 QTime _time;
565 _time = readTime(intstr, false, ok); 565 _time = readTime(intstr, false, ok);
566 if (_time.isValid()) return _time; 566 if (_time.isValid()) return _time;
567 return readTime(intstr, true, ok); 567 return readTime(intstr, true, ok);
568} 568}
569 569
570QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const 570QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
571{ 571{
572 QString str = intstr.simplifyWhiteSpace().lower(); 572 QString str = intstr.simplifyWhiteSpace().lower();
573 QString Format = timeFormat().simplifyWhiteSpace(); 573 QString Format = timeFormat().simplifyWhiteSpace();
574 if (!seconds) 574 if (!seconds)
575 Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); 575 Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null);
576 576
577 int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds 577 int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds
578 578
579 bool g_12h = false; 579 bool g_12h = false;
580 bool pm = false; 580 bool pm = false;
581 uint strpos = 0; 581 uint strpos = 0;
582 uint Formatpos = 0; 582 uint Formatpos = 0;
583 583
584 while (Format.length() > Formatpos || str.length() > strpos) 584 while (Format.length() > Formatpos || str.length() > strpos)
585 { 585 {
586 if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; 586 if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error;
587 587
588 QChar c = Format.at(Formatpos++); 588 QChar c = Format.at(Formatpos++);
589 589
590 if (c != '%') 590 if (c != '%')
591 { 591 {
592 if (c.isSpace()) 592 if (c.isSpace())
593 strpos++; 593 strpos++;
594 else if (c != str.at(strpos++)) 594 else if (c != str.at(strpos++))
595 goto error; 595 goto error;
596 continue; 596 continue;
597 } 597 }
598 598
599 // remove space at the begining 599 // remove space at the begining
600 if (str.length() > strpos && str.at(strpos).isSpace()) 600 if (str.length() > strpos && str.at(strpos).isSpace())
601 strpos++; 601 strpos++;
602 602
603 c = Format.at(Formatpos++); 603 c = Format.at(Formatpos++);
604 switch (c) 604 switch (c)
605 { 605 {
606 case 'p': 606 case 'p':
607 { 607 {
608 QString s; 608 QString s;
609 s = i18n("pm").lower(); 609 s = i18n("pm").lower();
610 int len = s.length(); 610 int len = s.length();
611 if (str.mid(strpos, len) == s) 611 if (str.mid(strpos, len) == s)
612 { 612 {
613 pm = true; 613 pm = true;
614 strpos += len; 614 strpos += len;
615 } 615 }
616 else 616 else
617 { 617 {
618 s = i18n("am").lower(); 618 s = i18n("am").lower();
619 len = s.length(); 619 len = s.length();
620 if (str.mid(strpos, len) == s) { 620 if (str.mid(strpos, len) == s) {
621 pm = false; 621 pm = false;
622 strpos += len; 622 strpos += len;
623 } 623 }
624 else 624 else
625 goto error; 625 goto error;
626 } 626 }
627 } 627 }
628 break; 628 break;
629 629
630 case 'k': 630 case 'k':
631 case 'H': 631 case 'H':
632 g_12h = false; 632 g_12h = false;
633 hour = readInt(str, strpos); 633 hour = readInt(str, strpos);
634 if (hour < 0 || hour > 23) 634 if (hour < 0 || hour > 23)
635 goto error; 635 goto error;
636 636
637 break; 637 break;
638 638
639 case 'l': 639 case 'l':
640 case 'I': 640 case 'I':
641 g_12h = true; 641 g_12h = true;
642 hour = readInt(str, strpos); 642 hour = readInt(str, strpos);
643 if (hour < 1 || hour > 12) 643 if (hour < 1 || hour > 12)
644 goto error; 644 goto error;
645 645
646 break; 646 break;
647 647
648 case 'M': 648 case 'M':
649 minute = readInt(str, strpos); 649 minute = readInt(str, strpos);
650 if (minute < 0 || minute > 59) 650 if (minute < 0 || minute > 59)
651 goto error; 651 goto error;
652 652
653 break; 653 break;
654 654
655 case 'S': 655 case 'S':
656 second = readInt(str, strpos); 656 second = readInt(str, strpos);
657 if (second < 0 || second > 59) 657 if (second < 0 || second > 59)
658 goto error; 658 goto error;
659 659
660 break; 660 break;
661 } 661 }
662 } 662 }
663 if (g_12h) 663 if (g_12h)
664 { 664 {
665 hour %= 12; 665 hour %= 12;
666 if (pm) hour += 12; 666 if (pm) hour += 12;
667 } 667 }
668 668
669 if (ok) *ok = true; 669 if (ok) *ok = true;
670 return QTime(hour, minute, second); 670 return QTime(hour, minute, second);
671 671
672 error: 672 error:
673 if (ok) *ok = false; 673 if (ok) *ok = false;
674 return QTime(-1, -1, -1); // return invalid date if it didn't work 674 return QTime(-1, -1, -1); // return invalid date if it didn't work
675 // This will be removed in the near future, since it gives a warning on stderr. 675 // This will be removed in the near future, since it gives a warning on stderr.
676 // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. 676 // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime.
677} 677}
678 678
679QDateTime KLocale::readDateTime(const QString &intstr, 679QDateTime KLocale::readDateTime(const QString &intstr,
680 IntDateFormat intIntDateFormat, 680 IntDateFormat intIntDateFormat,
681 bool* ok) const 681 bool* ok) const
682{ 682{
683 bool ok1, ok2; 683 bool ok1, ok2;
684 684
685 // AT the moment we can not read any other format then ISODate 685 // AT the moment we can not read any other format then ISODate
686 if ( intIntDateFormat != ISODate ) 686 if ( intIntDateFormat != ISODate )
687 { 687 {
688 qDebug("KLocale::readDateTime, only ISODate is supported."); 688 qDebug("KLocale::readDateTime, only ISODate is supported.");
689 return QDateTime(); 689 return QDateTime();
690 } 690 }
691 691
692 int pos = intstr.find("T"); 692 int pos = intstr.find("T");
693 QString date = intstr.left(pos); 693 QString date = intstr.left(pos);
694 QString time = intstr.mid(pos+1); 694 QString time = intstr.mid(pos+1);
695 695
696 QString dformat = dateFormat(intIntDateFormat); 696 QString dformat = dateFormat(intIntDateFormat);
697 QString tformat = timeFormat(intIntDateFormat); 697 QString tformat = timeFormat(intIntDateFormat);
698 698
699 QDate m_date = readDate(date, dformat, &ok1); 699 QDate m_date = readDate(date, dformat, &ok1);
700 QTime m_time = readTime(time, tformat, &ok2); 700 QTime m_time = readTime(time, tformat, &ok2);
701 701
702 QDateTime m_dt; 702 QDateTime m_dt;
703 703
704 if (ok) 704 if (ok)
705 { 705 {
706 if ((ok1 == false) || (ok2 == false)) 706 if ((ok1 == false) || (ok2 == false))
707 *ok = false; 707 *ok = false;
708 else 708 else
709 *ok = true; 709 *ok = true;
710 } 710 }
711 711
712 //only set values if both operations returned true. 712 //only set values if both operations returned true.
713 if ((ok1 == true) && (ok2 == true)) 713 if ((ok1 == true) && (ok2 == true))
714 { 714 {
715 m_dt.setDate(m_date); 715 m_dt.setDate(m_date);
716 m_dt.setTime(m_time); 716 m_dt.setTime(m_time);
717 } 717 }
718 718
719 //qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); 719 //qDebug("KLocale::readDateTime() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2);
720 return m_dt; 720 return m_dt;
721} 721}
722 722
723QDate KLocale::readDate(const QString &intstr, 723QDate KLocale::readDate(const QString &intstr,
724 IntDateFormat intIntDateFormat, 724 IntDateFormat intIntDateFormat,
725 bool* ok) const 725 bool* ok) const
726{ 726{
727 bool ok1; 727 bool ok1;
728 728
729 QString dformat = dateFormat(intIntDateFormat); 729 QString dformat = dateFormat(intIntDateFormat);
730 730
731 QDate m_date = readDate(intstr, dformat, &ok1); 731 QDate m_date = readDate(intstr, dformat, &ok1);
732 732
733 if (ok) 733 if (ok)
734 *ok = ok1; 734 *ok = ok1;
735 735
736 //qDebug("KLocale::readDate() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2); 736 //qDebug("KLocale::readDate() transformed %s into %s (%s), %s (%s) : err1=%i, err2=%i", intstr.latin1(), date.latin1(), dformat.latin1(), time.latin1(), tformat.latin1(), ok1, ok2);
737 return m_date; 737 return m_date;
738} 738}
739 739
740 740
741bool KLocale::use12Clock() const 741bool KLocale::use12Clock() const
742{ 742{
743 return !mHourF24Format ;; 743 return !mHourF24Format ;;
744} 744}
745 745
746bool KLocale::weekStartsMonday() const 746bool KLocale::weekStartsMonday() const
747{ 747{
748 return mWeekStartsMonday; 748 return mWeekStartsMonday;
749} 749}
750 750
751int KLocale::weekStartDay() const 751int KLocale::weekStartDay() const
752{ 752{
753 if ( mWeekStartsMonday ) 753 if ( mWeekStartsMonday )
754 return 1; 754 return 1;
755 return 7; 755 return 7;
756} 756}
757 757
758QString KLocale::weekDayName(int i,bool shortName) const 758QString KLocale::weekDayName(int i,bool shortName) const
759{ 759{
760 if ( shortName ) 760 if ( shortName )
761 switch ( i ) 761 switch ( i )
762 { 762 {
763 case 1: return i18n("Monday", "Mon"); 763 case 1: return i18n("Monday", "Mon");
764 case 2: return i18n("Tuesday", "Tue"); 764 case 2: return i18n("Tuesday", "Tue");
765 case 3: return i18n("Wednesday", "Wed"); 765 case 3: return i18n("Wednesday", "Wed");
766 case 4: return i18n("Thursday", "Thu"); 766 case 4: return i18n("Thursday", "Thu");
767 case 5: return i18n("Friday", "Fri"); 767 case 5: return i18n("Friday", "Fri");
768 case 6: return i18n("Saturday", "Sat"); 768 case 6: return i18n("Saturday", "Sat");
769 case 7: return i18n("Sunday", "Sun"); 769 case 7: return i18n("Sunday", "Sun");
770 } 770 }
771 else 771 else
772 switch ( i ) 772 switch ( i )
773 { 773 {
774 case 1: return i18n("Monday"); 774 case 1: return i18n("Monday");
775 case 2: return i18n("Tuesday"); 775 case 2: return i18n("Tuesday");
776 case 3: return i18n("Wednesday"); 776 case 3: return i18n("Wednesday");
777 case 4: return i18n("Thursday"); 777 case 4: return i18n("Thursday");
778 case 5: return i18n("Friday"); 778 case 5: return i18n("Friday");
779 case 6: return i18n("Saturday"); 779 case 6: return i18n("Saturday");
780 case 7: return i18n("Sunday"); 780 case 7: return i18n("Sunday");
781 } 781 }
782 782
783 return QString::null; 783 return QString::null;
784} 784}
785 785
786QString KLocale::monthName(int i,bool shortName) const 786QString KLocale::monthName(int i,bool shortName) const
787{ 787{
788 if ( shortName ) 788 if ( shortName )
789 switch ( i ) 789 switch ( i )
790 { 790 {
791 case 1: return i18n("January", "Jan"); 791 case 1: return i18n("January", "Jan");
792 case 2: return i18n("February", "Feb"); 792 case 2: return i18n("February", "Feb");
793 case 3: return i18n("March", "Mar"); 793 case 3: return i18n("March", "Mar");
794 case 4: return i18n("April", "Apr"); 794 case 4: return i18n("April", "Apr");
795 case 5: return i18n("May short", "May"); 795 case 5: return i18n("May short", "May");
796 case 6: return i18n("June", "Jun"); 796 case 6: return i18n("June", "Jun");
797 case 7: return i18n("July", "Jul"); 797 case 7: return i18n("July", "Jul");
798 case 8: return i18n("August", "Aug"); 798 case 8: return i18n("August", "Aug");
799 case 9: return i18n("September", "Sep"); 799 case 9: return i18n("September", "Sep");
800 case 10: return i18n("October", "Oct"); 800 case 10: return i18n("October", "Oct");
801 case 11: return i18n("November", "Nov"); 801 case 11: return i18n("November", "Nov");
802 case 12: return i18n("December", "Dec"); 802 case 12: return i18n("December", "Dec");
803 } 803 }
804 else 804 else
805 switch (i) 805 switch (i)
806 { 806 {
807 case 1: return i18n("January"); 807 case 1: return i18n("January");
808 case 2: return i18n("February"); 808 case 2: return i18n("February");
809 case 3: return i18n("March"); 809 case 3: return i18n("March");
810 case 4: return i18n("April"); 810 case 4: return i18n("April");
811 case 5: return i18n("May long", "May"); 811 case 5: return i18n("May long", "May");
812 case 6: return i18n("June"); 812 case 6: return i18n("June");
813 case 7: return i18n("July"); 813 case 7: return i18n("July");
814 case 8: return i18n("August"); 814 case 8: return i18n("August");
815 case 9: return i18n("September"); 815 case 9: return i18n("September");
816 case 10: return i18n("October"); 816 case 10: return i18n("October");
817 case 11: return i18n("November"); 817 case 11: return i18n("November");
818 case 12: return i18n("December"); 818 case 12: return i18n("December");
819 } 819 }
820 820
821 return QString::null; 821 return QString::null;
822} 822}
823 823
824QString KLocale::country() const 824QString KLocale::country() const
825{ 825{
826 return QString::null; 826 return QString::null;
827} 827}
828 828
829QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const 829QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const
830{ 830{
831 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; 831 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
832 832
833 if ( dformat == ISODate ) 833 if ( dformat == ISODate )
834 return "%Y-%m-%d"; 834 return "%Y-%m-%d";
835 835
836 if ( QApplication::desktop()->width() < 480 ) { 836 if ( QApplication::desktop()->width() < 480 ) {
837 if ( dformat == Default ) 837 if ( dformat == Default )
838 return "%a %d %b %Y"; 838 return "%a %d %b %Y";
839 else if ( dformat == Format1 ) 839 else if ( dformat == Format1 )
840 return "%a %b %d %Y"; 840 return "%a %b %d %Y";
841 } else { 841 } else {
842 if ( dformat == Default ) 842 if ( dformat == Default )
843 return "%A %d %B %Y"; 843 return "%A %d %B %Y";
844 else if ( dformat == Format1 ) 844 else if ( dformat == Format1 )
845 return "%A %B %d %Y"; 845 return "%A %B %d %Y";
846 846
847 } 847 }
848 return mDateFormat ; 848 return mDateFormat ;
849} 849}
850 850
851QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const 851QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const
852{ 852{
853 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; 853 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
854 854
855 if ( dformat == Default ) 855 if ( dformat == Default )
856 return "%d.%m.%Y"; 856 return "%d.%m.%Y";
857 else if ( dformat == Format1 ) 857 else if ( dformat == Format1 )
858 return "%m.%d.%Y"; 858 return "%m.%d.%Y";
859 else if ( dformat == ISODate ) // = Qt::ISODate 859 else if ( dformat == ISODate ) // = Qt::ISODate
860 return "%Y-%m-%d"; 860 return "%Y-%m-%d";
861 return mDateFormatShort ; 861 return mDateFormatShort ;
862 862
863} 863}
864 864
865 865
866QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const 866QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const
867{ 867{
868 const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat; 868 const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat;
869 869
870 if ( tformat == Default ) 870 if ( tformat == Default )
871 if ( mHourF24Format) 871 if ( mHourF24Format)
872 return "%H:%M:%S"; 872 return "%H:%M:%S";
873 else 873 else
874 return "%I:%M:%S%p"; 874 return "%I:%M:%S%p";
875 875
876 else if ( tformat == Format1 ) 876 else if ( tformat == Format1 )
877 if ( mHourF24Format) 877 if ( mHourF24Format)
878 return "%H:%M:%S"; 878 return "%H:%M:%S";
879 else 879 else
880 return "%I:%M:%S%p"; 880 return "%I:%M:%S%p";
881 881
882 else if ( tformat == ISODate ) // = Qt::ISODate 882 else if ( tformat == ISODate ) // = Qt::ISODate
883 if ( mHourF24Format) 883 if ( mHourF24Format)
884 return "%H:%M:%S"; 884 return "%H:%M:%S";
885 else 885 else
886 return "%I:%M:%S%p"; 886 return "%I:%M:%S%p";
887 // to satisfy the compiler 887 // to satisfy the compiler
888 return "%H:%M:%S"; 888 return "%H:%M:%S";
889} 889}
890 890
891void KLocale::insertCatalogue ( const QString & ) 891void KLocale::insertCatalogue ( const QString & )
892{ 892{
893} 893}
894 894
895KCalendarSystem *KLocale::calendar() 895KCalendarSystem *KLocale::calendar()
896{ 896{
897 if ( !mCalendarSystem ) { 897 if ( !mCalendarSystem ) {
898 mCalendarSystem = new KCalendarSystemGregorian; 898 mCalendarSystem = new KCalendarSystemGregorian;
899 } 899 }
900 900
901 return mCalendarSystem; 901 return mCalendarSystem;
902} 902}
903 903
904int KLocale::timezoneOffset( QString timeZone ) 904int KLocale::timezoneOffset( QString timeZone )
905{ 905{
906 int ret = 1001; 906 int ret = 1001;
907 int index = mTimeZoneList.findIndex( timeZone ); 907 int index = mTimeZoneList.findIndex( timeZone );
908 if ( index < 24 ) 908 if ( index < 24 )
909 ret = ( index-11 ) * 60 ; 909 ret = ( index-11 ) * 60 ;
910 return ret; 910 return ret;
911} 911}
912 912
913QStringList KLocale::timeZoneList() const 913QStringList KLocale::timeZoneList() const
914{ 914{
915 return mTimeZoneList; 915 return mTimeZoneList;
916} 916}
917void KLocale::setTimezone( const QString &timeZone, bool oddTZ ) 917void KLocale::setTimezone( const QString &timeZone, bool oddTZ )
918{ 918{
919 mTimeZoneOffset = timezoneOffset( timeZone ); 919 mTimeZoneOffset = timezoneOffset( timeZone );
920 if ( oddTZ ) 920 if ( oddTZ )
921 mTimeZoneOffset += 30; 921 mTimeZoneOffset += 30;
922} 922}
923 923
924void KLocale::setDaylightSaving( bool b, int start , int end ) 924void KLocale::setDaylightSaving( bool b, int start , int end )
925{ 925{
926 daylightEnabled = b; 926 daylightEnabled = b;
927 daylightStart = start; 927 daylightStart = start;
928 daylightEnd = end; 928 daylightEnd = end;
929 mSouthDaylight = (end < start); 929 mSouthDaylight = (end < start);
930 // qDebug("klocale daylight %d %d %d ", b, start , end ); 930 // qDebug("klocale daylight %d %d %d ", b, start , end );
931} 931}
932 932
933int KLocale::localTimeOffset( const QDateTime &dt ) 933int KLocale::localTimeOffset( const QDateTime &dt )
934{ 934{
935 bool addDaylight = false; 935 bool addDaylight = false;
936 if ( daylightEnabled ) { 936 if ( daylightEnabled ) {
937 int d_end, d_start; 937 int d_end, d_start;
938 int dayofyear = dt.date().dayOfYear(); 938 int dayofyear = dt.date().dayOfYear();
939 int year = dt.date().year(); 939 int year = dt.date().year();
940 int add = 0; 940 int add = 0;
941 if ( QDate::leapYear(year) ) 941 if ( QDate::leapYear(year) )
942 add = 1; 942 add = 1;
943 QDate date ( year,1,1 ); 943 QDate date ( year,1,1 );
944 if ( daylightEnd > 59 ) 944 if ( daylightEnd > 59 )
945 d_end = daylightEnd +add; 945 d_end = daylightEnd +add;
946 else 946 else
947 d_end = daylightEnd; 947 d_end = daylightEnd;
948 if ( daylightStart > 59 ) 948 if ( daylightStart > 59 )
949 d_start = daylightStart +add; 949 d_start = daylightStart +add;
950 else 950 else
951 d_start = daylightStart; 951 d_start = daylightStart;
952 QDate s_date = date.addDays( d_start -1 ); 952 QDate s_date = date.addDays( d_start -1 );
953 QDate e_date = date.addDays( d_end -1 ); 953 QDate e_date = date.addDays( d_end -1 );
954 int dof = s_date.dayOfWeek(); 954 int dof = s_date.dayOfWeek();
955 if ( dof < 7 ) 955 if ( dof < 7 )
956 s_date = s_date.addDays( -dof ); 956 s_date = s_date.addDays( -dof );
957 dof = e_date.dayOfWeek(); 957 dof = e_date.dayOfWeek();
958 if ( dof < 7 ) 958 if ( dof < 7 )
959 e_date = e_date.addDays( -dof ); 959 e_date = e_date.addDays( -dof );
960 QTime startTime ( 3,0,0 ); 960 QTime startTime ( 3,0,0 );
961 QDateTime startDt( s_date, startTime ); 961 QDateTime startDt( s_date, startTime );
962 QDateTime endDt( e_date, startTime ); 962 QDateTime endDt( e_date, startTime );
963 //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( )); 963 //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( ));
964 if ( mSouthDaylight ) { 964 if ( mSouthDaylight ) {
965 if ( ! ( endDt < dt && dt < startDt) ) 965 if ( ! ( endDt < dt && dt < startDt) )
966 addDaylight = true; 966 addDaylight = true;
967 } else { 967 } else {
968 if ( startDt < dt && dt < endDt ) 968 if ( startDt < dt && dt < endDt )
969 addDaylight = true; 969 addDaylight = true;
970 970
971 971
972 } 972 }
973 } 973 }
974 int addMin = 0; 974 int addMin = 0;
975 if ( addDaylight ) 975 if ( addDaylight )
976 addMin = 60; 976 addMin = 60;
977 return mTimeZoneOffset + addMin; 977 return mTimeZoneOffset + addMin;
978} 978}
979// ****************************************************************** 979// ******************************************************************
980// added LR 980// added LR
981QString KLocale::formatNumber(double num, int precision) const 981QString KLocale::formatNumber(double num, int precision) const
982{ 982{
983 bool neg = num < 0; 983 bool neg = num < 0;
984 if (precision == -1) precision = 2; 984 if (precision == -1) precision = 2;
985 QString res = QString::number(neg?-num:num, 'f', precision); 985 QString res = QString::number(neg?-num:num, 'f', precision);
986 int pos = res.find('.'); 986 int pos = res.find('.');
987 if (pos == -1) pos = res.length(); 987 if (pos == -1) pos = res.length();
988 else res.replace(pos, 1, decimalSymbol()); 988 else res.replace(pos, 1, decimalSymbol());
989 989
990 while (0 < (pos -= 3)) 990 while (0 < (pos -= 3))
991 res.insert(pos, thousandsSeparator()); // thousand sep 991 res.insert(pos, thousandsSeparator()); // thousand sep
992 992
993 // How can we know where we should put the sign? 993 // How can we know where we should put the sign?
994 res.prepend(neg?negativeSign():positiveSign()); 994 res.prepend(neg?negativeSign():positiveSign());
995 995
996 return res; 996 return res;
997} 997}
998QString KLocale::formatNumber(const QString &numStr) const 998QString KLocale::formatNumber(const QString &numStr) const
999{ 999{
1000 return formatNumber(numStr.toDouble()); 1000 return formatNumber(numStr.toDouble());
1001} 1001}
1002double KLocale::readNumber(const QString &_str, bool * ok) const 1002double KLocale::readNumber(const QString &_str, bool * ok) const
1003{ 1003{
1004 QString str = _str.stripWhiteSpace(); 1004 QString str = _str.stripWhiteSpace();
1005 bool neg = str.find(negativeSign()) == 0; 1005 bool neg = str.find(negativeSign()) == 0;
1006 if (neg) 1006 if (neg)
1007 str.remove( 0, negativeSign().length() ); 1007 str.remove( 0, negativeSign().length() );
1008 1008
1009 /* will hold the scientific notation portion of the number. 1009 /* will hold the scientific notation portion of the number.
1010 Example, with 2.34E+23, exponentialPart == "E+23" 1010 Example, with 2.34E+23, exponentialPart == "E+23"
1011 */ 1011 */
1012 QString exponentialPart; 1012 QString exponentialPart;
1013 int EPos; 1013 int EPos;
1014 1014
1015 EPos = str.find('E', 0, false); 1015 EPos = str.find('E', 0, false);
1016 1016
1017 if (EPos != -1) 1017 if (EPos != -1)
1018 { 1018 {
1019 exponentialPart = str.mid(EPos); 1019 exponentialPart = str.mid(EPos);
1020 str = str.left(EPos); 1020 str = str.left(EPos);
1021 } 1021 }
1022 1022
1023 int pos = str.find(decimalSymbol()); 1023 int pos = str.find(decimalSymbol());
1024 QString major; 1024 QString major;
1025 QString minor; 1025 QString minor;
1026 if ( pos == -1 ) 1026 if ( pos == -1 )
1027 major = str; 1027 major = str;
1028 else 1028 else
1029 { 1029 {
1030 major = str.left(pos); 1030 major = str.left(pos);
1031 minor = str.mid(pos + decimalSymbol().length()); 1031 minor = str.mid(pos + decimalSymbol().length());
1032 } 1032 }
1033 1033
1034 // Remove thousand separators 1034 // Remove thousand separators
1035 int thlen = thousandsSeparator().length(); 1035 int thlen = thousandsSeparator().length();