author | drw <drw> | 2003-04-13 22:32:47 (UTC) |
---|---|---|
committer | drw <drw> | 2003-04-13 22:32:47 (UTC) |
commit | 166ac140f8e01369a5d281c2918b0f8b9045f8e5 (patch) (unidiff) | |
tree | 672cbb8318703b6cedc7f83fb72c058d0b592c9e /noncore/settings/netsystemtime/settime.cpp | |
parent | f47258125bac368987a90ca49a118721ecbc3a8b (diff) | |
download | opie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.zip opie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.tar.gz opie-166ac140f8e01369a5d281c2918b0f8b9045f8e5.tar.bz2 |
Revamped NetSystemTime! Changes include: 1. improved UI (e.g. ok/cancel work, timezone correctly changes date, new layout better suited for running in landscape mode, etc.) 2. improved code organization 3. smaller executable
Diffstat (limited to 'noncore/settings/netsystemtime/settime.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 533 |
1 files changed, 0 insertions, 533 deletions
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp deleted file mode 100644 index 6a28989..0000000 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/dev/null | |||
@@ -1,533 +0,0 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include "settime.h" | ||
22 | |||
23 | #include <qpe/alarmserver.h> | ||
24 | #include <qpe/qpeapplication.h> | ||
25 | #include <qpe/config.h> | ||
26 | #include <qpe/datebookdb.h> | ||
27 | #include <qpe/datebookmonth.h> | ||
28 | #include <qpe/global.h> | ||
29 | #include <qpe/resource.h> | ||
30 | #include <qpe/timeconversion.h> | ||
31 | #include <qpe/tzselect.h> | ||
32 | #include <qpe/timestring.h> | ||
33 | #include <qpe/qpedialog.h> | ||
34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | ||
35 | #include <qpe/qcopenvelope_qws.h> | ||
36 | #endif | ||
37 | |||
38 | #include <qtimer.h> | ||
39 | #include <qbuttongroup.h> | ||
40 | #include <qcheckbox.h> | ||
41 | #include <qlabel.h> | ||
42 | #include <qlayout.h> | ||
43 | #include <qradiobutton.h> | ||
44 | #include <qspinbox.h> | ||
45 | #include <qtoolbutton.h> | ||
46 | #include <qwindowsystem_qws.h> | ||
47 | #include <qcombobox.h> | ||
48 | |||
49 | #include <sys/time.h> | ||
50 | #include <time.h> | ||
51 | #include <stdlib.h> | ||
52 | #include <stdio.h> | ||
53 | |||
54 | |||
55 | SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) | ||
56 | : NtpBase( parent, name, true, f ) | ||
57 | { | ||
58 | setCaption( tr("System Time") ); | ||
59 | _oldTimeZone=""; | ||
60 | QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 ); | ||
61 | |||
62 | // TextLabelMainPredTime = new QLabel( FrameSystemTime ); | ||
63 | // vb->addWidget( TextLabelMainPredTime, 1, 0 ); | ||
64 | |||
65 | timeButton = new SetTime( FrameSystemTime ); | ||
66 | vb->addWidget( timeButton ); | ||
67 | |||
68 | QHBoxLayout *db = new QHBoxLayout( vb ); | ||
69 | QLabel *dateLabel = new QLabel( tr("Date"), FrameSystemTime ); | ||
70 | db->addWidget( dateLabel, 1 ); | ||
71 | dateButton = new DateButton( TRUE, FrameSystemTime ); | ||
72 | db->addWidget( dateButton, 2 ); | ||
73 | |||
74 | ButtonSetTime = new QPushButton( FrameSystemTime ); | ||
75 | vb->addWidget( ButtonSetTime, 1, 0 ); | ||
76 | |||
77 | QFrame *hline = new QFrame( FrameSystemTime ); | ||
78 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | ||
79 | vb->addWidget( hline ); | ||
80 | |||
81 | QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" ); | ||
82 | |||
83 | QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" ); | ||
84 | lblZone->setMaximumSize( lblZone->sizeHint() ); | ||
85 | hb->addWidget( lblZone ); | ||
86 | |||
87 | tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" ); | ||
88 | tz->setMinimumSize( tz->sizeHint() ); | ||
89 | hb->addWidget( tz ); | ||
90 | |||
91 | hline = new QFrame( FrameSystemTime ); | ||
92 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | ||
93 | vb->addWidget( hline ); | ||
94 | |||
95 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | ||
96 | vb->addItem( spacer ); | ||
97 | |||
98 | Config config("qpe"); | ||
99 | config.setGroup( "Time" ); | ||
100 | |||
101 | QHBoxLayout *hb1 = new QHBoxLayout( vb ); | ||
102 | |||
103 | QLabel *l = new QLabel( tr("Time format"), FrameSystemTime ); | ||
104 | hb1->addWidget( l, 1 ); | ||
105 | |||
106 | |||
107 | ampmCombo = new QComboBox( FrameSystemTime ); | ||
108 | ampmCombo->insertItem( tr("24 hour"), 0 ); | ||
109 | ampmCombo->insertItem( tr("12 hour"), 1 ); | ||
110 | hb1->addWidget( ampmCombo, 2 ); | ||
111 | |||
112 | int show12hr = config.readBoolEntry("AMPM") ? 1 : 0; | ||
113 | ampmCombo->setCurrentItem( show12hr ); | ||
114 | timeButton->show12hourTime( show12hr ); | ||
115 | |||
116 | connect(ampmCombo, SIGNAL(activated(int)), | ||
117 | timeButton, SLOT(show12hourTime(int))); | ||
118 | |||
119 | |||
120 | |||
121 | QHBoxLayout *hb2 = new QHBoxLayout( vb ); | ||
122 | l = new QLabel( tr("Weeks start on" ), FrameSystemTime ); | ||
123 | //l->setAlignment( AlignRight | AlignVCenter ); | ||
124 | hb2->addWidget( l, 1 ); | ||
125 | |||
126 | weekStartCombo = new QComboBox( FrameSystemTime ); | ||
127 | weekStartCombo->insertItem( tr("Sunday"), 0 ); | ||
128 | weekStartCombo->insertItem( tr("Monday"), 1 ); | ||
129 | |||
130 | hb2->addWidget( weekStartCombo, 2 ); | ||
131 | int startMonday = config.readBoolEntry("MONDAY") ? 1 : 0; | ||
132 | dateButton->setWeekStartsMonday( startMonday ); | ||
133 | weekStartCombo->setCurrentItem( startMonday ); | ||
134 | |||
135 | connect( weekStartCombo, SIGNAL( activated(int)), | ||
136 | dateButton, SLOT(setWeekStartsMonday(int))); | ||
137 | |||
138 | |||
139 | QHBoxLayout *hb3 = new QHBoxLayout( vb ); | ||
140 | l = new QLabel( tr("Date format" ), FrameSystemTime ); | ||
141 | hb3->addWidget( l, 1 ); | ||
142 | dateFormatCombo = new QComboBox( FrameSystemTime ); | ||
143 | hb3->addWidget( dateFormatCombo, 2 ); | ||
144 | |||
145 | config.setGroup( "Date" ); | ||
146 | DateFormat df(QChar(config.readEntry("Separator", "/")[0]), | ||
147 | (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), | ||
148 | (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); | ||
149 | |||
150 | int currentdf = 0; | ||
151 | date_formats[0] = DateFormat('/', DateFormat::MonthDayYear); | ||
152 | dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) ); | ||
153 | date_formats[1] = DateFormat('.', DateFormat::DayMonthYear); | ||
154 | if (df == date_formats[1]) | ||
155 | currentdf = 1; | ||
156 | dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) ); | ||
157 | date_formats[2] = DateFormat('-', DateFormat::YearMonthDay, | ||
158 | DateFormat::DayMonthYear); | ||
159 | if (df == date_formats[2]) | ||
160 | currentdf = 2; | ||
161 | dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601 | ||
162 | date_formats[3] = DateFormat('/', DateFormat::DayMonthYear); | ||
163 | if (df == date_formats[3]) | ||
164 | currentdf = 3; | ||
165 | dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) ); | ||
166 | |||
167 | dateFormatCombo->setCurrentItem( currentdf ); | ||
168 | dateButton->setDateFormat( df ); | ||
169 | |||
170 | connect( dateFormatCombo, SIGNAL( activated(int)), | ||
171 | SLOT(formatChanged(int))); | ||
172 | |||
173 | QHBoxLayout *hb4 = new QHBoxLayout( vb ); | ||
174 | l = new QLabel( tr("Applet format" ), FrameSystemTime ); | ||
175 | hb4->addWidget( l, 1 ); | ||
176 | |||
177 | clockAppletCombo = new QComboBox( FrameSystemTime ); | ||
178 | clockAppletCombo->insertItem( tr("hh:mm"), 0 ); | ||
179 | clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); | ||
180 | clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); | ||
181 | |||
182 | hb4->addWidget( clockAppletCombo, 2 ); | ||
183 | int clockApplet = config.readNumEntry("ClockApplet",0); | ||
184 | clockAppletCombo->setCurrentItem( clockApplet ); | ||
185 | |||
186 | vb->addStretch( 0 ); | ||
187 | |||
188 | // hline = new QFrame( FrameSystemTime ); | ||
189 | // hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | ||
190 | // vb->addWidget( hline ); | ||
191 | // | ||
192 | // ButtonSetTime = new QPushButton( FrameSystemTime ); | ||
193 | // vb->addWidget( ButtonSetTime, 1, 0 ); | ||
194 | |||
195 | |||
196 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), | ||
197 | timeButton, SLOT( slotTzChange( const QString& ) ) ); | ||
198 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), | ||
199 | SLOT( tzChange( const QString& ) ) ); | ||
200 | |||
201 | // QObject::connect( weekStartCombo, SIGNAL( activated ( int )), | ||
202 | // SLOT(updateSystem(int ) )); | ||
203 | // QObject::connect( ampmCombo, SIGNAL( activated ( int )), | ||
204 | // SLOT(updateSystem(int ) )); | ||
205 | // QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), | ||
206 | // SLOT(updateSystem(int ) )); | ||
207 | // QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), | ||
208 | // SLOT(updateSystem(int ) )); | ||
209 | } | ||
210 | |||
211 | SetDateTime::~SetDateTime() | ||
212 | { | ||
213 | } | ||
214 | |||
215 | void SetDateTime::writeSettings() | ||
216 | { | ||
217 | Config config("qpe"); | ||
218 | config.setGroup( "Time" ); | ||
219 | config.writeEntry( "AMPM", ampmCombo->currentItem() ); | ||
220 | config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); | ||
221 | config.setGroup( "Date" ); | ||
222 | DateFormat df = date_formats[dateFormatCombo->currentItem()]; | ||
223 | config.writeEntry( "Separator", QString(df.separator())); | ||
224 | config.writeEntry( "ShortOrder", df.shortOrder()); | ||
225 | config.writeEntry( "LongOrder", df.longOrder()); | ||
226 | config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() ); | ||
227 | |||
228 | Config lconfig("locale"); | ||
229 | lconfig.setGroup( "Location" ); | ||
230 | lconfig.writeEntry( "Timezone", tz->currentZone() ); | ||
231 | |||
232 | } | ||
233 | |||
234 | void SetDateTime::commitTime() | ||
235 | { | ||
236 | Config cfg("ntp",Config::User); | ||
237 | cfg.setGroup("lookups"); | ||
238 | cfg.writeEntry("lastNtp",false); | ||
239 | tz->setFocus(); | ||
240 | // Need to process the QCOP event generated above before proceeding | ||
241 | qApp->processEvents(); | ||
242 | |||
243 | // before we progress further, set our TZ! | ||
244 | setenv( "TZ", tz->currentZone(), 1 ); | ||
245 | // now set the time... | ||
246 | QDateTime dt( dateButton->date(), timeButton->time() ); | ||
247 | |||
248 | if ( dt.isValid() ) setTime(dt); | ||
249 | } | ||
250 | |||
251 | void SetDateTime::setTime(QDateTime dt) | ||
252 | { | ||
253 | // really turn off the screensaver before doing anything | ||
254 | { | ||
255 | // Needs to be encased in { } so that it deconstructs and sends | ||
256 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | ||
257 | disableScreenSaver << 0 << 0 << 0; | ||
258 | } | ||
259 | Config cfg("ntp",Config::User); | ||
260 | cfg.setGroup("correction"); | ||
261 | int t = TimeConversion::toUTC(dt); | ||
262 | struct timeval myTv; | ||
263 | myTv.tv_sec = t; | ||
264 | cfg.writeEntry("time", t ); | ||
265 | myTv.tv_usec = 0; | ||
266 | |||
267 | if ( myTv.tv_sec != -1 ) | ||
268 | ::settimeofday( &myTv, 0 ); | ||
269 | Global::writeHWClock(); | ||
270 | // since time has changed quickly load in the datebookdb | ||
271 | // to allow the alarm server to get a better grip on itself | ||
272 | // (example re-trigger alarms for when we travel back in time) | ||
273 | DateBookDB db; | ||
274 | //QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); | ||
275 | //timeApplet << ""; | ||
276 | // Restore screensaver | ||
277 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | ||
278 | enableScreenSaver << -1 << -1 << -1; | ||
279 | } | ||
280 | |||
281 | void SetDateTime::updateSystem() | ||
282 | { | ||
283 | // really turn off the screensaver before doing anything | ||
284 | { | ||
285 | // Needs to be encased in { } so that it deconstructs and sends | ||
286 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | ||
287 | disableScreenSaver << 0 << 0 << 0; | ||
288 | } | ||
289 | qDebug("SetDateTime::updateSystem()"); | ||
290 | writeSettings(); | ||
291 | |||
292 | // set the timezone for everyone else... | ||
293 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | ||
294 | setTimeZone << tz->currentZone(); | ||
295 | |||
296 | // AM/PM setting and notify time changed | ||
297 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); | ||
298 | setClock << ampmCombo->currentItem(); | ||
299 | |||
300 | // Notify everyone what day we prefer to start the week on. | ||
301 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); | ||
302 | setWeek << weekStartCombo->currentItem(); | ||
303 | |||
304 | // Notify everyone what date format to use | ||
305 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); | ||
306 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; | ||
307 | |||
308 | // Restore screensaver | ||
309 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | ||
310 | enableScreenSaver << -1 << -1 << -1; | ||
311 | // since time has changed quickly load in the datebookdb | ||
312 | // to allow the alarm server to get a better grip on itself | ||
313 | // (example re-trigger alarms for when we travel back in time) | ||
314 | DateBookDB db; | ||
315 | |||
316 | } | ||
317 | |||
318 | void SetDateTime::tzChange( const QString &tz ) | ||
319 | { | ||
320 | // set the TZ get the time and leave gracefully... | ||
321 | _oldTimeZone = getenv( "TZ" ); | ||
322 | setenv( "TZ", tz, 1 ); | ||
323 | |||
324 | QDate d = QDate::currentDate(); | ||
325 | // reset the time. | ||
326 | if ( !_oldTimeZone.isNull() ) { | ||
327 | setenv( "TZ", _oldTimeZone, 1 ); | ||
328 | } | ||
329 | dateButton->setDate( d ); | ||
330 | updateSystem(); | ||
331 | } | ||
332 | |||
333 | void SetDateTime::formatChanged(int i) | ||
334 | { | ||
335 | dateButton->setDateFormat(date_formats[i]); | ||
336 | } | ||
337 | |||
338 | static const int ValueAM = 0; | ||
339 | static const int ValuePM = 1; | ||
340 | |||
341 | |||
342 | |||
343 | SetTime::SetTime( QWidget *parent, const char *name ) | ||
344 | : QWidget( parent, name ) | ||
345 | { | ||
346 | clock = new QTimer(this, "clock" ); | ||
347 | connect(clock, SIGNAL( timeout() ), SLOT(slotClockTick()) ); | ||
348 | clock->start( 1000 * 60 ); | ||
349 | |||
350 | use12hourTime = FALSE; | ||
351 | |||
352 | _time = QDateTime::currentDateTime(); | ||
353 | hour = _time.time().hour(); | ||
354 | minute = _time.time().minute(); | ||
355 | |||
356 | QHBoxLayout *hb2 = new QHBoxLayout( this ); | ||
357 | hb2->setSpacing( 3 ); | ||
358 | |||
359 | QLabel *l = new QLabel( tr("Hour"), this ); | ||
360 | // l->setAlignment( AlignRight | AlignVCenter ); | ||
361 | hb2->addWidget( l ); | ||
362 | |||
363 | sbHour = new QSpinBox( this ); | ||
364 | sbHour->setMinimumWidth( 30 ); | ||
365 | if(use12hourTime) { | ||
366 | sbHour->setMinValue(1); | ||
367 | sbHour->setMaxValue( 12 ); | ||
368 | int show_hour = hour; | ||
369 | if (hour > 12) | ||
370 | show_hour -= 12; | ||
371 | if (show_hour == 0) | ||
372 | show_hour = 12; | ||
373 | |||
374 | sbHour->setValue( show_hour ); | ||
375 | } else { | ||
376 | sbHour->setMinValue( 0 ); | ||
377 | sbHour->setMaxValue( 23 ); | ||
378 | sbHour->setValue( hour ); | ||
379 | } | ||
380 | sbHour->setWrapping(TRUE); | ||
381 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); | ||
382 | hb2->addWidget( sbHour ); | ||
383 | |||
384 | hb2->addStretch( 1 ); | ||
385 | |||
386 | l = new QLabel( tr("Minute"), this ); | ||
387 | //l->setAlignment( AlignRight | AlignVCenter ); | ||
388 | hb2->addWidget( l ); | ||
389 | |||
390 | sbMin = new QSpinBox( this ); | ||
391 | sbMin->setMinValue( 0 ); | ||
392 | sbMin->setMaxValue( 59 ); | ||
393 | sbMin->setWrapping(TRUE); | ||
394 | sbMin->setValue( minute ); | ||
395 | sbMin->setMinimumWidth( 30 ); | ||
396 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); | ||
397 | hb2->addWidget( sbMin ); | ||
398 | |||
399 | hb2->addStretch( 1 ); | ||
400 | |||
401 | ampm = new QComboBox( this ); | ||
402 | ampm->insertItem( tr("AM"), ValueAM ); | ||
403 | ampm->insertItem( tr("PM"), ValuePM ); | ||
404 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); | ||
405 | hb2->addWidget( ampm ); | ||
406 | |||
407 | hb2->addStretch( 1 ); | ||
408 | |||
409 | } | ||
410 | |||
411 | QTime SetTime::time() const | ||
412 | { | ||
413 | return QTime( hour, minute, 0 ); | ||
414 | } | ||
415 | |||
416 | void SetTime::hourChanged( int value ) | ||
417 | { | ||
418 | if(use12hourTime) { | ||
419 | int realhour = value; | ||
420 | if (realhour == 12) | ||
421 | realhour = 0; | ||
422 | if (ampm->currentItem() == ValuePM ) | ||
423 | realhour += 12; | ||
424 | hour = realhour; | ||
425 | } else | ||
426 | hour = value; | ||
427 | } | ||
428 | |||
429 | void SetTime::minuteChanged( int value ) | ||
430 | { | ||
431 | minute = value; | ||
432 | } | ||
433 | |||
434 | void SetTime::show12hourTime( int on ) | ||
435 | { | ||
436 | use12hourTime = on; | ||
437 | ampm->setEnabled(on); | ||
438 | |||
439 | int show_hour = hour; | ||
440 | if ( on ) { | ||
441 | /* this might change the value of hour */ | ||
442 | sbHour->setMinValue(1); | ||
443 | sbHour->setMaxValue( 12 ); | ||
444 | |||
445 | /* so use one we saved earlier */ | ||
446 | if (show_hour >= 12) { | ||
447 | show_hour -= 12; | ||
448 | ampm->setCurrentItem( ValuePM ); | ||
449 | } else { | ||
450 | ampm->setCurrentItem( ValueAM ); | ||
451 | } | ||
452 | if (show_hour == 0) | ||
453 | show_hour = 12; | ||
454 | |||
455 | } else { | ||
456 | sbHour->setMinValue( 0 ); | ||
457 | sbHour->setMaxValue( 23 ); | ||
458 | } | ||
459 | |||
460 | |||
461 | sbHour->setValue( show_hour ); | ||
462 | } | ||
463 | |||
464 | void SetTime::checkedPM( int c ) | ||
465 | { | ||
466 | int show_hour = sbHour->value(); | ||
467 | if (show_hour == 12) | ||
468 | show_hour = 0; | ||
469 | |||
470 | if ( c == ValuePM ) | ||
471 | show_hour += 12; | ||
472 | |||
473 | hour = show_hour; | ||
474 | } | ||
475 | |||
476 | void SetTime::slotTzChange( const QString &tz ) | ||
477 | { | ||
478 | // set the TZ get the time and leave gracefully... | ||
479 | QString strSave; | ||
480 | strSave = getenv( "TZ" ); | ||
481 | setenv( "TZ", tz, 1 ); | ||
482 | |||
483 | QTime t = QTime::currentTime(); | ||
484 | // reset the time. | ||
485 | if ( !strSave.isNull() ) { | ||
486 | setenv( "TZ", strSave, 1 ); | ||
487 | } | ||
488 | |||
489 | // just set the spinboxes and let it propage through | ||
490 | if(use12hourTime) { | ||
491 | int show_hour = t.hour(); | ||
492 | if (t.hour() >= 12) { | ||
493 | show_hour -= 12; | ||
494 | ampm->setCurrentItem( ValuePM ); | ||
495 | } else { | ||
496 | ampm->setCurrentItem( ValueAM ); | ||
497 | } | ||
498 | if (show_hour == 0) | ||
499 | show_hour = 12; | ||
500 | sbHour->setValue( show_hour ); | ||
501 | } else { | ||
502 | sbHour->setValue( t.hour() ); | ||
503 | } | ||
504 | sbMin->setValue( t.minute() ); | ||
505 | } | ||
506 | |||
507 | void SetTime::setTime( QDateTime dt ) | ||
508 | { | ||
509 | _time = dt; | ||
510 | QTime t = dt.time(); | ||
511 | // just set the spinboxes and let it propage through | ||
512 | if(use12hourTime) { | ||
513 | int show_hour = t.hour(); | ||
514 | if (t.hour() >= 12) { | ||
515 | show_hour -= 12; | ||
516 | ampm->setCurrentItem( ValuePM ); | ||
517 | } else { | ||
518 | ampm->setCurrentItem( ValueAM ); | ||
519 | } | ||
520 | if (show_hour == 0) | ||
521 | show_hour = 12; | ||
522 | sbHour->setValue( show_hour ); | ||
523 | } else { | ||
524 | sbHour->setValue( t.hour() ); | ||
525 | } | ||
526 | sbMin->setValue( t.minute() ); | ||
527 | } | ||
528 | |||
529 | void SetTime::slotClockTick() | ||
530 | { | ||
531 | setTime( _time.addSecs(60) ); | ||
532 | qDebug("SetTime::slotClockTick %s",_time.toString().latin1()); | ||
533 | } | ||