summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/ntp.cpp
Unidiff
Diffstat (limited to 'noncore/settings/netsystemtime/ntp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp56
1 files changed, 31 insertions, 25 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index c7e3b52..53dbe46 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -39,33 +39,32 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
39 ntpSrvs.setGroup(QString::number(i)); 39 ntpSrvs.setGroup(QString::number(i));
40 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); 40 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
41 } 41 }
42 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); 42 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
43 43
44 Config cfg("ntp",Config::User); 44 Config cfg("ntp",Config::User);
45 cfg.setGroup("settings"); 45 cfg.setGroup("settings");
46 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) ); 46 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) );
47 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) ); 47 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) );
48 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 48 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
49 49
50 //make tab order 50 //make tab order
51 51
52 TabWidgetMain->removePage( tabMain ); 52 TabWidgetMain->removePage( tabMain );
53 TabWidgetMain->removePage( tabManualSetTime ); 53 TabWidgetMain->removePage( tabManualSetTime );
54 TabWidgetMain->removePage( TabSettings ); 54 TabWidgetMain->removePage( TabSettings );
55 TabWidgetMain->removePage( tabPredict ); 55 TabWidgetMain->removePage( tabPredict );
56 TabWidgetMain->removePage( tabNtp ); 56 TabWidgetMain->removePage( tabNtp );
57 57
58 TabWidgetMain->insertTab( tabMain, tr( "Main" ) ); 58 TabWidgetMain->insertTab( tabMain, tr( "Main" ) );
59 TabWidgetMain->insertTab( tabManualSetTime, tr( "Manual" ) );
60 TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) ); 59 TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) );
61 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) ); 60 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) );
62 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) ); 61 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) );
63 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 ); 62 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 );
64 63
65 64
66 65
67 bool advMode = cfg.readBoolEntry("advancedFeatures", false ); 66 bool advMode = cfg.readBoolEntry("advancedFeatures", false );
68 showAdvancedFeatures(advMode); 67 showAdvancedFeatures(advMode);
69 CheckBoxAdvSettings->setChecked( advMode ); 68 CheckBoxAdvSettings->setChecked( advMode );
70 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), 69 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ),
71 SLOT( showAdvancedFeatures( bool ) ) ); 70 SLOT( showAdvancedFeatures( bool ) ) );
@@ -87,24 +86,27 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
87 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 86 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
88 this, SLOT(ntpFinished(OProcess*))); 87 this, SLOT(ntpFinished(OProcess*)));
89 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); 88 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp()));
90 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 89 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
91 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 90 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
92 slotCheckNtp(-1); 91 slotCheckNtp(-1);
93 readLookups(); 92 readLookups();
94} 93}
95 94
96Ntp::~Ntp() 95Ntp::~Ntp()
97{ 96{
98 delete ntpProcess; 97 delete ntpProcess;
98}
99
100void Ntp::saveConfig(){
99 int srvCount = ComboNtpSrv->count(); 101 int srvCount = ComboNtpSrv->count();
100 bool serversChanged = true; 102 bool serversChanged = true;
101 QString edit = ComboNtpSrv->currentText(); 103 QString edit = ComboNtpSrv->currentText();
102 for (int i = 0; i < srvCount; i++){ 104 for (int i = 0; i < srvCount; i++){
103 if ( edit == ComboNtpSrv->text(i)) serversChanged = false; 105 if ( edit == ComboNtpSrv->text(i)) serversChanged = false;
104 } 106 }
105 if (serversChanged){ 107 if (serversChanged){
106 Config ntpSrvs("/etc/ntpservers",Config::File); 108 Config ntpSrvs("/etc/ntpservers",Config::File);
107 ntpSrvs.setGroup("servers"); 109 ntpSrvs.setGroup("servers");
108 ntpSrvs.writeEntry("count", srvCount); 110 ntpSrvs.writeEntry("count", srvCount);
109 for (int i = 0; i < srvCount; i++){ 111 for (int i = 0; i < srvCount; i++){
110 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); 112 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1());
@@ -190,38 +192,28 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
190 _ntpOutput += lineStr; 192 _ntpOutput += lineStr;
191 } 193 }
192 lineStrOld = lineStr; 194 lineStrOld = lineStr;
193} 195}
194 196
195void Ntp::ntpFinished(OProcess *p) 197void Ntp::ntpFinished(OProcess *p)
196{ 198{
197 qDebug("p->exitStatus() %i",p->exitStatus()); 199 qDebug("p->exitStatus() %i",p->exitStatus());
198 if (p->exitStatus()!=0 || !p->normalExit()) 200 if (p->exitStatus()!=0 || !p->normalExit())
199 { 201 {
200 if ( isVisible() && _interactive ){ 202 if ( isVisible() && _interactive ){
201 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); 203 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput );
202 TabWidgetMain->showPage( tabManualSetTime );
203 } 204 }
204 205// slotCheckNtp(-1);
205 return; 206 return;
206 } 207 }
207
208 Global::writeHWClock();
209 // since time has changed quickly load in the datebookdb
210 // to allow the alarm server to get a better grip on itself
211 // (example re-trigger alarms for when we travel back in time)
212 DateBookDB db;
213
214 // QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" );
215 // timeApplet << "";
216 208
217 Config cfg("ntp",Config::User); 209 Config cfg("ntp",Config::User);
218 cfg.setGroup("lookups"); 210 cfg.setGroup("lookups");
219 int lastLookup = cfg.readNumEntry("time",0); 211 int lastLookup = cfg.readNumEntry("time",0);
220 int lookupCount = cfg.readNumEntry("count",0); 212 int lookupCount = cfg.readNumEntry("count",0);
221 bool lastNtp = cfg.readBoolEntry("lastNtp",false); 213 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
222 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 214 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
223 cfg.writeEntry("time", time); 215 cfg.writeEntry("time", time);
224 216
225 float timeShift = getTimeShift(); 217 float timeShift = getTimeShift();
226 if (timeShift == 0.0) return; 218 if (timeShift == 0.0) return;
227 int secsSinceLast = time - lastLookup; 219 int secsSinceLast = time - lastLookup;
@@ -297,50 +289,52 @@ void Ntp::readLookups()
297void Ntp::preditctTime() 289void Ntp::preditctTime()
298{ 290{
299 Config cfg("ntp",Config::User); 291 Config cfg("ntp",Config::User);
300 cfg.setGroup("lookups"); 292 cfg.setGroup("lookups");
301 int lastTime = cfg.readNumEntry("time",0); 293 int lastTime = cfg.readNumEntry("time",0);
302 cfg.writeEntry("lastNtp",true); 294 cfg.writeEntry("lastNtp",true);
303 setenv( "TZ", tz->currentZone(), 1 ); 295 setenv( "TZ", tz->currentZone(), 1 );
304 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 296 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
305 int corr = int((now - lastTime) * _shiftPerSec); 297 int corr = int((now - lastTime) * _shiftPerSec);
306 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); 298 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
307 predictedTime = QDateTime::currentDateTime().addSecs(corr); 299 predictedTime = QDateTime::currentDateTime().addSecs(corr);
308 TextLabelPredTime->setText(predictedTime.toString()); 300 TextLabelPredTime->setText(predictedTime.toString());
309 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); 301// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
310} 302}
311 303
312void Ntp::setPredictTime() 304void Ntp::setPredictTime()
313{ 305{
306 qDebug("Ntp::setPredictTime");
314 preditctTime(); 307 preditctTime();
315 setTime( predictedTime ); 308 timeButton->setTime( predictedTime );
316} 309}
317 310
318void Ntp::slotCheckNtp(int i) 311void Ntp::slotCheckNtp(int i)
319{ 312{
313 qDebug(" Ntp::slotCheckNtp(%i)",i);
320 if (i == 0) 314 if (i == 0)
321 { 315 {
322 TextLabelMainPredTime->hide(); 316// TextLabelMainPredTime->hide();
323 ButtonSetTime->setText( tr("Get time from network") ); 317 ButtonSetTime->setText( tr("Get time from network") );
324 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) ); 318 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) );
325 if ( ntpDelayElapsed() ) 319 if ( ntpDelayElapsed() )
326 { 320 {
327 slotRunNtp(); 321 slotRunNtp();
328 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); 322 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
329 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); 323 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) );
330 }else{ 324 }else{
331 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); 325 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) );
332 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 326 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
333 } 327 }
334 }else{ 328 }else{
335 preditctTime(); 329 preditctTime();
336 ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); 330 ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() );
337 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); 331 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
338 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 332 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
339 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 333 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
340 } 334 }
341} 335}
342 336
343void Ntp::slotProbeNtpServer() 337void Ntp::slotProbeNtpServer()
344{ 338{
345 ntpSock->connectToHost( getNtpServer() ,123); 339 ntpSock->connectToHost( getNtpServer() ,123);
346} 340}
@@ -409,12 +403,24 @@ void Ntp::showAdvancedFeatures(bool advMode)
409 TextLabel1_2_2->hide(); 403 TextLabel1_2_2->hide();
410 TextLabel2_3->hide(); 404 TextLabel2_3->hide();
411 TextLabel3_3_2->hide(); 405 TextLabel3_3_2->hide();
412 TextLabel1_2->hide(); 406 TextLabel1_2->hide();
413 SpinBoxMinLookupDelay->hide(); 407 SpinBoxMinLookupDelay->hide();
414 TextLabel2->hide(); 408 TextLabel2->hide();
415 TextLabel3_3->hide(); 409 TextLabel3_3->hide();
416 SpinBoxNtpDelay->hide(); 410 SpinBoxNtpDelay->hide();
417 Line1->hide(); 411 Line1->hide();
418 }; 412 };
419 TabWidgetMain->show(); 413 TabWidgetMain->show();
420} 414}
415
416
417void Ntp::accept( ){
418 qDebug("accepted");
419 //SetTimeDate
420 commitTime();
421 writeSettings();
422 updateSystem();
423 // Ntp
424 saveConfig();
425 qApp->quit();
426} \ No newline at end of file