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