summaryrefslogtreecommitdiffabout
path: root/kalarmd/alarmdialog.cpp
Unidiff
Diffstat (limited to 'kalarmd/alarmdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kalarmd/alarmdialog.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/kalarmd/alarmdialog.cpp b/kalarmd/alarmdialog.cpp
index 53ff488..65073f6 100644
--- a/kalarmd/alarmdialog.cpp
+++ b/kalarmd/alarmdialog.cpp
@@ -44,280 +44,285 @@
44#ifndef _WIN32_ 44#ifndef _WIN32_
45#include <unistd.h> 45#include <unistd.h>
46#include <sys/ioctl.h> 46#include <sys/ioctl.h>
47#endif 47#endif
48#include <stdio.h> 48#include <stdio.h>
49#include <fcntl.h> 49#include <fcntl.h>
50 50
51#ifndef DESKTOP_VERSION 51#ifndef DESKTOP_VERSION
52#include <qtopia/alarmserver.h> 52#include <qtopia/alarmserver.h>
53#include <qpe/resource.h> 53#include <qpe/resource.h>
54#include <qtopia/sound.h> 54#include <qtopia/sound.h>
55 55
56#endif 56#endif
57 57
58#include "alarmdialog.h" 58#include "alarmdialog.h"
59 59
60 60
61AlarmDialog::AlarmDialog(QWidget *parent,const char *name) 61AlarmDialog::AlarmDialog(QWidget *parent,const char *name)
62 : QDialog (parent, name, true, Qt::WStyle_Customize |Qt::WStyle_StaysOnTop | Qt::WStyle_DialogBorder) 62 : QDialog (parent, name, true, Qt::WStyle_Customize |Qt::WStyle_StaysOnTop | Qt::WStyle_DialogBorder)
63{ 63{
64 setCaption( "KO/Pi Alarm!" ); 64 setCaption( "KO/Pi Alarm!" );
65 QVBoxLayout* layout = new QVBoxLayout( this); 65 QVBoxLayout* layout = new QVBoxLayout( this);
66 QLabel* l = new QLabel("The following event triggered alarm:",this); 66 QLabel* l = new QLabel("The following event triggered alarm:",this);
67 layout->addWidget ( l ); 67 layout->addWidget ( l );
68 l->setAlignment( AlignCenter); 68 l->setAlignment( AlignCenter);
69 mMessage = new QLabel ( " ", this ); 69 mMessage = new QLabel ( " ", this );
70 int fs = 18; 70 int fs = 18;
71 int fs2 = 12; 71 int fs2 = 12;
72 int baseSize = 6; 72 int baseSize = 6;
73 if ( QApplication::desktop()->width() < 480 ) { 73 if ( QApplication::desktop()->width() < 480 ) {
74 fs2 = 10; 74 fs2 = 10;
75 fs = 12; 75 fs = 12;
76 baseSize = 4; 76 baseSize = 4;
77 } 77 }
78 layout->setSpacing( 3 ); 78 layout->setSpacing( 3 );
79 layout->setMargin( 3 ); 79 layout->setMargin( 3 );
80 QFont fo = QApplication::font(); 80 QFont fo = QApplication::font();
81 fo.setBold( true ); 81 fo.setBold( true );
82 fo.setPointSize( fs2 ); 82 fo.setPointSize( fs2 );
83 l->setFont( fo ); 83 l->setFont( fo );
84 fo.setPointSize( fs ); 84 fo.setPointSize( fs );
85 mMessage->setFont(fo ); 85 mMessage->setFont(fo );
86 mMessage->setAlignment( AlignCenter); 86 mMessage->setAlignment( AlignCenter);
87 layout->addWidget ( mMessage ); 87 layout->addWidget ( mMessage );
88 mMissedAlarms= new QLabel ( "(No missed Alarms)", this ); 88 mMissedAlarms= new QLabel ( "(No missed Alarms)", this );
89 mMissedAlarms->setAlignment( AlignCenter); 89 mMissedAlarms->setAlignment( AlignCenter);
90 90
91 playSoundTimer = new QTimer( this ); 91 playSoundTimer = new QTimer( this );
92 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) ); 92 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) );
93 93
94 playSoundTimer->stop(); 94 playSoundTimer->stop();
95 95
96 layout->addWidget ( mMissedAlarms ); 96 layout->addWidget ( mMissedAlarms );
97 mMissedAlarmsCombo = new QComboBox ( this ); 97 mMissedAlarmsCombo = new QComboBox ( this );
98 layout->addWidget ( mMissedAlarmsCombo ); 98 layout->addWidget ( mMissedAlarmsCombo );
99 99
100 QLabel* labb = new QLabel("Suspend duration (minutes):",this); 100 QLabel* labb = new QLabel("Suspend duration (minutes):",this);
101 labb->setAlignment(AlignCenter); 101 labb->setAlignment(AlignCenter);
102 layout->addWidget ( labb ); 102 layout->addWidget ( labb );
103 fo = font(); 103 fo = font();
104 int pointSize = 36; 104 int pointSize = 36;
105 if ( QApplication::desktop()->width() <= 320 ) 105 if ( QApplication::desktop()->width() <= 320 )
106 pointSize = 18; 106 pointSize = 18;
107 fo.setPointSize( pointSize ); 107 fo.setPointSize( pointSize );
108 mSuspendSpin = new QSpinBox(1,1440,1,this); 108 mSuspendSpin = new QSpinBox(1,1440,1,this);
109 mSuspendSpin->setFont( fo ); 109 mSuspendSpin->setFont( fo );
110 mSuspendSpin->setValue(7); // default suspend duration 110 mSuspendSpin->setValue(7); // default suspend duration
111 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 111 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
112 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 112 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
113 113
114#if QT_VERSION < 0x030000 114#if QT_VERSION < 0x030000
115 mSuspendSpin->upButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize )); 115 mSuspendSpin->upButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize ));
116 mSuspendSpin->downButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize )); 116 mSuspendSpin->downButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize ));
117#endif 117#endif
118 mSuspendSpin->setFixedSize( 18*baseSize, 10*baseSize+2 ); 118 mSuspendSpin->setFixedSize( 18*baseSize, 10*baseSize+2 );
119 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 119 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
120 QHBoxLayout* layoutSpin = new QHBoxLayout( layout ); 120 QHBoxLayout* layoutSpin = new QHBoxLayout( layout );
121 layoutSpin->addStretch (); 121 layoutSpin->addStretch ();
122 layoutSpin->addWidget ( mSuspendSpin ); 122 layoutSpin->addWidget ( mSuspendSpin );
123 layoutSpin->addStretch (); 123 layoutSpin->addStretch ();
124 124
125 QVBox * bbox = new QVBox ( this ); 125 QVBox * bbox = new QVBox ( this );
126 layout->addWidget ( bbox ); 126 layout->addWidget ( bbox );
127 bbox->layout()->setSpacing( 2 ); 127 bbox->layout()->setSpacing( 2 );
128 labb = new QLabel("Press \"Cancel\" or \"Esc\" to suspend!",bbox); 128 labb = new QLabel("Press \"Cancel\" or \"Esc\" to suspend!",bbox);
129 labb->setAlignment(AlignCenter); 129 labb->setAlignment(AlignCenter);
130 mSuspendButton = new QPushButton( "Suspend", bbox); 130 mSuspendButton = new QPushButton( "Suspend", bbox);
131 QPushButton* silen = new QPushButton( " Stop sound ", bbox); 131 QPushButton* silen = new QPushButton( " Stop sound ", bbox);
132 QPushButton* okbut = new QPushButton( "Ok", bbox); 132 QPushButton* okbut = new QPushButton( "Ok", bbox);
133 mSuspendButton->setFont( fo ); 133 mSuspendButton->setFont( fo );
134 silen->setFont( fo ); 134 silen->setFont( fo );
135 okbut->setFont( fo ); 135 okbut->setFont( fo );
136 okbut->setDefault( true ); 136 okbut->setDefault( true );
137 connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) ); 137 connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) );
138 connect (mSuspendButton, SIGNAL( clicked() ), this, SLOT (slotSuspend() ) ); 138 connect (mSuspendButton, SIGNAL( clicked() ), this, SLOT (slotSuspend() ) );
139 connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) ); 139 connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) );
140 connect (mSuspendSpin , SIGNAL( valueChanged ( int ) ), this, SLOT ( spinBoxChanged( int ) ) );
140#ifndef _WIN32_ 141#ifndef _WIN32_
141 if ( QFile::exists ( "/dev/sharp_led" ) ) 142 if ( QFile::exists ( "/dev/sharp_led" ) )
142 fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 143 fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
143 else 144 else
144#endif 145#endif
145 fd_led = 0; 146 fd_led = 0;
146 statusLED.which = SHARP_LED_SALARM; 147 statusLED.which = SHARP_LED_SALARM;
147 mSilent = false; 148 mSilent = false;
148 mSuspendCounter = 0; 149 mSuspendCounter = 0;
149 setServerNotification( true ); 150 setServerNotification( true );
150} 151}
151void AlarmDialog::reject () 152void AlarmDialog::reject ()
152{ 153{
153 QTimer::singleShot ( 3000, this, SLOT (suspend()) ); 154 QTimer::singleShot ( 3000, this, SLOT (suspend()) );
154 slotSuspend(); 155 slotSuspend();
155} 156}
156AlarmDialog::~AlarmDialog() 157AlarmDialog::~AlarmDialog()
157{ 158{
158} 159}
159void AlarmDialog::silent () 160void AlarmDialog::silent ()
160{ 161{
161 mSilent = true; 162 mSilent = true;
162} 163}
163void AlarmDialog::accept() 164void AlarmDialog::accept()
164{ 165{
165 slotOk(); 166 slotOk();
166} 167}
167 168
168void AlarmDialog::suspend() 169void AlarmDialog::suspend()
169{ 170{
170#ifdef DESKTOP_VERSION 171#ifdef DESKTOP_VERSION
171 172
172#else 173#else
173 Sound::soundAlarm (); 174 Sound::soundAlarm ();
174#endif 175#endif
175} 176}
176void AlarmDialog::slotOk() 177void AlarmDialog::slotOk()
177{ 178{
178 mStopAlarm = true; 179 mStopAlarm = true;
179 mMissedAlarms->setText("(No missed Alarms)"); 180 mMissedAlarms->setText("(No missed Alarms)");
180 mMessage->setText(""); 181 mMessage->setText("");
181 mMissedAlarmsCombo->clear(); 182 mMissedAlarmsCombo->clear();
182#ifndef _WIN32_ 183#ifndef _WIN32_
183 if ( fd_led > 0 ) { 184 if ( fd_led > 0 ) {
184 statusLED.status = LED_SALARM_OFF ; 185 statusLED.status = LED_SALARM_OFF ;
185 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); 186 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
186 } 187 }
187#endif 188#endif
188 QDialog::accept(); 189 QDialog::accept();
189} 190}
190 191
191void AlarmDialog::slotSuspend() 192void AlarmDialog::slotSuspend()
192{ 193{
193 //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value()); 194 //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value());
194 mStopAlarm = true; 195 mStopAlarm = true;
195 QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 ); 196 QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 );
196 QString mess = "suspend_alarm" +mFileName+"+++" ; 197 QString mess = "suspend_alarm" +mFileName+"+++" ;
197 if ( mMessage->text().left( 10 ) !="Suspended:" ) 198 if ( mMessage->text().left( 10 ) !="Suspended:" )
198 mess += "Suspended:\n"; 199 mess += "Suspended:\n";
199 mess +=mMessage->text(); 200 mess +=mMessage->text();
200#ifndef DESKTOP_VERSION 201#ifndef DESKTOP_VERSION
201 if ( mServerNotification ) 202 if ( mServerNotification )
202 AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1()); 203 AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1());
203#endif 204#endif
204 emit addAlarm( nextA , mess ); 205 emit addAlarm( nextA , mess );
205 slotOk(); 206 slotOk();
206} 207}
207 208
208void AlarmDialog::setServerNotification( bool b ) 209void AlarmDialog::setServerNotification( bool b )
209{ 210{
210 mServerNotification = b; 211 mServerNotification = b;
211} 212}
212int AlarmDialog::getSuspendTime( ) 213int AlarmDialog::getSuspendTime( )
213{ 214{
214 return mSuspendSpin->value(); 215 return mSuspendSpin->value();
215 216
216} 217}
217void AlarmDialog::setSuspendTime( int val ) 218void AlarmDialog::setSuspendTime( int val )
218{ 219{
219 mSuspendSpin->setValue( val ); 220 mSuspendSpin->setValue( val );
220} 221}
221bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes) 222bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes)
222{ 223{
223 if ( mess.left( 9) != "Suspended" ) 224 if ( mess.left( 9) != "Suspended" )
224 mSuspendCounter = suspendtimes; 225 mSuspendCounter = suspendtimes;
225 mPauseCount = pause; 226 mPauseCount = pause;
226 mFileName = fn; 227 mFileName = fn;
227 mPlayWav = playwav; 228 mPlayWav = playwav;
228 if ( !QFile::exists( fn ) ) 229 if ( !QFile::exists( fn ) )
229 mFileName = ""; 230 mFileName = "";
230 alarmCounter = 0 ; 231 alarmCounter = 0 ;
231 maxAlarmReplay = replay ; 232 maxAlarmReplay = replay ;
232 mStopAlarm = false; 233 mStopAlarm = false;
233 mSilent = false; 234 mSilent = false;
234 if ( !mMessage->text().stripWhiteSpace().isEmpty() ) { 235 if ( !mMessage->text().stripWhiteSpace().isEmpty() ) {
235 mMissedAlarmsCombo->show(); 236 mMissedAlarmsCombo->show();
236 QString newItem = mMessage->text().stripWhiteSpace(); 237 QString newItem = mMessage->text().stripWhiteSpace();
237 newItem.replace( QRegExp("\n"), QString(" ") ); 238 newItem.replace( QRegExp("\n"), QString(" ") );
238 mMissedAlarmsCombo->insertItem( newItem ); 239 mMissedAlarmsCombo->insertItem( newItem );
239 mMissedAlarms->setText( "Missed alarms:"); 240 mMissedAlarms->setText( "Missed alarms:");
240 } else 241 } else
241 mMissedAlarmsCombo->hide(); 242 mMissedAlarmsCombo->hide();
242 mMessage->setText(mess); 243 mMessage->setText(mess);
243 int w =sizeHint().width() ; 244 int w =sizeHint().width() ;
244 int h = sizeHint().height() ; 245 int h = sizeHint().height() ;
245 int dw = QApplication::desktop()->width(); 246 int dw = QApplication::desktop()->width();
246 int dh = QApplication::desktop()->height(); 247 int dh = QApplication::desktop()->height();
247 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 248 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
248 show(); 249 show();
249 raise(); 250 raise();
250 //qApp->processEvents(); 251 //qApp->processEvents();
251 //repaint(); 252 //repaint();
252 qApp->processEvents(); 253 qApp->processEvents();
253 254
254#ifndef _WIN32_ 255#ifndef _WIN32_
255 if ( fd_led > 0 ) { 256 if ( fd_led > 0 ) {
256 statusLED.status = LED_SALARM_ON ; 257 statusLED.status = LED_SALARM_ON ;
257 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); 258 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
258 } 259 }
259#endif 260#endif
260 playSoundTimer->start( 1000, true ); 261 playSoundTimer->start( 1000, true );
261 return true; 262 return true;
262 263
263} 264}
264 265
266void AlarmDialog::spinBoxChanged( int )
267{
268 mSilent = true;
269}
265 270
266void AlarmDialog::playSound () 271void AlarmDialog::playSound ()
267{ 272{
268 273
269 if (mStopAlarm ) 274 if (mStopAlarm )
270 return; 275 return;
271 if ( mSilent ) 276 if ( mSilent )
272 return; 277 return;
273 showNormal(); 278 showNormal();
274 setActiveWindow(); 279 setActiveWindow();
275 raise(); 280 raise();
276 mSuspendSpin->setFocus(); 281 mSuspendSpin->setFocus();
277 282
278 283
279 qApp->processEvents(); 284 qApp->processEvents();
280 if ( alarmCounter < maxAlarmReplay && ! mSilent) { 285 if ( alarmCounter < maxAlarmReplay && ! mSilent) {
281 ++alarmCounter; 286 ++alarmCounter;
282#ifdef DESKTOP_VERSION 287#ifdef DESKTOP_VERSION
283 mPlayWav = true; 288 mPlayWav = true;
284#endif 289#endif
285 if ( !mPlayWav || mFileName.length() < 2 ) { 290 if ( !mPlayWav || mFileName.length() < 2 ) {
286 291
287#ifdef DESKTOP_VERSION 292#ifdef DESKTOP_VERSION
288 qDebug("Sound play not possible - file not found"); 293 qDebug("Sound play not possible - file not found");
289#else 294#else
290 Sound::soundAlarm (); 295 Sound::soundAlarm ();
291#endif 296#endif
292 } else 297 } else
293 298
294 { 299 {
295#ifdef DESKTOP_VERSION 300#ifdef DESKTOP_VERSION
296#ifdef _WIN32_ 301#ifdef _WIN32_
297 QSound::play ( mFileName ); 302 QSound::play ( mFileName );
298#else 303#else
299 304
300 QString command = "playwave -r 22050 " + mFileName; 305 QString command = "playwave -r 22050 " + mFileName;
301 qDebug("KO: Playing file %s with 22kHz",mFileName.latin1() ); 306 qDebug("KO: Playing file %s with 22kHz",mFileName.latin1() );
302 int ret = system ( command.latin1() ); 307 int ret = system ( command.latin1() );
303 if ( ret != 0 ) { 308 if ( ret != 0 ) {
304 qDebug("Sound play command failed: %s ",command.latin1() ); 309 qDebug("Sound play command failed: %s ",command.latin1() );
305 } 310 }
306 311
307#endif 312#endif
308 313
309#else 314#else
310 QSound::play ( mFileName ); 315 QSound::play ( mFileName );
311#endif 316#endif
312 qDebug("BEEP!"); 317 qDebug("BEEP!");
313 } 318 }
314 } else { 319 } else {
315 if ( ! mSilent && mSuspendCounter > 0 ) { 320 if ( ! mSilent && mSuspendCounter > 0 ) {
316 --mSuspendCounter; 321 --mSuspendCounter;
317 reject (); 322 reject ();
318 hide(); 323 hide();
319 return; 324 return;
320 } 325 }
321 } 326 }
322 playSoundTimer->start( mPauseCount * 1000, true ); 327 playSoundTimer->start( mPauseCount * 1000, true );
323} 328}