summaryrefslogtreecommitdiff
path: root/noncore
authordrw <drw>2003-04-13 22:32:47 (UTC)
committer drw <drw>2003-04-13 22:32:47 (UTC)
commit166ac140f8e01369a5d281c2918b0f8b9045f8e5 (patch) (side-by-side diff)
tree672cbb8318703b6cedc7f83fb72c058d0b592c9e /noncore
parentf47258125bac368987a90ca49a118721ecbc3a8b (diff)
downloadopie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.zip
opie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.tar.gz
opie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.tar.bz2
Revamped NetSystemTime! Changes include: 1. improved UI (e.g. ok/cancel work, timezone correctly changes date, new layout better suited for running in landscape mode, etc.) 2. improved code organization 3. smaller executable
Diffstat (limited to 'noncore') (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/formattabwidget.cpp168
-rw-r--r--noncore/settings/netsystemtime/formattabwidget.h65
-rw-r--r--noncore/settings/netsystemtime/main.cpp37
-rw-r--r--noncore/settings/netsystemtime/mainwindow.cpp404
-rw-r--r--noncore/settings/netsystemtime/mainwindow.h95
-rw-r--r--noncore/settings/netsystemtime/netsystemtime.pro17
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp446
-rw-r--r--noncore/settings/netsystemtime/ntp.h58
-rw-r--r--noncore/settings/netsystemtime/ntpbase.ui838
-rw-r--r--noncore/settings/netsystemtime/ntptabwidget.cpp107
-rw-r--r--noncore/settings/netsystemtime/ntptabwidget.h60
-rw-r--r--noncore/settings/netsystemtime/predicttabwidget.cpp167
-rw-r--r--noncore/settings/netsystemtime/predicttabwidget.h68
-rw-r--r--noncore/settings/netsystemtime/settime.cpp533
-rw-r--r--noncore/settings/netsystemtime/settime.h102
-rw-r--r--noncore/settings/netsystemtime/settingstabwidget.cpp159
-rw-r--r--noncore/settings/netsystemtime/settingstabwidget.h62
-rw-r--r--noncore/settings/netsystemtime/timetabwidget.cpp292
-rw-r--r--noncore/settings/netsystemtime/timetabwidget.h77
19 files changed, 1769 insertions, 1986 deletions
diff --git a/noncore/settings/netsystemtime/formattabwidget.cpp b/noncore/settings/netsystemtime/formattabwidget.cpp
new file mode 100644
index 0000000..daa020f
--- a/dev/null
+++ b/noncore/settings/netsystemtime/formattabwidget.cpp
@@ -0,0 +1,168 @@
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "formattabwidget.h"
+
+#include <qpe/config.h>
+
+#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
+#include <qpe/qcopenvelope_qws.h>
+#endif
+
+#include <qcombobox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qscrollview.h>
+#include <qtimer.h>
+
+FormatTabWidget::FormatTabWidget( 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 );
+
+ // Time format selector
+ layout->addWidget( new QLabel( tr( "Time format" ), container ), 0, 0 );
+ cbAppletFormat = new QComboBox( container );
+ cbAppletFormat->insertItem( tr( "hh:mm" ), 0 );
+ cbAppletFormat->insertItem( tr( "D/M hh:mm" ), 1 );
+ cbAppletFormat->insertItem( tr( "M/D hh:mm" ), 2 );
+ layout->addWidget( cbAppletFormat, 0, 1 );
+
+ // 12/24 hour selector
+ layout->addWidget( new QLabel( tr( "12/24 hour" ), container ), 1, 0 );
+ cbAmpm = new QComboBox( container );
+ cbAmpm->insertItem( tr( "24 hour" ), 0 );
+ cbAmpm->insertItem( tr( "12 hour" ), 1 );
+ connect( cbAmpm, SIGNAL(activated(int)), this, SIGNAL(show12HourTime(int)) );
+ layout->addWidget( cbAmpm, 1, 1 );
+
+ // Date format selector
+ layout->addWidget( new QLabel( tr( "Date format" ), container ), 2, 0 );
+ cbDateFormat = new QComboBox( container );
+ connect( cbDateFormat, SIGNAL(activated(int)), this, SLOT(slotDateFormatChanged(int)) );
+ layout->addWidget( cbDateFormat, 2, 1 );
+
+ // Week starts on selector
+ layout->addWidget( new QLabel( tr( "Weeks start on" ), container ), 3, 0 );
+ cbWeekStart = new QComboBox( container );
+ cbWeekStart->insertItem( tr( "Sunday" ), 0 );
+ cbWeekStart->insertItem( tr( "Monday" ), 1 );
+ connect( cbWeekStart, SIGNAL(activated(int)), this, SIGNAL(weekStartChanged(int)) );
+ layout->addWidget( cbWeekStart, 3, 1 );
+
+ // Initialize values
+ Config config( "qpe" );
+ config.setGroup( "Date" );
+ cbAppletFormat->setCurrentItem( config.readNumEntry( "ClockApplet", 0 ) );
+
+ DateFormat df(QChar(config.readEntry("Separator", "/")[0]),
+ (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
+ (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
+
+ int currentdf = 0;
+ date_formats[0] = DateFormat( '/', DateFormat::MonthDayYear );
+ cbDateFormat->insertItem( tr( date_formats[0].toNumberString() ) );
+ date_formats[1] = DateFormat( '.', DateFormat::DayMonthYear );
+ if ( df == date_formats[1] )
+ currentdf = 1;
+ cbDateFormat->insertItem( tr( date_formats[1].toNumberString() ) );
+ date_formats[2] = DateFormat( '-', DateFormat::YearMonthDay, DateFormat::DayMonthYear );
+ if ( df == date_formats[2] )
+ currentdf = 2;
+ cbDateFormat->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601
+ date_formats[3] = DateFormat( '/', DateFormat::DayMonthYear );
+ if ( df == date_formats[3] )
+ currentdf = 3;
+ cbDateFormat->insertItem( tr( date_formats[3].toNumberString() ) );
+
+ cbDateFormat->setCurrentItem( currentdf );
+ //dateButton->setDateFormat( df );
+
+ config.setGroup( "Time" );
+ cbAmpm->setCurrentItem( config.readBoolEntry( "AMPM" ) ? 1 : 0 );
+ cbWeekStart->setCurrentItem( config.readBoolEntry( "MONDAY" ) ? 1 : 0 );
+
+ // Send initial configuration options
+ QTimer::singleShot( 1200, this, SLOT(sendOptions()) );
+}
+
+FormatTabWidget::~FormatTabWidget()
+{
+}
+
+void FormatTabWidget::saveSettings( bool commit )
+{
+ int ampm = cbAmpm->currentItem();
+ int weekstart = cbWeekStart->currentItem();
+ DateFormat df = date_formats[cbDateFormat->currentItem()];
+ int appletformat = cbAppletFormat->currentItem();
+
+ if ( commit )
+ {
+ // Write settings to config file
+ Config config("qpe");
+ config.setGroup( "Time" );
+ config.writeEntry( "AMPM", ampm );
+ config.writeEntry( "MONDAY", weekstart );
+ config.setGroup( "Date" );
+ config.writeEntry( "Separator", QString( df.separator() ) );
+ config.writeEntry( "ShortOrder", df.shortOrder() );
+ config.writeEntry( "LongOrder", df.longOrder() );
+ config.writeEntry( "ClockApplet", appletformat );
+ }
+
+ // Make rest of system aware of new settings
+ QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
+ setClock << ampm;
+ QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
+ setWeek << weekstart;
+ QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
+ setDateFormat << df;
+}
+
+void FormatTabWidget::slotDateFormatChanged( int selected )
+{
+ emit dateFormatChanged( date_formats[selected] );
+}
+
+void FormatTabWidget::sendOptions()
+{
+ emit show12HourTime( cbAmpm->currentItem() );
+ emit dateFormatChanged( date_formats[cbDateFormat->currentItem()] );
+ emit weekStartChanged( cbWeekStart->currentItem() );
+}
diff --git a/noncore/settings/netsystemtime/formattabwidget.h b/noncore/settings/netsystemtime/formattabwidget.h
new file mode 100644
index 0000000..e4073e7
--- a/dev/null
+++ b/noncore/settings/netsystemtime/formattabwidget.h
@@ -0,0 +1,65 @@
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef FORMATTABWIDGET_H
+#define FORMATTABWIDGET_H
+
+#include <qpe/timestring.h>
+
+#include <qwidget.h>
+
+class QComboBox;
+
+class FormatTabWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ FormatTabWidget( QWidget * = 0x0 );
+ ~FormatTabWidget();
+
+ void saveSettings( bool );
+
+private:
+ QComboBox *cbAmpm;
+ QComboBox *cbWeekStart;
+ QComboBox *cbDateFormat;
+ QComboBox *cbAppletFormat;
+ DateFormat date_formats[4];
+
+signals:
+ void show12HourTime( int );
+ void dateFormatChanged( const DateFormat & );
+ void weekStartChanged( int );
+
+private slots:
+ void slotDateFormatChanged( int );
+ void sendOptions();
+};
+
+#endif
diff --git a/noncore/settings/netsystemtime/main.cpp b/noncore/settings/netsystemtime/main.cpp
index 80fbcb8..4b20a61 100644
--- a/noncore/settings/netsystemtime/main.cpp
+++ b/noncore/settings/netsystemtime/main.cpp
@@ -1,15 +1,40 @@
-#include <stdio.h>
-#include "ntp.h"
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "mainwindow.h"
+
#include <qpe/qpeapplication.h>
int main( int argc, char ** argv )
{
- printf("This is netsystemtime ");
- printf("$Id$\n");
-
QPEApplication a( argc, argv );
- Ntp mw;
+ MainWindow mw;
a.showMainWidget( &mw );
return a.exec();
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp
new file mode 100644
index 0000000..306117a
--- a/dev/null
+++ b/noncore/settings/netsystemtime/mainwindow.cpp
@@ -0,0 +1,404 @@
+/*
+                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.,
+ 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 "systemtimeconfig.h"
+
+#include <opie/oprocess.h>
+#include <opie/otabwidget.h>
+
+#include <qpe/config.h>
+#include <qpe/datebookdb.h>
+#include <qpe/qpeapplication.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>
+
+MainWindow::MainWindow()
+ : QDialog( 0x0, 0x0, TRUE, 0 )
+{
+ 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 );
+
+ // Create QCOP channel
+ QCopChannel *channel = new QCopChannel( "QPE/Application/netsystemtime", this );
+ connect( channel, SIGNAL(received(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)) );
+ connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) );
+ connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) );
+ connect( predictTab, SIGNAL(setTime(const QDateTime &)), this, SLOT(slotSetTime(const QDateTime &)) );
+
+ // Do initial time server check
+ slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) );
+ slotCheckNtp( -1 );
+
+ // Display app
+ showMaximized();
+}
+
+MainWindow::~MainWindow()
+{
+ if ( ntpProcess )
+ 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 );
+
+ // Save format options
+ 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 );
+
+ // 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 " );
+ msg.append( QString::number( ntpDelay ) );
+ msg.append( tr( " minutes, but only " ) );
+ msg.append( QString::number( _lookupDiff / 60 ) );
+ msg.append( tr(" minutes elapsed since last lookup.<br>Continue?") );
+
+ 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 );
+ }
+
+ if ( !ntpProcess )
+ {
+ ntpProcess = new OProcess();
+ connect( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
+ this, SLOT(slotNtpOutput(OProcess*,char*,int)) );
+ connect( ntpProcess, SIGNAL(processExited(OProcess*)),
+ this, SLOT(slotNtpFinished(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" ) );
+ }
+}
+
+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();
+
+ // 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 = QString::number( timeShift );
+ output.append( tr( " seconds" ) );
+
+ // 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 );
+ 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/mainwindow.h b/noncore/settings/netsystemtime/mainwindow.h
new file mode 100644
index 0000000..fa94335
--- a/dev/null
+++ b/noncore/settings/netsystemtime/mainwindow.h
@@ -0,0 +1,95 @@
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef MAINWINDOW_H
+#define MAINWINDOW_H
+
+#include <qdialog.h>
+
+class TimeTabWidget;
+class FormatTabWidget;
+class SettingsTabWidget;
+class NTPTabWidget;
+class PredictTabWidget;
+
+class OProcess;
+class OTabWidget;
+class QDateTime;
+class QSocket;
+class QTimer;
+
+class MainWindow : public QDialog
+{
+ Q_OBJECT
+
+public:
+ MainWindow();
+ ~MainWindow();
+
+protected:
+ void accept();
+ void reject();
+
+private:
+ OTabWidget *mainWidget;
+
+ TimeTabWidget *timeTab;
+ FormatTabWidget *formatTab;
+ SettingsTabWidget *settingsTab;
+ NTPTabWidget *ntpTab;
+ PredictTabWidget *predictTab;
+
+ bool ntpTabEnabled;
+ bool predictTabEnabled;
+
+ OProcess *ntpProcess;
+ QTimer *ntpTimer;
+ QSocket *ntpSock;
+ int ntpDelay;
+ bool ntpInteractive;
+ QString ntpOutput;
+ int _lookupDiff;
+
+ void runNTP();
+ bool ntpDelayElapsed();
+
+private slots:
+ void slotSetTime( const QDateTime & );
+ void slotQCopReceive( const QCString &, const QByteArray & );
+ void slotDisplayNTPTab( bool );
+ void slotDisplayPredictTab( bool );
+ void slotGetNTPTime();
+ void slotTimerGetNTPTime();
+ void slotProbeNTPServer();
+ void slotNtpOutput( OProcess *, char *, int );
+ void slotNtpFinished( OProcess* );
+ void slotNTPDelayChanged( int );
+ void slotCheckNtp( int );
+};
+
+#endif
diff --git a/noncore/settings/netsystemtime/netsystemtime.pro b/noncore/settings/netsystemtime/netsystemtime.pro
index 3d0f299..0d154a6 100644
--- a/noncore/settings/netsystemtime/netsystemtime.pro
+++ b/noncore/settings/netsystemtime/netsystemtime.pro
@@ -1,12 +1,23 @@
TEMPLATE = app
CONFIG = qt warn_on debug
#CONFIG = qt warn_on release
-HEADERS = ntp.h settime.h
-SOURCES = main.cpp ntp.cpp settime.cpp
+HEADERS = mainwindow.h \
+ timetabwidget.h \
+ formattabwidget.h \
+ settingstabwidget.h \
+ predicttabwidget.h \
+ ntptabwidget.h
+SOURCES = main.cpp \
+ mainwindow.cpp \
+ timetabwidget.cpp \
+ formattabwidget.cpp \
+ settingstabwidget.cpp \
+ predicttabwidget.cpp \
+ ntptabwidget.cpp
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie
-INTERFACES = ntpbase.ui
+INTERFACES =
DESTDIR = $(OPIEDIR)/bin
TARGET = systemtime
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
deleted file mode 100644
index f653cd0..0000000
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/dev/null
@@ -1,446 +0,0 @@
-#include "ntp.h"
-#include <qpushbutton.h>
-#include <qregexp.h>
-#include <qtimer.h>
-#include <qtable.h>
-#include <qlabel.h>
-#include <qsocket.h>
-#include <qlineedit.h>
-#include <qspinbox.h>
-#include <qcheckbox.h>
-#include <qtabwidget.h>
-#include <qlayout.h>
-#include <qmessagebox.h>
-#include <qmultilineedit.h>
-#include <opie/oprocess.h>
-#include <qpe/qpeapplication.h>
-#include <qpe/config.h>
-#include <qpe/global.h>
-#include <qpe/timeconversion.h>
-#include <qpe/tzselect.h>
-#include <qpe/timestring.h>
-#include <qpe/qpedialog.h>
-#include <qpe/datebookdb.h>
-#include <qpe/datebookmonth.h>
-#include <qpe/qcopenvelope_qws.h>
-#include <sys/time.h>
-#include <time.h>
-#include <stdlib.h>
-
-
-Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
- : SetDateTime( parent, name, fl )
-{
- _interactive = false;
- Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
- ntpSrvs.setGroup("servers");
- int srvCount = ntpSrvs.readNumEntry("count", 0 );
- for (int i = 0; i < srvCount; i++)
- {
- ntpSrvs.setGroup(QString::number(i));
- ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
- }
- if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
-
- Config cfg("ntp",Config::User);
- cfg.setGroup("settings");
- SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) );
- SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) );
- ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
-
- //make tab order
-
- TabWidgetMain->removePage( tabMain );
- TabWidgetMain->removePage( tabManualSetTime );
- TabWidgetMain->removePage( TabSettings );
- TabWidgetMain->removePage( tabPredict );
- TabWidgetMain->removePage( tabNtp );
-
- TabWidgetMain->insertTab( tabMain, tr( "Main" ) );
- TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) );
- TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) );
- TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) );
- NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 );
-
-
-
- bool advMode = cfg.readBoolEntry("advancedFeatures", false );
- showAdvancedFeatures(advMode);
- CheckBoxAdvSettings->setChecked( advMode );
- connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ),
- SLOT( showAdvancedFeatures( bool ) ) );
-
- makeChannel();
-
- ntpTimer = new QTimer(this);
-
- ntpProcess = new OProcess( );
- connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
- SLOT(slotNtpDelayChanged(int)) );
-
- ntpSock = new QSocket( this );
- connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) );
- slotProbeNtpServer();
-
- connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
- this, SLOT(getNtpOutput(OProcess*,char*,int)));
- connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
- this, SLOT(ntpFinished(OProcess*)));
- connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp()));
- connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
- connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
- slotCheckNtp(-1);
- readLookups();
-}
-
-Ntp::~Ntp()
-{
- delete ntpProcess;
-}
-
-void Ntp::saveConfig(){
- int srvCount = ComboNtpSrv->count();
- bool serversChanged = true;
- int curSrv = ComboNtpSrv->currentItem();
- QString edit = ComboNtpSrv->currentText();
- for (int i = 0; i < srvCount; i++){
- if ( edit == ComboNtpSrv->text(i)) serversChanged = false;
- }
- if (serversChanged){
- Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
- ntpSrvs.setGroup("servers");
- ntpSrvs.writeEntry("count", ++srvCount);
- ntpSrvs.setGroup("0");
- ntpSrvs.writeEntry( "name", edit );
- curSrv = 0;
- for (int i = 1; i < srvCount; i++){
- qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1());
- ntpSrvs.setGroup(QString::number(i));
- ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) );
- }
- }
- Config cfg("ntp",Config::User);
- cfg.setGroup("settings");
- cfg.writeEntry("ntpServer", curSrv );
- cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
- cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
- cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() );
-}
-
-bool Ntp::ntpDelayElapsed()
-{
- Config cfg("ntp",Config::User);
- cfg.setGroup("lookups");
- _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
- if (_lookupDiff < 0) return true;
- int i =_lookupDiff - (SpinBoxNtpDelay->value()*60);
- return i > -60;
-}
-
-QString Ntp::getNtpServer()
-{
- return ComboNtpSrv->currentText();
-}
-
-void Ntp::slotButtonRunNtp()
-{
- _interactive = true;
- slotRunNtp();
-}
-
-void Ntp::slotTimerRunNtp()
-{
- _interactive = false;
- slotRunNtp();
-}
-
-
-void Ntp::slotRunNtp()
-{
- if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() )
- {
- switch (
- QMessageBox::warning(this, tr("Run NTP?"),
- tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
- QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+
- "<br>"+tr("Rerun NTP?"),
- QMessageBox::Ok,QMessageBox::Cancel)
- ) {
- case QMessageBox::Ok: break;
- case QMessageBox::Cancel: return;
- default: return;
- }
- }
- TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
- ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
-
- ntpProcess->clearArguments();
- *ntpProcess << "ntpdate" << getNtpServer();
- bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
- if ( !ret ) {
- QMessageBox::critical(this, tr("ntp error"),
- tr("Error while getting time form network!"));
- qDebug("Error while executing ntpdate");
- ntpOutPut( tr("Error while executing ntpdate"));
- }
-}
-
-void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
-{
- if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null");
- QString lineStr, lineStrOld;
- lineStr = buffer;
- lineStr=lineStr.left(buflen);
- if (lineStr!=lineStrOld)
- {
- ntpOutPut(lineStr);
- _ntpOutput += lineStr;
- }
- lineStrOld = lineStr;
-}
-
-void Ntp::ntpFinished(OProcess *p)
-{
- qDebug("p->exitStatus() %i",p->exitStatus());
- if (p->exitStatus()!=0 || !p->normalExit())
- {
- if ( isVisible() && _interactive ){
- QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput );
- }
-// slotCheckNtp(-1);
- return;
- }
-
- Config cfg("ntp",Config::User);
- cfg.setGroup("lookups");
- int lastLookup = cfg.readNumEntry("time",0);
- int lookupCount = cfg.readNumEntry("count",0);
- bool lastNtp = cfg.readBoolEntry("lastNtp",false);
- int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
- cfg.writeEntry("time", time);
-
- float timeShift = getTimeShift();
- if (timeShift == 0.0) return;
- int secsSinceLast = time - lastLookup;
- TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
- TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
-
- dateButton->setDate( QDate::currentDate() );
- timeButton->setTime( QDateTime::currentDateTime() );
-
- if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
- {
- cfg.setGroup("lookup_"+QString::number(lookupCount));
- lookupCount++;
- _shiftPerSec = timeShift / secsSinceLast;
- qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
- cfg.writeEntry("secsSinceLast",secsSinceLast);
- cfg.writeEntry("timeShift",QString::number(timeShift));
- cfg.setGroup("lookups");
- cfg.writeEntry("count",lookupCount);
- cfg.writeEntry("lastNtp",true);
- }
-}
-
-
-float Ntp::getTimeShift()
-{
- 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);
- qDebug("%s", _ntpOutput.latin1());
- qDebug("diff = >%s<",diff.latin1());
- return diff.toFloat();
-}
-
-void Ntp::readLookups()
-{
- Config cfg("ntp",Config::User);
- cfg.setGroup("lookups");
- int lookupCount = cfg.readNumEntry("count",0);
- float last, shift, shiftPerSec;
- qDebug("lookupCount = %i",lookupCount);
- TableLookups->setNumCols( 3 );
- TableLookups->setNumRows( lookupCount);
- TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
- TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
- TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
- int cw = TableLookups->width()/4;
- qDebug("column width %i",cw);
- cw = 50;
- TableLookups->setColumnWidth( 0, cw+30 );
- TableLookups->setColumnWidth( 1, cw );
- TableLookups->setColumnWidth( 2, cw );
- TableLookups->sortColumn(0, false, true );
- // TableLookups->setSorting( true );
- _shiftPerSec = 0;
- for (int i=0; i < lookupCount; i++)
- {
- cfg.setGroup("lookup_"+QString::number(i));
- last = cfg.readEntry("secsSinceLast",0).toFloat();
- shift = QString(cfg.readEntry("timeShift",0)).toFloat();
- shiftPerSec = shift / last;
- qDebug("%i shift %f",i,shiftPerSec);
- _shiftPerSec += shiftPerSec;
- TableLookups->setText( i,0,QString::number(shiftPerSec*60*60));
- TableLookups->setText( i,2,QString::number(shift));
- TableLookups->setText( i,1,QString::number(last/(60*60)));
- }
- _shiftPerSec /= lookupCount;
- TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h"));
-}
-
-void Ntp::preditctTime()
-{
- Config cfg("ntp",Config::User);
- cfg.setGroup("lookups");
- int lastTime = cfg.readNumEntry("time",0);
- cfg.writeEntry("lastNtp",true);
- setenv( "TZ", tz->currentZone(), 1 );
- int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
- int corr = int((now - lastTime) * _shiftPerSec);
- TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
- predictedTime = QDateTime::currentDateTime().addSecs(corr);
- TextLabelPredTime->setText(predictedTime.toString());
-// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
-}
-
-void Ntp::setPredictTime()
-{
- qDebug("Ntp::setPredictTime");
- preditctTime();
- timeButton->setTime( predictedTime );
-}
-
-void Ntp::slotCheckNtp(int i)
-{
- qDebug(" Ntp::slotCheckNtp(%i)",i);
- if (i == 0)
- {
-// TextLabelMainPredTime->hide();
- ButtonSetTime->setText( tr("Get time from network") );
- connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) );
- if ( ntpDelayElapsed() )
- {
- slotRunNtp();
- disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
- connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) );
- }else{
- disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) );
- connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
- }
- }else{
- preditctTime();
- ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() );
- if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
- connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
- connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
- }
-}
-
-void Ntp::slotProbeNtpServer()
-{
- ntpSock->connectToHost( getNtpServer() ,123);
-}
-
-void Ntp::slotNtpDelayChanged(int delay)
-{
- ntpTimer->changeInterval( delay*1000*60 );
-}
-
-void Ntp::ntpOutPut(QString out)
-{
-
- MultiLineEditntpOutPut->append(out);
- MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
-}
-
-
-void Ntp::makeChannel()
-{
- channel = new QCopChannel( "QPE/Application/netsystemtime", this );
- connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
- this, SLOT(receive(const QCString&, const QByteArray&)) );
-}
-
-
-
-void Ntp::receive(const QCString &msg, const QByteArray &arg)
-{
- qDebug("QCop(Ntp) "+msg+" "+QCString(arg));
- if ( msg == "ntpLookup(QString)" )
- {
- _interactive = false;
- slotRunNtp();
- }
- if ( msg == "setPredictedTime(QString)" )
- {
- setPredictTime();
- }else{
- qDebug("Ntp::receive: Huh what do ya want");
- }
-}
-
-void Ntp::setDocument(const QString &fileName)
-{
- qDebug("Ntp::setDocument( %s )",fileName.latin1());
-}
-
-void Ntp::showAdvancedFeatures(bool advMode)
-{
- if (advMode) {
-
- if ( tabNtp->isVisible() ) {
- TabWidgetMain->addTab( tabPredict, tr( "Predict" ) );
- TabWidgetMain->addTab( tabNtp, tr( "NTP" ) );
- }
- TextLabel1_2_2->show();
- TextLabel2_3->show();
- TextLabel3_3_2->show();
- TextLabel1_2->show();
- SpinBoxMinLookupDelay->show();
- TextLabel2->show();
- TextLabel3_3->show();
- SpinBoxNtpDelay->show();
- Line1->show();
- }else{
- TabWidgetMain->removePage( tabPredict );
- TabWidgetMain->removePage( tabNtp );
- TextLabel1_2_2->hide();
- TextLabel2_3->hide();
- TextLabel3_3_2->hide();
- TextLabel1_2->hide();
- SpinBoxMinLookupDelay->hide();
- TextLabel2->hide();
- TextLabel3_3->hide();
- SpinBoxNtpDelay->hide();
- Line1->hide();
- };
- TabWidgetMain->show();
-}
-
-
-void Ntp::accept( ){
- qDebug("saving");
- //SetTimeDate
- commitTime();
- writeSettings();
- updateSystem();
- // Ntp
- saveConfig();
- qApp->quit();
-}
-
-void Ntp::reject( ){
- qDebug("_oldTimeZone %s",_oldTimeZone.latin1());
- if (!_oldTimeZone.isEmpty()){
- qDebug("reverting timezone");
- tzChange(_oldTimeZone);
- commitTime();
- }
-}
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h
deleted file mode 100644
index 150140e..0000000
--- a/noncore/settings/netsystemtime/ntp.h
+++ b/dev/null
@@ -1,58 +0,0 @@
-#ifndef NTP_H
-#define NTP_H
-#include "settime.h"
-#include <qdatetime.h>
-
-class OProcess;
-class QString;
-class QTimer;
-class QSocket;
-class QCopChannel;
-
-class Ntp : public SetDateTime
-{
- Q_OBJECT
-
-public:
- Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
- ~Ntp();
-
-public slots:
- void setDocument (const QString &);
-protected:
- virtual void accept( );
- virtual void reject( );
- QDateTime predictedTime;
- void makeChannel();
-protected slots:
- void receive(const QCString &msg, const QByteArray &arg);
-private:
- QString _ntpOutput;
- float _shiftPerSec;
- int _lookupDiff;
- OProcess *ntpProcess;
- QTimer *ntpTimer;
- QSocket *ntpSock;
- QCopChannel *channel;
- bool _interactive;
- float getTimeShift();
- void readLookups();
- void ntpOutPut(QString);
- bool ntpDelayElapsed();
- QString getNtpServer();
- void saveConfig();
-private slots:
- void slotTimerRunNtp();
- void slotButtonRunNtp();
- void slotRunNtp();
- void getNtpOutput(OProcess *proc, char *buffer, int buflen);
- void ntpFinished(OProcess*);
- void preditctTime();
- void slotCheckNtp(int);
- void setPredictTime();
- void showAdvancedFeatures(bool);
- void slotProbeNtpServer();
- void slotNtpDelayChanged(int);
-};
-
-#endif
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui
deleted file mode 100644
index 8c106be..0000000
--- a/noncore/settings/netsystemtime/ntpbase.ui
+++ b/dev/null
@@ -1,838 +0,0 @@
-<!DOCTYPE UI><UI>
-<class>NtpBase</class>
-<widget>
- <class>QDialog</class>
- <property stdset="1">
- <name>name</name>
- <cstring>NtpBase</cstring>
- </property>
- <property stdset="1">
- <name>geometry</name>
- <rect>
- <x>0</x>
- <y>0</y>
- <width>317</width>
- <height>411</height>
- </rect>
- </property>
- <property stdset="1">
- <name>caption</name>
- <string>Network Time</string>
- </property>
- <property>
- <name>layoutMargin</name>
- </property>
- <property>
- <name>layoutSpacing</name>
- </property>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>2</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>2</number>
- </property>
- <widget row="0" column="0" >
- <class>QTabWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TabWidgetMain</cstring>
- </property>
- <property>
- <name>layoutMargin</name>
- </property>
- <property>
- <name>layoutSpacing</name>
- </property>
- <widget>
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>tabMain</cstring>
- </property>
- <attribute>
- <name>title</name>
- <string>Main</string>
- </attribute>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>2</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>2</number>
- </property>
- <widget row="0" column="0" >
- <class>QFrame</class>
- <property stdset="1">
- <name>name</name>
- <cstring>FrameSystemTime</cstring>
- </property>
- </widget>
- </grid>
- </widget>
- <widget>
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>tabNtp</cstring>
- </property>
- <attribute>
- <name>title</name>
- <string>NTP</string>
- </attribute>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>1</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>2</number>
- </property>
- <widget row="1" column="0" >
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>runNtp</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Get time from network</string>
- </property>
- </widget>
- <widget row="0" column="0" >
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>FrameNtp</cstring>
- </property>
- <property>
- <name>layoutMargin</name>
- </property>
- <property>
- <name>layoutSpacing</name>
- </property>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>2</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>2</number>
- </property>
- <widget row="0" column="0" >
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout4</cstring>
- </property>
- <vbox>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel1</cstring>
- </property>
- <property stdset="1">
- <name>autoMask</name>
- <bool>false</bool>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Start Time:</string>
- </property>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabelStartTime</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>nan</string>
- </property>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel3</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Time Shift:</string>
- </property>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabelTimeShift</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>nan</string>
- </property>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel5</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>New Time:</string>
- </property>
- </widget>
- <widget>
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabelNewTime</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>nan</string>
- </property>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer1</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </vbox>
- </widget>
- <widget row="1" column="0" >
- <class>QMultiLineEdit</class>
- <property stdset="1">
- <name>name</name>
- <cstring>MultiLineEditntpOutPut</cstring>
- </property>
- <property stdset="1">
- <name>font</name>
- <font>
- <pointsize>7</pointsize>
- </font>
- </property>
- <property stdset="1">
- <name>wordWrap</name>
- <enum>WidgetWidth</enum>
- </property>
- <property stdset="1">
- <name>text</name>
- <string></string>
- </property>
- </widget>
- </grid>
- </widget>
- </grid>
- </widget>
- <widget>
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>tabPredict</cstring>
- </property>
- <attribute>
- <name>title</name>
- <string>Predict</string>
- </attribute>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>5</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget row="0" column="0" >
- <class>QTable</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TableLookups</cstring>
- </property>
- <property stdset="1">
- <name>font</name>
- <font>
- <pointsize>8</pointsize>
- </font>
- </property>
- <property stdset="1">
- <name>numRows</name>
- <number>2</number>
- </property>
- <property stdset="1">
- <name>numCols</name>
- <number>2</number>
- </property>
- </widget>
- <widget row="1" column="0" >
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout9</cstring>
- </property>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget row="0" column="1" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabelShift</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>nan</string>
- </property>
- </widget>
- <widget row="1" column="0" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel4</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Esimated Shift:</string>
- </property>
- </widget>
- <widget row="1" column="1" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabelEstimatedShift</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>nan</string>
- </property>
- </widget>
- <widget row="2" column="0" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel3_2</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Predicted Time:</string>
- </property>
- </widget>
- <widget row="0" column="0" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Mean_shift_label</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Mean shift:</string>
- </property>
- </widget>
- <widget row="2" column="1" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabelPredTime</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>nan</string>
- </property>
- </widget>
- </grid>
- </widget>
- <widget row="2" column="0" >
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout11</cstring>
- </property>
- <hbox>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>PushButtonSetPredTime</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Set predicted time</string>
- </property>
- </widget>
- <widget>
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>PushButtonPredict</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Predict time</string>
- </property>
- </widget>
- </hbox>
- </widget>
- </grid>
- </widget>
- <widget>
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TabSettings</cstring>
- </property>
- <attribute>
- <name>title</name>
- <string>Settings</string>
- </attribute>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>2</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>2</number>
- </property>
- <widget row="0" column="0" >
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>FrameSettings</cstring>
- </property>
- <property>
- <name>layoutMargin</name>
- </property>
- <property>
- <name>layoutSpacing</name>
- </property>
- <vbox>
- <property stdset="1">
- <name>margin</name>
- <number>11</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout6</cstring>
- </property>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget row="0" column="0" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel7_2</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Use</string>
- </property>
- </widget>
- <widget row="0" column="2" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel2_2</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>as</string>
- </property>
- </widget>
- <widget row="1" column="0" rowspan="1" colspan="2" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel1_3</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>NTP server to get the time from the network.</string>
- </property>
- <property stdset="1">
- <name>alignment</name>
- <set>WordBreak|AlignVCenter|AlignLeft</set>
- </property>
- <property>
- <name>wordwrap</name>
- </property>
- </widget>
- <widget row="0" column="1" >
- <class>QComboBox</class>
- <property stdset="1">
- <name>name</name>
- <cstring>ComboNtpSrv</cstring>
- </property>
- <property stdset="1">
- <name>editable</name>
- <bool>true</bool>
- </property>
- </widget>
- </grid>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer3</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Minimum</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <widget>
- <class>QCheckBox</class>
- <property stdset="1">
- <name>name</name>
- <cstring>CheckBoxAdvSettings</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Advanced settings</string>
- </property>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer4</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- <widget>
- <class>Line</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Line1</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Horizontal</enum>
- </property>
- </widget>
- <widget>
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout7_2</cstring>
- </property>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget row="0" column="0" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel1_2_2</cstring>
- </property>
- <property stdset="1">
- <name>sizePolicy</name>
- <sizepolicy>
- <hsizetype>1</hsizetype>
- <vsizetype>1</vsizetype>
- </sizepolicy>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Wait for </string>
- </property>
- </widget>
- <widget row="0" column="2" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel2_3</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>minutes until</string>
- </property>
- </widget>
- <widget row="1" column="0" rowspan="1" colspan="3" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel3_3_2</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>NTP tries to syncronises the clock with the network.</string>
- </property>
- <property stdset="1">
- <name>alignment</name>
- <set>WordBreak|AlignVCenter|AlignLeft</set>
- </property>
- <property>
- <name>wordwrap</name>
- </property>
- </widget>
- <widget row="0" column="1" >
- <class>QSpinBox</class>
- <property stdset="1">
- <name>name</name>
- <cstring>SpinBoxNtpDelay</cstring>
- </property>
- <property stdset="1">
- <name>wrapping</name>
- <bool>true</bool>
- </property>
- <property stdset="1">
- <name>maxValue</name>
- <number>9999999</number>
- </property>
- <property stdset="1">
- <name>minValue</name>
- <number>1</number>
- </property>
- <property stdset="1">
- <name>value</name>
- <number>1440</number>
- </property>
- </widget>
- </grid>
- </widget>
- <widget>
- <class>QLayoutWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>Layout7</cstring>
- </property>
- <grid>
- <property stdset="1">
- <name>margin</name>
- <number>0</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget row="0" column="0" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel1_2</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Insure a delay of</string>
- </property>
- </widget>
- <widget row="0" column="2" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel2</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>minutes until</string>
- </property>
- </widget>
- <widget row="1" column="0" rowspan="1" colspan="3" >
- <class>QLabel</class>
- <property stdset="1">
- <name>name</name>
- <cstring>TextLabel3_3</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>a new NTP lookup will be used to predict the time.</string>
- </property>
- <property stdset="1">
- <name>alignment</name>
- <set>WordBreak|AlignVCenter|AlignLeft</set>
- </property>
- <property>
- <name>wordwrap</name>
- </property>
- </widget>
- <widget row="0" column="1" >
- <class>QSpinBox</class>
- <property stdset="1">
- <name>name</name>
- <cstring>SpinBoxMinLookupDelay</cstring>
- </property>
- <property stdset="1">
- <name>wrapping</name>
- <bool>true</bool>
- </property>
- <property stdset="1">
- <name>maxValue</name>
- <number>9999999</number>
- </property>
- <property stdset="1">
- <name>minValue</name>
- <number>42</number>
- </property>
- <property stdset="1">
- <name>value</name>
- <number>720</number>
- </property>
- </widget>
- </grid>
- </widget>
- </vbox>
- </widget>
- </grid>
- </widget>
- <widget>
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>tabManualSetTime</cstring>
- </property>
- <attribute>
- <name>title</name>
- <string>Manual</string>
- </attribute>
- <vbox>
- <property stdset="1">
- <name>margin</name>
- <number>11</number>
- </property>
- <property stdset="1">
- <name>spacing</name>
- <number>6</number>
- </property>
- <widget>
- <class>QWidget</class>
- <property stdset="1">
- <name>name</name>
- <cstring>FrameSetTime</cstring>
- </property>
- <property stdset="1">
- <name>sizePolicy</name>
- <sizepolicy>
- <hsizetype>5</hsizetype>
- <vsizetype>3</vsizetype>
- </sizepolicy>
- </property>
- </widget>
- <widget>
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>PushButtonSetManualTime</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>Set time</string>
- </property>
- </widget>
- <spacer>
- <property>
- <name>name</name>
- <cstring>Spacer4_2</cstring>
- </property>
- <property stdset="1">
- <name>orientation</name>
- <enum>Vertical</enum>
- </property>
- <property stdset="1">
- <name>sizeType</name>
- <enum>Expanding</enum>
- </property>
- <property>
- <name>sizeHint</name>
- <size>
- <width>20</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </vbox>
- </widget>
- </widget>
- </grid>
-</widget>
-</UI>
diff --git a/noncore/settings/netsystemtime/ntptabwidget.cpp b/noncore/settings/netsystemtime/ntptabwidget.cpp
new file mode 100644
index 0000000..d71c230
--- a/dev/null
+++ b/noncore/settings/netsystemtime/ntptabwidget.cpp
@@ -0,0 +1,107 @@
+/*
+                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.,
+ 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" ),
+ tr( "Get time from the network" ), container );
+ connect( pb, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) );
+ layout->addMultiCellWidget( pb, 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 );
+}
diff --git a/noncore/settings/netsystemtime/ntptabwidget.h b/noncore/settings/netsystemtime/ntptabwidget.h
new file mode 100644
index 0000000..811c57e
--- a/dev/null
+++ b/noncore/settings/netsystemtime/ntptabwidget.h
@@ -0,0 +1,60 @@
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef NTPTABWIDGET_H
+#define NTPTABWIDGET_H
+
+#include <qwidget.h>
+
+class QLabel;
+class QMultiLineEdit;
+
+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 & );
+
+private:
+ QLabel *lblStartTime;
+ QLabel *lblTimeShift;
+ QLabel *lblNewTime;
+ QMultiLineEdit *mleNtpOutput;
+
+signals:
+ void getNTPTime();
+};
+
+#endif
diff --git a/noncore/settings/netsystemtime/predicttabwidget.cpp b/noncore/settings/netsystemtime/predicttabwidget.cpp
new file mode 100644
index 0000000..8dc889f
--- a/dev/null
+++ b/noncore/settings/netsystemtime/predicttabwidget.cpp
@@ -0,0 +1,167 @@
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "predicttabwidget.h"
+
+#include <qpe/config.h>
+#include <qpe/timeconversion.h>
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qpushbutton.h>
+#include <qscrollview.h>
+#include <qtable.h>
+
+#include <stdlib.h>
+
+PredictTabWidget::PredictTabWidget( 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( this );
+ layout->setMargin( 2 );
+ layout->setSpacing( 4 );
+
+ // Predicted time drift
+ layout->addWidget( new QLabel( tr( "Predicted time drift" ), this ), 0, 0 );
+ lblDrift = new QLabel( tr( "n/a" ), this );
+ layout->addWidget( lblDrift, 0, 1 );
+
+ // Estimated time difference
+ layout->addWidget( new QLabel( tr( "Estimated shift" ), this ), 1, 0 );
+ lblDiff = new QLabel( tr( "n/a" ), this );
+ layout->addWidget( lblDiff, 1, 1 );
+
+ // Predicted time
+ layout->addWidget( new QLabel( tr( "Predicted time" ), this ), 2, 0 );
+ lblPredicted = new QLabel( tr( "n/a" ), this );
+ layout->addWidget( lblPredicted, 2, 1 );
+
+ // Prediction table
+ tblLookups = new QTable( 2, 3, this );
+ QFont font( tblLookups->font() );
+ font.setPointSize( 7 );
+ tblLookups->setFont( font );
+ tblLookups->horizontalHeader()->setLabel( 0, tr( "Shift [s/h]" ) );
+ tblLookups->horizontalHeader()->setLabel( 1, tr( "Last [h]" ) );
+ tblLookups->horizontalHeader()->setLabel( 2, tr( "Offset [s]" ) );
+ tblLookups->setColumnWidth( 0, 78 );
+ tblLookups->setColumnWidth( 1, 50 );
+ tblLookups->setColumnWidth( 2, 50 );
+ tblLookups->setMinimumHeight( 50 );
+ tblLookups->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
+ layout->addMultiCellWidget( tblLookups, 3, 3, 0, 1 );
+
+ // Predict time button
+ QPushButton *pb = new QPushButton( tr( "Predict time" ), this );
+ connect( pb, SIGNAL(clicked()), this, SLOT(slotPredictTime()) );
+ layout->addWidget( pb, 4, 0 );
+
+ // Set predicted time button
+ pb = new QPushButton( tr( "Set predicted time" ), this );
+ connect( pb, SIGNAL(clicked()), this, SLOT(slotSetPredictedTime()) );
+ layout->addWidget( pb, 4, 1 );
+
+ // Initialize values
+ Config config( "ntp" );
+ config.setGroup( "lookups" );
+ int lookupCount = config.readNumEntry( "count", 0 );
+ float last, shift, shiftPerSec;
+ tblLookups->setNumRows( lookupCount );
+ int cw = tblLookups->width() / 4;
+ cw = 50;
+ tblLookups->sortColumn( 0, FALSE, TRUE );
+ _shiftPerSec = 0;
+ QString grpname;
+ for ( int i=0; i < lookupCount; i++ )
+ {
+ grpname = "lookup_";
+ grpname.append( QString::number( i ) );
+ config.setGroup( grpname );
+ last = config.readEntry( "secsSinceLast", 0 ).toFloat();
+ shift = QString( config.readEntry( "timeShift", 0 ) ).toFloat();
+ shiftPerSec = shift / last;
+ _shiftPerSec += shiftPerSec;
+ tblLookups->setText( i, 0, QString::number( shiftPerSec * 60 * 60 ) );
+ tblLookups->setText( i, 2, QString::number( shift ) );
+ tblLookups->setText( i, 1, QString::number( last / ( 60 * 60 ) ) );
+ }
+ _shiftPerSec /= lookupCount;
+ QString drift = QString::number( _shiftPerSec * 60 * 60);
+ drift.append( tr( " s/h" ) );
+ lblDrift->setText( drift );
+
+ Config lconfig( "locale" );
+ lconfig.setGroup( "Location" );
+ tz = lconfig.readEntry( "Timezone", "America/New_York" );
+}
+
+PredictTabWidget::~PredictTabWidget()
+{
+}
+
+void PredictTabWidget::setShiftPerSec( int i )
+{
+ _shiftPerSec += i;
+}
+
+void PredictTabWidget::slotTZChanged( const QString &newtz )
+{
+ tz = newtz;
+}
+
+void PredictTabWidget::slotPredictTime()
+{
+ Config config( "ntp" );
+ config.setGroup( "lookups" );
+ int lastTime = config.readNumEntry( "time", 0 );
+ config.writeEntry( "lastNtp", TRUE );
+ setenv( "TZ", tz, 1 );
+ int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
+ int corr = int( ( now - lastTime ) * _shiftPerSec );
+ QString diff = QString::number( corr );
+ diff.append( tr( " seconds" ) );
+ lblDiff->setText( diff );
+ predictedTime = QDateTime::currentDateTime().addSecs( corr );
+ lblPredicted->setText( predictedTime.toString() );
+}
+
+void PredictTabWidget::slotSetPredictedTime()
+{
+ slotPredictTime();
+ emit setTime( predictedTime );
+}
diff --git a/noncore/settings/netsystemtime/predicttabwidget.h b/noncore/settings/netsystemtime/predicttabwidget.h
new file mode 100644
index 0000000..da1d8ed
--- a/dev/null
+++ b/noncore/settings/netsystemtime/predicttabwidget.h
@@ -0,0 +1,68 @@
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef PREDICTTABWIDGET_H
+#define PREDICTTABWIDGET_H
+
+#include <qdatetime.h>
+#include <qstring.h>
+#include <qwidget.h>
+
+class QLabel;
+class QTable;
+
+class PredictTabWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ PredictTabWidget( QWidget * = 0x0 );
+ ~PredictTabWidget();
+
+ void setShiftPerSec( int );
+
+private:
+ QTable *tblLookups;
+ QLabel *lblDrift;
+ QLabel *lblDiff;
+ QLabel *lblPredicted;
+
+ float _shiftPerSec;
+ QString tz;
+ QDateTime predictedTime;
+
+signals:
+ void setTime( const QDateTime & );
+
+public slots:
+ void slotTZChanged( const QString & );
+ void slotPredictTime();
+ void slotSetPredictedTime();
+};
+
+#endif
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp
deleted file mode 100644
index 6a28989..0000000
--- a/noncore/settings/netsystemtime/settime.cpp
+++ b/dev/null
@@ -1,533 +0,0 @@
-/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
-**
-** This file is part of Qtopia Environment.
-**
-** This file may be distributed and/or modified under the terms of the
-** GNU General Public License version 2 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** See http://www.trolltech.com/gpl/ for GPL licensing information.
-**
-** Contact info@trolltech.com if any conditions of this licensing are
-** not clear to you.
-**
-**********************************************************************/
-
-#include "settime.h"
-
-#include <qpe/alarmserver.h>
-#include <qpe/qpeapplication.h>
-#include <qpe/config.h>
-#include <qpe/datebookdb.h>
-#include <qpe/datebookmonth.h>
-#include <qpe/global.h>
-#include <qpe/resource.h>
-#include <qpe/timeconversion.h>
-#include <qpe/tzselect.h>
-#include <qpe/timestring.h>
-#include <qpe/qpedialog.h>
-#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
-#include <qpe/qcopenvelope_qws.h>
-#endif
-
-#include <qtimer.h>
-#include <qbuttongroup.h>
-#include <qcheckbox.h>
-#include <qlabel.h>
-#include <qlayout.h>
-#include <qradiobutton.h>
-#include <qspinbox.h>
-#include <qtoolbutton.h>
-#include <qwindowsystem_qws.h>
-#include <qcombobox.h>
-
-#include <sys/time.h>
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-
-SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f )
- : NtpBase( parent, name, true, f )
-{
- setCaption( tr("System Time") );
- _oldTimeZone="";
- QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 );
-
-// TextLabelMainPredTime = new QLabel( FrameSystemTime );
-// vb->addWidget( TextLabelMainPredTime, 1, 0 );
-
- timeButton = new SetTime( FrameSystemTime );
- vb->addWidget( timeButton );
-
- QHBoxLayout *db = new QHBoxLayout( vb );
- QLabel *dateLabel = new QLabel( tr("Date"), FrameSystemTime );
- db->addWidget( dateLabel, 1 );
- dateButton = new DateButton( TRUE, FrameSystemTime );
- db->addWidget( dateButton, 2 );
-
- ButtonSetTime = new QPushButton( FrameSystemTime );
- vb->addWidget( ButtonSetTime, 1, 0 );
-
- QFrame *hline = new QFrame( FrameSystemTime );
- hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
- vb->addWidget( hline );
-
- QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" );
-
- QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" );
- lblZone->setMaximumSize( lblZone->sizeHint() );
- hb->addWidget( lblZone );
-
- tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" );
- tz->setMinimumSize( tz->sizeHint() );
- hb->addWidget( tz );
-
- hline = new QFrame( FrameSystemTime );
- hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
- vb->addWidget( hline );
-
- QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
- vb->addItem( spacer );
-
- Config config("qpe");
- config.setGroup( "Time" );
-
- QHBoxLayout *hb1 = new QHBoxLayout( vb );
-
- QLabel *l = new QLabel( tr("Time format"), FrameSystemTime );
- hb1->addWidget( l, 1 );
-
-
- ampmCombo = new QComboBox( FrameSystemTime );
- ampmCombo->insertItem( tr("24 hour"), 0 );
- ampmCombo->insertItem( tr("12 hour"), 1 );
- hb1->addWidget( ampmCombo, 2 );
-
- int show12hr = config.readBoolEntry("AMPM") ? 1 : 0;
- ampmCombo->setCurrentItem( show12hr );
- timeButton->show12hourTime( show12hr );
-
- connect(ampmCombo, SIGNAL(activated(int)),
- timeButton, SLOT(show12hourTime(int)));
-
-
-
- QHBoxLayout *hb2 = new QHBoxLayout( vb );
- l = new QLabel( tr("Weeks start on" ), FrameSystemTime );
- //l->setAlignment( AlignRight | AlignVCenter );
- hb2->addWidget( l, 1 );
-
- weekStartCombo = new QComboBox( FrameSystemTime );
- weekStartCombo->insertItem( tr("Sunday"), 0 );
- weekStartCombo->insertItem( tr("Monday"), 1 );
-
- hb2->addWidget( weekStartCombo, 2 );
- int startMonday = config.readBoolEntry("MONDAY") ? 1 : 0;
- dateButton->setWeekStartsMonday( startMonday );
- weekStartCombo->setCurrentItem( startMonday );
-
- connect( weekStartCombo, SIGNAL( activated(int)),
- dateButton, SLOT(setWeekStartsMonday(int)));
-
-
- QHBoxLayout *hb3 = new QHBoxLayout( vb );
- l = new QLabel( tr("Date format" ), FrameSystemTime );
- hb3->addWidget( l, 1 );
- dateFormatCombo = new QComboBox( FrameSystemTime );
- hb3->addWidget( dateFormatCombo, 2 );
-
- config.setGroup( "Date" );
- DateFormat df(QChar(config.readEntry("Separator", "/")[0]),
- (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
- (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
-
- int currentdf = 0;
- date_formats[0] = DateFormat('/', DateFormat::MonthDayYear);
- dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) );
- date_formats[1] = DateFormat('.', DateFormat::DayMonthYear);
- if (df == date_formats[1])
- currentdf = 1;
- dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) );
- date_formats[2] = DateFormat('-', DateFormat::YearMonthDay,
- DateFormat::DayMonthYear);
- if (df == date_formats[2])
- currentdf = 2;
- dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601
- date_formats[3] = DateFormat('/', DateFormat::DayMonthYear);
- if (df == date_formats[3])
- currentdf = 3;
- dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) );
-
- dateFormatCombo->setCurrentItem( currentdf );
- dateButton->setDateFormat( df );
-
- connect( dateFormatCombo, SIGNAL( activated(int)),
- SLOT(formatChanged(int)));
-
- QHBoxLayout *hb4 = new QHBoxLayout( vb );
- l = new QLabel( tr("Applet format" ), FrameSystemTime );
- hb4->addWidget( l, 1 );
-
- clockAppletCombo = new QComboBox( FrameSystemTime );
- clockAppletCombo->insertItem( tr("hh:mm"), 0 );
- clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 );
- clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 );
-
- hb4->addWidget( clockAppletCombo, 2 );
- int clockApplet = config.readNumEntry("ClockApplet",0);
- clockAppletCombo->setCurrentItem( clockApplet );
-
- vb->addStretch( 0 );
-
-// hline = new QFrame( FrameSystemTime );
-// hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
-// vb->addWidget( hline );
-//
-// ButtonSetTime = new QPushButton( FrameSystemTime );
-// vb->addWidget( ButtonSetTime, 1, 0 );
-
-
- QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ),
- timeButton, SLOT( slotTzChange( const QString& ) ) );
- QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ),
- SLOT( tzChange( const QString& ) ) );
-
-// QObject::connect( weekStartCombo, SIGNAL( activated ( int )),
-// SLOT(updateSystem(int ) ));
-// QObject::connect( ampmCombo, SIGNAL( activated ( int )),
-// SLOT(updateSystem(int ) ));
-// QObject::connect( dateFormatCombo, SIGNAL( activated ( int )),
-// SLOT(updateSystem(int ) ));
-// QObject::connect( clockAppletCombo, SIGNAL( activated ( int )),
-// SLOT(updateSystem(int ) ));
-}
-
-SetDateTime::~SetDateTime()
-{
-}
-
-void SetDateTime::writeSettings()
-{
- Config config("qpe");
- config.setGroup( "Time" );
- config.writeEntry( "AMPM", ampmCombo->currentItem() );
- config.writeEntry( "MONDAY", weekStartCombo->currentItem() );
- config.setGroup( "Date" );
- DateFormat df = date_formats[dateFormatCombo->currentItem()];
- config.writeEntry( "Separator", QString(df.separator()));
- config.writeEntry( "ShortOrder", df.shortOrder());
- config.writeEntry( "LongOrder", df.longOrder());
- config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() );
-
- Config lconfig("locale");
- lconfig.setGroup( "Location" );
- lconfig.writeEntry( "Timezone", tz->currentZone() );
-
-}
-
-void SetDateTime::commitTime()
-{
- Config cfg("ntp",Config::User);
- cfg.setGroup("lookups");
- cfg.writeEntry("lastNtp",false);
- tz->setFocus();
- // Need to process the QCOP event generated above before proceeding
- qApp->processEvents();
-
- // before we progress further, set our TZ!
- setenv( "TZ", tz->currentZone(), 1 );
- // now set the time...
- QDateTime dt( dateButton->date(), timeButton->time() );
-
- if ( dt.isValid() ) setTime(dt);
-}
-
-void SetDateTime::setTime(QDateTime dt)
-{
- // really turn off the screensaver before doing anything
- {
- // Needs to be encased in { } so that it deconstructs and sends
- QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
- disableScreenSaver << 0 << 0 << 0;
- }
- Config cfg("ntp",Config::User);
- cfg.setGroup("correction");
- int t = TimeConversion::toUTC(dt);
- struct timeval myTv;
- myTv.tv_sec = t;
- cfg.writeEntry("time", t );
- myTv.tv_usec = 0;
-
- if ( myTv.tv_sec != -1 )
- ::settimeofday( &myTv, 0 );
- Global::writeHWClock();
- // 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;
- //QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" );
- //timeApplet << "";
- // Restore screensaver
- QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
- enableScreenSaver << -1 << -1 << -1;
-}
-
-void SetDateTime::updateSystem()
-{
- // really turn off the screensaver before doing anything
- {
- // Needs to be encased in { } so that it deconstructs and sends
- QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
- disableScreenSaver << 0 << 0 << 0;
- }
- qDebug("SetDateTime::updateSystem()");
- writeSettings();
-
- // set the timezone for everyone else...
- QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
- setTimeZone << tz->currentZone();
-
- // AM/PM setting and notify time changed
- QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
- setClock << ampmCombo->currentItem();
-
- // Notify everyone what day we prefer to start the week on.
- QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
- setWeek << weekStartCombo->currentItem();
-
- // Notify everyone what date format to use
- QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
- setDateFormat << date_formats[dateFormatCombo->currentItem()];
-
- // Restore screensaver
- QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
- enableScreenSaver << -1 << -1 << -1;
- // 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;
-
-}
-
-void SetDateTime::tzChange( const QString &tz )
-{
- // set the TZ get the time and leave gracefully...
- _oldTimeZone = getenv( "TZ" );
- setenv( "TZ", tz, 1 );
-
- QDate d = QDate::currentDate();
- // reset the time.
- if ( !_oldTimeZone.isNull() ) {
- setenv( "TZ", _oldTimeZone, 1 );
- }
- dateButton->setDate( d );
- updateSystem();
-}
-
-void SetDateTime::formatChanged(int i)
-{
- dateButton->setDateFormat(date_formats[i]);
-}
-
-static const int ValueAM = 0;
-static const int ValuePM = 1;
-
-
-
-SetTime::SetTime( QWidget *parent, const char *name )
- : QWidget( parent, name )
-{
- clock = new QTimer(this, "clock" );
- connect(clock, SIGNAL( timeout() ), SLOT(slotClockTick()) );
- clock->start( 1000 * 60 );
-
- use12hourTime = FALSE;
-
- _time = QDateTime::currentDateTime();
- hour = _time.time().hour();
- minute = _time.time().minute();
-
- QHBoxLayout *hb2 = new QHBoxLayout( this );
- hb2->setSpacing( 3 );
-
- QLabel *l = new QLabel( tr("Hour"), this );
- // l->setAlignment( AlignRight | AlignVCenter );
- hb2->addWidget( l );
-
- sbHour = new QSpinBox( this );
- sbHour->setMinimumWidth( 30 );
- if(use12hourTime) {
- sbHour->setMinValue(1);
- sbHour->setMaxValue( 12 );
- int show_hour = hour;
- if (hour > 12)
- show_hour -= 12;
- if (show_hour == 0)
- show_hour = 12;
-
- sbHour->setValue( show_hour );
- } else {
- sbHour->setMinValue( 0 );
- sbHour->setMaxValue( 23 );
- sbHour->setValue( hour );
- }
- sbHour->setWrapping(TRUE);
- connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) );
- hb2->addWidget( sbHour );
-
- hb2->addStretch( 1 );
-
- l = new QLabel( tr("Minute"), this );
- //l->setAlignment( AlignRight | AlignVCenter );
- hb2->addWidget( l );
-
- sbMin = new QSpinBox( this );
- sbMin->setMinValue( 0 );
- sbMin->setMaxValue( 59 );
- sbMin->setWrapping(TRUE);
- sbMin->setValue( minute );
- sbMin->setMinimumWidth( 30 );
- connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) );
- hb2->addWidget( sbMin );
-
- hb2->addStretch( 1 );
-
- ampm = new QComboBox( this );
- ampm->insertItem( tr("AM"), ValueAM );
- ampm->insertItem( tr("PM"), ValuePM );
- connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) );
- hb2->addWidget( ampm );
-
- hb2->addStretch( 1 );
-
-}
-
-QTime SetTime::time() const
-{
- return QTime( hour, minute, 0 );
-}
-
-void SetTime::hourChanged( int value )
-{
- if(use12hourTime) {
- int realhour = value;
- if (realhour == 12)
- realhour = 0;
- if (ampm->currentItem() == ValuePM )
- realhour += 12;
- hour = realhour;
- } else
- hour = value;
-}
-
-void SetTime::minuteChanged( int value )
-{
- minute = value;
-}
-
-void SetTime::show12hourTime( int on )
-{
- use12hourTime = on;
- ampm->setEnabled(on);
-
- int show_hour = hour;
- if ( on ) {
- /* this might change the value of hour */
- sbHour->setMinValue(1);
- sbHour->setMaxValue( 12 );
-
- /* so use one we saved earlier */
- if (show_hour >= 12) {
- show_hour -= 12;
- ampm->setCurrentItem( ValuePM );
- } else {
- ampm->setCurrentItem( ValueAM );
- }
- if (show_hour == 0)
- show_hour = 12;
-
- } else {
- sbHour->setMinValue( 0 );
- sbHour->setMaxValue( 23 );
- }
-
-
- sbHour->setValue( show_hour );
-}
-
-void SetTime::checkedPM( int c )
-{
- int show_hour = sbHour->value();
- if (show_hour == 12)
- show_hour = 0;
-
- if ( c == ValuePM )
- show_hour += 12;
-
- hour = show_hour;
-}
-
-void SetTime::slotTzChange( const QString &tz )
-{
- // set the TZ get the time and leave gracefully...
- QString strSave;
- strSave = getenv( "TZ" );
- setenv( "TZ", tz, 1 );
-
- QTime t = QTime::currentTime();
- // reset the time.
- if ( !strSave.isNull() ) {
- setenv( "TZ", strSave, 1 );
- }
-
- // just set the spinboxes and let it propage through
- if(use12hourTime) {
- int show_hour = t.hour();
- if (t.hour() >= 12) {
- show_hour -= 12;
- ampm->setCurrentItem( ValuePM );
- } else {
- ampm->setCurrentItem( ValueAM );
- }
- if (show_hour == 0)
- show_hour = 12;
- sbHour->setValue( show_hour );
- } else {
- sbHour->setValue( t.hour() );
- }
- sbMin->setValue( t.minute() );
-}
-
-void SetTime::setTime( QDateTime dt )
-{
- _time = dt;
- QTime t = dt.time();
- // just set the spinboxes and let it propage through
- if(use12hourTime) {
- int show_hour = t.hour();
- if (t.hour() >= 12) {
- show_hour -= 12;
- ampm->setCurrentItem( ValuePM );
- } else {
- ampm->setCurrentItem( ValueAM );
- }
- if (show_hour == 0)
- show_hour = 12;
- sbHour->setValue( show_hour );
- } else {
- sbHour->setValue( t.hour() );
- }
- sbMin->setValue( t.minute() );
-}
-
-void SetTime::slotClockTick()
-{
- setTime( _time.addSecs(60) );
- qDebug("SetTime::slotClockTick %s",_time.toString().latin1());
-}
diff --git a/noncore/settings/netsystemtime/settime.h b/noncore/settings/netsystemtime/settime.h
deleted file mode 100644
index 58d1006..0000000
--- a/noncore/settings/netsystemtime/settime.h
+++ b/dev/null
@@ -1,102 +0,0 @@
-/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
-**
-** This file is part of Qtopia Environment.
-**
-** This file may be distributed and/or modified under the terms of the
-** GNU General Public License version 2 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.
-**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
-**
-** See http://www.trolltech.com/gpl/ for GPL licensing information.
-**
-** Contact info@trolltech.com if any conditions of this licensing are
-** not clear to you.
-**
-**********************************************************************/
-#ifndef SYSTEM_TIME_H
-#define SYSTEM_TIME_H
-
-
-#include <qdatetime.h>
-#include <qdialog.h>
-
-#include <qpe/timestring.h>
-#include "ntpbase.h"
-
-class QToolButton;
-class QSpinBox;
-class QLabel;
-class TimeZoneSelector;
-class DateBookMonth;
-class QComboBox;
-
-class SetTime : public QWidget
-{
- Q_OBJECT
-public:
- SetTime( QWidget *parent=0, const char *name=0 );
-
- QTime time() const;
- void setTime( QDateTime );
-
-public slots:
- void slotTzChange( const QString& tz );
- void show12hourTime( int );
-
-protected slots:
- void slotClockTick();
- void hourChanged( int value );
- void minuteChanged( int value );
-
- void checkedPM( int );
-
-protected:
- int hour;
- int minute;
- bool use12hourTime;
- QDateTime _time;
- QTimer *clock;
- QComboBox *ampm;
- QSpinBox *sbHour;
- QSpinBox *sbMin;
-};
-
-class DateButton;
-
-class SetDateTime : public NtpBase
-{
- Q_OBJECT
-public:
- SetDateTime( QWidget *parent=0, const char *name=0, WFlags f=0 );
- ~SetDateTime();
-
-protected slots:
- void commitTime();
- void tzChange( const QString &tz );
- void formatChanged(int);
- void updateSystem();
-
-protected:
- void setTime(QDateTime dt);
- void writeSettings();
-
- SetTime *timeButton;
- DateButton *dateButton;
- TimeZoneSelector *tz;
- QString _oldTimeZone;
- QComboBox *weekStartCombo;
- QComboBox *ampmCombo;
- QComboBox *dateFormatCombo;
- QComboBox *clockAppletCombo;
- QPushButton *ButtonSetTime;
-
- DateFormat date_formats[4];
-};
-
-
-#endif
-
diff --git a/noncore/settings/netsystemtime/settingstabwidget.cpp b/noncore/settings/netsystemtime/settingstabwidget.cpp
new file mode 100644
index 0000000..2a7e28d
--- a/dev/null
+++ b/noncore/settings/netsystemtime/settingstabwidget.cpp
@@ -0,0 +1,159 @@
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "settingstabwidget.h"
+
+#include <qpe/config.h>
+#include <qpe/qpeapplication.h>
+
+#include <qcheckbox.h>
+#include <qcombobox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qscrollview.h>
+#include <qspinbox.h>
+
+SettingsTabWidget::SettingsTabWidget( 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 );
+
+ // Time server selector
+ layout->addWidget( new QLabel( tr( "Time server" ), container ), 0, 0 );
+ cbTimeServer = new QComboBox( TRUE, container );
+ layout->addMultiCellWidget( cbTimeServer, 1, 1, 0, 1 );
+
+ // Lookup delay selector
+ layout->addWidget( new QLabel( tr( "minutes between time updates" ), container ), 2, 1 );
+ sbNtpDelay = new QSpinBox( 1, 9999999, 1, container );
+ sbNtpDelay->setWrapping( TRUE );
+ sbNtpDelay->setMaximumWidth( 50 );
+ connect( sbNtpDelay, SIGNAL(valueChanged(int)), this, SIGNAL(ntpDelayChanged(int)) );
+ layout->addWidget( sbNtpDelay, 2, 0 );
+
+ // Prediction delay selector
+ layout->addWidget( new QLabel( tr( "minutes between prediction updates" ), container ), 3, 1 );
+ sbPredictDelay = new QSpinBox( 42, 9999999, 1, container );
+ sbPredictDelay->setWrapping( TRUE );
+ sbPredictDelay->setMaximumWidth( 50 );
+ layout->addWidget( sbPredictDelay, 3, 0 );
+
+ // Space filler
+ layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 4, 0 );
+
+ // Display time server information selector
+ chNtpTab = new QCheckBox( tr( "Display time server information" ), container );
+ connect( chNtpTab, SIGNAL( toggled( bool ) ), this, SIGNAL( displayNTPTab( bool ) ) );
+ layout->addMultiCellWidget( chNtpTab, 5, 5, 0, 1 );
+
+ // Display time prediction information selector
+ chPredictTab = new QCheckBox( tr( "Display time prediction information" ), container );
+ connect( chPredictTab, SIGNAL( toggled( bool ) ), this, SIGNAL( displayPredictTab( bool ) ) );
+ layout->addMultiCellWidget( chPredictTab, 6, 6, 0, 1 );
+
+ // Space filler
+ layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 );
+
+ // Initialize values
+ QString ntpSrvsFile = QPEApplication::qpeDir();
+ ntpSrvsFile.append( "etc/ntpservers" );
+ Config ntpSrvs( ntpSrvsFile, Config::File );
+ ntpSrvs.setGroup( "servers" );
+ int srvCount = ntpSrvs.readNumEntry( "count", 0 );
+ for ( int i = 0; i < srvCount; i++ )
+ {
+ ntpSrvs.setGroup( QString::number( i ) );
+ cbTimeServer->insertItem( ntpSrvs.readEntry( "name" ) );
+ }
+ if ( srvCount==0 )
+ cbTimeServer->insertItem( "time.fu-berlin.de" );
+
+ Config config( "ntp" );
+ config.setGroup( "settings" );
+ sbPredictDelay->setValue( config.readNumEntry( "minLookupDiff", 720 ) );
+ sbNtpDelay->setValue( config.readNumEntry( "ntpRefreshFreq", 1440 ) );
+ cbTimeServer->setCurrentItem( config.readNumEntry( "ntpServer", 0 ) );
+ chNtpTab->setChecked( config.readBoolEntry( "displayNtpTab", FALSE ) );
+ chPredictTab->setChecked( config.readBoolEntry( "displayPredictTab", FALSE ) );
+}
+
+SettingsTabWidget::~SettingsTabWidget()
+{
+}
+
+void SettingsTabWidget::saveSettings()
+{
+ int srvCount = cbTimeServer->count();
+ bool serversChanged = TRUE;
+ int curSrv = cbTimeServer->currentItem();
+ QString edit = cbTimeServer->currentText();
+ for ( int i = 0; i < srvCount; i++ )
+ {
+ if ( edit == cbTimeServer->text( i ) )
+ serversChanged = FALSE;
+ }
+ if ( serversChanged )
+ {
+ QString ntpSrvsFile = QPEApplication::qpeDir();
+ ntpSrvsFile.append( "etc/ntpservers" );
+ Config ntpSrvs( ntpSrvsFile, Config::File );
+ ntpSrvs.setGroup( "servers" );
+ ntpSrvs.writeEntry( "count", ++srvCount );
+ ntpSrvs.setGroup( "0" );
+ ntpSrvs.writeEntry( "name", edit );
+ curSrv = 0;
+ for ( int i = 1; i < srvCount; i++ )
+ {
+// qDebug( "ntpSrvs[%i/%i]=%s", i, srvCount, cbTimeServer->text( i ).latin1() );
+ ntpSrvs.setGroup( QString::number( i ) );
+ ntpSrvs.writeEntry( "name", cbTimeServer->text( i-1 ) );
+ }
+ }
+ Config config( "ntp", Config::User );
+ config.setGroup( "settings" );
+ config.writeEntry( "ntpServer", curSrv );
+ config.writeEntry( "minLookupDiff", sbPredictDelay->value() );
+ config.writeEntry( "ntpRefreshFreq", sbNtpDelay->value() );
+ config.writeEntry( "displayNtpTab", chNtpTab->isChecked() );
+ config.writeEntry( "displayPredictTab", chPredictTab->isChecked() );
+}
+
+QString SettingsTabWidget::ntpServer()
+{
+ return cbTimeServer->currentText();
+}
diff --git a/noncore/settings/netsystemtime/settingstabwidget.h b/noncore/settings/netsystemtime/settingstabwidget.h
new file mode 100644
index 0000000..2901bb3
--- a/dev/null
+++ b/noncore/settings/netsystemtime/settingstabwidget.h
@@ -0,0 +1,62 @@
+/*
+                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.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef SETTINGSTABWIDGET_H
+#define SETTINGSTABWIDGET_H
+
+#include <qwidget.h>
+
+class QCheckBox;
+class QComboBox;
+class QSpinBox;
+
+class SettingsTabWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ SettingsTabWidget( QWidget * = 0x0 );
+ ~SettingsTabWidget();
+
+ void saveSettings();
+ QString ntpServer();
+
+private:
+ QComboBox *cbTimeServer;
+ QSpinBox *sbNtpDelay;
+ QSpinBox *sbPredictDelay;
+ QCheckBox *chNtpTab;
+ QCheckBox *chPredictTab;
+
+signals:
+ void ntpDelayChanged( int );
+ void displayNTPTab( bool );
+ void displayPredictTab( bool );
+};
+
+#endif
diff --git a/noncore/settings/netsystemtime/timetabwidget.cpp b/noncore/settings/netsystemtime/timetabwidget.cpp
new file mode 100644
index 0000000..6f24462
--- a/dev/null
+++ b/noncore/settings/netsystemtime/timetabwidget.cpp
@@ -0,0 +1,292 @@
+/*
+                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.,
+ 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" ),
+ tr( "Get time from the network" ), container );
+ connect( pb, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) );
+ layout->addMultiCellWidget( pb, 8, 8, 0, 5 );
+
+ // Set predicted time button
+ 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::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 );
+ }
+}
+
+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
+ {
+ sbHour->setMinValue( 0 );
+ sbHour->setMaxValue( 23 );
+
+ if ( cbAmpm->currentItem() == ValuePM )
+ {
+ show_hour += 12;
+ if ( show_hour == 24 )
+ show_hour = 0;
+ }
+ }
+
+ sbHour->setValue( show_hour );
+}
+
+void TimeTabWidget::slotDateFormatChanged( const DateFormat &df )
+{
+ btnDate->setDateFormat( df );
+}
+
+void TimeTabWidget::slotWeekStartChanged( int monday )
+{
+ btnDate->setWeekStartsMonday( monday );
+}
+
+void TimeTabWidget::slotTZChanged( const QString &newtz )
+{
+ // 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 );
+ QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
+ setTimeZone << newtz;
+
+ // Set system timezone
+ QString currtz = getenv( "TZ" );
+ setenv( "TZ", newtz, 1 );
+
+ // Get new date/time
+ hour = sbHour->value();
+ if ( use12HourTime && cbAmpm->currentItem() == ValuePM )
+ hour += 12;
+ dt = QDateTime::currentDateTime();
+
+ // Reset system timezone
+ if ( !currtz.isNull() )
+ {
+ setenv( "TZ", currtz, 1 );
+ }
+
+ // Set controls to new time
+ setDateTime( dt );
+
+ emit tzChanged( newtz );
+}
diff --git a/noncore/settings/netsystemtime/timetabwidget.h b/noncore/settings/netsystemtime/timetabwidget.h
new file mode 100644
index 0000000..f44a1da
--- a/dev/null
+++ b/noncore/settings/netsystemtime/timetabwidget.h
@@ -0,0 +1,77 @@
+/*
+                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.,
+ 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 QSpinBox;
+class TimeZoneSelector;
+
+class TimeTabWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ TimeTabWidget( QWidget * = 0x0 );
+ ~TimeTabWidget();
+
+ void saveSettings( bool );
+ void setDateTime( const QDateTime & );
+
+private:
+ QSpinBox *sbHour;
+ QSpinBox *sbMin;
+ QComboBox *cbAmpm;
+ DateButton *btnDate;
+ TimeZoneSelector *selTimeZone;
+
+ 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