summaryrefslogtreecommitdiffabout
path: root/kalarmd/alarmdialog.cpp
Unidiff
Diffstat (limited to 'kalarmd/alarmdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kalarmd/alarmdialog.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/kalarmd/alarmdialog.cpp b/kalarmd/alarmdialog.cpp
index 65073f6..d72a8c2 100644
--- a/kalarmd/alarmdialog.cpp
+++ b/kalarmd/alarmdialog.cpp
@@ -68,97 +68,98 @@ AlarmDialog::AlarmDialog(QWidget *parent,const char *name)
68 l->setAlignment( AlignCenter); 68 l->setAlignment( AlignCenter);
69 mMessage = new QLabel ( " ", this ); 69 mMessage = new QLabel ( " ", this );
70 int fs = 18; 70 int fs = 18;
71 int fs2 = 12; 71 int fs2 = 12;
72 int baseSize = 6; 72 int baseSize = 6;
73 if ( QApplication::desktop()->width() < 480 ) { 73 if ( QApplication::desktop()->width() < 480 ) {
74 fs2 = 10; 74 fs2 = 10;
75 fs = 12; 75 fs = 12;
76 baseSize = 4; 76 baseSize = 4;
77 } 77 }
78 layout->setSpacing( 3 ); 78 layout->setSpacing( 3 );
79 layout->setMargin( 3 ); 79 layout->setMargin( 3 );
80 QFont fo = QApplication::font(); 80 QFont fo = QApplication::font();
81 fo.setBold( true ); 81 fo.setBold( true );
82 fo.setPointSize( fs2 ); 82 fo.setPointSize( fs2 );
83 l->setFont( fo ); 83 l->setFont( fo );
84 fo.setPointSize( fs ); 84 fo.setPointSize( fs );
85 mMessage->setFont(fo ); 85 mMessage->setFont(fo );
86 mMessage->setAlignment( AlignCenter); 86 mMessage->setAlignment( AlignCenter);
87 layout->addWidget ( mMessage ); 87 layout->addWidget ( mMessage );
88 mMissedAlarms= new QLabel ( "(No missed Alarms)", this ); 88 mMissedAlarms= new QLabel ( "(No missed Alarms)", this );
89 mMissedAlarms->setAlignment( AlignCenter); 89 mMissedAlarms->setAlignment( AlignCenter);
90 90
91 playSoundTimer = new QTimer( this ); 91 playSoundTimer = new QTimer( this );
92 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) ); 92 connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) );
93 93
94 playSoundTimer->stop(); 94 playSoundTimer->stop();
95 95
96 layout->addWidget ( mMissedAlarms ); 96 layout->addWidget ( mMissedAlarms );
97 mMissedAlarmsCombo = new QComboBox ( this ); 97 mMissedAlarmsCombo = new QComboBox ( this );
98 layout->addWidget ( mMissedAlarmsCombo ); 98 layout->addWidget ( mMissedAlarmsCombo );
99 99
100 QLabel* labb = new QLabel("Suspend duration (minutes):",this); 100 QLabel* labb = new QLabel("Suspend\nduration\n(minutes):",this);
101 labb->setAlignment(AlignCenter); 101 labb->setAlignment(AlignCenter);
102 layout->addWidget ( labb ); 102 //layout->addWidget ( labb );
103 fo = font(); 103 fo = font();
104 int pointSize = 36; 104 int pointSize = 36;
105 if ( QApplication::desktop()->width() <= 320 ) 105 if ( QApplication::desktop()->width() <= 320 )
106 pointSize = 18; 106 pointSize = 18;
107 fo.setPointSize( pointSize ); 107 fo.setPointSize( pointSize );
108 mSuspendSpin = new QSpinBox(1,1440,1,this); 108 mSuspendSpin = new QSpinBox(1,1440,1,this);
109 mSuspendSpin->setFont( fo ); 109 mSuspendSpin->setFont( fo );
110 mSuspendSpin->setValue(7); // default suspend duration 110 mSuspendSpin->setValue(7); // default suspend duration
111 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 111 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
112 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 112 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
113 113
114#if QT_VERSION < 0x030000 114#if QT_VERSION < 0x030000
115 mSuspendSpin->upButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize )); 115 mSuspendSpin->upButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize ));
116 mSuspendSpin->downButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize )); 116 mSuspendSpin->downButton ()->setFixedSize( QSize( 8*baseSize, 5*baseSize ));
117#endif 117#endif
118 mSuspendSpin->setFixedSize( 18*baseSize, 10*baseSize+2 ); 118 mSuspendSpin->setFixedSize( 18*baseSize, 10*baseSize+2 );
119 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); 119 mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus );
120 QHBoxLayout* layoutSpin = new QHBoxLayout( layout ); 120 QHBoxLayout* layoutSpin = new QHBoxLayout( layout );
121 layoutSpin->addStretch (); 121 layoutSpin->addStretch ();
122 layoutSpin->addWidget ( labb );
122 layoutSpin->addWidget ( mSuspendSpin ); 123 layoutSpin->addWidget ( mSuspendSpin );
123 layoutSpin->addStretch (); 124 layoutSpin->addStretch ();
124 125
125 QVBox * bbox = new QVBox ( this ); 126 QVBox * bbox = new QVBox ( this );
126 layout->addWidget ( bbox ); 127 layout->addWidget ( bbox );
127 bbox->layout()->setSpacing( 2 ); 128 bbox->layout()->setSpacing( 2 );
128 labb = new QLabel("Press \"Cancel\" or \"Esc\" to suspend!",bbox); 129 labb = new QLabel("Press \"Cancel\" or \"Esc\" to suspend!",bbox);
129 labb->setAlignment(AlignCenter); 130 labb->setAlignment(AlignCenter);
130 mSuspendButton = new QPushButton( "Suspend", bbox); 131 mSuspendButton = new QPushButton( "Suspend", bbox);
131 QPushButton* silen = new QPushButton( " Stop sound ", bbox); 132 QPushButton* silen = new QPushButton( " Stop sound ", bbox);
132 QPushButton* okbut = new QPushButton( "Ok", bbox); 133 okbut = new QPushButton( "Ok", bbox);
133 mSuspendButton->setFont( fo ); 134 mSuspendButton->setFont( fo );
134 silen->setFont( fo ); 135 silen->setFont( fo );
135 okbut->setFont( fo ); 136 okbut->setFont( fo );
136 okbut->setDefault( true ); 137 okbut->setDefault( true );
137 connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) ); 138 connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) );
138 connect (mSuspendButton, SIGNAL( clicked() ), this, SLOT (slotSuspend() ) ); 139 connect (mSuspendButton, SIGNAL( clicked() ), this, SLOT (slotSuspend() ) );
139 connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) ); 140 connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) );
140 connect (mSuspendSpin , SIGNAL( valueChanged ( int ) ), this, SLOT ( spinBoxChanged( int ) ) ); 141 connect (mSuspendSpin , SIGNAL( valueChanged ( int ) ), this, SLOT ( spinBoxChanged( int ) ) );
141#ifndef _WIN32_ 142#ifndef _WIN32_
142 if ( QFile::exists ( "/dev/sharp_led" ) ) 143 if ( QFile::exists ( "/dev/sharp_led" ) )
143 fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); 144 fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK );
144 else 145 else
145#endif 146#endif
146 fd_led = 0; 147 fd_led = 0;
147 statusLED.which = SHARP_LED_SALARM; 148 statusLED.which = SHARP_LED_SALARM;
148 mSilent = false; 149 mSilent = false;
149 mSuspendCounter = 0; 150 mSuspendCounter = 0;
150 setServerNotification( true ); 151 setServerNotification( true );
151} 152}
152void AlarmDialog::reject () 153void AlarmDialog::reject ()
153{ 154{
154 QTimer::singleShot ( 3000, this, SLOT (suspend()) ); 155 QTimer::singleShot ( 3000, this, SLOT (suspend()) );
155 slotSuspend(); 156 slotSuspend();
156} 157}
157AlarmDialog::~AlarmDialog() 158AlarmDialog::~AlarmDialog()
158{ 159{
159} 160}
160void AlarmDialog::silent () 161void AlarmDialog::silent ()
161{ 162{
162 mSilent = true; 163 mSilent = true;
163} 164}
164void AlarmDialog::accept() 165void AlarmDialog::accept()
@@ -212,105 +213,110 @@ void AlarmDialog::setServerNotification( bool b )
212} 213}
213int AlarmDialog::getSuspendTime( ) 214int AlarmDialog::getSuspendTime( )
214{ 215{
215 return mSuspendSpin->value(); 216 return mSuspendSpin->value();
216 217
217} 218}
218void AlarmDialog::setSuspendTime( int val ) 219void AlarmDialog::setSuspendTime( int val )
219{ 220{
220 mSuspendSpin->setValue( val ); 221 mSuspendSpin->setValue( val );
221} 222}
222bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes) 223bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes)
223{ 224{
224 if ( mess.left( 9) != "Suspended" ) 225 if ( mess.left( 9) != "Suspended" )
225 mSuspendCounter = suspendtimes; 226 mSuspendCounter = suspendtimes;
226 mPauseCount = pause; 227 mPauseCount = pause;
227 mFileName = fn; 228 mFileName = fn;
228 mPlayWav = playwav; 229 mPlayWav = playwav;
229 if ( !QFile::exists( fn ) ) 230 if ( !QFile::exists( fn ) )
230 mFileName = ""; 231 mFileName = "";
231 alarmCounter = 0 ; 232 alarmCounter = 0 ;
232 maxAlarmReplay = replay ; 233 maxAlarmReplay = replay ;
233 mStopAlarm = false; 234 mStopAlarm = false;
234 mSilent = false; 235 mSilent = false;
235 if ( !mMessage->text().stripWhiteSpace().isEmpty() ) { 236 if ( !mMessage->text().stripWhiteSpace().isEmpty() ) {
236 mMissedAlarmsCombo->show(); 237 mMissedAlarmsCombo->show();
237 QString newItem = mMessage->text().stripWhiteSpace(); 238 QString newItem = mMessage->text().stripWhiteSpace();
238 newItem.replace( QRegExp("\n"), QString(" ") ); 239 newItem.replace( QRegExp("\n"), QString(" ") );
239 mMissedAlarmsCombo->insertItem( newItem ); 240 mMissedAlarmsCombo->insertItem( newItem );
240 mMissedAlarms->setText( "Missed alarms:"); 241 mMissedAlarms->setText( "Missed alarms:");
241 } else 242 } else
242 mMissedAlarmsCombo->hide(); 243 mMissedAlarmsCombo->hide();
243 mMessage->setText(mess); 244 mMessage->setText(mess);
244 int w =sizeHint().width() ; 245 int w = minimumSizeHint().width() ;
245 int h = sizeHint().height() ; 246 int h = minimumSizeHint().height() ;
246 int dw = QApplication::desktop()->width(); 247 int dw = QApplication::desktop()->width();
247 int dh = QApplication::desktop()->height(); 248 int dh = QApplication::desktop()->height();
248 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 249 setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
249 show(); 250 hide();
250 raise();
251 //qApp->processEvents();
252 //repaint();
253 qApp->processEvents();
254 251
255#ifndef _WIN32_ 252#ifndef _WIN32_
256 if ( fd_led > 0 ) { 253 if ( fd_led > 0 ) {
257 statusLED.status = LED_SALARM_ON ; 254 statusLED.status = LED_SALARM_ON ;
258 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); 255 ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED);
259 } 256 }
260#endif 257#endif
261 playSoundTimer->start( 1000, true ); 258 okbut->setDefault( true );
259 QTimer::singleShot( 1, this, SLOT ( forceRepaint() ) );
260 // playSoundTimer->start( 1000, true );
262 return true; 261 return true;
263 262
264} 263}
265 264
266void AlarmDialog::spinBoxChanged( int ) 265void AlarmDialog::forceRepaint()
267{ 266{
267
268 showNormal();
269 setActiveWindow();
270 raise();
271 playSoundTimer->start( 1000, true );
272
273}
274void AlarmDialog::spinBoxChanged( int v )
275{
276 okbut->setDefault( false );
268 mSilent = true; 277 mSilent = true;
269} 278}
270 279
271void AlarmDialog::playSound () 280void AlarmDialog::playSound ()
272{ 281{
273 282
274 if (mStopAlarm ) 283 if (mStopAlarm )
275 return; 284 return;
276 if ( mSilent ) 285 if ( mSilent )
277 return; 286 return;
278 showNormal(); 287 showNormal();
279 setActiveWindow(); 288 setActiveWindow();
280 raise(); 289 raise();
281 mSuspendSpin->setFocus(); 290 mSuspendSpin->setFocus();
282
283
284 qApp->processEvents();
285 if ( alarmCounter < maxAlarmReplay && ! mSilent) { 291 if ( alarmCounter < maxAlarmReplay && ! mSilent) {
286 ++alarmCounter; 292 ++alarmCounter;
287#ifdef DESKTOP_VERSION 293#ifdef DESKTOP_VERSION
288 mPlayWav = true; 294 mPlayWav = true;
289#endif 295#endif
290 if ( !mPlayWav || mFileName.length() < 2 ) { 296 if ( !mPlayWav || mFileName.length() < 2 ) {
291 297
292#ifdef DESKTOP_VERSION 298#ifdef DESKTOP_VERSION
293 qDebug("Sound play not possible - file not found"); 299 qDebug("Sound play not possible - file not found");
294#else 300#else
295 Sound::soundAlarm (); 301 Sound::soundAlarm ();
296#endif 302#endif
297 } else 303 } else
298 304
299 { 305 {
300#ifdef DESKTOP_VERSION 306#ifdef DESKTOP_VERSION
301#ifdef _WIN32_ 307#ifdef _WIN32_
302 QSound::play ( mFileName ); 308 QSound::play ( mFileName );
303#else 309#else
304 310
305 QString command = "playwave -r 22050 " + mFileName; 311 QString command = "playwave -r 22050 " + mFileName;
306 qDebug("KO: Playing file %s with 22kHz",mFileName.latin1() ); 312 qDebug("KO: Playing file %s with 22kHz",mFileName.latin1() );
307 int ret = system ( command.latin1() ); 313 int ret = system ( command.latin1() );
308 if ( ret != 0 ) { 314 if ( ret != 0 ) {
309 qDebug("Sound play command failed: %s ",command.latin1() ); 315 qDebug("Sound play command failed: %s ",command.latin1() );
310 } 316 }
311 317
312#endif 318#endif
313 319
314#else 320#else
315 QSound::play ( mFileName ); 321 QSound::play ( mFileName );
316#endif 322#endif