summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kaddressbook/views/contactlistview.cpp28
-rw-r--r--microkde/kdecore/klocale.cpp4
-rw-r--r--microkde/kdecore/klocale.h1
3 files changed, 32 insertions, 1 deletions
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp
index 4cc22ea..c74f8cf 100644
--- a/kaddressbook/views/contactlistview.cpp
+++ b/kaddressbook/views/contactlistview.cpp
@@ -1,345 +1,371 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#include <qheader.h> 24#include <qheader.h>
25#include <qiconset.h> 25#include <qiconset.h>
26#include <qimage.h> 26#include <qimage.h>
27#include <qdragobject.h> 27#include <qdragobject.h>
28#include <qcombobox.h> 28#include <qcombobox.h>
29#include <qpainter.h> 29#include <qpainter.h>
30#include <qbrush.h> 30#include <qbrush.h>
31#include <qevent.h> 31#include <qevent.h>
32 32
33#include <klocale.h> 33#include <klocale.h>
34#include <kglobalsettings.h> 34#include <kglobalsettings.h>
35#include <kiconloader.h> 35#include <kiconloader.h>
36#include <kdebug.h> 36#include <kdebug.h>
37#include <kconfig.h> 37#include <kconfig.h>
38#include <kapplication.h> 38#include <kapplication.h>
39#include <kurl.h> 39#include <kurl.h>
40 40
41#include "kaddressbooktableview.h" 41#include "kaddressbooktableview.h"
42 42
43#include "contactlistview.h" 43#include "contactlistview.h"
44 44
45///////////////////////////////// 45/////////////////////////////////
46// DynamicTip Methods 46// DynamicTip Methods
47 47
48DynamicTip::DynamicTip( ContactListView *parent) 48DynamicTip::DynamicTip( ContactListView *parent)
49 : QToolTip( parent ) 49 : QToolTip( parent )
50{ 50{
51} 51}
52 52
53void DynamicTip::maybeTip( const QPoint &pos ) 53void DynamicTip::maybeTip( const QPoint &pos )
54{ 54{
55 static bool ishidden = true; 55 static bool ishidden = true;
56 if (!parentWidget()->inherits( "ContactListView" )) 56 if (!parentWidget()->inherits( "ContactListView" ))
57 return; 57 return;
58 58
59 ContactListView *plv = (ContactListView*)parentWidget(); 59 ContactListView *plv = (ContactListView*)parentWidget();
60 if (!plv->tooltips()) 60 if (!plv->tooltips())
61 return; 61 return;
62 62
63 QPoint posVp = plv->viewport()->pos(); 63 QPoint posVp = plv->viewport()->pos();
64 64
65 QListViewItem *lvi = plv->itemAt( pos - posVp ); 65 QListViewItem *lvi = plv->itemAt( pos - posVp );
66 if (!lvi) 66 if (!lvi)
67 return; 67 return;
68 68
69#ifndef KAB_EMBEDDED 69#ifndef KAB_EMBEDDED
70 ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi); 70 ContactListViewItem *plvi = dynamic_cast< ContactListViewItem* >(lvi);
71#else //KAB_EMBEDDED 71#else //KAB_EMBEDDED
72 ContactListViewItem *plvi = (ContactListViewItem*)(lvi); 72 ContactListViewItem *plvi = (ContactListViewItem*)(lvi);
73#endif //KAB_EMBEDDED 73#endif //KAB_EMBEDDED
74 74
75 if (!plvi) 75 if (!plvi)
76 return; 76 return;
77 77
78 if (ishidden) { 78 if (ishidden) {
79 QString s; 79 QString s;
80 QRect r = plv->itemRect( lvi ); 80 QRect r = plv->itemRect( lvi );
81 r.moveBy( posVp.x(), posVp.y() ); 81 r.moveBy( posVp.x(), posVp.y() );
82 82
83 //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width() 83 //kdDebug() << "Tip rec: " << r.x() << "," << r.y() << "," << r.width()
84 // << "," << r.height() << endl; 84 // << "," << r.height() << endl;
85 85
86 KABC::Addressee a = plvi->addressee(); 86 KABC::Addressee a = plvi->addressee();
87 if (a.isEmpty()) 87 if (a.isEmpty())
88 return; 88 return;
89 89
90 s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel()) 90 s += i18n("label: value", "%1: %2").arg(a.formattedNameLabel())
91 .arg(a.formattedName()); 91 .arg(a.formattedName());
92 92
93 s += '\n'; 93 s += '\n';
94 s += i18n("label: value", "%1: %2").arg(a.organizationLabel()) 94 s += i18n("label: value", "%1: %2").arg(a.organizationLabel())
95 .arg(a.organization()); 95 .arg(a.organization());
96 96
97 QString notes = a.note().stripWhiteSpace(); 97 QString notes = a.note().stripWhiteSpace();
98 if ( !notes.isEmpty() ) { 98 if ( !notes.isEmpty() ) {
99 notes += '\n'; 99 notes += '\n';
100 s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel()); 100 s += '\n' + i18n("label: value", "%1: \n").arg(a.noteLabel());
101 QFontMetrics fm( font() ); 101 QFontMetrics fm( font() );
102 102
103 // Begin word wrap code based on QMultiLineEdit code 103 // Begin word wrap code based on QMultiLineEdit code
104 int i = 0; 104 int i = 0;
105 bool doBreak = false; 105 bool doBreak = false;
106 int linew = 0; 106 int linew = 0;
107 int lastSpace = -1; 107 int lastSpace = -1;
108 int a = 0; 108 int a = 0;
109 int lastw = 0; 109 int lastw = 0;
110 110
111 while ( i < int(notes.length()) ) { 111 while ( i < int(notes.length()) ) {
112 doBreak = FALSE; 112 doBreak = FALSE;
113 if ( notes[i] != '\n' ) 113 if ( notes[i] != '\n' )
114 linew += fm.width( notes[i] ); 114 linew += fm.width( notes[i] );
115 115
116 if ( lastSpace >= a && notes[i] != '\n' ) 116 if ( lastSpace >= a && notes[i] != '\n' )
117 if (linew >= parentWidget()->width()) { 117 if (linew >= parentWidget()->width()) {
118 doBreak = TRUE; 118 doBreak = TRUE;
119 if ( lastSpace > a ) { 119 if ( lastSpace > a ) {
120 i = lastSpace; 120 i = lastSpace;
121 linew = lastw; 121 linew = lastw;
122 } 122 }
123 else 123 else
124 i = QMAX( a, i-1 ); 124 i = QMAX( a, i-1 );
125 } 125 }
126 126
127 if ( notes[i] == '\n' || doBreak ) { 127 if ( notes[i] == '\n' || doBreak ) {
128 s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n"; 128 s += notes.mid( a, i - a + (doBreak?1:0) ) +"\n";
129 129
130 a = i + 1; 130 a = i + 1;
131 lastSpace = a; 131 lastSpace = a;
132 linew = 0; 132 linew = 0;
133 } 133 }
134 134
135 if ( notes[i].isSpace() ) { 135 if ( notes[i].isSpace() ) {
136 lastSpace = i; 136 lastSpace = i;
137 lastw = linew; 137 lastw = linew;
138 } 138 }
139 139
140 if ( lastSpace <= a ) { 140 if ( lastSpace <= a ) {
141 lastw = linew; 141 lastw = linew;
142 } 142 }
143 143
144 ++i; 144 ++i;
145 } 145 }
146 } 146 }
147 147
148 tip( r, s ); 148 tip( r, s );
149 } 149 }
150 else 150 else
151 hide(); 151 hide();
152 ishidden = !ishidden; 152 ishidden = !ishidden;
153 153
154} 154}
155 155
156/////////////////////////// 156///////////////////////////
157// ContactListViewItem Methods 157// ContactListViewItem Methods
158 158
159ContactListViewItem::ContactListViewItem(const KABC::Addressee &a, 159ContactListViewItem::ContactListViewItem(const KABC::Addressee &a,
160 ContactListView *parent, 160 ContactListView *parent,
161 KABC::AddressBook *doc, 161 KABC::AddressBook *doc,
162 const KABC::Field::List &fields ) 162 const KABC::Field::List &fields )
163 : KListViewItem(parent), mAddressee(a), mFields( fields ), 163 : KListViewItem(parent), mAddressee(a), mFields( fields ),
164 parentListView( parent ), mDocument(doc) 164 parentListView( parent ), mDocument(doc)
165{ 165{
166 refresh(); 166 refresh();
167} 167}
168 168
169QString ContactListViewItem::key(int column, bool ascending) const 169QString ContactListViewItem::key(int column, bool ascending) const
170{ 170{
171 return QListViewItem::key(column, ascending).lower(); 171 int lan = KGlobal::locale()->language();
172 //qDebug("language %d ", lan);
173 if ( lan == 1 ) { //GERMAN
174 QString ret = QListViewItem::key(column, ascending).utf8();
175 int start = -1;
176 while ( (start = ret.find( 'ä', start+1)) > 0 ) {
177 ret.at(start-1) = 'a';
178 }
179 start = -1;
180 while ( (start = ret.find( 'ö', start+1)) > 0 ) {
181 ret.at(start-1) = 'o';
182 }
183 start = -1;
184 while ( (start = ret.find( 'ü', start+1)) > 0 ) {
185 ret.at(start-1) = 'o';
186 }
187 start = -1;
188 while ( (start = ret.find( 'ß', start+1)) > 0 ) {
189 ret.at(start-1) = 's';
190 }
191 //qDebug("conv string %s ", ret.latin1());
192
193 return ret;
194
195 }
196 else
197 return QListViewItem::key(column, ascending).lower();
172} 198}
173 199
174void ContactListViewItem::paintCell(QPainter * p, 200void ContactListViewItem::paintCell(QPainter * p,
175 const QColorGroup & cg, 201 const QColorGroup & cg,
176 int column, 202 int column,
177 int width, 203 int width,
178 int align) 204 int align)
179{ 205{
180 KListViewItem::paintCell(p, cg, column, width, align); 206 KListViewItem::paintCell(p, cg, column, width, align);
181 207
182 if ( !p ) 208 if ( !p )
183 return; 209 return;
184 210
185 if (parentListView->singleLine()) { 211 if (parentListView->singleLine()) {
186 p->setPen( parentListView->alternateColor() ); 212 p->setPen( parentListView->alternateColor() );
187 p->drawLine( 0, height() - 1, width, height() - 1 ); 213 p->drawLine( 0, height() - 1, width, height() - 1 );
188 } 214 }
189} 215}
190 216
191 217
192ContactListView *ContactListViewItem::parent() 218ContactListView *ContactListViewItem::parent()
193{ 219{
194 return parentListView; 220 return parentListView;
195} 221}
196 222
197 223
198void ContactListViewItem::refresh() 224void ContactListViewItem::refresh()
199{ 225{
200 // Update our addressee, since it may have changed else were 226 // Update our addressee, since it may have changed else were
201 mAddressee = mDocument->findByUid(mAddressee.uid()); 227 mAddressee = mDocument->findByUid(mAddressee.uid());
202 if (mAddressee.isEmpty()) 228 if (mAddressee.isEmpty())
203 return; 229 return;
204 230
205 int i = 0; 231 int i = 0;
206 KABC::Field::List::ConstIterator it; 232 KABC::Field::List::ConstIterator it;
207 for( it = mFields.begin(); it != mFields.end(); ++it ) { 233 for( it = mFields.begin(); it != mFields.end(); ++it ) {
208 setText( i++, (*it)->value( mAddressee ) ); 234 setText( i++, (*it)->value( mAddressee ) );
209 } 235 }
210} 236}
211 237
212/////////////////////////////// 238///////////////////////////////
213// ContactListView 239// ContactListView
214 240
215ContactListView::ContactListView(KAddressBookTableView *view, 241ContactListView::ContactListView(KAddressBookTableView *view,
216 KABC::AddressBook* /* doc */, 242 KABC::AddressBook* /* doc */,
217 QWidget *parent, 243 QWidget *parent,
218 const char *name ) 244 const char *name )
219 : KListView( parent, name ), 245 : KListView( parent, name ),
220 pabWidget( view ), 246 pabWidget( view ),
221 oldColumn( 0 ) 247 oldColumn( 0 )
222{ 248{
223 mABackground = true; 249 mABackground = true;
224 mSingleLine = false; 250 mSingleLine = false;
225 mToolTips = true; 251 mToolTips = true;
226#ifndef KAB_EMBEDDED 252#ifndef KAB_EMBEDDED
227 mAlternateColor = KGlobalSettings::alternateBackgroundColor(); 253 mAlternateColor = KGlobalSettings::alternateBackgroundColor();
228#else //KAB_EMBEDDED 254#else //KAB_EMBEDDED
229 mAlternateColor = QColor(240, 240, 240); 255 mAlternateColor = QColor(240, 240, 240);
230#endif //KAB_EMBEDDED 256#endif //KAB_EMBEDDED
231 257
232 setAlternateBackgroundEnabled(mABackground); 258 setAlternateBackgroundEnabled(mABackground);
233 setAcceptDrops( true ); 259 setAcceptDrops( true );
234 viewport()->setAcceptDrops( true ); 260 viewport()->setAcceptDrops( true );
235 setAllColumnsShowFocus( true ); 261 setAllColumnsShowFocus( true );
236 setShowSortIndicator(true); 262 setShowSortIndicator(true);
237 263
238 setSelectionModeExt( KListView::Extended ); 264 setSelectionModeExt( KListView::Extended );
239 setDropVisualizer(false); 265 setDropVisualizer(false);
240 // setFrameStyle(QFrame::NoFrame); 266 // setFrameStyle(QFrame::NoFrame);
241 //setLineWidth ( 0 ); 267 //setLineWidth ( 0 );
242 //setMidLineWidth ( 0 ); 268 //setMidLineWidth ( 0 );
243 //setMargin ( 0 ); 269 //setMargin ( 0 );
244#ifndef KAB_EMBEDDED 270#ifndef KAB_EMBEDDED
245 connect(this, SIGNAL(dropped(QDropEvent*)), 271 connect(this, SIGNAL(dropped(QDropEvent*)),
246 this, SLOT(itemDropped(QDropEvent*))); 272 this, SLOT(itemDropped(QDropEvent*)));
247#endif //KAB_EMBEDDED 273#endif //KAB_EMBEDDED
248 274
249 275
250 new DynamicTip( this ); 276 new DynamicTip( this );
251} 277}
252 278
253void ContactListView::setAlternateColor(const QColor &m_AlternateColor) 279void ContactListView::setAlternateColor(const QColor &m_AlternateColor)
254{ 280{
255 mAlternateColor = m_AlternateColor; 281 mAlternateColor = m_AlternateColor;
256} 282}
257 283
258void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect ) 284void ContactListView::paintEmptyArea( QPainter * p, const QRect & rect )
259{ 285{
260 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base); 286 QBrush b = palette().brush(QPalette::Active, QColorGroup::Base);
261 287
262 // Get the brush, which will have the background pixmap if there is one. 288 // Get the brush, which will have the background pixmap if there is one.
263 if (b.pixmap()) 289 if (b.pixmap())
264 { 290 {
265 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(), 291 p->drawTiledPixmap( rect.left(), rect.top(), rect.width(), rect.height(),
266 *(b.pixmap()), 292 *(b.pixmap()),
267 rect.left() + contentsX(), 293 rect.left() + contentsX(),
268 rect.top() + contentsY() ); 294 rect.top() + contentsY() );
269 } 295 }
270 296
271 else 297 else
272 { 298 {
273 // Do a normal paint 299 // Do a normal paint
274 KListView::paintEmptyArea(p, rect); 300 KListView::paintEmptyArea(p, rect);
275 } 301 }
276} 302}
277 303
278void ContactListView::contentsMousePressEvent(QMouseEvent* e) 304void ContactListView::contentsMousePressEvent(QMouseEvent* e)
279{ 305{
280 presspos = e->pos(); 306 presspos = e->pos();
281 KListView::contentsMousePressEvent(e); 307 KListView::contentsMousePressEvent(e);
282} 308}
283 309
284 310
285// To initiate a drag operation 311// To initiate a drag operation
286void ContactListView::contentsMouseMoveEvent( QMouseEvent *e ) 312void ContactListView::contentsMouseMoveEvent( QMouseEvent *e )
287{ 313{
288 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) { 314 if ((e->state() & LeftButton) && (e->pos() - presspos).manhattanLength() > 4 ) {
289 emit startAddresseeDrag(); 315 emit startAddresseeDrag();
290 } 316 }
291 else 317 else
292 KListView::contentsMouseMoveEvent( e ); 318 KListView::contentsMouseMoveEvent( e );
293} 319}
294 320
295bool ContactListView::acceptDrag(QDropEvent *e) const 321bool ContactListView::acceptDrag(QDropEvent *e) const
296{ 322{
297#ifndef KAB_EMBEDDED 323#ifndef KAB_EMBEDDED
298 return QTextDrag::canDecode(e); 324 return QTextDrag::canDecode(e);
299#else //KAB_EMBEDDED 325#else //KAB_EMBEDDED
300qDebug("ContactListView::acceptDrag has to be fixed"); 326qDebug("ContactListView::acceptDrag has to be fixed");
301 return false; 327 return false;
302#endif //KAB_EMBEDDED 328#endif //KAB_EMBEDDED
303} 329}
304 330
305void ContactListView::itemDropped(QDropEvent *e) 331void ContactListView::itemDropped(QDropEvent *e)
306{ 332{
307 contentsDropEvent(e); 333 contentsDropEvent(e);
308} 334}
309 335
310void ContactListView::contentsDropEvent( QDropEvent *e ) 336void ContactListView::contentsDropEvent( QDropEvent *e )
311{ 337{
312 emit addresseeDropped(e); 338 emit addresseeDropped(e);
313} 339}
314 340
315void ContactListView::setAlternateBackgroundEnabled(bool enabled) 341void ContactListView::setAlternateBackgroundEnabled(bool enabled)
316{ 342{
317 mABackground = enabled; 343 mABackground = enabled;
318 344
319 if (mABackground) 345 if (mABackground)
320 { 346 {
321 setAlternateBackground(mAlternateColor); 347 setAlternateBackground(mAlternateColor);
322 } 348 }
323 else 349 else
324 { 350 {
325 setAlternateBackground(QColor()); 351 setAlternateBackground(QColor());
326 } 352 }
327} 353}
328 354
329void ContactListView::setBackgroundPixmap(const QString &filename) 355void ContactListView::setBackgroundPixmap(const QString &filename)
330{ 356{
331 if (filename.isEmpty()) 357 if (filename.isEmpty())
332 { 358 {
333 unsetPalette(); 359 unsetPalette();
334 } 360 }
335 else 361 else
336 { 362 {
337 qDebug("ContactListView::setBackgroundPixmap has to be verified"); 363 qDebug("ContactListView::setBackgroundPixmap has to be verified");
338//US setPaletteBackgroundPixmap(QPixmap(filename)); 364//US setPaletteBackgroundPixmap(QPixmap(filename));
339 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename)); 365 KListView::setBackgroundPixmap((const QPixmap&)QPixmap(filename));
340 } 366 }
341 367
342} 368}
343#ifndef KAB_EMBEDDED 369#ifndef KAB_EMBEDDED
344#include "contactlistview.moc" 370#include "contactlistview.moc"
345#endif //KAB_EMBEDDED 371#endif //KAB_EMBEDDED
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index 673d845..3674f28 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -1,990 +1,994 @@
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 9
10QDict<QString> *mLocaleDict = 0; 10QDict<QString> *mLocaleDict = 0;
11void setLocaleDict( QDict<QString> * dict ) 11void setLocaleDict( QDict<QString> * dict )
12{ 12{
13 mLocaleDict = dict; 13 mLocaleDict = dict;
14 14
15} 15}
16QString i18n(const char *text) 16QString i18n(const char *text)
17{ 17{
18 if ( ! mLocaleDict ) 18 if ( ! mLocaleDict )
19 return QString( text ); 19 return QString( text );
20 else { 20 else {
21 QString* ret = mLocaleDict->find(QString(text)) ; 21 QString* ret = mLocaleDict->find(QString(text)) ;
22 if ( ret == 0 ) { 22 if ( ret == 0 ) {
23 return QString( text ); 23 return QString( text );
24 } 24 }
25 else { 25 else {
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 mIntTimeFormat = Default;
91 mLanguage = 0; 91 mLanguage = 0;
92 mDateFormat = "%a %Y %b %d"; 92 mDateFormat = "%a %Y %b %d";
93 mDateFormatShort = "%Y-%m-%d"; 93 mDateFormatShort = "%Y-%m-%d";
94 mTimeZoneList << i18n ("-11:00 US/Samoa") 94 mTimeZoneList << i18n ("-11:00 US/Samoa")
95 << i18n ("-10:00 US/Hawaii") 95 << i18n ("-10:00 US/Hawaii")
96 << i18n ("-09:00 US/Alaska") 96 << i18n ("-09:00 US/Alaska")
97 << i18n ("-08:00 US/Pacific") 97 << i18n ("-08:00 US/Pacific")
98 << i18n ("-07:00 US/Mountain") 98 << i18n ("-07:00 US/Mountain")
99 << i18n ("-06:00 US/Central") 99 << i18n ("-06:00 US/Central")
100 << i18n ("-05:00 US/Eastern") 100 << i18n ("-05:00 US/Eastern")
101 << i18n ("-04:00 Brazil/West") 101 << i18n ("-04:00 Brazil/West")
102 << i18n ("-03:00 Brazil/East") 102 << i18n ("-03:00 Brazil/East")
103 << i18n ("-02:00 Brazil/DeNoronha") 103 << i18n ("-02:00 Brazil/DeNoronha")
104 << i18n ("-01:00 Atlantic/Azores") 104 << i18n ("-01:00 Atlantic/Azores")
105 << i18n (" 00:00 Europe/London(UTC)") 105 << i18n (" 00:00 Europe/London(UTC)")
106 << i18n ("+01:00 Europe/Oslo(CET)") 106 << i18n ("+01:00 Europe/Oslo(CET)")
107 << i18n ("+02:00 Europe/Helsinki") 107 << i18n ("+02:00 Europe/Helsinki")
108 << i18n ("+03:00 Europe/Moscow") 108 << i18n ("+03:00 Europe/Moscow")
109 << i18n ("+04:00 Indian/Mauritius") 109 << i18n ("+04:00 Indian/Mauritius")
110 << i18n ("+05:00 Indian/Maldives") 110 << i18n ("+05:00 Indian/Maldives")
111 << i18n ("+06:00 Indian/Chagos") 111 << i18n ("+06:00 Indian/Chagos")
112 << i18n ("+07:00 Asia/Bangkok") 112 << i18n ("+07:00 Asia/Bangkok")
113 << i18n ("+08:00 Asia/Hongkong") 113 << i18n ("+08:00 Asia/Hongkong")
114 << i18n ("+09:00 Asia/Tokyo") 114 << i18n ("+09:00 Asia/Tokyo")
115 << i18n ("+10:00 Asia/Vladivostok") 115 << i18n ("+10:00 Asia/Vladivostok")
116 << i18n ("+11:00 Asia/Magadan") 116 << i18n ("+11:00 Asia/Magadan")
117 << i18n ("+12:00 Asia/Kamchatka") 117 << i18n ("+12:00 Asia/Kamchatka")
118 // << i18n (" xx:xx User defined offset") 118 // << i18n (" xx:xx User defined offset")
119 << i18n (" Local Time"); 119 << i18n (" Local Time");
120 mSouthDaylight = false; 120 mSouthDaylight = false;
121 mTimeZoneOffset = 0; 121 mTimeZoneOffset = 0;
122 daylightEnabled = false; 122 daylightEnabled = false;
123} 123}
124 124
125void KLocale::setDateFormat( QString s ) 125void KLocale::setDateFormat( QString s )
126{ 126{
127 mDateFormat = s; 127 mDateFormat = s;
128} 128}
129 129
130void KLocale::setDateFormatShort( QString s ) 130void KLocale::setDateFormatShort( QString s )
131{ 131{
132 mDateFormatShort = s; 132 mDateFormatShort = s;
133} 133}
134 134
135void KLocale::setHore24Format ( bool b ) 135void KLocale::setHore24Format ( bool b )
136{ 136{
137 mHourF24Format = b; 137 mHourF24Format = b;
138} 138}
139void KLocale::setWeekStartMonday( bool b ) 139void KLocale::setWeekStartMonday( bool b )
140{ 140{
141 mWeekStartsMonday = b; 141 mWeekStartsMonday = b;
142} 142}
143 143
144KLocale::IntDateFormat KLocale::getIntDateFormat( ) 144KLocale::IntDateFormat KLocale::getIntDateFormat( )
145{ 145{
146 return mIntDateFormat; 146 return mIntDateFormat;
147 147
148} 148}
149void KLocale::setIntDateFormat( KLocale::IntDateFormat i ) 149void KLocale::setIntDateFormat( KLocale::IntDateFormat i )
150{ 150{
151 mIntDateFormat = i; 151 mIntDateFormat = i;
152} 152}
153KLocale::IntDateFormat KLocale::getIntTimeFormat( ) 153KLocale::IntDateFormat KLocale::getIntTimeFormat( )
154{ 154{
155 return mIntTimeFormat; 155 return mIntTimeFormat;
156 156
157} 157}
158void KLocale::setIntTimeFormat( KLocale::IntDateFormat i ) 158void KLocale::setIntTimeFormat( KLocale::IntDateFormat i )
159{ 159{
160 mIntTimeFormat = i; 160 mIntTimeFormat = i;
161} 161}
162 162
163void KLocale::setLanguage( int i ) 163void KLocale::setLanguage( int i )
164{ 164{
165 mLanguage = i; 165 mLanguage = i;
166} 166}
167int KLocale::language( )
168{
169 return mLanguage;
170}
167QString KLocale::translate( const char *index ) const 171QString KLocale::translate( const char *index ) const
168{ 172{
169 return i18n( index ); 173 return i18n( index );
170} 174}
171 175
172QString KLocale::translate( const char *, const char *fallback) const 176QString KLocale::translate( const char *, const char *fallback) const
173{ 177{
174 return i18n( fallback ); 178 return i18n( fallback );
175} 179}
176 180
177QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const 181QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const
178{ 182{
179 const QString rst = timeFormat(intIntDateFormat); 183 const QString rst = timeFormat(intIntDateFormat);
180 184
181 // only "pm/am" here can grow, the rest shrinks, but 185 // only "pm/am" here can grow, the rest shrinks, but
182 // I'm rather safe than sorry 186 // I'm rather safe than sorry
183 QChar *buffer = new QChar[rst.length() * 3 / 2 + 30]; 187 QChar *buffer = new QChar[rst.length() * 3 / 2 + 30];
184 188
185 uint index = 0; 189 uint index = 0;
186 bool escape = false; 190 bool escape = false;
187 int number = 0; 191 int number = 0;
188 192
189 for ( uint format_index = 0; format_index < rst.length(); format_index++ ) 193 for ( uint format_index = 0; format_index < rst.length(); format_index++ )
190 { 194 {
191 if ( !escape ) 195 if ( !escape )
192 { 196 {
193 if ( rst.at( format_index ).unicode() == '%' ) 197 if ( rst.at( format_index ).unicode() == '%' )
194 escape = true; 198 escape = true;
195 else 199 else
196 buffer[index++] = rst.at( format_index ); 200 buffer[index++] = rst.at( format_index );
197 } 201 }
198 else 202 else
199 { 203 {
200 switch ( rst.at( format_index ).unicode() ) 204 switch ( rst.at( format_index ).unicode() )
201 { 205 {
202 case '%': 206 case '%':
203 buffer[index++] = '%'; 207 buffer[index++] = '%';
204 break; 208 break;
205 case 'H': 209 case 'H':
206 put_it_in( buffer, index, pTime.hour() ); 210 put_it_in( buffer, index, pTime.hour() );
207 break; 211 break;
208 case 'I': 212 case 'I':
209 put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 ); 213 put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 );
210 break; 214 break;
211 case 'M': 215 case 'M':
212 put_it_in( buffer, index, pTime.minute() ); 216 put_it_in( buffer, index, pTime.minute() );
213 break; 217 break;
214 case 'S': 218 case 'S':
215 if (includeSecs) 219 if (includeSecs)
216 put_it_in( buffer, index, pTime.second() ); 220 put_it_in( buffer, index, pTime.second() );
217 else 221 else
218 { 222 {
219 // we remove the seperator sign before the seconds and 223 // we remove the seperator sign before the seconds and
220 // assume that works everywhere 224 // assume that works everywhere
221 --index; 225 --index;
222 break; 226 break;
223 } 227 }
224 break; 228 break;
225 case 'k': 229 case 'k':
226 number = pTime.hour(); 230 number = pTime.hour();
227 case 'l': 231 case 'l':
228 // to share the code 232 // to share the code
229 if ( rst.at( format_index ).unicode() == 'l' ) 233 if ( rst.at( format_index ).unicode() == 'l' )
230 number = (pTime.hour() + 11) % 12 + 1; 234 number = (pTime.hour() + 11) % 12 + 1;
231 if ( number / 10 ) 235 if ( number / 10 )
232 buffer[index++] = number / 10 + '0'; 236 buffer[index++] = number / 10 + '0';
233 buffer[index++] = number % 10 + '0'; 237 buffer[index++] = number % 10 + '0';
234 break; 238 break;
235 case 'p': 239 case 'p':
236 { 240 {
237 QString s; 241 QString s;
238 if ( pTime.hour() >= 12 ) 242 if ( pTime.hour() >= 12 )
239 put_it_in( buffer, index, i18n("pm") ); 243 put_it_in( buffer, index, i18n("pm") );
240 else 244 else
241 put_it_in( buffer, index, i18n("am") ); 245 put_it_in( buffer, index, i18n("am") );
242 break; 246 break;
243 } 247 }
244 default: 248 default:
245 buffer[index++] = rst.at( format_index ); 249 buffer[index++] = rst.at( format_index );
246 break; 250 break;
247 } 251 }
248 escape = false; 252 escape = false;
249 } 253 }
250 } 254 }
251 QString ret( buffer, index ); 255 QString ret( buffer, index );
252 delete [] buffer; 256 delete [] buffer;
253 return ret; 257 return ret;
254} 258}
255 259
256QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const 260QString KLocale::formatDate(const QDate &pDate, bool shortFormat, IntDateFormat intIntDateFormat) const
257{ 261{
258 const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat); 262 const QString rst = shortFormat?dateFormatShort(intIntDateFormat):dateFormat(intIntDateFormat);
259 263
260 // I'm rather safe than sorry 264 // I'm rather safe than sorry
261 QChar *buffer = new QChar[rst.length() * 3 / 2 + 50]; 265 QChar *buffer = new QChar[rst.length() * 3 / 2 + 50];
262 266
263 unsigned int index = 0; 267 unsigned int index = 0;
264 bool escape = false; 268 bool escape = false;
265 int number = 0; 269 int number = 0;
266 270
267 for ( uint format_index = 0; format_index < rst.length(); ++format_index ) 271 for ( uint format_index = 0; format_index < rst.length(); ++format_index )
268 { 272 {
269 if ( !escape ) 273 if ( !escape )
270 { 274 {
271 if ( rst.at( format_index ).unicode() == '%' ) 275 if ( rst.at( format_index ).unicode() == '%' )
272 escape = true; 276 escape = true;
273 else 277 else
274 buffer[index++] = rst.at( format_index ); 278 buffer[index++] = rst.at( format_index );
275 } 279 }
276 else 280 else
277 { 281 {
278 switch ( rst.at( format_index ).unicode() ) 282 switch ( rst.at( format_index ).unicode() )
279 { 283 {
280 case '%': 284 case '%':
281 buffer[index++] = '%'; 285 buffer[index++] = '%';
282 break; 286 break;
283 case 'Y': 287 case 'Y':
284 put_it_in( buffer, index, pDate.year() / 100 ); 288 put_it_in( buffer, index, pDate.year() / 100 );
285 case 'y': 289 case 'y':
286 put_it_in( buffer, index, pDate.year() % 100 ); 290 put_it_in( buffer, index, pDate.year() % 100 );
287 break; 291 break;
288 case 'n': 292 case 'n':
289 number = pDate.month(); 293 number = pDate.month();
290 case 'e': 294 case 'e':
291 // to share the code 295 // to share the code
292 if ( rst.at( format_index ).unicode() == 'e' ) 296 if ( rst.at( format_index ).unicode() == 'e' )
293 number = pDate.day(); 297 number = pDate.day();
294 if ( number / 10 ) 298 if ( number / 10 )
295 buffer[index++] = number / 10 + '0'; 299 buffer[index++] = number / 10 + '0';
296 buffer[index++] = number % 10 + '0'; 300 buffer[index++] = number % 10 + '0';
297 break; 301 break;
298 case 'm': 302 case 'm':
299 put_it_in( buffer, index, pDate.month() ); 303 put_it_in( buffer, index, pDate.month() );
300 break; 304 break;
301 case 'b': 305 case 'b':
302 put_it_in( buffer, index, monthName(pDate.month(), true) ); 306 put_it_in( buffer, index, monthName(pDate.month(), true) );
303 break; 307 break;
304 case 'B': 308 case 'B':
305 put_it_in( buffer, index, monthName(pDate.month(), false) ); 309 put_it_in( buffer, index, monthName(pDate.month(), false) );
306 break; 310 break;
307 case 'd': 311 case 'd':
308 put_it_in( buffer, index, pDate.day() ); 312 put_it_in( buffer, index, pDate.day() );
309 break; 313 break;
310 case 'a': 314 case 'a':
311 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) ); 315 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), true) );
312 break; 316 break;
313 case 'A': 317 case 'A':
314 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) ); 318 put_it_in( buffer, index, weekDayName(pDate.dayOfWeek(), false) );
315 break; 319 break;
316 default: 320 default:
317 buffer[index++] = rst.at( format_index ); 321 buffer[index++] = rst.at( format_index );
318 break; 322 break;
319 } 323 }
320 escape = false; 324 escape = false;
321 } 325 }
322 } 326 }
323 QString ret( buffer, index ); 327 QString ret( buffer, index );
324 delete [] buffer; 328 delete [] buffer;
325 return ret; 329 return ret;
326} 330}
327 331
328QString KLocale::formatDateTime(const QDateTime &pDateTime, 332QString KLocale::formatDateTime(const QDateTime &pDateTime,
329 bool shortFormat, 333 bool shortFormat,
330 bool includeSeconds, 334 bool includeSeconds,
331 IntDateFormat intIntDateFormat) const 335 IntDateFormat intIntDateFormat) const
332{ 336{
333 QString format("%1 %2"); 337 QString format("%1 %2");
334 338
335 if ( intIntDateFormat == Default ) 339 if ( intIntDateFormat == Default )
336 format = "%1 %2"; 340 format = "%1 %2";
337 else if ( intIntDateFormat == Format1 ) 341 else if ( intIntDateFormat == Format1 )
338 format = "%1 %2"; 342 format = "%1 %2";
339 else if ( intIntDateFormat == ISODate ) 343 else if ( intIntDateFormat == ISODate )
340 format = "%1T%2"; 344 format = "%1T%2";
341 345
342 QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat )) 346 QString res = format.arg(formatDate( pDateTime.date(), shortFormat, intIntDateFormat ))
343 .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat )); 347 .arg(formatTime( pDateTime.time(), includeSeconds , intIntDateFormat ));
344 348
345 //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() ); 349 //qDebug("KLocale::formatDateTime transformed %s, into %s", pDateTime.toString().latin1(), res.latin1() );
346 350
347 return res; 351 return res;
348} 352}
349 353
350QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const 354QString KLocale::formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat) const
351{ 355{
352 return formatDateTime(pDateTime, true, true, intIntDateFormat); 356 return formatDateTime(pDateTime, true, true, intIntDateFormat);
353} 357}
354 358
355QDate KLocale::readDate(const QString &intstr, bool* ok) const 359QDate KLocale::readDate(const QString &intstr, bool* ok) const
356{ 360{
357 QDate date; 361 QDate date;
358 date = readDate(intstr, true, ok); 362 date = readDate(intstr, true, ok);
359 if (date.isValid()) return date; 363 if (date.isValid()) return date;
360 return readDate(intstr, false, ok); 364 return readDate(intstr, false, ok);
361} 365}
362 366
363QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const 367QDate KLocale::readDate(const QString &intstr, bool shortFormat, bool* ok) const
364{ 368{
365 QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace(); 369 QString fmt = (shortFormat ? dateFormatShort() : dateFormat()).simplifyWhiteSpace();
366 return readDate( intstr, fmt, ok ); 370 return readDate( intstr, fmt, ok );
367} 371}
368 372
369QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const 373QDate KLocale::readDate(const QString &intstr, const QString &fmt, bool* ok) const
370{ 374{
371 //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl; 375 //kdDebug(173) << "KLocale::readDate intstr=" << intstr << " fmt=" << fmt << endl;
372 QString str = intstr.simplifyWhiteSpace().lower(); 376 QString str = intstr.simplifyWhiteSpace().lower();
373 int day = -1, month = -1; 377 int day = -1, month = -1;
374 // allow the year to be omitted if not in the format 378 // allow the year to be omitted if not in the format
375 int year = QDate::currentDate().year(); 379 int year = QDate::currentDate().year();
376 uint strpos = 0; 380 uint strpos = 0;
377 uint fmtpos = 0; 381 uint fmtpos = 0;
378 382
379 while (fmt.length() > fmtpos || str.length() > strpos) 383 while (fmt.length() > fmtpos || str.length() > strpos)
380 { 384 {
381 if ( !(fmt.length() > fmtpos && str.length() > strpos) ) 385 if ( !(fmt.length() > fmtpos && str.length() > strpos) )
382 goto error; 386 goto error;
383 387
384 QChar c = fmt.at(fmtpos++); 388 QChar c = fmt.at(fmtpos++);
385 389
386 if (c != '%') { 390 if (c != '%') {
387 if (c.isSpace()) 391 if (c.isSpace())
388 strpos++; 392 strpos++;
389 else if (c != str.at(strpos++)) 393 else if (c != str.at(strpos++))
390 goto error; 394 goto error;
391 continue; 395 continue;
392 } 396 }
393 397
394 // remove space at the begining 398 // remove space at the begining
395 if (str.length() > strpos && str.at(strpos).isSpace()) 399 if (str.length() > strpos && str.at(strpos).isSpace())
396 strpos++; 400 strpos++;
397 401
398 c = fmt.at(fmtpos++); 402 c = fmt.at(fmtpos++);
399 switch (c) 403 switch (c)
400 { 404 {
401 case 'a': 405 case 'a':
402 case 'A': 406 case 'A':
403 // this will just be ignored 407 // this will just be ignored
404 { // Cristian Tache: porting to Win: Block added because of "j" redefinition 408 { // Cristian Tache: porting to Win: Block added because of "j" redefinition
405 for (int j = 1; j < 8; j++) { 409 for (int j = 1; j < 8; j++) {
406 QString s = weekDayName(j, c == 'a').lower(); 410 QString s = weekDayName(j, c == 'a').lower();
407 int len = s.length(); 411 int len = s.length();
408 if (str.mid(strpos, len) == s) 412 if (str.mid(strpos, len) == s)
409 strpos += len; 413 strpos += len;
410 } 414 }
411 break; 415 break;
412 } 416 }
413 case 'b': 417 case 'b':
414 case 'B': 418 case 'B':
415 { // Cristian Tache: porting to Win: Block added because of "j" redefinition 419 { // Cristian Tache: porting to Win: Block added because of "j" redefinition
416 for (int j = 1; j < 13; j++) { 420 for (int j = 1; j < 13; j++) {
417 QString s = monthName(j, c == 'b').lower(); 421 QString s = monthName(j, c == 'b').lower();
418 int len = s.length(); 422 int len = s.length();
419 if (str.mid(strpos, len) == s) { 423 if (str.mid(strpos, len) == s) {
420 month = j; 424 month = j;
421 strpos += len; 425 strpos += len;
422 } 426 }
423 } 427 }
424 break; 428 break;
425 } 429 }
426 case 'd': 430 case 'd':
427 case 'e': 431 case 'e':
428 day = readInt(str, strpos); 432 day = readInt(str, strpos);
429 if (day < 1 || day > 31) 433 if (day < 1 || day > 31)
430 goto error; 434 goto error;
431 435
432 break; 436 break;
433 437
434 case 'n': 438 case 'n':
435 case 'm': 439 case 'm':
436 month = readInt(str, strpos); 440 month = readInt(str, strpos);
437 if (month < 1 || month > 12) 441 if (month < 1 || month > 12)
438 goto error; 442 goto error;
439 443
440 break; 444 break;
441 445
442 case 'Y': 446 case 'Y':
443 case 'y': 447 case 'y':
444 year = readInt(str, strpos); 448 year = readInt(str, strpos);
445 if (year < 0) 449 if (year < 0)
446 goto error; 450 goto error;
447 // Qt treats a year in the range 0-100 as 1900-1999. 451 // Qt treats a year in the range 0-100 as 1900-1999.
448 // It is nicer for the user if we treat 0-68 as 2000-2068 452 // It is nicer for the user if we treat 0-68 as 2000-2068
449 if (year < 69) 453 if (year < 69)
450 year += 2000; 454 year += 2000;
451 else if (c == 'y') 455 else if (c == 'y')
452 year += 1900; 456 year += 1900;
453 457
454 break; 458 break;
455 } 459 }
456 } 460 }
457 //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl; 461 //kdDebug(173) << "KLocale::readDate day=" << day << " month=" << month << " year=" << year << endl;
458 if ( year != -1 && month != -1 && day != -1 ) 462 if ( year != -1 && month != -1 && day != -1 )
459 { 463 {
460 if (ok) *ok = true; 464 if (ok) *ok = true;
461 return QDate(year, month, day); 465 return QDate(year, month, day);
462 } 466 }
463 error: 467 error:
464 if (ok) *ok = false; 468 if (ok) *ok = false;
465 return QDate(); // invalid date 469 return QDate(); // invalid date
466} 470}
467 471
468QTime KLocale::readTime(const QString &intstr, bool *ok) const 472QTime KLocale::readTime(const QString &intstr, bool *ok) const
469{ 473{
470 QTime _time; 474 QTime _time;
471 _time = readTime(intstr, true, ok); 475 _time = readTime(intstr, true, ok);
472 if (_time.isValid()) return _time; 476 if (_time.isValid()) return _time;
473 return readTime(intstr, false, ok); 477 return readTime(intstr, false, ok);
474} 478}
475 479
476QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const 480QTime KLocale::readTime(const QString &intstr, bool seconds, bool *ok) const
477{ 481{
478 QString str = intstr.simplifyWhiteSpace().lower(); 482 QString str = intstr.simplifyWhiteSpace().lower();
479 QString Format = timeFormat().simplifyWhiteSpace(); 483 QString Format = timeFormat().simplifyWhiteSpace();
480 if (!seconds) 484 if (!seconds)
481 Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null); 485 Format.replace(QRegExp(QString::fromLatin1(".%S")), QString::null);
482 486
483 int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds 487 int hour = -1, minute = -1, second = seconds ? -1 : 0; // don't require seconds
484 488
485 bool g_12h = false; 489 bool g_12h = false;
486 bool pm = false; 490 bool pm = false;
487 uint strpos = 0; 491 uint strpos = 0;
488 uint Formatpos = 0; 492 uint Formatpos = 0;
489 493
490 while (Format.length() > Formatpos || str.length() > strpos) 494 while (Format.length() > Formatpos || str.length() > strpos)
491 { 495 {
492 if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error; 496 if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error;
493 497
494 QChar c = Format.at(Formatpos++); 498 QChar c = Format.at(Formatpos++);
495 499
496 if (c != '%') 500 if (c != '%')
497 { 501 {
498 if (c.isSpace()) 502 if (c.isSpace())
499 strpos++; 503 strpos++;
500 else if (c != str.at(strpos++)) 504 else if (c != str.at(strpos++))
501 goto error; 505 goto error;
502 continue; 506 continue;
503 } 507 }
504 508
505 // remove space at the begining 509 // remove space at the begining
506 if (str.length() > strpos && str.at(strpos).isSpace()) 510 if (str.length() > strpos && str.at(strpos).isSpace())
507 strpos++; 511 strpos++;
508 512
509 c = Format.at(Formatpos++); 513 c = Format.at(Formatpos++);
510 switch (c) 514 switch (c)
511 { 515 {
512 case 'p': 516 case 'p':
513 { 517 {
514 QString s; 518 QString s;
515 s = i18n("pm").lower(); 519 s = i18n("pm").lower();
516 int len = s.length(); 520 int len = s.length();
517 if (str.mid(strpos, len) == s) 521 if (str.mid(strpos, len) == s)
518 { 522 {
519 pm = true; 523 pm = true;
520 strpos += len; 524 strpos += len;
521 } 525 }
522 else 526 else
523 { 527 {
524 s = i18n("am").lower(); 528 s = i18n("am").lower();
525 len = s.length(); 529 len = s.length();
526 if (str.mid(strpos, len) == s) { 530 if (str.mid(strpos, len) == s) {
527 pm = false; 531 pm = false;
528 strpos += len; 532 strpos += len;
529 } 533 }
530 else 534 else
531 goto error; 535 goto error;
532 } 536 }
533 } 537 }
534 break; 538 break;
535 539
536 case 'k': 540 case 'k':
537 case 'H': 541 case 'H':
538 g_12h = false; 542 g_12h = false;
539 hour = readInt(str, strpos); 543 hour = readInt(str, strpos);
540 if (hour < 0 || hour > 23) 544 if (hour < 0 || hour > 23)
541 goto error; 545 goto error;
542 546
543 break; 547 break;
544 548
545 case 'l': 549 case 'l':
546 case 'I': 550 case 'I':
547 g_12h = true; 551 g_12h = true;
548 hour = readInt(str, strpos); 552 hour = readInt(str, strpos);
549 if (hour < 1 || hour > 12) 553 if (hour < 1 || hour > 12)
550 goto error; 554 goto error;
551 555
552 break; 556 break;
553 557
554 case 'M': 558 case 'M':
555 minute = readInt(str, strpos); 559 minute = readInt(str, strpos);
556 if (minute < 0 || minute > 59) 560 if (minute < 0 || minute > 59)
557 goto error; 561 goto error;
558 562
559 break; 563 break;
560 564
561 case 'S': 565 case 'S':
562 second = readInt(str, strpos); 566 second = readInt(str, strpos);
563 if (second < 0 || second > 59) 567 if (second < 0 || second > 59)
564 goto error; 568 goto error;
565 569
566 break; 570 break;
567 } 571 }
568 } 572 }
569 if (g_12h) 573 if (g_12h)
570 { 574 {
571 hour %= 12; 575 hour %= 12;
572 if (pm) hour += 12; 576 if (pm) hour += 12;
573 } 577 }
574 578
575 if (ok) *ok = true; 579 if (ok) *ok = true;
576 return QTime(hour, minute, second); 580 return QTime(hour, minute, second);
577 581
578 error: 582 error:
579 if (ok) *ok = false; 583 if (ok) *ok = false;
580 return QTime(-1, -1, -1); // return invalid date if it didn't work 584 return QTime(-1, -1, -1); // return invalid date if it didn't work
581 // This will be removed in the near future, since it gives a warning on stderr. 585 // This will be removed in the near future, since it gives a warning on stderr.
582 // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime. 586 // The presence of the bool* (since KDE-3.0) removes the need for an invalid QTime.
583} 587}
584 588
585QDateTime KLocale::readDateTime(const QString &intstr, 589QDateTime KLocale::readDateTime(const QString &intstr,
586 IntDateFormat intIntDateFormat, 590 IntDateFormat intIntDateFormat,
587 bool* ok) const 591 bool* ok) const
588{ 592{
589 bool ok1, ok2; 593 bool ok1, ok2;
590 594
591 // AT the moment we can not read any other format then ISODate 595 // AT the moment we can not read any other format then ISODate
592 if ( intIntDateFormat != ISODate ) 596 if ( intIntDateFormat != ISODate )
593 { 597 {
594 qDebug("KLocale::readDateTime, only ISODate is supported."); 598 qDebug("KLocale::readDateTime, only ISODate is supported.");
595 return QDateTime(); 599 return QDateTime();
596 } 600 }
597 601
598 int pos = intstr.find("T"); 602 int pos = intstr.find("T");
599 QString date = intstr.left(pos); 603 QString date = intstr.left(pos);
600 QString time = intstr.mid(pos+1); 604 QString time = intstr.mid(pos+1);
601 605
602 QString dformat = dateFormat(intIntDateFormat); 606 QString dformat = dateFormat(intIntDateFormat);
603 QString tformat = timeFormat(intIntDateFormat); 607 QString tformat = timeFormat(intIntDateFormat);
604 608
605 QDate m_date = readDate(date, dformat, &ok1); 609 QDate m_date = readDate(date, dformat, &ok1);
606 QTime m_time = readTime(time, tformat, &ok2); 610 QTime m_time = readTime(time, tformat, &ok2);
607 611
608 QDateTime m_dt; 612 QDateTime m_dt;
609 613
610 if (ok) 614 if (ok)
611 { 615 {
612 if ((ok1 == false) || (ok2 == false)) 616 if ((ok1 == false) || (ok2 == false))
613 *ok = false; 617 *ok = false;
614 else 618 else
615 *ok = true; 619 *ok = true;
616 } 620 }
617 621
618 //only set values if both operations returned true. 622 //only set values if both operations returned true.
619 if ((ok1 == true) && (ok2 == true)) 623 if ((ok1 == true) && (ok2 == true))
620 { 624 {
621 m_dt.setDate(m_date); 625 m_dt.setDate(m_date);
622 m_dt.setTime(m_time); 626 m_dt.setTime(m_time);
623 } 627 }
624 628
625 //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); 629 //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);
626 return m_dt; 630 return m_dt;
627} 631}
628 632
629QDate KLocale::readDate(const QString &intstr, 633QDate KLocale::readDate(const QString &intstr,
630 IntDateFormat intIntDateFormat, 634 IntDateFormat intIntDateFormat,
631 bool* ok) const 635 bool* ok) const
632{ 636{
633 bool ok1; 637 bool ok1;
634 638
635 QString dformat = dateFormat(intIntDateFormat); 639 QString dformat = dateFormat(intIntDateFormat);
636 640
637 QDate m_date = readDate(intstr, dformat, &ok1); 641 QDate m_date = readDate(intstr, dformat, &ok1);
638 642
639 if (ok) 643 if (ok)
640 *ok = ok1; 644 *ok = ok1;
641 645
642 //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); 646 //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);
643 return m_date; 647 return m_date;
644} 648}
645 649
646 650
647bool KLocale::use12Clock() const 651bool KLocale::use12Clock() const
648{ 652{
649 return !mHourF24Format ;; 653 return !mHourF24Format ;;
650} 654}
651 655
652bool KLocale::weekStartsMonday() const 656bool KLocale::weekStartsMonday() const
653{ 657{
654 return mWeekStartsMonday; 658 return mWeekStartsMonday;
655} 659}
656 660
657int KLocale::weekStartDay() const 661int KLocale::weekStartDay() const
658{ 662{
659 if ( mWeekStartsMonday ) 663 if ( mWeekStartsMonday )
660 return 1; 664 return 1;
661 return 7; 665 return 7;
662} 666}
663 667
664QString KLocale::weekDayName(int i,bool shortName) const 668QString KLocale::weekDayName(int i,bool shortName) const
665{ 669{
666 if ( shortName ) 670 if ( shortName )
667 switch ( i ) 671 switch ( i )
668 { 672 {
669 case 1: return i18n("Monday", "Mon"); 673 case 1: return i18n("Monday", "Mon");
670 case 2: return i18n("Tuesday", "Tue"); 674 case 2: return i18n("Tuesday", "Tue");
671 case 3: return i18n("Wednesday", "Wed"); 675 case 3: return i18n("Wednesday", "Wed");
672 case 4: return i18n("Thursday", "Thu"); 676 case 4: return i18n("Thursday", "Thu");
673 case 5: return i18n("Friday", "Fri"); 677 case 5: return i18n("Friday", "Fri");
674 case 6: return i18n("Saturday", "Sat"); 678 case 6: return i18n("Saturday", "Sat");
675 case 7: return i18n("Sunday", "Sun"); 679 case 7: return i18n("Sunday", "Sun");
676 } 680 }
677 else 681 else
678 switch ( i ) 682 switch ( i )
679 { 683 {
680 case 1: return i18n("Monday"); 684 case 1: return i18n("Monday");
681 case 2: return i18n("Tuesday"); 685 case 2: return i18n("Tuesday");
682 case 3: return i18n("Wednesday"); 686 case 3: return i18n("Wednesday");
683 case 4: return i18n("Thursday"); 687 case 4: return i18n("Thursday");
684 case 5: return i18n("Friday"); 688 case 5: return i18n("Friday");
685 case 6: return i18n("Saturday"); 689 case 6: return i18n("Saturday");
686 case 7: return i18n("Sunday"); 690 case 7: return i18n("Sunday");
687 } 691 }
688 692
689 return QString::null; 693 return QString::null;
690} 694}
691 695
692QString KLocale::monthName(int i,bool shortName) const 696QString KLocale::monthName(int i,bool shortName) const
693{ 697{
694 if ( shortName ) 698 if ( shortName )
695 switch ( i ) 699 switch ( i )
696 { 700 {
697 case 1: return i18n("January", "Jan"); 701 case 1: return i18n("January", "Jan");
698 case 2: return i18n("February", "Feb"); 702 case 2: return i18n("February", "Feb");
699 case 3: return i18n("March", "Mar"); 703 case 3: return i18n("March", "Mar");
700 case 4: return i18n("April", "Apr"); 704 case 4: return i18n("April", "Apr");
701 case 5: return i18n("May short", "May"); 705 case 5: return i18n("May short", "May");
702 case 6: return i18n("June", "Jun"); 706 case 6: return i18n("June", "Jun");
703 case 7: return i18n("July", "Jul"); 707 case 7: return i18n("July", "Jul");
704 case 8: return i18n("August", "Aug"); 708 case 8: return i18n("August", "Aug");
705 case 9: return i18n("September", "Sep"); 709 case 9: return i18n("September", "Sep");
706 case 10: return i18n("October", "Oct"); 710 case 10: return i18n("October", "Oct");
707 case 11: return i18n("November", "Nov"); 711 case 11: return i18n("November", "Nov");
708 case 12: return i18n("December", "Dec"); 712 case 12: return i18n("December", "Dec");
709 } 713 }
710 else 714 else
711 switch (i) 715 switch (i)
712 { 716 {
713 case 1: return i18n("January"); 717 case 1: return i18n("January");
714 case 2: return i18n("February"); 718 case 2: return i18n("February");
715 case 3: return i18n("March"); 719 case 3: return i18n("March");
716 case 4: return i18n("April"); 720 case 4: return i18n("April");
717 case 5: return i18n("May long", "May"); 721 case 5: return i18n("May long", "May");
718 case 6: return i18n("June"); 722 case 6: return i18n("June");
719 case 7: return i18n("July"); 723 case 7: return i18n("July");
720 case 8: return i18n("August"); 724 case 8: return i18n("August");
721 case 9: return i18n("September"); 725 case 9: return i18n("September");
722 case 10: return i18n("October"); 726 case 10: return i18n("October");
723 case 11: return i18n("November"); 727 case 11: return i18n("November");
724 case 12: return i18n("December"); 728 case 12: return i18n("December");
725 } 729 }
726 730
727 return QString::null; 731 return QString::null;
728} 732}
729 733
730QString KLocale::country() const 734QString KLocale::country() const
731{ 735{
732 return QString::null; 736 return QString::null;
733} 737}
734 738
735QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const 739QString KLocale::dateFormat(IntDateFormat intIntDateFormat) const
736{ 740{
737 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; 741 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
738 742
739 if ( dformat == ISODate ) 743 if ( dformat == ISODate )
740 return "%Y-%m-%d"; 744 return "%Y-%m-%d";
741 745
742 if ( QApplication::desktop()->width() < 480 ) { 746 if ( QApplication::desktop()->width() < 480 ) {
743 if ( dformat == Default ) 747 if ( dformat == Default )
744 return "%a %d %b %Y"; 748 return "%a %d %b %Y";
745 else if ( dformat == Format1 ) 749 else if ( dformat == Format1 )
746 return "%a %b %d %Y"; 750 return "%a %b %d %Y";
747 } else { 751 } else {
748 if ( dformat == Default ) 752 if ( dformat == Default )
749 return "%A %d %B %Y"; 753 return "%A %d %B %Y";
750 else if ( dformat == Format1 ) 754 else if ( dformat == Format1 )
751 return "%A %B %d %Y"; 755 return "%A %B %d %Y";
752 756
753 } 757 }
754 return mDateFormat ; 758 return mDateFormat ;
755} 759}
756 760
757QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const 761QString KLocale::dateFormatShort(IntDateFormat intIntDateFormat) const
758{ 762{
759 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat; 763 const IntDateFormat dformat = (intIntDateFormat == Undefined)?mIntDateFormat:intIntDateFormat;
760 764
761 if ( dformat == Default ) 765 if ( dformat == Default )
762 return "%d.%m.%Y"; 766 return "%d.%m.%Y";
763 else if ( dformat == Format1 ) 767 else if ( dformat == Format1 )
764 return "%m.%d.%Y"; 768 return "%m.%d.%Y";
765 else if ( dformat == ISODate ) // = Qt::ISODate 769 else if ( dformat == ISODate ) // = Qt::ISODate
766 return "%Y-%m-%d"; 770 return "%Y-%m-%d";
767 return mDateFormatShort ; 771 return mDateFormatShort ;
768 772
769} 773}
770 774
771 775
772QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const 776QString KLocale::timeFormat(IntDateFormat intIntTimeFormat) const
773{ 777{
774 const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat; 778 const IntDateFormat tformat = (intIntTimeFormat == Undefined)?mIntTimeFormat:intIntTimeFormat;
775 779
776 if ( tformat == Default ) 780 if ( tformat == Default )
777 if ( mHourF24Format) 781 if ( mHourF24Format)
778 return "%H:%M:%S"; 782 return "%H:%M:%S";
779 else 783 else
780 return "%I:%M:%S%p"; 784 return "%I:%M:%S%p";
781 785
782 else if ( tformat == Format1 ) 786 else if ( tformat == Format1 )
783 if ( mHourF24Format) 787 if ( mHourF24Format)
784 return "%H:%M:%S"; 788 return "%H:%M:%S";
785 else 789 else
786 return "%I:%M:%S%p"; 790 return "%I:%M:%S%p";
787 791
788 else if ( tformat == ISODate ) // = Qt::ISODate 792 else if ( tformat == ISODate ) // = Qt::ISODate
789 if ( mHourF24Format) 793 if ( mHourF24Format)
790 return "%H:%M:%S"; 794 return "%H:%M:%S";
791 else 795 else
792 return "%I:%M:%S%p"; 796 return "%I:%M:%S%p";
793 797
794} 798}
795 799
796void KLocale::insertCatalogue ( const QString & ) 800void KLocale::insertCatalogue ( const QString & )
797{ 801{
798} 802}
799 803
800KCalendarSystem *KLocale::calendar() 804KCalendarSystem *KLocale::calendar()
801{ 805{
802 if ( !mCalendarSystem ) { 806 if ( !mCalendarSystem ) {
803 mCalendarSystem = new KCalendarSystemGregorian; 807 mCalendarSystem = new KCalendarSystemGregorian;
804 } 808 }
805 809
806 return mCalendarSystem; 810 return mCalendarSystem;
807} 811}
808 812
809int KLocale::timezoneOffset( QString timeZone ) 813int KLocale::timezoneOffset( QString timeZone )
810{ 814{
811 int ret = 1001; 815 int ret = 1001;
812 int index = mTimeZoneList.findIndex( timeZone ); 816 int index = mTimeZoneList.findIndex( timeZone );
813 if ( index < 24 ) 817 if ( index < 24 )
814 ret = ( index-11 ) * 60 ; 818 ret = ( index-11 ) * 60 ;
815 return ret; 819 return ret;
816} 820}
817 821
818QStringList KLocale::timeZoneList() const 822QStringList KLocale::timeZoneList() const
819{ 823{
820 return mTimeZoneList; 824 return mTimeZoneList;
821} 825}
822void KLocale::setTimezone( const QString &timeZone, bool oddTZ ) 826void KLocale::setTimezone( const QString &timeZone, bool oddTZ )
823{ 827{
824 mTimeZoneOffset = timezoneOffset( timeZone ); 828 mTimeZoneOffset = timezoneOffset( timeZone );
825 if ( oddTZ ) 829 if ( oddTZ )
826 mTimeZoneOffset += 30; 830 mTimeZoneOffset += 30;
827} 831}
828 832
829void KLocale::setDaylightSaving( bool b, int start , int end ) 833void KLocale::setDaylightSaving( bool b, int start , int end )
830{ 834{
831 daylightEnabled = b; 835 daylightEnabled = b;
832 daylightStart = start; 836 daylightStart = start;
833 daylightEnd = end; 837 daylightEnd = end;
834 mSouthDaylight = (end < start); 838 mSouthDaylight = (end < start);
835 // qDebug("klocale daylight %d %d %d ", b, start , end ); 839 // qDebug("klocale daylight %d %d %d ", b, start , end );
836} 840}
837 841
838int KLocale::localTimeOffset( const QDateTime &dt ) 842int KLocale::localTimeOffset( const QDateTime &dt )
839{ 843{
840 bool addDaylight = false; 844 bool addDaylight = false;
841 if ( daylightEnabled ) { 845 if ( daylightEnabled ) {
842 int d_end, d_start; 846 int d_end, d_start;
843 int dayofyear = dt.date().dayOfYear(); 847 int dayofyear = dt.date().dayOfYear();
844 int year = dt.date().year(); 848 int year = dt.date().year();
845 int add = 0; 849 int add = 0;
846 if ( QDate::leapYear(year) ) 850 if ( QDate::leapYear(year) )
847 add = 1; 851 add = 1;
848 QDate date ( year,1,1 ); 852 QDate date ( year,1,1 );
849 if ( daylightEnd > 59 ) 853 if ( daylightEnd > 59 )
850 d_end = daylightEnd +add; 854 d_end = daylightEnd +add;
851 else 855 else
852 d_end = daylightEnd; 856 d_end = daylightEnd;
853 if ( daylightStart > 59 ) 857 if ( daylightStart > 59 )
854 d_start = daylightStart +add; 858 d_start = daylightStart +add;
855 else 859 else
856 d_start = daylightStart; 860 d_start = daylightStart;
857 QDate s_date = date.addDays( d_start -1 ); 861 QDate s_date = date.addDays( d_start -1 );
858 QDate e_date = date.addDays( d_end -1 ); 862 QDate e_date = date.addDays( d_end -1 );
859 int dof = s_date.dayOfWeek(); 863 int dof = s_date.dayOfWeek();
860 if ( dof < 7 ) 864 if ( dof < 7 )
861 s_date = s_date.addDays( -dof ); 865 s_date = s_date.addDays( -dof );
862 dof = e_date.dayOfWeek(); 866 dof = e_date.dayOfWeek();
863 if ( dof < 7 ) 867 if ( dof < 7 )
864 e_date = e_date.addDays( -dof ); 868 e_date = e_date.addDays( -dof );
865 QTime startTime ( 3,0,0 ); 869 QTime startTime ( 3,0,0 );
866 QDateTime startDt( s_date, startTime ); 870 QDateTime startDt( s_date, startTime );
867 QDateTime endDt( e_date, startTime ); 871 QDateTime endDt( e_date, startTime );
868 //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( )); 872 //qDebug("dayligt saving start %s end %s ",startDt.toString().latin1(),endDt.toString().latin1( ));
869 if ( mSouthDaylight ) { 873 if ( mSouthDaylight ) {
870 if ( ! ( endDt < dt && dt < startDt) ) 874 if ( ! ( endDt < dt && dt < startDt) )
871 addDaylight = true; 875 addDaylight = true;
872 } else { 876 } else {
873 if ( startDt < dt && dt < endDt ) 877 if ( startDt < dt && dt < endDt )
874 addDaylight = true; 878 addDaylight = true;
875 879
876 880
877 } 881 }
878 } 882 }
879 int addMin = 0; 883 int addMin = 0;
880 if ( addDaylight ) 884 if ( addDaylight )
881 addMin = 60; 885 addMin = 60;
882 return mTimeZoneOffset + addMin; 886 return mTimeZoneOffset + addMin;
883} 887}
884// ****************************************************************** 888// ******************************************************************
885// added LR 889// added LR
886QString KLocale::formatNumber(double num, int precision) const 890QString KLocale::formatNumber(double num, int precision) const
887{ 891{
888 bool neg = num < 0; 892 bool neg = num < 0;
889 if (precision == -1) precision = 2; 893 if (precision == -1) precision = 2;
890 QString res = QString::number(neg?-num:num, 'f', precision); 894 QString res = QString::number(neg?-num:num, 'f', precision);
891 int pos = res.find('.'); 895 int pos = res.find('.');
892 if (pos == -1) pos = res.length(); 896 if (pos == -1) pos = res.length();
893 else res.replace(pos, 1, decimalSymbol()); 897 else res.replace(pos, 1, decimalSymbol());
894 898
895 while (0 < (pos -= 3)) 899 while (0 < (pos -= 3))
896 res.insert(pos, thousandsSeparator()); // thousand sep 900 res.insert(pos, thousandsSeparator()); // thousand sep
897 901
898 // How can we know where we should put the sign? 902 // How can we know where we should put the sign?
899 res.prepend(neg?negativeSign():positiveSign()); 903 res.prepend(neg?negativeSign():positiveSign());
900 904
901 return res; 905 return res;
902} 906}
903QString KLocale::formatNumber(const QString &numStr) const 907QString KLocale::formatNumber(const QString &numStr) const
904{ 908{
905 return formatNumber(numStr.toDouble()); 909 return formatNumber(numStr.toDouble());
906} 910}
907double KLocale::readNumber(const QString &_str, bool * ok) const 911double KLocale::readNumber(const QString &_str, bool * ok) const
908{ 912{
909 QString str = _str.stripWhiteSpace(); 913 QString str = _str.stripWhiteSpace();
910 bool neg = str.find(negativeSign()) == 0; 914 bool neg = str.find(negativeSign()) == 0;
911 if (neg) 915 if (neg)
912 str.remove( 0, negativeSign().length() ); 916 str.remove( 0, negativeSign().length() );
913 917
914 /* will hold the scientific notation portion of the number. 918 /* will hold the scientific notation portion of the number.
915 Example, with 2.34E+23, exponentialPart == "E+23" 919 Example, with 2.34E+23, exponentialPart == "E+23"
916 */ 920 */
917 QString exponentialPart; 921 QString exponentialPart;
918 int EPos; 922 int EPos;
919 923
920 EPos = str.find('E', 0, false); 924 EPos = str.find('E', 0, false);
921 925
922 if (EPos != -1) 926 if (EPos != -1)
923 { 927 {
924 exponentialPart = str.mid(EPos); 928 exponentialPart = str.mid(EPos);
925 str = str.left(EPos); 929 str = str.left(EPos);
926 } 930 }
927 931
928 int pos = str.find(decimalSymbol()); 932 int pos = str.find(decimalSymbol());
929 QString major; 933 QString major;
930 QString minor; 934 QString minor;
931 if ( pos == -1 ) 935 if ( pos == -1 )
932 major = str; 936 major = str;
933 else 937 else
934 { 938 {
935 major = str.left(pos); 939 major = str.left(pos);
936 minor = str.mid(pos + decimalSymbol().length()); 940 minor = str.mid(pos + decimalSymbol().length());
937 } 941 }
938 942
939 // Remove thousand separators 943 // Remove thousand separators
940 int thlen = thousandsSeparator().length(); 944 int thlen = thousandsSeparator().length();
941 int lastpos = 0; 945 int lastpos = 0;
942 while ( ( pos = major.find( thousandsSeparator() ) ) > 0 ) 946 while ( ( pos = major.find( thousandsSeparator() ) ) > 0 )
943 { 947 {
944 // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N 948 // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N
945 int fromEnd = major.length() - pos; 949 int fromEnd = major.length() - pos;
946 if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error 950 if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error
947 || pos - lastpos > 3 // More than 3 digits between two separators -> error 951 || pos - lastpos > 3 // More than 3 digits between two separators -> error
948 || pos == 0 // Can't start with a separator 952 || pos == 0 // Can't start with a separator
949 || (lastpos>0 && pos-lastpos!=3)) // Must have exactly 3 digits between two separators 953 || (lastpos>0 && pos-lastpos!=3)) // Must have exactly 3 digits between two separators
950 { 954 {
951 if (ok) *ok = false; 955 if (ok) *ok = false;
952 return 0.0; 956 return 0.0;
953 } 957 }
954 958
955 lastpos = pos; 959 lastpos = pos;
956 major.remove( pos, thlen ); 960 major.remove( pos, thlen );
957 } 961 }
958 if (lastpos>0 && major.length()-lastpos!=3) // Must have exactly 3 digits after the last separator 962 if (lastpos>0 && major.length()-lastpos!=3) // Must have exactly 3 digits after the last separator
959 { 963 {
960 if (ok) *ok = false; 964 if (ok) *ok = false;
961 return 0.0; 965 return 0.0;
962 } 966 }
963 967
964 QString tot; 968 QString tot;
965 if (neg) tot = '-'; 969 if (neg) tot = '-';
966 970
967 tot += major + '.' + minor + exponentialPart; 971 tot += major + '.' + minor + exponentialPart;
968 972
969 return tot.toDouble(ok); 973 return tot.toDouble(ok);
970} 974}
971QString KLocale::decimalSymbol() const 975QString KLocale::decimalSymbol() const
972{ 976{
973 977
974 return m_decimalSymbol; 978 return m_decimalSymbol;
975} 979}
976 980
977QString KLocale::thousandsSeparator() const 981QString KLocale::thousandsSeparator() const
978{ 982{
979 983
980 return m_thousandsSeparator; 984 return m_thousandsSeparator;
981} 985}
982QString KLocale::positiveSign() const 986QString KLocale::positiveSign() const
983{ 987{
984 return m_positiveSign; 988 return m_positiveSign;
985} 989}
986 990
987QString KLocale::negativeSign() const 991QString KLocale::negativeSign() const
988{ 992{
989 return m_negativeSign; 993 return m_negativeSign;
990} 994}
diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h
index be9442c..14660d6 100644
--- a/microkde/kdecore/klocale.h
+++ b/microkde/kdecore/klocale.h
@@ -1,118 +1,119 @@
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, IntDateFormat intIntDateFormat = Undefined) const; 47 QString formatTime(const QTime &pTime, bool includeSecs = false, IntDateFormat intIntDateFormat = Undefined) const;
48 QString formatDateTime(const QDateTime &pDateTime, IntDateFormat intIntDateFormat = Undefined) 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, IntDateFormat intIntDateFormat = Undefined) 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 QDate readDate(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; 56 QDate readDate(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const;
57 57
58 QDateTime readDateTime(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const; 58 QDateTime readDateTime(const QString &intstr, IntDateFormat intIntDateFormat, bool* ok) const;
59 59
60 bool use12Clock() const; 60 bool use12Clock() const;
61 bool weekStartsMonday() const; 61 bool weekStartsMonday() const;
62 int weekStartDay() const; 62 int weekStartDay() const;
63 63
64 QString weekDayName(int,bool=false) const; 64 QString weekDayName(int,bool=false) const;
65 QString monthName(int,bool=false) const; 65 QString monthName(int,bool=false) const;
66 66
67 QString country() const; 67 QString country() const;
68 68
69 QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const; 69 QString dateFormat(IntDateFormat intIntDateFormat = Undefined) const;
70 QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const; 70 QString dateFormatShort(IntDateFormat intIntDateFormat = Undefined) const;
71 QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const; 71 QString timeFormat(IntDateFormat intIntDateFormat = Undefined) const;
72 72
73 void insertCatalogue ( const QString & ); 73 void insertCatalogue ( const QString & );
74 74
75 KCalendarSystem *calendar(); 75 KCalendarSystem *calendar();
76 void setHore24Format ( bool ); 76 void setHore24Format ( bool );
77 void setWeekStartMonday( bool ); 77 void setWeekStartMonday( bool );
78 void setIntDateFormat( IntDateFormat ); 78 void setIntDateFormat( IntDateFormat );
79 void setIntTimeFormat( IntDateFormat ); 79 void setIntTimeFormat( IntDateFormat );
80 IntDateFormat getIntDateFormat( ); 80 IntDateFormat getIntDateFormat( );
81 IntDateFormat getIntTimeFormat( ); 81 IntDateFormat getIntTimeFormat( );
82 void setLanguage( int ); 82 void setLanguage( int );
83 int language();
83 void setDateFormat( QString ); 84 void setDateFormat( QString );
84 void setDateFormatShort( QString ); 85 void setDateFormatShort( QString );
85 86
86 QString m_decimalSymbol; 87 QString m_decimalSymbol;
87 QString m_thousandsSeparator; 88 QString m_thousandsSeparator;
88 QString m_currencySymbol; 89 QString m_currencySymbol;
89 QString m_monetaryDecimalSymbol; 90 QString m_monetaryDecimalSymbol;
90 QString m_monetaryThousandsSeparator; 91 QString m_monetaryThousandsSeparator;
91 QString m_positiveSign; 92 QString m_positiveSign;
92 QString m_negativeSign; 93 QString m_negativeSign;
93 94
94 int timezoneOffset( QString ); 95 int timezoneOffset( QString );
95 QStringList timeZoneList() const; 96 QStringList timeZoneList() const;
96 void setDaylightSaving( bool, int , int ); 97 void setDaylightSaving( bool, int , int );
97 int localTimeOffset(const QDateTime &); 98 int localTimeOffset(const QDateTime &);
98 void setTimezone( const QString &timeZone , bool oddTZ); 99 void setTimezone( const QString &timeZone , bool oddTZ);
99 private: 100 private:
100 QTime readTime(const QString &str, bool seconds, bool *ok) const; 101 QTime readTime(const QString &str, bool seconds, bool *ok) const;
101 QDate readDate(const QString &str, bool shortFormat, bool *ok) const; 102 QDate readDate(const QString &str, bool shortFormat, bool *ok) const;
102 KCalendarSystem *mCalendarSystem; 103 KCalendarSystem *mCalendarSystem;
103 bool mWeekStartsMonday; 104 bool mWeekStartsMonday;
104 bool mHourF24Format; 105 bool mHourF24Format;
105 IntDateFormat mIntDateFormat; 106 IntDateFormat mIntDateFormat;
106 IntDateFormat mIntTimeFormat; 107 IntDateFormat mIntTimeFormat;
107 int mLanguage; 108 int mLanguage;
108 QString mDateFormat; 109 QString mDateFormat;
109 QString mDateFormatShort; 110 QString mDateFormatShort;
110 QStringList mTimeZoneList; 111 QStringList mTimeZoneList;
111 bool daylightEnabled; 112 bool daylightEnabled;
112 int mDaylightTZoffset; 113 int mDaylightTZoffset;
113 int mNondaylightTZoffset; 114 int mNondaylightTZoffset;
114 bool mSouthDaylight; 115 bool mSouthDaylight;
115 int daylightStart, daylightEnd, mTimeZoneOffset; 116 int daylightStart, daylightEnd, mTimeZoneOffset;
116}; 117};
117 118
118#endif 119#endif