summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-08-30 23:18:58 (UTC)
committer zautrix <zautrix>2004-08-30 23:18:58 (UTC)
commitdef659747d354789f84a992f18df2c3f80f12d01 (patch) (unidiff)
tree9ee66d8e8ef7ab81c9b5e8a32b417746b6cdf8a0
parentcec54f6e21264341191e4f94f9dd7bd19b2eea8d (diff)
downloadkdepimpi-def659747d354789f84a992f18df2c3f80f12d01.zip
kdepimpi-def659747d354789f84a992f18df2c3f80f12d01.tar.gz
kdepimpi-def659747d354789f84a992f18df2c3f80f12d01.tar.bz2
Made timer configurable
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kalarmd/simplealarmdaemonimpl.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/kalarmd/simplealarmdaemonimpl.cpp b/kalarmd/simplealarmdaemonimpl.cpp
index 471836b..18e4299 100644
--- a/kalarmd/simplealarmdaemonimpl.cpp
+++ b/kalarmd/simplealarmdaemonimpl.cpp
@@ -1,554 +1,607 @@
1/* 1/*
2 This file is part of the KOrganizer alarm daemon. 2 This file is part of the KOrganizer alarm daemon.
3 Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2002 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#include "simplealarmdaemonimpl.h" 24#include "simplealarmdaemonimpl.h"
25 25
26#include "alarmdialog.h" 26#include "alarmdialog.h"
27#include <qpopupmenu.h> 27#include <qpopupmenu.h>
28#include <qapp.h> 28#include <qapp.h>
29#include <qdir.h> 29#include <qdir.h>
30#include <qfile.h> 30#include <qfile.h>
31#include <qhbox.h> 31#include <qhbox.h>
32#include <qtimer.h> 32#include <qtimer.h>
33#include <qfile.h> 33#include <qfile.h>
34#include <qlayout.h> 34#include <qlayout.h>
35#include <qlineedit.h> 35#include <qlineedit.h>
36#include <qdialog.h> 36#include <qdialog.h>
37#include <qspinbox.h> 37#include <qspinbox.h>
38#include <qtextstream.h> 38#include <qtextstream.h>
39#include <qtopia/qcopenvelope_qws.h> 39#include <qtopia/qcopenvelope_qws.h>
40#include <qtopia/alarmserver.h> 40#include <qtopia/alarmserver.h>
41 41
42#include <stdlib.h> 42#include <stdlib.h>
43#include <stdio.h> 43#include <stdio.h>
44#include <unistd.h> 44#include <unistd.h>
45 45
46 46
47SimpleAlarmDaemonImpl::SimpleAlarmDaemonImpl( QWidget *parent ) 47SimpleAlarmDaemonImpl::SimpleAlarmDaemonImpl( QWidget *parent )
48 : QLabel( parent ) 48 : QLabel( parent )
49{ 49{
50 mAlarmDialog = new AlarmDialog( 0 ); 50 mAlarmDialog = new AlarmDialog( 0 );
51 mPopUp = new QPopupMenu( 0 ); 51 mPopUp = new QPopupMenu( 0 );
52 mPopUp->insertItem( "What's Next?", this, SLOT ( showWN() ) ); 52 mPopUp->insertItem( "What's Next?", this, SLOT ( showWN() ) );
53 mPopUp->insertItem( "Next Days!", this, SLOT ( showKO() ) ); 53 mPopUp->insertItem( "Next Days!", this, SLOT ( showKO() ) );
54 mPopUp->insertSeparator(); 54 mPopUp->insertSeparator();
55 mPopUp->insertItem( "What's Todo?", this, SLOT ( showTodo() ) ); 55 mPopUp->insertItem( "What's Todo?", this, SLOT ( showTodo() ) );
56 mPopUp->insertSeparator(); 56 mPopUp->insertSeparator();
57 mPopUp->insertItem( "Addresses", this, SLOT ( showAdd() ) ); 57 mPopUp->insertItem( "Addresses", this, SLOT ( showAdd() ) );
58 mPopUp->insertSeparator(); 58 mPopUp->insertSeparator();
59 mPopUp->insertItem( "Edit Journal", this, SLOT ( writeJournal() ) ); 59 mPopUp->insertItem( "Edit Journal", this, SLOT ( writeJournal() ) );
60 mPopUp->insertItem( "New Event", this, SLOT ( newEvent() ) ); 60 mPopUp->insertItem( "New Event", this, SLOT ( newEvent() ) );
61 mPopUp->insertItem( "New Todo", this, SLOT ( newTodo() ) ); 61 mPopUp->insertItem( "New Todo", this, SLOT ( newTodo() ) );
62 mPopUp->insertItem( "New Mail", this, SLOT ( newMail() ) ); 62 mPopUp->insertItem( "New Mail", this, SLOT ( newMail() ) );
63 mPopUp->insertSeparator(); 63 mPopUp->insertSeparator();
64 mPopUp->insertItem( "Multi Sync", this, SLOT ( ringSync() ) ); 64 mPopUp->insertItem( "Multi Sync", this, SLOT ( ringSync() ) );
65 mTimerPopUp = new QPopupMenu( mPopUp ); 65 mTimerPopUp = new QPopupMenu( mPopUp );
66 66
67 mBeepPopUp = new QPopupMenu( mPopUp ); 67 mBeepPopUp = new QPopupMenu( mPopUp );
68 mSoundPopUp = new QPopupMenu( mBeepPopUp ); 68 mSoundPopUp = new QPopupMenu( mBeepPopUp );
69 mPausePopUp = new QPopupMenu( mBeepPopUp ); 69 mPausePopUp = new QPopupMenu( mBeepPopUp );
70 QPopupMenu* savePopUp = new QPopupMenu( mBeepPopUp ); 70 QPopupMenu* savePopUp = new QPopupMenu( mBeepPopUp );
71 savePopUp->insertItem( "Save", 0 ); 71 savePopUp->insertItem( "Save", 0 );
72 savePopUp->insertItem( "Load", 1 ); 72 savePopUp->insertItem( "Load", 1 );
73 mSoundPopUp->insertItem( "Buzzer", 0 ); 73 mSoundPopUp->insertItem( "Buzzer", 0 );
74 mSoundPopUp->insertItem( "Wav file", 1 ); 74 mSoundPopUp->insertItem( "Wav file", 1 );
75 mPausePopUp->insertItem( " 1 sec", 1 ); 75 mPausePopUp->insertItem( " 1 sec", 1 );
76 mPausePopUp->insertItem( " 2 sec", 2 ); 76 mPausePopUp->insertItem( " 2 sec", 2 );
77 mPausePopUp->insertItem( " 3 sec", 3 ); 77 mPausePopUp->insertItem( " 3 sec", 3 );
78 mPausePopUp->insertItem( " 5 sec", 5 ); 78 mPausePopUp->insertItem( " 5 sec", 5 );
79 mPausePopUp->insertItem( "10 sec", 10 ); 79 mPausePopUp->insertItem( "10 sec", 10 );
80 mPausePopUp->insertItem( "30 sec", 30 ); 80 mPausePopUp->insertItem( "30 sec", 30 );
81 mPausePopUp->insertItem( " 1 min", 60 ); 81 mPausePopUp->insertItem( " 1 min", 60 );
82 mPausePopUp->insertItem( " 5 min", 300 ); 82 mPausePopUp->insertItem( " 5 min", 300 );
83 mPausePopUp->insertItem( "10 min", 600 ); 83 mPausePopUp->insertItem( "10 min", 600 );
84 mSuspendPopUp = new QPopupMenu( mBeepPopUp ); 84 mSuspendPopUp = new QPopupMenu( mBeepPopUp );
85 mSuspendPopUp->insertItem( "Off", 0 ); 85 mSuspendPopUp->insertItem( "Off", 0 );
86 mSuspendPopUp->insertItem( " 1x", 1 ); 86 mSuspendPopUp->insertItem( " 1x", 1 );
87 mSuspendPopUp->insertItem( " 2x", 2 ); 87 mSuspendPopUp->insertItem( " 2x", 2 );
88 mSuspendPopUp->insertItem( " 3x", 3 ); 88 mSuspendPopUp->insertItem( " 3x", 3 );
89 mSuspendPopUp->insertItem( " 5x", 5 ); 89 mSuspendPopUp->insertItem( " 5x", 5 );
90 mSuspendPopUp->insertItem( "10x", 10 ); 90 mSuspendPopUp->insertItem( "10x", 10 );
91 mSuspendPopUp->insertItem( "20x", 20 ); 91 mSuspendPopUp->insertItem( "20x", 20 );
92 mSuspendPopUp->insertItem( "30x", 30 ); 92 mSuspendPopUp->insertItem( "30x", 30 );
93 mBeepPopUp->insertItem( "Auto suspend",mSuspendPopUp ); 93 mBeepPopUp->insertItem( "Auto suspend",mSuspendPopUp );
94 mBeepPopUp->insertItem( "Beep interval",mPausePopUp ); 94 mBeepPopUp->insertItem( "Beep interval",mPausePopUp );
95 mBeepPopUp->insertItem( "Replay",mSoundPopUp ); 95 mBeepPopUp->insertItem( "Replay",mSoundPopUp );
96 mBeepPopUp->insertItem( "Config",savePopUp ); 96 mBeepPopUp->insertItem( "Config",savePopUp );
97 mBeepPopUp->insertItem( "300", 300 ); 97 mBeepPopUp->insertItem( "300", 300 );
98 mBeepPopUp->insertItem( "180", 180 ); 98 mBeepPopUp->insertItem( "180", 180 );
99 mBeepPopUp->insertItem( "60", 60 ); 99 mBeepPopUp->insertItem( "60", 60 );
100 mBeepPopUp->insertItem( "30", 30 ); 100 mBeepPopUp->insertItem( "30", 30 );
101 mBeepPopUp->insertItem( "10", 10 ); 101 mBeepPopUp->insertItem( "10", 10 );
102 mBeepPopUp->insertItem( "3", 3 ); 102 mBeepPopUp->insertItem( "3", 3 );
103 mBeepPopUp->insertItem( "1", 1 ); 103 mBeepPopUp->insertItem( "1", 1 );
104 mBeepPopUp->insertItem( "Off", 0 ); 104 mBeepPopUp->insertItem( "Off", 0 );
105 mBeepPopUp->setCheckable( true ); 105 mBeepPopUp->setCheckable( true );
106 mPopUp->insertSeparator(); 106 mPopUp->insertSeparator();
107 mPopUp->insertItem( "Play beeps", mBeepPopUp ); 107 mPopUp->insertItem( "Play beeps", mBeepPopUp );
108 mPopUp->insertSeparator(); 108 mPopUp->insertSeparator();
109 mPopUp->insertItem( "Timer", mTimerPopUp ); 109 mPopUp->insertItem( "Timer", mTimerPopUp );
110 mPopUp->insertSeparator(); 110 mPopUp->insertSeparator();
111 mPopUp->insertItem( "Simulate", this, SLOT ( simulate() ) ); 111 mPopUp->insertItem( "Simulate", this, SLOT ( simulate() ) );
112 112
113 mPopUp->resize( mPopUp->sizeHint() ); 113 mPopUp->resize( mPopUp->sizeHint() );
114 mPlayBeeps = 60; 114 mPlayBeeps = 60;
115 mBeepPopUp->setItemChecked ( mPlayBeeps, true ); 115 mBeepPopUp->setItemChecked ( mPlayBeeps, true );
116 connect ( mBeepPopUp, SIGNAL( activated ( int ) ), this, SLOT (slotPlayBeep( int ) ) ); 116 connect ( mBeepPopUp, SIGNAL( activated ( int ) ), this, SLOT (slotPlayBeep( int ) ) );
117 connect ( mTimerPopUp, SIGNAL( activated ( int ) ), this, SLOT (confTimer( int ) ) ); 117 connect ( mTimerPopUp, SIGNAL( activated ( int ) ), this, SLOT (confTimer( int ) ) );
118 connect ( mTimerPopUp, SIGNAL(aboutToShow() ), this, SLOT ( showTimer( ) ) ); 118 connect ( mTimerPopUp, SIGNAL(aboutToShow() ), this, SLOT ( showTimer( ) ) );
119 connect ( mSoundPopUp, SIGNAL( activated ( int ) ), this, SLOT (confSound( int ) ) ); 119 connect ( mSoundPopUp, SIGNAL( activated ( int ) ), this, SLOT (confSound( int ) ) );
120 connect ( mPausePopUp, SIGNAL( activated ( int ) ), this, SLOT (confPause( int ) ) ); 120 connect ( mPausePopUp, SIGNAL( activated ( int ) ), this, SLOT (confPause( int ) ) );
121 connect ( mSuspendPopUp, SIGNAL( activated ( int ) ), this, SLOT (confSuspend( int ) ) ); 121 connect ( mSuspendPopUp, SIGNAL( activated ( int ) ), this, SLOT (confSuspend( int ) ) );
122 connect ( savePopUp, SIGNAL( activated ( int ) ), this, SLOT (saveSlot( int ) ) ); 122 connect ( savePopUp, SIGNAL( activated ( int ) ), this, SLOT (saveSlot( int ) ) );
123 mTimerTime = 0; 123 mTimerTime = 0;
124 mCustomText = "Custom Text"; 124 mCustomText = "Custom Text";
125 mCustomMinutes = 7; 125 mCustomMinutes = 7;
126 mTimerPopupConf = 1; 126 mTimerPopupConf = 1;
127 fillTimerPopUp(); 127 fillTimerPopUp();
128 mPausePlay = 0; 128 mPausePlay = 0;
129 confPause( 1 ); 129 confPause( 1 );
130 mSuspend = 0; 130 mSuspend = 0;
131 confSuspend( 0 ); 131 confSuspend( 0 );
132 if ( QApplication::desktop()->width() < 480 ) { 132 if ( QApplication::desktop()->width() < 480 ) {
133 wavAlarm = false; 133 wavAlarm = false;
134 mSoundPopUp->setItemChecked ( 0, true ); 134 mSoundPopUp->setItemChecked ( 0, true );
135 } 135 }
136 else { 136 else {
137 wavAlarm = true; 137 wavAlarm = true;
138 mSoundPopUp->setItemChecked ( 1, true ); 138 mSoundPopUp->setItemChecked ( 1, true );
139 } 139 }
140 saveSlot( 1 ); 140 saveSlot( 1 );
141} 141}
142 142
143SimpleAlarmDaemonImpl::~SimpleAlarmDaemonImpl() 143SimpleAlarmDaemonImpl::~SimpleAlarmDaemonImpl()
144{ 144{
145 delete mPopUp; 145 delete mPopUp;
146 delete mAlarmDialog; 146 delete mAlarmDialog;
147} 147}
148void SimpleAlarmDaemonImpl::saveSlot( int load ) 148void SimpleAlarmDaemonImpl::saveSlot( int load )
149{ 149{
150 QString fileName = QDir::homeDirPath() +"/.kopialarmrc"; 150 QString fileName = QDir::homeDirPath() +"/.kopialarmrc";
151 //qDebug("save %d ", load ); 151 //qDebug("save %d ", load );
152 QFile file( fileName ); 152 QFile file( fileName );
153 if ( load ) { 153 if ( load ) {
154 if( !QFile::exists( fileName) ) 154 if( !QFile::exists( fileName) )
155 return; 155 return;
156 if (!file.open( IO_ReadOnly ) ) { 156 if (!file.open( IO_ReadOnly ) ) {
157 return ; 157 return ;
158 } 158 }
159 QString line; 159 QString line;
160 bool ok; 160 bool ok;
161 int val; 161 int val;
162 int len; 162 int len;
163 while ( file.readLine( line, 1024 ) > 0 ) { 163 while ( file.readLine( line, 1024 ) > 0 ) {
164 //qDebug("read %s ", line.latin1()); 164 //qDebug("read %s ", line.latin1());
165 len = line.length(); 165 len = line.length();
166 if ( line.left(4 ) == "PPAU" ) { 166 if ( line.left(4 ) == "PPAU" ) {
167 val = line.mid( 4,len-5).toInt( &ok ); 167 val = line.mid( 4,len-5).toInt( &ok );
168 if ( ok ) { 168 if ( ok ) {
169 confPause( val ); 169 confPause( val );
170 } 170 }
171 } 171 }
172 if ( line.left(4 ) == "SUCO" ) { 172 if ( line.left(4 ) == "SUCO" ) {
173 val = line.mid( 4,len-5).toInt( &ok ); 173 val = line.mid( 4,len-5).toInt( &ok );
174 if ( ok ) 174 if ( ok )
175 confSuspend ( val ); 175 confSuspend ( val );
176 } 176 }
177 if ( line.left(4 ) == "WAAL" ) { 177 if ( line.left(4 ) == "WAAL" ) {
178 val = line.mid( 4,len-5).toInt( &ok ); 178 val = line.mid( 4,len-5).toInt( &ok );
179 if ( ok ) 179 if ( ok )
180 confSound( val ); 180 confSound( val );
181 181
182 } 182 }
183 if ( line.left(4 ) == "PLBE" ) { 183 if ( line.left(4 ) == "PLBE" ) {
184 val = line.mid( 4,len-5).toInt( &ok ); 184 val = line.mid( 4,len-5).toInt( &ok );
185 if ( ok ) 185 if ( ok )
186 slotPlayBeep( val ); 186 slotPlayBeep( val );
187 187
188 } 188 }
189 if ( line.left(4 ) == "CUTE" ) { 189 if ( line.left(4 ) == "CUTE" ) {
190 mCustomText = line.mid( 5,len-6); 190 mCustomText = line.mid( 5,len-6);
191 // qDebug("text ***%s*** ",mCustomText.latin1() ); 191 // qDebug("text ***%s*** ",mCustomText.latin1() );
192 192
193 } 193 }
194 if ( line.left(4 ) == "CUMI" ) { 194 if ( line.left(4 ) == "CUMI" ) {
195 val = line.mid( 4,len-5).toInt( &ok ); 195 val = line.mid( 4,len-5).toInt( &ok );
196 if ( ok ) 196 if ( ok )
197 mCustomMinutes = val; 197 mCustomMinutes = val;
198 198
199 } 199 }
200 if ( line.left(4 ) == "SUTI" ) { 200 if ( line.left(4 ) == "SUTI" ) {
201 val = line.mid( 4,len-5).toInt( &ok ); 201 val = line.mid( 4,len-5).toInt( &ok );
202 if ( ok ) 202 if ( ok )
203 mAlarmDialog->setSuspendTime( val );; 203 mAlarmDialog->setSuspendTime( val );;
204 204
205 } 205 }
206 } 206 }
207 file.close(); 207 file.close();
208 } else { 208 } else {
209 if (!file.open( IO_WriteOnly ) ) { 209 if (!file.open( IO_WriteOnly ) ) {
210 return; 210 return;
211 } 211 }
212 QString configString ; 212 QString configString ;
213 configString += "PPAU " + QString::number( mPausePlay ) + "\n"; 213 configString += "PPAU " + QString::number( mPausePlay ) + "\n";
214 configString += "SUCO " + QString::number( mSuspend ) + "\n"; 214 configString += "SUCO " + QString::number( mSuspend ) + "\n";
215 configString += "WAAL " + QString::number( wavAlarm ) + "\n"; 215 configString += "WAAL " + QString::number( wavAlarm ) + "\n";
216 configString += "PLBE " + QString::number( mPlayBeeps ) + "\n"; 216 configString += "PLBE " + QString::number( mPlayBeeps ) + "\n";
217 configString += "CUTE " + mCustomText + "\n"; 217 configString += "CUTE " + mCustomText + "\n";
218 configString += "CUMI " + QString::number( mCustomMinutes ) + "\n"; 218 configString += "CUMI " + QString::number( mCustomMinutes ) + "\n";
219 configString += "SUTI " + QString::number( mAlarmDialog->getSuspendTime( )) + "\n"; 219 configString += "SUTI " + QString::number( mAlarmDialog->getSuspendTime( )) + "\n";
220 QTextStream ts( &file ); 220 QTextStream ts( &file );
221 ts << configString ; 221 ts << configString ;
222 file.close(); 222 file.close();
223 } 223 }
224 224
225} 225}
226void SimpleAlarmDaemonImpl::confSuspend( int num ) 226void SimpleAlarmDaemonImpl::confSuspend( int num )
227{ 227{
228 mSuspendPopUp->setItemChecked ( mSuspend,false ); 228 mSuspendPopUp->setItemChecked ( mSuspend,false );
229 mSuspend = num; 229 mSuspend = num;
230 mSuspendPopUp->setItemChecked ( mSuspend,true ); 230 mSuspendPopUp->setItemChecked ( mSuspend,true );
231} 231}
232void SimpleAlarmDaemonImpl::confPause( int num ) 232void SimpleAlarmDaemonImpl::confPause( int num )
233{ 233{
234 mPausePopUp->setItemChecked ( mPausePlay,false ); 234 mPausePopUp->setItemChecked ( mPausePlay,false );
235 mPausePlay = num; 235 mPausePlay = num;
236 mPausePopUp->setItemChecked ( mPausePlay,true ); 236 mPausePopUp->setItemChecked ( mPausePlay,true );
237} 237}
238void SimpleAlarmDaemonImpl::confSound( int num ) 238void SimpleAlarmDaemonImpl::confSound( int num )
239{ 239{
240 if ( num == 0 ) { 240 if ( num == 0 ) {
241 wavAlarm = false; 241 wavAlarm = false;
242 mSoundPopUp->setItemChecked ( 0, true ); 242 mSoundPopUp->setItemChecked ( 0, true );
243 mSoundPopUp->setItemChecked ( 1, false ); 243 mSoundPopUp->setItemChecked ( 1, false );
244 } else { 244 } else {
245 wavAlarm = true; 245 wavAlarm = true;
246 mSoundPopUp->setItemChecked ( 0, false ); 246 mSoundPopUp->setItemChecked ( 0, false );
247 mSoundPopUp->setItemChecked ( 1, true ); 247 mSoundPopUp->setItemChecked ( 1, true );
248 } 248 }
249} 249}
250void SimpleAlarmDaemonImpl::slotPlayBeep( int num ) 250void SimpleAlarmDaemonImpl::slotPlayBeep( int num )
251{ 251{
252 mBeepPopUp->setItemChecked ( mPlayBeeps,false ); 252 mBeepPopUp->setItemChecked ( mPlayBeeps,false );
253 mPlayBeeps = num; 253 mPlayBeeps = num;
254 mBeepPopUp->setItemChecked ( mPlayBeeps, true ); 254 mBeepPopUp->setItemChecked ( mPlayBeeps, true );
255} 255}
256 256
257void SimpleAlarmDaemonImpl::recieve( const QCString& msg, const QByteArray& ) 257void SimpleAlarmDaemonImpl::recieve( const QCString& msg, const QByteArray& )
258{ 258{
259 //qDebug("SimpleAlarmDaemonImpl::ALARM RECEIVED! %s", msg.data()); 259 //qDebug("SimpleAlarmDaemonImpl::ALARM RECEIVED! %s", msg.data());
260 QString mess = msg; 260 QString mess = msg;
261 mAlarmMessage = mess.mid( 9 ); 261 mAlarmMessage = mess.mid( 9 );
262 QString filename = getenv("QPEDIR") ; 262 QString filename = getenv("QPEDIR") ;
263 filename += "/pics/kdepim/korganizer/koalarm.wav"; 263 filename += "/pics/kdepim/korganizer/koalarm.wav";
264 QString tempfilename; 264 QString tempfilename;
265 if ( mess.left( 13 ) == "suspend_alarm") { 265 if ( mess.left( 13 ) == "suspend_alarm") {
266 bool error = false; 266 bool error = false;
267 int len = mess.mid( 13 ).find("+++"); 267 int len = mess.mid( 13 ).find("+++");
268 if ( len < 2 ) 268 if ( len < 2 )
269 error = true; 269 error = true;
270 else { 270 else {
271 tempfilename = mess.mid( 13, len ); 271 tempfilename = mess.mid( 13, len );
272 if ( !QFile::exists( tempfilename ) ) 272 if ( !QFile::exists( tempfilename ) )
273 error = true; 273 error = true;
274 } 274 }
275 if ( ! error ) { 275 if ( ! error ) {
276 filename = tempfilename; 276 filename = tempfilename;
277 } 277 }
278 mAlarmMessage = mess.mid( 13+len+3 ); 278 mAlarmMessage = mess.mid( 13+len+3 );
279 //qDebug("suspend file %s ",tempfilename.latin1() ); 279 //qDebug("suspend file %s ",tempfilename.latin1() );
280 startAlarm( mAlarmMessage, filename); 280 startAlarm( mAlarmMessage, filename);
281 return; 281 return;
282 } 282 }
283 if ( mess.left( 11 ) == "timer_alarm") { 283 if ( mess.left( 11 ) == "timer_alarm") {
284 mTimerTime = 0; 284 mTimerTime = 0;
285 startAlarm( mess.mid( 11 ), filename ); 285 startAlarm( mess.mid( 11 ), filename );
286 return; 286 return;
287 } 287 }
288 if ( mess.left( 10 ) == "proc_alarm") { 288 if ( mess.left( 10 ) == "proc_alarm") {
289 bool error = false; 289 bool error = false;
290 int len = mess.mid( 10 ).find("+++"); 290 int len = mess.mid( 10 ).find("+++");
291 if ( len < 2 ) 291 if ( len < 2 )
292 error = true; 292 error = true;
293 else { 293 else {
294 tempfilename = mess.mid( 10, len ); 294 tempfilename = mess.mid( 10, len );
295 if ( !QFile::exists( tempfilename ) ) 295 if ( !QFile::exists( tempfilename ) )
296 error = true; 296 error = true;
297 } 297 }
298 if ( error ) { 298 if ( error ) {
299 mAlarmMessage = "Procedure Alarm\nError - File not found\n"; 299 mAlarmMessage = "Procedure Alarm\nError - File not found\n";
300 mAlarmMessage += mess.mid( 10+len+3+9 ); 300 mAlarmMessage += mess.mid( 10+len+3+9 );
301 } else { 301 } else {
302 QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); 302 QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
303 //qDebug("-----system command %s ",tempfilename.latin1() ); 303 //qDebug("-----system command %s ",tempfilename.latin1() );
304 if ( vfork () == 0 ) { 304 if ( vfork () == 0 ) {
305 execl ( tempfilename.latin1(), 0 ); 305 execl ( tempfilename.latin1(), 0 );
306 return; 306 return;
307 } 307 }
308 return; 308 return;
309 } 309 }
310 310
311 //qDebug("+++++++system command %s ",tempfilename.latin1() ); 311 //qDebug("+++++++system command %s ",tempfilename.latin1() );
312 } 312 }
313 if ( mess.left( 11 ) == "audio_alarm") { 313 if ( mess.left( 11 ) == "audio_alarm") {
314 bool error = false; 314 bool error = false;
315 int len = mess.mid( 11 ).find("+++"); 315 int len = mess.mid( 11 ).find("+++");
316 if ( len < 2 ) 316 if ( len < 2 )
317 error = true; 317 error = true;
318 else { 318 else {
319 tempfilename = mess.mid( 11, len ); 319 tempfilename = mess.mid( 11, len );
320 if ( !QFile::exists( tempfilename ) ) 320 if ( !QFile::exists( tempfilename ) )
321 error = true; 321 error = true;
322 } 322 }
323 if ( ! error ) { 323 if ( ! error ) {
324 filename = tempfilename; 324 filename = tempfilename;
325 } 325 }
326 mAlarmMessage = mess.mid( 11+len+3+9 ); 326 mAlarmMessage = mess.mid( 11+len+3+9 );
327 //qDebug("audio file command %s ",tempfilename.latin1() ); 327 //qDebug("audio file command %s ",tempfilename.latin1() );
328 } 328 }
329 if ( mess.left( 9 ) == "cal_alarm") { 329 if ( mess.left( 9 ) == "cal_alarm") {
330 mAlarmMessage = mess.mid( 9 ) ; 330 mAlarmMessage = mess.mid( 9 ) ;
331 } 331 }
332 332
333 writeFile(); 333 writeFile();
334 startAlarm( mAlarmMessage, filename ); 334 startAlarm( mAlarmMessage, filename );
335 335
336} 336}
337 337
338int SimpleAlarmDaemonImpl::getFileNameLen( QString mess ) 338int SimpleAlarmDaemonImpl::getFileNameLen( QString mess )
339{ 339{
340 return 0; 340 return 0;
341} 341}
342void SimpleAlarmDaemonImpl::startAlarm( QString mess, QString filename ) 342void SimpleAlarmDaemonImpl::startAlarm( QString mess, QString filename )
343{ 343{
344 //mAlarmDialog->show(); 344 //mAlarmDialog->show();
345 //mAlarmDialog->raise(); 345 //mAlarmDialog->raise();
346 mAlarmDialog->eventNotification( mess, mPlayBeeps, filename, wavAlarm,mPausePlay ,mSuspend ); 346 mAlarmDialog->eventNotification( mess, mPlayBeeps, filename, wavAlarm,mPausePlay ,mSuspend );
347} 347}
348 348
349 349
350void SimpleAlarmDaemonImpl::fillTimerPopUp() 350void SimpleAlarmDaemonImpl::fillTimerPopUp()
351{ 351{
352 352
353 // qDebug(" timer %d %d ",mTimerPopupConf, mTimerTime ); 353 // qDebug(" timer %d %d ",mTimerPopupConf, mTimerTime );
354 if ( mTimerPopupConf == mTimerTime ) { 354 if ( mTimerPopupConf == mTimerTime ) {
355 if ( mTimerTime ) { 355 if ( mTimerTime ) {
356 int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer ); 356 int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer );
357 QTime t ( secs/3600, (secs/60)%60, secs%60 ); 357 QTime t ( secs/3600, (secs/60)%60, secs%60 );
358 mTimerPopUp->changeItem ( 1 , t.toString()); 358 mTimerPopUp->changeItem ( 1 , t.toString());
359 } 359 }
360 else { 360 else {
361 QString text = mCustomText.stripWhiteSpace (); 361 QString text = mCustomText.stripWhiteSpace ();
362 int in = text.find( " " ); 362 int in = text.find( " " );
363 text = text.left ( in ); 363 text = text.left ( in );
364 mTimerPopUp->changeItem ( 3, text ); 364 mTimerPopUp->changeItem ( 3, text );
365 } 365 }
366 return; 366 return;
367 } 367 }
368 mTimerPopupConf = mTimerTime; 368 mTimerPopupConf = mTimerTime;
369 mTimerPopUp->clear(); 369 mTimerPopUp->clear();
370 if ( mTimerTime ) { 370 if ( mTimerTime ) {
371 int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer ); 371 int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer );
372 QTime t ( secs/3600, (secs/60)%60, secs%60 ); 372 QTime t ( secs/3600, (secs/60)%60, secs%60 );
373 mTimerPopUp->insertItem( "Stop", 0 ); 373 mTimerPopUp->insertItem( "Stop", 0 );
374 mTimerPopUp->insertItem( t.toString(),1); 374 mTimerPopUp->insertItem( t.toString(),1);
375 } else { 375 } else {
376
377 QString fileName = QDir::homeDirPath() +"/.kopialarmtimerrc";
378 QFile file( fileName );
379 if( !QFile::exists( fileName) ) {
380 // write defaults
381 if (!file.open( IO_WriteOnly ) ) {
382 return;
383 }
384 QString configString ;
385 configString += "#config file for kopi alarm timer\n";
386 configString += "#format: <Text for popup menu>;<timer countdown in minutes>\n";
387 configString += "#NOTE: minimum value for timer are 3 minutes!\n";
388 configString += "24 h; 1440\n";
389 configString += " 8 h; 480\n";
390 configString += " 5 h; 300\n";
391 configString += " 1 h; 60\n";
392 configString += "30 min; 30\n";
393 configString += "15 min; 15\n";
394 configString += "SEPARATOR\n";
395 configString += "Pizza; 22\n";
396 configString += "Nap; 45\n";
397 configString += "Tea; 5\n";
398 QTextStream ts( &file );
399 ts << configString ;
400 file.close();
401 }
402
403 if (!file.open( IO_ReadOnly ) ) {
404 return ;
405 }
406 QString line;
407 bool ok;
408 while ( file.readLine( line, 1024 ) > 0 ) {
409 //qDebug("read %s ", line.latin1());
410 if ( line.left(1 ) != "#" ) {
411 // no comment
412 if ( line.left(9 ) == "SEPARATOR" ) {
413 mTimerPopUp->insertSeparator();
414 } else {
415 QStringList li = QStringList::split(";",line);
416 ok = false;
417 if ( li.count() == 2 ) {
418 int val = li[1].toInt( &ok );
419 if ( ok && val > 2 ) {
420 mTimerPopUp->insertItem( li[0], val);
421 }
422 }
423 }
424 }
425 }
426 file.close();
427#if 0
376 mTimerPopUp->insertItem( "24 h", 1440 ); 428 mTimerPopUp->insertItem( "24 h", 1440 );
377 // mTimerPopUp->insertItem( i18n("12 h"), 720 ); 429 // mTimerPopUp->insertItem( i18n("12 h"), 720 );
378 mTimerPopUp->insertItem( " 8 h", 480 ); 430 mTimerPopUp->insertItem( " 8 h", 480 );
379 mTimerPopUp->insertItem( " 5 h", 300 ); 431 mTimerPopUp->insertItem( " 5 h", 300 );
380 // mTimerPopUp->insertItem( i18n(" 2 h"), 120 ); 432 // mTimerPopUp->insertItem( i18n(" 2 h"), 120 );
381 mTimerPopUp->insertItem( " 1 h", 60 ); 433 mTimerPopUp->insertItem( " 1 h", 60 );
382 mTimerPopUp->insertItem( "30 min", 30 ); 434 mTimerPopUp->insertItem( "30 min", 30 );
383 mTimerPopUp->insertItem( "15 min", 15 ); 435 mTimerPopUp->insertItem( "15 min", 15 );
384 mTimerPopUp->insertItem( "10 min", 10 ); 436 mTimerPopUp->insertItem( "10 min", 10 );
385 //mTimerPopUp->insertItem( " 5 min", 5 ); 437 //mTimerPopUp->insertItem( " 5 min", 5 );
386 mTimerPopUp->insertSeparator(); 438 mTimerPopUp->insertSeparator();
387 mTimerPopUp->insertItem( "Pizza", 22 ); 439 mTimerPopUp->insertItem( "Pizza", 22 );
388 mTimerPopUp->insertItem( "Nap", 45 ); 440 mTimerPopUp->insertItem( "Nap", 45 );
389 mTimerPopUp->insertItem( "Tea", 5 ); 441 mTimerPopUp->insertItem( "Tea", 5 );
442#endif
390 QString text = mCustomText.stripWhiteSpace (); 443 QString text = mCustomText.stripWhiteSpace ();
391 int in = text.find( " " ); 444 int in = text.find( " " );
392 text = text.left ( in ); 445 text = text.left ( in );
393 mTimerPopUp->insertItem( text, 3 ); 446 mTimerPopUp->insertItem( text, 3 );
394 mTimerPopUp->insertSeparator(); 447 mTimerPopUp->insertSeparator();
395 mTimerPopUp->insertItem( "Customize", 2 ); 448 mTimerPopUp->insertItem( "Customize", 2 );
396 } 449 }
397 450
398} 451}
399 452
400void SimpleAlarmDaemonImpl::showTimer() 453void SimpleAlarmDaemonImpl::showTimer()
401{ 454{
402 fillTimerPopUp(); 455 fillTimerPopUp();
403} 456}
404 457
405void SimpleAlarmDaemonImpl::confTimer( int time ) 458void SimpleAlarmDaemonImpl::confTimer( int time )
406{ 459{
407 //qDebug("impleAlarmDaemonImpl::confTimer() %d ", time ); 460 //qDebug("impleAlarmDaemonImpl::confTimer() %d ", time );
408 int minutes = time; 461 int minutes = time;
409 if ( minutes == 0 ) { 462 if ( minutes == 0 ) {
410 if ( ! mTimerTime ) 463 if ( ! mTimerTime )
411 return; 464 return;
412 465
413 QDialog dia ( 0, ("Stop Timer" ), true ); 466 QDialog dia ( 0, ("Stop Timer" ), true );
414 QLabel lab (("Really stop the timer?"), &dia ); 467 QLabel lab (("Really stop the timer?"), &dia );
415 dia.setCaption(("KO/Pi Timer Stop" )); 468 dia.setCaption(("KO/Pi Timer Stop" ));
416 QVBoxLayout lay( &dia ); 469 QVBoxLayout lay( &dia );
417 lay.setMargin(5); 470 lay.setMargin(5);
418 lay.setSpacing(5); 471 lay.setSpacing(5);
419 lay.addWidget( &lab); 472 lay.addWidget( &lab);
420 dia.resize( 200, dia.sizeHint().height() ); 473 dia.resize( 200, dia.sizeHint().height() );
421 474
422 if ( !dia.exec() ) 475 if ( !dia.exec() )
423 return; 476 return;
424 477
425 AlarmServer::deleteAlarm ( mRunningTimer,"koalarm" , timerMesssage.latin1() ); 478 AlarmServer::deleteAlarm ( mRunningTimer,"koalarm" , timerMesssage.latin1() );
426 mTimerTime = 0; 479 mTimerTime = 0;
427 return; 480 return;
428 } 481 }
429 if ( mTimerTime ) 482 if ( mTimerTime )
430 return; 483 return;
431 if ( minutes == 1 ) { 484 if ( minutes == 1 ) {
432 return; 485 return;
433 } 486 }
434 QString mess = "timer_alarm"; 487 QString mess = "timer_alarm";
435 mess += ("Timer Alarm!\n"); 488 mess += ("Timer Alarm!\n");
436 if ( minutes == 22 ) 489 if ( minutes == 22 )
437 mess += ( "Pizza is ready"); 490 mess += ( "Pizza is ready");
438 else if ( minutes == 45 ) 491 else if ( minutes == 45 )
439 mess += ( "Please wake up!"); 492 mess += ( "Please wake up!");
440 else if ( minutes == 5 ) 493 else if ( minutes == 5 )
441 mess += ( "Tea is ready"); 494 mess += ( "Tea is ready");
442 else if ( minutes == 3 ) { 495 else if ( minutes == 3 ) {
443 mess += mCustomText; 496 mess += mCustomText;
444 minutes = mCustomMinutes ; 497 minutes = mCustomMinutes ;
445 } 498 }
446 else { 499 else {
447 if ( minutes == 2 ) { 500 if ( minutes == 2 ) {
448 // ask time 501 // ask time
449 QDialog dia ( 0, ("Customize Timer" ), true ); 502 QDialog dia ( 0, ("Customize Timer" ), true );
450 QLabel lab (("Message Text:"), &dia ); 503 QLabel lab (("Message Text:"), &dia );
451 dia.setCaption(("KO/Pi Timer" )); 504 dia.setCaption(("KO/Pi Timer" ));
452 QVBoxLayout lay( &dia ); 505 QVBoxLayout lay( &dia );
453 lay.setMargin(5); 506 lay.setMargin(5);
454 lay.setSpacing(5); 507 lay.setSpacing(5);
455 lay.addWidget( &lab); 508 lay.addWidget( &lab);
456 QLineEdit lEdit( mCustomText, &dia ); 509 QLineEdit lEdit( mCustomText, &dia );
457 lay.addWidget( &lEdit); 510 lay.addWidget( &lEdit);
458 QLabel lab2 (("Countdown time (1 min - 24 h):"), &dia ); 511 QLabel lab2 (("Countdown time (1 min - 24 h):"), &dia );
459 lay.addWidget( &lab2); 512 lay.addWidget( &lab2);
460 QHBox hbox ( &dia ); 513 QHBox hbox ( &dia );
461 QLabel lab3 (("h:"), &hbox ); 514 QLabel lab3 (("h:"), &hbox );
462 QSpinBox spinh( 0, 24, 1,& hbox ); 515 QSpinBox spinh( 0, 24, 1,& hbox );
463 QLabel lab4 ((" min:"), &hbox ); 516 QLabel lab4 ((" min:"), &hbox );
464 QSpinBox spinm( 0, 59, 1,&hbox ); 517 QSpinBox spinm( 0, 59, 1,&hbox );
465 spinh.setValue( mCustomMinutes/60 ); 518 spinh.setValue( mCustomMinutes/60 );
466 spinm.setValue( mCustomMinutes%60 ); 519 spinm.setValue( mCustomMinutes%60 );
467 lay.addWidget( &hbox); 520 lay.addWidget( &hbox);
468 dia.resize( dia.sizeHint().width(), dia.sizeHint().height() ); 521 dia.resize( dia.sizeHint().width(), dia.sizeHint().height() );
469 if ( !dia.exec() ) 522 if ( !dia.exec() )
470 return; 523 return;
471 mCustomText = lEdit.text(); 524 mCustomText = lEdit.text();
472 mCustomMinutes = spinh.value()*60+spinm.value(); 525 mCustomMinutes = spinh.value()*60+spinm.value();
473 if ( mCustomMinutes == 0 ) 526 if ( mCustomMinutes == 0 )
474 mCustomMinutes = 1; 527 mCustomMinutes = 1;
475 if ( mCustomMinutes > 1440 ) 528 if ( mCustomMinutes > 1440 )
476 mCustomMinutes = 1440; 529 mCustomMinutes = 1440;
477 mess += mCustomText; 530 mess += mCustomText;
478 minutes = mCustomMinutes; 531 minutes = mCustomMinutes;
479 } 532 }
480 else 533 else
481 mess+= QString::number ( minutes ) + ( " minutes are past!"); 534 mess+= QString::number ( minutes ) + ( " minutes are past!");
482 } 535 }
483 //minutes = 1; 536 //minutes = 1;
484 mRunningTimer = QDateTime::currentDateTime().addSecs( minutes * 60 ); 537 mRunningTimer = QDateTime::currentDateTime().addSecs( minutes * 60 );
485 timerMesssage = mess; 538 timerMesssage = mess;
486 AlarmServer::addAlarm ( mRunningTimer,"koalarm",timerMesssage.latin1()); 539 AlarmServer::addAlarm ( mRunningTimer,"koalarm",timerMesssage.latin1());
487 mTimerTime = 1; 540 mTimerTime = 1;
488} 541}
489 542
490void SimpleAlarmDaemonImpl::writeFile() 543void SimpleAlarmDaemonImpl::writeFile()
491{ 544{
492 QCopEnvelope e("QPE/Application/kopi", "-writeFile"); 545 QCopEnvelope e("QPE/Application/kopi", "-writeFile");
493} 546}
494void SimpleAlarmDaemonImpl::showWN() 547void SimpleAlarmDaemonImpl::showWN()
495{ 548{
496 QCopEnvelope e("QPE/Application/kopi", "-showWN"); 549 QCopEnvelope e("QPE/Application/kopi", "-showWN");
497} 550}
498void SimpleAlarmDaemonImpl::newTodo() 551void SimpleAlarmDaemonImpl::newTodo()
499{ 552{
500 QCopEnvelope e("QPE/Application/kopi", "-newTodo"); 553 QCopEnvelope e("QPE/Application/kopi", "-newTodo");
501} 554}
502 555
503void SimpleAlarmDaemonImpl::newEvent() 556void SimpleAlarmDaemonImpl::newEvent()
504{ 557{
505 QCopEnvelope e("QPE/Application/kopi", "-newEvent"); 558 QCopEnvelope e("QPE/Application/kopi", "-newEvent");
506 559
507} 560}
508void SimpleAlarmDaemonImpl::newMail() 561void SimpleAlarmDaemonImpl::newMail()
509{ 562{
510 QCopEnvelope e("QPE/Application/kmpi", "newMail()"); 563 QCopEnvelope e("QPE/Application/kmpi", "newMail()");
511} 564}
512void SimpleAlarmDaemonImpl::showAdd() 565void SimpleAlarmDaemonImpl::showAdd()
513{ 566{
514 QCopEnvelope e("QPE/Application/kapi", " "); 567 QCopEnvelope e("QPE/Application/kapi", " ");
515} 568}
516void SimpleAlarmDaemonImpl::ringSync() 569void SimpleAlarmDaemonImpl::ringSync()
517{ 570{
518 QCopEnvelope e("QPE/Application/kopi", "-ringSync"); 571 QCopEnvelope e("QPE/Application/kopi", "-ringSync");
519 572
520} 573}
521void SimpleAlarmDaemonImpl::newCountdown() 574void SimpleAlarmDaemonImpl::newCountdown()
522{ 575{
523 //recieve("cal_alarm", 10 ); 576 //recieve("cal_alarm", 10 );
524} 577}
525void SimpleAlarmDaemonImpl::simulate() 578void SimpleAlarmDaemonImpl::simulate()
526{ 579{
527 writeFile(); 580 writeFile();
528 QString filename = getenv("QPEDIR") ; 581 QString filename = getenv("QPEDIR") ;
529 filename += "/pics/kdepim/korganizer/koalarm.wav"; 582 filename += "/pics/kdepim/korganizer/koalarm.wav";
530 startAlarm("Alarm simulation", filename ); 583 startAlarm("Alarm simulation", filename );
531} 584}
532void SimpleAlarmDaemonImpl::showKO() 585void SimpleAlarmDaemonImpl::showKO()
533{ 586{
534 QCopEnvelope e("QPE/Application/kopi", "-showKO"); 587 QCopEnvelope e("QPE/Application/kopi", "-showKO");
535 588
536} 589}
537void SimpleAlarmDaemonImpl::showTodo() 590void SimpleAlarmDaemonImpl::showTodo()
538{ 591{
539 QCopEnvelope e("QPE/Application/kopi", "-showTodo"); 592 QCopEnvelope e("QPE/Application/kopi", "-showTodo");
540 593
541} 594}
542void SimpleAlarmDaemonImpl::writeJournal() 595void SimpleAlarmDaemonImpl::writeJournal()
543{ 596{
544 QCopEnvelope e("QPE/Application/kopi", "-showJournal"); 597 QCopEnvelope e("QPE/Application/kopi", "-showJournal");
545 598
546} 599}
547 600
548void SimpleAlarmDaemonImpl::mousePressEvent( QMouseEvent * ) 601void SimpleAlarmDaemonImpl::mousePressEvent( QMouseEvent * )
549{ 602{
550 603
551 mPopUp->popup(mapToGlobal(QPoint (0, -mPopUp->height() ))); 604 mPopUp->popup(mapToGlobal(QPoint (0, -mPopUp->height() )));
552 605
553} 606}
554 607