summaryrefslogtreecommitdiff
path: root/noncore
Side-by-side diff
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp9
-rw-r--r--noncore/settings/netsystemtime/settime.cpp3
2 files changed, 8 insertions, 4 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 830c0c3..7971f9a 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -127,67 +127,67 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
{
QString lineStr, lineStrOld;
lineStr = buffer;
lineStr=lineStr.left(buflen);
if (lineStr!=lineStrOld)
{
ntpOutPut(lineStr);
_ntpOutput += lineStr;
}
lineStrOld = lineStr;
}
void Ntp::ntpFinished(OProcess *p)
{
qDebug("p->exitStatus() %i",p->exitStatus());
if (p->exitStatus()!=0 || !p->normalExit())
{
slotProbeNtpServer();
return;
}
Config cfg("ntp",Config::User);
cfg.setGroup("lookups");
int lastLookup = cfg.readNumEntry("time",0);
int lookupCount = cfg.readNumEntry("count",0);
+ bool lastNtp = cfg.readBoolEntry("lastNtp",false);
int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
cfg.writeEntry("time", time);
- cfg.setGroup("correction");
- cfg.writeEntry("time", time);
float timeShift = getTimeShift();
if (timeShift == 0.0) return;
int secsSinceLast = time - lastLookup;
TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
- if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
+ if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
{
+ cfg.setGroup("lookup_"+QString::number(lookupCount));
lookupCount++;
cfg.writeEntry("count",lookupCount);
- cfg.setGroup("lookup_"+QString::number(lookupCount));
_shiftPerSec = timeShift / secsSinceLast;
qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
cfg.writeEntry("secsSinceLast",secsSinceLast);
cfg.writeEntry("timeShift",QString::number(timeShift));
+ cfg.writeEntry("lastNtp",true);
}
}
float Ntp::getTimeShift()
{
QString _offset = "offset";
QString _sec = "sec";
QRegExp _reOffset = QRegExp(_offset);
QRegExp _reEndOffset = QRegExp(_sec);
int posOffset = _reOffset.match( _ntpOutput );
int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
posOffset += _offset.length() + 1;
QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
qDebug("%s", _ntpOutput.latin1());
qDebug("diff = >%s<",diff.latin1());
return diff.toFloat();
}
void Ntp::readLookups()
{
Config cfg("ntp",Config::User);
cfg.setGroup("lookups");
int lookupCount = cfg.readNumEntry("count",0);
@@ -207,48 +207,49 @@ void Ntp::readLookups()
TableLookups->sortColumn(0, false, true );
// TableLookups->setSorting( true );
for (int i=0; i < lookupCount; i++)
{
cfg.setGroup("lookup_"+QString::number(i));
last = cfg.readEntry("secsSinceLast",0).toFloat();
shift = QString(cfg.readEntry("timeShift",0)).toFloat();
// qDebug("%i last %f",i,last);
// qDebug("%i shift %f",i,shift);
shiftPerSec = shift / last;
_shiftPerSec += shiftPerSec;
TableLookups->setText( i,0,QString::number(shiftPerSec*60*60));
TableLookups->setText( i,2,QString::number(shift));
TableLookups->setText( i,1,QString::number(last/(60*60)));
}
_shiftPerSec /= lookupCount;
TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h"));
}
void Ntp::preditctTime()
{
Config cfg("ntp",Config::User);
cfg.setGroup("lookups");
int lastTime = cfg.readNumEntry("time",0);
+ cfg.writeEntry("lastNtp",true);
setenv( "TZ", tz->currentZone(), 1 );
int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
int corr = int((now - lastTime) * _shiftPerSec);
TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
predictedTime = QDateTime::currentDateTime().addSecs(corr);
TextLabelPredTime->setText(predictedTime.toString());
TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
}
void Ntp::setPredictTime()
{
preditctTime();
setTime( predictedTime );
}
void Ntp::slotCheckNtp(int i)
{
if (i == 0)
{
TextLabelMainPredTime->hide();
ButtonSetTime->setText( tr("Get time from network") );
connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
if ( ntpDelayElapsed() )
{
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp
index e7e604f..9c5323a 100644
--- a/noncore/settings/netsystemtime/settime.cpp
+++ b/noncore/settings/netsystemtime/settime.cpp
@@ -209,48 +209,51 @@ SetDateTime::~SetDateTime()
}
void SetDateTime::writeSettings()
{
Config config("qpe");
config.setGroup( "Time" );
config.writeEntry( "AMPM", ampmCombo->currentItem() );
config.writeEntry( "MONDAY", weekStartCombo->currentItem() );
config.setGroup( "Date" );
DateFormat df = date_formats[dateFormatCombo->currentItem()];
config.writeEntry( "Separator", QString(df.separator()));
config.writeEntry( "ShortOrder", df.shortOrder());
config.writeEntry( "LongOrder", df.longOrder());
config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() );
Config lconfig("locale");
lconfig.setGroup( "Location" );
lconfig.writeEntry( "Timezone", tz->currentZone() );
}
void SetDateTime::commitTime()
{
+ Config cfg("ntp",Config::User);
+ cfg.setGroup("lookups");
+ cfg.writeEntry("lastNtp",false);
tz->setFocus();
// Need to process the QCOP event generated above before proceeding
qApp->processEvents();
// before we progress further, set our TZ!
setenv( "TZ", tz->currentZone(), 1 );
// now set the time...
QDateTime dt( dateButton->date(), timeButton->time() );
if ( dt.isValid() ) setTime(dt);
}
void SetDateTime::setTime(QDateTime dt)
{
// really turn off the screensaver before doing anything
{
// Needs to be encased in { } so that it deconstructs and sends
QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
disableScreenSaver << 0 << 0 << 0;
}
Config cfg("ntp",Config::User);
cfg.setGroup("correction");
int t = TimeConversion::toUTC(dt);
struct timeval myTv;