Diffstat (limited to 'noncore/settings/netsystemtime/ntp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 40805a0..111f7d4 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -37,24 +37,41 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
37 | { | 37 | { |
38 | ntpSrvs.setGroup(QString::number(i)); | 38 | ntpSrvs.setGroup(QString::number(i)); |
39 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); | 39 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); |
40 | } | 40 | } |
41 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); | 41 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); |
42 | 42 | ||
43 | Config cfg("ntp",Config::User); | 43 | Config cfg("ntp",Config::User); |
44 | cfg.setGroup("settings"); | 44 | cfg.setGroup("settings"); |
45 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) ); | 45 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) ); |
46 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) ); | 46 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) ); |
47 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); | 47 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); |
48 | 48 | ||
49 | //make tab order | ||
50 | |||
51 | TabWidgetMain->removePage( tabMain ); | ||
52 | TabWidgetMain->removePage( tabManualSetTime ); | ||
53 | TabWidgetMain->removePage( TabSettings ); | ||
54 | TabWidgetMain->removePage( tabPredict ); | ||
55 | TabWidgetMain->removePage( tabNtp ); | ||
56 | |||
57 | TabWidgetMain->insertTab( tabMain, tr( "Main" ) ); | ||
58 | TabWidgetMain->insertTab( tabManualSetTime, tr( "Manual" ) ); | ||
59 | TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) ); | ||
60 | TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) ); | ||
61 | TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) ); | ||
62 | NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 ); | ||
63 | |||
64 | |||
65 | |||
49 | bool advMode = cfg.readBoolEntry("advancedFeatures", false ); | 66 | bool advMode = cfg.readBoolEntry("advancedFeatures", false ); |
50 | showAdvancedFeatures(advMode); | 67 | showAdvancedFeatures(advMode); |
51 | CheckBoxAdvSettings->setChecked( advMode ); | 68 | CheckBoxAdvSettings->setChecked( advMode ); |
52 | connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), | 69 | connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), |
53 | SLOT( showAdvancedFeatures( bool ) ) ); | 70 | SLOT( showAdvancedFeatures( bool ) ) ); |
54 | 71 | ||
55 | makeChannel(); | 72 | makeChannel(); |
56 | 73 | ||
57 | ntpTimer = new QTimer(this); | 74 | ntpTimer = new QTimer(this); |
58 | 75 | ||
59 | ntpProcess = new OProcess( ); | 76 | ntpProcess = new OProcess( ); |
60 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 77 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
@@ -103,69 +120,78 @@ bool Ntp::ntpDelayElapsed() | |||
103 | if (_lookupDiff < 0) return true; | 120 | if (_lookupDiff < 0) return true; |
104 | int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); | 121 | int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); |
105 | return i > -60; | 122 | return i > -60; |
106 | } | 123 | } |
107 | 124 | ||
108 | QString Ntp::getNtpServer() | 125 | QString Ntp::getNtpServer() |
109 | { | 126 | { |
110 | return ComboNtpSrv->currentText(); | 127 | return ComboNtpSrv->currentText(); |
111 | } | 128 | } |
112 | 129 | ||
113 | void Ntp::slotRunNtp() | 130 | void Ntp::slotRunNtp() |
114 | { | 131 | { |
115 | if ( !ntpDelayElapsed() ) | 132 | if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) |
116 | { | 133 | { |
117 | switch ( | 134 | switch ( |
118 | QMessageBox::warning(this, tr("Run NTP?"), | 135 | QMessageBox::warning(this, tr("Run NTP?"), |
119 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 136 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
120 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ | 137 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ |
121 | "<br>"+tr("Rerun NTP?"), | 138 | "<br>"+tr("Rerun NTP?"), |
122 | QMessageBox::Ok,QMessageBox::Cancel) | 139 | QMessageBox::Ok,QMessageBox::Cancel) |
123 | ) { | 140 | ) { |
124 | case QMessageBox::Ok: break; | 141 | case QMessageBox::Ok: break; |
125 | case QMessageBox::Cancel: return; | 142 | case QMessageBox::Cancel: return; |
126 | default: return; | 143 | default: return; |
127 | } | 144 | } |
128 | } | 145 | } |
129 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 146 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
130 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 147 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
131 | 148 | ||
132 | ntpProcess->clearArguments(); | 149 | ntpProcess->clearArguments(); |
133 | *ntpProcess << "ntpdate" << getNtpServer(); | 150 | *ntpProcess << "ntpdate" << getNtpServer(); |
134 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 151 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
135 | if ( !ret ) { | 152 | if ( !ret ) { |
153 | QMessageBox::critical(this, tr("ntp error"), | ||
154 | tr("Error while getting time form network!")); | ||
136 | qDebug("Error while executing ntpdate"); | 155 | qDebug("Error while executing ntpdate"); |
137 | ntpOutPut( tr("Error while executing ntpdate")); | 156 | ntpOutPut( tr("Error while executing ntpdate")); |
138 | } | 157 | } |
139 | } | 158 | } |
140 | 159 | ||
141 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 160 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
142 | { | 161 | { |
162 | if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null"); | ||
143 | QString lineStr, lineStrOld; | 163 | QString lineStr, lineStrOld; |
144 | lineStr = buffer; | 164 | lineStr = buffer; |
145 | lineStr=lineStr.left(buflen); | 165 | lineStr=lineStr.left(buflen); |
146 | if (lineStr!=lineStrOld) | 166 | if (lineStr!=lineStrOld) |
147 | { | 167 | { |
148 | ntpOutPut(lineStr); | 168 | ntpOutPut(lineStr); |
149 | _ntpOutput += lineStr; | 169 | _ntpOutput += lineStr; |
150 | } | 170 | } |
151 | lineStrOld = lineStr; | 171 | lineStrOld = lineStr; |
152 | } | 172 | } |
153 | 173 | ||
154 | void Ntp::ntpFinished(OProcess *p) | 174 | void Ntp::ntpFinished(OProcess *p) |
155 | { | 175 | { |
156 | //qDebug("p->exitStatus() %i",p->exitStatus()); | 176 | qDebug("p->exitStatus() %i",p->exitStatus()); |
157 | if (p->exitStatus()!=0 || !p->normalExit()) | 177 | if (p->exitStatus()!=0 || !p->normalExit()) |
158 | { | 178 | { |
159 | slotProbeNtpServer(); | 179 | QMessageBox::critical(this, tr("ntp error"), |
180 | tr("Error while getting time form\n server")+ | ||
181 | getNtpServer()+"\n"+ | ||
182 | _ntpOutput ); | ||
183 | // TabWidgetMain->setCurrentPage( 1 ); | ||
184 | TabWidgetMain->showPage( tabManualSetTime ); | ||
185 | |||
160 | return; | 186 | return; |
161 | } | 187 | } |
162 | 188 | ||
163 | Global::writeHWClock(); | 189 | Global::writeHWClock(); |
164 | // since time has changed quickly load in the datebookdb | 190 | // since time has changed quickly load in the datebookdb |
165 | // to allow the alarm server to get a better grip on itself | 191 | // to allow the alarm server to get a better grip on itself |
166 | // (example re-trigger alarms for when we travel back in time) | 192 | // (example re-trigger alarms for when we travel back in time) |
167 | DateBookDB db; | 193 | DateBookDB db; |
168 | 194 | ||
169 | // QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); | 195 | // QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); |
170 | // timeApplet << ""; | 196 | // timeApplet << ""; |
171 | 197 | ||
@@ -298,24 +324,25 @@ void Ntp::slotCheckNtp(int i) | |||
298 | void Ntp::slotProbeNtpServer() | 324 | void Ntp::slotProbeNtpServer() |
299 | { | 325 | { |
300 | ntpSock->connectToHost( getNtpServer() ,123); | 326 | ntpSock->connectToHost( getNtpServer() ,123); |
301 | } | 327 | } |
302 | 328 | ||
303 | void Ntp::slotNtpDelayChanged(int delay) | 329 | void Ntp::slotNtpDelayChanged(int delay) |
304 | { | 330 | { |
305 | ntpTimer->changeInterval( delay*1000*60 ); | 331 | ntpTimer->changeInterval( delay*1000*60 ); |
306 | } | 332 | } |
307 | 333 | ||
308 | void Ntp::ntpOutPut(QString out) | 334 | void Ntp::ntpOutPut(QString out) |
309 | { | 335 | { |
336 | |||
310 | MultiLineEditntpOutPut->append(out); | 337 | MultiLineEditntpOutPut->append(out); |
311 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 338 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
312 | } | 339 | } |
313 | 340 | ||
314 | 341 | ||
315 | void Ntp::makeChannel() | 342 | void Ntp::makeChannel() |
316 | { | 343 | { |
317 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); | 344 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); |
318 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 345 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
319 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 346 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
320 | } | 347 | } |
321 | 348 | ||
@@ -329,30 +356,31 @@ void Ntp::receive(const QCString &msg, const QByteArray &arg) | |||
329 | slotRunNtp(); | 356 | slotRunNtp(); |
330 | } | 357 | } |
331 | if ( msg == "setPredictedTime(QString)" ) | 358 | if ( msg == "setPredictedTime(QString)" ) |
332 | { | 359 | { |
333 | setPredictTime(); | 360 | setPredictTime(); |
334 | }else{ | 361 | }else{ |
335 | qDebug("Ntp::receive: Huh what do ya want"); | 362 | qDebug("Ntp::receive: Huh what do ya want"); |
336 | } | 363 | } |
337 | } | 364 | } |
338 | 365 | ||
339 | void Ntp::setDocument(const QString &fileName) | 366 | void Ntp::setDocument(const QString &fileName) |
340 | { | 367 | { |
341 | 368 | qDebug("Ntp::setDocument( %s )",fileName.latin1()); | |
342 | } | 369 | } |
343 | 370 | ||
344 | void Ntp::showAdvancedFeatures(bool advMode) | 371 | void Ntp::showAdvancedFeatures(bool advMode) |
345 | { | 372 | { |
346 | if (advMode) { | 373 | if (advMode) { |
374 | |||
347 | TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); | 375 | TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); |
348 | TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); | 376 | TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); |
349 | TextLabel1_2_2->show(); | 377 | TextLabel1_2_2->show(); |
350 | TextLabel2_3->show(); | 378 | TextLabel2_3->show(); |
351 | TextLabel3_3_2->show(); | 379 | TextLabel3_3_2->show(); |
352 | TextLabel1_2->show(); | 380 | TextLabel1_2->show(); |
353 | SpinBoxMinLookupDelay->show(); | 381 | SpinBoxMinLookupDelay->show(); |
354 | TextLabel2->show(); | 382 | TextLabel2->show(); |
355 | TextLabel3_3->show(); | 383 | TextLabel3_3->show(); |
356 | SpinBoxNtpDelay->show(); | 384 | SpinBoxNtpDelay->show(); |
357 | Line1->show(); | 385 | Line1->show(); |
358 | }else{ | 386 | }else{ |