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