00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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(""),
00035 mFile(""),
00036 mMailSubject(""),
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 mDescription = text;
00279 mParent->
updated();
00280 }
00281
00282 void Alarm::setText(
const QString &text)
00283 {
00284
if (mType == Display) {
00285 mDescription = text;
00286 mParent->
updated();
00287 }
00288 }
00289
00290 QString
Alarm::text()
const
00291
{
00292
return (mType == Display) ? mDescription : QString::null;
00293 }
00294
00295 void Alarm::setTime(
const QDateTime &alarmTime)
00296 {
00297 mAlarmTime = alarmTime;
00298 mHasTime =
true;
00299
00300 mParent->
updated();
00301 }
00302
00303 QDateTime
Alarm::time()
const
00304
{
00305
if (
hasTime() )
00306
return mAlarmTime;
00307
else
00308 {
00309
if (mParent->
type()==
"Todo") {
00310
Todo *t = static_cast<Todo*>(mParent);
00311
return mOffset.
end( t->
dtDue() );
00312 }
else if (mEndOffset) {
00313
return mOffset.
end( mParent->
dtEnd() );
00314 }
else {
00315
return mOffset.
end( mParent->
dtStart() );
00316 }
00317 }
00318 }
00319
00320 bool Alarm::hasTime()
const
00321
{
00322
return mHasTime;
00323 }
00324
00325 void Alarm::setSnoozeTime(
int alarmSnoozeTime)
00326 {
00327 mAlarmSnoozeTime = alarmSnoozeTime;
00328 mParent->
updated();
00329 }
00330
00331 int Alarm::snoozeTime()
const
00332
{
00333
return mAlarmSnoozeTime;
00334 }
00335
00336 void Alarm::setRepeatCount(
int alarmRepeatCount)
00337 {
00338 kdDebug(5800) <<
"Alarm::setRepeatCount(): " << alarmRepeatCount << endl;
00339
00340 mAlarmRepeatCount = alarmRepeatCount;
00341 mParent->
updated();
00342 }
00343
00344 int Alarm::repeatCount()
const
00345
{
00346 kdDebug(5800) <<
"Alarm::repeatCount(): " << mAlarmRepeatCount << endl;
00347
return mAlarmRepeatCount;
00348 }
00349
00350 void Alarm::toggleAlarm()
00351 {
00352 mAlarmEnabled = !mAlarmEnabled;
00353 mParent->
updated();
00354 }
00355
00356 void Alarm::setEnabled(
bool enable)
00357 {
00358 mAlarmEnabled = enable;
00359 mParent->
updated();
00360 }
00361
00362 bool Alarm::enabled()
const
00363
{
00364
return mAlarmEnabled;
00365 }
00366
00367 void Alarm::setStartOffset(
const Duration &offset )
00368 {
00369 mOffset = offset;
00370 mEndOffset =
false;
00371 mHasTime =
false;
00372 mParent->
updated();
00373 }
00374
00375 Duration Alarm::startOffset()
const
00376
{
00377
return (mHasTime || mEndOffset) ? 0 : mOffset;
00378 }
00379
00380 bool Alarm::hasStartOffset()
const
00381
{
00382
return !mHasTime && !mEndOffset;
00383 }
00384
00385 bool Alarm::hasEndOffset()
const
00386
{
00387
return !mHasTime && mEndOffset;
00388 }
00389
00390 void Alarm::setEndOffset(
const Duration &offset )
00391 {
00392 mOffset = offset;
00393 mEndOffset =
true;
00394 mHasTime =
false;
00395 mParent->
updated();
00396 }
00397
00398 Duration Alarm::endOffset()
const
00399
{
00400
return (mHasTime || !mEndOffset) ? 0 : mOffset;
00401 }
00402
00403 void Alarm::setParent(
Incidence *parent )
00404 {
00405 mParent = parent;
00406 }