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