summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (ignore 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.pro21
-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, 1771 insertions, 1988 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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "formattabwidget.h"
30
31#include <qpe/config.h>
32
33#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
34#include <qpe/qcopenvelope_qws.h>
35#endif
36
37#include <qcombobox.h>
38#include <qlabel.h>
39#include <qlayout.h>
40#include <qscrollview.h>
41#include <qtimer.h>
42
43FormatTabWidget::FormatTabWidget( QWidget *parent )
44 : QWidget( parent, 0x0, 0 )
45{
46 QVBoxLayout *tmpvb = new QVBoxLayout( this );
47 QScrollView *sv = new QScrollView( this );
48 tmpvb->addWidget( sv, 0, 0 );
49 sv->setResizePolicy( QScrollView::AutoOneFit );
50 sv->setFrameStyle( QFrame::NoFrame );
51 QWidget *container = new QWidget( sv->viewport() );
52 sv->addChild( container );
53
54 QGridLayout *layout = new QGridLayout( container );
55 layout->setMargin( 2 );
56 layout->setSpacing( 4 );
57
58 // Time format selector
59 layout->addWidget( new QLabel( tr( "Time format" ), container ), 0, 0 );
60 cbAppletFormat = new QComboBox( container );
61 cbAppletFormat->insertItem( tr( "hh:mm" ), 0 );
62 cbAppletFormat->insertItem( tr( "D/M hh:mm" ), 1 );
63 cbAppletFormat->insertItem( tr( "M/D hh:mm" ), 2 );
64 layout->addWidget( cbAppletFormat, 0, 1 );
65
66 // 12/24 hour selector
67 layout->addWidget( new QLabel( tr( "12/24 hour" ), container ), 1, 0 );
68 cbAmpm = new QComboBox( container );
69 cbAmpm->insertItem( tr( "24 hour" ), 0 );
70 cbAmpm->insertItem( tr( "12 hour" ), 1 );
71 connect( cbAmpm, SIGNAL(activated(int)), this, SIGNAL(show12HourTime(int)) );
72 layout->addWidget( cbAmpm, 1, 1 );
73
74 // Date format selector
75 layout->addWidget( new QLabel( tr( "Date format" ), container ), 2, 0 );
76 cbDateFormat = new QComboBox( container );
77 connect( cbDateFormat, SIGNAL(activated(int)), this, SLOT(slotDateFormatChanged(int)) );
78 layout->addWidget( cbDateFormat, 2, 1 );
79
80 // Week starts on selector
81 layout->addWidget( new QLabel( tr( "Weeks start on" ), container ), 3, 0 );
82 cbWeekStart = new QComboBox( container );
83 cbWeekStart->insertItem( tr( "Sunday" ), 0 );
84 cbWeekStart->insertItem( tr( "Monday" ), 1 );
85 connect( cbWeekStart, SIGNAL(activated(int)), this, SIGNAL(weekStartChanged(int)) );
86 layout->addWidget( cbWeekStart, 3, 1 );
87
88 // Initialize values
89 Config config( "qpe" );
90 config.setGroup( "Date" );
91 cbAppletFormat->setCurrentItem( config.readNumEntry( "ClockApplet", 0 ) );
92
93 DateFormat df(QChar(config.readEntry("Separator", "/")[0]),
94 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
95 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
96
97 int currentdf = 0;
98 date_formats[0] = DateFormat( '/', DateFormat::MonthDayYear );
99 cbDateFormat->insertItem( tr( date_formats[0].toNumberString() ) );
100 date_formats[1] = DateFormat( '.', DateFormat::DayMonthYear );
101 if ( df == date_formats[1] )
102 currentdf = 1;
103 cbDateFormat->insertItem( tr( date_formats[1].toNumberString() ) );
104 date_formats[2] = DateFormat( '-', DateFormat::YearMonthDay, DateFormat::DayMonthYear );
105 if ( df == date_formats[2] )
106 currentdf = 2;
107 cbDateFormat->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601
108 date_formats[3] = DateFormat( '/', DateFormat::DayMonthYear );
109 if ( df == date_formats[3] )
110 currentdf = 3;
111 cbDateFormat->insertItem( tr( date_formats[3].toNumberString() ) );
112
113 cbDateFormat->setCurrentItem( currentdf );
114 //dateButton->setDateFormat( df );
115
116 config.setGroup( "Time" );
117 cbAmpm->setCurrentItem( config.readBoolEntry( "AMPM" ) ? 1 : 0 );
118 cbWeekStart->setCurrentItem( config.readBoolEntry( "MONDAY" ) ? 1 : 0 );
119
120 // Send initial configuration options
121 QTimer::singleShot( 1200, this, SLOT(sendOptions()) );
122}
123
124FormatTabWidget::~FormatTabWidget()
125{
126}
127
128void FormatTabWidget::saveSettings( bool commit )
129{
130 int ampm = cbAmpm->currentItem();
131 int weekstart = cbWeekStart->currentItem();
132 DateFormat df = date_formats[cbDateFormat->currentItem()];
133 int appletformat = cbAppletFormat->currentItem();
134
135 if ( commit )
136 {
137 // Write settings to config file
138 Config config("qpe");
139 config.setGroup( "Time" );
140 config.writeEntry( "AMPM", ampm );
141 config.writeEntry( "MONDAY", weekstart );
142 config.setGroup( "Date" );
143 config.writeEntry( "Separator", QString( df.separator() ) );
144 config.writeEntry( "ShortOrder", df.shortOrder() );
145 config.writeEntry( "LongOrder", df.longOrder() );
146 config.writeEntry( "ClockApplet", appletformat );
147 }
148
149 // Make rest of system aware of new settings
150 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
151 setClock << ampm;
152 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
153 setWeek << weekstart;
154 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
155 setDateFormat << df;
156}
157
158void FormatTabWidget::slotDateFormatChanged( int selected )
159{
160 emit dateFormatChanged( date_formats[selected] );
161}
162
163void FormatTabWidget::sendOptions()
164{
165 emit show12HourTime( cbAmpm->currentItem() );
166 emit dateFormatChanged( date_formats[cbDateFormat->currentItem()] );
167 emit weekStartChanged( cbWeekStart->currentItem() );
168}
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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef FORMATTABWIDGET_H
30#define FORMATTABWIDGET_H
31
32#include <qpe/timestring.h>
33
34#include <qwidget.h>
35
36class QComboBox;
37
38class FormatTabWidget : public QWidget
39{
40 Q_OBJECT
41
42public:
43 FormatTabWidget( QWidget * = 0x0 );
44 ~FormatTabWidget();
45
46 void saveSettings( bool );
47
48private:
49 QComboBox *cbAmpm;
50 QComboBox *cbWeekStart;
51 QComboBox *cbDateFormat;
52 QComboBox *cbAppletFormat;
53 DateFormat date_formats[4];
54
55signals:
56 void show12HourTime( int );
57 void dateFormatChanged( const DateFormat & );
58 void weekStartChanged( int );
59
60private slots:
61 void slotDateFormatChanged( int );
62 void sendOptions();
63};
64
65#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 @@
1#include <stdio.h> 1/*
2#include "ntp.h" 2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "mainwindow.h"
30
3#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
4 32
5int main( int argc, char ** argv ) 33int main( int argc, char ** argv )
6{ 34{
7 printf("This is netsystemtime ");
8 printf("$Id$\n");
9
10 QPEApplication a( argc, argv ); 35 QPEApplication a( argc, argv );
11 36
12 Ntp mw; 37 MainWindow mw;
13 a.showMainWidget( &mw ); 38 a.showMainWidget( &mw );
14 39
15 return a.exec(); 40 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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "mainwindow.h"
30#include "timetabwidget.h"
31#include "formattabwidget.h"
32#include "settingstabwidget.h"
33#include "ntptabwidget.h"
34#include "predicttabwidget.h"
35#include "systemtimeconfig.h"
36
37#include <opie/oprocess.h>
38#include <opie/otabwidget.h>
39
40#include <qpe/config.h>
41#include <qpe/datebookdb.h>
42#include <qpe/qpeapplication.h>
43
44#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
45#include <qpe/qcopenvelope_qws.h>
46#endif
47
48#include <qlayout.h>
49#include <qmessagebox.h>
50#include <qsocket.h>
51#include <qstring.h>
52#include <qtimer.h>
53
54MainWindow::MainWindow()
55 : QDialog( 0x0, 0x0, TRUE, 0 )
56{
57 setCaption( tr( "SystemTime" ) );
58
59 QVBoxLayout *layout = new QVBoxLayout( this );
60 layout->setMargin( 2 );
61 layout->setSpacing( 4 );
62
63 // Create main tabbed control
64 mainWidget = new OTabWidget( this );
65
66 // Default object pointers to null
67 ntpProcess = 0x0;
68 ntpTab = 0x0;
69
70 // Add tab widgets
71 mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) );
72 mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) );
73 mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) );
74 mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) );
75 Config config( "ntp" );
76 config.setGroup( "settings" );
77 slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) );
78 slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) );
79
80 mainWidget->setCurrentTab( tr( "Time" ) );
81 layout->addWidget( mainWidget );
82
83 // Create QCOP channel
84 QCopChannel *channel = new QCopChannel( "QPE/Application/netsystemtime", this );
85 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
86 this, SLOT(slotQCopReceive(const QCString&, const QByteArray&)) );
87
88 // Create NTP socket
89 ntpSock = new QSocket( this );
90 connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) );
91 slotProbeNTPServer();
92
93 // Create timer for automatic time lookups
94 ntpTimer = new QTimer( this );
95
96 // Connect everything together
97 connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) );
98 connect( timeTab, SIGNAL(tzChanged(const QString &)), predictTab, SLOT(slotTZChanged(const QString &)) );
99 connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) );
100 connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime( int )) );
101 connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat &)),
102 timeTab, SLOT(slotDateFormatChanged(const DateFormat &)) );
103 connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) );
104 connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) );
105 connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) );
106 connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) );
107 connect( predictTab, SIGNAL(setTime(const QDateTime &)), this, SLOT(slotSetTime(const QDateTime &)) );
108
109 // Do initial time server check
110 slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) );
111 slotCheckNtp( -1 );
112
113 // Display app
114 showMaximized();
115}
116
117MainWindow::~MainWindow()
118{
119 if ( ntpProcess )
120 delete ntpProcess;
121}
122
123void MainWindow::accept()
124{
125 // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends)
126 {
127 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
128 disableScreenSaver << 0 << 0 << 0;
129 }
130
131 // Update the systemtime
132 timeTab->saveSettings( TRUE );
133
134 // Save format options
135 formatTab->saveSettings( TRUE );
136
137 // Save settings options
138 settingsTab->saveSettings();
139
140 // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better
141 // grip on itself (example re-trigger alarms for when we travel back in time).
142 DateBookDB db;
143
144 // Turn back on the screensaver
145 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
146 enableScreenSaver << -1 << -1 << -1;
147
148 // Exit app
149 qApp->quit();
150}
151
152void MainWindow::reject()
153{
154 // Reset time settings
155 timeTab->saveSettings( FALSE );
156
157 // Send notifications but do not save settings
158 formatTab->saveSettings( FALSE );
159
160 // Exit app
161 qApp->quit();
162}
163
164void MainWindow::runNTP()
165{
166 if ( !ntpDelayElapsed() && ntpInteractive )
167 {
168 QString msg = tr( "You asked for a delay of " );
169 msg.append( QString::number( ntpDelay ) );
170 msg.append( tr( " minutes, but only " ) );
171 msg.append( QString::number( _lookupDiff / 60 ) );
172 msg.append( tr(" minutes elapsed since last lookup.<br>Continue?") );
173
174 switch (
175 QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No )
176 )
177 {
178 case QMessageBox::Yes: break;
179 case QMessageBox::No: return;
180 default: return;
181 }
182 }
183
184 QString srv = settingsTab->ntpServer();
185
186 // Send information to time server tab if enabled
187 if ( ntpTabEnabled )
188 {
189 ntpTab->setStartTime( QDateTime::currentDateTime().toString() );
190 QString output = tr( "Running:\nntpdate " );
191 output.append( srv );
192 ntpTab->addNtpOutput( output );
193 }
194
195 if ( !ntpProcess )
196 {
197 ntpProcess = new OProcess();
198 connect( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
199 this, SLOT(slotNtpOutput(OProcess*,char*,int)) );
200 connect( ntpProcess, SIGNAL(processExited(OProcess*)),
201 this, SLOT(slotNtpFinished(OProcess*)) );
202 }
203
204 else
205 ntpProcess->clearArguments();
206
207 *ntpProcess << "ntpdate" << srv;
208 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput );
209 if ( !ret )
210 {
211 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) );
212 if ( ntpTabEnabled )
213 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) );
214 }
215}
216
217bool MainWindow::ntpDelayElapsed()
218{
219 // Determine if time elapsed is greater than time delay
220 Config config( "ntp" );
221 config.setGroup( "lookups" );
222 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 );
223 if ( _lookupDiff < 0 )
224 return true;
225 return ( _lookupDiff - ( ntpDelay * 60) ) > 0;
226}
227
228void MainWindow::slotSetTime( const QDateTime &dt )
229{
230 timeTab->setDateTime( dt );
231}
232
233void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & )
234{
235 if ( msg == "ntpLookup(QString)" )
236 {
237 ntpInteractive = false;
238 runNTP();
239 }
240 if ( msg == "setPredictedTime(QString)" )
241 {
242 //setPredictTime();
243 }
244}
245
246void MainWindow::slotDisplayNTPTab( bool display )
247{
248 ntpTabEnabled = display;
249
250 // Create widget if it hasn't needed
251 if ( display && !ntpTab )
252 {
253 ntpTab = new NTPTabWidget( mainWidget );
254 connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) );
255 }
256
257 // Display/hide tab
258 display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) )
259 : mainWidget->removePage( ntpTab );
260}
261
262void MainWindow::slotDisplayPredictTab( bool display )
263{
264 predictTabEnabled = display;
265
266 // Create widget if it hasn't needed
267 if ( display && !predictTab )
268 {
269 }
270 // Display/hide tab
271 display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) )
272 : mainWidget->removePage( predictTab );
273}
274
275void MainWindow::slotGetNTPTime()
276{
277 ntpInteractive = TRUE;
278 runNTP();
279}
280
281void MainWindow::slotTimerGetNTPTime()
282{
283 ntpInteractive = FALSE;
284 runNTP();
285}
286
287void MainWindow::slotProbeNTPServer()
288{
289 ntpSock->connectToHost( settingsTab->ntpServer(), 123 );
290}
291
292void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen )
293{
294 QString output = QString( buffer ).left( buflen );
295 ntpOutput.append( output );
296
297 if ( ntpTabEnabled )
298 ntpTab->addNtpOutput( output );
299}
300
301void MainWindow::slotNtpFinished( OProcess *p )
302{
303 QString output;
304 QDateTime dt = QDateTime::currentDateTime();
305
306 // Verify run was successful
307 if ( p->exitStatus() != 0 || !p->normalExit() )
308 {
309 if ( isVisible() && ntpInteractive )
310 {
311 output = tr( "Error while getting time from\n server: " );
312 output.append( settingsTab->ntpServer() );
313 QMessageBox::critical(this, tr( "Error" ), output );
314 }
315 // slotCheckNtp(-1);
316 return;
317 }
318
319 // Set controls on time tab to new time value
320 timeTab->setDateTime( dt );
321
322 // Write out lookup information
323 Config config( "ntp" );
324 config.setGroup( "lookups" );
325 int lastLookup = config.readNumEntry( "time", 0 );
326 int lookupCount = config.readNumEntry( "count", 0 );
327 bool lastNtp = config.readBoolEntry( "lastNtp", FALSE );
328 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
329 config.writeEntry( "time", time );
330
331 // Calculate new time/time shift
332 QString _offset = "offset";
333 QString _sec = "sec";
334 QRegExp _reOffset = QRegExp( _offset );
335 QRegExp _reEndOffset = QRegExp( _sec );
336 int posOffset = _reOffset.match( ntpOutput );
337 int posEndOffset = _reEndOffset.match( ntpOutput, posOffset );
338 posOffset += _offset.length() + 1;
339 QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 );
340
341 float timeShift = diff.toFloat();
342 if ( timeShift == 0.0 )
343 return;
344 int secsSinceLast = time - lastLookup;
345 output = QString::number( timeShift );
346 output.append( tr( " seconds" ) );
347
348 // Display information on time server tab
349 if ( ntpTabEnabled )
350 {
351 ntpTab->setTimeShift( output );
352 ntpTab->setNewTime( dt.toString() );
353 }
354
355 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay )
356 {
357 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) );
358 config.setGroup( grpname );
359 lookupCount++;
360 predictTab->setShiftPerSec( timeShift / secsSinceLast );
361 config.writeEntry( "secsSinceLast", secsSinceLast );
362 config.writeEntry( "timeShift", QString::number( timeShift ) );
363 config.setGroup( "lookups" );
364 config.writeEntry( "count", lookupCount );
365 config.writeEntry( "lastNtp", TRUE );
366 }
367}
368
369void MainWindow::slotNTPDelayChanged( int delay )
370{
371 ntpTimer->changeInterval( delay * 1000 * 60 );
372 ntpDelay = delay;
373}
374
375void MainWindow::slotCheckNtp( int i )
376{
377 if ( i == 0 )
378 {
379 if ( ntpDelayElapsed() )
380 {
381 runNTP();
382 disconnect( ntpTimer, SIGNAL(timeout()), this, SLOT(slotProbeNTPServer()) );
383 connect( ntpTimer, SIGNAL(timeout()), SLOT(slotTimerGetNTPTime()) );
384 }
385 else
386 {
387 disconnect(ntpTimer, SIGNAL(timeout()), this, SLOT(slotTimerGetNTPTime()) );
388 connect(ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) );
389 }
390 }
391 else
392 {
393 predictTab->slotPredictTime();
394 if ( i > 0 )
395 {
396 QString output = tr( "Could not connect to server " );
397 output.append( settingsTab->ntpServer() );
398 ntpOutput.append( output );
399 if ( ntpTabEnabled )
400 ntpTab->addNtpOutput( output );
401 }
402 connect( ntpTimer, SIGNAL(timeout()), SLOT(slotProbeNTPServer()) );
403 }
404}
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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef MAINWINDOW_H
30#define MAINWINDOW_H
31
32#include <qdialog.h>
33
34class TimeTabWidget;
35class FormatTabWidget;
36class SettingsTabWidget;
37class NTPTabWidget;
38class PredictTabWidget;
39
40class OProcess;
41class OTabWidget;
42class QDateTime;
43class QSocket;
44class QTimer;
45
46class MainWindow : public QDialog
47{
48 Q_OBJECT
49
50public:
51 MainWindow();
52 ~MainWindow();
53
54protected:
55 void accept();
56 void reject();
57
58private:
59 OTabWidget *mainWidget;
60
61 TimeTabWidget *timeTab;
62 FormatTabWidget *formatTab;
63 SettingsTabWidget *settingsTab;
64 NTPTabWidget *ntpTab;
65 PredictTabWidget *predictTab;
66
67 bool ntpTabEnabled;
68 bool predictTabEnabled;
69
70 OProcess *ntpProcess;
71 QTimer *ntpTimer;
72 QSocket *ntpSock;
73 int ntpDelay;
74 bool ntpInteractive;
75 QString ntpOutput;
76 int _lookupDiff;
77
78 void runNTP();
79 bool ntpDelayElapsed();
80
81private slots:
82 void slotSetTime( const QDateTime & );
83 void slotQCopReceive( const QCString &, const QByteArray & );
84 void slotDisplayNTPTab( bool );
85 void slotDisplayPredictTab( bool );
86 void slotGetNTPTime();
87 void slotTimerGetNTPTime();
88 void slotProbeNTPServer();
89 void slotNtpOutput( OProcess *, char *, int );
90 void slotNtpFinished( OProcess* );
91 void slotNTPDelayChanged( int );
92 void slotCheckNtp( int );
93};
94
95#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,13 +1,24 @@
1 TEMPLATE= app 1 TEMPLATE= app
2 CONFIG = qt warn_on debug 2 CONFIG = qt warn_on debug
3 #CONFIG = qt warn_on release 3 #CONFIG = qt warn_on release
4 HEADERS = ntp.h settime.h 4 HEADERS = mainwindow.h \
5 SOURCES = main.cpp ntp.cpp settime.cpp 5 timetabwidget.h \
6 formattabwidget.h \
7 settingstabwidget.h \
8 predicttabwidget.h \
9 ntptabwidget.h
10 SOURCES = main.cpp \
11 mainwindow.cpp \
12 timetabwidget.cpp \
13 formattabwidget.cpp \
14 settingstabwidget.cpp \
15 predicttabwidget.cpp \
16 ntptabwidget.cpp
6 INCLUDEPATH+= $(OPIEDIR)/include 17 INCLUDEPATH+= $(OPIEDIR)/include
7 DEPENDPATH+= $(OPIEDIR)/include 18 DEPENDPATH+= $(OPIEDIR)/include
8LIBS += -lqpe -lopie 19 LIBS += -lqpe -lopie
9 INTERFACES= ntpbase.ui 20 INTERFACES=
10DESTDIR = $(OPIEDIR)/bin 21 DESTDIR = $(OPIEDIR)/bin
11 TARGET = systemtime 22 TARGET = systemtime
12 23
13TRANSLATIONS = ../../../i18n/de/systemtime.ts \ 24TRANSLATIONS = ../../../i18n/de/systemtime.ts \
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 @@
1#include "ntp.h"
2#include <qpushbutton.h>
3#include <qregexp.h>
4#include <qtimer.h>
5#include <qtable.h>
6#include <qlabel.h>
7#include <qsocket.h>
8#include <qlineedit.h>
9#include <qspinbox.h>
10#include <qcheckbox.h>
11#include <qtabwidget.h>
12#include <qlayout.h>
13#include <qmessagebox.h>
14#include <qmultilineedit.h>
15#include <opie/oprocess.h>
16#include <qpe/qpeapplication.h>
17#include <qpe/config.h>
18#include <qpe/global.h>
19#include <qpe/timeconversion.h>
20#include <qpe/tzselect.h>
21#include <qpe/timestring.h>
22#include <qpe/qpedialog.h>
23#include <qpe/datebookdb.h>
24#include <qpe/datebookmonth.h>
25#include <qpe/qcopenvelope_qws.h>
26#include <sys/time.h>
27#include <time.h>
28#include <stdlib.h>
29
30
31Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
32 : SetDateTime( parent, name, fl )
33{
34 _interactive = false;
35 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
36 ntpSrvs.setGroup("servers");
37 int srvCount = ntpSrvs.readNumEntry("count", 0 );
38 for (int i = 0; i < srvCount; i++)
39 {
40 ntpSrvs.setGroup(QString::number(i));
41 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
42 }
43 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
44
45 Config cfg("ntp",Config::User);
46 cfg.setGroup("settings");
47 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) );
48 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) );
49 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
50
51 //make tab order
52
53 TabWidgetMain->removePage( tabMain );
54 TabWidgetMain->removePage( tabManualSetTime );
55 TabWidgetMain->removePage( TabSettings );
56 TabWidgetMain->removePage( tabPredict );
57 TabWidgetMain->removePage( tabNtp );
58
59 TabWidgetMain->insertTab( tabMain, tr( "Main" ) );
60 TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) );
61 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) );
62 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) );
63 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 );
64
65
66
67 bool advMode = cfg.readBoolEntry("advancedFeatures", false );
68 showAdvancedFeatures(advMode);
69 CheckBoxAdvSettings->setChecked( advMode );
70 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ),
71 SLOT( showAdvancedFeatures( bool ) ) );
72
73 makeChannel();
74
75 ntpTimer = new QTimer(this);
76
77 ntpProcess = new OProcess( );
78 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
79 SLOT(slotNtpDelayChanged(int)) );
80
81 ntpSock = new QSocket( this );
82 connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) );
83 slotProbeNtpServer();
84
85 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
86 this, SLOT(getNtpOutput(OProcess*,char*,int)));
87 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
88 this, SLOT(ntpFinished(OProcess*)));
89 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp()));
90 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
91 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
92 slotCheckNtp(-1);
93 readLookups();
94}
95
96Ntp::~Ntp()
97{
98 delete ntpProcess;
99}
100
101void Ntp::saveConfig(){
102 int srvCount = ComboNtpSrv->count();
103 bool serversChanged = true;
104 int curSrv = ComboNtpSrv->currentItem();
105 QString edit = ComboNtpSrv->currentText();
106 for (int i = 0; i < srvCount; i++){
107 if ( edit == ComboNtpSrv->text(i)) serversChanged = false;
108 }
109 if (serversChanged){
110 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
111 ntpSrvs.setGroup("servers");
112 ntpSrvs.writeEntry("count", ++srvCount);
113 ntpSrvs.setGroup("0");
114 ntpSrvs.writeEntry( "name", edit );
115 curSrv = 0;
116 for (int i = 1; i < srvCount; i++){
117 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1());
118 ntpSrvs.setGroup(QString::number(i));
119 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) );
120 }
121 }
122 Config cfg("ntp",Config::User);
123 cfg.setGroup("settings");
124 cfg.writeEntry("ntpServer", curSrv );
125 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
126 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
127 cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() );
128}
129
130bool Ntp::ntpDelayElapsed()
131{
132 Config cfg("ntp",Config::User);
133 cfg.setGroup("lookups");
134 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
135 if (_lookupDiff < 0) return true;
136 int i =_lookupDiff - (SpinBoxNtpDelay->value()*60);
137 return i > -60;
138}
139
140QString Ntp::getNtpServer()
141{
142 return ComboNtpSrv->currentText();
143}
144
145void Ntp::slotButtonRunNtp()
146{
147 _interactive = true;
148 slotRunNtp();
149}
150
151void Ntp::slotTimerRunNtp()
152{
153 _interactive = false;
154 slotRunNtp();
155}
156
157
158void Ntp::slotRunNtp()
159{
160 if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() )
161 {
162 switch (
163 QMessageBox::warning(this, tr("Run NTP?"),
164 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
165 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+
166 "<br>"+tr("Rerun NTP?"),
167 QMessageBox::Ok,QMessageBox::Cancel)
168 ) {
169 case QMessageBox::Ok: break;
170 case QMessageBox::Cancel: return;
171 default: return;
172 }
173 }
174 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
175 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
176
177 ntpProcess->clearArguments();
178 *ntpProcess << "ntpdate" << getNtpServer();
179 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
180 if ( !ret ) {
181 QMessageBox::critical(this, tr("ntp error"),
182 tr("Error while getting time form network!"));
183 qDebug("Error while executing ntpdate");
184 ntpOutPut( tr("Error while executing ntpdate"));
185 }
186}
187
188void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
189{
190 if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null");
191 QString lineStr, lineStrOld;
192 lineStr = buffer;
193 lineStr=lineStr.left(buflen);
194 if (lineStr!=lineStrOld)
195 {
196 ntpOutPut(lineStr);
197 _ntpOutput += lineStr;
198 }
199 lineStrOld = lineStr;
200}
201
202void Ntp::ntpFinished(OProcess *p)
203{
204 qDebug("p->exitStatus() %i",p->exitStatus());
205 if (p->exitStatus()!=0 || !p->normalExit())
206 {
207 if ( isVisible() && _interactive ){
208 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput );
209 }
210// slotCheckNtp(-1);
211 return;
212 }
213
214 Config cfg("ntp",Config::User);
215 cfg.setGroup("lookups");
216 int lastLookup = cfg.readNumEntry("time",0);
217 int lookupCount = cfg.readNumEntry("count",0);
218 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
219 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
220 cfg.writeEntry("time", time);
221
222 float timeShift = getTimeShift();
223 if (timeShift == 0.0) return;
224 int secsSinceLast = time - lastLookup;
225 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
226 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
227
228 dateButton->setDate( QDate::currentDate() );
229 timeButton->setTime( QDateTime::currentDateTime() );
230
231 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
232 {
233 cfg.setGroup("lookup_"+QString::number(lookupCount));
234 lookupCount++;
235 _shiftPerSec = timeShift / secsSinceLast;
236 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
237 cfg.writeEntry("secsSinceLast",secsSinceLast);
238 cfg.writeEntry("timeShift",QString::number(timeShift));
239 cfg.setGroup("lookups");
240 cfg.writeEntry("count",lookupCount);
241 cfg.writeEntry("lastNtp",true);
242 }
243}
244
245
246float Ntp::getTimeShift()
247{
248 QString _offset = "offset";
249 QString _sec = "sec";
250 QRegExp _reOffset = QRegExp(_offset);
251 QRegExp _reEndOffset = QRegExp(_sec);
252 int posOffset = _reOffset.match( _ntpOutput );
253 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
254 posOffset += _offset.length() + 1;
255 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
256 qDebug("%s", _ntpOutput.latin1());
257 qDebug("diff = >%s<",diff.latin1());
258 return diff.toFloat();
259}
260
261void Ntp::readLookups()
262{
263 Config cfg("ntp",Config::User);
264 cfg.setGroup("lookups");
265 int lookupCount = cfg.readNumEntry("count",0);
266 float last, shift, shiftPerSec;
267 qDebug("lookupCount = %i",lookupCount);
268 TableLookups->setNumCols( 3 );
269 TableLookups->setNumRows( lookupCount);
270 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
271 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
272 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
273 int cw = TableLookups->width()/4;
274 qDebug("column width %i",cw);
275 cw = 50;
276 TableLookups->setColumnWidth( 0, cw+30 );
277 TableLookups->setColumnWidth( 1, cw );
278 TableLookups->setColumnWidth( 2, cw );
279 TableLookups->sortColumn(0, false, true );
280 // TableLookups->setSorting( true );
281 _shiftPerSec = 0;
282 for (int i=0; i < lookupCount; i++)
283 {
284 cfg.setGroup("lookup_"+QString::number(i));
285 last = cfg.readEntry("secsSinceLast",0).toFloat();
286 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
287 shiftPerSec = shift / last;
288 qDebug("%i shift %f",i,shiftPerSec);
289 _shiftPerSec += shiftPerSec;
290 TableLookups->setText( i,0,QString::number(shiftPerSec*60*60));
291 TableLookups->setText( i,2,QString::number(shift));
292 TableLookups->setText( i,1,QString::number(last/(60*60)));
293 }
294 _shiftPerSec /= lookupCount;
295 TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h"));
296}
297
298void Ntp::preditctTime()
299{
300 Config cfg("ntp",Config::User);
301 cfg.setGroup("lookups");
302 int lastTime = cfg.readNumEntry("time",0);
303 cfg.writeEntry("lastNtp",true);
304 setenv( "TZ", tz->currentZone(), 1 );
305 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
306 int corr = int((now - lastTime) * _shiftPerSec);
307 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
308 predictedTime = QDateTime::currentDateTime().addSecs(corr);
309 TextLabelPredTime->setText(predictedTime.toString());
310// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
311}
312
313void Ntp::setPredictTime()
314{
315 qDebug("Ntp::setPredictTime");
316 preditctTime();
317 timeButton->setTime( predictedTime );
318}
319
320void Ntp::slotCheckNtp(int i)
321{
322 qDebug(" Ntp::slotCheckNtp(%i)",i);
323 if (i == 0)
324 {
325// TextLabelMainPredTime->hide();
326 ButtonSetTime->setText( tr("Get time from network") );
327 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) );
328 if ( ntpDelayElapsed() )
329 {
330 slotRunNtp();
331 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
332 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) );
333 }else{
334 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) );
335 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
336 }
337 }else{
338 preditctTime();
339 ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() );
340 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
341 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
342 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
343 }
344}
345
346void Ntp::slotProbeNtpServer()
347{
348 ntpSock->connectToHost( getNtpServer() ,123);
349}
350
351void Ntp::slotNtpDelayChanged(int delay)
352{
353 ntpTimer->changeInterval( delay*1000*60 );
354}
355
356void Ntp::ntpOutPut(QString out)
357{
358
359 MultiLineEditntpOutPut->append(out);
360 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
361}
362
363
364void Ntp::makeChannel()
365{
366 channel = new QCopChannel( "QPE/Application/netsystemtime", this );
367 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
368 this, SLOT(receive(const QCString&, const QByteArray&)) );
369}
370
371
372
373void Ntp::receive(const QCString &msg, const QByteArray &arg)
374{
375 qDebug("QCop(Ntp) "+msg+" "+QCString(arg));
376 if ( msg == "ntpLookup(QString)" )
377 {
378 _interactive = false;
379 slotRunNtp();
380 }
381 if ( msg == "setPredictedTime(QString)" )
382 {
383 setPredictTime();
384 }else{
385 qDebug("Ntp::receive: Huh what do ya want");
386 }
387}
388
389void Ntp::setDocument(const QString &fileName)
390{
391 qDebug("Ntp::setDocument( %s )",fileName.latin1());
392}
393
394void Ntp::showAdvancedFeatures(bool advMode)
395{
396 if (advMode) {
397
398 if ( tabNtp->isVisible() ) {
399 TabWidgetMain->addTab( tabPredict, tr( "Predict" ) );
400 TabWidgetMain->addTab( tabNtp, tr( "NTP" ) );
401 }
402 TextLabel1_2_2->show();
403 TextLabel2_3->show();
404 TextLabel3_3_2->show();
405 TextLabel1_2->show();
406 SpinBoxMinLookupDelay->show();
407 TextLabel2->show();
408 TextLabel3_3->show();
409 SpinBoxNtpDelay->show();
410 Line1->show();
411 }else{
412 TabWidgetMain->removePage( tabPredict );
413 TabWidgetMain->removePage( tabNtp );
414 TextLabel1_2_2->hide();
415 TextLabel2_3->hide();
416 TextLabel3_3_2->hide();
417 TextLabel1_2->hide();
418 SpinBoxMinLookupDelay->hide();
419 TextLabel2->hide();
420 TextLabel3_3->hide();
421 SpinBoxNtpDelay->hide();
422 Line1->hide();
423 };
424 TabWidgetMain->show();
425}
426
427
428void Ntp::accept( ){
429 qDebug("saving");
430 //SetTimeDate
431 commitTime();
432 writeSettings();
433 updateSystem();
434 // Ntp
435 saveConfig();
436 qApp->quit();
437}
438
439void Ntp::reject( ){
440 qDebug("_oldTimeZone %s",_oldTimeZone.latin1());
441 if (!_oldTimeZone.isEmpty()){
442 qDebug("reverting timezone");
443 tzChange(_oldTimeZone);
444 commitTime();
445 }
446}
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 @@
1#ifndef NTP_H
2#define NTP_H
3#include "settime.h"
4#include <qdatetime.h>
5
6class OProcess;
7class QString;
8class QTimer;
9class QSocket;
10class QCopChannel;
11
12class Ntp : public SetDateTime
13{
14 Q_OBJECT
15
16public:
17 Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
18 ~Ntp();
19
20public slots:
21 void setDocument (const QString &);
22protected:
23 virtual void accept( );
24 virtual void reject( );
25 QDateTime predictedTime;
26 void makeChannel();
27protected slots:
28 void receive(const QCString &msg, const QByteArray &arg);
29private:
30 QString _ntpOutput;
31 float _shiftPerSec;
32 int _lookupDiff;
33 OProcess *ntpProcess;
34 QTimer *ntpTimer;
35 QSocket *ntpSock;
36 QCopChannel *channel;
37 bool _interactive;
38 float getTimeShift();
39 void readLookups();
40 void ntpOutPut(QString);
41 bool ntpDelayElapsed();
42 QString getNtpServer();
43 void saveConfig();
44private slots:
45 void slotTimerRunNtp();
46 void slotButtonRunNtp();
47 void slotRunNtp();
48 void getNtpOutput(OProcess *proc, char *buffer, int buflen);
49 void ntpFinished(OProcess*);
50 void preditctTime();
51 void slotCheckNtp(int);
52 void setPredictTime();
53 void showAdvancedFeatures(bool);
54 void slotProbeNtpServer();
55 void slotNtpDelayChanged(int);
56};
57
58#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 @@
1<!DOCTYPE UI><UI>
2<class>NtpBase</class>
3<widget>
4 <class>QDialog</class>
5 <property stdset="1">
6 <name>name</name>
7 <cstring>NtpBase</cstring>
8 </property>
9 <property stdset="1">
10 <name>geometry</name>
11 <rect>
12 <x>0</x>
13 <y>0</y>
14 <width>317</width>
15 <height>411</height>
16 </rect>
17 </property>
18 <property stdset="1">
19 <name>caption</name>
20 <string>Network Time</string>
21 </property>
22 <property>
23 <name>layoutMargin</name>
24 </property>
25 <property>
26 <name>layoutSpacing</name>
27 </property>
28 <grid>
29 <property stdset="1">
30 <name>margin</name>
31 <number>2</number>
32 </property>
33 <property stdset="1">
34 <name>spacing</name>
35 <number>2</number>
36 </property>
37 <widget row="0" column="0" >
38 <class>QTabWidget</class>
39 <property stdset="1">
40 <name>name</name>
41 <cstring>TabWidgetMain</cstring>
42 </property>
43 <property>
44 <name>layoutMargin</name>
45 </property>
46 <property>
47 <name>layoutSpacing</name>
48 </property>
49 <widget>
50 <class>QWidget</class>
51 <property stdset="1">
52 <name>name</name>
53 <cstring>tabMain</cstring>
54 </property>
55 <attribute>
56 <name>title</name>
57 <string>Main</string>
58 </attribute>
59 <grid>
60 <property stdset="1">
61 <name>margin</name>
62 <number>2</number>
63 </property>
64 <property stdset="1">
65 <name>spacing</name>
66 <number>2</number>
67 </property>
68 <widget row="0" column="0" >
69 <class>QFrame</class>
70 <property stdset="1">
71 <name>name</name>
72 <cstring>FrameSystemTime</cstring>
73 </property>
74 </widget>
75 </grid>
76 </widget>
77 <widget>
78 <class>QWidget</class>
79 <property stdset="1">
80 <name>name</name>
81 <cstring>tabNtp</cstring>
82 </property>
83 <attribute>
84 <name>title</name>
85 <string>NTP</string>
86 </attribute>
87 <grid>
88 <property stdset="1">
89 <name>margin</name>
90 <number>1</number>
91 </property>
92 <property stdset="1">
93 <name>spacing</name>
94 <number>2</number>
95 </property>
96 <widget row="1" column="0" >
97 <class>QPushButton</class>
98 <property stdset="1">
99 <name>name</name>
100 <cstring>runNtp</cstring>
101 </property>
102 <property stdset="1">
103 <name>text</name>
104 <string>Get time from network</string>
105 </property>
106 </widget>
107 <widget row="0" column="0" >
108 <class>QWidget</class>
109 <property stdset="1">
110 <name>name</name>
111 <cstring>FrameNtp</cstring>
112 </property>
113 <property>
114 <name>layoutMargin</name>
115 </property>
116 <property>
117 <name>layoutSpacing</name>
118 </property>
119 <grid>
120 <property stdset="1">
121 <name>margin</name>
122 <number>2</number>
123 </property>
124 <property stdset="1">
125 <name>spacing</name>
126 <number>2</number>
127 </property>
128 <widget row="0" column="0" >
129 <class>QLayoutWidget</class>
130 <property stdset="1">
131 <name>name</name>
132 <cstring>Layout4</cstring>
133 </property>
134 <vbox>
135 <property stdset="1">
136 <name>margin</name>
137 <number>0</number>
138 </property>
139 <property stdset="1">
140 <name>spacing</name>
141 <number>6</number>
142 </property>
143 <widget>
144 <class>QLabel</class>
145 <property stdset="1">
146 <name>name</name>
147 <cstring>TextLabel1</cstring>
148 </property>
149 <property stdset="1">
150 <name>autoMask</name>
151 <bool>false</bool>
152 </property>
153 <property stdset="1">
154 <name>text</name>
155 <string>Start Time:</string>
156 </property>
157 </widget>
158 <widget>
159 <class>QLabel</class>
160 <property stdset="1">
161 <name>name</name>
162 <cstring>TextLabelStartTime</cstring>
163 </property>
164 <property stdset="1">
165 <name>text</name>
166 <string>nan</string>
167 </property>
168 </widget>
169 <widget>
170 <class>QLabel</class>
171 <property stdset="1">
172 <name>name</name>
173 <cstring>TextLabel3</cstring>
174 </property>
175 <property stdset="1">
176 <name>text</name>
177 <string>Time Shift:</string>
178 </property>
179 </widget>
180 <widget>
181 <class>QLabel</class>
182 <property stdset="1">
183 <name>name</name>
184 <cstring>TextLabelTimeShift</cstring>
185 </property>
186 <property stdset="1">
187 <name>text</name>
188 <string>nan</string>
189 </property>
190 </widget>
191 <widget>
192 <class>QLabel</class>
193 <property stdset="1">
194 <name>name</name>
195 <cstring>TextLabel5</cstring>
196 </property>
197 <property stdset="1">
198 <name>text</name>
199 <string>New Time:</string>
200 </property>
201 </widget>
202 <widget>
203 <class>QLabel</class>
204 <property stdset="1">
205 <name>name</name>
206 <cstring>TextLabelNewTime</cstring>
207 </property>
208 <property stdset="1">
209 <name>text</name>
210 <string>nan</string>
211 </property>
212 </widget>
213 <spacer>
214 <property>
215 <name>name</name>
216 <cstring>Spacer1</cstring>
217 </property>
218 <property stdset="1">
219 <name>orientation</name>
220 <enum>Vertical</enum>
221 </property>
222 <property stdset="1">
223 <name>sizeType</name>
224 <enum>Expanding</enum>
225 </property>
226 <property>
227 <name>sizeHint</name>
228 <size>
229 <width>20</width>
230 <height>20</height>
231 </size>
232 </property>
233 </spacer>
234 </vbox>
235 </widget>
236 <widget row="1" column="0" >
237 <class>QMultiLineEdit</class>
238 <property stdset="1">
239 <name>name</name>
240 <cstring>MultiLineEditntpOutPut</cstring>
241 </property>
242 <property stdset="1">
243 <name>font</name>
244 <font>
245 <pointsize>7</pointsize>
246 </font>
247 </property>
248 <property stdset="1">
249 <name>wordWrap</name>
250 <enum>WidgetWidth</enum>
251 </property>
252 <property stdset="1">
253 <name>text</name>
254 <string></string>
255 </property>
256 </widget>
257 </grid>
258 </widget>
259 </grid>
260 </widget>
261 <widget>
262 <class>QWidget</class>
263 <property stdset="1">
264 <name>name</name>
265 <cstring>tabPredict</cstring>
266 </property>
267 <attribute>
268 <name>title</name>
269 <string>Predict</string>
270 </attribute>
271 <grid>
272 <property stdset="1">
273 <name>margin</name>
274 <number>5</number>
275 </property>
276 <property stdset="1">
277 <name>spacing</name>
278 <number>6</number>
279 </property>
280 <widget row="0" column="0" >
281 <class>QTable</class>
282 <property stdset="1">
283 <name>name</name>
284 <cstring>TableLookups</cstring>
285 </property>
286 <property stdset="1">
287 <name>font</name>
288 <font>
289 <pointsize>8</pointsize>
290 </font>
291 </property>
292 <property stdset="1">
293 <name>numRows</name>
294 <number>2</number>
295 </property>
296 <property stdset="1">
297 <name>numCols</name>
298 <number>2</number>
299 </property>
300 </widget>
301 <widget row="1" column="0" >
302 <class>QLayoutWidget</class>
303 <property stdset="1">
304 <name>name</name>
305 <cstring>Layout9</cstring>
306 </property>
307 <grid>
308 <property stdset="1">
309 <name>margin</name>
310 <number>0</number>
311 </property>
312 <property stdset="1">
313 <name>spacing</name>
314 <number>6</number>
315 </property>
316 <widget row="0" column="1" >
317 <class>QLabel</class>
318 <property stdset="1">
319 <name>name</name>
320 <cstring>TextLabelShift</cstring>
321 </property>
322 <property stdset="1">
323 <name>text</name>
324 <string>nan</string>
325 </property>
326 </widget>
327 <widget row="1" column="0" >
328 <class>QLabel</class>
329 <property stdset="1">
330 <name>name</name>
331 <cstring>TextLabel4</cstring>
332 </property>
333 <property stdset="1">
334 <name>text</name>
335 <string>Esimated Shift:</string>
336 </property>
337 </widget>
338 <widget row="1" column="1" >
339 <class>QLabel</class>
340 <property stdset="1">
341 <name>name</name>
342 <cstring>TextLabelEstimatedShift</cstring>
343 </property>
344 <property stdset="1">
345 <name>text</name>
346 <string>nan</string>
347 </property>
348 </widget>
349 <widget row="2" column="0" >
350 <class>QLabel</class>
351 <property stdset="1">
352 <name>name</name>
353 <cstring>TextLabel3_2</cstring>
354 </property>
355 <property stdset="1">
356 <name>text</name>
357 <string>Predicted Time:</string>
358 </property>
359 </widget>
360 <widget row="0" column="0" >
361 <class>QLabel</class>
362 <property stdset="1">
363 <name>name</name>
364 <cstring>Mean_shift_label</cstring>
365 </property>
366 <property stdset="1">
367 <name>text</name>
368 <string>Mean shift:</string>
369 </property>
370 </widget>
371 <widget row="2" column="1" >
372 <class>QLabel</class>
373 <property stdset="1">
374 <name>name</name>
375 <cstring>TextLabelPredTime</cstring>
376 </property>
377 <property stdset="1">
378 <name>text</name>
379 <string>nan</string>
380 </property>
381 </widget>
382 </grid>
383 </widget>
384 <widget row="2" column="0" >
385 <class>QLayoutWidget</class>
386 <property stdset="1">
387 <name>name</name>
388 <cstring>Layout11</cstring>
389 </property>
390 <hbox>
391 <property stdset="1">
392 <name>margin</name>
393 <number>0</number>
394 </property>
395 <property stdset="1">
396 <name>spacing</name>
397 <number>6</number>
398 </property>
399 <widget>
400 <class>QPushButton</class>
401 <property stdset="1">
402 <name>name</name>
403 <cstring>PushButtonSetPredTime</cstring>
404 </property>
405 <property stdset="1">
406 <name>text</name>
407 <string>Set predicted time</string>
408 </property>
409 </widget>
410 <widget>
411 <class>QPushButton</class>
412 <property stdset="1">
413 <name>name</name>
414 <cstring>PushButtonPredict</cstring>
415 </property>
416 <property stdset="1">
417 <name>text</name>
418 <string>Predict time</string>
419 </property>
420 </widget>
421 </hbox>
422 </widget>
423 </grid>
424 </widget>
425 <widget>
426 <class>QWidget</class>
427 <property stdset="1">
428 <name>name</name>
429 <cstring>TabSettings</cstring>
430 </property>
431 <attribute>
432 <name>title</name>
433 <string>Settings</string>
434 </attribute>
435 <grid>
436 <property stdset="1">
437 <name>margin</name>
438 <number>2</number>
439 </property>
440 <property stdset="1">
441 <name>spacing</name>
442 <number>2</number>
443 </property>
444 <widget row="0" column="0" >
445 <class>QWidget</class>
446 <property stdset="1">
447 <name>name</name>
448 <cstring>FrameSettings</cstring>
449 </property>
450 <property>
451 <name>layoutMargin</name>
452 </property>
453 <property>
454 <name>layoutSpacing</name>
455 </property>
456 <vbox>
457 <property stdset="1">
458 <name>margin</name>
459 <number>11</number>
460 </property>
461 <property stdset="1">
462 <name>spacing</name>
463 <number>6</number>
464 </property>
465 <widget>
466 <class>QLayoutWidget</class>
467 <property stdset="1">
468 <name>name</name>
469 <cstring>Layout6</cstring>
470 </property>
471 <grid>
472 <property stdset="1">
473 <name>margin</name>
474 <number>0</number>
475 </property>
476 <property stdset="1">
477 <name>spacing</name>
478 <number>6</number>
479 </property>
480 <widget row="0" column="0" >
481 <class>QLabel</class>
482 <property stdset="1">
483 <name>name</name>
484 <cstring>TextLabel7_2</cstring>
485 </property>
486 <property stdset="1">
487 <name>text</name>
488 <string>Use</string>
489 </property>
490 </widget>
491 <widget row="0" column="2" >
492 <class>QLabel</class>
493 <property stdset="1">
494 <name>name</name>
495 <cstring>TextLabel2_2</cstring>
496 </property>
497 <property stdset="1">
498 <name>text</name>
499 <string>as</string>
500 </property>
501 </widget>
502 <widget row="1" column="0" rowspan="1" colspan="2" >
503 <class>QLabel</class>
504 <property stdset="1">
505 <name>name</name>
506 <cstring>TextLabel1_3</cstring>
507 </property>
508 <property stdset="1">
509 <name>text</name>
510 <string>NTP server to get the time from the network.</string>
511 </property>
512 <property stdset="1">
513 <name>alignment</name>
514 <set>WordBreak|AlignVCenter|AlignLeft</set>
515 </property>
516 <property>
517 <name>wordwrap</name>
518 </property>
519 </widget>
520 <widget row="0" column="1" >
521 <class>QComboBox</class>
522 <property stdset="1">
523 <name>name</name>
524 <cstring>ComboNtpSrv</cstring>
525 </property>
526 <property stdset="1">
527 <name>editable</name>
528 <bool>true</bool>
529 </property>
530 </widget>
531 </grid>
532 </widget>
533 <spacer>
534 <property>
535 <name>name</name>
536 <cstring>Spacer3</cstring>
537 </property>
538 <property stdset="1">
539 <name>orientation</name>
540 <enum>Vertical</enum>
541 </property>
542 <property stdset="1">
543 <name>sizeType</name>
544 <enum>Minimum</enum>
545 </property>
546 <property>
547 <name>sizeHint</name>
548 <size>
549 <width>20</width>
550 <height>20</height>
551 </size>
552 </property>
553 </spacer>
554 <widget>
555 <class>QCheckBox</class>
556 <property stdset="1">
557 <name>name</name>
558 <cstring>CheckBoxAdvSettings</cstring>
559 </property>
560 <property stdset="1">
561 <name>text</name>
562 <string>Advanced settings</string>
563 </property>
564 </widget>
565 <spacer>
566 <property>
567 <name>name</name>
568 <cstring>Spacer4</cstring>
569 </property>
570 <property stdset="1">
571 <name>orientation</name>
572 <enum>Vertical</enum>
573 </property>
574 <property stdset="1">
575 <name>sizeType</name>
576 <enum>Expanding</enum>
577 </property>
578 <property>
579 <name>sizeHint</name>
580 <size>
581 <width>20</width>
582 <height>20</height>
583 </size>
584 </property>
585 </spacer>
586 <widget>
587 <class>Line</class>
588 <property stdset="1">
589 <name>name</name>
590 <cstring>Line1</cstring>
591 </property>
592 <property stdset="1">
593 <name>orientation</name>
594 <enum>Horizontal</enum>
595 </property>
596 </widget>
597 <widget>
598 <class>QLayoutWidget</class>
599 <property stdset="1">
600 <name>name</name>
601 <cstring>Layout7_2</cstring>
602 </property>
603 <grid>
604 <property stdset="1">
605 <name>margin</name>
606 <number>0</number>
607 </property>
608 <property stdset="1">
609 <name>spacing</name>
610 <number>6</number>
611 </property>
612 <widget row="0" column="0" >
613 <class>QLabel</class>
614 <property stdset="1">
615 <name>name</name>
616 <cstring>TextLabel1_2_2</cstring>
617 </property>
618 <property stdset="1">
619 <name>sizePolicy</name>
620 <sizepolicy>
621 <hsizetype>1</hsizetype>
622 <vsizetype>1</vsizetype>
623 </sizepolicy>
624 </property>
625 <property stdset="1">
626 <name>text</name>
627 <string>Wait for </string>
628 </property>
629 </widget>
630 <widget row="0" column="2" >
631 <class>QLabel</class>
632 <property stdset="1">
633 <name>name</name>
634 <cstring>TextLabel2_3</cstring>
635 </property>
636 <property stdset="1">
637 <name>text</name>
638 <string>minutes until</string>
639 </property>
640 </widget>
641 <widget row="1" column="0" rowspan="1" colspan="3" >
642 <class>QLabel</class>
643 <property stdset="1">
644 <name>name</name>
645 <cstring>TextLabel3_3_2</cstring>
646 </property>
647 <property stdset="1">
648 <name>text</name>
649 <string>NTP tries to syncronises the clock with the network.</string>
650 </property>
651 <property stdset="1">
652 <name>alignment</name>
653 <set>WordBreak|AlignVCenter|AlignLeft</set>
654 </property>
655 <property>
656 <name>wordwrap</name>
657 </property>
658 </widget>
659 <widget row="0" column="1" >
660 <class>QSpinBox</class>
661 <property stdset="1">
662 <name>name</name>
663 <cstring>SpinBoxNtpDelay</cstring>
664 </property>
665 <property stdset="1">
666 <name>wrapping</name>
667 <bool>true</bool>
668 </property>
669 <property stdset="1">
670 <name>maxValue</name>
671 <number>9999999</number>
672 </property>
673 <property stdset="1">
674 <name>minValue</name>
675 <number>1</number>
676 </property>
677 <property stdset="1">
678 <name>value</name>
679 <number>1440</number>
680 </property>
681 </widget>
682 </grid>
683 </widget>
684 <widget>
685 <class>QLayoutWidget</class>
686 <property stdset="1">
687 <name>name</name>
688 <cstring>Layout7</cstring>
689 </property>
690 <grid>
691 <property stdset="1">
692 <name>margin</name>
693 <number>0</number>
694 </property>
695 <property stdset="1">
696 <name>spacing</name>
697 <number>6</number>
698 </property>
699 <widget row="0" column="0" >
700 <class>QLabel</class>
701 <property stdset="1">
702 <name>name</name>
703 <cstring>TextLabel1_2</cstring>
704 </property>
705 <property stdset="1">
706 <name>text</name>
707 <string>Insure a delay of</string>
708 </property>
709 </widget>
710 <widget row="0" column="2" >
711 <class>QLabel</class>
712 <property stdset="1">
713 <name>name</name>
714 <cstring>TextLabel2</cstring>
715 </property>
716 <property stdset="1">
717 <name>text</name>
718 <string>minutes until</string>
719 </property>
720 </widget>
721 <widget row="1" column="0" rowspan="1" colspan="3" >
722 <class>QLabel</class>
723 <property stdset="1">
724 <name>name</name>
725 <cstring>TextLabel3_3</cstring>
726 </property>
727 <property stdset="1">
728 <name>text</name>
729 <string>a new NTP lookup will be used to predict the time.</string>
730 </property>
731 <property stdset="1">
732 <name>alignment</name>
733 <set>WordBreak|AlignVCenter|AlignLeft</set>
734 </property>
735 <property>
736 <name>wordwrap</name>
737 </property>
738 </widget>
739 <widget row="0" column="1" >
740 <class>QSpinBox</class>
741 <property stdset="1">
742 <name>name</name>
743 <cstring>SpinBoxMinLookupDelay</cstring>
744 </property>
745 <property stdset="1">
746 <name>wrapping</name>
747 <bool>true</bool>
748 </property>
749 <property stdset="1">
750 <name>maxValue</name>
751 <number>9999999</number>
752 </property>
753 <property stdset="1">
754 <name>minValue</name>
755 <number>42</number>
756 </property>
757 <property stdset="1">
758 <name>value</name>
759 <number>720</number>
760 </property>
761 </widget>
762 </grid>
763 </widget>
764 </vbox>
765 </widget>
766 </grid>
767 </widget>
768 <widget>
769 <class>QWidget</class>
770 <property stdset="1">
771 <name>name</name>
772 <cstring>tabManualSetTime</cstring>
773 </property>
774 <attribute>
775 <name>title</name>
776 <string>Manual</string>
777 </attribute>
778 <vbox>
779 <property stdset="1">
780 <name>margin</name>
781 <number>11</number>
782 </property>
783 <property stdset="1">
784 <name>spacing</name>
785 <number>6</number>
786 </property>
787 <widget>
788 <class>QWidget</class>
789 <property stdset="1">
790 <name>name</name>
791 <cstring>FrameSetTime</cstring>
792 </property>
793 <property stdset="1">
794 <name>sizePolicy</name>
795 <sizepolicy>
796 <hsizetype>5</hsizetype>
797 <vsizetype>3</vsizetype>
798 </sizepolicy>
799 </property>
800 </widget>
801 <widget>
802 <class>QPushButton</class>
803 <property stdset="1">
804 <name>name</name>
805 <cstring>PushButtonSetManualTime</cstring>
806 </property>
807 <property stdset="1">
808 <name>text</name>
809 <string>Set time</string>
810 </property>
811 </widget>
812 <spacer>
813 <property>
814 <name>name</name>
815 <cstring>Spacer4_2</cstring>
816 </property>
817 <property stdset="1">
818 <name>orientation</name>
819 <enum>Vertical</enum>
820 </property>
821 <property stdset="1">
822 <name>sizeType</name>
823 <enum>Expanding</enum>
824 </property>
825 <property>
826 <name>sizeHint</name>
827 <size>
828 <width>20</width>
829 <height>20</height>
830 </size>
831 </property>
832 </spacer>
833 </vbox>
834 </widget>
835 </widget>
836 </grid>
837</widget>
838</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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "ntptabwidget.h"
30
31#include <qpe/resource.h>
32
33#include <qlabel.h>
34#include <qlayout.h>
35#include <qmultilineedit.h>
36#include <qpushbutton.h>
37#include <qscrollview.h>
38
39NTPTabWidget::NTPTabWidget( QWidget *parent )
40 : QWidget( parent, 0x0, 0 )
41{
42 QVBoxLayout *tmpvb = new QVBoxLayout( this );
43 QScrollView *sv = new QScrollView( this );
44 tmpvb->addWidget( sv, 0, 0 );
45 sv->setResizePolicy( QScrollView::AutoOneFit );
46 sv->setFrameStyle( QFrame::NoFrame );
47 QWidget *container = new QWidget( sv->viewport() );
48 sv->addChild( container );
49
50 QGridLayout *layout = new QGridLayout( container );
51 layout->setMargin( 2 );
52 layout->setSpacing( 4 );
53
54 // Start time
55 layout->addWidget( new QLabel( tr( "Start time" ), container ), 0, 0 );
56 lblStartTime = new QLabel( tr( "n/a" ), container );
57 layout->addWidget( lblStartTime, 0, 1 );
58
59 // Time shift
60 layout->addWidget( new QLabel( tr( "Time shift" ), container ), 1, 0 );
61 lblTimeShift = new QLabel( tr( "n/a" ), container );
62 layout->addWidget( lblTimeShift, 1, 1 );
63
64 // New time
65 layout->addWidget( new QLabel( tr( "New time" ), container ), 2, 0 );
66 lblNewTime = new QLabel( tr( "n/a" ), container );
67 layout->addWidget( lblNewTime, 2, 1 );
68
69 // NTP output display
70 mleNtpOutput = new QMultiLineEdit( container );
71 QFont font( mleNtpOutput->font() );
72 font.setPointSize( 7 );
73 mleNtpOutput->setFont( font );
74 mleNtpOutput->setWordWrap( QMultiLineEdit::WidgetWidth );
75 layout->addMultiCellWidget( mleNtpOutput, 3, 3, 0, 1 );
76
77 // Set NTP time button
78 QPushButton *pb = new QPushButton( Resource::loadPixmap( "netsystemtime/ntptab" ),
79 tr( "Get time from the network" ), container );
80 connect( pb, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) );
81 layout->addMultiCellWidget( pb, 4, 4, 0, 1 );
82}
83
84NTPTabWidget::~NTPTabWidget()
85{
86}
87
88void NTPTabWidget::setStartTime( const QString &str )
89{
90 lblStartTime->setText( str );
91}
92
93void NTPTabWidget::setTimeShift( const QString &str )
94{
95 lblTimeShift->setText( str );
96}
97
98void NTPTabWidget::setNewTime( const QString &str )
99{
100 lblNewTime->setText( str );
101}
102
103void NTPTabWidget::addNtpOutput( const QString &str )
104{
105 mleNtpOutput->append( str );
106 mleNtpOutput->setCursorPosition( mleNtpOutput->numLines() + 1, 0, FALSE );
107}
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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef NTPTABWIDGET_H
30#define NTPTABWIDGET_H
31
32#include <qwidget.h>
33
34class QLabel;
35class QMultiLineEdit;
36
37class NTPTabWidget : public QWidget
38{
39 Q_OBJECT
40
41public:
42 NTPTabWidget( QWidget * = 0x0 );
43 ~NTPTabWidget();
44
45 void setStartTime( const QString & );
46 void setTimeShift( const QString & );
47 void setNewTime( const QString & );
48 void addNtpOutput( const QString & );
49
50private:
51 QLabel *lblStartTime;
52 QLabel *lblTimeShift;
53 QLabel *lblNewTime;
54 QMultiLineEdit *mleNtpOutput;
55
56signals:
57 void getNTPTime();
58};
59
60#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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "predicttabwidget.h"
30
31#include <qpe/config.h>
32#include <qpe/timeconversion.h>
33
34#include <qlabel.h>
35#include <qlayout.h>
36#include <qpushbutton.h>
37#include <qscrollview.h>
38#include <qtable.h>
39
40#include <stdlib.h>
41
42PredictTabWidget::PredictTabWidget( QWidget *parent )
43 : QWidget( parent, 0x0, 0 )
44{
45/*
46 QVBoxLayout *tmpvb = new QVBoxLayout( this );
47 QScrollView *sv = new QScrollView( this );
48 tmpvb->addWidget( sv, 0, 0 );
49 sv->setResizePolicy( QScrollView::AutoOneFit );
50 sv->setFrameStyle( QFrame::NoFrame );
51 QWidget *container = new QWidget( sv->viewport() );
52 sv->addChild( container );
53*/
54
55 QGridLayout *layout = new QGridLayout( this );
56 layout->setMargin( 2 );
57 layout->setSpacing( 4 );
58
59 // Predicted time drift
60 layout->addWidget( new QLabel( tr( "Predicted time drift" ), this ), 0, 0 );
61 lblDrift = new QLabel( tr( "n/a" ), this );
62 layout->addWidget( lblDrift, 0, 1 );
63
64 // Estimated time difference
65 layout->addWidget( new QLabel( tr( "Estimated shift" ), this ), 1, 0 );
66 lblDiff = new QLabel( tr( "n/a" ), this );
67 layout->addWidget( lblDiff, 1, 1 );
68
69 // Predicted time
70 layout->addWidget( new QLabel( tr( "Predicted time" ), this ), 2, 0 );
71 lblPredicted = new QLabel( tr( "n/a" ), this );
72 layout->addWidget( lblPredicted, 2, 1 );
73
74 // Prediction table
75 tblLookups = new QTable( 2, 3, this );
76 QFont font( tblLookups->font() );
77 font.setPointSize( 7 );
78 tblLookups->setFont( font );
79 tblLookups->horizontalHeader()->setLabel( 0, tr( "Shift [s/h]" ) );
80 tblLookups->horizontalHeader()->setLabel( 1, tr( "Last [h]" ) );
81 tblLookups->horizontalHeader()->setLabel( 2, tr( "Offset [s]" ) );
82 tblLookups->setColumnWidth( 0, 78 );
83 tblLookups->setColumnWidth( 1, 50 );
84 tblLookups->setColumnWidth( 2, 50 );
85 tblLookups->setMinimumHeight( 50 );
86 tblLookups->setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Maximum ) );
87 layout->addMultiCellWidget( tblLookups, 3, 3, 0, 1 );
88
89 // Predict time button
90 QPushButton *pb = new QPushButton( tr( "Predict time" ), this );
91 connect( pb, SIGNAL(clicked()), this, SLOT(slotPredictTime()) );
92 layout->addWidget( pb, 4, 0 );
93
94 // Set predicted time button
95 pb = new QPushButton( tr( "Set predicted time" ), this );
96 connect( pb, SIGNAL(clicked()), this, SLOT(slotSetPredictedTime()) );
97 layout->addWidget( pb, 4, 1 );
98
99 // Initialize values
100 Config config( "ntp" );
101 config.setGroup( "lookups" );
102 int lookupCount = config.readNumEntry( "count", 0 );
103 float last, shift, shiftPerSec;
104 tblLookups->setNumRows( lookupCount );
105 int cw = tblLookups->width() / 4;
106 cw = 50;
107 tblLookups->sortColumn( 0, FALSE, TRUE );
108 _shiftPerSec = 0;
109 QString grpname;
110 for ( int i=0; i < lookupCount; i++ )
111 {
112 grpname = "lookup_";
113 grpname.append( QString::number( i ) );
114 config.setGroup( grpname );
115 last = config.readEntry( "secsSinceLast", 0 ).toFloat();
116 shift = QString( config.readEntry( "timeShift", 0 ) ).toFloat();
117 shiftPerSec = shift / last;
118 _shiftPerSec += shiftPerSec;
119 tblLookups->setText( i, 0, QString::number( shiftPerSec * 60 * 60 ) );
120 tblLookups->setText( i, 2, QString::number( shift ) );
121 tblLookups->setText( i, 1, QString::number( last / ( 60 * 60 ) ) );
122 }
123 _shiftPerSec /= lookupCount;
124 QString drift = QString::number( _shiftPerSec * 60 * 60);
125 drift.append( tr( " s/h" ) );
126 lblDrift->setText( drift );
127
128 Config lconfig( "locale" );
129 lconfig.setGroup( "Location" );
130 tz = lconfig.readEntry( "Timezone", "America/New_York" );
131}
132
133PredictTabWidget::~PredictTabWidget()
134{
135}
136
137void PredictTabWidget::setShiftPerSec( int i )
138{
139 _shiftPerSec += i;
140}
141
142void PredictTabWidget::slotTZChanged( const QString &newtz )
143{
144 tz = newtz;
145}
146
147void PredictTabWidget::slotPredictTime()
148{
149 Config config( "ntp" );
150 config.setGroup( "lookups" );
151 int lastTime = config.readNumEntry( "time", 0 );
152 config.writeEntry( "lastNtp", TRUE );
153 setenv( "TZ", tz, 1 );
154 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
155 int corr = int( ( now - lastTime ) * _shiftPerSec );
156 QString diff = QString::number( corr );
157 diff.append( tr( " seconds" ) );
158 lblDiff->setText( diff );
159 predictedTime = QDateTime::currentDateTime().addSecs( corr );
160 lblPredicted->setText( predictedTime.toString() );
161}
162
163void PredictTabWidget::slotSetPredictedTime()
164{
165 slotPredictTime();
166 emit setTime( predictedTime );
167}
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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef PREDICTTABWIDGET_H
30#define PREDICTTABWIDGET_H
31
32#include <qdatetime.h>
33#include <qstring.h>
34#include <qwidget.h>
35
36class QLabel;
37class QTable;
38
39class PredictTabWidget : public QWidget
40{
41 Q_OBJECT
42
43public:
44 PredictTabWidget( QWidget * = 0x0 );
45 ~PredictTabWidget();
46
47 void setShiftPerSec( int );
48
49private:
50 QTable *tblLookups;
51 QLabel *lblDrift;
52 QLabel *lblDiff;
53 QLabel *lblPredicted;
54
55 float _shiftPerSec;
56 QString tz;
57 QDateTime predictedTime;
58
59signals:
60 void setTime( const QDateTime & );
61
62public slots:
63 void slotTZChanged( const QString & );
64 void slotPredictTime();
65 void slotSetPredictedTime();
66};
67
68#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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21#include "settime.h"
22
23#include <qpe/alarmserver.h>
24#include <qpe/qpeapplication.h>
25#include <qpe/config.h>
26#include <qpe/datebookdb.h>
27#include <qpe/datebookmonth.h>
28#include <qpe/global.h>
29#include <qpe/resource.h>
30#include <qpe/timeconversion.h>
31#include <qpe/tzselect.h>
32#include <qpe/timestring.h>
33#include <qpe/qpedialog.h>
34#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
35#include <qpe/qcopenvelope_qws.h>
36#endif
37
38#include <qtimer.h>
39#include <qbuttongroup.h>
40#include <qcheckbox.h>
41#include <qlabel.h>
42#include <qlayout.h>
43#include <qradiobutton.h>
44#include <qspinbox.h>
45#include <qtoolbutton.h>
46#include <qwindowsystem_qws.h>
47#include <qcombobox.h>
48
49#include <sys/time.h>
50#include <time.h>
51#include <stdlib.h>
52#include <stdio.h>
53
54
55SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f )
56 : NtpBase( parent, name, true, f )
57{
58 setCaption( tr("System Time") );
59 _oldTimeZone="";
60 QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 );
61
62// TextLabelMainPredTime = new QLabel( FrameSystemTime );
63// vb->addWidget( TextLabelMainPredTime, 1, 0 );
64
65 timeButton = new SetTime( FrameSystemTime );
66 vb->addWidget( timeButton );
67
68 QHBoxLayout *db = new QHBoxLayout( vb );
69 QLabel *dateLabel = new QLabel( tr("Date"), FrameSystemTime );
70 db->addWidget( dateLabel, 1 );
71 dateButton = new DateButton( TRUE, FrameSystemTime );
72 db->addWidget( dateButton, 2 );
73
74 ButtonSetTime = new QPushButton( FrameSystemTime );
75 vb->addWidget( ButtonSetTime, 1, 0 );
76
77 QFrame *hline = new QFrame( FrameSystemTime );
78 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
79 vb->addWidget( hline );
80
81 QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" );
82
83 QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" );
84 lblZone->setMaximumSize( lblZone->sizeHint() );
85 hb->addWidget( lblZone );
86
87 tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" );
88 tz->setMinimumSize( tz->sizeHint() );
89 hb->addWidget( tz );
90
91 hline = new QFrame( FrameSystemTime );
92 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
93 vb->addWidget( hline );
94
95 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
96 vb->addItem( spacer );
97
98 Config config("qpe");
99 config.setGroup( "Time" );
100
101 QHBoxLayout *hb1 = new QHBoxLayout( vb );
102
103 QLabel *l = new QLabel( tr("Time format"), FrameSystemTime );
104 hb1->addWidget( l, 1 );
105
106
107 ampmCombo = new QComboBox( FrameSystemTime );
108 ampmCombo->insertItem( tr("24 hour"), 0 );
109 ampmCombo->insertItem( tr("12 hour"), 1 );
110 hb1->addWidget( ampmCombo, 2 );
111
112 int show12hr = config.readBoolEntry("AMPM") ? 1 : 0;
113 ampmCombo->setCurrentItem( show12hr );
114 timeButton->show12hourTime( show12hr );
115
116 connect(ampmCombo, SIGNAL(activated(int)),
117 timeButton, SLOT(show12hourTime(int)));
118
119
120
121 QHBoxLayout *hb2 = new QHBoxLayout( vb );
122 l = new QLabel( tr("Weeks start on" ), FrameSystemTime );
123 //l->setAlignment( AlignRight | AlignVCenter );
124 hb2->addWidget( l, 1 );
125
126 weekStartCombo = new QComboBox( FrameSystemTime );
127 weekStartCombo->insertItem( tr("Sunday"), 0 );
128 weekStartCombo->insertItem( tr("Monday"), 1 );
129
130 hb2->addWidget( weekStartCombo, 2 );
131 int startMonday = config.readBoolEntry("MONDAY") ? 1 : 0;
132 dateButton->setWeekStartsMonday( startMonday );
133 weekStartCombo->setCurrentItem( startMonday );
134
135 connect( weekStartCombo, SIGNAL( activated(int)),
136 dateButton, SLOT(setWeekStartsMonday(int)));
137
138
139 QHBoxLayout *hb3 = new QHBoxLayout( vb );
140 l = new QLabel( tr("Date format" ), FrameSystemTime );
141 hb3->addWidget( l, 1 );
142 dateFormatCombo = new QComboBox( FrameSystemTime );
143 hb3->addWidget( dateFormatCombo, 2 );
144
145 config.setGroup( "Date" );
146 DateFormat df(QChar(config.readEntry("Separator", "/")[0]),
147 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
148 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
149
150 int currentdf = 0;
151 date_formats[0] = DateFormat('/', DateFormat::MonthDayYear);
152 dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) );
153 date_formats[1] = DateFormat('.', DateFormat::DayMonthYear);
154 if (df == date_formats[1])
155 currentdf = 1;
156 dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) );
157 date_formats[2] = DateFormat('-', DateFormat::YearMonthDay,
158 DateFormat::DayMonthYear);
159 if (df == date_formats[2])
160 currentdf = 2;
161 dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601
162 date_formats[3] = DateFormat('/', DateFormat::DayMonthYear);
163 if (df == date_formats[3])
164 currentdf = 3;
165 dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) );
166
167 dateFormatCombo->setCurrentItem( currentdf );
168 dateButton->setDateFormat( df );
169
170 connect( dateFormatCombo, SIGNAL( activated(int)),
171 SLOT(formatChanged(int)));
172
173 QHBoxLayout *hb4 = new QHBoxLayout( vb );
174 l = new QLabel( tr("Applet format" ), FrameSystemTime );
175 hb4->addWidget( l, 1 );
176
177 clockAppletCombo = new QComboBox( FrameSystemTime );
178 clockAppletCombo->insertItem( tr("hh:mm"), 0 );
179 clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 );
180 clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 );
181
182 hb4->addWidget( clockAppletCombo, 2 );
183 int clockApplet = config.readNumEntry("ClockApplet",0);
184 clockAppletCombo->setCurrentItem( clockApplet );
185
186 vb->addStretch( 0 );
187
188// hline = new QFrame( FrameSystemTime );
189// hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
190// vb->addWidget( hline );
191//
192// ButtonSetTime = new QPushButton( FrameSystemTime );
193// vb->addWidget( ButtonSetTime, 1, 0 );
194
195
196 QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ),
197 timeButton, SLOT( slotTzChange( const QString& ) ) );
198 QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ),
199 SLOT( tzChange( const QString& ) ) );
200
201// QObject::connect( weekStartCombo, SIGNAL( activated ( int )),
202 // SLOT(updateSystem(int ) ));
203// QObject::connect( ampmCombo, SIGNAL( activated ( int )),
204 // SLOT(updateSystem(int ) ));
205// QObject::connect( dateFormatCombo, SIGNAL( activated ( int )),
206 // SLOT(updateSystem(int ) ));
207// QObject::connect( clockAppletCombo, SIGNAL( activated ( int )),
208 // SLOT(updateSystem(int ) ));
209}
210
211SetDateTime::~SetDateTime()
212{
213}
214
215void SetDateTime::writeSettings()
216{
217 Config config("qpe");
218 config.setGroup( "Time" );
219 config.writeEntry( "AMPM", ampmCombo->currentItem() );
220 config.writeEntry( "MONDAY", weekStartCombo->currentItem() );
221 config.setGroup( "Date" );
222 DateFormat df = date_formats[dateFormatCombo->currentItem()];
223 config.writeEntry( "Separator", QString(df.separator()));
224 config.writeEntry( "ShortOrder", df.shortOrder());
225 config.writeEntry( "LongOrder", df.longOrder());
226 config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() );
227
228 Config lconfig("locale");
229 lconfig.setGroup( "Location" );
230 lconfig.writeEntry( "Timezone", tz->currentZone() );
231
232}
233
234void SetDateTime::commitTime()
235{
236 Config cfg("ntp",Config::User);
237 cfg.setGroup("lookups");
238 cfg.writeEntry("lastNtp",false);
239 tz->setFocus();
240 // Need to process the QCOP event generated above before proceeding
241 qApp->processEvents();
242
243 // before we progress further, set our TZ!
244 setenv( "TZ", tz->currentZone(), 1 );
245 // now set the time...
246 QDateTime dt( dateButton->date(), timeButton->time() );
247
248 if ( dt.isValid() ) setTime(dt);
249}
250
251void SetDateTime::setTime(QDateTime dt)
252{
253 // really turn off the screensaver before doing anything
254 {
255 // Needs to be encased in { } so that it deconstructs and sends
256 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
257 disableScreenSaver << 0 << 0 << 0;
258 }
259 Config cfg("ntp",Config::User);
260 cfg.setGroup("correction");
261 int t = TimeConversion::toUTC(dt);
262 struct timeval myTv;
263 myTv.tv_sec = t;
264 cfg.writeEntry("time", t );
265 myTv.tv_usec = 0;
266
267 if ( myTv.tv_sec != -1 )
268 ::settimeofday( &myTv, 0 );
269 Global::writeHWClock();
270 // since time has changed quickly load in the datebookdb
271 // to allow the alarm server to get a better grip on itself
272 // (example re-trigger alarms for when we travel back in time)
273 DateBookDB db;
274 //QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" );
275 //timeApplet << "";
276 // Restore screensaver
277 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
278 enableScreenSaver << -1 << -1 << -1;
279}
280
281void SetDateTime::updateSystem()
282{
283 // really turn off the screensaver before doing anything
284 {
285 // Needs to be encased in { } so that it deconstructs and sends
286 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
287 disableScreenSaver << 0 << 0 << 0;
288 }
289 qDebug("SetDateTime::updateSystem()");
290 writeSettings();
291
292 // set the timezone for everyone else...
293 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
294 setTimeZone << tz->currentZone();
295
296 // AM/PM setting and notify time changed
297 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
298 setClock << ampmCombo->currentItem();
299
300 // Notify everyone what day we prefer to start the week on.
301 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
302 setWeek << weekStartCombo->currentItem();
303
304 // Notify everyone what date format to use
305 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
306 setDateFormat << date_formats[dateFormatCombo->currentItem()];
307
308 // Restore screensaver
309 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
310 enableScreenSaver << -1 << -1 << -1;
311 // since time has changed quickly load in the datebookdb
312 // to allow the alarm server to get a better grip on itself
313 // (example re-trigger alarms for when we travel back in time)
314 DateBookDB db;
315
316}
317
318void SetDateTime::tzChange( const QString &tz )
319{
320 // set the TZ get the time and leave gracefully...
321 _oldTimeZone = getenv( "TZ" );
322 setenv( "TZ", tz, 1 );
323
324 QDate d = QDate::currentDate();
325 // reset the time.
326 if ( !_oldTimeZone.isNull() ) {
327 setenv( "TZ", _oldTimeZone, 1 );
328 }
329 dateButton->setDate( d );
330 updateSystem();
331}
332
333void SetDateTime::formatChanged(int i)
334{
335 dateButton->setDateFormat(date_formats[i]);
336}
337
338static const int ValueAM = 0;
339static const int ValuePM = 1;
340
341
342
343SetTime::SetTime( QWidget *parent, const char *name )
344 : QWidget( parent, name )
345{
346 clock = new QTimer(this, "clock" );
347 connect(clock, SIGNAL( timeout() ), SLOT(slotClockTick()) );
348 clock->start( 1000 * 60 );
349
350 use12hourTime = FALSE;
351
352 _time = QDateTime::currentDateTime();
353 hour = _time.time().hour();
354 minute = _time.time().minute();
355
356 QHBoxLayout *hb2 = new QHBoxLayout( this );
357 hb2->setSpacing( 3 );
358
359 QLabel *l = new QLabel( tr("Hour"), this );
360 // l->setAlignment( AlignRight | AlignVCenter );
361 hb2->addWidget( l );
362
363 sbHour = new QSpinBox( this );
364 sbHour->setMinimumWidth( 30 );
365 if(use12hourTime) {
366 sbHour->setMinValue(1);
367 sbHour->setMaxValue( 12 );
368 int show_hour = hour;
369 if (hour > 12)
370 show_hour -= 12;
371 if (show_hour == 0)
372 show_hour = 12;
373
374 sbHour->setValue( show_hour );
375 } else {
376 sbHour->setMinValue( 0 );
377 sbHour->setMaxValue( 23 );
378 sbHour->setValue( hour );
379 }
380 sbHour->setWrapping(TRUE);
381 connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) );
382 hb2->addWidget( sbHour );
383
384 hb2->addStretch( 1 );
385
386 l = new QLabel( tr("Minute"), this );
387 //l->setAlignment( AlignRight | AlignVCenter );
388 hb2->addWidget( l );
389
390 sbMin = new QSpinBox( this );
391 sbMin->setMinValue( 0 );
392 sbMin->setMaxValue( 59 );
393 sbMin->setWrapping(TRUE);
394 sbMin->setValue( minute );
395 sbMin->setMinimumWidth( 30 );
396 connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) );
397 hb2->addWidget( sbMin );
398
399 hb2->addStretch( 1 );
400
401 ampm = new QComboBox( this );
402 ampm->insertItem( tr("AM"), ValueAM );
403 ampm->insertItem( tr("PM"), ValuePM );
404 connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) );
405 hb2->addWidget( ampm );
406
407 hb2->addStretch( 1 );
408
409}
410
411QTime SetTime::time() const
412{
413 return QTime( hour, minute, 0 );
414}
415
416void SetTime::hourChanged( int value )
417{
418 if(use12hourTime) {
419 int realhour = value;
420 if (realhour == 12)
421 realhour = 0;
422 if (ampm->currentItem() == ValuePM )
423 realhour += 12;
424 hour = realhour;
425 } else
426 hour = value;
427}
428
429void SetTime::minuteChanged( int value )
430{
431 minute = value;
432}
433
434void SetTime::show12hourTime( int on )
435{
436 use12hourTime = on;
437 ampm->setEnabled(on);
438
439 int show_hour = hour;
440 if ( on ) {
441 /* this might change the value of hour */
442 sbHour->setMinValue(1);
443 sbHour->setMaxValue( 12 );
444
445 /* so use one we saved earlier */
446 if (show_hour >= 12) {
447 show_hour -= 12;
448 ampm->setCurrentItem( ValuePM );
449 } else {
450 ampm->setCurrentItem( ValueAM );
451 }
452 if (show_hour == 0)
453 show_hour = 12;
454
455 } else {
456 sbHour->setMinValue( 0 );
457 sbHour->setMaxValue( 23 );
458 }
459
460
461 sbHour->setValue( show_hour );
462}
463
464void SetTime::checkedPM( int c )
465{
466 int show_hour = sbHour->value();
467 if (show_hour == 12)
468 show_hour = 0;
469
470 if ( c == ValuePM )
471 show_hour += 12;
472
473 hour = show_hour;
474}
475
476void SetTime::slotTzChange( const QString &tz )
477{
478 // set the TZ get the time and leave gracefully...
479 QString strSave;
480 strSave = getenv( "TZ" );
481 setenv( "TZ", tz, 1 );
482
483 QTime t = QTime::currentTime();
484 // reset the time.
485 if ( !strSave.isNull() ) {
486 setenv( "TZ", strSave, 1 );
487 }
488
489 // just set the spinboxes and let it propage through
490 if(use12hourTime) {
491 int show_hour = t.hour();
492 if (t.hour() >= 12) {
493 show_hour -= 12;
494 ampm->setCurrentItem( ValuePM );
495 } else {
496 ampm->setCurrentItem( ValueAM );
497 }
498 if (show_hour == 0)
499 show_hour = 12;
500 sbHour->setValue( show_hour );
501 } else {
502 sbHour->setValue( t.hour() );
503 }
504 sbMin->setValue( t.minute() );
505}
506
507void SetTime::setTime( QDateTime dt )
508{
509 _time = dt;
510 QTime t = dt.time();
511 // just set the spinboxes and let it propage through
512 if(use12hourTime) {
513 int show_hour = t.hour();
514 if (t.hour() >= 12) {
515 show_hour -= 12;
516 ampm->setCurrentItem( ValuePM );
517 } else {
518 ampm->setCurrentItem( ValueAM );
519 }
520 if (show_hour == 0)
521 show_hour = 12;
522 sbHour->setValue( show_hour );
523 } else {
524 sbHour->setValue( t.hour() );
525 }
526 sbMin->setValue( t.minute() );
527}
528
529void SetTime::slotClockTick()
530{
531 setTime( _time.addSecs(60) );
532 qDebug("SetTime::slotClockTick %s",_time.toString().latin1());
533}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#ifndef SYSTEM_TIME_H
21#define SYSTEM_TIME_H
22
23
24#include <qdatetime.h>
25#include <qdialog.h>
26
27#include <qpe/timestring.h>
28#include "ntpbase.h"
29
30class QToolButton;
31class QSpinBox;
32class QLabel;
33class TimeZoneSelector;
34class DateBookMonth;
35class QComboBox;
36
37class SetTime : public QWidget
38{
39 Q_OBJECT
40public:
41 SetTime( QWidget *parent=0, const char *name=0 );
42
43 QTime time() const;
44 void setTime( QDateTime );
45
46public slots:
47 void slotTzChange( const QString& tz );
48 void show12hourTime( int );
49
50protected slots:
51 void slotClockTick();
52 void hourChanged( int value );
53 void minuteChanged( int value );
54
55 void checkedPM( int );
56
57protected:
58 int hour;
59 int minute;
60 bool use12hourTime;
61 QDateTime _time;
62 QTimer *clock;
63 QComboBox *ampm;
64 QSpinBox *sbHour;
65 QSpinBox *sbMin;
66};
67
68class DateButton;
69
70class SetDateTime : public NtpBase
71{
72 Q_OBJECT
73public:
74 SetDateTime( QWidget *parent=0, const char *name=0, WFlags f=0 );
75 ~SetDateTime();
76
77protected slots:
78 void commitTime();
79 void tzChange( const QString &tz );
80 void formatChanged(int);
81 void updateSystem();
82
83protected:
84 void setTime(QDateTime dt);
85 void writeSettings();
86
87 SetTime *timeButton;
88 DateButton *dateButton;
89 TimeZoneSelector *tz;
90 QString _oldTimeZone;
91 QComboBox *weekStartCombo;
92 QComboBox *ampmCombo;
93 QComboBox *dateFormatCombo;
94 QComboBox *clockAppletCombo;
95 QPushButton *ButtonSetTime;
96
97 DateFormat date_formats[4];
98};
99
100
101#endif
102
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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "settingstabwidget.h"
30
31#include <qpe/config.h>
32#include <qpe/qpeapplication.h>
33
34#include <qcheckbox.h>
35#include <qcombobox.h>
36#include <qlabel.h>
37#include <qlayout.h>
38#include <qscrollview.h>
39#include <qspinbox.h>
40
41SettingsTabWidget::SettingsTabWidget( QWidget *parent )
42 : QWidget( parent, 0x0, 0 )
43{
44 QVBoxLayout *tmpvb = new QVBoxLayout( this );
45 QScrollView *sv = new QScrollView( this );
46 tmpvb->addWidget( sv, 0, 0 );
47 sv->setResizePolicy( QScrollView::AutoOneFit );
48 sv->setFrameStyle( QFrame::NoFrame );
49 QWidget *container = new QWidget( sv->viewport() );
50 sv->addChild( container );
51
52 QGridLayout *layout = new QGridLayout( container );
53 layout->setMargin( 2 );
54 layout->setSpacing( 4 );
55
56 // Time server selector
57 layout->addWidget( new QLabel( tr( "Time server" ), container ), 0, 0 );
58 cbTimeServer = new QComboBox( TRUE, container );
59 layout->addMultiCellWidget( cbTimeServer, 1, 1, 0, 1 );
60
61 // Lookup delay selector
62 layout->addWidget( new QLabel( tr( "minutes between time updates" ), container ), 2, 1 );
63 sbNtpDelay = new QSpinBox( 1, 9999999, 1, container );
64 sbNtpDelay->setWrapping( TRUE );
65 sbNtpDelay->setMaximumWidth( 50 );
66 connect( sbNtpDelay, SIGNAL(valueChanged(int)), this, SIGNAL(ntpDelayChanged(int)) );
67 layout->addWidget( sbNtpDelay, 2, 0 );
68
69 // Prediction delay selector
70 layout->addWidget( new QLabel( tr( "minutes between prediction updates" ), container ), 3, 1 );
71 sbPredictDelay = new QSpinBox( 42, 9999999, 1, container );
72 sbPredictDelay->setWrapping( TRUE );
73 sbPredictDelay->setMaximumWidth( 50 );
74 layout->addWidget( sbPredictDelay, 3, 0 );
75
76 // Space filler
77 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 4, 0 );
78
79 // Display time server information selector
80 chNtpTab = new QCheckBox( tr( "Display time server information" ), container );
81 connect( chNtpTab, SIGNAL( toggled( bool ) ), this, SIGNAL( displayNTPTab( bool ) ) );
82 layout->addMultiCellWidget( chNtpTab, 5, 5, 0, 1 );
83
84 // Display time prediction information selector
85 chPredictTab = new QCheckBox( tr( "Display time prediction information" ), container );
86 connect( chPredictTab, SIGNAL( toggled( bool ) ), this, SIGNAL( displayPredictTab( bool ) ) );
87 layout->addMultiCellWidget( chPredictTab, 6, 6, 0, 1 );
88
89 // Space filler
90 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 );
91
92 // Initialize values
93 QString ntpSrvsFile = QPEApplication::qpeDir();
94 ntpSrvsFile.append( "etc/ntpservers" );
95 Config ntpSrvs( ntpSrvsFile, Config::File );
96 ntpSrvs.setGroup( "servers" );
97 int srvCount = ntpSrvs.readNumEntry( "count", 0 );
98 for ( int i = 0; i < srvCount; i++ )
99 {
100 ntpSrvs.setGroup( QString::number( i ) );
101 cbTimeServer->insertItem( ntpSrvs.readEntry( "name" ) );
102 }
103 if ( srvCount==0 )
104 cbTimeServer->insertItem( "time.fu-berlin.de" );
105
106 Config config( "ntp" );
107 config.setGroup( "settings" );
108 sbPredictDelay->setValue( config.readNumEntry( "minLookupDiff", 720 ) );
109 sbNtpDelay->setValue( config.readNumEntry( "ntpRefreshFreq", 1440 ) );
110 cbTimeServer->setCurrentItem( config.readNumEntry( "ntpServer", 0 ) );
111 chNtpTab->setChecked( config.readBoolEntry( "displayNtpTab", FALSE ) );
112 chPredictTab->setChecked( config.readBoolEntry( "displayPredictTab", FALSE ) );
113}
114
115SettingsTabWidget::~SettingsTabWidget()
116{
117}
118
119void SettingsTabWidget::saveSettings()
120{
121 int srvCount = cbTimeServer->count();
122 bool serversChanged = TRUE;
123 int curSrv = cbTimeServer->currentItem();
124 QString edit = cbTimeServer->currentText();
125 for ( int i = 0; i < srvCount; i++ )
126 {
127 if ( edit == cbTimeServer->text( i ) )
128 serversChanged = FALSE;
129 }
130 if ( serversChanged )
131 {
132 QString ntpSrvsFile = QPEApplication::qpeDir();
133 ntpSrvsFile.append( "etc/ntpservers" );
134 Config ntpSrvs( ntpSrvsFile, Config::File );
135 ntpSrvs.setGroup( "servers" );
136 ntpSrvs.writeEntry( "count", ++srvCount );
137 ntpSrvs.setGroup( "0" );
138 ntpSrvs.writeEntry( "name", edit );
139 curSrv = 0;
140 for ( int i = 1; i < srvCount; i++ )
141 {
142 // qDebug( "ntpSrvs[%i/%i]=%s", i, srvCount, cbTimeServer->text( i ).latin1() );
143 ntpSrvs.setGroup( QString::number( i ) );
144 ntpSrvs.writeEntry( "name", cbTimeServer->text( i-1 ) );
145 }
146 }
147 Config config( "ntp", Config::User );
148 config.setGroup( "settings" );
149 config.writeEntry( "ntpServer", curSrv );
150 config.writeEntry( "minLookupDiff", sbPredictDelay->value() );
151 config.writeEntry( "ntpRefreshFreq", sbNtpDelay->value() );
152 config.writeEntry( "displayNtpTab", chNtpTab->isChecked() );
153 config.writeEntry( "displayPredictTab", chPredictTab->isChecked() );
154}
155
156QString SettingsTabWidget::ntpServer()
157{
158 return cbTimeServer->currentText();
159}
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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef SETTINGSTABWIDGET_H
30#define SETTINGSTABWIDGET_H
31
32#include <qwidget.h>
33
34class QCheckBox;
35class QComboBox;
36class QSpinBox;
37
38class SettingsTabWidget : public QWidget
39{
40 Q_OBJECT
41
42public:
43 SettingsTabWidget( QWidget * = 0x0 );
44 ~SettingsTabWidget();
45
46 void saveSettings();
47 QString ntpServer();
48
49private:
50 QComboBox *cbTimeServer;
51 QSpinBox *sbNtpDelay;
52 QSpinBox *sbPredictDelay;
53 QCheckBox *chNtpTab;
54 QCheckBox *chPredictTab;
55
56signals:
57 void ntpDelayChanged( int );
58 void displayNTPTab( bool );
59 void displayPredictTab( bool );
60};
61
62#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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#include "timetabwidget.h"
30
31#include <qpe/config.h>
32#include <qpe/datebookmonth.h>
33#include <qpe/global.h>
34#include <qpe/resource.h>
35#include <qpe/tzselect.h>
36
37#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
38#include <qpe/qcopenvelope_qws.h>
39#endif
40
41#include <qcombobox.h>
42#include <qdatetime.h>
43#include <qframe.h>
44#include <qlabel.h>
45#include <qlayout.h>
46#include <qpushbutton.h>
47#include <qscrollview.h>
48#include <qspinbox.h>
49
50#include <stdlib.h>
51#include <sys/time.h>
52
53static const int ValueAM = 0;
54static const int ValuePM = 1;
55
56TimeTabWidget::TimeTabWidget( QWidget *parent )
57 : QWidget( parent, 0x0, 0 )
58{
59 // Synchronize HW clock to systemtime
60 // This app will update systemtime
61 // - if Cancel is clicked, will reset systemtime to HW clock's time
62 // - if Ok is clicked, will leave systemtime as is
63 system("/sbin/hwclock --systohc --utc");
64
65 QVBoxLayout *tmpvb = new QVBoxLayout( this );
66 QScrollView *sv = new QScrollView( this );
67 tmpvb->addWidget( sv, 0, 0 );
68 sv->setResizePolicy( QScrollView::AutoOneFit );
69 sv->setFrameStyle( QFrame::NoFrame );
70 QWidget *container = new QWidget( sv->viewport() );
71 sv->addChild( container );
72
73 QGridLayout *layout = new QGridLayout( container );
74 layout->setMargin( 2 );
75 layout->setSpacing( 4 );
76
77 // Hours
78 layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 );
79 sbHour = new QSpinBox( container );
80 sbHour->setWrapping( TRUE );
81 layout->addMultiCellWidget( sbHour, 2, 2, 0, 1 );
82
83 // Minutes
84 layout->addMultiCellWidget( new QLabel( tr( "Minute" ), container ), 1, 1, 2, 3 );
85 sbMin = new QSpinBox( container );
86 sbMin->setWrapping( TRUE );
87 sbMin->setMinValue( 0 );
88 sbMin->setMaxValue( 59 );
89 layout->addMultiCellWidget( sbMin, 2, 2, 2, 3 );
90
91 // AM/PM
92 cbAmpm = new QComboBox( container );
93 cbAmpm->insertItem( tr( "AM" ), ValueAM );
94 cbAmpm->insertItem( tr( "PM" ), ValuePM );
95 layout->addMultiCellWidget( cbAmpm, 2, 2, 4, 5 );
96
97 // Date
98 layout->addWidget( new QLabel( tr( "Date" ), container ), 4, 0 );
99 btnDate = new DateButton( TRUE, container );
100 layout->addMultiCellWidget( btnDate, 4, 4, 1, 5 );
101
102 // Timezone
103 layout->addMultiCellWidget( new QLabel( tr( "Time zone" ), container ), 6, 6, 0, 1 );
104 selTimeZone = new TimeZoneSelector( container );
105 connect( selTimeZone, SIGNAL(signalNewTz(const QString &)), this, SLOT(slotTZChanged(const QString &)) );
106 layout->addMultiCellWidget( selTimeZone, 6, 6, 2, 5 );
107
108 // Space filler
109 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 );
110
111 // Set NTP time button
112 QPushButton *pb = new QPushButton( Resource::loadPixmap( "netsystemtime/ntptab" ),
113 tr( "Get time from the network" ), container );
114 connect( pb, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) );
115 layout->addMultiCellWidget( pb, 8, 8, 0, 5 );
116
117 // Set predicted time button
118 pb = new QPushButton( Resource::loadPixmap( "netsystemtime/predicttab" ), tr( "Set predicted time" ),
119 container );
120 connect( pb, SIGNAL(clicked()), this, SIGNAL(getPredictedTime()) );
121 layout->addMultiCellWidget( pb, 9, 9, 0, 5 );
122
123 // Space filler at bottom of widget
124 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 10, 0 );
125
126 // Initialize values
127 Config config( "locale" );
128 config.setGroup( "Location" );
129 selTimeZone->setCurrentZone( config.readEntry( "Timezone", "America/New_York" ) );
130 use12HourTime = FALSE;
131 setDateTime( QDateTime::currentDateTime() );
132}
133
134TimeTabWidget::~TimeTabWidget()
135{
136}
137
138void TimeTabWidget::saveSettings( bool commit )
139{
140 if ( commit )
141 {
142 // Set timezone and announce to world
143 QString tz = selTimeZone->currentZone();
144 Config config("locale");
145 config.setGroup( "Location" );
146 config.writeEntry( "Timezone", tz );
147 setenv( "TZ", tz, 1 );
148 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
149 setTimeZone << tz;
150
151 // If controls have a valid date & time, update systemtime
152 int hour = sbHour->value();
153 if ( use12HourTime && cbAmpm->currentItem() == ValuePM )
154 hour += 12;
155 QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) );
156 setSystemTime( dt );
157 }
158 else
159 {
160 // Reset systemtime to hardware clock (i.e. undo any changes made by this app)
161 system("/sbin/hwclock --hctosys --utc");
162 }
163}
164
165void TimeTabWidget::setDateTime( const QDateTime &dt )
166{
167 // Set time
168 QTime t = dt.time();
169 if( use12HourTime )
170 {
171 int show_hour = t.hour();
172 if ( t.hour() >= 12 )
173 {
174 show_hour -= 12;
175 cbAmpm->setCurrentItem( ValuePM );
176 }
177 else
178 {
179 cbAmpm->setCurrentItem( ValueAM );
180 }
181 if ( show_hour == 0 )
182 show_hour = 12;
183 sbHour->setValue( show_hour );
184 }
185 else
186 {
187 sbHour->setValue( t.hour() );
188 }
189 sbMin->setValue( t.minute() );
190
191 // Set date
192 btnDate->setDate( dt.date() );
193}
194
195void TimeTabWidget::setSystemTime( const QDateTime &dt )
196{
197 // Set system clock
198 if ( dt.isValid() )
199 {
200 struct timeval myTv;
201 int t = TimeConversion::toUTC( dt );
202 myTv.tv_sec = t;
203 myTv.tv_usec = 0;
204
205 if ( myTv.tv_sec != -1 )
206 ::settimeofday( &myTv, 0 );
207 }
208}
209
210void TimeTabWidget::slotUse12HourTime( int i )
211{
212 use12HourTime = (i == 1);
213
214 cbAmpm->setEnabled( use12HourTime );
215
216 int show_hour = sbHour->value();
217
218 if ( use12HourTime )
219 {
220 sbHour->setMinValue( 1 );
221 sbHour->setMaxValue( 12 );
222
223 if ( show_hour >= 12 )
224 {
225 show_hour -= 12;
226 cbAmpm->setCurrentItem( ValuePM );
227 }
228 else
229 {
230 cbAmpm->setCurrentItem( ValueAM );
231 }
232 if ( show_hour == 0 )
233 show_hour = 12;
234 }
235 else
236 {
237 sbHour->setMinValue( 0 );
238 sbHour->setMaxValue( 23 );
239
240 if ( cbAmpm->currentItem() == ValuePM )
241 {
242 show_hour += 12;
243 if ( show_hour == 24 )
244 show_hour = 0;
245 }
246 }
247
248 sbHour->setValue( show_hour );
249}
250
251void TimeTabWidget::slotDateFormatChanged( const DateFormat &df )
252{
253 btnDate->setDateFormat( df );
254}
255
256void TimeTabWidget::slotWeekStartChanged( int monday )
257{
258 btnDate->setWeekStartsMonday( monday );
259}
260
261void TimeTabWidget::slotTZChanged( const QString &newtz )
262{
263 // If controls have a valid date & time, update systemtime
264 int hour = sbHour->value();
265 if ( use12HourTime && cbAmpm->currentItem() == ValuePM )
266 hour += 12;
267 QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) );
268 setSystemTime( dt );
269 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
270 setTimeZone << newtz;
271
272 // Set system timezone
273 QString currtz = getenv( "TZ" );
274 setenv( "TZ", newtz, 1 );
275
276 // Get new date/time
277 hour = sbHour->value();
278 if ( use12HourTime && cbAmpm->currentItem() == ValuePM )
279 hour += 12;
280 dt = QDateTime::currentDateTime();
281
282 // Reset system timezone
283 if ( !currtz.isNull() )
284 {
285 setenv( "TZ", currtz, 1 );
286 }
287
288 // Set controls to new time
289 setDateTime( dt );
290
291 emit tzChanged( newtz );
292}
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 @@
1/*
2                This file is part of the OPIE Project
3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef TIMETABWIDGET_H
30#define TIMETABWIDGET_H
31
32#include <qwidget.h>
33
34class DateButton;
35class DateFormat;
36class QComboBox;
37class QDateTime;
38class QSpinBox;
39class TimeZoneSelector;
40
41class TimeTabWidget : public QWidget
42{
43 Q_OBJECT
44
45public:
46 TimeTabWidget( QWidget * = 0x0 );
47 ~TimeTabWidget();
48
49 void saveSettings( bool );
50 void setDateTime( const QDateTime & );
51
52private:
53 QSpinBox *sbHour;
54 QSpinBox *sbMin;
55 QComboBox *cbAmpm;
56 DateButton *btnDate;
57 TimeZoneSelector *selTimeZone;
58
59 bool use12HourTime;
60
61 void setSystemTime( const QDateTime & );
62
63signals:
64 void tzChanged( const QString & );
65 void getNTPTime();
66 void getPredictedTime();
67
68public slots:
69 void slotUse12HourTime( int );
70 void slotDateFormatChanged( const DateFormat & );
71 void slotWeekStartChanged( int );
72
73private slots:
74 void slotTZChanged( const QString & );
75};
76
77#endif