alarm.cpp
Go to the documentation of this file.
00001 /* 00002 This file is part of the kcalcore library. 00003 00004 Copyright (c) 1998 Preston Brown <pbrown@kde.org> 00005 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00006 Copyright (c) 2003 David Jarvie <software@astrojar.org.uk> 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License as published by the Free Software Foundation; either 00011 version 2 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public License 00019 along with this library; see the file COPYING.LIB. If not, write to 00020 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00021 Boston, MA 02110-1301, USA. 00022 */ 00033 #include "alarm.h" 00034 #include "duration.h" 00035 #include "incidence.h" 00036 00037 using namespace KCalCore; 00038 00043 //@cond PRIVATE 00044 class KCalCore::Alarm::Private 00045 { 00046 public: 00047 Private() 00048 : mParent( 0 ), 00049 mType( Alarm::Invalid ), 00050 mAlarmSnoozeTime( 5 ), 00051 mAlarmRepeatCount( 0 ), 00052 mEndOffset( false ), 00053 mHasTime( false ), 00054 mAlarmEnabled( false ), 00055 mHasLocationRadius ( false ), 00056 mLocationRadius ( 0 ) 00057 {} 00058 Private( const Private &other ) 00059 : mParent( other.mParent ), 00060 mType( other.mType ), 00061 mDescription( other.mDescription ), 00062 mFile( other.mFile ), 00063 mMailSubject( other.mMailSubject ), 00064 mMailAttachFiles( other.mMailAttachFiles ), 00065 mMailAddresses( other.mMailAddresses ), 00066 mAlarmTime( other.mAlarmTime ), 00067 mAlarmSnoozeTime( other.mAlarmSnoozeTime ), 00068 mAlarmRepeatCount( other.mAlarmRepeatCount ), 00069 mOffset( other.mOffset ), 00070 mEndOffset( other.mEndOffset ), 00071 mHasTime( other.mHasTime ), 00072 mAlarmEnabled( other.mAlarmEnabled ), 00073 mHasLocationRadius( other.mHasLocationRadius ), 00074 mLocationRadius( other.mLocationRadius ) 00075 {} 00076 00077 Incidence *mParent; // the incidence which this alarm belongs to 00078 00079 Type mType; // type of alarm 00080 QString mDescription;// text to display/email body/procedure arguments 00081 QString mFile; // program to run/optional audio file to play 00082 QString mMailSubject;// subject of email 00083 QStringList mMailAttachFiles; // filenames to attach to email 00084 Person::List mMailAddresses; // who to mail for reminder 00085 00086 KDateTime mAlarmTime;// time at which to trigger the alarm 00087 Duration mAlarmSnoozeTime; // how long after alarm to snooze before 00088 // triggering again 00089 int mAlarmRepeatCount;// number of times for alarm to repeat 00090 // after the initial time 00091 00092 Duration mOffset; // time relative to incidence DTSTART 00093 // to trigger the alarm 00094 bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART 00095 bool mHasTime; // use mAlarmTime, not mOffset 00096 bool mAlarmEnabled; 00097 00098 bool mHasLocationRadius; 00099 int mLocationRadius; // location radius for the alarm 00100 }; 00101 //@endcond 00102 00103 Alarm::Alarm( Incidence *parent ) : d( new KCalCore::Alarm::Private ) 00104 { 00105 d->mParent = parent; 00106 } 00107 00108 Alarm::Alarm( const Alarm &other ) : 00109 CustomProperties( other ), d( new KCalCore::Alarm::Private( *other.d ) ) 00110 { 00111 } 00112 00113 Alarm::~Alarm() 00114 { 00115 delete d; 00116 } 00117 00118 Alarm &Alarm::operator=( const Alarm &a ) 00119 { 00120 if ( &a != this ) { 00121 d->mParent = a.d->mParent; 00122 d->mType = a.d->mType; 00123 d->mDescription = a.d->mDescription; 00124 d->mFile = a.d->mFile; 00125 d->mMailAttachFiles = a.d->mMailAttachFiles; 00126 d->mMailAddresses = a.d->mMailAddresses; 00127 d->mMailSubject = a.d->mMailSubject; 00128 d->mAlarmSnoozeTime = a.d->mAlarmSnoozeTime; 00129 d->mAlarmRepeatCount = a.d->mAlarmRepeatCount; 00130 d->mAlarmTime = a.d->mAlarmTime; 00131 d->mOffset = a.d->mOffset; 00132 d->mEndOffset = a.d->mEndOffset; 00133 d->mHasTime = a.d->mHasTime; 00134 d->mAlarmEnabled = a.d->mAlarmEnabled; 00135 } 00136 00137 return *this; 00138 } 00139 00140 bool Alarm::operator==( const Alarm &rhs ) const 00141 { 00142 if ( d->mType != rhs.d->mType || 00143 d->mAlarmSnoozeTime != rhs.d->mAlarmSnoozeTime || 00144 d->mAlarmRepeatCount != rhs.d->mAlarmRepeatCount || 00145 d->mAlarmEnabled != rhs.d->mAlarmEnabled || 00146 d->mHasTime != rhs.d->mHasTime || 00147 d->mHasLocationRadius != rhs.d->mHasLocationRadius || 00148 d->mLocationRadius != rhs.d->mLocationRadius ) { 00149 return false; 00150 } 00151 00152 if ( d->mHasTime ) { 00153 if ( d->mAlarmTime != rhs.d->mAlarmTime ) { 00154 return false; 00155 } 00156 } else { 00157 if ( d->mOffset != rhs.d->mOffset || d->mEndOffset != rhs.d->mEndOffset ) { 00158 return false; 00159 } 00160 } 00161 00162 switch ( d->mType ) { 00163 case Display: 00164 return d->mDescription == rhs.d->mDescription; 00165 00166 case Email: 00167 return d->mDescription == rhs.d->mDescription && 00168 d->mMailAttachFiles == rhs.d->mMailAttachFiles && 00169 d->mMailAddresses == rhs.d->mMailAddresses && 00170 d->mMailSubject == rhs.d->mMailSubject; 00171 00172 case Procedure: 00173 return d->mFile == rhs.d->mFile && 00174 d->mDescription == rhs.d->mDescription; 00175 00176 case Audio: 00177 return d->mFile == rhs.d->mFile; 00178 00179 case Invalid: 00180 break; 00181 } 00182 return false; 00183 } 00184 00185 bool Alarm::operator!=( const Alarm &a ) const 00186 { 00187 return !operator==( a ); 00188 } 00189 00190 void Alarm::setType( Alarm::Type type ) 00191 { 00192 if ( type == d->mType ) { 00193 return; 00194 } 00195 00196 if ( d->mParent ) { 00197 d->mParent->update(); 00198 } 00199 switch ( type ) { 00200 case Display: 00201 d->mDescription = ""; 00202 break; 00203 case Procedure: 00204 d->mFile = d->mDescription = ""; 00205 break; 00206 case Audio: 00207 d->mFile = ""; 00208 break; 00209 case Email: 00210 d->mMailSubject = d->mDescription = ""; 00211 d->mMailAddresses.clear(); 00212 d->mMailAttachFiles.clear(); 00213 break; 00214 case Invalid: 00215 break; 00216 default: 00217 if ( d->mParent ) { 00218 d->mParent->updated(); // not really 00219 } 00220 return; 00221 } 00222 d->mType = type; 00223 if ( d->mParent ) { 00224 d->mParent->updated(); 00225 } 00226 } 00227 00228 Alarm::Type Alarm::type() const 00229 { 00230 return d->mType; 00231 } 00232 00233 void Alarm::setAudioAlarm( const QString &audioFile ) 00234 { 00235 if ( d->mParent ) { 00236 d->mParent->update(); 00237 } 00238 d->mType = Audio; 00239 d->mFile = audioFile; 00240 if ( d->mParent ) { 00241 d->mParent->updated(); 00242 } 00243 } 00244 00245 void Alarm::setAudioFile( const QString &audioFile ) 00246 { 00247 if ( d->mType == Audio ) { 00248 if ( d->mParent ) { 00249 d->mParent->update(); 00250 } 00251 d->mFile = audioFile; 00252 if ( d->mParent ) { 00253 d->mParent->updated(); 00254 } 00255 } 00256 } 00257 00258 QString Alarm::audioFile() const 00259 { 00260 return ( d->mType == Audio ) ? d->mFile : QString(); 00261 } 00262 00263 void Alarm::setProcedureAlarm( const QString &programFile, 00264 const QString &arguments ) 00265 { 00266 if ( d->mParent ) { 00267 d->mParent->update(); 00268 } 00269 d->mType = Procedure; 00270 d->mFile = programFile; 00271 d->mDescription = arguments; 00272 if ( d->mParent ) { 00273 d->mParent->updated(); 00274 } 00275 } 00276 00277 void Alarm::setProgramFile( const QString &programFile ) 00278 { 00279 if ( d->mType == Procedure ) { 00280 if ( d->mParent ) { 00281 d->mParent->update(); 00282 } 00283 d->mFile = programFile; 00284 if ( d->mParent ) { 00285 d->mParent->updated(); 00286 } 00287 } 00288 } 00289 00290 QString Alarm::programFile() const 00291 { 00292 return ( d->mType == Procedure ) ? d->mFile : QString(); 00293 } 00294 00295 void Alarm::setProgramArguments( const QString &arguments ) 00296 { 00297 if ( d->mType == Procedure ) { 00298 if ( d->mParent ) { 00299 d->mParent->update(); 00300 } 00301 d->mDescription = arguments; 00302 if ( d->mParent ) { 00303 d->mParent->updated(); 00304 } 00305 } 00306 } 00307 00308 QString Alarm::programArguments() const 00309 { 00310 return ( d->mType == Procedure ) ? d->mDescription : QString(); 00311 } 00312 00313 void Alarm::setEmailAlarm( const QString &subject, const QString &text, 00314 const Person::List &addressees, 00315 const QStringList &attachments ) 00316 { 00317 if ( d->mParent ) { 00318 d->mParent->update(); 00319 } 00320 d->mType = Email; 00321 d->mMailSubject = subject; 00322 d->mDescription = text; 00323 d->mMailAddresses = addressees; 00324 d->mMailAttachFiles = attachments; 00325 if ( d->mParent ) { 00326 d->mParent->updated(); 00327 } 00328 } 00329 00330 void Alarm::setMailAddress( const Person::Ptr &mailAddress ) 00331 { 00332 if ( d->mType == Email ) { 00333 if ( d->mParent ) { 00334 d->mParent->update(); 00335 } 00336 d->mMailAddresses.clear(); 00337 d->mMailAddresses.append( mailAddress ); 00338 if ( d->mParent ) { 00339 d->mParent->updated(); 00340 } 00341 } 00342 } 00343 00344 void Alarm::setMailAddresses( const Person::List &mailAddresses ) 00345 { 00346 if ( d->mType == Email ) { 00347 if ( d->mParent ) { 00348 d->mParent->update(); 00349 } 00350 d->mMailAddresses += mailAddresses; 00351 if ( d->mParent ) { 00352 d->mParent->updated(); 00353 } 00354 } 00355 } 00356 00357 void Alarm::addMailAddress( const Person::Ptr &mailAddress ) 00358 { 00359 if ( d->mType == Email ) { 00360 if ( d->mParent ) { 00361 d->mParent->update(); 00362 } 00363 d->mMailAddresses.append( mailAddress ); 00364 if ( d->mParent ) { 00365 d->mParent->updated(); 00366 } 00367 } 00368 } 00369 00370 Person::List Alarm::mailAddresses() const 00371 { 00372 return ( d->mType == Email ) ? d->mMailAddresses : Person::List(); 00373 } 00374 00375 void Alarm::setMailSubject( const QString &mailAlarmSubject ) 00376 { 00377 if ( d->mType == Email ) { 00378 if ( d->mParent ) { 00379 d->mParent->update(); 00380 } 00381 d->mMailSubject = mailAlarmSubject; 00382 if ( d->mParent ) { 00383 d->mParent->updated(); 00384 } 00385 } 00386 } 00387 00388 QString Alarm::mailSubject() const 00389 { 00390 return ( d->mType == Email ) ? d->mMailSubject : QString(); 00391 } 00392 00393 void Alarm::setMailAttachment( const QString &mailAttachFile ) 00394 { 00395 if ( d->mType == Email ) { 00396 if ( d->mParent ) { 00397 d->mParent->update(); 00398 } 00399 d->mMailAttachFiles.clear(); 00400 d->mMailAttachFiles += mailAttachFile; 00401 if ( d->mParent ) { 00402 d->mParent->updated(); 00403 } 00404 } 00405 } 00406 00407 void Alarm::setMailAttachments( const QStringList &mailAttachFiles ) 00408 { 00409 if ( d->mType == Email ) { 00410 if ( d->mParent ) { 00411 d->mParent->update(); 00412 } 00413 d->mMailAttachFiles = mailAttachFiles; 00414 if ( d->mParent ) { 00415 d->mParent->updated(); 00416 } 00417 } 00418 } 00419 00420 void Alarm::addMailAttachment( const QString &mailAttachFile ) 00421 { 00422 if ( d->mType == Email ) { 00423 if ( d->mParent ) { 00424 d->mParent->update(); 00425 } 00426 d->mMailAttachFiles += mailAttachFile; 00427 if ( d->mParent ) { 00428 d->mParent->updated(); 00429 } 00430 } 00431 } 00432 00433 QStringList Alarm::mailAttachments() const 00434 { 00435 return ( d->mType == Email ) ? d->mMailAttachFiles : QStringList(); 00436 } 00437 00438 void Alarm::setMailText( const QString &text ) 00439 { 00440 if ( d->mType == Email ) { 00441 if ( d->mParent ) { 00442 d->mParent->update(); 00443 } 00444 d->mDescription = text; 00445 if ( d->mParent ) { 00446 d->mParent->updated(); 00447 } 00448 } 00449 } 00450 00451 QString Alarm::mailText() const 00452 { 00453 return ( d->mType == Email ) ? d->mDescription : QString(); 00454 } 00455 00456 void Alarm::setDisplayAlarm( const QString &text ) 00457 { 00458 if ( d->mParent ) { 00459 d->mParent->update(); 00460 } 00461 d->mType = Display; 00462 if ( !text.isNull() ) { 00463 d->mDescription = text; 00464 } 00465 if ( d->mParent ) { 00466 d->mParent->updated(); 00467 } 00468 } 00469 00470 void Alarm::setText( const QString &text ) 00471 { 00472 if ( d->mType == Display ) { 00473 if ( d->mParent ) { 00474 d->mParent->update(); 00475 } 00476 d->mDescription = text; 00477 if ( d->mParent ) { 00478 d->mParent->updated(); 00479 } 00480 } 00481 } 00482 00483 QString Alarm::text() const 00484 { 00485 return ( d->mType == Display ) ? d->mDescription : QString(); 00486 } 00487 00488 void Alarm::setTime( const KDateTime &alarmTime ) 00489 { 00490 if ( d->mParent ) { 00491 d->mParent->update(); 00492 } 00493 d->mAlarmTime = alarmTime; 00494 d->mHasTime = true; 00495 00496 if ( d->mParent ) { 00497 d->mParent->updated(); 00498 } 00499 } 00500 00501 KDateTime Alarm::time() const 00502 { 00503 if ( hasTime() ) { 00504 return d->mAlarmTime; 00505 } else if ( d->mParent ) { 00506 if ( d->mEndOffset ) { 00507 KDateTime dt = d->mParent->dateTime( Incidence::RoleAlarmEndOffset ); 00508 return d->mOffset.end( dt ); 00509 } else { 00510 KDateTime dt = d->mParent->dateTime( Incidence::RoleAlarmStartOffset ); 00511 return d->mOffset.end( dt ); 00512 } 00513 } else { 00514 return KDateTime(); 00515 } 00516 } 00517 00518 KDateTime Alarm::nextTime( const KDateTime &preTime, bool ignoreRepetitions ) const 00519 { 00520 if ( d->mParent && d->mParent->recurs() ) { 00521 KDateTime dtEnd = d->mParent->dateTime( Incidence::RoleAlarmEndOffset ); 00522 00523 KDateTime dtStart = d->mParent->dtStart(); 00524 // Find the incidence's earliest alarm 00525 // Alarm time is defined by an offset from the event start or end time. 00526 KDateTime alarmStart = d->mOffset.end( d->mEndOffset ? dtEnd : dtStart ); 00527 // Find the offset from the event start time, which is also used as the 00528 // offset from the recurrence time. 00529 Duration alarmOffset( dtStart, alarmStart ); 00530 /* 00531 kDebug() << "dtStart " << dtStart; 00532 kDebug() << "dtEnd " << dtEnd; 00533 kDebug() << "alarmStart " << alarmStart; 00534 kDebug() << "alarmOffset " << alarmOffset.value(); 00535 kDebug() << "preTime " << preTime; 00536 */ 00537 if ( alarmStart > preTime ) { 00538 // No need to go further. 00539 return alarmStart; 00540 } 00541 if ( d->mAlarmRepeatCount && !ignoreRepetitions ) { 00542 // The alarm has repetitions, so check whether repetitions of previous 00543 // recurrences happen after given time. 00544 KDateTime prevRecurrence = d->mParent->recurrence()->getPreviousDateTime( preTime ); 00545 if ( prevRecurrence.isValid() ) { 00546 KDateTime prevLastRepeat = alarmOffset.end( duration().end( prevRecurrence ) ); 00547 // kDebug() << "prevRecurrence" << prevRecurrence; 00548 // kDebug() << "prevLastRepeat" << prevLastRepeat; 00549 if ( prevLastRepeat > preTime ) { 00550 // Yes they did, return alarm offset to previous recurrence. 00551 KDateTime prevAlarm = alarmOffset.end( prevRecurrence ); 00552 // kDebug() << "prevAlarm " << prevAlarm; 00553 return prevAlarm; 00554 } 00555 } 00556 } 00557 // Check the next recurrence now. 00558 KDateTime nextRecurrence = d->mParent->recurrence()->getNextDateTime( preTime ); 00559 if ( nextRecurrence.isValid() ) { 00560 KDateTime nextAlarm = alarmOffset.end( nextRecurrence ); 00561 /* 00562 kDebug() << "nextRecurrence" << nextRecurrence; 00563 kDebug() << "nextAlarm " << nextAlarm; 00564 */ 00565 if ( nextAlarm > preTime ) { 00566 // It's first alarm takes place after given time. 00567 return nextAlarm; 00568 } 00569 } 00570 } else { 00571 // Not recurring. 00572 KDateTime alarmTime = time(); 00573 if ( alarmTime > preTime ) { 00574 return alarmTime; 00575 } 00576 } 00577 return KDateTime(); 00578 } 00579 00580 bool Alarm::hasTime() const 00581 { 00582 return d->mHasTime; 00583 } 00584 00585 void Alarm::shiftTimes( const KDateTime::Spec &oldSpec, 00586 const KDateTime::Spec &newSpec ) 00587 { 00588 if ( d->mParent ) { 00589 d->mParent->update(); 00590 } 00591 d->mAlarmTime = d->mAlarmTime.toTimeSpec( oldSpec ); 00592 d->mAlarmTime.setTimeSpec( newSpec ); 00593 if ( d->mParent ) { 00594 d->mParent->updated(); 00595 } 00596 } 00597 00598 void Alarm::setSnoozeTime( const Duration &alarmSnoozeTime ) 00599 { 00600 if ( alarmSnoozeTime.value() > 0 ) { 00601 if ( d->mParent ) { 00602 d->mParent->update(); 00603 } 00604 d->mAlarmSnoozeTime = alarmSnoozeTime; 00605 if ( d->mParent ) { 00606 d->mParent->updated(); 00607 } 00608 } 00609 } 00610 00611 Duration Alarm::snoozeTime() const 00612 { 00613 return d->mAlarmSnoozeTime; 00614 } 00615 00616 void Alarm::setRepeatCount( int alarmRepeatCount ) 00617 { 00618 if ( d->mParent ) { 00619 d->mParent->update(); 00620 } 00621 d->mAlarmRepeatCount = alarmRepeatCount; 00622 if ( d->mParent ) { 00623 d->mParent->updated(); 00624 } 00625 } 00626 00627 int Alarm::repeatCount() const 00628 { 00629 return d->mAlarmRepeatCount; 00630 } 00631 00632 Duration Alarm::duration() const 00633 { 00634 return Duration( d->mAlarmSnoozeTime.value() * d->mAlarmRepeatCount, 00635 d->mAlarmSnoozeTime.type() ); 00636 } 00637 00638 KDateTime Alarm::nextRepetition( const KDateTime &preTime ) const 00639 { 00640 KDateTime at = nextTime( preTime ); 00641 if ( at > preTime ) { 00642 return at; 00643 } 00644 if ( !d->mAlarmRepeatCount ) { 00645 // there isn't an occurrence after the specified time 00646 return KDateTime(); 00647 } 00648 qint64 repetition; 00649 int interval = d->mAlarmSnoozeTime.value(); 00650 bool daily = d->mAlarmSnoozeTime.isDaily(); 00651 if ( daily ) { 00652 int daysTo = at.daysTo( preTime ); 00653 if ( !preTime.isDateOnly() && preTime.time() <= at.time() ) { 00654 --daysTo; 00655 } 00656 repetition = daysTo / interval + 1; 00657 } else { 00658 repetition = at.secsTo_long( preTime ) / interval + 1; 00659 } 00660 if ( repetition > d->mAlarmRepeatCount ) { 00661 // all repetitions have finished before the specified time 00662 return KDateTime(); 00663 } 00664 return daily ? at.addDays( int( repetition * interval ) ) 00665 : at.addSecs( repetition * interval ); 00666 } 00667 00668 KDateTime Alarm::previousRepetition( const KDateTime &afterTime ) const 00669 { 00670 KDateTime at = time(); 00671 if ( at >= afterTime ) { 00672 // alarm's first/only time is at/after the specified time 00673 return KDateTime(); 00674 } 00675 if ( !d->mAlarmRepeatCount ) { 00676 return at; 00677 } 00678 qint64 repetition; 00679 int interval = d->mAlarmSnoozeTime.value(); 00680 bool daily = d->mAlarmSnoozeTime.isDaily(); 00681 if ( daily ) { 00682 int daysTo = at.daysTo( afterTime ); 00683 if ( afterTime.isDateOnly() || afterTime.time() <= at.time() ) { 00684 --daysTo; 00685 } 00686 repetition = daysTo / interval; 00687 } else { 00688 repetition = ( at.secsTo_long( afterTime ) - 1 ) / interval; 00689 } 00690 if ( repetition > d->mAlarmRepeatCount ) { 00691 repetition = d->mAlarmRepeatCount; 00692 } 00693 return daily ? at.addDays( int( repetition * interval ) ) 00694 : at.addSecs( repetition * interval ); 00695 } 00696 00697 KDateTime Alarm::endTime() const 00698 { 00699 if ( !d->mAlarmRepeatCount ) { 00700 return time(); 00701 } 00702 if ( d->mAlarmSnoozeTime.isDaily() ) { 00703 return time().addDays( d->mAlarmRepeatCount * d->mAlarmSnoozeTime.asDays() ); 00704 } else { 00705 return time().addSecs( d->mAlarmRepeatCount * d->mAlarmSnoozeTime.asSeconds() ); 00706 } 00707 } 00708 00709 void Alarm::toggleAlarm() 00710 { 00711 if ( d->mParent ) { 00712 d->mParent->update(); 00713 } 00714 d->mAlarmEnabled = !d->mAlarmEnabled; 00715 if ( d->mParent ) { 00716 d->mParent->updated(); 00717 } 00718 } 00719 00720 void Alarm::setEnabled( bool enable ) 00721 { 00722 if ( d->mParent ) { 00723 d->mParent->update(); 00724 } 00725 d->mAlarmEnabled = enable; 00726 if ( d->mParent ) { 00727 d->mParent->updated(); 00728 } 00729 } 00730 00731 bool Alarm::enabled() const 00732 { 00733 return d->mAlarmEnabled; 00734 } 00735 00736 void Alarm::setStartOffset( const Duration &offset ) 00737 { 00738 if ( d->mParent ) { 00739 d->mParent->update(); 00740 } 00741 d->mOffset = offset; 00742 d->mEndOffset = false; 00743 d->mHasTime = false; 00744 if ( d->mParent ) { 00745 d->mParent->updated(); 00746 } 00747 } 00748 00749 Duration Alarm::startOffset() const 00750 { 00751 return ( d->mHasTime || d->mEndOffset ) ? Duration( 0 ) : d->mOffset; 00752 } 00753 00754 bool Alarm::hasStartOffset() const 00755 { 00756 return !d->mHasTime && !d->mEndOffset; 00757 } 00758 00759 bool Alarm::hasEndOffset() const 00760 { 00761 return !d->mHasTime && d->mEndOffset; 00762 } 00763 00764 void Alarm::setEndOffset( const Duration &offset ) 00765 { 00766 if ( d->mParent ) { 00767 d->mParent->update(); 00768 } 00769 d->mOffset = offset; 00770 d->mEndOffset = true; 00771 d->mHasTime = false; 00772 if ( d->mParent ) { 00773 d->mParent->updated(); 00774 } 00775 } 00776 00777 Duration Alarm::endOffset() const 00778 { 00779 return ( d->mHasTime || !d->mEndOffset ) ? Duration( 0 ) : d->mOffset; 00780 } 00781 00782 void Alarm::setParent( Incidence *parent ) 00783 { 00784 d->mParent = parent; 00785 } 00786 00787 QString Alarm::parentUid() const 00788 { 00789 return d->mParent ? d->mParent->uid() : QString(); 00790 } 00791 00792 void Alarm::customPropertyUpdated() 00793 { 00794 if ( d->mParent ) { 00795 d->mParent->update(); 00796 d->mParent->updated(); 00797 } 00798 } 00799 00800 void Alarm::setHasLocationRadius( bool hasLocationRadius ) 00801 { 00802 if ( d->mParent ) { 00803 d->mParent->update(); 00804 } 00805 d->mHasLocationRadius = hasLocationRadius; 00806 if ( hasLocationRadius ) { 00807 setNonKDECustomProperty( "X-LOCATION-RADIUS", QString::number( d->mLocationRadius ) ); 00808 } else { 00809 removeNonKDECustomProperty( "X-LOCATION-RADIUS" ); 00810 } 00811 if ( d->mParent ) { 00812 d->mParent->updated(); 00813 } 00814 } 00815 00816 bool Alarm::hasLocationRadius() const 00817 { 00818 return d->mHasLocationRadius; 00819 } 00820 00821 void Alarm::setLocationRadius( int locationRadius ) 00822 { 00823 if ( d->mParent ) { 00824 d->mParent->update(); 00825 } 00826 d->mLocationRadius = locationRadius; 00827 if ( d->mParent ) { 00828 d->mParent->updated(); 00829 } 00830 } 00831 00832 int Alarm::locationRadius() const 00833 { 00834 return d->mLocationRadius; 00835 } 00836 00837 void Alarm::virtual_hook( int id, void *data ) 00838 { 00839 Q_UNUSED( id ); 00840 Q_UNUSED( data ); 00841 Q_ASSERT( false ); 00842 }