summaryrefslogtreecommitdiffabout
path: root/kalarmd/alarmdialog.cpp
Unidiff
Diffstat (limited to 'kalarmd/alarmdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kalarmd/alarmdialog.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/kalarmd/alarmdialog.cpp b/kalarmd/alarmdialog.cpp
index bdeee4a..53ff488 100644
--- a/kalarmd/alarmdialog.cpp
+++ b/kalarmd/alarmdialog.cpp
@@ -3,91 +3,92 @@
3 Copyright (c) 2000 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2000 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24// $Id$ 24// $Id$
25 25
26#include <qhbox.h> 26#include <qhbox.h>
27#include <qvbox.h> 27#include <qvbox.h>
28#include <qapp.h> 28#include <qapp.h>
29#include <qlabel.h> 29#include <qlabel.h>
30#include <qlayout.h> 30#include <qlayout.h>
31#include <qfile.h> 31#include <qfile.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qsound.h> 33#include <qsound.h>
34#include <qpushbutton.h> 34#include <qpushbutton.h>
35#include <qregexp.h>
35#ifndef DESKTOP_VERSION 36#ifndef DESKTOP_VERSION
36#define protected public 37#define protected public
37#include <qspinbox.h> 38#include <qspinbox.h>
38#undef protected 39#undef protected
39#else 40#else
40#include <qspinbox.h> 41#include <qspinbox.h>
41#endif 42#endif
42#include <stdlib.h> 43#include <stdlib.h>
43#ifndef _WIN32_ 44#ifndef _WIN32_
44#include <unistd.h> 45#include <unistd.h>
45#include <sys/ioctl.h> 46#include <sys/ioctl.h>
46#endif 47#endif
47#include <stdio.h> 48#include <stdio.h>
48#include <fcntl.h> 49#include <fcntl.h>
49 50
50#ifndef DESKTOP_VERSION 51#ifndef DESKTOP_VERSION
51#include <qtopia/alarmserver.h> 52#include <qtopia/alarmserver.h>
52#include <qpe/resource.h> 53#include <qpe/resource.h>
53#include <qtopia/sound.h> 54#include <qtopia/sound.h>
54 55
55#endif 56#endif
56 57
57#include "alarmdialog.h" 58#include "alarmdialog.h"
58 59
59 60
60AlarmDialog::AlarmDialog(QWidget *parent,const char *name) 61AlarmDialog::AlarmDialog(QWidget *parent,const char *name)
61 : QDialog (parent, name, true, Qt::WStyle_StaysOnTop ) 62 : QDialog (parent, name, true, Qt::WStyle_Customize |Qt::WStyle_StaysOnTop | Qt::WStyle_DialogBorder)
62{ 63{
63 setCaption( "KO/Pi Alarm!" ); 64 setCaption( "KO/Pi Alarm!" );
64 QVBoxLayout* layout = new QVBoxLayout( this); 65 QVBoxLayout* layout = new QVBoxLayout( this);
65 QLabel* l = new QLabel("The following event triggered alarm:",this); 66 QLabel* l = new QLabel("The following event triggered alarm:",this);
66 layout->addWidget ( l ); 67 layout->addWidget ( l );
67 l->setAlignment( AlignCenter); 68 l->setAlignment( AlignCenter);
68 mMessage = new QLabel ( " ", this ); 69 mMessage = new QLabel ( " ", this );
69 int fs = 18; 70 int fs = 18;
70 int fs2 = 12; 71 int fs2 = 12;
71 int baseSize = 6; 72 int baseSize = 6;
72 if ( QApplication::desktop()->width() < 480 ) { 73 if ( QApplication::desktop()->width() < 480 ) {
73 fs2 = 10; 74 fs2 = 10;
74 fs = 12; 75 fs = 12;
75 baseSize = 4; 76 baseSize = 4;
76 } 77 }
77 layout->setSpacing( 3 ); 78 layout->setSpacing( 3 );
78 layout->setMargin( 3 ); 79 layout->setMargin( 3 );
79 QFont fo = QApplication::font(); 80 QFont fo = QApplication::font();
80 fo.setBold( true ); 81 fo.setBold( true );
81 fo.setPointSize( fs2 ); 82 fo.setPointSize( fs2 );
82 l->setFont( fo ); 83 l->setFont( fo );
83 fo.setPointSize( fs ); 84 fo.setPointSize( fs );
84 mMessage->setFont(fo ); 85 mMessage->setFont(fo );
85 mMessage->setAlignment( AlignCenter); 86 mMessage->setAlignment( AlignCenter);
86 layout->addWidget ( mMessage ); 87 layout->addWidget ( mMessage );
87 mMissedAlarms= new QLabel ( "(No missed Alarms)", this ); 88 mMissedAlarms= new QLabel ( "(No missed Alarms)", this );
88 mMissedAlarms->setAlignment( AlignCenter); 89 mMissedAlarms->setAlignment( AlignCenter);
89 90
90 playSoundTimer = new QTimer( this ); 91 playSoundTimer = new QTimer( this );
91 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) ); 92 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) );
92 93
93 playSoundTimer->stop(); 94 playSoundTimer->stop();
@@ -203,104 +204,106 @@ void AlarmDialog::slotSuspend()
203 emit addAlarm( nextA , mess ); 204 emit addAlarm( nextA , mess );
204 slotOk(); 205 slotOk();
205} 206}
206 207
207void AlarmDialog::setServerNotification( bool b ) 208void AlarmDialog::setServerNotification( bool b )
208{ 209{
209 mServerNotification = b; 210 mServerNotification = b;
210} 211}
211int AlarmDialog::getSuspendTime( ) 212int AlarmDialog::getSuspendTime( )
212{ 213{
213 return mSuspendSpin->value(); 214 return mSuspendSpin->value();
214 215
215} 216}
216void AlarmDialog::setSuspendTime( int val ) 217void AlarmDialog::setSuspendTime( int val )
217{ 218{
218 mSuspendSpin->setValue( val ); 219 mSuspendSpin->setValue( val );
219} 220}
220bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes) 221bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes)
221{ 222{
222 if ( mess.left( 9) != "Suspended" ) 223 if ( mess.left( 9) != "Suspended" )
223 mSuspendCounter = suspendtimes; 224 mSuspendCounter = suspendtimes;
224 mPauseCount = pause; 225 mPauseCount = pause;
225 mFileName = fn; 226 mFileName = fn;
226 mPlayWav = playwav; 227 mPlayWav = playwav;
227 if ( !QFile::exists( fn ) ) 228 if ( !QFile::exists( fn ) )
228 mFileName = ""; 229 mFileName = "";
229 alarmCounter = 0 ; 230 alarmCounter = 0 ;
230 maxAlarmReplay = replay ; 231 maxAlarmReplay = replay ;
231 mStopAlarm = false; 232 mStopAlarm = false;
232 mSilent = false; 233 mSilent = false;
233 if ( !mMessage->text().stripWhiteSpace().isEmpty() ) { 234 if ( !mMessage->text().stripWhiteSpace().isEmpty() ) {
234 mMissedAlarmsCombo->show(); 235 mMissedAlarmsCombo->show();
235 mMissedAlarmsCombo->insertItem( mMessage->text().stripWhiteSpace() ); 236 QString newItem = mMessage->text().stripWhiteSpace();
237 newItem.replace( QRegExp("\n"), QString(" ") );
238 mMissedAlarmsCombo->insertItem( newItem );
236 mMissedAlarms->setText( "Missed alarms:"); 239 mMissedAlarms->setText( "Missed alarms:");
237 } else 240 } else
238 mMissedAlarmsCombo->hide(); 241 mMissedAlarmsCombo->hide();
239 mMessage->setText(mess); 242 mMessage->setText(mess);
240 int w =sizeHint().width() ; 243 int w =sizeHint().width() ;
241 int h = sizeHint().height() ; 244 int h = sizeHint().height() ;
242 int dw = QApplication::desktop()->width(); 245 int dw = QApplication::desktop()->width();
243 int dh = QApplication::desktop()->height(); 246 int dh = QApplication::desktop()->height();
244 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 247 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
245 show(); 248 show();
246 raise(); 249 raise();
247 //qApp->processEvents(); 250 //qApp->processEvents();
248 //repaint(); 251 //repaint();
249 qApp->processEvents(); 252 qApp->processEvents();
250 253
251#ifndef _WIN32_ 254#ifndef _WIN32_
252 if ( fd_led > 0 ) { 255 if ( fd_led > 0 ) {
253 statusLED.status = LED_SALARM_ON ; 256 statusLED.status = LED_SALARM_ON ;
254 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); 257 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
255 } 258 }
256#endif 259#endif
257 playSoundTimer->start( 1000, true ); 260 playSoundTimer->start( 1000, true );
258 return true; 261 return true;
259 262
260} 263}
261 264
262 265
263void AlarmDialog::playSound () 266void AlarmDialog::playSound ()
264{ 267{
265 268
266 if (mStopAlarm ) 269 if (mStopAlarm )
267 return; 270 return;
268 if (mSilent ) 271 if ( mSilent )
269 return; 272 return;
270 showNormal(); 273 showNormal();
271 setActiveWindow(); 274 setActiveWindow();
275 raise();
272 mSuspendSpin->setFocus(); 276 mSuspendSpin->setFocus();
273 raise(); 277
274 repaint();
275 278
276 qApp->processEvents(); 279 qApp->processEvents();
277 if ( alarmCounter < maxAlarmReplay && ! mSilent) { 280 if ( alarmCounter < maxAlarmReplay && ! mSilent) {
278 ++alarmCounter; 281 ++alarmCounter;
279#ifdef DESKTOP_VERSION 282#ifdef DESKTOP_VERSION
280 mPlayWav = true; 283 mPlayWav = true;
281#endif 284#endif
282 if ( !mPlayWav || mFileName.length() < 2 ) { 285 if ( !mPlayWav || mFileName.length() < 2 ) {
283 286
284#ifdef DESKTOP_VERSION 287#ifdef DESKTOP_VERSION
285 qDebug("Sound play not possible - file not found"); 288 qDebug("Sound play not possible - file not found");
286#else 289#else
287 Sound::soundAlarm (); 290 Sound::soundAlarm ();
288#endif 291#endif
289 } else 292 } else
290 293
291 { 294 {
292#ifdef DESKTOP_VERSION 295#ifdef DESKTOP_VERSION
293#ifdef _WIN32_ 296#ifdef _WIN32_
294 QSound::play ( mFileName ); 297 QSound::play ( mFileName );
295#else 298#else
296 299
297 QString command = "playwave -r 22050 " + mFileName; 300 QString command = "playwave -r 22050 " + mFileName;
298 qDebug("KO: Playing file %s with 22kHz",mFileName.latin1() ); 301 qDebug("KO: Playing file %s with 22kHz",mFileName.latin1() );
299 int ret = system ( command.latin1() ); 302 int ret = system ( command.latin1() );
300 if ( ret != 0 ) { 303 if ( ret != 0 ) {
301 qDebug("Sound play command failed: %s ",command.latin1() ); 304 qDebug("Sound play command failed: %s ",command.latin1() );
302 } 305 }
303 306
304#endif 307#endif
305 308
306#else 309#else