-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 9 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 3 |
2 files changed, 8 insertions, 4 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 830c0c3..7971f9a 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -1,287 +1,288 @@ | |||
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/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
14 | #include <qpe/config.h> | 14 | #include <qpe/config.h> |
15 | #include <qpe/global.h> | 15 | #include <qpe/global.h> |
16 | #include <qpe/timeconversion.h> | 16 | #include <qpe/timeconversion.h> |
17 | #include <qpe/tzselect.h> | 17 | #include <qpe/tzselect.h> |
18 | #include <qpe/timestring.h> | 18 | #include <qpe/timestring.h> |
19 | #include <qpe/qpedialog.h> | 19 | #include <qpe/qpedialog.h> |
20 | #include <sys/time.h> | 20 | #include <sys/time.h> |
21 | #include <time.h> | 21 | #include <time.h> |
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | 23 | ||
24 | 24 | ||
25 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 25 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
26 | : SetDateTime( parent, name, fl ) | 26 | : SetDateTime( parent, name, fl ) |
27 | { | 27 | { |
28 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); | 28 | Config ntpSrvs(QPEApplication::qpeDir()+"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 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); | 40 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); |
41 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); | 41 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); |
42 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); | 42 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); |
43 | 43 | ||
44 | ntpTimer = new QTimer(this); | 44 | ntpTimer = new QTimer(this); |
45 | 45 | ||
46 | ntpProcess = new OProcess( ); | 46 | ntpProcess = new OProcess( ); |
47 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 47 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
48 | SLOT(slotNtpDelayChanged(int)) ); | 48 | SLOT(slotNtpDelayChanged(int)) ); |
49 | 49 | ||
50 | ntpSock = new QSocket( this ); | 50 | ntpSock = new QSocket( this ); |
51 | connect( ntpSock, SIGNAL( error(int) ), | 51 | connect( ntpSock, SIGNAL( error(int) ), |
52 | SLOT(slotCheckNtp(int)) ); | 52 | SLOT(slotCheckNtp(int)) ); |
53 | slotProbeNtpServer(); | 53 | slotProbeNtpServer(); |
54 | 54 | ||
55 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 55 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
56 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 56 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
57 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 57 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
58 | this, SLOT(ntpFinished(OProcess*))); | 58 | this, SLOT(ntpFinished(OProcess*))); |
59 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 59 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
60 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 60 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
61 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 61 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
62 | slotCheckNtp(-1); | 62 | slotCheckNtp(-1); |
63 | readLookups(); | 63 | readLookups(); |
64 | } | 64 | } |
65 | 65 | ||
66 | Ntp::~Ntp() | 66 | Ntp::~Ntp() |
67 | { | 67 | { |
68 | delete ntpProcess; | 68 | delete ntpProcess; |
69 | Config ntpSrvs("/etc/ntpservers",Config::File); | 69 | Config ntpSrvs("/etc/ntpservers",Config::File); |
70 | ntpSrvs.setGroup("servers"); | 70 | ntpSrvs.setGroup("servers"); |
71 | int srvCount = ComboNtpSrv->count(); | 71 | int srvCount = ComboNtpSrv->count(); |
72 | ntpSrvs.writeEntry("count", srvCount); | 72 | ntpSrvs.writeEntry("count", srvCount); |
73 | for (int i = 0; i < srvCount; i++) | 73 | for (int i = 0; i < srvCount; i++) |
74 | { | 74 | { |
75 | ntpSrvs.setGroup(QString::number(i)); | 75 | ntpSrvs.setGroup(QString::number(i)); |
76 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | 76 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); |
77 | } | 77 | } |
78 | Config cfg("ntp",Config::User); | 78 | Config cfg("ntp",Config::User); |
79 | cfg.setGroup("settings"); | 79 | cfg.setGroup("settings"); |
80 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); | 80 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); |
81 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 81 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
82 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 82 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
83 | } | 83 | } |
84 | 84 | ||
85 | bool Ntp::ntpDelayElapsed() | 85 | bool Ntp::ntpDelayElapsed() |
86 | { | 86 | { |
87 | Config cfg("ntp",Config::User); | 87 | Config cfg("ntp",Config::User); |
88 | cfg.setGroup("lookups"); | 88 | cfg.setGroup("lookups"); |
89 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | 89 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); |
90 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; | 90 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; |
91 | } | 91 | } |
92 | 92 | ||
93 | QString Ntp::getNtpServer() | 93 | QString Ntp::getNtpServer() |
94 | { | 94 | { |
95 | return ComboNtpSrv->currentText(); | 95 | return ComboNtpSrv->currentText(); |
96 | } | 96 | } |
97 | 97 | ||
98 | void Ntp::slotRunNtp() | 98 | void Ntp::slotRunNtp() |
99 | { | 99 | { |
100 | if ( !ntpDelayElapsed() ) | 100 | if ( !ntpDelayElapsed() ) |
101 | { | 101 | { |
102 | switch ( | 102 | switch ( |
103 | QMessageBox::warning(this, tr("Run NTP?"), | 103 | QMessageBox::warning(this, tr("Run NTP?"), |
104 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 104 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
105 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ | 105 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ |
106 | "<br>"+tr("Rerun NTP?"), | 106 | "<br>"+tr("Rerun NTP?"), |
107 | QMessageBox::Ok,QMessageBox::Cancel) | 107 | QMessageBox::Ok,QMessageBox::Cancel) |
108 | ) { | 108 | ) { |
109 | case QMessageBox::Ok: break; | 109 | case QMessageBox::Ok: break; |
110 | case QMessageBox::Cancel: return; | 110 | case QMessageBox::Cancel: return; |
111 | default: return; | 111 | default: return; |
112 | } | 112 | } |
113 | } | 113 | } |
114 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 114 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
115 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 115 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
116 | 116 | ||
117 | ntpProcess->clearArguments(); | 117 | ntpProcess->clearArguments(); |
118 | *ntpProcess << "ntpdate" << getNtpServer(); | 118 | *ntpProcess << "ntpdate" << getNtpServer(); |
119 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 119 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
120 | if ( !ret ) { | 120 | if ( !ret ) { |
121 | qDebug("Error while executing ntpdate"); | 121 | qDebug("Error while executing ntpdate"); |
122 | ntpOutPut( tr("Error while executing ntpdate")); | 122 | ntpOutPut( tr("Error while executing ntpdate")); |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 126 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
127 | { | 127 | { |
128 | QString lineStr, lineStrOld; | 128 | QString lineStr, lineStrOld; |
129 | lineStr = buffer; | 129 | lineStr = buffer; |
130 | lineStr=lineStr.left(buflen); | 130 | lineStr=lineStr.left(buflen); |
131 | if (lineStr!=lineStrOld) | 131 | if (lineStr!=lineStrOld) |
132 | { | 132 | { |
133 | ntpOutPut(lineStr); | 133 | ntpOutPut(lineStr); |
134 | _ntpOutput += lineStr; | 134 | _ntpOutput += lineStr; |
135 | } | 135 | } |
136 | lineStrOld = lineStr; | 136 | lineStrOld = lineStr; |
137 | } | 137 | } |
138 | 138 | ||
139 | void Ntp::ntpFinished(OProcess *p) | 139 | void Ntp::ntpFinished(OProcess *p) |
140 | { | 140 | { |
141 | qDebug("p->exitStatus() %i",p->exitStatus()); | 141 | qDebug("p->exitStatus() %i",p->exitStatus()); |
142 | if (p->exitStatus()!=0 || !p->normalExit()) | 142 | if (p->exitStatus()!=0 || !p->normalExit()) |
143 | { | 143 | { |
144 | slotProbeNtpServer(); | 144 | slotProbeNtpServer(); |
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | Config cfg("ntp",Config::User); | 147 | Config cfg("ntp",Config::User); |
148 | cfg.setGroup("lookups"); | 148 | cfg.setGroup("lookups"); |
149 | int lastLookup = cfg.readNumEntry("time",0); | 149 | int lastLookup = cfg.readNumEntry("time",0); |
150 | int lookupCount = cfg.readNumEntry("count",0); | 150 | int lookupCount = cfg.readNumEntry("count",0); |
151 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); | ||
151 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 152 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
152 | cfg.writeEntry("time", time); | 153 | cfg.writeEntry("time", time); |
153 | cfg.setGroup("correction"); | ||
154 | cfg.writeEntry("time", time); | ||
155 | 154 | ||
156 | float timeShift = getTimeShift(); | 155 | float timeShift = getTimeShift(); |
157 | if (timeShift == 0.0) return; | 156 | if (timeShift == 0.0) return; |
158 | int secsSinceLast = time - lastLookup; | 157 | int secsSinceLast = time - lastLookup; |
159 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 158 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
160 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); | 159 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); |
161 | if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) | 160 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) |
162 | { | 161 | { |
162 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | ||
163 | lookupCount++; | 163 | lookupCount++; |
164 | cfg.writeEntry("count",lookupCount); | 164 | cfg.writeEntry("count",lookupCount); |
165 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | ||
166 | _shiftPerSec = timeShift / secsSinceLast; | 165 | _shiftPerSec = timeShift / secsSinceLast; |
167 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); | 166 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); |
168 | cfg.writeEntry("secsSinceLast",secsSinceLast); | 167 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
169 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 168 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
169 | cfg.writeEntry("lastNtp",true); | ||
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | float Ntp::getTimeShift() | 174 | float Ntp::getTimeShift() |
175 | { | 175 | { |
176 | QString _offset = "offset"; | 176 | QString _offset = "offset"; |
177 | QString _sec = "sec"; | 177 | QString _sec = "sec"; |
178 | QRegExp _reOffset = QRegExp(_offset); | 178 | QRegExp _reOffset = QRegExp(_offset); |
179 | QRegExp _reEndOffset = QRegExp(_sec); | 179 | QRegExp _reEndOffset = QRegExp(_sec); |
180 | int posOffset = _reOffset.match( _ntpOutput ); | 180 | int posOffset = _reOffset.match( _ntpOutput ); |
181 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); | 181 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); |
182 | posOffset += _offset.length() + 1; | 182 | posOffset += _offset.length() + 1; |
183 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); | 183 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); |
184 | qDebug("%s", _ntpOutput.latin1()); | 184 | qDebug("%s", _ntpOutput.latin1()); |
185 | qDebug("diff = >%s<",diff.latin1()); | 185 | qDebug("diff = >%s<",diff.latin1()); |
186 | return diff.toFloat(); | 186 | return diff.toFloat(); |
187 | } | 187 | } |
188 | 188 | ||
189 | void Ntp::readLookups() | 189 | void Ntp::readLookups() |
190 | { | 190 | { |
191 | Config cfg("ntp",Config::User); | 191 | Config cfg("ntp",Config::User); |
192 | cfg.setGroup("lookups"); | 192 | cfg.setGroup("lookups"); |
193 | int lookupCount = cfg.readNumEntry("count",0); | 193 | int lookupCount = cfg.readNumEntry("count",0); |
194 | float last, shift, shiftPerSec; | 194 | float last, shift, shiftPerSec; |
195 | qDebug("lookupCount = %i",lookupCount); | 195 | qDebug("lookupCount = %i",lookupCount); |
196 | TableLookups->setNumCols( 3 ); | 196 | TableLookups->setNumCols( 3 ); |
197 | TableLookups->setNumRows( lookupCount); | 197 | TableLookups->setNumRows( lookupCount); |
198 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); | 198 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); |
199 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); | 199 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); |
200 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); | 200 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); |
201 | int cw = TableLookups->width()/4; | 201 | int cw = TableLookups->width()/4; |
202 | qDebug("column width %i",cw); | 202 | qDebug("column width %i",cw); |
203 | cw = 50; | 203 | cw = 50; |
204 | TableLookups->setColumnWidth( 0, cw+30 ); | 204 | TableLookups->setColumnWidth( 0, cw+30 ); |
205 | TableLookups->setColumnWidth( 1, cw ); | 205 | TableLookups->setColumnWidth( 1, cw ); |
206 | TableLookups->setColumnWidth( 2, cw ); | 206 | TableLookups->setColumnWidth( 2, cw ); |
207 | TableLookups->sortColumn(0, false, true ); | 207 | TableLookups->sortColumn(0, false, true ); |
208 | // TableLookups->setSorting( true ); | 208 | // TableLookups->setSorting( true ); |
209 | for (int i=0; i < lookupCount; i++) | 209 | for (int i=0; i < lookupCount; i++) |
210 | { | 210 | { |
211 | cfg.setGroup("lookup_"+QString::number(i)); | 211 | cfg.setGroup("lookup_"+QString::number(i)); |
212 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 212 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
213 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 213 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
214 | // qDebug("%i last %f",i,last); | 214 | // qDebug("%i last %f",i,last); |
215 | // qDebug("%i shift %f",i,shift); | 215 | // qDebug("%i shift %f",i,shift); |
216 | shiftPerSec = shift / last; | 216 | shiftPerSec = shift / last; |
217 | _shiftPerSec += shiftPerSec; | 217 | _shiftPerSec += shiftPerSec; |
218 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); | 218 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); |
219 | TableLookups->setText( i,2,QString::number(shift)); | 219 | TableLookups->setText( i,2,QString::number(shift)); |
220 | TableLookups->setText( i,1,QString::number(last/(60*60))); | 220 | TableLookups->setText( i,1,QString::number(last/(60*60))); |
221 | } | 221 | } |
222 | _shiftPerSec /= lookupCount; | 222 | _shiftPerSec /= lookupCount; |
223 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); | 223 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); |
224 | } | 224 | } |
225 | 225 | ||
226 | void Ntp::preditctTime() | 226 | void Ntp::preditctTime() |
227 | { | 227 | { |
228 | Config cfg("ntp",Config::User); | 228 | Config cfg("ntp",Config::User); |
229 | cfg.setGroup("lookups"); | 229 | cfg.setGroup("lookups"); |
230 | int lastTime = cfg.readNumEntry("time",0); | 230 | int lastTime = cfg.readNumEntry("time",0); |
231 | cfg.writeEntry("lastNtp",true); | ||
231 | setenv( "TZ", tz->currentZone(), 1 ); | 232 | setenv( "TZ", tz->currentZone(), 1 ); |
232 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 233 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
233 | int corr = int((now - lastTime) * _shiftPerSec); | 234 | int corr = int((now - lastTime) * _shiftPerSec); |
234 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 235 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
235 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 236 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
236 | TextLabelPredTime->setText(predictedTime.toString()); | 237 | TextLabelPredTime->setText(predictedTime.toString()); |
237 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 238 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
238 | } | 239 | } |
239 | 240 | ||
240 | void Ntp::setPredictTime() | 241 | void Ntp::setPredictTime() |
241 | { | 242 | { |
242 | preditctTime(); | 243 | preditctTime(); |
243 | setTime( predictedTime ); | 244 | setTime( predictedTime ); |
244 | } | 245 | } |
245 | 246 | ||
246 | void Ntp::slotCheckNtp(int i) | 247 | void Ntp::slotCheckNtp(int i) |
247 | { | 248 | { |
248 | if (i == 0) | 249 | if (i == 0) |
249 | { | 250 | { |
250 | TextLabelMainPredTime->hide(); | 251 | TextLabelMainPredTime->hide(); |
251 | ButtonSetTime->setText( tr("Get time from network") ); | 252 | ButtonSetTime->setText( tr("Get time from network") ); |
252 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 253 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
253 | if ( ntpDelayElapsed() ) | 254 | if ( ntpDelayElapsed() ) |
254 | { | 255 | { |
255 | slotRunNtp(); | 256 | slotRunNtp(); |
256 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 257 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
257 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 258 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); |
258 | }else{ | 259 | }else{ |
259 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 260 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); |
260 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 261 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
261 | } | 262 | } |
262 | }else{ | 263 | }else{ |
263 | preditctTime(); | 264 | preditctTime(); |
264 | ButtonSetTime->setText( tr("Set predicted time") ); | 265 | ButtonSetTime->setText( tr("Set predicted time") ); |
265 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 266 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
266 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 267 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
267 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 268 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
268 | } | 269 | } |
269 | } | 270 | } |
270 | 271 | ||
271 | void Ntp::slotProbeNtpServer() | 272 | void Ntp::slotProbeNtpServer() |
272 | { | 273 | { |
273 | qDebug("Ntp::slotProbeNtpServer()"); | 274 | qDebug("Ntp::slotProbeNtpServer()"); |
274 | ntpSock->connectToHost( getNtpServer() ,123); | 275 | ntpSock->connectToHost( getNtpServer() ,123); |
275 | } | 276 | } |
276 | 277 | ||
277 | void Ntp::slotNtpDelayChanged(int delay) | 278 | void Ntp::slotNtpDelayChanged(int delay) |
278 | { | 279 | { |
279 | ntpTimer->changeInterval( delay*1000*60 ); | 280 | ntpTimer->changeInterval( delay*1000*60 ); |
280 | } | 281 | } |
281 | 282 | ||
282 | void Ntp::ntpOutPut(QString out) | 283 | void Ntp::ntpOutPut(QString out) |
283 | { | 284 | { |
284 | MultiLineEditntpOutPut->append(out); | 285 | MultiLineEditntpOutPut->append(out); |
285 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 286 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
286 | } | 287 | } |
287 | 288 | ||
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp index e7e604f..9c5323a 100644 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/noncore/settings/netsystemtime/settime.cpp | |||
@@ -41,384 +41,387 @@ | |||
41 | #include <qlayout.h> | 41 | #include <qlayout.h> |
42 | #include <qradiobutton.h> | 42 | #include <qradiobutton.h> |
43 | #include <qspinbox.h> | 43 | #include <qspinbox.h> |
44 | #include <qtoolbutton.h> | 44 | #include <qtoolbutton.h> |
45 | #include <qwindowsystem_qws.h> | 45 | #include <qwindowsystem_qws.h> |
46 | #include <qcombobox.h> | 46 | #include <qcombobox.h> |
47 | 47 | ||
48 | #include <sys/time.h> | 48 | #include <sys/time.h> |
49 | #include <time.h> | 49 | #include <time.h> |
50 | #include <stdlib.h> | 50 | #include <stdlib.h> |
51 | #include <stdio.h> | 51 | #include <stdio.h> |
52 | 52 | ||
53 | 53 | ||
54 | SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) | 54 | SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) |
55 | : NtpBase( parent, name, f ) | 55 | : NtpBase( parent, name, f ) |
56 | { | 56 | { |
57 | // setCaption( tr("Set System Time") ); | 57 | // setCaption( tr("Set System Time") ); |
58 | 58 | ||
59 | // QVBoxLayout *vb = new QVBoxLayout( this, 5 ); | 59 | // QVBoxLayout *vb = new QVBoxLayout( this, 5 ); |
60 | QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 ); | 60 | QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 ); |
61 | QVBoxLayout *vb2 = new QVBoxLayout( FrameSetTime, 5 ); | 61 | QVBoxLayout *vb2 = new QVBoxLayout( FrameSetTime, 5 ); |
62 | 62 | ||
63 | TextLabelMainPredTime = new QLabel( FrameSystemTime ); | 63 | TextLabelMainPredTime = new QLabel( FrameSystemTime ); |
64 | vb->addWidget( TextLabelMainPredTime, 1, 0 ); | 64 | vb->addWidget( TextLabelMainPredTime, 1, 0 ); |
65 | ButtonSetTime = new QPushButton( FrameSystemTime ); | 65 | ButtonSetTime = new QPushButton( FrameSystemTime ); |
66 | vb->addWidget( ButtonSetTime, 1, 0 ); | 66 | vb->addWidget( ButtonSetTime, 1, 0 ); |
67 | 67 | ||
68 | QFrame *hline = new QFrame( FrameSystemTime ); | 68 | QFrame *hline = new QFrame( FrameSystemTime ); |
69 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 69 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
70 | vb->addWidget( hline ); | 70 | vb->addWidget( hline ); |
71 | 71 | ||
72 | QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" ); | 72 | QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" ); |
73 | 73 | ||
74 | QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" ); | 74 | QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" ); |
75 | lblZone->setMaximumSize( lblZone->sizeHint() ); | 75 | lblZone->setMaximumSize( lblZone->sizeHint() ); |
76 | hb->addWidget( lblZone ); | 76 | hb->addWidget( lblZone ); |
77 | 77 | ||
78 | tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" ); | 78 | tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" ); |
79 | tz->setMinimumSize( tz->sizeHint() ); | 79 | tz->setMinimumSize( tz->sizeHint() ); |
80 | hb->addWidget( tz ); | 80 | hb->addWidget( tz ); |
81 | 81 | ||
82 | timeButton = new SetTime( FrameSetTime ); | 82 | timeButton = new SetTime( FrameSetTime ); |
83 | vb2->addWidget( timeButton ); | 83 | vb2->addWidget( timeButton ); |
84 | 84 | ||
85 | QHBoxLayout *db = new QHBoxLayout( vb2 ); | 85 | QHBoxLayout *db = new QHBoxLayout( vb2 ); |
86 | QLabel *dateLabel = new QLabel( tr("Date"), FrameSetTime ); | 86 | QLabel *dateLabel = new QLabel( tr("Date"), FrameSetTime ); |
87 | db->addWidget( dateLabel, 1 ); | 87 | db->addWidget( dateLabel, 1 ); |
88 | dateButton = new DateButton( TRUE, FrameSetTime ); | 88 | dateButton = new DateButton( TRUE, FrameSetTime ); |
89 | db->addWidget( dateButton, 2 ); | 89 | db->addWidget( dateButton, 2 ); |
90 | 90 | ||
91 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | 91 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); |
92 | vb2->addItem( spacer ); | 92 | vb2->addItem( spacer ); |
93 | 93 | ||
94 | hline = new QFrame( FrameSystemTime ); | 94 | hline = new QFrame( FrameSystemTime ); |
95 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 95 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
96 | vb->addWidget( hline ); | 96 | vb->addWidget( hline ); |
97 | 97 | ||
98 | Config config("qpe"); | 98 | Config config("qpe"); |
99 | config.setGroup( "Time" ); | 99 | config.setGroup( "Time" ); |
100 | 100 | ||
101 | QHBoxLayout *hb1 = new QHBoxLayout( vb ); | 101 | QHBoxLayout *hb1 = new QHBoxLayout( vb ); |
102 | 102 | ||
103 | QLabel *l = new QLabel( tr("Time format"), FrameSystemTime ); | 103 | QLabel *l = new QLabel( tr("Time format"), FrameSystemTime ); |
104 | hb1->addWidget( l, 1 ); | 104 | hb1->addWidget( l, 1 ); |
105 | 105 | ||
106 | 106 | ||
107 | ampmCombo = new QComboBox( FrameSystemTime ); | 107 | ampmCombo = new QComboBox( FrameSystemTime ); |
108 | ampmCombo->insertItem( tr("24 hour"), 0 ); | 108 | ampmCombo->insertItem( tr("24 hour"), 0 ); |
109 | ampmCombo->insertItem( tr("12 hour"), 1 ); | 109 | ampmCombo->insertItem( tr("12 hour"), 1 ); |
110 | hb1->addWidget( ampmCombo, 2 ); | 110 | hb1->addWidget( ampmCombo, 2 ); |
111 | 111 | ||
112 | int show12hr = config.readBoolEntry("AMPM") ? 1 : 0; | 112 | int show12hr = config.readBoolEntry("AMPM") ? 1 : 0; |
113 | ampmCombo->setCurrentItem( show12hr ); | 113 | ampmCombo->setCurrentItem( show12hr ); |
114 | timeButton->show12hourTime( show12hr ); | 114 | timeButton->show12hourTime( show12hr ); |
115 | 115 | ||
116 | connect(ampmCombo, SIGNAL(activated(int)), | 116 | connect(ampmCombo, SIGNAL(activated(int)), |
117 | timeButton, SLOT(show12hourTime(int))); | 117 | timeButton, SLOT(show12hourTime(int))); |
118 | 118 | ||
119 | 119 | ||
120 | 120 | ||
121 | QHBoxLayout *hb2 = new QHBoxLayout( vb ); | 121 | QHBoxLayout *hb2 = new QHBoxLayout( vb ); |
122 | l = new QLabel( tr("Weeks start on" ), FrameSystemTime ); | 122 | l = new QLabel( tr("Weeks start on" ), FrameSystemTime ); |
123 | //l->setAlignment( AlignRight | AlignVCenter ); | 123 | //l->setAlignment( AlignRight | AlignVCenter ); |
124 | hb2->addWidget( l, 1 ); | 124 | hb2->addWidget( l, 1 ); |
125 | 125 | ||
126 | weekStartCombo = new QComboBox( FrameSystemTime ); | 126 | weekStartCombo = new QComboBox( FrameSystemTime ); |
127 | weekStartCombo->insertItem( tr("Sunday"), 0 ); | 127 | weekStartCombo->insertItem( tr("Sunday"), 0 ); |
128 | weekStartCombo->insertItem( tr("Monday"), 1 ); | 128 | weekStartCombo->insertItem( tr("Monday"), 1 ); |
129 | 129 | ||
130 | hb2->addWidget( weekStartCombo, 2 ); | 130 | hb2->addWidget( weekStartCombo, 2 ); |
131 | int startMonday = config.readBoolEntry("MONDAY") ? 1 : 0; | 131 | int startMonday = config.readBoolEntry("MONDAY") ? 1 : 0; |
132 | dateButton->setWeekStartsMonday( startMonday ); | 132 | dateButton->setWeekStartsMonday( startMonday ); |
133 | weekStartCombo->setCurrentItem( startMonday ); | 133 | weekStartCombo->setCurrentItem( startMonday ); |
134 | 134 | ||
135 | connect( weekStartCombo, SIGNAL( activated(int)), | 135 | connect( weekStartCombo, SIGNAL( activated(int)), |
136 | dateButton, SLOT(setWeekStartsMonday(int))); | 136 | dateButton, SLOT(setWeekStartsMonday(int))); |
137 | 137 | ||
138 | 138 | ||
139 | QHBoxLayout *hb3 = new QHBoxLayout( vb ); | 139 | QHBoxLayout *hb3 = new QHBoxLayout( vb ); |
140 | l = new QLabel( tr("Date format" ), FrameSystemTime ); | 140 | l = new QLabel( tr("Date format" ), FrameSystemTime ); |
141 | hb3->addWidget( l, 1 ); | 141 | hb3->addWidget( l, 1 ); |
142 | dateFormatCombo = new QComboBox( FrameSystemTime ); | 142 | dateFormatCombo = new QComboBox( FrameSystemTime ); |
143 | hb3->addWidget( dateFormatCombo, 2 ); | 143 | hb3->addWidget( dateFormatCombo, 2 ); |
144 | 144 | ||
145 | config.setGroup( "Date" ); | 145 | config.setGroup( "Date" ); |
146 | DateFormat df(QChar(config.readEntry("Separator", "/")[0]), | 146 | DateFormat df(QChar(config.readEntry("Separator", "/")[0]), |
147 | (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), | 147 | (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), |
148 | (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); | 148 | (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); |
149 | 149 | ||
150 | int currentdf = 0; | 150 | int currentdf = 0; |
151 | date_formats[0] = DateFormat('/', DateFormat::MonthDayYear); | 151 | date_formats[0] = DateFormat('/', DateFormat::MonthDayYear); |
152 | dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) ); | 152 | dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) ); |
153 | date_formats[1] = DateFormat('.', DateFormat::DayMonthYear); | 153 | date_formats[1] = DateFormat('.', DateFormat::DayMonthYear); |
154 | if (df == date_formats[1]) | 154 | if (df == date_formats[1]) |
155 | currentdf = 1; | 155 | currentdf = 1; |
156 | dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) ); | 156 | dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) ); |
157 | date_formats[2] = DateFormat('-', DateFormat::YearMonthDay, | 157 | date_formats[2] = DateFormat('-', DateFormat::YearMonthDay, |
158 | DateFormat::DayMonthYear); | 158 | DateFormat::DayMonthYear); |
159 | if (df == date_formats[2]) | 159 | if (df == date_formats[2]) |
160 | currentdf = 2; | 160 | currentdf = 2; |
161 | dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601 | 161 | dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601 |
162 | date_formats[3] = DateFormat('/', DateFormat::DayMonthYear); | 162 | date_formats[3] = DateFormat('/', DateFormat::DayMonthYear); |
163 | if (df == date_formats[3]) | 163 | if (df == date_formats[3]) |
164 | currentdf = 3; | 164 | currentdf = 3; |
165 | dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) ); | 165 | dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) ); |
166 | 166 | ||
167 | dateFormatCombo->setCurrentItem( currentdf ); | 167 | dateFormatCombo->setCurrentItem( currentdf ); |
168 | dateButton->setDateFormat( df ); | 168 | dateButton->setDateFormat( df ); |
169 | 169 | ||
170 | connect( dateFormatCombo, SIGNAL( activated(int)), | 170 | connect( dateFormatCombo, SIGNAL( activated(int)), |
171 | SLOT(formatChanged(int))); | 171 | SLOT(formatChanged(int))); |
172 | 172 | ||
173 | QHBoxLayout *hb4 = new QHBoxLayout( vb ); | 173 | QHBoxLayout *hb4 = new QHBoxLayout( vb ); |
174 | l = new QLabel( tr("Applet format" ), FrameSystemTime ); | 174 | l = new QLabel( tr("Applet format" ), FrameSystemTime ); |
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 | Config cfg("ntp",Config::User); | ||
234 | cfg.setGroup("lookups"); | ||
235 | cfg.writeEntry("lastNtp",false); | ||
233 | tz->setFocus(); | 236 | tz->setFocus(); |
234 | // Need to process the QCOP event generated above before proceeding | 237 | // Need to process the QCOP event generated above before proceeding |
235 | qApp->processEvents(); | 238 | qApp->processEvents(); |
236 | 239 | ||
237 | // before we progress further, set our TZ! | 240 | // before we progress further, set our TZ! |
238 | setenv( "TZ", tz->currentZone(), 1 ); | 241 | setenv( "TZ", tz->currentZone(), 1 ); |
239 | // now set the time... | 242 | // now set the time... |
240 | QDateTime dt( dateButton->date(), timeButton->time() ); | 243 | QDateTime dt( dateButton->date(), timeButton->time() ); |
241 | 244 | ||
242 | if ( dt.isValid() ) setTime(dt); | 245 | if ( dt.isValid() ) setTime(dt); |
243 | } | 246 | } |
244 | 247 | ||
245 | void SetDateTime::setTime(QDateTime dt) | 248 | void SetDateTime::setTime(QDateTime dt) |
246 | { | 249 | { |
247 | // really turn off the screensaver before doing anything | 250 | // really turn off the screensaver before doing anything |
248 | { | 251 | { |
249 | // Needs to be encased in { } so that it deconstructs and sends | 252 | // Needs to be encased in { } so that it deconstructs and sends |
250 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 253 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
251 | disableScreenSaver << 0 << 0 << 0; | 254 | disableScreenSaver << 0 << 0 << 0; |
252 | } | 255 | } |
253 | Config cfg("ntp",Config::User); | 256 | Config cfg("ntp",Config::User); |
254 | cfg.setGroup("correction"); | 257 | cfg.setGroup("correction"); |
255 | int t = TimeConversion::toUTC(dt); | 258 | int t = TimeConversion::toUTC(dt); |
256 | struct timeval myTv; | 259 | struct timeval myTv; |
257 | myTv.tv_sec = t; | 260 | myTv.tv_sec = t; |
258 | cfg.writeEntry("time", t ); | 261 | cfg.writeEntry("time", t ); |
259 | myTv.tv_usec = 0; | 262 | myTv.tv_usec = 0; |
260 | 263 | ||
261 | if ( myTv.tv_sec != -1 ) | 264 | if ( myTv.tv_sec != -1 ) |
262 | ::settimeofday( &myTv, 0 ); | 265 | ::settimeofday( &myTv, 0 ); |
263 | Global::writeHWClock(); | 266 | Global::writeHWClock(); |
264 | // since time has changed quickly load in the datebookdb | 267 | // since time has changed quickly load in the datebookdb |
265 | // to allow the alarm server to get a better grip on itself | 268 | // to allow the alarm server to get a better grip on itself |
266 | // (example re-trigger alarms for when we travel back in time) | 269 | // (example re-trigger alarms for when we travel back in time) |
267 | DateBookDB db; | 270 | DateBookDB db; |
268 | // Restore screensaver | 271 | // Restore screensaver |
269 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 272 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
270 | enableScreenSaver << -1 << -1 << -1; | 273 | enableScreenSaver << -1 << -1 << -1; |
271 | } | 274 | } |
272 | 275 | ||
273 | void SetDateTime::updateSystem(int i) | 276 | void SetDateTime::updateSystem(int i) |
274 | { | 277 | { |
275 | // really turn off the screensaver before doing anything | 278 | // really turn off the screensaver before doing anything |
276 | { | 279 | { |
277 | // Needs to be encased in { } so that it deconstructs and sends | 280 | // Needs to be encased in { } so that it deconstructs and sends |
278 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 281 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
279 | disableScreenSaver << 0 << 0 << 0; | 282 | disableScreenSaver << 0 << 0 << 0; |
280 | } | 283 | } |
281 | qDebug("SetDateTime::updateSystem(int %i)",i); | 284 | qDebug("SetDateTime::updateSystem(int %i)",i); |
282 | writeSettings(); | 285 | writeSettings(); |
283 | 286 | ||
284 | // set the timezone for everyone else... | 287 | // set the timezone for everyone else... |
285 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | 288 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); |
286 | setTimeZone << tz->currentZone(); | 289 | setTimeZone << tz->currentZone(); |
287 | 290 | ||
288 | // AM/PM setting and notify time changed | 291 | // AM/PM setting and notify time changed |
289 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); | 292 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); |
290 | setClock << ampmCombo->currentItem(); | 293 | setClock << ampmCombo->currentItem(); |
291 | 294 | ||
292 | // Notify everyone what day we prefer to start the week on. | 295 | // Notify everyone what day we prefer to start the week on. |
293 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); | 296 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); |
294 | setWeek << weekStartCombo->currentItem(); | 297 | setWeek << weekStartCombo->currentItem(); |
295 | 298 | ||
296 | // Notify everyone what date format to use | 299 | // Notify everyone what date format to use |
297 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); | 300 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); |
298 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; | 301 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; |
299 | 302 | ||
300 | // Restore screensaver | 303 | // Restore screensaver |
301 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 304 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
302 | enableScreenSaver << -1 << -1 << -1; | 305 | enableScreenSaver << -1 << -1 << -1; |
303 | // since time has changed quickly load in the datebookdb | 306 | // since time has changed quickly load in the datebookdb |
304 | // to allow the alarm server to get a better grip on itself | 307 | // to allow the alarm server to get a better grip on itself |
305 | // (example re-trigger alarms for when we travel back in time) | 308 | // (example re-trigger alarms for when we travel back in time) |
306 | DateBookDB db; | 309 | DateBookDB db; |
307 | 310 | ||
308 | } | 311 | } |
309 | 312 | ||
310 | void SetDateTime::tzChange( const QString &tz ) | 313 | void SetDateTime::tzChange( const QString &tz ) |
311 | { | 314 | { |
312 | // set the TZ get the time and leave gracefully... | 315 | // set the TZ get the time and leave gracefully... |
313 | QString strSave; | 316 | QString strSave; |
314 | strSave = getenv( "TZ" ); | 317 | strSave = getenv( "TZ" ); |
315 | setenv( "TZ", tz, 1 ); | 318 | setenv( "TZ", tz, 1 ); |
316 | 319 | ||
317 | QDate d = QDate::currentDate(); | 320 | QDate d = QDate::currentDate(); |
318 | // reset the time. | 321 | // reset the time. |
319 | if ( !strSave.isNull() ) { | 322 | if ( !strSave.isNull() ) { |
320 | setenv( "TZ", strSave, 1 ); | 323 | setenv( "TZ", strSave, 1 ); |
321 | } | 324 | } |
322 | dateButton->setDate( d ); | 325 | dateButton->setDate( d ); |
323 | updateSystem(); | 326 | updateSystem(); |
324 | } | 327 | } |
325 | 328 | ||
326 | void SetDateTime::formatChanged(int i) | 329 | void SetDateTime::formatChanged(int i) |
327 | { | 330 | { |
328 | dateButton->setDateFormat(date_formats[i]); | 331 | dateButton->setDateFormat(date_formats[i]); |
329 | } | 332 | } |
330 | 333 | ||
331 | static const int ValueAM = 0; | 334 | static const int ValueAM = 0; |
332 | static const int ValuePM = 1; | 335 | static const int ValuePM = 1; |
333 | 336 | ||
334 | 337 | ||
335 | 338 | ||
336 | SetTime::SetTime( QWidget *parent, const char *name ) | 339 | SetTime::SetTime( QWidget *parent, const char *name ) |
337 | : QWidget( parent, name ) | 340 | : QWidget( parent, name ) |
338 | { | 341 | { |
339 | use12hourTime = FALSE; | 342 | use12hourTime = FALSE; |
340 | 343 | ||
341 | QTime currTime = QTime::currentTime(); | 344 | QTime currTime = QTime::currentTime(); |
342 | hour = currTime.hour(); | 345 | hour = currTime.hour(); |
343 | minute = currTime.minute(); | 346 | minute = currTime.minute(); |
344 | 347 | ||
345 | QHBoxLayout *hb2 = new QHBoxLayout( this ); | 348 | QHBoxLayout *hb2 = new QHBoxLayout( this ); |
346 | hb2->setSpacing( 3 ); | 349 | hb2->setSpacing( 3 ); |
347 | 350 | ||
348 | QLabel *l = new QLabel( tr("Hour"), this ); | 351 | QLabel *l = new QLabel( tr("Hour"), this ); |
349 | // l->setAlignment( AlignRight | AlignVCenter ); | 352 | // l->setAlignment( AlignRight | AlignVCenter ); |
350 | hb2->addWidget( l ); | 353 | hb2->addWidget( l ); |
351 | 354 | ||
352 | sbHour = new QSpinBox( this ); | 355 | sbHour = new QSpinBox( this ); |
353 | sbHour->setMinimumWidth( 30 ); | 356 | sbHour->setMinimumWidth( 30 ); |
354 | if(use12hourTime) { | 357 | if(use12hourTime) { |
355 | sbHour->setMinValue(1); | 358 | sbHour->setMinValue(1); |
356 | sbHour->setMaxValue( 12 ); | 359 | sbHour->setMaxValue( 12 ); |
357 | int show_hour = hour; | 360 | int show_hour = hour; |
358 | if (hour > 12) | 361 | if (hour > 12) |
359 | show_hour -= 12; | 362 | show_hour -= 12; |
360 | if (show_hour == 0) | 363 | if (show_hour == 0) |
361 | show_hour = 12; | 364 | show_hour = 12; |
362 | 365 | ||
363 | sbHour->setValue( show_hour ); | 366 | sbHour->setValue( show_hour ); |
364 | } else { | 367 | } else { |
365 | sbHour->setMinValue( 0 ); | 368 | sbHour->setMinValue( 0 ); |
366 | sbHour->setMaxValue( 23 ); | 369 | sbHour->setMaxValue( 23 ); |
367 | sbHour->setValue( hour ); | 370 | sbHour->setValue( hour ); |
368 | } | 371 | } |
369 | sbHour->setWrapping(TRUE); | 372 | sbHour->setWrapping(TRUE); |
370 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); | 373 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); |
371 | hb2->addWidget( sbHour ); | 374 | hb2->addWidget( sbHour ); |
372 | 375 | ||
373 | hb2->addStretch( 1 ); | 376 | hb2->addStretch( 1 ); |
374 | 377 | ||
375 | l = new QLabel( tr("Minute"), this ); | 378 | l = new QLabel( tr("Minute"), this ); |
376 | //l->setAlignment( AlignRight | AlignVCenter ); | 379 | //l->setAlignment( AlignRight | AlignVCenter ); |
377 | hb2->addWidget( l ); | 380 | hb2->addWidget( l ); |
378 | 381 | ||
379 | sbMin = new QSpinBox( this ); | 382 | sbMin = new QSpinBox( this ); |
380 | sbMin->setMinValue( 0 ); | 383 | sbMin->setMinValue( 0 ); |
381 | sbMin->setMaxValue( 59 ); | 384 | sbMin->setMaxValue( 59 ); |
382 | sbMin->setWrapping(TRUE); | 385 | sbMin->setWrapping(TRUE); |
383 | sbMin->setValue( minute ); | 386 | sbMin->setValue( minute ); |
384 | sbMin->setMinimumWidth( 30 ); | 387 | sbMin->setMinimumWidth( 30 ); |
385 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); | 388 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); |
386 | hb2->addWidget( sbMin ); | 389 | hb2->addWidget( sbMin ); |
387 | 390 | ||
388 | hb2->addStretch( 1 ); | 391 | hb2->addStretch( 1 ); |
389 | 392 | ||
390 | ampm = new QComboBox( this ); | 393 | ampm = new QComboBox( this ); |
391 | ampm->insertItem( tr("AM"), ValueAM ); | 394 | ampm->insertItem( tr("AM"), ValueAM ); |
392 | ampm->insertItem( tr("PM"), ValuePM ); | 395 | ampm->insertItem( tr("PM"), ValuePM ); |
393 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); | 396 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); |
394 | hb2->addWidget( ampm ); | 397 | hb2->addWidget( ampm ); |
395 | 398 | ||
396 | hb2->addStretch( 1 ); | 399 | hb2->addStretch( 1 ); |
397 | 400 | ||
398 | } | 401 | } |
399 | 402 | ||
400 | QTime SetTime::time() const | 403 | QTime SetTime::time() const |
401 | { | 404 | { |
402 | return QTime( hour, minute, 0 ); | 405 | return QTime( hour, minute, 0 ); |
403 | } | 406 | } |
404 | 407 | ||
405 | void SetTime::hourChanged( int value ) | 408 | void SetTime::hourChanged( int value ) |
406 | { | 409 | { |
407 | if(use12hourTime) { | 410 | if(use12hourTime) { |
408 | int realhour = value; | 411 | int realhour = value; |
409 | if (realhour == 12) | 412 | if (realhour == 12) |
410 | realhour = 0; | 413 | realhour = 0; |
411 | if (ampm->currentItem() == ValuePM ) | 414 | if (ampm->currentItem() == ValuePM ) |
412 | realhour += 12; | 415 | realhour += 12; |
413 | hour = realhour; | 416 | hour = realhour; |
414 | } else | 417 | } else |
415 | hour = value; | 418 | hour = value; |
416 | } | 419 | } |
417 | 420 | ||
418 | void SetTime::minuteChanged( int value ) | 421 | void SetTime::minuteChanged( int value ) |
419 | { | 422 | { |
420 | minute = value; | 423 | minute = value; |
421 | } | 424 | } |
422 | 425 | ||
423 | void SetTime::show12hourTime( int on ) | 426 | void SetTime::show12hourTime( int on ) |
424 | { | 427 | { |