summaryrefslogtreecommitdiff
path: root/core/settings/citytime/citytime.cpp
Unidiff
Diffstat (limited to 'core/settings/citytime/citytime.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/citytime/citytime.cpp94
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
@@ -20,36 +20,40 @@
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
40CityTime::CityTime( QWidget *parent, const char* name, 44CityTime::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 )
@@ -115,39 +119,39 @@ CityTime::CityTime( QWidget *parent, const char* name,
115 timerEvent( 0 ); 119 timerEvent( 0 );
116} 120}
117 121
118CityTime::~CityTime() 122CityTime::~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
@@ -155,13 +159,13 @@ CityTime::~CityTime()
155 } 159 }
156} 160}
157 161
158void CityTime::timerEvent( QTimerEvent *e ) 162void 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
@@ -177,13 +181,13 @@ void CityTime::showTime( void )
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 }
@@ -220,13 +224,13 @@ void CityTime::slotNewTz( const QString & strNewCountry,
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();
@@ -238,21 +242,21 @@ void CityTime::readInTimes( void )
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();
@@ -260,18 +264,18 @@ void CityTime::readInTimes( void )
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
275void CityTime::changeClock( bool newClock ) 279void CityTime::changeClock( bool newClock )
276{ 280{
277 bWhichClock = newClock; 281 bWhichClock = newClock;