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