Diffstat (limited to 'noncore/settings/netsystemtime') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/netsystemtime/main.cpp | 10 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/mainwindow.cpp | 25 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/mainwindow.h | 3 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/netsystemtime.pro | 7 |
4 files changed, 19 insertions, 26 deletions
diff --git a/noncore/settings/netsystemtime/main.cpp b/noncore/settings/netsystemtime/main.cpp index 4b20a61..da98eee 100644 --- a/noncore/settings/netsystemtime/main.cpp +++ b/noncore/settings/netsystemtime/main.cpp | |||
@@ -8,34 +8,28 @@ | |||
8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public | 8 | :`=1 )Y*s>-.-- : the terms of the GNU General Public |
9 | .="- .-=="i, .._ License as published by the Free Software | 9 | .="- .-=="i, .._ License as published by the Free Software |
10 | - . .-<_> .<> Foundation; either version 2 of the License, | 10 | - . .-<_> .<> Foundation; either version 2 of the License, |
11 | ._= =} : or (at your option) any later version. | 11 | ._= =} : or (at your option) any later version. |
12 | .%`+i> _;_. | 12 | .%`+i> _;_. |
13 | .i_,=:_. -<s. This file is distributed in the hope that | 13 | .i_,=:_. -<s. This file is distributed in the hope that |
14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 14 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
15 | : .. .:, . . . without even the implied warranty of | 15 | : .. .:, . . . without even the implied warranty of |
16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 16 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General | 17 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General |
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "mainwindow.h" | 29 | #include "mainwindow.h" |
30 | 30 | ||
31 | #include <qpe/qpeapplication.h> | 31 | #include <qpe/qpeapplication.h> |
32 | #include <opie/oapplicationfactory.h> | ||
32 | 33 | ||
33 | int main( int argc, char ** argv ) | ||
34 | { | ||
35 | QPEApplication a( argc, argv ); | ||
36 | 34 | ||
37 | MainWindow mw; | 35 | OPIE_EXPORT_APP( OApplicationFactory<MainWindow> ) |
38 | a.showMainWidget( &mw ); | ||
39 | |||
40 | return a.exec(); | ||
41 | } | ||
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp index 2d240ba..66e1ca3 100644 --- a/noncore/settings/netsystemtime/mainwindow.cpp +++ b/noncore/settings/netsystemtime/mainwindow.cpp | |||
@@ -18,120 +18,121 @@ | |||
18 | ..}^=.= = ; Public License for more details. | 18 | ..}^=.= = ; Public License for more details. |
19 | ++= -. .` .: | 19 | ++= -. .` .: |
20 | : = ...= . :.=- You should have received a copy of the GNU | 20 | : = ...= . :.=- You should have received a copy of the GNU |
21 | -. .:....=;==+<; General Public License along with this file; | 21 | -. .:....=;==+<; General Public License along with this file; |
22 | -_. . . )=. = see the file COPYING. If not, write to the | 22 | -_. . . )=. = see the file COPYING. If not, write to the |
23 | -- :-=` Free Software Foundation, Inc., | 23 | -- :-=` Free Software Foundation, Inc., |
24 | 59 Temple Place - Suite 330, | 24 | 59 Temple Place - Suite 330, |
25 | Boston, MA 02111-1307, USA. | 25 | Boston, MA 02111-1307, USA. |
26 | 26 | ||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include "mainwindow.h" | 29 | #include "mainwindow.h" |
30 | #include "timetabwidget.h" | 30 | #include "timetabwidget.h" |
31 | #include "formattabwidget.h" | 31 | #include "formattabwidget.h" |
32 | #include "settingstabwidget.h" | 32 | #include "settingstabwidget.h" |
33 | #include "ntptabwidget.h" | 33 | #include "ntptabwidget.h" |
34 | #include "predicttabwidget.h" | 34 | #include "predicttabwidget.h" |
35 | 35 | ||
36 | #include <opie/oprocess.h> | 36 | #include <opie/oprocess.h> |
37 | #include <opie/otabwidget.h> | 37 | #include <opie/otabwidget.h> |
38 | 38 | ||
39 | #include <qpe/config.h> | 39 | #include <qpe/config.h> |
40 | #include <qpe/datebookdb.h> | 40 | #include <qpe/datebookdb.h> |
41 | #include <qpe/qpeapplication.h> | 41 | #include <qpe/qpeapplication.h> |
42 | #include <qpe/qpedialog.h> | ||
42 | 43 | ||
43 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 44 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
44 | #include <qpe/qcopenvelope_qws.h> | 45 | #include <qpe/qcopenvelope_qws.h> |
45 | #endif | 46 | #endif |
46 | 47 | ||
47 | #include <qlayout.h> | 48 | #include <qlayout.h> |
48 | #include <qmessagebox.h> | 49 | #include <qmessagebox.h> |
49 | #include <qsocket.h> | 50 | #include <qsocket.h> |
50 | #include <qstring.h> | 51 | #include <qstring.h> |
51 | #include <qtimer.h> | 52 | #include <qtimer.h> |
52 | 53 | ||
53 | MainWindow::MainWindow() | 54 | MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags f ) |
54 | : QDialog( 0x0, 0x0, TRUE, 0 ) | 55 | : QDialog( 0x0, 0x0, TRUE, 0 ) |
55 | { | 56 | { |
56 | setCaption( tr( "SystemTime" ) ); | 57 | setCaption( tr( "SystemTime" ) ); |
57 | 58 | ||
58 | QVBoxLayout *layout = new QVBoxLayout( this ); | 59 | QVBoxLayout *layout = new QVBoxLayout( this ); |
59 | layout->setMargin( 2 ); | 60 | layout->setMargin( 2 ); |
60 | layout->setSpacing( 4 ); | 61 | layout->setSpacing( 4 ); |
61 | 62 | ||
62 | // Create main tabbed control | 63 | // Create main tabbed control |
63 | mainWidget = new OTabWidget( this ); | 64 | mainWidget = new OTabWidget( this ); |
64 | 65 | ||
65 | // Default object pointers to null | 66 | // Default object pointers to null |
66 | ntpProcess = 0x0; | 67 | ntpProcess = 0x0; |
67 | ntpTab = 0x0; | 68 | ntpTab = 0x0; |
68 | 69 | ||
69 | // Add tab widgets | 70 | // Add tab widgets |
70 | mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) ); | 71 | mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) ); |
71 | mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) ); | 72 | mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) ); |
72 | mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) ); | 73 | mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) ); |
73 | mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) ); | 74 | mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) ); |
74 | Config config( "ntp" ); | 75 | Config config( "ntp" ); |
75 | config.setGroup( "settings" ); | 76 | config.setGroup( "settings" ); |
76 | slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) ); | 77 | slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) ); |
77 | slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) ); | 78 | slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) ); |
78 | 79 | ||
79 | mainWidget->setCurrentTab( tr( "Time" ) ); | 80 | mainWidget->setCurrentTab( tr( "Time" ) ); |
80 | layout->addWidget( mainWidget ); | 81 | layout->addWidget( mainWidget ); |
81 | 82 | ||
82 | // Create QCOP channel | 83 | connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), |
83 | QCopChannel *channel = new QCopChannel( "QPE/Application/netsystemtime", this ); | 84 | this, SLOT(slotQCopReceive(const QCString&, const QByteArray&)) ); |
84 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 85 | |
85 | this, SLOT(slotQCopReceive(const QCString&, const QByteArray&)) ); | ||
86 | 86 | ||
87 | // Create NTP socket | 87 | // Create NTP socket |
88 | ntpSock = new QSocket( this ); | 88 | ntpSock = new QSocket( this ); |
89 | connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); | 89 | connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); |
90 | slotProbeNTPServer(); | 90 | slotProbeNTPServer(); |
91 | 91 | ||
92 | // Create timer for automatic time lookups | 92 | // Create timer for automatic time lookups |
93 | ntpTimer = new QTimer( this ); | 93 | ntpTimer = new QTimer( this ); |
94 | 94 | ||
95 | // Connect everything together | 95 | // Connect everything together |
96 | connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); | 96 | connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); |
97 | connect( timeTab, SIGNAL(tzChanged(const QString &)), predictTab, SLOT(slotTZChanged(const QString &)) ); | 97 | connect( timeTab, SIGNAL(tzChanged(const QString &)), predictTab, SLOT(slotTZChanged(const QString &)) ); |
98 | connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) ); | 98 | connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) ); |
99 | connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime( int )) ); | 99 | connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime( int )) ); |
100 | connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat &)), | 100 | connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat &)), |
101 | timeTab, SLOT(slotDateFormatChanged(const DateFormat &)) ); | 101 | timeTab, SLOT(slotDateFormatChanged(const DateFormat &)) ); |
102 | connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) ); | 102 | connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) ); |
103 | connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) ); | 103 | connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) ); |
104 | connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) ); | 104 | connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) ); |
105 | connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) ); | 105 | connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) ); |
106 | connect( predictTab, SIGNAL(setTime(const QDateTime &)), this, SLOT(slotSetTime(const QDateTime &)) ); | 106 | connect( predictTab, SIGNAL(setTime(const QDateTime &)), this, SLOT(slotSetTime(const QDateTime &)) ); |
107 | 107 | ||
108 | // Do initial time server check | 108 | // Do initial time server check |
109 | slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); | 109 | slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); |
110 | slotCheckNtp( -1 ); | 110 | slotCheckNtp( -1 ); |
111 | 111 | ||
112 | // Display app | 112 | // Display app |
113 | showMaximized(); | 113 | //showMaximized(); |
114 | (void)new QPEDialogListener(this); | ||
114 | } | 115 | } |
115 | 116 | ||
116 | MainWindow::~MainWindow() | 117 | MainWindow::~MainWindow() |
117 | { | 118 | { |
118 | if ( ntpProcess ) | 119 | if ( ntpProcess ) |
119 | delete ntpProcess; | 120 | delete ntpProcess; |
120 | } | 121 | } |
121 | 122 | ||
122 | void MainWindow::accept() | 123 | void MainWindow::accept() |
123 | { | 124 | { |
124 | // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends) | 125 | // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends) |
125 | { | 126 | { |
126 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 127 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
127 | disableScreenSaver << 0 << 0 << 0; | 128 | disableScreenSaver << 0 << 0 << 0; |
128 | } | 129 | } |
129 | 130 | ||
130 | // Update the systemtime | 131 | // Update the systemtime |
131 | timeTab->saveSettings( TRUE ); | 132 | timeTab->saveSettings( TRUE ); |
132 | 133 | ||
133 | // Save format options | 134 | // Save format options |
134 | formatTab->saveSettings( TRUE ); | 135 | formatTab->saveSettings( TRUE ); |
135 | 136 | ||
136 | // Save settings options | 137 | // Save settings options |
137 | settingsTab->saveSettings(); | 138 | settingsTab->saveSettings(); |
@@ -144,83 +145,83 @@ void MainWindow::accept() | |||
144 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 145 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
145 | enableScreenSaver << -1 << -1 << -1; | 146 | enableScreenSaver << -1 << -1 << -1; |
146 | 147 | ||
147 | // Exit app | 148 | // Exit app |
148 | qApp->quit(); | 149 | qApp->quit(); |
149 | } | 150 | } |
150 | 151 | ||
151 | void MainWindow::reject() | 152 | void MainWindow::reject() |
152 | { | 153 | { |
153 | // Reset time settings | 154 | // Reset time settings |
154 | timeTab->saveSettings( FALSE ); | 155 | timeTab->saveSettings( FALSE ); |
155 | 156 | ||
156 | // Send notifications but do not save settings | 157 | // Send notifications but do not save settings |
157 | formatTab->saveSettings( FALSE ); | 158 | formatTab->saveSettings( FALSE ); |
158 | 159 | ||
159 | // Exit app | 160 | // Exit app |
160 | qApp->quit(); | 161 | qApp->quit(); |
161 | } | 162 | } |
162 | 163 | ||
163 | void MainWindow::runNTP() | 164 | void MainWindow::runNTP() |
164 | { | 165 | { |
165 | if ( !ntpDelayElapsed() && ntpInteractive ) | 166 | if ( !ntpDelayElapsed() && ntpInteractive ) |
166 | { | 167 | { |
167 | QString msg = tr( "You asked for a delay of %1 minutes, but only %2 minutes elapsed since last lookup.<br>Continue?" ).arg( QString::number( ntpDelay ) ).arg( QString::number( _lookupDiff / 60 ) ); | 168 | QString msg = tr( "You asked for a delay of %1 minutes, but only %2 minutes elapsed since last lookup.<br>Continue?" ).arg( QString::number( ntpDelay ) ).arg( QString::number( _lookupDiff / 60 ) ); |
168 | 169 | ||
169 | switch ( | 170 | switch ( |
170 | QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No ) | 171 | QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No ) |
171 | ) | 172 | ) |
172 | { | 173 | { |
173 | case QMessageBox::Yes: break; | 174 | case QMessageBox::Yes: break; |
174 | case QMessageBox::No: return; | 175 | case QMessageBox::No: return; |
175 | default: return; | 176 | default: return; |
176 | } | 177 | } |
177 | } | 178 | } |
178 | 179 | ||
179 | QString srv = settingsTab->ntpServer(); | 180 | QString srv = settingsTab->ntpServer(); |
180 | 181 | ||
181 | // Send information to time server tab if enabled | 182 | // Send information to time server tab if enabled |
182 | if ( ntpTabEnabled ) | 183 | if ( ntpTabEnabled ) |
183 | { | 184 | { |
184 | ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); | 185 | ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); |
185 | QString output = tr( "Running:\nntpdate " ); | 186 | QString output = tr( "Running:\nntpdate " ); |
186 | output.append( srv ); | 187 | output.append( srv ); |
187 | ntpTab->addNtpOutput( output ); | 188 | ntpTab->addNtpOutput( output ); |
188 | } | 189 | } |
189 | 190 | ||
190 | if ( !ntpProcess ) | 191 | if ( !ntpProcess ) |
191 | { | 192 | { |
192 | ntpProcess = new OProcess(); | 193 | ntpProcess = new OProcess(); |
193 | connect( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 194 | connect( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
194 | this, SLOT(slotNtpOutput(OProcess*,char*,int)) ); | 195 | this, SLOT(slotNtpOutput(OProcess*,char*,int)) ); |
195 | connect( ntpProcess, SIGNAL(processExited(OProcess*)), | 196 | connect( ntpProcess, SIGNAL(processExited(OProcess*)), |
196 | this, SLOT(slotNtpFinished(OProcess*)) ); | 197 | this, SLOT(slotNtpFinished(OProcess*)) ); |
197 | } | 198 | } |
198 | 199 | ||
199 | else | 200 | else |
200 | ntpProcess->clearArguments(); | 201 | ntpProcess->clearArguments(); |
201 | 202 | ||
202 | *ntpProcess << "ntpdate" << srv; | 203 | *ntpProcess << "ntpdate" << srv; |
203 | bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); | 204 | bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); |
204 | if ( !ret ) | 205 | if ( !ret ) |
205 | { | 206 | { |
206 | QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); | 207 | QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); |
207 | if ( ntpTabEnabled ) | 208 | if ( ntpTabEnabled ) |
208 | ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); | 209 | ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); |
209 | } | 210 | } |
210 | } | 211 | } |
211 | 212 | ||
212 | bool MainWindow::ntpDelayElapsed() | 213 | bool MainWindow::ntpDelayElapsed() |
213 | { | 214 | { |
214 | // Determine if time elapsed is greater than time delay | 215 | // Determine if time elapsed is greater than time delay |
215 | Config config( "ntp" ); | 216 | Config config( "ntp" ); |
216 | config.setGroup( "lookups" ); | 217 | config.setGroup( "lookups" ); |
217 | _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); | 218 | _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); |
218 | if ( _lookupDiff < 0 ) | 219 | if ( _lookupDiff < 0 ) |
219 | return true; | 220 | return true; |
220 | return ( _lookupDiff - ( ntpDelay * 60) ) > 0; | 221 | return ( _lookupDiff - ( ntpDelay * 60) ) > 0; |
221 | } | 222 | } |
222 | 223 | ||
223 | void MainWindow::slotSetTime( const QDateTime &dt ) | 224 | void MainWindow::slotSetTime( const QDateTime &dt ) |
224 | { | 225 | { |
225 | timeTab->setDateTime( dt ); | 226 | timeTab->setDateTime( dt ); |
226 | } | 227 | } |
@@ -276,90 +277,90 @@ void MainWindow::slotGetNTPTime() | |||
276 | void MainWindow::slotTimerGetNTPTime() | 277 | void MainWindow::slotTimerGetNTPTime() |
277 | { | 278 | { |
278 | ntpInteractive = FALSE; | 279 | ntpInteractive = FALSE; |
279 | runNTP(); | 280 | runNTP(); |
280 | } | 281 | } |
281 | 282 | ||
282 | void MainWindow::slotProbeNTPServer() | 283 | void MainWindow::slotProbeNTPServer() |
283 | { | 284 | { |
284 | ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); | 285 | ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); |
285 | } | 286 | } |
286 | 287 | ||
287 | void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) | 288 | void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) |
288 | { | 289 | { |
289 | QString output = QString( buffer ).left( buflen ); | 290 | QString output = QString( buffer ).left( buflen ); |
290 | ntpOutput.append( output ); | 291 | ntpOutput.append( output ); |
291 | 292 | ||
292 | if ( ntpTabEnabled ) | 293 | if ( ntpTabEnabled ) |
293 | ntpTab->addNtpOutput( output ); | 294 | ntpTab->addNtpOutput( output ); |
294 | } | 295 | } |
295 | 296 | ||
296 | void MainWindow::slotNtpFinished( OProcess *p ) | 297 | void MainWindow::slotNtpFinished( OProcess *p ) |
297 | { | 298 | { |
298 | QString output; | 299 | QString output; |
299 | QDateTime dt = QDateTime::currentDateTime(); | 300 | QDateTime dt = QDateTime::currentDateTime(); |
300 | 301 | ||
301 | // Verify run was successful | 302 | // Verify run was successful |
302 | if ( p->exitStatus() != 0 || !p->normalExit() ) | 303 | if ( p->exitStatus() != 0 || !p->normalExit() ) |
303 | { | 304 | { |
304 | if ( isVisible() && ntpInteractive ) | 305 | if ( isVisible() && ntpInteractive ) |
305 | { | 306 | { |
306 | output = tr( "Error while getting time from\n server: " ); | 307 | output = tr( "Error while getting time from\n server: " ); |
307 | output.append( settingsTab->ntpServer() ); | 308 | output.append( settingsTab->ntpServer() ); |
308 | QMessageBox::critical(this, tr( "Error" ), output ); | 309 | QMessageBox::critical(this, tr( "Error" ), output ); |
309 | } | 310 | } |
310 | // slotCheckNtp(-1); | 311 | // slotCheckNtp(-1); |
311 | return; | 312 | return; |
312 | } | 313 | } |
313 | 314 | ||
314 | // Set controls on time tab to new time value | 315 | // Set controls on time tab to new time value |
315 | timeTab->setDateTime( dt ); | 316 | timeTab->setDateTime( dt ); |
316 | 317 | ||
317 | // Write out lookup information | 318 | // Write out lookup information |
318 | Config config( "ntp" ); | 319 | Config config( "ntp" ); |
319 | config.setGroup( "lookups" ); | 320 | config.setGroup( "lookups" ); |
320 | int lastLookup = config.readNumEntry( "time", 0 ); | 321 | int lastLookup = config.readNumEntry( "time", 0 ); |
321 | int lookupCount = config.readNumEntry( "count", 0 ); | 322 | int lookupCount = config.readNumEntry( "count", 0 ); |
322 | bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); | 323 | bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); |
323 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 324 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
324 | config.writeEntry( "time", time ); | 325 | config.writeEntry( "time", time ); |
325 | 326 | ||
326 | // Calculate new time/time shift | 327 | // Calculate new time/time shift |
327 | QString _offset = "offset"; | 328 | QString _offset = "offset"; |
328 | QString _sec = "sec"; | 329 | QString _sec = "sec"; |
329 | QRegExp _reOffset = QRegExp( _offset ); | 330 | QRegExp _reOffset = QRegExp( _offset ); |
330 | QRegExp _reEndOffset = QRegExp( _sec ); | 331 | QRegExp _reEndOffset = QRegExp( _sec ); |
331 | int posOffset = _reOffset.match( ntpOutput ); | 332 | int posOffset = _reOffset.match( ntpOutput ); |
332 | int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); | 333 | int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); |
333 | posOffset += _offset.length() + 1; | 334 | posOffset += _offset.length() + 1; |
334 | QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); | 335 | QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); |
335 | 336 | ||
336 | float timeShift = diff.toFloat(); | 337 | float timeShift = diff.toFloat(); |
337 | if ( timeShift == 0.0 ) | 338 | if ( timeShift == 0.0 ) |
338 | return; | 339 | return; |
339 | int secsSinceLast = time - lastLookup; | 340 | int secsSinceLast = time - lastLookup; |
340 | output = tr( "%1 seconds").arg(QString::number( timeShift )); | 341 | output = tr( "%1 seconds").arg(QString::number( timeShift )); |
341 | 342 | ||
342 | // Display information on time server tab | 343 | // Display information on time server tab |
343 | if ( ntpTabEnabled ) | 344 | if ( ntpTabEnabled ) |
344 | { | 345 | { |
345 | ntpTab->setTimeShift( output ); | 346 | ntpTab->setTimeShift( output ); |
346 | ntpTab->setNewTime( dt.toString() ); | 347 | ntpTab->setNewTime( dt.toString() ); |
347 | } | 348 | } |
348 | 349 | ||
349 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) | 350 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) |
350 | { | 351 | { |
351 | QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); | 352 | QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); |
352 | config.setGroup( grpname ); | 353 | config.setGroup( grpname ); |
353 | lookupCount++; | 354 | lookupCount++; |
354 | predictTab->setShiftPerSec( timeShift / secsSinceLast ); | 355 | predictTab->setShiftPerSec( timeShift / secsSinceLast ); |
355 | config.writeEntry( "secsSinceLast", secsSinceLast ); | 356 | config.writeEntry( "secsSinceLast", secsSinceLast ); |
356 | config.writeEntry( "timeShift", QString::number( timeShift ) ); | 357 | config.writeEntry( "timeShift", QString::number( timeShift ) ); |
357 | config.setGroup( "lookups" ); | 358 | config.setGroup( "lookups" ); |
358 | config.writeEntry( "count", lookupCount ); | 359 | config.writeEntry( "count", lookupCount ); |
359 | config.writeEntry( "lastNtp", TRUE ); | 360 | config.writeEntry( "lastNtp", TRUE ); |
360 | } | 361 | } |
361 | } | 362 | } |
362 | 363 | ||
363 | void MainWindow::slotNTPDelayChanged( int delay ) | 364 | void MainWindow::slotNTPDelayChanged( int delay ) |
364 | { | 365 | { |
365 | ntpTimer->changeInterval( delay * 1000 * 60 ); | 366 | ntpTimer->changeInterval( delay * 1000 * 60 ); |
diff --git a/noncore/settings/netsystemtime/mainwindow.h b/noncore/settings/netsystemtime/mainwindow.h index fa94335..1cdbc1a 100644 --- a/noncore/settings/netsystemtime/mainwindow.h +++ b/noncore/settings/netsystemtime/mainwindow.h | |||
@@ -27,50 +27,51 @@ | |||
27 | */ | 27 | */ |
28 | 28 | ||
29 | #ifndef MAINWINDOW_H | 29 | #ifndef MAINWINDOW_H |
30 | #define MAINWINDOW_H | 30 | #define MAINWINDOW_H |
31 | 31 | ||
32 | #include <qdialog.h> | 32 | #include <qdialog.h> |
33 | 33 | ||
34 | class TimeTabWidget; | 34 | class TimeTabWidget; |
35 | class FormatTabWidget; | 35 | class FormatTabWidget; |
36 | class SettingsTabWidget; | 36 | class SettingsTabWidget; |
37 | class NTPTabWidget; | 37 | class NTPTabWidget; |
38 | class PredictTabWidget; | 38 | class PredictTabWidget; |
39 | 39 | ||
40 | class OProcess; | 40 | class OProcess; |
41 | class OTabWidget; | 41 | class OTabWidget; |
42 | class QDateTime; | 42 | class QDateTime; |
43 | class QSocket; | 43 | class QSocket; |
44 | class QTimer; | 44 | class QTimer; |
45 | 45 | ||
46 | class MainWindow : public QDialog | 46 | class MainWindow : public QDialog |
47 | { | 47 | { |
48 | Q_OBJECT | 48 | Q_OBJECT |
49 | 49 | ||
50 | public: | 50 | public: |
51 | MainWindow(); | 51 | MainWindow( QWidget *parent = 0, const char *name = 0, bool modal = FALSE,WFlags f = 0); |
52 | ~MainWindow(); | 52 | ~MainWindow(); |
53 | static QString appName() { return QString::fromLatin1("systemtime"); } | ||
53 | 54 | ||
54 | protected: | 55 | protected: |
55 | void accept(); | 56 | void accept(); |
56 | void reject(); | 57 | void reject(); |
57 | 58 | ||
58 | private: | 59 | private: |
59 | OTabWidget *mainWidget; | 60 | OTabWidget *mainWidget; |
60 | 61 | ||
61 | TimeTabWidget *timeTab; | 62 | TimeTabWidget *timeTab; |
62 | FormatTabWidget *formatTab; | 63 | FormatTabWidget *formatTab; |
63 | SettingsTabWidget *settingsTab; | 64 | SettingsTabWidget *settingsTab; |
64 | NTPTabWidget *ntpTab; | 65 | NTPTabWidget *ntpTab; |
65 | PredictTabWidget *predictTab; | 66 | PredictTabWidget *predictTab; |
66 | 67 | ||
67 | bool ntpTabEnabled; | 68 | bool ntpTabEnabled; |
68 | bool predictTabEnabled; | 69 | bool predictTabEnabled; |
69 | 70 | ||
70 | OProcess *ntpProcess; | 71 | OProcess *ntpProcess; |
71 | QTimer *ntpTimer; | 72 | QTimer *ntpTimer; |
72 | QSocket *ntpSock; | 73 | QSocket *ntpSock; |
73 | int ntpDelay; | 74 | int ntpDelay; |
74 | bool ntpInteractive; | 75 | bool ntpInteractive; |
75 | QString ntpOutput; | 76 | QString ntpOutput; |
76 | int _lookupDiff; | 77 | int _lookupDiff; |
diff --git a/noncore/settings/netsystemtime/netsystemtime.pro b/noncore/settings/netsystemtime/netsystemtime.pro index 7a12dd1..2140f2e 100644 --- a/noncore/settings/netsystemtime/netsystemtime.pro +++ b/noncore/settings/netsystemtime/netsystemtime.pro | |||
@@ -1,44 +1,41 @@ | |||
1 | TEMPLATE= app | 1 | CONFIG = qt warn_on release quick-app |
2 | CONFIG = qt warn_on debug | ||
3 | #CONFIG = qt warn_on release | ||
4 | HEADERS = mainwindow.h \ | 2 | HEADERS = mainwindow.h \ |
5 | timetabwidget.h \ | 3 | timetabwidget.h \ |
6 | formattabwidget.h \ | 4 | formattabwidget.h \ |
7 | settingstabwidget.h \ | 5 | settingstabwidget.h \ |
8 | predicttabwidget.h \ | 6 | predicttabwidget.h \ |
9 | ntptabwidget.h | 7 | ntptabwidget.h |
10 | SOURCES = main.cpp \ | 8 | SOURCES = main.cpp \ |
11 | mainwindow.cpp \ | 9 | mainwindow.cpp \ |
12 | timetabwidget.cpp \ | 10 | timetabwidget.cpp \ |
13 | formattabwidget.cpp \ | 11 | formattabwidget.cpp \ |
14 | settingstabwidget.cpp \ | 12 | settingstabwidget.cpp \ |
15 | predicttabwidget.cpp \ | 13 | predicttabwidget.cpp \ |
16 | ntptabwidget.cpp | 14 | ntptabwidget.cpp |
17 | INCLUDEPATH+= $(OPIEDIR)/include | 15 | INCLUDEPATH+= $(OPIEDIR)/include |
18 | DEPENDPATH+= $(OPIEDIR)/include | 16 | DEPENDPATH+= $(OPIEDIR)/include |
19 | LIBS += -lqpe -lopie | 17 | LIBS += -lqpe -lopie |
20 | INTERFACES= | 18 | |
21 | DESTDIR = $(OPIEDIR)/bin | ||
22 | TARGET = systemtime | 19 | TARGET = systemtime |
23 | 20 | ||
24 | TRANSLATIONS = ../../../i18n/de/systemtime.ts \ | 21 | TRANSLATIONS = ../../../i18n/de/systemtime.ts \ |
25 | ../../../i18n/nl/systemtime.ts \ | 22 | ../../../i18n/nl/systemtime.ts \ |
26 | ../../../i18n/da/systemtime.ts \ | 23 | ../../../i18n/da/systemtime.ts \ |
27 | ../../../i18n/xx/systemtime.ts \ | 24 | ../../../i18n/xx/systemtime.ts \ |
28 | ../../../i18n/en/systemtime.ts \ | 25 | ../../../i18n/en/systemtime.ts \ |
29 | ../../../i18n/es/systemtime.ts \ | 26 | ../../../i18n/es/systemtime.ts \ |
30 | ../../../i18n/fr/systemtime.ts \ | 27 | ../../../i18n/fr/systemtime.ts \ |
31 | ../../../i18n/hu/systemtime.ts \ | 28 | ../../../i18n/hu/systemtime.ts \ |
32 | ../../../i18n/ja/systemtime.ts \ | 29 | ../../../i18n/ja/systemtime.ts \ |
33 | ../../../i18n/ko/systemtime.ts \ | 30 | ../../../i18n/ko/systemtime.ts \ |
34 | ../../../i18n/no/systemtime.ts \ | 31 | ../../../i18n/no/systemtime.ts \ |
35 | ../../../i18n/pl/systemtime.ts \ | 32 | ../../../i18n/pl/systemtime.ts \ |
36 | ../../../i18n/pt/systemtime.ts \ | 33 | ../../../i18n/pt/systemtime.ts \ |
37 | ../../../i18n/pt_BR/systemtime.ts \ | 34 | ../../../i18n/pt_BR/systemtime.ts \ |
38 | ../../../i18n/sl/systemtime.ts \ | 35 | ../../../i18n/sl/systemtime.ts \ |
39 | ../../../i18n/zh_CN/systemtime.ts \ | 36 | ../../../i18n/zh_CN/systemtime.ts \ |
40 | ../../../i18n/zh_TW/systemtime.ts | 37 | ../../../i18n/zh_TW/systemtime.ts |
41 | 38 | ||
42 | 39 | ||
43 | 40 | ||
44 | include ( $(OPIEDIR)/include.pro ) | 41 | include ( $(OPIEDIR)/include.pro ) |