-rw-r--r-- | noncore/settings/netsystemtime/mainwindow.cpp | 61 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntptabwidget.cpp | 53 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntptabwidget.h | 46 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/timetabwidget.cpp | 55 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/timetabwidget.h | 47 |
5 files changed, 147 insertions, 115 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,102 +1,102 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General -..}^=.= = ; Public License for more details. -++= -. .` .: - : = ...= . :.=- You should have received a copy of the GNU - -. .:....=;==+<; General Public License along with this file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General +..}^=.= = ; Public License for more details. +++= -. .` .: +: = ...= . :.=- You should have received a copy of the GNU +-. .:....=;==+<; General Public License along with this file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "mainwindow.h" #include "timetabwidget.h" #include "formattabwidget.h" #include "settingstabwidget.h" #include "ntptabwidget.h" #include "predicttabwidget.h" #include <qpe/config.h> #include <qpe/datebookdb.h> #include <qpe/qpeapplication.h> #include <qpe/qpedialog.h> #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif #include <qlayout.h> #include <qmessagebox.h> #include <qsocket.h> #include <qstring.h> #include <qtimer.h> using namespace Opie::Ui; using namespace Opie::Core; MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f ) - : QDialog( 0x0, 0x0, TRUE, 0 ) + : QDialog( parent, name, modal, f ) { setCaption( tr( "SystemTime" ) ); QVBoxLayout *layout = new QVBoxLayout( this ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Create main tabbed control mainWidget = new OTabWidget( this ); // 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 ) ); 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(); // Create timer for automatic time lookups ntpTimer = new QTimer( this ); // Connect everything together connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); connect( timeTab, SIGNAL(tzChanged(const QString&)), predictTab, SLOT(slotTZChanged(const QString&)) ); connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) ); connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime(int)) ); connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat&)), timeTab, SLOT(slotDateFormatChanged(const DateFormat&)) ); connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) ); connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) ); @@ -142,257 +142,272 @@ void MainWindow::accept() // 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 ); // Send notifications but do not save settings 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 ( QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No ) ) { case QMessageBox::Yes: break; case QMessageBox::No: return; default: return; } } 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 ); } + // 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" ) ); + + // 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 ) return true; return ( _lookupDiff - ( ntpDelay * 60) ) > 0; } void MainWindow::slotSetTime( const QDateTime &dt ) { timeTab->setDateTime( dt ); } void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & ) { if ( msg == "ntpLookup(QString)" ) { ntpInteractive = false; runNTP(); } if ( msg == "setPredictedTime(QString)" ) { //setPredictTime(); } } void MainWindow::slotDisplayNTPTab( bool display ) { ntpTabEnabled = display; // Create widget if it hasn't needed if ( display && !ntpTab ) { ntpTab = new NTPTabWidget( mainWidget ); connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); } // Display/hide tab display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) ) : mainWidget->removePage( ntpTab ); } void MainWindow::slotDisplayPredictTab( bool display ) { predictTabEnabled = 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; runNTP(); } void MainWindow::slotTimerGetNTPTime() { 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 + 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 ); } // 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 ); 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 ); float timeShift = diff.toFloat(); if ( timeShift == 0.0 ) return; int secsSinceLast = time - lastLookup; output = tr( "%1 seconds").arg(QString::number( timeShift )); // Display information on time server tab if ( ntpTabEnabled ) { ntpTab->setTimeShift( output ); ntpTab->setNewTime( dt.toString() ); } if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) { QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); config.setGroup( grpname ); lookupCount++; - predictTab->setShiftPerSec( timeShift / secsSinceLast ); + 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 ); } } void MainWindow::slotNTPDelayChanged( int delay ) { ntpTimer->changeInterval( delay * 1000 * 60 ); ntpDelay = delay; } void MainWindow::slotCheckNtp( int i ) { if ( i == 0 ) { if ( ntpDelayElapsed() ) { runNTP(); disconnect( ntpTimer, SIGNAL(timeout()), this, SLOT(slotProbeNTPServer()) ); connect( ntpTimer, SIGNAL(timeout()), SLOT(slotTimerGetNTPTime()) ); } else { disconnect(ntpTimer, SIGNAL(timeout()), this, SLOT(slotTimerGetNTPTime()) ); connect(ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); } } else { predictTab->slotPredictTime(); if ( i > 0 ) { QString output = tr( "Could not connect to server " ); output.append( settingsTab->ntpServer() ); ntpOutput.append( output ); if ( ntpTabEnabled ) ntpTab->addNtpOutput( output ); } connect( ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) ); } } diff --git a/noncore/settings/netsystemtime/ntptabwidget.cpp b/noncore/settings/netsystemtime/ntptabwidget.cpp index d71c230..616bc22 100644 --- a/noncore/settings/netsystemtime/ntptabwidget.cpp +++ b/noncore/settings/netsystemtime/ntptabwidget.cpp @@ -1,107 +1,112 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General -..}^=.= = ; Public License for more details. -++= -. .` .: - : = ...= . :.=- You should have received a copy of the GNU - -. .:....=;==+<; General Public License along with this file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General +..}^=.= = ; Public License for more details. +++= -. .` .: +: = ...= . :.=- You should have received a copy of the GNU +-. .:....=;==+<; General Public License along with this file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "ntptabwidget.h" #include <qpe/resource.h> #include <qlabel.h> #include <qlayout.h> #include <qmultilineedit.h> #include <qpushbutton.h> #include <qscrollview.h> NTPTabWidget::NTPTabWidget( QWidget *parent ) : QWidget( parent, 0x0, 0 ) { QVBoxLayout *tmpvb = new QVBoxLayout( this ); QScrollView *sv = new QScrollView( this ); tmpvb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Start time layout->addWidget( new QLabel( tr( "Start time" ), container ), 0, 0 ); lblStartTime = new QLabel( tr( "n/a" ), container ); layout->addWidget( lblStartTime, 0, 1 ); // Time shift layout->addWidget( new QLabel( tr( "Time shift" ), container ), 1, 0 ); lblTimeShift = new QLabel( tr( "n/a" ), container ); layout->addWidget( lblTimeShift, 1, 1 ); // New time layout->addWidget( new QLabel( tr( "New time" ), container ), 2, 0 ); lblNewTime = new QLabel( tr( "n/a" ), container ); layout->addWidget( lblNewTime, 2, 1 ); // NTP output display mleNtpOutput = new QMultiLineEdit( container ); QFont font( mleNtpOutput->font() ); font.setPointSize( 7 ); mleNtpOutput->setFont( font ); mleNtpOutput->setWordWrap( QMultiLineEdit::WidgetWidth ); layout->addMultiCellWidget( mleNtpOutput, 3, 3, 0, 1 ); // Set NTP time button - QPushButton *pb = new QPushButton( Resource::loadPixmap( "netsystemtime/ntptab" ), + m_ntpBtn = new QPushButton( Resource::loadPixmap( "netsystemtime/ntptab" ), tr( "Get time from the network" ), container ); - connect( pb, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) ); - layout->addMultiCellWidget( pb, 4, 4, 0, 1 ); + connect( m_ntpBtn, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) ); + layout->addMultiCellWidget( m_ntpBtn, 4, 4, 0, 1 ); } NTPTabWidget::~NTPTabWidget() { } void NTPTabWidget::setStartTime( const QString &str ) { lblStartTime->setText( str ); } void NTPTabWidget::setTimeShift( const QString &str ) { lblTimeShift->setText( str ); } void NTPTabWidget::setNewTime( const QString &str ) { lblNewTime->setText( str ); } void NTPTabWidget::addNtpOutput( const QString &str ) { mleNtpOutput->append( str ); mleNtpOutput->setCursorPosition( mleNtpOutput->numLines() + 1, 0, FALSE ); } + +void NTPTabWidget::setNTPBtnEnabled( bool enabled ) +{ + m_ntpBtn->setEnabled( enabled ); +} diff --git a/noncore/settings/netsystemtime/ntptabwidget.h b/noncore/settings/netsystemtime/ntptabwidget.h index 811c57e..f05482e 100644 --- a/noncore/settings/netsystemtime/ntptabwidget.h +++ b/noncore/settings/netsystemtime/ntptabwidget.h @@ -1,60 +1,64 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General -..}^=.= = ; Public License for more details. -++= -. .` .: - : = ...= . :.=- You should have received a copy of the GNU - -. .:....=;==+<; General Public License along with this file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General +..}^=.= = ; Public License for more details. +++= -. .` .: +: = ...= . :.=- You should have received a copy of the GNU +-. .:....=;==+<; General Public License along with this file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef NTPTABWIDGET_H #define NTPTABWIDGET_H #include <qwidget.h> class QLabel; class QMultiLineEdit; +class QPushButton; class NTPTabWidget : public QWidget { Q_OBJECT public: NTPTabWidget( QWidget * = 0x0 ); ~NTPTabWidget(); void setStartTime( const QString & ); void setTimeShift( const QString & ); void setNewTime( const QString & ); void addNtpOutput( const QString & ); + void setNTPBtnEnabled( bool enabled ); private: QLabel *lblStartTime; QLabel *lblTimeShift; QLabel *lblNewTime; QMultiLineEdit *mleNtpOutput; + QPushButton *m_ntpBtn; + signals: void getNTPTime(); }; #endif diff --git a/noncore/settings/netsystemtime/timetabwidget.cpp b/noncore/settings/netsystemtime/timetabwidget.cpp index 3cc127d..905461f 100644 --- a/noncore/settings/netsystemtime/timetabwidget.cpp +++ b/noncore/settings/netsystemtime/timetabwidget.cpp @@ -1,242 +1,247 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General -..}^=.= = ; Public License for more details. -++= -. .` .: - : = ...= . :.=- You should have received a copy of the GNU - -. .:....=;==+<; General Public License along with this file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General +..}^=.= = ; Public License for more details. +++= -. .` .: +: = ...= . :.=- You should have received a copy of the GNU +-. .:....=;==+<; General Public License along with this file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "timetabwidget.h" #include <qpe/config.h> #include <qpe/datebookmonth.h> #include <qpe/global.h> #include <qpe/resource.h> #include <qpe/tzselect.h> #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif #include <qcombobox.h> #include <qdatetime.h> #include <qframe.h> #include <qlabel.h> #include <qlayout.h> #include <qpushbutton.h> #include <qscrollview.h> #include <qspinbox.h> #include <stdlib.h> #include <sys/time.h> static const int ValueAM = 0; static const int ValuePM = 1; TimeTabWidget::TimeTabWidget( QWidget *parent ) : QWidget( parent, 0x0, 0 ) { // Synchronize HW clock to systemtime // This app will update systemtime // - if Cancel is clicked, will reset systemtime to HW clock's time // - if Ok is clicked, will leave systemtime as is system("/sbin/hwclock --systohc --utc"); QVBoxLayout *tmpvb = new QVBoxLayout( this ); QScrollView *sv = new QScrollView( this ); tmpvb->addWidget( sv, 0, 0 ); sv->setResizePolicy( QScrollView::AutoOneFit ); sv->setFrameStyle( QFrame::NoFrame ); QWidget *container = new QWidget( sv->viewport() ); sv->addChild( container ); QGridLayout *layout = new QGridLayout( container ); layout->setMargin( 2 ); layout->setSpacing( 4 ); // Hours layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 ); sbHour = new QSpinBox( container ); sbHour->setWrapping( TRUE ); layout->addMultiCellWidget( sbHour, 2, 2, 0, 1 ); // Minutes layout->addMultiCellWidget( new QLabel( tr( "Minute" ), container ), 1, 1, 2, 3 ); sbMin = new QSpinBox( container ); sbMin->setWrapping( TRUE ); sbMin->setMinValue( 0 ); sbMin->setMaxValue( 59 ); layout->addMultiCellWidget( sbMin, 2, 2, 2, 3 ); // AM/PM cbAmpm = new QComboBox( container ); cbAmpm->insertItem( tr( "AM" ), ValueAM ); cbAmpm->insertItem( tr( "PM" ), ValuePM ); layout->addMultiCellWidget( cbAmpm, 2, 2, 4, 5 ); // Date layout->addWidget( new QLabel( tr( "Date" ), container ), 4, 0 ); btnDate = new DateButton( TRUE, container ); layout->addMultiCellWidget( btnDate, 4, 4, 1, 5 ); // Timezone layout->addMultiCellWidget( new QLabel( tr( "Time zone" ), container ), 6, 6, 0, 1 ); selTimeZone = new TimeZoneSelector( container ); connect( selTimeZone, SIGNAL(signalNewTz(const QString&)), this, SLOT(slotTZChanged(const QString&)) ); layout->addMultiCellWidget( selTimeZone, 6, 6, 2, 5 ); // Space filler layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 ); // Set NTP time button - QPushButton *pb = new QPushButton( Resource::loadPixmap( "netsystemtime/ntptab" ), + m_ntpBtn = new QPushButton( Resource::loadPixmap( "netsystemtime/ntptab" ), tr( "Get time from the network" ), container ); - connect( pb, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) ); - layout->addMultiCellWidget( pb, 8, 8, 0, 5 ); + connect( m_ntpBtn, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) ); + layout->addMultiCellWidget( m_ntpBtn, 8, 8, 0, 5 ); // Set predicted time button - pb = new QPushButton( Resource::loadPixmap( "netsystemtime/predicttab" ), tr( "Set predicted time" ), + QPushButton *pb = new QPushButton( Resource::loadPixmap( "netsystemtime/predicttab" ), tr( "Set predicted time" ), container ); connect( pb, SIGNAL(clicked()), this, SIGNAL(getPredictedTime()) ); layout->addMultiCellWidget( pb, 9, 9, 0, 5 ); // Space filler at bottom of widget layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 10, 0 ); // Initialize values Config config( "locale" ); config.setGroup( "Location" ); selTimeZone->setCurrentZone( config.readEntry( "Timezone", "America/New_York" ) ); use12HourTime = FALSE; setDateTime( QDateTime::currentDateTime() ); } TimeTabWidget::~TimeTabWidget() { } void TimeTabWidget::saveSettings( bool commit ) { if ( commit ) { // Set timezone and announce to world QString tz = selTimeZone->currentZone(); Config config("locale"); config.setGroup( "Location" ); config.writeEntry( "Timezone", tz ); setenv( "TZ", tz, 1 ); QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); setTimeZone << tz; // If controls have a valid date & time, update systemtime int hour = sbHour->value(); if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) hour += 12; QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); setSystemTime( dt ); } else { // Reset systemtime to hardware clock (i.e. undo any changes made by this app) system("/sbin/hwclock --hctosys --utc"); } } void TimeTabWidget::setDateTime( const QDateTime &dt ) { // Set time QTime t = dt.time(); if( use12HourTime ) { int show_hour = t.hour(); if ( t.hour() >= 12 ) { show_hour -= 12; cbAmpm->setCurrentItem( ValuePM ); } else { cbAmpm->setCurrentItem( ValueAM ); } if ( show_hour == 0 ) show_hour = 12; sbHour->setValue( show_hour ); } else { sbHour->setValue( t.hour() ); } sbMin->setValue( t.minute() ); // Set date btnDate->setDate( dt.date() ); } +void TimeTabWidget::setNTPBtnEnabled( bool enabled ) +{ + m_ntpBtn->setEnabled( enabled ); +} + void TimeTabWidget::setSystemTime( const QDateTime &dt ) { // Set system clock if ( dt.isValid() ) { struct timeval myTv; int t = TimeConversion::toUTC( dt ); myTv.tv_sec = t; myTv.tv_usec = 0; if ( myTv.tv_sec != -1 ) ::settimeofday( &myTv, 0 ); /* * Commit the datetime to the 'hardware' * as Global::writeHWClock() is a NOOP with Opie Alarm */ system("/sbin/hwclock --systohc --utc"); } } void TimeTabWidget::slotUse12HourTime( int i ) { use12HourTime = (i == 1); cbAmpm->setEnabled( use12HourTime ); int show_hour = sbHour->value(); if ( use12HourTime ) { sbHour->setMinValue( 1 ); sbHour->setMaxValue( 12 ); if ( show_hour >= 12 ) { show_hour -= 12; cbAmpm->setCurrentItem( ValuePM ); } else { cbAmpm->setCurrentItem( ValueAM ); } if ( show_hour == 0 ) show_hour = 12; } else { diff --git a/noncore/settings/netsystemtime/timetabwidget.h b/noncore/settings/netsystemtime/timetabwidget.h index f44a1da..949535d 100644 --- a/noncore/settings/netsystemtime/timetabwidget.h +++ b/noncore/settings/netsystemtime/timetabwidget.h @@ -1,77 +1,80 @@ /* - This file is part of the OPIE Project + This file is part of the OPIE Project =. - .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> - .>+-= - _;:, .> :=|. This file is free software; you can -.> <`_, > . <= redistribute it and/or modify it under -:`=1 )Y*s>-.-- : the terms of the GNU General Public -.="- .-=="i, .._ License as published by the Free Software - - . .-<_> .<> Foundation; either version 2 of the License, - ._= =} : or (at your option) any later version. - .%`+i> _;_. - .i_,=:_. -<s. This file is distributed in the hope that - + . -:. = it will be useful, but WITHOUT ANY WARRANTY; - : .. .:, . . . without even the implied warranty of - =_ + =;=|` MERCHANTABILITY or FITNESS FOR A - _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General -..}^=.= = ; Public License for more details. -++= -. .` .: - : = ...= . :.=- You should have received a copy of the GNU - -. .:....=;==+<; General Public License along with this file; - -_. . . )=. = see the file COPYING. If not, write to the - -- :-=` Free Software Foundation, Inc., + .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> + .>+-= +_;:, .> :=|. This file is free software; you can +.> <`_, > . <= redistribute it and/or modify it under +:`=1 )Y*s>-.-- : the terms of the GNU General Public +.="- .-=="i, .._ License as published by the Free Software +- . .-<_> .<> Foundation; either version 2 of the License, + ._= =} : or (at your option) any later version. + .%`+i> _;_. + .i_,=:_. -<s. This file is distributed in the hope that + + . -:. = it will be useful, but WITHOUT ANY WARRANTY; + : .. .:, . . . without even the implied warranty of + =_ + =;=|` MERCHANTABILITY or FITNESS FOR A + _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General +..}^=.= = ; Public License for more details. +++= -. .` .: +: = ...= . :.=- You should have received a copy of the GNU +-. .:....=;==+<; General Public License along with this file; + -_. . . )=. = see the file COPYING. If not, write to the + -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef TIMETABWIDGET_H #define TIMETABWIDGET_H #include <qwidget.h> class DateButton; class DateFormat; class QComboBox; class QDateTime; +class QPushButton; class QSpinBox; class TimeZoneSelector; class TimeTabWidget : public QWidget { Q_OBJECT public: - TimeTabWidget( QWidget * = 0x0 ); + TimeTabWidget( QWidget * = 0l ); ~TimeTabWidget(); void saveSettings( bool ); void setDateTime( const QDateTime & ); + void setNTPBtnEnabled( bool enabled ); private: QSpinBox *sbHour; QSpinBox *sbMin; QComboBox *cbAmpm; DateButton *btnDate; TimeZoneSelector *selTimeZone; + QPushButton *m_ntpBtn; bool use12HourTime; void setSystemTime( const QDateTime & ); signals: void tzChanged( const QString & ); void getNTPTime(); void getPredictedTime(); public slots: void slotUse12HourTime( int ); void slotDateFormatChanged( const DateFormat & ); void slotWeekStartChanged( int ); private slots: void slotTZChanged( const QString & ); }; #endif |