author | llornkcor <llornkcor> | 2006-07-09 18:56:40 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2006-07-09 18:56:40 (UTC) |
commit | 36dece4760b1ac1799929221b49eb3bee98c2367 (patch) (unidiff) | |
tree | a45f66d2d90bd9fbbff8e8903cd1cb9323c39f6e /library/timestring.cpp | |
parent | 604065c6e662cb3894acf03abadafacc3ab52913 (diff) | |
download | opie-36dece4760b1ac1799929221b49eb3bee98c2367.zip opie-36dece4760b1ac1799929221b49eb3bee98c2367.tar.gz opie-36dece4760b1ac1799929221b49eb3bee98c2367.tar.bz2 |
initial commit to add video4linux camera app from qtopia 2, needs more work
-rw-r--r-- | library/timestring.cpp | 255 |
1 files changed, 178 insertions, 77 deletions
diff --git a/library/timestring.cpp b/library/timestring.cpp index 91c29ae..afd162d 100644 --- a/library/timestring.cpp +++ b/library/timestring.cpp | |||
@@ -1,123 +1,141 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2006 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the Qtopia Environment. | 4 | ** This file is part of the Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This program is free software; you can redistribute it and/or modify it |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** under the terms of the GNU General Public License as published by the |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Free Software Foundation; either version 2 of the License, or (at your |
9 | ** packaging of this file. | 9 | ** option) any later version. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** A copy of the GNU GPL license version 2 is included in this package as |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** LICENSE.GPL. |
13 | ** | ||
14 | ** This program is distributed in the hope that it will be useful, but | ||
15 | ** WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | ** See the GNU General Public License for more details. | ||
18 | ** | ||
19 | ** In addition, as a special exception Trolltech gives permission to link | ||
20 | ** the code of this program with Qtopia applications copyrighted, developed | ||
21 | ** and distributed by Trolltech under the terms of the Qtopia Personal Use | ||
22 | ** License Agreement. You must comply with the GNU General Public License | ||
23 | ** in all respects for all of the code used other than the applications | ||
24 | ** licensed under the Qtopia Personal Use License Agreement. If you modify | ||
25 | ** this file, you may extend this exception to your version of the file, | ||
26 | ** but you are not obligated to do so. If you do not wish to do so, delete | ||
27 | ** this exception statement from your version. | ||
13 | ** | 28 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 30 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 31 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 32 | ** not clear to you. |
18 | ** | 33 | ** |
19 | **********************************************************************/ | 34 | **********************************************************************/ |
20 | 35 | ||
21 | #include "timestring.h" | 36 | #include "timestring.h" |
22 | #include <qobject.h> | 37 | #include <qobject.h> |
23 | #include <qpe/qpeapplication.h> //for qApp | 38 | #include <qdatetime.h> |
39 | #include <qapplication.h> | ||
24 | #include "config.h" | 40 | #include "config.h" |
25 | 41 | ||
42 | #include <time.h> | ||
43 | |||
26 | 44 | ||
27 | class TimeStringFormatKeeper : public QObject | 45 | class TimeStringFormat : public QObject |
28 | { | 46 | { |
29 | Q_OBJECT | 47 | Q_OBJECT |
30 | public: | 48 | public: |
31 | static DateFormat currentFormat() | 49 | static DateFormat currentFormat() |
32 | { | 50 | { |
33 | if ( !self ) | 51 | if ( !self ) |
34 | self = new TimeStringFormatKeeper; | 52 | self = new TimeStringFormat; |
35 | return self->format; | 53 | return self->format; |
36 | } | 54 | } |
37 | private slots: | 55 | private slots: |
38 | void formatChanged( DateFormat f ) | 56 | void formatChanged( DateFormat f ) |
39 | { | 57 | { |
40 | format = f; | 58 | format = f; |
41 | } | 59 | } |
42 | private: | 60 | private: |
43 | static TimeStringFormatKeeper *self; | 61 | static TimeStringFormat *self; |
44 | DateFormat format; | 62 | DateFormat format; |
45 | 63 | ||
46 | TimeStringFormatKeeper() | 64 | TimeStringFormat() |
47 | : QObject( qApp ) | 65 | : QObject( qApp ) |
48 | { | 66 | { |
49 | Config config("qpe"); | 67 | Config config("qpe"); |
50 | config.setGroup( "Date" ); | 68 | config.setGroup( "Date" ); |
51 | format = DateFormat(QChar(config.readEntry("Separator", "/")[0]), | 69 | format = ::DateFormat(QChar(config.readEntry("Separator", "/")[0]), |
52 | (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), | 70 | (::DateFormat::Order)config.readNumEntry("ShortOrder", ::DateFormat::DayMonthYear), |
53 | (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); | 71 | (::DateFormat::Order)config.readNumEntry("LongOrder", ::DateFormat::DayMonthYear)); |
54 | 72 | ||
55 | connect( qApp, SIGNAL( dateFormatChanged(DateFormat) ), | 73 | connect( qApp, SIGNAL( dateFormatChanged(DateFormat) ), |
56 | this, SLOT( formatChanged(DateFormat) ) ); | 74 | this, SLOT( formatChanged(DateFormat) ) ); |
57 | } | 75 | } |
58 | }; | 76 | }; |
59 | 77 | ||
60 | TimeStringFormatKeeper *TimeStringFormatKeeper::self = 0; | 78 | TimeStringFormat *TimeStringFormat::self = 0; |
61 | 79 | ||
62 | QString DateFormat::toNumberString() const | 80 | QString DateFormat::toNumberString() const |
63 | { | 81 | { |
64 | QString buf = ""; | 82 | QString buf = ""; |
65 | // for each part of the order | 83 | // for each part of the order |
66 | for (int i = 0; i < 3; i++) { | 84 | for (int i = 0; i < 3; i++) { |
67 | // switch on the relavent 3 bits. | 85 | // switch on the relavent 3 bits. |
68 | switch((_shortOrder >> (i * 3)) & 0x0007) { | 86 | switch((_shortOrder >> (i * 3)) & 0x0007) { |
69 | case 0x0001: | 87 | case 0x0001: |
70 | buf += QObject::tr( "D" , "Shortcut for Day"); | 88 | buf += TimeStringFormat::tr( "D", "first letter of the word 'Day'" ); |
71 | break; | 89 | break; |
72 | case 0x0002: | 90 | case 0x0002: |
73 | buf += QObject::tr( "M", "Shortcur for Month" ); | 91 | buf += TimeStringFormat::tr( "M" , "first letter of the word 'Month'" ); |
74 | break; | 92 | break; |
75 | case 0x0004: | 93 | case 0x0004: |
76 | buf += QObject::tr( "Y" ); | 94 | buf += TimeStringFormat::tr( "Y" , "first letter of the word 'Year'" ); |
77 | break; | 95 | break; |
78 | } | 96 | } |
79 | if (i < 2) | 97 | if (i < 2) |
80 | buf += _shortSeparator; | 98 | buf += _shortSeparator; |
81 | } | 99 | } |
82 | return buf; | 100 | return buf; |
83 | } | 101 | } |
84 | 102 | ||
85 | QString DateFormat::toWordString() const | 103 | QString DateFormat::toWordString() const |
86 | { | 104 | { |
87 | QString buf = ""; | 105 | QString buf = ""; |
88 | // for each part of the order | 106 | // for each part of the order |
89 | for (int i = 0; i < 3; i++) { | 107 | for (int i = 0; i < 3; i++) { |
90 | // switch on the relavent 3 bits. | 108 | // switch on the relavent 3 bits. |
91 | switch((_longOrder >> (i * 3)) & 0x0007) { | 109 | switch((_longOrder >> (i * 3)) & 0x0007) { |
92 | case 0x0001: | 110 | case 0x0001: |
93 | buf += QObject::tr( "day" ); | 111 | buf += TimeStringFormat::tr( "day", "in month" ); |
94 | if (i < 2) { | 112 | if (i < 2) { |
95 | if ((_shortOrder << ((i+1) * 3)) & 0x0007) | 113 | if ((_shortOrder << ((i+1) * 3)) & 0x0007) |
96 | buf += ", "; | 114 | buf += ", "; |
97 | else | 115 | else |
98 | buf += " "; | 116 | buf += " "; |
99 | } | 117 | } |
100 | break; | 118 | break; |
101 | case 0x0002: | 119 | case 0x0002: |
102 | buf += QObject::tr( "month" ); | 120 | buf += TimeStringFormat::tr( "month" ); |
103 | if (i < 2) | 121 | if (i < 2) |
104 | buf += " "; | 122 | buf += " "; |
105 | break; | 123 | break; |
106 | case 0x0004: | 124 | case 0x0004: |
107 | buf += QObject::tr( "year" ); | 125 | buf += TimeStringFormat::tr( "year" ); |
108 | if (i < 2) | 126 | if (i < 2) |
109 | buf += ", "; | 127 | buf += ", "; |
110 | break; | 128 | break; |
111 | } | 129 | } |
112 | } | 130 | } |
113 | return buf; | 131 | return buf; |
114 | } | 132 | } |
115 | 133 | ||
116 | QString DateFormat::numberDate(const QDate &d, int v) const | 134 | QString DateFormat::numberDate(const QDate &d, int v) const |
117 | { | 135 | { |
118 | QString buf = ""; | 136 | QString buf = ""; |
119 | 137 | ||
120 | int pad = 2; | 138 | int pad = 2; |
121 | 139 | ||
122 | // for each part of the order | 140 | // for each part of the order |
123 | for (int i = 0; i < 3; i++) { | 141 | for (int i = 0; i < 3; i++) { |
@@ -136,90 +154,166 @@ QString DateFormat::numberDate(const QDate &d, int v) const | |||
136 | break; | 154 | break; |
137 | case 0x0004: | 155 | case 0x0004: |
138 | { | 156 | { |
139 | int year = d.year(); | 157 | int year = d.year(); |
140 | if (!(v & longNumber)) | 158 | if (!(v & longNumber)) |
141 | year = year % 100; | 159 | year = year % 100; |
142 | buf += QString().sprintf("%02d",year); | 160 | buf += QString().sprintf("%02d",year); |
143 | } | 161 | } |
144 | break; | 162 | break; |
145 | } | 163 | } |
146 | if (i < 2) | 164 | if (i < 2) |
147 | buf += _shortSeparator; | 165 | buf += _shortSeparator; |
148 | } | 166 | } |
149 | return buf; | 167 | return buf; |
150 | } | 168 | } |
151 | 169 | ||
170 | static const char* unTranslatedFullMonthNames[] = { | ||
171 | QT_TRANSLATE_NOOP( "QDate", "January" ), | ||
172 | QT_TRANSLATE_NOOP( "QDate", "February" ), | ||
173 | QT_TRANSLATE_NOOP( "QDate", "March" ), | ||
174 | QT_TRANSLATE_NOOP( "QDate", "April" ), | ||
175 | QT_TRANSLATE_NOOP( "QDate", "May" ), | ||
176 | QT_TRANSLATE_NOOP( "QDate", "June" ), | ||
177 | QT_TRANSLATE_NOOP( "QDate", "July" ), | ||
178 | QT_TRANSLATE_NOOP( "QDate", "August" ), | ||
179 | QT_TRANSLATE_NOOP( "QDate", "September" ), | ||
180 | QT_TRANSLATE_NOOP( "QDate", "October" ), | ||
181 | QT_TRANSLATE_NOOP( "QDate", "November" ), | ||
182 | QT_TRANSLATE_NOOP( "QDate", "December" ) | ||
183 | }; | ||
184 | |||
185 | static const char* unTranslatedFullDayNames[] = { | ||
186 | QT_TRANSLATE_NOOP( "QDate", "Monday" ), | ||
187 | QT_TRANSLATE_NOOP( "QDate", "Tuesday" ), | ||
188 | QT_TRANSLATE_NOOP( "QDate", "Wednesday" ), | ||
189 | QT_TRANSLATE_NOOP( "QDate", "Thursday" ), | ||
190 | QT_TRANSLATE_NOOP( "QDate", "Friday" ), | ||
191 | QT_TRANSLATE_NOOP( "QDate", "Saturday" ), | ||
192 | QT_TRANSLATE_NOOP( "QDate", "Sunday" ) | ||
193 | }; | ||
194 | |||
195 | #ifdef QTOPIA_DESKTOP | ||
196 | //translations in qt.qm | ||
197 | static const char* unTranslatedMediumDayNames[] = { | ||
198 | "Mon" , "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" | ||
199 | }; | ||
200 | |||
201 | static const char* unTranslatedMediumMonthNames[] = { | ||
202 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | ||
203 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | ||
204 | }; | ||
205 | #endif | ||
206 | |||
207 | static QString dayname(const QDate& d, bool lng) | ||
208 | { | ||
209 | if (lng && qApp) | ||
210 | return qApp->translate("QDate", unTranslatedFullDayNames[d.dayOfWeek()-1]); | ||
211 | else { | ||
212 | #ifdef QTOPIA_DESKTOP | ||
213 | if (qApp) | ||
214 | return qApp->translate("QDate", unTranslatedMediumDayNames[ d.dayOfWeek()-1]); | ||
215 | #endif | ||
216 | return d.dayName(d.dayOfWeek()); | ||
217 | } | ||
218 | } | ||
219 | |||
152 | QString DateFormat::wordDate(const QDate &d, int v) const | 220 | QString DateFormat::wordDate(const QDate &d, int v) const |
153 | { | 221 | { |
154 | QString buf = ""; | ||
155 | // for each part of the order | 222 | // for each part of the order |
156 | if (v & showWeekDay) { | 223 | QString weekDay; |
157 | QString weekDay = d.dayName(d.dayOfWeek()); | 224 | if (v & showWeekDay) |
158 | if (!(v & longWord)) { | 225 | weekDay = ::dayname(d,(v & longWord)); |
159 | weekDay = weekDay.left(3); | ||
160 | } | ||
161 | buf += weekDay; | ||
162 | if ((_longOrder & 0x0007) == 0x0002) | ||
163 | buf += ' '; | ||
164 | else | ||
165 | buf += ", "; | ||
166 | } | ||
167 | 226 | ||
227 | QString date=""; | ||
228 | QString sep=""; | ||
168 | for (int i = 0; i < 3; i++) { | 229 | for (int i = 0; i < 3; i++) { |
169 | // switch on the relavent 3 bits. | 230 | // switch on the relavent 3 bits. |
170 | switch((_longOrder >> (i * 3)) & 0x0007) { | 231 | int field = (_longOrder >> (i * 3)) & 0x0007; |
171 | case 0x0001: | 232 | if ( field && !date.isEmpty() ) |
172 | if (i==1) { | 233 | date += sep; |
173 | buf += QString().sprintf("%02d, ",d.day()); | 234 | switch (field) { |
174 | } else { | 235 | case 0x0001: // Day |
175 | buf += QString().sprintf("%2d",d.day()); | 236 | { |
176 | if (separator()=='.') // 2002/1/11 | 237 | QString daysuffix = TimeStringFormat::tr("@day", "day suffix - applies to some asian languages (e.g. Japanese and Trad. Chinese). If it doesn't apply to your language it has to be translated to an '@day' " ); |
177 | buf += ". "; | 238 | if (i==1) { |
178 | else | 239 | date += QString().sprintf("%02d",d.day()); |
179 | buf += " "; | 240 | if (daysuffix != "@day") |
180 | } | 241 | date+=daysuffix; |
242 | sep = TimeStringFormat::tr(",","day-date separator") + " "; | ||
243 | } else { | ||
244 | date += QString().sprintf("%2d",d.day()); | ||
245 | if (daysuffix == "@day") { | ||
246 | if (separator()=='.') // 2002/1/11 | ||
247 | sep = ". "; | ||
248 | else | ||
249 | sep = " "; | ||
250 | } else { | ||
251 | date += daysuffix+" "; | ||
252 | sep = " "; | ||
253 | } | ||
254 | } | ||
255 | } | ||
181 | break; | 256 | break; |
182 | case 0x0002: | 257 | case 0x0002: // Month |
183 | { | 258 | { |
184 | QString monthName = d.monthName(d.month()); | 259 | QString monthName; |
185 | if (!(v & longWord)) { | 260 | |
186 | monthName = monthName.left(3); | 261 | if (v & longWord) |
187 | } | 262 | monthName = qApp->translate("QDate", unTranslatedFullMonthNames[d.month()-1] ); |
188 | buf += monthName; | 263 | else { |
264 | #ifdef QTOPIA_DESKTOP | ||
265 | monthName = qApp->translate("QDate", unTranslatedMediumMonthNames[d.month()-1] ); | ||
266 | #else | ||
267 | monthName = d.monthName( d.month() ); | ||
268 | #endif | ||
269 | } | ||
270 | date += monthName; | ||
189 | } | 271 | } |
190 | if (i < 2) | 272 | sep = " ";//TimeStringFormat::tr(" ","month-date separator"); |
191 | buf += " "; | ||
192 | break; | 273 | break; |
193 | case 0x0004: | 274 | case 0x0004: // Year |
194 | { | 275 | { |
195 | int year = d.year(); | 276 | int year = d.year(); |
196 | if (!(v & longNumber)) | 277 | if (!(v & longNumber)) |
197 | year = year % 100; | 278 | year = year % 100; |
198 | 279 | ||
199 | if (year < 10) | 280 | if (year < 10) |
200 | buf += "0"; | 281 | date += "0"; |
282 | |||
283 | date += QString::number(year); | ||
284 | QString yearsuffix = TimeStringFormat::tr("@year", "year suffix - applies to some asian languages (e.g. Japanese and Trad. Chinese). If it doesn't apply to your language it has to be translated to an '@year' " ); | ||
285 | if (yearsuffix != "@year") | ||
286 | date += yearsuffix; | ||
201 | 287 | ||
202 | buf += QString::number(year); | ||
203 | } | 288 | } |
204 | if (i < 2) | 289 | sep = TimeStringFormat::tr(",","year-date seperator") + " "; |
205 | buf += ", "; | ||
206 | break; | 290 | break; |
207 | } | 291 | } |
208 | } | 292 | } |
209 | return buf; | 293 | |
294 | QString r = ""; | ||
295 | if ( weekDay.isEmpty() ) | ||
296 | r = date; | ||
297 | else if ((_longOrder & 0x0007) == 0x0002) | ||
298 | r = TimeStringFormat::tr("%1 %2","1=Monday 2=January 12").arg(weekDay).arg(date); | ||
299 | else if ( _longOrder ) | ||
300 | r = TimeStringFormat::tr("%1, %2","1=Monday 2=12 January").arg(weekDay).arg(date); | ||
301 | else | ||
302 | r = weekDay; | ||
303 | return r; | ||
210 | } | 304 | } |
211 | 305 | ||
212 | #ifndef QT_NO_DATASTREAM | 306 | #ifndef QT_NO_DATASTREAM |
213 | void DateFormat::save(QDataStream &d) const | 307 | void DateFormat::save(QDataStream &d) const |
214 | { | 308 | { |
215 | d << _shortSeparator.unicode(); | 309 | d << _shortSeparator.unicode(); |
216 | uint v= _shortOrder; | 310 | uint v= _shortOrder; |
217 | d << v; | 311 | d << v; |
218 | v = _longOrder; | 312 | v = _longOrder; |
219 | d << v; | 313 | d << v; |
220 | } | 314 | } |
221 | 315 | ||
222 | void DateFormat::load(QDataStream &d) | 316 | void DateFormat::load(QDataStream &d) |
223 | { | 317 | { |
224 | ushort value; | 318 | ushort value; |
225 | d >> value; | 319 | d >> value; |
@@ -238,45 +332,45 @@ QDataStream &operator<<(QDataStream &s, const DateFormat&df) | |||
238 | return s; | 332 | return s; |
239 | } | 333 | } |
240 | QDataStream &operator>>(QDataStream &s, DateFormat&df) | 334 | QDataStream &operator>>(QDataStream &s, DateFormat&df) |
241 | { | 335 | { |
242 | df.load(s); | 336 | df.load(s); |
243 | return s; | 337 | return s; |
244 | } | 338 | } |
245 | #endif | 339 | #endif |
246 | 340 | ||
247 | QString TimeString::shortDate( const QDate &d, DateFormat dtf ) | 341 | QString TimeString::shortDate( const QDate &d, DateFormat dtf ) |
248 | { | 342 | { |
249 | return dtf.wordDate(d); | 343 | return dtf.wordDate(d); |
250 | } | 344 | } |
251 | 345 | ||
252 | QString TimeString::dateString( const QDate &d, DateFormat dtf ) | 346 | QString TimeString::dateString( const QDate &d, DateFormat dtf ) |
253 | { | 347 | { |
254 | return QObject::tr( dtf.wordDate(d, DateFormat::longNumber | DateFormat::longWord) ); | 348 | return dtf.wordDate(d, DateFormat::longNumber); |
255 | } | 349 | } |
256 | 350 | ||
257 | 351 | ||
258 | QString TimeString::longDateString( const QDate &d, DateFormat dtf ) | 352 | QString TimeString::longDateString( const QDate &d, DateFormat dtf ) |
259 | { | 353 | { |
260 | return QObject::tr( dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber | 354 | return dtf.wordDate(d, DateFormat::showWeekDay | DateFormat::longNumber |
261 | | DateFormat::longWord) ); | 355 | | DateFormat::longWord); |
262 | } | 356 | } |
263 | 357 | ||
264 | DateFormat TimeString::currentDateFormat() | 358 | DateFormat TimeString::currentDateFormat() |
265 | { | 359 | { |
266 | return TimeStringFormatKeeper::currentFormat(); | 360 | return TimeStringFormat::currentFormat(); |
267 | } | 361 | } |
268 | 362 | ||
269 | 363 | ||
270 | QString TimeString::dateString( const QDateTime &dt, bool ampm, bool seconds, DateFormat dtf ) | 364 | QString TimeString::dateString( const QDateTime &dt, bool ampm, bool seconds, DateFormat dtf ) |
271 | { | 365 | { |
272 | const QDate& d = dt.date(); | 366 | const QDate& d = dt.date(); |
273 | const QTime& t = dt.time(); | 367 | const QTime& t = dt.time(); |
274 | 368 | ||
275 | // based on QDateTime::toString() | 369 | // based on QDateTime::toString() |
276 | QString buf = timeString(t,ampm,seconds); | 370 | QString buf = timeString(t,ampm,seconds); |
277 | buf += " "; | 371 | buf += " "; |
278 | buf += longDateString( d, dtf ); | 372 | buf += longDateString( d, dtf ); |
279 | 373 | ||
280 | return buf; | 374 | return buf; |
281 | } | 375 | } |
282 | 376 | ||
@@ -300,66 +394,73 @@ QString TimeString::timeString( const QTime &t, bool ampm, bool seconds ) | |||
300 | if ( hour > 12 ) | 394 | if ( hour > 12 ) |
301 | argString = argString.arg( hour - 12, 2 ); | 395 | argString = argString.arg( hour - 12, 2 ); |
302 | else { | 396 | else { |
303 | if ( hour == 0 ) | 397 | if ( hour == 0 ) |
304 | argString = argString.arg( 12 ); | 398 | argString = argString.arg( 12 ); |
305 | else | 399 | else |
306 | argString = argString.arg( hour, 2 ); | 400 | argString = argString.arg( hour, 2 ); |
307 | } | 401 | } |
308 | if ( t.minute() < 10 ) | 402 | if ( t.minute() < 10 ) |
309 | strMin.prepend( "0" ); | 403 | strMin.prepend( "0" ); |
310 | if ( t.second() < 10 ) | 404 | if ( t.second() < 10 ) |
311 | strSec.prepend( "0" ); | 405 | strSec.prepend( "0" ); |
312 | argString = argString.arg( strMin ); | 406 | argString = argString.arg( strMin ); |
313 | if ( seconds ) | 407 | if ( seconds ) |
314 | argString = argString.arg( strSec ); | 408 | argString = argString.arg( strSec ); |
315 | if ( hour >= 12 ) | 409 | if ( hour >= 12 ) |
316 | argString = argString.arg( QObject::tr("PM") ); | 410 | argString = argString.arg( TimeStringFormat::tr("PM") ); |
317 | else | 411 | else |
318 | argString = argString.arg( QObject::tr("AM") ); | 412 | argString = argString.arg( TimeStringFormat::tr("AM") ); |
319 | return argString; | 413 | return argString; |
320 | } | 414 | } |
321 | 415 | ||
322 | QString TimeString::shortTime( bool ampm, bool seconds ) | 416 | QString TimeString::shortTime( bool ampm, bool seconds ) |
323 | { | 417 | { |
324 | static const char* const day[] = { | ||
325 | QT_TRANSLATE_NOOP( "QObject", "Mon" ), | ||
326 | QT_TRANSLATE_NOOP( "QObject", "Tue" ), | ||
327 | QT_TRANSLATE_NOOP( "QObject", "Wed" ), | ||
328 | QT_TRANSLATE_NOOP( "QObject", "Thu" ), | ||
329 | QT_TRANSLATE_NOOP( "QObject", "Fri" ), | ||
330 | QT_TRANSLATE_NOOP( "QObject", "Sat" ), | ||
331 | QT_TRANSLATE_NOOP( "QObject", "Sun" ) | ||
332 | }; | ||
333 | // just create a shorter time String | 418 | // just create a shorter time String |
334 | QDateTime dtTmp = QDateTime::currentDateTime(); | 419 | QDateTime dtTmp = QDateTime::currentDateTime(); |
335 | QString strTime; | 420 | QString strTime = TimeStringFormat::tr( "%1 %2", "1=Monday 2=12:45" ) |
336 | strTime = QObject::tr( day[dtTmp.date().dayOfWeek()-1] ) + " " + | 421 | .arg(::dayname(dtTmp.date(),FALSE)) |
337 | timeString( dtTmp.time(), ampm, seconds ); | 422 | .arg(timeString( dtTmp.time(), ampm, seconds )); |
338 | return strTime; | 423 | return strTime; |
339 | } | 424 | } |
340 | 425 | ||
341 | QString TimeString::dateString( const QDateTime &t, bool ampm ) | 426 | QString TimeString::dateString( const QDateTime &t, bool ampm ) |
342 | { | 427 | { |
343 | return dateString(t,ampm,FALSE); | 428 | return dateString(t,ampm,FALSE); |
344 | } | 429 | } |
345 | 430 | ||
346 | QString TimeString::timeString( const QTime &t, bool ampm) | 431 | QString TimeString::timeString( const QTime &t, bool ampm) |
347 | { | 432 | { |
348 | return timeString(t,ampm,FALSE); | 433 | return timeString(t,ampm,FALSE); |
349 | } | 434 | } |
350 | 435 | ||
351 | QString TimeString::shortTime( bool ampm ) | 436 | QString TimeString::shortTime( bool ampm ) |
352 | { | 437 | { |
353 | return shortTime(ampm,FALSE); | 438 | return shortTime(ampm,FALSE); |
354 | } | 439 | } |
355 | 440 | ||
356 | QString TimeString::numberDateString( const QDate &d, DateFormat dtf ) | 441 | QString TimeString::numberDateString( const QDate &d, DateFormat dtf ) |
357 | { | 442 | { |
358 | return dtf.numberDate(d); | 443 | return dtf.numberDate(d); |
359 | } | 444 | } |
360 | QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf ) | 445 | QString TimeString::longNumberDateString( const QDate &d, DateFormat dtf ) |
361 | { | 446 | { |
362 | return dtf.numberDate(d,DateFormat::longNumber); | 447 | return dtf.numberDate(d,DateFormat::longNumber); |
363 | } | 448 | } |
449 | /*! | ||
450 | Returns date/time \a dt as a string, | ||
451 | showing year, month, date, hours, minutes, and seconds. | ||
452 | \a len determines the length of the resulting string. | ||
453 | |||
454 | The format, including order depends on the user's settings. | ||
455 | |||
456 | First availability: Qtopia 1.6 | ||
457 | */ | ||
458 | //QString TimeString::localYMDHMS( const QDateTime &dt, Length len ) | ||
459 | //{ | ||
460 | // const QDate& d = dt.date(); | ||
461 | // const QTime& t = dt.time(); | ||
462 | // return LocalTimeFormat::tr("%1 %2","date,time").arg(localYMD(d,len)).arg(localHMS(t)); | ||
463 | //} | ||
464 | |||
364 | 465 | ||
365 | #include "timestring.moc" | 466 | #include "timestring.moc" |