summaryrefslogtreecommitdiffabout
path: root/microkde
authorzautrix <zautrix>2005-03-28 23:39:37 (UTC)
committer zautrix <zautrix>2005-03-28 23:39:37 (UTC)
commit4e7c45695672ecdbd0cd14cac0ea29a8e134ee78 (patch) (unidiff)
tree6815e055d6cb35d56d43f036261f5be9d2a9c350 /microkde
parent4034290f894ff7d1b0cf1197078e0ed832566bb7 (diff)
downloadkdepimpi-4e7c45695672ecdbd0cd14cac0ea29a8e134ee78.zip
kdepimpi-4e7c45695672ecdbd0cd14cac0ea29a8e134ee78.tar.gz
kdepimpi-4e7c45695672ecdbd0cd14cac0ea29a8e134ee78.tar.bz2
montview sunday fix
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/klocale.cpp37
-rw-r--r--microkde/kdecore/klocale.h2
2 files changed, 38 insertions, 1 deletions
diff --git a/microkde/kdecore/klocale.cpp b/microkde/kdecore/klocale.cpp
index 7f31ab1..1d8ae9f 100644
--- a/microkde/kdecore/klocale.cpp
+++ b/microkde/kdecore/klocale.cpp
@@ -223,96 +223,133 @@ void KLocale::setDateFormatShort( QString 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
271int KLocale::weekNum ( const QDate & date )
272{
273 QDate seda = date;
274 int weekNum = 0;
275 int dayofweek = seda.dayOfWeek(); // 1... 7 Mo .. So. Do = 4
276 int daystoprevthursday = (dayofweek + 3) % 7 ;
277 int dayofyear = seda.dayOfYear();
278 int prevThursday = dayofyear - ( daystoprevthursday );
279 int subweeknum = 0;
280 if ( prevThursday < 1 ) {
281 seda = seda.addDays( - daystoprevthursday );
282 dayofyear = seda.dayOfYear();
283 prevThursday = dayofyear;
284 subweeknum = prevThursday / 7;
285 if ( prevThursday % 7 != 0 )
286 ++subweeknum;
287 } else {
288 if ( dayofyear >= 360 ) { //maybe week 1
289 seda = seda.addDays( 7 - daystoprevthursday );
290 dayofyear = seda.dayOfYear();
291 if ( dayofyear < 360 && ( dayofweek < 4 || dayofweek == 7 && !mWeekStartsMonday ) )
292 return 1;
293 }
294 }
295 if ( ! weekNum ) {
296 weekNum = prevThursday / 7;
297 if ( prevThursday % 7 != 0 )
298 ++weekNum;
299 if ( dayofweek < 4 )
300 ++weekNum;
301 else if ( dayofweek == 7 && !mWeekStartsMonday )
302 ++weekNum;
303 if ( weekNum > subweeknum )
304 weekNum -= subweeknum;
305 }
306 return weekNum;
307}
271QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const 308QString KLocale::formatTime(const QTime &pTime, bool includeSecs, IntDateFormat intIntDateFormat) const
272{ 309{
273 const QString rst = timeFormat(intIntDateFormat); 310 const QString rst = timeFormat(intIntDateFormat);
274 311
275 // only "pm/am" here can grow, the rest shrinks, but 312 // only "pm/am" here can grow, the rest shrinks, but
276 // I'm rather safe than sorry 313 // I'm rather safe than sorry
277 QChar *buffer = new QChar[rst.length() * 3 / 2 + 30]; 314 QChar *buffer = new QChar[rst.length() * 3 / 2 + 30];
278 315
279 uint index = 0; 316 uint index = 0;
280 bool escape = false; 317 bool escape = false;
281 int number = 0; 318 int number = 0;
282 319
283 for ( uint format_index = 0; format_index < rst.length(); format_index++ ) 320 for ( uint format_index = 0; format_index < rst.length(); format_index++ )
284 { 321 {
285 if ( !escape ) 322 if ( !escape )
286 { 323 {
287 if ( rst.at( format_index ).unicode() == '%' ) 324 if ( rst.at( format_index ).unicode() == '%' )
288 escape = true; 325 escape = true;
289 else 326 else
290 buffer[index++] = rst.at( format_index ); 327 buffer[index++] = rst.at( format_index );
291 } 328 }
292 else 329 else
293 { 330 {
294 switch ( rst.at( format_index ).unicode() ) 331 switch ( rst.at( format_index ).unicode() )
295 { 332 {
296 case '%': 333 case '%':
297 buffer[index++] = '%'; 334 buffer[index++] = '%';
298 break; 335 break;
299 case 'H': 336 case 'H':
300 put_it_in( buffer, index, pTime.hour() ); 337 put_it_in( buffer, index, pTime.hour() );
301 break; 338 break;
302 case 'I': 339 case 'I':
303 put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 ); 340 put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 );
304 break; 341 break;
305 case 'M': 342 case 'M':
306 put_it_in( buffer, index, pTime.minute() ); 343 put_it_in( buffer, index, pTime.minute() );
307 break; 344 break;
308 case 'S': 345 case 'S':
309 if (includeSecs) 346 if (includeSecs)
310 put_it_in( buffer, index, pTime.second() ); 347 put_it_in( buffer, index, pTime.second() );
311 else 348 else
312 { 349 {
313 // we remove the seperator sign before the seconds and 350 // we remove the seperator sign before the seconds and
314 // assume that works everywhere 351 // assume that works everywhere
315 --index; 352 --index;
316 break; 353 break;
317 } 354 }
318 break; 355 break;
diff --git a/microkde/kdecore/klocale.h b/microkde/kdecore/klocale.h
index 14660d6..58e0b39 100644
--- a/microkde/kdecore/klocale.h
+++ b/microkde/kdecore/klocale.h
@@ -20,97 +20,97 @@ QString i18n(const char *text1, const char *textn, int num);
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 int weekNum ( const QDate & );
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 int language();
84 void setDateFormat( QString ); 84 void setDateFormat( QString );
85 void setDateFormatShort( QString ); 85 void setDateFormatShort( QString );
86 86
87 QString m_decimalSymbol; 87 QString m_decimalSymbol;
88 QString m_thousandsSeparator; 88 QString m_thousandsSeparator;
89 QString m_currencySymbol; 89 QString m_currencySymbol;
90 QString m_monetaryDecimalSymbol; 90 QString m_monetaryDecimalSymbol;
91 QString m_monetaryThousandsSeparator; 91 QString m_monetaryThousandsSeparator;
92 QString m_positiveSign; 92 QString m_positiveSign;
93 QString m_negativeSign; 93 QString m_negativeSign;
94 94
95 int timezoneOffset( QString ); 95 int timezoneOffset( QString );
96 QStringList timeZoneList() const; 96 QStringList timeZoneList() const;
97 void setDaylightSaving( bool, int , int ); 97 void setDaylightSaving( bool, int , int );
98 int localTimeOffset(const QDateTime &); 98 int localTimeOffset(const QDateTime &);
99 void setTimezone( const QString &timeZone , bool oddTZ); 99 void setTimezone( const QString &timeZone , bool oddTZ);
100 private: 100 private:
101 QTime readTime(const QString &str, bool seconds, bool *ok) const; 101 QTime readTime(const QString &str, bool seconds, bool *ok) const;
102 QDate readDate(const QString &str, bool shortFormat, bool *ok) const; 102 QDate readDate(const QString &str, bool shortFormat, bool *ok) const;
103 KCalendarSystem *mCalendarSystem; 103 KCalendarSystem *mCalendarSystem;
104 bool mWeekStartsMonday; 104 bool mWeekStartsMonday;
105 bool mHourF24Format; 105 bool mHourF24Format;
106 IntDateFormat mIntDateFormat; 106 IntDateFormat mIntDateFormat;
107 IntDateFormat mIntTimeFormat; 107 IntDateFormat mIntTimeFormat;
108 int mLanguage; 108 int mLanguage;
109 QString mDateFormat; 109 QString mDateFormat;
110 QString mDateFormatShort; 110 QString mDateFormatShort;
111 QStringList mTimeZoneList; 111 QStringList mTimeZoneList;
112 bool daylightEnabled; 112 bool daylightEnabled;
113 int mDaylightTZoffset; 113 int mDaylightTZoffset;
114 int mNondaylightTZoffset; 114 int mNondaylightTZoffset;
115 bool mSouthDaylight; 115 bool mSouthDaylight;
116 int daylightStart, daylightEnd, mTimeZoneOffset; 116 int daylightStart, daylightEnd, mTimeZoneOffset;