summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/mainwindow.cpp
Side-by-side diff
Diffstat (limited to 'noncore/settings/netsystemtime/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/mainwindow.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp
index 35d4105..c1cd796 100644
--- a/noncore/settings/netsystemtime/mainwindow.cpp
+++ b/noncore/settings/netsystemtime/mainwindow.cpp
@@ -46,54 +46,54 @@
#include <qlayout.h>
#include <qmessagebox.h>
#include <qsocket.h>
#include <qstring.h>
#include <qtimer.h>
using namespace Opie::Ui;
using namespace Opie::Core;
MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f )
: QDialog( parent, name, modal, f )
{
setCaption( tr( "SystemTime" ) );
QVBoxLayout *layout = new QVBoxLayout( this );
layout->setMargin( 2 );
layout->setSpacing( 4 );
// Create main tabbed control
mainWidget = new OTabWidget( this );
// Default object pointers to null
ntpProcess = 0x0;
ntpTab = 0x0;
+ predictTab = 0x0;
// Add tab widgets
mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) );
mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) );
mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) );
- mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) );
Config config( "ntp" );
config.setGroup( "settings" );
slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", false ) );
slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", false ) );
mainWidget->setCurrentTab( tr( "Time" ) );
layout->addWidget( mainWidget );
connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
this, SLOT(slotQCopReceive(const QCString&,const QByteArray&)) );
// Create NTP socket
ntpSock = new QSocket( this );
connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) );
slotProbeNTPServer();
// Create timer for automatic time lookups
ntpTimer = new QTimer( this );
// Connect everything together
connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) );
connect( timeTab, SIGNAL(tzChanged(const QString&)), predictTab, SLOT(slotTZChanged(const QString&)) );
connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) );
@@ -254,48 +254,49 @@ void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & )
void MainWindow::slotDisplayNTPTab( bool display )
{
ntpTabEnabled = display;
// Create widget if it hasn't needed
if ( display && !ntpTab )
{
ntpTab = new NTPTabWidget( mainWidget );
connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) );
}
// Display/hide tab
display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) )
: mainWidget->removePage( ntpTab );
}
void MainWindow::slotDisplayPredictTab( bool display )
{
predictTabEnabled = display;
// Create widget if it hasn't needed
if ( display && !predictTab )
{
+ predictTab = new PredictTabWidget( mainWidget );
}
// Display/hide tab
display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) )
: mainWidget->removePage( predictTab );
}
void MainWindow::slotGetNTPTime()
{
ntpInteractive = true;
runNTP();
}
void MainWindow::slotTimerGetNTPTime()
{
ntpInteractive = false;
runNTP();
}
void MainWindow::slotProbeNTPServer()
{
ntpSock->connectToHost( settingsTab->ntpServer(), 123 );
}
void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen )
@@ -350,69 +351,78 @@ void MainWindow::slotNtpFinished( OProcess *p )
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 );
float timeShift = diff.toFloat();
if ( timeShift == 0.0 )
return;
int secsSinceLast = time - lastLookup;
output = tr( "%1 seconds").arg(QString::number( timeShift ));
// Display information on time server tab
if ( ntpTabEnabled )
{
ntpTab->setTimeShift( output );
ntpTab->setNewTime( dt.toString() );
}
if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay )
{
QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) );
config.setGroup( grpname );
lookupCount++;
- predictTab->setShiftPerSec( (int)(timeShift / secsSinceLast) );
+
+ if(predictTab)
+ {
+ predictTab->setShiftPerSec( (int)(timeShift / secsSinceLast) );
+ }
+
config.writeEntry( "secsSinceLast", secsSinceLast );
config.writeEntry( "timeShift", QString::number( timeShift ) );
config.setGroup( "lookups" );
config.writeEntry( "count", lookupCount );
config.writeEntry( "lastNtp", true );
}
}
void MainWindow::slotNTPDelayChanged( int delay )
{
ntpTimer->changeInterval( delay * 1000 * 60 );
ntpDelay = delay;
}
void MainWindow::slotCheckNtp( int i )
{
if ( i == 0 )
{
if ( ntpDelayElapsed() )
{
runNTP();
disconnect( ntpTimer, SIGNAL(timeout()), this, SLOT(slotProbeNTPServer()) );
connect( ntpTimer, SIGNAL(timeout()), SLOT(slotTimerGetNTPTime()) );
}
else
{
disconnect(ntpTimer, SIGNAL(timeout()), this, SLOT(slotTimerGetNTPTime()) );
connect(ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) );
}
}
else
{
- predictTab->slotPredictTime();
+ if(predictTab)
+ {
+ predictTab->slotPredictTime();
+ }
+
if ( i > 0 )
{
QString output = tr( "Could not connect to server " );
output.append( settingsTab->ntpServer() );
ntpOutput.append( output );
if ( ntpTabEnabled )
ntpTab->addNtpOutput( output );
}
connect( ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) );
}
}