author | tille <tille> | 2002-10-21 21:52:48 (UTC) |
---|---|---|
committer | tille <tille> | 2002-10-21 21:52:48 (UTC) |
commit | 5bcd4ccebd86f912c693de16675da44d21e11d94 (patch) (unidiff) | |
tree | 069d23db3e886319f0a76071609d11b814bd4bfb | |
parent | 21d29dbf8a9c1a12c7c23f96b80307e87ffaa50a (diff) | |
download | opie-5bcd4ccebd86f912c693de16675da44d21e11d94.zip opie-5bcd4ccebd86f912c693de16675da44d21e11d94.tar.gz opie-5bcd4ccebd86f912c693de16675da44d21e11d94.tar.bz2 |
saves feature settings now
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 6f6316c..f60e38d 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -1,367 +1,370 @@ | |||
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/qcopenvelope_qws.h> | 24 | #include <qpe/qcopenvelope_qws.h> |
25 | #include <sys/time.h> | 25 | #include <sys/time.h> |
26 | #include <time.h> | 26 | #include <time.h> |
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | 28 | ||
29 | 29 | ||
30 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 30 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
31 | : SetDateTime( parent, name, fl ) | 31 | : SetDateTime( parent, name, fl ) |
32 | { | 32 | { |
33 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); | 33 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); |
34 | ntpSrvs.setGroup("servers"); | 34 | ntpSrvs.setGroup("servers"); |
35 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); | 35 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); |
36 | for (int i = 0; i < srvCount; i++) | 36 | for (int i = 0; i < srvCount; i++) |
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 | bool advMode = cfg.readBoolEntry("advancedFeatures", false ); | 49 | bool advMode = cfg.readBoolEntry("advancedFeatures", false ); |
50 | showAdvancedFeatures(advMode); | 50 | showAdvancedFeatures(advMode); |
51 | CheckBoxAdvSettings->setChecked( advMode ); | 51 | CheckBoxAdvSettings->setChecked( advMode ); |
52 | connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), | 52 | connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), |
53 | SLOT( showAdvancedFeatures( bool ) ) ); | 53 | SLOT( showAdvancedFeatures( bool ) ) ); |
54 | 54 | ||
55 | makeChannel(); | 55 | makeChannel(); |
56 | 56 | ||
57 | ntpTimer = new QTimer(this); | 57 | ntpTimer = new QTimer(this); |
58 | 58 | ||
59 | ntpProcess = new OProcess( ); | 59 | ntpProcess = new OProcess( ); |
60 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 60 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
61 | SLOT(slotNtpDelayChanged(int)) ); | 61 | SLOT(slotNtpDelayChanged(int)) ); |
62 | 62 | ||
63 | ntpSock = new QSocket( this ); | 63 | ntpSock = new QSocket( this ); |
64 | connect( ntpSock, SIGNAL( error(int) ), | 64 | connect( ntpSock, SIGNAL( error(int) ), |
65 | SLOT(slotCheckNtp(int)) ); | 65 | SLOT(slotCheckNtp(int)) ); |
66 | slotProbeNtpServer(); | 66 | slotProbeNtpServer(); |
67 | 67 | ||
68 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 68 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
69 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 69 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
70 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 70 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
71 | this, SLOT(ntpFinished(OProcess*))); | 71 | this, SLOT(ntpFinished(OProcess*))); |
72 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 72 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
73 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 73 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
74 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 74 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
75 | slotCheckNtp(-1); | 75 | slotCheckNtp(-1); |
76 | readLookups(); | 76 | readLookups(); |
77 | } | 77 | } |
78 | 78 | ||
79 | Ntp::~Ntp() | 79 | Ntp::~Ntp() |
80 | { | 80 | { |
81 | delete ntpProcess; | 81 | delete ntpProcess; |
82 | Config ntpSrvs("/etc/ntpservers",Config::File); | 82 | Config ntpSrvs("/etc/ntpservers",Config::File); |
83 | ntpSrvs.setGroup("servers"); | 83 | ntpSrvs.setGroup("servers"); |
84 | int srvCount = ComboNtpSrv->count(); | 84 | int srvCount = ComboNtpSrv->count(); |
85 | ntpSrvs.writeEntry("count", srvCount); | 85 | ntpSrvs.writeEntry("count", srvCount); |
86 | for (int i = 0; i < srvCount; i++) | 86 | for (int i = 0; i < srvCount; i++){ |
87 | { | 87 | ntpSrvs.setGroup(QString::number(i)); |
88 | ntpSrvs.setGroup(QString::number(i)); | 88 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); |
89 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | ||
90 | } | 89 | } |
91 | Config cfg("ntp",Config::User); | 90 | Config cfg("ntp",Config::User); |
92 | cfg.setGroup("settings"); | 91 | cfg.setGroup("settings"); |
93 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); | 92 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); |
94 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 93 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
95 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 94 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
95 | cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); | ||
96 | } | 96 | } |
97 | 97 | ||
98 | bool Ntp::ntpDelayElapsed() | 98 | bool Ntp::ntpDelayElapsed() |
99 | { | 99 | { |
100 | Config cfg("ntp",Config::User); | 100 | Config cfg("ntp",Config::User); |
101 | cfg.setGroup("lookups"); | 101 | cfg.setGroup("lookups"); |
102 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | 102 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); |
103 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; | 103 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; |
104 | } | 104 | } |
105 | 105 | ||
106 | QString Ntp::getNtpServer() | 106 | QString Ntp::getNtpServer() |
107 | { | 107 | { |
108 | return ComboNtpSrv->currentText(); | 108 | return ComboNtpSrv->currentText(); |
109 | } | 109 | } |
110 | 110 | ||
111 | void Ntp::slotRunNtp() | 111 | void Ntp::slotRunNtp() |
112 | { | 112 | { |
113 | if ( !ntpDelayElapsed() ) | 113 | if ( !ntpDelayElapsed() ) |
114 | { | 114 | { |
115 | switch ( | 115 | switch ( |
116 | QMessageBox::warning(this, tr("Run NTP?"), | 116 | QMessageBox::warning(this, tr("Run NTP?"), |
117 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 117 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
118 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ | 118 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ |
119 | "<br>"+tr("Rerun NTP?"), | 119 | "<br>"+tr("Rerun NTP?"), |
120 | QMessageBox::Ok,QMessageBox::Cancel) | 120 | QMessageBox::Ok,QMessageBox::Cancel) |
121 | ) { | 121 | ) { |
122 | case QMessageBox::Ok: break; | 122 | case QMessageBox::Ok: break; |
123 | case QMessageBox::Cancel: return; | 123 | case QMessageBox::Cancel: return; |
124 | default: return; | 124 | default: return; |
125 | } | 125 | } |
126 | } | 126 | } |
127 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 127 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
128 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 128 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
129 | 129 | ||
130 | ntpProcess->clearArguments(); | 130 | ntpProcess->clearArguments(); |
131 | *ntpProcess << "ntpdate" << getNtpServer(); | 131 | *ntpProcess << "ntpdate" << getNtpServer(); |
132 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 132 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
133 | if ( !ret ) { | 133 | if ( !ret ) { |
134 | qDebug("Error while executing ntpdate"); | 134 | qDebug("Error while executing ntpdate"); |
135 | ntpOutPut( tr("Error while executing ntpdate")); | 135 | ntpOutPut( tr("Error while executing ntpdate")); |
136 | } | 136 | } |
137 | } | 137 | } |
138 | 138 | ||
139 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 139 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
140 | { | 140 | { |
141 | QString lineStr, lineStrOld; | 141 | QString lineStr, lineStrOld; |
142 | lineStr = buffer; | 142 | lineStr = buffer; |
143 | lineStr=lineStr.left(buflen); | 143 | lineStr=lineStr.left(buflen); |
144 | if (lineStr!=lineStrOld) | 144 | if (lineStr!=lineStrOld) |
145 | { | 145 | { |
146 | ntpOutPut(lineStr); | 146 | ntpOutPut(lineStr); |
147 | _ntpOutput += lineStr; | 147 | _ntpOutput += lineStr; |
148 | } | 148 | } |
149 | lineStrOld = lineStr; | 149 | lineStrOld = lineStr; |
150 | } | 150 | } |
151 | 151 | ||
152 | void Ntp::ntpFinished(OProcess *p) | 152 | void Ntp::ntpFinished(OProcess *p) |
153 | { | 153 | { |
154 | //qDebug("p->exitStatus() %i",p->exitStatus()); | 154 | //qDebug("p->exitStatus() %i",p->exitStatus()); |
155 | if (p->exitStatus()!=0 || !p->normalExit()) | 155 | if (p->exitStatus()!=0 || !p->normalExit()) |
156 | { | 156 | { |
157 | slotProbeNtpServer(); | 157 | slotProbeNtpServer(); |
158 | return; | 158 | return; |
159 | } | 159 | } |
160 | 160 | ||
161 | Global::writeHWClock(); | 161 | Global::writeHWClock(); |
162 | // since time has changed quickly load in the datebookdb | 162 | // since time has changed quickly load in the datebookdb |
163 | // to allow the alarm server to get a better grip on itself | 163 | // to allow the alarm server to get a better grip on itself |
164 | // (example re-trigger alarms for when we travel back in time) | 164 | // (example re-trigger alarms for when we travel back in time) |
165 | DateBookDB db; | 165 | DateBookDB db; |
166 | 166 | ||
167 | // QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); | 167 | // QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); |
168 | // timeApplet << ""; | 168 | // timeApplet << ""; |
169 | 169 | ||
170 | Config cfg("ntp",Config::User); | 170 | Config cfg("ntp",Config::User); |
171 | cfg.setGroup("lookups"); | 171 | cfg.setGroup("lookups"); |
172 | int lastLookup = cfg.readNumEntry("time",0); | 172 | int lastLookup = cfg.readNumEntry("time",0); |
173 | int lookupCount = cfg.readNumEntry("count",0); | 173 | int lookupCount = cfg.readNumEntry("count",0); |
174 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); | 174 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); |
175 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 175 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
176 | cfg.writeEntry("time", time); | 176 | cfg.writeEntry("time", time); |
177 | 177 | ||
178 | float timeShift = getTimeShift(); | 178 | float timeShift = getTimeShift(); |
179 | if (timeShift == 0.0) return; | 179 | if (timeShift == 0.0) return; |
180 | int secsSinceLast = time - lastLookup; | 180 | int secsSinceLast = time - lastLookup; |
181 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 181 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
182 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); | 182 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); |
183 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) | 183 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) |
184 | { | 184 | { |
185 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | 185 | cfg.setGroup("lookup_"+QString::number(lookupCount)); |
186 | lookupCount++; | 186 | lookupCount++; |
187 | _shiftPerSec = timeShift / secsSinceLast; | 187 | _shiftPerSec = timeShift / secsSinceLast; |
188 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); | 188 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); |
189 | cfg.writeEntry("secsSinceLast",secsSinceLast); | 189 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
190 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 190 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
191 | cfg.setGroup("lookups"); | 191 | cfg.setGroup("lookups"); |
192 | cfg.writeEntry("count",lookupCount); | 192 | cfg.writeEntry("count",lookupCount); |
193 | cfg.writeEntry("lastNtp",true); | 193 | cfg.writeEntry("lastNtp",true); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | float Ntp::getTimeShift() | 198 | float Ntp::getTimeShift() |
199 | { | 199 | { |
200 | QString _offset = "offset"; | 200 | QString _offset = "offset"; |
201 | QString _sec = "sec"; | 201 | QString _sec = "sec"; |
202 | QRegExp _reOffset = QRegExp(_offset); | 202 | QRegExp _reOffset = QRegExp(_offset); |
203 | QRegExp _reEndOffset = QRegExp(_sec); | 203 | QRegExp _reEndOffset = QRegExp(_sec); |
204 | int posOffset = _reOffset.match( _ntpOutput ); | 204 | int posOffset = _reOffset.match( _ntpOutput ); |
205 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); | 205 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); |
206 | posOffset += _offset.length() + 1; | 206 | posOffset += _offset.length() + 1; |
207 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); | 207 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); |
208 | qDebug("%s", _ntpOutput.latin1()); | 208 | qDebug("%s", _ntpOutput.latin1()); |
209 | qDebug("diff = >%s<",diff.latin1()); | 209 | qDebug("diff = >%s<",diff.latin1()); |
210 | return diff.toFloat(); | 210 | return diff.toFloat(); |
211 | } | 211 | } |
212 | 212 | ||
213 | void Ntp::readLookups() | 213 | void Ntp::readLookups() |
214 | { | 214 | { |
215 | Config cfg("ntp",Config::User); | 215 | Config cfg("ntp",Config::User); |
216 | cfg.setGroup("lookups"); | 216 | cfg.setGroup("lookups"); |
217 | int lookupCount = cfg.readNumEntry("count",0); | 217 | int lookupCount = cfg.readNumEntry("count",0); |
218 | float last, shift, shiftPerSec; | 218 | float last, shift, shiftPerSec; |
219 | qDebug("lookupCount = %i",lookupCount); | 219 | qDebug("lookupCount = %i",lookupCount); |
220 | TableLookups->setNumCols( 3 ); | 220 | TableLookups->setNumCols( 3 ); |
221 | TableLookups->setNumRows( lookupCount); | 221 | TableLookups->setNumRows( lookupCount); |
222 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); | 222 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); |
223 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); | 223 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); |
224 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); | 224 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); |
225 | int cw = TableLookups->width()/4; | 225 | int cw = TableLookups->width()/4; |
226 | qDebug("column width %i",cw); | 226 | qDebug("column width %i",cw); |
227 | cw = 50; | 227 | cw = 50; |
228 | TableLookups->setColumnWidth( 0, cw+30 ); | 228 | TableLookups->setColumnWidth( 0, cw+30 ); |
229 | TableLookups->setColumnWidth( 1, cw ); | 229 | TableLookups->setColumnWidth( 1, cw ); |
230 | TableLookups->setColumnWidth( 2, cw ); | 230 | TableLookups->setColumnWidth( 2, cw ); |
231 | TableLookups->sortColumn(0, false, true ); | 231 | TableLookups->sortColumn(0, false, true ); |
232 | // TableLookups->setSorting( true ); | 232 | // TableLookups->setSorting( true ); |
233 | _shiftPerSec = 0; | 233 | _shiftPerSec = 0; |
234 | for (int i=0; i < lookupCount; i++) | 234 | for (int i=0; i < lookupCount; i++) |
235 | { | 235 | { |
236 | cfg.setGroup("lookup_"+QString::number(i)); | 236 | cfg.setGroup("lookup_"+QString::number(i)); |
237 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 237 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
238 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 238 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
239 | shiftPerSec = shift / last; | 239 | shiftPerSec = shift / last; |
240 | qDebug("%i shift %f",i,shiftPerSec); | 240 | qDebug("%i shift %f",i,shiftPerSec); |
241 | _shiftPerSec += shiftPerSec; | 241 | _shiftPerSec += shiftPerSec; |
242 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); | 242 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); |
243 | TableLookups->setText( i,2,QString::number(shift)); | 243 | TableLookups->setText( i,2,QString::number(shift)); |
244 | TableLookups->setText( i,1,QString::number(last/(60*60))); | 244 | TableLookups->setText( i,1,QString::number(last/(60*60))); |
245 | } | 245 | } |
246 | _shiftPerSec /= lookupCount; | 246 | _shiftPerSec /= lookupCount; |
247 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); | 247 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); |
248 | } | 248 | } |
249 | 249 | ||
250 | void Ntp::preditctTime() | 250 | void Ntp::preditctTime() |
251 | { | 251 | { |
252 | Config cfg("ntp",Config::User); | 252 | Config cfg("ntp",Config::User); |
253 | cfg.setGroup("lookups"); | 253 | cfg.setGroup("lookups"); |
254 | int lastTime = cfg.readNumEntry("time",0); | 254 | int lastTime = cfg.readNumEntry("time",0); |
255 | cfg.writeEntry("lastNtp",true); | 255 | cfg.writeEntry("lastNtp",true); |
256 | setenv( "TZ", tz->currentZone(), 1 ); | 256 | setenv( "TZ", tz->currentZone(), 1 ); |
257 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 257 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
258 | int corr = int((now - lastTime) * _shiftPerSec); | 258 | int corr = int((now - lastTime) * _shiftPerSec); |
259 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 259 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
260 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 260 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
261 | TextLabelPredTime->setText(predictedTime.toString()); | 261 | TextLabelPredTime->setText(predictedTime.toString()); |
262 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 262 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
263 | } | 263 | } |
264 | 264 | ||
265 | void Ntp::setPredictTime() | 265 | void Ntp::setPredictTime() |
266 | { | 266 | { |
267 | preditctTime(); | 267 | preditctTime(); |
268 | setTime( predictedTime ); | 268 | setTime( predictedTime ); |
269 | } | 269 | } |
270 | 270 | ||
271 | void Ntp::slotCheckNtp(int i) | 271 | void Ntp::slotCheckNtp(int i) |
272 | { | 272 | { |
273 | if (i == 0) | 273 | if (i == 0) |
274 | { | 274 | { |
275 | TextLabelMainPredTime->hide(); | 275 | TextLabelMainPredTime->hide(); |
276 | ButtonSetTime->setText( tr("Get time from network") ); | 276 | ButtonSetTime->setText( tr("Get time from network") ); |
277 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 277 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
278 | if ( ntpDelayElapsed() ) | 278 | if ( ntpDelayElapsed() ) |
279 | { | 279 | { |
280 | slotRunNtp(); | 280 | slotRunNtp(); |
281 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 281 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
282 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 282 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); |
283 | }else{ | 283 | }else{ |
284 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 284 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); |
285 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 285 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
286 | } | 286 | } |
287 | }else{ | 287 | }else{ |
288 | preditctTime(); | 288 | preditctTime(); |
289 | ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); | 289 | ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); |
290 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 290 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
291 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 291 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
292 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 292 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
293 | } | 293 | } |
294 | } | 294 | } |
295 | 295 | ||
296 | void Ntp::slotProbeNtpServer() | 296 | void Ntp::slotProbeNtpServer() |
297 | { | 297 | { |
298 | ntpSock->connectToHost( getNtpServer() ,123); | 298 | ntpSock->connectToHost( getNtpServer() ,123); |
299 | } | 299 | } |
300 | 300 | ||
301 | void Ntp::slotNtpDelayChanged(int delay) | 301 | void Ntp::slotNtpDelayChanged(int delay) |
302 | { | 302 | { |
303 | ntpTimer->changeInterval( delay*1000*60 ); | 303 | ntpTimer->changeInterval( delay*1000*60 ); |
304 | } | 304 | } |
305 | 305 | ||
306 | void Ntp::ntpOutPut(QString out) | 306 | void Ntp::ntpOutPut(QString out) |
307 | { | 307 | { |
308 | MultiLineEditntpOutPut->append(out); | 308 | MultiLineEditntpOutPut->append(out); |
309 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 309 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
310 | } | 310 | } |
311 | 311 | ||
312 | 312 | ||
313 | void Ntp::makeChannel() | 313 | void Ntp::makeChannel() |
314 | { | 314 | { |
315 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); | 315 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); |
316 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 316 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
317 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 317 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | 321 | ||
322 | void Ntp::receive(const QCString &msg, const QByteArray &arg) | 322 | void Ntp::receive(const QCString &msg, const QByteArray &arg) |
323 | { | 323 | { |
324 | qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); | 324 | qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); |
325 | if ( msg == "ntpLookup(QString)" ) | 325 | if ( msg == "ntpLookup(QString)" ) |
326 | { | 326 | { |
327 | slotRunNtp(); | 327 | slotRunNtp(); |
328 | } | 328 | } |
329 | if ( msg == "setPredictedTime(QString)" ) | 329 | if ( msg == "setPredictedTime(QString)" ) |
330 | { | 330 | { |
331 | setPredictTime(); | 331 | setPredictTime(); |
332 | }else{ | 332 | }else{ |
333 | qDebug("Ntp::receive: Huh what do ya want"); | 333 | qDebug("Ntp::receive: Huh what do ya want"); |
334 | } | 334 | } |
335 | } | 335 | } |
336 | 336 | ||
337 | void Ntp::setDocument(const QString &fileName) | 337 | void Ntp::setDocument(const QString &fileName) |
338 | { | 338 | { |
339 | 339 | ||
340 | } | 340 | } |
341 | 341 | ||
342 | void Ntp::showAdvancedFeatures(bool advMode) | 342 | void Ntp::showAdvancedFeatures(bool advMode) |
343 | { | 343 | { |
344 | if (advMode) { | 344 | if (advMode) { |
345 | TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); | 345 | TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); |
346 | TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); | 346 | TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); |
347 | TextLabel1_2_2->show(); | 347 | TextLabel1_2_2->show(); |
348 | TextLabel2_3->show(); | 348 | TextLabel2_3->show(); |
349 | TextLabel3_3_2->show(); | 349 | TextLabel3_3_2->show(); |
350 | TextLabel1_2->show(); | 350 | TextLabel1_2->show(); |
351 | SpinBoxMinLookupDelay->show(); | 351 | SpinBoxMinLookupDelay->show(); |
352 | TextLabel2->show(); | 352 | TextLabel2->show(); |
353 | TextLabel3_3->show(); | 353 | TextLabel3_3->show(); |
354 | SpinBoxNtpDelay->show(); | 354 | SpinBoxNtpDelay->show(); |
355 | Line1->show(); | ||
355 | }else{ | 356 | }else{ |
356 | TabWidgetMain->removePage( tabPredict ); | 357 | TabWidgetMain->removePage( tabPredict ); |
357 | TabWidgetMain->removePage( tabNtp ); | 358 | TabWidgetMain->removePage( tabNtp ); |
358 | TextLabel1_2_2->hide(); | 359 | TextLabel1_2_2->hide(); |
359 | TextLabel2_3->hide(); | 360 | TextLabel2_3->hide(); |
360 | TextLabel3_3_2->hide(); | 361 | TextLabel3_3_2->hide(); |
361 | TextLabel1_2->hide(); | 362 | TextLabel1_2->hide(); |
362 | SpinBoxMinLookupDelay->hide(); | 363 | SpinBoxMinLookupDelay->hide(); |
363 | TextLabel2->hide(); | 364 | TextLabel2->hide(); |
364 | TextLabel3_3->hide(); | 365 | TextLabel3_3->hide(); |
365 | SpinBoxNtpDelay->hide(); | 366 | SpinBoxNtpDelay->hide(); |
367 | Line1->hide(); | ||
366 | }; | 368 | }; |
369 | TabWidgetMain->show(); | ||
367 | } | 370 | } |