summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/ntp.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/netsystemtime/ntp.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index c7e3b52..53dbe46 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -47,25 +47,24 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) );
ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
//make tab order
TabWidgetMain->removePage( tabMain );
TabWidgetMain->removePage( tabManualSetTime );
TabWidgetMain->removePage( TabSettings );
TabWidgetMain->removePage( tabPredict );
TabWidgetMain->removePage( tabNtp );
TabWidgetMain->insertTab( tabMain, tr( "Main" ) );
- TabWidgetMain->insertTab( tabManualSetTime, tr( "Manual" ) );
TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) );
TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) );
TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) );
NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 );
bool advMode = cfg.readBoolEntry("advancedFeatures", false );
showAdvancedFeatures(advMode);
CheckBoxAdvSettings->setChecked( advMode );
connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ),
SLOT( showAdvancedFeatures( bool ) ) );
@@ -87,24 +86,27 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
this, SLOT(ntpFinished(OProcess*)));
connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp()));
connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
slotCheckNtp(-1);
readLookups();
}
Ntp::~Ntp()
{
delete ntpProcess;
+}
+
+void Ntp::saveConfig(){
int srvCount = ComboNtpSrv->count();
bool serversChanged = true;
QString edit = ComboNtpSrv->currentText();
for (int i = 0; i < srvCount; i++){
if ( edit == ComboNtpSrv->text(i)) serversChanged = false;
}
if (serversChanged){
Config ntpSrvs("/etc/ntpservers",Config::File);
ntpSrvs.setGroup("servers");
ntpSrvs.writeEntry("count", srvCount);
for (int i = 0; i < srvCount; i++){
qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1());
@@ -190,39 +192,29 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
_ntpOutput += lineStr;
}
lineStrOld = lineStr;
}
void Ntp::ntpFinished(OProcess *p)
{
qDebug("p->exitStatus() %i",p->exitStatus());
if (p->exitStatus()!=0 || !p->normalExit())
{
if ( isVisible() && _interactive ){
QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput );
- TabWidgetMain->showPage( tabManualSetTime );
}
-
+// slotCheckNtp(-1);
return;
}
- Global::writeHWClock();
- // since time has changed quickly load in the datebookdb
- // to allow the alarm server to get a better grip on itself
- // (example re-trigger alarms for when we travel back in time)
- DateBookDB db;
-
- // QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" );
- // timeApplet << "";
-
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);
float timeShift = getTimeShift();
if (timeShift == 0.0) return;
int secsSinceLast = time - lastLookup;
TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
@@ -297,38 +289,40 @@ void Ntp::readLookups()
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>");
+// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
}
void Ntp::setPredictTime()
{
+ qDebug("Ntp::setPredictTime");
preditctTime();
- setTime( predictedTime );
+ timeButton->setTime( predictedTime );
}
void Ntp::slotCheckNtp(int i)
{
+ qDebug(" Ntp::slotCheckNtp(%i)",i);
if (i == 0)
{
- TextLabelMainPredTime->hide();
+// TextLabelMainPredTime->hide();
ButtonSetTime->setText( tr("Get time from network") );
connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) );
if ( ntpDelayElapsed() )
{
slotRunNtp();
disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) );
}else{
disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) );
connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
}
}else{
@@ -409,12 +403,24 @@ void Ntp::showAdvancedFeatures(bool advMode)
TextLabel1_2_2->hide();
TextLabel2_3->hide();
TextLabel3_3_2->hide();
TextLabel1_2->hide();
SpinBoxMinLookupDelay->hide();
TextLabel2->hide();
TextLabel3_3->hide();
SpinBoxNtpDelay->hide();
Line1->hide();
};
TabWidgetMain->show();
}
+
+
+void Ntp::accept( ){
+ qDebug("accepted");
+ //SetTimeDate
+ commitTime();
+ writeSettings();
+ updateSystem();
+ // Ntp
+ saveConfig();
+ qApp->quit();
+} \ No newline at end of file