summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/predicttabwidget.cpp4
1 files changed, 1 insertions, 3 deletions
diff --git a/noncore/settings/netsystemtime/predicttabwidget.cpp b/noncore/settings/netsystemtime/predicttabwidget.cpp
index a9fe418..c706add 100644
--- a/noncore/settings/netsystemtime/predicttabwidget.cpp
+++ b/noncore/settings/netsystemtime/predicttabwidget.cpp
@@ -1,168 +1,166 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 =. 3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> 4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can 6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that 13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details. 18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .: 19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU 20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file; 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the 22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc., 23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "predicttabwidget.h" 29#include "predicttabwidget.h"
30 30
31#include <qpe/config.h> 31#include <qpe/config.h>
32#include <qpe/timeconversion.h> 32#include <qpe/timeconversion.h>
33 33
34#include <qlabel.h> 34#include <qlabel.h>
35#include <qlayout.h> 35#include <qlayout.h>
36#include <qpushbutton.h> 36#include <qpushbutton.h>
37#include <qscrollview.h> 37#include <qscrollview.h>
38#include <qtable.h> 38#include <qtable.h>
39 39
40#include <stdlib.h> 40#include <stdlib.h>
41 41
42PredictTabWidget::PredictTabWidget( QWidget *parent ) 42PredictTabWidget::PredictTabWidget( QWidget *parent )
43 : QWidget( parent, 0x0, 0 ) 43 : QWidget( parent, 0x0, 0 )
44{ 44{
45/* 45/*
46 QVBoxLayout *tmpvb = new QVBoxLayout( this ); 46 QVBoxLayout *tmpvb = new QVBoxLayout( this );
47 QScrollView *sv = new QScrollView( this ); 47 QScrollView *sv = new QScrollView( this );
48 tmpvb->addWidget( sv, 0, 0 ); 48 tmpvb->addWidget( sv, 0, 0 );
49 sv->setResizePolicy( QScrollView::AutoOneFit ); 49 sv->setResizePolicy( QScrollView::AutoOneFit );
50 sv->setFrameStyle( QFrame::NoFrame ); 50 sv->setFrameStyle( QFrame::NoFrame );
51 QWidget *container = new QWidget( sv->viewport() ); 51 QWidget *container = new QWidget( sv->viewport() );
52 sv->addChild( container ); 52 sv->addChild( container );
53*/ 53*/
54 54
55 QGridLayout *layout = new QGridLayout( this ); 55 QGridLayout *layout = new QGridLayout( this );
56 layout->setMargin( 2 ); 56 layout->setMargin( 2 );
57 layout->setSpacing( 4 ); 57 layout->setSpacing( 4 );
58 58
59 // Predicted time drift 59 // Predicted time drift
60 layout->addWidget( new QLabel( tr( "Predicted time drift" ), this ), 0, 0 ); 60 layout->addWidget( new QLabel( tr( "Predicted time drift" ), this ), 0, 0 );
61 lblDrift = new QLabel( tr( "n/a" ), this ); 61 lblDrift = new QLabel( tr( "n/a" ), this );
62 layout->addWidget( lblDrift, 0, 1 ); 62 layout->addWidget( lblDrift, 0, 1 );
63 63
64 // Estimated time difference 64 // Estimated time difference
65 layout->addWidget( new QLabel( tr( "Estimated shift" ), this ), 1, 0 ); 65 layout->addWidget( new QLabel( tr( "Estimated shift" ), this ), 1, 0 );
66 lblDiff = new QLabel( tr( "n/a" ), this ); 66 lblDiff = new QLabel( tr( "n/a" ), this );
67 layout->addWidget( lblDiff, 1, 1 ); 67 layout->addWidget( lblDiff, 1, 1 );
68 68
69 // Predicted time 69 // Predicted time
70 layout->addWidget( new QLabel( tr( "Predicted time" ), this ), 2, 0 ); 70 layout->addWidget( new QLabel( tr( "Predicted time" ), this ), 2, 0 );
71 lblPredicted = new QLabel( tr( "n/a" ), this ); 71 lblPredicted = new QLabel( tr( "n/a" ), this );
72 layout->addWidget( lblPredicted, 2, 1 ); 72 layout->addWidget( lblPredicted, 2, 1 );
73 73
74 // Prediction table 74 // Prediction table
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
83 tblLookups->setColumnWidth( 1, 50 );
84 tblLookups->setColumnWidth( 2, 50 );
85 tblLookups->setMinimumHeight( 50 ); 83 tblLookups->setMinimumHeight( 50 );
86 tblLookups->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) ); 84 tblLookups->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
87 layout->addMultiCellWidget( tblLookups, 3, 3, 0, 1 ); 85 layout->addMultiCellWidget( tblLookups, 3, 3, 0, 1 );
88 86
89 // Predict time button 87 // Predict time button
90 QPushButton *pb = new QPushButton( tr( "Predict time" ), this ); 88 QPushButton *pb = new QPushButton( tr( "Predict time" ), this );
91 connect( pb, SIGNAL(clicked()), this, SLOT(slotPredictTime()) ); 89 connect( pb, SIGNAL(clicked()), this, SLOT(slotPredictTime()) );
92 layout->addWidget( pb, 4, 0 ); 90 layout->addWidget( pb, 4, 0 );
93 91
94 // Set predicted time button 92 // Set predicted time button
95 pb = new QPushButton( tr( "Set predicted time" ), this ); 93 pb = new QPushButton( tr( "Set predicted time" ), this );
96 connect( pb, SIGNAL(clicked()), this, SLOT(slotSetPredictedTime()) ); 94 connect( pb, SIGNAL(clicked()), this, SLOT(slotSetPredictedTime()) );
97 layout->addWidget( pb, 4, 1 ); 95 layout->addWidget( pb, 4, 1 );
98 96
99 // Initialize values 97 // Initialize values
100 Config config( "ntp" ); 98 Config config( "ntp" );
101 config.setGroup( "lookups" ); 99 config.setGroup( "lookups" );
102 int lookupCount = config.readNumEntry( "count", 0 ); 100 int lookupCount = config.readNumEntry( "count", 0 );
103 float last, shift, shiftPerSec; 101 float last, shift, shiftPerSec;
104 tblLookups->setNumRows( lookupCount ); 102 tblLookups->setNumRows( lookupCount );
105 int cw = tblLookups->width() / 4; 103 int cw = tblLookups->width() / 4;
106 cw = 50; 104 cw = 50;
107 tblLookups->sortColumn( 0, FALSE, TRUE ); 105 tblLookups->sortColumn( 0, FALSE, TRUE );
108 _shiftPerSec = 0; 106 _shiftPerSec = 0;
109 QString grpname; 107 QString grpname;
110 for ( int i=0; i < lookupCount; i++ ) 108 for ( int i=0; i < lookupCount; i++ )
111 { 109 {
112 grpname = "lookup_"; 110 grpname = "lookup_";
113 grpname.append( QString::number( i ) ); 111 grpname.append( QString::number( i ) );
114 config.setGroup( grpname ); 112 config.setGroup( grpname );
115 last = config.readEntry( "secsSinceLast", 0 ).toFloat(); 113 last = config.readEntry( "secsSinceLast", 0 ).toFloat();
116 shift = QString( config.readEntry( "timeShift", 0 ) ).toFloat(); 114 shift = QString( config.readEntry( "timeShift", 0 ) ).toFloat();
117 shiftPerSec = shift / last; 115 shiftPerSec = shift / last;
118 _shiftPerSec += shiftPerSec; 116 _shiftPerSec += shiftPerSec;
119 tblLookups->setText( i, 0, QString::number( shiftPerSec * 60 * 60 ) ); 117 tblLookups->setText( i, 0, QString::number( shiftPerSec * 60 * 60 ) );
120 tblLookups->setText( i, 2, QString::number( shift ) ); 118 tblLookups->setText( i, 2, QString::number( shift ) );
121 tblLookups->setText( i, 1, QString::number( last / ( 60 * 60 ) ) ); 119 tblLookups->setText( i, 1, QString::number( last / ( 60 * 60 ) ) );
122 } 120 }
123 if(lookupCount) 121 if(lookupCount)
124 _shiftPerSec /= lookupCount; 122 _shiftPerSec /= lookupCount;
125 QString drift = QString::number( _shiftPerSec * 60 * 60); 123 QString drift = QString::number( _shiftPerSec * 60 * 60);
126 drift.append( tr( " s/h" ) ); 124 drift.append( tr( " s/h" ) );
127 lblDrift->setText( drift ); 125 lblDrift->setText( drift );
128 126
129 Config lconfig( "locale" ); 127 Config lconfig( "locale" );
130 lconfig.setGroup( "Location" ); 128 lconfig.setGroup( "Location" );
131 tz = lconfig.readEntry( "Timezone", "America/New_York" ); 129 tz = lconfig.readEntry( "Timezone", "America/New_York" );
132} 130}
133 131
134PredictTabWidget::~PredictTabWidget() 132PredictTabWidget::~PredictTabWidget()
135{ 133{
136} 134}
137 135
138void PredictTabWidget::setShiftPerSec( int i ) 136void PredictTabWidget::setShiftPerSec( int i )
139{ 137{
140 _shiftPerSec += i; 138 _shiftPerSec += i;
141} 139}
142 140
143void PredictTabWidget::slotTZChanged( const QString &newtz ) 141void PredictTabWidget::slotTZChanged( const QString &newtz )
144{ 142{
145 tz = newtz; 143 tz = newtz;
146} 144}
147 145
148void PredictTabWidget::slotPredictTime() 146void PredictTabWidget::slotPredictTime()
149{ 147{
150 Config config( "ntp" ); 148 Config config( "ntp" );
151 config.setGroup( "lookups" ); 149 config.setGroup( "lookups" );
152 int lastTime = config.readNumEntry( "time", 0 ); 150 int lastTime = config.readNumEntry( "time", 0 );
153 config.writeEntry( "lastNtp", TRUE ); 151 config.writeEntry( "lastNtp", TRUE );
154 setenv( "TZ", tz, 1 ); 152 setenv( "TZ", tz, 1 );
155 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 153 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
156 int corr = int( ( now - lastTime ) * _shiftPerSec ); 154 int corr = int( ( now - lastTime ) * _shiftPerSec );
157 QString diff = QString::number( corr ); 155 QString diff = QString::number( corr );
158 diff.append( tr( " seconds" ) ); 156 diff.append( tr( " seconds" ) );
159 lblDiff->setText( diff ); 157 lblDiff->setText( diff );
160 predictedTime = QDateTime::currentDateTime().addSecs( corr ); 158 predictedTime = QDateTime::currentDateTime().addSecs( corr );
161 lblPredicted->setText( predictedTime.toString() ); 159 lblPredicted->setText( predictedTime.toString() );
162} 160}
163 161
164void PredictTabWidget::slotSetPredictedTime() 162void PredictTabWidget::slotSetPredictedTime()
165{ 163{
166 slotPredictTime(); 164 slotPredictTime();
167 emit setTime( predictedTime ); 165 emit setTime( predictedTime );
168} 166}