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
@@ -1,125 +1,126 @@
1/* 1/*
2 This file is part of the KDE alarm daemon. 2 This file is part of the KDE alarm daemon.
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();
94 95
95 layout->addWidget ( mMissedAlarms ); 96 layout->addWidget ( mMissedAlarms );
96 mMissedAlarmsCombo = new QComboBox ( this ); 97 mMissedAlarmsCombo = new QComboBox ( this );
97 layout->addWidget ( mMissedAlarmsCombo ); 98 layout->addWidget ( mMissedAlarmsCombo );
98 99
99 QLabel* labb = new QLabel("Suspend duration (minutes):",this); 100 QLabel* labb = new QLabel("Suspend duration (minutes):",this);
100 labb->setAlignment(AlignCenter); 101 labb->setAlignment(AlignCenter);
101 layout->addWidget ( labb ); 102 layout->addWidget ( labb );
102 fo = font(); 103 fo = font();
103 int pointSize = 36; 104 int pointSize = 36;
104 if ( QApplication::desktop()->width() <= 320 ) 105 if ( QApplication::desktop()->width() <= 320 )
105 pointSize = 18; 106 pointSize = 18;
106 fo.setPointSize( pointSize ); 107 fo.setPointSize( pointSize );
107 mSuspendSpin = new QSpinBox(1,1440,1,this); 108 mSuspendSpin = new QSpinBox(1,1440,1,this);
108 mSuspendSpin->setFont( fo ); 109 mSuspendSpin->setFont( fo );
109 mSuspendSpin->setValue(7); // default suspend duration 110 mSuspendSpin->setValue(7); // default suspend duration
110 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 111 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
111 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 112 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
112 113
113#if QT_VERSION < 0x030000 114#if QT_VERSION < 0x030000
114 mSuspendSpin->upButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize )); 115 mSuspendSpin->upButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize ));
115 mSuspendSpin->downButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize )); 116 mSuspendSpin->downButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize ));
116#endif 117#endif
117 mSuspendSpin->setFixedSize( 18*baseSize, 10*baseSize+2 ); 118 mSuspendSpin->setFixedSize( 18*baseSize, 10*baseSize+2 );
118 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 119 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
119 QHBoxLayout* layoutSpin = new QHBoxLayout( layout ); 120 QHBoxLayout* layoutSpin = new QHBoxLayout( layout );
120 layoutSpin->addStretch (); 121 layoutSpin->addStretch ();
121 layoutSpin->addWidget ( mSuspendSpin ); 122 layoutSpin->addWidget ( mSuspendSpin );
122 layoutSpin->addStretch (); 123 layoutSpin->addStretch ();
123 124
124 QVBox * bbox = new QVBox ( this ); 125 QVBox * bbox = new QVBox ( this );
125 layout->addWidget ( bbox ); 126 layout->addWidget ( bbox );
@@ -171,150 +172,152 @@ void AlarmDialog::suspend()
171#else 172#else
172 Sound::soundAlarm (); 173 Sound::soundAlarm ();
173#endif 174#endif
174} 175}
175void AlarmDialog::slotOk() 176void AlarmDialog::slotOk()
176{ 177{
177 mStopAlarm = true; 178 mStopAlarm = true;
178 mMissedAlarms->setText("(No missed Alarms)"); 179 mMissedAlarms->setText("(No missed Alarms)");
179 mMessage->setText(""); 180 mMessage->setText("");
180 mMissedAlarmsCombo->clear(); 181 mMissedAlarmsCombo->clear();
181#ifndef _WIN32_ 182#ifndef _WIN32_
182 if ( fd_led > 0 ) { 183 if ( fd_led > 0 ) {
183 statusLED.status = LED_SALARM_OFF ; 184 statusLED.status = LED_SALARM_OFF ;
184 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); 185 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
185 } 186 }
186#endif 187#endif
187 QDialog::accept(); 188 QDialog::accept();
188} 189}
189 190
190void AlarmDialog::slotSuspend() 191void AlarmDialog::slotSuspend()
191{ 192{
192 //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value()); 193 //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value());
193 mStopAlarm = true; 194 mStopAlarm = true;
194 QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 ); 195 QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 );
195 QString mess = "suspend_alarm" +mFileName+"+++" ; 196 QString mess = "suspend_alarm" +mFileName+"+++" ;
196 if ( mMessage->text().left( 10 ) !="Suspended:" ) 197 if ( mMessage->text().left( 10 ) !="Suspended:" )
197 mess += "Suspended:\n"; 198 mess += "Suspended:\n";
198 mess +=mMessage->text(); 199 mess +=mMessage->text();
199#ifndef DESKTOP_VERSION 200#ifndef DESKTOP_VERSION
200 if ( mServerNotification ) 201 if ( mServerNotification )
201 AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1()); 202 AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1());
202#endif 203#endif
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
307 QSound::play ( mFileName ); 310 QSound::play ( mFileName );
308#endif 311#endif
309 qDebug("BEEP!"); 312 qDebug("BEEP!");
310 } 313 }
311 } else { 314 } else {
312 if ( ! mSilent && mSuspendCounter > 0 ) { 315 if ( ! mSilent && mSuspendCounter > 0 ) {
313 --mSuspendCounter; 316 --mSuspendCounter;
314 reject (); 317 reject ();
315 hide(); 318 hide();
316 return; 319 return;
317 } 320 }
318 } 321 }
319 playSoundTimer->start( mPauseCount * 1000, true ); 322 playSoundTimer->start( mPauseCount * 1000, true );
320} 323}