-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 551cedc..06d944d 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -55,113 +55,117 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
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( ); |
77 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 77 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
78 | SLOT(slotNtpDelayChanged(int)) ); | 78 | SLOT(slotNtpDelayChanged(int)) ); |
79 | 79 | ||
80 | ntpSock = new QSocket( this ); | 80 | ntpSock = new QSocket( this ); |
81 | connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) ); | 81 | connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) ); |
82 | slotProbeNtpServer(); | 82 | slotProbeNtpServer(); |
83 | 83 | ||
84 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 84 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
85 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 85 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
86 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 86 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
87 | this, SLOT(ntpFinished(OProcess*))); | 87 | this, SLOT(ntpFinished(OProcess*))); |
88 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); | 88 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); |
89 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 89 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
90 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 90 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
91 | slotCheckNtp(-1); | 91 | slotCheckNtp(-1); |
92 | readLookups(); | 92 | readLookups(); |
93 | } | 93 | } |
94 | 94 | ||
95 | Ntp::~Ntp() | 95 | Ntp::~Ntp() |
96 | { | 96 | { |
97 | delete ntpProcess; | 97 | delete ntpProcess; |
98 | } | 98 | } |
99 | 99 | ||
100 | void Ntp::saveConfig(){ | 100 | void 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 | QString edit = ComboNtpSrv->currentText(); | 104 | QString edit = ComboNtpSrv->currentText(); |
104 | for (int i = 0; i < srvCount; i++){ | 105 | for (int i = 0; i < srvCount; i++){ |
105 | if ( edit == ComboNtpSrv->text(i)) serversChanged = false; | 106 | if ( edit == ComboNtpSrv->text(i)) serversChanged = false; |
106 | } | 107 | } |
107 | if (serversChanged){ | 108 | if (serversChanged){ |
108 | Config ntpSrvs("/etc/ntpservers",Config::File); | 109 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); |
109 | ntpSrvs.setGroup("servers"); | 110 | ntpSrvs.setGroup("servers"); |
110 | ntpSrvs.writeEntry("count", srvCount); | 111 | ntpSrvs.writeEntry("count", ++srvCount); |
111 | for (int i = 0; i < srvCount; i++){ | 112 | ntpSrvs.setGroup("0"); |
113 | ntpSrvs.writeEntry( "name", edit ); | ||
114 | curSrv = 0; | ||
115 | for (int i = 1; i < srvCount; i++){ | ||
112 | qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); | 116 | qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); |
113 | ntpSrvs.setGroup(QString::number(i)); | 117 | ntpSrvs.setGroup(QString::number(i)); |
114 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | 118 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) ); |
115 | } | 119 | } |
116 | } | 120 | } |
117 | Config cfg("ntp",Config::User); | 121 | Config cfg("ntp",Config::User); |
118 | cfg.setGroup("settings"); | 122 | cfg.setGroup("settings"); |
119 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); | 123 | cfg.writeEntry("ntpServer", curSrv ); |
120 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 124 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
121 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 125 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
122 | cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); | 126 | cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); |
123 | } | 127 | } |
124 | 128 | ||
125 | bool Ntp::ntpDelayElapsed() | 129 | bool Ntp::ntpDelayElapsed() |
126 | { | 130 | { |
127 | Config cfg("ntp",Config::User); | 131 | Config cfg("ntp",Config::User); |
128 | cfg.setGroup("lookups"); | 132 | cfg.setGroup("lookups"); |
129 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | 133 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); |
130 | if (_lookupDiff < 0) return true; | 134 | if (_lookupDiff < 0) return true; |
131 | int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); | 135 | int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); |
132 | return i > -60; | 136 | return i > -60; |
133 | } | 137 | } |
134 | 138 | ||
135 | QString Ntp::getNtpServer() | 139 | QString Ntp::getNtpServer() |
136 | { | 140 | { |
137 | return ComboNtpSrv->currentText(); | 141 | return ComboNtpSrv->currentText(); |
138 | } | 142 | } |
139 | 143 | ||
140 | void Ntp::slotButtonRunNtp() | 144 | void Ntp::slotButtonRunNtp() |
141 | { | 145 | { |
142 | _interactive = true; | 146 | _interactive = true; |
143 | slotRunNtp(); | 147 | slotRunNtp(); |
144 | } | 148 | } |
145 | 149 | ||
146 | void Ntp::slotTimerRunNtp() | 150 | void Ntp::slotTimerRunNtp() |
147 | { | 151 | { |
148 | _interactive = false; | 152 | _interactive = false; |
149 | slotRunNtp(); | 153 | slotRunNtp(); |
150 | } | 154 | } |
151 | 155 | ||
152 | 156 | ||
153 | void Ntp::slotRunNtp() | 157 | void Ntp::slotRunNtp() |
154 | { | 158 | { |
155 | if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) | 159 | if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) |
156 | { | 160 | { |
157 | switch ( | 161 | switch ( |
158 | QMessageBox::warning(this, tr("Run NTP?"), | 162 | QMessageBox::warning(this, tr("Run NTP?"), |
159 | 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 ")+ |
160 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ | 164 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ |
161 | "<br>"+tr("Rerun NTP?"), | 165 | "<br>"+tr("Rerun NTP?"), |
162 | QMessageBox::Ok,QMessageBox::Cancel) | 166 | QMessageBox::Ok,QMessageBox::Cancel) |
163 | ) { | 167 | ) { |
164 | case QMessageBox::Ok: break; | 168 | case QMessageBox::Ok: break; |
165 | case QMessageBox::Cancel: return; | 169 | case QMessageBox::Cancel: return; |
166 | default: return; | 170 | default: return; |
167 | } | 171 | } |
@@ -387,49 +391,49 @@ void Ntp::showAdvancedFeatures(bool advMode) | |||
387 | if (advMode) { | 391 | if (advMode) { |
388 | 392 | ||
389 | TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); | 393 | TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); |
390 | TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); | 394 | TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); |
391 | TextLabel1_2_2->show(); | 395 | TextLabel1_2_2->show(); |
392 | TextLabel2_3->show(); | 396 | TextLabel2_3->show(); |
393 | TextLabel3_3_2->show(); | 397 | TextLabel3_3_2->show(); |
394 | TextLabel1_2->show(); | 398 | TextLabel1_2->show(); |
395 | SpinBoxMinLookupDelay->show(); | 399 | SpinBoxMinLookupDelay->show(); |
396 | TextLabel2->show(); | 400 | TextLabel2->show(); |
397 | TextLabel3_3->show(); | 401 | TextLabel3_3->show(); |
398 | SpinBoxNtpDelay->show(); | 402 | SpinBoxNtpDelay->show(); |
399 | Line1->show(); | 403 | Line1->show(); |
400 | }else{ | 404 | }else{ |
401 | TabWidgetMain->removePage( tabPredict ); | 405 | TabWidgetMain->removePage( tabPredict ); |
402 | TabWidgetMain->removePage( tabNtp ); | 406 | TabWidgetMain->removePage( tabNtp ); |
403 | TextLabel1_2_2->hide(); | 407 | TextLabel1_2_2->hide(); |
404 | TextLabel2_3->hide(); | 408 | TextLabel2_3->hide(); |
405 | TextLabel3_3_2->hide(); | 409 | TextLabel3_3_2->hide(); |
406 | TextLabel1_2->hide(); | 410 | TextLabel1_2->hide(); |
407 | SpinBoxMinLookupDelay->hide(); | 411 | SpinBoxMinLookupDelay->hide(); |
408 | TextLabel2->hide(); | 412 | TextLabel2->hide(); |
409 | TextLabel3_3->hide(); | 413 | TextLabel3_3->hide(); |
410 | SpinBoxNtpDelay->hide(); | 414 | SpinBoxNtpDelay->hide(); |
411 | Line1->hide(); | 415 | Line1->hide(); |
412 | }; | 416 | }; |
413 | TabWidgetMain->show(); | 417 | TabWidgetMain->show(); |
414 | } | 418 | } |
415 | 419 | ||
416 | 420 | ||
417 | void Ntp::accept( ){ | 421 | void Ntp::accept( ){ |
418 | qDebug("saving"); | 422 | qDebug("saving"); |
419 | //SetTimeDate | 423 | //SetTimeDate |
420 | commitTime(); | 424 | commitTime(); |
421 | writeSettings(); | 425 | writeSettings(); |
422 | updateSystem(); | 426 | updateSystem(); |
423 | // Ntp | 427 | // Ntp |
424 | saveConfig(); | 428 | saveConfig(); |
425 | qApp->quit(); | 429 | qApp->quit(); |
426 | } | 430 | } |
427 | 431 | ||
428 | void Ntp::reject( ){ | 432 | void Ntp::reject( ){ |
429 | qDebug("_oldTimeZone %s",_oldTimeZone.latin1()); | 433 | qDebug("_oldTimeZone %s",_oldTimeZone.latin1()); |
430 | if (!_oldTimeZone.isEmpty()){ | 434 | if (!_oldTimeZone.isEmpty()){ |
431 | qDebug("reverting timezone"); | 435 | qDebug("reverting timezone"); |
432 | tzChange(_oldTimeZone); | 436 | tzChange(_oldTimeZone); |
433 | commitTime(); | 437 | commitTime(); |
434 | } | 438 | } |
435 | } \ No newline at end of file | 439 | } |