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