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