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