summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/mainwindow.cpp1
1 files changed, 0 insertions, 1 deletions
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp
index 306117a..ab71463 100644
--- a/noncore/settings/netsystemtime/mainwindow.cpp
+++ b/noncore/settings/netsystemtime/mainwindow.cpp
@@ -1,404 +1,403 @@
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 "mainwindow.h" 29#include "mainwindow.h"
30#include "timetabwidget.h" 30#include "timetabwidget.h"
31#include "formattabwidget.h" 31#include "formattabwidget.h"
32#include "settingstabwidget.h" 32#include "settingstabwidget.h"
33#include "ntptabwidget.h" 33#include "ntptabwidget.h"
34#include "predicttabwidget.h" 34#include "predicttabwidget.h"
35#include "systemtimeconfig.h"
36 35
37#include <opie/oprocess.h> 36#include <opie/oprocess.h>
38#include <opie/otabwidget.h> 37#include <opie/otabwidget.h>
39 38
40#include <qpe/config.h> 39#include <qpe/config.h>
41#include <qpe/datebookdb.h> 40#include <qpe/datebookdb.h>
42#include <qpe/qpeapplication.h> 41#include <qpe/qpeapplication.h>
43 42
44#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 43#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
45#include <qpe/qcopenvelope_qws.h> 44#include <qpe/qcopenvelope_qws.h>
46#endif 45#endif
47 46
48#include <qlayout.h> 47#include <qlayout.h>
49#include <qmessagebox.h> 48#include <qmessagebox.h>
50#include <qsocket.h> 49#include <qsocket.h>
51#include <qstring.h> 50#include <qstring.h>
52#include <qtimer.h> 51#include <qtimer.h>
53 52
54MainWindow::MainWindow() 53MainWindow::MainWindow()
55 : QDialog( 0x0, 0x0, TRUE, 0 ) 54 : QDialog( 0x0, 0x0, TRUE, 0 )
56{ 55{
57 setCaption( tr( "SystemTime" ) ); 56 setCaption( tr( "SystemTime" ) );
58 57
59 QVBoxLayout *layout = new QVBoxLayout( this ); 58 QVBoxLayout *layout = new QVBoxLayout( this );
60 layout->setMargin( 2 ); 59 layout->setMargin( 2 );
61 layout->setSpacing( 4 ); 60 layout->setSpacing( 4 );
62 61
63 // Create main tabbed control 62 // Create main tabbed control
64 mainWidget = new OTabWidget( this ); 63 mainWidget = new OTabWidget( this );
65 64
66 // Default object pointers to null 65 // Default object pointers to null
67 ntpProcess = 0x0; 66 ntpProcess = 0x0;
68 ntpTab = 0x0; 67 ntpTab = 0x0;
69 68
70 // Add tab widgets 69 // Add tab widgets
71 mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) ); 70 mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) );
72 mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) ); 71 mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) );
73 mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) ); 72 mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) );
74 mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) ); 73 mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) );
75 Config config( "ntp" ); 74 Config config( "ntp" );
76 config.setGroup( "settings" ); 75 config.setGroup( "settings" );
77 slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) ); 76 slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) );
78 slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) ); 77 slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) );
79 78
80 mainWidget->setCurrentTab( tr( "Time" ) ); 79 mainWidget->setCurrentTab( tr( "Time" ) );
81 layout->addWidget( mainWidget ); 80 layout->addWidget( mainWidget );
82 81
83 // Create QCOP channel 82 // Create QCOP channel
84 QCopChannel *channel = new QCopChannel( "QPE/Application/netsystemtime", this ); 83 QCopChannel *channel = new QCopChannel( "QPE/Application/netsystemtime", this );
85 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 84 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
86 this, SLOT(slotQCopReceive(const QCString&, const QByteArray&)) ); 85 this, SLOT(slotQCopReceive(const QCString&, const QByteArray&)) );
87 86
88 // Create NTP socket 87 // Create NTP socket
89 ntpSock = new QSocket( this ); 88 ntpSock = new QSocket( this );
90 connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); 89 connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) );
91 slotProbeNTPServer(); 90 slotProbeNTPServer();
92 91
93 // Create timer for automatic time lookups 92 // Create timer for automatic time lookups
94 ntpTimer = new QTimer( this ); 93 ntpTimer = new QTimer( this );
95 94
96 // Connect everything together 95 // Connect everything together
97 connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); 96 connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) );
98 connect( timeTab, SIGNAL(tzChanged(const QString &)), predictTab, SLOT(slotTZChanged(const QString &)) ); 97 connect( timeTab, SIGNAL(tzChanged(const QString &)), predictTab, SLOT(slotTZChanged(const QString &)) );
99 connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) ); 98 connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) );
100 connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime( int )) ); 99 connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime( int )) );
101 connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat &)), 100 connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat &)),
102 timeTab, SLOT(slotDateFormatChanged(const DateFormat &)) ); 101 timeTab, SLOT(slotDateFormatChanged(const DateFormat &)) );
103 connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) ); 102 connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) );
104 connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) ); 103 connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) );
105 connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) ); 104 connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) );
106 connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) ); 105 connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) );
107 connect( predictTab, SIGNAL(setTime(const QDateTime &)), this, SLOT(slotSetTime(const QDateTime &)) ); 106 connect( predictTab, SIGNAL(setTime(const QDateTime &)), this, SLOT(slotSetTime(const QDateTime &)) );
108 107
109 // Do initial time server check 108 // Do initial time server check
110 slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); 109 slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) );
111 slotCheckNtp( -1 ); 110 slotCheckNtp( -1 );
112 111
113 // Display app 112 // Display app
114 showMaximized(); 113 showMaximized();
115} 114}
116 115
117MainWindow::~MainWindow() 116MainWindow::~MainWindow()
118{ 117{
119 if ( ntpProcess ) 118 if ( ntpProcess )
120 delete ntpProcess; 119 delete ntpProcess;
121} 120}
122 121
123void MainWindow::accept() 122void MainWindow::accept()
124{ 123{
125 // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends) 124 // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends)
126 { 125 {
127 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 126 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
128 disableScreenSaver << 0 << 0 << 0; 127 disableScreenSaver << 0 << 0 << 0;
129 } 128 }
130 129
131 // Update the systemtime 130 // Update the systemtime
132 timeTab->saveSettings( TRUE ); 131 timeTab->saveSettings( TRUE );
133 132
134 // Save format options 133 // Save format options
135 formatTab->saveSettings( TRUE ); 134 formatTab->saveSettings( TRUE );
136 135
137 // Save settings options 136 // Save settings options
138 settingsTab->saveSettings(); 137 settingsTab->saveSettings();
139 138
140 // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better 139 // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better
141 // grip on itself (example re-trigger alarms for when we travel back in time). 140 // grip on itself (example re-trigger alarms for when we travel back in time).
142 DateBookDB db; 141 DateBookDB db;
143 142
144 // Turn back on the screensaver 143 // Turn back on the screensaver
145 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 144 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
146 enableScreenSaver << -1 << -1 << -1; 145 enableScreenSaver << -1 << -1 << -1;
147 146
148 // Exit app 147 // Exit app
149 qApp->quit(); 148 qApp->quit();
150} 149}
151 150
152void MainWindow::reject() 151void MainWindow::reject()
153{ 152{
154 // Reset time settings 153 // Reset time settings
155 timeTab->saveSettings( FALSE ); 154 timeTab->saveSettings( FALSE );
156 155
157 // Send notifications but do not save settings 156 // Send notifications but do not save settings
158 formatTab->saveSettings( FALSE ); 157 formatTab->saveSettings( FALSE );
159 158
160 // Exit app 159 // Exit app
161 qApp->quit(); 160 qApp->quit();
162} 161}
163 162
164void MainWindow::runNTP() 163void MainWindow::runNTP()
165{ 164{
166 if ( !ntpDelayElapsed() && ntpInteractive ) 165 if ( !ntpDelayElapsed() && ntpInteractive )
167 { 166 {
168 QString msg = tr( "You asked for a delay of " ); 167 QString msg = tr( "You asked for a delay of " );
169 msg.append( QString::number( ntpDelay ) ); 168 msg.append( QString::number( ntpDelay ) );
170 msg.append( tr( " minutes, but only " ) ); 169 msg.append( tr( " minutes, but only " ) );
171 msg.append( QString::number( _lookupDiff / 60 ) ); 170 msg.append( QString::number( _lookupDiff / 60 ) );
172 msg.append( tr(" minutes elapsed since last lookup.<br>Continue?") ); 171 msg.append( tr(" minutes elapsed since last lookup.<br>Continue?") );
173 172
174 switch ( 173 switch (
175 QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No ) 174 QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No )
176 ) 175 )
177 { 176 {
178 case QMessageBox::Yes: break; 177 case QMessageBox::Yes: break;
179 case QMessageBox::No: return; 178 case QMessageBox::No: return;
180 default: return; 179 default: return;
181 } 180 }
182 } 181 }
183 182
184 QString srv = settingsTab->ntpServer(); 183 QString srv = settingsTab->ntpServer();
185 184
186 // Send information to time server tab if enabled 185 // Send information to time server tab if enabled
187 if ( ntpTabEnabled ) 186 if ( ntpTabEnabled )
188 { 187 {
189 ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); 188 ntpTab->setStartTime( QDateTime::currentDateTime().toString() );
190 QString output = tr( "Running:\nntpdate " ); 189 QString output = tr( "Running:\nntpdate " );
191 output.append( srv ); 190 output.append( srv );
192 ntpTab->addNtpOutput( output ); 191 ntpTab->addNtpOutput( output );
193 } 192 }
194 193
195 if ( !ntpProcess ) 194 if ( !ntpProcess )
196 { 195 {
197 ntpProcess = new OProcess(); 196 ntpProcess = new OProcess();
198 connect( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 197 connect( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
199 this, SLOT(slotNtpOutput(OProcess*,char*,int)) ); 198 this, SLOT(slotNtpOutput(OProcess*,char*,int)) );
200 connect( ntpProcess, SIGNAL(processExited(OProcess*)), 199 connect( ntpProcess, SIGNAL(processExited(OProcess*)),
201 this, SLOT(slotNtpFinished(OProcess*)) ); 200 this, SLOT(slotNtpFinished(OProcess*)) );
202 } 201 }
203 202
204 else 203 else
205 ntpProcess->clearArguments(); 204 ntpProcess->clearArguments();
206 205
207 *ntpProcess << "ntpdate" << srv; 206 *ntpProcess << "ntpdate" << srv;
208 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); 207 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput );
209 if ( !ret ) 208 if ( !ret )
210 { 209 {
211 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); 210 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) );
212 if ( ntpTabEnabled ) 211 if ( ntpTabEnabled )
213 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); 212 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) );
214 } 213 }
215} 214}
216 215
217bool MainWindow::ntpDelayElapsed() 216bool MainWindow::ntpDelayElapsed()
218{ 217{
219 // Determine if time elapsed is greater than time delay 218 // Determine if time elapsed is greater than time delay
220 Config config( "ntp" ); 219 Config config( "ntp" );
221 config.setGroup( "lookups" ); 220 config.setGroup( "lookups" );
222 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); 221 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 );
223 if ( _lookupDiff < 0 ) 222 if ( _lookupDiff < 0 )
224 return true; 223 return true;
225 return ( _lookupDiff - ( ntpDelay * 60) ) > 0; 224 return ( _lookupDiff - ( ntpDelay * 60) ) > 0;
226} 225}
227 226
228void MainWindow::slotSetTime( const QDateTime &dt ) 227void MainWindow::slotSetTime( const QDateTime &dt )
229{ 228{
230 timeTab->setDateTime( dt ); 229 timeTab->setDateTime( dt );
231} 230}
232 231
233void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & ) 232void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & )
234{ 233{
235 if ( msg == "ntpLookup(QString)" ) 234 if ( msg == "ntpLookup(QString)" )
236 { 235 {
237 ntpInteractive = false; 236 ntpInteractive = false;
238 runNTP(); 237 runNTP();
239 } 238 }
240 if ( msg == "setPredictedTime(QString)" ) 239 if ( msg == "setPredictedTime(QString)" )
241 { 240 {
242 //setPredictTime(); 241 //setPredictTime();
243 } 242 }
244} 243}
245 244
246void MainWindow::slotDisplayNTPTab( bool display ) 245void MainWindow::slotDisplayNTPTab( bool display )
247{ 246{
248 ntpTabEnabled = display; 247 ntpTabEnabled = display;
249 248
250 // Create widget if it hasn't needed 249 // Create widget if it hasn't needed
251 if ( display && !ntpTab ) 250 if ( display && !ntpTab )
252 { 251 {
253 ntpTab = new NTPTabWidget( mainWidget ); 252 ntpTab = new NTPTabWidget( mainWidget );
254 connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); 253 connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) );
255 } 254 }
256 255
257 // Display/hide tab 256 // Display/hide tab
258 display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) ) 257 display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) )
259 : mainWidget->removePage( ntpTab ); 258 : mainWidget->removePage( ntpTab );
260} 259}
261 260
262void MainWindow::slotDisplayPredictTab( bool display ) 261void MainWindow::slotDisplayPredictTab( bool display )
263{ 262{
264 predictTabEnabled = display; 263 predictTabEnabled = display;
265 264
266 // Create widget if it hasn't needed 265 // Create widget if it hasn't needed
267 if ( display && !predictTab ) 266 if ( display && !predictTab )
268 { 267 {
269 } 268 }
270 // Display/hide tab 269 // Display/hide tab
271 display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) ) 270 display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) )
272 : mainWidget->removePage( predictTab ); 271 : mainWidget->removePage( predictTab );
273} 272}
274 273
275void MainWindow::slotGetNTPTime() 274void MainWindow::slotGetNTPTime()
276{ 275{
277 ntpInteractive = TRUE; 276 ntpInteractive = TRUE;
278 runNTP(); 277 runNTP();
279} 278}
280 279
281void MainWindow::slotTimerGetNTPTime() 280void MainWindow::slotTimerGetNTPTime()
282{ 281{
283 ntpInteractive = FALSE; 282 ntpInteractive = FALSE;
284 runNTP(); 283 runNTP();
285} 284}
286 285
287void MainWindow::slotProbeNTPServer() 286void MainWindow::slotProbeNTPServer()
288{ 287{
289 ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); 288 ntpSock->connectToHost( settingsTab->ntpServer(), 123 );
290} 289}
291 290
292void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) 291void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen )
293{ 292{
294 QString output = QString( buffer ).left( buflen ); 293 QString output = QString( buffer ).left( buflen );
295 ntpOutput.append( output ); 294 ntpOutput.append( output );
296 295
297 if ( ntpTabEnabled ) 296 if ( ntpTabEnabled )
298 ntpTab->addNtpOutput( output ); 297 ntpTab->addNtpOutput( output );
299} 298}
300 299
301void MainWindow::slotNtpFinished( OProcess *p ) 300void MainWindow::slotNtpFinished( OProcess *p )
302{ 301{
303 QString output; 302 QString output;
304 QDateTime dt = QDateTime::currentDateTime(); 303 QDateTime dt = QDateTime::currentDateTime();
305 304
306 // Verify run was successful 305 // Verify run was successful
307 if ( p->exitStatus() != 0 || !p->normalExit() ) 306 if ( p->exitStatus() != 0 || !p->normalExit() )
308 { 307 {
309 if ( isVisible() && ntpInteractive ) 308 if ( isVisible() && ntpInteractive )
310 { 309 {
311 output = tr( "Error while getting time from\n server: " ); 310 output = tr( "Error while getting time from\n server: " );
312 output.append( settingsTab->ntpServer() ); 311 output.append( settingsTab->ntpServer() );
313 QMessageBox::critical(this, tr( "Error" ), output ); 312 QMessageBox::critical(this, tr( "Error" ), output );
314 } 313 }
315 // slotCheckNtp(-1); 314 // slotCheckNtp(-1);
316 return; 315 return;
317 } 316 }
318 317
319 // Set controls on time tab to new time value 318 // Set controls on time tab to new time value
320 timeTab->setDateTime( dt ); 319 timeTab->setDateTime( dt );
321 320
322 // Write out lookup information 321 // Write out lookup information
323 Config config( "ntp" ); 322 Config config( "ntp" );
324 config.setGroup( "lookups" ); 323 config.setGroup( "lookups" );
325 int lastLookup = config.readNumEntry( "time", 0 ); 324 int lastLookup = config.readNumEntry( "time", 0 );
326 int lookupCount = config.readNumEntry( "count", 0 ); 325 int lookupCount = config.readNumEntry( "count", 0 );
327 bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); 326 bool lastNtp = config.readBoolEntry( "lastNtp", FALSE );
328 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 327 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
329 config.writeEntry( "time", time ); 328 config.writeEntry( "time", time );
330 329
331 // Calculate new time/time shift 330 // Calculate new time/time shift
332 QString _offset = "offset"; 331 QString _offset = "offset";
333 QString _sec = "sec"; 332 QString _sec = "sec";
334 QRegExp _reOffset = QRegExp( _offset ); 333 QRegExp _reOffset = QRegExp( _offset );
335 QRegExp _reEndOffset = QRegExp( _sec ); 334 QRegExp _reEndOffset = QRegExp( _sec );
336 int posOffset = _reOffset.match( ntpOutput ); 335 int posOffset = _reOffset.match( ntpOutput );
337 int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); 336 int posEndOffset = _reEndOffset.match( ntpOutput, posOffset );
338 posOffset += _offset.length() + 1; 337 posOffset += _offset.length() + 1;
339 QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); 338 QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 );
340 339
341 float timeShift = diff.toFloat(); 340 float timeShift = diff.toFloat();
342 if ( timeShift == 0.0 ) 341 if ( timeShift == 0.0 )
343 return; 342 return;
344 int secsSinceLast = time - lastLookup; 343 int secsSinceLast = time - lastLookup;
345 output = QString::number( timeShift ); 344 output = QString::number( timeShift );
346 output.append( tr( " seconds" ) ); 345 output.append( tr( " seconds" ) );
347 346
348 // Display information on time server tab 347 // Display information on time server tab
349 if ( ntpTabEnabled ) 348 if ( ntpTabEnabled )
350 { 349 {
351 ntpTab->setTimeShift( output ); 350 ntpTab->setTimeShift( output );
352 ntpTab->setNewTime( dt.toString() ); 351 ntpTab->setNewTime( dt.toString() );
353 } 352 }
354 353
355 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) 354 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay )
356 { 355 {
357 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); 356 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) );
358 config.setGroup( grpname ); 357 config.setGroup( grpname );
359 lookupCount++; 358 lookupCount++;
360 predictTab->setShiftPerSec( timeShift / secsSinceLast ); 359 predictTab->setShiftPerSec( timeShift / secsSinceLast );
361 config.writeEntry( "secsSinceLast", secsSinceLast ); 360 config.writeEntry( "secsSinceLast", secsSinceLast );
362 config.writeEntry( "timeShift", QString::number( timeShift ) ); 361 config.writeEntry( "timeShift", QString::number( timeShift ) );
363 config.setGroup( "lookups" ); 362 config.setGroup( "lookups" );
364 config.writeEntry( "count", lookupCount ); 363 config.writeEntry( "count", lookupCount );
365 config.writeEntry( "lastNtp", TRUE ); 364 config.writeEntry( "lastNtp", TRUE );
366 } 365 }
367} 366}
368 367
369void MainWindow::slotNTPDelayChanged( int delay ) 368void MainWindow::slotNTPDelayChanged( int delay )
370{ 369{
371 ntpTimer->changeInterval( delay * 1000 * 60 ); 370 ntpTimer->changeInterval( delay * 1000 * 60 );
372 ntpDelay = delay; 371 ntpDelay = delay;
373} 372}
374 373
375void MainWindow::slotCheckNtp( int i ) 374void MainWindow::slotCheckNtp( int i )
376{ 375{
377 if ( i == 0 ) 376 if ( i == 0 )
378 { 377 {
379 if ( ntpDelayElapsed() ) 378 if ( ntpDelayElapsed() )
380 { 379 {
381 runNTP(); 380 runNTP();
382 disconnect( ntpTimer, SIGNAL(timeout()), this, SLOT(slotProbeNTPServer()) ); 381 disconnect( ntpTimer, SIGNAL(timeout()), this, SLOT(slotProbeNTPServer()) );
383 connect( ntpTimer, SIGNAL(timeout()), SLOT(slotTimerGetNTPTime()) ); 382 connect( ntpTimer, SIGNAL(timeout()), SLOT(slotTimerGetNTPTime()) );
384 } 383 }
385 else 384 else
386 { 385 {
387 disconnect(ntpTimer, SIGNAL(timeout()), this, SLOT(slotTimerGetNTPTime()) ); 386 disconnect(ntpTimer, SIGNAL(timeout()), this, SLOT(slotTimerGetNTPTime()) );
388 connect(ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); 387 connect(ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) );
389 } 388 }
390 } 389 }
391 else 390 else
392 { 391 {
393 predictTab->slotPredictTime(); 392 predictTab->slotPredictTime();
394 if ( i > 0 ) 393 if ( i > 0 )
395 { 394 {
396 QString output = tr( "Could not connect to server " ); 395 QString output = tr( "Could not connect to server " );
397 output.append( settingsTab->ntpServer() ); 396 output.append( settingsTab->ntpServer() );
398 ntpOutput.append( output ); 397 ntpOutput.append( output );
399 if ( ntpTabEnabled ) 398 if ( ntpTabEnabled )
400 ntpTab->addNtpOutput( output ); 399 ntpTab->addNtpOutput( output );
401 } 400 }
402 connect( ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); 401 connect( ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) );
403 } 402 }
404} 403}