Diffstat (limited to 'core/settings/citytime/citytime.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/settings/citytime/citytime.cpp | 94 |
1 files changed, 49 insertions, 45 deletions
diff --git a/core/settings/citytime/citytime.cpp b/core/settings/citytime/citytime.cpp index 721285d..d73bda1 100644 --- a/core/settings/citytime/citytime.cpp +++ b/core/settings/citytime/citytime.cpp | |||
@@ -14,48 +14,52 @@ | |||
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 | /* OPIE */ | ||
26 | #include <qpe/qpeapplication.h> | 27 | #include <qpe/qpeapplication.h> |
27 | #include <qpe/config.h> | 28 | #include <qpe/config.h> |
28 | #include <qpe/tzselect.h> | 29 | #include <qpe/tzselect.h> |
29 | #if !defined(QT_NO_COP) | 30 | #if !defined(QT_NO_COP) |
30 | #include <qpe/qcopenvelope_qws.h> | 31 | #include <qpe/qcopenvelope_qws.h> |
31 | #endif | 32 | #endif |
33 | #include <opie2/odebug.h> | ||
32 | 34 | ||
35 | /* QT */ | ||
33 | #include <qlabel.h> | 36 | #include <qlabel.h> |
34 | #include <qmessagebox.h> | 37 | #include <qmessagebox.h> |
35 | #include <qtoolbutton.h> | 38 | #include <qtoolbutton.h> |
36 | #include <qlayout.h> | 39 | #include <qlayout.h> |
37 | 40 | ||
41 | /* STD */ | ||
38 | #include <stdlib.h> | 42 | #include <stdlib.h> |
39 | 43 | ||
40 | CityTime::CityTime( QWidget *parent, const char* name, | 44 | CityTime::CityTime( QWidget *parent, const char* name, |
41 | WFlags fl ) | 45 | WFlags fl ) |
42 | : CityTimeBase( parent, name, fl ), | 46 | : CityTimeBase( parent, name, fl ), |
43 | strRealTz(0), | 47 | strRealTz(0), |
44 | bAdded(false) | 48 | bAdded(false) |
45 | { | 49 | { |
46 | Config config( "qpe" ); | 50 | Config config( "qpe" ); |
47 | config.setGroup( "Time" ); | 51 | config.setGroup( "Time" ); |
48 | bWhichClock = config.readBoolEntry( "AMPM", TRUE ); | 52 | bWhichClock = config.readBoolEntry( "AMPM", TRUE ); |
49 | qDebug( QString("%1").arg(bWhichClock) ); | 53 | odebug << QString("%1").arg(bWhichClock) << oendl; |
50 | frmMap->changeClock( bWhichClock ); | 54 | frmMap->changeClock( bWhichClock ); |
51 | 55 | ||
52 | char *pEnv; | 56 | char *pEnv; |
53 | pEnv = NULL; | 57 | pEnv = NULL; |
54 | pEnv = getenv("TZ"); | 58 | pEnv = getenv("TZ"); |
55 | if ( pEnv ) | 59 | if ( pEnv ) |
56 | strRealTz = pEnv; | 60 | strRealTz = pEnv; |
57 | pEnv = NULL; | 61 | pEnv = NULL; |
58 | pEnv = getenv("HOME"); | 62 | pEnv = getenv("HOME"); |
59 | if ( pEnv ) | 63 | if ( pEnv ) |
60 | strHome = pEnv; | 64 | strHome = pEnv; |
61 | // append the labels to their respective lists... | 65 | // append the labels to their respective lists... |
@@ -109,87 +113,87 @@ CityTime::CityTime( QWidget *parent, const char* name, | |||
109 | bAdded = true; | 113 | bAdded = true; |
110 | readInTimes(); | 114 | readInTimes(); |
111 | changed = FALSE; | 115 | changed = FALSE; |
112 | QObject::connect( qApp, SIGNAL( clockChanged(bool) ), | 116 | QObject::connect( qApp, SIGNAL( clockChanged(bool) ), |
113 | this, SLOT( changeClock(bool) ) ); | 117 | this, SLOT( changeClock(bool) ) ); |
114 | // now start the timer so we can update the time quickly every second | 118 | // now start the timer so we can update the time quickly every second |
115 | timerEvent( 0 ); | 119 | timerEvent( 0 ); |
116 | } | 120 | } |
117 | 121 | ||
118 | CityTime::~CityTime() | 122 | CityTime::~CityTime() |
119 | { | 123 | { |
120 | if ( changed ) { | 124 | if ( changed ) { |
121 | Config cfg("CityTime"); | 125 | Config cfg("CityTime"); |
122 | cfg.setGroup("TimeZones"); | 126 | cfg.setGroup("TimeZones"); |
123 | QListIterator<QToolButton> itCity( listCities ); | 127 | QListIterator<QToolButton> itCity( listCities ); |
124 | int i; | 128 | int i; |
125 | bool realTzWritten = FALSE; | 129 | bool realTzWritten = FALSE; |
126 | for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { | 130 | for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { |
127 | if ( !strCityTz[i].isNull() ) { | 131 | if ( !strCityTz[i].isNull() ) { |
128 | cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); | 132 | cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); |
129 | cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); | 133 | cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); |
130 | if ( strCityTz[i] == strRealTz ) | 134 | if ( strCityTz[i] == strRealTz ) |
131 | realTzWritten = TRUE; | 135 | realTzWritten = TRUE; |
132 | } | 136 | } |
133 | } | 137 | } |
134 | if ( realTzWritten ) { | 138 | if ( realTzWritten ) { |
135 | cfg.removeEntry("Zone"+QString::number(CITIES)); | 139 | cfg.removeEntry("Zone"+QString::number(CITIES)); |
136 | cfg.removeEntry("ZoneName"+QString::number(CITIES)); | 140 | cfg.removeEntry("ZoneName"+QString::number(CITIES)); |
137 | } else { | 141 | } else { |
138 | cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); | 142 | cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); |
139 | if ( nameRealTz.isEmpty() ) { | 143 | if ( nameRealTz.isEmpty() ) { |
140 | int i = strRealTz.find( '/' ); | 144 | int i = strRealTz.find( '/' ); |
141 | nameRealTz = strRealTz.mid( i+1 ); | 145 | nameRealTz = strRealTz.mid( i+1 ); |
142 | } | 146 | } |
143 | cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); | 147 | cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); |
144 | } | 148 | } |
145 | QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); | 149 | QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); |
146 | 150 | ||
147 | changed = FALSE; | 151 | changed = FALSE; |
148 | } | 152 | } |
149 | // restore the timezone, just in case we messed with it and | 153 | // restore the timezone, just in case we messed with it and |
150 | // are destroyed at an inoppurtune moment | 154 | // are destroyed at an inoppurtune moment |
151 | if ( !strRealTz.isNull() ) { | 155 | if ( !strRealTz.isNull() ) { |
152 | // this should be checked, but there is not much that can done at this | 156 | // this should be checked, but there is not much that can done at this |
153 | //point if it fails | 157 | //point if it fails |
154 | setenv( "TZ", strRealTz, true ); | 158 | setenv( "TZ", strRealTz, true ); |
155 | } | 159 | } |
156 | } | 160 | } |
157 | 161 | ||
158 | void CityTime::timerEvent( QTimerEvent *e ) | 162 | void CityTime::timerEvent( QTimerEvent *e ) |
159 | { | 163 | { |
160 | if ( e ) | 164 | if ( e ) |
161 | killTimer( timerId ); | 165 | killTimer( timerId ); |
162 | // change the time again!! | 166 | // change the time again!! |
163 | showTime(); | 167 | showTime(); |
164 | int ms = 1000 - QTime::currentTime().msec(); | 168 | int ms = 1000 - QTime::currentTime().msec(); |
165 | timerId = startTimer( ms ); | 169 | timerId = startTimer( ms ); |
166 | } | 170 | } |
167 | 171 | ||
168 | void CityTime::mousePressEvent( QMouseEvent * ) | 172 | void CityTime::mousePressEvent( QMouseEvent * ) |
169 | { | 173 | { |
170 | // DEBUG enable this to get a look at the zone information DEBUG | 174 | // DEBUG enable this to get a look at the zone information DEBUG |
171 | // frmMap->showZones(); | 175 | // frmMap->showZones(); |
172 | } | 176 | } |
173 | 177 | ||
174 | void CityTime::showTime( void ) | 178 | void CityTime::showTime( void ) |
175 | { | 179 | { |
176 | int i; | 180 | int i; |
177 | QListIterator<QLabel> itTime(listTimes); | 181 | QListIterator<QLabel> itTime(listTimes); |
178 | 182 | ||
179 | // traverse the list... | 183 | // traverse the list... |
180 | for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) { | 184 | for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) { |
181 | if ( !strCityTz[i].isNull() ) { | 185 | if ( !strCityTz[i].isNull() ) { |
182 | if ( setenv( "TZ", strCityTz[i], true ) == 0 ) { | 186 | if ( setenv( "TZ", strCityTz[i], true ) == 0 ) { |
183 | itTime.current()->setText( TimeString::shortTime( bWhichClock ) ); | 187 | itTime.current()->setText( TimeString::shortTime( bWhichClock ) ); |
184 | } else { | 188 | } else { |
185 | QMessageBox::critical( this, tr( "Time Changing" ), | 189 | QMessageBox::critical( this, tr( "Time Changing" ), |
186 | tr( "There was a problem setting timezone %1" ) | 190 | tr( "There was a problem setting timezone %1" ) |
187 | .arg( QString::number( i + 1 ) ) ); | 191 | .arg( QString::number( i + 1 ) ) ); |
188 | } | 192 | } |
189 | } | 193 | } |
190 | } | 194 | } |
191 | // done playing around... put it all back | 195 | // done playing around... put it all back |
192 | unsetenv( "TZ" ); | 196 | unsetenv( "TZ" ); |
193 | if ( !strRealTz.isNull() ) { | 197 | if ( !strRealTz.isNull() ) { |
194 | if ( setenv( "TZ", strRealTz, true ) != 0 ) { | 198 | if ( setenv( "TZ", strRealTz, true ) != 0 ) { |
195 | QMessageBox::critical( this, tr( "Restore Time Zone" ), | 199 | QMessageBox::critical( this, tr( "Restore Time Zone" ), |
@@ -214,66 +218,66 @@ void CityTime::slotNewTz( const QString & strNewCountry, | |||
214 | QListIterator<QToolButton> itCity(listCities); | 218 | QListIterator<QToolButton> itCity(listCities); |
215 | int i; | 219 | int i; |
216 | // go through the list and make adjustments based on which button is on | 220 | // go through the list and make adjustments based on which button is on |
217 | for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) { | 221 | for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) { |
218 | QToolButton *cmdTmp = itCity.current(); | 222 | QToolButton *cmdTmp = itCity.current(); |
219 | if ( cmdTmp->isOn() ) { | 223 | if ( cmdTmp->isOn() ) { |
220 | strCityTz[i] = strNewCountry + strNewCity; | 224 | strCityTz[i] = strNewCountry + strNewCity; |
221 | QString s = strNewCity; | 225 | QString s = strNewCity; |
222 | cmdTmp->setText( s.replace( QRegExp("_"), " " ) ); | 226 | cmdTmp->setText( s.replace( QRegExp("_"), " " ) ); |
223 | cmdTmp->toggle(); | 227 | cmdTmp->toggle(); |
224 | // we can actually break, since there is only one button | 228 | // we can actually break, since there is only one button |
225 | // that is ever pressed! | 229 | // that is ever pressed! |
226 | changed = TRUE; | 230 | changed = TRUE; |
227 | break; | 231 | break; |
228 | } | 232 | } |
229 | } | 233 | } |
230 | showTime(); | 234 | showTime(); |
231 | buttonWidget->show(); | 235 | buttonWidget->show(); |
232 | selWidget->hide(); | 236 | selWidget->hide(); |
233 | } | 237 | } |
234 | 238 | ||
235 | void CityTime::readInTimes( void ) | 239 | void CityTime::readInTimes( void ) |
236 | { | 240 | { |
237 | Config cfg("CityTime"); | 241 | Config cfg("CityTime"); |
238 | cfg.setGroup("TimeZones"); | 242 | cfg.setGroup("TimeZones"); |
239 | QListIterator<QToolButton> itCity( listCities ); | 243 | QListIterator<QToolButton> itCity( listCities ); |
240 | int i=0; | 244 | int i=0; |
241 | nameRealTz = QString::null; | 245 | nameRealTz = QString::null; |
242 | QString zn; | 246 | QString zn; |
243 | for ( ; i < CITIES ; i++ ) { | 247 | for ( ; i < CITIES ; i++ ) { |
244 | zn = cfg.readEntry("Zone"+QString::number(i), QString::null); | 248 | zn = cfg.readEntry("Zone"+QString::number(i), QString::null); |
245 | if ( zn.isNull() ) | 249 | if ( zn.isNull() ) |
246 | break; | 250 | break; |
247 | QString nm = cfg.readEntry("ZoneName"+QString::number(i)); | 251 | QString nm = cfg.readEntry("ZoneName"+QString::number(i)); |
248 | strCityTz[i] = zn; | 252 | strCityTz[i] = zn; |
249 | itCity.current()->setText(nm); | 253 | itCity.current()->setText(nm); |
250 | if ( zn == strRealTz ) | 254 | if ( zn == strRealTz ) |
251 | nameRealTz = nm; | 255 | nameRealTz = nm; |
252 | ++itCity; | 256 | ++itCity; |
253 | } | 257 | } |
254 | if ( i == 0 ) { | 258 | if ( i == 0 ) { |
255 | // write in our own in a shameless self promotion and some humor | 259 | // write in our own in a shameless self promotion and some humor |
256 | QStringList list = timezoneDefaults(); | 260 | QStringList list = timezoneDefaults(); |
257 | int i; | 261 | int i; |
258 | QStringList::Iterator it = list.begin(); | 262 | QStringList::Iterator it = list.begin(); |
259 | for ( i = 0, itCity.toFirst(); i < CITIES && itCity.current(); | 263 | for ( i = 0, itCity.toFirst(); i < CITIES && itCity.current(); |
260 | i++, ++itCity ) { | 264 | i++, ++itCity ) { |
261 | strCityTz[i] = *it++; | 265 | strCityTz[i] = *it++; |
262 | itCity.current()->setText( *it++ ); | 266 | itCity.current()->setText( *it++ ); |
263 | } | 267 | } |
264 | } | 268 | } |
265 | if ( nameRealTz.isEmpty() ) { | 269 | if ( nameRealTz.isEmpty() ) { |
266 | //remember the current time zone even if we don't have room | 270 | //remember the current time zone even if we don't have room |
267 | //to show it. | 271 | //to show it. |
268 | zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); | 272 | zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); |
269 | if ( zn == strRealTz ) | 273 | if ( zn == strRealTz ) |
270 | nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); | 274 | nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); |
271 | i++; | 275 | i++; |
272 | } | 276 | } |
273 | } | 277 | } |
274 | 278 | ||
275 | void CityTime::changeClock( bool newClock ) | 279 | void CityTime::changeClock( bool newClock ) |
276 | { | 280 | { |
277 | bWhichClock = newClock; | 281 | bWhichClock = newClock; |
278 | showTime(); | 282 | showTime(); |
279 | } | 283 | } |