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