summaryrefslogtreecommitdiff
authorzecke <zecke>2004-10-22 15:15:01 (UTC)
committer zecke <zecke>2004-10-22 15:15:01 (UTC)
commitf2a2eca1870e1fd88c82a6ccb039610949daa72c (patch) (unidiff)
tree9ca204b4cddfee6272cfc8d5e55b27b60a0743d0
parent0a3ab70a5be70bb04691a2a566ce63719e57f83e (diff)
downloadopie-f2a2eca1870e1fd88c82a6ccb039610949daa72c.zip
opie-f2a2eca1870e1fd88c82a6ccb039610949daa72c.tar.gz
opie-f2a2eca1870e1fd88c82a6ccb039610949daa72c.tar.bz2
Write the hardware clock after setting the datetime. This way we can
gurantee it is set while opiealarm has not run.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/timetabwidget.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/noncore/settings/netsystemtime/timetabwidget.cpp b/noncore/settings/netsystemtime/timetabwidget.cpp
index 1ea460e..3cc127d 100644
--- a/noncore/settings/netsystemtime/timetabwidget.cpp
+++ b/noncore/settings/netsystemtime/timetabwidget.cpp
@@ -40,65 +40,65 @@
40 40
41#include <qcombobox.h> 41#include <qcombobox.h>
42#include <qdatetime.h> 42#include <qdatetime.h>
43#include <qframe.h> 43#include <qframe.h>
44#include <qlabel.h> 44#include <qlabel.h>
45#include <qlayout.h> 45#include <qlayout.h>
46#include <qpushbutton.h> 46#include <qpushbutton.h>
47#include <qscrollview.h> 47#include <qscrollview.h>
48#include <qspinbox.h> 48#include <qspinbox.h>
49 49
50#include <stdlib.h> 50#include <stdlib.h>
51#include <sys/time.h> 51#include <sys/time.h>
52 52
53static const int ValueAM = 0; 53static const int ValueAM = 0;
54static const int ValuePM = 1; 54static const int ValuePM = 1;
55 55
56TimeTabWidget::TimeTabWidget( QWidget *parent ) 56TimeTabWidget::TimeTabWidget( QWidget *parent )
57 : QWidget( parent, 0x0, 0 ) 57 : QWidget( parent, 0x0, 0 )
58{ 58{
59 // Synchronize HW clock to systemtime 59 // Synchronize HW clock to systemtime
60 // This app will update systemtime 60 // This app will update systemtime
61 // - if Cancel is clicked, will reset systemtime to HW clock's time 61 // - if Cancel is clicked, will reset systemtime to HW clock's time
62 // - if Ok is clicked, will leave systemtime as is 62 // - if Ok is clicked, will leave systemtime as is
63 system("/sbin/hwclock --systohc --utc"); 63 system("/sbin/hwclock --systohc --utc");
64 64
65 QVBoxLayout *tmpvb = new QVBoxLayout( this ); 65 QVBoxLayout *tmpvb = new QVBoxLayout( this );
66 QScrollView *sv = new QScrollView( this ); 66 QScrollView *sv = new QScrollView( this );
67 tmpvb->addWidget( sv, 0, 0 ); 67 tmpvb->addWidget( sv, 0, 0 );
68 sv->setResizePolicy( QScrollView::AutoOneFit ); 68 sv->setResizePolicy( QScrollView::AutoOneFit );
69 sv->setFrameStyle( QFrame::NoFrame ); 69 sv->setFrameStyle( QFrame::NoFrame );
70 QWidget *container = new QWidget( sv->viewport() ); 70 QWidget *container = new QWidget( sv->viewport() );
71 sv->addChild( container ); 71 sv->addChild( container );
72 72
73 QGridLayout *layout = new QGridLayout( container ); 73 QGridLayout *layout = new QGridLayout( container );
74 layout->setMargin( 2 ); 74 layout->setMargin( 2 );
75 layout->setSpacing( 4 ); 75 layout->setSpacing( 4 );
76 76
77 // Hours 77 // Hours
78 layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 ); 78 layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 );
79 sbHour = new QSpinBox( container ); 79 sbHour = new QSpinBox( container );
80 sbHour->setWrapping( TRUE ); 80 sbHour->setWrapping( TRUE );
81 layout->addMultiCellWidget( sbHour, 2, 2, 0, 1 ); 81 layout->addMultiCellWidget( sbHour, 2, 2, 0, 1 );
82 82
83 // Minutes 83 // Minutes
84 layout->addMultiCellWidget( new QLabel( tr( "Minute" ), container ), 1, 1, 2, 3 ); 84 layout->addMultiCellWidget( new QLabel( tr( "Minute" ), container ), 1, 1, 2, 3 );
85 sbMin = new QSpinBox( container ); 85 sbMin = new QSpinBox( container );
86 sbMin->setWrapping( TRUE ); 86 sbMin->setWrapping( TRUE );
87 sbMin->setMinValue( 0 ); 87 sbMin->setMinValue( 0 );
88 sbMin->setMaxValue( 59 ); 88 sbMin->setMaxValue( 59 );
89 layout->addMultiCellWidget( sbMin, 2, 2, 2, 3 ); 89 layout->addMultiCellWidget( sbMin, 2, 2, 2, 3 );
90 90
91 // AM/PM 91 // AM/PM
92 cbAmpm = new QComboBox( container ); 92 cbAmpm = new QComboBox( container );
93 cbAmpm->insertItem( tr( "AM" ), ValueAM ); 93 cbAmpm->insertItem( tr( "AM" ), ValueAM );
94 cbAmpm->insertItem( tr( "PM" ), ValuePM ); 94 cbAmpm->insertItem( tr( "PM" ), ValuePM );
95 layout->addMultiCellWidget( cbAmpm, 2, 2, 4, 5 ); 95 layout->addMultiCellWidget( cbAmpm, 2, 2, 4, 5 );
96 96
97 // Date 97 // Date
98 layout->addWidget( new QLabel( tr( "Date" ), container ), 4, 0 ); 98 layout->addWidget( new QLabel( tr( "Date" ), container ), 4, 0 );
99 btnDate = new DateButton( TRUE, container ); 99 btnDate = new DateButton( TRUE, container );
100 layout->addMultiCellWidget( btnDate, 4, 4, 1, 5 ); 100 layout->addMultiCellWidget( btnDate, 4, 4, 1, 5 );
101 101
102 // Timezone 102 // Timezone
103 layout->addMultiCellWidget( new QLabel( tr( "Time zone" ), container ), 6, 6, 0, 1 ); 103 layout->addMultiCellWidget( new QLabel( tr( "Time zone" ), container ), 6, 6, 0, 1 );
104 selTimeZone = new TimeZoneSelector( container ); 104 selTimeZone = new TimeZoneSelector( container );
@@ -158,88 +158,94 @@ void TimeTabWidget::saveSettings( bool commit )
158 else 158 else
159 { 159 {
160 // Reset systemtime to hardware clock (i.e. undo any changes made by this app) 160 // Reset systemtime to hardware clock (i.e. undo any changes made by this app)
161 system("/sbin/hwclock --hctosys --utc"); 161 system("/sbin/hwclock --hctosys --utc");
162 } 162 }
163} 163}
164 164
165void TimeTabWidget::setDateTime( const QDateTime &dt ) 165void TimeTabWidget::setDateTime( const QDateTime &dt )
166{ 166{
167 // Set time 167 // Set time
168 QTime t = dt.time(); 168 QTime t = dt.time();
169 if( use12HourTime ) 169 if( use12HourTime )
170 { 170 {
171 int show_hour = t.hour(); 171 int show_hour = t.hour();
172 if ( t.hour() >= 12 ) 172 if ( t.hour() >= 12 )
173 { 173 {
174 show_hour -= 12; 174 show_hour -= 12;
175 cbAmpm->setCurrentItem( ValuePM ); 175 cbAmpm->setCurrentItem( ValuePM );
176 } 176 }
177 else 177 else
178 { 178 {
179 cbAmpm->setCurrentItem( ValueAM ); 179 cbAmpm->setCurrentItem( ValueAM );
180 } 180 }
181 if ( show_hour == 0 ) 181 if ( show_hour == 0 )
182 show_hour = 12; 182 show_hour = 12;
183 sbHour->setValue( show_hour ); 183 sbHour->setValue( show_hour );
184 } 184 }
185 else 185 else
186 { 186 {
187 sbHour->setValue( t.hour() ); 187 sbHour->setValue( t.hour() );
188 } 188 }
189 sbMin->setValue( t.minute() ); 189 sbMin->setValue( t.minute() );
190 190
191 // Set date 191 // Set date
192 btnDate->setDate( dt.date() ); 192 btnDate->setDate( dt.date() );
193} 193}
194 194
195void TimeTabWidget::setSystemTime( const QDateTime &dt ) 195void TimeTabWidget::setSystemTime( const QDateTime &dt )
196{ 196{
197 // Set system clock 197 // Set system clock
198 if ( dt.isValid() ) 198 if ( dt.isValid() )
199 { 199 {
200 struct timeval myTv; 200 struct timeval myTv;
201 int t = TimeConversion::toUTC( dt ); 201 int t = TimeConversion::toUTC( dt );
202 myTv.tv_sec = t; 202 myTv.tv_sec = t;
203 myTv.tv_usec = 0; 203 myTv.tv_usec = 0;
204 204
205 if ( myTv.tv_sec != -1 ) 205 if ( myTv.tv_sec != -1 )
206 ::settimeofday( &myTv, 0 ); 206 ::settimeofday( &myTv, 0 );
207
208 /*
209 * Commit the datetime to the 'hardware'
210 * as Global::writeHWClock() is a NOOP with Opie Alarm
211 */
212 system("/sbin/hwclock --systohc --utc");
207 } 213 }
208} 214}
209 215
210void TimeTabWidget::slotUse12HourTime( int i ) 216void TimeTabWidget::slotUse12HourTime( int i )
211{ 217{
212 use12HourTime = (i == 1); 218 use12HourTime = (i == 1);
213 219
214 cbAmpm->setEnabled( use12HourTime ); 220 cbAmpm->setEnabled( use12HourTime );
215 221
216 int show_hour = sbHour->value(); 222 int show_hour = sbHour->value();
217 223
218 if ( use12HourTime ) 224 if ( use12HourTime )
219 { 225 {
220 sbHour->setMinValue( 1 ); 226 sbHour->setMinValue( 1 );
221 sbHour->setMaxValue( 12 ); 227 sbHour->setMaxValue( 12 );
222 228
223 if ( show_hour >= 12 ) 229 if ( show_hour >= 12 )
224 { 230 {
225 show_hour -= 12; 231 show_hour -= 12;
226 cbAmpm->setCurrentItem( ValuePM ); 232 cbAmpm->setCurrentItem( ValuePM );
227 } 233 }
228 else 234 else
229 { 235 {
230 cbAmpm->setCurrentItem( ValueAM ); 236 cbAmpm->setCurrentItem( ValueAM );
231 } 237 }
232 if ( show_hour == 0 ) 238 if ( show_hour == 0 )
233 show_hour = 12; 239 show_hour = 12;
234 } 240 }
235 else 241 else
236 { 242 {
237 sbHour->setMinValue( 0 ); 243 sbHour->setMinValue( 0 );
238 sbHour->setMaxValue( 23 ); 244 sbHour->setMaxValue( 23 );
239 245
240 if ( cbAmpm->currentItem() == ValuePM ) 246 if ( cbAmpm->currentItem() == ValuePM )
241 { 247 {
242 show_hour += 12; 248 show_hour += 12;
243 if ( show_hour == 24 ) 249 if ( show_hour == 24 )
244 show_hour = 0; 250 show_hour = 0;
245 } 251 }