29 #include <tdelocale.h>
32 #include "alarmtext.h"
36 #include "preferences.h"
37 #include "alarmcalendar.h"
42 const TQCString APPNAME(
"KALARM");
47 TQString KAEvent::calVersionString() {
return TQString::fromLatin1(
"1.5.0"); }
48 int KAEvent::calVersion() {
return KAlarm::Version(1,5,0); }
53 static const TQCString NEXT_RECUR_PROPERTY(
"NEXTRECUR");
54 static const TQCString REPEAT_PROPERTY(
"REPEAT");
56 static const TQCString TYPE_PROPERTY(
"TYPE");
57 static const TQString FILE_TYPE = TQString::fromLatin1(
"FILE");
58 static const TQString AT_LOGIN_TYPE = TQString::fromLatin1(
"LOGIN");
59 static const TQString REMINDER_TYPE = TQString::fromLatin1(
"REMINDER");
60 static const TQString REMINDER_ONCE_TYPE = TQString::fromLatin1(
"REMINDER_ONCE");
61 static const TQString ARCHIVE_REMINDER_ONCE_TYPE = TQString::fromLatin1(
"ONCE");
62 static const TQString TIME_DEFERRAL_TYPE = TQString::fromLatin1(
"DEFERRAL");
63 static const TQString DATE_DEFERRAL_TYPE = TQString::fromLatin1(
"DATE_DEFERRAL");
64 static const TQString DISPLAYING_TYPE = TQString::fromLatin1(
"DISPLAYING");
65 static const TQString PRE_ACTION_TYPE = TQString::fromLatin1(
"PRE");
66 static const TQString POST_ACTION_TYPE = TQString::fromLatin1(
"POST");
67 static const TQCString NEXT_REPEAT_PROPERTY(
"NEXTREPEAT");
69 static const TQCString FONT_COLOUR_PROPERTY(
"FONTCOLOR");
71 static const TQCString EMAIL_ID_PROPERTY(
"EMAILID");
73 static const TQCString VOLUME_PROPERTY(
"VOLUME");
74 static const TQCString SPEAK_PROPERTY(
"SPEAK");
77 static const TQString DATE_ONLY_CATEGORY = TQString::fromLatin1(
"DATE");
78 static const TQString EMAIL_BCC_CATEGORY = TQString::fromLatin1(
"BCC");
79 static const TQString CONFIRM_ACK_CATEGORY = TQString::fromLatin1(
"ACKCONF");
80 static const TQString LATE_CANCEL_CATEGORY = TQString::fromLatin1(
"LATECANCEL;");
81 static const TQString AUTO_CLOSE_CATEGORY = TQString::fromLatin1(
"LATECLOSE;");
82 static const TQString TEMPL_AFTER_TIME_CATEGORY = TQString::fromLatin1(
"TMPLAFTTIME;");
83 static const TQString KMAIL_SERNUM_CATEGORY = TQString::fromLatin1(
"KMAIL:");
84 static const TQString KORGANIZER_CATEGORY = TQString::fromLatin1(
"KORG");
85 static const TQString DEFER_CATEGORY = TQString::fromLatin1(
"DEFER;");
86 static const TQString ARCHIVE_CATEGORY = TQString::fromLatin1(
"SAVE");
87 static const TQString ARCHIVE_CATEGORIES = TQString::fromLatin1(
"SAVE:");
88 static const TQString LOG_CATEGORY = TQString::fromLatin1(
"LOG:");
89 static const TQString xtermURL = TQString::fromLatin1(
"xterm:");
92 static const TQString DISABLED_STATUS = TQString::fromLatin1(
"DISABLED");
94 static const TQString EXPIRED_UID = TQString::fromLatin1(
"-exp-");
95 static const TQString DISPLAYING_UID = TQString::fromLatin1(
"-disp-");
96 static const TQString TEMPLATE_UID = TQString::fromLatin1(
"-tmpl-");
97 static const TQString KORGANIZER_UID = TQString::fromLatin1(
"-korg-");
104 EmailAddressList emailAddresses;
105 TQString emailSubject;
106 TQStringList emailAttachments;
108 TQColor bgColour, fgColour;
114 KAAlarm::SubType type;
115 KAAlarmEventBase::Type action;
118 bool reminderOnceOnly;
125 typedef TQMap<KAAlarm::SubType, AlarmData> AlarmMap;
127 static void setProcedureAlarm(
Alarm*,
const TQString& commandLine);
135 inline void KAEvent::set_deferral(DeferType type)
150 inline void KAEvent::set_reminder(
int minutes)
152 if (minutes && !mReminderMinutes)
154 else if (!minutes && mReminderMinutes)
156 mReminderMinutes = minutes;
157 mArchiveReminderMinutes = 0;
160 inline void KAEvent::set_archiveReminder()
162 if (mReminderMinutes)
164 mArchiveReminderMinutes = mReminderMinutes;
165 mReminderMinutes = 0;
169 void KAEvent::copy(
const KAEvent& event)
171 KAAlarmEventBase::copy(event);
172 mTemplateName =
event.mTemplateName;
173 mAudioFile =
event.mAudioFile;
174 mPreAction =
event.mPreAction;
175 mPostAction =
event.mPostAction;
176 mStartDateTime =
event.mStartDateTime;
177 mSaveDateTime =
event.mSaveDateTime;
178 mAtLoginDateTime =
event.mAtLoginDateTime;
179 mDeferralTime =
event.mDeferralTime;
180 mDisplayingTime =
event.mDisplayingTime;
181 mDisplayingFlags =
event.mDisplayingFlags;
182 mReminderMinutes =
event.mReminderMinutes;
183 mArchiveReminderMinutes =
event.mArchiveReminderMinutes;
184 mDeferDefaultMinutes =
event.mDeferDefaultMinutes;
185 mRevision =
event.mRevision;
186 mAlarmCount =
event.mAlarmCount;
187 mDeferral =
event.mDeferral;
188 mLogFile =
event.mLogFile;
189 mCommandXterm =
event.mCommandXterm;
190 mKMailSerialNumber =
event.mKMailSerialNumber;
191 mCopyToKOrganizer =
event.mCopyToKOrganizer;
192 mReminderOnceOnly =
event.mReminderOnceOnly;
193 mMainExpired =
event.mMainExpired;
194 mArchiveRepeatAtLogin =
event.mArchiveRepeatAtLogin;
195 mArchive =
event.mArchive;
196 mTemplateAfterTime =
event.mTemplateAfterTime;
197 mEnabled =
event.mEnabled;
198 mUpdated =
event.mUpdated;
200 if (event.mRecurrence)
201 mRecurrence =
new KARecurrence(*event.mRecurrence);
209 void KAEvent::set(
const Event& event)
212 mEventID =
event.uid();
213 mRevision =
event.revision();
214 mTemplateName = TQString();
215 mLogFile = TQString();
216 mTemplateAfterTime = -1;
220 mCommandXterm =
false;
221 mCopyToKOrganizer =
false;
224 mReminderOnceOnly =
false;
226 mArchiveRepeatAtLogin =
false;
227 mArchiveReminderMinutes = 0;
228 mDeferDefaultMinutes = 0;
230 mKMailSerialNumber = 0;
231 mBgColour = TQColor(255, 255, 255);
232 mFgColour = TQColor(0, 0, 0);
237 bool dateOnly =
false;
238 const TQStringList cats =
event.categories();
239 for (
unsigned int i = 0; i < cats.count(); ++i)
241 if (cats[i] == DATE_ONLY_CATEGORY)
243 else if (cats[i] == CONFIRM_ACK_CATEGORY)
245 else if (cats[i] == EMAIL_BCC_CATEGORY)
247 else if (cats[i] == ARCHIVE_CATEGORY)
249 else if (cats[i] == KORGANIZER_CATEGORY)
250 mCopyToKOrganizer =
true;
251 else if (cats[i].startsWith(KMAIL_SERNUM_CATEGORY))
252 mKMailSerialNumber = cats[i].mid(KMAIL_SERNUM_CATEGORY.length()).toULong();
253 else if (cats[i].startsWith(LOG_CATEGORY))
255 TQString logUrl = cats[i].mid(LOG_CATEGORY.length());
256 if (logUrl == xtermURL)
257 mCommandXterm =
true;
261 else if (cats[i].startsWith(ARCHIVE_CATEGORIES))
265 TQStringList list = TQStringList::split(
';', cats[i].mid(ARCHIVE_CATEGORIES.length()));
266 for (
unsigned int j = 0; j < list.count(); ++j)
268 if (list[j] == AT_LOGIN_TYPE)
269 mArchiveRepeatAtLogin =
true;
270 else if (list[j] == ARCHIVE_REMINDER_ONCE_TYPE)
271 mReminderOnceOnly =
true;
275 const char* cat = list[j].latin1();
276 while ((ch = *cat) != 0 && (ch < '0' || ch >
'9'))
280 mArchiveReminderMinutes = ch -
'0';
281 while ((ch = *++cat) >=
'0' && ch <=
'9')
282 mArchiveReminderMinutes = mArchiveReminderMinutes * 10 + ch -
'0';
286 case 'H': mArchiveReminderMinutes *= 60;
break;
287 case 'D': mArchiveReminderMinutes *= 1440;
break;
293 else if (cats[i].startsWith(DEFER_CATEGORY))
295 mDeferDefaultMinutes =
static_cast<int>(cats[i].mid(DEFER_CATEGORY.length()).toUInt(&ok));
297 mDeferDefaultMinutes = 0;
299 else if (cats[i].startsWith(TEMPL_AFTER_TIME_CATEGORY))
301 mTemplateAfterTime =
static_cast<int>(cats[i].mid(TEMPL_AFTER_TIME_CATEGORY.length()).toUInt(&ok));
303 mTemplateAfterTime = -1;
305 else if (cats[i].startsWith(LATE_CANCEL_CATEGORY))
307 mLateCancel =
static_cast<int>(cats[i].mid(LATE_CANCEL_CATEGORY.length()).toUInt(&ok));
308 if (!ok || !mLateCancel)
311 else if (cats[i].startsWith(AUTO_CLOSE_CATEGORY))
313 mLateCancel =
static_cast<int>(cats[i].mid(AUTO_CLOSE_CATEGORY.length()).toUInt(&ok));
314 if (!ok || !mLateCancel)
319 TQString prop =
event.customProperty(APPNAME, REPEAT_PROPERTY);
323 TQStringList list = TQStringList::split(
':', prop);
324 if (list.count() >= 2)
326 int interval =
static_cast<int>(list[0].toUInt());
327 int count =
static_cast<int>(list[1].toUInt());
328 if (interval && count)
330 mRepeatInterval = interval;
331 mRepeatCount = count;
335 mNextMainDateTime = readDateTime(event, dateOnly, mStartDateTime);
336 mSaveDateTime =
event.created();
337 if (uidStatus() == TEMPLATE)
338 mTemplateName =
event.summary();
339 if (event.
statusStr() == DISABLED_STATUS)
344 mActionType = T_MESSAGE;
346 mRepeatAtLogin =
false;
348 mRepeatSound =
false;
349 mCommandScript =
false;
350 mDeferral = NO_DEFERRAL;
354 mReminderMinutes = 0;
355 mEmailFromIdentity = 0;
361 mEmailAddresses.clear();
362 mEmailAttachments.clear();
366 readAlarms(event, &alarmMap);
372 bool isEmailText =
false;
373 bool setDeferralTime =
false;
375 for (AlarmMap::ConstIterator it = alarmMap.begin(); it != alarmMap.end(); ++it)
377 const AlarmData& data = it.data();
378 DateTime dateTime = data.alarm->hasStartOffset() ? mNextMainDateTime.addSecs(data.alarm->startOffset().asSeconds()) : data.alarm->time();
381 case KAAlarm::MAIN__ALARM:
382 mMainExpired =
false;
384 alTime.setDateOnly(mStartDateTime.isDateOnly());
385 if (data.repeatCount && data.repeatInterval)
387 mRepeatInterval = data.repeatInterval;
388 mRepeatCount = data.repeatCount;
389 mNextRepeat = data.nextRepeat;
392 case KAAlarm::AT_LOGIN__ALARM:
393 mRepeatAtLogin =
true;
394 mAtLoginDateTime = dateTime.rawDateTime();
395 alTime = mAtLoginDateTime;
397 case KAAlarm::REMINDER__ALARM:
398 mReminderMinutes = -(data.startOffsetSecs / 60);
399 if (mReminderMinutes)
400 mArchiveReminderMinutes = 0;
402 case KAAlarm::DEFERRED_REMINDER_DATE__ALARM:
403 case KAAlarm::DEFERRED_DATE__ALARM:
404 mDeferral = (data.type == KAAlarm::DEFERRED_REMINDER_DATE__ALARM) ? REMINDER_DEFERRAL : NORMAL_DEFERRAL;
405 mDeferralTime = dateTime;
406 mDeferralTime.setDateOnly(
true);
407 if (data.alarm->hasStartOffset())
408 deferralOffset = data.alarm->startOffset();
410 case KAAlarm::DEFERRED_REMINDER_TIME__ALARM:
411 case KAAlarm::DEFERRED_TIME__ALARM:
412 mDeferral = (data.type == KAAlarm::DEFERRED_REMINDER_TIME__ALARM) ? REMINDER_DEFERRAL : NORMAL_DEFERRAL;
413 mDeferralTime = dateTime;
414 if (data.alarm->hasStartOffset())
415 deferralOffset = data.alarm->startOffset();
417 case KAAlarm::DISPLAYING__ALARM:
420 mDisplayingFlags = data.displayingFlags;
421 bool dateOnly = (mDisplayingFlags & DEFERRAL) ? !(mDisplayingFlags & TIMED_FLAG)
422 : mStartDateTime.isDateOnly();
423 mDisplayingTime = dateTime;
424 mDisplayingTime.setDateOnly(dateOnly);
425 alTime = mDisplayingTime;
428 case KAAlarm::AUDIO__ALARM:
429 mAudioFile = data.cleanText;
430 mSpeak = data.speak && mAudioFile.isEmpty();
431 mBeep = !mSpeak && mAudioFile.isEmpty();
432 mSoundVolume = (!mBeep && !mSpeak) ? data.soundVolume : -1;
433 mFadeVolume = (mSoundVolume >= 0 && data.fadeSeconds > 0) ? data.fadeVolume : -1;
434 mFadeSeconds = (mFadeVolume >= 0) ? data.fadeSeconds : 0;
435 mRepeatSound = (!mBeep && !mSpeak) && (data.repeatCount < 0);
437 case KAAlarm::PRE_ACTION__ALARM:
438 mPreAction = data.cleanText;
440 case KAAlarm::POST_ACTION__ALARM:
441 mPostAction = data.cleanText;
443 case KAAlarm::INVALID__ALARM:
448 if (data.reminderOnceOnly)
449 mReminderOnceOnly =
true;
450 bool noSetNextTime =
false;
453 case KAAlarm::DEFERRED_REMINDER_DATE__ALARM:
454 case KAAlarm::DEFERRED_DATE__ALARM:
455 case KAAlarm::DEFERRED_REMINDER_TIME__ALARM:
456 case KAAlarm::DEFERRED_TIME__ALARM:
461 setDeferralTime =
true;
462 noSetNextTime =
true;
465 case KAAlarm::AT_LOGIN__ALARM:
466 case KAAlarm::REMINDER__ALARM:
467 case KAAlarm::DISPLAYING__ALARM:
468 if (!set && !noSetNextTime)
469 mNextMainDateTime = alTime;
471 case KAAlarm::MAIN__ALARM:
476 mActionType = data.action;
477 mText = (mActionType == T_COMMAND) ? data.cleanText.stripWhiteSpace() : data.cleanText;
482 mDefaultFont = data.defaultFont;
483 if (data.isEmailText)
487 mBgColour = data.bgColour;
488 mFgColour = data.fgColour;
491 mCommandScript = data.commandScript;
494 mEmailFromIdentity = data.emailFromId;
495 mEmailAddresses = data.emailAddresses;
496 mEmailSubject = data.emailSubject;
497 mEmailAttachments = data.emailAttachments;
504 if (data.action == T_FILE && mActionType == T_MESSAGE)
505 mActionType = T_FILE;
508 case KAAlarm::AUDIO__ALARM:
509 case KAAlarm::PRE_ACTION__ALARM:
510 case KAAlarm::POST_ACTION__ALARM:
511 case KAAlarm::INVALID__ALARM:
517 mKMailSerialNumber = 0;
519 mArchiveRepeatAtLogin =
false;
524 int nextRepeat = mNextRepeat;
525 setRecurrence(*recur);
526 if (nextRepeat <= mRepeatCount)
527 mNextRepeat = nextRepeat;
532 if (mMainExpired && deferralOffset.
asSeconds() && checkRecur() != KARecurrence::NO_RECUR)
536 DateTime dt = mRecurrence->getNextDateTime(mStartDateTime.dateTime().addDays(-1));
537 dt.setDateOnly(mStartDateTime.isDateOnly());
538 if (mDeferralTime.isDateOnly())
540 mDeferralTime = dt.addSecs(deferralOffset.
asSeconds());
541 mDeferralTime.setDateOnly(
true);
544 mDeferralTime = deferralOffset.
end(dt.dateTime());
548 if (mNextMainDateTime == mDeferralTime)
549 mDeferral = CANCEL_DEFERRAL;
551 mNextMainDateTime = mDeferralTime;
561 DateTime KAEvent::readDateTime(
const Event& event,
bool dateOnly, DateTime& start)
563 start.set(event.
dtStart(), dateOnly);
564 DateTime next = start;
565 TQString prop =
event.customProperty(APPNAME, NEXT_RECUR_PROPERTY);
566 if (prop.length() >= 8)
569 TQDate d(prop.left(4).toInt(), prop.mid(4,2).toInt(), prop.mid(6,2).toInt());
572 if (dateOnly && prop.length() == 8)
574 else if (!dateOnly && prop.length() == 15 && prop[8] == TQChar(
'T'))
576 TQTime t(prop.mid(9,2).toInt(), prop.mid(11,2).toInt(), prop.mid(13,2).toInt());
578 next = TQDateTime(d, t);
589 void KAEvent::readAlarms(
const Event& event,
void* almap)
591 AlarmMap* alarmMap = (AlarmMap*)almap;
592 Alarm::List alarms =
event.alarms();
593 for (Alarm::List::ConstIterator it = alarms.begin(); it != alarms.end(); ++it)
597 readAlarm(**it, data);
598 if (data.type != KAAlarm::INVALID__ALARM)
599 alarmMap->insert(data.type, data);
607 void KAEvent::readAlarm(
const Alarm& alarm, AlarmData& data)
612 data.displayingFlags = 0;
613 data.isEmailText =
false;
617 if (data.repeatCount)
620 TQString
property = alarm.
customProperty(APPNAME, NEXT_REPEAT_PROPERTY);
621 int n =
static_cast<int>(
property.toUInt(&ok));
625 switch (alarm.
type())
627 case Alarm::Procedure:
628 data.action = T_COMMAND;
630 data.commandScript = data.cleanText.isEmpty();
633 if (!data.commandScript)
634 data.cleanText +=
' ';
639 data.action = T_EMAIL;
640 data.emailFromId = alarm.
customProperty(APPNAME, EMAIL_ID_PROPERTY).toUInt();
648 data.action = T_MESSAGE;
649 data.cleanText = AlarmText::fromCalendarText(alarm.
text(), data.isEmailText);
650 TQString
property = alarm.
customProperty(APPNAME, FONT_COLOUR_PROPERTY);
651 TQStringList list = TQStringList::split(TQChar(
';'), property,
true);
652 data.bgColour = TQColor(255, 255, 255);
653 data.fgColour = TQColor(0, 0, 0);
654 int n = list.count();
657 if (!list[0].isEmpty())
663 if (n > 1 && !list[1].isEmpty())
670 data.defaultFont = (n <= 2 || list[2].isEmpty());
671 if (!data.defaultFont)
672 data.font.fromString(list[2]);
677 data.action = T_AUDIO;
679 data.type = KAAlarm::AUDIO__ALARM;
680 data.soundVolume = -1;
681 data.fadeVolume = -1;
682 data.fadeSeconds = 0;
683 data.speak = !alarm.
customProperty(APPNAME, SPEAK_PROPERTY).isNull();
684 TQString
property = alarm.
customProperty(APPNAME, VOLUME_PROPERTY);
685 if (!property.isEmpty())
690 TQStringList list = TQStringList::split(TQChar(
';'), property,
true);
691 data.soundVolume = list[0].toFloat(&ok);
693 data.soundVolume = -1;
694 if (data.soundVolume >= 0 && list.count() >= 3)
696 fadeVolume = list[1].toFloat(&ok);
698 fadeSecs =
static_cast<int>(list[2].toUInt(&ok));
699 if (ok && fadeVolume >= 0 && fadeSecs > 0)
701 data.fadeVolume = fadeVolume;
702 data.fadeSeconds = fadeSecs;
709 data.type = KAAlarm::INVALID__ALARM;
713 bool atLogin =
false;
714 bool reminder =
false;
715 bool deferral =
false;
716 bool dateDeferral =
false;
717 data.reminderOnceOnly =
false;
718 data.type = KAAlarm::MAIN__ALARM;
720 TQStringList types = TQStringList::split(TQChar(
','), property);
721 for (
unsigned int i = 0; i < types.count(); ++i)
723 TQString type = types[i];
724 if (type == AT_LOGIN_TYPE)
726 else if (type == FILE_TYPE && data.action == T_MESSAGE)
727 data.action = T_FILE;
728 else if (type == REMINDER_TYPE)
730 else if (type == REMINDER_ONCE_TYPE)
731 reminder = data.reminderOnceOnly =
true;
732 else if (type == TIME_DEFERRAL_TYPE)
734 else if (type == DATE_DEFERRAL_TYPE)
735 dateDeferral = deferral =
true;
736 else if (type == DISPLAYING_TYPE)
737 data.type = KAAlarm::DISPLAYING__ALARM;
738 else if (type == PRE_ACTION_TYPE && data.action == T_COMMAND)
739 data.type = KAAlarm::PRE_ACTION__ALARM;
740 else if (type == POST_ACTION_TYPE && data.action == T_COMMAND)
741 data.type = KAAlarm::POST_ACTION__ALARM;
746 if (data.type == KAAlarm::MAIN__ALARM)
747 data.type = dateDeferral ? KAAlarm::DEFERRED_REMINDER_DATE__ALARM
748 : deferral ? KAAlarm::DEFERRED_REMINDER_TIME__ALARM : KAAlarm::REMINDER__ALARM;
749 else if (data.type == KAAlarm::DISPLAYING__ALARM)
750 data.displayingFlags = dateDeferral ? REMINDER | DATE_DEFERRAL
751 : deferral ? REMINDER | TIME_DEFERRAL : REMINDER;
755 if (data.type == KAAlarm::MAIN__ALARM)
756 data.type = dateDeferral ? KAAlarm::DEFERRED_DATE__ALARM : KAAlarm::DEFERRED_TIME__ALARM;
757 else if (data.type == KAAlarm::DISPLAYING__ALARM)
758 data.displayingFlags = dateDeferral ? DATE_DEFERRAL : TIME_DEFERRAL;
762 if (data.type == KAAlarm::MAIN__ALARM)
763 data.type = KAAlarm::AT_LOGIN__ALARM;
764 else if (data.type == KAAlarm::DISPLAYING__ALARM)
765 data.displayingFlags = REPEAT_AT_LOGIN;
773 void KAEvent::set(
const TQDateTime& dateTime,
const TQString& text,
const TQColor& bg,
const TQColor& fg,
774 const TQFont& font, Action action,
int lateCancel,
int flags)
777 mStartDateTime.set(dateTime, flags & ANY_TIME);
778 mNextMainDateTime = mStartDateTime;
785 mActionType = (KAAlarmEventBase::Type)action;
788 mActionType = T_MESSAGE;
791 mText = (mActionType == T_COMMAND) ? text.stripWhiteSpace() : text;
792 mEventID = TQString();
793 mTemplateName = TQString();
794 mPreAction = TQString();
795 mPostAction = TQString();
799 mTemplateAfterTime = -1;
805 mLateCancel = lateCancel;
806 mDeferral = NO_DEFERRAL;
808 KAAlarmEventBase::set(flags & ~READ_ONLY_FLAGS);
809 mStartDateTime.setDateOnly(flags & ANY_TIME);
810 set_deferral((flags & DEFERRAL) ? NORMAL_DEFERRAL : NO_DEFERRAL);
811 mCommandXterm = flags & EXEC_IN_XTERM;
812 mCopyToKOrganizer = flags & COPY_KORGANIZER;
813 mEnabled = !(flags & DISABLED);
815 mKMailSerialNumber = 0;
816 mReminderMinutes = 0;
817 mArchiveReminderMinutes = 0;
818 mDeferDefaultMinutes = 0;
819 mArchiveRepeatAtLogin =
false;
820 mReminderOnceOnly =
false;
822 mMainExpired =
false;
827 void KAEvent::setLogFile(
const TQString& logfile)
830 if (!logfile.isEmpty())
831 mCommandXterm =
false;
834 void KAEvent::setEmail(uint from,
const EmailAddressList& addresses,
const TQString& subject,
const TQStringList& attachments)
836 mEmailFromIdentity = from;
837 mEmailAddresses = addresses;
838 mEmailSubject = subject;
839 mEmailAttachments = attachments;
842 void KAEvent::setAudioFile(
const TQString& filename,
float volume,
float fadeVolume,
int fadeSeconds)
844 mAudioFile = filename;
845 mSoundVolume = filename.isEmpty() ? -1 : volume;
846 if (mSoundVolume >= 0)
848 mFadeVolume = (fadeSeconds > 0) ? fadeVolume : -1;
849 mFadeSeconds = (mFadeVolume >= 0) ? fadeSeconds : 0;
859 void KAEvent::setReminder(
int minutes,
bool onceOnly)
861 if (minutes != mReminderMinutes)
863 set_reminder(minutes);
864 mReminderOnceOnly = onceOnly;
873 DateTime KAEvent::displayDateTime()
const
875 DateTime dt = mainDateTime(
true);
876 if (mDeferral > 0 && mDeferral != REMINDER_DEFERRAL)
879 return mDeferralTime;
880 return TQMIN(mDeferralTime, dt);
888 TQString KAEvent::uid(
const TQString&
id, Status status)
890 TQString result = id;
893 if ((i = result.find(EXPIRED_UID)) > 0)
896 len = EXPIRED_UID.length();
898 else if ((i = result.find(DISPLAYING_UID)) > 0)
900 oldStatus = DISPLAYING;
901 len = DISPLAYING_UID.length();
903 else if ((i = result.find(TEMPLATE_UID)) > 0)
905 oldStatus = TEMPLATE;
906 len = TEMPLATE_UID.length();
908 else if ((i = result.find(KORGANIZER_UID)) > 0)
910 oldStatus = KORGANIZER;
911 len = KORGANIZER_UID.length();
916 i = result.findRev(
'-');
919 if (status != oldStatus && i > 0)
924 case ACTIVE: part =
"-";
break;
925 case EXPIRED: part = EXPIRED_UID;
break;
926 case DISPLAYING: part = DISPLAYING_UID;
break;
927 case TEMPLATE: part = TEMPLATE_UID;
break;
928 case KORGANIZER: part = KORGANIZER_UID;
break;
930 result.replace(i, len, part);
940 if (uid.find(EXPIRED_UID) > 0)
942 if (uid.find(DISPLAYING_UID) > 0)
944 if (uid.find(TEMPLATE_UID) > 0)
946 if (uid.find(KORGANIZER_UID) > 0)
951 int KAEvent::flags()
const
953 return KAAlarmEventBase::flags()
954 | (mStartDateTime.isDateOnly() ? ANY_TIME : 0)
955 | (mDeferral > 0 ? DEFERRAL : 0)
956 | (mCommandXterm ? EXEC_IN_XTERM : 0)
957 | (mCopyToKOrganizer ? COPY_KORGANIZER : 0)
958 | (mEnabled ? 0 : DISABLED);
964 Event* KAEvent::event()
const
968 updateKCalEvent(*ev,
false);
978 bool KAEvent::updateKCalEvent(
Event& ev,
bool checkUid,
bool original,
bool cancelCancelledDefer)
const
980 if ((checkUid && !mEventID.isEmpty() && mEventID != ev.
uid())
981 || (!mAlarmCount && (!original || !mMainExpired)))
996 if (mStartDateTime.isDateOnly())
997 cats.append(DATE_ONLY_CATEGORY);
999 cats.append(CONFIRM_ACK_CATEGORY);
1001 cats.append(EMAIL_BCC_CATEGORY);
1002 if (mKMailSerialNumber)
1003 cats.append(TQString(
"%1%2").arg(KMAIL_SERNUM_CATEGORY).arg(mKMailSerialNumber));
1004 if (mCopyToKOrganizer)
1005 cats.append(KORGANIZER_CATEGORY);
1007 cats.append(LOG_CATEGORY + xtermURL);
1008 else if (!mLogFile.isEmpty())
1009 cats.append(LOG_CATEGORY + mLogFile);
1011 cats.append(TQString(
"%1%2").arg(mAutoClose ? AUTO_CLOSE_CATEGORY : LATE_CANCEL_CATEGORY).arg(mLateCancel));
1012 if (mDeferDefaultMinutes)
1013 cats.append(TQString(
"%1%2").arg(DEFER_CATEGORY).arg(mDeferDefaultMinutes));
1014 if (!mTemplateName.isEmpty() && mTemplateAfterTime >= 0)
1015 cats.append(TQString(
"%1%2").arg(TEMPL_AFTER_TIME_CATEGORY).arg(mTemplateAfterTime));
1016 if (mArchive && !original)
1018 TQStringList params;
1019 if (mArchiveReminderMinutes)
1021 if (mReminderOnceOnly)
1022 params += ARCHIVE_REMINDER_ONCE_TYPE;
1024 int count = mArchiveReminderMinutes;
1025 if (count % 1440 == 0)
1030 else if (count % 60 == 0)
1035 params += TQString(
"%1%2").arg(count).arg(unit);
1037 if (mArchiveRepeatAtLogin)
1038 params += AT_LOGIN_TYPE;
1039 if (params.count() > 0)
1041 TQString cat = ARCHIVE_CATEGORIES;
1042 cat += params.join(TQString::fromLatin1(
";"));
1046 cats.append(ARCHIVE_CATEGORY);
1061 DateTime dtMain = original ? mStartDateTime : mNextMainDateTime;
1062 int ancillaryType = 0;
1063 DateTime ancillaryTime;
1064 int ancillaryOffset = 0;
1065 if (!mMainExpired || original)
1072 if (!original && checkRecur() != KARecurrence::NO_RECUR)
1074 TQDateTime dt = mNextMainDateTime.dateTime();
1076 dt.toString(mNextMainDateTime.isDateOnly() ?
"yyyyMMdd" :
"yyyyMMddThhmmss"));
1079 initKCalAlarm(ev, 0, TQStringList(), KAAlarm::MAIN_ALARM);
1080 ancillaryOffset = 0;
1081 ancillaryType = dtMain.isValid() ? 2 : 0;
1083 else if (mRepeatCount && mRepeatInterval)
1087 TQString param = TQString(
"%1:%2").arg(mRepeatInterval).arg(mRepeatCount);
1092 if (mRepeatAtLogin || (mArchiveRepeatAtLogin && original))
1095 if (mArchiveRepeatAtLogin)
1096 dtl = mStartDateTime.dateTime().addDays(-1);
1097 else if (mAtLoginDateTime.isValid())
1098 dtl = mAtLoginDateTime;
1099 else if (mStartDateTime.isDateOnly())
1100 dtl = TQDate::currentDate().addDays(-1);
1102 dtl = TQDateTime::currentDateTime();
1103 initKCalAlarm(ev, dtl, AT_LOGIN_TYPE);
1104 if (!ancillaryType && dtl.isValid())
1106 ancillaryTime = dtl;
1110 if (mReminderMinutes || (mArchiveReminderMinutes && original))
1112 int minutes = mReminderMinutes ? mReminderMinutes : mArchiveReminderMinutes;
1113 initKCalAlarm(ev, -minutes * 60, TQStringList(mReminderOnceOnly ? REMINDER_ONCE_TYPE : REMINDER_TYPE));
1116 ancillaryOffset = -minutes * 60;
1120 if (mDeferral > 0 || (mDeferral == CANCEL_DEFERRAL && !cancelCancelledDefer))
1122 DateTime nextDateTime = mNextMainDateTime;
1125 if (checkRecur() == KARecurrence::NO_RECUR)
1126 nextDateTime = mStartDateTime;
1134 nextDateTime = mRecurrence->getNextDateTime(mStartDateTime.dateTime().addDays(-1));
1135 nextDateTime.setDateOnly(mStartDateTime.isDateOnly());
1140 if (mDeferralTime.isDateOnly())
1142 startOffset = nextDateTime.secsTo(mDeferralTime.dateTime());
1143 list += DATE_DEFERRAL_TYPE;
1147 startOffset = nextDateTime.dateTime().secsTo(mDeferralTime.dateTime());
1148 list += TIME_DEFERRAL_TYPE;
1150 if (mDeferral == REMINDER_DEFERRAL)
1151 list += mReminderOnceOnly ? REMINDER_ONCE_TYPE : REMINDER_TYPE;
1152 initKCalAlarm(ev, startOffset, list);
1153 if (!ancillaryType && mDeferralTime.isValid())
1155 ancillaryOffset = startOffset;
1159 if (!mTemplateName.isEmpty())
1161 else if (mDisplaying)
1163 TQStringList list(DISPLAYING_TYPE);
1164 if (mDisplayingFlags & REPEAT_AT_LOGIN)
1165 list += AT_LOGIN_TYPE;
1166 else if (mDisplayingFlags & DEFERRAL)
1168 if (mDisplayingFlags & TIMED_FLAG)
1169 list += TIME_DEFERRAL_TYPE;
1171 list += DATE_DEFERRAL_TYPE;
1173 if (mDisplayingFlags & REMINDER)
1174 list += mReminderOnceOnly ? REMINDER_ONCE_TYPE : REMINDER_TYPE;
1175 initKCalAlarm(ev, mDisplayingTime, list);
1176 if (!ancillaryType && mDisplayingTime.isValid())
1178 ancillaryTime = mDisplayingTime;
1182 if (mBeep || mSpeak || !mAudioFile.isEmpty())
1185 if (ancillaryType == 2)
1186 initKCalAlarm(ev, ancillaryOffset, TQStringList(), KAAlarm::AUDIO_ALARM);
1188 initKCalAlarm(ev, ancillaryTime, TQStringList(), KAAlarm::AUDIO_ALARM);
1190 if (!mPreAction.isEmpty())
1193 if (ancillaryType == 2)
1194 initKCalAlarm(ev, ancillaryOffset, TQStringList(PRE_ACTION_TYPE), KAAlarm::PRE_ACTION_ALARM);
1196 initKCalAlarm(ev, ancillaryTime, TQStringList(PRE_ACTION_TYPE), KAAlarm::PRE_ACTION_ALARM);
1198 if (!mPostAction.isEmpty())
1201 if (ancillaryType == 2)
1202 initKCalAlarm(ev, ancillaryOffset, TQStringList(POST_ACTION_TYPE), KAAlarm::POST_ACTION_ALARM);
1204 initKCalAlarm(ev, ancillaryTime, TQStringList(POST_ACTION_TYPE), KAAlarm::POST_ACTION_ALARM);
1208 mRecurrence->writeRecurrence(*ev.
recurrence());
1211 if (mSaveDateTime.isValid())
1222 Alarm* KAEvent::initKCalAlarm(
Event& event,
const DateTime& dt,
const TQStringList& types, KAAlarm::Type type)
const
1224 int startOffset = dt.isDateOnly() ? mStartDateTime.secsTo(dt)
1225 : mStartDateTime.dateTime().secsTo(dt.dateTime());
1226 return initKCalAlarm(event, startOffset, types, type);
1229 Alarm* KAEvent::initKCalAlarm(
Event& event,
int startOffsetSecs,
const TQStringList& types, KAAlarm::Type type)
const
1231 TQStringList alltypes;
1232 Alarm* alarm =
event.newAlarm();
1234 if (type != KAAlarm::MAIN_ALARM)
1243 case KAAlarm::AUDIO_ALARM:
1252 if (!mAudioFile.isEmpty() && mSoundVolume >= 0)
1254 TQString::fromLatin1(
"%1;%2;%3").arg(TQString::number(mSoundVolume,
'f', 2))
1255 .arg(TQString::number(mFadeVolume,
'f', 2))
1256 .arg(mFadeSeconds));
1258 case KAAlarm::PRE_ACTION_ALARM:
1259 setProcedureAlarm(alarm, mPreAction);
1261 case KAAlarm::POST_ACTION_ALARM:
1262 setProcedureAlarm(alarm, mPostAction);
1264 case KAAlarm::MAIN_ALARM:
1269 TQString::number(mNextRepeat));
1271 case KAAlarm::INVALID_ALARM:
1272 switch (mActionType)
1275 alltypes += FILE_TYPE;
1280 TQString::fromLatin1(
"%1;%2;%3").arg(mBgColour.name())
1281 .arg(mFgColour.name())
1282 .arg(mDefaultFont ? TQString() : mFont.toString()));
1288 setProcedureAlarm(alarm, mText);
1291 alarm->
setEmailAlarm(mEmailSubject, mText, mEmailAddresses, mEmailAttachments);
1292 if (mEmailFromIdentity)
1293 alarm->
setCustomProperty(APPNAME, EMAIL_ID_PROPERTY, TQString::number(mEmailFromIdentity));
1299 case KAAlarm::REMINDER_ALARM:
1300 case KAAlarm::DEFERRED_ALARM:
1301 case KAAlarm::DEFERRED_REMINDER_ALARM:
1302 case KAAlarm::AT_LOGIN_ALARM:
1303 case KAAlarm::DISPLAYING_ALARM:
1307 if (alltypes.count() > 0)
1315 KAAlarm KAEvent::alarm(KAAlarm::Type type)
const
1321 al.mEventID = mEventID;
1322 al.mActionType = mActionType;
1324 al.mBgColour = mBgColour;
1325 al.mFgColour = mFgColour;
1327 al.mDefaultFont = mDefaultFont;
1330 al.mSoundVolume = mSoundVolume;
1331 al.mFadeVolume = mFadeVolume;
1332 al.mFadeSeconds = mFadeSeconds;
1333 al.mRepeatSound = mRepeatSound;
1334 al.mConfirmAck = mConfirmAck;
1335 al.mRepeatCount = 0;
1336 al.mRepeatInterval = 0;
1337 al.mRepeatAtLogin =
false;
1338 al.mDeferred =
false;
1339 al.mLateCancel = mLateCancel;
1340 al.mAutoClose = mAutoClose;
1341 al.mEmailBcc = mEmailBcc;
1342 al.mCommandScript = mCommandScript;
1343 if (mActionType == T_EMAIL)
1345 al.mEmailFromIdentity = mEmailFromIdentity;
1346 al.mEmailAddresses = mEmailAddresses;
1347 al.mEmailSubject = mEmailSubject;
1348 al.mEmailAttachments = mEmailAttachments;
1352 case KAAlarm::MAIN_ALARM:
1355 al.mType = KAAlarm::MAIN__ALARM;
1356 al.mNextMainDateTime = mNextMainDateTime;
1357 al.mRepeatCount = mRepeatCount;
1358 al.mRepeatInterval = mRepeatInterval;
1359 al.mNextRepeat = mNextRepeat;
1362 case KAAlarm::REMINDER_ALARM:
1363 if (mReminderMinutes)
1365 al.mType = KAAlarm::REMINDER__ALARM;
1366 if (mReminderOnceOnly)
1367 al.mNextMainDateTime = mStartDateTime.addMins(-mReminderMinutes);
1369 al.mNextMainDateTime = mNextMainDateTime.addMins(-mReminderMinutes);
1372 case KAAlarm::DEFERRED_REMINDER_ALARM:
1373 if (mDeferral != REMINDER_DEFERRAL)
1376 case KAAlarm::DEFERRED_ALARM:
1379 al.mType =
static_cast<KAAlarm::SubType
>((mDeferral == REMINDER_DEFERRAL ? KAAlarm::DEFERRED_REMINDER_ALARM : KAAlarm::DEFERRED_ALARM)
1380 | (mDeferralTime.isDateOnly() ? 0 : KAAlarm::TIMED_DEFERRAL_FLAG));
1381 al.mNextMainDateTime = mDeferralTime;
1382 al.mDeferred =
true;
1385 case KAAlarm::AT_LOGIN_ALARM:
1388 al.mType = KAAlarm::AT_LOGIN__ALARM;
1389 al.mNextMainDateTime = mAtLoginDateTime;
1390 al.mRepeatAtLogin =
true;
1392 al.mAutoClose =
false;
1395 case KAAlarm::DISPLAYING_ALARM:
1398 al.mType = KAAlarm::DISPLAYING__ALARM;
1399 al.mNextMainDateTime = mDisplayingTime;
1400 al.mDisplaying =
true;
1403 case KAAlarm::AUDIO_ALARM:
1404 case KAAlarm::PRE_ACTION_ALARM:
1405 case KAAlarm::POST_ACTION_ALARM:
1406 case KAAlarm::INVALID_ALARM:
1421 KAAlarm KAEvent::firstAlarm()
const
1426 return alarm(KAAlarm::MAIN_ALARM);
1427 return nextAlarm(KAAlarm::MAIN_ALARM);
1437 KAAlarm KAEvent::nextAlarm(KAAlarm::Type prevType)
const
1441 case KAAlarm::MAIN_ALARM:
1442 if (mReminderMinutes)
1443 return alarm(KAAlarm::REMINDER_ALARM);
1445 case KAAlarm::REMINDER_ALARM:
1447 if (mDeferral == REMINDER_DEFERRAL)
1448 return alarm(KAAlarm::DEFERRED_REMINDER_ALARM);
1449 if (mDeferral == NORMAL_DEFERRAL)
1450 return alarm(KAAlarm::DEFERRED_ALARM);
1452 case KAAlarm::DEFERRED_REMINDER_ALARM:
1453 case KAAlarm::DEFERRED_ALARM:
1455 return alarm(KAAlarm::AT_LOGIN_ALARM);
1457 case KAAlarm::AT_LOGIN_ALARM:
1459 return alarm(KAAlarm::DISPLAYING_ALARM);
1461 case KAAlarm::DISPLAYING_ALARM:
1463 case KAAlarm::AUDIO_ALARM:
1464 case KAAlarm::PRE_ACTION_ALARM:
1465 case KAAlarm::POST_ACTION_ALARM:
1466 case KAAlarm::INVALID_ALARM:
1478 void KAEvent::removeExpiredAlarm(KAAlarm::Type type)
1480 int count = mAlarmCount;
1483 case KAAlarm::MAIN_ALARM:
1486 case KAAlarm::AT_LOGIN_ALARM:
1490 mArchiveRepeatAtLogin =
true;
1491 mRepeatAtLogin =
false;
1495 case KAAlarm::REMINDER_ALARM:
1497 set_archiveReminder();
1499 case KAAlarm::DEFERRED_REMINDER_ALARM:
1500 case KAAlarm::DEFERRED_ALARM:
1501 set_deferral(NO_DEFERRAL);
1503 case KAAlarm::DISPLAYING_ALARM:
1506 mDisplaying =
false;
1510 case KAAlarm::AUDIO_ALARM:
1511 case KAAlarm::PRE_ACTION_ALARM:
1512 case KAAlarm::POST_ACTION_ALARM:
1513 case KAAlarm::INVALID_ALARM:
1517 if (mAlarmCount != count)
1528 bool KAEvent::defer(
const DateTime& dateTime,
bool reminder,
bool adjustRecurrence)
1530 bool result =
false;
1531 bool setNextRepetition =
false;
1532 bool checkRepetition =
false;
1533 cancelCancelledDeferral();
1534 if (checkRecur() == KARecurrence::NO_RECUR)
1536 if (mReminderMinutes || mDeferral == REMINDER_DEFERRAL || mArchiveReminderMinutes)
1538 if (dateTime < mNextMainDateTime.dateTime())
1540 set_deferral(REMINDER_DEFERRAL);
1541 mDeferralTime = dateTime;
1546 if (mReminderMinutes || mDeferral == REMINDER_DEFERRAL)
1547 set_deferral(NO_DEFERRAL);
1550 if (mReminderMinutes)
1551 set_archiveReminder();
1553 if (mDeferral != REMINDER_DEFERRAL)
1556 if (mRepeatCount && mRepeatInterval && dateTime < mainEndRepeatTime())
1559 set_deferral(NORMAL_DEFERRAL);
1560 mDeferralTime = dateTime;
1562 setNextRepetition =
true;
1567 mNextMainDateTime = mDeferralTime = dateTime;
1568 set_deferral(NORMAL_DEFERRAL);
1572 mMainExpired =
true;
1577 mArchiveRepeatAtLogin =
true;
1578 mRepeatAtLogin =
false;
1588 if (dateTime >= mNextMainDateTime.dateTime())
1589 set_deferral(NO_DEFERRAL);
1592 set_deferral(REMINDER_DEFERRAL);
1593 mDeferralTime = dateTime;
1594 checkRepetition =
true;
1599 mDeferralTime = dateTime;
1601 set_deferral(NORMAL_DEFERRAL);
1602 if (adjustRecurrence)
1604 TQDateTime now = TQDateTime::currentDateTime();
1605 if (mainEndRepeatTime() < now)
1609 if (!mMainExpired && setNextOccurrence(now) == NO_OCCURRENCE)
1611 mMainExpired =
true;
1616 setNextRepetition = (mRepeatCount && mRepeatInterval);
1619 checkRepetition =
true;
1621 if (checkRepetition)
1622 setNextRepetition = (mRepeatCount && mRepeatInterval && mDeferralTime < mainEndRepeatTime());
1623 if (setNextRepetition)
1627 mNextRepeat = (mNextMainDateTime < mDeferralTime)
1628 ? mNextMainDateTime.secsTo(mDeferralTime) / (mRepeatInterval * 60) + 1 : 0;
1637 void KAEvent::cancelDefer()
1644 || nextOccurrence(TQDateTime::currentDateTime(), mDeferralTime, RETURN_REPETITION) == NO_OCCURRENCE)
1647 mDeferralTime = DateTime();
1648 set_deferral(NO_DEFERRAL);
1651 set_deferral(CANCEL_DEFERRAL);
1659 void KAEvent::cancelCancelledDeferral()
1661 if (mDeferral == CANCEL_DEFERRAL)
1663 mDeferralTime = DateTime();
1664 set_deferral(NO_DEFERRAL);
1671 DateTime KAEvent::deferralLimit(KAEvent::DeferLimitType* limitType)
const
1673 DeferLimitType ltype;
1675 bool recurs = (checkRecur() != KARecurrence::NO_RECUR);
1676 if (recurs || mRepeatCount)
1680 DateTime reminderTime;
1681 TQDateTime now = TQDateTime::currentDateTime();
1682 OccurType type = nextOccurrence(now, endTime, RETURN_REPETITION);
1683 if (type & OCCURRENCE_REPEAT)
1684 ltype = LIMIT_REPETITION;
1685 else if (type == NO_OCCURRENCE)
1687 else if (mReminderMinutes && (now < (reminderTime = endTime.addMins(-mReminderMinutes))))
1689 endTime = reminderTime;
1690 ltype = LIMIT_REMINDER;
1692 else if (type == FIRST_OR_ONLY_OCCURRENCE && !recurs)
1693 ltype = LIMIT_REPETITION;
1695 ltype = LIMIT_RECURRENCE;
1697 else if ((mReminderMinutes || mDeferral == REMINDER_DEFERRAL || mArchiveReminderMinutes)
1698 && TQDateTime::currentDateTime() < mNextMainDateTime.dateTime())
1701 endTime = mNextMainDateTime;
1702 ltype = LIMIT_REMINDER;
1706 if (ltype != LIMIT_NONE)
1707 endTime = endTime.addMins(-1);
1722 bool KAEvent::setDisplaying(
const KAEvent& event, KAAlarm::Type alarmType,
const TQDateTime& repeatAtLoginTime)
1725 && (alarmType == KAAlarm::MAIN_ALARM
1726 || alarmType == KAAlarm::REMINDER_ALARM
1727 || alarmType == KAAlarm::DEFERRED_REMINDER_ALARM
1728 || alarmType == KAAlarm::DEFERRED_ALARM
1729 || alarmType == KAAlarm::AT_LOGIN_ALARM))
1732 KAAlarm al =
event.alarm(alarmType);
1738 mDisplayingTime = (alarmType == KAAlarm::AT_LOGIN_ALARM) ? repeatAtLoginTime : al.dateTime();
1739 switch (al.subType())
1741 case KAAlarm::AT_LOGIN__ALARM: mDisplayingFlags = REPEAT_AT_LOGIN;
break;
1742 case KAAlarm::REMINDER__ALARM: mDisplayingFlags = REMINDER;
break;
1743 case KAAlarm::DEFERRED_REMINDER_TIME__ALARM: mDisplayingFlags = REMINDER | TIME_DEFERRAL;
break;
1744 case KAAlarm::DEFERRED_REMINDER_DATE__ALARM: mDisplayingFlags = REMINDER | DATE_DEFERRAL;
break;
1745 case KAAlarm::DEFERRED_TIME__ALARM: mDisplayingFlags = TIME_DEFERRAL;
break;
1746 case KAAlarm::DEFERRED_DATE__ALARM: mDisplayingFlags = DATE_DEFERRAL;
break;
1747 default: mDisplayingFlags = 0;
break;
1760 KAAlarm KAEvent::convertDisplayingAlarm()
const
1765 al = alarm(KAAlarm::DISPLAYING_ALARM);
1766 if (mDisplayingFlags & REPEAT_AT_LOGIN)
1768 al.mRepeatAtLogin =
true;
1769 al.mType = KAAlarm::AT_LOGIN__ALARM;
1771 else if (mDisplayingFlags & DEFERRAL)
1773 al.mDeferred =
true;
1774 al.mType = (mDisplayingFlags == (REMINDER | DATE_DEFERRAL)) ? KAAlarm::DEFERRED_REMINDER_DATE__ALARM
1775 : (mDisplayingFlags == (REMINDER | TIME_DEFERRAL)) ? KAAlarm::DEFERRED_REMINDER_TIME__ALARM
1776 : (mDisplayingFlags == DATE_DEFERRAL) ? KAAlarm::DEFERRED_DATE__ALARM
1777 : KAAlarm::DEFERRED_TIME__ALARM;
1779 else if (mDisplayingFlags & REMINDER)
1780 al.mType = KAAlarm::REMINDER__ALARM;
1782 al.mType = KAAlarm::MAIN__ALARM;
1790 void KAEvent::reinstateFromDisplaying(
const KAEvent& dispEvent)
1792 if (dispEvent.mDisplaying)
1796 mDisplaying =
false;
1807 bool KAEvent::occursAfter(
const TQDateTime& preDateTime,
bool includeRepetitions)
const
1810 if (checkRecur() != KARecurrence::NO_RECUR)
1812 if (mRecurrence->duration() < 0)
1814 dt = mRecurrence->endDateTime();
1817 dt = mNextMainDateTime.dateTime();
1818 if (mStartDateTime.isDateOnly())
1820 TQDate pre = preDateTime.date();
1821 if (preDateTime.time() < Preferences::startOfDay())
1822 pre = pre.addDays(-1);
1823 if (pre < dt.date())
1826 else if (preDateTime < dt)
1829 if (includeRepetitions && mRepeatCount)
1831 if (preDateTime < dt.addSecs(mRepeatCount * mRepeatInterval * 60))
1842 KAEvent::OccurType KAEvent::nextOccurrence(
const TQDateTime& preDateTime, DateTime& result,
1843 KAEvent::OccurOption includeRepetitions)
const
1846 TQDateTime pre = preDateTime;
1847 if (includeRepetitions != IGNORE_REPETITION)
1849 if (!mRepeatCount || !mRepeatInterval)
1850 includeRepetitions = IGNORE_REPETITION;
1853 repeatSecs = mRepeatInterval * 60;
1854 pre = preDateTime.addSecs(-mRepeatCount * repeatSecs);
1859 bool recurs = (checkRecur() != KARecurrence::NO_RECUR);
1861 type = nextRecurrence(pre, result);
1862 else if (pre < mNextMainDateTime.dateTime())
1864 result = mNextMainDateTime;
1865 type = FIRST_OR_ONLY_OCCURRENCE;
1869 result = DateTime();
1870 type = NO_OCCURRENCE;
1873 if (type != NO_OCCURRENCE && result <= preDateTime && includeRepetitions != IGNORE_REPETITION)
1876 int repetition = result.secsTo(preDateTime) / repeatSecs + 1;
1877 DateTime repeatDT = result.addSecs(repetition * repeatSecs);
1885 OccurType newType = previousOccurrence(repeatDT.dateTime(), dt,
false);
1890 if (includeRepetitions == RETURN_REPETITION && result <= preDateTime)
1893 int repetition = result.secsTo(preDateTime) / repeatSecs + 1;
1894 result = result.addSecs(repetition * repeatSecs);
1895 type =
static_cast<OccurType
>(type | OCCURRENCE_REPEAT);
1900 if (includeRepetitions == RETURN_REPETITION)
1904 type =
static_cast<OccurType
>(type | OCCURRENCE_REPEAT);
1917 KAEvent::OccurType KAEvent::previousOccurrence(
const TQDateTime& afterDateTime, DateTime& result,
bool includeRepetitions)
const
1919 if (mStartDateTime >= afterDateTime)
1921 result = TQDateTime();
1922 return NO_OCCURRENCE;
1927 if (checkRecur() == KARecurrence::NO_RECUR)
1929 result = mStartDateTime;
1930 type = FIRST_OR_ONLY_OCCURRENCE;
1934 TQDateTime recurStart = mRecurrence->startDateTime();
1935 TQDateTime after = afterDateTime;
1936 if (mStartDateTime.isDateOnly() && afterDateTime.time() > Preferences::startOfDay())
1937 after = after.addDays(1);
1938 TQDateTime dt = mRecurrence->getPreviousDateTime(after);
1939 result.set(dt, mStartDateTime.isDateOnly());
1941 return NO_OCCURRENCE;
1942 if (dt == recurStart)
1943 type = FIRST_OR_ONLY_OCCURRENCE;
1944 else if (mRecurrence->getNextDateTime(dt).isValid())
1945 type = result.isDateOnly() ? RECURRENCE_DATE : RECURRENCE_DATE_TIME;
1947 type = LAST_RECURRENCE;
1950 if (includeRepetitions && mRepeatCount)
1955 int repeatSecs = mRepeatInterval * 60;
1956 DateTime lastRepetition = result.addSecs(mRepeatCount * repeatSecs);
1957 if (lastRepetition < afterDateTime)
1959 result = lastRepetition;
1960 return static_cast<OccurType
>(type | OCCURRENCE_REPEAT);
1962 int repetition = (result.dateTime().secsTo(afterDateTime) - 1) / repeatSecs;
1965 result = result.addSecs(repetition * repeatSecs);
1966 return static_cast<OccurType
>(type | OCCURRENCE_REPEAT);
1980 KAEvent::OccurType KAEvent::setNextOccurrence(
const TQDateTime& preDateTime)
1982 if (preDateTime < mNextMainDateTime.dateTime())
1983 return FIRST_OR_ONLY_OCCURRENCE;
1984 TQDateTime pre = preDateTime;
1988 if (mRepeatCount && mRepeatInterval)
1989 pre = preDateTime.addSecs(-mRepeatCount * mRepeatInterval * 60);
1993 if (pre < mNextMainDateTime.dateTime())
1995 dt = mNextMainDateTime;
1996 type = FIRST_OR_ONLY_OCCURRENCE;
1998 else if (checkRecur() != KARecurrence::NO_RECUR)
2000 type = nextRecurrence(pre, dt);
2001 if (type == NO_OCCURRENCE)
2002 return NO_OCCURRENCE;
2003 if (type != FIRST_OR_ONLY_OCCURRENCE && dt != mNextMainDateTime)
2006 mNextMainDateTime = dt;
2008 if (mDeferral == REMINDER_DEFERRAL || mArchiveReminderMinutes)
2010 if (mReminderOnceOnly)
2012 if (mReminderMinutes)
2013 set_archiveReminder();
2016 set_reminder(mArchiveReminderMinutes);
2018 if (mDeferral == REMINDER_DEFERRAL)
2019 set_deferral(NO_DEFERRAL);
2024 return NO_OCCURRENCE;
2026 if (mRepeatCount && mRepeatInterval)
2028 int secs = dt.dateTime().secsTo(preDateTime);
2032 type =
static_cast<OccurType
>(type | OCCURRENCE_REPEAT);
2033 mNextRepeat = (secs / (60 * mRepeatInterval)) + 1;
2035 if (mReminderMinutes)
2036 set_archiveReminder();
2037 if (mDeferral == REMINDER_DEFERRAL)
2038 set_deferral(NO_DEFERRAL);
2041 else if (mNextRepeat)
2056 KAEvent::OccurType KAEvent::nextRecurrence(
const TQDateTime& preDateTime, DateTime& result)
const
2058 TQDateTime recurStart = mRecurrence->startDateTime();
2059 TQDateTime pre = preDateTime;
2060 if (mStartDateTime.isDateOnly() && preDateTime.time() < Preferences::startOfDay())
2062 pre = pre.addDays(-1);
2063 pre.setTime(Preferences::startOfDay());
2065 TQDateTime dt = mRecurrence->getNextDateTime(pre);
2066 result.set(dt, mStartDateTime.isDateOnly());
2068 return NO_OCCURRENCE;
2069 if (dt == recurStart)
2070 return FIRST_OR_ONLY_OCCURRENCE;
2071 if (mRecurrence->duration() >= 0 && dt == mRecurrence->endDateTime())
2072 return LAST_RECURRENCE;
2073 return result.isDateOnly() ? RECURRENCE_DATE : RECURRENCE_DATE_TIME;
2079 TQString KAEvent::recurrenceText(
bool brief)
const
2082 return brief ? i18n(
"Brief form of 'At Login'",
"Login") : i18n(
"At login");
2085 int frequency = mRecurrence->frequency();
2086 switch (mRecurrence->defaultRRuleConst()->recurrenceType())
2088 case RecurrenceRule::rMinutely:
2090 return i18n(
"1 Minute",
"%n Minutes", frequency);
2091 else if (frequency % 60 == 0)
2092 return i18n(
"1 Hour",
"%n Hours", frequency/60);
2096 return i18n(
"Hours and Minutes",
"%1H %2M").arg(TQString::number(frequency/60)).arg(mins.sprintf(
"%02d", frequency%60));
2098 case RecurrenceRule::rDaily:
2099 return i18n(
"1 Day",
"%n Days", frequency);
2100 case RecurrenceRule::rWeekly:
2101 return i18n(
"1 Week",
"%n Weeks", frequency);
2102 case RecurrenceRule::rMonthly:
2103 return i18n(
"1 Month",
"%n Months", frequency);
2104 case RecurrenceRule::rYearly:
2105 return i18n(
"1 Year",
"%n Years", frequency);
2106 case RecurrenceRule::rNone:
2111 return brief ? TQString() : i18n(
"None");
2117 TQString KAEvent::repetitionText(
bool brief)
const
2121 if (mRepeatInterval % 1440)
2123 if (mRepeatInterval < 60)
2124 return i18n(
"1 Minute",
"%n Minutes", mRepeatInterval);
2125 if (mRepeatInterval % 60 == 0)
2126 return i18n(
"1 Hour",
"%n Hours", mRepeatInterval/60);
2128 return i18n(
"Hours and Minutes",
"%1H %2M").arg(TQString::number(mRepeatInterval/60)).arg(mins.sprintf(
"%02d", mRepeatInterval%60));
2130 if (mRepeatInterval % (7*1440))
2131 return i18n(
"1 Day",
"%n Days", mRepeatInterval/1440);
2132 return i18n(
"1 Week",
"%n Weeks", mRepeatInterval/(7*1440));
2134 return brief ? TQString() : i18n(
"None");
2142 void KAEvent::setFirstRecurrence()
2144 switch (checkRecur())
2146 case KARecurrence::NO_RECUR:
2147 case KARecurrence::MINUTELY:
2149 case KARecurrence::ANNUAL_DATE:
2150 case KARecurrence::ANNUAL_POS:
2151 if (mRecurrence->yearMonths().isEmpty())
2154 case KARecurrence::DAILY:
2155 case KARecurrence::WEEKLY:
2156 case KARecurrence::MONTHLY_POS:
2157 case KARecurrence::MONTHLY_DAY:
2160 TQDateTime recurStart = mRecurrence->startDateTime();
2161 if (mRecurrence->recursOn(recurStart.date()))
2165 int frequency = mRecurrence->frequency();
2166 mRecurrence->setFrequency(1);
2168 nextRecurrence(mNextMainDateTime.dateTime(), next);
2169 if (!next.isValid())
2170 mRecurrence->setStartDateTime(recurStart);
2173 mRecurrence->setStartDateTime(next.dateTime());
2174 mStartDateTime = mNextMainDateTime = next;
2177 mRecurrence->setFrequency(frequency);
2184 void KAEvent::setRecurrence(
const KARecurrence& recurrence)
2188 if (recurrence.doesRecur())
2190 mRecurrence =
new KARecurrence(recurrence);
2191 mRecurrence->setStartDateTime(mStartDateTime.dateTime());
2192 mRecurrence->setFloats(mStartDateTime.isDateOnly());
2198 setRepetition(mRepeatInterval, mRepeatCount);
2206 bool KAEvent::setRepetition(
int interval,
int count)
2209 mRepeatInterval = 0;
2212 if (interval > 0 && count > 0 && !mRepeatAtLogin)
2214 Q_ASSERT(checkRecur() != KARecurrence::NO_RECUR);
2215 if (interval % 1440 && mStartDateTime.isDateOnly())
2217 if (checkRecur() != KARecurrence::NO_RECUR)
2219 int longestInterval = mRecurrence->longestInterval() - 1;
2220 if (interval * count > longestInterval)
2221 count = longestInterval / interval;
2223 mRepeatInterval = interval;
2224 mRepeatCount = count;
2239 bool KAEvent::setRecurMinutely(
int freq,
int count,
const TQDateTime& end)
2241 return setRecur(RecurrenceRule::rMinutely, freq, count, end);
2255 bool KAEvent::setRecurDaily(
int freq,
const TQBitArray& days,
int count,
const TQDate& end)
2257 if (!setRecur(RecurrenceRule::rDaily, freq, count, end))
2260 for (
int i = 0; i < 7; ++i)
2262 if (days.testBit(i))
2266 mRecurrence->addWeeklyDays(days);
2281 bool KAEvent::setRecurWeekly(
int freq,
const TQBitArray& days,
int count,
const TQDate& end)
2283 if (!setRecur(RecurrenceRule::rWeekly, freq, count, end))
2285 mRecurrence->addWeeklyDays(days);
2300 bool KAEvent::setRecurMonthlyByDate(
int freq,
const TQValueList<int>& days,
int count,
const TQDate& end)
2302 if (!setRecur(RecurrenceRule::rMonthly, freq, count, end))
2304 for (TQValueListConstIterator<int> it = days.begin(); it != days.end(); ++it)
2305 mRecurrence->addMonthlyDate(*it);
2321 bool KAEvent::setRecurMonthlyByPos(
int freq,
const TQValueList<MonthPos>& posns,
int count,
const TQDate& end)
2323 if (!setRecur(RecurrenceRule::rMonthly, freq, count, end))
2325 for (TQValueListConstIterator<MonthPos> it = posns.begin(); it != posns.end(); ++it)
2326 mRecurrence->addMonthlyPos((*it).weeknum, (*it).days);
2344 bool KAEvent::setRecurAnnualByDate(
int freq,
const TQValueList<int>& months,
int day, KARecurrence::Feb29Type feb29,
int count,
const TQDate& end)
2346 if (!setRecur(RecurrenceRule::rYearly, freq, count, end, feb29))
2348 for (TQValueListConstIterator<int> it = months.begin(); it != months.end(); ++it)
2349 mRecurrence->addYearlyMonth(*it);
2351 mRecurrence->addMonthlyDate(day);
2368 bool KAEvent::setRecurAnnualByPos(
int freq,
const TQValueList<MonthPos>& posns,
const TQValueList<int>& months,
int count,
const TQDate& end)
2370 if (!setRecur(RecurrenceRule::rYearly, freq, count, end))
2372 for (TQValueListConstIterator<int> it = months.begin(); it != months.end(); ++it)
2373 mRecurrence->addYearlyMonth(*it);
2374 for (TQValueListConstIterator<MonthPos> it = posns.begin(); it != posns.end(); ++it)
2375 mRecurrence->addYearlyPos((*it).weeknum, (*it).days);
2389 bool KAEvent::setRecur(
RecurrenceRule::PeriodType recurType,
int freq,
int count,
const TQDateTime& end, KARecurrence::Feb29Type feb29)
2391 if (count >= -1 && (count || end.date().isValid()))
2394 mRecurrence =
new KARecurrence;
2395 if (mRecurrence->init(recurType, freq, count, mNextMainDateTime, end, feb29))
2408 void KAEvent::clearRecur()
2412 mRepeatInterval = 0;
2423 KARecurrence::Type KAEvent::checkRecur()
const
2427 KARecurrence::Type type = mRecurrence->type();
2430 case KARecurrence::MINUTELY:
2431 case KARecurrence::DAILY:
2432 case KARecurrence::WEEKLY:
2433 case KARecurrence::MONTHLY_DAY:
2434 case KARecurrence::MONTHLY_POS:
2435 case KARecurrence::ANNUAL_DATE:
2436 case KARecurrence::ANNUAL_POS:
2440 const_cast<KAEvent*
>(
this)->clearRecur();
2444 return KARecurrence::NO_RECUR;
2451 int KAEvent::recurInterval()
const
2455 switch (mRecurrence->type())
2457 case KARecurrence::MINUTELY:
2458 case KARecurrence::DAILY:
2459 case KARecurrence::WEEKLY:
2460 case KARecurrence::MONTHLY_DAY:
2461 case KARecurrence::MONTHLY_POS:
2462 case KARecurrence::ANNUAL_DATE:
2463 case KARecurrence::ANNUAL_POS:
2464 return mRecurrence->frequency();
2476 void KAEvent::checkRepetition()
const
2478 if (mRepeatCount && !mRepeatInterval)
2479 const_cast<KAEvent*
>(
this)->mRepeatCount = 0;
2480 if (!mRepeatCount && mRepeatInterval)
2481 const_cast<KAEvent*
>(
this)->mRepeatInterval = 0;
2488 TQValueList<KAEvent::MonthPos> KAEvent::convRecurPos(
const TQValueList<KCal::RecurrenceRule::WDayPos>& wdaypos)
2490 TQValueList<MonthPos> mposns;
2491 for (TQValueList<KCal::RecurrenceRule::WDayPos>::ConstIterator it = wdaypos.begin(); it != wdaypos.end(); ++it)
2493 int daybit = (*it).day() - 1;
2494 int weeknum = (*it).pos();
2496 for (TQValueList<MonthPos>::Iterator mit = mposns.begin(); mit != mposns.end(); ++mit)
2498 if ((*mit).weeknum == weeknum)
2500 (*mit).days.setBit(daybit);
2508 mpos.days.fill(
false);
2509 mpos.days.setBit(daybit);
2510 mpos.weeknum = weeknum;
2511 mposns.append(mpos);
2525 Event::List events = calendar.events();
2526 for (Event::List::ConstIterator evit = events.begin(); evit != events.end(); ++evit)
2532 if (!event.isTemplate())
2546 bool KAEvent::adjustStartOfDay(
const Event::List& events)
2548 bool changed =
false;
2549 TQTime startOfDay = Preferences::startOfDay();
2550 for (Event::List::ConstIterator evit = events.begin(); evit != events.end(); ++evit)
2552 Event*
event = *evit;
2553 const TQStringList cats =
event->
categories();
2554 if (cats.find(DATE_ONLY_CATEGORY) != cats.end())
2557 TQTime oldTime =
event->dtStart().time();
2558 int adjustment = oldTime.secsTo(startOfDay);
2561 event->setDtStart(TQDateTime(event->dtStart().date(), startOfDay));
2562 Alarm::List alarms =
event->alarms();
2563 int deferralOffset = 0;
2564 for (Alarm::List::ConstIterator alit = alarms.begin(); alit != alarms.end(); ++alit)
2567 Alarm& alarm = **alit;
2569 readAlarm(alarm, data);
2570 if (data.type & KAAlarm::TIMED_DEFERRAL_FLAG)
2576 else if (data.type == KAAlarm::AUDIO__ALARM
2589 int deferralOffset = 0;
2590 int newDeferralOffset = 0;
2592 TQDateTime nextMainDateTime = readDateTime(*event,
false, start).rawDateTime();
2594 readAlarms(*event, &alarmMap);
2595 for (AlarmMap::Iterator it = alarmMap.begin(); it != alarmMap.end(); ++it)
2597 const AlarmData& data = it.data();
2598 if (!data.alarm->hasStartOffset())
2600 if ((data.type & KAAlarm::DEFERRED_ALARM)
2601 && !(data.type & KAAlarm::TIMED_DEFERRAL_FLAG))
2604 TQDateTime altime = nextMainDateTime.addSecs(data.alarm->startOffset().asSeconds());
2605 altime.setTime(startOfDay);
2606 deferralOffset = data.alarm->startOffset().asSeconds();
2607 newDeferralOffset =
event->dtStart().secsTo(altime);
2608 const_cast<Alarm*
>(data.alarm)->setStartOffset(newDeferralOffset);
2611 else if (data.type == KAAlarm::AUDIO__ALARM
2612 && data.alarm->startOffset().asSeconds() == deferralOffset)
2615 const_cast<Alarm*
>(data.alarm)->setStartOffset(newDeferralOffset);
2629 void KAEvent::convertKCalEvents(
KCal::Calendar& calendar,
int version,
bool adjustSummerTime)
2632 static const TQChar SEPARATOR =
';';
2633 static const TQChar LATE_CANCEL_CODE =
'C';
2634 static const TQChar AT_LOGIN_CODE =
'L';
2635 static const TQChar DEFERRAL_CODE =
'D';
2636 static const TQString TEXT_PREFIX = TQString::fromLatin1(
"TEXT:");
2637 static const TQString FILE_PREFIX = TQString::fromLatin1(
"FILE:");
2638 static const TQString COMMAND_PREFIX = TQString::fromLatin1(
"CMD:");
2641 static const TQString BEEP_CATEGORY = TQString::fromLatin1(
"BEEP");
2644 static const TQString LATE_CANCEL_CAT = TQString::fromLatin1(
"LATECANCEL");
2647 static const TQString TEMPL_DEF_TIME_CAT = TQString::fromLatin1(
"TMPLDEFTIME");
2650 static const TQString EXEC_IN_XTERM_CAT = TQString::fromLatin1(
"XTERM");
2653 static const TQCString KMAIL_ID_PROPERTY(
"KMAILID");
2655 if (version >= calVersion())
2658 kdDebug(5950) <<
"KAEvent::convertKCalEvents(): adjusting version " << version << endl;
2659 bool pre_0_7 = (version < KAlarm::Version(0,7,0));
2660 bool pre_0_9 = (version < KAlarm::Version(0,9,0));
2661 bool pre_0_9_2 = (version < KAlarm::Version(0,9,2));
2662 bool pre_1_1_1 = (version < KAlarm::Version(1,1,1));
2663 bool pre_1_2_1 = (version < KAlarm::Version(1,2,1));
2664 bool pre_1_3_0 = (version < KAlarm::Version(1,3,0));
2665 bool pre_1_3_1 = (version < KAlarm::Version(1,3,1));
2666 bool pre_1_4_14 = (version < KAlarm::Version(1,4,14));
2667 bool pre_1_5_0 = (version < KAlarm::Version(1,5,0));
2668 Q_ASSERT(calVersion() == KAlarm::Version(1,5,0));
2670 TQDateTime dt0(TQDate(1970,1,1), TQTime(0,0,0));
2671 TQTime startOfDay = Preferences::startOfDay();
2673 Event::List events = calendar.
rawEvents();
2674 for (Event::List::ConstIterator evit = events.begin(); evit != events.end(); ++evit)
2676 Event*
event = *evit;
2677 Alarm::List alarms =
event->
alarms();
2678 if (alarms.isEmpty())
2680 TQStringList cats =
event->categories();
2681 bool addLateCancel =
false;
2683 if (pre_0_7 && event->doesFloat())
2687 event->setFloats(
false);
2704 for (Alarm::List::ConstIterator alit = alarms.begin(); alit != alarms.end(); ++alit)
2706 Alarm* alarm = *alit;
2707 bool atLogin =
false;
2708 bool deferral =
false;
2709 bool lateCancel =
false;
2710 KAAlarmEventBase::Type action = T_MESSAGE;
2711 TQString txt = alarm->
text();
2712 int length = txt.length();
2714 if (txt[0].isDigit())
2716 while (++i < length && txt[i].isDigit()) ;
2717 if (i < length && txt[i++] == SEPARATOR)
2721 TQChar ch = txt[i++];
2722 if (ch == SEPARATOR)
2724 if (ch == LATE_CANCEL_CODE)
2726 else if (ch == AT_LOGIN_CODE)
2728 else if (ch == DEFERRAL_CODE)
2735 if (txt.find(TEXT_PREFIX, i) == i)
2736 i += TEXT_PREFIX.length();
2737 else if (txt.find(FILE_PREFIX, i) == i)
2740 i += FILE_PREFIX.length();
2742 else if (txt.find(COMMAND_PREFIX, i) == i)
2745 i += COMMAND_PREFIX.length();
2761 setProcedureAlarm(alarm, txt);
2769 types += AT_LOGIN_TYPE;
2773 types += TIME_DEFERRAL_TYPE;
2775 addLateCancel =
true;
2776 if (types.count() > 0)
2793 if (adjustSummerTime)
2797 TQDateTime dt = alarm->
time();
2798 time_t t = dt0.secsTo(dt);
2799 struct tm* dtm = localtime(&t);
2802 dt = dt.addSecs(-3600);
2821 if (uidStatus(event->uid()) == EXPIRED)
2822 event->setCreated(event->dtEnd());
2823 TQDateTime start =
event->dtStart();
2824 if (event->doesFloat())
2826 event->setFloats(
false);
2827 start.setTime(startOfDay);
2828 cats.append(DATE_ONLY_CATEGORY);
2830 event->setHasEndDate(
false);
2832 Alarm::List::ConstIterator alit;
2833 for (alit = alarms.begin(); alit != alarms.end(); ++alit)
2835 Alarm* alarm = *alit;
2836 TQDateTime dt = alarm->
time();
2840 if (cats.count() > 0)
2842 for (alit = alarms.begin(); alit != alarms.end(); ++alit)
2844 Alarm* alarm = *alit;
2845 if (alarm->
type() == Alarm::Display)
2847 TQString::fromLatin1(
"%1;;").arg(cats[0]));
2849 cats.remove(cats.begin());
2852 for (TQStringList::Iterator it = cats.begin(); it != cats.end(); ++it)
2854 if (*it == BEEP_CATEGORY)
2858 Alarm* alarm =
event->newAlarm();
2861 TQDateTime dt =
event->dtStart();
2865 readAlarms(*event, &alarmMap);
2866 AlarmMap::ConstIterator it = alarmMap.begin();
2867 if (it != alarmMap.end())
2869 dt = it.data().alarm->time();
2884 TQStringList::Iterator it;
2885 while ((it = cats.find(LATE_CANCEL_CAT)) != cats.end())
2888 addLateCancel =
true;
2898 for (Alarm::List::ConstIterator alit = alarms.begin(); alit != alarms.end(); ++alit)
2900 Alarm* alarm = *alit;
2901 if (alarm->
type() == Alarm::Display)
2903 TQString oldtext = alarm->
text();
2904 TQString newtext = AlarmText::toCalendarText(oldtext);
2905 if (oldtext != newtext)
2917 TQStringList::Iterator it;
2918 while ((it = cats.find(TEMPL_DEF_TIME_CAT)) != cats.end())
2921 cats.append(TQString(
"%1%2").arg(TEMPL_AFTER_TIME_CATEGORY).arg(0));
2931 TQStringList::Iterator it;
2932 while ((it = cats.find(EXEC_IN_XTERM_CAT)) != cats.end())
2935 cats.append(LOG_CATEGORY + xtermURL);
2940 cats.append(TQString(
"%1%2").arg(LATE_CANCEL_CATEGORY).arg(1));
2942 event->setCategories(cats);
2946 && event->recurrence() && event->recurrence()->doesRecur())
2955 bool dateOnly = (cats.find(DATE_ONLY_CATEGORY) != cats.end());
2956 DateTime startDateTime(event->dtStart(), dateOnly);
2958 DateTime nextMainDateTime;
2959 bool mainExpired =
true;
2960 Alarm::List::ConstIterator alit;
2961 for (alit = alarms.begin(); alit != alarms.end(); ++alit)
2963 Alarm* alarm = *alit;
2966 bool mainAlarm =
true;
2967 TQString
property = alarm->
customProperty(APPNAME, TYPE_PROPERTY);
2968 TQStringList types = TQStringList::split(TQChar(
','), property);
2969 for (
unsigned int i = 0; i < types.count(); ++i)
2971 TQString type = types[i];
2972 if (type == AT_LOGIN_TYPE
2973 || type == TIME_DEFERRAL_TYPE
2974 || type == DATE_DEFERRAL_TYPE
2975 || type == REMINDER_TYPE
2976 || type == REMINDER_ONCE_TYPE
2977 || type == DISPLAYING_TYPE
2978 || type == PRE_ACTION_TYPE
2979 || type == POST_ACTION_TYPE)
2984 mainExpired =
false;
2985 nextMainDateTime = alarm->
time();
2986 nextMainDateTime.setDateOnly(dateOnly);
2987 if (nextMainDateTime != startDateTime)
2989 TQDateTime dt = nextMainDateTime.dateTime();
2990 event->setCustomProperty(APPNAME, NEXT_RECUR_PROPERTY,
2991 dt.toString(dateOnly ?
"yyyyMMdd" :
"yyyyMMddThhmmss"));
3002 DateTime dt =
event->recurrence()->getNextDateTime(startDateTime.dateTime().addDays(-1));
3003 dt.setDateOnly(dateOnly);
3004 adjustment = startDateTime.secsTo(dt);
3007 adjustment = startDateTime.secsTo(nextMainDateTime);
3011 for (alit = alarms.begin(); alit != alarms.end(); ++alit)
3013 Alarm* alarm = *alit;
3016 TQString
property = alarm->
customProperty(APPNAME, TYPE_PROPERTY);
3017 TQStringList types = TQStringList::split(TQChar(
','), property);
3018 for (
unsigned int i = 0; i < types.count(); ++i)
3020 TQString type = types[i];
3021 if (type == TIME_DEFERRAL_TYPE
3022 || type == DATE_DEFERRAL_TYPE)
3039 for (Alarm::List::ConstIterator alit = alarms.begin(); alit != alarms.end(); ++alit)
3041 Alarm* alarm = *alit;
3042 TQString name = alarm->
customProperty(APPNAME, KMAIL_ID_PROPERTY);
3045 uint
id = KAMail::identityUoid(name);
3050 convertRepetition(event);
3064 Event::List events = calendar.
rawEvents();
3065 for (Event::List::ConstIterator ev = events.begin(); ev != events.end(); ++ev)
3066 convertRepetition(*ev);
3077 bool KAEvent::convertRepetition(
KCal::Event* event)
3079 Alarm::List alarms =
event->alarms();
3080 if (alarms.isEmpty())
3085 bool converted =
false;
3086 bool readOnly =
event->isReadOnly();
3087 for (Alarm::List::ConstIterator alit = alarms.begin(); alit != alarms.end(); ++alit)
3089 Alarm* alarm = *alit;
3095 event->setReadOnly(
false);
3110 event->setReadOnly(
true);
3116 void KAEvent::dumpDebug()
const
3118 kdDebug(5950) <<
"KAEvent dump:\n";
3119 KAAlarmEventBase::dumpDebug();
3120 if (!mTemplateName.isEmpty())
3122 kdDebug(5950) <<
"-- mTemplateName:" << mTemplateName <<
":\n";
3123 kdDebug(5950) <<
"-- mTemplateAfterTime:" << mTemplateAfterTime <<
":\n";
3125 if (mActionType == T_MESSAGE || mActionType == T_FILE)
3127 kdDebug(5950) <<
"-- mAudioFile:" << mAudioFile <<
":\n";
3128 kdDebug(5950) <<
"-- mPreAction:" << mPreAction <<
":\n";
3129 kdDebug(5950) <<
"-- mPostAction:" << mPostAction <<
":\n";
3131 else if (mActionType == T_COMMAND)
3133 kdDebug(5950) <<
"-- mCommandXterm:" << (mCommandXterm ?
"true" :
"false") <<
":\n";
3134 kdDebug(5950) <<
"-- mLogFile:" << mLogFile <<
":\n";
3136 kdDebug(5950) <<
"-- mKMailSerialNumber:" << mKMailSerialNumber <<
":\n";
3137 kdDebug(5950) <<
"-- mCopyToKOrganizer:" << (mCopyToKOrganizer ?
"true" :
"false") <<
":\n";
3138 kdDebug(5950) <<
"-- mStartDateTime:" << mStartDateTime.toString() <<
":\n";
3139 kdDebug(5950) <<
"-- mSaveDateTime:" << mSaveDateTime.toString() <<
":\n";
3141 kdDebug(5950) <<
"-- mAtLoginDateTime:" << mAtLoginDateTime.toString() <<
":\n";
3142 kdDebug(5950) <<
"-- mArchiveRepeatAtLogin:" << (mArchiveRepeatAtLogin ?
"true" :
"false") <<
":\n";
3143 kdDebug(5950) <<
"-- mEnabled:" << (mEnabled ?
"true" :
"false") <<
":\n";
3144 if (mReminderMinutes)
3145 kdDebug(5950) <<
"-- mReminderMinutes:" << mReminderMinutes <<
":\n";
3146 if (mArchiveReminderMinutes)
3147 kdDebug(5950) <<
"-- mArchiveReminderMinutes:" << mArchiveReminderMinutes <<
":\n";
3148 if (mReminderMinutes || mArchiveReminderMinutes)
3149 kdDebug(5950) <<
"-- mReminderOnceOnly:" << mReminderOnceOnly <<
":\n";
3150 else if (mDeferral > 0)
3152 kdDebug(5950) <<
"-- mDeferral:" << (mDeferral == NORMAL_DEFERRAL ?
"normal" :
"reminder") <<
":\n";
3153 kdDebug(5950) <<
"-- mDeferralTime:" << mDeferralTime.toString() <<
":\n";
3155 else if (mDeferral == CANCEL_DEFERRAL)
3156 kdDebug(5950) <<
"-- mDeferral:cancel:\n";
3157 kdDebug(5950) <<
"-- mDeferDefaultMinutes:" << mDeferDefaultMinutes <<
":\n";
3160 kdDebug(5950) <<
"-- mDisplayingTime:" << mDisplayingTime.toString() <<
":\n";
3161 kdDebug(5950) <<
"-- mDisplayingFlags:" << mDisplayingFlags <<
":\n";
3163 kdDebug(5950) <<
"-- mRevision:" << mRevision <<
":\n";
3164 kdDebug(5950) <<
"-- mRecurrence:" << (mRecurrence ?
"true" :
"false") <<
":\n";
3165 kdDebug(5950) <<
"-- mAlarmCount:" << mAlarmCount <<
":\n";
3166 kdDebug(5950) <<
"-- mMainExpired:" << (mMainExpired ?
"true" :
"false") <<
":\n";
3167 kdDebug(5950) <<
"KAEvent dump end\n";
3177 KAAlarm::KAAlarm(
const KAAlarm& alarm)
3178 : KAAlarmEventBase(alarm),
3180 mRecurs(alarm.mRecurs),
3181 mDeferred(alarm.mDeferred)
3185 int KAAlarm::flags()
const
3187 return KAAlarmEventBase::flags()
3188 | (mDeferred ? KAEvent::DEFERRAL : 0);
3193 void KAAlarm::dumpDebug()
const
3195 kdDebug(5950) <<
"KAAlarm dump:\n";
3196 KAAlarmEventBase::dumpDebug();
3197 const char* altype = 0;
3200 case MAIN__ALARM: altype =
"MAIN";
break;
3201 case REMINDER__ALARM: altype =
"REMINDER";
break;
3202 case DEFERRED_DATE__ALARM: altype =
"DEFERRED(DATE)";
break;
3203 case DEFERRED_TIME__ALARM: altype =
"DEFERRED(TIME)";
break;
3204 case DEFERRED_REMINDER_DATE__ALARM: altype =
"DEFERRED_REMINDER(DATE)";
break;
3205 case DEFERRED_REMINDER_TIME__ALARM: altype =
"DEFERRED_REMINDER(TIME)";
break;
3206 case AT_LOGIN__ALARM: altype =
"LOGIN";
break;
3207 case DISPLAYING__ALARM: altype =
"DISPLAYING";
break;
3208 case AUDIO__ALARM: altype =
"AUDIO";
break;
3209 case PRE_ACTION__ALARM: altype =
"PRE_ACTION";
break;
3210 case POST_ACTION__ALARM: altype =
"POST_ACTION";
break;
3211 default: altype =
"INVALID";
break;
3213 kdDebug(5950) <<
"-- mType:" << altype <<
":\n";
3214 kdDebug(5950) <<
"-- mRecurs:" << (mRecurs ?
"true" :
"false") <<
":\n";
3215 kdDebug(5950) <<
"-- mDeferred:" << (mDeferred ?
"true" :
"false") <<
":\n";
3216 kdDebug(5950) <<
"KAAlarm dump end\n";
3219 const char* KAAlarm::debugType(Type type)
3223 case MAIN_ALARM:
return "MAIN";
3224 case REMINDER_ALARM:
return "REMINDER";
3225 case DEFERRED_ALARM:
return "DEFERRED";
3226 case DEFERRED_REMINDER_ALARM:
return "DEFERRED_REMINDER";
3227 case AT_LOGIN_ALARM:
return "LOGIN";
3228 case DISPLAYING_ALARM:
return "DISPLAYING";
3229 case AUDIO_ALARM:
return "AUDIO";
3230 case PRE_ACTION_ALARM:
return "PRE_ACTION";
3231 case POST_ACTION_ALARM:
return "POST_ACTION";
3232 default:
return "INVALID";
3242 void KAAlarmEventBase::copy(
const KAAlarmEventBase& rhs)
3244 mEventID = rhs.mEventID;
3246 mNextMainDateTime = rhs.mNextMainDateTime;
3247 mBgColour = rhs.mBgColour;
3248 mFgColour = rhs.mFgColour;
3250 mEmailFromIdentity = rhs.mEmailFromIdentity;
3251 mEmailAddresses = rhs.mEmailAddresses;
3252 mEmailSubject = rhs.mEmailSubject;
3253 mEmailAttachments = rhs.mEmailAttachments;
3254 mSoundVolume = rhs.mSoundVolume;
3255 mFadeVolume = rhs.mFadeVolume;
3256 mFadeSeconds = rhs.mFadeSeconds;
3257 mActionType = rhs.mActionType;
3258 mCommandScript = rhs.mCommandScript;
3259 mRepeatCount = rhs.mRepeatCount;
3260 mRepeatInterval = rhs.mRepeatInterval;
3261 mNextRepeat = rhs.mNextRepeat;
3263 mSpeak = rhs.mSpeak;
3264 mRepeatSound = rhs.mRepeatSound;
3265 mRepeatAtLogin = rhs.mRepeatAtLogin;
3266 mDisplaying = rhs.mDisplaying;
3267 mLateCancel = rhs.mLateCancel;
3268 mAutoClose = rhs.mAutoClose;
3269 mEmailBcc = rhs.mEmailBcc;
3270 mConfirmAck = rhs.mConfirmAck;
3271 mDefaultFont = rhs.mDefaultFont;
3274 void KAAlarmEventBase::set(
int flags)
3276 mSpeak = flags & KAEvent::SPEAK;
3277 mBeep = (flags & KAEvent::BEEP) && !mSpeak;
3278 mRepeatSound = flags & KAEvent::REPEAT_SOUND;
3279 mRepeatAtLogin = flags & KAEvent::REPEAT_AT_LOGIN;
3280 mAutoClose = (flags & KAEvent::AUTO_CLOSE) && mLateCancel;
3281 mEmailBcc = flags & KAEvent::EMAIL_BCC;
3282 mConfirmAck = flags & KAEvent::CONFIRM_ACK;
3283 mDisplaying = flags & KAEvent::DISPLAYING_;
3284 mDefaultFont = flags & KAEvent::DEFAULT_FONT;
3285 mCommandScript = flags & KAEvent::SCRIPT;
3288 int KAAlarmEventBase::flags()
const
3290 return (mBeep && !mSpeak ? KAEvent::BEEP : 0)
3291 | (mSpeak ? KAEvent::SPEAK : 0)
3292 | (mRepeatSound ? KAEvent::REPEAT_SOUND : 0)
3293 | (mRepeatAtLogin ? KAEvent::REPEAT_AT_LOGIN : 0)
3294 | (mAutoClose ? KAEvent::AUTO_CLOSE : 0)
3295 | (mEmailBcc ? KAEvent::EMAIL_BCC : 0)
3296 | (mConfirmAck ? KAEvent::CONFIRM_ACK : 0)
3297 | (mDisplaying ? KAEvent::DISPLAYING_ : 0)
3298 | (mDefaultFont ? KAEvent::DEFAULT_FONT : 0)
3299 | (mCommandScript ? KAEvent::SCRIPT : 0);
3302 const TQFont& KAAlarmEventBase::font()
const
3304 return mDefaultFont ? Preferences::messageFont() : mFont;
3308 void KAAlarmEventBase::dumpDebug()
const
3310 kdDebug(5950) <<
"-- mEventID:" << mEventID <<
":\n";
3311 kdDebug(5950) <<
"-- mActionType:" << (mActionType == T_MESSAGE ?
"MESSAGE" : mActionType == T_FILE ?
"FILE" : mActionType == T_COMMAND ?
"COMMAND" : mActionType == T_EMAIL ?
"EMAIL" : mActionType == T_AUDIO ?
"AUDIO" :
"??") <<
":\n";
3312 kdDebug(5950) <<
"-- mText:" << mText <<
":\n";
3313 if (mActionType == T_COMMAND)
3314 kdDebug(5950) <<
"-- mCommandScript:" << (mCommandScript ?
"true" :
"false") <<
":\n";
3315 kdDebug(5950) <<
"-- mNextMainDateTime:" << mNextMainDateTime.toString() <<
":\n";
3316 if (mActionType == T_EMAIL)
3318 kdDebug(5950) <<
"-- mEmail: FromKMail:" << mEmailFromIdentity <<
":\n";
3319 kdDebug(5950) <<
"-- Addresses:" << mEmailAddresses.join(
", ") <<
":\n";
3320 kdDebug(5950) <<
"-- Subject:" << mEmailSubject <<
":\n";
3321 kdDebug(5950) <<
"-- Attachments:" << mEmailAttachments.join(
", ") <<
":\n";
3322 kdDebug(5950) <<
"-- Bcc:" << (mEmailBcc ?
"true" :
"false") <<
":\n";
3324 kdDebug(5950) <<
"-- mBgColour:" << TQString(mBgColour.name()) <<
":\n";
3325 kdDebug(5950) <<
"-- mFgColour:" << TQString(mFgColour.name()) <<
":\n";
3326 kdDebug(5950) <<
"-- mDefaultFont:" << (mDefaultFont ?
"true" :
"false") <<
":\n";
3328 kdDebug(5950) <<
"-- mFont:" << TQString(mFont.toString()) <<
":\n";
3329 kdDebug(5950) <<
"-- mBeep:" << (mBeep ?
"true" :
"false") <<
":\n";
3330 kdDebug(5950) <<
"-- mSpeak:" << (mSpeak ?
"true" :
"false") <<
":\n";
3331 if (mActionType == T_AUDIO)
3333 if (mSoundVolume >= 0)
3335 kdDebug(5950) <<
"-- mSoundVolume:" << mSoundVolume <<
":\n";
3336 if (mFadeVolume >= 0)
3338 kdDebug(5950) <<
"-- mFadeVolume:" << mFadeVolume <<
":\n";
3339 kdDebug(5950) <<
"-- mFadeSeconds:" << mFadeSeconds <<
":\n";
3342 kdDebug(5950) <<
"-- mFadeVolume:-:\n";
3345 kdDebug(5950) <<
"-- mSoundVolume:-:\n";
3346 kdDebug(5950) <<
"-- mRepeatSound:" << (mRepeatSound ?
"true" :
"false") <<
":\n";
3348 kdDebug(5950) <<
"-- mConfirmAck:" << (mConfirmAck ?
"true" :
"false") <<
":\n";
3349 kdDebug(5950) <<
"-- mRepeatAtLogin:" << (mRepeatAtLogin ?
"true" :
"false") <<
":\n";
3350 kdDebug(5950) <<
"-- mRepeatCount:" << mRepeatCount <<
":\n";
3351 kdDebug(5950) <<
"-- mRepeatInterval:" << mRepeatInterval <<
":\n";
3352 kdDebug(5950) <<
"-- mNextRepeat:" << mNextRepeat <<
":\n";
3353 kdDebug(5950) <<
"-- mDisplaying:" << (mDisplaying ?
"true" :
"false") <<
":\n";
3354 kdDebug(5950) <<
"-- mLateCancel:" << mLateCancel <<
":\n";
3355 kdDebug(5950) <<
"-- mAutoClose:" << (mAutoClose ?
"true" :
"false") <<
":\n";
3368 EmailAddressList& EmailAddressList::operator=(
const TQValueList<Person>& addresses)
3371 for (TQValueList<Person>::ConstIterator it = addresses.begin(); it != addresses.end(); ++it)
3373 if (!(*it).email().isEmpty())
3383 TQString EmailAddressList::join(
const TQString& separator)
const
3387 for (TQValueList<Person>::ConstIterator it = begin(); it != end(); ++it)
3392 result += separator;
3395 TQString name = (*it).name();
3396 if (!name.isEmpty())
3399 int len = name.length();
3400 for (
int i = 0; i < len; ++i)
3402 TQChar ch = name[i];
3403 if (!ch.isLetterOrNumber())
3410 result += (*it).name();
3411 result += (quote ?
"\" <" :
" <");
3415 result += (*it).email();
3432 static void setProcedureAlarm(
Alarm* alarm,
const TQString& commandLine)
3434 TQString command = TQString();
3435 TQString arguments = TQString();
3437 bool quoted =
false;
3438 uint posMax = commandLine.length();
3440 for (pos = 0; pos < posMax; ++pos)
3442 TQChar ch = commandLine[pos];
3445 if (ch == quoteChar)
3462 done = !command.isEmpty();
3466 if (command.isEmpty())
3484 for ( ; pos < posMax && commandLine[pos] ==
' '; ++pos) ;
3485 arguments = commandLine.mid(pos);
represents calendar alarms and events
Provides read and write access to calendar files.
KAEvent corresponds to a KCal::Event instance.
Status
The category of an event, indicated by the middle part of its UID.
void setAudioAlarm(const TQString &audioFile=TQString())
bool hasStartOffset() const
TQString audioFile() const
Duration snoozeTime() const
TQString programFile() const
void setRepeatCount(int alarmRepeatCount)
TQString mailSubject() const
void setEnabled(bool enable)
void setDisplayAlarm(const TQString &text=TQString())
Duration startOffset() const
void setSnoozeTime(const Duration &alarmSnoozeTime)
TQString programArguments() const
void setEmailAlarm(const TQString &subject, const TQString &text, const TQValueList< Person > &addressees, const TQStringList &attachments=TQStringList())
TQString mailText() const
void setStartOffset(const Duration &)
TQValueList< Person > mailAddresses() const
void setTime(const TQDateTime &alarmTime)
void setProcedureAlarm(const TQString &programFile, const TQString &arguments=TQString())
TQStringList mailAttachments() const
Event::List rawEvents(EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
virtual Event::List rawEvents(EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)=0
void setCustomProperty(const TQCString &app, const TQCString &key, const TQString &value)
TQString customProperty(const TQCString &app, const TQCString &key) const
void removeCustomProperty(const TQCString &app, const TQCString &key)
TQDateTime end(const TQDateTime &start) const
void setTransparency(Transparency transparency)
void setUid(const TQString &)
virtual TQDateTime dtStart() const
TQString statusStr() const
void setReadOnly(bool readonly)
const Alarm::List & alarms() const
void setSummary(const TQString &summary)
void setCustomStatus(const TQString &status)
TQStringList categories() const
virtual void setDtStart(const TQDateTime &dtStart)
void setCategories(const TQStringList &categories)
Recurrence * recurrence() const
void setRevision(int rev)
void setCreated(const TQDateTime &)
void setMinutely(int freq)
void setDuration(int duration)
the KAlarm application object