summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/timetabwidget.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/settings/netsystemtime/timetabwidget.cpp b/noncore/settings/netsystemtime/timetabwidget.cpp
index 895514b..e6fcf7f 100644
--- a/noncore/settings/netsystemtime/timetabwidget.cpp
+++ b/noncore/settings/netsystemtime/timetabwidget.cpp
@@ -1,318 +1,318 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4 Copyright (C) Opie Team <opie-devel@handhelds.org> 4 Copyright (C) Opie Team <opie-devel@handhelds.org>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17 : ..    .:,     . . . without even the implied warranty of 17 : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22:     =  ...= . :.=- 22:     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29*/ 29*/
30 30
31#include "timetabwidget.h" 31#include "timetabwidget.h"
32 32
33#include <opie2/oresource.h> 33#include <opie2/oresource.h>
34 34
35#include <qpe/applnk.h> 35#include <qpe/applnk.h>
36#include <qpe/config.h> 36#include <qpe/config.h>
37#include <qpe/datebookmonth.h> 37#include <qpe/datebookmonth.h>
38#include <qpe/global.h> 38#include <qpe/global.h>
39#include <qpe/tzselect.h> 39#include <qpe/tzselect.h>
40 40
41#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 41#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
42#include <qpe/qcopenvelope_qws.h> 42#include <qpe/qcopenvelope_qws.h>
43#endif 43#endif
44 44
45#include <qcombobox.h> 45#include <qcombobox.h>
46#include <qdatetime.h> 46#include <qdatetime.h>
47#include <qframe.h> 47#include <qframe.h>
48#include <qlabel.h> 48#include <qlabel.h>
49#include <qlayout.h> 49#include <qlayout.h>
50#include <qpushbutton.h> 50#include <qpushbutton.h>
51#include <qscrollview.h> 51#include <qscrollview.h>
52#include <qspinbox.h> 52#include <qspinbox.h>
53#include <qmessagebox.h> 53#include <qmessagebox.h>
54#include <qfile.h> 54#include <qfile.h>
55 55
56#include <stdlib.h> 56#include <stdlib.h>
57#include <sys/time.h> 57#include <sys/time.h>
58 58
59static const int ValueAM = 0; 59static const int ValueAM = 0;
60static const int ValuePM = 1; 60static const int ValuePM = 1;
61 61
62TimeTabWidget::TimeTabWidget( QWidget *parent ) 62TimeTabWidget::TimeTabWidget( QWidget *parent )
63 : QWidget( parent, 0x0, 0 ) 63 : QWidget( parent, 0x0, 0 )
64{ 64{
65 // Synchronize HW clock to systemtime 65 // Synchronize HW clock to systemtime
66 // This app will update systemtime 66 // This app will update systemtime
67 // - if Cancel is clicked, will reset systemtime to HW clock's time 67 // - if Cancel is clicked, will reset systemtime to HW clock's time
68 // - if Ok is clicked, will leave systemtime as is 68 // - if Ok is clicked, will leave systemtime as is
69 system("/sbin/hwclock --systohc --utc"); 69 system("/sbin/hwclock --systohc --utc");
70 70
71 QVBoxLayout *tmpvb = new QVBoxLayout( this ); 71 QVBoxLayout *tmpvb = new QVBoxLayout( this );
72 QScrollView *sv = new QScrollView( this ); 72 QScrollView *sv = new QScrollView( this );
73 tmpvb->addWidget( sv, 0, 0 ); 73 tmpvb->addWidget( sv, 0, 0 );
74 sv->setResizePolicy( QScrollView::AutoOneFit ); 74 sv->setResizePolicy( QScrollView::AutoOneFit );
75 sv->setFrameStyle( QFrame::NoFrame ); 75 sv->setFrameStyle( QFrame::NoFrame );
76 QWidget *container = new QWidget( sv->viewport() ); 76 QWidget *container = new QWidget( sv->viewport() );
77 sv->addChild( container ); 77 sv->addChild( container );
78 78
79 QGridLayout *layout = new QGridLayout( container ); 79 QGridLayout *layout = new QGridLayout( container );
80 layout->setMargin( 2 ); 80 layout->setMargin( 2 );
81 layout->setSpacing( 4 ); 81 layout->setSpacing( 4 );
82 82
83 // Hours 83 // Hours
84 layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 ); 84 layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 );
85 sbHour = new QSpinBox( container ); 85 sbHour = new QSpinBox( container );
86 sbHour->setWrapping( TRUE ); 86 sbHour->setWrapping( TRUE );
87 layout->addMultiCellWidget( sbHour, 2, 2, 0, 1 ); 87 layout->addMultiCellWidget( sbHour, 2, 2, 0, 1 );
88 88
89 // Minutes 89 // Minutes
90 layout->addMultiCellWidget( new QLabel( tr( "Minute" ), container ), 1, 1, 2, 3 ); 90 layout->addMultiCellWidget( new QLabel( tr( "Minute" ), container ), 1, 1, 2, 3 );
91 sbMin = new QSpinBox( container ); 91 sbMin = new QSpinBox( container );
92 sbMin->setWrapping( TRUE ); 92 sbMin->setWrapping( TRUE );
93 sbMin->setMinValue( 0 ); 93 sbMin->setMinValue( 0 );
94 sbMin->setMaxValue( 59 ); 94 sbMin->setMaxValue( 59 );
95 layout->addMultiCellWidget( sbMin, 2, 2, 2, 3 ); 95 layout->addMultiCellWidget( sbMin, 2, 2, 2, 3 );
96 96
97 // AM/PM 97 // AM/PM
98 cbAmpm = new QComboBox( container ); 98 cbAmpm = new QComboBox( container );
99 cbAmpm->insertItem( tr( "AM" ), ValueAM ); 99 cbAmpm->insertItem( tr( "AM" ), ValueAM );
100 cbAmpm->insertItem( tr( "PM" ), ValuePM ); 100 cbAmpm->insertItem( tr( "PM" ), ValuePM );
101 layout->addMultiCellWidget( cbAmpm, 2, 2, 4, 5 ); 101 layout->addMultiCellWidget( cbAmpm, 2, 2, 4, 5 );
102 102
103 // Date 103 // Date
104 layout->addWidget( new QLabel( tr( "Date" ), container ), 4, 0 ); 104 layout->addWidget( new QLabel( tr( "Date" ), container ), 4, 0 );
105 btnDate = new DateButton( TRUE, container ); 105 btnDate = new DateButton( TRUE, container );
106 layout->addMultiCellWidget( btnDate, 4, 4, 1, 5 ); 106 layout->addMultiCellWidget( btnDate, 4, 4, 1, 5 );
107 107
108 // Timezone 108 // Timezone
109 layout->addMultiCellWidget( new QLabel( tr( "Time zone" ), container ), 6, 6, 0, 1 ); 109 layout->addMultiCellWidget( new QLabel( tr( "Time zone" ), container ), 6, 6, 0, 1 );
110 selTimeZone = new TimeZoneSelector( container ); 110 selTimeZone = new TimeZoneSelector( container );
111 connect( selTimeZone, SIGNAL(signalNewTz(const QString&)), this, SLOT(slotTZChanged(const QString&)) ); 111 connect( selTimeZone, SIGNAL(signalNewTz(const QString&)), this, SLOT(slotTZChanged(const QString&)) );
112 layout->addMultiCellWidget( selTimeZone, 6, 6, 2, 5 ); 112 layout->addMultiCellWidget( selTimeZone, 6, 6, 2, 5 );
113 113
114 // Space filler 114 // Space filler
115 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 ); 115 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 );
116 116
117 // Set NTP time button 117 // Set NTP time button
118 m_ntpBtn = new QPushButton( Opie::Core::OResource::loadPixmap( "netsystemtime/ntptab", Opie::Core::OResource::SmallIcon ), 118 m_ntpBtn = new QPushButton( Opie::Core::OResource::loadPixmap( "netsystemtime/ntptab", Opie::Core::OResource::SmallIcon ),
119 tr( "Get time from the network" ), container ); 119 tr( "Get time from the network" ), container );
120 m_ntpBtn->setMinimumHeight( AppLnk::smallIconSize()+4 ); 120 m_ntpBtn->setMinimumHeight( AppLnk::smallIconSize()+4 );
121 connect( m_ntpBtn, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) ); 121 connect( m_ntpBtn, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) );
122 layout->addMultiCellWidget( m_ntpBtn, 8, 8, 0, 5 ); 122 layout->addMultiCellWidget( m_ntpBtn, 8, 8, 0, 5 );
123 123
124 // Set predicted time button 124 // Set predicted time button
125 QPushButton *pb = new QPushButton( Opie::Core::OResource::loadPixmap( "netsystemtime/predicttab", Opie::Core::OResource::SmallIcon ), 125 QPushButton *pb = new QPushButton( Opie::Core::OResource::loadPixmap( "netsystemtime/predicttab", Opie::Core::OResource::SmallIcon ),
126 tr( "Set predicted time" ), container ); 126 tr( "Set predicted time" ), container );
127 pb->setMinimumHeight( AppLnk::smallIconSize()+4 ); 127 pb->setMinimumHeight( AppLnk::smallIconSize()+4 );
128 connect( pb, SIGNAL(clicked()), this, SIGNAL(getPredictedTime()) ); 128 connect( pb, SIGNAL(clicked()), this, SIGNAL(getPredictedTime()) );
129 layout->addMultiCellWidget( pb, 9, 9, 0, 5 ); 129 layout->addMultiCellWidget( pb, 9, 9, 0, 5 );
130 130
131 // Space filler at bottom of widget 131 // Space filler at bottom of widget
132 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 10, 0 ); 132 layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 10, 0 );
133 133
134 // Initialize values 134 // Initialize values
135 Config config( "locale" ); 135 Config config( "locale" );
136 config.setGroup( "Location" ); 136 config.setGroup( "Location" );
137 selTimeZone->setCurrentZone( config.readEntry( "Timezone", "America/New_York" ) ); 137 selTimeZone->setCurrentZone( config.readEntry( "Timezone", "America/New_York" ) );
138 use12HourTime = FALSE; 138 use12HourTime = FALSE;
139 setDateTime( QDateTime::currentDateTime() ); 139 setDateTime( QDateTime::currentDateTime() );
140} 140}
141 141
142TimeTabWidget::~TimeTabWidget() 142TimeTabWidget::~TimeTabWidget()
143{ 143{
144} 144}
145 145
146void TimeTabWidget::saveSettings( bool commit ) 146void TimeTabWidget::saveSettings( bool commit )
147{ 147{
148 if ( commit ) 148 if ( commit )
149 { 149 {
150 // Set timezone and announce to world 150 // Set timezone and announce to world
151 QString tz = selTimeZone->currentZone(); 151 QString tz = selTimeZone->currentZone();
152 Config config("locale"); 152 Config config("locale");
153 config.setGroup( "Location" ); 153 config.setGroup( "Location" );
154 config.writeEntry( "Timezone", tz ); 154 config.writeEntry( "Timezone", tz );
155 setenv( "TZ", tz, 1 ); 155 setenv( "TZ", tz, 1 );
156 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); 156 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
157 setTimeZone << tz; 157 setTimeZone << tz;
158 158
159 // If controls have a valid date & time, update systemtime 159 // If controls have a valid date & time, update systemtime
160 int hour = sbHour->value(); 160 int hour = sbHour->value();
161 if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) 161 if ( use12HourTime && cbAmpm->currentItem() == ValuePM )
162 hour += 12; 162 hour += 12;
163 QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); 163 QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) );
164 setSystemTime( dt ); 164 setSystemTime( dt );
165 } 165 }
166 else 166 else
167 { 167 {
168 // Reset systemtime to hardware clock (i.e. undo any changes made by this app) 168 // Reset systemtime to hardware clock (i.e. undo any changes made by this app)
169 system("/sbin/hwclock --hctosys --utc"); 169 system("/sbin/hwclock --hctosys --utc");
170 } 170 }
171} 171}
172 172
173void TimeTabWidget::setDateTime( const QDateTime &dt ) 173void TimeTabWidget::setDateTime( const QDateTime &dt )
174{ 174{
175 // Set time 175 // Set time
176 QTime t = dt.time(); 176 QTime t = dt.time();
177 if( use12HourTime ) 177 if( use12HourTime )
178 { 178 {
179 int show_hour = t.hour(); 179 int show_hour = t.hour();
180 if ( t.hour() >= 12 ) 180 if ( t.hour() > 12 )
181 { 181 {
182 show_hour -= 12; 182 show_hour -= 12;
183 cbAmpm->setCurrentItem( ValuePM ); 183 cbAmpm->setCurrentItem( ValuePM );
184 } 184 }
185 else 185 else
186 { 186 {
187 cbAmpm->setCurrentItem( ValueAM ); 187 cbAmpm->setCurrentItem( ValueAM );
188 } 188 }
189 if ( show_hour == 0 ) 189 if ( show_hour == 0 )
190 show_hour = 12; 190 show_hour = 12;
191 sbHour->setValue( show_hour ); 191 sbHour->setValue( show_hour );
192 } 192 }
193 else 193 else
194 { 194 {
195 sbHour->setValue( t.hour() ); 195 sbHour->setValue( t.hour() );
196 } 196 }
197 sbMin->setValue( t.minute() ); 197 sbMin->setValue( t.minute() );
198 198
199 // Set date 199 // Set date
200 btnDate->setDate( dt.date() ); 200 btnDate->setDate( dt.date() );
201} 201}
202 202
203void TimeTabWidget::setNTPBtnEnabled( bool enabled ) 203void TimeTabWidget::setNTPBtnEnabled( bool enabled )
204{ 204{
205 m_ntpBtn->setEnabled( enabled ); 205 m_ntpBtn->setEnabled( enabled );
206} 206}
207 207
208void TimeTabWidget::setSystemTime( const QDateTime &dt ) 208void TimeTabWidget::setSystemTime( const QDateTime &dt )
209{ 209{
210 // Set system clock 210 // Set system clock
211 if ( dt.isValid() ) 211 if ( dt.isValid() )
212 { 212 {
213 struct timeval myTv; 213 struct timeval myTv;
214 int t = TimeConversion::toUTC( dt ); 214 int t = TimeConversion::toUTC( dt );
215 myTv.tv_sec = t; 215 myTv.tv_sec = t;
216 myTv.tv_usec = 0; 216 myTv.tv_usec = 0;
217 217
218 if ( myTv.tv_sec != -1 ) 218 if ( myTv.tv_sec != -1 )
219 ::settimeofday( &myTv, 0 ); 219 ::settimeofday( &myTv, 0 );
220 220
221 /* 221 /*
222 * Commit the datetime to the 'hardware' 222 * Commit the datetime to the 'hardware'
223 * as Global::writeHWClock() is a NOOP with Opie Alarm 223 * as Global::writeHWClock() is a NOOP with Opie Alarm
224 */ 224 */
225 system("/sbin/hwclock --systohc --utc"); 225 system("/sbin/hwclock --systohc --utc");
226 } 226 }
227} 227}
228 228
229void TimeTabWidget::slotUse12HourTime( int i ) 229void TimeTabWidget::slotUse12HourTime( int i )
230{ 230{
231 use12HourTime = (i == 1); 231 use12HourTime = (i == 1);
232 232
233 cbAmpm->setEnabled( use12HourTime ); 233 cbAmpm->setEnabled( use12HourTime );
234 234
235 int show_hour = sbHour->value(); 235 int show_hour = sbHour->value();
236 236
237 if ( use12HourTime ) 237 if ( use12HourTime )
238 { 238 {
239 sbHour->setMinValue( 1 ); 239 sbHour->setMinValue( 1 );
240 sbHour->setMaxValue( 12 ); 240 sbHour->setMaxValue( 12 );
241 241
242 if ( show_hour >= 12 ) 242 if ( show_hour > 12 )
243 { 243 {
244 show_hour -= 12; 244 show_hour -= 12;
245 cbAmpm->setCurrentItem( ValuePM ); 245 cbAmpm->setCurrentItem( ValuePM );
246 } 246 }
247 else 247 else
248 { 248 {
249 cbAmpm->setCurrentItem( ValueAM ); 249 cbAmpm->setCurrentItem( ValueAM );
250 } 250 }
251 if ( show_hour == 0 ) 251 if ( show_hour == 0 )
252 show_hour = 12; 252 show_hour = 12;
253 } 253 }
254 else 254 else
255 { 255 {
256 sbHour->setMinValue( 0 ); 256 sbHour->setMinValue( 0 );
257 sbHour->setMaxValue( 23 ); 257 sbHour->setMaxValue( 23 );
258 258
259 if ( cbAmpm->currentItem() == ValuePM ) 259 if ( cbAmpm->currentItem() == ValuePM )
260 { 260 {
261 show_hour += 12; 261 show_hour += 12;
262 if ( show_hour == 24 ) 262 if ( show_hour == 24 )
263 show_hour = 0; 263 show_hour = 0;
264 } 264 }
265 } 265 }
266 266
267 sbHour->setValue( show_hour ); 267 sbHour->setValue( show_hour );
268} 268}
269 269
270void TimeTabWidget::slotDateFormatChanged( const DateFormat &df ) 270void TimeTabWidget::slotDateFormatChanged( const DateFormat &df )
271{ 271{
272 btnDate->setDateFormat( df ); 272 btnDate->setDateFormat( df );
273} 273}
274 274
275void TimeTabWidget::slotWeekStartChanged( int monday ) 275void TimeTabWidget::slotWeekStartChanged( int monday )
276{ 276{
277 btnDate->setWeekStartsMonday( monday ); 277 btnDate->setWeekStartsMonday( monday );
278} 278}
279 279
280void TimeTabWidget::slotTZChanged( const QString &newtz ) 280void TimeTabWidget::slotTZChanged( const QString &newtz )
281{ 281{
282 // Check timezone has a valid file in /usr/share/zoneinfo 282 // Check timezone has a valid file in /usr/share/zoneinfo
283 if(!QFile::exists("/usr/share/zoneinfo/" + newtz)) { 283 if(!QFile::exists("/usr/share/zoneinfo/" + newtz)) {
284 QMessageBox::warning(this, tr("Time zone file missing"), 284 QMessageBox::warning(this, tr("Time zone file missing"),
285 (tr("There is no time zone file for the\nselected time zone (%1).\nYou will need to install it before the\nsystem time zone can be set correctly.")).arg(newtz)); 285 (tr("There is no time zone file for the\nselected time zone (%1).\nYou will need to install it before the\nsystem time zone can be set correctly.")).arg(newtz));
286 } 286 }
287 else { 287 else {
288 // If controls have a valid date & time, update systemtime 288 // If controls have a valid date & time, update systemtime
289 int hour = sbHour->value(); 289 int hour = sbHour->value();
290 if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) 290 if ( use12HourTime && cbAmpm->currentItem() == ValuePM )
291 hour += 12; 291 hour += 12;
292 QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); 292 QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) );
293 setSystemTime( dt ); 293 setSystemTime( dt );
294 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); 294 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
295 setTimeZone << newtz; 295 setTimeZone << newtz;
296 296
297 // Set system timezone 297 // Set system timezone
298 QString currtz = getenv( "TZ" ); 298 QString currtz = getenv( "TZ" );
299 setenv( "TZ", newtz, 1 ); 299 setenv( "TZ", newtz, 1 );
300 300
301 // Get new date/time 301 // Get new date/time
302 hour = sbHour->value(); 302 hour = sbHour->value();
303 if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) 303 if ( use12HourTime && cbAmpm->currentItem() == ValuePM )
304 hour += 12; 304 hour += 12;
305 dt = QDateTime::currentDateTime(); 305 dt = QDateTime::currentDateTime();
306 306
307 // Reset system timezone 307 // Reset system timezone
308 if ( !currtz.isNull() ) 308 if ( !currtz.isNull() )
309 { 309 {
310 setenv( "TZ", currtz, 1 ); 310 setenv( "TZ", currtz, 1 );
311 } 311 }
312 312
313 // Set controls to new time 313 // Set controls to new time
314 setDateTime( dt ); 314 setDateTime( dt );
315 315
316 emit tzChanged( newtz ); 316 emit tzChanged( newtz );
317 } 317 }
318} 318}