summaryrefslogtreecommitdiff
authorzecke <zecke>2003-05-21 17:04:59 (UTC)
committer zecke <zecke>2003-05-21 17:04:59 (UTC)
commit6041221c6d2892c6e7a61570c524fd090f447739 (patch) (side-by-side diff)
tree2df82af7bfd19f1bb42268f696d38b3ab180135d
parent9a3bcbb66840f7a0affddd551ee1356259c85ca4 (diff)
downloadopie-6041221c6d2892c6e7a61570c524fd090f447739.zip
opie-6041221c6d2892c6e7a61570c524fd090f447739.tar.gz
opie-6041221c6d2892c6e7a61570c524fd090f447739.tar.bz2
Fix to prevent division by 0
from Mark Hsu
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/predicttabwidget.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/noncore/settings/netsystemtime/predicttabwidget.cpp b/noncore/settings/netsystemtime/predicttabwidget.cpp
index 8dc889f..a9fe418 100644
--- a/noncore/settings/netsystemtime/predicttabwidget.cpp
+++ b/noncore/settings/netsystemtime/predicttabwidget.cpp
@@ -75,93 +75,94 @@ PredictTabWidget::PredictTabWidget( QWidget *parent )
tblLookups = new QTable( 2, 3, this );
QFont font( tblLookups->font() );
font.setPointSize( 7 );
tblLookups->setFont( font );
tblLookups->horizontalHeader()->setLabel( 0, tr( "Shift [s/h]" ) );
tblLookups->horizontalHeader()->setLabel( 1, tr( "Last [h]" ) );
tblLookups->horizontalHeader()->setLabel( 2, tr( "Offset [s]" ) );
tblLookups->setColumnWidth( 0, 78 );
tblLookups->setColumnWidth( 1, 50 );
tblLookups->setColumnWidth( 2, 50 );
tblLookups->setMinimumHeight( 50 );
tblLookups->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
layout->addMultiCellWidget( tblLookups, 3, 3, 0, 1 );
// Predict time button
QPushButton *pb = new QPushButton( tr( "Predict time" ), this );
connect( pb, SIGNAL(clicked()), this, SLOT(slotPredictTime()) );
layout->addWidget( pb, 4, 0 );
// Set predicted time button
pb = new QPushButton( tr( "Set predicted time" ), this );
connect( pb, SIGNAL(clicked()), this, SLOT(slotSetPredictedTime()) );
layout->addWidget( pb, 4, 1 );
// Initialize values
Config config( "ntp" );
config.setGroup( "lookups" );
int lookupCount = config.readNumEntry( "count", 0 );
float last, shift, shiftPerSec;
tblLookups->setNumRows( lookupCount );
int cw = tblLookups->width() / 4;
cw = 50;
tblLookups->sortColumn( 0, FALSE, TRUE );
_shiftPerSec = 0;
QString grpname;
for ( int i=0; i < lookupCount; i++ )
{
grpname = "lookup_";
grpname.append( QString::number( i ) );
config.setGroup( grpname );
last = config.readEntry( "secsSinceLast", 0 ).toFloat();
shift = QString( config.readEntry( "timeShift", 0 ) ).toFloat();
shiftPerSec = shift / last;
_shiftPerSec += shiftPerSec;
tblLookups->setText( i, 0, QString::number( shiftPerSec * 60 * 60 ) );
tblLookups->setText( i, 2, QString::number( shift ) );
tblLookups->setText( i, 1, QString::number( last / ( 60 * 60 ) ) );
}
- _shiftPerSec /= lookupCount;
+ if(lookupCount)
+ _shiftPerSec /= lookupCount;
QString drift = QString::number( _shiftPerSec * 60 * 60);
drift.append( tr( " s/h" ) );
lblDrift->setText( drift );
Config lconfig( "locale" );
lconfig.setGroup( "Location" );
tz = lconfig.readEntry( "Timezone", "America/New_York" );
}
PredictTabWidget::~PredictTabWidget()
{
}
void PredictTabWidget::setShiftPerSec( int i )
{
_shiftPerSec += i;
}
void PredictTabWidget::slotTZChanged( const QString &newtz )
{
tz = newtz;
}
void PredictTabWidget::slotPredictTime()
{
Config config( "ntp" );
config.setGroup( "lookups" );
int lastTime = config.readNumEntry( "time", 0 );
config.writeEntry( "lastNtp", TRUE );
setenv( "TZ", tz, 1 );
int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
int corr = int( ( now - lastTime ) * _shiftPerSec );
QString diff = QString::number( corr );
diff.append( tr( " seconds" ) );
lblDiff->setText( diff );
predictedTime = QDateTime::currentDateTime().addSecs( corr );
lblPredicted->setText( predictedTime.toString() );
}
void PredictTabWidget::slotSetPredictedTime()
{
slotPredictTime();
emit setTime( predictedTime );
}