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