-rw-r--r-- | library/tzselect.cpp | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/library/tzselect.cpp b/library/tzselect.cpp index 4343eab..f28100b 100644 --- a/library/tzselect.cpp +++ b/library/tzselect.cpp | |||
@@ -1,303 +1,302 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of the 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 | 21 | #define QTOPIA_INTERNAL_TZSELECT_INC_LOCAL |
22 | 22 | ||
23 | #include "tzselect.h" | 23 | #include "tzselect.h" |
24 | #include "resource.h" | 24 | #include "resource.h" |
25 | #include "global.h" | ||
26 | #include "config.h" | 25 | #include "config.h" |
27 | #include <qtoolbutton.h> | 26 | #include <qtoolbutton.h> |
28 | #include <qfile.h> | 27 | #include <qfile.h> |
29 | #include <stdlib.h> | 28 | #include <stdlib.h> |
30 | 29 | ||
31 | #include <qcopchannel_qws.h> | 30 | #include <qcopchannel_qws.h> |
32 | #include <qpe/qpeapplication.h> | 31 | #include <qpe/qpeapplication.h> |
33 | #include <qmessagebox.h> | 32 | #include <qmessagebox.h> |
34 | 33 | ||
35 | /*! | 34 | /*! |
36 | \class TimeZoneSelector | 35 | \class TimeZoneSelector |
37 | 36 | ||
38 | \brief The TimeZoneSelector widget allows users to configure their time zone information. | 37 | \brief The TimeZoneSelector widget allows users to configure their time zone information. |
39 | 38 | ||
40 | \ingroup qtopiaemb | 39 | \ingroup qtopiaemb |
41 | */ | 40 | */ |
42 | 41 | ||
43 | class TimeZoneSelectorPrivate | 42 | class TimeZoneSelectorPrivate |
44 | { | 43 | { |
45 | public: | 44 | public: |
46 | TimeZoneSelectorPrivate() : includeLocal(FALSE) {} | 45 | TimeZoneSelectorPrivate() : includeLocal(FALSE) {} |
47 | bool includeLocal; | 46 | bool includeLocal; |
48 | }; | 47 | }; |
49 | 48 | ||
50 | TZCombo::TZCombo( QWidget *p, const char* n ) | 49 | TZCombo::TZCombo( QWidget *p, const char* n ) |
51 | : QComboBox( p, n ) | 50 | : QComboBox( p, n ) |
52 | { | 51 | { |
53 | updateZones(); | 52 | updateZones(); |
54 | // check to see if TZ is set, if it is set the current item to that | 53 | // check to see if TZ is set, if it is set the current item to that |
55 | QString tz = getenv("TZ"); | 54 | QString tz = getenv("TZ"); |
56 | if (parent()->inherits("TimeZoneSelector")) { | 55 | if (parent()->inherits("TimeZoneSelector")) { |
57 | if ( ((TimeZoneSelector *)parent())->localIncluded() ) { | 56 | if ( ((TimeZoneSelector *)parent())->localIncluded() ) { |
58 | // overide to the 'local' type. | 57 | // overide to the 'local' type. |
59 | tz = "None"; | 58 | tz = "None"; |
60 | } | 59 | } |
61 | } | 60 | } |
62 | if ( !tz.isNull() ) { | 61 | if ( !tz.isNull() ) { |
63 | int n = 0, | 62 | int n = 0, |
64 | index = 0; | 63 | index = 0; |
65 | for ( QStringList::Iterator it=identifiers.begin(); | 64 | for ( QStringList::Iterator it=identifiers.begin(); |
66 | it!=identifiers.end(); ++it) { | 65 | it!=identifiers.end(); ++it) { |
67 | if ( *it == tz ) | 66 | if ( *it == tz ) |
68 | index = n; | 67 | index = n; |
69 | n++; | 68 | n++; |
70 | } | 69 | } |
71 | setCurrentItem(index); | 70 | setCurrentItem(index); |
72 | } else { | 71 | } else { |
73 | setCurrentItem(0); | 72 | setCurrentItem(0); |
74 | } | 73 | } |
75 | 74 | ||
76 | 75 | ||
77 | 76 | ||
78 | // listen on QPE/System | 77 | // listen on QPE/System |
79 | #if !defined(QT_NO_COP) | 78 | #if !defined(QT_NO_COP) |
80 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); | 79 | QCopChannel *channel = new QCopChannel( "QPE/System", this ); |
81 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 80 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
82 | this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) ); | 81 | this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) ); |
83 | #endif | 82 | #endif |
84 | 83 | ||
85 | 84 | ||
86 | } | 85 | } |
87 | 86 | ||
88 | TZCombo::~TZCombo() | 87 | TZCombo::~TZCombo() |
89 | { | 88 | { |
90 | } | 89 | } |
91 | 90 | ||
92 | void TZCombo::updateZones() | 91 | void TZCombo::updateZones() |
93 | { | 92 | { |
94 | QString cur = currentText(); | 93 | QString cur = currentText(); |
95 | clear(); | 94 | clear(); |
96 | identifiers.clear(); | 95 | identifiers.clear(); |
97 | int curix=0; | 96 | int curix=0; |
98 | QString tz = getenv("TZ"); | 97 | QString tz = getenv("TZ"); |
99 | bool tzFound = FALSE; | 98 | bool tzFound = FALSE; |
100 | Config cfg("CityTime"); | 99 | Config cfg("CityTime"); |
101 | cfg.setGroup("TimeZones"); | 100 | cfg.setGroup("TimeZones"); |
102 | int listIndex = 0; | 101 | int listIndex = 0; |
103 | if (parent()->inherits("TimeZoneSelector")) { | 102 | if (parent()->inherits("TimeZoneSelector")) { |
104 | if ( ((TimeZoneSelector *)parent())->localIncluded() ) { | 103 | if ( ((TimeZoneSelector *)parent())->localIncluded() ) { |
105 | // overide to the 'local' type. | 104 | // overide to the 'local' type. |
106 | identifiers.append( "None" ); | 105 | identifiers.append( "None" ); |
107 | insertItem( tr("None") ); | 106 | insertItem( tr("None") ); |
108 | if ( cur == tr("None")) | 107 | if ( cur == tr("None")) |
109 | curix = 0; | 108 | curix = 0; |
110 | listIndex++; | 109 | listIndex++; |
111 | } | 110 | } |
112 | } | 111 | } |
113 | int cfgIndex = 0; | 112 | int cfgIndex = 0; |
114 | while (1) { | 113 | while (1) { |
115 | QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null); | 114 | QString zn = cfg.readEntry("Zone"+QString::number(cfgIndex), QString::null); |
116 | if ( zn.isNull() ) | 115 | if ( zn.isNull() ) |
117 | break; | 116 | break; |
118 | if ( zn == tz ) | 117 | if ( zn == tz ) |
119 | tzFound = TRUE; | 118 | tzFound = TRUE; |
120 | QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex)); | 119 | QString nm = cfg.readEntry("ZoneName"+QString::number(cfgIndex)); |
121 | identifiers.append(zn); | 120 | identifiers.append(zn); |
122 | insertItem(nm); | 121 | insertItem(nm); |
123 | if ( nm == cur ) | 122 | if ( nm == cur ) |
124 | curix = listIndex; | 123 | curix = listIndex; |
125 | ++cfgIndex; | 124 | ++cfgIndex; |
126 | ++listIndex; | 125 | ++listIndex; |
127 | } | 126 | } |
128 | if ( !listIndex ) { | 127 | if ( !listIndex ) { |
129 | QStringList list = timezoneDefaults(); | 128 | QStringList list = timezoneDefaults(); |
130 | for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) { | 129 | for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) { |
131 | QString zn = *it; | 130 | QString zn = *it; |
132 | QString nm = *++it; | 131 | QString nm = *++it; |
133 | if ( zn == tz ) | 132 | if ( zn == tz ) |
134 | tzFound = TRUE; | 133 | tzFound = TRUE; |
135 | if ( nm == cur ) | 134 | if ( nm == cur ) |
136 | curix = listIndex; | 135 | curix = listIndex; |
137 | identifiers.append(zn); | 136 | identifiers.append(zn); |
138 | insertItem(nm); | 137 | insertItem(nm); |
139 | ++listIndex; | 138 | ++listIndex; |
140 | } | 139 | } |
141 | } | 140 | } |
142 | for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) { | 141 | for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) { |
143 | insertItem(*it); | 142 | insertItem(*it); |
144 | identifiers.append(*it); | 143 | identifiers.append(*it); |
145 | if ( *it == cur ) | 144 | if ( *it == cur ) |
146 | curix = listIndex; | 145 | curix = listIndex; |
147 | ++listIndex; | 146 | ++listIndex; |
148 | } | 147 | } |
149 | if ( !tzFound && !tz.isEmpty()) { | 148 | if ( !tzFound && !tz.isEmpty()) { |
150 | int i = tz.find( '/' ); | 149 | int i = tz.find( '/' ); |
151 | QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " "); | 150 | QString nm = tz.mid( i+1 ).replace(QRegExp("_"), " "); |
152 | identifiers.append(tz); | 151 | identifiers.append(tz); |
153 | insertItem(nm); | 152 | insertItem(nm); |
154 | if ( nm == cur ) | 153 | if ( nm == cur ) |
155 | curix = listIndex; | 154 | curix = listIndex; |
156 | ++listIndex; | 155 | ++listIndex; |
157 | } | 156 | } |
158 | setCurrentItem(curix); | 157 | setCurrentItem(curix); |
159 | } | 158 | } |
160 | 159 | ||
161 | 160 | ||
162 | void TZCombo::keyPressEvent( QKeyEvent *e ) | 161 | void TZCombo::keyPressEvent( QKeyEvent *e ) |
163 | { | 162 | { |
164 | // ### should popup() in Qt 3.0 (it's virtual there) | 163 | // ### should popup() in Qt 3.0 (it's virtual there) |
165 | // updateZones(); | 164 | // updateZones(); |
166 | QComboBox::keyPressEvent(e); | 165 | QComboBox::keyPressEvent(e); |
167 | } | 166 | } |
168 | 167 | ||
169 | void TZCombo::mousePressEvent(QMouseEvent*e) | 168 | void TZCombo::mousePressEvent(QMouseEvent*e) |
170 | { | 169 | { |
171 | // ### should popup() in Qt 3.0 (it's virtual there) | 170 | // ### should popup() in Qt 3.0 (it's virtual there) |
172 | // updateZones(); | 171 | // updateZones(); |
173 | QComboBox::mousePressEvent(e); | 172 | QComboBox::mousePressEvent(e); |
174 | } | 173 | } |
175 | 174 | ||
176 | QString TZCombo::currZone() const | 175 | QString TZCombo::currZone() const |
177 | { | 176 | { |
178 | return identifiers[currentItem()]; | 177 | return identifiers[currentItem()]; |
179 | } | 178 | } |
180 | 179 | ||
181 | void TZCombo::setCurrZone( const QString& id ) | 180 | void TZCombo::setCurrZone( const QString& id ) |
182 | { | 181 | { |
183 | for (int i=0; i< count(); i++) { | 182 | for (int i=0; i< count(); i++) { |
184 | if ( identifiers[i] == id ) { | 183 | if ( identifiers[i] == id ) { |
185 | setCurrentItem(i); | 184 | setCurrentItem(i); |
186 | return; | 185 | return; |
187 | } | 186 | } |
188 | } | 187 | } |
189 | insertItem(id); | 188 | insertItem(id); |
190 | setCurrentItem( count() - 1); | 189 | setCurrentItem( count() - 1); |
191 | identifiers.append(id); | 190 | identifiers.append(id); |
192 | extras.append(id); | 191 | extras.append(id); |
193 | } | 192 | } |
194 | 193 | ||
195 | 194 | ||
196 | 195 | ||
197 | void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&) | 196 | void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&) |
198 | { | 197 | { |
199 | if ( msg == "timeZoneListChange()" ) { | 198 | if ( msg == "timeZoneListChange()" ) { |
200 | updateZones(); | 199 | updateZones(); |
201 | } | 200 | } |
202 | } | 201 | } |
203 | 202 | ||
204 | /*! | 203 | /*! |
205 | Creates a new TimeZoneSelector with parent \a p and name \a n. The combobox will be | 204 | Creates a new TimeZoneSelector with parent \a p and name \a n. The combobox will be |
206 | populated with the available timezones. | 205 | populated with the available timezones. |
207 | */ | 206 | */ |
208 | 207 | ||
209 | TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) : | 208 | TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) : |
210 | QHBox(p,n) | 209 | QHBox(p,n) |
211 | { | 210 | { |
212 | d = new TimeZoneSelectorPrivate(); | 211 | d = new TimeZoneSelectorPrivate(); |
213 | // build the combobox before we do any updates... | 212 | // build the combobox before we do any updates... |
214 | cmbTz = new TZCombo( this, "timezone combo" ); | 213 | cmbTz = new TZCombo( this, "timezone combo" ); |
215 | 214 | ||
216 | cmdTz = new QToolButton( this, "timezone button" ); | 215 | cmdTz = new QToolButton( this, "timezone button" ); |
217 | cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) ); | 216 | cmdTz->setIconSet( Resource::loadIconSet( "citytime_icon" ) ); |
218 | cmdTz->setMaximumSize( cmdTz->sizeHint() ); | 217 | cmdTz->setMaximumSize( cmdTz->sizeHint() ); |
219 | 218 | ||
220 | // set up a connection to catch a newly selected item and throw our | 219 | // set up a connection to catch a newly selected item and throw our |
221 | // signal | 220 | // signal |
222 | QObject::connect( cmbTz, SIGNAL( activated( int ) ), | 221 | QObject::connect( cmbTz, SIGNAL( activated( int ) ), |
223 | this, SLOT( slotTzActive( int ) ) ); | 222 | this, SLOT( slotTzActive( int ) ) ); |
224 | QObject::connect( cmdTz, SIGNAL( clicked() ), | 223 | QObject::connect( cmdTz, SIGNAL( clicked() ), |
225 | this, SLOT( slotExecute() ) ); | 224 | this, SLOT( slotExecute() ) ); |
226 | } | 225 | } |
227 | 226 | ||
228 | /*! | 227 | /*! |
229 | Destroys a TimeZoneSelector. | 228 | Destroys a TimeZoneSelector. |
230 | */ | 229 | */ |
231 | TimeZoneSelector::~TimeZoneSelector() | 230 | TimeZoneSelector::~TimeZoneSelector() |
232 | { | 231 | { |
233 | } | 232 | } |
234 | 233 | ||
235 | void TimeZoneSelector::setLocalIncluded(bool b) | 234 | void TimeZoneSelector::setLocalIncluded(bool b) |
236 | { | 235 | { |
237 | d->includeLocal = b; | 236 | d->includeLocal = b; |
238 | cmbTz->updateZones(); | 237 | cmbTz->updateZones(); |
239 | } | 238 | } |
240 | 239 | ||
241 | bool TimeZoneSelector::localIncluded() const | 240 | bool TimeZoneSelector::localIncluded() const |
242 | { | 241 | { |
243 | return d->includeLocal; | 242 | return d->includeLocal; |
244 | } | 243 | } |
245 | 244 | ||
246 | /*! | 245 | /*! |
247 | Returns the currently selected timezone as a string in location format, e.g. | 246 | Returns the currently selected timezone as a string in location format, e.g. |
248 | \code Australia/Brisbane \endcode | 247 | \code Australia/Brisbane \endcode |
249 | */ | 248 | */ |
250 | QString TimeZoneSelector::currentZone() const | 249 | QString TimeZoneSelector::currentZone() const |
251 | { | 250 | { |
252 | return cmbTz->currZone(); | 251 | return cmbTz->currZone(); |
253 | } | 252 | } |
254 | 253 | ||
255 | /*! | 254 | /*! |
256 | Sets the current timezone to \a id. | 255 | Sets the current timezone to \a id. |
257 | */ | 256 | */ |
258 | void TimeZoneSelector::setCurrentZone( const QString& id ) | 257 | void TimeZoneSelector::setCurrentZone( const QString& id ) |
259 | { | 258 | { |
260 | cmbTz->setCurrZone( id ); | 259 | cmbTz->setCurrZone( id ); |
261 | } | 260 | } |
262 | /*! \fn void TimeZoneSelector::signalNewTz( const QString& id ) | 261 | /*! \fn void TimeZoneSelector::signalNewTz( const QString& id ) |
263 | This signal is emitted when a timezone has been selected by the user. The id | 262 | This signal is emitted when a timezone has been selected by the user. The id |
264 | is a \l QString in location format, eg \code Australia/Brisbane \endcode | 263 | is a \l QString in location format, eg \code Australia/Brisbane \endcode |
265 | */ | 264 | */ |
266 | 265 | ||
267 | 266 | ||
268 | void TimeZoneSelector::slotTzActive( int ) | 267 | void TimeZoneSelector::slotTzActive( int ) |
269 | { | 268 | { |
270 | emit signalNewTz( cmbTz->currZone() ); | 269 | emit signalNewTz( cmbTz->currZone() ); |
271 | } | 270 | } |
272 | 271 | ||
273 | void TimeZoneSelector::slotExecute( void ) | 272 | void TimeZoneSelector::slotExecute( void ) |
274 | { | 273 | { |
275 | // execute the world time application... | 274 | // execute the world time application... |
276 | if (QFile::exists(QPEApplication::qpeDir()+"bin/citytime")) | 275 | if (QFile::exists(QPEApplication::qpeDir()+"bin/citytime")) |
277 | Global::execute( "citytime" ); | 276 | Global::execute( "citytime" ); |
278 | else | 277 | else |
279 | QMessageBox::warning(this,tr("citytime executable not found"), | 278 | QMessageBox::warning(this,tr("citytime executable not found"), |
280 | tr("In order to choose the time zones,\nplease install citytime.")); | 279 | tr("In order to choose the time zones,\nplease install citytime.")); |
281 | } | 280 | } |
282 | 281 | ||
283 | QStringList timezoneDefaults( void ) | 282 | QStringList timezoneDefaults( void ) |
284 | { | 283 | { |
285 | QStringList tzs; | 284 | QStringList tzs; |
286 | // load up the list just like the file format (citytime.cpp) | 285 | // load up the list just like the file format (citytime.cpp) |
287 | tzs.append( "America/New_York" ); | 286 | tzs.append( "America/New_York" ); |
288 | tzs.append( "New York" ); | 287 | tzs.append( "New York" ); |
289 | tzs.append( "America/Los_Angeles" ); | 288 | tzs.append( "America/Los_Angeles" ); |
290 | tzs.append( "Los Angeles" ); | 289 | tzs.append( "Los Angeles" ); |
291 | tzs.append( "Australia/Brisbane" ); | 290 | tzs.append( "Australia/Brisbane" ); |
292 | tzs.append( "Brisbane" ); | 291 | tzs.append( "Brisbane" ); |
293 | tzs.append( "Europe/Berlin" ); | 292 | tzs.append( "Europe/Berlin" ); |
294 | tzs.append( "Berlin" ); | 293 | tzs.append( "Berlin" ); |
295 | tzs.append( "Asia/Tokyo" ); | 294 | tzs.append( "Asia/Tokyo" ); |
296 | tzs.append( "Tokyo" ); | 295 | tzs.append( "Tokyo" ); |
297 | tzs.append( "America/Denver" ); | 296 | tzs.append( "America/Denver" ); |
298 | tzs.append( "Denver" ); | 297 | tzs.append( "Denver" ); |
299 | 298 | ||
300 | return tzs; | 299 | return tzs; |
301 | } | 300 | } |
302 | 301 | ||
303 | 302 | ||