summaryrefslogtreecommitdiff
authordrw <drw>2004-02-22 16:43:28 (UTC)
committer drw <drw>2004-02-22 16:43:28 (UTC)
commita607c211c7ad47f1083fa820da5632a1d2110e44 (patch) (unidiff)
tree364b2e0cd0e80d409ad4462e00c5b510eb75744a
parent58c4c8a50f2a30f5736ee53fdd46c3bf6bc4f8c4 (diff)
downloadopie-a607c211c7ad47f1083fa820da5632a1d2110e44.zip
opie-a607c211c7ad47f1083fa820da5632a1d2110e44.tar.gz
opie-a607c211c7ad47f1083fa820da5632a1d2110e44.tar.bz2
System Time: libopie->libopie2
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/config.in2
-rw-r--r--noncore/settings/netsystemtime/main.cpp4
-rw-r--r--noncore/settings/netsystemtime/mainwindow.cpp543
-rw-r--r--noncore/settings/netsystemtime/mainwindow.h75
-rw-r--r--noncore/settings/netsystemtime/netsystemtime.pro36
-rw-r--r--noncore/settings/netsystemtime/opie-systemtime.control2
6 files changed, 330 insertions, 332 deletions
diff --git a/noncore/settings/netsystemtime/config.in b/noncore/settings/netsystemtime/config.in
index ea90f65..37ac303 100644
--- a/noncore/settings/netsystemtime/config.in
+++ b/noncore/settings/netsystemtime/config.in
@@ -1,4 +1,4 @@
1 config NETSYSTEMTIME 1 config NETSYSTEMTIME
2 boolean "opie-systemtime (clock setup tool with NTP ability)" 2 boolean "opie-systemtime (clock setup tool with NTP ability)"
3 default "y" 3 default "y"
4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE 4 depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI
diff --git a/noncore/settings/netsystemtime/main.cpp b/noncore/settings/netsystemtime/main.cpp
index da98eee..4a2d17c 100644
--- a/noncore/settings/netsystemtime/main.cpp
+++ b/noncore/settings/netsystemtime/main.cpp
@@ -28,8 +28,6 @@
28 28
29#include "mainwindow.h" 29#include "mainwindow.h"
30 30
31#include <qpe/qpeapplication.h> 31#include <opie2/oapplicationfactory.h>
32#include <opie/oapplicationfactory.h>
33
34 32
35OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) 33OPIE_EXPORT_APP( OApplicationFactory<MainWindow> )
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
@@ -33,9 +33,6 @@
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>
@@ -52,348 +49,348 @@
52#include <qtimer.h> 49#include <qtimer.h>
53 50
54MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f ) 51MainWindow::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
117MainWindow::~MainWindow() 114MainWindow::~MainWindow()
118{ 115{
119 if ( ntpProcess ) 116 if ( ntpProcess )
120 delete ntpProcess; 117 delete ntpProcess;
121} 118}
122 119
123void MainWindow::accept() 120void 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
152void MainWindow::reject() 149void 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
164void MainWindow::runNTP() 161void 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
213bool MainWindow::ntpDelayElapsed() 210bool 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
224void MainWindow::slotSetTime( const QDateTime &dt ) 221void MainWindow::slotSetTime( const QDateTime &dt )
225{ 222{
226 timeTab->setDateTime( dt ); 223 timeTab->setDateTime( dt );
227} 224}
228 225
229void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & ) 226void 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
242void MainWindow::slotDisplayNTPTab( bool display ) 239void 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
258void MainWindow::slotDisplayPredictTab( bool display ) 255void 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
271void MainWindow::slotGetNTPTime() 268void MainWindow::slotGetNTPTime()
272{ 269{
273 ntpInteractive = TRUE; 270 ntpInteractive = TRUE;
274 runNTP(); 271 runNTP();
275} 272}
276 273
277void MainWindow::slotTimerGetNTPTime() 274void MainWindow::slotTimerGetNTPTime()
278{ 275{
279 ntpInteractive = FALSE; 276 ntpInteractive = FALSE;
280 runNTP(); 277 runNTP();
281} 278}
282 279
283void MainWindow::slotProbeNTPServer() 280void MainWindow::slotProbeNTPServer()
284{ 281{
285 ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); 282 ntpSock->connectToHost( settingsTab->ntpServer(), 123 );
286} 283}
287 284
288void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) 285void 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
297void MainWindow::slotNtpFinished( OProcess *p ) 294void 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
364void MainWindow::slotNTPDelayChanged( int delay ) 361void 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
370void MainWindow::slotCheckNtp( int i ) 367void 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}
diff --git a/noncore/settings/netsystemtime/mainwindow.h b/noncore/settings/netsystemtime/mainwindow.h
index 1cdbc1a..d4a9713 100644
--- a/noncore/settings/netsystemtime/mainwindow.h
+++ b/noncore/settings/netsystemtime/mainwindow.h
@@ -31,66 +31,69 @@
31 31
32#include <qdialog.h> 32#include <qdialog.h>
33 33
34#include <opie2/oprocess.h>
35#include <opie2/otabwidget.h>
36
34class TimeTabWidget; 37class TimeTabWidget;
35class FormatTabWidget; 38class FormatTabWidget;
36class SettingsTabWidget; 39class SettingsTabWidget;
37class NTPTabWidget; 40class NTPTabWidget;
38class PredictTabWidget; 41class PredictTabWidget;
39 42
40class OProcess; 43using Opie::OTabWidget;
41class OTabWidget; 44
42class QDateTime; 45class QDateTime;
43class QSocket; 46class QSocket;
44class QTimer; 47class QTimer;
45 48
46class MainWindow : public QDialog 49class MainWindow : public QDialog
47{ 50{
48 Q_OBJECT 51 Q_OBJECT
49 52
50public: 53public:
51 MainWindow( QWidget *parent = 0, const char *name = 0, bool modal = FALSE,WFlags f = 0); 54 MainWindow( QWidget *parent = 0, const char *name = 0, bool modal = FALSE,WFlags f = 0);
52 ~MainWindow(); 55 ~MainWindow();
53 static QString appName() { return QString::fromLatin1("systemtime"); } 56 static QString appName() { return QString::fromLatin1("systemtime"); }
54 57
55protected: 58protected:
56 void accept(); 59 void accept();
57 void reject(); 60 void reject();
58 61
59private: 62private:
60 OTabWidget *mainWidget; 63 OTabWidget *mainWidget;
61 64
62 TimeTabWidget *timeTab; 65 TimeTabWidget *timeTab;
63 FormatTabWidget *formatTab; 66 FormatTabWidget *formatTab;
64 SettingsTabWidget *settingsTab; 67 SettingsTabWidget *settingsTab;
65 NTPTabWidget *ntpTab; 68 NTPTabWidget *ntpTab;
66 PredictTabWidget *predictTab; 69 PredictTabWidget *predictTab;
67 70
68 bool ntpTabEnabled; 71 bool ntpTabEnabled;
69 bool predictTabEnabled; 72 bool predictTabEnabled;
70 73
71 OProcess *ntpProcess; 74 OProcess *ntpProcess;
72 QTimer *ntpTimer; 75 QTimer *ntpTimer;
73 QSocket *ntpSock; 76 QSocket *ntpSock;
74 int ntpDelay; 77 int ntpDelay;
75 bool ntpInteractive; 78 bool ntpInteractive;
76 QString ntpOutput; 79 QString ntpOutput;
77 int _lookupDiff; 80 int _lookupDiff;
78 81
79 void runNTP(); 82 void runNTP();
80 bool ntpDelayElapsed(); 83 bool ntpDelayElapsed();
81 84
82private slots: 85private slots:
83 void slotSetTime( const QDateTime & ); 86 void slotSetTime( const QDateTime & );
84 void slotQCopReceive( const QCString &, const QByteArray & ); 87 void slotQCopReceive( const QCString &, const QByteArray & );
85 void slotDisplayNTPTab( bool ); 88 void slotDisplayNTPTab( bool );
86 void slotDisplayPredictTab( bool ); 89 void slotDisplayPredictTab( bool );
87 void slotGetNTPTime(); 90 void slotGetNTPTime();
88 void slotTimerGetNTPTime(); 91 void slotTimerGetNTPTime();
89 void slotProbeNTPServer(); 92 void slotProbeNTPServer();
90 void slotNtpOutput( OProcess *, char *, int ); 93 void slotNtpOutput( OProcess *, char *, int );
91 void slotNtpFinished( OProcess* ); 94 void slotNtpFinished( OProcess* );
92 void slotNTPDelayChanged( int ); 95 void slotNTPDelayChanged( int );
93 void slotCheckNtp( int ); 96 void slotCheckNtp( int );
94}; 97};
95 98
96#endif 99#endif
diff --git a/noncore/settings/netsystemtime/netsystemtime.pro b/noncore/settings/netsystemtime/netsystemtime.pro
index 56f7f6c..70ef67d 100644
--- a/noncore/settings/netsystemtime/netsystemtime.pro
+++ b/noncore/settings/netsystemtime/netsystemtime.pro
@@ -1,21 +1,21 @@
1 CONFIG = qt warn_on release quick-app 1CONFIG = qt warn_on release quick-app
2 HEADERS = mainwindow.h \ 2HEADERS = mainwindow.h \
3 timetabwidget.h \ 3 timetabwidget.h \
4 formattabwidget.h \ 4 formattabwidget.h \
5 settingstabwidget.h \ 5 settingstabwidget.h \
6 predicttabwidget.h \ 6 predicttabwidget.h \
7 ntptabwidget.h 7 ntptabwidget.h
8 SOURCES = main.cpp \ 8SOURCES = main.cpp \
9 mainwindow.cpp \ 9 mainwindow.cpp \
10 timetabwidget.cpp \ 10 timetabwidget.cpp \
11 formattabwidget.cpp \ 11 formattabwidget.cpp \
12 settingstabwidget.cpp \ 12 settingstabwidget.cpp \
13 predicttabwidget.cpp \ 13 predicttabwidget.cpp \
14 ntptabwidget.cpp 14 ntptabwidget.cpp
15 INCLUDEPATH+= $(OPIEDIR)/include 15INCLUDEPATH += $(OPIEDIR)/include
16 DEPENDPATH+= $(OPIEDIR)/include 16DEPENDPATH += $(OPIEDIR)/include
17 LIBS += -lqpe -lopie 17LIBS += -lqpe -lopiecore2 -lopieui2
18 18
19 TARGET = systemtime 19TARGET = systemtime
20 20
21include ( $(OPIEDIR)/include.pro ) 21include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/settings/netsystemtime/opie-systemtime.control b/noncore/settings/netsystemtime/opie-systemtime.control
index 1ebc1da..58afc31 100644
--- a/noncore/settings/netsystemtime/opie-systemtime.control
+++ b/noncore/settings/netsystemtime/opie-systemtime.control
@@ -5,7 +5,7 @@ Section: opie/settings
5Provides: opie-netsystemtime 5Provides: opie-netsystemtime
6Maintainer: Patrick S. Vogt <tille@handhelds.org>, Dan Williams <drw@handhelds.org> 6Maintainer: Patrick S. Vogt <tille@handhelds.org>, Dan Williams <drw@handhelds.org>
7Architecture: arm 7Architecture: arm
8Depends: task-opie-minimal, ntpdate, libopie1 8Depends: task-opie-minimal, ntpdate, libopiecore2, libopieui2
9Description: System time 9Description: System time
10 This utility allows the system time to be set manually 10 This utility allows the system time to be set manually
11 or synced with a timerserver via Internet. 11 or synced with a timerserver via Internet.