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