summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 7971f9a..40b5531 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -116,101 +116,102 @@ void Ntp::slotRunNtp()
116 116
117 ntpProcess->clearArguments(); 117 ntpProcess->clearArguments();
118 *ntpProcess << "ntpdate" << getNtpServer(); 118 *ntpProcess << "ntpdate" << getNtpServer();
119 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 119 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
120 if ( !ret ) { 120 if ( !ret ) {
121 qDebug("Error while executing ntpdate"); 121 qDebug("Error while executing ntpdate");
122 ntpOutPut( tr("Error while executing ntpdate")); 122 ntpOutPut( tr("Error while executing ntpdate"));
123 } 123 }
124} 124}
125 125
126void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 126void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
127{ 127{
128 QString lineStr, lineStrOld; 128 QString lineStr, lineStrOld;
129 lineStr = buffer; 129 lineStr = buffer;
130 lineStr=lineStr.left(buflen); 130 lineStr=lineStr.left(buflen);
131 if (lineStr!=lineStrOld) 131 if (lineStr!=lineStrOld)
132 { 132 {
133 ntpOutPut(lineStr); 133 ntpOutPut(lineStr);
134 _ntpOutput += lineStr; 134 _ntpOutput += lineStr;
135 } 135 }
136 lineStrOld = lineStr; 136 lineStrOld = lineStr;
137} 137}
138 138
139void Ntp::ntpFinished(OProcess *p) 139void Ntp::ntpFinished(OProcess *p)
140{ 140{
141 qDebug("p->exitStatus() %i",p->exitStatus()); 141 qDebug("p->exitStatus() %i",p->exitStatus());
142 if (p->exitStatus()!=0 || !p->normalExit()) 142 if (p->exitStatus()!=0 || !p->normalExit())
143 { 143 {
144 slotProbeNtpServer(); 144 slotProbeNtpServer();
145 return; 145 return;
146 } 146 }
147 Config cfg("ntp",Config::User); 147 Config cfg("ntp",Config::User);
148 cfg.setGroup("lookups"); 148 cfg.setGroup("lookups");
149 int lastLookup = cfg.readNumEntry("time",0); 149 int lastLookup = cfg.readNumEntry("time",0);
150 int lookupCount = cfg.readNumEntry("count",0); 150 int lookupCount = cfg.readNumEntry("count",0);
151 bool lastNtp = cfg.readBoolEntry("lastNtp",false); 151 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
152 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 152 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
153 cfg.writeEntry("time", time); 153 cfg.writeEntry("time", time);
154 154
155 float timeShift = getTimeShift(); 155 float timeShift = getTimeShift();
156 if (timeShift == 0.0) return; 156 if (timeShift == 0.0) return;
157 int secsSinceLast = time - lastLookup; 157 int secsSinceLast = time - lastLookup;
158 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 158 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
159 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 159 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
160 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 160 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
161 { 161 {
162 cfg.setGroup("lookup_"+QString::number(lookupCount)); 162 cfg.setGroup("lookup_"+QString::number(lookupCount));
163 lookupCount++; 163 lookupCount++;
164 cfg.writeEntry("count",lookupCount);
165 _shiftPerSec = timeShift / secsSinceLast; 164 _shiftPerSec = timeShift / secsSinceLast;
166 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 165 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
167 cfg.writeEntry("secsSinceLast",secsSinceLast); 166 cfg.writeEntry("secsSinceLast",secsSinceLast);
168 cfg.writeEntry("timeShift",QString::number(timeShift)); 167 cfg.writeEntry("timeShift",QString::number(timeShift));
168 cfg.setGroup("lookups");
169 cfg.writeEntry("count",lookupCount);
169 cfg.writeEntry("lastNtp",true); 170 cfg.writeEntry("lastNtp",true);
170 } 171 }
171} 172}
172 173
173 174
174float Ntp::getTimeShift() 175float Ntp::getTimeShift()
175{ 176{
176 QString _offset = "offset"; 177 QString _offset = "offset";
177 QString _sec = "sec"; 178 QString _sec = "sec";
178 QRegExp _reOffset = QRegExp(_offset); 179 QRegExp _reOffset = QRegExp(_offset);
179 QRegExp _reEndOffset = QRegExp(_sec); 180 QRegExp _reEndOffset = QRegExp(_sec);
180 int posOffset = _reOffset.match( _ntpOutput ); 181 int posOffset = _reOffset.match( _ntpOutput );
181 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 182 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
182 posOffset += _offset.length() + 1; 183 posOffset += _offset.length() + 1;
183 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 184 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
184 qDebug("%s", _ntpOutput.latin1()); 185 qDebug("%s", _ntpOutput.latin1());
185 qDebug("diff = >%s<",diff.latin1()); 186 qDebug("diff = >%s<",diff.latin1());
186 return diff.toFloat(); 187 return diff.toFloat();
187} 188}
188 189
189void Ntp::readLookups() 190void Ntp::readLookups()
190{ 191{
191 Config cfg("ntp",Config::User); 192 Config cfg("ntp",Config::User);
192 cfg.setGroup("lookups"); 193 cfg.setGroup("lookups");
193 int lookupCount = cfg.readNumEntry("count",0); 194 int lookupCount = cfg.readNumEntry("count",0);
194 float last, shift, shiftPerSec; 195 float last, shift, shiftPerSec;
195 qDebug("lookupCount = %i",lookupCount); 196 qDebug("lookupCount = %i",lookupCount);
196 TableLookups->setNumCols( 3 ); 197 TableLookups->setNumCols( 3 );
197 TableLookups->setNumRows( lookupCount); 198 TableLookups->setNumRows( lookupCount);
198 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); 199 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
199 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); 200 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
200 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); 201 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
201 int cw = TableLookups->width()/4; 202 int cw = TableLookups->width()/4;
202 qDebug("column width %i",cw); 203 qDebug("column width %i",cw);
203 cw = 50; 204 cw = 50;
204 TableLookups->setColumnWidth( 0, cw+30 ); 205 TableLookups->setColumnWidth( 0, cw+30 );
205 TableLookups->setColumnWidth( 1, cw ); 206 TableLookups->setColumnWidth( 1, cw );
206 TableLookups->setColumnWidth( 2, cw ); 207 TableLookups->setColumnWidth( 2, cw );
207 TableLookups->sortColumn(0, false, true ); 208 TableLookups->sortColumn(0, false, true );
208 // TableLookups->setSorting( true ); 209 // TableLookups->setSorting( true );
209 for (int i=0; i < lookupCount; i++) 210 for (int i=0; i < lookupCount; i++)
210 { 211 {
211 cfg.setGroup("lookup_"+QString::number(i)); 212 cfg.setGroup("lookup_"+QString::number(i));
212 last = cfg.readEntry("secsSinceLast",0).toFloat(); 213 last = cfg.readEntry("secsSinceLast",0).toFloat();
213 shift = QString(cfg.readEntry("timeShift",0)).toFloat(); 214 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
214 // qDebug("%i last %f",i,last); 215 // qDebug("%i last %f",i,last);
215 // qDebug("%i shift %f",i,shift); 216 // qDebug("%i shift %f",i,shift);
216 shiftPerSec = shift / last; 217 shiftPerSec = shift / last;