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