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