summaryrefslogtreecommitdiff
path: root/library/tzselect.cpp
Unidiff
Diffstat (limited to 'library/tzselect.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/tzselect.cpp104
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,7 +1,7 @@
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
@@ -18,6 +18,8 @@
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"
@@ -30,16 +32,29 @@
30#include <qcopchannel_qws.h> 32#include <qcopchannel_qws.h>
31#endif 33#endif
32 34
35class TimeZoneSelectorPrivate
36{
37public:
38 TimeZoneSelectorPrivate() : includeLocal(FALSE) {}
39 bool includeLocal;
40};
41
33TZCombo::TZCombo( QWidget *p, const char* n ) 42TZCombo::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;
@@ -76,43 +91,63 @@ void TZCombo::updateZones()
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}
@@ -164,12 +199,12 @@ void TZCombo::handleSystemChannel(const QCString&msg, const QByteArray&)
164TimeZoneSelector::TimeZoneSelector(QWidget* p, const char* n) : 199TimeZoneSelector::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
@@ -184,6 +219,17 @@ TimeZoneSelector::~TimeZoneSelector()
184{ 219{
185} 220}
186 221
222void TimeZoneSelector::setLocalIncluded(bool b)
223{
224 d->includeLocal = b;
225 cmbTz->updateZones();
226}
227
228bool TimeZoneSelector::localIncluded() const
229{
230 return d->includeLocal;
231}
232
187 233
188QString TimeZoneSelector::currentZone() const 234QString TimeZoneSelector::currentZone() const
189{ 235{
@@ -202,8 +248,8 @@ void TimeZoneSelector::slotTzActive( int )
202 248
203void TimeZoneSelector::slotExecute( void ) 249void 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
209QStringList timezoneDefaults( void ) 255QStringList timezoneDefaults( void )