-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 55 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 4 |
2 files changed, 40 insertions, 19 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 6e74e32..c7e3b52 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -25,16 +25,17 @@ | |||
25 | #include <sys/time.h> | 25 | #include <sys/time.h> |
26 | #include <time.h> | 26 | #include <time.h> |
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | 28 | ||
29 | 29 | ||
30 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 30 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
31 | : SetDateTime( parent, name, fl ) | 31 | : SetDateTime( parent, name, fl ) |
32 | { | 32 | { |
33 | _interactive = false; | ||
33 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); | 34 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); |
34 | ntpSrvs.setGroup("servers"); | 35 | ntpSrvs.setGroup("servers"); |
35 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); | 36 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); |
36 | for (int i = 0; i < srvCount; i++) | 37 | for (int i = 0; i < srvCount; i++) |
37 | { | 38 | { |
38 | ntpSrvs.setGroup(QString::number(i)); | 39 | ntpSrvs.setGroup(QString::number(i)); |
39 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); | 40 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); |
40 | } | 41 | } |
@@ -73,41 +74,48 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
73 | 74 | ||
74 | ntpTimer = new QTimer(this); | 75 | ntpTimer = new QTimer(this); |
75 | 76 | ||
76 | ntpProcess = new OProcess( ); | 77 | ntpProcess = new OProcess( ); |
77 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 78 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
78 | SLOT(slotNtpDelayChanged(int)) ); | 79 | SLOT(slotNtpDelayChanged(int)) ); |
79 | 80 | ||
80 | ntpSock = new QSocket( this ); | 81 | ntpSock = new QSocket( this ); |
81 | connect( ntpSock, SIGNAL( error(int) ), | 82 | connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) ); |
82 | SLOT(slotCheckNtp(int)) ); | ||
83 | slotProbeNtpServer(); | 83 | slotProbeNtpServer(); |
84 | 84 | ||
85 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 85 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
86 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 86 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
87 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 87 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
88 | this, SLOT(ntpFinished(OProcess*))); | 88 | this, SLOT(ntpFinished(OProcess*))); |
89 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 89 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); |
90 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 90 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
91 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 91 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
92 | slotCheckNtp(-1); | 92 | slotCheckNtp(-1); |
93 | readLookups(); | 93 | readLookups(); |
94 | } | 94 | } |
95 | 95 | ||
96 | Ntp::~Ntp() | 96 | Ntp::~Ntp() |
97 | { | 97 | { |
98 | delete ntpProcess; | 98 | delete ntpProcess; |
99 | Config ntpSrvs("/etc/ntpservers",Config::File); | ||
100 | ntpSrvs.setGroup("servers"); | ||
101 | int srvCount = ComboNtpSrv->count(); | 99 | int srvCount = ComboNtpSrv->count(); |
102 | ntpSrvs.writeEntry("count", srvCount); | 100 | bool serversChanged = true; |
101 | QString edit = ComboNtpSrv->currentText(); | ||
103 | for (int i = 0; i < srvCount; i++){ | 102 | for (int i = 0; i < srvCount; i++){ |
104 | ntpSrvs.setGroup(QString::number(i)); | 103 | if ( edit == ComboNtpSrv->text(i)) serversChanged = false; |
105 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | 104 | } |
105 | if (serversChanged){ | ||
106 | Config ntpSrvs("/etc/ntpservers",Config::File); | ||
107 | ntpSrvs.setGroup("servers"); | ||
108 | ntpSrvs.writeEntry("count", srvCount); | ||
109 | for (int i = 0; i < srvCount; i++){ | ||
110 | qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); | ||
111 | ntpSrvs.setGroup(QString::number(i)); | ||
112 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | ||
113 | } | ||
106 | } | 114 | } |
107 | Config cfg("ntp",Config::User); | 115 | Config cfg("ntp",Config::User); |
108 | cfg.setGroup("settings"); | 116 | cfg.setGroup("settings"); |
109 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); | 117 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); |
110 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 118 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
111 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 119 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
112 | cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); | 120 | cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); |
113 | } | 121 | } |
@@ -122,16 +130,29 @@ bool Ntp::ntpDelayElapsed() | |||
122 | return i > -60; | 130 | return i > -60; |
123 | } | 131 | } |
124 | 132 | ||
125 | QString Ntp::getNtpServer() | 133 | QString Ntp::getNtpServer() |
126 | { | 134 | { |
127 | return ComboNtpSrv->currentText(); | 135 | return ComboNtpSrv->currentText(); |
128 | } | 136 | } |
129 | 137 | ||
138 | void Ntp::slotButtonRunNtp() | ||
139 | { | ||
140 | _interactive = true; | ||
141 | slotRunNtp(); | ||
142 | } | ||
143 | |||
144 | void Ntp::slotTimerRunNtp() | ||
145 | { | ||
146 | _interactive = false; | ||
147 | slotRunNtp(); | ||
148 | } | ||
149 | |||
150 | |||
130 | void Ntp::slotRunNtp() | 151 | void Ntp::slotRunNtp() |
131 | { | 152 | { |
132 | if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) | 153 | if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) |
133 | { | 154 | { |
134 | switch ( | 155 | switch ( |
135 | QMessageBox::warning(this, tr("Run NTP?"), | 156 | QMessageBox::warning(this, tr("Run NTP?"), |
136 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 157 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
137 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ | 158 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ |
@@ -171,24 +192,21 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | |||
171 | lineStrOld = lineStr; | 192 | lineStrOld = lineStr; |
172 | } | 193 | } |
173 | 194 | ||
174 | void Ntp::ntpFinished(OProcess *p) | 195 | void Ntp::ntpFinished(OProcess *p) |
175 | { | 196 | { |
176 | qDebug("p->exitStatus() %i",p->exitStatus()); | 197 | qDebug("p->exitStatus() %i",p->exitStatus()); |
177 | if (p->exitStatus()!=0 || !p->normalExit()) | 198 | if (p->exitStatus()!=0 || !p->normalExit()) |
178 | { | 199 | { |
179 | if ( isVisible() ) { | 200 | if ( isVisible() && _interactive ){ |
180 | QMessageBox::critical(this, tr("ntp error"), | 201 | QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); |
181 | tr("Error while getting time form\n server")+ | 202 | TabWidgetMain->showPage( tabManualSetTime ); |
182 | getNtpServer()+"\n"+ | ||
183 | _ntpOutput ); | ||
184 | TabWidgetMain->showPage( tabManualSetTime ); | ||
185 | } | 203 | } |
186 | 204 | ||
187 | return; | 205 | return; |
188 | } | 206 | } |
189 | 207 | ||
190 | Global::writeHWClock(); | 208 | Global::writeHWClock(); |
191 | // since time has changed quickly load in the datebookdb | 209 | // since time has changed quickly load in the datebookdb |
192 | // to allow the alarm server to get a better grip on itself | 210 | // to allow the alarm server to get a better grip on itself |
193 | // (example re-trigger alarms for when we travel back in time) | 211 | // (example re-trigger alarms for when we travel back in time) |
194 | DateBookDB db; | 212 | DateBookDB db; |
@@ -298,24 +316,24 @@ void Ntp::setPredictTime() | |||
298 | } | 316 | } |
299 | 317 | ||
300 | void Ntp::slotCheckNtp(int i) | 318 | void Ntp::slotCheckNtp(int i) |
301 | { | 319 | { |
302 | if (i == 0) | 320 | if (i == 0) |
303 | { | 321 | { |
304 | TextLabelMainPredTime->hide(); | 322 | TextLabelMainPredTime->hide(); |
305 | ButtonSetTime->setText( tr("Get time from network") ); | 323 | ButtonSetTime->setText( tr("Get time from network") ); |
306 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 324 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) ); |
307 | if ( ntpDelayElapsed() ) | 325 | if ( ntpDelayElapsed() ) |
308 | { | 326 | { |
309 | slotRunNtp(); | 327 | slotRunNtp(); |
310 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 328 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
311 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 329 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); |
312 | }else{ | 330 | }else{ |
313 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 331 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); |
314 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 332 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
315 | } | 333 | } |
316 | }else{ | 334 | }else{ |
317 | preditctTime(); | 335 | preditctTime(); |
318 | ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); | 336 | ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); |
319 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 337 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
320 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 338 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
321 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 339 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
@@ -349,16 +367,17 @@ void Ntp::makeChannel() | |||
349 | 367 | ||
350 | 368 | ||
351 | 369 | ||
352 | void Ntp::receive(const QCString &msg, const QByteArray &arg) | 370 | void Ntp::receive(const QCString &msg, const QByteArray &arg) |
353 | { | 371 | { |
354 | qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); | 372 | qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); |
355 | if ( msg == "ntpLookup(QString)" ) | 373 | if ( msg == "ntpLookup(QString)" ) |
356 | { | 374 | { |
375 | _interactive = false; | ||
357 | slotRunNtp(); | 376 | slotRunNtp(); |
358 | } | 377 | } |
359 | if ( msg == "setPredictedTime(QString)" ) | 378 | if ( msg == "setPredictedTime(QString)" ) |
360 | { | 379 | { |
361 | setPredictTime(); | 380 | setPredictTime(); |
362 | }else{ | 381 | }else{ |
363 | qDebug("Ntp::receive: Huh what do ya want"); | 382 | qDebug("Ntp::receive: Huh what do ya want"); |
364 | } | 383 | } |
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index f6694c9..15cddbd 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h | |||
@@ -27,23 +27,25 @@ protected slots: | |||
27 | private: | 27 | private: |
28 | QString _ntpOutput; | 28 | QString _ntpOutput; |
29 | float _shiftPerSec; | 29 | float _shiftPerSec; |
30 | int _lookupDiff; | 30 | int _lookupDiff; |
31 | OProcess *ntpProcess; | 31 | OProcess *ntpProcess; |
32 | QTimer *ntpTimer; | 32 | QTimer *ntpTimer; |
33 | QSocket *ntpSock; | 33 | QSocket *ntpSock; |
34 | QCopChannel *channel; | 34 | QCopChannel *channel; |
35 | 35 | bool _interactive; | |
36 | float getTimeShift(); | 36 | float getTimeShift(); |
37 | void readLookups(); | 37 | void readLookups(); |
38 | void ntpOutPut(QString); | 38 | void ntpOutPut(QString); |
39 | bool ntpDelayElapsed(); | 39 | bool ntpDelayElapsed(); |
40 | QString getNtpServer(); | 40 | QString getNtpServer(); |
41 | private slots: | 41 | private slots: |
42 | void slotTimerRunNtp(); | ||
43 | void slotButtonRunNtp(); | ||
42 | void slotRunNtp(); | 44 | void slotRunNtp(); |
43 | void getNtpOutput(OProcess *proc, char *buffer, int buflen); | 45 | void getNtpOutput(OProcess *proc, char *buffer, int buflen); |
44 | void ntpFinished(OProcess*); | 46 | void ntpFinished(OProcess*); |
45 | void preditctTime(); | 47 | void preditctTime(); |
46 | void slotCheckNtp(int); | 48 | void slotCheckNtp(int); |
47 | void setPredictTime(); | 49 | void setPredictTime(); |
48 | void showAdvancedFeatures(bool); | 50 | void showAdvancedFeatures(bool); |
49 | void slotProbeNtpServer(); | 51 | void slotProbeNtpServer(); |