-rw-r--r-- | kalarmd/alarmdialog.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/kalarmd/alarmdialog.cpp b/kalarmd/alarmdialog.cpp index 7ead3b9..7b888ab 100644 --- a/kalarmd/alarmdialog.cpp +++ b/kalarmd/alarmdialog.cpp | |||
@@ -1,229 +1,233 @@ | |||
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 | #ifndef DESKTOP_VERSION | ||
35 | #define protected public | 36 | #define protected public |
36 | #include <qspinbox.h> | 37 | #include <qspinbox.h> |
37 | #undef protected | 38 | #undef protected |
39 | #else | ||
40 | #include <qspinbox.h> | ||
41 | #endif | ||
38 | #include <stdlib.h> | 42 | #include <stdlib.h> |
39 | #ifndef _WIN32_ | 43 | #ifndef _WIN32_ |
40 | #include <unistd.h> | 44 | #include <unistd.h> |
41 | #include <sys/ioctl.h> | 45 | #include <sys/ioctl.h> |
42 | #endif | 46 | #endif |
43 | #include <stdio.h> | 47 | #include <stdio.h> |
44 | #include <fcntl.h> | 48 | #include <fcntl.h> |
45 | 49 | ||
46 | #ifndef DESKTOP_VERSION | 50 | #ifndef DESKTOP_VERSION |
47 | #include <qtopia/alarmserver.h> | 51 | #include <qtopia/alarmserver.h> |
48 | #include <qpe/resource.h> | 52 | #include <qpe/resource.h> |
49 | #include <qtopia/sound.h> | 53 | #include <qtopia/sound.h> |
50 | 54 | ||
51 | #endif | 55 | #endif |
52 | 56 | ||
53 | #include "alarmdialog.h" | 57 | #include "alarmdialog.h" |
54 | 58 | ||
55 | 59 | ||
56 | AlarmDialog::AlarmDialog(QWidget *parent,const char *name) | 60 | AlarmDialog::AlarmDialog(QWidget *parent,const char *name) |
57 | : QDialog (parent, name, true, Qt::WStyle_StaysOnTop ) | 61 | : QDialog (parent, name, true, Qt::WStyle_StaysOnTop ) |
58 | { | 62 | { |
59 | setCaption( "KO/Pi Alarm!" ); | 63 | setCaption( "KO/Pi Alarm!" ); |
60 | QVBoxLayout* layout = new QVBoxLayout( this); | 64 | QVBoxLayout* layout = new QVBoxLayout( this); |
61 | QLabel* l = new QLabel("The following event triggered alarm:",this); | 65 | QLabel* l = new QLabel("The following event triggered alarm:",this); |
62 | layout->addWidget ( l ); | 66 | layout->addWidget ( l ); |
63 | l->setAlignment( AlignCenter); | 67 | l->setAlignment( AlignCenter); |
64 | mMessage = new QLabel ( " ", this ); | 68 | mMessage = new QLabel ( " ", this ); |
65 | int fs = 18; | 69 | int fs = 18; |
66 | int fs2 = 12; | 70 | int fs2 = 12; |
67 | if ( QApplication::desktop()->width() < 480 ) { | 71 | if ( QApplication::desktop()->width() < 480 ) { |
68 | setMaximumSize(220, 260); | 72 | setMaximumSize(220, 260); |
69 | fs2 = 10; | 73 | fs2 = 10; |
70 | } | 74 | } |
71 | else { | 75 | else { |
72 | setMaximumSize(440, 440); | 76 | setMaximumSize(440, 440); |
73 | } | 77 | } |
74 | layout->setSpacing( 3 ); | 78 | layout->setSpacing( 3 ); |
75 | layout->setMargin( 3 ); | 79 | layout->setMargin( 3 ); |
76 | QFont fo = QApplication::font(); | 80 | QFont fo = QApplication::font(); |
77 | fo.setBold( true ); | 81 | fo.setBold( true ); |
78 | fo.setPointSize( fs2 ); | 82 | fo.setPointSize( fs2 ); |
79 | l->setFont( fo ); | 83 | l->setFont( fo ); |
80 | fo.setPointSize( fs ); | 84 | fo.setPointSize( fs ); |
81 | mMessage->setFont(fo ); | 85 | mMessage->setFont(fo ); |
82 | mMessage->setAlignment( AlignCenter); | 86 | mMessage->setAlignment( AlignCenter); |
83 | layout->addWidget ( mMessage ); | 87 | layout->addWidget ( mMessage ); |
84 | mMissedAlarms= new QLabel ( "(No missed Alarms)", this ); | 88 | mMissedAlarms= new QLabel ( "(No missed Alarms)", this ); |
85 | mMissedAlarms->setAlignment( AlignCenter); | 89 | mMissedAlarms->setAlignment( AlignCenter); |
86 | 90 | ||
87 | playSoundTimer = new QTimer( this ); | 91 | playSoundTimer = new QTimer( this ); |
88 | connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) ); | 92 | connect ( playSoundTimer, SIGNAL( timeout() ), this, SLOT (playSound() ) ); |
89 | 93 | ||
90 | playSoundTimer->stop(); | 94 | playSoundTimer->stop(); |
91 | 95 | ||
92 | layout->addWidget ( mMissedAlarms ); | 96 | layout->addWidget ( mMissedAlarms ); |
93 | mMissedAlarmsCombo = new QComboBox ( this ); | 97 | mMissedAlarmsCombo = new QComboBox ( this ); |
94 | layout->addWidget ( mMissedAlarmsCombo ); | 98 | layout->addWidget ( mMissedAlarmsCombo ); |
95 | 99 | ||
96 | QLabel* labb = new QLabel("Suspend duration (minutes):",this); | 100 | QLabel* labb = new QLabel("Suspend duration (minutes):",this); |
97 | labb->setAlignment(AlignCenter); | 101 | labb->setAlignment(AlignCenter); |
98 | layout->addWidget ( labb ); | 102 | layout->addWidget ( labb ); |
99 | fo = font(); | 103 | fo = font(); |
100 | int pointSize = 36; | 104 | int pointSize = 36; |
101 | if ( QApplication::desktop()->width() <= 320 ) | 105 | if ( QApplication::desktop()->width() <= 320 ) |
102 | pointSize = 24; | 106 | pointSize = 24; |
103 | fo.setPointSize( pointSize ); | 107 | fo.setPointSize( pointSize ); |
104 | mSuspendSpin = new QSpinBox(1,1440,1,this); | 108 | mSuspendSpin = new QSpinBox(1,1440,1,this); |
105 | mSuspendSpin->setFont( fo ); | 109 | mSuspendSpin->setFont( fo ); |
106 | mSuspendSpin->setValue(7); // default suspend duration | 110 | mSuspendSpin->setValue(7); // default suspend duration |
107 | mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); | 111 | mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); |
108 | mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); | 112 | mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); |
109 | #if QT_VERSION < 0x030000 | 113 | #if QT_VERSION < 0x030000 |
110 | mSuspendSpin->upButton ()->setFixedSize( QSize( 48, 30 )); | 114 | mSuspendSpin->upButton ()->setFixedSize( QSize( 48, 30 )); |
111 | mSuspendSpin->downButton ()->setFixedSize( QSize( 48, 30 )); | 115 | mSuspendSpin->downButton ()->setFixedSize( QSize( 48, 30 )); |
112 | #endif | 116 | #endif |
113 | mSuspendSpin->setFixedSize( 100,62 ); | 117 | mSuspendSpin->setFixedSize( 100,62 ); |
114 | mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); | 118 | mSuspendSpin->setButtonSymbols( QSpinBox::PlusMinus ); |
115 | QHBoxLayout* layoutSpin = new QHBoxLayout( layout ); | 119 | QHBoxLayout* layoutSpin = new QHBoxLayout( layout ); |
116 | layoutSpin->addStretch (); | 120 | layoutSpin->addStretch (); |
117 | layoutSpin->addWidget ( mSuspendSpin ); | 121 | layoutSpin->addWidget ( mSuspendSpin ); |
118 | layoutSpin->addStretch (); | 122 | layoutSpin->addStretch (); |
119 | 123 | ||
120 | QVBox * bbox = new QVBox ( this ); | 124 | QVBox * bbox = new QVBox ( this ); |
121 | layout->addWidget ( bbox ); | 125 | layout->addWidget ( bbox ); |
122 | bbox->layout()->setSpacing( 2 ); | 126 | bbox->layout()->setSpacing( 2 ); |
123 | labb = new QLabel("Press \"Cancel\" or \"Esc\" to suspend!",bbox); | 127 | labb = new QLabel("Press \"Cancel\" or \"Esc\" to suspend!",bbox); |
124 | labb->setAlignment(AlignCenter); | 128 | labb->setAlignment(AlignCenter); |
125 | mSuspendButton = new QPushButton( "Suspend", bbox); | 129 | mSuspendButton = new QPushButton( "Suspend", bbox); |
126 | QPushButton* silen = new QPushButton( " Stop sound ", bbox); | 130 | QPushButton* silen = new QPushButton( " Stop sound ", bbox); |
127 | QPushButton* okbut = new QPushButton( "Ok", bbox); | 131 | QPushButton* okbut = new QPushButton( "Ok", bbox); |
128 | mSuspendButton->setFont( fo ); | 132 | mSuspendButton->setFont( fo ); |
129 | silen->setFont( fo ); | 133 | silen->setFont( fo ); |
130 | okbut->setFont( fo ); | 134 | okbut->setFont( fo ); |
131 | okbut->setDefault( true ); | 135 | okbut->setDefault( true ); |
132 | connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) ); | 136 | connect (silen , SIGNAL( clicked() ), this, SLOT (silent() ) ); |
133 | connect (mSuspendButton, SIGNAL( clicked() ), this, SLOT (slotSuspend() ) ); | 137 | connect (mSuspendButton, SIGNAL( clicked() ), this, SLOT (slotSuspend() ) ); |
134 | connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) ); | 138 | connect (okbut , SIGNAL( clicked() ), this, SLOT (slotOk() ) ); |
135 | #ifndef _WIN32_ | 139 | #ifndef _WIN32_ |
136 | if ( QFile::exists ( "/dev/sharp_led" ) ) | 140 | if ( QFile::exists ( "/dev/sharp_led" ) ) |
137 | fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); | 141 | fd_led = open ( "/dev/sharp_led", O_RDWR|O_NONBLOCK ); |
138 | else | 142 | else |
139 | #endif | 143 | #endif |
140 | fd_led = 0; | 144 | fd_led = 0; |
141 | statusLED.which = SHARP_LED_SALARM; | 145 | statusLED.which = SHARP_LED_SALARM; |
142 | mSilent = false; | 146 | mSilent = false; |
143 | mSuspendCounter = 0; | 147 | mSuspendCounter = 0; |
144 | setServerNotification( true ); | 148 | setServerNotification( true ); |
145 | } | 149 | } |
146 | void AlarmDialog::reject () | 150 | void AlarmDialog::reject () |
147 | { | 151 | { |
148 | QTimer::singleShot ( 3000, this, SLOT (suspend()) ); | 152 | QTimer::singleShot ( 3000, this, SLOT (suspend()) ); |
149 | slotSuspend(); | 153 | slotSuspend(); |
150 | } | 154 | } |
151 | AlarmDialog::~AlarmDialog() | 155 | AlarmDialog::~AlarmDialog() |
152 | { | 156 | { |
153 | } | 157 | } |
154 | void AlarmDialog::silent () | 158 | void AlarmDialog::silent () |
155 | { | 159 | { |
156 | mSilent = true; | 160 | mSilent = true; |
157 | } | 161 | } |
158 | void AlarmDialog::accept() | 162 | void AlarmDialog::accept() |
159 | { | 163 | { |
160 | slotOk(); | 164 | slotOk(); |
161 | } | 165 | } |
162 | 166 | ||
163 | void AlarmDialog::suspend() | 167 | void AlarmDialog::suspend() |
164 | { | 168 | { |
165 | #ifdef DESKTOP_VERSION | 169 | #ifdef DESKTOP_VERSION |
166 | 170 | ||
167 | #else | 171 | #else |
168 | Sound::soundAlarm (); | 172 | Sound::soundAlarm (); |
169 | #endif | 173 | #endif |
170 | } | 174 | } |
171 | void AlarmDialog::slotOk() | 175 | void AlarmDialog::slotOk() |
172 | { | 176 | { |
173 | mStopAlarm = true; | 177 | mStopAlarm = true; |
174 | mMissedAlarms->setText("(No missed Alarms)"); | 178 | mMissedAlarms->setText("(No missed Alarms)"); |
175 | mMessage->setText(""); | 179 | mMessage->setText(""); |
176 | mMissedAlarmsCombo->clear(); | 180 | mMissedAlarmsCombo->clear(); |
177 | #ifndef _WIN32_ | 181 | #ifndef _WIN32_ |
178 | if ( fd_led > 0 ) { | 182 | if ( fd_led > 0 ) { |
179 | statusLED.status = LED_SALARM_OFF ; | 183 | statusLED.status = LED_SALARM_OFF ; |
180 | ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); | 184 | ioctl (fd_led, SHARP_LED_SETSTATUS, &statusLED); |
181 | } | 185 | } |
182 | #endif | 186 | #endif |
183 | QDialog::accept(); | 187 | QDialog::accept(); |
184 | } | 188 | } |
185 | 189 | ||
186 | void AlarmDialog::slotSuspend() | 190 | void AlarmDialog::slotSuspend() |
187 | { | 191 | { |
188 | //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value()); | 192 | //qDebug("AlarmDialog::suspend() "); // emit suspendSignal(mSuspendSpin->value()); |
189 | mStopAlarm = true; | 193 | mStopAlarm = true; |
190 | QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 ); | 194 | QDateTime nextA = QDateTime::currentDateTime().addSecs( mSuspendSpin->value() * 60 ); |
191 | QString mess = "suspend_alarm" +mFileName+"+++" ; | 195 | QString mess = "suspend_alarm" +mFileName+"+++" ; |
192 | if ( mMessage->text().left( 10 ) !="Suspended:" ) | 196 | if ( mMessage->text().left( 10 ) !="Suspended:" ) |
193 | mess += "Suspended:\n"; | 197 | mess += "Suspended:\n"; |
194 | mess +=mMessage->text(); | 198 | mess +=mMessage->text(); |
195 | #ifndef DESKTOP_VERSION | 199 | #ifndef DESKTOP_VERSION |
196 | if ( mServerNotification ) | 200 | if ( mServerNotification ) |
197 | AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1()); | 201 | AlarmServer::addAlarm ( nextA,"koalarm",mess.latin1()); |
198 | #endif | 202 | #endif |
199 | emit addAlarm( nextA , mess ); | 203 | emit addAlarm( nextA , mess ); |
200 | slotOk(); | 204 | slotOk(); |
201 | } | 205 | } |
202 | 206 | ||
203 | void AlarmDialog::setServerNotification( bool b ) | 207 | void AlarmDialog::setServerNotification( bool b ) |
204 | { | 208 | { |
205 | mServerNotification = b; | 209 | mServerNotification = b; |
206 | } | 210 | } |
207 | int AlarmDialog::getSuspendTime( ) | 211 | int AlarmDialog::getSuspendTime( ) |
208 | { | 212 | { |
209 | return mSuspendSpin->value(); | 213 | return mSuspendSpin->value(); |
210 | 214 | ||
211 | } | 215 | } |
212 | void AlarmDialog::setSuspendTime( int val ) | 216 | void AlarmDialog::setSuspendTime( int val ) |
213 | { | 217 | { |
214 | mSuspendSpin->setValue( val ); | 218 | mSuspendSpin->setValue( val ); |
215 | } | 219 | } |
216 | bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes) | 220 | bool AlarmDialog::eventNotification( QString mess, int replay , QString fn, bool playwav, int pause , int suspendtimes) |
217 | { | 221 | { |
218 | if ( mess.left( 9) != "Suspended" ) | 222 | if ( mess.left( 9) != "Suspended" ) |
219 | mSuspendCounter = suspendtimes; | 223 | mSuspendCounter = suspendtimes; |
220 | mPauseCount = pause; | 224 | mPauseCount = pause; |
221 | mFileName = fn; | 225 | mFileName = fn; |
222 | mPlayWav = playwav; | 226 | mPlayWav = playwav; |
223 | if ( !QFile::exists( fn ) ) | 227 | if ( !QFile::exists( fn ) ) |
224 | mFileName = ""; | 228 | mFileName = ""; |
225 | alarmCounter = 0 ; | 229 | alarmCounter = 0 ; |
226 | maxAlarmReplay = replay ; | 230 | maxAlarmReplay = replay ; |
227 | mStopAlarm = false; | 231 | mStopAlarm = false; |
228 | mSilent = false; | 232 | mSilent = false; |
229 | if ( !mMessage->text().stripWhiteSpace().isEmpty() ) { | 233 | if ( !mMessage->text().stripWhiteSpace().isEmpty() ) { |