-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 77 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 13 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.ui | 167 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 27 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.h | 10 |
5 files changed, 210 insertions, 84 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 87b20ec..4a7959e 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp @@ -4,5 +4,7 @@ #include <qtable.h> #include <qlabel.h> +#include <qsocket.h> #include <qlineedit.h> +#include <qspinbox.h> #include <qmultilineedit.h> #include <opie/oprocess.h> @@ -23,8 +25,16 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) Config cfg("ntp",Config::User); cfg.setGroup("settings"); - _maxOffset = cfg.readNumEntry("maxOffset",5); - _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); - LineEditNtpServer->setText( cfg.readEntry("ntpServer") ); +// _maxOffset = cfg.readNumEntry("maxOffset",5); +// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); + SpinBoxMinDelay->setValue( cfg.readNumEntry("minLookupDiff",10) ); + SpinBoxMinDelay->setMinValue( 7 ); + LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) ); ntpProcess = new OProcess( ); + + QSocket *ntpSock = new QSocket( this ); + ntpSock->connectToHost( LineEditNtpSrv->text() ,123); + connect( ntpSock, SIGNAL( error(int) ), + SLOT(slotCheckNtp(int)) ); + connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), this, SLOT(getNtpOutput(OProcess*,char*,int))); @@ -33,7 +43,6 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); -// _nextCorrection = new QTimer( this ); -// connect( _nextCorrection, SIGNAL(timeout()), SLOT(correctClock()) ); - slotRunNtp(); + +// slotRunNtp(); readLookups(); } @@ -41,12 +50,8 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) Ntp::~Ntp() { - -} - -void Ntp::accept() -{ Config cfg("ntp",Config::User); cfg.setGroup("settings"); - cfg.writeEntry("ntpServer", LineEditNtpServer->text()); + cfg.writeEntry("ntpServer", LineEditNtpSrv->text()); + cfg.writeEntry( "minLookupDiff", SpinBoxMinDelay->value() ); } @@ -56,5 +61,5 @@ void Ntp::slotRunNtp() TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); ntpProcess->clearArguments(); - *ntpProcess << "ntpdate" << LineEditNtpServer->text(); + *ntpProcess << "ntpdate" << LineEditNtpSrv->text(); bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); if ( !ret ) { @@ -70,5 +75,5 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) if (lineStr!=lineStrOld) { -// outPut->append(lineStr); + MultiLineEditntpOutPut->append(lineStr); _ntpOutput += lineStr; } @@ -91,5 +96,5 @@ void Ntp::ntpFinished(OProcess*) int secsSinceLast = time - lastLookup; TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); - if ( lastLookup > 0 && secsSinceLast > 60*_minLookupDiff) + if ( lastLookup > 0 && secsSinceLast > 60*24* SpinBoxMinDelay->value()) { lookupCount++; @@ -152,10 +157,10 @@ void Ntp::readLookups() TableLookups->setNumCols( 3 ); TableLookups->setNumRows( lookupCount); - TableLookups->horizontalHeader()->setLabel(2,"secsSinceLast"); - TableLookups->horizontalHeader()->setLabel(1,"timeShift"); + TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); + TableLookups->horizontalHeader()->setLabel(2,"timeShift"); TableLookups->horizontalHeader()->setLabel(0,"shift/s"); - int cw = TableLookups->width()/4; + int cw = 50;//TableLookups->width()/4; qDebug("column width %i",cw); - TableLookups->setColumnWidth( 0, cw ); + TableLookups->setColumnWidth( 0, cw+30 ); TableLookups->setColumnWidth( 1, cw ); TableLookups->setColumnWidth( 2, cw ); @@ -165,11 +170,11 @@ void Ntp::readLookups() 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); +// qDebug("%i last %f",i,last); +// qDebug("%i shift %f",i,shift); shiftPerSec = shift / last; _shiftPerSec += shiftPerSec; TableLookups->setText( i,0,QString::number(shiftPerSec)); - TableLookups->setText( i,1,QString::number(shift)); - TableLookups->setText( i,2,QString::number(last)); + TableLookups->setText( i,2,QString::number(shift)); + TableLookups->setText( i,1,QString::number(last)); } _shiftPerSec /= lookupCount+1; @@ -186,6 +191,26 @@ void Ntp::preditctTime() int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); int corr = int((now - lastTime) * _shiftPerSec); - QDateTime dt = QDateTime::currentDateTime().addSecs(corr); - setTime(dt); - TextLabelPredTime->setText(dt.toString()); + predictedTime = QDateTime::currentDateTime().addSecs(corr); + TextLabelPredTime->setText(predictedTime.toString()); + TextLabelMainPredTime->setText(predictedTime.toString()); +} + +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()) ); + }else{ + preditctTime(); + ButtonSetTime->setText( tr("Predict time") ); + connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); + }; } diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index d2e238d..284ae27 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h @@ -3,5 +3,4 @@ #include "settime.h" #include <qdatetime.h> -#include <qtimer.h> class OProcess; @@ -17,15 +16,12 @@ public: ~Ntp(); - OProcess *ntpProcess; - protected: - virtual void accept(); + QDateTime predictedTime; + private: QString _ntpOutput; - int _maxOffset; float _shiftPerSec; -// QTimer *_nextCorrection; - int _minLookupDiff; + OProcess *ntpProcess; float getTimeShift(); @@ -35,6 +31,7 @@ private slots: void getNtpOutput(OProcess *proc, char *buffer, int buflen); void ntpFinished(OProcess*); -// void correctClock(); void preditctTime(); + void slotCheckNtp(int); + void setPredictTime(); }; diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui index ccae5bf..e444065 100644 --- a/noncore/settings/netsystemtime/ntpbase.ui +++ b/noncore/settings/netsystemtime/ntpbase.ui @@ -2,5 +2,5 @@ <class>NtpBase</class> <widget> - <class>QDialog</class> + <class>QWidget</class> <property stdset="1"> <name>name</name> @@ -12,5 +12,5 @@ <x>0</x> <y>0</y> - <width>280</width> + <width>276</width> <height>337</height> </rect> @@ -248,38 +248,14 @@ </widget> <widget row="1" column="0" > - <class>QLayoutWidget</class> + <class>QMultiLineEdit</class> <property stdset="1"> <name>name</name> - <cstring>Layout6</cstring> - </property> - <hbox> - <property stdset="1"> - <name>margin</name> - <number>0</number> + <cstring>MultiLineEditntpOutPut</cstring> </property> <property stdset="1"> - <name>spacing</name> - <number>6</number> - </property> - <widget> - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel7</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>NTP Server:</string> + <name>wordWrap</name> + <enum>WidgetWidth</enum> </property> </widget> - <widget> - <class>QLineEdit</class> - <property stdset="1"> - <name>name</name> - <cstring>LineEditNtpServer</cstring> - </property> - </widget> - </hbox> - </widget> </grid> </widget> @@ -294,5 +270,5 @@ <attribute> <name>title</name> - <string>Auto</string> + <string>Predict</string> </attribute> <grid> @@ -427,4 +403,133 @@ <enum>Raised</enum> </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget row="0" column="0" > + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout6</cstring> + </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <spacer row="2" column="0" > + <property> + <name>name</name> + <cstring>Spacer2</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Vertical</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget row="1" column="0" > + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout6</cstring> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel7_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>NTP Server:</string> + </property> + </widget> + <widget> + <class>QLineEdit</class> + <property stdset="1"> + <name>name</name> + <cstring>LineEditNtpSrv</cstring> + </property> + </widget> + </hbox> + </widget> + <widget row="0" column="0" > + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout5</cstring> + </property> + <hbox> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel1_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Min. delay:</string> + </property> + </widget> + <widget> + <class>QSpinBox</class> + <property stdset="1"> + <name>name</name> + <cstring>SpinBoxMinDelay</cstring> + </property> + </widget> + <widget> + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>minutes</string> + </property> + </widget> + </hbox> + </widget> + </grid> + </widget> + </grid> </widget> </grid> diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp index 01268c9..2cef6e8 100644 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/noncore/settings/netsystemtime/settime.cpp @@ -61,4 +61,13 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) QVBoxLayout *vb2 = new QVBoxLayout( FrameSetTime, 5 ); + TextLabelMainPredTime = new QLabel( FrameSystemTime ); + vb->addWidget( TextLabelMainPredTime, 1, 0 ); + ButtonSetTime = new QPushButton( FrameSystemTime ); + vb->addWidget( ButtonSetTime, 1, 0 ); + + QFrame *hline = new QFrame( FrameSystemTime ); + hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); + vb->addWidget( hline ); + QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" ); @@ -83,5 +92,5 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) vb2->addItem( spacer ); - QFrame *hline = new QFrame( FrameSystemTime ); + hline = new QFrame( FrameSystemTime ); hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); vb->addWidget( hline ); @@ -93,5 +102,4 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) QLabel *l = new QLabel( tr("Time format"), FrameSystemTime ); - // l->setAlignment( AlignRight | AlignVCenter ); hb1->addWidget( l, 1 ); @@ -178,14 +186,14 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) vb->addStretch( 0 ); + QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()), + this, SLOT(commitTime())); + QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), timeButton, SLOT( slotTzChange( const QString& ) ) ); QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), SLOT( tzChange( const QString& ) ) ); - QObject::connect( PushButtonSetManualTime, SLOT(clicked()), - SLOT(commitTime())); -// dl = new QPEDialogListener(this); } -void SetDateTime::accept() +SetDateTime::~SetDateTime() { @@ -265,11 +273,4 @@ void SetDateTime::setTime(QDateTime dt) enableScreenSaver << -1 << -1 << -1; - // QDialog::accept(); -} - -void SetDateTime::done(int r) -{ -// QDialog::done(r); - close(); } diff --git a/noncore/settings/netsystemtime/settime.h b/noncore/settings/netsystemtime/settime.h index 729bf4b..60423e7 100644 --- a/noncore/settings/netsystemtime/settime.h +++ b/noncore/settings/netsystemtime/settime.h @@ -34,5 +34,4 @@ class TimeZoneSelector; class DateBookMonth; class QComboBox; -//class QPEDialogListener; class SetTime : public QWidget @@ -70,14 +69,13 @@ class SetDateTime : public NtpBase public: SetDateTime( QWidget *parent=0, const char *name=0, WFlags f=0 ); + ~SetDateTime(); protected slots: + void commitTime(); void tzChange( const QString &tz ); void formatChanged(int); protected: - void commitTime(); void setTime(QDateTime dt); - virtual void accept(); - virtual void done(int); SetTime *timeButton; @@ -88,6 +86,6 @@ protected: QComboBox *dateFormatCombo; QComboBox *clockAppletCombo; - -// QPEDialogListener *dl; + QPushButton *ButtonSetTime; + QLabel *TextLabelMainPredTime; DateFormat date_formats[4]; |