summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/mainwindow.cpp
authordrw <drw>2005-02-23 16:14:09 (UTC)
committer drw <drw>2005-02-23 16:14:09 (UTC)
commite5b1e010c321ba1edac704f9d668df75b22fd074 (patch) (unidiff)
treec76221c7d8292f66ef05040721edf816a04fbeba /noncore/settings/netsystemtime/mainwindow.cpp
parent30857db6ca3f355aa3d50b59f03a13c82f265af2 (diff)
downloadopie-e5b1e010c321ba1edac704f9d668df75b22fd074.zip
opie-e5b1e010c321ba1edac704f9d668df75b22fd074.tar.gz
opie-e5b1e010c321ba1edac704f9d668df75b22fd074.tar.bz2
Fix UI to prevent error dialog from displaying when it shouldn't
Diffstat (limited to 'noncore/settings/netsystemtime/mainwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/mainwindow.cpp61
1 files changed, 38 insertions, 23 deletions
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp
index 385d355..486257f 100644
--- a/noncore/settings/netsystemtime/mainwindow.cpp
+++ b/noncore/settings/netsystemtime/mainwindow.cpp
@@ -1,35 +1,35 @@
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
@@ -42,25 +42,25 @@
42#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
43#endif 43#endif
44 44
45#include <qlayout.h> 45#include <qlayout.h>
46#include <qmessagebox.h> 46#include <qmessagebox.h>
47#include <qsocket.h> 47#include <qsocket.h>
48#include <qstring.h> 48#include <qstring.h>
49#include <qtimer.h> 49#include <qtimer.h>
50 50
51using namespace Opie::Ui; 51using namespace Opie::Ui;
52using namespace Opie::Core; 52using namespace Opie::Core;
53MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f ) 53MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f )
54 : QDialog( 0x0, 0x0, TRUE, 0 ) 54 : QDialog( parent, name, modal, f )
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;
@@ -178,43 +178,53 @@ void MainWindow::runNTP()
178 178
179 QString srv = settingsTab->ntpServer(); 179 QString srv = settingsTab->ntpServer();
180 180
181 // Send information to time server tab if enabled 181 // Send information to time server tab if enabled
182 if ( ntpTabEnabled ) 182 if ( ntpTabEnabled )
183 { 183 {
184 ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); 184 ntpTab->setStartTime( QDateTime::currentDateTime().toString() );
185 QString output = tr( "Running:\nntpdate " ); 185 QString output = tr( "Running:\nntpdate " );
186 output.append( srv ); 186 output.append( srv );
187 ntpTab->addNtpOutput( output ); 187 ntpTab->addNtpOutput( output );
188 } 188 }
189 189
190 // Disable set time buttons & change app caption to indicate time update is happening
191 ntpTab->setNTPBtnEnabled( false );
192 timeTab->setNTPBtnEnabled( false );
193 setCaption( tr( "Retrieving time from network..." ) );
194
190 if ( !ntpProcess ) 195 if ( !ntpProcess )
191 { 196 {
192 ntpProcess = new OProcess(); 197 ntpProcess = new OProcess();
193 connect( ntpProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), 198 connect( ntpProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),
194 this, SLOT(slotNtpOutput(Opie::Core::OProcess*,char*,int)) ); 199 this, SLOT(slotNtpOutput(Opie::Core::OProcess*,char*,int)) );
195 connect( ntpProcess, SIGNAL(processExited(Opie::Core::OProcess*)), 200 connect( ntpProcess, SIGNAL(processExited(Opie::Core::OProcess*)),
196 this, SLOT(slotNtpFinished(Opie::Core::OProcess*)) ); 201 this, SLOT(slotNtpFinished(Opie::Core::OProcess*)) );
197 } 202 }
198 203
199 else 204 else
200 ntpProcess->clearArguments(); 205 ntpProcess->clearArguments();
201 206
202 *ntpProcess << "ntpdate" << srv; 207 *ntpProcess << "ntpdate" << srv;
203 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); 208 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput );
204 if ( !ret ) 209 if ( !ret )
205 { 210 {
206 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); 211 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) );
207 if ( ntpTabEnabled ) 212 if ( ntpTabEnabled )
208 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); 213 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) );
214
215 // Re-enable set time buttons & change app caption to indicate time update is happening
216 ntpTab->setNTPBtnEnabled( true );
217 timeTab->setNTPBtnEnabled( true );
218 setCaption( tr( "SystemTime" ) );
209 } 219 }
210} 220}
211 221
212bool MainWindow::ntpDelayElapsed() 222bool MainWindow::ntpDelayElapsed()
213{ 223{
214 // Determine if time elapsed is greater than time delay 224 // Determine if time elapsed is greater than time delay
215 Config config( "ntp" ); 225 Config config( "ntp" );
216 config.setGroup( "lookups" ); 226 config.setGroup( "lookups" );
217 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); 227 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 );
218 if ( _lookupDiff < 0 ) 228 if ( _lookupDiff < 0 )
219 return true; 229 return true;
220 return ( _lookupDiff - ( ntpDelay * 60) ) > 0; 230 return ( _lookupDiff - ( ntpDelay * 60) ) > 0;
@@ -289,24 +299,29 @@ void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen )
289 QString output = QString( buffer ).left( buflen ); 299 QString output = QString( buffer ).left( buflen );
290 ntpOutput.append( output ); 300 ntpOutput.append( output );
291 301
292 if ( ntpTabEnabled ) 302 if ( ntpTabEnabled )
293 ntpTab->addNtpOutput( output ); 303 ntpTab->addNtpOutput( output );
294} 304}
295 305
296void MainWindow::slotNtpFinished( OProcess *p ) 306void MainWindow::slotNtpFinished( OProcess *p )
297{ 307{
298 QString output; 308 QString output;
299 QDateTime dt = QDateTime::currentDateTime(); 309 QDateTime dt = QDateTime::currentDateTime();
300 310
311 // Re-enable set time buttons & change app caption to indicate time update is happening
312 ntpTab->setNTPBtnEnabled( true );
313 timeTab->setNTPBtnEnabled( true );
314 setCaption( tr( "SystemTime" ) );
315
301 // Verify run was successful 316 // Verify run was successful
302 if ( p->exitStatus() != 0 || !p->normalExit() ) 317 if ( p->exitStatus() != 0 || !p->normalExit() )
303 { 318 {
304 if ( isVisible() && ntpInteractive ) 319 if ( isVisible() && ntpInteractive )
305 { 320 {
306 output = tr( "Error while getting time from\n server: " ); 321 output = tr( "Error while getting time from\n server: " );
307 output.append( settingsTab->ntpServer() ); 322 output.append( settingsTab->ntpServer() );
308 QMessageBox::critical(this, tr( "Error" ), output ); 323 QMessageBox::critical(this, tr( "Error" ), output );
309 } 324 }
310 // slotCheckNtp(-1); 325 // slotCheckNtp(-1);
311 return; 326 return;
312 } 327 }
@@ -342,25 +357,25 @@ void MainWindow::slotNtpFinished( OProcess *p )
342 // Display information on time server tab 357 // Display information on time server tab
343 if ( ntpTabEnabled ) 358 if ( ntpTabEnabled )
344 { 359 {
345 ntpTab->setTimeShift( output ); 360 ntpTab->setTimeShift( output );
346 ntpTab->setNewTime( dt.toString() ); 361 ntpTab->setNewTime( dt.toString() );
347 } 362 }
348 363
349 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) 364 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay )
350 { 365 {
351 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); 366 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) );
352 config.setGroup( grpname ); 367 config.setGroup( grpname );
353 lookupCount++; 368 lookupCount++;
354 predictTab->setShiftPerSec( timeShift / secsSinceLast ); 369 predictTab->setShiftPerSec( (int)(timeShift / secsSinceLast) );
355 config.writeEntry( "secsSinceLast", secsSinceLast ); 370 config.writeEntry( "secsSinceLast", secsSinceLast );
356 config.writeEntry( "timeShift", QString::number( timeShift ) ); 371 config.writeEntry( "timeShift", QString::number( timeShift ) );
357 config.setGroup( "lookups" ); 372 config.setGroup( "lookups" );
358 config.writeEntry( "count", lookupCount ); 373 config.writeEntry( "count", lookupCount );
359 config.writeEntry( "lastNtp", TRUE ); 374 config.writeEntry( "lastNtp", TRUE );
360 } 375 }
361} 376}
362 377
363void MainWindow::slotNTPDelayChanged( int delay ) 378void MainWindow::slotNTPDelayChanged( int delay )
364{ 379{
365 ntpTimer->changeInterval( delay * 1000 * 60 ); 380 ntpTimer->changeInterval( delay * 1000 * 60 );
366 ntpDelay = delay; 381 ntpDelay = delay;