author | tille <tille> | 2002-11-16 13:34:04 (UTC) |
---|---|---|
committer | tille <tille> | 2002-11-16 13:34:04 (UTC) |
commit | 91b18bba79406b6ff54ca7f1360035eceefee378 (patch) (side-by-side diff) | |
tree | 92035493670bd6ffed38b445ab3f6003954c3ae5 | |
parent | 9591a32654e5189841b9a6d60e7bf235b1b0fa4b (diff) | |
download | opie-91b18bba79406b6ff54ca7f1360035eceefee378.zip opie-91b18bba79406b6ff54ca7f1360035eceefee378.tar.gz opie-91b18bba79406b6ff54ca7f1360035eceefee378.tar.bz2 |
fixes:
- saving of ntpservers
- poping up of messagebox
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 43 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 4 |
2 files changed, 34 insertions, 13 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 6e74e32..c7e3b52 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp @@ -21,24 +21,25 @@ #include <qpe/timestring.h> #include <qpe/qpedialog.h> #include <qpe/datebookdb.h> #include <qpe/qcopenvelope_qws.h> #include <sys/time.h> #include <time.h> #include <stdlib.h> Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) : SetDateTime( parent, name, fl ) { + _interactive = false; Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); ntpSrvs.setGroup("servers"); int srvCount = ntpSrvs.readNumEntry("count", 0 ); for (int i = 0; i < srvCount; i++) { ntpSrvs.setGroup(QString::number(i)); ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); } if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); Config cfg("ntp",Config::User); cfg.setGroup("settings"); @@ -69,73 +70,93 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), SLOT( showAdvancedFeatures( bool ) ) ); makeChannel(); ntpTimer = new QTimer(this); ntpProcess = new OProcess( ); connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), SLOT(slotNtpDelayChanged(int)) ); ntpSock = new QSocket( this ); - connect( ntpSock, SIGNAL( error(int) ), - SLOT(slotCheckNtp(int)) ); + connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) ); slotProbeNtpServer(); connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), this, SLOT(getNtpOutput(OProcess*,char*,int))); connect ( ntpProcess, SIGNAL(processExited(OProcess*)), this, SLOT(ntpFinished(OProcess*))); - connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); + 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; + 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"); - int srvCount = ComboNtpSrv->count(); ntpSrvs.writeEntry("count", srvCount); for (int i = 0; i < srvCount; i++){ + qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); ntpSrvs.setGroup(QString::number(i)); ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); } + } Config cfg("ntp",Config::User); cfg.setGroup("settings"); cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); } bool Ntp::ntpDelayElapsed() { Config cfg("ntp",Config::User); cfg.setGroup("lookups"); _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); if (_lookupDiff < 0) return true; int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); return i > -60; } QString Ntp::getNtpServer() { return ComboNtpSrv->currentText(); } +void Ntp::slotButtonRunNtp() +{ + _interactive = true; + slotRunNtp(); +} + +void Ntp::slotTimerRunNtp() +{ + _interactive = false; + slotRunNtp(); +} + + void Ntp::slotRunNtp() { if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) { switch ( QMessageBox::warning(this, tr("Run NTP?"), tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ "<br>"+tr("Rerun NTP?"), QMessageBox::Ok,QMessageBox::Cancel) ) { case QMessageBox::Ok: break; @@ -167,29 +188,26 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) { ntpOutPut(lineStr); _ntpOutput += lineStr; } lineStrOld = lineStr; } void Ntp::ntpFinished(OProcess *p) { qDebug("p->exitStatus() %i",p->exitStatus()); if (p->exitStatus()!=0 || !p->normalExit()) { - if ( isVisible() ) { - QMessageBox::critical(this, tr("ntp error"), - tr("Error while getting time form\n server")+ - getNtpServer()+"\n"+ - _ntpOutput ); + if ( isVisible() && _interactive ){ + QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); TabWidgetMain->showPage( tabManualSetTime ); } 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; @@ -294,32 +312,32 @@ void Ntp::preditctTime() 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()) ); + connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) ); if ( ntpDelayElapsed() ) { slotRunNtp(); disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); - connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); + connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); }else{ - disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); + disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); } }else{ preditctTime(); ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); } } void Ntp::slotProbeNtpServer() @@ -345,24 +363,25 @@ void Ntp::makeChannel() channel = new QCopChannel( "QPE/Application/netsystemtime", this ); connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), this, SLOT(receive(const QCString&, const QByteArray&)) ); } void Ntp::receive(const QCString &msg, const QByteArray &arg) { qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); if ( msg == "ntpLookup(QString)" ) { + _interactive = false; slotRunNtp(); } if ( msg == "setPredictedTime(QString)" ) { setPredictTime(); }else{ qDebug("Ntp::receive: Huh what do ya want"); } } void Ntp::setDocument(const QString &fileName) { diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index f6694c9..15cddbd 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h @@ -23,31 +23,33 @@ protected: QDateTime predictedTime; void makeChannel(); protected slots: void receive(const QCString &msg, const QByteArray &arg); private: QString _ntpOutput; float _shiftPerSec; int _lookupDiff; OProcess *ntpProcess; QTimer *ntpTimer; QSocket *ntpSock; QCopChannel *channel; - + bool _interactive; float getTimeShift(); void readLookups(); void ntpOutPut(QString); bool ntpDelayElapsed(); QString getNtpServer(); private slots: + void slotTimerRunNtp(); + void slotButtonRunNtp(); void slotRunNtp(); void getNtpOutput(OProcess *proc, char *buffer, int buflen); void ntpFinished(OProcess*); void preditctTime(); void slotCheckNtp(int); void setPredictTime(); void showAdvancedFeatures(bool); void slotProbeNtpServer(); void slotNtpDelayChanged(int); }; #endif |