summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp50
-rw-r--r--noncore/settings/netsystemtime/ntp.h4
-rw-r--r--noncore/settings/netsystemtime/settime.cpp24
-rw-r--r--noncore/settings/netsystemtime/settime.h1
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
@@ -27,18 +27,18 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
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
41Ntp::~Ntp() 41Ntp::~Ntp()
42{ 42{
43 43
44} 44}
@@ -78,16 +78,18 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
78void Ntp::ntpFinished(OProcess*) 78void 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++;
@@ -96,34 +98,38 @@ void Ntp::ntpFinished(OProcess*)
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
104void 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
123float Ntp::getTimeShift() 129float 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 );
@@ -174,10 +180,12 @@ 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
@@ -20,22 +20,22 @@ public:
20 20
21protected: 21protected:
22 virtual void accept(); 22 virtual void accept();
23 23
24private: 24private:
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();
33private slots: 33private 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
@@ -203,50 +203,52 @@ void SetDateTime::accept()
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
209void SetDateTime::commitTime() 209void 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; 229void 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
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
@@ -71,16 +71,17 @@ 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
73protected slots: 73protected slots:
74 void tzChange( const QString &tz ); 74 void tzChange( const QString &tz );
75 void formatChanged(int); 75 void formatChanged(int);
76 76
77protected: 77protected:
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;