summaryrefslogtreecommitdiffabout
path: root/kalarmd
authorzautrix <zautrix>2005-03-27 09:46:04 (UTC)
committer zautrix <zautrix>2005-03-27 09:46:04 (UTC)
commitb170a7414ff72016285ea207caa7ccf786530e77 (patch) (unidiff)
treecb635d155fed20ecb33f877659a00d88bedb309e /kalarmd
parentee6f7d5329658c567882e8e496c65eef8874496e (diff)
downloadkdepimpi-b170a7414ff72016285ea207caa7ccf786530e77.zip
kdepimpi-b170a7414ff72016285ea207caa7ccf786530e77.tar.gz
kdepimpi-b170a7414ff72016285ea207caa7ccf786530e77.tar.bz2
many fixes
Diffstat (limited to 'kalarmd') (more/less context) (show whitespace changes)
-rw-r--r--kalarmd/alarmdialog.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/kalarmd/alarmdialog.cpp b/kalarmd/alarmdialog.cpp
index c939ae0..7ead3b9 100644
--- a/kalarmd/alarmdialog.cpp
+++ b/kalarmd/alarmdialog.cpp
@@ -26,114 +26,123 @@
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()) );
@@ -238,43 +247,66 @@ bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, boo
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_
268 QSound::play ( mFileName ); 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
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}