author | tille <tille> | 2002-07-06 16:11:39 (UTC) |
---|---|---|
committer | tille <tille> | 2002-07-06 16:11:39 (UTC) |
commit | 8beb5fcdbca8110dc586a7e620bf8eae892087fb (patch) (unidiff) | |
tree | e3f96de0e645f160fd54bdcb6b4c36a25f4437c1 | |
parent | b83751deab22e8e25d21265bd59ab53766109ca2 (diff) | |
download | opie-8beb5fcdbca8110dc586a7e620bf8eae892087fb.zip opie-8beb5fcdbca8110dc586a7e620bf8eae892087fb.tar.gz opie-8beb5fcdbca8110dc586a7e620bf8eae892087fb.tar.bz2 |
qcop calls
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 10 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 6 |
2 files changed, 10 insertions, 6 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 2b779fa..15dae93 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -1,325 +1,329 @@ | |||
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 <qpe/datebookdb.h> | 20 | #include <qpe/datebookdb.h> |
21 | #include <qpe/qcopenvelope_qws.h> | 21 | #include <qpe/qcopenvelope_qws.h> |
22 | #include <sys/time.h> | 22 | #include <sys/time.h> |
23 | #include <time.h> | 23 | #include <time.h> |
24 | #include <stdlib.h> | 24 | #include <stdlib.h> |
25 | 25 | ||
26 | 26 | ||
27 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 27 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
28 | : SetDateTime( parent, name, fl ) | 28 | : SetDateTime( parent, name, fl ) |
29 | { | 29 | { |
30 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); | 30 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); |
31 | ntpSrvs.setGroup("servers"); | 31 | ntpSrvs.setGroup("servers"); |
32 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); | 32 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); |
33 | for (int i = 0; i < srvCount; i++) | 33 | for (int i = 0; i < srvCount; i++) |
34 | { | 34 | { |
35 | ntpSrvs.setGroup(QString::number(i)); | 35 | ntpSrvs.setGroup(QString::number(i)); |
36 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); | 36 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); |
37 | } | 37 | } |
38 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); | 38 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); |
39 | 39 | ||
40 | Config cfg("ntp",Config::User); | 40 | Config cfg("ntp",Config::User); |
41 | cfg.setGroup("settings"); | 41 | cfg.setGroup("settings"); |
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 | makeChannel(); | 46 | makeChannel(); |
47 | 47 | ||
48 | ntpTimer = new QTimer(this); | 48 | ntpTimer = new QTimer(this); |
49 | 49 | ||
50 | ntpProcess = new OProcess( ); | 50 | ntpProcess = new OProcess( ); |
51 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 51 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
52 | SLOT(slotNtpDelayChanged(int)) ); | 52 | SLOT(slotNtpDelayChanged(int)) ); |
53 | 53 | ||
54 | ntpSock = new QSocket( this ); | 54 | ntpSock = new QSocket( this ); |
55 | connect( ntpSock, SIGNAL( error(int) ), | 55 | connect( ntpSock, SIGNAL( error(int) ), |
56 | SLOT(slotCheckNtp(int)) ); | 56 | SLOT(slotCheckNtp(int)) ); |
57 | slotProbeNtpServer(); | 57 | slotProbeNtpServer(); |
58 | 58 | ||
59 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 59 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
60 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 60 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
61 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 61 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
62 | this, SLOT(ntpFinished(OProcess*))); | 62 | this, SLOT(ntpFinished(OProcess*))); |
63 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 63 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
64 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 64 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
65 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 65 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
66 | slotCheckNtp(-1); | 66 | slotCheckNtp(-1); |
67 | readLookups(); | 67 | readLookups(); |
68 | } | 68 | } |
69 | 69 | ||
70 | Ntp::~Ntp() | 70 | Ntp::~Ntp() |
71 | { | 71 | { |
72 | delete ntpProcess; | 72 | delete ntpProcess; |
73 | Config ntpSrvs("/etc/ntpservers",Config::File); | 73 | Config ntpSrvs("/etc/ntpservers",Config::File); |
74 | ntpSrvs.setGroup("servers"); | 74 | ntpSrvs.setGroup("servers"); |
75 | int srvCount = ComboNtpSrv->count(); | 75 | int srvCount = ComboNtpSrv->count(); |
76 | ntpSrvs.writeEntry("count", srvCount); | 76 | ntpSrvs.writeEntry("count", srvCount); |
77 | for (int i = 0; i < srvCount; i++) | 77 | for (int i = 0; i < srvCount; i++) |
78 | { | 78 | { |
79 | ntpSrvs.setGroup(QString::number(i)); | 79 | ntpSrvs.setGroup(QString::number(i)); |
80 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | 80 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); |
81 | } | 81 | } |
82 | Config cfg("ntp",Config::User); | 82 | Config cfg("ntp",Config::User); |
83 | cfg.setGroup("settings"); | 83 | cfg.setGroup("settings"); |
84 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); | 84 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); |
85 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 85 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
86 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 86 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
87 | } | 87 | } |
88 | 88 | ||
89 | bool Ntp::ntpDelayElapsed() | 89 | bool Ntp::ntpDelayElapsed() |
90 | { | 90 | { |
91 | Config cfg("ntp",Config::User); | 91 | Config cfg("ntp",Config::User); |
92 | cfg.setGroup("lookups"); | 92 | cfg.setGroup("lookups"); |
93 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | 93 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); |
94 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; | 94 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; |
95 | } | 95 | } |
96 | 96 | ||
97 | QString Ntp::getNtpServer() | 97 | QString Ntp::getNtpServer() |
98 | { | 98 | { |
99 | return ComboNtpSrv->currentText(); | 99 | return ComboNtpSrv->currentText(); |
100 | } | 100 | } |
101 | 101 | ||
102 | void Ntp::slotRunNtp() | 102 | void Ntp::slotRunNtp() |
103 | { | 103 | { |
104 | if ( !ntpDelayElapsed() ) | 104 | if ( !ntpDelayElapsed() ) |
105 | { | 105 | { |
106 | switch ( | 106 | switch ( |
107 | QMessageBox::warning(this, tr("Run NTP?"), | 107 | QMessageBox::warning(this, tr("Run NTP?"), |
108 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 108 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
109 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ | 109 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ |
110 | "<br>"+tr("Rerun NTP?"), | 110 | "<br>"+tr("Rerun NTP?"), |
111 | QMessageBox::Ok,QMessageBox::Cancel) | 111 | QMessageBox::Ok,QMessageBox::Cancel) |
112 | ) { | 112 | ) { |
113 | case QMessageBox::Ok: break; | 113 | case QMessageBox::Ok: break; |
114 | case QMessageBox::Cancel: return; | 114 | case QMessageBox::Cancel: return; |
115 | default: return; | 115 | default: return; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 118 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
119 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 119 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
120 | 120 | ||
121 | ntpProcess->clearArguments(); | 121 | ntpProcess->clearArguments(); |
122 | *ntpProcess << "ntpdate" << getNtpServer(); | 122 | *ntpProcess << "ntpdate" << getNtpServer(); |
123 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 123 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
124 | if ( !ret ) { | 124 | if ( !ret ) { |
125 | qDebug("Error while executing ntpdate"); | 125 | qDebug("Error while executing ntpdate"); |
126 | ntpOutPut( tr("Error while executing ntpdate")); | 126 | ntpOutPut( tr("Error while executing ntpdate")); |
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
130 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 130 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
131 | { | 131 | { |
132 | QString lineStr, lineStrOld; | 132 | QString lineStr, lineStrOld; |
133 | lineStr = buffer; | 133 | lineStr = buffer; |
134 | lineStr=lineStr.left(buflen); | 134 | lineStr=lineStr.left(buflen); |
135 | if (lineStr!=lineStrOld) | 135 | if (lineStr!=lineStrOld) |
136 | { | 136 | { |
137 | ntpOutPut(lineStr); | 137 | ntpOutPut(lineStr); |
138 | _ntpOutput += lineStr; | 138 | _ntpOutput += lineStr; |
139 | } | 139 | } |
140 | lineStrOld = lineStr; | 140 | lineStrOld = lineStr; |
141 | } | 141 | } |
142 | 142 | ||
143 | void Ntp::ntpFinished(OProcess *p) | 143 | void Ntp::ntpFinished(OProcess *p) |
144 | { | 144 | { |
145 | qDebug("p->exitStatus() %i",p->exitStatus()); | 145 | qDebug("p->exitStatus() %i",p->exitStatus()); |
146 | if (p->exitStatus()!=0 || !p->normalExit()) | 146 | if (p->exitStatus()!=0 || !p->normalExit()) |
147 | { | 147 | { |
148 | slotProbeNtpServer(); | 148 | slotProbeNtpServer(); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | 151 | ||
152 | Global::writeHWClock(); | 152 | Global::writeHWClock(); |
153 | // since time has changed quickly load in the datebookdb | 153 | // since time has changed quickly load in the datebookdb |
154 | // to allow the alarm server to get a better grip on itself | 154 | // to allow the alarm server to get a better grip on itself |
155 | // (example re-trigger alarms for when we travel back in time) | 155 | // (example re-trigger alarms for when we travel back in time) |
156 | DateBookDB db; | 156 | DateBookDB db; |
157 | 157 | ||
158 | Config cfg("ntp",Config::User); | 158 | Config cfg("ntp",Config::User); |
159 | cfg.setGroup("lookups"); | 159 | cfg.setGroup("lookups"); |
160 | int lastLookup = cfg.readNumEntry("time",0); | 160 | int lastLookup = cfg.readNumEntry("time",0); |
161 | int lookupCount = cfg.readNumEntry("count",0); | 161 | int lookupCount = cfg.readNumEntry("count",0); |
162 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); | 162 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); |
163 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 163 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
164 | cfg.writeEntry("time", time); | 164 | cfg.writeEntry("time", time); |
165 | 165 | ||
166 | float timeShift = getTimeShift(); | 166 | float timeShift = getTimeShift(); |
167 | if (timeShift == 0.0) return; | 167 | if (timeShift == 0.0) return; |
168 | int secsSinceLast = time - lastLookup; | 168 | int secsSinceLast = time - lastLookup; |
169 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 169 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
170 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); | 170 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); |
171 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) | 171 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) |
172 | { | 172 | { |
173 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | 173 | cfg.setGroup("lookup_"+QString::number(lookupCount)); |
174 | lookupCount++; | 174 | lookupCount++; |
175 | _shiftPerSec = timeShift / secsSinceLast; | 175 | _shiftPerSec = timeShift / secsSinceLast; |
176 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); | 176 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); |
177 | cfg.writeEntry("secsSinceLast",secsSinceLast); | 177 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
178 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 178 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
179 | cfg.setGroup("lookups"); | 179 | cfg.setGroup("lookups"); |
180 | cfg.writeEntry("count",lookupCount); | 180 | cfg.writeEntry("count",lookupCount); |
181 | cfg.writeEntry("lastNtp",true); | 181 | cfg.writeEntry("lastNtp",true); |
182 | } | 182 | } |
183 | } | 183 | } |
184 | 184 | ||
185 | 185 | ||
186 | float Ntp::getTimeShift() | 186 | float Ntp::getTimeShift() |
187 | { | 187 | { |
188 | QString _offset = "offset"; | 188 | QString _offset = "offset"; |
189 | QString _sec = "sec"; | 189 | QString _sec = "sec"; |
190 | QRegExp _reOffset = QRegExp(_offset); | 190 | QRegExp _reOffset = QRegExp(_offset); |
191 | QRegExp _reEndOffset = QRegExp(_sec); | 191 | QRegExp _reEndOffset = QRegExp(_sec); |
192 | int posOffset = _reOffset.match( _ntpOutput ); | 192 | int posOffset = _reOffset.match( _ntpOutput ); |
193 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); | 193 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); |
194 | posOffset += _offset.length() + 1; | 194 | posOffset += _offset.length() + 1; |
195 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); | 195 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); |
196 | qDebug("%s", _ntpOutput.latin1()); | 196 | qDebug("%s", _ntpOutput.latin1()); |
197 | qDebug("diff = >%s<",diff.latin1()); | 197 | qDebug("diff = >%s<",diff.latin1()); |
198 | return diff.toFloat(); | 198 | return diff.toFloat(); |
199 | } | 199 | } |
200 | 200 | ||
201 | void Ntp::readLookups() | 201 | void Ntp::readLookups() |
202 | { | 202 | { |
203 | Config cfg("ntp",Config::User); | 203 | Config cfg("ntp",Config::User); |
204 | cfg.setGroup("lookups"); | 204 | cfg.setGroup("lookups"); |
205 | int lookupCount = cfg.readNumEntry("count",0); | 205 | int lookupCount = cfg.readNumEntry("count",0); |
206 | float last, shift, shiftPerSec; | 206 | float last, shift, shiftPerSec; |
207 | qDebug("lookupCount = %i",lookupCount); | 207 | qDebug("lookupCount = %i",lookupCount); |
208 | TableLookups->setNumCols( 3 ); | 208 | TableLookups->setNumCols( 3 ); |
209 | TableLookups->setNumRows( lookupCount); | 209 | TableLookups->setNumRows( lookupCount); |
210 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); | 210 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); |
211 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); | 211 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); |
212 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); | 212 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); |
213 | int cw = TableLookups->width()/4; | 213 | int cw = TableLookups->width()/4; |
214 | qDebug("column width %i",cw); | 214 | qDebug("column width %i",cw); |
215 | cw = 50; | 215 | cw = 50; |
216 | TableLookups->setColumnWidth( 0, cw+30 ); | 216 | TableLookups->setColumnWidth( 0, cw+30 ); |
217 | TableLookups->setColumnWidth( 1, cw ); | 217 | TableLookups->setColumnWidth( 1, cw ); |
218 | TableLookups->setColumnWidth( 2, cw ); | 218 | TableLookups->setColumnWidth( 2, cw ); |
219 | TableLookups->sortColumn(0, false, true ); | 219 | TableLookups->sortColumn(0, false, true ); |
220 | // TableLookups->setSorting( true ); | 220 | // TableLookups->setSorting( true ); |
221 | _shiftPerSec = 0; | 221 | _shiftPerSec = 0; |
222 | for (int i=0; i < lookupCount; i++) | 222 | for (int i=0; i < lookupCount; i++) |
223 | { | 223 | { |
224 | cfg.setGroup("lookup_"+QString::number(i)); | 224 | cfg.setGroup("lookup_"+QString::number(i)); |
225 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 225 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
226 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 226 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
227 | shiftPerSec = shift / last; | 227 | shiftPerSec = shift / last; |
228 | qDebug("%i shift %f",i,shiftPerSec); | 228 | qDebug("%i shift %f",i,shiftPerSec); |
229 | _shiftPerSec += shiftPerSec; | 229 | _shiftPerSec += shiftPerSec; |
230 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); | 230 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); |
231 | TableLookups->setText( i,2,QString::number(shift)); | 231 | TableLookups->setText( i,2,QString::number(shift)); |
232 | TableLookups->setText( i,1,QString::number(last/(60*60))); | 232 | TableLookups->setText( i,1,QString::number(last/(60*60))); |
233 | } | 233 | } |
234 | _shiftPerSec /= lookupCount; | 234 | _shiftPerSec /= lookupCount; |
235 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); | 235 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); |
236 | } | 236 | } |
237 | 237 | ||
238 | void Ntp::preditctTime() | 238 | void Ntp::preditctTime() |
239 | { | 239 | { |
240 | Config cfg("ntp",Config::User); | 240 | Config cfg("ntp",Config::User); |
241 | cfg.setGroup("lookups"); | 241 | cfg.setGroup("lookups"); |
242 | int lastTime = cfg.readNumEntry("time",0); | 242 | int lastTime = cfg.readNumEntry("time",0); |
243 | cfg.writeEntry("lastNtp",true); | 243 | cfg.writeEntry("lastNtp",true); |
244 | setenv( "TZ", tz->currentZone(), 1 ); | 244 | setenv( "TZ", tz->currentZone(), 1 ); |
245 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 245 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
246 | int corr = int((now - lastTime) * _shiftPerSec); | 246 | int corr = int((now - lastTime) * _shiftPerSec); |
247 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 247 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
248 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 248 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
249 | TextLabelPredTime->setText(predictedTime.toString()); | 249 | TextLabelPredTime->setText(predictedTime.toString()); |
250 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 250 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
251 | } | 251 | } |
252 | 252 | ||
253 | void Ntp::setPredictTime() | 253 | void Ntp::setPredictTime() |
254 | { | 254 | { |
255 | preditctTime(); | 255 | preditctTime(); |
256 | setTime( predictedTime ); | 256 | setTime( predictedTime ); |
257 | } | 257 | } |
258 | 258 | ||
259 | void Ntp::slotCheckNtp(int i) | 259 | void Ntp::slotCheckNtp(int i) |
260 | { | 260 | { |
261 | if (i == 0) | 261 | if (i == 0) |
262 | { | 262 | { |
263 | TextLabelMainPredTime->hide(); | 263 | TextLabelMainPredTime->hide(); |
264 | ButtonSetTime->setText( tr("Get time from network") ); | 264 | ButtonSetTime->setText( tr("Get time from network") ); |
265 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 265 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
266 | if ( ntpDelayElapsed() ) | 266 | if ( ntpDelayElapsed() ) |
267 | { | 267 | { |
268 | slotRunNtp(); | 268 | slotRunNtp(); |
269 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 269 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
270 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 270 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); |
271 | }else{ | 271 | }else{ |
272 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 272 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); |
273 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 273 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
274 | } | 274 | } |
275 | }else{ | 275 | }else{ |
276 | preditctTime(); | 276 | preditctTime(); |
277 | ButtonSetTime->setText( tr("Set predicted time") ); | 277 | ButtonSetTime->setText( tr("Set predicted time") ); |
278 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 278 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
279 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 279 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
280 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 280 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
281 | } | 281 | } |
282 | } | 282 | } |
283 | 283 | ||
284 | void Ntp::slotProbeNtpServer() | 284 | void Ntp::slotProbeNtpServer() |
285 | { | 285 | { |
286 | qDebug("Ntp::slotProbeNtpServer()"); | 286 | qDebug("Ntp::slotProbeNtpServer()"); |
287 | ntpSock->connectToHost( getNtpServer() ,123); | 287 | ntpSock->connectToHost( getNtpServer() ,123); |
288 | } | 288 | } |
289 | 289 | ||
290 | void Ntp::slotNtpDelayChanged(int delay) | 290 | void Ntp::slotNtpDelayChanged(int delay) |
291 | { | 291 | { |
292 | ntpTimer->changeInterval( delay*1000*60 ); | 292 | ntpTimer->changeInterval( delay*1000*60 ); |
293 | } | 293 | } |
294 | 294 | ||
295 | void Ntp::ntpOutPut(QString out) | 295 | void Ntp::ntpOutPut(QString out) |
296 | { | 296 | { |
297 | MultiLineEditntpOutPut->append(out); | 297 | MultiLineEditntpOutPut->append(out); |
298 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 298 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
299 | } | 299 | } |
300 | 300 | ||
301 | 301 | ||
302 | void Ntp::makeChannel() | 302 | void Ntp::makeChannel() |
303 | { | 303 | { |
304 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); | 304 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); |
305 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 305 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
306 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 306 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
307 | } | 307 | } |
308 | 308 | ||
309 | 309 | ||
310 | 310 | ||
311 | void Ntp::receive(const QCString &msg, const QByteArray &arg) | 311 | void Ntp::receive(const QCString &msg, const QByteArray &arg) |
312 | { | 312 | { |
313 | qDebug("QCop "+msg+" "+QCString(arg)); | 313 | qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); |
314 | if ( msg == "open(QString)" ) | 314 | if ( msg == "ntpLookup(QString)" ) |
315 | { | 315 | { |
316 | //qApp->exec(); | 316 | slotRunNtp(); |
317 | } | ||
318 | if ( msg == "setPredictedTime(QString)" ) | ||
319 | { | ||
320 | setPredictTime(); | ||
317 | }else{ | 321 | }else{ |
318 | qDebug("Ntp::receive: Huh what do ya want"); | 322 | qDebug("Ntp::receive: Huh what do ya want"); |
319 | } | 323 | } |
320 | } | 324 | } |
321 | 325 | ||
322 | void Ntp::setDocument(const QString &fileName) | 326 | void Ntp::setDocument(const QString &fileName) |
323 | { | 327 | { |
324 | 328 | ||
325 | } \ No newline at end of file | 329 | } \ No newline at end of file |
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp index 9c5323a..b0fcb74 100644 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/noncore/settings/netsystemtime/settime.cpp | |||
@@ -1,499 +1,499 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "settime.h" | 21 | #include "settime.h" |
22 | 22 | ||
23 | #include <qpe/alarmserver.h> | 23 | #include <qpe/alarmserver.h> |
24 | #include <qpe/qpeapplication.h> | 24 | #include <qpe/qpeapplication.h> |
25 | #include <qpe/config.h> | 25 | #include <qpe/config.h> |
26 | #include <qpe/datebookdb.h> | 26 | #include <qpe/datebookdb.h> |
27 | #include <qpe/datebookmonth.h> | 27 | #include <qpe/datebookmonth.h> |
28 | #include <qpe/global.h> | 28 | #include <qpe/global.h> |
29 | #include <qpe/resource.h> | 29 | #include <qpe/resource.h> |
30 | #include <qpe/timeconversion.h> | 30 | #include <qpe/timeconversion.h> |
31 | #include <qpe/tzselect.h> | 31 | #include <qpe/tzselect.h> |
32 | #include <qpe/timestring.h> | 32 | #include <qpe/timestring.h> |
33 | #include <qpe/qpedialog.h> | 33 | #include <qpe/qpedialog.h> |
34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
35 | #include <qpe/qcopenvelope_qws.h> | 35 | #include <qpe/qcopenvelope_qws.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include <qbuttongroup.h> | 38 | #include <qbuttongroup.h> |
39 | #include <qcheckbox.h> | 39 | #include <qcheckbox.h> |
40 | #include <qlabel.h> | 40 | #include <qlabel.h> |
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); | 233 | Config cfg("ntp",Config::User); |
234 | cfg.setGroup("lookups"); | 234 | cfg.setGroup("lookups"); |
235 | cfg.writeEntry("lastNtp",false); | 235 | cfg.writeEntry("lastNtp",false); |
236 | tz->setFocus(); | 236 | tz->setFocus(); |
237 | // Need to process the QCOP event generated above before proceeding | 237 | // Need to process the QCOP event generated above before proceeding |
238 | qApp->processEvents(); | 238 | qApp->processEvents(); |
239 | 239 | ||
240 | // before we progress further, set our TZ! | 240 | // before we progress further, set our TZ! |
241 | setenv( "TZ", tz->currentZone(), 1 ); | 241 | setenv( "TZ", tz->currentZone(), 1 ); |
242 | // now set the time... | 242 | // now set the time... |
243 | QDateTime dt( dateButton->date(), timeButton->time() ); | 243 | QDateTime dt( dateButton->date(), timeButton->time() ); |
244 | 244 | ||
245 | if ( dt.isValid() ) setTime(dt); | 245 | if ( dt.isValid() ) setTime(dt); |
246 | } | 246 | } |
247 | 247 | ||
248 | void SetDateTime::setTime(QDateTime dt) | 248 | void SetDateTime::setTime(QDateTime dt) |
249 | { | 249 | { |
250 | // really turn off the screensaver before doing anything | 250 | // really turn off the screensaver before doing anything |
251 | { | 251 | { |
252 | // Needs to be encased in { } so that it deconstructs and sends | 252 | // Needs to be encased in { } so that it deconstructs and sends |
253 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 253 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
254 | disableScreenSaver << 0 << 0 << 0; | 254 | disableScreenSaver << 0 << 0 << 0; |
255 | } | 255 | } |
256 | Config cfg("ntp",Config::User); | 256 | Config cfg("ntp",Config::User); |
257 | cfg.setGroup("correction"); | 257 | cfg.setGroup("correction"); |
258 | int t = TimeConversion::toUTC(dt); | 258 | int t = TimeConversion::toUTC(dt); |
259 | struct timeval myTv; | 259 | struct timeval myTv; |
260 | myTv.tv_sec = t; | 260 | myTv.tv_sec = t; |
261 | cfg.writeEntry("time", t ); | 261 | cfg.writeEntry("time", t ); |
262 | myTv.tv_usec = 0; | 262 | myTv.tv_usec = 0; |
263 | 263 | ||
264 | if ( myTv.tv_sec != -1 ) | 264 | if ( myTv.tv_sec != -1 ) |
265 | ::settimeofday( &myTv, 0 ); | 265 | ::settimeofday( &myTv, 0 ); |
266 | Global::writeHWClock(); | 266 | Global::writeHWClock(); |
267 | // since time has changed quickly load in the datebookdb | 267 | // since time has changed quickly load in the datebookdb |
268 | // 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 |
269 | // (example re-trigger alarms for when we travel back in time) | 269 | // (example re-trigger alarms for when we travel back in time) |
270 | DateBookDB db; | 270 | DateBookDB db; |
271 | // Restore screensaver | 271 | // Restore screensaver |
272 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 272 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
273 | enableScreenSaver << -1 << -1 << -1; | 273 | enableScreenSaver << -1 << -1 << -1; |
274 | } | 274 | } |
275 | 275 | ||
276 | void SetDateTime::updateSystem(int i) | 276 | void SetDateTime::updateSystem(int i) |
277 | { | 277 | { |
278 | // really turn off the screensaver before doing anything | 278 | // really turn off the screensaver before doing anything |
279 | { | 279 | { |
280 | // Needs to be encased in { } so that it deconstructs and sends | 280 | // Needs to be encased in { } so that it deconstructs and sends |
281 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 281 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
282 | disableScreenSaver << 0 << 0 << 0; | 282 | disableScreenSaver << 0 << 0 << 0; |
283 | } | 283 | } |
284 | qDebug("SetDateTime::updateSystem(int %i)",i); | 284 | qDebug("SetDateTime::updateSystem(int %i)",i); |
285 | writeSettings(); | 285 | writeSettings(); |
286 | 286 | ||
287 | // set the timezone for everyone else... | 287 | // set the timezone for everyone else... |
288 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | 288 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); |
289 | setTimeZone << tz->currentZone(); | 289 | setTimeZone << tz->currentZone(); |
290 | 290 | ||
291 | // AM/PM setting and notify time changed | 291 | // AM/PM setting and notify time changed |
292 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); | 292 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); |
293 | setClock << ampmCombo->currentItem(); | 293 | setClock << ampmCombo->currentItem(); |
294 | 294 | ||
295 | // Notify everyone what day we prefer to start the week on. | 295 | // Notify everyone what day we prefer to start the week on. |
296 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); | 296 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); |
297 | setWeek << weekStartCombo->currentItem(); | 297 | setWeek << weekStartCombo->currentItem(); |
298 | 298 | ||
299 | // Notify everyone what date format to use | 299 | // Notify everyone what date format to use |
300 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); | 300 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); |
301 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; | 301 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; |
302 | 302 | ||
303 | // Restore screensaver | 303 | // Restore screensaver |
304 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 304 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
305 | enableScreenSaver << -1 << -1 << -1; | 305 | enableScreenSaver << -1 << -1 << -1; |
306 | // since time has changed quickly load in the datebookdb | 306 | // since time has changed quickly load in the datebookdb |
307 | // 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 |
308 | // (example re-trigger alarms for when we travel back in time) | 308 | // (example re-trigger alarms for when we travel back in time) |
309 | DateBookDB db; | 309 | DateBookDB db; |
310 | 310 | ||
311 | } | 311 | } |
312 | 312 | ||
313 | void SetDateTime::tzChange( const QString &tz ) | 313 | void SetDateTime::tzChange( const QString &tz ) |
314 | { | 314 | { |
315 | // set the TZ get the time and leave gracefully... | 315 | // set the TZ get the time and leave gracefully... |
316 | QString strSave; | 316 | QString strSave; |
317 | strSave = getenv( "TZ" ); | 317 | strSave = getenv( "TZ" ); |
318 | setenv( "TZ", tz, 1 ); | 318 | setenv( "TZ", tz, 1 ); |
319 | 319 | ||
320 | QDate d = QDate::currentDate(); | 320 | QDate d = QDate::currentDate(); |
321 | // reset the time. | 321 | // reset the time. |
322 | if ( !strSave.isNull() ) { | 322 | if ( !strSave.isNull() ) { |
323 | setenv( "TZ", strSave, 1 ); | 323 | setenv( "TZ", strSave, 1 ); |
324 | } | 324 | } |
325 | dateButton->setDate( d ); | 325 | dateButton->setDate( d ); |
326 | updateSystem(); | 326 | updateSystem(); |
327 | } | 327 | } |
328 | 328 | ||
329 | void SetDateTime::formatChanged(int i) | 329 | void SetDateTime::formatChanged(int i) |
330 | { | 330 | { |
331 | dateButton->setDateFormat(date_formats[i]); | 331 | dateButton->setDateFormat(date_formats[i]); |
332 | } | 332 | } |
333 | 333 | ||
334 | static const int ValueAM = 0; | 334 | static const int ValueAM = 0; |
335 | static const int ValuePM = 1; | 335 | static const int ValuePM = 1; |
336 | 336 | ||
337 | 337 | ||
338 | 338 | ||
339 | SetTime::SetTime( QWidget *parent, const char *name ) | 339 | SetTime::SetTime( QWidget *parent, const char *name ) |
340 | : QWidget( parent, name ) | 340 | : QWidget( parent, name ) |
341 | { | 341 | { |
342 | use12hourTime = FALSE; | 342 | use12hourTime = FALSE; |
343 | 343 | ||
344 | QTime currTime = QTime::currentTime(); | 344 | QTime currTime = QTime::currentTime(); |
345 | hour = currTime.hour(); | 345 | hour = currTime.hour(); |
346 | minute = currTime.minute(); | 346 | minute = currTime.minute(); |
347 | 347 | ||
348 | QHBoxLayout *hb2 = new QHBoxLayout( this ); | 348 | QHBoxLayout *hb2 = new QHBoxLayout( this ); |
349 | hb2->setSpacing( 3 ); | 349 | hb2->setSpacing( 3 ); |
350 | 350 | ||
351 | QLabel *l = new QLabel( tr("Hour"), this ); | 351 | QLabel *l = new QLabel( tr("Hour"), this ); |
352 | // l->setAlignment( AlignRight | AlignVCenter ); | 352 | // l->setAlignment( AlignRight | AlignVCenter ); |
353 | hb2->addWidget( l ); | 353 | hb2->addWidget( l ); |
354 | 354 | ||
355 | sbHour = new QSpinBox( this ); | 355 | sbHour = new QSpinBox( this ); |
356 | sbHour->setMinimumWidth( 30 ); | 356 | sbHour->setMinimumWidth( 30 ); |
357 | if(use12hourTime) { | 357 | if(use12hourTime) { |
358 | sbHour->setMinValue(1); | 358 | sbHour->setMinValue(1); |
359 | sbHour->setMaxValue( 12 ); | 359 | sbHour->setMaxValue( 12 ); |
360 | int show_hour = hour; | 360 | int show_hour = hour; |
361 | if (hour > 12) | 361 | if (hour > 12) |
362 | show_hour -= 12; | 362 | show_hour -= 12; |
363 | if (show_hour == 0) | 363 | if (show_hour == 0) |
364 | show_hour = 12; | 364 | show_hour = 12; |
365 | 365 | ||
366 | sbHour->setValue( show_hour ); | 366 | sbHour->setValue( show_hour ); |
367 | } else { | 367 | } else { |
368 | sbHour->setMinValue( 0 ); | 368 | sbHour->setMinValue( 0 ); |
369 | sbHour->setMaxValue( 23 ); | 369 | sbHour->setMaxValue( 23 ); |
370 | sbHour->setValue( hour ); | 370 | sbHour->setValue( hour ); |
371 | } | 371 | } |
372 | sbHour->setWrapping(TRUE); | 372 | sbHour->setWrapping(TRUE); |
373 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); | 373 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); |
374 | hb2->addWidget( sbHour ); | 374 | hb2->addWidget( sbHour ); |
375 | 375 | ||
376 | hb2->addStretch( 1 ); | 376 | hb2->addStretch( 1 ); |
377 | 377 | ||
378 | l = new QLabel( tr("Minute"), this ); | 378 | l = new QLabel( tr("Minute"), this ); |
379 | //l->setAlignment( AlignRight | AlignVCenter ); | 379 | //l->setAlignment( AlignRight | AlignVCenter ); |
380 | hb2->addWidget( l ); | 380 | hb2->addWidget( l ); |
381 | 381 | ||
382 | sbMin = new QSpinBox( this ); | 382 | sbMin = new QSpinBox( this ); |
383 | sbMin->setMinValue( 0 ); | 383 | sbMin->setMinValue( 0 ); |
384 | sbMin->setMaxValue( 59 ); | 384 | sbMin->setMaxValue( 59 ); |
385 | sbMin->setWrapping(TRUE); | 385 | sbMin->setWrapping(TRUE); |
386 | sbMin->setValue( minute ); | 386 | sbMin->setValue( minute ); |
387 | sbMin->setMinimumWidth( 30 ); | 387 | sbMin->setMinimumWidth( 30 ); |
388 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); | 388 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); |
389 | hb2->addWidget( sbMin ); | 389 | hb2->addWidget( sbMin ); |
390 | 390 | ||
391 | hb2->addStretch( 1 ); | 391 | hb2->addStretch( 1 ); |
392 | 392 | ||
393 | ampm = new QComboBox( this ); | 393 | ampm = new QComboBox( this ); |
394 | ampm->insertItem( tr("AM"), ValueAM ); | 394 | ampm->insertItem( tr("AM"), ValueAM ); |
395 | ampm->insertItem( tr("PM"), ValuePM ); | 395 | ampm->insertItem( tr("PM"), ValuePM ); |
396 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); | 396 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); |
397 | hb2->addWidget( ampm ); | 397 | hb2->addWidget( ampm ); |
398 | 398 | ||
399 | hb2->addStretch( 1 ); | 399 | hb2->addStretch( 1 ); |
400 | 400 | ||
401 | } | 401 | } |
402 | 402 | ||
403 | QTime SetTime::time() const | 403 | QTime SetTime::time() const |
404 | { | 404 | { |
405 | return QTime( hour, minute, 0 ); | 405 | return QTime( hour, minute, 0 ); |
406 | } | 406 | } |
407 | 407 | ||
408 | void SetTime::hourChanged( int value ) | 408 | void SetTime::hourChanged( int value ) |
409 | { | 409 | { |
410 | if(use12hourTime) { | 410 | if(use12hourTime) { |
411 | int realhour = value; | 411 | int realhour = value; |
412 | if (realhour == 12) | 412 | if (realhour == 12) |
413 | realhour = 0; | 413 | realhour = 0; |
414 | if (ampm->currentItem() == ValuePM ) | 414 | if (ampm->currentItem() == ValuePM ) |
415 | realhour += 12; | 415 | realhour += 12; |
416 | hour = realhour; | 416 | hour = realhour; |
417 | } else | 417 | } else |
418 | hour = value; | 418 | hour = value; |
419 | } | 419 | } |
420 | 420 | ||
421 | void SetTime::minuteChanged( int value ) | 421 | void SetTime::minuteChanged( int value ) |
422 | { | 422 | { |
423 | minute = value; | 423 | minute = value; |
424 | } | 424 | } |
425 | 425 | ||
426 | void SetTime::show12hourTime( int on ) | 426 | void SetTime::show12hourTime( int on ) |
427 | { | 427 | { |
428 | use12hourTime = on; | 428 | use12hourTime = on; |
429 | ampm->setEnabled(on); | 429 | ampm->setEnabled(on); |
430 | 430 | ||
431 | int show_hour = hour; | 431 | int show_hour = hour; |
432 | if ( on ) { | 432 | if ( on ) { |
433 | /* this might change the value of hour */ | 433 | /* this might change the value of hour */ |
434 | sbHour->setMinValue(1); | 434 | sbHour->setMinValue(1); |
435 | sbHour->setMaxValue( 12 ); | 435 | sbHour->setMaxValue( 12 ); |
436 | 436 | ||
437 | /* so use one we saved earlier */ | 437 | /* so use one we saved earlier */ |
438 | if (show_hour >= 12) { | 438 | if (show_hour >= 12) { |
439 | show_hour -= 12; | 439 | show_hour -= 12; |
440 | ampm->setCurrentItem( ValuePM ); | 440 | ampm->setCurrentItem( ValuePM ); |
441 | } else { | 441 | } else { |
442 | ampm->setCurrentItem( ValueAM ); | 442 | ampm->setCurrentItem( ValueAM ); |
443 | } | 443 | } |
444 | if (show_hour == 0) | 444 | if (show_hour == 0) |
445 | show_hour = 12; | 445 | show_hour = 12; |
446 | 446 | ||
447 | } else { | 447 | } else { |
448 | sbHour->setMinValue( 0 ); | 448 | sbHour->setMinValue( 0 ); |
449 | sbHour->setMaxValue( 23 ); | 449 | sbHour->setMaxValue( 23 ); |
450 | } | 450 | } |
451 | 451 | ||
452 | 452 | ||
453 | sbHour->setValue( show_hour ); | 453 | sbHour->setValue( show_hour ); |
454 | } | 454 | } |
455 | 455 | ||
456 | void SetTime::checkedPM( int c ) | 456 | void SetTime::checkedPM( int c ) |
457 | { | 457 | { |
458 | int show_hour = sbHour->value(); | 458 | int show_hour = sbHour->value(); |
459 | if (show_hour == 12) | 459 | if (show_hour == 12) |
460 | show_hour = 0; | 460 | show_hour = 0; |
461 | 461 | ||
462 | if ( c == ValuePM ) | 462 | if ( c == ValuePM ) |
463 | show_hour += 12; | 463 | show_hour += 12; |
464 | 464 | ||
465 | hour = show_hour; | 465 | hour = show_hour; |
466 | } | 466 | } |
467 | 467 | ||
468 | void SetTime::slotTzChange( const QString &tz ) | 468 | void SetTime::slotTzChange( const QString &tz ) |
469 | { | 469 | { |
470 | // set the TZ get the time and leave gracefully... | 470 | // set the TZ get the time and leave gracefully... |
471 | QString strSave; | 471 | QString strSave; |
472 | strSave = getenv( "TZ" ); | 472 | strSave = getenv( "TZ" ); |
473 | setenv( "TZ", tz, 1 ); | 473 | setenv( "TZ", tz, 1 ); |
474 | 474 | ||
475 | QTime t = QTime::currentTime(); | 475 | QTime t = QTime::currentTime(); |
476 | // reset the time. | 476 | // reset the time. |
477 | if ( !strSave.isNull() ) { | 477 | if ( !strSave.isNull() ) { |
478 | setenv( "TZ", strSave, 1 ); | 478 | setenv( "TZ", strSave, 1 ); |
479 | } | 479 | } |
480 | 480 | ||
481 | // just set the spinboxes and let it propage through | 481 | // just set the spinboxes and let it propage through |
482 | if(use12hourTime) { | 482 | if(use12hourTime) { |
483 | int show_hour = t.hour(); | 483 | int show_hour = t.hour(); |
484 | if (t.hour() >= 12) { | 484 | if (t.hour() >= 12) { |
485 | show_hour -= 12; | 485 | show_hour -= 12; |
486 | ampm->setCurrentItem( ValuePM ); | 486 | ampm->setCurrentItem( ValuePM ); |
487 | } else { | 487 | } else { |
488 | ampm->setCurrentItem( ValueAM ); | 488 | ampm->setCurrentItem( ValueAM ); |
489 | } | 489 | } |
490 | if (show_hour == 0) | 490 | if (show_hour == 0) |
491 | show_hour = 12; | 491 | show_hour = 12; |
492 | sbHour->setValue( show_hour ); | 492 | sbHour->setValue( show_hour ); |
493 | } else { | 493 | } else { |
494 | sbHour->setValue( t.hour() ); | 494 | sbHour->setValue( t.hour() ); |
495 | } | 495 | } |
496 | sbMin->setValue( t.minute() ); | 496 | sbMin->setValue( t.minute() ); |
497 | } | 497 | } |
498 | 498 | ||
499 | 499 | ||