summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp5
-rw-r--r--noncore/settings/netsystemtime/settime.cpp2
2 files changed, 6 insertions, 1 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 15dae93..6c5aaf5 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -1,329 +1,332 @@
1#include "ntp.h" 1#include "ntp.h"
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qregexp.h> 3#include <qregexp.h>
4#include <qtimer.h> 4#include <qtimer.h>
5#include <qtable.h> 5#include <qtable.h>
6#include <qlabel.h> 6#include <qlabel.h>
7#include <qsocket.h> 7#include <qsocket.h>
8#include <qlineedit.h> 8#include <qlineedit.h>
9#include <qspinbox.h> 9#include <qspinbox.h>
10#include <qmessagebox.h> 10#include <qmessagebox.h>
11#include <qmultilineedit.h> 11#include <qmultilineedit.h>
12#include <opie/oprocess.h> 12#include <opie/oprocess.h>
13#include <qpe/qpeapplication.h> 13#include <qpe/qpeapplication.h>
14#include <qpe/config.h> 14#include <qpe/config.h>
15#include <qpe/global.h> 15#include <qpe/global.h>
16#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
17#include <qpe/tzselect.h> 17#include <qpe/tzselect.h>
18#include <qpe/timestring.h> 18#include <qpe/timestring.h>
19#include <qpe/qpedialog.h> 19#include <qpe/qpedialog.h>
20#include <qpe/datebookdb.h> 20#include <qpe/datebookdb.h>
21#include <qpe/qcopenvelope_qws.h> 21#include <qpe/qcopenvelope_qws.h>
22#include <sys/time.h> 22#include <sys/time.h>
23#include <time.h> 23#include <time.h>
24#include <stdlib.h> 24#include <stdlib.h>
25 25
26 26
27Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) 27Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
28 : SetDateTime( parent, name, fl ) 28 : SetDateTime( parent, name, fl )
29{ 29{
30 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); 30 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
31 ntpSrvs.setGroup("servers"); 31 ntpSrvs.setGroup("servers");
32 int srvCount = ntpSrvs.readNumEntry("count", 0 ); 32 int srvCount = ntpSrvs.readNumEntry("count", 0 );
33 for (int i = 0; i < srvCount; i++) 33 for (int i = 0; i < srvCount; i++)
34 { 34 {
35 ntpSrvs.setGroup(QString::number(i)); 35 ntpSrvs.setGroup(QString::number(i));
36 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); 36 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
37 } 37 }
38 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); 38 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
39 39
40 Config cfg("ntp",Config::User); 40 Config cfg("ntp",Config::User);
41 cfg.setGroup("settings"); 41 cfg.setGroup("settings");
42 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); 42 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
43 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); 43 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
44 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 44 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
45 45
46 makeChannel(); 46 makeChannel();
47 47
48 ntpTimer = new QTimer(this); 48 ntpTimer = new QTimer(this);
49 49
50 ntpProcess = new OProcess( ); 50 ntpProcess = new OProcess( );
51 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 51 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
52 SLOT(slotNtpDelayChanged(int)) ); 52 SLOT(slotNtpDelayChanged(int)) );
53 53
54 ntpSock = new QSocket( this ); 54 ntpSock = new QSocket( this );
55 connect( ntpSock, SIGNAL( error(int) ), 55 connect( ntpSock, SIGNAL( error(int) ),
56 SLOT(slotCheckNtp(int)) ); 56 SLOT(slotCheckNtp(int)) );
57 slotProbeNtpServer(); 57 slotProbeNtpServer();
58 58
59 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 59 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
60 this, SLOT(getNtpOutput(OProcess*,char*,int))); 60 this, SLOT(getNtpOutput(OProcess*,char*,int)));
61 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 61 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
62 this, SLOT(ntpFinished(OProcess*))); 62 this, SLOT(ntpFinished(OProcess*)));
63 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); 63 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp()));
64 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 64 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
65 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 65 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
66 slotCheckNtp(-1); 66 slotCheckNtp(-1);
67 readLookups(); 67 readLookups();
68} 68}
69 69
70Ntp::~Ntp() 70Ntp::~Ntp()
71{ 71{
72 delete ntpProcess; 72 delete ntpProcess;
73 Config ntpSrvs("/etc/ntpservers",Config::File); 73 Config ntpSrvs("/etc/ntpservers",Config::File);
74 ntpSrvs.setGroup("servers"); 74 ntpSrvs.setGroup("servers");
75 int srvCount = ComboNtpSrv->count(); 75 int srvCount = ComboNtpSrv->count();
76 ntpSrvs.writeEntry("count", srvCount); 76 ntpSrvs.writeEntry("count", srvCount);
77 for (int i = 0; i < srvCount; i++) 77 for (int i = 0; i < srvCount; i++)
78 { 78 {
79 ntpSrvs.setGroup(QString::number(i)); 79 ntpSrvs.setGroup(QString::number(i));
80 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); 80 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
81 } 81 }
82 Config cfg("ntp",Config::User); 82 Config cfg("ntp",Config::User);
83 cfg.setGroup("settings"); 83 cfg.setGroup("settings");
84 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); 84 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
85 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 85 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
86 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 86 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
87} 87}
88 88
89bool Ntp::ntpDelayElapsed() 89bool Ntp::ntpDelayElapsed()
90{ 90{
91 Config cfg("ntp",Config::User); 91 Config cfg("ntp",Config::User);
92 cfg.setGroup("lookups"); 92 cfg.setGroup("lookups");
93 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 93 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
94 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; 94 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60;
95} 95}
96 96
97QString Ntp::getNtpServer() 97QString Ntp::getNtpServer()
98{ 98{
99 return ComboNtpSrv->currentText(); 99 return ComboNtpSrv->currentText();
100} 100}
101 101
102void Ntp::slotRunNtp() 102void Ntp::slotRunNtp()
103{ 103{
104 if ( !ntpDelayElapsed() ) 104 if ( !ntpDelayElapsed() )
105 { 105 {
106 switch ( 106 switch (
107 QMessageBox::warning(this, tr("Run NTP?"), 107 QMessageBox::warning(this, tr("Run NTP?"),
108 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 108 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
109 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ 109 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+
110 "<br>"+tr("Rerun NTP?"), 110 "<br>"+tr("Rerun NTP?"),
111 QMessageBox::Ok,QMessageBox::Cancel) 111 QMessageBox::Ok,QMessageBox::Cancel)
112 ) { 112 ) {
113 case QMessageBox::Ok: break; 113 case QMessageBox::Ok: break;
114 case QMessageBox::Cancel: return; 114 case QMessageBox::Cancel: return;
115 default: return; 115 default: return;
116 } 116 }
117 } 117 }
118 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 118 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
119 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 119 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
120 120
121 ntpProcess->clearArguments(); 121 ntpProcess->clearArguments();
122 *ntpProcess << "ntpdate" << getNtpServer(); 122 *ntpProcess << "ntpdate" << getNtpServer();
123 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 123 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
124 if ( !ret ) { 124 if ( !ret ) {
125 qDebug("Error while executing ntpdate"); 125 qDebug("Error while executing ntpdate");
126 ntpOutPut( tr("Error while executing ntpdate")); 126 ntpOutPut( tr("Error while executing ntpdate"));
127 } 127 }
128} 128}
129 129
130void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 130void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
131{ 131{
132 QString lineStr, lineStrOld; 132 QString lineStr, lineStrOld;
133 lineStr = buffer; 133 lineStr = buffer;
134 lineStr=lineStr.left(buflen); 134 lineStr=lineStr.left(buflen);
135 if (lineStr!=lineStrOld) 135 if (lineStr!=lineStrOld)
136 { 136 {
137 ntpOutPut(lineStr); 137 ntpOutPut(lineStr);
138 _ntpOutput += lineStr; 138 _ntpOutput += lineStr;
139 } 139 }
140 lineStrOld = lineStr; 140 lineStrOld = lineStr;
141} 141}
142 142
143void Ntp::ntpFinished(OProcess *p) 143void Ntp::ntpFinished(OProcess *p)
144{ 144{
145 qDebug("p->exitStatus() %i",p->exitStatus()); 145 qDebug("p->exitStatus() %i",p->exitStatus());
146 if (p->exitStatus()!=0 || !p->normalExit()) 146 if (p->exitStatus()!=0 || !p->normalExit())
147 { 147 {
148 slotProbeNtpServer(); 148 slotProbeNtpServer();
149 return; 149 return;
150 } 150 }
151 151
152 Global::writeHWClock(); 152 Global::writeHWClock();
153 // since time has changed quickly load in the datebookdb 153 // since time has changed quickly load in the datebookdb
154 // to allow the alarm server to get a better grip on itself 154 // to allow the alarm server to get a better grip on itself
155 // (example re-trigger alarms for when we travel back in time) 155 // (example re-trigger alarms for when we travel back in time)
156 DateBookDB db; 156 DateBookDB db;
157 157
158 QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" );
159 timeApplet << "";
160
158 Config cfg("ntp",Config::User); 161 Config cfg("ntp",Config::User);
159 cfg.setGroup("lookups"); 162 cfg.setGroup("lookups");
160 int lastLookup = cfg.readNumEntry("time",0); 163 int lastLookup = cfg.readNumEntry("time",0);
161 int lookupCount = cfg.readNumEntry("count",0); 164 int lookupCount = cfg.readNumEntry("count",0);
162 bool lastNtp = cfg.readBoolEntry("lastNtp",false); 165 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
163 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 166 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
164 cfg.writeEntry("time", time); 167 cfg.writeEntry("time", time);
165 168
166 float timeShift = getTimeShift(); 169 float timeShift = getTimeShift();
167 if (timeShift == 0.0) return; 170 if (timeShift == 0.0) return;
168 int secsSinceLast = time - lastLookup; 171 int secsSinceLast = time - lastLookup;
169 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 172 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
170 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 173 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
171 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 174 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
172 { 175 {
173 cfg.setGroup("lookup_"+QString::number(lookupCount)); 176 cfg.setGroup("lookup_"+QString::number(lookupCount));
174 lookupCount++; 177 lookupCount++;
175 _shiftPerSec = timeShift / secsSinceLast; 178 _shiftPerSec = timeShift / secsSinceLast;
176 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 179 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
177 cfg.writeEntry("secsSinceLast",secsSinceLast); 180 cfg.writeEntry("secsSinceLast",secsSinceLast);
178 cfg.writeEntry("timeShift",QString::number(timeShift)); 181 cfg.writeEntry("timeShift",QString::number(timeShift));
179 cfg.setGroup("lookups"); 182 cfg.setGroup("lookups");
180 cfg.writeEntry("count",lookupCount); 183 cfg.writeEntry("count",lookupCount);
181 cfg.writeEntry("lastNtp",true); 184 cfg.writeEntry("lastNtp",true);
182 } 185 }
183} 186}
184 187
185 188
186float Ntp::getTimeShift() 189float Ntp::getTimeShift()
187{ 190{
188 QString _offset = "offset"; 191 QString _offset = "offset";
189 QString _sec = "sec"; 192 QString _sec = "sec";
190 QRegExp _reOffset = QRegExp(_offset); 193 QRegExp _reOffset = QRegExp(_offset);
191 QRegExp _reEndOffset = QRegExp(_sec); 194 QRegExp _reEndOffset = QRegExp(_sec);
192 int posOffset = _reOffset.match( _ntpOutput ); 195 int posOffset = _reOffset.match( _ntpOutput );
193 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 196 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
194 posOffset += _offset.length() + 1; 197 posOffset += _offset.length() + 1;
195 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 198 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
196 qDebug("%s", _ntpOutput.latin1()); 199 qDebug("%s", _ntpOutput.latin1());
197 qDebug("diff = >%s<",diff.latin1()); 200 qDebug("diff = >%s<",diff.latin1());
198 return diff.toFloat(); 201 return diff.toFloat();
199} 202}
200 203
201void Ntp::readLookups() 204void Ntp::readLookups()
202{ 205{
203 Config cfg("ntp",Config::User); 206 Config cfg("ntp",Config::User);
204 cfg.setGroup("lookups"); 207 cfg.setGroup("lookups");
205 int lookupCount = cfg.readNumEntry("count",0); 208 int lookupCount = cfg.readNumEntry("count",0);
206 float last, shift, shiftPerSec; 209 float last, shift, shiftPerSec;
207 qDebug("lookupCount = %i",lookupCount); 210 qDebug("lookupCount = %i",lookupCount);
208 TableLookups->setNumCols( 3 ); 211 TableLookups->setNumCols( 3 );
209 TableLookups->setNumRows( lookupCount); 212 TableLookups->setNumRows( lookupCount);
210 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); 213 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
211 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); 214 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
212 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); 215 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
213 int cw = TableLookups->width()/4; 216 int cw = TableLookups->width()/4;
214 qDebug("column width %i",cw); 217 qDebug("column width %i",cw);
215 cw = 50; 218 cw = 50;
216 TableLookups->setColumnWidth( 0, cw+30 ); 219 TableLookups->setColumnWidth( 0, cw+30 );
217 TableLookups->setColumnWidth( 1, cw ); 220 TableLookups->setColumnWidth( 1, cw );
218 TableLookups->setColumnWidth( 2, cw ); 221 TableLookups->setColumnWidth( 2, cw );
219 TableLookups->sortColumn(0, false, true ); 222 TableLookups->sortColumn(0, false, true );
220 // TableLookups->setSorting( true ); 223 // TableLookups->setSorting( true );
221 _shiftPerSec = 0; 224 _shiftPerSec = 0;
222 for (int i=0; i < lookupCount; i++) 225 for (int i=0; i < lookupCount; i++)
223 { 226 {
224 cfg.setGroup("lookup_"+QString::number(i)); 227 cfg.setGroup("lookup_"+QString::number(i));
225 last = cfg.readEntry("secsSinceLast",0).toFloat(); 228 last = cfg.readEntry("secsSinceLast",0).toFloat();
226 shift = QString(cfg.readEntry("timeShift",0)).toFloat(); 229 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
227 shiftPerSec = shift / last; 230 shiftPerSec = shift / last;
228 qDebug("%i shift %f",i,shiftPerSec); 231 qDebug("%i shift %f",i,shiftPerSec);
229 _shiftPerSec += shiftPerSec; 232 _shiftPerSec += shiftPerSec;
230 TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); 233 TableLookups->setText( i,0,QString::number(shiftPerSec*60*60));
231 TableLookups->setText( i,2,QString::number(shift)); 234 TableLookups->setText( i,2,QString::number(shift));
232 TableLookups->setText( i,1,QString::number(last/(60*60))); 235 TableLookups->setText( i,1,QString::number(last/(60*60)));
233 } 236 }
234 _shiftPerSec /= lookupCount; 237 _shiftPerSec /= lookupCount;
235 TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); 238 TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h"));
236} 239}
237 240
238void Ntp::preditctTime() 241void Ntp::preditctTime()
239{ 242{
240 Config cfg("ntp",Config::User); 243 Config cfg("ntp",Config::User);
241 cfg.setGroup("lookups"); 244 cfg.setGroup("lookups");
242 int lastTime = cfg.readNumEntry("time",0); 245 int lastTime = cfg.readNumEntry("time",0);
243 cfg.writeEntry("lastNtp",true); 246 cfg.writeEntry("lastNtp",true);
244 setenv( "TZ", tz->currentZone(), 1 ); 247 setenv( "TZ", tz->currentZone(), 1 );
245 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 248 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
246 int corr = int((now - lastTime) * _shiftPerSec); 249 int corr = int((now - lastTime) * _shiftPerSec);
247 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); 250 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
248 predictedTime = QDateTime::currentDateTime().addSecs(corr); 251 predictedTime = QDateTime::currentDateTime().addSecs(corr);
249 TextLabelPredTime->setText(predictedTime.toString()); 252 TextLabelPredTime->setText(predictedTime.toString());
250 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); 253 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
251} 254}
252 255
253void Ntp::setPredictTime() 256void Ntp::setPredictTime()
254{ 257{
255 preditctTime(); 258 preditctTime();
256 setTime( predictedTime ); 259 setTime( predictedTime );
257} 260}
258 261
259void Ntp::slotCheckNtp(int i) 262void Ntp::slotCheckNtp(int i)
260{ 263{
261 if (i == 0) 264 if (i == 0)
262 { 265 {
263 TextLabelMainPredTime->hide(); 266 TextLabelMainPredTime->hide();
264 ButtonSetTime->setText( tr("Get time from network") ); 267 ButtonSetTime->setText( tr("Get time from network") );
265 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); 268 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
266 if ( ntpDelayElapsed() ) 269 if ( ntpDelayElapsed() )
267 { 270 {
268 slotRunNtp(); 271 slotRunNtp();
269 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); 272 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
270 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); 273 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
271 }else{ 274 }else{
272 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); 275 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
273 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 276 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
274 } 277 }
275 }else{ 278 }else{
276 preditctTime(); 279 preditctTime();
277 ButtonSetTime->setText( tr("Set predicted time") ); 280 ButtonSetTime->setText( tr("Set predicted time") );
278 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); 281 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
279 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 282 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
280 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 283 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
281 } 284 }
282} 285}
283 286
284void Ntp::slotProbeNtpServer() 287void Ntp::slotProbeNtpServer()
285{ 288{
286 qDebug("Ntp::slotProbeNtpServer()"); 289 qDebug("Ntp::slotProbeNtpServer()");
287 ntpSock->connectToHost( getNtpServer() ,123); 290 ntpSock->connectToHost( getNtpServer() ,123);
288} 291}
289 292
290void Ntp::slotNtpDelayChanged(int delay) 293void Ntp::slotNtpDelayChanged(int delay)
291{ 294{
292 ntpTimer->changeInterval( delay*1000*60 ); 295 ntpTimer->changeInterval( delay*1000*60 );
293} 296}
294 297
295void Ntp::ntpOutPut(QString out) 298void Ntp::ntpOutPut(QString out)
296{ 299{
297 MultiLineEditntpOutPut->append(out); 300 MultiLineEditntpOutPut->append(out);
298 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); 301 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
299} 302}
300 303
301 304
302void Ntp::makeChannel() 305void Ntp::makeChannel()
303 { 306 {
304 channel = new QCopChannel( "QPE/Application/netsystemtime", this ); 307 channel = new QCopChannel( "QPE/Application/netsystemtime", this );
305 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 308 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
306 this, SLOT(receive(const QCString&, const QByteArray&)) ); 309 this, SLOT(receive(const QCString&, const QByteArray&)) );
307} 310}
308 311
309 312
310 313
311void Ntp::receive(const QCString &msg, const QByteArray &arg) 314void Ntp::receive(const QCString &msg, const QByteArray &arg)
312{ 315{
313 qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); 316 qDebug("QCop(Ntp) "+msg+" "+QCString(arg));
314 if ( msg == "ntpLookup(QString)" ) 317 if ( msg == "ntpLookup(QString)" )
315 { 318 {
316 slotRunNtp(); 319 slotRunNtp();
317 } 320 }
318 if ( msg == "setPredictedTime(QString)" ) 321 if ( msg == "setPredictedTime(QString)" )
319 { 322 {
320 setPredictTime(); 323 setPredictTime();
321 }else{ 324 }else{
322 qDebug("Ntp::receive: Huh what do ya want"); 325 qDebug("Ntp::receive: Huh what do ya want");
323 } 326 }
324} 327}
325 328
326void Ntp::setDocument(const QString &fileName) 329void Ntp::setDocument(const QString &fileName)
327{ 330{
328 331
329} \ No newline at end of file 332} \ No newline at end of file
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp
index b0fcb74..e3b2ddd 100644
--- a/noncore/settings/netsystemtime/settime.cpp
+++ b/noncore/settings/netsystemtime/settime.cpp
@@ -79,384 +79,386 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f )
79 tz->setMinimumSize( tz->sizeHint() ); 79 tz->setMinimumSize( tz->sizeHint() );
80 hb->addWidget( tz ); 80 hb->addWidget( tz );
81 81
82 timeButton = new SetTime( FrameSetTime ); 82 timeButton = new SetTime( FrameSetTime );
83 vb2->addWidget( timeButton ); 83 vb2->addWidget( timeButton );
84 84
85 QHBoxLayout *db = new QHBoxLayout( vb2 ); 85 QHBoxLayout *db = new QHBoxLayout( vb2 );
86 QLabel *dateLabel = new QLabel( tr("Date"), FrameSetTime ); 86 QLabel *dateLabel = new QLabel( tr("Date"), FrameSetTime );
87 db->addWidget( dateLabel, 1 ); 87 db->addWidget( dateLabel, 1 );
88 dateButton = new DateButton( TRUE, FrameSetTime ); 88 dateButton = new DateButton( TRUE, FrameSetTime );
89 db->addWidget( dateButton, 2 ); 89 db->addWidget( dateButton, 2 );
90 90
91 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); 91 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
92 vb2->addItem( spacer ); 92 vb2->addItem( spacer );
93 93
94 hline = new QFrame( FrameSystemTime ); 94 hline = new QFrame( FrameSystemTime );
95 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); 95 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
96 vb->addWidget( hline ); 96 vb->addWidget( hline );
97 97
98 Config config("qpe"); 98 Config config("qpe");
99 config.setGroup( "Time" ); 99 config.setGroup( "Time" );
100 100
101 QHBoxLayout *hb1 = new QHBoxLayout( vb ); 101 QHBoxLayout *hb1 = new QHBoxLayout( vb );
102 102
103 QLabel *l = new QLabel( tr("Time format"), FrameSystemTime ); 103 QLabel *l = new QLabel( tr("Time format"), FrameSystemTime );
104 hb1->addWidget( l, 1 ); 104 hb1->addWidget( l, 1 );
105 105
106 106
107 ampmCombo = new QComboBox( FrameSystemTime ); 107 ampmCombo = new QComboBox( FrameSystemTime );
108 ampmCombo->insertItem( tr("24 hour"), 0 ); 108 ampmCombo->insertItem( tr("24 hour"), 0 );
109 ampmCombo->insertItem( tr("12 hour"), 1 ); 109 ampmCombo->insertItem( tr("12 hour"), 1 );
110 hb1->addWidget( ampmCombo, 2 ); 110 hb1->addWidget( ampmCombo, 2 );
111 111
112 int show12hr = config.readBoolEntry("AMPM") ? 1 : 0; 112 int show12hr = config.readBoolEntry("AMPM") ? 1 : 0;
113 ampmCombo->setCurrentItem( show12hr ); 113 ampmCombo->setCurrentItem( show12hr );
114 timeButton->show12hourTime( show12hr ); 114 timeButton->show12hourTime( show12hr );
115 115
116 connect(ampmCombo, SIGNAL(activated(int)), 116 connect(ampmCombo, SIGNAL(activated(int)),
117 timeButton, SLOT(show12hourTime(int))); 117 timeButton, SLOT(show12hourTime(int)));
118 118
119 119
120 120
121 QHBoxLayout *hb2 = new QHBoxLayout( vb ); 121 QHBoxLayout *hb2 = new QHBoxLayout( vb );
122 l = new QLabel( tr("Weeks start on" ), FrameSystemTime ); 122 l = new QLabel( tr("Weeks start on" ), FrameSystemTime );
123 //l->setAlignment( AlignRight | AlignVCenter ); 123 //l->setAlignment( AlignRight | AlignVCenter );
124 hb2->addWidget( l, 1 ); 124 hb2->addWidget( l, 1 );
125 125
126 weekStartCombo = new QComboBox( FrameSystemTime ); 126 weekStartCombo = new QComboBox( FrameSystemTime );
127 weekStartCombo->insertItem( tr("Sunday"), 0 ); 127 weekStartCombo->insertItem( tr("Sunday"), 0 );
128 weekStartCombo->insertItem( tr("Monday"), 1 ); 128 weekStartCombo->insertItem( tr("Monday"), 1 );
129 129
130 hb2->addWidget( weekStartCombo, 2 ); 130 hb2->addWidget( weekStartCombo, 2 );
131 int startMonday = config.readBoolEntry("MONDAY") ? 1 : 0; 131 int startMonday = config.readBoolEntry("MONDAY") ? 1 : 0;
132 dateButton->setWeekStartsMonday( startMonday ); 132 dateButton->setWeekStartsMonday( startMonday );
133 weekStartCombo->setCurrentItem( startMonday ); 133 weekStartCombo->setCurrentItem( startMonday );
134 134
135 connect( weekStartCombo, SIGNAL( activated(int)), 135 connect( weekStartCombo, SIGNAL( activated(int)),
136 dateButton, SLOT(setWeekStartsMonday(int))); 136 dateButton, SLOT(setWeekStartsMonday(int)));
137 137
138 138
139 QHBoxLayout *hb3 = new QHBoxLayout( vb ); 139 QHBoxLayout *hb3 = new QHBoxLayout( vb );
140 l = new QLabel( tr("Date format" ), FrameSystemTime ); 140 l = new QLabel( tr("Date format" ), FrameSystemTime );
141 hb3->addWidget( l, 1 ); 141 hb3->addWidget( l, 1 );
142 dateFormatCombo = new QComboBox( FrameSystemTime ); 142 dateFormatCombo = new QComboBox( FrameSystemTime );
143 hb3->addWidget( dateFormatCombo, 2 ); 143 hb3->addWidget( dateFormatCombo, 2 );
144 144
145 config.setGroup( "Date" ); 145 config.setGroup( "Date" );
146 DateFormat df(QChar(config.readEntry("Separator", "/")[0]), 146 DateFormat df(QChar(config.readEntry("Separator", "/")[0]),
147 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), 147 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
148 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); 148 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
149 149
150 int currentdf = 0; 150 int currentdf = 0;
151 date_formats[0] = DateFormat('/', DateFormat::MonthDayYear); 151 date_formats[0] = DateFormat('/', DateFormat::MonthDayYear);
152 dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) ); 152 dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) );
153 date_formats[1] = DateFormat('.', DateFormat::DayMonthYear); 153 date_formats[1] = DateFormat('.', DateFormat::DayMonthYear);
154 if (df == date_formats[1]) 154 if (df == date_formats[1])
155 currentdf = 1; 155 currentdf = 1;
156 dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) ); 156 dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) );
157 date_formats[2] = DateFormat('-', DateFormat::YearMonthDay, 157 date_formats[2] = DateFormat('-', DateFormat::YearMonthDay,
158 DateFormat::DayMonthYear); 158 DateFormat::DayMonthYear);
159 if (df == date_formats[2]) 159 if (df == date_formats[2])
160 currentdf = 2; 160 currentdf = 2;
161 dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601 161 dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601
162 date_formats[3] = DateFormat('/', DateFormat::DayMonthYear); 162 date_formats[3] = DateFormat('/', DateFormat::DayMonthYear);
163 if (df == date_formats[3]) 163 if (df == date_formats[3])
164 currentdf = 3; 164 currentdf = 3;
165 dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) ); 165 dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) );
166 166
167 dateFormatCombo->setCurrentItem( currentdf ); 167 dateFormatCombo->setCurrentItem( currentdf );
168 dateButton->setDateFormat( df ); 168 dateButton->setDateFormat( df );
169 169
170 connect( dateFormatCombo, SIGNAL( activated(int)), 170 connect( dateFormatCombo, SIGNAL( activated(int)),
171 SLOT(formatChanged(int))); 171 SLOT(formatChanged(int)));
172 172
173 QHBoxLayout *hb4 = new QHBoxLayout( vb ); 173 QHBoxLayout *hb4 = new QHBoxLayout( vb );
174 l = new QLabel( tr("Applet format" ), FrameSystemTime ); 174 l = new QLabel( tr("Applet format" ), FrameSystemTime );
175 hb4->addWidget( l, 1 ); 175 hb4->addWidget( l, 1 );
176 176
177 clockAppletCombo = new QComboBox( FrameSystemTime ); 177 clockAppletCombo = new QComboBox( FrameSystemTime );
178 clockAppletCombo->insertItem( tr("hh:mm"), 0 ); 178 clockAppletCombo->insertItem( tr("hh:mm"), 0 );
179 clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); 179 clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 );
180 clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); 180 clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 );
181 181
182 hb4->addWidget( clockAppletCombo, 2 ); 182 hb4->addWidget( clockAppletCombo, 2 );
183 int clockApplet = config.readNumEntry("ClockApplet",0); 183 int clockApplet = config.readNumEntry("ClockApplet",0);
184 clockAppletCombo->setCurrentItem( clockApplet ); 184 clockAppletCombo->setCurrentItem( clockApplet );
185 185
186 vb->addStretch( 0 ); 186 vb->addStretch( 0 );
187 187
188 QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()), 188 QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()),
189 this, SLOT(commitTime())); 189 this, SLOT(commitTime()));
190 190
191 QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), 191 QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ),
192 timeButton, SLOT( slotTzChange( const QString& ) ) ); 192 timeButton, SLOT( slotTzChange( const QString& ) ) );
193 QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), 193 QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ),
194 SLOT( tzChange( const QString& ) ) ); 194 SLOT( tzChange( const QString& ) ) );
195 195
196 QObject::connect( weekStartCombo, SIGNAL( activated ( int )), 196 QObject::connect( weekStartCombo, SIGNAL( activated ( int )),
197 SLOT(updateSystem(int ) )); 197 SLOT(updateSystem(int ) ));
198 QObject::connect( ampmCombo, SIGNAL( activated ( int )), 198 QObject::connect( ampmCombo, SIGNAL( activated ( int )),
199 SLOT(updateSystem(int ) )); 199 SLOT(updateSystem(int ) ));
200 QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), 200 QObject::connect( dateFormatCombo, SIGNAL( activated ( int )),
201 SLOT(updateSystem(int ) )); 201 SLOT(updateSystem(int ) ));
202 QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), 202 QObject::connect( clockAppletCombo, SIGNAL( activated ( int )),
203 SLOT(updateSystem(int ) )); 203 SLOT(updateSystem(int ) ));
204} 204}
205 205
206SetDateTime::~SetDateTime() 206SetDateTime::~SetDateTime()
207{ 207{
208 writeSettings(); 208 writeSettings();
209 209
210} 210}
211 211
212void SetDateTime::writeSettings() 212void SetDateTime::writeSettings()
213{ 213{
214 Config config("qpe"); 214 Config config("qpe");
215 config.setGroup( "Time" ); 215 config.setGroup( "Time" );
216 config.writeEntry( "AMPM", ampmCombo->currentItem() ); 216 config.writeEntry( "AMPM", ampmCombo->currentItem() );
217 config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); 217 config.writeEntry( "MONDAY", weekStartCombo->currentItem() );
218 config.setGroup( "Date" ); 218 config.setGroup( "Date" );
219 DateFormat df = date_formats[dateFormatCombo->currentItem()]; 219 DateFormat df = date_formats[dateFormatCombo->currentItem()];
220 config.writeEntry( "Separator", QString(df.separator())); 220 config.writeEntry( "Separator", QString(df.separator()));
221 config.writeEntry( "ShortOrder", df.shortOrder()); 221 config.writeEntry( "ShortOrder", df.shortOrder());
222 config.writeEntry( "LongOrder", df.longOrder()); 222 config.writeEntry( "LongOrder", df.longOrder());
223 config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() ); 223 config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() );
224 224
225 Config lconfig("locale"); 225 Config lconfig("locale");
226 lconfig.setGroup( "Location" ); 226 lconfig.setGroup( "Location" );
227 lconfig.writeEntry( "Timezone", tz->currentZone() ); 227 lconfig.writeEntry( "Timezone", tz->currentZone() );
228 228
229} 229}
230 230
231void SetDateTime::commitTime() 231void SetDateTime::commitTime()
232{ 232{
233 Config cfg("ntp",Config::User); 233 Config cfg("ntp",Config::User);
234 cfg.setGroup("lookups"); 234 cfg.setGroup("lookups");
235 cfg.writeEntry("lastNtp",false); 235 cfg.writeEntry("lastNtp",false);
236 tz->setFocus(); 236 tz->setFocus();
237 // Need to process the QCOP event generated above before proceeding 237 // Need to process the QCOP event generated above before proceeding
238 qApp->processEvents(); 238 qApp->processEvents();
239 239
240 // before we progress further, set our TZ! 240 // before we progress further, set our TZ!
241 setenv( "TZ", tz->currentZone(), 1 ); 241 setenv( "TZ", tz->currentZone(), 1 );
242 // now set the time... 242 // now set the time...
243 QDateTime dt( dateButton->date(), timeButton->time() ); 243 QDateTime dt( dateButton->date(), timeButton->time() );
244 244
245 if ( dt.isValid() ) setTime(dt); 245 if ( dt.isValid() ) setTime(dt);
246} 246}
247 247
248void SetDateTime::setTime(QDateTime dt) 248void SetDateTime::setTime(QDateTime dt)
249{ 249{
250 // really turn off the screensaver before doing anything 250 // really turn off the screensaver before doing anything
251 { 251 {
252 // Needs to be encased in { } so that it deconstructs and sends 252 // Needs to be encased in { } so that it deconstructs and sends
253 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 253 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
254 disableScreenSaver << 0 << 0 << 0; 254 disableScreenSaver << 0 << 0 << 0;
255 } 255 }
256 Config cfg("ntp",Config::User); 256 Config cfg("ntp",Config::User);
257 cfg.setGroup("correction"); 257 cfg.setGroup("correction");
258 int t = TimeConversion::toUTC(dt); 258 int t = TimeConversion::toUTC(dt);
259 struct timeval myTv; 259 struct timeval myTv;
260 myTv.tv_sec = t; 260 myTv.tv_sec = t;
261 cfg.writeEntry("time", t ); 261 cfg.writeEntry("time", t );
262 myTv.tv_usec = 0; 262 myTv.tv_usec = 0;
263 263
264 if ( myTv.tv_sec != -1 ) 264 if ( myTv.tv_sec != -1 )
265 ::settimeofday( &myTv, 0 ); 265 ::settimeofday( &myTv, 0 );
266 Global::writeHWClock(); 266 Global::writeHWClock();
267 // since time has changed quickly load in the datebookdb 267 // since time has changed quickly load in the datebookdb
268 // to allow the alarm server to get a better grip on itself 268 // to allow the alarm server to get a better grip on itself
269 // (example re-trigger alarms for when we travel back in time) 269 // (example re-trigger alarms for when we travel back in time)
270 DateBookDB db; 270 DateBookDB db;
271 QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" );
272 timeApplet << "";
271 // Restore screensaver 273 // Restore screensaver
272 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 274 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
273 enableScreenSaver << -1 << -1 << -1; 275 enableScreenSaver << -1 << -1 << -1;
274} 276}
275 277
276void SetDateTime::updateSystem(int i) 278void SetDateTime::updateSystem(int i)
277{ 279{
278 // really turn off the screensaver before doing anything 280 // really turn off the screensaver before doing anything
279 { 281 {
280 // Needs to be encased in { } so that it deconstructs and sends 282 // Needs to be encased in { } so that it deconstructs and sends
281 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 283 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
282 disableScreenSaver << 0 << 0 << 0; 284 disableScreenSaver << 0 << 0 << 0;
283 } 285 }
284 qDebug("SetDateTime::updateSystem(int %i)",i); 286 qDebug("SetDateTime::updateSystem(int %i)",i);
285 writeSettings(); 287 writeSettings();
286 288
287 // set the timezone for everyone else... 289 // set the timezone for everyone else...
288 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); 290 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
289 setTimeZone << tz->currentZone(); 291 setTimeZone << tz->currentZone();
290 292
291 // AM/PM setting and notify time changed 293 // AM/PM setting and notify time changed
292 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); 294 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
293 setClock << ampmCombo->currentItem(); 295 setClock << ampmCombo->currentItem();
294 296
295 // Notify everyone what day we prefer to start the week on. 297 // Notify everyone what day we prefer to start the week on.
296 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); 298 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
297 setWeek << weekStartCombo->currentItem(); 299 setWeek << weekStartCombo->currentItem();
298 300
299 // Notify everyone what date format to use 301 // Notify everyone what date format to use
300 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); 302 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
301 setDateFormat << date_formats[dateFormatCombo->currentItem()]; 303 setDateFormat << date_formats[dateFormatCombo->currentItem()];
302 304
303 // Restore screensaver 305 // Restore screensaver
304 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 306 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
305 enableScreenSaver << -1 << -1 << -1; 307 enableScreenSaver << -1 << -1 << -1;
306 // since time has changed quickly load in the datebookdb 308 // since time has changed quickly load in the datebookdb
307 // to allow the alarm server to get a better grip on itself 309 // to allow the alarm server to get a better grip on itself
308 // (example re-trigger alarms for when we travel back in time) 310 // (example re-trigger alarms for when we travel back in time)
309 DateBookDB db; 311 DateBookDB db;
310 312
311} 313}
312 314
313void SetDateTime::tzChange( const QString &tz ) 315void SetDateTime::tzChange( const QString &tz )
314{ 316{
315 // set the TZ get the time and leave gracefully... 317 // set the TZ get the time and leave gracefully...
316 QString strSave; 318 QString strSave;
317 strSave = getenv( "TZ" ); 319 strSave = getenv( "TZ" );
318 setenv( "TZ", tz, 1 ); 320 setenv( "TZ", tz, 1 );
319 321
320 QDate d = QDate::currentDate(); 322 QDate d = QDate::currentDate();
321 // reset the time. 323 // reset the time.
322 if ( !strSave.isNull() ) { 324 if ( !strSave.isNull() ) {
323 setenv( "TZ", strSave, 1 ); 325 setenv( "TZ", strSave, 1 );
324 } 326 }
325 dateButton->setDate( d ); 327 dateButton->setDate( d );
326 updateSystem(); 328 updateSystem();
327} 329}
328 330
329void SetDateTime::formatChanged(int i) 331void SetDateTime::formatChanged(int i)
330{ 332{
331 dateButton->setDateFormat(date_formats[i]); 333 dateButton->setDateFormat(date_formats[i]);
332} 334}
333 335
334static const int ValueAM = 0; 336static const int ValueAM = 0;
335static const int ValuePM = 1; 337static const int ValuePM = 1;
336 338
337 339
338 340
339SetTime::SetTime( QWidget *parent, const char *name ) 341SetTime::SetTime( QWidget *parent, const char *name )
340 : QWidget( parent, name ) 342 : QWidget( parent, name )
341{ 343{
342 use12hourTime = FALSE; 344 use12hourTime = FALSE;
343 345
344 QTime currTime = QTime::currentTime(); 346 QTime currTime = QTime::currentTime();
345 hour = currTime.hour(); 347 hour = currTime.hour();
346 minute = currTime.minute(); 348 minute = currTime.minute();
347 349
348 QHBoxLayout *hb2 = new QHBoxLayout( this ); 350 QHBoxLayout *hb2 = new QHBoxLayout( this );
349 hb2->setSpacing( 3 ); 351 hb2->setSpacing( 3 );
350 352
351 QLabel *l = new QLabel( tr("Hour"), this ); 353 QLabel *l = new QLabel( tr("Hour"), this );
352 // l->setAlignment( AlignRight | AlignVCenter ); 354 // l->setAlignment( AlignRight | AlignVCenter );
353 hb2->addWidget( l ); 355 hb2->addWidget( l );
354 356
355 sbHour = new QSpinBox( this ); 357 sbHour = new QSpinBox( this );
356 sbHour->setMinimumWidth( 30 ); 358 sbHour->setMinimumWidth( 30 );
357 if(use12hourTime) { 359 if(use12hourTime) {
358 sbHour->setMinValue(1); 360 sbHour->setMinValue(1);
359 sbHour->setMaxValue( 12 ); 361 sbHour->setMaxValue( 12 );
360 int show_hour = hour; 362 int show_hour = hour;
361 if (hour > 12) 363 if (hour > 12)
362 show_hour -= 12; 364 show_hour -= 12;
363 if (show_hour == 0) 365 if (show_hour == 0)
364 show_hour = 12; 366 show_hour = 12;
365 367
366 sbHour->setValue( show_hour ); 368 sbHour->setValue( show_hour );
367 } else { 369 } else {
368 sbHour->setMinValue( 0 ); 370 sbHour->setMinValue( 0 );
369 sbHour->setMaxValue( 23 ); 371 sbHour->setMaxValue( 23 );
370 sbHour->setValue( hour ); 372 sbHour->setValue( hour );
371 } 373 }
372 sbHour->setWrapping(TRUE); 374 sbHour->setWrapping(TRUE);
373 connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); 375 connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) );
374 hb2->addWidget( sbHour ); 376 hb2->addWidget( sbHour );
375 377
376 hb2->addStretch( 1 ); 378 hb2->addStretch( 1 );
377 379
378 l = new QLabel( tr("Minute"), this ); 380 l = new QLabel( tr("Minute"), this );
379 //l->setAlignment( AlignRight | AlignVCenter ); 381 //l->setAlignment( AlignRight | AlignVCenter );
380 hb2->addWidget( l ); 382 hb2->addWidget( l );
381 383
382 sbMin = new QSpinBox( this ); 384 sbMin = new QSpinBox( this );
383 sbMin->setMinValue( 0 ); 385 sbMin->setMinValue( 0 );
384 sbMin->setMaxValue( 59 ); 386 sbMin->setMaxValue( 59 );
385 sbMin->setWrapping(TRUE); 387 sbMin->setWrapping(TRUE);
386 sbMin->setValue( minute ); 388 sbMin->setValue( minute );
387 sbMin->setMinimumWidth( 30 ); 389 sbMin->setMinimumWidth( 30 );
388 connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); 390 connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) );
389 hb2->addWidget( sbMin ); 391 hb2->addWidget( sbMin );
390 392
391 hb2->addStretch( 1 ); 393 hb2->addStretch( 1 );
392 394
393 ampm = new QComboBox( this ); 395 ampm = new QComboBox( this );
394 ampm->insertItem( tr("AM"), ValueAM ); 396 ampm->insertItem( tr("AM"), ValueAM );
395 ampm->insertItem( tr("PM"), ValuePM ); 397 ampm->insertItem( tr("PM"), ValuePM );
396 connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); 398 connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) );
397 hb2->addWidget( ampm ); 399 hb2->addWidget( ampm );
398 400
399 hb2->addStretch( 1 ); 401 hb2->addStretch( 1 );
400 402
401} 403}
402 404
403QTime SetTime::time() const 405QTime SetTime::time() const
404{ 406{
405 return QTime( hour, minute, 0 ); 407 return QTime( hour, minute, 0 );
406} 408}
407 409
408void SetTime::hourChanged( int value ) 410void SetTime::hourChanged( int value )
409{ 411{
410 if(use12hourTime) { 412 if(use12hourTime) {
411 int realhour = value; 413 int realhour = value;
412 if (realhour == 12) 414 if (realhour == 12)
413 realhour = 0; 415 realhour = 0;
414 if (ampm->currentItem() == ValuePM ) 416 if (ampm->currentItem() == ValuePM )
415 realhour += 12; 417 realhour += 12;
416 hour = realhour; 418 hour = realhour;
417 } else 419 } else
418 hour = value; 420 hour = value;
419} 421}
420 422
421void SetTime::minuteChanged( int value ) 423void SetTime::minuteChanged( int value )
422{ 424{
423 minute = value; 425 minute = value;
424} 426}
425 427
426void SetTime::show12hourTime( int on ) 428void SetTime::show12hourTime( int on )
427{ 429{
428 use12hourTime = on; 430 use12hourTime = on;
429 ampm->setEnabled(on); 431 ampm->setEnabled(on);
430 432
431 int show_hour = hour; 433 int show_hour = hour;
432 if ( on ) { 434 if ( on ) {
433 /* this might change the value of hour */ 435 /* this might change the value of hour */
434 sbHour->setMinValue(1); 436 sbHour->setMinValue(1);
435 sbHour->setMaxValue( 12 ); 437 sbHour->setMaxValue( 12 );
436 438
437 /* so use one we saved earlier */ 439 /* so use one we saved earlier */
438 if (show_hour >= 12) { 440 if (show_hour >= 12) {
439 show_hour -= 12; 441 show_hour -= 12;
440 ampm->setCurrentItem( ValuePM ); 442 ampm->setCurrentItem( ValuePM );
441 } else { 443 } else {
442 ampm->setCurrentItem( ValueAM ); 444 ampm->setCurrentItem( ValueAM );
443 } 445 }
444 if (show_hour == 0) 446 if (show_hour == 0)
445 show_hour = 12; 447 show_hour = 12;
446 448
447 } else { 449 } else {
448 sbHour->setMinValue( 0 ); 450 sbHour->setMinValue( 0 );
449 sbHour->setMaxValue( 23 ); 451 sbHour->setMaxValue( 23 );
450 } 452 }
451 453
452 454
453 sbHour->setValue( show_hour ); 455 sbHour->setValue( show_hour );
454} 456}
455 457
456void SetTime::checkedPM( int c ) 458void SetTime::checkedPM( int c )
457{ 459{
458 int show_hour = sbHour->value(); 460 int show_hour = sbHour->value();
459 if (show_hour == 12) 461 if (show_hour == 12)
460 show_hour = 0; 462 show_hour = 0;
461 463
462 if ( c == ValuePM ) 464 if ( c == ValuePM )