author | harlekin <harlekin> | 2003-02-11 18:37:03 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2003-02-11 18:37:03 (UTC) |
commit | cb85b004afe2750733cef1663961539f6a3968e6 (patch) (unidiff) | |
tree | 6084bf1fb78375325938f96077e0faa03ece955f | |
parent | ec6795c6a15a3b9f4721b628d48366097da9c903 (diff) | |
download | opie-cb85b004afe2750733cef1663961539f6a3968e6.zip opie-cb85b004afe2750733cef1663961539f6a3968e6.tar.gz opie-cb85b004afe2750733cef1663961539f6a3968e6.tar.bz2 |
fix bug #644, ampm vs 24 h handling
-rw-r--r-- | core/settings/citytime/citytime.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/core/settings/citytime/citytime.cpp b/core/settings/citytime/citytime.cpp index 5dc9b02..b359ae1 100644 --- a/core/settings/citytime/citytime.cpp +++ b/core/settings/citytime/citytime.cpp | |||
@@ -1,282 +1,284 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 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. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | // changes by Maximilian Reiss <harlekin@handhelds.org> | 21 | // changes by Maximilian Reiss <harlekin@handhelds.org> |
22 | 22 | ||
23 | #include "zonemap.h" | 23 | #include "zonemap.h" |
24 | #include "citytime.h" | 24 | #include "citytime.h" |
25 | 25 | ||
26 | #include <qpe/qpeapplication.h> | 26 | #include <qpe/qpeapplication.h> |
27 | #include <qpe/config.h> | 27 | #include <qpe/config.h> |
28 | #include <qpe/timestring.h> | 28 | #include <qpe/timestring.h> |
29 | #include <qpe/tzselect.h> | 29 | #include <qpe/tzselect.h> |
30 | #if !defined(QT_NO_COP) | 30 | #if !defined(QT_NO_COP) |
31 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #include <qdir.h> | 34 | #include <qdir.h> |
35 | #include <qfile.h> | 35 | #include <qfile.h> |
36 | #include <qlabel.h> | 36 | #include <qlabel.h> |
37 | #include <qmessagebox.h> | 37 | #include <qmessagebox.h> |
38 | #include <qregexp.h> | 38 | #include <qregexp.h> |
39 | #include <qtextstream.h> | 39 | #include <qtextstream.h> |
40 | #include <qtoolbutton.h> | 40 | #include <qtoolbutton.h> |
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | 42 | ||
43 | #include <stdlib.h> | 43 | #include <stdlib.h> |
44 | 44 | ||
45 | CityTime::CityTime( QWidget *parent, const char* name, | 45 | CityTime::CityTime( QWidget *parent, const char* name, |
46 | WFlags fl ) | 46 | WFlags fl ) |
47 | : CityTimeBase( parent, name, fl ), | 47 | : CityTimeBase( parent, name, fl ), |
48 | strRealTz(0), | 48 | strRealTz(0), |
49 | bAdded(false) | 49 | bAdded(false) |
50 | { | 50 | { |
51 | Config config( "qpe" ); | 51 | Config config( "qpe" ); |
52 | config.setGroup( "Time" ); | ||
52 | bWhichClock = config.readBoolEntry( "AMPM", TRUE ); | 53 | bWhichClock = config.readBoolEntry( "AMPM", TRUE ); |
54 | qDebug( QString("%1").arg(bWhichClock) ); | ||
53 | frmMap->changeClock( bWhichClock ); | 55 | frmMap->changeClock( bWhichClock ); |
54 | 56 | ||
55 | char *pEnv; | 57 | char *pEnv; |
56 | pEnv = NULL; | 58 | pEnv = NULL; |
57 | pEnv = getenv("TZ"); | 59 | pEnv = getenv("TZ"); |
58 | if ( pEnv ) | 60 | if ( pEnv ) |
59 | strRealTz = pEnv; | 61 | strRealTz = pEnv; |
60 | pEnv = NULL; | 62 | pEnv = NULL; |
61 | pEnv = getenv("HOME"); | 63 | pEnv = getenv("HOME"); |
62 | if ( pEnv ) | 64 | if ( pEnv ) |
63 | strHome = pEnv; | 65 | strHome = pEnv; |
64 | // append the labels to their respective lists... | 66 | // append the labels to their respective lists... |
65 | listCities.setAutoDelete( true ); | 67 | listCities.setAutoDelete( true ); |
66 | listTimes.setAutoDelete( true ); | 68 | listTimes.setAutoDelete( true ); |
67 | 69 | ||
68 | listCities.append( cmdCity1 ); | 70 | listCities.append( cmdCity1 ); |
69 | listCities.append( cmdCity2 ); | 71 | listCities.append( cmdCity2 ); |
70 | listCities.append( cmdCity3 ); | 72 | listCities.append( cmdCity3 ); |
71 | 73 | ||
72 | listTimes.append( lblCTime1 ); | 74 | listTimes.append( lblCTime1 ); |
73 | listTimes.append( lblCTime2 ); | 75 | listTimes.append( lblCTime2 ); |
74 | listTimes.append( lblCTime3 ); | 76 | listTimes.append( lblCTime3 ); |
75 | 77 | ||
76 | 78 | ||
77 | // kludgy way of getting the screen size so we don't have to depend | 79 | // kludgy way of getting the screen size so we don't have to depend |
78 | // on a resize event... | 80 | // on a resize event... |
79 | QWidget *d = QApplication::desktop(); | 81 | QWidget *d = QApplication::desktop(); |
80 | if ( d->width() < d->height() ) { | 82 | if ( d->width() < d->height() ) { |
81 | // append for that 4 down look | 83 | // append for that 4 down look |
82 | listCities.append( cmdCity4 ); | 84 | listCities.append( cmdCity4 ); |
83 | listCities.append( cmdCity5 ); | 85 | listCities.append( cmdCity5 ); |
84 | listCities.append( cmdCity6 ); | 86 | listCities.append( cmdCity6 ); |
85 | listTimes.append( lblCTime4 ); | 87 | listTimes.append( lblCTime4 ); |
86 | listTimes.append( lblCTime5 ); | 88 | listTimes.append( lblCTime5 ); |
87 | listTimes.append( lblCTime6 ); | 89 | listTimes.append( lblCTime6 ); |
88 | lblCTime7->hide(); | 90 | lblCTime7->hide(); |
89 | lblCTime8->hide(); | 91 | lblCTime8->hide(); |
90 | lblCTime9->hide(); | 92 | lblCTime9->hide(); |
91 | cmdCity7->hide(); | 93 | cmdCity7->hide(); |
92 | cmdCity8->hide(); | 94 | cmdCity8->hide(); |
93 | cmdCity9->hide(); | 95 | cmdCity9->hide(); |
94 | } else { | 96 | } else { |
95 | listCities.append( cmdCity7 ); | 97 | listCities.append( cmdCity7 ); |
96 | listCities.append( cmdCity8 ); | 98 | listCities.append( cmdCity8 ); |
97 | listCities.append( cmdCity9 ); | 99 | listCities.append( cmdCity9 ); |
98 | listTimes.append( lblCTime7 ); | 100 | listTimes.append( lblCTime7 ); |
99 | listTimes.append( lblCTime8 ); | 101 | listTimes.append( lblCTime8 ); |
100 | listTimes.append( lblCTime9 ); | 102 | listTimes.append( lblCTime9 ); |
101 | lblCTime4->hide(); | 103 | lblCTime4->hide(); |
102 | lblCTime5->hide(); | 104 | lblCTime5->hide(); |
103 | lblCTime6->hide(); | 105 | lblCTime6->hide(); |
104 | cmdCity4->hide(); | 106 | cmdCity4->hide(); |
105 | cmdCity5->hide(); | 107 | cmdCity5->hide(); |
106 | cmdCity6->hide(); | 108 | cmdCity6->hide(); |
107 | } | 109 | } |
108 | 110 | ||
109 | selWidget = frmMap->selectionWidget( this ); | 111 | selWidget = frmMap->selectionWidget( this ); |
110 | selWidget->hide(); | 112 | selWidget->hide(); |
111 | CityTimeBaseLayout->addWidget( selWidget ); | 113 | CityTimeBaseLayout->addWidget( selWidget ); |
112 | bAdded = true; | 114 | bAdded = true; |
113 | readInTimes(); | 115 | readInTimes(); |
114 | changed = FALSE; | 116 | changed = FALSE; |
115 | QObject::connect( qApp, SIGNAL( clockChanged( bool ) ), | 117 | QObject::connect( qApp, SIGNAL( clockChanged( bool ) ), |
116 | this, SLOT( changeClock( bool ) ) ); | 118 | this, SLOT( changeClock( bool ) ) ); |
117 | // now start the timer so we can update the time quickly every second | 119 | // now start the timer so we can update the time quickly every second |
118 | timerEvent( 0 ); | 120 | timerEvent( 0 ); |
119 | } | 121 | } |
120 | 122 | ||
121 | CityTime::~CityTime() | 123 | CityTime::~CityTime() |
122 | { | 124 | { |
123 | if ( changed ) { | 125 | if ( changed ) { |
124 | Config cfg("CityTime"); | 126 | Config cfg("CityTime"); |
125 | cfg.setGroup("TimeZones"); | 127 | cfg.setGroup("TimeZones"); |
126 | QListIterator<QToolButton> itCity( listCities ); | 128 | QListIterator<QToolButton> itCity( listCities ); |
127 | int i; | 129 | int i; |
128 | bool realTzWritten = FALSE; | 130 | bool realTzWritten = FALSE; |
129 | for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { | 131 | for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { |
130 | if ( !strCityTz[i].isNull() ) { | 132 | if ( !strCityTz[i].isNull() ) { |
131 | cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); | 133 | cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); |
132 | cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); | 134 | cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); |
133 | if ( strCityTz[i] == strRealTz ) | 135 | if ( strCityTz[i] == strRealTz ) |
134 | realTzWritten = TRUE; | 136 | realTzWritten = TRUE; |
135 | } | 137 | } |
136 | } | 138 | } |
137 | if ( realTzWritten ) { | 139 | if ( realTzWritten ) { |
138 | cfg.removeEntry("Zone"+QString::number(CITIES)); | 140 | cfg.removeEntry("Zone"+QString::number(CITIES)); |
139 | cfg.removeEntry("ZoneName"+QString::number(CITIES)); | 141 | cfg.removeEntry("ZoneName"+QString::number(CITIES)); |
140 | } else { | 142 | } else { |
141 | cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); | 143 | cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); |
142 | if ( nameRealTz.isEmpty() ) { | 144 | if ( nameRealTz.isEmpty() ) { |
143 | int i = strRealTz.find( '/' ); | 145 | int i = strRealTz.find( '/' ); |
144 | nameRealTz = strRealTz.mid( i+1 ); | 146 | nameRealTz = strRealTz.mid( i+1 ); |
145 | } | 147 | } |
146 | cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); | 148 | cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); |
147 | } | 149 | } |
148 | QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); | 150 | QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); |
149 | 151 | ||
150 | changed = FALSE; | 152 | changed = FALSE; |
151 | } | 153 | } |
152 | // restore the timezone, just in case we messed with it and | 154 | // restore the timezone, just in case we messed with it and |
153 | // are destroyed at an inoppurtune moment | 155 | // are destroyed at an inoppurtune moment |
154 | if ( !strRealTz.isNull() ) { | 156 | if ( !strRealTz.isNull() ) { |
155 | // this should be checked, but there is not much that can done at this | 157 | // this should be checked, but there is not much that can done at this |
156 | //point if it fails | 158 | //point if it fails |
157 | setenv( "TZ", strRealTz, true ); | 159 | setenv( "TZ", strRealTz, true ); |
158 | } | 160 | } |
159 | } | 161 | } |
160 | 162 | ||
161 | void CityTime::timerEvent( QTimerEvent *e ) | 163 | void CityTime::timerEvent( QTimerEvent *e ) |
162 | { | 164 | { |
163 | if ( e ) | 165 | if ( e ) |
164 | killTimer( timerId ); | 166 | killTimer( timerId ); |
165 | // change the time again!! | 167 | // change the time again!! |
166 | showTime(); | 168 | showTime(); |
167 | int ms = 1000 - QTime::currentTime().msec(); | 169 | int ms = 1000 - QTime::currentTime().msec(); |
168 | timerId = startTimer( ms ); | 170 | timerId = startTimer( ms ); |
169 | } | 171 | } |
170 | 172 | ||
171 | void CityTime::mousePressEvent( QMouseEvent * ) | 173 | void CityTime::mousePressEvent( QMouseEvent * ) |
172 | { | 174 | { |
173 | // DEBUG enable this to get a look at the zone information DEBUG | 175 | // DEBUG enable this to get a look at the zone information DEBUG |
174 | // frmMap->showZones(); | 176 | // frmMap->showZones(); |
175 | } | 177 | } |
176 | 178 | ||
177 | void CityTime::showTime( void ) | 179 | void CityTime::showTime( void ) |
178 | { | 180 | { |
179 | int i; | 181 | int i; |
180 | QListIterator<QLabel> itTime(listTimes); | 182 | QListIterator<QLabel> itTime(listTimes); |
181 | 183 | ||
182 | // traverse the list... | 184 | // traverse the list... |
183 | for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) { | 185 | for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) { |
184 | if ( !strCityTz[i].isNull() ) { | 186 | if ( !strCityTz[i].isNull() ) { |
185 | if ( setenv( "TZ", strCityTz[i], true ) == 0 ) { | 187 | if ( setenv( "TZ", strCityTz[i], true ) == 0 ) { |
186 | itTime.current()->setText( TimeString::shortTime(bWhichClock) ); | 188 | itTime.current()->setText( TimeString::shortTime( bWhichClock ) ); |
187 | } else { | 189 | } else { |
188 | QMessageBox::critical( this, tr( "Time Changing" ), | 190 | QMessageBox::critical( this, tr( "Time Changing" ), |
189 | tr( "There was a problem setting timezone %1" ) | 191 | tr( "There was a problem setting timezone %1" ) |
190 | .arg( QString::number( i + 1 ) ) ); | 192 | .arg( QString::number( i + 1 ) ) ); |
191 | } | 193 | } |
192 | } | 194 | } |
193 | } | 195 | } |
194 | // done playing around... put it all back | 196 | // done playing around... put it all back |
195 | unsetenv( "TZ" ); | 197 | unsetenv( "TZ" ); |
196 | if ( !strRealTz.isNull() ) { | 198 | if ( !strRealTz.isNull() ) { |
197 | if ( setenv( "TZ", strRealTz, true ) != 0 ) { | 199 | if ( setenv( "TZ", strRealTz, true ) != 0 ) { |
198 | QMessageBox::critical( this, tr( "Restore Time Zone" ), | 200 | QMessageBox::critical( this, tr( "Restore Time Zone" ), |
199 | tr( "There was a problem setting your timezone." | 201 | tr( "There was a problem setting your timezone." |
200 | "Your time may be wrong now..." ) ); | 202 | "Your time may be wrong now..." ) ); |
201 | } | 203 | } |
202 | } | 204 | } |
203 | } | 205 | } |
204 | 206 | ||
205 | void CityTime::beginNewTz() | 207 | void CityTime::beginNewTz() |
206 | { | 208 | { |
207 | buttonWidget->hide(); | 209 | buttonWidget->hide(); |
208 | frmMap->setFocus(); | 210 | frmMap->setFocus(); |
209 | selWidget->show(); | 211 | selWidget->show(); |
210 | // CityTimeBaseLayout->addWidget( selWidget ); | 212 | // CityTimeBaseLayout->addWidget( selWidget ); |
211 | } | 213 | } |
212 | 214 | ||
213 | void CityTime::slotNewTz( const QString & strNewCountry, | 215 | void CityTime::slotNewTz( const QString & strNewCountry, |
214 | const QString & strNewCity ) | 216 | const QString & strNewCity ) |
215 | { | 217 | { |
216 | // determine what to do based on what putton is pressed... | 218 | // determine what to do based on what putton is pressed... |
217 | QListIterator<QToolButton> itCity(listCities); | 219 | QListIterator<QToolButton> itCity(listCities); |
218 | int i; | 220 | int i; |
219 | // go through the list and make adjustments based on which button is on | 221 | // go through the list and make adjustments based on which button is on |
220 | for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) { | 222 | for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) { |
221 | QToolButton *cmdTmp = itCity.current(); | 223 | QToolButton *cmdTmp = itCity.current(); |
222 | if ( cmdTmp->isOn() ) { | 224 | if ( cmdTmp->isOn() ) { |
223 | strCityTz[i] = strNewCountry + strNewCity; | 225 | strCityTz[i] = strNewCountry + strNewCity; |
224 | QString s = strNewCity; | 226 | QString s = strNewCity; |
225 | cmdTmp->setText( s.replace( QRegExp("_"), " " ) ); | 227 | cmdTmp->setText( s.replace( QRegExp("_"), " " ) ); |
226 | cmdTmp->toggle(); | 228 | cmdTmp->toggle(); |
227 | // we can actually break, since there is only one button | 229 | // we can actually break, since there is only one button |
228 | // that is ever pressed! | 230 | // that is ever pressed! |
229 | changed = TRUE; | 231 | changed = TRUE; |
230 | break; | 232 | break; |
231 | } | 233 | } |
232 | } | 234 | } |
233 | showTime(); | 235 | showTime(); |
234 | buttonWidget->show(); | 236 | buttonWidget->show(); |
235 | selWidget->hide(); | 237 | selWidget->hide(); |
236 | } | 238 | } |
237 | 239 | ||
238 | void CityTime::readInTimes( void ) | 240 | void CityTime::readInTimes( void ) |
239 | { | 241 | { |
240 | Config cfg("CityTime"); | 242 | Config cfg("CityTime"); |
241 | cfg.setGroup("TimeZones"); | 243 | cfg.setGroup("TimeZones"); |
242 | QListIterator<QToolButton> itCity( listCities ); | 244 | QListIterator<QToolButton> itCity( listCities ); |
243 | int i=0; | 245 | int i=0; |
244 | nameRealTz = QString::null; | 246 | nameRealTz = QString::null; |
245 | QString zn; | 247 | QString zn; |
246 | for ( ; i < CITIES ; i++ ) { | 248 | for ( ; i < CITIES ; i++ ) { |
247 | zn = cfg.readEntry("Zone"+QString::number(i), QString::null); | 249 | zn = cfg.readEntry("Zone"+QString::number(i), QString::null); |
248 | if ( zn.isNull() ) | 250 | if ( zn.isNull() ) |
249 | break; | 251 | break; |
250 | QString nm = cfg.readEntry("ZoneName"+QString::number(i)); | 252 | QString nm = cfg.readEntry("ZoneName"+QString::number(i)); |
251 | strCityTz[i] = zn; | 253 | strCityTz[i] = zn; |
252 | itCity.current()->setText(nm); | 254 | itCity.current()->setText(nm); |
253 | if ( zn == strRealTz ) | 255 | if ( zn == strRealTz ) |
254 | nameRealTz = nm; | 256 | nameRealTz = nm; |
255 | ++itCity; | 257 | ++itCity; |
256 | } | 258 | } |
257 | if ( i == 0 ) { | 259 | if ( i == 0 ) { |
258 | // write in our own in a shameless self promotion and some humor | 260 | // write in our own in a shameless self promotion and some humor |
259 | QStringList list = timezoneDefaults(); | 261 | QStringList list = timezoneDefaults(); |
260 | int i; | 262 | int i; |
261 | QStringList::Iterator it = list.begin(); | 263 | QStringList::Iterator it = list.begin(); |
262 | for ( i = 0, itCity.toFirst(); i < CITIES && itCity.current(); | 264 | for ( i = 0, itCity.toFirst(); i < CITIES && itCity.current(); |
263 | i++, ++itCity ) { | 265 | i++, ++itCity ) { |
264 | strCityTz[i] = *it++; | 266 | strCityTz[i] = *it++; |
265 | itCity.current()->setText( *it++ ); | 267 | itCity.current()->setText( *it++ ); |
266 | } | 268 | } |
267 | } | 269 | } |
268 | if ( nameRealTz.isEmpty() ) { | 270 | if ( nameRealTz.isEmpty() ) { |
269 | //remember the current time zone even if we don't have room | 271 | //remember the current time zone even if we don't have room |
270 | //to show it. | 272 | //to show it. |
271 | zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); | 273 | zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); |
272 | if ( zn == strRealTz ) | 274 | if ( zn == strRealTz ) |
273 | nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); | 275 | nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); |
274 | i++; | 276 | i++; |
275 | } | 277 | } |
276 | } | 278 | } |
277 | 279 | ||
278 | void CityTime::changeClock( bool newClock ) | 280 | void CityTime::changeClock( bool newClock ) |
279 | { | 281 | { |
280 | bWhichClock = newClock; | 282 | bWhichClock = newClock; |
281 | showTime(); | 283 | showTime(); |
282 | } | 284 | } |