summaryrefslogtreecommitdiffabout
path: root/kalarmd/alarmdialog.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kalarmd/alarmdialog.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kalarmd/alarmdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kalarmd/alarmdialog.cpp259
1 files changed, 259 insertions, 0 deletions
diff --git a/kalarmd/alarmdialog.cpp b/kalarmd/alarmdialog.cpp
new file mode 100644
index 0000000..b82724f
--- a/dev/null
+++ b/kalarmd/alarmdialog.cpp
@@ -0,0 +1,259 @@
1/*
2 This file is part of the KDE alarm daemon.
3 Copyright (c) 2000 Cornelius Schumacher <schumacher@kde.org>
4
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
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
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
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution.
22*/
23
24// $Id$
25
26#include <qhbox.h>
27#include <qvbox.h>
28#include <qapp.h>
29#include <qlabel.h>
30#include <qlayout.h>
31#include <qfile.h>
32#include <qtimer.h>
33#include <qsound.h>
34#include <qpushbutton.h>
35#include <qspinbox.h>
36#include <stdlib.h>
37#ifndef _WIN32_
38#include <unistd.h>
39#include <sys/ioctl.h>
40#endif
41#include <stdio.h>
42#include <fcntl.h>
43
44#ifndef DESKTOP_VERSION
45#include <qtopia/alarmserver.h>
46#include <qpe/resource.h>
47#include <qtopia/sound.h>
48#endif
49
50#include "alarmdialog.h"
51#include "alarmdialog.moc"
52
53
54AlarmDialog::AlarmDialog(QWidget *parent,const char *name)
55 : QDialog (parent, name, true, Qt::WStyle_StaysOnTop )
56{
57 setCaption( "KO/Pi Alarm!" );
58 QVBoxLayout* layout = new QVBoxLayout( this);
59 QLabel* l = new QLabel("The following event triggered alarm:",this);
60 layout->addWidget ( l );
61 l->setAlignment( AlignCenter);
62 mMessage = new QLabel ( " ", this );
63 int fs = 18;
64 int fs2 = 12;
65 if ( QApplication::desktop()->width() < 480 ) {
66 setMaximumSize(220, 260);
67 fs2 = 10;
68 }
69 else {
70 setMaximumSize(440, 440);
71 }
72 layout->setSpacing( 3 );
73 layout->setMargin( 3 );
74
75 l->setFont( QFont("helvetica",fs2, QFont::Bold) );
76 mMessage->setFont( QFont("helvetica",fs, QFont::Bold) );
77 mMessage->setAlignment( AlignCenter);
78 l = new QLabel("Missed Alarms:",this);
79 l->setAlignment( AlignCenter);
80 layout->addWidget ( mMessage );
81 layout->addWidget ( l );
82 mMissedAlarms= new QLabel ( "", this );
83 mMissedAlarms->setAlignment( AlignCenter);
84
85 playSoundTimer = new QTimer( this );
86 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) );
87
88 playSoundTimer->stop();
89
90 layout->addWidget ( mMissedAlarms );
91 QHBox *suspendBox = new QHBox( this );
92 suspendBox->setSpacing(3);
93 layout->addWidget ( suspendBox );
94 (void)new QLabel("Suspend duration (minutes):",suspendBox);
95 mSuspendSpin = new QSpinBox(1,1440,1,suspendBox);
96 mSuspendSpin->setValue(7); // default suspend duration
97 QHBox * bbox = new QHBox ( this );
98 layout->addWidget ( bbox );
99 bbox->layout()->setSpacing( 5 );
100 QPushButton* suspend = new QPushButton( "Suspend", bbox);
101 QPushButton* silen = new QPushButton( " Stop sound ", bbox);
102 QPushButton* okbut = new QPushButton( "Ok", bbox);
103 connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) );
104 connect (suspend , SIGNAL( clicked() ), this, SLOT (slotSuspend() ) );
105 connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) );
106#ifndef _WIN32_
107 if ( QFile::exists ( "/dev/sharp_led" ) )
108 fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
109 else
110#endif
111 fd_led = 0;
112 statusLED.which = SHARP_LED_SALARM;
113 mSilent = false;
114 mSuspendCounter = 0;
115 setServerNotification( true );
116}
117void AlarmDialog::reject ()
118{
119 QTimer::singleShot ( 3000, this, SLOT (suspend()) );
120 slotSuspend();
121}
122AlarmDialog::~AlarmDialog()
123{
124}
125void AlarmDialog::silent ()
126{
127 mSilent = true;
128}
129void AlarmDialog::accept()
130{
131 slotOk();
132}
133
134void AlarmDialog::suspend()
135{
136#ifdef DESKTOP_VERSION
137
138#else
139 Sound::soundAlarm ();
140#endif
141}
142void AlarmDialog::slotOk()
143{
144 mStopAlarm = true;
145 mMissedAlarms->setText("");
146 mMessage->setText("");
147#ifndef _WIN32_
148 if ( fd_led > 0 ) {
149 statusLED.status = LED_SALARM_OFF ;
150 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
151 }
152#endif
153 QDialog::accept();
154}
155
156void AlarmDialog::slotSuspend()
157{
158 //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value());
159 mStopAlarm = true;
160 QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 );
161 QString mess = "suspend_alarm" +mFileName+"+++" ;
162 if ( mMessage->text().left( 10 ) !="Suspended:" )
163 mess += "Suspended:\n";
164 mess +=mMessage->text();
165#ifndef DESKTOP_VERSION
166 if ( mServerNotification )
167 AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1());
168#endif
169 emit addAlarm( nextA , mess );
170 slotOk();
171}
172
173void AlarmDialog::setServerNotification( bool b )
174{
175 mServerNotification = b;
176}
177int AlarmDialog::getSuspendTime( )
178{
179 return mSuspendSpin->value();
180
181}
182void AlarmDialog::setSuspendTime( int val )
183{
184 mSuspendSpin->setValue( val );
185}
186bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes)
187{
188 if ( mess.left( 9) != "Suspended" )
189 mSuspendCounter = suspendtimes;
190 mPauseCount = pause;
191 mFileName = fn;
192 mPlayWav = playwav;
193 if ( !QFile::exists( fn ) )
194 mFileName = "";
195 alarmCounter = 0 ;
196 maxAlarmReplay = replay ;
197 mStopAlarm = false;
198 mSilent = false;
199 if ( mMissedAlarms->text() == "" )
200 mMissedAlarms->setText( mMessage->text());
201 else
202 mMissedAlarms->setText( mMessage->text()+ "\n" + mMissedAlarms->text() );
203 if ( mMissedAlarms->text().length() > 180 )
204 mMissedAlarms->setText(mMissedAlarms->text().left ( 180 ));
205 mMessage->setText(mess);
206 int w =sizeHint().width() ;
207 int h = sizeHint().height() ;
208 int dw = QApplication::desktop()->width();
209 int dh = QApplication::desktop()->height();
210 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
211 show();
212 raise();
213 qApp->processEvents();
214 repaint();
215 qApp->processEvents();
216
217#ifndef _WIN32_
218 if ( fd_led > 0 ) {
219 statusLED.status = LED_SALARM_ON ;
220 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
221 }
222#endif
223 playSoundTimer->start( 1000, true );
224 return true;
225
226}
227
228
229void AlarmDialog::playSound ()
230{
231 if (mStopAlarm )
232 return;
233 showNormal();
234 setActiveWindow();
235 setFocus();
236 raise();
237
238 qApp->processEvents();
239 if ( alarmCounter < maxAlarmReplay && ! mSilent) {
240 ++alarmCounter;
241 if ( !mPlayWav || mFileName.length() < 2 ) {
242
243#ifndef DESKTOP_VERSION
244 Sound::soundAlarm ();
245#endif
246 } else {
247 QSound::play ( mFileName );
248 //qDebug("BEEP!");
249 }
250 } else {
251 if ( ! mSilent && mSuspendCounter > 0 ) {
252 --mSuspendCounter;
253 reject ();
254 hide();
255 return;
256 }
257 }
258 playSoundTimer->start( mPauseCount * 1000, true );
259}