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.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/core/settings/citytime/citytime.cpp b/core/settings/citytime/citytime.cpp
index b2f9f14..f33b19f 100644
--- a/core/settings/citytime/citytime.cpp
+++ b/core/settings/citytime/citytime.cpp
@@ -1,135 +1,140 @@
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>
22
21#include "zonemap.h" 23#include "zonemap.h"
22#include "citytime.h" 24#include "citytime.h"
23 25
24#include <qpe/qpeapplication.h> 26#include <qpe/qpeapplication.h>
25#include <qpe/config.h> 27#include <qpe/config.h>
26#include <qpe/timestring.h> 28#include <qpe/timestring.h>
27#include <qpe/tzselect.h> 29#include <qpe/tzselect.h>
28#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 30#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
29#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
30#endif 32#endif
31 33
32
33#include <qdir.h> 34#include <qdir.h>
34#include <qfile.h> 35#include <qfile.h>
35#include <qlabel.h> 36#include <qlabel.h>
36#include <qmessagebox.h> 37#include <qmessagebox.h>
37#include <qregexp.h> 38#include <qregexp.h>
38#include <qtextstream.h> 39#include <qtextstream.h>
39#include <qtoolbutton.h> 40#include <qtoolbutton.h>
41#include <qlayout.h>
40 42
41#include <stdlib.h> 43#include <stdlib.h>
42 44
43CityTime::CityTime( QWidget *parent, const char* name, 45CityTime::CityTime( QWidget *parent, const char* name,
44 WFlags fl ) 46 WFlags fl )
45 : CityTimeBase( parent, name, fl ), 47 : CityTimeBase( parent, name, fl ),
46 strRealTz(0), 48 strRealTz(0),
47 bAdded(false) 49 bAdded(false)
48{ 50{
49 Config config( "qpe" ); 51 Config config( "qpe" );
50 bWhichClock = config.readBoolEntry( "AMPM", TRUE ); 52 bWhichClock = config.readBoolEntry( "AMPM", TRUE );
51 frmMap->changeClock( bWhichClock ); 53 frmMap->changeClock( bWhichClock );
52 54
53 char *pEnv; 55 char *pEnv;
54 pEnv = NULL; 56 pEnv = NULL;
55 pEnv = getenv("TZ"); 57 pEnv = getenv("TZ");
56 if ( pEnv ) 58 if ( pEnv )
57 strRealTz = pEnv; 59 strRealTz = pEnv;
58 pEnv = NULL; 60 pEnv = NULL;
59 pEnv = getenv("HOME"); 61 pEnv = getenv("HOME");
60 if ( pEnv ) 62 if ( pEnv )
61 strHome = pEnv; 63 strHome = pEnv;
62 // append the labels to their respective lists... 64 // append the labels to their respective lists...
63 listCities.setAutoDelete( true ); 65 listCities.setAutoDelete( true );
64 listTimes.setAutoDelete( true ); 66 listTimes.setAutoDelete( true );
65 67
66 listCities.append( cmdCity1 ); 68 listCities.append( cmdCity1 );
67 listCities.append( cmdCity2 ); 69 listCities.append( cmdCity2 );
68 listCities.append( cmdCity3 ); 70 listCities.append( cmdCity3 );
69 71
70 listTimes.append( lblCTime1 ); 72 listTimes.append( lblCTime1 );
71 listTimes.append( lblCTime2 ); 73 listTimes.append( lblCTime2 );
72 listTimes.append( lblCTime3 ); 74 listTimes.append( lblCTime3 );
73 75
74 76
75 // kludgy way of getting the screen size so we don't have to depend 77 // kludgy way of getting the screen size so we don't have to depend
76 // on a resize event... 78 // on a resize event...
77 QWidget *d = QApplication::desktop(); 79 QWidget *d = QApplication::desktop();
78 if ( d->width() < d->height() ) { 80 if ( d->width() < d->height() ) {
79 // append for that 4 down look 81 // append for that 4 down look
80
81 listCities.append( cmdCity4 ); 82 listCities.append( cmdCity4 );
82 listCities.append( cmdCity5 ); 83 listCities.append( cmdCity5 );
83 listCities.append( cmdCity6 ); 84 listCities.append( cmdCity6 );
84 listTimes.append( lblCTime4 ); 85 listTimes.append( lblCTime4 );
85 listTimes.append( lblCTime5 ); 86 listTimes.append( lblCTime5 );
86 listTimes.append( lblCTime6 ); 87 listTimes.append( lblCTime6 );
87 lblCTime7->hide(); 88 lblCTime7->hide();
88 lblCTime8->hide(); 89 lblCTime8->hide();
89 lblCTime9->hide(); 90 lblCTime9->hide();
90 cmdCity7->hide(); 91 cmdCity7->hide();
91 cmdCity8->hide(); 92 cmdCity8->hide();
92 cmdCity9->hide(); 93 cmdCity9->hide();
93 } else { 94 } else {
94 listCities.append( cmdCity7 ); 95 listCities.append( cmdCity7 );
95 listCities.append( cmdCity8 ); 96 listCities.append( cmdCity8 );
96 listCities.append( cmdCity9 ); 97 listCities.append( cmdCity9 );
97 listTimes.append( lblCTime7 ); 98 listTimes.append( lblCTime7 );
98 listTimes.append( lblCTime8 ); 99 listTimes.append( lblCTime8 );
99 listTimes.append( lblCTime9 ); 100 listTimes.append( lblCTime9 );
100 lblCTime4->hide(); 101 lblCTime4->hide();
101 lblCTime5->hide(); 102 lblCTime5->hide();
102 lblCTime6->hide(); 103 lblCTime6->hide();
103 cmdCity4->hide(); 104 cmdCity4->hide();
104 cmdCity5->hide(); 105 cmdCity5->hide();
105 cmdCity6->hide(); 106 cmdCity6->hide();
106 } 107 }
108
109 selWidget = frmMap->selectionWidget( this );
110 selWidget->hide();
111 CityTimeBaseLayout->addWidget( selWidget );
107 bAdded = true; 112 bAdded = true;
108 readInTimes(); 113 readInTimes();
109 changed = FALSE; 114 changed = FALSE;
110 QObject::connect( qApp, SIGNAL( clockChanged(bool) ), 115 QObject::connect( qApp, SIGNAL( clockChanged( bool ) ),
111 this, SLOT( changeClock(bool) ) ); 116 this, SLOT( changeClock( bool ) ) );
112 // now start the timer so we can update the time quickly every second 117 // now start the timer so we can update the time quickly every second
113 timerEvent( 0 ); 118 timerEvent( 0 );
114} 119}
115 120
116CityTime::~CityTime() 121CityTime::~CityTime()
117{ 122{
118 if ( changed ) { 123 if ( changed ) {
119 Config cfg("CityTime"); 124 Config cfg("CityTime");
120 cfg.setGroup("TimeZones"); 125 cfg.setGroup("TimeZones");
121 QListIterator<QToolButton> itCity( listCities ); 126 QListIterator<QToolButton> itCity( listCities );
122 int i; 127 int i;
123 bool realTzWritten = FALSE; 128 bool realTzWritten = FALSE;
124 for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { 129 for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) {
125 if ( !strCityTz[i].isNull() ) { 130 if ( !strCityTz[i].isNull() ) {
126 cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); 131 cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]);
127 cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); 132 cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text());
128 if ( strCityTz[i] == strRealTz ) 133 if ( strCityTz[i] == strRealTz )
129 realTzWritten = TRUE; 134 realTzWritten = TRUE;
130 } 135 }
131 } 136 }
132 if ( realTzWritten ) { 137 if ( realTzWritten ) {
133 cfg.removeEntry("Zone"+QString::number(CITIES)); 138 cfg.removeEntry("Zone"+QString::number(CITIES));
134 cfg.removeEntry("ZoneName"+QString::number(CITIES)); 139 cfg.removeEntry("ZoneName"+QString::number(CITIES));
135 } else { 140 } else {
@@ -178,72 +183,77 @@ void CityTime::showTime( void )
178 for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) { 183 for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) {
179 if ( !strCityTz[i].isNull() ) { 184 if ( !strCityTz[i].isNull() ) {
180 if ( setenv( "TZ", strCityTz[i], true ) == 0 ) { 185 if ( setenv( "TZ", strCityTz[i], true ) == 0 ) {
181 itTime.current()->setText( TimeString::shortTime(bWhichClock) ); 186 itTime.current()->setText( TimeString::shortTime(bWhichClock) );
182 } else { 187 } else {
183 QMessageBox::critical( this, tr( "Time Changing" ), 188 QMessageBox::critical( this, tr( "Time Changing" ),
184 tr( "There was a problem setting timezone %1" ) 189 tr( "There was a problem setting timezone %1" )
185 .arg( QString::number( i + 1 ) ) ); 190 .arg( QString::number( i + 1 ) ) );
186 } 191 }
187 } 192 }
188 } 193 }
189 // done playing around... put it all back 194 // done playing around... put it all back
190 unsetenv( "TZ" ); 195 unsetenv( "TZ" );
191 if ( !strRealTz.isNull() ) { 196 if ( !strRealTz.isNull() ) {
192 if ( setenv( "TZ", strRealTz, true ) != 0 ) { 197 if ( setenv( "TZ", strRealTz, true ) != 0 ) {
193 QMessageBox::critical( this, tr( "Restore Time Zone" ), 198 QMessageBox::critical( this, tr( "Restore Time Zone" ),
194 tr( "There was a problem setting your timezone." 199 tr( "There was a problem setting your timezone."
195 "Your time may be wrong now..." ) ); 200 "Your time may be wrong now..." ) );
196 } 201 }
197 } 202 }
198} 203}
199 204
200void CityTime::beginNewTz() 205void CityTime::beginNewTz()
201{ 206{
207 buttonWidget->hide();
202 frmMap->setFocus(); 208 frmMap->setFocus();
209 selWidget->show();
210 // CityTimeBaseLayout->addWidget( selWidget );
203} 211}
204 212
205void CityTime::slotNewTz( const QString & strNewCountry, 213void CityTime::slotNewTz( const QString & strNewCountry,
206 const QString & strNewCity ) 214 const QString & strNewCity )
207{ 215{
208 // determine what to do based on what putton is pressed... 216 // determine what to do based on what putton is pressed...
209 QListIterator<QToolButton> itCity(listCities); 217 QListIterator<QToolButton> itCity(listCities);
210 int i; 218 int i;
211 // go through the list and make adjustments based on which button is on 219 // go through the list and make adjustments based on which button is on
212 for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) { 220 for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) {
213 QToolButton *cmdTmp = itCity.current(); 221 QToolButton *cmdTmp = itCity.current();
214 if ( cmdTmp->isOn() ) { 222 if ( cmdTmp->isOn() ) {
215 strCityTz[i] = strNewCountry + strNewCity; 223 strCityTz[i] = strNewCountry + strNewCity;
216 QString s = strNewCity; 224 QString s = strNewCity;
217 cmdTmp->setText( s.replace( QRegExp("_"), " " ) ); 225 cmdTmp->setText( s.replace( QRegExp("_"), " " ) );
218 cmdTmp->toggle(); 226 cmdTmp->toggle();
219 // we can actually break, since there is only one button 227 // we can actually break, since there is only one button
220 // that is ever pressed! 228 // that is ever pressed!
221 changed = TRUE; 229 changed = TRUE;
222 break; 230 break;
223 } 231 }
224 } 232 }
225 showTime(); 233 showTime();
234 buttonWidget->show();
235 selWidget->hide();
226} 236}
227 237
228void CityTime::readInTimes( void ) 238void CityTime::readInTimes( void )
229{ 239{
230 Config cfg("CityTime"); 240 Config cfg("CityTime");
231 cfg.setGroup("TimeZones"); 241 cfg.setGroup("TimeZones");
232 QListIterator<QToolButton> itCity( listCities ); 242 QListIterator<QToolButton> itCity( listCities );
233 int i=0; 243 int i=0;
234 nameRealTz = QString::null; 244 nameRealTz = QString::null;
235 QString zn; 245 QString zn;
236 for ( ; i < CITIES ; i++ ) { 246 for ( ; i < CITIES ; i++ ) {
237 zn = cfg.readEntry("Zone"+QString::number(i), QString::null); 247 zn = cfg.readEntry("Zone"+QString::number(i), QString::null);
238 if ( zn.isNull() ) 248 if ( zn.isNull() )
239 break; 249 break;
240 QString nm = cfg.readEntry("ZoneName"+QString::number(i)); 250 QString nm = cfg.readEntry("ZoneName"+QString::number(i));
241 strCityTz[i] = zn; 251 strCityTz[i] = zn;
242 itCity.current()->setText(nm); 252 itCity.current()->setText(nm);
243 if ( zn == strRealTz ) 253 if ( zn == strRealTz )
244 nameRealTz = nm; 254 nameRealTz = nm;
245 ++itCity; 255 ++itCity;
246 } 256 }
247 if ( i == 0 ) { 257 if ( i == 0 ) {
248 // write in our own in a shameless self promotion and some humor 258 // write in our own in a shameless self promotion and some humor
249 QStringList list = timezoneDefaults(); 259 QStringList list = timezoneDefaults();