-rw-r--r-- | noncore/settings/netsystemtime/main.cpp | 2 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/netsystemtime.pro | 4 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 15 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 7 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.ui | 107 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/opie-netsystemtime.control | 1 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 459 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.h | 97 |
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,11 +1,13 @@ | |||
1 | //#include "settime.h" | ||
1 | #include "ntp.h" | 2 | #include "ntp.h" |
2 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
3 | 4 | ||
4 | int main( int argc, char ** argv ) | 5 | int 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(); |
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,9 +1,9 @@ | |||
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 |
8 | LIBS += -lqpe -lopie | 8 | LIBS += -lqpe -lopie |
9 | INTERFACES= ntpbase.ui | 9 | INTERFACES= ntpbase.ui |
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 | |||
@@ -17,9 +17,9 @@ | |||
17 | #include <stdlib.h> | 17 | #include <stdlib.h> |
18 | 18 | ||
19 | 19 | ||
20 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 20 | Ntp::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); |
@@ -39,8 +39,13 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
39 | } | 39 | } |
40 | 40 | ||
41 | Ntp::~Ntp() | 41 | Ntp::~Ntp() |
42 | { | 42 | { |
43 | |||
44 | } | ||
45 | |||
46 | void 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 | } |
@@ -53,9 +58,8 @@ void Ntp::slotRunNtp() | |||
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 | ||
61 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 65 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
@@ -64,9 +68,9 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | |||
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 | } |
@@ -89,9 +93,9 @@ void Ntp::ntpFinished(OProcess*) | |||
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 | } |
@@ -104,9 +108,8 @@ void Ntp::correctClock() | |||
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 | ||
@@ -172,9 +175,9 @@ void Ntp::preditctTime() | |||
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,15 +1,15 @@ | |||
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 | ||
7 | class OProcess; | 7 | class OProcess; |
8 | class QString; | 8 | class QString; |
9 | 9 | ||
10 | 10 | ||
11 | class Ntp : public NtpBase | 11 | class Ntp : public SetDateTime |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
@@ -17,8 +17,11 @@ public: | |||
17 | ~Ntp(); | 17 | ~Ntp(); |
18 | 18 | ||
19 | OProcess *ntpProcess; | 19 | OProcess *ntpProcess; |
20 | 20 | ||
21 | protected: | ||
22 | virtual void accept(); | ||
23 | |||
21 | private: | 24 | private: |
22 | QString _ntpOutput; | 25 | QString _ntpOutput; |
23 | int _maxOffset; | 26 | int _maxOffset; |
24 | float _shiftPerSec; | 27 | float _shiftPerSec; |
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,8 +1,8 @@ | |||
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> |
@@ -10,9 +10,9 @@ | |||
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"> |
@@ -49,8 +49,44 @@ | |||
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> |
@@ -256,9 +292,9 @@ | |||
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> |
@@ -360,36 +396,87 @@ | |||
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,7 +1,8 @@ | |||
1 | Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop | 1 | Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop |
2 | Priority: optional | 2 | Priority: optional |
3 | Section: opie/settings | 3 | Section: opie/settings |
4 | Depends: ntpdate | ||
4 | Maintainer: Patrick S. Vogt <tille@handhelds.org> | 5 | Maintainer: Patrick S. Vogt <tille@handhelds.org> |
5 | Architecture: arm | 6 | Architecture: arm |
6 | Version: $QPE_VERSION-$SUB_VERSION | 7 | Version: $QPE_VERSION-$SUB_VERSION |
7 | Depends: opie-base ($QPE_VERSION), ntpdate | 8 | Depends: opie-base ($QPE_VERSION), ntpdate |
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 | |||
54 | SetDateTime::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 | |||
189 | void 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 | |||
209 | void 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 | |||
268 | void SetDateTime::done(int r) | ||
269 | { | ||
270 | // QDialog::done(r); | ||
271 | close(); | ||
272 | } | ||
273 | |||
274 | void 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 | |||
289 | void SetDateTime::formatChanged(int i) | ||
290 | { | ||
291 | dateButton->setDateFormat(date_formats[i]); | ||
292 | } | ||
293 | |||
294 | static const int ValueAM = 0; | ||
295 | static const int ValuePM = 1; | ||
296 | |||
297 | |||
298 | |||
299 | SetTime::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 | |||
363 | QTime SetTime::time() const | ||
364 | { | ||
365 | return QTime( hour, minute, 0 ); | ||
366 | } | ||
367 | |||
368 | void 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 | |||
381 | void SetTime::minuteChanged( int value ) | ||
382 | { | ||
383 | minute = value; | ||
384 | } | ||
385 | |||
386 | void 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 | |||
416 | void 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 | |||
428 | void 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 | |||
30 | class QToolButton; | ||
31 | class QSpinBox; | ||
32 | class QLabel; | ||
33 | class TimeZoneSelector; | ||
34 | class DateBookMonth; | ||
35 | class QComboBox; | ||
36 | //class QPEDialogListener; | ||
37 | |||
38 | class SetTime : public QWidget | ||
39 | { | ||
40 | Q_OBJECT | ||
41 | public: | ||
42 | SetTime( QWidget *parent=0, const char *name=0 ); | ||
43 | |||
44 | QTime time() const; | ||
45 | |||
46 | public slots: | ||
47 | void slotTzChange( const QString& tz ); | ||
48 | void show12hourTime( int ); | ||
49 | |||
50 | protected slots: | ||
51 | void hourChanged( int value ); | ||
52 | void minuteChanged( int value ); | ||
53 | |||
54 | void checkedPM( int ); | ||
55 | |||
56 | protected: | ||
57 | int hour; | ||
58 | int minute; | ||
59 | bool use12hourTime; | ||
60 | QComboBox *ampm; | ||
61 | QSpinBox *sbHour; | ||
62 | QSpinBox *sbMin; | ||
63 | }; | ||
64 | |||
65 | class DateButton; | ||
66 | |||
67 | class SetDateTime : public NtpBase | ||
68 | { | ||
69 | Q_OBJECT | ||
70 | public: | ||
71 | SetDateTime( QWidget *parent=0, const char *name=0, WFlags f=0 ); | ||
72 | |||
73 | protected slots: | ||
74 | void tzChange( const QString &tz ); | ||
75 | void formatChanged(int); | ||
76 | |||
77 | protected: | ||
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 | |||