-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index aecefc1..f653cd0 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -1,441 +1,446 @@ | |||
1 | #include "ntp.h" | 1 | #include "ntp.h" |
2 | #include <qpushbutton.h> | 2 | #include <qpushbutton.h> |
3 | #include <qregexp.h> | 3 | #include <qregexp.h> |
4 | #include <qtimer.h> | 4 | #include <qtimer.h> |
5 | #include <qtable.h> | 5 | #include <qtable.h> |
6 | #include <qlabel.h> | 6 | #include <qlabel.h> |
7 | #include <qsocket.h> | 7 | #include <qsocket.h> |
8 | #include <qlineedit.h> | 8 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 9 | #include <qspinbox.h> |
10 | #include <qcheckbox.h> | 10 | #include <qcheckbox.h> |
11 | #include <qtabwidget.h> | 11 | #include <qtabwidget.h> |
12 | #include <qlayout.h> | 12 | #include <qlayout.h> |
13 | #include <qmessagebox.h> | 13 | #include <qmessagebox.h> |
14 | #include <qmultilineedit.h> | 14 | #include <qmultilineedit.h> |
15 | #include <opie/oprocess.h> | 15 | #include <opie/oprocess.h> |
16 | #include <qpe/qpeapplication.h> | 16 | #include <qpe/qpeapplication.h> |
17 | #include <qpe/config.h> | 17 | #include <qpe/config.h> |
18 | #include <qpe/global.h> | 18 | #include <qpe/global.h> |
19 | #include <qpe/timeconversion.h> | 19 | #include <qpe/timeconversion.h> |
20 | #include <qpe/tzselect.h> | 20 | #include <qpe/tzselect.h> |
21 | #include <qpe/timestring.h> | 21 | #include <qpe/timestring.h> |
22 | #include <qpe/qpedialog.h> | 22 | #include <qpe/qpedialog.h> |
23 | #include <qpe/datebookdb.h> | 23 | #include <qpe/datebookdb.h> |
24 | #include <qpe/datebookmonth.h> | ||
24 | #include <qpe/qcopenvelope_qws.h> | 25 | #include <qpe/qcopenvelope_qws.h> |
25 | #include <sys/time.h> | 26 | #include <sys/time.h> |
26 | #include <time.h> | 27 | #include <time.h> |
27 | #include <stdlib.h> | 28 | #include <stdlib.h> |
28 | 29 | ||
29 | 30 | ||
30 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 31 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
31 | : SetDateTime( parent, name, fl ) | 32 | : SetDateTime( parent, name, fl ) |
32 | { | 33 | { |
33 | _interactive = false; | 34 | _interactive = false; |
34 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); | 35 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); |
35 | ntpSrvs.setGroup("servers"); | 36 | ntpSrvs.setGroup("servers"); |
36 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); | 37 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); |
37 | for (int i = 0; i < srvCount; i++) | 38 | for (int i = 0; i < srvCount; i++) |
38 | { | 39 | { |
39 | ntpSrvs.setGroup(QString::number(i)); | 40 | ntpSrvs.setGroup(QString::number(i)); |
40 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); | 41 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); |
41 | } | 42 | } |
42 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); | 43 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); |
43 | 44 | ||
44 | Config cfg("ntp",Config::User); | 45 | Config cfg("ntp",Config::User); |
45 | cfg.setGroup("settings"); | 46 | cfg.setGroup("settings"); |
46 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) ); | 47 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) ); |
47 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) ); | 48 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) ); |
48 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); | 49 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); |
49 | 50 | ||
50 | //make tab order | 51 | //make tab order |
51 | 52 | ||
52 | TabWidgetMain->removePage( tabMain ); | 53 | TabWidgetMain->removePage( tabMain ); |
53 | TabWidgetMain->removePage( tabManualSetTime ); | 54 | TabWidgetMain->removePage( tabManualSetTime ); |
54 | TabWidgetMain->removePage( TabSettings ); | 55 | TabWidgetMain->removePage( TabSettings ); |
55 | TabWidgetMain->removePage( tabPredict ); | 56 | TabWidgetMain->removePage( tabPredict ); |
56 | TabWidgetMain->removePage( tabNtp ); | 57 | TabWidgetMain->removePage( tabNtp ); |
57 | 58 | ||
58 | TabWidgetMain->insertTab( tabMain, tr( "Main" ) ); | 59 | TabWidgetMain->insertTab( tabMain, tr( "Main" ) ); |
59 | TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) ); | 60 | TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) ); |
60 | TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) ); | 61 | TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) ); |
61 | TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) ); | 62 | TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) ); |
62 | NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 ); | 63 | NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 ); |
63 | 64 | ||
64 | 65 | ||
65 | 66 | ||
66 | bool advMode = cfg.readBoolEntry("advancedFeatures", false ); | 67 | bool advMode = cfg.readBoolEntry("advancedFeatures", false ); |
67 | showAdvancedFeatures(advMode); | 68 | showAdvancedFeatures(advMode); |
68 | CheckBoxAdvSettings->setChecked( advMode ); | 69 | CheckBoxAdvSettings->setChecked( advMode ); |
69 | connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), | 70 | connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), |
70 | SLOT( showAdvancedFeatures( bool ) ) ); | 71 | SLOT( showAdvancedFeatures( bool ) ) ); |
71 | 72 | ||
72 | makeChannel(); | 73 | makeChannel(); |
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) ),SLOT(slotCheckNtp(int)) ); | 82 | connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) ); |
82 | slotProbeNtpServer(); | 83 | slotProbeNtpServer(); |
83 | 84 | ||
84 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 85 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
85 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 86 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
86 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 87 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
87 | this, SLOT(ntpFinished(OProcess*))); | 88 | this, SLOT(ntpFinished(OProcess*))); |
88 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); | 89 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); |
89 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 90 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
90 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 91 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
91 | slotCheckNtp(-1); | 92 | slotCheckNtp(-1); |
92 | readLookups(); | 93 | readLookups(); |
93 | } | 94 | } |
94 | 95 | ||
95 | Ntp::~Ntp() | 96 | Ntp::~Ntp() |
96 | { | 97 | { |
97 | delete ntpProcess; | 98 | delete ntpProcess; |
98 | } | 99 | } |
99 | 100 | ||
100 | void Ntp::saveConfig(){ | 101 | void Ntp::saveConfig(){ |
101 | int srvCount = ComboNtpSrv->count(); | 102 | int srvCount = ComboNtpSrv->count(); |
102 | bool serversChanged = true; | 103 | bool serversChanged = true; |
103 | int curSrv = ComboNtpSrv->currentItem(); | 104 | int curSrv = ComboNtpSrv->currentItem(); |
104 | QString edit = ComboNtpSrv->currentText(); | 105 | QString edit = ComboNtpSrv->currentText(); |
105 | for (int i = 0; i < srvCount; i++){ | 106 | for (int i = 0; i < srvCount; i++){ |
106 | if ( edit == ComboNtpSrv->text(i)) serversChanged = false; | 107 | if ( edit == ComboNtpSrv->text(i)) serversChanged = false; |
107 | } | 108 | } |
108 | if (serversChanged){ | 109 | if (serversChanged){ |
109 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); | 110 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); |
110 | ntpSrvs.setGroup("servers"); | 111 | ntpSrvs.setGroup("servers"); |
111 | ntpSrvs.writeEntry("count", ++srvCount); | 112 | ntpSrvs.writeEntry("count", ++srvCount); |
112 | ntpSrvs.setGroup("0"); | 113 | ntpSrvs.setGroup("0"); |
113 | ntpSrvs.writeEntry( "name", edit ); | 114 | ntpSrvs.writeEntry( "name", edit ); |
114 | curSrv = 0; | 115 | curSrv = 0; |
115 | for (int i = 1; i < srvCount; i++){ | 116 | for (int i = 1; i < srvCount; i++){ |
116 | qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); | 117 | qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); |
117 | ntpSrvs.setGroup(QString::number(i)); | 118 | ntpSrvs.setGroup(QString::number(i)); |
118 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) ); | 119 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) ); |
119 | } | 120 | } |
120 | } | 121 | } |
121 | Config cfg("ntp",Config::User); | 122 | Config cfg("ntp",Config::User); |
122 | cfg.setGroup("settings"); | 123 | cfg.setGroup("settings"); |
123 | cfg.writeEntry("ntpServer", curSrv ); | 124 | cfg.writeEntry("ntpServer", curSrv ); |
124 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 125 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
125 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 126 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
126 | cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); | 127 | cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); |
127 | } | 128 | } |
128 | 129 | ||
129 | bool Ntp::ntpDelayElapsed() | 130 | bool Ntp::ntpDelayElapsed() |
130 | { | 131 | { |
131 | Config cfg("ntp",Config::User); | 132 | Config cfg("ntp",Config::User); |
132 | cfg.setGroup("lookups"); | 133 | cfg.setGroup("lookups"); |
133 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | 134 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); |
134 | if (_lookupDiff < 0) return true; | 135 | if (_lookupDiff < 0) return true; |
135 | int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); | 136 | int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); |
136 | return i > -60; | 137 | return i > -60; |
137 | } | 138 | } |
138 | 139 | ||
139 | QString Ntp::getNtpServer() | 140 | QString Ntp::getNtpServer() |
140 | { | 141 | { |
141 | return ComboNtpSrv->currentText(); | 142 | return ComboNtpSrv->currentText(); |
142 | } | 143 | } |
143 | 144 | ||
144 | void Ntp::slotButtonRunNtp() | 145 | void Ntp::slotButtonRunNtp() |
145 | { | 146 | { |
146 | _interactive = true; | 147 | _interactive = true; |
147 | slotRunNtp(); | 148 | slotRunNtp(); |
148 | } | 149 | } |
149 | 150 | ||
150 | void Ntp::slotTimerRunNtp() | 151 | void Ntp::slotTimerRunNtp() |
151 | { | 152 | { |
152 | _interactive = false; | 153 | _interactive = false; |
153 | slotRunNtp(); | 154 | slotRunNtp(); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
157 | void Ntp::slotRunNtp() | 158 | void Ntp::slotRunNtp() |
158 | { | 159 | { |
159 | if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) | 160 | if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) |
160 | { | 161 | { |
161 | switch ( | 162 | switch ( |
162 | QMessageBox::warning(this, tr("Run NTP?"), | 163 | QMessageBox::warning(this, tr("Run NTP?"), |
163 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 164 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
164 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ | 165 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ |
165 | "<br>"+tr("Rerun NTP?"), | 166 | "<br>"+tr("Rerun NTP?"), |
166 | QMessageBox::Ok,QMessageBox::Cancel) | 167 | QMessageBox::Ok,QMessageBox::Cancel) |
167 | ) { | 168 | ) { |
168 | case QMessageBox::Ok: break; | 169 | case QMessageBox::Ok: break; |
169 | case QMessageBox::Cancel: return; | 170 | case QMessageBox::Cancel: return; |
170 | default: return; | 171 | default: return; |
171 | } | 172 | } |
172 | } | 173 | } |
173 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 174 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
174 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 175 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
175 | 176 | ||
176 | ntpProcess->clearArguments(); | 177 | ntpProcess->clearArguments(); |
177 | *ntpProcess << "ntpdate" << getNtpServer(); | 178 | *ntpProcess << "ntpdate" << getNtpServer(); |
178 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 179 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
179 | if ( !ret ) { | 180 | if ( !ret ) { |
180 | QMessageBox::critical(this, tr("ntp error"), | 181 | QMessageBox::critical(this, tr("ntp error"), |
181 | tr("Error while getting time form network!")); | 182 | tr("Error while getting time form network!")); |
182 | qDebug("Error while executing ntpdate"); | 183 | qDebug("Error while executing ntpdate"); |
183 | ntpOutPut( tr("Error while executing ntpdate")); | 184 | ntpOutPut( tr("Error while executing ntpdate")); |
184 | } | 185 | } |
185 | } | 186 | } |
186 | 187 | ||
187 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 188 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
188 | { | 189 | { |
189 | if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null"); | 190 | if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null"); |
190 | QString lineStr, lineStrOld; | 191 | QString lineStr, lineStrOld; |
191 | lineStr = buffer; | 192 | lineStr = buffer; |
192 | lineStr=lineStr.left(buflen); | 193 | lineStr=lineStr.left(buflen); |
193 | if (lineStr!=lineStrOld) | 194 | if (lineStr!=lineStrOld) |
194 | { | 195 | { |
195 | ntpOutPut(lineStr); | 196 | ntpOutPut(lineStr); |
196 | _ntpOutput += lineStr; | 197 | _ntpOutput += lineStr; |
197 | } | 198 | } |
198 | lineStrOld = lineStr; | 199 | lineStrOld = lineStr; |
199 | } | 200 | } |
200 | 201 | ||
201 | void Ntp::ntpFinished(OProcess *p) | 202 | void Ntp::ntpFinished(OProcess *p) |
202 | { | 203 | { |
203 | qDebug("p->exitStatus() %i",p->exitStatus()); | 204 | qDebug("p->exitStatus() %i",p->exitStatus()); |
204 | if (p->exitStatus()!=0 || !p->normalExit()) | 205 | if (p->exitStatus()!=0 || !p->normalExit()) |
205 | { | 206 | { |
206 | if ( isVisible() && _interactive ){ | 207 | if ( isVisible() && _interactive ){ |
207 | QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); | 208 | QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); |
208 | } | 209 | } |
209 | // slotCheckNtp(-1); | 210 | // slotCheckNtp(-1); |
210 | return; | 211 | return; |
211 | } | 212 | } |
212 | 213 | ||
213 | Config cfg("ntp",Config::User); | 214 | Config cfg("ntp",Config::User); |
214 | cfg.setGroup("lookups"); | 215 | cfg.setGroup("lookups"); |
215 | int lastLookup = cfg.readNumEntry("time",0); | 216 | int lastLookup = cfg.readNumEntry("time",0); |
216 | int lookupCount = cfg.readNumEntry("count",0); | 217 | int lookupCount = cfg.readNumEntry("count",0); |
217 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); | 218 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); |
218 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 219 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
219 | cfg.writeEntry("time", time); | 220 | cfg.writeEntry("time", time); |
220 | 221 | ||
221 | float timeShift = getTimeShift(); | 222 | float timeShift = getTimeShift(); |
222 | if (timeShift == 0.0) return; | 223 | if (timeShift == 0.0) return; |
223 | int secsSinceLast = time - lastLookup; | 224 | int secsSinceLast = time - lastLookup; |
224 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 225 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
225 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); | 226 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); |
227 | |||
228 | dateButton->setDate( QDate::currentDate() ); | ||
229 | timeButton->setTime( QDateTime::currentDateTime() ); | ||
230 | |||
226 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) | 231 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) |
227 | { | 232 | { |
228 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | 233 | cfg.setGroup("lookup_"+QString::number(lookupCount)); |
229 | lookupCount++; | 234 | lookupCount++; |
230 | _shiftPerSec = timeShift / secsSinceLast; | 235 | _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); | 236 | 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); | 237 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
233 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 238 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
234 | cfg.setGroup("lookups"); | 239 | cfg.setGroup("lookups"); |
235 | cfg.writeEntry("count",lookupCount); | 240 | cfg.writeEntry("count",lookupCount); |
236 | cfg.writeEntry("lastNtp",true); | 241 | cfg.writeEntry("lastNtp",true); |
237 | } | 242 | } |
238 | } | 243 | } |
239 | 244 | ||
240 | 245 | ||
241 | float Ntp::getTimeShift() | 246 | float Ntp::getTimeShift() |
242 | { | 247 | { |
243 | QString _offset = "offset"; | 248 | QString _offset = "offset"; |
244 | QString _sec = "sec"; | 249 | QString _sec = "sec"; |
245 | QRegExp _reOffset = QRegExp(_offset); | 250 | QRegExp _reOffset = QRegExp(_offset); |
246 | QRegExp _reEndOffset = QRegExp(_sec); | 251 | QRegExp _reEndOffset = QRegExp(_sec); |
247 | int posOffset = _reOffset.match( _ntpOutput ); | 252 | int posOffset = _reOffset.match( _ntpOutput ); |
248 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); | 253 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); |
249 | posOffset += _offset.length() + 1; | 254 | posOffset += _offset.length() + 1; |
250 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); | 255 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); |
251 | qDebug("%s", _ntpOutput.latin1()); | 256 | qDebug("%s", _ntpOutput.latin1()); |
252 | qDebug("diff = >%s<",diff.latin1()); | 257 | qDebug("diff = >%s<",diff.latin1()); |
253 | return diff.toFloat(); | 258 | return diff.toFloat(); |
254 | } | 259 | } |
255 | 260 | ||
256 | void Ntp::readLookups() | 261 | void Ntp::readLookups() |
257 | { | 262 | { |
258 | Config cfg("ntp",Config::User); | 263 | Config cfg("ntp",Config::User); |
259 | cfg.setGroup("lookups"); | 264 | cfg.setGroup("lookups"); |
260 | int lookupCount = cfg.readNumEntry("count",0); | 265 | int lookupCount = cfg.readNumEntry("count",0); |
261 | float last, shift, shiftPerSec; | 266 | float last, shift, shiftPerSec; |
262 | qDebug("lookupCount = %i",lookupCount); | 267 | qDebug("lookupCount = %i",lookupCount); |
263 | TableLookups->setNumCols( 3 ); | 268 | TableLookups->setNumCols( 3 ); |
264 | TableLookups->setNumRows( lookupCount); | 269 | TableLookups->setNumRows( lookupCount); |
265 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); | 270 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); |
266 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); | 271 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); |
267 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); | 272 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); |
268 | int cw = TableLookups->width()/4; | 273 | int cw = TableLookups->width()/4; |
269 | qDebug("column width %i",cw); | 274 | qDebug("column width %i",cw); |
270 | cw = 50; | 275 | cw = 50; |
271 | TableLookups->setColumnWidth( 0, cw+30 ); | 276 | TableLookups->setColumnWidth( 0, cw+30 ); |
272 | TableLookups->setColumnWidth( 1, cw ); | 277 | TableLookups->setColumnWidth( 1, cw ); |
273 | TableLookups->setColumnWidth( 2, cw ); | 278 | TableLookups->setColumnWidth( 2, cw ); |
274 | TableLookups->sortColumn(0, false, true ); | 279 | TableLookups->sortColumn(0, false, true ); |
275 | // TableLookups->setSorting( true ); | 280 | // TableLookups->setSorting( true ); |
276 | _shiftPerSec = 0; | 281 | _shiftPerSec = 0; |
277 | for (int i=0; i < lookupCount; i++) | 282 | for (int i=0; i < lookupCount; i++) |
278 | { | 283 | { |
279 | cfg.setGroup("lookup_"+QString::number(i)); | 284 | cfg.setGroup("lookup_"+QString::number(i)); |
280 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 285 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
281 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 286 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
282 | shiftPerSec = shift / last; | 287 | shiftPerSec = shift / last; |
283 | qDebug("%i shift %f",i,shiftPerSec); | 288 | qDebug("%i shift %f",i,shiftPerSec); |
284 | _shiftPerSec += shiftPerSec; | 289 | _shiftPerSec += shiftPerSec; |
285 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); | 290 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); |
286 | TableLookups->setText( i,2,QString::number(shift)); | 291 | TableLookups->setText( i,2,QString::number(shift)); |
287 | TableLookups->setText( i,1,QString::number(last/(60*60))); | 292 | TableLookups->setText( i,1,QString::number(last/(60*60))); |
288 | } | 293 | } |
289 | _shiftPerSec /= lookupCount; | 294 | _shiftPerSec /= lookupCount; |
290 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); | 295 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); |
291 | } | 296 | } |
292 | 297 | ||
293 | void Ntp::preditctTime() | 298 | void Ntp::preditctTime() |
294 | { | 299 | { |
295 | Config cfg("ntp",Config::User); | 300 | Config cfg("ntp",Config::User); |
296 | cfg.setGroup("lookups"); | 301 | cfg.setGroup("lookups"); |
297 | int lastTime = cfg.readNumEntry("time",0); | 302 | int lastTime = cfg.readNumEntry("time",0); |
298 | cfg.writeEntry("lastNtp",true); | 303 | cfg.writeEntry("lastNtp",true); |
299 | setenv( "TZ", tz->currentZone(), 1 ); | 304 | setenv( "TZ", tz->currentZone(), 1 ); |
300 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 305 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
301 | int corr = int((now - lastTime) * _shiftPerSec); | 306 | int corr = int((now - lastTime) * _shiftPerSec); |
302 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 307 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
303 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 308 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
304 | TextLabelPredTime->setText(predictedTime.toString()); | 309 | TextLabelPredTime->setText(predictedTime.toString()); |
305 | // TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 310 | // TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
306 | } | 311 | } |
307 | 312 | ||
308 | void Ntp::setPredictTime() | 313 | void Ntp::setPredictTime() |
309 | { | 314 | { |
310 | qDebug("Ntp::setPredictTime"); | 315 | qDebug("Ntp::setPredictTime"); |
311 | preditctTime(); | 316 | preditctTime(); |
312 | timeButton->setTime( predictedTime ); | 317 | timeButton->setTime( predictedTime ); |
313 | } | 318 | } |
314 | 319 | ||
315 | void Ntp::slotCheckNtp(int i) | 320 | void Ntp::slotCheckNtp(int i) |
316 | { | 321 | { |
317 | qDebug(" Ntp::slotCheckNtp(%i)",i); | 322 | qDebug(" Ntp::slotCheckNtp(%i)",i); |
318 | if (i == 0) | 323 | if (i == 0) |
319 | { | 324 | { |
320 | // TextLabelMainPredTime->hide(); | 325 | // TextLabelMainPredTime->hide(); |
321 | ButtonSetTime->setText( tr("Get time from network") ); | 326 | ButtonSetTime->setText( tr("Get time from network") ); |
322 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) ); | 327 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) ); |
323 | if ( ntpDelayElapsed() ) | 328 | if ( ntpDelayElapsed() ) |
324 | { | 329 | { |
325 | slotRunNtp(); | 330 | slotRunNtp(); |
326 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 331 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
327 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); | 332 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); |
328 | }else{ | 333 | }else{ |
329 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); | 334 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); |
330 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 335 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
331 | } | 336 | } |
332 | }else{ | 337 | }else{ |
333 | preditctTime(); | 338 | preditctTime(); |
334 | ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); | 339 | ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); |
335 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 340 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
336 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 341 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
337 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 342 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
338 | } | 343 | } |
339 | } | 344 | } |
340 | 345 | ||
341 | void Ntp::slotProbeNtpServer() | 346 | void Ntp::slotProbeNtpServer() |
342 | { | 347 | { |
343 | ntpSock->connectToHost( getNtpServer() ,123); | 348 | ntpSock->connectToHost( getNtpServer() ,123); |
344 | } | 349 | } |
345 | 350 | ||
346 | void Ntp::slotNtpDelayChanged(int delay) | 351 | void Ntp::slotNtpDelayChanged(int delay) |
347 | { | 352 | { |
348 | ntpTimer->changeInterval( delay*1000*60 ); | 353 | ntpTimer->changeInterval( delay*1000*60 ); |
349 | } | 354 | } |
350 | 355 | ||
351 | void Ntp::ntpOutPut(QString out) | 356 | void Ntp::ntpOutPut(QString out) |
352 | { | 357 | { |
353 | 358 | ||
354 | MultiLineEditntpOutPut->append(out); | 359 | MultiLineEditntpOutPut->append(out); |
355 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 360 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
356 | } | 361 | } |
357 | 362 | ||
358 | 363 | ||
359 | void Ntp::makeChannel() | 364 | void Ntp::makeChannel() |
360 | { | 365 | { |
361 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); | 366 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); |
362 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 367 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
363 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 368 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
364 | } | 369 | } |
365 | 370 | ||
366 | 371 | ||
367 | 372 | ||
368 | void Ntp::receive(const QCString &msg, const QByteArray &arg) | 373 | void Ntp::receive(const QCString &msg, const QByteArray &arg) |
369 | { | 374 | { |
370 | qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); | 375 | qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); |
371 | if ( msg == "ntpLookup(QString)" ) | 376 | if ( msg == "ntpLookup(QString)" ) |
372 | { | 377 | { |
373 | _interactive = false; | 378 | _interactive = false; |
374 | slotRunNtp(); | 379 | slotRunNtp(); |
375 | } | 380 | } |
376 | if ( msg == "setPredictedTime(QString)" ) | 381 | if ( msg == "setPredictedTime(QString)" ) |
377 | { | 382 | { |
378 | setPredictTime(); | 383 | setPredictTime(); |
379 | }else{ | 384 | }else{ |
380 | qDebug("Ntp::receive: Huh what do ya want"); | 385 | qDebug("Ntp::receive: Huh what do ya want"); |
381 | } | 386 | } |
382 | } | 387 | } |
383 | 388 | ||
384 | void Ntp::setDocument(const QString &fileName) | 389 | void Ntp::setDocument(const QString &fileName) |
385 | { | 390 | { |
386 | qDebug("Ntp::setDocument( %s )",fileName.latin1()); | 391 | qDebug("Ntp::setDocument( %s )",fileName.latin1()); |
387 | } | 392 | } |
388 | 393 | ||
389 | void Ntp::showAdvancedFeatures(bool advMode) | 394 | void Ntp::showAdvancedFeatures(bool advMode) |
390 | { | 395 | { |
391 | if (advMode) { | 396 | if (advMode) { |
392 | 397 | ||
393 | if ( tabNtp->isVisible() ) { | 398 | if ( tabNtp->isVisible() ) { |
394 | TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); | 399 | TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); |
395 | TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); | 400 | TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); |
396 | } | 401 | } |
397 | TextLabel1_2_2->show(); | 402 | TextLabel1_2_2->show(); |
398 | TextLabel2_3->show(); | 403 | TextLabel2_3->show(); |
399 | TextLabel3_3_2->show(); | 404 | TextLabel3_3_2->show(); |
400 | TextLabel1_2->show(); | 405 | TextLabel1_2->show(); |
401 | SpinBoxMinLookupDelay->show(); | 406 | SpinBoxMinLookupDelay->show(); |
402 | TextLabel2->show(); | 407 | TextLabel2->show(); |
403 | TextLabel3_3->show(); | 408 | TextLabel3_3->show(); |
404 | SpinBoxNtpDelay->show(); | 409 | SpinBoxNtpDelay->show(); |
405 | Line1->show(); | 410 | Line1->show(); |
406 | }else{ | 411 | }else{ |
407 | TabWidgetMain->removePage( tabPredict ); | 412 | TabWidgetMain->removePage( tabPredict ); |
408 | TabWidgetMain->removePage( tabNtp ); | 413 | TabWidgetMain->removePage( tabNtp ); |
409 | TextLabel1_2_2->hide(); | 414 | TextLabel1_2_2->hide(); |
410 | TextLabel2_3->hide(); | 415 | TextLabel2_3->hide(); |
411 | TextLabel3_3_2->hide(); | 416 | TextLabel3_3_2->hide(); |
412 | TextLabel1_2->hide(); | 417 | TextLabel1_2->hide(); |
413 | SpinBoxMinLookupDelay->hide(); | 418 | SpinBoxMinLookupDelay->hide(); |
414 | TextLabel2->hide(); | 419 | TextLabel2->hide(); |
415 | TextLabel3_3->hide(); | 420 | TextLabel3_3->hide(); |
416 | SpinBoxNtpDelay->hide(); | 421 | SpinBoxNtpDelay->hide(); |
417 | Line1->hide(); | 422 | Line1->hide(); |
418 | }; | 423 | }; |
419 | TabWidgetMain->show(); | 424 | TabWidgetMain->show(); |
420 | } | 425 | } |
421 | 426 | ||
422 | 427 | ||
423 | void Ntp::accept( ){ | 428 | void Ntp::accept( ){ |
424 | qDebug("saving"); | 429 | qDebug("saving"); |
425 | //SetTimeDate | 430 | //SetTimeDate |
426 | commitTime(); | 431 | commitTime(); |
427 | writeSettings(); | 432 | writeSettings(); |
428 | updateSystem(); | 433 | updateSystem(); |
429 | // Ntp | 434 | // Ntp |
430 | saveConfig(); | 435 | saveConfig(); |
431 | qApp->quit(); | 436 | qApp->quit(); |
432 | } | 437 | } |
433 | 438 | ||
434 | void Ntp::reject( ){ | 439 | void Ntp::reject( ){ |
435 | qDebug("_oldTimeZone %s",_oldTimeZone.latin1()); | 440 | qDebug("_oldTimeZone %s",_oldTimeZone.latin1()); |
436 | if (!_oldTimeZone.isEmpty()){ | 441 | if (!_oldTimeZone.isEmpty()){ |
437 | qDebug("reverting timezone"); | 442 | qDebug("reverting timezone"); |
438 | tzChange(_oldTimeZone); | 443 | tzChange(_oldTimeZone); |
439 | commitTime(); | 444 | commitTime(); |
440 | } | 445 | } |
441 | } | 446 | } |