author | tille <tille> | 2002-06-26 16:24:42 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-26 16:24:42 (UTC) |
commit | e9b05e2b93bf000777ae1c55e7d5cac35a67145d (patch) (unidiff) | |
tree | 11848aecc3f8ee23fd71d84cb7b821090bad19dc | |
parent | 97e2050f5880cb27d2cd028ed61eef1dc59d1ad1 (diff) | |
download | opie-e9b05e2b93bf000777ae1c55e7d5cac35a67145d.zip opie-e9b05e2b93bf000777ae1c55e7d5cac35a67145d.tar.gz opie-e9b05e2b93bf000777ae1c55e7d5cac35a67145d.tar.bz2 |
timer working
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 58 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 4 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.ui | 4 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/opie-netsystemtime.control | 2 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 2 |
5 files changed, 41 insertions, 29 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 364609d..bcbf7a1 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -1,272 +1,282 @@ | |||
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 <qmessagebox.h> | 10 | #include <qmessagebox.h> |
11 | #include <qmultilineedit.h> | 11 | #include <qmultilineedit.h> |
12 | #include <opie/oprocess.h> | 12 | #include <opie/oprocess.h> |
13 | #include <qpe/config.h> | 13 | #include <qpe/config.h> |
14 | #include <qpe/global.h> | 14 | #include <qpe/global.h> |
15 | #include <qpe/timeconversion.h> | 15 | #include <qpe/timeconversion.h> |
16 | #include <qpe/tzselect.h> | 16 | #include <qpe/tzselect.h> |
17 | #include <qpe/timestring.h> | 17 | #include <qpe/timestring.h> |
18 | #include <qpe/qpedialog.h> | 18 | #include <qpe/qpedialog.h> |
19 | #include <sys/time.h> | 19 | #include <sys/time.h> |
20 | #include <time.h> | 20 | #include <time.h> |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | 22 | ||
23 | 23 | ||
24 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 24 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
25 | : SetDateTime( parent, name, fl ) | 25 | : SetDateTime( parent, name, fl ) |
26 | { | 26 | { |
27 | 27 | ||
28 | Config ntpSrvs("/etc/ntpservers",Config::File); | 28 | Config ntpSrvs("/etc/ntpservers",Config::File); |
29 | ntpSrvs.setGroup("servers"); | 29 | ntpSrvs.setGroup("servers"); |
30 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); | 30 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); |
31 | for (int i = 0; i < srvCount; i++) | 31 | for (int i = 0; i < srvCount; i++) |
32 | { | 32 | { |
33 | ntpSrvs.setGroup(QString::number(i)); | 33 | ntpSrvs.setGroup(QString::number(i)); |
34 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); | 34 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); |
35 | } | 35 | } |
36 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); | 36 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); |
37 | 37 | ||
38 | Config cfg("ntp",Config::User); | 38 | Config cfg("ntp",Config::User); |
39 | cfg.setGroup("settings"); | 39 | cfg.setGroup("settings"); |
40 | // _maxOffset = cfg.readNumEntry("maxOffset",5); | 40 | // _maxOffset = cfg.readNumEntry("maxOffset",5); |
41 | // _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); | 41 | // _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); |
42 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); | 42 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); |
43 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); | 43 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); |
44 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); | 44 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); |
45 | 45 | ||
46 | ntpTimer = new QTimer(this); | 46 | ntpTimer = new QTimer(this); |
47 | ntpTimer->start(SpinBoxNtpDelay->value()*100); | 47 | ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); |
48 | 48 | ||
49 | ntpProcess = new OProcess( ); | 49 | ntpProcess = new OProcess( ); |
50 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 50 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
51 | SLOT(slotNtpDelayChanged(int)) ); | 51 | SLOT(slotNtpDelayChanged(int)) ); |
52 | 52 | ||
53 | ntpSock = new QSocket( this ); | 53 | ntpSock = new QSocket( this ); |
54 | connect( ntpSock, SIGNAL( error(int) ), | 54 | connect( ntpSock, SIGNAL( error(int) ), |
55 | SLOT(slotCheckNtp(int)) ); | 55 | SLOT(slotCheckNtp(int)) ); |
56 | slotProbeNtpServer(); | 56 | slotProbeNtpServer(); |
57 | 57 | ||
58 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 58 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
59 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 59 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
60 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 60 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
61 | this, SLOT(ntpFinished(OProcess*))); | 61 | this, SLOT(ntpFinished(OProcess*))); |
62 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 62 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
63 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 63 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
64 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 64 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
65 | slotCheckNtp(-1); | 65 | slotCheckNtp(-1); |
66 | readLookups(); | 66 | readLookups(); |
67 | } | 67 | } |
68 | 68 | ||
69 | Ntp::~Ntp() | 69 | Ntp::~Ntp() |
70 | { | 70 | { |
71 | delete ntpProcess; | 71 | delete ntpProcess; |
72 | Config ntpSrvs("/etc/ntpservers",Config::File); | 72 | Config ntpSrvs("/etc/ntpservers",Config::File); |
73 | ntpSrvs.setGroup("servers"); | 73 | ntpSrvs.setGroup("servers"); |
74 | int srvCount = ComboNtpSrv->count(); | 74 | int srvCount = ComboNtpSrv->count(); |
75 | ntpSrvs.writeEntry("count", srvCount); | 75 | ntpSrvs.writeEntry("count", srvCount); |
76 | for (int i = 0; i < srvCount; i++) | 76 | for (int i = 0; i < srvCount; i++) |
77 | { | 77 | { |
78 | ntpSrvs.setGroup(QString::number(i)); | 78 | ntpSrvs.setGroup(QString::number(i)); |
79 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | 79 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); |
80 | } | 80 | } |
81 | Config cfg("ntp",Config::User); | 81 | Config cfg("ntp",Config::User); |
82 | cfg.setGroup("settings"); | 82 | cfg.setGroup("settings"); |
83 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); | 83 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); |
84 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 84 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
85 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 85 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | bool Ntp::ntpDelayElapsed() | |
89 | void Ntp::slotRunNtp() | ||
90 | { | 89 | { |
91 | Config cfg("ntp",Config::User); | 90 | Config cfg("ntp",Config::User); |
92 | cfg.setGroup("lookups"); | 91 | cfg.setGroup("lookups"); |
93 | int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | 92 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); |
93 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; | ||
94 | } | ||
94 | 95 | ||
95 | if ( lookupDiff < SpinBoxNtpDelay->value()*60 ) | 96 | QString Ntp::getNtpServer() |
97 | { | ||
98 | return ComboNtpSrv->currentText(); | ||
99 | } | ||
100 | |||
101 | void Ntp::slotRunNtp() | ||
102 | { | ||
103 | if ( !ntpDelayElapsed() ) | ||
96 | { | 104 | { |
97 | switch ( | 105 | switch ( |
98 | QMessageBox::warning(this, tr("Run ntp?"), | 106 | QMessageBox::warning(this, tr("Run NTP?"), |
99 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 107 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
100 | QString::number(lookupDiff%60)+tr(" minutes elapsed since last loopup.")+ | 108 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ |
101 | "<br>"+tr("Rerun ntp?"), | 109 | "<br>"+tr("Rerun NTP?"), |
102 | QMessageBox::Ok,QMessageBox::Cancel) | 110 | QMessageBox::Ok,QMessageBox::Cancel) |
103 | ) { | 111 | ) { |
104 | case QMessageBox::Ok: break; | 112 | case QMessageBox::Ok: break; |
105 | case QMessageBox::Cancel: return; | 113 | case QMessageBox::Cancel: return; |
106 | default: return; | 114 | default: return; |
107 | } | 115 | } |
108 | } | 116 | } |
109 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 117 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
110 | MultiLineEditntpOutPut->append( "\n"+tr("Running:")+"\nntpdate "+ ComboNtpSrv->currentText()+"\n"); | 118 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
111 | ntpProcess->clearArguments(); | 119 | ntpProcess->clearArguments(); |
112 | *ntpProcess << "ntpdate" << ComboNtpSrv->currentText(); | 120 | *ntpProcess << "ntpdate" << getNtpServer(); |
113 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 121 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
114 | if ( !ret ) { | 122 | if ( !ret ) { |
115 | qDebug("Error while executing ntp"); | 123 | qDebug("Error while executing ntpdate"); |
124 | ntpOutPut( tr("Error while executing ntpdate")); | ||
116 | } | 125 | } |
117 | } | 126 | } |
118 | 127 | ||
119 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 128 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
120 | { | 129 | { |
121 | QString lineStr, lineStrOld; | 130 | QString lineStr, lineStrOld; |
122 | lineStr = buffer; | 131 | lineStr = buffer; |
123 | lineStr=lineStr.left(buflen); | 132 | lineStr=lineStr.left(buflen); |
124 | if (lineStr!=lineStrOld) | 133 | if (lineStr!=lineStrOld) |
125 | { | 134 | { |
126 | MultiLineEditntpOutPut->append(lineStr); | 135 | ntpOutPut(lineStr); |
127 | _ntpOutput += lineStr; | 136 | _ntpOutput += lineStr; |
128 | } | 137 | } |
129 | lineStrOld = lineStr; | 138 | lineStrOld = lineStr; |
130 | } | 139 | } |
131 | 140 | ||
132 | void Ntp::ntpFinished(OProcess*) | 141 | void Ntp::ntpFinished(OProcess*) |
133 | { | 142 | { |
134 | Config cfg("ntp",Config::User); | 143 | Config cfg("ntp",Config::User); |
135 | cfg.setGroup("lookups"); | 144 | cfg.setGroup("lookups"); |
136 | int lastLookup = cfg.readNumEntry("time",0); | 145 | int lastLookup = cfg.readNumEntry("time",0); |
137 | int lookupCount = cfg.readNumEntry("count",-1); | 146 | int lookupCount = cfg.readNumEntry("count",-1); |
138 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 147 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
139 | cfg.writeEntry("time", time); | 148 | cfg.writeEntry("time", time); |
140 | cfg.setGroup("correction"); | 149 | cfg.setGroup("correction"); |
141 | cfg.writeEntry("time", time); | 150 | cfg.writeEntry("time", time); |
142 | 151 | ||
143 | float timeShift = getTimeShift(); | 152 | float timeShift = getTimeShift(); |
144 | if (timeShift == 0.0) return; | 153 | if (timeShift == 0.0) return; |
145 | int secsSinceLast = time - lastLookup; | 154 | int secsSinceLast = time - lastLookup; |
146 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 155 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
147 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); | 156 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); |
148 | if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) | 157 | if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) |
149 | { | 158 | { |
150 | lookupCount++; | 159 | lookupCount++; |
151 | cfg.writeEntry("count",lookupCount); | 160 | cfg.writeEntry("count",lookupCount); |
152 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | 161 | cfg.setGroup("lookup_"+QString::number(lookupCount)); |
153 | _shiftPerSec = timeShift / secsSinceLast; | 162 | _shiftPerSec = timeShift / secsSinceLast; |
154 | // float nextCorr = _maxOffset / _shiftPerSec; | ||
155 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); | 163 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); |
156 | cfg.writeEntry("secsSinceLast",secsSinceLast); | 164 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
157 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 165 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
158 | } | 166 | } |
159 | } | 167 | } |
160 | 168 | ||
161 | 169 | ||
162 | float Ntp::getTimeShift() | 170 | float Ntp::getTimeShift() |
163 | { | 171 | { |
164 | QString _offset = "offset"; | 172 | QString _offset = "offset"; |
165 | QString _sec = "sec"; | 173 | QString _sec = "sec"; |
166 | QRegExp _reOffset = QRegExp(_offset); | 174 | QRegExp _reOffset = QRegExp(_offset); |
167 | QRegExp _reEndOffset = QRegExp(_sec); | 175 | QRegExp _reEndOffset = QRegExp(_sec); |
168 | int posOffset = _reOffset.match( _ntpOutput ); | 176 | int posOffset = _reOffset.match( _ntpOutput ); |
169 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); | 177 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); |
170 | posOffset += _offset.length() + 1; | 178 | posOffset += _offset.length() + 1; |
171 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); | 179 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); |
172 | qDebug("%s", _ntpOutput.latin1()); | 180 | qDebug("%s", _ntpOutput.latin1()); |
173 | qDebug("diff = >%s<",diff.latin1()); | 181 | qDebug("diff = >%s<",diff.latin1()); |
174 | return diff.toFloat(); | 182 | return diff.toFloat(); |
175 | } | 183 | } |
176 | 184 | ||
177 | void Ntp::readLookups() | 185 | void Ntp::readLookups() |
178 | { | 186 | { |
179 | Config cfg("ntp",Config::User); | 187 | Config cfg("ntp",Config::User); |
180 | cfg.setGroup("lookups"); | 188 | cfg.setGroup("lookups"); |
181 | int lookupCount = cfg.readNumEntry("count",-1); | 189 | int lookupCount = cfg.readNumEntry("count",-1); |
182 | float last, shift, shiftPerSec; | 190 | float last, shift, shiftPerSec; |
183 | qDebug("lookupCount = %i",lookupCount); | 191 | qDebug("lookupCount = %i",lookupCount); |
184 | TableLookups->setNumCols( 3 ); | 192 | TableLookups->setNumCols( 3 ); |
185 | TableLookups->setNumRows( lookupCount); | 193 | TableLookups->setNumRows( lookupCount); |
186 | TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); | 194 | TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); |
187 | TableLookups->horizontalHeader()->setLabel(2,"timeShift"); | 195 | TableLookups->horizontalHeader()->setLabel(2,"timeShift"); |
188 | TableLookups->horizontalHeader()->setLabel(0,"shift/s"); | 196 | TableLookups->horizontalHeader()->setLabel(0,"shift/s"); |
189 | int cw = 50;//TableLookups->width()/4; | 197 | int cw = 50;//TableLookups->width()/4; |
190 | qDebug("column width %i",cw); | 198 | qDebug("column width %i",cw); |
191 | TableLookups->setColumnWidth( 0, cw+30 ); | 199 | TableLookups->setColumnWidth( 0, cw+30 ); |
192 | TableLookups->setColumnWidth( 1, cw ); | 200 | TableLookups->setColumnWidth( 1, cw ); |
193 | TableLookups->setColumnWidth( 2, cw ); | 201 | TableLookups->setColumnWidth( 2, cw ); |
194 | TableLookups->sortColumn(0, false, true ); | 202 | TableLookups->sortColumn(0, false, true ); |
195 | // TableLookups->setSorting( true ); | 203 | // TableLookups->setSorting( true ); |
196 | for (int i=0; i < lookupCount; i++) | 204 | for (int i=0; i < lookupCount; i++) |
197 | { | 205 | { |
198 | cfg.setGroup("lookup_"+QString::number(i)); | 206 | cfg.setGroup("lookup_"+QString::number(i)); |
199 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 207 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
200 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 208 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
201 | // qDebug("%i last %f",i,last); | 209 | // qDebug("%i last %f",i,last); |
202 | // qDebug("%i shift %f",i,shift); | 210 | // qDebug("%i shift %f",i,shift); |
203 | shiftPerSec = shift / last; | 211 | shiftPerSec = shift / last; |
204 | _shiftPerSec += shiftPerSec; | 212 | _shiftPerSec += shiftPerSec; |
205 | TableLookups->setText( i,0,QString::number(shiftPerSec)); | 213 | TableLookups->setText( i,0,QString::number(shiftPerSec)); |
206 | TableLookups->setText( i,2,QString::number(shift)); | 214 | TableLookups->setText( i,2,QString::number(shift)); |
207 | TableLookups->setText( i,1,QString::number(last)); | 215 | TableLookups->setText( i,1,QString::number(last)); |
208 | } | 216 | } |
209 | _shiftPerSec /= lookupCount+1; | 217 | _shiftPerSec /= lookupCount+1; |
210 | TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); | 218 | TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); |
211 | } | 219 | } |
212 | 220 | ||
213 | void Ntp::preditctTime() | 221 | void Ntp::preditctTime() |
214 | { | 222 | { |
215 | qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1()); | ||
216 | Config cfg("ntp",Config::User); | 223 | Config cfg("ntp",Config::User); |
217 | cfg.setGroup("lookups"); | 224 | cfg.setGroup("lookups"); |
218 | int lastTime = cfg.readNumEntry("time",0); | 225 | int lastTime = cfg.readNumEntry("time",0); |
219 | setenv( "TZ", tz->currentZone(), 1 ); | 226 | setenv( "TZ", tz->currentZone(), 1 ); |
220 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 227 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
221 | int corr = int((now - lastTime) * _shiftPerSec); | 228 | int corr = int((now - lastTime) * _shiftPerSec); |
222 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 229 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
223 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 230 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
224 | TextLabelPredTime->setText(predictedTime.toString()); | 231 | TextLabelPredTime->setText(predictedTime.toString()); |
225 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 232 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
226 | } | 233 | } |
227 | 234 | ||
228 | void Ntp::setPredictTime() | 235 | void Ntp::setPredictTime() |
229 | { | 236 | { |
230 | preditctTime(); | 237 | preditctTime(); |
231 | setTime( predictedTime ); | 238 | setTime( predictedTime ); |
232 | } | 239 | } |
233 | 240 | ||
234 | void Ntp::slotCheckNtp(int i) | 241 | void Ntp::slotCheckNtp(int i) |
235 | { | 242 | { |
236 | if (i == 0) | 243 | if (i == 0) |
237 | { | 244 | { |
238 | TextLabelMainPredTime->hide(); | 245 | TextLabelMainPredTime->hide(); |
239 | ButtonSetTime->setText( tr("Get time from network") ); | 246 | ButtonSetTime->setText( tr("Get time from network") ); |
240 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 247 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
241 | Config cfg("ntp",Config::User); | 248 | if ( ntpDelayElapsed() ) |
242 | cfg.setGroup("lookups"); | ||
243 | int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | ||
244 | if ( lookupDiff > SpinBoxNtpDelay->value()*60 ) | ||
245 | { | 249 | { |
250 | slotRunNtp(); | ||
246 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 251 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
247 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 252 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); |
248 | }else{ | 253 | }else{ |
249 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 254 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); |
250 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 255 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
251 | } | 256 | } |
252 | }else{ | 257 | }else{ |
253 | preditctTime(); | 258 | preditctTime(); |
254 | ButtonSetTime->setText( tr("Set predicted time") ); | 259 | ButtonSetTime->setText( tr("Set predicted time") ); |
260 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | ||
255 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 261 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
256 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 262 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
257 | } | 263 | } |
264 | //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); | ||
258 | } | 265 | } |
259 | 266 | ||
260 | void Ntp::slotProbeNtpServer() | 267 | void Ntp::slotProbeNtpServer() |
261 | { | 268 | { |
262 | Config cfg("ntp",Config::User); | 269 | if ( ntpDelayElapsed() ) |
263 | cfg.setGroup("lookups"); | 270 | ntpSock->connectToHost( getNtpServer() ,123); |
264 | int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | ||
265 | if ( lookupDiff > SpinBoxNtpDelay->value()*60 ) | ||
266 | ntpSock->connectToHost( ComboNtpSrv->currentText() ,123); | ||
267 | } | 271 | } |
268 | 272 | ||
269 | void Ntp::slotNtpDelayChanged(int delay) | 273 | void Ntp::slotNtpDelayChanged(int delay) |
270 | { | 274 | { |
271 | ntpTimer->changeInterval( delay*100 ); | 275 | ntpTimer->changeInterval( delay*1000*60 ); |
276 | } | ||
277 | |||
278 | void Ntp::ntpOutPut(QString out) | ||
279 | { | ||
280 | MultiLineEditntpOutPut->append(out); | ||
281 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | ||
272 | } | 282 | } |
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index 7cc309f..c78dc55 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h | |||
@@ -1,43 +1,47 @@ | |||
1 | #ifndef NTP_H | 1 | #ifndef NTP_H |
2 | #define NTP_H | 2 | #define NTP_H |
3 | #include "settime.h" | 3 | #include "settime.h" |
4 | #include <qdatetime.h> | 4 | #include <qdatetime.h> |
5 | 5 | ||
6 | class OProcess; | 6 | class OProcess; |
7 | class QString; | 7 | class QString; |
8 | class QTimer; | 8 | class QTimer; |
9 | class QSocket; | 9 | class QSocket; |
10 | 10 | ||
11 | class Ntp : public SetDateTime | 11 | class Ntp : public SetDateTime |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 16 | Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
17 | ~Ntp(); | 17 | ~Ntp(); |
18 | 18 | ||
19 | protected: | 19 | protected: |
20 | QDateTime predictedTime; | 20 | QDateTime predictedTime; |
21 | 21 | ||
22 | 22 | ||
23 | private: | 23 | private: |
24 | QString _ntpOutput; | 24 | QString _ntpOutput; |
25 | float _shiftPerSec; | 25 | float _shiftPerSec; |
26 | int _lookupDiff; | ||
26 | OProcess *ntpProcess; | 27 | OProcess *ntpProcess; |
27 | QTimer *ntpTimer; | 28 | QTimer *ntpTimer; |
28 | QSocket *ntpSock; | 29 | QSocket *ntpSock; |
29 | 30 | ||
30 | float getTimeShift(); | 31 | float getTimeShift(); |
31 | void readLookups(); | 32 | void readLookups(); |
33 | void ntpOutPut(QString); | ||
34 | bool ntpDelayElapsed(); | ||
35 | QString getNtpServer(); | ||
32 | private slots: | 36 | private slots: |
33 | void slotRunNtp(); | 37 | void slotRunNtp(); |
34 | void getNtpOutput(OProcess *proc, char *buffer, int buflen); | 38 | void getNtpOutput(OProcess *proc, char *buffer, int buflen); |
35 | void ntpFinished(OProcess*); | 39 | void ntpFinished(OProcess*); |
36 | void preditctTime(); | 40 | void preditctTime(); |
37 | void slotCheckNtp(int); | 41 | void slotCheckNtp(int); |
38 | void setPredictTime(); | 42 | void setPredictTime(); |
39 | void slotProbeNtpServer(); | 43 | void slotProbeNtpServer(); |
40 | void slotNtpDelayChanged(int); | 44 | void slotNtpDelayChanged(int); |
41 | }; | 45 | }; |
42 | 46 | ||
43 | #endif | 47 | #endif |
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui index 4e10fd2..a83dc93 100644 --- a/noncore/settings/netsystemtime/ntpbase.ui +++ b/noncore/settings/netsystemtime/ntpbase.ui | |||
@@ -1,143 +1,143 @@ | |||
1 | <!DOCTYPE UI><UI> | 1 | <!DOCTYPE UI><UI> |
2 | <class>NtpBase</class> | 2 | <class>NtpBase</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>NtpBase</cstring> | 7 | <cstring>NtpBase</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>331</width> | 14 | <width>328</width> |
15 | <height>426</height> | 15 | <height>411</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>caption</name> | 19 | <name>caption</name> |
20 | <string>Network Time</string> | 20 | <string>Network Time</string> |
21 | </property> | 21 | </property> |
22 | <property> | 22 | <property> |
23 | <name>layoutMargin</name> | 23 | <name>layoutMargin</name> |
24 | </property> | 24 | </property> |
25 | <property> | 25 | <property> |
26 | <name>layoutSpacing</name> | 26 | <name>layoutSpacing</name> |
27 | </property> | 27 | </property> |
28 | <grid> | 28 | <grid> |
29 | <property stdset="1"> | 29 | <property stdset="1"> |
30 | <name>margin</name> | 30 | <name>margin</name> |
31 | <number>2</number> | 31 | <number>2</number> |
32 | </property> | 32 | </property> |
33 | <property stdset="1"> | 33 | <property stdset="1"> |
34 | <name>spacing</name> | 34 | <name>spacing</name> |
35 | <number>2</number> | 35 | <number>2</number> |
36 | </property> | 36 | </property> |
37 | <widget row="0" column="0" > | 37 | <widget row="0" column="0" > |
38 | <class>QTabWidget</class> | 38 | <class>QTabWidget</class> |
39 | <property stdset="1"> | 39 | <property stdset="1"> |
40 | <name>name</name> | 40 | <name>name</name> |
41 | <cstring>TabWidgetMain</cstring> | 41 | <cstring>TabWidgetMain</cstring> |
42 | </property> | 42 | </property> |
43 | <property> | 43 | <property> |
44 | <name>layoutMargin</name> | 44 | <name>layoutMargin</name> |
45 | </property> | 45 | </property> |
46 | <property> | 46 | <property> |
47 | <name>layoutSpacing</name> | 47 | <name>layoutSpacing</name> |
48 | </property> | 48 | </property> |
49 | <widget> | 49 | <widget> |
50 | <class>QWidget</class> | 50 | <class>QWidget</class> |
51 | <property stdset="1"> | 51 | <property stdset="1"> |
52 | <name>name</name> | 52 | <name>name</name> |
53 | <cstring>tabMain</cstring> | 53 | <cstring>tabMain</cstring> |
54 | </property> | 54 | </property> |
55 | <attribute> | 55 | <attribute> |
56 | <name>title</name> | 56 | <name>title</name> |
57 | <string>Main</string> | 57 | <string>Main</string> |
58 | </attribute> | 58 | </attribute> |
59 | <grid> | 59 | <grid> |
60 | <property stdset="1"> | 60 | <property stdset="1"> |
61 | <name>margin</name> | 61 | <name>margin</name> |
62 | <number>2</number> | 62 | <number>2</number> |
63 | </property> | 63 | </property> |
64 | <property stdset="1"> | 64 | <property stdset="1"> |
65 | <name>spacing</name> | 65 | <name>spacing</name> |
66 | <number>2</number> | 66 | <number>2</number> |
67 | </property> | 67 | </property> |
68 | <widget row="0" column="0" > | 68 | <widget row="0" column="0" > |
69 | <class>QFrame</class> | 69 | <class>QFrame</class> |
70 | <property stdset="1"> | 70 | <property stdset="1"> |
71 | <name>name</name> | 71 | <name>name</name> |
72 | <cstring>FrameSystemTime</cstring> | 72 | <cstring>FrameSystemTime</cstring> |
73 | </property> | 73 | </property> |
74 | <property stdset="1"> | 74 | <property stdset="1"> |
75 | <name>frameShape</name> | 75 | <name>frameShape</name> |
76 | <enum>StyledPanel</enum> | 76 | <enum>StyledPanel</enum> |
77 | </property> | 77 | </property> |
78 | <property stdset="1"> | 78 | <property stdset="1"> |
79 | <name>frameShadow</name> | 79 | <name>frameShadow</name> |
80 | <enum>Raised</enum> | 80 | <enum>Raised</enum> |
81 | </property> | 81 | </property> |
82 | </widget> | 82 | </widget> |
83 | </grid> | 83 | </grid> |
84 | </widget> | 84 | </widget> |
85 | <widget> | 85 | <widget> |
86 | <class>QWidget</class> | 86 | <class>QWidget</class> |
87 | <property stdset="1"> | 87 | <property stdset="1"> |
88 | <name>name</name> | 88 | <name>name</name> |
89 | <cstring>tabNtp</cstring> | 89 | <cstring>tabNtp</cstring> |
90 | </property> | 90 | </property> |
91 | <attribute> | 91 | <attribute> |
92 | <name>title</name> | 92 | <name>title</name> |
93 | <string>NTP</string> | 93 | <string>NTP</string> |
94 | </attribute> | 94 | </attribute> |
95 | <grid> | 95 | <grid> |
96 | <property stdset="1"> | 96 | <property stdset="1"> |
97 | <name>margin</name> | 97 | <name>margin</name> |
98 | <number>1</number> | 98 | <number>1</number> |
99 | </property> | 99 | </property> |
100 | <property stdset="1"> | 100 | <property stdset="1"> |
101 | <name>spacing</name> | 101 | <name>spacing</name> |
102 | <number>2</number> | 102 | <number>2</number> |
103 | </property> | 103 | </property> |
104 | <widget row="1" column="0" > | 104 | <widget row="1" column="0" > |
105 | <class>QPushButton</class> | 105 | <class>QPushButton</class> |
106 | <property stdset="1"> | 106 | <property stdset="1"> |
107 | <name>name</name> | 107 | <name>name</name> |
108 | <cstring>runNtp</cstring> | 108 | <cstring>runNtp</cstring> |
109 | </property> | 109 | </property> |
110 | <property stdset="1"> | 110 | <property stdset="1"> |
111 | <name>text</name> | 111 | <name>text</name> |
112 | <string>Get time from network</string> | 112 | <string>Get time from network</string> |
113 | </property> | 113 | </property> |
114 | </widget> | 114 | </widget> |
115 | <widget row="0" column="0" > | 115 | <widget row="0" column="0" > |
116 | <class>QFrame</class> | 116 | <class>QFrame</class> |
117 | <property stdset="1"> | 117 | <property stdset="1"> |
118 | <name>name</name> | 118 | <name>name</name> |
119 | <cstring>FrameNtp</cstring> | 119 | <cstring>FrameNtp</cstring> |
120 | </property> | 120 | </property> |
121 | <property stdset="1"> | 121 | <property stdset="1"> |
122 | <name>frameShape</name> | 122 | <name>frameShape</name> |
123 | <enum>StyledPanel</enum> | 123 | <enum>StyledPanel</enum> |
124 | </property> | 124 | </property> |
125 | <property stdset="1"> | 125 | <property stdset="1"> |
126 | <name>frameShadow</name> | 126 | <name>frameShadow</name> |
127 | <enum>Raised</enum> | 127 | <enum>Raised</enum> |
128 | </property> | 128 | </property> |
129 | <property> | 129 | <property> |
130 | <name>layoutMargin</name> | 130 | <name>layoutMargin</name> |
131 | </property> | 131 | </property> |
132 | <property> | 132 | <property> |
133 | <name>layoutSpacing</name> | 133 | <name>layoutSpacing</name> |
134 | </property> | 134 | </property> |
135 | <grid> | 135 | <grid> |
136 | <property stdset="1"> | 136 | <property stdset="1"> |
137 | <name>margin</name> | 137 | <name>margin</name> |
138 | <number>2</number> | 138 | <number>2</number> |
139 | </property> | 139 | </property> |
140 | <property stdset="1"> | 140 | <property stdset="1"> |
141 | <name>spacing</name> | 141 | <name>spacing</name> |
142 | <number>2</number> | 142 | <number>2</number> |
143 | </property> | 143 | </property> |
diff --git a/noncore/settings/netsystemtime/opie-netsystemtime.control b/noncore/settings/netsystemtime/opie-netsystemtime.control index 406d7b0..d3290e9 100644 --- a/noncore/settings/netsystemtime/opie-netsystemtime.control +++ b/noncore/settings/netsystemtime/opie-netsystemtime.control | |||
@@ -1,11 +1,11 @@ | |||
1 | Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop | 1 | Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop etc/ntpservers |
2 | Priority: optional | 2 | Priority: optional |
3 | Section: opie/settings | 3 | Section: opie/settings |
4 | Depends: ntpdate | 4 | Depends: ntpdate |
5 | Conflicts: opie-systemtime | 5 | Conflicts: opie-systemtime |
6 | Maintainer: Patrick S. Vogt <tille@handhelds.org> | 6 | Maintainer: Patrick S. Vogt <tille@handhelds.org> |
7 | Architecture: arm | 7 | Architecture: arm |
8 | Version: $QPE_VERSION-$SUB_VERSION | 8 | Version: $QPE_VERSION-$SUB_VERSION |
9 | Depends: opie-base ($QPE_VERSION), ntpdate | 9 | Depends: opie-base ($QPE_VERSION), ntpdate |
10 | Description: ntp ( Network Time Protocol) gui | 10 | Description: ntp ( Network Time Protocol) gui |
11 | This utility syncs system time with a atomic timerserver via internet | 11 | This utility syncs system time with a atomic timerserver via internet |
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp index 2398c08..93543cd 100644 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/noncore/settings/netsystemtime/settime.cpp | |||
@@ -175,315 +175,313 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) | |||
175 | hb4->addWidget( l, 1 ); | 175 | hb4->addWidget( l, 1 ); |
176 | 176 | ||
177 | clockAppletCombo = new QComboBox( FrameSystemTime ); | 177 | clockAppletCombo = new QComboBox( FrameSystemTime ); |
178 | clockAppletCombo->insertItem( tr("hh:mm"), 0 ); | 178 | clockAppletCombo->insertItem( tr("hh:mm"), 0 ); |
179 | clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); | 179 | clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); |
180 | clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); | 180 | clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); |
181 | 181 | ||
182 | hb4->addWidget( clockAppletCombo, 2 ); | 182 | hb4->addWidget( clockAppletCombo, 2 ); |
183 | int clockApplet = config.readNumEntry("ClockApplet",0); | 183 | int clockApplet = config.readNumEntry("ClockApplet",0); |
184 | clockAppletCombo->setCurrentItem( clockApplet ); | 184 | clockAppletCombo->setCurrentItem( clockApplet ); |
185 | 185 | ||
186 | vb->addStretch( 0 ); | 186 | vb->addStretch( 0 ); |
187 | 187 | ||
188 | QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()), | 188 | QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()), |
189 | this, SLOT(commitTime())); | 189 | this, SLOT(commitTime())); |
190 | 190 | ||
191 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), | 191 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), |
192 | timeButton, SLOT( slotTzChange( const QString& ) ) ); | 192 | timeButton, SLOT( slotTzChange( const QString& ) ) ); |
193 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), | 193 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), |
194 | SLOT( tzChange( const QString& ) ) ); | 194 | SLOT( tzChange( const QString& ) ) ); |
195 | 195 | ||
196 | QObject::connect( weekStartCombo, SIGNAL( activated ( int )), | 196 | QObject::connect( weekStartCombo, SIGNAL( activated ( int )), |
197 | SLOT(updateSystem(int ) )); | 197 | SLOT(updateSystem(int ) )); |
198 | QObject::connect( ampmCombo, SIGNAL( activated ( int )), | 198 | QObject::connect( ampmCombo, SIGNAL( activated ( int )), |
199 | SLOT(updateSystem(int ) )); | 199 | SLOT(updateSystem(int ) )); |
200 | QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), | 200 | QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), |
201 | SLOT(updateSystem(int ) )); | 201 | SLOT(updateSystem(int ) )); |
202 | QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), | 202 | QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), |
203 | SLOT(updateSystem(int ) )); | 203 | SLOT(updateSystem(int ) )); |
204 | } | 204 | } |
205 | 205 | ||
206 | SetDateTime::~SetDateTime() | 206 | SetDateTime::~SetDateTime() |
207 | { | 207 | { |
208 | writeSettings(); | 208 | writeSettings(); |
209 | 209 | ||
210 | } | 210 | } |
211 | 211 | ||
212 | void SetDateTime::writeSettings() | 212 | void SetDateTime::writeSettings() |
213 | { | 213 | { |
214 | Config config("qpe"); | 214 | Config config("qpe"); |
215 | config.setGroup( "Time" ); | 215 | config.setGroup( "Time" ); |
216 | config.writeEntry( "AMPM", ampmCombo->currentItem() ); | 216 | config.writeEntry( "AMPM", ampmCombo->currentItem() ); |
217 | config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); | 217 | config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); |
218 | config.setGroup( "Date" ); | 218 | config.setGroup( "Date" ); |
219 | DateFormat df = date_formats[dateFormatCombo->currentItem()]; | 219 | DateFormat df = date_formats[dateFormatCombo->currentItem()]; |
220 | config.writeEntry( "Separator", QString(df.separator())); | 220 | config.writeEntry( "Separator", QString(df.separator())); |
221 | config.writeEntry( "ShortOrder", df.shortOrder()); | 221 | config.writeEntry( "ShortOrder", df.shortOrder()); |
222 | config.writeEntry( "LongOrder", df.longOrder()); | 222 | config.writeEntry( "LongOrder", df.longOrder()); |
223 | config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() ); | 223 | config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() ); |
224 | 224 | ||
225 | Config lconfig("locale"); | 225 | Config lconfig("locale"); |
226 | lconfig.setGroup( "Location" ); | 226 | lconfig.setGroup( "Location" ); |
227 | lconfig.writeEntry( "Timezone", tz->currentZone() ); | 227 | lconfig.writeEntry( "Timezone", tz->currentZone() ); |
228 | 228 | ||
229 | } | 229 | } |
230 | 230 | ||
231 | void SetDateTime::commitTime() | 231 | void SetDateTime::commitTime() |
232 | { | 232 | { |
233 | tz->setFocus(); | 233 | tz->setFocus(); |
234 | // really turn off the screensaver before doing anything | 234 | // really turn off the screensaver before doing anything |
235 | { | 235 | { |
236 | // Needs to be encased in { } so that it deconstructs and sends | 236 | // Needs to be encased in { } so that it deconstructs and sends |
237 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 237 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
238 | disableScreenSaver << 0 << 0 << 0; | 238 | disableScreenSaver << 0 << 0 << 0; |
239 | } | 239 | } |
240 | // Need to process the QCOP event generated above before proceeding | 240 | // Need to process the QCOP event generated above before proceeding |
241 | qApp->processEvents(); | 241 | qApp->processEvents(); |
242 | 242 | ||
243 | // before we progress further, set our TZ! | 243 | // before we progress further, set our TZ! |
244 | setenv( "TZ", tz->currentZone(), 1 ); | 244 | setenv( "TZ", tz->currentZone(), 1 ); |
245 | // now set the time... | 245 | // now set the time... |
246 | QDateTime dt( dateButton->date(), timeButton->time() ); | 246 | QDateTime dt( dateButton->date(), timeButton->time() ); |
247 | 247 | ||
248 | if ( dt.isValid() ) setTime(dt); | 248 | if ( dt.isValid() ) setTime(dt); |
249 | } | 249 | } |
250 | 250 | ||
251 | void SetDateTime::setTime(QDateTime dt) | 251 | void SetDateTime::setTime(QDateTime dt) |
252 | { | 252 | { |
253 | Config cfg("ntp",Config::User); | 253 | Config cfg("ntp",Config::User); |
254 | cfg.setGroup("correction"); | 254 | cfg.setGroup("correction"); |
255 | int t = TimeConversion::toUTC(dt); | 255 | int t = TimeConversion::toUTC(dt); |
256 | struct timeval myTv; | 256 | struct timeval myTv; |
257 | myTv.tv_sec = t; | 257 | myTv.tv_sec = t; |
258 | cfg.writeEntry("time", t ); | 258 | cfg.writeEntry("time", t ); |
259 | myTv.tv_usec = 0; | 259 | myTv.tv_usec = 0; |
260 | 260 | ||
261 | if ( myTv.tv_sec != -1 ) | 261 | if ( myTv.tv_sec != -1 ) |
262 | ::settimeofday( &myTv, 0 ); | 262 | ::settimeofday( &myTv, 0 ); |
263 | Global::writeHWClock(); | 263 | Global::writeHWClock(); |
264 | // since time has changed quickly load in the datebookdb | 264 | // since time has changed quickly load in the datebookdb |
265 | // to allow the alarm server to get a better grip on itself | 265 | // to allow the alarm server to get a better grip on itself |
266 | // (example re-trigger alarms for when we travel back in time) | 266 | // (example re-trigger alarms for when we travel back in time) |
267 | DateBookDB db; | 267 | DateBookDB db; |
268 | } | 268 | } |
269 | 269 | ||
270 | void SetDateTime::updateSystem(int i) | 270 | void SetDateTime::updateSystem(int i) |
271 | { | 271 | { |
272 | qDebug("SetDateTime::updateSystem(int %i)",i); | 272 | qDebug("SetDateTime::updateSystem(int %i)",i); |
273 | writeSettings(); | 273 | writeSettings(); |
274 | 274 | ||
275 | // set the timezone for everyone else... | 275 | // set the timezone for everyone else... |
276 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | 276 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); |
277 | setTimeZone << tz->currentZone(); | 277 | setTimeZone << tz->currentZone(); |
278 | 278 | ||
279 | // AM/PM setting and notify time changed | 279 | // AM/PM setting and notify time changed |
280 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); | 280 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); |
281 | setClock << ampmCombo->currentItem(); | 281 | setClock << ampmCombo->currentItem(); |
282 | 282 | ||
283 | // Notify everyone what day we prefer to start the week on. | 283 | // Notify everyone what day we prefer to start the week on. |
284 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); | 284 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); |
285 | setWeek << weekStartCombo->currentItem(); | 285 | setWeek << weekStartCombo->currentItem(); |
286 | 286 | ||
287 | // Notify everyone what date format to use | 287 | // Notify everyone what date format to use |
288 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); | 288 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); |
289 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; | 289 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; |
290 | 290 | ||
291 | // Restore screensaver | 291 | // Restore screensaver |
292 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 292 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
293 | enableScreenSaver << -1 << -1 << -1; | 293 | enableScreenSaver << -1 << -1 << -1; |
294 | // since time has changed quickly load in the datebookdb | 294 | // since time has changed quickly load in the datebookdb |
295 | // to allow the alarm server to get a better grip on itself | 295 | // to allow the alarm server to get a better grip on itself |
296 | // (example re-trigger alarms for when we travel back in time) | 296 | // (example re-trigger alarms for when we travel back in time) |
297 | DateBookDB db; | 297 | DateBookDB db; |
298 | 298 | ||
299 | } | 299 | } |
300 | 300 | ||
301 | void SetDateTime::tzChange( const QString &tz ) | 301 | void SetDateTime::tzChange( const QString &tz ) |
302 | { | 302 | { |
303 | qDebug("SetDateTime::tzChange"); | ||
304 | // set the TZ get the time and leave gracefully... | 303 | // set the TZ get the time and leave gracefully... |
305 | QString strSave; | 304 | QString strSave; |
306 | strSave = getenv( "TZ" ); | 305 | strSave = getenv( "TZ" ); |
307 | setenv( "TZ", tz, 1 ); | 306 | setenv( "TZ", tz, 1 ); |
308 | 307 | ||
309 | QDate d = QDate::currentDate(); | 308 | QDate d = QDate::currentDate(); |
310 | // reset the time. | 309 | // reset the time. |
311 | if ( !strSave.isNull() ) { | 310 | if ( !strSave.isNull() ) { |
312 | setenv( "TZ", strSave, 1 ); | 311 | setenv( "TZ", strSave, 1 ); |
313 | } | 312 | } |
314 | dateButton->setDate( d ); | 313 | dateButton->setDate( d ); |
315 | updateSystem(); | 314 | updateSystem(); |
316 | } | 315 | } |
317 | 316 | ||
318 | void SetDateTime::formatChanged(int i) | 317 | void SetDateTime::formatChanged(int i) |
319 | { | 318 | { |
320 | dateButton->setDateFormat(date_formats[i]); | 319 | dateButton->setDateFormat(date_formats[i]); |
321 | } | 320 | } |
322 | 321 | ||
323 | static const int ValueAM = 0; | 322 | static const int ValueAM = 0; |
324 | static const int ValuePM = 1; | 323 | static const int ValuePM = 1; |
325 | 324 | ||
326 | 325 | ||
327 | 326 | ||
328 | SetTime::SetTime( QWidget *parent, const char *name ) | 327 | SetTime::SetTime( QWidget *parent, const char *name ) |
329 | : QWidget( parent, name ) | 328 | : QWidget( parent, name ) |
330 | { | 329 | { |
331 | use12hourTime = FALSE; | 330 | use12hourTime = FALSE; |
332 | 331 | ||
333 | QTime currTime = QTime::currentTime(); | 332 | QTime currTime = QTime::currentTime(); |
334 | hour = currTime.hour(); | 333 | hour = currTime.hour(); |
335 | minute = currTime.minute(); | 334 | minute = currTime.minute(); |
336 | 335 | ||
337 | QHBoxLayout *hb2 = new QHBoxLayout( this ); | 336 | QHBoxLayout *hb2 = new QHBoxLayout( this ); |
338 | hb2->setSpacing( 3 ); | 337 | hb2->setSpacing( 3 ); |
339 | 338 | ||
340 | QLabel *l = new QLabel( tr("Hour"), this ); | 339 | QLabel *l = new QLabel( tr("Hour"), this ); |
341 | // l->setAlignment( AlignRight | AlignVCenter ); | 340 | // l->setAlignment( AlignRight | AlignVCenter ); |
342 | hb2->addWidget( l ); | 341 | hb2->addWidget( l ); |
343 | 342 | ||
344 | sbHour = new QSpinBox( this ); | 343 | sbHour = new QSpinBox( this ); |
345 | sbHour->setMinimumWidth( 30 ); | 344 | sbHour->setMinimumWidth( 30 ); |
346 | if(use12hourTime) { | 345 | if(use12hourTime) { |
347 | sbHour->setMinValue(1); | 346 | sbHour->setMinValue(1); |
348 | sbHour->setMaxValue( 12 ); | 347 | sbHour->setMaxValue( 12 ); |
349 | int show_hour = hour; | 348 | int show_hour = hour; |
350 | if (hour > 12) | 349 | if (hour > 12) |
351 | show_hour -= 12; | 350 | show_hour -= 12; |
352 | if (show_hour == 0) | 351 | if (show_hour == 0) |
353 | show_hour = 12; | 352 | show_hour = 12; |
354 | 353 | ||
355 | sbHour->setValue( show_hour ); | 354 | sbHour->setValue( show_hour ); |
356 | } else { | 355 | } else { |
357 | sbHour->setMinValue( 0 ); | 356 | sbHour->setMinValue( 0 ); |
358 | sbHour->setMaxValue( 23 ); | 357 | sbHour->setMaxValue( 23 ); |
359 | sbHour->setValue( hour ); | 358 | sbHour->setValue( hour ); |
360 | } | 359 | } |
361 | sbHour->setWrapping(TRUE); | 360 | sbHour->setWrapping(TRUE); |
362 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); | 361 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); |
363 | hb2->addWidget( sbHour ); | 362 | hb2->addWidget( sbHour ); |
364 | 363 | ||
365 | hb2->addStretch( 1 ); | 364 | hb2->addStretch( 1 ); |
366 | 365 | ||
367 | l = new QLabel( tr("Minute"), this ); | 366 | l = new QLabel( tr("Minute"), this ); |
368 | //l->setAlignment( AlignRight | AlignVCenter ); | 367 | //l->setAlignment( AlignRight | AlignVCenter ); |
369 | hb2->addWidget( l ); | 368 | hb2->addWidget( l ); |
370 | 369 | ||
371 | sbMin = new QSpinBox( this ); | 370 | sbMin = new QSpinBox( this ); |
372 | sbMin->setMinValue( 0 ); | 371 | sbMin->setMinValue( 0 ); |
373 | sbMin->setMaxValue( 59 ); | 372 | sbMin->setMaxValue( 59 ); |
374 | sbMin->setWrapping(TRUE); | 373 | sbMin->setWrapping(TRUE); |
375 | sbMin->setValue( minute ); | 374 | sbMin->setValue( minute ); |
376 | sbMin->setMinimumWidth( 30 ); | 375 | sbMin->setMinimumWidth( 30 ); |
377 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); | 376 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); |
378 | hb2->addWidget( sbMin ); | 377 | hb2->addWidget( sbMin ); |
379 | 378 | ||
380 | hb2->addStretch( 1 ); | 379 | hb2->addStretch( 1 ); |
381 | 380 | ||
382 | ampm = new QComboBox( this ); | 381 | ampm = new QComboBox( this ); |
383 | ampm->insertItem( tr("AM"), ValueAM ); | 382 | ampm->insertItem( tr("AM"), ValueAM ); |
384 | ampm->insertItem( tr("PM"), ValuePM ); | 383 | ampm->insertItem( tr("PM"), ValuePM ); |
385 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); | 384 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); |
386 | hb2->addWidget( ampm ); | 385 | hb2->addWidget( ampm ); |
387 | 386 | ||
388 | hb2->addStretch( 1 ); | 387 | hb2->addStretch( 1 ); |
389 | 388 | ||
390 | } | 389 | } |
391 | 390 | ||
392 | QTime SetTime::time() const | 391 | QTime SetTime::time() const |
393 | { | 392 | { |
394 | return QTime( hour, minute, 0 ); | 393 | return QTime( hour, minute, 0 ); |
395 | } | 394 | } |
396 | 395 | ||
397 | void SetTime::hourChanged( int value ) | 396 | void SetTime::hourChanged( int value ) |
398 | { | 397 | { |
399 | if(use12hourTime) { | 398 | if(use12hourTime) { |
400 | int realhour = value; | 399 | int realhour = value; |
401 | if (realhour == 12) | 400 | if (realhour == 12) |
402 | realhour = 0; | 401 | realhour = 0; |
403 | if (ampm->currentItem() == ValuePM ) | 402 | if (ampm->currentItem() == ValuePM ) |
404 | realhour += 12; | 403 | realhour += 12; |
405 | hour = realhour; | 404 | hour = realhour; |
406 | } else | 405 | } else |
407 | hour = value; | 406 | hour = value; |
408 | } | 407 | } |
409 | 408 | ||
410 | void SetTime::minuteChanged( int value ) | 409 | void SetTime::minuteChanged( int value ) |
411 | { | 410 | { |
412 | minute = value; | 411 | minute = value; |
413 | } | 412 | } |
414 | 413 | ||
415 | void SetTime::show12hourTime( int on ) | 414 | void SetTime::show12hourTime( int on ) |
416 | { | 415 | { |
417 | use12hourTime = on; | 416 | use12hourTime = on; |
418 | ampm->setEnabled(on); | 417 | ampm->setEnabled(on); |
419 | 418 | ||
420 | int show_hour = hour; | 419 | int show_hour = hour; |
421 | if ( on ) { | 420 | if ( on ) { |
422 | /* this might change the value of hour */ | 421 | /* this might change the value of hour */ |
423 | sbHour->setMinValue(1); | 422 | sbHour->setMinValue(1); |
424 | sbHour->setMaxValue( 12 ); | 423 | sbHour->setMaxValue( 12 ); |
425 | 424 | ||
426 | /* so use one we saved earlier */ | 425 | /* so use one we saved earlier */ |
427 | if (show_hour >= 12) { | 426 | if (show_hour >= 12) { |
428 | show_hour -= 12; | 427 | show_hour -= 12; |
429 | ampm->setCurrentItem( ValuePM ); | 428 | ampm->setCurrentItem( ValuePM ); |
430 | } else { | 429 | } else { |
431 | ampm->setCurrentItem( ValueAM ); | 430 | ampm->setCurrentItem( ValueAM ); |
432 | } | 431 | } |
433 | if (show_hour == 0) | 432 | if (show_hour == 0) |
434 | show_hour = 12; | 433 | show_hour = 12; |
435 | 434 | ||
436 | } else { | 435 | } else { |
437 | sbHour->setMinValue( 0 ); | 436 | sbHour->setMinValue( 0 ); |
438 | sbHour->setMaxValue( 23 ); | 437 | sbHour->setMaxValue( 23 ); |
439 | } | 438 | } |
440 | 439 | ||
441 | 440 | ||
442 | sbHour->setValue( show_hour ); | 441 | sbHour->setValue( show_hour ); |
443 | } | 442 | } |
444 | 443 | ||
445 | void SetTime::checkedPM( int c ) | 444 | void SetTime::checkedPM( int c ) |
446 | { | 445 | { |
447 | int show_hour = sbHour->value(); | 446 | int show_hour = sbHour->value(); |
448 | if (show_hour == 12) | 447 | if (show_hour == 12) |
449 | show_hour = 0; | 448 | show_hour = 0; |
450 | 449 | ||
451 | if ( c == ValuePM ) | 450 | if ( c == ValuePM ) |
452 | show_hour += 12; | 451 | show_hour += 12; |
453 | 452 | ||
454 | hour = show_hour; | 453 | hour = show_hour; |
455 | } | 454 | } |
456 | 455 | ||
457 | void SetTime::slotTzChange( const QString &tz ) | 456 | void SetTime::slotTzChange( const QString &tz ) |
458 | { | 457 | { |
459 | qDebug("SetTime::slotTzChange"); | ||
460 | // set the TZ get the time and leave gracefully... | 458 | // set the TZ get the time and leave gracefully... |
461 | QString strSave; | 459 | QString strSave; |
462 | strSave = getenv( "TZ" ); | 460 | strSave = getenv( "TZ" ); |
463 | setenv( "TZ", tz, 1 ); | 461 | setenv( "TZ", tz, 1 ); |
464 | 462 | ||
465 | QTime t = QTime::currentTime(); | 463 | QTime t = QTime::currentTime(); |
466 | // reset the time. | 464 | // reset the time. |
467 | if ( !strSave.isNull() ) { | 465 | if ( !strSave.isNull() ) { |
468 | setenv( "TZ", strSave, 1 ); | 466 | setenv( "TZ", strSave, 1 ); |
469 | } | 467 | } |
470 | 468 | ||
471 | // just set the spinboxes and let it propage through | 469 | // just set the spinboxes and let it propage through |
472 | if(use12hourTime) { | 470 | if(use12hourTime) { |
473 | int show_hour = t.hour(); | 471 | int show_hour = t.hour(); |
474 | if (t.hour() >= 12) { | 472 | if (t.hour() >= 12) { |
475 | show_hour -= 12; | 473 | show_hour -= 12; |
476 | ampm->setCurrentItem( ValuePM ); | 474 | ampm->setCurrentItem( ValuePM ); |
477 | } else { | 475 | } else { |
478 | ampm->setCurrentItem( ValueAM ); | 476 | ampm->setCurrentItem( ValueAM ); |
479 | } | 477 | } |
480 | if (show_hour == 0) | 478 | if (show_hour == 0) |
481 | show_hour = 12; | 479 | show_hour = 12; |
482 | sbHour->setValue( show_hour ); | 480 | sbHour->setValue( show_hour ); |
483 | } else { | 481 | } else { |
484 | sbHour->setValue( t.hour() ); | 482 | sbHour->setValue( t.hour() ); |
485 | } | 483 | } |
486 | sbMin->setValue( t.minute() ); | 484 | sbMin->setValue( t.minute() ); |
487 | } | 485 | } |
488 | 486 | ||
489 | 487 | ||