summaryrefslogtreecommitdiff
path: root/noncore/tools/clock/clock.cpp
Unidiff
Diffstat (limited to 'noncore/tools/clock/clock.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index 4d92683..118cf1f 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -28,241 +28,241 @@
28#include <qpe/timestring.h> 28#include <qpe/timestring.h>
29#include <qpe/alarmserver.h> 29#include <qpe/alarmserver.h>
30#include <qpe/sound.h> 30#include <qpe/sound.h>
31#include <qpe/resource.h> 31#include <qpe/resource.h>
32#include <qsound.h> 32#include <qsound.h>
33#include <qtimer.h> 33#include <qtimer.h>
34 34
35#include <opie/oclickablelabel.h> 35#include <opie/oclickablelabel.h>
36 36
37#include <qlcdnumber.h> 37#include <qlcdnumber.h>
38#include <qslider.h> 38#include <qslider.h>
39#include <qlabel.h> 39#include <qlabel.h>
40#include <qlayout.h> 40#include <qlayout.h>
41#include <qtimer.h> 41#include <qtimer.h>
42#include <qpushbutton.h> 42#include <qpushbutton.h>
43#include <qradiobutton.h> 43#include <qradiobutton.h>
44#include <qbuttongroup.h> 44#include <qbuttongroup.h>
45#include <qpainter.h> 45#include <qpainter.h>
46#include <qmessagebox.h> 46#include <qmessagebox.h>
47#include <qdatetime.h> 47#include <qdatetime.h>
48 48
49#include <math.h> 49#include <math.h>
50#include <unistd.h> 50#include <unistd.h>
51#include <sys/types.h> 51#include <sys/types.h>
52 52
53#include <pthread.h> 53#include <pthread.h>
54 54
55 55
56const double deg2rad = 0.017453292519943295769; // pi/180 56const double deg2rad = 0.017453292519943295769; // pi/180
57const int sw_prec = 2; 57const int sw_prec = 2;
58 58
59void startPlayer() 59void startPlayer()
60{ 60{
61 Config config( "qpe" ); 61 Config config( "qpe" );
62 config.setGroup( "Time" ); 62 config.setGroup( "Time" );
63 sleep(15); 63 sleep(15);
64 QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); 64 QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" );
65 e << config.readEntry( "mp3File", "" ); 65 e << config.readEntry( "mp3File", "" );
66} 66}
67 67
68 68
69static void toggleScreenSaver( bool on ) 69static void toggleScreenSaver( bool on )
70{ 70{
71 QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" ); 71 QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" );
72 e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend ); 72 e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend );
73} 73}
74 74
75Clock::Clock( QWidget * parent, const char * name, WFlags f ) 75Clock::Clock( QWidget * parent, const char * name, WFlags f )
76 : QVBox( parent, name , f ) 76 : QVBox( parent, name , f )
77{ 77{
78 setSpacing( 4 ); 78 setSpacing( 4 );
79 setMargin( 1 ); 79 setMargin( 1 );
80 80
81 81
82 snoozeBtn = new QPushButton ( this ); 82 snoozeBtn = new QPushButton ( this );
83 snoozeBtn->setText( tr( "Snooze" ) ); 83 snoozeBtn->setText( tr( "Snooze" ) );
84 84
85 aclock = new AnalogClock( this ); 85 aclock = new AnalogClock( this );
86 aclock->display( QTime::currentTime() ); 86 aclock->display( QTime::currentTime() );
87 aclock->setLineWidth( 2 ); 87 aclock->setLineWidth( 2 );
88 88
89 QHBox *hb = new QHBox( this ); 89 QHBox *hb = new QHBox( this );
90 hb->setMargin( 0 ); 90 hb->setMargin( 0 );
91 QWidget *space = new QWidget( hb ); 91 QWidget *space = new QWidget( hb );
92 lcd = new QLCDNumber( hb ); 92 lcd = new QLCDNumber( hb );
93 lcd->setSegmentStyle( QLCDNumber::Flat ); 93 lcd->setSegmentStyle( QLCDNumber::Flat );
94 lcd->setFrameStyle( QFrame::NoFrame ); 94 lcd->setFrameStyle( QFrame::NoFrame );
95 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); 95 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
96 lcd->setFixedHeight( 23 ); 96 lcd->setFixedHeight( 23 );
97 97
98 ampmLabel = new QLabel( tr( "PM" ), hb ); 98 ampmLabel = new QLabel( tr( "PM" ), hb );
99 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 99 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
100 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); 100 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) );
101 ampmLabel->setAlignment( AlignLeft | AlignBottom ); 101 ampmLabel->setAlignment( AlignLeft | AlignBottom );
102 space = new QWidget( hb ); 102 space = new QWidget( hb );
103 103
104 date = new QLabel( this ); 104 date = new QLabel( this );
105 date->setAlignment( AlignHCenter | AlignVCenter ); 105 date->setAlignment( AlignHCenter | AlignVCenter );
106 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 106 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
107 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 107 date->setText( TimeString::longDateString( QDate::currentDate() ) );
108 108
109 QWidget *controls = new QWidget( this ); 109 QWidget *controls = new QWidget( this );
110 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); 110 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 );
111 111
112 QButtonGroup *grp = new QButtonGroup( controls ); 112 QButtonGroup *grp = new QButtonGroup( controls );
113 grp->setRadioButtonExclusive( true ); 113 grp->setRadioButtonExclusive( true );
114 grp->hide(); 114 grp->hide();
115 115
116 clockRB = new QRadioButton ( tr( "Clock" ), controls ); 116 clockRB = new QRadioButton ( tr( "Clock" ), controls );
117 gl->addWidget( clockRB, 0, 0 ); 117 gl->addWidget( clockRB, 0, 0 );
118 grp->insert( clockRB ); 118 grp->insert( clockRB );
119 119
120 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); 120 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls );
121 gl->addWidget( swatchRB, 1, 0 ); 121 gl->addWidget( swatchRB, 1, 0 );
122 grp->insert( swatchRB ); 122 grp->insert( swatchRB );
123 123
124 connect( grp, SIGNAL( clicked( int ) ), this, SLOT( modeSelect( int ) ) ); 124 connect( grp, SIGNAL( clicked(int) ), this, SLOT( modeSelect(int) ) );
125 grp->setButton( 0 ); 125 grp->setButton( 0 );
126 126
127 set = new QPushButton ( controls ); 127 set = new QPushButton ( controls );
128 set->setMaximumSize( 50, 30 ); 128 set->setMaximumSize( 50, 30 );
129 gl->addWidget( set , 0, 1 ); 129 gl->addWidget( set , 0, 1 );
130 set->setText( tr( "Start" ) ); 130 set->setText( tr( "Start" ) );
131 set->setEnabled( FALSE ); 131 set->setEnabled( FALSE );
132 grp->insert( set ); 132 grp->insert( set );
133 133
134 reset = new QPushButton ( controls ); 134 reset = new QPushButton ( controls );
135 gl->addWidget( reset, 1, 1 ); 135 gl->addWidget( reset, 1, 1 );
136 reset->setText( tr( "Reset" ) ); 136 reset->setText( tr( "Reset" ) );
137 reset->setEnabled( FALSE ); 137 reset->setEnabled( FALSE );
138 grp->insert( reset ); 138 grp->insert( reset );
139 139
140 alarmOffBtn = new QPushButton ( controls ); 140 alarmOffBtn = new QPushButton ( controls );
141 gl->addWidget( alarmOffBtn, 0, 2 ); 141 gl->addWidget( alarmOffBtn, 0, 2 );
142 142
143 alarmBtn = new QPushButton ( controls ); 143 alarmBtn = new QPushButton ( controls );
144 gl->addWidget( alarmBtn, 1, 2 ); 144 gl->addWidget( alarmBtn, 1, 2 );
145 145
146 alarmBtn->setText( tr( "Set Alarm" ) ); 146 alarmBtn->setText( tr( "Set Alarm" ) );
147 147
148 OClickableLabel *click = new OClickableLabel( controls, "label" ); 148 OClickableLabel *click = new OClickableLabel( controls, "label" );
149 click->setText( tr( "Set date and time." ) ); 149 click->setText( tr( "Set date and time." ) );
150 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter ); 150 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter );
151 connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) ); 151 connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) );
152 152
153 connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) ); 153 connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) );
154 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); 154 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
155 155
156 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); 156 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
157 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); 157 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) );
158 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); 158 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
159 159
160 connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ), 160 connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ),
161 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); 161 this, SLOT( appMessage(const QCString&,const QByteArray&) ) );
162 162
163 t = new QTimer( this ); 163 t = new QTimer( this );
164 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); 164 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
165 t->start( 1000 ); 165 t->start( 1000 );
166 166
167 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); 167 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) );
168 168
169 swatch_running = FALSE; 169 swatch_running = FALSE;
170 swatch_totalms = 0; 170 swatch_totalms = 0;
171 171
172 connect( qApp, SIGNAL( clockChanged( bool ) ), this, SLOT( changeClock( bool ) ) ); 172 connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( changeClock(bool) ) );
173 173
174 174
175 Config config( "qpe" ); 175 Config config( "qpe" );
176 config.setGroup( "Time" ); 176 config.setGroup( "Time" );
177 ampm = config.readBoolEntry( "AMPM", TRUE ); 177 ampm = config.readBoolEntry( "AMPM", TRUE );
178 178
179 QString tmp = config.readEntry( "clockAlarmHour", "" ); 179 QString tmp = config.readEntry( "clockAlarmHour", "" );
180 bool ok; 180 bool ok;
181 hour = tmp.toInt( &ok, 10 ); 181 hour = tmp.toInt( &ok, 10 );
182 tmp = config.readEntry( "clockAlarmMinute", "" ); 182 tmp = config.readEntry( "clockAlarmMinute", "" );
183 minute = tmp.toInt( &ok, 10 ); 183 minute = tmp.toInt( &ok, 10 );
184 184
185 if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) 185 if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" )
186 { 186 {
187 alarmOffBtn->setText( tr( "Alarm Is On" ) ); 187 alarmOffBtn->setText( tr( "Alarm Is On" ) );
188 alarmBool = TRUE; 188 alarmBool = TRUE;
189 snoozeBtn->show(); 189 snoozeBtn->show();
190 } 190 }
191 else 191 else
192 { 192 {
193 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 193 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
194 alarmBool = FALSE; 194 alarmBool = FALSE;
195 snoozeBtn->hide(); 195 snoozeBtn->hide();
196 } 196 }
197 197
198 QTimer::singleShot( 0, this, SLOT( updateClock() ) ); 198 QTimer::singleShot( 0, this, SLOT( updateClock() ) );
199 199
200 Config cfg( "Clock" ); 200 Config cfg( "Clock" );
201 cfg.setGroup( "Mode" ); 201 cfg.setGroup( "Mode" );
202 int mode = cfg.readBoolEntry( "clockMode"); 202 int mode = cfg.readBoolEntry( "clockMode");
203 setSwatchMode( mode); 203 setSwatchMode( mode);
204 modeSelect( mode); 204 modeSelect( mode);
205} 205}
206 206
207Clock::~Clock() 207Clock::~Clock()
208{ 208{
209 toggleScreenSaver( true ); 209 toggleScreenSaver( true );
210} 210}
211 211
212void Clock::updateClock() 212void Clock::updateClock()
213{ 213{
214 if ( clockRB->isChecked() ) 214 if ( clockRB->isChecked() )
215 { 215 {
216 QTime tm = QDateTime::currentDateTime().time(); 216 QTime tm = QDateTime::currentDateTime().time();
217 QString s; 217 QString s;
218 if ( ampm ) 218 if ( ampm )
219 { 219 {
220 int hour = tm.hour(); 220 int hour = tm.hour();
221 if ( hour == 0 ) 221 if ( hour == 0 )
222 hour = 12; 222 hour = 12;
223 if ( hour > 12 ) 223 if ( hour > 12 )
224 hour -= 12; 224 hour -= 12;
225 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); 225 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
226 ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); 226 ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" );
227 ampmLabel->show(); 227 ampmLabel->show();
228 } 228 }
229 else 229 else
230 { 230 {
231 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); 231 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
232 ampmLabel->hide(); 232 ampmLabel->hide();
233 } 233 }
234 lcd->display( s ); 234 lcd->display( s );
235 lcd->repaint( FALSE ); 235 lcd->repaint( FALSE );
236 aclock->display( QTime::currentTime() ); 236 aclock->display( QTime::currentTime() );
237 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 237 date->setText( TimeString::longDateString( QDate::currentDate() ) );
238 } 238 }
239 else 239 else
240 { 240 {
241 QTime swatch_time; 241 QTime swatch_time;
242 QString lcdtext; 242 QString lcdtext;
243 int totalms = swatch_totalms; 243 int totalms = swatch_totalms;
244 if ( swatch_running ) 244 if ( swatch_running )
245 totalms += swatch_start.elapsed(); 245 totalms += swatch_start.elapsed();
246 swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); 246 swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms );
247 QString d = swatch_running ? QString( " " ) 247 QString d = swatch_running ? QString( " " )
248 : QString::number( totalms % 1000 + 1000 ); 248 : QString::number( totalms % 1000 + 1000 );
249 lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); 249 lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec );
250 lcd->display( lcdtext ); 250 lcd->display( lcdtext );
251 lcd->repaint( FALSE ); 251 lcd->repaint( FALSE );
252 aclock->display( swatch_time ); 252 aclock->display( swatch_time );
253 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 253 date->setText( TimeString::longDateString( QDate::currentDate() ) );
254 } 254 }
255} 255}
256 256
257void Clock::changeClock( bool a ) 257void Clock::changeClock( bool a )
258{ 258{
259 ampm = a; 259 ampm = a;
260 updateClock(); 260 updateClock();
261} 261}
262 262
263void Clock::clearClock( void ) 263void Clock::clearClock( void )
264{ 264{
265 lcd->display( QTime( 0, 0, 0 ).toString() ); 265 lcd->display( QTime( 0, 0, 0 ).toString() );
266 aclock->display( QTime( 0, 0, 0 ) ); 266 aclock->display( QTime( 0, 0, 0 ) );
267} 267}
268 268