summaryrefslogtreecommitdiff
authortille <tille>2003-01-29 10:09:50 (UTC)
committer tille <tille>2003-01-29 10:09:50 (UTC)
commit59a67d792570e231d2de14cee78ff75fa79453ec (patch) (unidiff)
tree5155aa2a954b6c68d07c69da8dcf495c4bcd45cc
parented9991ab41fcf7c8d592796d083d932c44c4a723 (diff)
downloadopie-59a67d792570e231d2de14cee78ff75fa79453ec.zip
opie-59a67d792570e231d2de14cee78ff75fa79453ec.tar.gz
opie-59a67d792570e231d2de14cee78ff75fa79453ec.tar.bz2
fix for adv tab
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 06d944d..aecefc1 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -39,38 +39,38 @@ 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( TabSettings, tr( "Settings" ) ); 59 TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) );
60 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) ); 60 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) );
61 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) ); 61 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) );
62 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 ); 62 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 );
63 63
64 64
65 65
66 bool advMode = cfg.readBoolEntry("advancedFeatures", false ); 66 bool advMode = cfg.readBoolEntry("advancedFeatures", false );
67 showAdvancedFeatures(advMode); 67 showAdvancedFeatures(advMode);
68 CheckBoxAdvSettings->setChecked( advMode ); 68 CheckBoxAdvSettings->setChecked( advMode );
69 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), 69 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ),
70 SLOT( showAdvancedFeatures( bool ) ) ); 70 SLOT( showAdvancedFeatures( bool ) ) );
71 71
72 makeChannel(); 72 makeChannel();
73 73
74 ntpTimer = new QTimer(this); 74 ntpTimer = new QTimer(this);
75 75
76 ntpProcess = new OProcess( ); 76 ntpProcess = new OProcess( );
@@ -91,56 +91,56 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
91 slotCheckNtp(-1); 91 slotCheckNtp(-1);
92 readLookups(); 92 readLookups();
93} 93}
94 94
95Ntp::~Ntp() 95Ntp::~Ntp()
96{ 96{
97 delete ntpProcess; 97 delete ntpProcess;
98} 98}
99 99
100void Ntp::saveConfig(){ 100void Ntp::saveConfig(){
101 int srvCount = ComboNtpSrv->count(); 101 int srvCount = ComboNtpSrv->count();
102 bool serversChanged = true; 102 bool serversChanged = true;
103 int curSrv = ComboNtpSrv->currentItem(); 103 int curSrv = ComboNtpSrv->currentItem();
104 QString edit = ComboNtpSrv->currentText(); 104 QString edit = ComboNtpSrv->currentText();
105 for (int i = 0; i < srvCount; i++){ 105 for (int i = 0; i < srvCount; i++){
106 if ( edit == ComboNtpSrv->text(i)) serversChanged = false; 106 if ( edit == ComboNtpSrv->text(i)) serversChanged = false;
107 } 107 }
108 if (serversChanged){ 108 if (serversChanged){
109 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); 109 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
110 ntpSrvs.setGroup("servers"); 110 ntpSrvs.setGroup("servers");
111 ntpSrvs.writeEntry("count", ++srvCount); 111 ntpSrvs.writeEntry("count", ++srvCount);
112 ntpSrvs.setGroup("0"); 112 ntpSrvs.setGroup("0");
113 ntpSrvs.writeEntry( "name", edit ); 113 ntpSrvs.writeEntry( "name", edit );
114 curSrv = 0; 114 curSrv = 0;
115 for (int i = 1; i < srvCount; i++){ 115 for (int i = 1; i < srvCount; i++){
116 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); 116 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1());
117 ntpSrvs.setGroup(QString::number(i)); 117 ntpSrvs.setGroup(QString::number(i));
118 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) ); 118 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) );
119 } 119 }
120 } 120 }
121 Config cfg("ntp",Config::User); 121 Config cfg("ntp",Config::User);
122 cfg.setGroup("settings"); 122 cfg.setGroup("settings");
123 cfg.writeEntry("ntpServer", curSrv ); 123 cfg.writeEntry("ntpServer", curSrv );
124 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 124 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
125 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 125 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
126 cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); 126 cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() );
127} 127}
128 128
129bool Ntp::ntpDelayElapsed() 129bool Ntp::ntpDelayElapsed()
130{ 130{
131 Config cfg("ntp",Config::User); 131 Config cfg("ntp",Config::User);
132 cfg.setGroup("lookups"); 132 cfg.setGroup("lookups");
133 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 133 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
134 if (_lookupDiff < 0) return true; 134 if (_lookupDiff < 0) return true;
135 int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); 135 int i =_lookupDiff - (SpinBoxNtpDelay->value()*60);
136 return i > -60; 136 return i > -60;
137} 137}
138 138
139QString Ntp::getNtpServer() 139QString Ntp::getNtpServer()
140{ 140{
141 return ComboNtpSrv->currentText(); 141 return ComboNtpSrv->currentText();
142} 142}
143 143
144void Ntp::slotButtonRunNtp() 144void Ntp::slotButtonRunNtp()
145{ 145{
146 _interactive = true; 146 _interactive = true;
@@ -163,25 +163,25 @@ void Ntp::slotRunNtp()
163 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 163 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
164 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ 164 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+
165 "<br>"+tr("Rerun NTP?"), 165 "<br>"+tr("Rerun NTP?"),
166 QMessageBox::Ok,QMessageBox::Cancel) 166 QMessageBox::Ok,QMessageBox::Cancel)
167 ) { 167 ) {
168 case QMessageBox::Ok: break; 168 case QMessageBox::Ok: break;
169 case QMessageBox::Cancel: return; 169 case QMessageBox::Cancel: return;
170 default: return; 170 default: return;
171 } 171 }
172 } 172 }
173 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 173 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
174 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 174 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
175 175
176 ntpProcess->clearArguments(); 176 ntpProcess->clearArguments();
177 *ntpProcess << "ntpdate" << getNtpServer(); 177 *ntpProcess << "ntpdate" << getNtpServer();
178 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 178 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
179 if ( !ret ) { 179 if ( !ret ) {
180 QMessageBox::critical(this, tr("ntp error"), 180 QMessageBox::critical(this, tr("ntp error"),
181 tr("Error while getting time form network!")); 181 tr("Error while getting time form network!"));
182 qDebug("Error while executing ntpdate"); 182 qDebug("Error while executing ntpdate");
183 ntpOutPut( tr("Error while executing ntpdate")); 183 ntpOutPut( tr("Error while executing ntpdate"));
184 } 184 }
185} 185}
186 186
187void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 187void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
@@ -193,40 +193,40 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
193 if (lineStr!=lineStrOld) 193 if (lineStr!=lineStrOld)
194 { 194 {
195 ntpOutPut(lineStr); 195 ntpOutPut(lineStr);
196 _ntpOutput += lineStr; 196 _ntpOutput += lineStr;
197 } 197 }
198 lineStrOld = lineStr; 198 lineStrOld = lineStr;
199} 199}
200 200
201void Ntp::ntpFinished(OProcess *p) 201void Ntp::ntpFinished(OProcess *p)
202{ 202{
203 qDebug("p->exitStatus() %i",p->exitStatus()); 203 qDebug("p->exitStatus() %i",p->exitStatus());
204 if (p->exitStatus()!=0 || !p->normalExit()) 204 if (p->exitStatus()!=0 || !p->normalExit())
205 { 205 {
206 if ( isVisible() && _interactive ){ 206 if ( isVisible() && _interactive ){
207 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); 207 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput );
208 } 208 }
209// slotCheckNtp(-1); 209// slotCheckNtp(-1);
210 return; 210 return;
211 } 211 }
212 212
213 Config cfg("ntp",Config::User); 213 Config cfg("ntp",Config::User);
214 cfg.setGroup("lookups"); 214 cfg.setGroup("lookups");
215 int lastLookup = cfg.readNumEntry("time",0); 215 int lastLookup = cfg.readNumEntry("time",0);
216 int lookupCount = cfg.readNumEntry("count",0); 216 int lookupCount = cfg.readNumEntry("count",0);
217 bool lastNtp = cfg.readBoolEntry("lastNtp",false); 217 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
218 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 218 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
219 cfg.writeEntry("time", time); 219 cfg.writeEntry("time", time);
220 220
221 float timeShift = getTimeShift(); 221 float timeShift = getTimeShift();
222 if (timeShift == 0.0) return; 222 if (timeShift == 0.0) return;
223 int secsSinceLast = time - lastLookup; 223 int secsSinceLast = time - lastLookup;
224 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 224 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
225 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 225 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
226 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 226 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
227 { 227 {
228 cfg.setGroup("lookup_"+QString::number(lookupCount)); 228 cfg.setGroup("lookup_"+QString::number(lookupCount));
229 lookupCount++; 229 lookupCount++;
230 _shiftPerSec = timeShift / secsSinceLast; 230 _shiftPerSec = timeShift / secsSinceLast;
231 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 231 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
232 cfg.writeEntry("secsSinceLast",secsSinceLast); 232 cfg.writeEntry("secsSinceLast",secsSinceLast);
@@ -320,53 +320,53 @@ void Ntp::slotCheckNtp(int i)
320// TextLabelMainPredTime->hide(); 320// TextLabelMainPredTime->hide();
321 ButtonSetTime->setText( tr("Get time from network") ); 321 ButtonSetTime->setText( tr("Get time from network") );
322 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) ); 322 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) );
323 if ( ntpDelayElapsed() ) 323 if ( ntpDelayElapsed() )
324 { 324 {
325 slotRunNtp(); 325 slotRunNtp();
326 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); 326 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
327 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); 327 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) );
328 }else{ 328 }else{
329 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); 329 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) );
330 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 330 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
331 } 331 }
332 }else{ 332 }else{
333 preditctTime(); 333 preditctTime();
334 ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); 334 ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() );
335 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); 335 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
336 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 336 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
337 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 337 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
338 } 338 }
339} 339}
340 340
341void Ntp::slotProbeNtpServer() 341void Ntp::slotProbeNtpServer()
342{ 342{
343 ntpSock->connectToHost( getNtpServer() ,123); 343 ntpSock->connectToHost( getNtpServer() ,123);
344} 344}
345 345
346void Ntp::slotNtpDelayChanged(int delay) 346void Ntp::slotNtpDelayChanged(int delay)
347{ 347{
348 ntpTimer->changeInterval( delay*1000*60 ); 348 ntpTimer->changeInterval( delay*1000*60 );
349} 349}
350 350
351void Ntp::ntpOutPut(QString out) 351void Ntp::ntpOutPut(QString out)
352{ 352{
353 353
354 MultiLineEditntpOutPut->append(out); 354 MultiLineEditntpOutPut->append(out);
355 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); 355 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
356} 356}
357 357
358 358
359void Ntp::makeChannel() 359void Ntp::makeChannel()
360 { 360{
361 channel = new QCopChannel( "QPE/Application/netsystemtime", this ); 361 channel = new QCopChannel( "QPE/Application/netsystemtime", this );
362 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 362 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
363 this, SLOT(receive(const QCString&, const QByteArray&)) ); 363 this, SLOT(receive(const QCString&, const QByteArray&)) );
364} 364}
365 365
366 366
367 367
368void Ntp::receive(const QCString &msg, const QByteArray &arg) 368void Ntp::receive(const QCString &msg, const QByteArray &arg)
369{ 369{
370 qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); 370 qDebug("QCop(Ntp) "+msg+" "+QCString(arg));
371 if ( msg == "ntpLookup(QString)" ) 371 if ( msg == "ntpLookup(QString)" )
372 { 372 {
@@ -380,27 +380,29 @@ void Ntp::receive(const QCString &msg, const QByteArray &arg)
380 qDebug("Ntp::receive: Huh what do ya want"); 380 qDebug("Ntp::receive: Huh what do ya want");
381 } 381 }
382} 382}
383 383
384void Ntp::setDocument(const QString &fileName) 384void Ntp::setDocument(const QString &fileName)
385{ 385{
386 qDebug("Ntp::setDocument( %s )",fileName.latin1()); 386 qDebug("Ntp::setDocument( %s )",fileName.latin1());
387} 387}
388 388
389void Ntp::showAdvancedFeatures(bool advMode) 389void Ntp::showAdvancedFeatures(bool advMode)
390{ 390{
391 if (advMode) { 391 if (advMode) {
392 392
393 TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); 393 if ( tabNtp->isVisible() ) {
394 TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); 394 TabWidgetMain->addTab( tabPredict, tr( "Predict" ) );
395 TabWidgetMain->addTab( tabNtp, tr( "NTP" ) );
396 }
395 TextLabel1_2_2->show(); 397 TextLabel1_2_2->show();
396 TextLabel2_3->show(); 398 TextLabel2_3->show();
397 TextLabel3_3_2->show(); 399 TextLabel3_3_2->show();
398 TextLabel1_2->show(); 400 TextLabel1_2->show();
399 SpinBoxMinLookupDelay->show(); 401 SpinBoxMinLookupDelay->show();
400 TextLabel2->show(); 402 TextLabel2->show();
401 TextLabel3_3->show(); 403 TextLabel3_3->show();
402 SpinBoxNtpDelay->show(); 404 SpinBoxNtpDelay->show();
403 Line1->show(); 405 Line1->show();
404 }else{ 406 }else{
405 TabWidgetMain->removePage( tabPredict ); 407 TabWidgetMain->removePage( tabPredict );
406 TabWidgetMain->removePage( tabNtp ); 408 TabWidgetMain->removePage( tabNtp );
@@ -413,27 +415,27 @@ void Ntp::showAdvancedFeatures(bool advMode)
413 TextLabel3_3->hide(); 415 TextLabel3_3->hide();
414 SpinBoxNtpDelay->hide(); 416 SpinBoxNtpDelay->hide();
415 Line1->hide(); 417 Line1->hide();
416 }; 418 };
417 TabWidgetMain->show(); 419 TabWidgetMain->show();
418} 420}
419 421
420 422
421void Ntp::accept( ){ 423void Ntp::accept( ){
422 qDebug("saving"); 424 qDebug("saving");
423 //SetTimeDate 425 //SetTimeDate
424 commitTime(); 426 commitTime();
425 writeSettings(); 427 writeSettings();
426 updateSystem(); 428 updateSystem();
427 // Ntp 429 // Ntp
428 saveConfig(); 430 saveConfig();
429 qApp->quit(); 431 qApp->quit();
430} 432}
431 433
432void Ntp::reject( ){ 434void Ntp::reject( ){
433 qDebug("_oldTimeZone %s",_oldTimeZone.latin1()); 435 qDebug("_oldTimeZone %s",_oldTimeZone.latin1());
434 if (!_oldTimeZone.isEmpty()){ 436 if (!_oldTimeZone.isEmpty()){
435 qDebug("reverting timezone"); 437 qDebug("reverting timezone");
436 tzChange(_oldTimeZone); 438 tzChange(_oldTimeZone);
437 commitTime(); 439 commitTime();
438 } 440 }
439} 441}