summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2005-04-02 14:07:31 (UTC)
committer zautrix <zautrix>2005-04-02 14:07:31 (UTC)
commitb0d17f8f2ef9b09b7d8b8aa0f6cc34f400f8fddd (patch) (unidiff)
tree942bcf89b35cf165e9147c1e4a5efa817c48007f /libkcal
parent997e7660a81baa2b8aeb1b66a3cc3ebe54e00ebe (diff)
downloadkdepimpi-b0d17f8f2ef9b09b7d8b8aa0f6cc34f400f8fddd.zip
kdepimpi-b0d17f8f2ef9b09b7d8b8aa0f6cc34f400f8fddd.tar.gz
kdepimpi-b0d17f8f2ef9b09b7d8b8aa0f6cc34f400f8fddd.tar.bz2
fixes
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/alarm.cpp24
-rw-r--r--libkcal/alarm.h1
-rw-r--r--libkcal/kincidenceformatter.cpp14
3 files changed, 37 insertions, 2 deletions
diff --git a/libkcal/alarm.cpp b/libkcal/alarm.cpp
index 1fc7169..d8f15b5 100644
--- a/libkcal/alarm.cpp
+++ b/libkcal/alarm.cpp
@@ -1,457 +1,481 @@
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
119 case Invalid: 120 case Invalid:
120 break; 121 break;
121 } 122 }
122 return false; 123 return false;
123} 124}
124 125
125void Alarm::setType(Alarm::Type type) 126void Alarm::setType(Alarm::Type type)
126{ 127{
127 if (type == mType) 128 if (type == mType)
128 return; 129 return;
129 130
130 switch (type) { 131 switch (type) {
131 case Display: 132 case Display:
132 mDescription = ""; 133 mDescription = "";
133 break; 134 break;
134 case Procedure: 135 case Procedure:
135 mFile = mDescription = ""; 136 mFile = mDescription = "";
136 break; 137 break;
137 case Audio: 138 case Audio:
138 mFile = ""; 139 mFile = "";
139 break; 140 break;
140 case Email: 141 case Email:
141 mMailSubject = mDescription = ""; 142 mMailSubject = mDescription = "";
142 mMailAddresses.clear(); 143 mMailAddresses.clear();
143 mMailAttachFiles.clear(); 144 mMailAttachFiles.clear();
144 break; 145 break;
145 case Invalid: 146 case Invalid:
146 break; 147 break;
147 default: 148 default:
148 return; 149 return;
149 } 150 }
150 mType = type; 151 mType = type;
151 mParent->updated(); 152 mParent->updated();
152} 153}
153 154
154Alarm::Type Alarm::type() const 155Alarm::Type Alarm::type() const
155{ 156{
156 return mType; 157 return mType;
157} 158}
158 159
159void Alarm::setAudioAlarm(const QString &audioFile) 160void Alarm::setAudioAlarm(const QString &audioFile)
160{ 161{
161 mType = Audio; 162 mType = Audio;
162 mFile = audioFile; 163 mFile = audioFile;
163 mParent->updated(); 164 mParent->updated();
164} 165}
165 166
166void Alarm::setAudioFile(const QString &audioFile) 167void Alarm::setAudioFile(const QString &audioFile)
167{ 168{
168 if (mType == Audio) { 169 if (mType == Audio) {
169 mFile = audioFile; 170 mFile = audioFile;
170 mParent->updated(); 171 mParent->updated();
171 } 172 }
172} 173}
173 174
174QString Alarm::audioFile() const 175QString Alarm::audioFile() const
175{ 176{
176 return (mType == Audio) ? mFile : QString::null; 177 return (mType == Audio) ? mFile : QString::null;
177} 178}
178 179
179void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments) 180void Alarm::setProcedureAlarm(const QString &programFile, const QString &arguments)
180{ 181{
181 mType = Procedure; 182 mType = Procedure;
182 mFile = programFile; 183 mFile = programFile;
183 mDescription = arguments; 184 mDescription = arguments;
184 mParent->updated(); 185 mParent->updated();
185} 186}
186 187
187void Alarm::setProgramFile(const QString &programFile) 188void Alarm::setProgramFile(const QString &programFile)
188{ 189{
189 if (mType == Procedure) { 190 if (mType == Procedure) {
190 mFile = programFile; 191 mFile = programFile;
191 mParent->updated(); 192 mParent->updated();
192 } 193 }
193} 194}
194 195
195QString Alarm::programFile() const 196QString Alarm::programFile() const
196{ 197{
197 return (mType == Procedure) ? mFile : QString::null; 198 return (mType == Procedure) ? mFile : QString::null;
198} 199}
199 200
200void Alarm::setProgramArguments(const QString &arguments) 201void Alarm::setProgramArguments(const QString &arguments)
201{ 202{
202 if (mType == Procedure) { 203 if (mType == Procedure) {
203 mDescription = arguments; 204 mDescription = arguments;
204 mParent->updated(); 205 mParent->updated();
205 } 206 }
206} 207}
207 208
208QString Alarm::programArguments() const 209QString Alarm::programArguments() const
209{ 210{
210 return (mType == Procedure) ? mDescription : QString::null; 211 return (mType == Procedure) ? mDescription : QString::null;
211} 212}
212 213
213void Alarm::setEmailAlarm(const QString &subject, const QString &text, 214void Alarm::setEmailAlarm(const QString &subject, const QString &text,
214 const QValueList<Person> &addressees, const QStringList &attachments) 215 const QValueList<Person> &addressees, const QStringList &attachments)
215{ 216{
216 mType = Email; 217 mType = Email;
217 mMailSubject = subject; 218 mMailSubject = subject;
218 mDescription = text; 219 mDescription = text;
219 mMailAddresses = addressees; 220 mMailAddresses = addressees;
220 mMailAttachFiles = attachments; 221 mMailAttachFiles = attachments;
221 mParent->updated(); 222 mParent->updated();
222} 223}
223 224
224void Alarm::setMailAddress(const Person &mailAddress) 225void Alarm::setMailAddress(const Person &mailAddress)
225{ 226{
226 if (mType == Email) { 227 if (mType == Email) {
227 mMailAddresses.clear(); 228 mMailAddresses.clear();
228 mMailAddresses += mailAddress; 229 mMailAddresses += mailAddress;
229 mParent->updated(); 230 mParent->updated();
230 } 231 }
231} 232}
232 233
233void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses) 234void Alarm::setMailAddresses(const QValueList<Person> &mailAddresses)
234{ 235{
235 if (mType == Email) { 236 if (mType == Email) {
236 mMailAddresses = mailAddresses; 237 mMailAddresses = mailAddresses;
237 mParent->updated(); 238 mParent->updated();
238 } 239 }
239} 240}
240 241
241void Alarm::addMailAddress(const Person &mailAddress) 242void Alarm::addMailAddress(const Person &mailAddress)
242{ 243{
243 if (mType == Email) { 244 if (mType == Email) {
244 mMailAddresses += mailAddress; 245 mMailAddresses += mailAddress;
245 mParent->updated(); 246 mParent->updated();
246 } 247 }
247} 248}
248 249
249QValueList<Person> Alarm::mailAddresses() const 250QValueList<Person> Alarm::mailAddresses() const
250{ 251{
251 return (mType == Email) ? mMailAddresses : QValueList<Person>(); 252 return (mType == Email) ? mMailAddresses : QValueList<Person>();
252} 253}
253 254
254void Alarm::setMailSubject(const QString &mailAlarmSubject) 255void Alarm::setMailSubject(const QString &mailAlarmSubject)
255{ 256{
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}
448 472
449Duration Alarm::endOffset() const 473Duration Alarm::endOffset() const
450{ 474{
451 return (mHasTime || !mEndOffset) ? 0 : mOffset; 475 return (mHasTime || !mEndOffset) ? 0 : mOffset;
452} 476}
453 477
454void Alarm::setParent( Incidence *parent ) 478void Alarm::setParent( Incidence *parent )
455{ 479{
456 mParent = parent; 480 mParent = parent;
457} 481}
diff --git a/libkcal/alarm.h b/libkcal/alarm.h
index 682b626..ac6ea0d 100644
--- a/libkcal/alarm.h
+++ b/libkcal/alarm.h
@@ -1,245 +1,246 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21#ifndef KCAL_ALARM_H 21#ifndef KCAL_ALARM_H
22#define KCAL_ALARM_H 22#define KCAL_ALARM_H
23 23
24#include <qstring.h> 24#include <qstring.h>
25#include <qvaluelist.h> 25#include <qvaluelist.h>
26 26
27#include "customproperties.h" 27#include "customproperties.h"
28#include "duration.h" 28#include "duration.h"
29#include "person.h" 29#include "person.h"
30 30
31namespace KCal { 31namespace KCal {
32 32
33class Incidence; 33class Incidence;
34 34
35/** 35/**
36 This class represents an alarm notification. 36 This class represents an alarm notification.
37*/ 37*/
38class Alarm : public CustomProperties 38class Alarm : public CustomProperties
39{ 39{
40 public: 40 public:
41 enum Type { Invalid, Display, Procedure, Email, Audio }; 41 enum Type { Invalid, Display, Procedure, Email, Audio };
42 typedef QValueList<Alarm *> List; 42 typedef QValueList<Alarm *> List;
43 43
44 /** Construct a new alarm with variables initialized to "sane" values. */ 44 /** Construct a new alarm with variables initialized to "sane" values. */
45 explicit Alarm(Incidence *parent); 45 explicit Alarm(Incidence *parent);
46 /** Destruct Alarm object. */ 46 /** Destruct Alarm object. */
47 ~Alarm(); 47 ~Alarm();
48 48
49 /** Compare this alarm with another one. */ 49 /** Compare this alarm with another one. */
50 bool operator==(const Alarm &) const; 50 bool operator==(const Alarm &) const;
51 bool operator!=(const Alarm &a) const { return !operator==(a); } 51 bool operator!=(const Alarm &a) const { return !operator==(a); }
52 52
53 /** Set the type of the alarm. 53 /** Set the type of the alarm.
54 If the specified type is different from the current type of the alarm, 54 If the specified type is different from the current type of the alarm,
55 the alarm's type-specific properties are initialised to null. 55 the alarm's type-specific properties are initialised to null.
56 @param type type of alarm. 56 @param type type of alarm.
57 */ 57 */
58 void setType(Type type); 58 void setType(Type type);
59 /** Return the type of the alarm */ 59 /** Return the type of the alarm */
60 Type type() const; 60 Type type() const;
61 int offset(); 61 int offset();
62 QString offsetText();
62 /** Set the alarm to be a display alarm. 63 /** Set the alarm to be a display alarm.
63 @param text text to display when the alarm is triggered. 64 @param text text to display when the alarm is triggered.
64 */ 65 */
65 void setDisplayAlarm(const QString &text); 66 void setDisplayAlarm(const QString &text);
66 /** Set the text to be displayed when the alarm is triggered. 67 /** Set the text to be displayed when the alarm is triggered.
67 Ignored if the alarm is not a display alarm. 68 Ignored if the alarm is not a display alarm.
68 */ 69 */
69 void setText(const QString &text); 70 void setText(const QString &text);
70 /** Return the text string that displays when the alarm is triggered. */ 71 /** Return the text string that displays when the alarm is triggered. */
71 QString text() const; 72 QString text() const;
72 73
73 /** Set the alarm to be an audio alarm. 74 /** Set the alarm to be an audio alarm.
74 @param audioFile optional file to play when the alarm is triggered. 75 @param audioFile optional file to play when the alarm is triggered.
75 */ 76 */
76 void setAudioAlarm(const QString &audioFile = QString::null); 77 void setAudioAlarm(const QString &audioFile = QString::null);
77 /** Set the file to play when the audio alarm is triggered. 78 /** Set the file to play when the audio alarm is triggered.
78 Ignored if the alarm is not an audio alarm. 79 Ignored if the alarm is not an audio alarm.
79 */ 80 */
80 void setAudioFile(const QString &audioFile); 81 void setAudioFile(const QString &audioFile);
81 /** Return the name of the audio file for the alarm. 82 /** Return the name of the audio file for the alarm.
82 @return The audio file for the alarm, or QString::null if not an audio alarm. 83 @return The audio file for the alarm, or QString::null if not an audio alarm.
83 */ 84 */
84 QString audioFile() const; 85 QString audioFile() const;
85 86
86 /** Set the alarm to be a procedure alarm. 87 /** Set the alarm to be a procedure alarm.
87 @param programFile program to execute when the alarm is triggered. 88 @param programFile program to execute when the alarm is triggered.
88 @param arguments arguments to supply to programFile. 89 @param arguments arguments to supply to programFile.
89 */ 90 */
90 void setProcedureAlarm(const QString &programFile, const QString &arguments = QString::null); 91 void setProcedureAlarm(const QString &programFile, const QString &arguments = QString::null);
91 /** Set the program file to execute when the alarm is triggered. 92 /** Set the program file to execute when the alarm is triggered.
92 Ignored if the alarm is not a procedure alarm. 93 Ignored if the alarm is not a procedure alarm.
93 */ 94 */
94 void setProgramFile(const QString &programFile); 95 void setProgramFile(const QString &programFile);
95 /** Return the name of the program file to execute when the alarm is triggered. 96 /** Return the name of the program file to execute when the alarm is triggered.
96 @return the program file name, or QString::null if not a procedure alarm. 97 @return the program file name, or QString::null if not a procedure alarm.
97 */ 98 */
98 QString programFile() const; 99 QString programFile() const;
99 /** Set the arguments to the program to execute when the alarm is triggered. 100 /** Set the arguments to the program to execute when the alarm is triggered.
100 Ignored if the alarm is not a procedure alarm. 101 Ignored if the alarm is not a procedure alarm.
101 */ 102 */
102 void setProgramArguments(const QString &arguments); 103 void setProgramArguments(const QString &arguments);
103 /** Return the arguments to the program to run when the alarm is triggered. 104 /** Return the arguments to the program to run when the alarm is triggered.
104 @return the program arguments, or QString::null if not a procedure alarm. 105 @return the program arguments, or QString::null if not a procedure alarm.
105 */ 106 */
106 QString programArguments() const; 107 QString programArguments() const;
107 108
108 /** Set the alarm to be an email alarm. 109 /** Set the alarm to be an email alarm.
109 @param subject subject line of email. 110 @param subject subject line of email.
110 @param text body of email. 111 @param text body of email.
111 @param addressees email addresses of recipient(s). 112 @param addressees email addresses of recipient(s).
112 @param attachments optional names of files to attach to the email. 113 @param attachments optional names of files to attach to the email.
113 */ 114 */
114 void setEmailAlarm(const QString &subject, const QString &text, const QValueList<Person> &addressees, 115 void setEmailAlarm(const QString &subject, const QString &text, const QValueList<Person> &addressees,
115 const QStringList &attachments = QStringList()); 116 const QStringList &attachments = QStringList());
116 117
117 /** Send mail to this address when the alarm is triggered. 118 /** Send mail to this address when the alarm is triggered.
118 Ignored if the alarm is not an email alarm. 119 Ignored if the alarm is not an email alarm.
119 */ 120 */
120 void setMailAddress(const Person &mailAlarmAddress); 121 void setMailAddress(const Person &mailAlarmAddress);
121 /** Send mail to these addresses when the alarm is triggered. 122 /** Send mail to these addresses when the alarm is triggered.
122 Ignored if the alarm is not an email alarm. 123 Ignored if the alarm is not an email alarm.
123 */ 124 */
124 void setMailAddresses(const QValueList<Person> &mailAlarmAddresses); 125 void setMailAddresses(const QValueList<Person> &mailAlarmAddresses);
125 /** Add this address to the list of addresses to send mail to when the alarm is triggered. 126 /** Add this address to the list of addresses to send mail to when the alarm is triggered.
126 Ignored if the alarm is not an email alarm. 127 Ignored if the alarm is not an email alarm.
127 */ 128 */
128 void addMailAddress(const Person &mailAlarmAddress); 129 void addMailAddress(const Person &mailAlarmAddress);
129 /** return the addresses to send mail to when an alarm goes off */ 130 /** return the addresses to send mail to when an alarm goes off */
130 QValueList<Person> mailAddresses() const; 131 QValueList<Person> mailAddresses() const;
131 132
132 /** Set the subject line of the mail. 133 /** Set the subject line of the mail.
133 Ignored if the alarm is not an email alarm. 134 Ignored if the alarm is not an email alarm.
134 */ 135 */
135 void setMailSubject(const QString &mailAlarmSubject); 136 void setMailSubject(const QString &mailAlarmSubject);
136 /** return the subject line of the mail */ 137 /** return the subject line of the mail */
137 QString mailSubject() const; 138 QString mailSubject() const;
138 139
139 /** Attach this filename to the email. 140 /** Attach this filename to the email.
140 Ignored if the alarm is not an email alarm. 141 Ignored if the alarm is not an email alarm.
141 */ 142 */
142 void setMailAttachment(const QString &mailAttachFile); 143 void setMailAttachment(const QString &mailAttachFile);
143 /** Attach these filenames to the email. 144 /** Attach these filenames to the email.
144 Ignored if the alarm is not an email alarm. 145 Ignored if the alarm is not an email alarm.
145 */ 146 */
146 void setMailAttachments(const QStringList &mailAttachFiles); 147 void setMailAttachments(const QStringList &mailAttachFiles);
147 /** Add this filename to the list of files to attach to the email. 148 /** Add this filename to the list of files to attach to the email.
148 Ignored if the alarm is not an email alarm. 149 Ignored if the alarm is not an email alarm.
149 */ 150 */
150 void addMailAttachment(const QString &mailAttachFile); 151 void addMailAttachment(const QString &mailAttachFile);
151 /** return the filenames to attach to the email */ 152 /** return the filenames to attach to the email */
152 QStringList mailAttachments() const; 153 QStringList mailAttachments() const;
153 154
154 /** Set the email body text. 155 /** Set the email body text.
155 Ignored if the alarm is not an email alarm. 156 Ignored if the alarm is not an email alarm.
156 */ 157 */
157 void setMailText(const QString &text); 158 void setMailText(const QString &text);
158 /** Return the email body text. 159 /** Return the email body text.
159 @return the body text, or QString::null if not an email alarm. 160 @return the body text, or QString::null if not an email alarm.
160 */ 161 */
161 QString mailText() const; 162 QString mailText() const;
162 163
163 /** set the time to trigger an alarm */ 164 /** set the time to trigger an alarm */
164 void setTime(const QDateTime &alarmTime); 165 void setTime(const QDateTime &alarmTime);
165 /** return the date/time when an alarm goes off */ 166 /** return the date/time when an alarm goes off */
166 QDateTime time() const; 167 QDateTime time() const;
167 /** Return true, if the alarm has an explicit date/time. */ 168 /** Return true, if the alarm has an explicit date/time. */
168 bool hasTime() const; 169 bool hasTime() const;
169 170
170 /** Set offset of alarm in time relative to the start of the event. */ 171 /** Set offset of alarm in time relative to the start of the event. */
171 void setStartOffset(const Duration &); 172 void setStartOffset(const Duration &);
172 /** Return offset of alarm in time relative to the start of the event. 173 /** Return offset of alarm in time relative to the start of the event.
173 * If the alarm's time is not defined in terms of an offset relative 174 * If the alarm's time is not defined in terms of an offset relative
174 * to the start of the event, returns zero. 175 * to the start of the event, returns zero.
175 */ 176 */
176 Duration startOffset() const; 177 Duration startOffset() const;
177 /** Return whether the alarm is defined in terms of an offset relative 178 /** Return whether the alarm is defined in terms of an offset relative
178 * to the start of the event. 179 * to the start of the event.
179 */ 180 */
180 bool hasStartOffset() const; 181 bool hasStartOffset() const;
181 182
182 /** Set offset of alarm in time relative to the end of the event. */ 183 /** Set offset of alarm in time relative to the end of the event. */
183 void setEndOffset(const Duration &); 184 void setEndOffset(const Duration &);
184 /** Return offset of alarm in time relative to the end of the event. 185 /** Return offset of alarm in time relative to the end of the event.
185 * If the alarm's time is not defined in terms of an offset relative 186 * If the alarm's time is not defined in terms of an offset relative
186 * to the end of the event, returns zero. 187 * to the end of the event, returns zero.
187 */ 188 */
188 Duration endOffset() const; 189 Duration endOffset() const;
189 /** Return whether the alarm is defined in terms of an offset relative 190 /** Return whether the alarm is defined in terms of an offset relative
190 * to the end of the event. 191 * to the end of the event.
191 */ 192 */
192 bool hasEndOffset() const; 193 bool hasEndOffset() const;
193 194
194 /** Set the interval between snoozes for the alarm. 195 /** Set the interval between snoozes for the alarm.
195 @param snoozeTime the time in minutes between snoozes. 196 @param snoozeTime the time in minutes between snoozes.
196 */ 197 */
197 void setSnoozeTime(int alarmSnoozeTime); 198 void setSnoozeTime(int alarmSnoozeTime);
198 /** Get how long the alarm snooze interval is. 199 /** Get how long the alarm snooze interval is.
199 @return the number of minutes between snoozes. 200 @return the number of minutes between snoozes.
200 */ 201 */
201 int snoozeTime() const; 202 int snoozeTime() const;
202 203
203 /** set how many times an alarm is to repeat itself (w/snoozes) */ 204 /** set how many times an alarm is to repeat itself (w/snoozes) */
204 void setRepeatCount(int alarmRepeatCount); 205 void setRepeatCount(int alarmRepeatCount);
205 /** get how many times an alarm repeats */ 206 /** get how many times an alarm repeats */
206 int repeatCount() const; 207 int repeatCount() const;
207 208
208 /** toggles the value of alarm to be either on or off. 209 /** toggles the value of alarm to be either on or off.
209 set's the alarm time to be x minutes before dtStart time. */ 210 set's the alarm time to be x minutes before dtStart time. */
210 void toggleAlarm(); 211 void toggleAlarm();
211 212
212 /** set the alarm enabled status */ 213 /** set the alarm enabled status */
213 void setEnabled(bool enable); 214 void setEnabled(bool enable);
214 /** get the alarm enabled status */ 215 /** get the alarm enabled status */
215 bool enabled() const; 216 bool enabled() const;
216 217
217 /** Set the alarm's parent incidence */ 218 /** Set the alarm's parent incidence */
218 void setParent( Incidence * ); 219 void setParent( Incidence * );
219 /** get the alarm's parent incidence */ 220 /** get the alarm's parent incidence */
220 Incidence *parent() const { return mParent; } 221 Incidence *parent() const { return mParent; }
221 222
222 private: 223 private:
223 Incidence *mParent; // the incidence which this alarm belongs to 224 Incidence *mParent; // the incidence which this alarm belongs to
224 Type mType; // type of alarm 225 Type mType; // type of alarm
225 QString mDescription; // text to display/email body/procedure arguments 226 QString mDescription; // text to display/email body/procedure arguments
226 QString mFile; // procedure program to run/optional audio file to play 227 QString mFile; // procedure program to run/optional audio file to play
227 QStringList mMailAttachFiles; // filenames to attach to email 228 QStringList mMailAttachFiles; // filenames to attach to email
228 QValueList<Person> mMailAddresses; // who to mail for reminder 229 QValueList<Person> mMailAddresses; // who to mail for reminder
229 QString mMailSubject; // subject of email 230 QString mMailSubject; // subject of email
230 231
231 int mAlarmSnoozeTime; // number of minutes after alarm to 232 int mAlarmSnoozeTime; // number of minutes after alarm to
232 // snooze before ringing again 233 // snooze before ringing again
233 int mAlarmRepeatCount; // number of times for alarm to repeat 234 int mAlarmRepeatCount; // number of times for alarm to repeat
234 // after the initial time 235 // after the initial time
235 236
236 QDateTime mAlarmTime; // time at which to trigger the alarm 237 QDateTime mAlarmTime; // time at which to trigger the alarm
237 Duration mOffset; // time relative to incidence DTSTART to trigger the alarm 238 Duration mOffset; // time relative to incidence DTSTART to trigger the alarm
238 bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART 239 bool mEndOffset; // if true, mOffset relates to DTEND, not DTSTART
239 bool mHasTime; // use mAlarmTime, not mOffset 240 bool mHasTime; // use mAlarmTime, not mOffset
240 bool mAlarmEnabled; 241 bool mAlarmEnabled;
241}; 242};
242 243
243} 244}
244 245
245#endif 246#endif
diff --git a/libkcal/kincidenceformatter.cpp b/libkcal/kincidenceformatter.cpp
index e506a96..d67ad52 100644
--- a/libkcal/kincidenceformatter.cpp
+++ b/libkcal/kincidenceformatter.cpp
@@ -1,393 +1,403 @@
1#include "kincidenceformatter.h" 1#include "kincidenceformatter.h"
2#include <kstaticdeleter.h> 2#include <kstaticdeleter.h>
3#include <kglobal.h> 3#include <kglobal.h>
4#include <klocale.h> 4#include <klocale.h>
5#ifdef DEKTOP_VERSION 5#ifdef DEKTOP_VERSION
6#include <kabc/stdaddressbook.h> 6#include <kabc/stdaddressbook.h>
7#define size count 7#define size count
8#endif 8#endif
9 9
10KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; 10KIncidenceFormatter* KIncidenceFormatter::mInstance = 0;
11static KStaticDeleter<KIncidenceFormatter> insd; 11static KStaticDeleter<KIncidenceFormatter> insd;
12 12
13QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified ) 13QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified )
14{ 14{
15// #ifndef QT_NO_INPUTDIALOG 15// #ifndef QT_NO_INPUTDIALOG
16// return QInputDialog::getItem( caption, label, items, current, editable ); 16// return QInputDialog::getItem( caption, label, items, current, editable );
17// #else 17// #else
18// return QString::null; 18// return QString::null;
19// #endif 19// #endif
20 mDetails = details; 20 mDetails = details;
21 mCreated = created ; 21 mCreated = created ;
22 mModified = modified; 22 mModified = modified;
23 mText = ""; 23 mText = "";
24 if ( inc->type() == "Event" ) 24 if ( inc->type() == "Event" )
25 setEvent((Event *) inc ); 25 setEvent((Event *) inc );
26 else if ( inc->type() == "Todo" ) 26 else if ( inc->type() == "Todo" )
27 setTodo((Todo *) inc ); 27 setTodo((Todo *) inc );
28 return mText; 28 return mText;
29} 29}
30 30
31KIncidenceFormatter* KIncidenceFormatter::instance() 31KIncidenceFormatter* KIncidenceFormatter::instance()
32{ 32{
33 if (!mInstance) { 33 if (!mInstance) {
34 mInstance = insd.setObject(new KIncidenceFormatter()); 34 mInstance = insd.setObject(new KIncidenceFormatter());
35 } 35 }
36 return mInstance; 36 return mInstance;
37} 37}
38KIncidenceFormatter::~KIncidenceFormatter() 38KIncidenceFormatter::~KIncidenceFormatter()
39{ 39{
40 if (mInstance == this) 40 if (mInstance == this)
41 mInstance = insd.setObject(0); 41 mInstance = insd.setObject(0);
42 //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); 42 //qDebug("KIncidenceFormatter::~KIncidenceFormatter ");
43} 43}
44KIncidenceFormatter::KIncidenceFormatter() 44KIncidenceFormatter::KIncidenceFormatter()
45{ 45{
46 mColorMode = 0; 46 mColorMode = 0;
47} 47}
48void KIncidenceFormatter::setEvent(Event *event) 48void KIncidenceFormatter::setEvent(Event *event)
49{ 49{
50 int mode = 0; 50 int mode = 0;
51 mCurrentIncidence = event; 51 mCurrentIncidence = event;
52 bool shortDate = true; 52 bool shortDate = true;
53 if ( mode == 0 ) { 53 if ( mode == 0 ) {
54 addTag("h3",deTag(event->summary())); 54 addTag("h3",deTag(event->summary()));
55 } 55 }
56 else { 56 else {
57 if ( mColorMode == 1 ) { 57 if ( mColorMode == 1 ) {
58 mText +="<font color=\"#00A000\">"; 58 mText +="<font color=\"#00A000\">";
59 } 59 }
60 if ( mColorMode == 2 ) { 60 if ( mColorMode == 2 ) {
61 mText +="<font color=\"#C00000\">"; 61 mText +="<font color=\"#C00000\">";
62 } 62 }
63 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; 63 // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>";
64 if ( mode == 1 ) { 64 if ( mode == 1 ) {
65 addTag("h2",i18n( "Local: " ) +deTag(event->summary())); 65 addTag("h2",i18n( "Local: " ) +deTag(event->summary()));
66 } else { 66 } else {
67 addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); 67 addTag("h2",i18n( "Remote: " ) +deTag(event->summary()));
68 } 68 }
69 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 69 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
70 if ( mColorMode ) 70 if ( mColorMode )
71 mText += "</font>"; 71 mText += "</font>";
72 } 72 }
73 if (event->cancelled ()) { 73 if (event->cancelled ()) {
74 mText +="<font color=\"#B00000\">"; 74 mText +="<font color=\"#B00000\">";
75 addTag("i",i18n("This event has been cancelled!")); 75 addTag("i",i18n("This event has been cancelled!"));
76 mText.append("<br>"); 76 mText.append("<br>");
77 mText += "</font>"; 77 mText += "</font>";
78 } 78 }
79 if (!event->location().isEmpty()) { 79 if (!event->location().isEmpty()) {
80 addTag("b",i18n("Location: ")); 80 addTag("b",i18n("Location: "));
81 mText.append(deTag(event->location())+"<br>"); 81 mText.append(deTag(event->location())+"<br>");
82 } 82 }
83 if (event->doesFloat()) { 83 if (event->doesFloat()) {
84 if (event->isMultiDay()) { 84 if (event->isMultiDay()) {
85 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") 85 mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>")
86 .arg(event->dtStartDateStr(shortDate)) 86 .arg(event->dtStartDateStr(shortDate))
87 .arg(event->dtEndDateStr(shortDate))); 87 .arg(event->dtEndDateStr(shortDate)));
88 } else { 88 } else {
89 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); 89 mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate )));
90 } 90 }
91 } else { 91 } else {
92 if (event->isMultiDay()) { 92 if (event->isMultiDay()) {
93 mText.append(i18n("<p><b>From:</b> %1</p> ") 93 mText.append(i18n("<p><b>From:</b> %1</p> ")
94 .arg(event->dtStartStr( shortDate))); 94 .arg(event->dtStartStr( shortDate)));
95 mText.append(i18n("<p><b>To:</b> %1</p>") 95 mText.append(i18n("<p><b>To:</b> %1</p>")
96 .arg(event->dtEndStr(shortDate))); 96 .arg(event->dtEndStr(shortDate)));
97 } else { 97 } else {
98 mText.append(i18n("<p><b>On:</b> %1</p> ") 98 mText.append(i18n("<p><b>On:</b> %1</p> ")
99 .arg(event->dtStartDateStr( shortDate ))); 99 .arg(event->dtStartDateStr( shortDate )));
100 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") 100 mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>")
101 .arg(event->dtStartTimeStr()) 101 .arg(event->dtStartTimeStr())
102 .arg(event->dtEndTimeStr())); 102 .arg(event->dtEndTimeStr()));
103 } 103 }
104 } 104 }
105 105
106 if (event->recurrence()->doesRecur()) { 106 if (event->recurrence()->doesRecur()) {
107 107
108 QString recurText = event->recurrence()->recurrenceText(); 108 QString recurText = event->recurrence()->recurrenceText();
109 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); 109 addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>");
110 110
111 bool ok; 111 bool ok;
112 QDate start = QDate::currentDate(); 112 QDate start = QDate::currentDate();
113 QDateTime next; 113 QDateTime next;
114 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); 114 next = event->getNextOccurence( QDateTime::currentDateTime() , &ok );
115 if ( ok ) { 115 if ( ok ) {
116 addTag("p",i18n("<b>Next recurrence is on:</b>") ); 116 addTag("p",i18n("<b>Next recurrence is on:</b>") );
117 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); 117 addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate ));
118 118
119 } else { 119 } else {
120 bool last; 120 bool last;
121 QDate nextd; 121 QDate nextd;
122 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); 122 nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last );
123 if ( last ) { 123 if ( last ) {
124 addTag("p",i18n("<b>Last recurrence was on:</b>") ); 124 addTag("p",i18n("<b>Last recurrence was on:</b>") );
125 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); 125 addTag("p", KGlobal::locale()->formatDate( nextd, shortDate ));
126 } 126 }
127 } 127 }
128 } 128 }
129 129
130 130
131 if (event->isAlarmEnabled()) { 131 if (event->isAlarmEnabled()) {
132 Alarm *alarm =event->alarms().first() ; 132 Alarm *alarm =event->alarms().first() ;
133 QDateTime t = alarm->time(); 133 QDateTime t = alarm->time();
134 int min = t.secsTo( event->dtStart() )/60; 134 QString s =i18n("( %1 before )").arg( alarm->offsetText() );
135 QString s =i18n("(%1 min before)").arg( min );
136 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); 135 addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate ));
137 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); 136 //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
138 //addTag("p",s); 137 //addTag("p",s);
139 } 138 }
140 139
140
141
141 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); 142 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
142 // mText.append(event->secrecyStr()+"<br>"); 143 // mText.append(event->secrecyStr()+"<br>");
143 formatCategories(event); 144 formatCategories(event);
144 if ( mDetails ) { 145 if ( mDetails ) {
145 if (!event->description().isEmpty()) { 146 if (!event->description().isEmpty()) {
146 addTag("p",i18n("<b>Details: </b>")); 147 addTag("p",i18n("<b>Details: </b>"));
147 addTag("p",deTag(event->description())); 148 addTag("p",deTag(event->description()));
148 } 149 }
149 } 150 }
150 151
151 formatReadOnly(event); 152 formatReadOnly(event);
152 formatAttendees(event); 153 formatAttendees(event);
153 154
154 if ( mCreated ) { 155 if ( mCreated ) {
155 addTag("p",i18n("<b>Created: ") +" </b>"); 156 addTag("p",i18n("<b>Created: ") +" </b>");
156 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); 157 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate ));
157 158
158 } 159 }
159 if ( mModified ) { 160 if ( mModified ) {
160 addTag("p",i18n("<b>Last modified: ") +" </b>"); 161 addTag("p",i18n("<b>Last modified: ") +" </b>");
161 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 162 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
162 163
163 } 164 }
164 165
165} 166}
166 167
167void KIncidenceFormatter::setTodo(Todo *event ) 168void KIncidenceFormatter::setTodo(Todo *event )
168{ 169{
169 int mode = 0; 170 int mode = 0;
170 mCurrentIncidence = event; 171 mCurrentIncidence = event;
171 bool shortDate = true; 172 bool shortDate = true;
172 if (mode == 0 ) 173 if (mode == 0 )
173 addTag("h3",deTag(event->summary())); 174 addTag("h3",deTag(event->summary()));
174 else { 175 else {
175 if ( mColorMode == 1 ) { 176 if ( mColorMode == 1 ) {
176 mText +="<font color=\"#00A000\">"; 177 mText +="<font color=\"#00A000\">";
177 } 178 }
178 if ( mColorMode == 2 ) { 179 if ( mColorMode == 2 ) {
179 mText +="<font color=\"#B00000\">"; 180 mText +="<font color=\"#B00000\">";
180 } 181 }
181 if ( mode == 1 ) { 182 if ( mode == 1 ) {
182 addTag("h2",i18n( "Local: " ) +deTag(event->summary())); 183 addTag("h2",i18n( "Local: " ) +deTag(event->summary()));
183 } else { 184 } else {
184 addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); 185 addTag("h2",i18n( "Remote: " ) +deTag(event->summary()));
185 } 186 }
186 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); 187 addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) );
187 if ( mColorMode ) 188 if ( mColorMode )
188 mText += "</font>"; 189 mText += "</font>";
189 } 190 }
190 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { 191 if ( event->percentComplete() == 100 && event->hasCompletedDate() ) {
191 mText +="<font color=\"#B00000\">"; 192 mText +="<font color=\"#B00000\">";
192 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) ); 193 addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) );
193 mText += "</font>"; 194 mText += "</font>";
194 } else { 195 } else {
195 mText.append(i18n("<p><i>%1 % completed</i></p>") 196 mText.append(i18n("<p><i>%1 % completed</i></p>")
196 .arg(event->percentComplete())); 197 .arg(event->percentComplete()));
197 } 198 }
198 if (event->cancelled ()) { 199 if (event->cancelled ()) {
199 mText +="<font color=\"#B00000\">"; 200 mText +="<font color=\"#B00000\">";
200 addTag("i",i18n("This todo has been cancelled!")); 201 addTag("i",i18n("This todo has been cancelled!"));
201 mText.append("<br>"); 202 mText.append("<br>");
202 mText += "</font>"; 203 mText += "</font>";
203 } 204 }
204 205
205 if (!event->location().isEmpty()) { 206 if (!event->location().isEmpty()) {
206 addTag("b",i18n("Location: ")); 207 addTag("b",i18n("Location: "));
207 mText.append(deTag(event->location())+"<br>"); 208 mText.append(deTag(event->location())+"<br>");
208 } 209 }
209 210
210 if (event->recurrence()->doesRecur()) { 211 if (event->recurrence()->doesRecur()) {
211 212
212 QString recurText = event->recurrence()->recurrenceText(); 213 QString recurText = event->recurrence()->recurrenceText();
213 addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>"); 214 addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>");
214 } 215 }
215 216
216 if (event->hasStartDate()) { 217 if (event->hasStartDate()) {
217 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate))); 218 mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate)));
218 } 219 }
219 220
220 221
221 if (event->hasDueDate()) { 222 if (event->hasDueDate()) {
222 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); 223 mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate)));
223 } 224 }
224 mText.append(i18n("<p><b>Priority:</b> %2</p>") 225 mText.append(i18n("<p><b>Priority:</b> %2</p>")
225 .arg(QString::number(event->priority()))); 226 .arg(QString::number(event->priority())));
226 227
228 if (event->isAlarmEnabled()) {
229 Alarm *alarm =event->alarms().first() ;
230 QDateTime t = alarm->time();
231 QString s =i18n("( %1 before )").arg( alarm->offsetText() );
232 addTag("p",i18n("<b>Alarm on: ") + s +" </b>");
233 addTag("p", KGlobal::locale()->formatDateTime( t, shortDate ));
234 //addTag("p",s);
235 }
236
227 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); 237 addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() );
228 formatCategories(event); 238 formatCategories(event);
229 if ( mDetails ) { 239 if ( mDetails ) {
230 if (!event->description().isEmpty()) { 240 if (!event->description().isEmpty()) {
231 addTag("p",i18n("<b>Details: </b>")); 241 addTag("p",i18n("<b>Details: </b>"));
232 addTag("p",deTag(event->description())); 242 addTag("p",deTag(event->description()));
233 } 243 }
234 } 244 }
235 formatReadOnly(event); 245 formatReadOnly(event);
236 formatAttendees(event); 246 formatAttendees(event);
237 if ( mCreated ) { 247 if ( mCreated ) {
238 addTag("p",i18n("<b>Created: ") +" </b>"); 248 addTag("p",i18n("<b>Created: ") +" </b>");
239 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); 249 addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate ));
240 250
241 } 251 }
242 if ( mModified ) { 252 if ( mModified ) {
243 addTag("p",i18n("<b>Last modified: ") +" </b>"); 253 addTag("p",i18n("<b>Last modified: ") +" </b>");
244 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); 254 addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate ));
245 255
246 } 256 }
247} 257}
248 258
249void KIncidenceFormatter::setJournal(Journal* ) 259void KIncidenceFormatter::setJournal(Journal* )
250{ 260{
251 261
252} 262}
253 263
254void KIncidenceFormatter::formatCategories(Incidence *event) 264void KIncidenceFormatter::formatCategories(Incidence *event)
255{ 265{
256 if (!event->categoriesStr().isEmpty()) { 266 if (!event->categoriesStr().isEmpty()) {
257 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStr() ); 267 addTag("p",i18n("<b>Categories: </b>")+event->categoriesStr() );
258 //mText.append(event->categoriesStr()); 268 //mText.append(event->categoriesStr());
259 } 269 }
260} 270}
261void KIncidenceFormatter::addTag(const QString & tag,const QString & text) 271void KIncidenceFormatter::addTag(const QString & tag,const QString & text)
262{ 272{
263 int number=text.contains("\n"); 273 int number=text.contains("\n");
264 QString str = "<" + tag + ">"; 274 QString str = "<" + tag + ">";
265 QString tmpText=text; 275 QString tmpText=text;
266 QString tmpStr=str; 276 QString tmpStr=str;
267 if(number !=-1) 277 if(number !=-1)
268 { 278 {
269 if (number > 0) { 279 if (number > 0) {
270 int pos=0; 280 int pos=0;
271 QString tmp; 281 QString tmp;
272 for(int i=0;i<=number;i++) { 282 for(int i=0;i<=number;i++) {
273 pos=tmpText.find("\n"); 283 pos=tmpText.find("\n");
274 tmp=tmpText.left(pos); 284 tmp=tmpText.left(pos);
275 tmpText=tmpText.right(tmpText.length()-pos-1); 285 tmpText=tmpText.right(tmpText.length()-pos-1);
276 tmpStr+=tmp+"<br>"; 286 tmpStr+=tmp+"<br>";
277 } 287 }
278 } 288 }
279 else tmpStr += tmpText; 289 else tmpStr += tmpText;
280 tmpStr+="</" + tag + ">"; 290 tmpStr+="</" + tag + ">";
281 mText.append(tmpStr); 291 mText.append(tmpStr);
282 } 292 }
283 else 293 else
284 { 294 {
285 str += text + "</" + tag + ">"; 295 str += text + "</" + tag + ">";
286 mText.append(str); 296 mText.append(str);
287 } 297 }
288} 298}
289 299
290void KIncidenceFormatter::formatAttendees(Incidence *event) 300void KIncidenceFormatter::formatAttendees(Incidence *event)
291{ 301{
292 QPtrList<Attendee> attendees = event->attendees(); 302 QPtrList<Attendee> attendees = event->attendees();
293 if (attendees.count()) { 303 if (attendees.count()) {
294 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); 304 QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small);
295 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); 305 QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small);
296 addTag("h3",i18n("Organizer")); 306 addTag("h3",i18n("Organizer"));
297 mText.append("<ul><li>"); 307 mText.append("<ul><li>");
298#if 0 308#if 0
299 //ndef KORG_NOKABC 309 //ndef KORG_NOKABC
300 310
301 KABC::AddressBook *add_book = KABC::StdAddressBook::self(); 311 KABC::AddressBook *add_book = KABC::StdAddressBook::self();
302 KABC::Addressee::List addressList; 312 KABC::Addressee::List addressList;
303 addressList = add_book->findByEmail(event->organizer()); 313 addressList = add_book->findByEmail(event->organizer());
304 KABC::Addressee o = addressList.first(); 314 KABC::Addressee o = addressList.first();
305 if (!o.isEmpty() && addressList.size()<2) { 315 if (!o.isEmpty() && addressList.size()<2) {
306 mText += "<a href=\"uid:" + o.uid() + "\">"; 316 mText += "<a href=\"uid:" + o.uid() + "\">";
307 mText += o.formattedName(); 317 mText += o.formattedName();
308 mText += "</a>\n"; 318 mText += "</a>\n";
309 } else { 319 } else {
310 mText.append(event->organizer()); 320 mText.append(event->organizer());
311 } 321 }
312#else 322#else
313 mText.append(event->organizer()); 323 mText.append(event->organizer());
314#endif 324#endif
315 if (iconPath) { 325 if (iconPath) {
316 mText += " <a href=\"mailto:" + event->organizer() + "\">"; 326 mText += " <a href=\"mailto:" + event->organizer() + "\">";
317 mText += "<IMG src=\"" + iconPath + "\">"; 327 mText += "<IMG src=\"" + iconPath + "\">";
318 mText += "</a>\n"; 328 mText += "</a>\n";
319 } 329 }
320 mText.append("</li></ul>"); 330 mText.append("</li></ul>");
321 331
322 addTag("h3",i18n("Attendees")); 332 addTag("h3",i18n("Attendees"));
323 Attendee *a; 333 Attendee *a;
324 mText.append("<ul>"); 334 mText.append("<ul>");
325 for(a=attendees.first();a;a=attendees.next()) { 335 for(a=attendees.first();a;a=attendees.next()) {
326#if 0 336#if 0
327//ndef KORG_NOKABC 337//ndef KORG_NOKABC
328 if (a->name().isEmpty()) { 338 if (a->name().isEmpty()) {
329 addressList = add_book->findByEmail(a->email()); 339 addressList = add_book->findByEmail(a->email());
330 KABC::Addressee o = addressList.first(); 340 KABC::Addressee o = addressList.first();
331 if (!o.isEmpty() && addressList.size()<2) { 341 if (!o.isEmpty() && addressList.size()<2) {
332 mText += "<a href=\"uid:" + o.uid() + "\">"; 342 mText += "<a href=\"uid:" + o.uid() + "\">";
333 mText += o.formattedName(); 343 mText += o.formattedName();
334 mText += "</a>\n"; 344 mText += "</a>\n";
335 } else { 345 } else {
336 mText += "<li>"; 346 mText += "<li>";
337 mText.append(a->email()); 347 mText.append(a->email());
338 mText += "\n"; 348 mText += "\n";
339 } 349 }
340 } else { 350 } else {
341 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 351 mText += "<li><a href=\"uid:" + a->uid() + "\">";
342 if (!a->name().isEmpty()) mText += a->name(); 352 if (!a->name().isEmpty()) mText += a->name();
343 else mText += a->email(); 353 else mText += a->email();
344 mText += "</a>\n"; 354 mText += "</a>\n";
345 } 355 }
346#else 356#else
347 //qDebug("nokabc "); 357 //qDebug("nokabc ");
348 mText += "<li><a href=\"uid:" + a->uid() + "\">"; 358 mText += "<li><a href=\"uid:" + a->uid() + "\">";
349 if (!a->name().isEmpty()) mText += a->name(); 359 if (!a->name().isEmpty()) mText += a->name();
350 else mText += a->email(); 360 else mText += a->email();
351 mText += "</a>\n"; 361 mText += "</a>\n";
352#endif 362#endif
353 363
354 if (!a->email().isEmpty()) { 364 if (!a->email().isEmpty()) {
355 if (iconPath) { 365 if (iconPath) {
356 mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; 366 mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">";
357 if ( a->RSVP() ) 367 if ( a->RSVP() )
358 mText += "<IMG src=\"" + iconPath + "\">"; 368 mText += "<IMG src=\"" + iconPath + "\">";
359 else 369 else
360 mText += "<IMG src=\"" + NOiconPath + "\">"; 370 mText += "<IMG src=\"" + NOiconPath + "\">";
361 mText += "</a>\n"; 371 mText += "</a>\n";
362 } 372 }
363 } 373 }
364 if (a->status() != Attendee::NeedsAction ) 374 if (a->status() != Attendee::NeedsAction )
365 mText +="[" + a->statusStr() + "] "; 375 mText +="[" + a->statusStr() + "] ";
366 if (a->role() == Attendee::Chair ) 376 if (a->role() == Attendee::Chair )
367 mText +="(" + a->roleStr().left(1) + ".)"; 377 mText +="(" + a->roleStr().left(1) + ".)";
368 } 378 }
369 mText.append("</li></ul>"); 379 mText.append("</li></ul>");
370 } 380 }
371} 381}
372 382
373void KIncidenceFormatter::formatReadOnly(Incidence *event) 383void KIncidenceFormatter::formatReadOnly(Incidence *event)
374{ 384{
375 if (event->isReadOnly()) { 385 if (event->isReadOnly()) {
376 addTag("p","<em>(" + i18n("read-only") + ")</em>"); 386 addTag("p","<em>(" + i18n("read-only") + ")</em>");
377 } 387 }
378} 388}
379QString KIncidenceFormatter::deTag(QString text) 389QString KIncidenceFormatter::deTag(QString text)
380{ 390{
381#if QT_VERSION >= 0x030000 391#if QT_VERSION >= 0x030000
382 text.replace( '<' , "&lt;" ); 392 text.replace( '<' , "&lt;" );
383 text.replace( '>' , "&gt;" ); 393 text.replace( '>' , "&gt;" );
384#else 394#else
385 if ( text.find ('<') >= 0 ) { 395 if ( text.find ('<') >= 0 ) {
386 text.replace( QRegExp("<") , "&lt;" ); 396 text.replace( QRegExp("<") , "&lt;" );
387 } 397 }
388 if ( text.find ('>') >= 0 ) { 398 if ( text.find ('>') >= 0 ) {
389 text.replace( QRegExp(">") , "&gt;" ); 399 text.replace( QRegExp(">") , "&gt;" );
390 } 400 }
391#endif 401#endif
392 return text; 402 return text;
393} 403}