summaryrefslogtreecommitdiff
authorzecke <zecke>2003-05-21 17:04:59 (UTC)
committer zecke <zecke>2003-05-21 17:04:59 (UTC)
commit6041221c6d2892c6e7a61570c524fd090f447739 (patch) (unidiff)
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 )
75 tblLookups = new QTable( 2, 3, this ); 75 tblLookups = new QTable( 2, 3, this );
76 QFont font( tblLookups->font() ); 76 QFont font( tblLookups->font() );
77 font.setPointSize( 7 ); 77 font.setPointSize( 7 );
78 tblLookups->setFont( font ); 78 tblLookups->setFont( font );
79 tblLookups->horizontalHeader()->setLabel( 0, tr( "Shift [s/h]" ) ); 79 tblLookups->horizontalHeader()->setLabel( 0, tr( "Shift [s/h]" ) );
80 tblLookups->horizontalHeader()->setLabel( 1, tr( "Last [h]" ) ); 80 tblLookups->horizontalHeader()->setLabel( 1, tr( "Last [h]" ) );
81 tblLookups->horizontalHeader()->setLabel( 2, tr( "Offset [s]" ) ); 81 tblLookups->horizontalHeader()->setLabel( 2, tr( "Offset [s]" ) );
82 tblLookups->setColumnWidth( 0, 78 ); 82 tblLookups->setColumnWidth( 0, 78 );
83 tblLookups->setColumnWidth( 1, 50 ); 83 tblLookups->setColumnWidth( 1, 50 );
84 tblLookups->setColumnWidth( 2, 50 ); 84 tblLookups->setColumnWidth( 2, 50 );
85 tblLookups->setMinimumHeight( 50 ); 85 tblLookups->setMinimumHeight( 50 );
86 tblLookups->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); 86 tblLookups->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
87 layout->addMultiCellWidget( tblLookups, 3, 3, 0, 1 ); 87 layout->addMultiCellWidget( tblLookups, 3, 3, 0, 1 );
88 88
89 // Predict time button 89 // Predict time button
90 QPushButton *pb = new QPushButton( tr( "Predict time" ), this ); 90 QPushButton *pb = new QPushButton( tr( "Predict time" ), this );
91 connect( pb, SIGNAL(clicked()), this, SLOT(slotPredictTime()) ); 91 connect( pb, SIGNAL(clicked()), this, SLOT(slotPredictTime()) );
92 layout->addWidget( pb, 4, 0 ); 92 layout->addWidget( pb, 4, 0 );
93 93
94 // Set predicted time button 94 // Set predicted time button
95 pb = new QPushButton( tr( "Set predicted time" ), this ); 95 pb = new QPushButton( tr( "Set predicted time" ), this );
96 connect( pb, SIGNAL(clicked()), this, SLOT(slotSetPredictedTime()) ); 96 connect( pb, SIGNAL(clicked()), this, SLOT(slotSetPredictedTime()) );
97 layout->addWidget( pb, 4, 1 ); 97 layout->addWidget( pb, 4, 1 );
98 98
99 // Initialize values 99 // Initialize values
100 Config config( "ntp" ); 100 Config config( "ntp" );
101 config.setGroup( "lookups" ); 101 config.setGroup( "lookups" );
102 int lookupCount = config.readNumEntry( "count", 0 ); 102 int lookupCount = config.readNumEntry( "count", 0 );
103 float last, shift, shiftPerSec; 103 float last, shift, shiftPerSec;
104 tblLookups->setNumRows( lookupCount ); 104 tblLookups->setNumRows( lookupCount );
105 int cw = tblLookups->width() / 4; 105 int cw = tblLookups->width() / 4;
106 cw = 50; 106 cw = 50;
107 tblLookups->sortColumn( 0, FALSE, TRUE ); 107 tblLookups->sortColumn( 0, FALSE, TRUE );
108 _shiftPerSec = 0; 108 _shiftPerSec = 0;
109 QString grpname; 109 QString grpname;
110 for ( int i=0; i < lookupCount; i++ ) 110 for ( int i=0; i < lookupCount; i++ )
111 { 111 {
112 grpname = "lookup_"; 112 grpname = "lookup_";
113 grpname.append( QString::number( i ) ); 113 grpname.append( QString::number( i ) );
114 config.setGroup( grpname ); 114 config.setGroup( grpname );
115 last = config.readEntry( "secsSinceLast", 0 ).toFloat(); 115 last = config.readEntry( "secsSinceLast", 0 ).toFloat();
116 shift = QString( config.readEntry( "timeShift", 0 ) ).toFloat(); 116 shift = QString( config.readEntry( "timeShift", 0 ) ).toFloat();
117 shiftPerSec = shift / last; 117 shiftPerSec = shift / last;
118 _shiftPerSec += shiftPerSec; 118 _shiftPerSec += shiftPerSec;
119 tblLookups->setText( i, 0, QString::number( shiftPerSec * 60 * 60 ) ); 119 tblLookups->setText( i, 0, QString::number( shiftPerSec * 60 * 60 ) );
120 tblLookups->setText( i, 2, QString::number( shift ) ); 120 tblLookups->setText( i, 2, QString::number( shift ) );
121 tblLookups->setText( i, 1, QString::number( last / ( 60 * 60 ) ) ); 121 tblLookups->setText( i, 1, QString::number( last / ( 60 * 60 ) ) );
122 } 122 }
123 _shiftPerSec /= lookupCount; 123 if(lookupCount)
124 _shiftPerSec /= lookupCount;
124 QString drift = QString::number( _shiftPerSec * 60 * 60); 125 QString drift = QString::number( _shiftPerSec * 60 * 60);
125 drift.append( tr( " s/h" ) ); 126 drift.append( tr( " s/h" ) );
126 lblDrift->setText( drift ); 127 lblDrift->setText( drift );
127 128
128 Config lconfig( "locale" ); 129 Config lconfig( "locale" );
129 lconfig.setGroup( "Location" ); 130 lconfig.setGroup( "Location" );
130 tz = lconfig.readEntry( "Timezone", "America/New_York" ); 131 tz = lconfig.readEntry( "Timezone", "America/New_York" );
131} 132}
132 133
133PredictTabWidget::~PredictTabWidget() 134PredictTabWidget::~PredictTabWidget()
134{ 135{
135} 136}
136 137
137void PredictTabWidget::setShiftPerSec( int i ) 138void PredictTabWidget::setShiftPerSec( int i )
138{ 139{
139 _shiftPerSec += i; 140 _shiftPerSec += i;
140} 141}
141 142
142void PredictTabWidget::slotTZChanged( const QString &newtz ) 143void PredictTabWidget::slotTZChanged( const QString &newtz )
143{ 144{
144 tz = newtz; 145 tz = newtz;
145} 146}
146 147
147void PredictTabWidget::slotPredictTime() 148void PredictTabWidget::slotPredictTime()
148{ 149{
149 Config config( "ntp" ); 150 Config config( "ntp" );
150 config.setGroup( "lookups" ); 151 config.setGroup( "lookups" );
151 int lastTime = config.readNumEntry( "time", 0 ); 152 int lastTime = config.readNumEntry( "time", 0 );
152 config.writeEntry( "lastNtp", TRUE ); 153 config.writeEntry( "lastNtp", TRUE );
153 setenv( "TZ", tz, 1 ); 154 setenv( "TZ", tz, 1 );
154 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 155 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
155 int corr = int( ( now - lastTime ) * _shiftPerSec ); 156 int corr = int( ( now - lastTime ) * _shiftPerSec );
156 QString diff = QString::number( corr ); 157 QString diff = QString::number( corr );
157 diff.append( tr( " seconds" ) ); 158 diff.append( tr( " seconds" ) );
158 lblDiff->setText( diff ); 159 lblDiff->setText( diff );
159 predictedTime = QDateTime::currentDateTime().addSecs( corr ); 160 predictedTime = QDateTime::currentDateTime().addSecs( corr );
160 lblPredicted->setText( predictedTime.toString() ); 161 lblPredicted->setText( predictedTime.toString() );
161} 162}
162 163
163void PredictTabWidget::slotSetPredictedTime() 164void PredictTabWidget::slotSetPredictedTime()
164{ 165{
165 slotPredictTime(); 166 slotPredictTime();
166 emit setTime( predictedTime ); 167 emit setTime( predictedTime );
167} 168}