summaryrefslogtreecommitdiffabout
path: root/libkcal/alarm.cpp
Unidiff
Diffstat (limited to 'libkcal/alarm.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/alarm.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp
index 07812c2..29e6205 100644
--- a/libkcal/alarm.cpp
+++ b/libkcal/alarm.cpp
@@ -1,407 +1,423 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 5
6 This library is free software; you can redistribute it and/or 6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public 7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either 8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version. 9 version 2 of the License, or (at your option) any later version.
10 10
11 This library is distributed in the hope that it will be useful, 11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details. 14 Library General Public License for more details.
15 15
16 You should have received a copy of the GNU Library General Public License 16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to 17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. 19 Boston, MA 02111-1307, USA.
20*/ 20*/
21 21
22#include <kdebug.h> 22#include <kdebug.h>
23 23
24#include "incidence.h" 24#include "incidence.h"
25#include "todo.h" 25#include "todo.h"
26 26
27#include "alarm.h" 27#include "alarm.h"
28 28
29using namespace KCal; 29using namespace KCal;
30#include <qwidget.h> 30#include <qwidget.h>
31Alarm::Alarm(Incidence *parent) 31Alarm::Alarm(Incidence *parent)
32 : mParent(parent), 32 : mParent(parent),
33 mType(Audio), 33 mType(Audio),
34 mDescription(""), // to make operator==() not fail 34 mDescription(""), // to make operator==() not fail
35 mFile(""), // to make operator==() not fail 35 mFile(""), // to make operator==() not fail
36 mMailSubject(""), // to make operator==() not fail 36 mMailSubject(""), // to make operator==() not fail
37 mAlarmSnoozeTime(5), 37 mAlarmSnoozeTime(5),
38 mAlarmRepeatCount(0), 38 mAlarmRepeatCount(0),
39 mEndOffset(false), 39 mEndOffset(false),
40 mHasTime(false), 40 mHasTime(false),
41 mAlarmEnabled(false) 41 mAlarmEnabled(false)
42{ 42{
43 43
44} 44}
45 45
46Alarm::~Alarm() 46Alarm::~Alarm()
47{ 47{
48} 48}
49 49
50bool Alarm::operator==( const Alarm& rhs ) const 50bool Alarm::operator==( const Alarm& rhs ) const
51{ 51{
52 if ( mType != rhs.mType || 52 if ( mType != rhs.mType ||
53 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || 53 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ||
54 mAlarmRepeatCount != rhs.mAlarmRepeatCount || 54 mAlarmRepeatCount != rhs.mAlarmRepeatCount ||
55 mAlarmEnabled != rhs.mAlarmEnabled || 55 mAlarmEnabled != rhs.mAlarmEnabled ||
56 mHasTime != rhs.mHasTime) 56 mHasTime != rhs.mHasTime)
57 return false; 57 return false;
58 58
59 if (mHasTime) { 59 if (mHasTime) {
60 if (mAlarmTime != rhs.mAlarmTime) 60 if (mAlarmTime != rhs.mAlarmTime)
61 return false; 61 return false;
62 } else { 62 } else {
63 if (mOffset != rhs.mOffset || 63 if (mOffset != rhs.mOffset ||
64 mEndOffset != rhs.mEndOffset) 64 mEndOffset != rhs.mEndOffset)
65 return false; 65 return false;
66 } 66 }
67 67
68 switch (mType) { 68 switch (mType) {
69 case Display: 69 case Display:
70 return mDescription == rhs.mDescription; 70 return mDescription == rhs.mDescription;
71 71
72 case Email: 72 case Email:
73 return mDescription == rhs.mDescription && 73 return mDescription == rhs.mDescription &&
74 mMailAttachFiles == rhs.mMailAttachFiles && 74 mMailAttachFiles == rhs.mMailAttachFiles &&
75 mMailAddresses == rhs.mMailAddresses && 75 mMailAddresses == rhs.mMailAddresses &&
76 mMailSubject == rhs.mMailSubject; 76 mMailSubject == rhs.mMailSubject;
77 77
78 case Procedure: 78 case Procedure:
79 return mFile == rhs.mFile && 79 return mFile == rhs.mFile &&
80 mDescription == rhs.mDescription; 80 mDescription == rhs.mDescription;
81 81
82 case Audio: 82 case Audio:
83 return mFile == rhs.mFile; 83 return mFile == rhs.mFile;
84 84
85 case Invalid: 85 case Invalid:
86 break; 86 break;
87 } 87 }
88 return false; 88 return false;
89} 89}
90 90
91void Alarm::setType(Alarm::Type type) 91void Alarm::setType(Alarm::Type type)
92{ 92{
93 if (type == mType) 93 if (type == mType)
94 return; 94 return;
95 95
96 switch (type) { 96 switch (type) {
97 case Display: 97 case Display:
98 mDescription = ""; 98 mDescription = "";
99 break; 99 break;
100 case Procedure: 100 case Procedure:
101 mFile = mDescription = ""; 101 mFile = mDescription = "";
102 break; 102 break;
103 case Audio: 103 case Audio:
104 mFile = ""; 104 mFile = "";
105 break; 105 break;
106 case Email: 106 case Email:
107 mMailSubject = mDescription = ""; 107 mMailSubject = mDescription = "";
108 mMailAddresses.clear(); 108 mMailAddresses.clear();
109 mMailAttachFiles.clear(); 109 mMailAttachFiles.clear();
110 break; 110 break;
111 case Invalid: 111 case Invalid:
112 break; 112 break;
113 default: 113 default:
114 return; 114 return;
115 } 115 }
116 mType = type; 116 mType = type;
117 mParent->updated(); 117 mParent->updated();
118} 118}
119 119
120Alarm::Type Alarm::type() const 120Alarm::Type Alarm::type() const
121{ 121{
122 return mType; 122 return mType;
123} 123}
124 124
125void Alarm::setAudioAlarm(const QString &audioFile) 125void Alarm::setAudioAlarm(const QString &audioFile)
126{ 126{
127 mType = Audio; 127 mType = Audio;
128 mFile = audioFile; 128 mFile = audioFile;
129 mParent->updated(); 129 mParent->updated();
130} 130}
131 131
132void Alarm::setAudioFile(const QString &audioFile) 132void Alarm::setAudioFile(const QString &audioFile)
133{ 133{
134 if (mType == Audio) { 134 if (mType == Audio) {
135 mFile = audioFile; 135 mFile = audioFile;
136 mParent->updated(); 136 mParent->updated();
137 } 137 }
138} 138}
139 139
140QString Alarm::audioFile() const 140QString Alarm::audioFile() const
141{ 141{
142 return (mType == Audio) ? mFile : QString::null; 142 return (mType == Audio) ? mFile : QString::null;
143} 143}
144 144
145void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) 145void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments)
146{ 146{
147 mType = Procedure; 147 mType = Procedure;
148 mFile = programFile; 148 mFile = programFile;
149 mDescription = arguments; 149 mDescription = arguments;
150 mParent->updated(); 150 mParent->updated();
151} 151}
152 152
153void Alarm::setProgramFile(const QString &programFile) 153void Alarm::setProgramFile(const QString &programFile)
154{ 154{
155 if (mType == Procedure) { 155 if (mType == Procedure) {
156 mFile = programFile; 156 mFile = programFile;
157 mParent->updated(); 157 mParent->updated();
158 } 158 }
159} 159}
160 160
161QString Alarm::programFile() const 161QString Alarm::programFile() const
162{ 162{
163 return (mType == Procedure) ? mFile : QString::null; 163 return (mType == Procedure) ? mFile : QString::null;
164} 164}
165 165
166void Alarm::setProgramArguments(const QString &arguments) 166void Alarm::setProgramArguments(const QString &arguments)
167{ 167{
168 if (mType == Procedure) { 168 if (mType == Procedure) {
169 mDescription = arguments; 169 mDescription = arguments;
170 mParent->updated(); 170 mParent->updated();
171 } 171 }
172} 172}
173 173
174QString Alarm::programArguments() const 174QString Alarm::programArguments() const
175{ 175{
176 return (mType == Procedure) ? mDescription : QString::null; 176 return (mType == Procedure) ? mDescription : QString::null;
177} 177}
178 178
179void Alarm::setEmailAlarm(const QString &subject, const QString &text, 179void Alarm::setEmailAlarm(const QString &subject, const QString &text,
180 const QValueList<Person> &addressees, const QStringList &attachments) 180 const QValueList<Person> &addressees, const QStringList &attachments)
181{ 181{
182 mType = Email; 182 mType = Email;
183 mMailSubject = subject; 183 mMailSubject = subject;
184 mDescription = text; 184 mDescription = text;
185 mMailAddresses = addressees; 185 mMailAddresses = addressees;
186 mMailAttachFiles = attachments; 186 mMailAttachFiles = attachments;
187 mParent->updated(); 187 mParent->updated();
188} 188}
189 189
190void Alarm::setMailAddress(const Person &mailAddress) 190void Alarm::setMailAddress(const Person &mailAddress)
191{ 191{
192 if (mType == Email) { 192 if (mType == Email) {
193 mMailAddresses.clear(); 193 mMailAddresses.clear();
194 mMailAddresses += mailAddress; 194 mMailAddresses += mailAddress;
195 mParent->updated(); 195 mParent->updated();
196 } 196 }
197} 197}
198 198
199void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) 199void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses)
200{ 200{
201 if (mType == Email) { 201 if (mType == Email) {
202 mMailAddresses = mailAddresses; 202 mMailAddresses = mailAddresses;
203 mParent->updated(); 203 mParent->updated();
204 } 204 }
205} 205}
206 206
207void Alarm::addMailAddress(const Person &mailAddress) 207void Alarm::addMailAddress(const Person &mailAddress)
208{ 208{
209 if (mType == Email) { 209 if (mType == Email) {
210 mMailAddresses += mailAddress; 210 mMailAddresses += mailAddress;
211 mParent->updated(); 211 mParent->updated();
212 } 212 }
213} 213}
214 214
215QValueList<Person> Alarm::mailAddresses() const 215QValueList<Person> Alarm::mailAddresses() const
216{ 216{
217 return (mType == Email) ? mMailAddresses : QValueList<Person>(); 217 return (mType == Email) ? mMailAddresses : QValueList<Person>();
218} 218}
219 219
220void Alarm::setMailSubject(const QString &mailAlarmSubject) 220void Alarm::setMailSubject(const QString &mailAlarmSubject)
221{ 221{
222 if (mType == Email) { 222 if (mType == Email) {
223 mMailSubject = mailAlarmSubject; 223 mMailSubject = mailAlarmSubject;
224 mParent->updated(); 224 mParent->updated();
225 } 225 }
226} 226}
227 227
228QString Alarm::mailSubject() const 228QString Alarm::mailSubject() const
229{ 229{
230 return (mType == Email) ? mMailSubject : QString::null; 230 return (mType == Email) ? mMailSubject : QString::null;
231} 231}
232 232
233void Alarm::setMailAttachment(const QString &mailAttachFile) 233void Alarm::setMailAttachment(const QString &mailAttachFile)
234{ 234{
235 if (mType == Email) { 235 if (mType == Email) {
236 mMailAttachFiles.clear(); 236 mMailAttachFiles.clear();
237 mMailAttachFiles += mailAttachFile; 237 mMailAttachFiles += mailAttachFile;
238 mParent->updated(); 238 mParent->updated();
239 } 239 }
240} 240}
241 241
242void Alarm::setMailAttachments(const QStringList &mailAttachFiles) 242void Alarm::setMailAttachments(const QStringList &mailAttachFiles)
243{ 243{
244 if (mType == Email) { 244 if (mType == Email) {
245 mMailAttachFiles = mailAttachFiles; 245 mMailAttachFiles = mailAttachFiles;
246 mParent->updated(); 246 mParent->updated();
247 } 247 }
248} 248}
249 249
250void Alarm::addMailAttachment(const QString &mailAttachFile) 250void Alarm::addMailAttachment(const QString &mailAttachFile)
251{ 251{
252 if (mType == Email) { 252 if (mType == Email) {
253 mMailAttachFiles += mailAttachFile; 253 mMailAttachFiles += mailAttachFile;
254 mParent->updated(); 254 mParent->updated();
255 } 255 }
256} 256}
257 257
258QStringList Alarm::mailAttachments() const 258QStringList Alarm::mailAttachments() const
259{ 259{
260 return (mType == Email) ? mMailAttachFiles : QStringList(); 260 return (mType == Email) ? mMailAttachFiles : QStringList();
261} 261}
262 262
263void Alarm::setMailText(const QString &text) 263void Alarm::setMailText(const QString &text)
264{ 264{
265 if (mType == Email) { 265 if (mType == Email) {
266 mDescription = text; 266 mDescription = text;
267 mParent->updated(); 267 mParent->updated();
268 } 268 }
269} 269}
270 270
271QString Alarm::mailText() const 271QString Alarm::mailText() const
272{ 272{
273 return (mType == Email) ? mDescription : QString::null; 273 return (mType == Email) ? mDescription : QString::null;
274} 274}
275 275
276void Alarm::setDisplayAlarm(const QString &text) 276void Alarm::setDisplayAlarm(const QString &text)
277{ 277{
278 mType = Display; 278 mType = Display;
279 mDescription = text; 279 mDescription = text;
280 mParent->updated(); 280 mParent->updated();
281} 281}
282 282
283void Alarm::setText(const QString &text) 283void Alarm::setText(const QString &text)
284{ 284{
285 if (mType == Display) { 285 if (mType == Display) {
286 mDescription = text; 286 mDescription = text;
287 mParent->updated(); 287 mParent->updated();
288 } 288 }
289} 289}
290 290
291QString Alarm::text() const 291QString Alarm::text() const
292{ 292{
293 return (mType == Display) ? mDescription : QString::null; 293 return (mType == Display) ? mDescription : QString::null;
294} 294}
295 295
296void Alarm::setTime(const QDateTime &alarmTime) 296void Alarm::setTime(const QDateTime &alarmTime)
297{ 297{
298 mAlarmTime = alarmTime; 298 mAlarmTime = alarmTime;
299 mHasTime = true; 299 mHasTime = true;
300 300
301 mParent->updated(); 301 mParent->updated();
302} 302}
303int Alarm::offset()
304{
305 if ( hasTime() ) {
306 if (mParent->type()=="Todo") {
307 Todo *t = static_cast<Todo*>(mParent);
308 return t->dtDue().secsTo( mAlarmTime ) ;
309 } else
310 return mParent->dtStart().secsTo( mAlarmTime ) ;
311 }
312 else
313 {
314 return mOffset.asSeconds();
315 }
316
317}
318
303 319
304QDateTime Alarm::time() const 320QDateTime Alarm::time() const
305{ 321{
306 if ( hasTime() ) 322 if ( hasTime() )
307 return mAlarmTime; 323 return mAlarmTime;
308 else 324 else
309 { 325 {
310 if (mParent->type()=="Todo") { 326 if (mParent->type()=="Todo") {
311 Todo *t = static_cast<Todo*>(mParent); 327 Todo *t = static_cast<Todo*>(mParent);
312 return mOffset.end( t->dtDue() ); 328 return mOffset.end( t->dtDue() );
313 } else if (mEndOffset) { 329 } else if (mEndOffset) {
314 return mOffset.end( mParent->dtEnd() ); 330 return mOffset.end( mParent->dtEnd() );
315 } else { 331 } else {
316 return mOffset.end( mParent->dtStart() ); 332 return mOffset.end( mParent->dtStart() );
317 } 333 }
318 } 334 }
319} 335}
320 336
321bool Alarm::hasTime() const 337bool Alarm::hasTime() const
322{ 338{
323 return mHasTime; 339 return mHasTime;
324} 340}
325 341
326void Alarm::setSnoozeTime(int alarmSnoozeTime) 342void Alarm::setSnoozeTime(int alarmSnoozeTime)
327{ 343{
328 mAlarmSnoozeTime = alarmSnoozeTime; 344 mAlarmSnoozeTime = alarmSnoozeTime;
329 mParent->updated(); 345 mParent->updated();
330} 346}
331 347
332int Alarm::snoozeTime() const 348int Alarm::snoozeTime() const
333{ 349{
334 return mAlarmSnoozeTime; 350 return mAlarmSnoozeTime;
335} 351}
336 352
337void Alarm::setRepeatCount(int alarmRepeatCount) 353void Alarm::setRepeatCount(int alarmRepeatCount)
338{ 354{
339 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; 355 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl;
340 356
341 mAlarmRepeatCount = alarmRepeatCount; 357 mAlarmRepeatCount = alarmRepeatCount;
342 mParent->updated(); 358 mParent->updated();
343} 359}
344 360
345int Alarm::repeatCount() const 361int Alarm::repeatCount() const
346{ 362{
347 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; 363 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl;
348 return mAlarmRepeatCount; 364 return mAlarmRepeatCount;
349} 365}
350 366
351void Alarm::toggleAlarm() 367void Alarm::toggleAlarm()
352{ 368{
353 mAlarmEnabled = !mAlarmEnabled; 369 mAlarmEnabled = !mAlarmEnabled;
354 mParent->updated(); 370 mParent->updated();
355} 371}
356 372
357void Alarm::setEnabled(bool enable) 373void Alarm::setEnabled(bool enable)
358{ 374{
359 mAlarmEnabled = enable; 375 mAlarmEnabled = enable;
360 mParent->updated(); 376 mParent->updated();
361} 377}
362 378
363bool Alarm::enabled() const 379bool Alarm::enabled() const
364{ 380{
365 return mAlarmEnabled; 381 return mAlarmEnabled;
366} 382}
367 383
368void Alarm::setStartOffset( const Duration &offset ) 384void Alarm::setStartOffset( const Duration &offset )
369{ 385{
370 mOffset = offset; 386 mOffset = offset;
371 mEndOffset = false; 387 mEndOffset = false;
372 mHasTime = false; 388 mHasTime = false;
373 mParent->updated(); 389 mParent->updated();
374} 390}
375 391
376Duration Alarm::startOffset() const 392Duration Alarm::startOffset() const
377{ 393{
378 return (mHasTime || mEndOffset) ? 0 : mOffset; 394 return (mHasTime || mEndOffset) ? 0 : mOffset;
379} 395}
380 396
381bool Alarm::hasStartOffset() const 397bool Alarm::hasStartOffset() const
382{ 398{
383 return !mHasTime && !mEndOffset; 399 return !mHasTime && !mEndOffset;
384} 400}
385 401
386bool Alarm::hasEndOffset() const 402bool Alarm::hasEndOffset() const
387{ 403{
388 return !mHasTime && mEndOffset; 404 return !mHasTime && mEndOffset;
389} 405}
390 406
391void Alarm::setEndOffset( const Duration &offset ) 407void Alarm::setEndOffset( const Duration &offset )
392{ 408{
393 mOffset = offset; 409 mOffset = offset;
394 mEndOffset = true; 410 mEndOffset = true;
395 mHasTime = false; 411 mHasTime = false;
396 mParent->updated(); 412 mParent->updated();
397} 413}
398 414
399Duration Alarm::endOffset() const 415Duration Alarm::endOffset() const
400{ 416{
401 return (mHasTime || !mEndOffset) ? 0 : mOffset; 417 return (mHasTime || !mEndOffset) ? 0 : mOffset;
402} 418}
403 419
404void Alarm::setParent( Incidence *parent ) 420void Alarm::setParent( Incidence *parent )
405{ 421{
406 mParent = parent; 422 mParent = parent;
407} 423}