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.h | |
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.h | 94 |
1 files changed, 63 insertions, 31 deletions
diff --git a/library/timestring.h b/library/timestring.h index 875c8bf..b8d1aea 100644 --- a/library/timestring.h +++ b/library/timestring.h | |||
@@ -1,150 +1,182 @@ | |||
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 | ** | ||
6 | ** This program is free software; you can redistribute it and/or modify it | ||
7 | ** under the terms of the GNU General Public License as published by the | ||
8 | ** Free Software Foundation; either version 2 of the License, or (at your | ||
9 | ** option) any later version. | ||
10 | ** | ||
11 | ** A copy of the GNU GPL license version 2 is included in this package as | ||
12 | ** LICENSE.GPL. | ||
5 | ** | 13 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 14 | ** This program is distributed in the hope that it will be useful, but |
7 | ** GNU General Public License version 2 as published by the Free Software | 15 | ** WITHOUT ANY WARRANTY; without even the implied warranty of |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 16 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
9 | ** packaging of this file. | 17 | ** See the GNU General Public License for more details. |
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | 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. | ||
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 | #ifndef _TIMESTRING_H_ | 36 | #ifndef _TIMESTRING_H_ |
22 | #define _TIMESTRING_H_ | 37 | #define _TIMESTRING_H_ |
23 | #include <qdatetime.h> | 38 | #include <qdatetime.h> |
24 | #include <qstring.h> | 39 | #include <qstring.h> |
40 | #include <qarray.h> | ||
25 | 41 | ||
26 | #if (QT_VERSION-0 >= 0x030000) | 42 | #if (QT_VERSION-0 >= 0x030000) |
27 | #define DateFormat QPEDateFormat | 43 | #define DateFormat QPEDateFormat |
28 | #endif | 44 | #endif |
29 | 45 | ||
46 | #include <qtopia/qpeglobal.h> | ||
47 | |||
48 | class QObject; | ||
49 | |||
30 | // return a string with the time based on whether or not you want | 50 | // return a string with the time based on whether or not you want |
31 | // you want it in 12 hour form. if ampm is true, then return | 51 | // you want it in 12 hour form. if ampm is true, then return |
32 | // it in 12 hour (am/pm) form otherwise return it in 24 hour form | 52 | // it in 12 hour (am/pm) form otherwise return it in 24 hour form |
33 | // in theory Qt 3,0 handles this better (hopefully obsoleteing this) | 53 | // in theory Qt 3,0 handles this better (hopefully obsoleteing this) |
34 | class DateFormat | 54 | class DateFormat |
35 | { | 55 | { |
36 | public: | 56 | public: |
37 | // date format type 001,010,100 = day month year | 57 | // date format type 1,2,4 = day,month,year |
38 | enum Order { | 58 | enum Order { |
39 | DayMonthYear = 0x0111, // 0x001 + 0x010(0x2 << 3) + 0x100(0x4 << 3) | 59 | DayMonthYear = 0421, // right-to-left |
40 | MonthDayYear = 0x010A, | 60 | MonthDayYear = 0412, |
41 | YearMonthDay = 0x0054 | 61 | YearMonthDay = 0124 |
42 | }; | 62 | }; |
43 | 63 | ||
44 | DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so), | 64 | DateFormat(QChar s = '/', Order so = MonthDayYear) : _shortOrder(so), |
45 | _longOrder(so), _shortSeparator(s) { } | 65 | _longOrder(so), _shortSeparator(s) { } |
46 | DateFormat(QChar s, Order so, Order lo) : _shortOrder(so), | 66 | DateFormat(QChar s, Order so, Order lo) : _shortOrder(so), |
47 | _longOrder(lo), _shortSeparator(s) { } | 67 | _longOrder(lo), _shortSeparator(s) { } |
48 | DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder), | 68 | DateFormat(const DateFormat &o) : _shortOrder(o._shortOrder), |
49 | _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { } | 69 | _longOrder(o._longOrder), _shortSeparator(o._shortSeparator) { } |
50 | 70 | ||
51 | bool operator==(const DateFormat &o) | 71 | bool operator==(const DateFormat &o) |
52 | { | 72 | { |
53 | if (o._shortOrder == _shortOrder && o._longOrder == _longOrder && | 73 | if (o._shortOrder == _shortOrder && o._longOrder == _longOrder && |
54 | o._shortSeparator == _shortSeparator) | 74 | o._shortSeparator == _shortSeparator) |
55 | return TRUE; | 75 | return TRUE; |
56 | return FALSE; | 76 | return FALSE; |
57 | } | 77 | } |
58 | 78 | ||
59 | // verbosity specifiers | 79 | // verbosity specifiers |
60 | enum Verbosity { | 80 | enum Verbosity { |
61 | shortNumber = 0x01, // default | 81 | shortNumber = 0x01, // default |
62 | longNumber = 0x02, | 82 | longNumber = 0x02, |
63 | 83 | ||
64 | padNumber = 0x04, | 84 | padNumber = 0x04, |
65 | 85 | ||
66 | shortWord = 0x08, // default | 86 | shortWord = 0x08, // default |
67 | longWord = 0x10, | 87 | longWord = 0x10, |
68 | 88 | ||
69 | showWeekDay = 0x20 | 89 | showWeekDay = 0x20 |
70 | }; | 90 | }; |
71 | 91 | ||
72 | QString toNumberString() const; // the M/D/Y string. | 92 | QString toNumberString() const; // the M/D/Y string. |
73 | QString toWordString() const; // the Month day, year string. | 93 | QString toWordString() const; // the Month day, year string. |
74 | 94 | ||
75 | QString numberDate(const QDate &d, int v = 0) const; | 95 | QString numberDate(const QDate &d, int v = 0) const; |
76 | QString wordDate(const QDate &d, int v = 0) const; | 96 | QString wordDate(const QDate &d, int v = 0) const; |
77 | 97 | ||
78 | #ifndef QT_NO_DATASTREAM | 98 | #ifndef QT_NO_DATASTREAM |
79 | void load(QDataStream&); | 99 | void load(QDataStream&); |
80 | void save(QDataStream&) const; | 100 | void save(QDataStream&) const; |
81 | #endif | 101 | #endif |
82 | 102 | ||
83 | QChar separator() const { return _shortSeparator; }; | 103 | QChar separator() const { return _shortSeparator; }; |
84 | Order shortOrder() const { return _shortOrder; }; | 104 | Order shortOrder() const { return _shortOrder; }; |
85 | Order longOrder() const { return _longOrder; }; | 105 | Order longOrder() const { return _longOrder; }; |
86 | 106 | ||
87 | private: | 107 | private: |
88 | Order _shortOrder; | 108 | Order _shortOrder; |
89 | Order _longOrder; | 109 | Order _longOrder; |
90 | QChar _shortSeparator; | 110 | QChar _shortSeparator; |
91 | }; | 111 | }; |
92 | 112 | ||
93 | #ifndef QT_NO_DATASTREAM | 113 | #ifndef QT_NO_DATASTREAM |
94 | QDataStream &operator<<(QDataStream &s, const DateFormat&df); | 114 | QDataStream &operator<<(QDataStream &s, const DateFormat&df); |
95 | QDataStream &operator>>(QDataStream &s, DateFormat&df); | 115 | QDataStream &operator>>(QDataStream &s, DateFormat&df); |
96 | #endif | 116 | #endif |
97 | 117 | ||
98 | class TimeString | 118 | class TimeString |
99 | { | 119 | { |
100 | public: | 120 | public: |
101 | 121 | ||
102 | //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601, | 122 | //enum DateFormat { MonthDayYear, DayMonthYear, ISO8601, |
103 | //YearMonthDay = ISO8601 }; | 123 | //YearMonthDay = ISO8601 }; |
104 | 124 | ||
105 | /** | 125 | |
106 | * @name Convience functions which use currentDateFormat | 126 | //private: |
107 | */ | 127 | static QString shortDate( const QDate &d ) |
108 | //@{ | ||
109 | static QString shortDate( const QDate &d ) | ||
110 | { return shortDate( d, currentDateFormat() ); } | 128 | { return shortDate( d, currentDateFormat() ); } |
111 | static QString dateString( const QDate &d ) | 129 | static QString dateString( const QDate &d ) |
112 | { return dateString( d, currentDateFormat() ); } | 130 | { return dateString( d, currentDateFormat() ); } |
113 | static QString longDateString( const QDate &d ) | 131 | static QString longDateString( const QDate &d ) |
114 | { return longDateString( d, currentDateFormat() ); } | 132 | { return longDateString( d, currentDateFormat() ); } |
115 | //@} | ||
116 | static QString dateString( const QDateTime &dt, bool ampm, bool seconds ) | 133 | static QString dateString( const QDateTime &dt, bool ampm, bool seconds ) |
117 | { return dateString( dt, ampm, seconds, currentDateFormat() ); } | 134 | { return dateString( dt, ampm, seconds, currentDateFormat() ); } |
118 | 135 | ||
136 | public: | ||
137 | enum Length { Short, Medium, Long }; | ||
138 | static QString localH( int hour ); | ||
139 | static QString localHM( const QTime & ); | ||
140 | static QString localHM( const QTime &, Length ); // qtopia 2.1.0 | ||
141 | static QString localHMS( const QTime & ); | ||
142 | static QString localHMDayOfWeek( const QDateTime &t ); | ||
143 | static QString localHMSDayOfWeek( const QDateTime &t ); | ||
144 | static QString localMD( const QDate &, Length=Medium ); | ||
145 | static QString localYMD( const QDate &, Length=Medium ); | ||
146 | static QString localYMDHMS( const QDateTime &, Length=Medium ); | ||
147 | static QString localDayOfWeek( const QDate&, Length=Medium ); | ||
148 | static QString localDayOfWeek( int day1to7, Length=Medium ); | ||
149 | |||
150 | static QString hourString( int hour, bool ampm ); | ||
151 | static bool currentAMPM(); | ||
152 | static DateFormat currentDateFormat(); | ||
153 | static QArray<DateFormat> formatOptions(); // qtopia 1.6.0 | ||
154 | |||
155 | static void connectChange(QObject*,const char* member); | ||
156 | static void disconnectChange(QObject*,const char* member); | ||
119 | 157 | ||
120 | /** @name Do not use as they don't honor system settings for AMPM | 158 | // Not recommended to call these (they don't honor system ampm) |
121 | * | 159 | static QString dateString( const QDateTime &t, bool ampm ); |
122 | */ | ||
123 | //@{ | ||
124 | static QString dateString( const QDateTime &t, bool ampm = false ); | ||
125 | static QString timeString( const QTime &t, bool ampm, bool seconds ); | 160 | static QString timeString( const QTime &t, bool ampm, bool seconds ); |
126 | static QString timeString( const QTime &t, bool ampm = false ); | 161 | static QString timeString( const QTime &t, bool ampm ); |
127 | static QString shortTime( bool ampm, bool seconds ); | 162 | static QString shortTime( bool ampm, bool seconds ); |
128 | static QString shortTime( bool ampm = false ); | 163 | static QString shortTime( bool ampm ); |
129 | //@} | ||
130 | 164 | ||
131 | static QString numberDateString( const QDate &d, DateFormat ); | 165 | static QString numberDateString( const QDate &d, DateFormat ); |
132 | static QString numberDateString( const QDate &d ) | 166 | static QString numberDateString( const QDate &d ) |
133 | { return numberDateString( d, currentDateFormat() ); } | 167 | { return numberDateString( d, currentDateFormat() ); } |
134 | static QString longNumberDateString( const QDate &d, DateFormat ); | 168 | static QString longNumberDateString( const QDate &d, DateFormat ); |
135 | static QString longNumberDateString( const QDate &d ) | 169 | static QString longNumberDateString( const QDate &d ) |
136 | { return longNumberDateString( d, currentDateFormat() ); } | 170 | { return longNumberDateString( d, currentDateFormat() ); } |
137 | 171 | ||
138 | static QString shortDate( const QDate &, DateFormat ); | 172 | static QString shortDate( const QDate &, DateFormat ); |
139 | static QString dateString( const QDate &, DateFormat ); | 173 | static QString dateString( const QDate &, DateFormat ); |
140 | static QString longDateString( const QDate &, DateFormat ); | 174 | static QString longDateString( const QDate &, DateFormat ); |
141 | 175 | ||
142 | static DateFormat currentDateFormat(); | ||
143 | |||
144 | private: | 176 | private: |
145 | static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat ); | 177 | static QString dateString( const QDateTime &t, bool ampm, bool seconds, DateFormat ); |
146 | 178 | ||
147 | 179 | ||
148 | }; | 180 | }; |
149 | 181 | ||
150 | #endif | 182 | #endif |