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