summaryrefslogtreecommitdiffabout
path: root/libkcal/alarm.cpp
Unidiff
Diffstat (limited to 'libkcal/alarm.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/alarm.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp
index 1fc7169..d8f15b5 100644
--- a/libkcal/alarm.cpp
+++ b/libkcal/alarm.cpp
@@ -1,118 +1,119 @@
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#include <klocale.h>
23 24
24#include "incidence.h" 25#include "incidence.h"
25#include "todo.h" 26#include "todo.h"
26 27
27#include "alarm.h" 28#include "alarm.h"
28 29
29using namespace KCal; 30using namespace KCal;
30#include <qwidget.h> 31#include <qwidget.h>
31Alarm::Alarm(Incidence *parent) 32Alarm::Alarm(Incidence *parent)
32 : mParent(parent), 33 : mParent(parent),
33 mType(Audio), 34 mType(Audio),
34 mDescription(""), // to make operator==() not fail 35 mDescription(""), // to make operator==() not fail
35 mFile(""), // to make operator==() not fail 36 mFile(""), // to make operator==() not fail
36 mMailSubject(""), // to make operator==() not fail 37 mMailSubject(""), // to make operator==() not fail
37 mAlarmSnoozeTime(5), 38 mAlarmSnoozeTime(5),
38 mAlarmRepeatCount(0), 39 mAlarmRepeatCount(0),
39 mEndOffset(false), 40 mEndOffset(false),
40 mHasTime(false), 41 mHasTime(false),
41 mAlarmEnabled(false) 42 mAlarmEnabled(false)
42{ 43{
43 44
44} 45}
45 46
46Alarm::~Alarm() 47Alarm::~Alarm()
47{ 48{
48} 49}
49 50
50bool Alarm::operator==( const Alarm& rhs ) const 51bool Alarm::operator==( const Alarm& rhs ) const
51{ 52{
52 53
53 if ( mType != rhs.mType || 54 if ( mType != rhs.mType ||
54 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime || 55 mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ||
55 mAlarmRepeatCount != rhs.mAlarmRepeatCount || 56 mAlarmRepeatCount != rhs.mAlarmRepeatCount ||
56 mAlarmEnabled != rhs.mAlarmEnabled || 57 mAlarmEnabled != rhs.mAlarmEnabled ||
57 mHasTime != rhs.mHasTime) 58 mHasTime != rhs.mHasTime)
58 return false; 59 return false;
59 60
60#if 0 61#if 0
61 if ( mType != rhs.mType ) { 62 if ( mType != rhs.mType ) {
62 63
63 qDebug("aaa1 "); 64 qDebug("aaa1 ");
64 return false; 65 return false;
65 } 66 }
66 67
67 if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) { 68 if ( mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ) {
68 69
69 qDebug("aaa2 "); 70 qDebug("aaa2 ");
70 return false; 71 return false;
71 } 72 }
72 73
73 74
74 if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) { 75 if ( mAlarmRepeatCount != rhs.mAlarmRepeatCount ) {
75 76
76 qDebug("aaa3 "); 77 qDebug("aaa3 ");
77 return false; 78 return false;
78 } 79 }
79 80
80 if ( mAlarmEnabled != rhs.mAlarmEnabled ) { 81 if ( mAlarmEnabled != rhs.mAlarmEnabled ) {
81 82
82 qDebug("aaa4 "); 83 qDebug("aaa4 ");
83 return false; 84 return false;
84 } 85 }
85 86
86 if ( mHasTime != rhs.mHasTime ) { 87 if ( mHasTime != rhs.mHasTime ) {
87 88
88 qDebug("aaa5 "); 89 qDebug("aaa5 ");
89 return false; 90 return false;
90 } 91 }
91#endif 92#endif
92 93
93 94
94 if (mHasTime) { 95 if (mHasTime) {
95 if (mAlarmTime != rhs.mAlarmTime) 96 if (mAlarmTime != rhs.mAlarmTime)
96 return false; 97 return false;
97 } else { 98 } else {
98 if (mOffset != rhs.mOffset || 99 if (mOffset != rhs.mOffset ||
99 mEndOffset != rhs.mEndOffset) 100 mEndOffset != rhs.mEndOffset)
100 return false; 101 return false;
101 } 102 }
102 switch (mType) { 103 switch (mType) {
103 case Display: 104 case Display:
104 return mDescription == rhs.mDescription; 105 return mDescription == rhs.mDescription;
105 106
106 case Email: 107 case Email:
107 return mDescription == rhs.mDescription && 108 return mDescription == rhs.mDescription &&
108 mMailAttachFiles == rhs.mMailAttachFiles && 109 mMailAttachFiles == rhs.mMailAttachFiles &&
109 mMailAddresses == rhs.mMailAddresses && 110 mMailAddresses == rhs.mMailAddresses &&
110 mMailSubject == rhs.mMailSubject; 111 mMailSubject == rhs.mMailSubject;
111 112
112 case Procedure: 113 case Procedure:
113 return mFile == rhs.mFile && 114 return mFile == rhs.mFile &&
114 mDescription == rhs.mDescription; 115 mDescription == rhs.mDescription;
115 116
116 case Audio: 117 case Audio:
117 return mFile == rhs.mFile; 118 return mFile == rhs.mFile;
118 119
@@ -256,192 +257,215 @@ void Alarm::setMailSubject(const QString &mailAlarmSubject)
256 if (mType == Email) { 257 if (mType == Email) {
257 mMailSubject = mailAlarmSubject; 258 mMailSubject = mailAlarmSubject;
258 mParent->updated(); 259 mParent->updated();
259 } 260 }
260} 261}
261 262
262QString Alarm::mailSubject() const 263QString Alarm::mailSubject() const
263{ 264{
264 return (mType == Email) ? mMailSubject : QString::null; 265 return (mType == Email) ? mMailSubject : QString::null;
265} 266}
266 267
267void Alarm::setMailAttachment(const QString &mailAttachFile) 268void Alarm::setMailAttachment(const QString &mailAttachFile)
268{ 269{
269 if (mType == Email) { 270 if (mType == Email) {
270 mMailAttachFiles.clear(); 271 mMailAttachFiles.clear();
271 mMailAttachFiles += mailAttachFile; 272 mMailAttachFiles += mailAttachFile;
272 mParent->updated(); 273 mParent->updated();
273 } 274 }
274} 275}
275 276
276void Alarm::setMailAttachments(const QStringList &mailAttachFiles) 277void Alarm::setMailAttachments(const QStringList &mailAttachFiles)
277{ 278{
278 if (mType == Email) { 279 if (mType == Email) {
279 mMailAttachFiles = mailAttachFiles; 280 mMailAttachFiles = mailAttachFiles;
280 mParent->updated(); 281 mParent->updated();
281 } 282 }
282} 283}
283 284
284void Alarm::addMailAttachment(const QString &mailAttachFile) 285void Alarm::addMailAttachment(const QString &mailAttachFile)
285{ 286{
286 if (mType == Email) { 287 if (mType == Email) {
287 mMailAttachFiles += mailAttachFile; 288 mMailAttachFiles += mailAttachFile;
288 mParent->updated(); 289 mParent->updated();
289 } 290 }
290} 291}
291 292
292QStringList Alarm::mailAttachments() const 293QStringList Alarm::mailAttachments() const
293{ 294{
294 return (mType == Email) ? mMailAttachFiles : QStringList(); 295 return (mType == Email) ? mMailAttachFiles : QStringList();
295} 296}
296 297
297void Alarm::setMailText(const QString &text) 298void Alarm::setMailText(const QString &text)
298{ 299{
299 if (mType == Email) { 300 if (mType == Email) {
300 mDescription = text; 301 mDescription = text;
301 mParent->updated(); 302 mParent->updated();
302 } 303 }
303} 304}
304 305
305QString Alarm::mailText() const 306QString Alarm::mailText() const
306{ 307{
307 return (mType == Email) ? mDescription : QString::null; 308 return (mType == Email) ? mDescription : QString::null;
308} 309}
309 310
310void Alarm::setDisplayAlarm(const QString &text) 311void Alarm::setDisplayAlarm(const QString &text)
311{ 312{
312 mType = Display; 313 mType = Display;
313 mDescription = text; 314 mDescription = text;
314 mParent->updated(); 315 mParent->updated();
315} 316}
316 317
317void Alarm::setText(const QString &text) 318void Alarm::setText(const QString &text)
318{ 319{
319 if (mType == Display) { 320 if (mType == Display) {
320 mDescription = text; 321 mDescription = text;
321 mParent->updated(); 322 mParent->updated();
322 } 323 }
323} 324}
324 325
325QString Alarm::text() const 326QString Alarm::text() const
326{ 327{
327 return (mType == Display) ? mDescription : QString::null; 328 return (mType == Display) ? mDescription : QString::null;
328} 329}
329 330
330void Alarm::setTime(const QDateTime &alarmTime) 331void Alarm::setTime(const QDateTime &alarmTime)
331{ 332{
332 mAlarmTime = alarmTime; 333 mAlarmTime = alarmTime;
333 mHasTime = true; 334 mHasTime = true;
334 335
335 mParent->updated(); 336 mParent->updated();
336} 337}
337int Alarm::offset() 338int Alarm::offset()
338{ 339{
339 if ( hasTime() ) { 340 if ( hasTime() ) {
340 if (mParent->type()=="Todo") { 341 if (mParent->type()=="Todo") {
341 Todo *t = static_cast<Todo*>(mParent); 342 Todo *t = static_cast<Todo*>(mParent);
342 return t->dtDue().secsTo( mAlarmTime ) ; 343 return t->dtDue().secsTo( mAlarmTime ) ;
343 } else 344 } else
344 return mParent->dtStart().secsTo( mAlarmTime ) ; 345 return mParent->dtStart().secsTo( mAlarmTime ) ;
345 } 346 }
346 else 347 else
347 { 348 {
348 return mOffset.asSeconds(); 349 return mOffset.asSeconds();
349 } 350 }
350 351
351} 352}
353QString Alarm::offsetText()
354{
355 int min = -offset()/60;
356 int hours = min /60;
357 min = min % 60;
358 int days = hours /24;
359 hours = hours % 24;
360 QString message;
361 qDebug("%d %d %d ", days, hours, min );
362 if ( days > 0 )
363 message += i18n("%1d").arg( days );
364 if ( hours > 0 ) {
365 if ( !message.isEmpty() ) message += "/";
366 message += i18n("%1h").arg( hours );
367 }
368 if ( min > 0 ) {
369 if ( !message.isEmpty() ) message += "/";
370 message += i18n("%1min").arg( min );
371 }
372 if ( message.isEmpty() )
373 message = i18n("%1min").arg( 0 );
374 return message;
375}
352 376
353 377
354QDateTime Alarm::time() const 378QDateTime Alarm::time() const
355{ 379{
356 if ( hasTime() ) 380 if ( hasTime() )
357 return mAlarmTime; 381 return mAlarmTime;
358 else 382 else
359 { 383 {
360 if (mParent->type()=="Todo") { 384 if (mParent->type()=="Todo") {
361 Todo *t = static_cast<Todo*>(mParent); 385 Todo *t = static_cast<Todo*>(mParent);
362 return mOffset.end( t->dtDue() ); 386 return mOffset.end( t->dtDue() );
363 } else if (mEndOffset) { 387 } else if (mEndOffset) {
364 return mOffset.end( mParent->dtEnd() ); 388 return mOffset.end( mParent->dtEnd() );
365 } else { 389 } else {
366 return mOffset.end( mParent->dtStart() ); 390 return mOffset.end( mParent->dtStart() );
367 } 391 }
368 } 392 }
369} 393}
370 394
371bool Alarm::hasTime() const 395bool Alarm::hasTime() const
372{ 396{
373 return mHasTime; 397 return mHasTime;
374} 398}
375 399
376void Alarm::setSnoozeTime(int alarmSnoozeTime) 400void Alarm::setSnoozeTime(int alarmSnoozeTime)
377{ 401{
378 mAlarmSnoozeTime = alarmSnoozeTime; 402 mAlarmSnoozeTime = alarmSnoozeTime;
379 mParent->updated(); 403 mParent->updated();
380} 404}
381 405
382int Alarm::snoozeTime() const 406int Alarm::snoozeTime() const
383{ 407{
384 return mAlarmSnoozeTime; 408 return mAlarmSnoozeTime;
385} 409}
386 410
387void Alarm::setRepeatCount(int alarmRepeatCount) 411void Alarm::setRepeatCount(int alarmRepeatCount)
388{ 412{
389 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl; 413 kdDebug(5800) << "Alarm::setRepeatCount(): " << alarmRepeatCount << endl;
390 414
391 mAlarmRepeatCount = alarmRepeatCount; 415 mAlarmRepeatCount = alarmRepeatCount;
392 mParent->updated(); 416 mParent->updated();
393} 417}
394 418
395int Alarm::repeatCount() const 419int Alarm::repeatCount() const
396{ 420{
397 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl; 421 kdDebug(5800) << "Alarm::repeatCount(): " << mAlarmRepeatCount << endl;
398 return mAlarmRepeatCount; 422 return mAlarmRepeatCount;
399} 423}
400 424
401void Alarm::toggleAlarm() 425void Alarm::toggleAlarm()
402{ 426{
403 mAlarmEnabled = !mAlarmEnabled; 427 mAlarmEnabled = !mAlarmEnabled;
404 mParent->updated(); 428 mParent->updated();
405} 429}
406 430
407void Alarm::setEnabled(bool enable) 431void Alarm::setEnabled(bool enable)
408{ 432{
409 mAlarmEnabled = enable; 433 mAlarmEnabled = enable;
410 mParent->updated(); 434 mParent->updated();
411} 435}
412 436
413bool Alarm::enabled() const 437bool Alarm::enabled() const
414{ 438{
415 return mAlarmEnabled; 439 return mAlarmEnabled;
416} 440}
417 441
418void Alarm::setStartOffset( const Duration &offset ) 442void Alarm::setStartOffset( const Duration &offset )
419{ 443{
420 mOffset = offset; 444 mOffset = offset;
421 mEndOffset = false; 445 mEndOffset = false;
422 mHasTime = false; 446 mHasTime = false;
423 mParent->updated(); 447 mParent->updated();
424} 448}
425 449
426Duration Alarm::startOffset() const 450Duration Alarm::startOffset() const
427{ 451{
428 return (mHasTime || mEndOffset) ? 0 : mOffset; 452 return (mHasTime || mEndOffset) ? 0 : mOffset;
429} 453}
430 454
431bool Alarm::hasStartOffset() const 455bool Alarm::hasStartOffset() const
432{ 456{
433 return !mHasTime && !mEndOffset; 457 return !mHasTime && !mEndOffset;
434} 458}
435 459
436bool Alarm::hasEndOffset() const 460bool Alarm::hasEndOffset() const
437{ 461{
438 return !mHasTime && mEndOffset; 462 return !mHasTime && mEndOffset;
439} 463}
440 464
441void Alarm::setEndOffset( const Duration &offset ) 465void Alarm::setEndOffset( const Duration &offset )
442{ 466{
443 mOffset = offset; 467 mOffset = offset;
444 mEndOffset = true; 468 mEndOffset = true;
445 mHasTime = false; 469 mHasTime = false;
446 mParent->updated(); 470 mParent->updated();
447} 471}