summaryrefslogtreecommitdiff
path: root/library/tzselect.cpp
authorzecke <zecke>2002-09-10 12:09:49 (UTC)
committer zecke <zecke>2002-09-10 12:09:49 (UTC)
commit6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4 (patch) (unidiff)
tree6ebc93c6432f4ed9d00ef1448b6a047ef522a79a /library/tzselect.cpp
parentd10cddb3c9ce75bc90b14add14bc133737fe35aa (diff)
downloadopie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.zip
opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.gz
opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.bz2
Qtopia1-6 merge
still to test bic changes to be resolved more changes to be made?
Diffstat (limited to 'library/tzselect.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/tzselect.cpp104
1 files changed, 75 insertions, 29 deletions
diff --git a/library/tzselect.cpp b/library/tzselect.cpp
index 5f102d5..6cc0bea 100644
--- a/library/tzselect.cpp
+++ b/library/tzselect.cpp
@@ -1,228 +1,274 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of the 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#define QTOPIA_INTERNAL_TZSELECT_INC_LOCAL
22
21#include "tzselect.h" 23#include "tzselect.h"
22#include "resource.h" 24#include "resource.h"
23#include "global.h" 25#include "global.h"
24#include "config.h" 26#include "config.h"
25#include <qtoolbutton.h> 27#include <qtoolbutton.h>
26#include <qfile.h> 28#include <qfile.h>
27#include <stdlib.h> 29#include <stdlib.h>
28 30
29#ifdef Q_WS_QWS 31#ifdef Q_WS_QWS
30#include <qcopchannel_qws.h> 32#include <qcopchannel_qws.h>
31#endif 33#endif
32 34
35class TimeZoneSelectorPrivate
36{
37public:
38 TimeZoneSelectorPrivate() : includeLocal(FALSE) {}
39 bool includeLocal;
40};
41
33TZCombo::TZCombo( QWidget *p, const char* n ) 42TZCombo::TZCombo( QWidget *p, const char* n )
34 : QComboBox( p, n ) 43 : QComboBox( p, n )
35{ 44{
36 updateZones(); 45 updateZones();
37 // check to see if TZ is set, if it is set the current item to that 46 // check to see if TZ is set, if it is set the current item to that
38 QString tz = getenv("TZ"); 47 QString tz = getenv("TZ");
48 if (parent()->inherits("TimeZoneSelector")) {
49 if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
50 // overide to the 'local' type.
51 tz = "None";
52 }
53 }
39 if ( !tz.isNull() ) { 54 if ( !tz.isNull() ) {
40 int n = 0, 55 int n = 0,
41 index = 0; 56 index = 0;
42 for ( QStringList::Iterator it=identifiers.begin(); 57 for ( QStringList::Iterator it=identifiers.begin();
43 it!=identifiers.end(); ++it) { 58 it!=identifiers.end(); ++it) {
44 if ( *it == tz ) 59 if ( *it == tz )
45 index = n; 60 index = n;
46 n++; 61 n++;
47 } 62 }
48 setCurrentItem(index); 63 setCurrentItem(index);
49 } else { 64 } else {
50 setCurrentItem(0); 65 setCurrentItem(0);
51 } 66 }
52 67
53 68
54 69
55 // listen on QPE/System 70 // listen on QPE/System
56#if defined(Q_WS_QWS) 71#if defined(Q_WS_QWS)
57#if !defined(QT_NO_COP) 72#if !defined(QT_NO_COP)
58 QCopChannel *channel = new QCopChannel( "QPE/System", this ); 73 QCopChannel *channel = new QCopChannel( "QPE/System", this );
59 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 74 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
60 this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) ); 75 this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) );
61#endif 76#endif
62#endif 77#endif
63 78
64 79
65} 80}
66 81
67TZCombo::~TZCombo() 82TZCombo::~TZCombo()
68{ 83{
69} 84}
70 85
71void TZCombo::updateZones() 86void TZCombo::updateZones()
72{ 87{
73 QString cur = currentText(); 88 QString cur = currentText();
74 clear(); 89 clear();
75 identifiers.clear(); 90 identifiers.clear();
76 int curix=0; 91 int curix=0;
77 QString tz = getenv("TZ"); 92 QString tz = getenv("TZ");
78 bool tzFound = FALSE; 93 bool tzFound = FALSE;
79 Config cfg("CityTime"); 94 Config cfg("WorldTime");
80 cfg.setGroup("TimeZones"); 95 cfg.setGroup("TimeZones");
81 int i=0; 96 int listIndex = 0;
82 for ( ; 1; i++ ) { 97 if (parent()->inherits("TimeZoneSelector")) {
83 QString zn = cfg.readEntry("Zone"+QString::number(i), QString::null); 98 if ( ((TimeZoneSelector *)parent())->localIncluded() ) {
99 // overide to the 'local' type.
100 identifiers.append( "None" );
101 insertItem( tr("None") );
102 if ( cur == tr("None"))
103 curix = 0;
104 listIndex++;
105 }
106 }
107 int cfgIndex = 0;
108 while (1) {
109 QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null);
84 if ( zn.isNull() ) 110 if ( zn.isNull() )
85 break; 111 break;
86 if ( zn == tz ) 112 if ( zn == tz )
87 tzFound = TRUE; 113 tzFound = TRUE;
88 QString nm = cfg.readEntry("ZoneName"+QString::number(i)); 114 QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex));
89 identifiers.append(zn); 115 identifiers.append(zn);
90 insertItem(nm); 116 insertItem(nm);
91 if ( nm == cur ) 117 if ( nm == cur )
92 curix = i; 118 curix = listIndex;
119 ++cfgIndex;
120 ++listIndex;
93 } 121 }
94 if ( !tzFound && !tz.isEmpty()) { 122 if ( !listIndex ) {
95 int i = tz.find( '/' ); 123 QStringList list = timezoneDefaults();
96 QString nm = tz.mid( i+1 ); 124 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) {
97 identifiers.append(tz); 125 QString zn = *it;
98 insertItem(nm); 126 QString nm = *++it;
99 if ( nm == cur ) 127 if ( zn == tz )
100 curix = i; 128 tzFound = TRUE;
101 ++i; 129 if ( nm == cur )
130 curix = listIndex;
131 identifiers.append(zn);
132 insertItem(nm);
133 ++listIndex;
134 }
102 } 135 }
103 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) { 136 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) {
104 insertItem(*it); 137 insertItem(*it);
105 identifiers.append(*it); 138 identifiers.append(*it);
106 if ( *it == cur ) 139 if ( *it == cur )
107 curix = i; 140 curix = listIndex;
108 ++i; 141 ++listIndex;
109 } 142 }
110 if ( !i ) { 143 if ( !tzFound && !tz.isEmpty()) {
111 QStringList list = timezoneDefaults(); 144 int i = tz.find( '/' );
112 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) { 145 QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " ");
113 identifiers.append(*it); ++it; 146 identifiers.append(tz);
114 insertItem(*it); 147 insertItem(nm);
115 } 148 if ( nm == cur )
149 curix = listIndex;
150 ++listIndex;
116 } 151 }
117 setCurrentItem(curix); 152 setCurrentItem(curix);
118} 153}
119 154
120 155
121void TZCombo::keyPressEvent( QKeyEvent *e ) 156void TZCombo::keyPressEvent( QKeyEvent *e )
122{ 157{
123 // ### should popup() in Qt 3.0 (it's virtual there) 158 // ### should popup() in Qt 3.0 (it's virtual there)
124// updateZones(); 159// updateZones();
125 QComboBox::keyPressEvent(e); 160 QComboBox::keyPressEvent(e);
126} 161}
127 162
128void TZCombo::mousePressEvent(QMouseEvent*e) 163void TZCombo::mousePressEvent(QMouseEvent*e)
129{ 164{
130 // ### should popup() in Qt 3.0 (it's virtual there) 165 // ### should popup() in Qt 3.0 (it's virtual there)
131// updateZones(); 166// updateZones();
132 QComboBox::mousePressEvent(e); 167 QComboBox::mousePressEvent(e);
133} 168}
134 169
135QString TZCombo::currZone() const 170QString TZCombo::currZone() const
136{ 171{
137 return identifiers[currentItem()]; 172 return identifiers[currentItem()];
138} 173}
139 174
140void TZCombo::setCurrZone( const QString& id ) 175void TZCombo::setCurrZone( const QString& id )
141{ 176{
142 for (int i=0; i< count(); i++) { 177 for (int i=0; i< count(); i++) {
143 if ( identifiers[i] == id ) { 178 if ( identifiers[i] == id ) {
144 setCurrentItem(i); 179 setCurrentItem(i);
145 return; 180 return;
146 } 181 }
147 } 182 }
148 insertItem(id); 183 insertItem(id);
149 setCurrentItem( count() - 1); 184 setCurrentItem( count() - 1);
150 identifiers.append(id); 185 identifiers.append(id);
151 extras.append(id); 186 extras.append(id);
152} 187}
153 188
154 189
155 190
156void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&) 191void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&)
157{ 192{
158 if ( msg == "timeZoneListChange()" ) { 193 if ( msg == "timeZoneListChange()" ) {
159 updateZones(); 194 updateZones();
160 } 195 }
161} 196}
162 197
163 198
164TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) : 199TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) :
165 QHBox(p,n) 200 QHBox(p,n)
166{ 201{
202 d = new TimeZoneSelectorPrivate();
167 // build the combobox before we do any updates... 203 // build the combobox before we do any updates...
168 cmbTz = new TZCombo( this, "timezone combo" ); 204 cmbTz = new TZCombo( this, "timezone combo" );
169 205
170 cmdTz = new QToolButton( this, "timezone button" ); 206 cmdTz = new QToolButton( this, "timezone button" );
171 QPixmap pixGlobe = Resource::loadPixmap( "citytime_icon" ); 207 cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) );
172 cmdTz->setPixmap( pixGlobe );
173 cmdTz->setMaximumSize( cmdTz->sizeHint() ); 208 cmdTz->setMaximumSize( cmdTz->sizeHint() );
174 209
175 // set up a connection to catch a newly selected item and throw our 210 // set up a connection to catch a newly selected item and throw our
176 // signal 211 // signal
177 QObject::connect( cmbTz, SIGNAL( activated( int ) ), 212 QObject::connect( cmbTz, SIGNAL( activated( int ) ),
178 this, SLOT( slotTzActive( int ) ) ); 213 this, SLOT( slotTzActive( int ) ) );
179 QObject::connect( cmdTz, SIGNAL( clicked() ), 214 QObject::connect( cmdTz, SIGNAL( clicked() ),
180 this, SLOT( slotExecute() ) ); 215 this, SLOT( slotExecute() ) );
181} 216}
182 217
183TimeZoneSelector::~TimeZoneSelector() 218TimeZoneSelector::~TimeZoneSelector()
184{ 219{
185} 220}
186 221
222void TimeZoneSelector::setLocalIncluded(bool b)
223{
224 d->includeLocal = b;
225 cmbTz->updateZones();
226}
227
228bool TimeZoneSelector::localIncluded() const
229{
230 return d->includeLocal;
231}
232
187 233
188QString TimeZoneSelector::currentZone() const 234QString TimeZoneSelector::currentZone() const
189{ 235{
190 return cmbTz->currZone(); 236 return cmbTz->currZone();
191} 237}
192 238
193void TimeZoneSelector::setCurrentZone( const QString& id ) 239void TimeZoneSelector::setCurrentZone( const QString& id )
194{ 240{
195 cmbTz->setCurrZone( id ); 241 cmbTz->setCurrZone( id );
196} 242}
197 243
198void TimeZoneSelector::slotTzActive( int ) 244void TimeZoneSelector::slotTzActive( int )
199{ 245{
200 emit signalNewTz( cmbTz->currZone() ); 246 emit signalNewTz( cmbTz->currZone() );
201} 247}
202 248
203void TimeZoneSelector::slotExecute( void ) 249void TimeZoneSelector::slotExecute( void )
204{ 250{
205 // execute the city time application... 251 // execute the world time application...
206 Global::execute( "citytime" ); 252 Global::execute( "worldtime" );
207} 253}
208 254
209QStringList timezoneDefaults( void ) 255QStringList timezoneDefaults( void )
210{ 256{
211 QStringList tzs; 257 QStringList tzs;
212 // load up the list just like the file format (citytime.cpp) 258 // load up the list just like the file format (citytime.cpp)
213 tzs.append( "America/New_York" ); 259 tzs.append( "America/New_York" );
214 tzs.append( "New York" ); 260 tzs.append( "New York" );
215 tzs.append( "America/Los_Angeles" ); 261 tzs.append( "America/Los_Angeles" );
216 tzs.append( "Los Angeles" ); 262 tzs.append( "Los Angeles" );
217 tzs.append( "Australia/Brisbane" ); 263 tzs.append( "Australia/Brisbane" );
218 tzs.append( "Brisbane" ); 264 tzs.append( "Brisbane" );
219 tzs.append( "Europe/Oslo" ); 265 tzs.append( "Europe/Oslo" );
220 tzs.append( "Oslo" ); 266 tzs.append( "Oslo" );
221 tzs.append( "Asia/Tokyo" ); 267 tzs.append( "Asia/Tokyo" );
222 tzs.append( "Tokyo" ); 268 tzs.append( "Tokyo" );
223 tzs.append( "Asia/Hong_Kong" ); 269 tzs.append( "Asia/Hong_Kong" );
224 tzs.append( "Hong Kong" ); 270 tzs.append( "Hong Kong" );
225 return tzs; 271 return tzs;
226} 272}
227 273
228 274