-rw-r--r-- | noncore/settings/netsystemtime/mainwindow.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp index 486257f..01d9a98 100644 --- a/noncore/settings/netsystemtime/mainwindow.cpp +++ b/noncore/settings/netsystemtime/mainwindow.cpp @@ -64,26 +64,26 @@ MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags // Default object pointers to null ntpProcess = 0x0; ntpTab = 0x0; // Add tab widgets mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) ); mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) ); mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) ); mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) ); Config config( "ntp" ); config.setGroup( "settings" ); - slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) ); - slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) ); + slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", false ) ); + slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", false ) ); mainWidget->setCurrentTab( tr( "Time" ) ); layout->addWidget( mainWidget ); connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), this, SLOT(slotQCopReceive(const QCString&,const QByteArray&)) ); // Create NTP socket ntpSock = new QSocket( this ); connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); slotProbeNTPServer(); @@ -119,51 +119,51 @@ MainWindow::~MainWindow() delete ntpProcess; } void MainWindow::accept() { // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends) { QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); disableScreenSaver << 0 << 0 << 0; } // Update the systemtime - timeTab->saveSettings( TRUE ); + timeTab->saveSettings( true ); // Save format options - formatTab->saveSettings( TRUE ); + formatTab->saveSettings( true ); // Save settings options settingsTab->saveSettings(); // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better // grip on itself (example re-trigger alarms for when we travel back in time). DateBookDB db; // Turn back on the screensaver QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); enableScreenSaver << -1 << -1 << -1; // Exit app qApp->quit(); } void MainWindow::reject() { // Reset time settings - timeTab->saveSettings( FALSE ); + timeTab->saveSettings( false ); // Send notifications but do not save settings - formatTab->saveSettings( FALSE ); + formatTab->saveSettings( false ); // Exit app qApp->quit(); } void MainWindow::runNTP() { if ( !ntpDelayElapsed() && ntpInteractive ) { 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 ) ); switch ( @@ -176,53 +176,55 @@ void MainWindow::runNTP() } } QString srv = settingsTab->ntpServer(); // Send information to time server tab if enabled if ( ntpTabEnabled ) { ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); QString output = tr( "Running:\nntpdate " ); output.append( srv ); ntpTab->addNtpOutput( output ); + ntpTab->setNTPBtnEnabled( false ); } // Disable set time buttons & change app caption to indicate time update is happening - ntpTab->setNTPBtnEnabled( false ); timeTab->setNTPBtnEnabled( false ); setCaption( tr( "Retrieving time from network..." ) ); if ( !ntpProcess ) { ntpProcess = new OProcess(); connect( ntpProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), this, SLOT(slotNtpOutput(Opie::Core::OProcess*,char*,int)) ); connect( ntpProcess, SIGNAL(processExited(Opie::Core::OProcess*)), this, SLOT(slotNtpFinished(Opie::Core::OProcess*)) ); } else ntpProcess->clearArguments(); *ntpProcess << "ntpdate" << srv; bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); if ( !ret ) { QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); if ( ntpTabEnabled ) + { ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); + ntpTab->setNTPBtnEnabled( true ); + } // Re-enable set time buttons & change app caption to indicate time update is happening - ntpTab->setNTPBtnEnabled( true ); timeTab->setNTPBtnEnabled( true ); setCaption( tr( "SystemTime" ) ); } } bool MainWindow::ntpDelayElapsed() { // Determine if time elapsed is greater than time delay Config config( "ntp" ); config.setGroup( "lookups" ); _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); if ( _lookupDiff < 0 ) @@ -270,54 +272,55 @@ void MainWindow::slotDisplayPredictTab( bool display ) // Create widget if it hasn't needed if ( display && !predictTab ) { } // Display/hide tab display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) ) : mainWidget->removePage( predictTab ); } void MainWindow::slotGetNTPTime() { - ntpInteractive = TRUE; + ntpInteractive = true; runNTP(); } void MainWindow::slotTimerGetNTPTime() { - ntpInteractive = FALSE; + ntpInteractive = false; runNTP(); } void MainWindow::slotProbeNTPServer() { ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); } void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) { QString output = QString( buffer ).left( buflen ); ntpOutput.append( output ); if ( ntpTabEnabled ) ntpTab->addNtpOutput( output ); } void MainWindow::slotNtpFinished( OProcess *p ) { QString output; QDateTime dt = QDateTime::currentDateTime(); // Re-enable set time buttons & change app caption to indicate time update is happening + if ( ntpTabEnabled ) ntpTab->setNTPBtnEnabled( true ); timeTab->setNTPBtnEnabled( true ); setCaption( tr( "SystemTime" ) ); // Verify run was successful if ( p->exitStatus() != 0 || !p->normalExit() ) { if ( isVisible() && ntpInteractive ) { output = tr( "Error while getting time from\n server: " ); output.append( settingsTab->ntpServer() ); QMessageBox::critical(this, tr( "Error" ), output ); @@ -325,25 +328,25 @@ void MainWindow::slotNtpFinished( OProcess *p ) // slotCheckNtp(-1); return; } // Set controls on time tab to new time value timeTab->setDateTime( dt ); // Write out lookup information Config config( "ntp" ); config.setGroup( "lookups" ); int lastLookup = config.readNumEntry( "time", 0 ); int lookupCount = config.readNumEntry( "count", 0 ); - bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); + bool lastNtp = config.readBoolEntry( "lastNtp", false ); int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); config.writeEntry( "time", time ); // Calculate new time/time shift QString _offset = "offset"; QString _sec = "sec"; QRegExp _reOffset = QRegExp( _offset ); QRegExp _reEndOffset = QRegExp( _sec ); int posOffset = _reOffset.match( ntpOutput ); int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); posOffset += _offset.length() + 1; QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); @@ -362,25 +365,25 @@ void MainWindow::slotNtpFinished( OProcess *p ) } if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) { QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); config.setGroup( grpname ); lookupCount++; predictTab->setShiftPerSec( (int)(timeShift / secsSinceLast) ); config.writeEntry( "secsSinceLast", secsSinceLast ); config.writeEntry( "timeShift", QString::number( timeShift ) ); config.setGroup( "lookups" ); config.writeEntry( "count", lookupCount ); - config.writeEntry( "lastNtp", TRUE ); + config.writeEntry( "lastNtp", true ); } } void MainWindow::slotNTPDelayChanged( int delay ) { ntpTimer->changeInterval( delay * 1000 * 60 ); ntpDelay = delay; } void MainWindow::slotCheckNtp( int i ) { if ( i == 0 ) |