summaryrefslogtreecommitdiffabout
path: root/kalarmd/alarmdialog.cpp
Unidiff
Diffstat (limited to 'kalarmd/alarmdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kalarmd/alarmdialog.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/kalarmd/alarmdialog.cpp b/kalarmd/alarmdialog.cpp
index 521781e..751ba57 100644
--- a/kalarmd/alarmdialog.cpp
+++ b/kalarmd/alarmdialog.cpp
@@ -1,258 +1,261 @@
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 <qspinbox.h> 35#include <qspinbox.h>
36#include <stdlib.h> 36#include <stdlib.h>
37#ifndef _WIN32_ 37#ifndef _WIN32_
38#include <unistd.h> 38#include <unistd.h>
39#include <sys/ioctl.h> 39#include <sys/ioctl.h>
40#endif 40#endif
41#include <stdio.h> 41#include <stdio.h>
42#include <fcntl.h> 42#include <fcntl.h>
43 43
44#ifndef DESKTOP_VERSION 44#ifndef DESKTOP_VERSION
45#include <qtopia/alarmserver.h> 45#include <qtopia/alarmserver.h>
46#include <qpe/resource.h> 46#include <qpe/resource.h>
47#include <qtopia/sound.h> 47#include <qtopia/sound.h>
48#endif 48#endif
49 49
50#include "alarmdialog.h" 50#include "alarmdialog.h"
51 51
52 52
53AlarmDialog::AlarmDialog(QWidget *parent,const char *name) 53AlarmDialog::AlarmDialog(QWidget *parent,const char *name)
54 : QDialog (parent, name, true, Qt::WStyle_StaysOnTop ) 54 : QDialog (parent, name, true, Qt::WStyle_StaysOnTop )
55{ 55{
56 setCaption( "KO/Pi Alarm!" ); 56 setCaption( "KO/Pi Alarm!" );
57 QVBoxLayout* layout = new QVBoxLayout( this); 57 QVBoxLayout* layout = new QVBoxLayout( this);
58 QLabel* l = new QLabel("The following event triggered alarm:",this); 58 QLabel* l = new QLabel("The following event triggered alarm:",this);
59 layout->addWidget ( l ); 59 layout->addWidget ( l );
60 l->setAlignment( AlignCenter); 60 l->setAlignment( AlignCenter);
61 mMessage = new QLabel ( " ", this ); 61 mMessage = new QLabel ( " ", this );
62 int fs = 18; 62 int fs = 18;
63 int fs2 = 12; 63 int fs2 = 12;
64 if ( QApplication::desktop()->width() < 480 ) { 64 if ( QApplication::desktop()->width() < 480 ) {
65 setMaximumSize(220, 260); 65 setMaximumSize(220, 260);
66 fs2 = 10; 66 fs2 = 10;
67 } 67 }
68 else { 68 else {
69 setMaximumSize(440, 440); 69 setMaximumSize(440, 440);
70 } 70 }
71 layout->setSpacing( 3 ); 71 layout->setSpacing( 3 );
72 layout->setMargin( 3 ); 72 layout->setMargin( 3 );
73 73 QFont fo = QApplication::font();
74 l->setFont( QFont("helvetica",fs2, QFont::Bold) ); 74 fo.setBold( true );
75 mMessage->setFont( QFont("helvetica",fs, QFont::Bold) ); 75 fo.setPointSize( fs2 );
76 l->setFont( fo );
77 fo.setPointSize( fs );
78 mMessage->setFont(fo );
76 mMessage->setAlignment( AlignCenter); 79 mMessage->setAlignment( AlignCenter);
77 l = new QLabel("Missed Alarms:",this); 80 l = new QLabel("Missed Alarms:",this);
78 l->setAlignment( AlignCenter); 81 l->setAlignment( AlignCenter);
79 layout->addWidget ( mMessage ); 82 layout->addWidget ( mMessage );
80 layout->addWidget ( l ); 83 layout->addWidget ( l );
81 mMissedAlarms= new QLabel ( "", this ); 84 mMissedAlarms= new QLabel ( "", this );
82 mMissedAlarms->setAlignment( AlignCenter); 85 mMissedAlarms->setAlignment( AlignCenter);
83 86
84 playSoundTimer = new QTimer( this ); 87 playSoundTimer = new QTimer( this );
85 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) ); 88 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) );
86 89
87 playSoundTimer->stop(); 90 playSoundTimer->stop();
88 91
89 layout->addWidget ( mMissedAlarms ); 92 layout->addWidget ( mMissedAlarms );
90 QHBox *suspendBox = new QHBox( this ); 93 QHBox *suspendBox = new QHBox( this );
91 suspendBox->setSpacing(3); 94 suspendBox->setSpacing(3);
92 layout->addWidget ( suspendBox ); 95 layout->addWidget ( suspendBox );
93 (void)new QLabel("Suspend duration (minutes):",suspendBox); 96 (void)new QLabel("Suspend duration (minutes):",suspendBox);
94 mSuspendSpin = new QSpinBox(1,1440,1,suspendBox); 97 mSuspendSpin = new QSpinBox(1,1440,1,suspendBox);
95 mSuspendSpin->setValue(7); // default suspend duration 98 mSuspendSpin->setValue(7); // default suspend duration
96 QHBox * bbox = new QHBox ( this ); 99 QHBox * bbox = new QHBox ( this );
97 layout->addWidget ( bbox ); 100 layout->addWidget ( bbox );
98 bbox->layout()->setSpacing( 5 ); 101 bbox->layout()->setSpacing( 5 );
99 QPushButton* suspend = new QPushButton( "Suspend", bbox); 102 QPushButton* suspend = new QPushButton( "Suspend", bbox);
100 QPushButton* silen = new QPushButton( " Stop sound ", bbox); 103 QPushButton* silen = new QPushButton( " Stop sound ", bbox);
101 QPushButton* okbut = new QPushButton( "Ok", bbox); 104 QPushButton* okbut = new QPushButton( "Ok", bbox);
102 connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) ); 105 connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) );
103 connect (suspend , SIGNAL( clicked() ), this, SLOT (slotSuspend() ) ); 106 connect (suspend , SIGNAL( clicked() ), this, SLOT (slotSuspend() ) );
104 connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) ); 107 connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) );
105#ifndef _WIN32_ 108#ifndef _WIN32_
106 if ( QFile::exists ( "/dev/sharp_led" ) ) 109 if ( QFile::exists ( "/dev/sharp_led" ) )
107 fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 110 fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
108 else 111 else
109#endif 112#endif
110 fd_led = 0; 113 fd_led = 0;
111 statusLED.which = SHARP_LED_SALARM; 114 statusLED.which = SHARP_LED_SALARM;
112 mSilent = false; 115 mSilent = false;
113 mSuspendCounter = 0; 116 mSuspendCounter = 0;
114 setServerNotification( true ); 117 setServerNotification( true );
115} 118}
116void AlarmDialog::reject () 119void AlarmDialog::reject ()
117{ 120{
118 QTimer::singleShot ( 3000, this, SLOT (suspend()) ); 121 QTimer::singleShot ( 3000, this, SLOT (suspend()) );
119 slotSuspend(); 122 slotSuspend();
120} 123}
121AlarmDialog::~AlarmDialog() 124AlarmDialog::~AlarmDialog()
122{ 125{
123} 126}
124void AlarmDialog::silent () 127void AlarmDialog::silent ()
125{ 128{
126 mSilent = true; 129 mSilent = true;
127} 130}
128void AlarmDialog::accept() 131void AlarmDialog::accept()
129{ 132{
130 slotOk(); 133 slotOk();
131} 134}
132 135
133void AlarmDialog::suspend() 136void AlarmDialog::suspend()
134{ 137{
135#ifdef DESKTOP_VERSION 138#ifdef DESKTOP_VERSION
136 139
137#else 140#else
138 Sound::soundAlarm (); 141 Sound::soundAlarm ();
139#endif 142#endif
140} 143}
141void AlarmDialog::slotOk() 144void AlarmDialog::slotOk()
142{ 145{
143 mStopAlarm = true; 146 mStopAlarm = true;
144 mMissedAlarms->setText(""); 147 mMissedAlarms->setText("");
145 mMessage->setText(""); 148 mMessage->setText("");
146#ifndef _WIN32_ 149#ifndef _WIN32_
147 if ( fd_led > 0 ) { 150 if ( fd_led > 0 ) {
148 statusLED.status = LED_SALARM_OFF ; 151 statusLED.status = LED_SALARM_OFF ;
149 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); 152 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
150 } 153 }
151#endif 154#endif
152 QDialog::accept(); 155 QDialog::accept();
153} 156}
154 157
155void AlarmDialog::slotSuspend() 158void AlarmDialog::slotSuspend()
156{ 159{
157 //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value()); 160 //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value());
158 mStopAlarm = true; 161 mStopAlarm = true;
159 QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 ); 162 QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 );
160 QString mess = "suspend_alarm" +mFileName+"+++" ; 163 QString mess = "suspend_alarm" +mFileName+"+++" ;
161 if ( mMessage->text().left( 10 ) !="Suspended:" ) 164 if ( mMessage->text().left( 10 ) !="Suspended:" )
162 mess += "Suspended:\n"; 165 mess += "Suspended:\n";
163 mess +=mMessage->text(); 166 mess +=mMessage->text();
164#ifndef DESKTOP_VERSION 167#ifndef DESKTOP_VERSION
165 if ( mServerNotification ) 168 if ( mServerNotification )
166 AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1()); 169 AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1());
167#endif 170#endif
168 emit addAlarm( nextA , mess ); 171 emit addAlarm( nextA , mess );
169 slotOk(); 172 slotOk();
170} 173}
171 174
172void AlarmDialog::setServerNotification( bool b ) 175void AlarmDialog::setServerNotification( bool b )
173{ 176{
174 mServerNotification = b; 177 mServerNotification = b;
175} 178}
176int AlarmDialog::getSuspendTime( ) 179int AlarmDialog::getSuspendTime( )
177{ 180{
178 return mSuspendSpin->value(); 181 return mSuspendSpin->value();
179 182
180} 183}
181void AlarmDialog::setSuspendTime( int val ) 184void AlarmDialog::setSuspendTime( int val )
182{ 185{
183 mSuspendSpin->setValue( val ); 186 mSuspendSpin->setValue( val );
184} 187}
185bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes) 188bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes)
186{ 189{
187 if ( mess.left( 9) != "Suspended" ) 190 if ( mess.left( 9) != "Suspended" )
188 mSuspendCounter = suspendtimes; 191 mSuspendCounter = suspendtimes;
189 mPauseCount = pause; 192 mPauseCount = pause;
190 mFileName = fn; 193 mFileName = fn;
191 mPlayWav = playwav; 194 mPlayWav = playwav;
192 if ( !QFile::exists( fn ) ) 195 if ( !QFile::exists( fn ) )
193 mFileName = ""; 196 mFileName = "";
194 alarmCounter = 0 ; 197 alarmCounter = 0 ;
195 maxAlarmReplay = replay ; 198 maxAlarmReplay = replay ;
196 mStopAlarm = false; 199 mStopAlarm = false;
197 mSilent = false; 200 mSilent = false;
198 if ( mMissedAlarms->text() == "" ) 201 if ( mMissedAlarms->text() == "" )
199 mMissedAlarms->setText( mMessage->text()); 202 mMissedAlarms->setText( mMessage->text());
200 else 203 else
201 mMissedAlarms->setText( mMessage->text()+ "\n" + mMissedAlarms->text() ); 204 mMissedAlarms->setText( mMessage->text()+ "\n" + mMissedAlarms->text() );
202 if ( mMissedAlarms->text().length() > 180 ) 205 if ( mMissedAlarms->text().length() > 180 )
203 mMissedAlarms->setText(mMissedAlarms->text().left ( 180 )); 206 mMissedAlarms->setText(mMissedAlarms->text().left ( 180 ));
204 mMessage->setText(mess); 207 mMessage->setText(mess);
205 int w =sizeHint().width() ; 208 int w =sizeHint().width() ;
206 int h = sizeHint().height() ; 209 int h = sizeHint().height() ;
207 int dw = QApplication::desktop()->width(); 210 int dw = QApplication::desktop()->width();
208 int dh = QApplication::desktop()->height(); 211 int dh = QApplication::desktop()->height();
209 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 212 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
210 show(); 213 show();
211 raise(); 214 raise();
212 qApp->processEvents(); 215 qApp->processEvents();
213 repaint(); 216 repaint();
214 qApp->processEvents(); 217 qApp->processEvents();
215 218
216#ifndef _WIN32_ 219#ifndef _WIN32_
217 if ( fd_led > 0 ) { 220 if ( fd_led > 0 ) {
218 statusLED.status = LED_SALARM_ON ; 221 statusLED.status = LED_SALARM_ON ;
219 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); 222 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
220 } 223 }
221#endif 224#endif
222 playSoundTimer->start( 1000, true ); 225 playSoundTimer->start( 1000, true );
223 return true; 226 return true;
224 227
225} 228}
226 229
227 230
228void AlarmDialog::playSound () 231void AlarmDialog::playSound ()
229{ 232{
230 if (mStopAlarm ) 233 if (mStopAlarm )
231 return; 234 return;
232 showNormal(); 235 showNormal();
233 setActiveWindow(); 236 setActiveWindow();
234 setFocus(); 237 setFocus();
235 raise(); 238 raise();
236 239
237 qApp->processEvents(); 240 qApp->processEvents();
238 if ( alarmCounter < maxAlarmReplay && ! mSilent) { 241 if ( alarmCounter < maxAlarmReplay && ! mSilent) {
239 ++alarmCounter; 242 ++alarmCounter;
240 if ( !mPlayWav || mFileName.length() < 2 ) { 243 if ( !mPlayWav || mFileName.length() < 2 ) {
241 244
242#ifndef DESKTOP_VERSION 245#ifndef DESKTOP_VERSION
243 Sound::soundAlarm (); 246 Sound::soundAlarm ();
244#endif 247#endif
245 } else { 248 } else {
246 QSound::play ( mFileName ); 249 QSound::play ( mFileName );
247 //qDebug("BEEP!"); 250 //qDebug("BEEP!");
248 } 251 }
249 } else { 252 } else {
250 if ( ! mSilent && mSuspendCounter > 0 ) { 253 if ( ! mSilent && mSuspendCounter > 0 ) {
251 --mSuspendCounter; 254 --mSuspendCounter;
252 reject (); 255 reject ();
253 hide(); 256 hide();
254 return; 257 return;
255 } 258 }
256 } 259 }
257 playSoundTimer->start( mPauseCount * 1000, true ); 260 playSoundTimer->start( mPauseCount * 1000, true );
258} 261}