summaryrefslogtreecommitdiff
path: root/library/tzselect.cpp
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /library/tzselect.cpp
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'library/tzselect.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/tzselect.cpp228
1 files changed, 228 insertions, 0 deletions
diff --git a/library/tzselect.cpp b/library/tzselect.cpp
new file mode 100644
index 0000000..5f102d5
--- a/dev/null
+++ b/library/tzselect.cpp
@@ -0,0 +1,228 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
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
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
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.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "tzselect.h"
22#include "resource.h"
23#include "global.h"
24#include "config.h"
25#include <qtoolbutton.h>
26#include <qfile.h>
27#include <stdlib.h>
28
29#ifdef Q_WS_QWS
30#include <qcopchannel_qws.h>
31#endif
32
33TZCombo::TZCombo( QWidget *p, const char* n )
34 : QComboBox( p, n )
35{
36 updateZones();
37 // check to see if TZ is set, if it is set the current item to that
38 QString tz = getenv("TZ");
39 if ( !tz.isNull() ) {
40 int n = 0,
41 index = 0;
42 for ( QStringList::Iterator it=identifiers.begin();
43 it!=identifiers.end(); ++it) {
44 if ( *it == tz )
45 index = n;
46 n++;
47 }
48 setCurrentItem(index);
49 } else {
50 setCurrentItem(0);
51 }
52
53
54
55 // listen on QPE/System
56#if defined(Q_WS_QWS)
57#if !defined(QT_NO_COP)
58 QCopChannel *channel = new QCopChannel( "QPE/System", this );
59 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
60 this, SLOT(handleSystemChannel(const QCString&, const QByteArray&)) );
61#endif
62#endif
63
64
65}
66
67TZCombo::~TZCombo()
68{
69}
70
71void TZCombo::updateZones()
72{
73 QString cur = currentText();
74 clear();
75 identifiers.clear();
76 int curix=0;
77 QString tz = getenv("TZ");
78 bool tzFound = FALSE;
79 Config cfg("CityTime");
80 cfg.setGroup("TimeZones");
81 int i=0;
82 for ( ; 1; i++ ) {
83 QString zn = cfg.readEntry("Zone"+QString::number(i), QString::null);
84 if ( zn.isNull() )
85 break;
86 if ( zn == tz )
87 tzFound = TRUE;
88 QString nm = cfg.readEntry("ZoneName"+QString::number(i));
89 identifiers.append(zn);
90 insertItem(nm);
91 if ( nm == cur )
92 curix = i;
93 }
94 if ( !tzFound && !tz.isEmpty()) {
95 int i = tz.find( '/' );
96 QString nm = tz.mid( i+1 );
97 identifiers.append(tz);
98 insertItem(nm);
99 if ( nm == cur )
100 curix = i;
101 ++i;
102 }
103 for (QStringList::Iterator it=extras.begin(); it!=extras.end(); ++it) {
104 insertItem(*it);
105 identifiers.append(*it);
106 if ( *it == cur )
107 curix = i;
108 ++i;
109 }
110 if ( !i ) {
111 QStringList list = timezoneDefaults();
112 for ( QStringList::Iterator it = list.begin(); it!=list.end(); ++it ) {
113 identifiers.append(*it); ++it;
114 insertItem(*it);
115 }
116 }
117 setCurrentItem(curix);
118}
119
120
121void TZCombo::keyPressEvent( QKeyEvent *e )
122{
123 // ### should popup() in Qt 3.0 (it's virtual there)
124// updateZones();
125 QComboBox::keyPressEvent(e);
126}
127
128void TZCombo::mousePressEvent(QMouseEvent*e)
129{
130 // ### should popup() in Qt 3.0 (it's virtual there)
131// updateZones();
132 QComboBox::mousePressEvent(e);
133}
134
135QString TZCombo::currZone() const
136{
137 return identifiers[currentItem()];
138}
139
140void TZCombo::setCurrZone( const QString& id )
141{
142 for (int i=0; i< count(); i++) {
143 if ( identifiers[i] == id ) {
144 setCurrentItem(i);
145 return;
146 }
147 }
148 insertItem(id);
149 setCurrentItem( count() - 1);
150 identifiers.append(id);
151 extras.append(id);
152}
153
154
155
156void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&)
157{
158 if ( msg == "timeZoneListChange()" ) {
159 updateZones();
160 }
161}
162
163
164TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) :
165 QHBox(p,n)
166{
167 // build the combobox before we do any updates...
168 cmbTz = new TZCombo( this, "timezone combo" );
169
170 cmdTz = new QToolButton( this, "timezone button" );
171 QPixmap pixGlobe = Resource::loadPixmap( "citytime_icon" );
172 cmdTz->setPixmap( pixGlobe );
173 cmdTz->setMaximumSize( cmdTz->sizeHint() );
174
175 // set up a connection to catch a newly selected item and throw our
176 // signal
177 QObject::connect( cmbTz, SIGNAL( activated( int ) ),
178 this, SLOT( slotTzActive( int ) ) );
179 QObject::connect( cmdTz, SIGNAL( clicked() ),
180 this, SLOT( slotExecute() ) );
181}
182
183TimeZoneSelector::~TimeZoneSelector()
184{
185}
186
187
188QString TimeZoneSelector::currentZone() const
189{
190 return cmbTz->currZone();
191}
192
193void TimeZoneSelector::setCurrentZone( const QString& id )
194{
195 cmbTz->setCurrZone( id );
196}
197
198void TimeZoneSelector::slotTzActive( int )
199{
200 emit signalNewTz( cmbTz->currZone() );
201}
202
203void TimeZoneSelector::slotExecute( void )
204{
205 // execute the city time application...
206 Global::execute( "citytime" );
207}
208
209QStringList timezoneDefaults( void )
210{
211 QStringList tzs;
212 // load up the list just like the file format (citytime.cpp)
213 tzs.append( "America/New_York" );
214 tzs.append( "New York" );
215 tzs.append( "America/Los_Angeles" );
216 tzs.append( "Los Angeles" );
217 tzs.append( "Australia/Brisbane" );
218 tzs.append( "Brisbane" );
219 tzs.append( "Europe/Oslo" );
220 tzs.append( "Oslo" );
221 tzs.append( "Asia/Tokyo" );
222 tzs.append( "Tokyo" );
223 tzs.append( "Asia/Hong_Kong" );
224 tzs.append( "Hong Kong" );
225 return tzs;
226}
227
228