summaryrefslogtreecommitdiff
authortille <tille>2002-06-25 13:09:08 (UTC)
committer tille <tille>2002-06-25 13:09:08 (UTC)
commit8501705e4e50602aaabe9877e6d8821555e3a05a (patch) (unidiff)
tree3f34b6d0f8b7f7e692ccbefd91356685c322204f
parentd282b4f9cba20305e237910aca531b0360666f13 (diff)
downloadopie-8501705e4e50602aaabe9877e6d8821555e3a05a.zip
opie-8501705e4e50602aaabe9877e6d8821555e3a05a.tar.gz
opie-8501705e4e50602aaabe9877e6d8821555e3a05a.tar.bz2
included systemtime gui
not yet much funtionaliti
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/main.cpp2
-rw-r--r--noncore/settings/netsystemtime/netsystemtime.pro4
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp15
-rw-r--r--noncore/settings/netsystemtime/ntp.h7
-rw-r--r--noncore/settings/netsystemtime/ntpbase.ui107
-rw-r--r--noncore/settings/netsystemtime/opie-netsystemtime.control1
-rw-r--r--noncore/settings/netsystemtime/settime.cpp459
-rw-r--r--noncore/settings/netsystemtime/settime.h97
8 files changed, 672 insertions, 20 deletions
diff --git a/noncore/settings/netsystemtime/main.cpp b/noncore/settings/netsystemtime/main.cpp
index 2b23751..5b01408 100644
--- a/noncore/settings/netsystemtime/main.cpp
+++ b/noncore/settings/netsystemtime/main.cpp
@@ -1,12 +1,14 @@
1//#include "settime.h"
1#include "ntp.h" 2#include "ntp.h"
2#include <qpe/qpeapplication.h> 3#include <qpe/qpeapplication.h>
3 4
4int main( int argc, char ** argv ) 5int main( int argc, char ** argv )
5{ 6{
6 QPEApplication a( argc, argv ); 7 QPEApplication a( argc, argv );
7 8
9 // SetDateTime mw;
8 Ntp mw; 10 Ntp mw;
9 a.showMainWidget( &mw ); 11 a.showMainWidget( &mw );
10 12
11 return a.exec(); 13 return a.exec();
12} 14}
diff --git a/noncore/settings/netsystemtime/netsystemtime.pro b/noncore/settings/netsystemtime/netsystemtime.pro
index 7b8ebbc..a8092cf 100644
--- a/noncore/settings/netsystemtime/netsystemtime.pro
+++ b/noncore/settings/netsystemtime/netsystemtime.pro
@@ -1,28 +1,28 @@
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 4 HEADERS = ntp.h settime.h
5 SOURCES = main.cpp ntp.cpp 5 SOURCES = main.cpp ntp.cpp settime.cpp
6 INCLUDEPATH+= $(OPIEDIR)/include 6 INCLUDEPATH+= $(OPIEDIR)/include
7 DEPENDPATH+= $(OPIEDIR)/include 7 DEPENDPATH+= $(OPIEDIR)/include
8LIBS += -lqpe -lopie 8LIBS += -lqpe -lopie
9 INTERFACES= ntpbase.ui 9 INTERFACES= ntpbase.ui
10DESTDIR = $(OPIEDIR)/bin 10DESTDIR = $(OPIEDIR)/bin
11 TARGET = netsystemtime 11 TARGET = netsystemtime
12 12
13 13
14TRANSLATIONS = ../../../i18n/de/../../bin/netsystemtime.ts 14TRANSLATIONS = ../../../i18n/de/../../bin/netsystemtime.ts
15TRANSLATIONS += ../../../i18n/en/../../bin/netsystemtime.ts 15TRANSLATIONS += ../../../i18n/en/../../bin/netsystemtime.ts
16TRANSLATIONS += ../../../i18n/es/../../bin/netsystemtime.ts 16TRANSLATIONS += ../../../i18n/es/../../bin/netsystemtime.ts
17TRANSLATIONS += ../../../i18n/fr/../../bin/netsystemtime.ts 17TRANSLATIONS += ../../../i18n/fr/../../bin/netsystemtime.ts
18TRANSLATIONS += ../../../i18n/hu/../../bin/netsystemtime.ts 18TRANSLATIONS += ../../../i18n/hu/../../bin/netsystemtime.ts
19TRANSLATIONS += ../../../i18n/ja/../../bin/netsystemtime.ts 19TRANSLATIONS += ../../../i18n/ja/../../bin/netsystemtime.ts
20TRANSLATIONS += ../../../i18n/ko/../../bin/netsystemtime.ts 20TRANSLATIONS += ../../../i18n/ko/../../bin/netsystemtime.ts
21TRANSLATIONS += ../../../i18n/no/../../bin/netsystemtime.ts 21TRANSLATIONS += ../../../i18n/no/../../bin/netsystemtime.ts
22TRANSLATIONS += ../../../i18n/pl/../../bin/netsystemtime.ts 22TRANSLATIONS += ../../../i18n/pl/../../bin/netsystemtime.ts
23TRANSLATIONS += ../../../i18n/pt/../../bin/netsystemtime.ts 23TRANSLATIONS += ../../../i18n/pt/../../bin/netsystemtime.ts
24TRANSLATIONS += ../../../i18n/pt_BR/../../bin/netsystemtime.ts 24TRANSLATIONS += ../../../i18n/pt_BR/../../bin/netsystemtime.ts
25TRANSLATIONS += ../../../i18n/sl/../../bin/netsystemtime.ts 25TRANSLATIONS += ../../../i18n/sl/../../bin/netsystemtime.ts
26TRANSLATIONS += ../../../i18n/zh_CN/../../bin/netsystemtime.ts 26TRANSLATIONS += ../../../i18n/zh_CN/../../bin/netsystemtime.ts
27TRANSLATIONS += ../../../i18n/zh_TW/../../bin/netsystemtime.ts 27TRANSLATIONS += ../../../i18n/zh_TW/../../bin/netsystemtime.ts
28 28
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 04b113b..ddb1372 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -1,180 +1,183 @@
1#include "ntp.h" 1#include "ntp.h"
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qregexp.h> 3#include <qregexp.h>
4#include <qtable.h> 4#include <qtable.h>
5#include <qlabel.h> 5#include <qlabel.h>
6#include <qlineedit.h> 6#include <qlineedit.h>
7#include <qmultilineedit.h> 7#include <qmultilineedit.h>
8#include <opie/oprocess.h> 8#include <opie/oprocess.h>
9#include <qpe/config.h> 9#include <qpe/config.h>
10#include <qpe/global.h> 10#include <qpe/global.h>
11#include <qpe/timeconversion.h> 11#include <qpe/timeconversion.h>
12#include <qpe/tzselect.h> 12#include <qpe/tzselect.h>
13#include <qpe/timestring.h> 13#include <qpe/timestring.h>
14#include <qpe/qpedialog.h> 14#include <qpe/qpedialog.h>
15#include <sys/time.h> 15#include <sys/time.h>
16#include <time.h> 16#include <time.h>
17#include <stdlib.h> 17#include <stdlib.h>
18 18
19 19
20Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) 20Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
21 : NtpBase( parent, name, fl ) 21 : SetDateTime( parent, name, fl )
22{ 22{
23 Config cfg("ntp",Config::User); 23 Config cfg("ntp",Config::User);
24 cfg.setGroup("settings"); 24 cfg.setGroup("settings");
25 _maxOffset = cfg.readNumEntry("maxOffset",5); 25 _maxOffset = cfg.readNumEntry("maxOffset",5);
26 _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); 26 _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
27 LineEditNtpServer->setText( cfg.readEntry("ntpServer") ); 27 LineEditNtpServer->setText( cfg.readEntry("ntpServer") );
28 ntpProcess = new OProcess( ); 28 ntpProcess = new OProcess( );
29 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 29 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
30 this, SLOT(getNtpOutput(OProcess*,char*,int))); 30 this, SLOT(getNtpOutput(OProcess*,char*,int)));
31 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 31 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
32 this, SLOT(ntpFinished(OProcess*))); 32 this, SLOT(ntpFinished(OProcess*)));
33 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); 33 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp()));
34 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 34 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
35 _nextCorrection = new QTimer( this ); 35 _nextCorrection = new QTimer( this );
36 connect( _nextCorrection, SIGNAL(timeout()), SLOT(correctClock()) ); 36 connect( _nextCorrection, SIGNAL(timeout()), SLOT(correctClock()) );
37 slotRunNtp(); 37 slotRunNtp();
38 readLookups(); 38 readLookups();
39} 39}
40 40
41Ntp::~Ntp() 41Ntp::~Ntp()
42{ 42{
43
44}
45
46void Ntp::accept()
47{
43 Config cfg("ntp",Config::User); 48 Config cfg("ntp",Config::User);
44 cfg.setGroup("settings"); 49 cfg.setGroup("settings");
45 cfg.writeEntry("ntpServer", LineEditNtpServer->text()); 50 cfg.writeEntry("ntpServer", LineEditNtpServer->text());
46} 51}
47 52
48 53
49void Ntp::slotRunNtp() 54void Ntp::slotRunNtp()
50{ 55{
51 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 56 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
52 ntpProcess->clearArguments(); 57 ntpProcess->clearArguments();
53 *ntpProcess << "ntpdate" << LineEditNtpServer->text(); 58 *ntpProcess << "ntpdate" << LineEditNtpServer->text();
54 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 59 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
55 if ( !ret ) { 60 if ( !ret ) {
56 qDebug("Error while executing ntp"); 61 qDebug("Error while executing ntp");
57 outPut->append("\nError while executing\n\n");
58 } 62 }
59} 63}
60 64
61void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 65void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
62{ 66{
63 QString lineStr, lineStrOld; 67 QString lineStr, lineStrOld;
64 lineStr = buffer; 68 lineStr = buffer;
65 lineStr=lineStr.left(buflen); 69 lineStr=lineStr.left(buflen);
66 if (lineStr!=lineStrOld) 70 if (lineStr!=lineStrOld)
67 { 71 {
68 outPut->append(lineStr); 72 // outPut->append(lineStr);
69 _ntpOutput += lineStr; 73 _ntpOutput += lineStr;
70 } 74 }
71 lineStrOld = lineStr; 75 lineStrOld = lineStr;
72} 76}
73 77
74void Ntp::ntpFinished(OProcess*) 78void Ntp::ntpFinished(OProcess*)
75{ 79{
76 Config cfg("ntp",Config::User); 80 Config cfg("ntp",Config::User);
77 cfg.setGroup("lookups"); 81 cfg.setGroup("lookups");
78 int lastLookup = cfg.readNumEntry("time",0); 82 int lastLookup = cfg.readNumEntry("time",0);
79 int lookupCount = cfg.readNumEntry("count",-1); 83 int lookupCount = cfg.readNumEntry("count",-1);
80 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 84 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
81 cfg.writeEntry("time", time); 85 cfg.writeEntry("time", time);
82 86
83 float timeShift = getTimeShift(); 87 float timeShift = getTimeShift();
84 if (timeShift == 0.0) return; 88 if (timeShift == 0.0) return;
85 int secsSinceLast = time - lastLookup; 89 int secsSinceLast = time - lastLookup;
86 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 90 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
87 if ( lastLookup > 0 && secsSinceLast > 60*_minLookupDiff) 91 if ( lastLookup > 0 && secsSinceLast > 60*_minLookupDiff)
88 { 92 {
89 lookupCount++; 93 lookupCount++;
90 cfg.writeEntry("count",lookupCount); 94 cfg.writeEntry("count",lookupCount);
91 cfg.setGroup("lookup_"+QString::number(lookupCount)); 95 cfg.setGroup("lookup_"+QString::number(lookupCount));
92 _shiftPerSec = timeShift / secsSinceLast; 96 _shiftPerSec = timeShift / secsSinceLast;
93 float nextCorr = _maxOffset / _shiftPerSec; 97// float nextCorr = _maxOffset / _shiftPerSec;
94 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 98 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
95 cfg.writeEntry("secsSinceLast",secsSinceLast); 99 cfg.writeEntry("secsSinceLast",secsSinceLast);
96 cfg.writeEntry("timeShift",QString::number(timeShift)); 100 cfg.writeEntry("timeShift",QString::number(timeShift));
97 } 101 }
98} 102}
99 103
100void Ntp::correctClock() 104void Ntp::correctClock()
101{ 105{
102 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1()); 106 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
103 Config cfg("ntp",Config::User); 107 Config cfg("ntp",Config::User);
104 cfg.setGroup("correction"); 108 cfg.setGroup("correction");
105 int lastTime = cfg.readNumEntry("time",0); 109 int lastTime = cfg.readNumEntry("time",0);
106 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 110 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
107 int corr = int((now - lastTime) * _shiftPerSec); 111 int corr = int((now - lastTime) * _shiftPerSec);
108 outPut->append( "time will be shifted by "+QString::number(corr)+ "secs");
109 struct timeval myTv; 112 struct timeval myTv;
110 myTv.tv_sec = TimeConversion::toUTC( QDateTime::currentDateTime().addSecs(corr) ); 113 myTv.tv_sec = TimeConversion::toUTC( QDateTime::currentDateTime().addSecs(corr) );
111 myTv.tv_usec = 0; 114 myTv.tv_usec = 0;
112 115
113 if ( myTv.tv_sec != -1 ) 116 if ( myTv.tv_sec != -1 )
114 ::settimeofday( &myTv, 0 ); 117 ::settimeofday( &myTv, 0 );
115 Global::writeHWClock(); 118 Global::writeHWClock();
116 cfg.writeEntry("time",now); 119 cfg.writeEntry("time",now);
117 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1()); 120 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
118} 121}
119 122
120float Ntp::getTimeShift() 123float Ntp::getTimeShift()
121{ 124{
122 QString _offset = "offset"; 125 QString _offset = "offset";
123 QString _sec = "sec"; 126 QString _sec = "sec";
124 QRegExp _reOffset = QRegExp(_offset); 127 QRegExp _reOffset = QRegExp(_offset);
125 QRegExp _reEndOffset = QRegExp(_sec); 128 QRegExp _reEndOffset = QRegExp(_sec);
126 int posOffset = _reOffset.match( _ntpOutput ); 129 int posOffset = _reOffset.match( _ntpOutput );
127 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 130 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
128 posOffset += _offset.length() + 1; 131 posOffset += _offset.length() + 1;
129 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 132 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
130 qDebug("%s", _ntpOutput.latin1()); 133 qDebug("%s", _ntpOutput.latin1());
131 qDebug("diff = >%s<",diff.latin1()); 134 qDebug("diff = >%s<",diff.latin1());
132 TextLabelTimeShift->setText(diff); 135 TextLabelTimeShift->setText(diff);
133 return diff.toFloat(); 136 return diff.toFloat();
134} 137}
135 138
136void Ntp::readLookups() 139void Ntp::readLookups()
137{ 140{
138 Config cfg("ntp",Config::User); 141 Config cfg("ntp",Config::User);
139 cfg.setGroup("lookups"); 142 cfg.setGroup("lookups");
140 int lookupCount = cfg.readNumEntry("count",-1); 143 int lookupCount = cfg.readNumEntry("count",-1);
141 float last, shift, shiftPerSec; 144 float last, shift, shiftPerSec;
142 qDebug("lookupCount = %i",lookupCount); 145 qDebug("lookupCount = %i",lookupCount);
143 TableLookups->setNumCols( 3 ); 146 TableLookups->setNumCols( 3 );
144 TableLookups->setNumRows( lookupCount); 147 TableLookups->setNumRows( lookupCount);
145 TableLookups->horizontalHeader()->setLabel(2,"secsSinceLast"); 148 TableLookups->horizontalHeader()->setLabel(2,"secsSinceLast");
146 TableLookups->horizontalHeader()->setLabel(1,"timeShift"); 149 TableLookups->horizontalHeader()->setLabel(1,"timeShift");
147 TableLookups->horizontalHeader()->setLabel(0,"shift/s"); 150 TableLookups->horizontalHeader()->setLabel(0,"shift/s");
148 int cw = TableLookups->width()/4; 151 int cw = TableLookups->width()/4;
149 qDebug("column width %i",cw); 152 qDebug("column width %i",cw);
150 TableLookups->setColumnWidth( 0, cw ); 153 TableLookups->setColumnWidth( 0, cw );
151 TableLookups->setColumnWidth( 1, cw ); 154 TableLookups->setColumnWidth( 1, cw );
152 TableLookups->setColumnWidth( 2, cw ); 155 TableLookups->setColumnWidth( 2, cw );
153 for (int i=0; i < lookupCount; i++) 156 for (int i=0; i < lookupCount; i++)
154 { 157 {
155 cfg.setGroup("lookup_"+QString::number(i)); 158 cfg.setGroup("lookup_"+QString::number(i));
156 last = cfg.readEntry("secsSinceLast",0).toFloat(); 159 last = cfg.readEntry("secsSinceLast",0).toFloat();
157 shift = QString(cfg.readEntry("timeShift",0)).toFloat(); 160 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
158 qDebug("%i last %f",i,last); 161 qDebug("%i last %f",i,last);
159 qDebug("%i shift %f",i,shift); 162 qDebug("%i shift %f",i,shift);
160 shiftPerSec = shift / last; 163 shiftPerSec = shift / last;
161 _shiftPerSec += shiftPerSec; 164 _shiftPerSec += shiftPerSec;
162 TableLookups->setText( i,0,QString::number(shiftPerSec)); 165 TableLookups->setText( i,0,QString::number(shiftPerSec));
163 TableLookups->setText( i,1,QString::number(shift)); 166 TableLookups->setText( i,1,QString::number(shift));
164 TableLookups->setText( i,2,QString::number(last)); 167 TableLookups->setText( i,2,QString::number(last));
165 } 168 }
166 _shiftPerSec /= lookupCount+1; 169 _shiftPerSec /= lookupCount+1;
167 TextLabelShift->setText(QString::number(_shiftPerSec)); 170 TextLabelShift->setText(QString::number(_shiftPerSec));
168} 171}
169 172
170void Ntp::preditctTime() 173void Ntp::preditctTime()
171{ 174{
172 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1()); 175 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
173 Config cfg("ntp",Config::User); 176 Config cfg("ntp",Config::User);
174 cfg.setGroup("lookups"); 177 cfg.setGroup("lookups");
175 int lastTime = cfg.readNumEntry("time",0); 178 int lastTime = cfg.readNumEntry("time",0);
179 setenv( "TZ", tz->currentZone(), 1 );
176 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 180 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
177 int corr = int((now - lastTime) * _shiftPerSec); 181 int corr = int((now - lastTime) * _shiftPerSec);
178 outPut->append( "time will be shifted by "+QString::number(corr)+ "secs");
179 TextLabelPredTime->setText(QDateTime::currentDateTime().addSecs(corr).toString()); 182 TextLabelPredTime->setText(QDateTime::currentDateTime().addSecs(corr).toString());
180} 183}
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h
index e3f6d16..fc233bf 100644
--- a/noncore/settings/netsystemtime/ntp.h
+++ b/noncore/settings/netsystemtime/ntp.h
@@ -1,38 +1,41 @@
1#ifndef NTP_H 1#ifndef NTP_H
2#define NTP_H 2#define NTP_H
3#include "ntpbase.h" 3#include "settime.h"
4#include <qdatetime.h> 4#include <qdatetime.h>
5#include <qtimer.h> 5#include <qtimer.h>
6 6
7class OProcess; 7class OProcess;
8class QString; 8class QString;
9 9
10 10
11class Ntp : public NtpBase 11class Ntp : public SetDateTime
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14 14
15public: 15public:
16 Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 16 Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
17 ~Ntp(); 17 ~Ntp();
18 18
19 OProcess *ntpProcess; 19 OProcess *ntpProcess;
20 20
21protected:
22 virtual void accept();
23
21private: 24private:
22 QString _ntpOutput; 25 QString _ntpOutput;
23 int _maxOffset; 26 int _maxOffset;
24 float _shiftPerSec; 27 float _shiftPerSec;
25 QTimer *_nextCorrection; 28 QTimer *_nextCorrection;
26 int _minLookupDiff; 29 int _minLookupDiff;
27 30
28 float getTimeShift(); 31 float getTimeShift();
29 void readLookups(); 32 void readLookups();
30private slots: 33private slots:
31 void slotRunNtp(); 34 void slotRunNtp();
32 void getNtpOutput(OProcess *proc, char *buffer, int buflen); 35 void getNtpOutput(OProcess *proc, char *buffer, int buflen);
33 void ntpFinished(OProcess*); 36 void ntpFinished(OProcess*);
34 void correctClock(); 37 void correctClock();
35 void preditctTime(); 38 void preditctTime();
36}; 39};
37 40
38#endif 41#endif
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui
index 1c1e1aa..ccae5bf 100644
--- a/noncore/settings/netsystemtime/ntpbase.ui
+++ b/noncore/settings/netsystemtime/ntpbase.ui
@@ -1,100 +1,136 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>NtpBase</class> 2<class>NtpBase</class>
3<widget> 3<widget>
4 <class>QWidget</class> 4 <class>QDialog</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>NtpBase</cstring> 7 <cstring>NtpBase</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>292</width> 14 <width>280</width>
15 <height>337</height> 15 <height>337</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Network Time</string> 20 <string>Network Time</string>
21 </property> 21 </property>
22 <property> 22 <property>
23 <name>layoutMargin</name> 23 <name>layoutMargin</name>
24 </property> 24 </property>
25 <property> 25 <property>
26 <name>layoutSpacing</name> 26 <name>layoutSpacing</name>
27 </property> 27 </property>
28 <grid> 28 <grid>
29 <property stdset="1"> 29 <property stdset="1">
30 <name>margin</name> 30 <name>margin</name>
31 <number>2</number> 31 <number>2</number>
32 </property> 32 </property>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>spacing</name> 34 <name>spacing</name>
35 <number>1</number> 35 <number>1</number>
36 </property> 36 </property>
37 <widget row="0" column="0" > 37 <widget row="0" column="0" >
38 <class>QTabWidget</class> 38 <class>QTabWidget</class>
39 <property stdset="1"> 39 <property stdset="1">
40 <name>name</name> 40 <name>name</name>
41 <cstring>TabWidgetMain</cstring> 41 <cstring>TabWidgetMain</cstring>
42 </property> 42 </property>
43 <property> 43 <property>
44 <name>layoutMargin</name> 44 <name>layoutMargin</name>
45 </property> 45 </property>
46 <property> 46 <property>
47 <name>layoutSpacing</name> 47 <name>layoutSpacing</name>
48 </property> 48 </property>
49 <widget> 49 <widget>
50 <class>QWidget</class> 50 <class>QWidget</class>
51 <property stdset="1"> 51 <property stdset="1">
52 <name>name</name> 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>3</number>
63 </property>
64 <property stdset="1">
65 <name>spacing</name>
66 <number>3</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 <property stdset="1">
75 <name>frameShape</name>
76 <enum>StyledPanel</enum>
77 </property>
78 <property stdset="1">
79 <name>frameShadow</name>
80 <enum>Raised</enum>
81 </property>
82 </widget>
83 </grid>
84 </widget>
85 <widget>
86 <class>QWidget</class>
87 <property stdset="1">
88 <name>name</name>
53 <cstring>tabNtp</cstring> 89 <cstring>tabNtp</cstring>
54 </property> 90 </property>
55 <attribute> 91 <attribute>
56 <name>title</name> 92 <name>title</name>
57 <string>NTP</string> 93 <string>NTP</string>
58 </attribute> 94 </attribute>
59 <grid> 95 <grid>
60 <property stdset="1"> 96 <property stdset="1">
61 <name>margin</name> 97 <name>margin</name>
62 <number>3</number> 98 <number>3</number>
63 </property> 99 </property>
64 <property stdset="1"> 100 <property stdset="1">
65 <name>spacing</name> 101 <name>spacing</name>
66 <number>3</number> 102 <number>3</number>
67 </property> 103 </property>
68 <widget row="1" column="0" > 104 <widget row="1" column="0" >
69 <class>QPushButton</class> 105 <class>QPushButton</class>
70 <property stdset="1"> 106 <property stdset="1">
71 <name>name</name> 107 <name>name</name>
72 <cstring>runNtp</cstring> 108 <cstring>runNtp</cstring>
73 </property> 109 </property>
74 <property stdset="1"> 110 <property stdset="1">
75 <name>text</name> 111 <name>text</name>
76 <string>get time from network</string> 112 <string>get time from network</string>
77 </property> 113 </property>
78 </widget> 114 </widget>
79 <widget row="0" column="0" > 115 <widget row="0" column="0" >
80 <class>QFrame</class> 116 <class>QFrame</class>
81 <property stdset="1"> 117 <property stdset="1">
82 <name>name</name> 118 <name>name</name>
83 <cstring>FrameNtp</cstring> 119 <cstring>FrameNtp</cstring>
84 </property> 120 </property>
85 <property stdset="1"> 121 <property stdset="1">
86 <name>frameShape</name> 122 <name>frameShape</name>
87 <enum>StyledPanel</enum> 123 <enum>StyledPanel</enum>
88 </property> 124 </property>
89 <property stdset="1"> 125 <property stdset="1">
90 <name>frameShadow</name> 126 <name>frameShadow</name>
91 <enum>Raised</enum> 127 <enum>Raised</enum>
92 </property> 128 </property>
93 <property> 129 <property>
94 <name>layoutMargin</name> 130 <name>layoutMargin</name>
95 </property> 131 </property>
96 <grid> 132 <grid>
97 <property stdset="1"> 133 <property stdset="1">
98 <name>margin</name> 134 <name>margin</name>
99 <number>11</number> 135 <number>11</number>
100 </property> 136 </property>
@@ -212,97 +248,97 @@
212 </widget> 248 </widget>
213 <widget row="1" column="0" > 249 <widget row="1" column="0" >
214 <class>QLayoutWidget</class> 250 <class>QLayoutWidget</class>
215 <property stdset="1"> 251 <property stdset="1">
216 <name>name</name> 252 <name>name</name>
217 <cstring>Layout6</cstring> 253 <cstring>Layout6</cstring>
218 </property> 254 </property>
219 <hbox> 255 <hbox>
220 <property stdset="1"> 256 <property stdset="1">
221 <name>margin</name> 257 <name>margin</name>
222 <number>0</number> 258 <number>0</number>
223 </property> 259 </property>
224 <property stdset="1"> 260 <property stdset="1">
225 <name>spacing</name> 261 <name>spacing</name>
226 <number>6</number> 262 <number>6</number>
227 </property> 263 </property>
228 <widget> 264 <widget>
229 <class>QLabel</class> 265 <class>QLabel</class>
230 <property stdset="1"> 266 <property stdset="1">
231 <name>name</name> 267 <name>name</name>
232 <cstring>TextLabel7</cstring> 268 <cstring>TextLabel7</cstring>
233 </property> 269 </property>
234 <property stdset="1"> 270 <property stdset="1">
235 <name>text</name> 271 <name>text</name>
236 <string>NTP Server:</string> 272 <string>NTP Server:</string>
237 </property> 273 </property>
238 </widget> 274 </widget>
239 <widget> 275 <widget>
240 <class>QLineEdit</class> 276 <class>QLineEdit</class>
241 <property stdset="1"> 277 <property stdset="1">
242 <name>name</name> 278 <name>name</name>
243 <cstring>LineEditNtpServer</cstring> 279 <cstring>LineEditNtpServer</cstring>
244 </property> 280 </property>
245 </widget> 281 </widget>
246 </hbox> 282 </hbox>
247 </widget> 283 </widget>
248 </grid> 284 </grid>
249 </widget> 285 </widget>
250 </grid> 286 </grid>
251 </widget> 287 </widget>
252 <widget> 288 <widget>
253 <class>QWidget</class> 289 <class>QWidget</class>
254 <property stdset="1"> 290 <property stdset="1">
255 <name>name</name> 291 <name>name</name>
256 <cstring>tab</cstring> 292 <cstring>tab</cstring>
257 </property> 293 </property>
258 <attribute> 294 <attribute>
259 <name>title</name> 295 <name>title</name>
260 <string>Auto Correction</string> 296 <string>Auto</string>
261 </attribute> 297 </attribute>
262 <grid> 298 <grid>
263 <property stdset="1"> 299 <property stdset="1">
264 <name>margin</name> 300 <name>margin</name>
265 <number>2</number> 301 <number>2</number>
266 </property> 302 </property>
267 <property stdset="1"> 303 <property stdset="1">
268 <name>spacing</name> 304 <name>spacing</name>
269 <number>2</number> 305 <number>2</number>
270 </property> 306 </property>
271 <widget row="0" column="0" > 307 <widget row="0" column="0" >
272 <class>QTable</class> 308 <class>QTable</class>
273 <property stdset="1"> 309 <property stdset="1">
274 <name>name</name> 310 <name>name</name>
275 <cstring>TableLookups</cstring> 311 <cstring>TableLookups</cstring>
276 </property> 312 </property>
277 <property stdset="1"> 313 <property stdset="1">
278 <name>numRows</name> 314 <name>numRows</name>
279 <number>2</number> 315 <number>2</number>
280 </property> 316 </property>
281 <property stdset="1"> 317 <property stdset="1">
282 <name>numCols</name> 318 <name>numCols</name>
283 <number>2</number> 319 <number>2</number>
284 </property> 320 </property>
285 </widget> 321 </widget>
286 <widget row="2" column="0" > 322 <widget row="2" column="0" >
287 <class>QPushButton</class> 323 <class>QPushButton</class>
288 <property stdset="1"> 324 <property stdset="1">
289 <name>name</name> 325 <name>name</name>
290 <cstring>PushButtonPredict</cstring> 326 <cstring>PushButtonPredict</cstring>
291 </property> 327 </property>
292 <property stdset="1"> 328 <property stdset="1">
293 <name>text</name> 329 <name>text</name>
294 <string>predict time</string> 330 <string>predict time</string>
295 </property> 331 </property>
296 </widget> 332 </widget>
297 <widget row="1" column="0" > 333 <widget row="1" column="0" >
298 <class>QLayoutWidget</class> 334 <class>QLayoutWidget</class>
299 <property stdset="1"> 335 <property stdset="1">
300 <name>name</name> 336 <name>name</name>
301 <cstring>Layout5</cstring> 337 <cstring>Layout5</cstring>
302 </property> 338 </property>
303 <grid> 339 <grid>
304 <property stdset="1"> 340 <property stdset="1">
305 <name>margin</name> 341 <name>margin</name>
306 <number>0</number> 342 <number>0</number>
307 </property> 343 </property>
308 <property stdset="1"> 344 <property stdset="1">
@@ -316,80 +352,131 @@
316 <cstring>TextLabelShift</cstring> 352 <cstring>TextLabelShift</cstring>
317 </property> 353 </property>
318 <property stdset="1"> 354 <property stdset="1">
319 <name>text</name> 355 <name>text</name>
320 <string>nan</string> 356 <string>nan</string>
321 </property> 357 </property>
322 </widget> 358 </widget>
323 <widget row="1" column="1" > 359 <widget row="1" column="1" >
324 <class>QLabel</class> 360 <class>QLabel</class>
325 <property stdset="1"> 361 <property stdset="1">
326 <name>name</name> 362 <name>name</name>
327 <cstring>TextLabelPredTime</cstring> 363 <cstring>TextLabelPredTime</cstring>
328 </property> 364 </property>
329 <property stdset="1"> 365 <property stdset="1">
330 <name>text</name> 366 <name>text</name>
331 <string>nan</string> 367 <string>nan</string>
332 </property> 368 </property>
333 </widget> 369 </widget>
334 <widget row="0" column="0" > 370 <widget row="0" column="0" >
335 <class>QLabel</class> 371 <class>QLabel</class>
336 <property stdset="1"> 372 <property stdset="1">
337 <name>name</name> 373 <name>name</name>
338 <cstring>Mean_shift_label</cstring> 374 <cstring>Mean_shift_label</cstring>
339 </property> 375 </property>
340 <property stdset="1"> 376 <property stdset="1">
341 <name>text</name> 377 <name>text</name>
342 <string>Mean shift:</string> 378 <string>Mean shift:</string>
343 </property> 379 </property>
344 </widget> 380 </widget>
345 <widget row="1" column="0" > 381 <widget row="1" column="0" >
346 <class>QLabel</class> 382 <class>QLabel</class>
347 <property stdset="1"> 383 <property stdset="1">
348 <name>name</name> 384 <name>name</name>
349 <cstring>TextLabel3_2</cstring> 385 <cstring>TextLabel3_2</cstring>
350 </property> 386 </property>
351 <property stdset="1"> 387 <property stdset="1">
352 <name>text</name> 388 <name>text</name>
353 <string>Pred. Time:</string> 389 <string>Pred. Time:</string>
354 </property> 390 </property>
355 </widget> 391 </widget>
356 </grid> 392 </grid>
357 </widget> 393 </widget>
358 </grid> 394 </grid>
359 </widget> 395 </widget>
360 <widget> 396 <widget>
361 <class>QWidget</class> 397 <class>QWidget</class>
362 <property stdset="1"> 398 <property stdset="1">
363 <name>name</name> 399 <name>name</name>
364 <cstring>TabDebug</cstring> 400 <cstring>TabSettings</cstring>
365 </property> 401 </property>
366 <attribute> 402 <attribute>
367 <name>title</name> 403 <name>title</name>
368 <string>Debug</string> 404 <string>Settings</string>
369 </attribute> 405 </attribute>
370 <grid> 406 <grid>
371 <property stdset="1"> 407 <property stdset="1">
372 <name>margin</name> 408 <name>margin</name>
373 <number>3</number> 409 <number>3</number>
374 </property> 410 </property>
375 <property stdset="1"> 411 <property stdset="1">
376 <name>spacing</name> 412 <name>spacing</name>
377 <number>6</number> 413 <number>3</number>
378 </property> 414 </property>
379 <widget row="0" column="0" > 415 <widget row="0" column="0" >
380 <class>QMultiLineEdit</class> 416 <class>QFrame</class>
381 <property stdset="1"> 417 <property stdset="1">
382 <name>name</name> 418 <name>name</name>
383 <cstring>outPut</cstring> 419 <cstring>FrameSettings</cstring>
384 </property> 420 </property>
385 <property stdset="1"> 421 <property stdset="1">
386 <name>wordWrap</name> 422 <name>frameShape</name>
387 <enum>WidgetWidth</enum> 423 <enum>StyledPanel</enum>
424 </property>
425 <property stdset="1">
426 <name>frameShadow</name>
427 <enum>Raised</enum>
388 </property> 428 </property>
389 </widget> 429 </widget>
390 </grid> 430 </grid>
391 </widget> 431 </widget>
432 <widget>
433 <class>QWidget</class>
434 <property stdset="1">
435 <name>name</name>
436 <cstring>tabSetTime</cstring>
437 </property>
438 <attribute>
439 <name>title</name>
440 <string>Manual</string>
441 </attribute>
442 <vbox>
443 <property stdset="1">
444 <name>margin</name>
445 <number>2</number>
446 </property>
447 <property stdset="1">
448 <name>spacing</name>
449 <number>2</number>
450 </property>
451 <widget>
452 <class>QFrame</class>
453 <property stdset="1">
454 <name>name</name>
455 <cstring>FrameSetTime</cstring>
456 </property>
457 <property stdset="1">
458 <name>frameShape</name>
459 <enum>StyledPanel</enum>
460 </property>
461 <property stdset="1">
462 <name>frameShadow</name>
463 <enum>Raised</enum>
464 </property>
465 </widget>
466 <widget>
467 <class>QPushButton</class>
468 <property stdset="1">
469 <name>name</name>
470 <cstring>PushButtonSetManualTime</cstring>
471 </property>
472 <property stdset="1">
473 <name>text</name>
474 <string>Set time</string>
475 </property>
476 </widget>
477 </vbox>
478 </widget>
392 </widget> 479 </widget>
393 </grid> 480 </grid>
394</widget> 481</widget>
395</UI> 482</UI>
diff --git a/noncore/settings/netsystemtime/opie-netsystemtime.control b/noncore/settings/netsystemtime/opie-netsystemtime.control
index 8067822..a5809b0 100644
--- a/noncore/settings/netsystemtime/opie-netsystemtime.control
+++ b/noncore/settings/netsystemtime/opie-netsystemtime.control
@@ -1,9 +1,10 @@
1Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop 1Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop
2Priority: optional 2Priority: optional
3Section: opie/settings 3Section: opie/settings
4Depends: ntpdate
4Maintainer: Patrick S. Vogt <tille@handhelds.org> 5Maintainer: Patrick S. Vogt <tille@handhelds.org>
5Architecture: arm 6Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION 7Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION), ntpdate 8Depends: opie-base ($QPE_VERSION), ntpdate
8Description: ntp ( Network Time Protocol) gui 9Description: ntp ( Network Time Protocol) gui
9This utility syncs system time with a atomic timerserver via internet \ No newline at end of file 10This utility syncs system time with a atomic timerserver via internet \ No newline at end of file
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp
new file mode 100644
index 0000000..dac5bd4
--- a/dev/null
+++ b/noncore/settings/netsystemtime/settime.cpp
@@ -0,0 +1,459 @@
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 <qbuttongroup.h>
39#include <qcheckbox.h>
40#include <qlabel.h>
41#include <qlayout.h>
42#include <qradiobutton.h>
43#include <qspinbox.h>
44#include <qtoolbutton.h>
45#include <qwindowsystem_qws.h>
46#include <qcombobox.h>
47
48#include <sys/time.h>
49#include <time.h>
50#include <stdlib.h>
51#include <stdio.h>
52
53
54SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f )
55 : NtpBase( parent, name, f )
56{
57 // setCaption( tr("Set System Time") );
58
59// QVBoxLayout *vb = new QVBoxLayout( this, 5 );
60 QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 );
61 QVBoxLayout *vb2 = new QVBoxLayout( FrameSetTime, 5 );
62
63 QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" );
64
65 QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" );
66 lblZone->setMaximumSize( lblZone->sizeHint() );
67 hb->addWidget( lblZone );
68
69 tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" );
70 tz->setMinimumSize( tz->sizeHint() );
71 hb->addWidget( tz );
72
73 timeButton = new SetTime( FrameSetTime );
74 vb2->addWidget( timeButton );
75
76 QHBoxLayout *db = new QHBoxLayout( vb2 );
77 QLabel *dateLabel = new QLabel( tr("Date"), FrameSetTime );
78 db->addWidget( dateLabel, 1 );
79 dateButton = new DateButton( TRUE, FrameSetTime );
80 db->addWidget( dateButton, 2 );
81
82 QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
83 vb2->addItem( spacer );
84
85 QFrame *hline = new QFrame( FrameSystemTime );
86 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
87 vb->addWidget( hline );
88
89 Config config("qpe");
90 config.setGroup( "Time" );
91
92 QHBoxLayout *hb1 = new QHBoxLayout( vb );
93
94 QLabel *l = new QLabel( tr("Time format"), FrameSystemTime );
95 // l->setAlignment( AlignRight | AlignVCenter );
96 hb1->addWidget( l, 1 );
97
98
99 ampmCombo = new QComboBox( FrameSystemTime );
100 ampmCombo->insertItem( tr("24 hour"), 0 );
101 ampmCombo->insertItem( tr("12 hour"), 1 );
102 hb1->addWidget( ampmCombo, 2 );
103
104 int show12hr = config.readBoolEntry("AMPM") ? 1 : 0;
105 ampmCombo->setCurrentItem( show12hr );
106 timeButton->show12hourTime( show12hr );
107
108 connect(ampmCombo, SIGNAL(activated(int)),
109 timeButton, SLOT(show12hourTime(int)));
110
111
112
113 QHBoxLayout *hb2 = new QHBoxLayout( vb );
114 l = new QLabel( tr("Weeks start on" ), FrameSystemTime );
115 //l->setAlignment( AlignRight | AlignVCenter );
116 hb2->addWidget( l, 1 );
117
118 weekStartCombo = new QComboBox( FrameSystemTime );
119 weekStartCombo->insertItem( tr("Sunday"), 0 );
120 weekStartCombo->insertItem( tr("Monday"), 1 );
121
122 hb2->addWidget( weekStartCombo, 2 );
123 int startMonday = config.readBoolEntry("MONDAY") ? 1 : 0;
124 dateButton->setWeekStartsMonday( startMonday );
125 weekStartCombo->setCurrentItem( startMonday );
126
127 connect( weekStartCombo, SIGNAL( activated(int)),
128 dateButton, SLOT(setWeekStartsMonday(int)));
129
130
131 QHBoxLayout *hb3 = new QHBoxLayout( vb );
132 l = new QLabel( tr("Date format" ), FrameSystemTime );
133 hb3->addWidget( l, 1 );
134 dateFormatCombo = new QComboBox( FrameSystemTime );
135 hb3->addWidget( dateFormatCombo, 2 );
136
137 config.setGroup( "Date" );
138 DateFormat df(QChar(config.readEntry("Separator", "/")[0]),
139 (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear),
140 (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear));
141
142 int currentdf = 0;
143 date_formats[0] = DateFormat('/', DateFormat::MonthDayYear);
144 dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) );
145 date_formats[1] = DateFormat('.', DateFormat::DayMonthYear);
146 if (df == date_formats[1])
147 currentdf = 1;
148 dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) );
149 date_formats[2] = DateFormat('-', DateFormat::YearMonthDay,
150 DateFormat::DayMonthYear);
151 if (df == date_formats[2])
152 currentdf = 2;
153 dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601
154 date_formats[3] = DateFormat('/', DateFormat::DayMonthYear);
155 if (df == date_formats[3])
156 currentdf = 3;
157 dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) );
158
159 dateFormatCombo->setCurrentItem( currentdf );
160 dateButton->setDateFormat( df );
161
162 connect( dateFormatCombo, SIGNAL( activated(int)),
163 SLOT(formatChanged(int)));
164
165 QHBoxLayout *hb4 = new QHBoxLayout( vb );
166 l = new QLabel( tr("Applet format" ), FrameSystemTime );
167 hb4->addWidget( l, 1 );
168
169 clockAppletCombo = new QComboBox( FrameSystemTime );
170 clockAppletCombo->insertItem( tr("hh:mm"), 0 );
171 clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 );
172 clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 );
173
174 hb4->addWidget( clockAppletCombo, 2 );
175 int clockApplet = config.readNumEntry("ClockApplet",0);
176 clockAppletCombo->setCurrentItem( clockApplet );
177
178 vb->addStretch( 0 );
179
180 QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ),
181 timeButton, SLOT( slotTzChange( const QString& ) ) );
182 QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ),
183 SLOT( tzChange( const QString& ) ) );
184 QObject::connect( PushButtonSetManualTime, SLOT(clicked()),
185 SLOT(commitTime()));
186// dl = new QPEDialogListener(this);
187}
188
189void SetDateTime::accept()
190{
191
192 Config config("qpe");
193 config.setGroup( "Time" );
194 config.writeEntry( "AMPM", ampmCombo->currentItem() );
195 config.writeEntry( "MONDAY", weekStartCombo->currentItem() );
196 config.setGroup( "Date" );
197 DateFormat df = date_formats[dateFormatCombo->currentItem()];
198 config.writeEntry( "Separator", QString(df.separator()));
199 config.writeEntry( "ShortOrder", df.shortOrder());
200 config.writeEntry( "LongOrder", df.longOrder());
201 config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() );
202
203 Config lconfig("locale");
204 lconfig.setGroup( "Location" );
205 lconfig.writeEntry( "Timezone", tz->currentZone() );
206
207}
208
209void SetDateTime::commitTime()
210{
211 Config cfg("ntp",Config::User);
212 cfg.setGroup("lookups");
213 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
214 cfg.writeEntry("time", time);
215 tz->setFocus();
216 // really turn off the screensaver before doing anything
217 {
218 // Needs to be encased in { } so that it deconstructs and sends
219 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
220 disableScreenSaver << 0 << 0 << 0;
221 }
222 // Need to process the QCOP event generated above before proceeding
223 qApp->processEvents();
224
225 // before we progress further, set our TZ!
226 setenv( "TZ", tz->currentZone(), 1 );
227 // now set the time...
228 QDateTime dt( dateButton->date(), timeButton->time() );
229
230 if ( dt.isValid() ) {
231 struct timeval myTv;
232 myTv.tv_sec = TimeConversion::toUTC( dt );
233 myTv.tv_usec = 0;
234
235 if ( myTv.tv_sec != -1 )
236 ::settimeofday( &myTv, 0 );
237 Global::writeHWClock();
238 // since time has changed quickly load in the datebookdb
239 // to allow the alarm server to get a better grip on itself
240 // (example re-trigger alarms for when we travel back in time)
241 DateBookDB db;
242 } else {
243 qWarning( "Invalid date/time" );
244 }
245 // set the timezone for everyone else...
246 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
247 setTimeZone << tz->currentZone();
248
249 // AM/PM setting and notify time changed
250 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
251 setClock << ampmCombo->currentItem();
252
253 // Notify everyone what day we prefer to start the week on.
254 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
255 setWeek << weekStartCombo->currentItem();
256
257 // Notify everyone what date format to use
258 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
259 setDateFormat << date_formats[dateFormatCombo->currentItem()];
260
261 // Restore screensaver
262 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
263 enableScreenSaver << -1 << -1 << -1;
264
265 // QDialog::accept();
266}
267
268void SetDateTime::done(int r)
269{
270// QDialog::done(r);
271 close();
272}
273
274void SetDateTime::tzChange( const QString &tz )
275{
276 // set the TZ get the time and leave gracefully...
277 QString strSave;
278 strSave = getenv( "TZ" );
279 setenv( "TZ", tz, 1 );
280
281 QDate d = QDate::currentDate();
282 // reset the time.
283 if ( !strSave.isNull() ) {
284 setenv( "TZ", strSave, 1 );
285 }
286 dateButton->setDate( d );
287}
288
289void SetDateTime::formatChanged(int i)
290{
291 dateButton->setDateFormat(date_formats[i]);
292}
293
294static const int ValueAM = 0;
295static const int ValuePM = 1;
296
297
298
299SetTime::SetTime( QWidget *parent, const char *name )
300 : QWidget( parent, name )
301{
302 use12hourTime = FALSE;
303
304 QTime currTime = QTime::currentTime();
305 hour = currTime.hour();
306 minute = currTime.minute();
307
308 QHBoxLayout *hb2 = new QHBoxLayout( this );
309 hb2->setSpacing( 3 );
310
311 QLabel *l = new QLabel( tr("Hour"), this );
312 // l->setAlignment( AlignRight | AlignVCenter );
313 hb2->addWidget( l );
314
315 sbHour = new QSpinBox( this );
316 sbHour->setMinimumWidth( 30 );
317 if(use12hourTime) {
318 sbHour->setMinValue(1);
319 sbHour->setMaxValue( 12 );
320 int show_hour = hour;
321 if (hour > 12)
322 show_hour -= 12;
323 if (show_hour == 0)
324 show_hour = 12;
325
326 sbHour->setValue( show_hour );
327 } else {
328 sbHour->setMinValue( 0 );
329 sbHour->setMaxValue( 23 );
330 sbHour->setValue( hour );
331 }
332 sbHour->setWrapping(TRUE);
333 connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) );
334 hb2->addWidget( sbHour );
335
336 hb2->addStretch( 1 );
337
338 l = new QLabel( tr("Minute"), this );
339 //l->setAlignment( AlignRight | AlignVCenter );
340 hb2->addWidget( l );
341
342 sbMin = new QSpinBox( this );
343 sbMin->setMinValue( 0 );
344 sbMin->setMaxValue( 59 );
345 sbMin->setWrapping(TRUE);
346 sbMin->setValue( minute );
347 sbMin->setMinimumWidth( 30 );
348 connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) );
349 hb2->addWidget( sbMin );
350
351 hb2->addStretch( 1 );
352
353 ampm = new QComboBox( this );
354 ampm->insertItem( tr("AM"), ValueAM );
355 ampm->insertItem( tr("PM"), ValuePM );
356 connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) );
357 hb2->addWidget( ampm );
358
359 hb2->addStretch( 1 );
360
361}
362
363QTime SetTime::time() const
364{
365 return QTime( hour, minute, 0 );
366}
367
368void SetTime::hourChanged( int value )
369{
370 if(use12hourTime) {
371 int realhour = value;
372 if (realhour == 12)
373 realhour = 0;
374 if (ampm->currentItem() == ValuePM )
375 realhour += 12;
376 hour = realhour;
377 } else
378 hour = value;
379}
380
381void SetTime::minuteChanged( int value )
382{
383 minute = value;
384}
385
386void SetTime::show12hourTime( int on )
387{
388 use12hourTime = on;
389 ampm->setEnabled(on);
390
391 int show_hour = hour;
392 if ( on ) {
393 /* this might change the value of hour */
394 sbHour->setMinValue(1);
395 sbHour->setMaxValue( 12 );
396
397 /* so use one we saved earlier */
398 if (show_hour >= 12) {
399 show_hour -= 12;
400 ampm->setCurrentItem( ValuePM );
401 } else {
402 ampm->setCurrentItem( ValueAM );
403 }
404 if (show_hour == 0)
405 show_hour = 12;
406
407 } else {
408 sbHour->setMinValue( 0 );
409 sbHour->setMaxValue( 23 );
410 }
411
412
413 sbHour->setValue( show_hour );
414}
415
416void SetTime::checkedPM( int c )
417{
418 int show_hour = sbHour->value();
419 if (show_hour == 12)
420 show_hour = 0;
421
422 if ( c == ValuePM )
423 show_hour += 12;
424
425 hour = show_hour;
426}
427
428void SetTime::slotTzChange( const QString &tz )
429{
430 // set the TZ get the time and leave gracefully...
431 QString strSave;
432 strSave = getenv( "TZ" );
433 setenv( "TZ", tz, 1 );
434
435 QTime t = QTime::currentTime();
436 // reset the time.
437 if ( !strSave.isNull() ) {
438 setenv( "TZ", strSave, 1 );
439 }
440
441 // just set the spinboxes and let it propage through
442 if(use12hourTime) {
443 int show_hour = t.hour();
444 if (t.hour() >= 12) {
445 show_hour -= 12;
446 ampm->setCurrentItem( ValuePM );
447 } else {
448 ampm->setCurrentItem( ValueAM );
449 }
450 if (show_hour == 0)
451 show_hour = 12;
452 sbHour->setValue( show_hour );
453 } else {
454 sbHour->setValue( t.hour() );
455 }
456 sbMin->setValue( t.minute() );
457}
458
459
diff --git a/noncore/settings/netsystemtime/settime.h b/noncore/settings/netsystemtime/settime.h
new file mode 100644
index 0000000..053d17a
--- a/dev/null
+++ b/noncore/settings/netsystemtime/settime.h
@@ -0,0 +1,97 @@
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//class QPEDialogListener;
37
38class SetTime : public QWidget
39{
40 Q_OBJECT
41public:
42 SetTime( QWidget *parent=0, const char *name=0 );
43
44 QTime time() const;
45
46public slots:
47 void slotTzChange( const QString& tz );
48 void show12hourTime( int );
49
50protected slots:
51 void hourChanged( int value );
52 void minuteChanged( int value );
53
54 void checkedPM( int );
55
56protected:
57 int hour;
58 int minute;
59 bool use12hourTime;
60 QComboBox *ampm;
61 QSpinBox *sbHour;
62 QSpinBox *sbMin;
63};
64
65class DateButton;
66
67class SetDateTime : public NtpBase
68{
69 Q_OBJECT
70public:
71 SetDateTime( QWidget *parent=0, const char *name=0, WFlags f=0 );
72
73protected slots:
74 void tzChange( const QString &tz );
75 void formatChanged(int);
76
77protected:
78 void commitTime();
79 virtual void accept();
80 virtual void done(int);
81
82 SetTime *timeButton;
83 DateButton *dateButton;
84 TimeZoneSelector *tz;
85 QComboBox *weekStartCombo;
86 QComboBox *ampmCombo;
87 QComboBox *dateFormatCombo;
88 QComboBox *clockAppletCombo;
89
90// QPEDialogListener *dl;
91
92 DateFormat date_formats[4];
93};
94
95
96#endif
97