libkcal Library API Documentation

alarm.cpp

00001 /*
00002     This file is part of libkcal.
00003     Copyright (c) 1998 Preston Brown
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019     Boston, MA 02111-1307, USA.
00020 */
00021 
00022 #include <kdebug.h>
00023 
00024 #include "incidence.h"
00025 #include "todo.h"
00026 
00027 #include "alarm.h"
00028 
00029 using namespace KCal;
00030 
00031 Alarm::Alarm(Incidence *parent)
00032  : mParent(parent),
00033    mType(Invalid),
00034    mDescription(""),    // to make operator==() not fail
00035    mFile(""),           // to make operator==() not fail
00036    mMailSubject(""),    // to make operator==() not fail
00037    mAlarmSnoozeTime(5),
00038    mAlarmRepeatCount(0),
00039    mEndOffset(false),
00040    mHasTime(false),
00041    mAlarmEnabled(false)
00042 {
00043 }
00044 
00045 Alarm::~Alarm()
00046 {
00047 }
00048 
00049 bool Alarm::operator==( const Alarm& rhs ) const
00050 {
00051   if ( mType != rhs.mType ||
00052        mAlarmSnoozeTime != rhs.mAlarmSnoozeTime ||
00053        mAlarmRepeatCount != rhs.mAlarmRepeatCount ||
00054        mAlarmEnabled != rhs.mAlarmEnabled ||
00055        mHasTime != rhs.mHasTime)
00056     return false;
00057 
00058   if (mHasTime) {
00059     if (mAlarmTime != rhs.mAlarmTime)
00060       return false;
00061   } else {
00062     if (mOffset != rhs.mOffset ||
00063         mEndOffset != rhs.mEndOffset)
00064       return false;
00065   }
00066 
00067   switch (mType) {
00068     case Display:
00069       return mDescription == rhs.mDescription;
00070 
00071     case Email:
00072       return mDescription == rhs.mDescription &&
00073              mMailAttachFiles == rhs.mMailAttachFiles &&
00074              mMailAddresses == rhs.mMailAddresses &&
00075              mMailSubject == rhs.mMailSubject;
00076 
00077     case Procedure:
00078       return mFile == rhs.mFile &&
00079              mDescription == rhs.mDescription;
00080 
00081     case Audio:
00082       return mFile == rhs.mFile;
00083 
00084     case Invalid:
00085       break;
00086   }
00087   return false;
00088 }
00089 
00090 void Alarm::setType(Alarm::Type type)
00091 {
00092   if (type == mType)
00093     return;
00094 
00095   switch (type) {
00096     case Display:
00097       mDescription = "";
00098       break;
00099     case Procedure:
00100       mFile = mDescription = "";
00101       break;
00102     case Audio:
00103       mFile = "";
00104       break;
00105     case Email:
00106       mMailSubject = mDescription = "";
00107       mMailAddresses.clear();
00108       mMailAttachFiles.clear();
00109       break;
00110     case Invalid:
00111       break;
00112     default:
00113       return;
00114   }
00115   mType = type;
00116   mParent->updated();
00117 }
00118 
00119 Alarm::Type Alarm::type() const
00120 {
00121   return mType;
00122 }
00123 
00124 void Alarm::setAudioAlarm(const QString &audioFile)
00125 {
00126   mType = Audio;
00127   mFile = audioFile;
00128   mParent->updated();
00129 }
00130 
00131 void Alarm::setAudioFile(const QString &audioFile)
00132 {
00133   if (mType == Audio) {
00134     mFile = audioFile;
00135     mParent->updated();
00136   }
00137 }
00138 
00139 QString Alarm::audioFile() const
00140 {
00141   return (mType == Audio) ? mFile : QString::null;
00142 }
00143 
00144 void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments)
00145 {
00146   mType = Procedure;
00147   mFile = programFile;
00148   mDescription = arguments;
00149   mParent->updated();
00150 }
00151 
00152 void Alarm::setProgramFile(const QString &programFile)
00153 {
00154   if (mType == Procedure) {
00155     mFile = programFile;
00156     mParent->updated();
00157   }
00158 }
00159 
00160 QString Alarm::programFile() const
00161 {
00162   return (mType == Procedure) ? mFile : QString::null;
00163 }
00164 
00165 void Alarm::setProgramArguments(const QString &arguments)
00166 {
00167   if (mType == Procedure) {
00168     mDescription = arguments;
00169     mParent->updated();
00170   }
00171 }
00172 
00173 QString Alarm::programArguments() const
00174 {
00175   return (mType == Procedure) ? mDescription : QString::null;
00176 }
00177 
00178 void Alarm::setEmailAlarm(const QString &subject, const QString &text,
00179                           const QValueList<Person> &addressees, const QStringList &attachments)
00180 {
00181   mType = Email;
00182   mMailSubject = subject;
00183   mDescription = text;
00184   mMailAddresses = addressees;
00185   mMailAttachFiles = attachments;
00186   mParent->updated();
00187 }
00188 
00189 void Alarm::setMailAddress(const Person &mailAddress)
00190 {
00191   if (mType == Email) {
00192     mMailAddresses.clear();
00193     mMailAddresses += mailAddress;
00194     mParent->updated();
00195   }
00196 }
00197 
00198 void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses)
00199 {
00200   if (mType == Email) {
00201     mMailAddresses = mailAddresses;
00202     mParent->updated();
00203   }
00204 }
00205 
00206 void Alarm::addMailAddress(const Person &mailAddress)
00207 {
00208   if (mType == Email) {
00209     mMailAddresses += mailAddress;
00210     mParent->updated();
00211   }
00212 }
00213 
00214 QValueList<Person> Alarm::mailAddresses() const
00215 {
00216   return (mType == Email) ? mMailAddresses : QValueList<Person>();
00217 }
00218 
00219 void Alarm::setMailSubject(const QString &mailAlarmSubject)
00220 {
00221   if (mType == Email) {
00222     mMailSubject = mailAlarmSubject;
00223     mParent->updated();
00224   }
00225 }
00226 
00227 QString Alarm::mailSubject() const
00228 {
00229   return (mType == Email) ? mMailSubject : QString::null;
00230 }
00231 
00232 void Alarm::setMailAttachment(const QString &mailAttachFile)
00233 {
00234   if (mType == Email) {
00235     mMailAttachFiles.clear();
00236     mMailAttachFiles += mailAttachFile;
00237     mParent->updated();
00238   }
00239 }
00240 
00241 void Alarm::setMailAttachments(const QStringList &mailAttachFiles)
00242 {
00243   if (mType == Email) {
00244     mMailAttachFiles = mailAttachFiles;
00245     mParent->updated();
00246   }
00247 }
00248 
00249 void Alarm::addMailAttachment(const QString &mailAttachFile)
00250 {
00251   if (mType == Email) {
00252     mMailAttachFiles += mailAttachFile;
00253     mParent->updated();
00254   }
00255 }
00256 
00257 QStringList Alarm::mailAttachments() const
00258 {
00259   return (mType == Email) ? mMailAttachFiles : QStringList();
00260 }
00261 
00262 void Alarm::setMailText(const QString &text)
00263 {
00264   if (mType == Email) {
00265     mDescription = text;
00266     mParent->updated();
00267   }
00268 }
00269 
00270 QString Alarm::mailText() const
00271 {
00272   return (mType == Email) ? mDescription : QString::null;
00273 }
00274 
00275 void Alarm::setDisplayAlarm(const QString &text)
00276 {
00277   mType = Display;
00278   if ( !text.isNull() )
00279     mDescription = text;
00280   mParent->updated();
00281 }
00282 
00283 void Alarm::setText(const QString &text)
00284 {
00285   if (mType == Display) {
00286     mDescription = text;
00287     mParent->updated();
00288   }
00289 }
00290 
00291 QString Alarm::text() const
00292 {
00293   return (mType == Display) ? mDescription : QString::null;
00294 }
00295 
00296 void Alarm::setTime(const QDateTime &alarmTime)
00297 {
00298   mAlarmTime = alarmTime;
00299   mHasTime = true;
00300 
00301   mParent->updated();
00302 }
00303 
00304 QDateTime Alarm::time() const
00305 {
00306   if ( hasTime() )
00307     return mAlarmTime;
00308   else
00309   {
00310     if (mParent->type()=="Todo") {
00311       Todo *t = static_cast<Todo*>(mParent);
00312       return mOffset.end( t->dtDue() );
00313     } else if (mEndOffset) {
00314       return mOffset.end( mParent->dtEnd() );
00315     } else {
00316       return mOffset.end( mParent->dtStart() );
00317     }
00318   }
00319 }
00320 
00321 bool Alarm::hasTime() const
00322 {
00323   return mHasTime;
00324 }
00325 
00326 void Alarm::setSnoozeTime(int alarmSnoozeTime)
00327 {
00328   mAlarmSnoozeTime = alarmSnoozeTime;
00329   mParent->updated();
00330 }
00331 
00332 int Alarm::snoozeTime() const
00333 {
00334   return mAlarmSnoozeTime;
00335 }
00336 
00337 void Alarm::setRepeatCount(int alarmRepeatCount)
00338 {
00339   mAlarmRepeatCount = alarmRepeatCount;
00340   mParent->updated();
00341 }
00342 
00343 int Alarm::repeatCount() const
00344 {
00345   return mAlarmRepeatCount;
00346 }
00347 
00348 void Alarm::toggleAlarm()
00349 {
00350   mAlarmEnabled = !mAlarmEnabled;
00351   mParent->updated();
00352 }
00353 
00354 void Alarm::setEnabled(bool enable)
00355 {
00356   mAlarmEnabled = enable;
00357   mParent->updated();
00358 }
00359 
00360 bool Alarm::enabled() const
00361 {
00362   return mAlarmEnabled;
00363 }
00364 
00365 void Alarm::setStartOffset( const Duration &offset )
00366 {
00367   mOffset = offset;
00368   mEndOffset = false;
00369   mHasTime = false;
00370   mParent->updated();
00371 }
00372 
00373 Duration Alarm::startOffset() const
00374 {
00375   return (mHasTime || mEndOffset) ? 0 : mOffset;
00376 }
00377 
00378 bool Alarm::hasStartOffset() const
00379 {
00380   return !mHasTime && !mEndOffset;
00381 }
00382 
00383 bool Alarm::hasEndOffset() const
00384 {
00385   return !mHasTime && mEndOffset;
00386 }
00387 
00388 void Alarm::setEndOffset( const Duration &offset )
00389 {
00390   mOffset = offset;
00391   mEndOffset = true;
00392   mHasTime = false;
00393   mParent->updated();
00394 }
00395 
00396 Duration Alarm::endOffset() const
00397 {
00398   return (mHasTime || !mEndOffset) ? 0 : mOffset;
00399 }
00400 
00401 void Alarm::setParent( Incidence *parent )
00402 {
00403   mParent = parent;
00404 }
KDE Logo
This file is part of the documentation for libkcal Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Oct 4 14:39:37 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003