• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.7 API Reference
  • KDE Home
  • Contact Us
 

KAlarm Library

  • kalarmcal
kaevent.cpp
1 /*
2  * kaevent.cpp - represents calendar events
3  * This file is part of kalarmcal library, which provides access to KAlarm
4  * calendar data.
5  * Copyright © 2001-2013 by David Jarvie <djarvie@kde.org>
6  *
7  * This library is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Library General Public License as published
9  * by the Free Software Foundation; either version 2 of the License, or (at
10  * your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15  * License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB. If not, write to the
19  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20  * MA 02110-1301, USA.
21  */
22 
23 #include "kaevent.h"
24 
25 #include "alarmtext.h"
26 #include "identities.h"
27 #include "version.h"
28 
29 #ifndef KALARMCAL_USE_KRESOURCES
30 #include <kcalcore/memorycalendar.h>
31 #else
32 #include <kcal/calendarlocal.h>
33 #endif
34 #include <kholidays/holidays.h>
35 using namespace KHolidays;
36 
37 #include <ksystemtimezone.h>
38 #include <klocalizedstring.h>
39 #ifdef KALARMCAL_USE_KRESOURCES
40 #include <ksharedconfig.h>
41 #include <kglobal.h>
42 #include <kconfiggroup.h>
43 #endif
44 #include <kglobal.h>
45 #include <kdebug.h>
46 
47 #ifndef KALARMCAL_USE_KRESOURCES
48 using namespace KCalCore;
49 #else
50 using namespace KCal;
51 #endif
52 using namespace KHolidays;
53 
54 namespace KAlarmCal
55 {
56 
57 //=============================================================================
58 
59 #ifndef KALARMCAL_USE_KRESOURCES
60 typedef KCalCore::Person EmailAddress;
61 class EmailAddressList : public KCalCore::Person::List
62 #else
63 typedef KCal::Person EmailAddress;
64 class EmailAddressList : public QList<KCal::Person>
65 #endif
66 {
67  public:
68 #ifndef KALARMCAL_USE_KRESOURCES
69  EmailAddressList() : KCalCore::Person::List() { }
70  EmailAddressList(const KCalCore::Person::List& list) { operator=(list); }
71  EmailAddressList& operator=(const KCalCore::Person::List&);
72 #else
73  EmailAddressList() : QList<KCal::Person>() { }
74  EmailAddressList(const QList<KCal::Person>& list) { operator=(list); }
75  EmailAddressList& operator=(const QList<KCal::Person>&);
76 #endif
77  operator QStringList() const;
78  QString join(const QString& separator) const;
79  QStringList pureAddresses() const;
80  QString pureAddresses(const QString& separator) const;
81  private:
82  QString address(int index) const;
83 };
84 
85 //=============================================================================
86 
87 class KAAlarm::Private
88 {
89  public:
90  Private();
91 
92  Action mActionType; // alarm action type
93  Type mType; // alarm type
94  DateTime mNextMainDateTime; // next time to display the alarm, excluding repetitions
95  Repetition mRepetition; // sub-repetition count and interval
96  int mNextRepeat; // repetition count of next due sub-repetition
97  bool mRepeatAtLogin; // whether to repeat the alarm at every login
98  bool mRecurs; // there is a recurrence rule for the alarm
99  bool mDeferred; // whether the alarm is an extra deferred/deferred-reminder alarm
100  bool mTimedDeferral; // if mDeferred = true: true if the deferral is timed, false if date-only
101 };
102 
103 //=============================================================================
104 
105 class KAEventPrivate : public QSharedData
106 {
107  public:
108  // Read-only internal flags additional to KAEvent::Flags enum values.
109  // NOTE: If any values are added to those in KAEvent::Flags, ensure
110  // that these values don't overlap them.
111  enum
112  {
113  REMINDER = 0x100000,
114  DEFERRAL = 0x200000,
115  TIMED_FLAG = 0x400000,
116  DATE_DEFERRAL = DEFERRAL,
117  TIME_DEFERRAL = DEFERRAL | TIMED_FLAG,
118  DISPLAYING_ = 0x800000,
119  READ_ONLY_FLAGS = 0xF00000
120  };
121  enum ReminderType // current active state of reminder
122  {
123  NO_REMINDER, // reminder is not due
124  ACTIVE_REMINDER, // reminder is due
125  HIDDEN_REMINDER // reminder-after is disabled due to main alarm being deferred past it
126  };
127  enum DeferType
128  {
129  NO_DEFERRAL = 0, // there is no deferred alarm
130  NORMAL_DEFERRAL, // the main alarm, a recurrence or a repeat is deferred
131  REMINDER_DEFERRAL // a reminder alarm is deferred
132  };
133  // Alarm types.
134  // This uses the same scheme as KAAlarm::Type, with some extra values.
135  // Note that the actual enum values need not be the same as in KAAlarm::Type.
136  enum AlarmType
137  {
138  INVALID_ALARM = 0, // Not an alarm
139  MAIN_ALARM = 1, // THE real alarm. Must be the first in the enumeration.
140  REMINDER_ALARM = 0x02, // Reminder in advance of/after the main alarm
141  DEFERRED_ALARM = 0x04, // Deferred alarm
142  DEFERRED_REMINDER_ALARM = REMINDER_ALARM | DEFERRED_ALARM, // Deferred reminder alarm
143  // The following values must be greater than the preceding ones, to
144  // ensure that in ordered processing they are processed afterwards.
145  AT_LOGIN_ALARM = 0x10, // Additional repeat-at-login trigger
146  DISPLAYING_ALARM = 0x20, // Copy of the alarm currently being displayed
147  // The following are extra internal KAEvent values
148  AUDIO_ALARM = 0x30, // sound to play when displaying the alarm
149  PRE_ACTION_ALARM = 0x40, // command to execute before displaying the alarm
150  POST_ACTION_ALARM = 0x50 // command to execute after the alarm window is closed
151  };
152 
153  struct AlarmData
154  {
155 #ifndef KALARMCAL_USE_KRESOURCES
156  Alarm::Ptr alarm;
157 #else
158  const Alarm* alarm;
159 #endif
160  QString cleanText; // text or audio file name
161  QFont font;
162  QColor bgColour, fgColour;
163  float soundVolume;
164  float fadeVolume;
165  int fadeSeconds;
166  int repeatSoundPause;
167  int nextRepeat;
168  uint emailFromId;
169  KAEventPrivate::AlarmType type;
170  KAAlarm::Action action;
171  int displayingFlags;
172  KAEvent::ExtraActionOptions extraActionOptions;
173  bool speak;
174  bool defaultFont;
175  bool isEmailText;
176  bool commandScript;
177  bool timedDeferral;
178  bool hiddenReminder;
179  };
180  typedef QMap<AlarmType, AlarmData> AlarmMap;
181 
182  KAEventPrivate();
183  KAEventPrivate(const KDateTime&, const QString& message, const QColor& bg, const QColor& fg,
184  const QFont& f, KAEvent::SubAction, int lateCancel, KAEvent::Flags flags,
185  bool changesPending = false);
186 #ifndef KALARMCAL_USE_KRESOURCES
187  explicit KAEventPrivate(const KCalCore::Event::Ptr&);
188 #else
189  explicit KAEventPrivate(const KCal::Event*);
190 #endif
191  KAEventPrivate(const KAEventPrivate&);
192  ~KAEventPrivate() { delete mRecurrence; }
193  KAEventPrivate& operator=(const KAEventPrivate& e) { if (&e != this) copy(e); return *this; }
194 #ifndef KALARMCAL_USE_KRESOURCES
195  void set(const KCalCore::Event::Ptr&);
196 #else
197  void set(const KCal::Event*);
198 #endif
199  void set(const KDateTime&, const QString& message, const QColor& bg, const QColor& fg,
200  const QFont&, KAEvent::SubAction, int lateCancel, KAEvent::Flags flags,
201  bool changesPending = false);
202  void setAudioFile(const QString& filename, float volume, float fadeVolume, int fadeSeconds, int repeatPause, bool allowEmptyFile);
203  KAEvent::OccurType setNextOccurrence(const KDateTime& preDateTime);
204  void setFirstRecurrence();
205  void setCategory(CalEvent::Type);
206  void setRepeatAtLogin(bool);
207  void setRepeatAtLoginTrue(bool clearReminder);
208  void setReminder(int minutes, bool onceOnly);
209  void activateReminderAfter(const DateTime& mainAlarmTime);
210  void defer(const DateTime&, bool reminder, bool adjustRecurrence = false);
211  void cancelDefer();
212 #ifndef KALARMCAL_USE_KRESOURCES
213  bool setDisplaying(const KAEventPrivate&, KAAlarm::Type, Akonadi::Collection::Id, const KDateTime& dt, bool showEdit, bool showDefer);
214  void reinstateFromDisplaying(const KCalCore::Event::Ptr&, Akonadi::Collection::Id&, bool& showEdit, bool& showDefer);
215 #else
216  bool setDisplaying(const KAEventPrivate&, KAAlarm::Type, const QString& resourceID, const KDateTime& dt, bool showEdit, bool showDefer);
217  void reinstateFromDisplaying(const KCal::Event*, QString& resourceID, bool& showEdit, bool& showDefer);
218  void setCommandError(const QString& configString);
219  void setCommandError(KAEvent::CmdErrType, bool writeConfig) const;
220 #endif
221  void startChanges() { ++mChangeCount; }
222  void endChanges();
223  void removeExpiredAlarm(KAAlarm::Type);
224  KAAlarm alarm(KAAlarm::Type) const;
225  KAAlarm firstAlarm() const;
226  KAAlarm nextAlarm(KAAlarm::Type) const;
227 #ifndef KALARMCAL_USE_KRESOURCES
228  bool updateKCalEvent(const KCalCore::Event::Ptr&, KAEvent::UidAction, bool setCustomProperties = true) const;
229 #else
230  bool updateKCalEvent(KCal::Event*, KAEvent::UidAction) const;
231 #endif
232  DateTime mainDateTime(bool withRepeats = false) const
233  { return (withRepeats && mNextRepeat && mRepetition)
234  ? mRepetition.duration(mNextRepeat).end(mNextMainDateTime.kDateTime()) : mNextMainDateTime; }
235  DateTime mainEndRepeatTime() const
236  { return mRepetition ? mRepetition.duration().end(mNextMainDateTime.kDateTime()) : mNextMainDateTime; }
237  DateTime deferralLimit(KAEvent::DeferLimitType* = 0) const;
238  KAEvent::Flags flags() const;
239  bool isWorkingTime(const KDateTime&) const;
240  bool setRepetition(const Repetition&);
241  bool occursAfter(const KDateTime& preDateTime, bool includeRepetitions) const;
242  KAEvent::OccurType nextOccurrence(const KDateTime& preDateTime, DateTime& result, KAEvent::OccurOption = KAEvent::IGNORE_REPETITION) const;
243  KAEvent::OccurType previousOccurrence(const KDateTime& afterDateTime, DateTime& result, bool includeRepetitions = false) const;
244  void setRecurrence(const KARecurrence&);
245 #ifndef KALARMCAL_USE_KRESOURCES
246  bool setRecur(KCalCore::RecurrenceRule::PeriodType, int freq, int count, const QDate& end, KARecurrence::Feb29Type = KARecurrence::Feb29_None);
247  bool setRecur(KCalCore::RecurrenceRule::PeriodType, int freq, int count, const KDateTime& end, KARecurrence::Feb29Type = KARecurrence::Feb29_None);
248 #else
249  bool setRecur(KCal::RecurrenceRule::PeriodType, int freq, int count, const QDate& end, KARecurrence::Feb29Type = KARecurrence::Feb29_None);
250  bool setRecur(KCal::RecurrenceRule::PeriodType, int freq, int count, const KDateTime& end, KARecurrence::Feb29Type = KARecurrence::Feb29_None);
251 #endif
252  KARecurrence::Type checkRecur() const;
253  void clearRecur();
254  void calcTriggerTimes() const;
255 #ifdef KDE_NO_DEBUG_OUTPUT
256  void dumpDebug() const { }
257 #else
258  void dumpDebug() const;
259 #endif
260 #ifndef KALARMCAL_USE_KRESOURCES
261  static bool convertRepetition(const KCalCore::Event::Ptr&);
262  static bool convertStartOfDay(const KCalCore::Event::Ptr&);
263  static DateTime readDateTime(const KCalCore::Event::Ptr&, bool dateOnly, DateTime& start);
264  static void readAlarms(const KCalCore::Event::Ptr&, AlarmMap*, bool cmdDisplay = false);
265  static void readAlarm(const KCalCore::Alarm::Ptr&, AlarmData&, bool audioMain, bool cmdDisplay = false);
266 #else
267  static bool convertRepetition(KCal::Event*);
268  static bool convertStartOfDay(KCal::Event*);
269  static DateTime readDateTime(const KCal::Event*, bool dateOnly, DateTime& start);
270  static void readAlarms(const KCal::Event*, AlarmMap*, bool cmdDisplay = false);
271  static void readAlarm(const KCal::Alarm*, AlarmData&, bool audioMain, bool cmdDisplay = false);
272 #endif
273 
274  private:
275  void copy(const KAEventPrivate&);
276  bool mayOccurDailyDuringWork(const KDateTime&) const;
277  int nextWorkRepetition(const KDateTime& pre) const;
278  void calcNextWorkingTime(const DateTime& nextTrigger) const;
279  DateTime nextWorkingTime() const;
280  KAEvent::OccurType nextRecurrence(const KDateTime& preDateTime, DateTime& result) const;
281 #ifndef KALARMCAL_USE_KRESOURCES
282  void setAudioAlarm(const KCalCore::Alarm::Ptr&) const;
283  KCalCore::Alarm::Ptr initKCalAlarm(const KCalCore::Event::Ptr&, const DateTime&, const QStringList& types, AlarmType = INVALID_ALARM) const;
284  KCalCore::Alarm::Ptr initKCalAlarm(const KCalCore::Event::Ptr&, int startOffsetSecs, const QStringList& types, AlarmType = INVALID_ALARM) const;
285 #else
286  void setAudioAlarm(KCal::Alarm*) const;
287  KCal::Alarm* initKCalAlarm(KCal::Event*, const DateTime&, const QStringList& types, AlarmType = INVALID_ALARM) const;
288  KCal::Alarm* initKCalAlarm(KCal::Event*, int startOffsetSecs, const QStringList& types, AlarmType = INVALID_ALARM) const;
289 #endif
290  inline void set_deferral(DeferType);
291  inline void activate_reminder(bool activate);
292 
293  public:
294 #ifdef KALARMCAL_USE_KRESOURCES
295  static QString mCmdErrConfigGroup; // config file group for command error recording
296 #endif
297  static QFont mDefaultFont; // default alarm message font
298  static const KHolidays::HolidayRegion* mHolidays; // holiday region to use
299  static QBitArray mWorkDays; // working days of the week
300  static QTime mWorkDayStart; // start time of the working day
301  static QTime mWorkDayEnd; // end time of the working day
302  static int mWorkTimeIndex; // incremented every time working days/times are changed
303 #ifdef KALARMCAL_USE_KRESOURCES
304  AlarmResource* mResource; // resource which owns the event (for convenience - not used by this class)
305 #endif
306  mutable DateTime mAllTrigger; // next trigger time, including reminders, ignoring working hours
307  mutable DateTime mMainTrigger; // next trigger time, ignoring reminders and working hours
308  mutable DateTime mAllWorkTrigger; // next trigger time, taking account of reminders and working hours
309  mutable DateTime mMainWorkTrigger; // next trigger time, ignoring reminders but taking account of working hours
310  mutable KAEvent::CmdErrType mCommandError; // command execution error last time the alarm triggered
311 
312  QString mEventID; // UID: KCal::Event unique ID
313  QString mTemplateName; // alarm template's name, or null if normal event
314 #ifndef KALARMCAL_USE_KRESOURCES
315  QMap<QByteArray, QString> mCustomProperties; // KCal::Event's non-KAlarm custom properties
316  Akonadi::Item::Id mItemId; // Akonadi::Item ID for this event
317  mutable Akonadi::Collection::Id mCollectionId; // ID of collection containing the event, or for a displaying event,
318  // saved collection ID (not the collection the event is in)
319 #else
320  QString mOriginalResourceId;// saved resource ID (not the resource the event is in)
321 #endif
322  QString mText; // message text, file URL, command, email body [or audio file for KAAlarm]
323  QString mAudioFile; // ATTACH: audio file to play
324  QString mPreAction; // command to execute before alarm is displayed
325  QString mPostAction; // command to execute after alarm window is closed
326  DateTime mStartDateTime; // DTSTART and DTEND: start and end time for event
327  KDateTime mCreatedDateTime; // CREATED: date event was created, or saved in archive calendar
328  DateTime mNextMainDateTime; // next time to display the alarm, excluding repetitions
329  KDateTime mAtLoginDateTime; // repeat-at-login end time
330  DateTime mDeferralTime; // extra time to trigger alarm (if alarm or reminder deferred)
331  DateTime mDisplayingTime; // date/time shown in the alarm currently being displayed
332  int mDisplayingFlags; // type of alarm which is currently being displayed (for display alarm)
333  int mReminderMinutes; // how long in advance reminder is to be, or 0 if none (<0 for reminder AFTER the alarm)
334  DateTime mReminderAfterTime; // if mReminderActive true, time to trigger reminder AFTER the main alarm, or invalid if not pending
335  ReminderType mReminderActive; // whether a reminder is due (before next, or after last, main alarm/recurrence)
336  int mDeferDefaultMinutes; // default number of minutes for deferral dialog, or 0 to select time control
337  bool mDeferDefaultDateOnly;// select date-only by default in deferral dialog
338  int mRevision; // SEQUENCE: revision number of the original alarm, or 0
339  KARecurrence* mRecurrence; // RECUR: recurrence specification, or 0 if none
340  Repetition mRepetition; // sub-repetition count and interval
341  int mNextRepeat; // repetition count of next due sub-repetition
342  int mAlarmCount; // number of alarms: count of !mMainExpired, mRepeatAtLogin, mDeferral, mReminderActive, mDisplaying
343  DeferType mDeferral; // whether the alarm is an extra deferred/deferred-reminder alarm
344  unsigned long mKMailSerialNumber; // if email text, message's KMail serial number
345  int mTemplateAfterTime; // time not specified: use n minutes after default time, or -1 (applies to templates only)
346  QColor mBgColour; // background colour of alarm message
347  QColor mFgColour; // foreground colour of alarm message, or invalid for default
348  QFont mFont; // font of alarm message (ignored if mUseDefaultFont true)
349  uint mEmailFromIdentity; // standard email identity uoid for 'From' field, or empty
350  EmailAddressList mEmailAddresses; // ATTENDEE: addresses to send email to
351  QString mEmailSubject; // SUMMARY: subject line of email
352  QStringList mEmailAttachments; // ATTACH: email attachment file names
353  mutable int mChangeCount; // >0 = inhibit calling calcTriggerTimes()
354  mutable bool mTriggerChanged; // true if need to recalculate trigger times
355  QString mLogFile; // alarm output is to be logged to this URL
356  float mSoundVolume; // volume for sound file (range 0 - 1), or < 0 for unspecified
357  float mFadeVolume; // initial volume for sound file (range 0 - 1), or < 0 for no fade
358  int mFadeSeconds; // fade time (seconds) for sound file, or 0 if none
359  int mRepeatSoundPause; // seconds to pause between sound file repetitions, or -1 if no repetition
360  int mLateCancel; // how many minutes late will cancel the alarm, or 0 for no cancellation
361  mutable const KHolidays::HolidayRegion*
362  mExcludeHolidays; // non-null to not trigger alarms on holidays (= mHolidays when trigger calculated)
363  mutable int mWorkTimeOnly; // non-zero to trigger alarm only during working hours (= mWorkTimeIndex when trigger calculated)
364  KAEvent::SubAction mActionSubType; // sub-action type for the event's main alarm
365  CalEvent::Type mCategory; // event category (active, archived, template, ...)
366  KAEvent::ExtraActionOptions mExtraActionOptions;// options for pre- or post-alarm actions
367 #ifndef KALARMCAL_USE_KRESOURCES
368  KACalendar::Compat mCompatibility; // event's storage format compatibility
369  bool mReadOnly; // event is read-only in its original calendar file
370 #endif
371  bool mConfirmAck; // alarm acknowledgement requires confirmation by user
372  bool mUseDefaultFont; // use default message font, not mFont
373  bool mCommandScript; // the command text is a script, not a shell command line
374  bool mCommandXterm; // command alarm is to be executed in a terminal window
375  bool mCommandDisplay; // command output is to be displayed in an alarm window
376  bool mEmailBcc; // blind copy the email to the user
377  bool mBeep; // whether to beep when the alarm is displayed
378  bool mSpeak; // whether to speak the message when the alarm is displayed
379  bool mCopyToKOrganizer; // KOrganizer should hold a copy of the event
380  bool mReminderOnceOnly; // the reminder is output only for the first recurrence
381  bool mAutoClose; // whether to close the alarm window after the late-cancel period
382  bool mMainExpired; // main alarm has expired (in which case a deferral alarm will exist)
383  bool mRepeatAtLogin; // whether to repeat the alarm at every login
384  bool mArchiveRepeatAtLogin; // if now archived, original event was repeat-at-login
385  bool mArchive; // event has triggered in the past, so archive it when closed
386  bool mDisplaying; // whether the alarm is currently being displayed (i.e. in displaying calendar)
387  bool mDisplayingDefer; // show Defer button (applies to displaying calendar only)
388  bool mDisplayingEdit; // show Edit button (applies to displaying calendar only)
389  bool mEnabled; // false if event is disabled
390 
391  public:
392  static const QByteArray FLAGS_PROPERTY;
393  static const QString DATE_ONLY_FLAG;
394  static const QString EMAIL_BCC_FLAG;
395  static const QString CONFIRM_ACK_FLAG;
396  static const QString KORGANIZER_FLAG;
397  static const QString EXCLUDE_HOLIDAYS_FLAG;
398  static const QString WORK_TIME_ONLY_FLAG;
399  static const QString REMINDER_ONCE_FLAG;
400  static const QString DEFER_FLAG;
401  static const QString LATE_CANCEL_FLAG;
402  static const QString AUTO_CLOSE_FLAG;
403  static const QString TEMPL_AFTER_TIME_FLAG;
404  static const QString KMAIL_SERNUM_FLAG;
405  static const QString ARCHIVE_FLAG;
406  static const QByteArray NEXT_RECUR_PROPERTY;
407  static const QByteArray REPEAT_PROPERTY;
408  static const QByteArray LOG_PROPERTY;
409  static const QString xtermURL;
410  static const QString displayURL;
411  static const QByteArray TYPE_PROPERTY;
412  static const QString FILE_TYPE;
413  static const QString AT_LOGIN_TYPE;
414  static const QString REMINDER_TYPE;
415  static const QString REMINDER_ONCE_TYPE;
416  static const QString TIME_DEFERRAL_TYPE;
417  static const QString DATE_DEFERRAL_TYPE;
418  static const QString DISPLAYING_TYPE;
419  static const QString PRE_ACTION_TYPE;
420  static const QString POST_ACTION_TYPE;
421  static const QString SOUND_REPEAT_TYPE;
422  static const QByteArray NEXT_REPEAT_PROPERTY;
423  static const QString HIDDEN_REMINDER_FLAG;
424  static const QByteArray FONT_COLOUR_PROPERTY;
425  static const QByteArray VOLUME_PROPERTY;
426  static const QString EMAIL_ID_FLAG;
427  static const QString SPEAK_FLAG;
428  static const QString EXEC_ON_DEFERRAL_FLAG;
429  static const QString CANCEL_ON_ERROR_FLAG;
430  static const QString DONT_SHOW_ERROR_FLAG;
431  static const QString DISABLED_STATUS;
432  static const QString DISP_DEFER;
433  static const QString DISP_EDIT;
434  static const QString CMD_ERROR_VALUE;
435  static const QString CMD_ERROR_PRE_VALUE;
436  static const QString CMD_ERROR_POST_VALUE;
437  static const QString SC;
438 };
439 
440 //=============================================================================
441 
442 // KAlarm version which first used the current calendar/event format.
443 // If this changes, KAEvent::convertKCalEvents() must be changed correspondingly.
444 // The string version is the KAlarm version string used in the calendar file.
445 QByteArray KAEvent::currentCalendarVersionString() { return QByteArray("2.7.0"); }
446 int KAEvent::currentCalendarVersion() { return Version(2,7,0); }
447 
448 // Custom calendar properties.
449 // Note that all custom property names are prefixed with X-KDE-KALARM- in the calendar file.
450 
451 // Event properties
452 const QByteArray KAEventPrivate::FLAGS_PROPERTY("FLAGS"); // X-KDE-KALARM-FLAGS property
453 const QString KAEventPrivate::DATE_ONLY_FLAG = QLatin1String("DATE");
454 const QString KAEventPrivate::EMAIL_BCC_FLAG = QLatin1String("BCC");
455 const QString KAEventPrivate::CONFIRM_ACK_FLAG = QLatin1String("ACKCONF");
456 const QString KAEventPrivate::KORGANIZER_FLAG = QLatin1String("KORG");
457 const QString KAEventPrivate::EXCLUDE_HOLIDAYS_FLAG = QLatin1String("EXHOLIDAYS");
458 const QString KAEventPrivate::WORK_TIME_ONLY_FLAG = QLatin1String("WORKTIME");
459 const QString KAEventPrivate::REMINDER_ONCE_FLAG = QLatin1String("ONCE");
460 const QString KAEventPrivate::DEFER_FLAG = QLatin1String("DEFER"); // default defer interval for this alarm
461 const QString KAEventPrivate::LATE_CANCEL_FLAG = QLatin1String("LATECANCEL");
462 const QString KAEventPrivate::AUTO_CLOSE_FLAG = QLatin1String("LATECLOSE");
463 const QString KAEventPrivate::TEMPL_AFTER_TIME_FLAG = QLatin1String("TMPLAFTTIME");
464 const QString KAEventPrivate::KMAIL_SERNUM_FLAG = QLatin1String("KMAIL");
465 const QString KAEventPrivate::ARCHIVE_FLAG = QLatin1String("ARCHIVE");
466 
467 const QByteArray KAEventPrivate::NEXT_RECUR_PROPERTY("NEXTRECUR"); // X-KDE-KALARM-NEXTRECUR property
468 const QByteArray KAEventPrivate::REPEAT_PROPERTY("REPEAT"); // X-KDE-KALARM-REPEAT property
469 const QByteArray KAEventPrivate::LOG_PROPERTY("LOG"); // X-KDE-KALARM-LOG property
470 const QString KAEventPrivate::xtermURL = QLatin1String("xterm:");
471 const QString KAEventPrivate::displayURL = QLatin1String("display:");
472 
473 // - General alarm properties
474 const QByteArray KAEventPrivate::TYPE_PROPERTY("TYPE"); // X-KDE-KALARM-TYPE property
475 const QString KAEventPrivate::FILE_TYPE = QLatin1String("FILE");
476 const QString KAEventPrivate::AT_LOGIN_TYPE = QLatin1String("LOGIN");
477 const QString KAEventPrivate::REMINDER_TYPE = QLatin1String("REMINDER");
478 const QString KAEventPrivate::TIME_DEFERRAL_TYPE = QLatin1String("DEFERRAL");
479 const QString KAEventPrivate::DATE_DEFERRAL_TYPE = QLatin1String("DATE_DEFERRAL");
480 const QString KAEventPrivate::DISPLAYING_TYPE = QLatin1String("DISPLAYING"); // used only in displaying calendar
481 const QString KAEventPrivate::PRE_ACTION_TYPE = QLatin1String("PRE");
482 const QString KAEventPrivate::POST_ACTION_TYPE = QLatin1String("POST");
483 const QString KAEventPrivate::SOUND_REPEAT_TYPE = QLatin1String("SOUNDREPEAT");
484 const QByteArray KAEventPrivate::NEXT_REPEAT_PROPERTY("NEXTREPEAT"); // X-KDE-KALARM-NEXTREPEAT property
485 const QString KAEventPrivate::HIDDEN_REMINDER_FLAG = QLatin1String("HIDE");
486 // - Display alarm properties
487 const QByteArray KAEventPrivate::FONT_COLOUR_PROPERTY("FONTCOLOR"); // X-KDE-KALARM-FONTCOLOR property
488 // - Email alarm properties
489 const QString KAEventPrivate::EMAIL_ID_FLAG = QLatin1String("EMAILID");
490 // - Audio alarm properties
491 const QByteArray KAEventPrivate::VOLUME_PROPERTY("VOLUME"); // X-KDE-KALARM-VOLUME property
492 const QString KAEventPrivate::SPEAK_FLAG = QLatin1String("SPEAK");
493 // - Command alarm properties
494 const QString KAEventPrivate::EXEC_ON_DEFERRAL_FLAG = QLatin1String("EXECDEFER");
495 const QString KAEventPrivate::CANCEL_ON_ERROR_FLAG = QLatin1String("ERRCANCEL");
496 const QString KAEventPrivate::DONT_SHOW_ERROR_FLAG = QLatin1String("ERRNOSHOW");
497 
498 // Event status strings
499 const QString KAEventPrivate::DISABLED_STATUS = QLatin1String("DISABLED");
500 
501 // Displaying event ID identifier
502 const QString KAEventPrivate::DISP_DEFER = QLatin1String("DEFER");
503 const QString KAEventPrivate::DISP_EDIT = QLatin1String("EDIT");
504 
505 // Command error strings
506 #ifdef KALARMCAL_USE_KRESOURCES
507 QString KAEventPrivate::mCmdErrConfigGroup = QLatin1String("CommandErrors");
508 #endif
509 const QString KAEventPrivate::CMD_ERROR_VALUE = QLatin1String("MAIN");
510 const QString KAEventPrivate::CMD_ERROR_PRE_VALUE = QLatin1String("PRE");
511 const QString KAEventPrivate::CMD_ERROR_POST_VALUE = QLatin1String("POST");
512 
513 const QString KAEventPrivate::SC = QLatin1String(";");
514 
515 QFont KAEventPrivate::mDefaultFont;
516 const KHolidays::HolidayRegion* KAEventPrivate::mHolidays = 0;
517 QBitArray KAEventPrivate::mWorkDays(7);
518 QTime KAEventPrivate::mWorkDayStart(9, 0, 0);
519 QTime KAEventPrivate::mWorkDayEnd(17, 0, 0);
520 int KAEventPrivate::mWorkTimeIndex = 1;
521 
522 #ifndef KALARMCAL_USE_KRESOURCES
523 static void setProcedureAlarm(const Alarm::Ptr&, const QString& commandLine);
524 #else
525 static void setProcedureAlarm(Alarm*, const QString& commandLine);
526 #endif
527 static QString reminderToString(int minutes);
528 
529 /*=============================================================================
530 = Class KAEvent
531 = Corresponds to a KCal::Event instance.
532 =============================================================================*/
533 
534 inline void KAEventPrivate::set_deferral(DeferType type)
535 {
536  if (type)
537  {
538  if (mDeferral == NO_DEFERRAL)
539  ++mAlarmCount;
540  }
541  else
542  {
543  if (mDeferral != NO_DEFERRAL)
544  --mAlarmCount;
545  }
546  mDeferral = type;
547 }
548 
549 inline void KAEventPrivate::activate_reminder(bool activate)
550 {
551  if (activate && mReminderActive != ACTIVE_REMINDER && mReminderMinutes)
552  {
553  if (mReminderActive == NO_REMINDER)
554  ++mAlarmCount;
555  mReminderActive = ACTIVE_REMINDER;
556  }
557  else if (!activate && mReminderActive != NO_REMINDER)
558  {
559  mReminderActive = NO_REMINDER;
560  mReminderAfterTime = DateTime();
561  --mAlarmCount;
562  }
563 }
564 
565 K_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer<KAEventPrivate>,
566  emptyKAEventPrivate, (new KAEventPrivate))
567 
568 KAEvent::KAEvent()
569  : d(*emptyKAEventPrivate)
570 { }
571 
572 KAEventPrivate::KAEventPrivate()
573  :
574 #ifdef KALARMCAL_USE_KRESOURCES
575  mResource(0),
576 #endif
577  mCommandError(KAEvent::CMD_NO_ERROR),
578 #ifndef KALARMCAL_USE_KRESOURCES
579  mItemId(-1),
580  mCollectionId(-1),
581 #endif
582  mReminderMinutes(0),
583  mReminderActive(NO_REMINDER),
584  mRevision(0),
585  mRecurrence(0),
586  mNextRepeat(0),
587  mAlarmCount(0),
588  mDeferral(NO_DEFERRAL),
589  mChangeCount(0),
590  mTriggerChanged(false),
591  mLateCancel(0),
592  mExcludeHolidays(0),
593  mWorkTimeOnly(0),
594  mCategory(CalEvent::EMPTY),
595 #ifndef KALARMCAL_USE_KRESOURCES
596  mCompatibility(KACalendar::Current),
597  mReadOnly(false),
598 #endif
599  mConfirmAck(false),
600  mEmailBcc(false),
601  mBeep(false),
602  mAutoClose(false),
603  mRepeatAtLogin(false),
604  mDisplaying(false)
605 { }
606 
607 KAEvent::KAEvent(const KDateTime& dt, const QString& message, const QColor& bg, const QColor& fg, const QFont& f,
608  SubAction action, int lateCancel, Flags flags, bool changesPending)
609  : d(new KAEventPrivate(dt, message, bg, fg, f, action, lateCancel, flags, changesPending))
610 {
611 }
612 
613 KAEventPrivate::KAEventPrivate(const KDateTime& dt, const QString& message, const QColor& bg, const QColor& fg, const QFont& f,
614  KAEvent::SubAction action, int lateCancel, KAEvent::Flags flags, bool changesPending)
615  : mRevision(0),
616  mRecurrence(0)
617 {
618  set(dt, message, bg, fg, f, action, lateCancel, flags, changesPending);
619 }
620 
621 #ifndef KALARMCAL_USE_KRESOURCES
622 KAEvent::KAEvent(const Event::Ptr& e)
623 #else
624 KAEvent::KAEvent(const Event* e)
625 #endif
626  : d(new KAEventPrivate(e))
627 {
628 }
629 
630 #ifndef KALARMCAL_USE_KRESOURCES
631 KAEventPrivate::KAEventPrivate(const Event::Ptr& e)
632 #else
633 KAEventPrivate::KAEventPrivate(const Event* e)
634 #endif
635  : mRecurrence(0)
636 {
637  set(e);
638 }
639 
640 KAEventPrivate::KAEventPrivate(const KAEventPrivate& e)
641  : QSharedData(e),
642  mRecurrence(0)
643 {
644  copy(e);
645 }
646 
647 KAEvent::KAEvent(const KAEvent& other)
648  : d(other.d)
649 { }
650 
651 KAEvent::~KAEvent()
652 { }
653 
654 KAEvent& KAEvent::operator=(const KAEvent& other)
655 {
656  if (&other != this)
657  d = other.d;
658  return *this;
659 }
660 
661 /******************************************************************************
662 * Copies the data from another instance.
663 */
664 void KAEventPrivate::copy(const KAEventPrivate& event)
665 {
666 #ifdef KALARMCAL_USE_KRESOURCES
667  mResource = event.mResource;
668 #endif
669  mAllTrigger = event.mAllTrigger;
670  mMainTrigger = event.mMainTrigger;
671  mAllWorkTrigger = event.mAllWorkTrigger;
672  mMainWorkTrigger = event.mMainWorkTrigger;
673  mCommandError = event.mCommandError;
674  mEventID = event.mEventID;
675  mTemplateName = event.mTemplateName;
676 #ifndef KALARMCAL_USE_KRESOURCES
677  mCustomProperties = event.mCustomProperties;
678  mItemId = event.mItemId;
679  mCollectionId = event.mCollectionId;
680 #else
681  mOriginalResourceId = event.mOriginalResourceId;
682 #endif
683  mText = event.mText;
684  mAudioFile = event.mAudioFile;
685  mPreAction = event.mPreAction;
686  mPostAction = event.mPostAction;
687  mStartDateTime = event.mStartDateTime;
688  mCreatedDateTime = event.mCreatedDateTime;
689  mNextMainDateTime = event.mNextMainDateTime;
690  mAtLoginDateTime = event.mAtLoginDateTime;
691  mDeferralTime = event.mDeferralTime;
692  mDisplayingTime = event.mDisplayingTime;
693  mDisplayingFlags = event.mDisplayingFlags;
694  mReminderMinutes = event.mReminderMinutes;
695  mReminderAfterTime = event.mReminderAfterTime;
696  mReminderActive = event.mReminderActive;
697  mDeferDefaultMinutes = event.mDeferDefaultMinutes;
698  mDeferDefaultDateOnly = event.mDeferDefaultDateOnly;
699  mRevision = event.mRevision;
700  mRepetition = event.mRepetition;
701  mNextRepeat = event.mNextRepeat;
702  mAlarmCount = event.mAlarmCount;
703  mDeferral = event.mDeferral;
704  mKMailSerialNumber = event.mKMailSerialNumber;
705  mTemplateAfterTime = event.mTemplateAfterTime;
706  mBgColour = event.mBgColour;
707  mFgColour = event.mFgColour;
708  mFont = event.mFont;
709  mEmailFromIdentity = event.mEmailFromIdentity;
710  mEmailAddresses = event.mEmailAddresses;
711  mEmailSubject = event.mEmailSubject;
712  mEmailAttachments = event.mEmailAttachments;
713  mLogFile = event.mLogFile;
714  mSoundVolume = event.mSoundVolume;
715  mFadeVolume = event.mFadeVolume;
716  mFadeSeconds = event.mFadeSeconds;
717  mRepeatSoundPause = event.mRepeatSoundPause;
718  mLateCancel = event.mLateCancel;
719  mExcludeHolidays = event.mExcludeHolidays;
720  mWorkTimeOnly = event.mWorkTimeOnly;
721  mActionSubType = event.mActionSubType;
722  mCategory = event.mCategory;
723  mExtraActionOptions = event.mExtraActionOptions;
724 #ifndef KALARMCAL_USE_KRESOURCES
725  mCompatibility = event.mCompatibility;
726  mReadOnly = event.mReadOnly;
727 #endif
728  mConfirmAck = event.mConfirmAck;
729  mUseDefaultFont = event.mUseDefaultFont;
730  mCommandScript = event.mCommandScript;
731  mCommandXterm = event.mCommandXterm;
732  mCommandDisplay = event.mCommandDisplay;
733  mEmailBcc = event.mEmailBcc;
734  mBeep = event.mBeep;
735  mSpeak = event.mSpeak;
736  mCopyToKOrganizer = event.mCopyToKOrganizer;
737  mReminderOnceOnly = event.mReminderOnceOnly;
738  mAutoClose = event.mAutoClose;
739  mMainExpired = event.mMainExpired;
740  mRepeatAtLogin = event.mRepeatAtLogin;
741  mArchiveRepeatAtLogin = event.mArchiveRepeatAtLogin;
742  mArchive = event.mArchive;
743  mDisplaying = event.mDisplaying;
744  mDisplayingDefer = event.mDisplayingDefer;
745  mDisplayingEdit = event.mDisplayingEdit;
746  mEnabled = event.mEnabled;
747  mChangeCount = 0;
748  mTriggerChanged = event.mTriggerChanged;
749  delete mRecurrence;
750  if (event.mRecurrence)
751  mRecurrence = new KARecurrence(*event.mRecurrence);
752  else
753  mRecurrence = 0;
754 }
755 
756 #ifndef KALARMCAL_USE_KRESOURCES
757 void KAEvent::set(const Event::Ptr& e)
758 #else
759 void KAEvent::set(const Event* e)
760 #endif
761 {
762  d->set(e);
763 }
764 
765 /******************************************************************************
766 * Initialise the KAEventPrivate from a KCal::Event.
767 */
768 #ifndef KALARMCAL_USE_KRESOURCES
769 void KAEventPrivate::set(const Event::Ptr& event)
770 #else
771 void KAEventPrivate::set(const Event* event)
772 #endif
773 {
774  startChanges();
775  // Extract status from the event
776  mCommandError = KAEvent::CMD_NO_ERROR;
777 #ifdef KALARMCAL_USE_KRESOURCES
778  mResource = 0;
779 #endif
780  mEventID = event->uid();
781  mRevision = event->revision();
782  mTemplateName.clear();
783  mLogFile.clear();
784 #ifndef KALARMCAL_USE_KRESOURCES
785  mItemId = -1;
786  mCollectionId = -1;
787 #else
788  mOriginalResourceId.clear();
789 #endif
790  mTemplateAfterTime = -1;
791  mBeep = false;
792  mSpeak = false;
793  mEmailBcc = false;
794  mCommandXterm = false;
795  mCommandDisplay = false;
796  mCopyToKOrganizer = false;
797  mConfirmAck = false;
798  mArchive = false;
799  mReminderOnceOnly = false;
800  mAutoClose = false;
801  mArchiveRepeatAtLogin = false;
802  mDisplayingDefer = false;
803  mDisplayingEdit = false;
804  mDeferDefaultDateOnly = false;
805  mReminderActive = NO_REMINDER;
806  mReminderMinutes = 0;
807  mDeferDefaultMinutes = 0;
808  mLateCancel = 0;
809  mKMailSerialNumber = 0;
810  mExcludeHolidays = 0;
811  mWorkTimeOnly = 0;
812  mChangeCount = 0;
813  mBgColour = QColor(255, 255, 255); // missing/invalid colour - return white background
814  mFgColour = QColor(0, 0, 0); // and black foreground
815 #ifndef KALARMCAL_USE_KRESOURCES
816  mCompatibility = KACalendar::Current;
817  mReadOnly = event->isReadOnly();
818 #endif
819  mUseDefaultFont = true;
820  mEnabled = true;
821  clearRecur();
822  QString param;
823  bool ok;
824  mCategory = CalEvent::status(event, &param);
825  if (mCategory == CalEvent::DISPLAYING)
826  {
827  // It's a displaying calendar event - set values specific to displaying alarms
828  const QStringList params = param.split(SC, QString::KeepEmptyParts);
829  int n = params.count();
830  if (n)
831  {
832 #ifndef KALARMCAL_USE_KRESOURCES
833  const qlonglong id = params[0].toLongLong(&ok);
834  if (ok)
835  mCollectionId = id; // original collection ID which contained the event
836 #else
837  mOriginalResourceId = params[0];
838 #endif
839  for (int i = 1; i < n; ++i)
840  {
841  if (params[i] == DISP_DEFER)
842  mDisplayingDefer = true;
843  if (params[i] == DISP_EDIT)
844  mDisplayingEdit = true;
845  }
846  }
847  }
848 #ifndef KALARMCAL_USE_KRESOURCES
849  // Store the non-KAlarm custom properties of the event
850  const QByteArray kalarmKey = "X-KDE-" + KACalendar::APPNAME + '-';
851  mCustomProperties = event->customProperties();
852  for (QMap<QByteArray, QString>::Iterator it = mCustomProperties.begin(); it != mCustomProperties.end(); )
853  {
854  if (it.key().startsWith(kalarmKey))
855  it = mCustomProperties.erase(it);
856  else
857  ++it;
858  }
859 #endif
860 
861  bool dateOnly = false;
862  QStringList flags = event->customProperty(KACalendar::APPNAME, FLAGS_PROPERTY).split(SC, QString::SkipEmptyParts);
863  flags << QString() << QString(); // to avoid having to check for end of list
864  for (int i = 0, end = flags.count() - 1; i < end; ++i)
865  {
866  QString flag = flags.at(i);
867  if (flag == DATE_ONLY_FLAG)
868  dateOnly = true;
869  else if (flag == CONFIRM_ACK_FLAG)
870  mConfirmAck = true;
871  else if (flag == EMAIL_BCC_FLAG)
872  mEmailBcc = true;
873  else if (flag == KORGANIZER_FLAG)
874  mCopyToKOrganizer = true;
875  else if (flag == EXCLUDE_HOLIDAYS_FLAG)
876  mExcludeHolidays = mHolidays;
877  else if (flag == WORK_TIME_ONLY_FLAG)
878  mWorkTimeOnly = 1;
879  else if (flag == KMAIL_SERNUM_FLAG)
880  {
881  const unsigned long n = flags.at(i + 1).toULong(&ok);
882  if (!ok)
883  continue;
884  mKMailSerialNumber = n;
885  ++i;
886  }
887  else if (flag == KAEventPrivate::ARCHIVE_FLAG)
888  mArchive = true;
889  else if (flag == KAEventPrivate::AT_LOGIN_TYPE)
890  mArchiveRepeatAtLogin = true;
891  else if (flag == KAEventPrivate::REMINDER_TYPE)
892  {
893  flag = flags.at(++i);
894  if (flag == KAEventPrivate::REMINDER_ONCE_FLAG)
895  {
896  mReminderOnceOnly = true;
897  ++i;
898  }
899  const int len = flag.length() - 1;
900  mReminderMinutes = -flag.left(len).toInt(); // -> 0 if conversion fails
901  switch (flag.at(len).toLatin1())
902  {
903  case 'M': break;
904  case 'H': mReminderMinutes *= 60; break;
905  case 'D': mReminderMinutes *= 1440; break;
906  default: mReminderMinutes = 0; break;
907  }
908  }
909  else if (flag == DEFER_FLAG)
910  {
911  QString mins = flags.at(i + 1);
912  if (mins.endsWith(QLatin1Char('D')))
913  {
914  mDeferDefaultDateOnly = true;
915  mins.truncate(mins.length() - 1);
916  }
917  const int n = static_cast<int>(mins.toUInt(&ok));
918  if (!ok)
919  continue;
920  mDeferDefaultMinutes = n;
921  ++i;
922  }
923  else if (flag == TEMPL_AFTER_TIME_FLAG)
924  {
925  const int n = static_cast<int>(flags.at(i + 1).toUInt(&ok));
926  if (!ok)
927  continue;
928  mTemplateAfterTime = n;
929  ++i;
930  }
931  else if (flag == LATE_CANCEL_FLAG)
932  {
933  mLateCancel = static_cast<int>(flags.at(i + 1).toUInt(&ok));
934  if (ok)
935  ++i;
936  if (!ok || !mLateCancel)
937  mLateCancel = 1; // invalid parameter defaults to 1 minute
938  }
939  else if (flag == AUTO_CLOSE_FLAG)
940  {
941  mLateCancel = static_cast<int>(flags.at(i + 1).toUInt(&ok));
942  if (ok)
943  ++i;
944  if (!ok || !mLateCancel)
945  mLateCancel = 1; // invalid parameter defaults to 1 minute
946  mAutoClose = true;
947  }
948  }
949 
950  QString prop = event->customProperty(KACalendar::APPNAME, LOG_PROPERTY);
951  if (!prop.isEmpty())
952  {
953  if (prop == xtermURL)
954  mCommandXterm = true;
955  else if (prop == displayURL)
956  mCommandDisplay = true;
957  else
958  mLogFile = prop;
959  }
960  prop = event->customProperty(KACalendar::APPNAME, REPEAT_PROPERTY);
961  if (!prop.isEmpty())
962  {
963  // This property is used when the main alarm has expired
964  const QStringList list = prop.split(QLatin1Char(':'));
965  if (list.count() >= 2)
966  {
967  const int interval = static_cast<int>(list[0].toUInt());
968  const int count = static_cast<int>(list[1].toUInt());
969  if (interval && count)
970  {
971  if (interval % (24*60))
972  mRepetition.set(Duration(interval * 60, Duration::Seconds), count);
973  else
974  mRepetition.set(Duration(interval / (24*60), Duration::Days), count);
975  }
976  }
977  }
978  mNextMainDateTime = readDateTime(event, dateOnly, mStartDateTime);
979  mCreatedDateTime = event->created();
980  if (dateOnly && !mRepetition.isDaily())
981  mRepetition.set(Duration(mRepetition.intervalDays(), Duration::Days));
982  if (mCategory == CalEvent::TEMPLATE)
983  mTemplateName = event->summary();
984 #ifndef KALARMCAL_USE_KRESOURCES
985  if (event->customStatus() == DISABLED_STATUS)
986 #else
987  if (event->statusStr() == DISABLED_STATUS)
988 #endif
989  mEnabled = false;
990 
991  // Extract status from the event's alarms.
992  // First set up defaults.
993  mActionSubType = KAEvent::MESSAGE;
994  mMainExpired = true;
995  mRepeatAtLogin = false;
996  mDisplaying = false;
997  mCommandScript = false;
998  mExtraActionOptions = 0;
999  mDeferral = NO_DEFERRAL;
1000  mSoundVolume = -1;
1001  mFadeVolume = -1;
1002  mRepeatSoundPause = -1;
1003  mFadeSeconds = 0;
1004  mEmailFromIdentity = 0;
1005  mReminderAfterTime = DateTime();
1006  mText.clear();
1007  mAudioFile.clear();
1008  mPreAction.clear();
1009  mPostAction.clear();
1010  mEmailSubject.clear();
1011  mEmailAddresses.clear();
1012  mEmailAttachments.clear();
1013 
1014  // Extract data from all the event's alarms and index the alarms by sequence number
1015  AlarmMap alarmMap;
1016  readAlarms(event, &alarmMap, mCommandDisplay);
1017 
1018  // Incorporate the alarms' details into the overall event
1019  mAlarmCount = 0; // initialise as invalid
1020  DateTime alTime;
1021  bool set = false;
1022  bool isEmailText = false;
1023  bool setDeferralTime = false;
1024  Duration deferralOffset;
1025  for (AlarmMap::ConstIterator it = alarmMap.constBegin(); it != alarmMap.constEnd(); ++it)
1026  {
1027  const AlarmData& data = it.value();
1028  const DateTime dateTime = data.alarm->hasStartOffset() ? data.alarm->startOffset().end(mNextMainDateTime.effectiveKDateTime()) : data.alarm->time();
1029  switch (data.type)
1030  {
1031  case MAIN_ALARM:
1032  mMainExpired = false;
1033  alTime = dateTime;
1034  alTime.setDateOnly(mStartDateTime.isDateOnly());
1035  if (data.alarm->repeatCount() && data.alarm->snoozeTime())
1036  {
1037  mRepetition.set(data.alarm->snoozeTime(), data.alarm->repeatCount()); // values may be adjusted in setRecurrence()
1038  mNextRepeat = data.nextRepeat;
1039  }
1040  if (data.action != KAAlarm::AUDIO)
1041  break;
1042  // Fall through to AUDIO_ALARM
1043  case AUDIO_ALARM:
1044  mAudioFile = data.cleanText;
1045  mSpeak = data.speak && mAudioFile.isEmpty();
1046  mBeep = !mSpeak && mAudioFile.isEmpty();
1047  mSoundVolume = (!mBeep && !mSpeak) ? data.soundVolume : -1;
1048  mFadeVolume = (mSoundVolume >= 0 && data.fadeSeconds > 0) ? data.fadeVolume : -1;
1049  mFadeSeconds = (mFadeVolume >= 0) ? data.fadeSeconds : 0;
1050  mRepeatSoundPause = (!mBeep && !mSpeak) ? data.repeatSoundPause : -1;
1051  break;
1052  case AT_LOGIN_ALARM:
1053  mRepeatAtLogin = true;
1054  mAtLoginDateTime = dateTime.kDateTime();
1055  alTime = mAtLoginDateTime;
1056  break;
1057  case REMINDER_ALARM:
1058  // N.B. there can be a start offset but no valid date/time (e.g. in template)
1059  if (data.alarm->startOffset().asSeconds() / 60)
1060  {
1061  mReminderActive = ACTIVE_REMINDER;
1062  if (mReminderMinutes < 0)
1063  {
1064  mReminderAfterTime = dateTime; // the reminder is AFTER the main alarm
1065  mReminderAfterTime.setDateOnly(dateOnly);
1066  if (data.hiddenReminder)
1067  mReminderActive = HIDDEN_REMINDER;
1068  }
1069  }
1070  break;
1071  case DEFERRED_REMINDER_ALARM:
1072  case DEFERRED_ALARM:
1073  mDeferral = (data.type == DEFERRED_REMINDER_ALARM) ? REMINDER_DEFERRAL : NORMAL_DEFERRAL;
1074  mDeferralTime = dateTime;
1075  if (!data.timedDeferral)
1076  mDeferralTime.setDateOnly(true);
1077  if (data.alarm->hasStartOffset())
1078  deferralOffset = data.alarm->startOffset();
1079  break;
1080  case DISPLAYING_ALARM:
1081  {
1082  mDisplaying = true;
1083  mDisplayingFlags = data.displayingFlags;
1084  const bool dateOnly = (mDisplayingFlags & DEFERRAL) ? !(mDisplayingFlags & TIMED_FLAG)
1085  : mStartDateTime.isDateOnly();
1086  mDisplayingTime = dateTime;
1087  mDisplayingTime.setDateOnly(dateOnly);
1088  alTime = mDisplayingTime;
1089  break;
1090  }
1091  case PRE_ACTION_ALARM:
1092  mPreAction = data.cleanText;
1093  mExtraActionOptions = data.extraActionOptions;
1094  break;
1095  case POST_ACTION_ALARM:
1096  mPostAction = data.cleanText;
1097  break;
1098  case INVALID_ALARM:
1099  default:
1100  break;
1101  }
1102 
1103  bool noSetNextTime = false;
1104  switch (data.type)
1105  {
1106  case DEFERRED_REMINDER_ALARM:
1107  case DEFERRED_ALARM:
1108  if (!set)
1109  {
1110  // The recurrence has to be evaluated before we can
1111  // calculate the time of a deferral alarm.
1112  setDeferralTime = true;
1113  noSetNextTime = true;
1114  }
1115  // fall through to REMINDER_ALARM
1116  case REMINDER_ALARM:
1117  case AT_LOGIN_ALARM:
1118  case DISPLAYING_ALARM:
1119  if (!set && !noSetNextTime)
1120  mNextMainDateTime = alTime;
1121  // fall through to MAIN_ALARM
1122  case MAIN_ALARM:
1123  // Ensure that the basic fields are set up even if there is no main
1124  // alarm in the event (if it has expired and then been deferred)
1125  if (!set)
1126  {
1127  mActionSubType = static_cast<KAEvent::SubAction>(data.action);
1128  mText = (mActionSubType == KAEvent::COMMAND) ? data.cleanText.trimmed() : data.cleanText;
1129  switch (data.action)
1130  {
1131  case KAAlarm::COMMAND:
1132  mCommandScript = data.commandScript;
1133  if (!mCommandDisplay)
1134  break;
1135  // fall through to MESSAGE
1136  case KAAlarm::MESSAGE:
1137  mFont = data.font;
1138  mUseDefaultFont = data.defaultFont;
1139  if (data.isEmailText)
1140  isEmailText = true;
1141  // fall through to FILE
1142  case KAAlarm::FILE:
1143  mBgColour = data.bgColour;
1144  mFgColour = data.fgColour;
1145  break;
1146  case KAAlarm::EMAIL:
1147  mEmailFromIdentity = data.emailFromId;
1148  mEmailAddresses = data.alarm->mailAddresses();
1149  mEmailSubject = data.alarm->mailSubject();
1150  mEmailAttachments = data.alarm->mailAttachments();
1151  break;
1152  case KAAlarm::AUDIO:
1153  // Already mostly handled above
1154  mRepeatSoundPause = data.repeatSoundPause;
1155  break;
1156  default:
1157  break;
1158  }
1159  set = true;
1160  }
1161  if (data.action == KAAlarm::FILE && mActionSubType == KAEvent::MESSAGE)
1162  mActionSubType = KAEvent::FILE;
1163  ++mAlarmCount;
1164  break;
1165  case AUDIO_ALARM:
1166  case PRE_ACTION_ALARM:
1167  case POST_ACTION_ALARM:
1168  case INVALID_ALARM:
1169  default:
1170  break;
1171  }
1172  }
1173  if (!isEmailText)
1174  mKMailSerialNumber = 0;
1175 
1176  Recurrence* recur = event->recurrence();
1177  if (recur && recur->recurs())
1178  {
1179  const int nextRepeat = mNextRepeat; // setRecurrence() clears mNextRepeat
1180  setRecurrence(*recur);
1181  if (nextRepeat <= mRepetition.count())
1182  mNextRepeat = nextRepeat;
1183  }
1184  else if (mRepetition)
1185  {
1186  // Convert a repetition with no recurrence into a recurrence
1187  if (mRepetition.isDaily())
1188  setRecur(RecurrenceRule::rDaily, mRepetition.intervalDays(), mRepetition.count() + 1, QDate());
1189  else
1190  setRecur(RecurrenceRule::rMinutely, mRepetition.intervalMinutes(), mRepetition.count() + 1, KDateTime());
1191  mRepetition.set(0, 0);
1192  mTriggerChanged = true;
1193  }
1194 
1195  if (mRepeatAtLogin)
1196  {
1197  mArchiveRepeatAtLogin = false;
1198  if (mReminderMinutes > 0)
1199  {
1200  mReminderMinutes = 0; // pre-alarm reminder not allowed for at-login alarm
1201  mReminderActive = NO_REMINDER;
1202  }
1203  setRepeatAtLoginTrue(false); // clear other incompatible statuses
1204  }
1205 
1206  if (mMainExpired && deferralOffset && checkRecur() != KARecurrence::NO_RECUR)
1207  {
1208  // Adjust the deferral time for an expired recurrence, since the
1209  // offset is relative to the first actual occurrence.
1210  DateTime dt = mRecurrence->getNextDateTime(mStartDateTime.addDays(-1).kDateTime());
1211  dt.setDateOnly(mStartDateTime.isDateOnly());
1212  if (mDeferralTime.isDateOnly())
1213  {
1214  mDeferralTime = deferralOffset.end(dt.kDateTime());
1215  mDeferralTime.setDateOnly(true);
1216  }
1217  else
1218  mDeferralTime = deferralOffset.end(dt.effectiveKDateTime());
1219  }
1220  if (mDeferral != NO_DEFERRAL)
1221  {
1222  if (setDeferralTime)
1223  mNextMainDateTime = mDeferralTime;
1224  }
1225  mTriggerChanged = true;
1226  endChanges();
1227 }
1228 
1229 void KAEvent::set(const KDateTime& dt, const QString& message, const QColor& bg, const QColor& fg,
1230  const QFont& f, SubAction act, int lateCancel, Flags flags, bool changesPending)
1231 {
1232  d->set(dt, message, bg, fg, f, act, lateCancel, flags, changesPending);
1233 }
1234 
1235 /******************************************************************************
1236 * Initialise the instance with the specified parameters.
1237 */
1238 void KAEventPrivate::set(const KDateTime& dateTime, const QString& text, const QColor& bg, const QColor& fg,
1239  const QFont& font, KAEvent::SubAction action, int lateCancel, KAEvent::Flags flags,
1240  bool changesPending)
1241 {
1242  clearRecur();
1243  mStartDateTime = dateTime;
1244  mStartDateTime.setDateOnly(flags & KAEvent::ANY_TIME);
1245  mNextMainDateTime = mStartDateTime;
1246  switch (action)
1247  {
1248  case KAEvent::MESSAGE:
1249  case KAEvent::FILE:
1250  case KAEvent::COMMAND:
1251  case KAEvent::EMAIL:
1252  case KAEvent::AUDIO:
1253  mActionSubType = static_cast<KAEvent::SubAction>(action);
1254  break;
1255  default:
1256  mActionSubType = KAEvent::MESSAGE;
1257  break;
1258  }
1259  mEventID.clear();
1260  mTemplateName.clear();
1261 #ifndef KALARMCAL_USE_KRESOURCES
1262  mItemId = -1;
1263  mCollectionId = -1;
1264 #else
1265  mResource = 0;
1266  mOriginalResourceId.clear();
1267 #endif
1268  mPreAction.clear();
1269  mPostAction.clear();
1270  mText = (mActionSubType == KAEvent::COMMAND) ? text.trimmed()
1271  : (mActionSubType == KAEvent::AUDIO) ? QString() : text;
1272  mCategory = CalEvent::ACTIVE;
1273  mAudioFile = (mActionSubType == KAEvent::AUDIO) ? text : QString();
1274  mSoundVolume = -1;
1275  mFadeVolume = -1;
1276  mTemplateAfterTime = -1;
1277  mFadeSeconds = 0;
1278  mBgColour = bg;
1279  mFgColour = fg;
1280  mFont = font;
1281  mAlarmCount = 1;
1282  mLateCancel = lateCancel; // do this before setting flags
1283  mDeferral = NO_DEFERRAL; // do this before setting flags
1284 
1285  mStartDateTime.setDateOnly(flags & KAEvent::ANY_TIME);
1286  set_deferral((flags & DEFERRAL) ? NORMAL_DEFERRAL : NO_DEFERRAL);
1287  mRepeatAtLogin = flags & KAEvent::REPEAT_AT_LOGIN;
1288  mConfirmAck = flags & KAEvent::CONFIRM_ACK;
1289  mUseDefaultFont = flags & KAEvent::DEFAULT_FONT;
1290  mCommandScript = flags & KAEvent::SCRIPT;
1291  mCommandXterm = flags & KAEvent::EXEC_IN_XTERM;
1292  mCommandDisplay = flags & KAEvent::DISPLAY_COMMAND;
1293  mCopyToKOrganizer = flags & KAEvent::COPY_KORGANIZER;
1294  mExcludeHolidays = (flags & KAEvent::EXCL_HOLIDAYS) ? mHolidays : 0;
1295  mWorkTimeOnly = flags & KAEvent::WORK_TIME_ONLY;
1296  mEmailBcc = flags & KAEvent::EMAIL_BCC;
1297  mEnabled = !(flags & KAEvent::DISABLED);
1298  mDisplaying = flags & DISPLAYING_;
1299  mReminderOnceOnly = flags & KAEvent::REMINDER_ONCE;
1300  mAutoClose = (flags & KAEvent::AUTO_CLOSE) && mLateCancel;
1301  mRepeatSoundPause = (flags & KAEvent::REPEAT_SOUND) ? 0 : -1;
1302  mSpeak = (flags & KAEvent::SPEAK) && action != KAEvent::AUDIO;
1303  mBeep = (flags & KAEvent::BEEP) && action != KAEvent::AUDIO && !mSpeak;
1304  if (mRepeatAtLogin) // do this after setting other flags
1305  {
1306  ++mAlarmCount;
1307  setRepeatAtLoginTrue(false);
1308  }
1309 
1310  mKMailSerialNumber = 0;
1311  mReminderMinutes = 0;
1312  mDeferDefaultMinutes = 0;
1313  mDeferDefaultDateOnly = false;
1314  mArchiveRepeatAtLogin = false;
1315  mReminderActive = NO_REMINDER;
1316  mDisplaying = false;
1317  mMainExpired = false;
1318  mDisplayingDefer = false;
1319  mDisplayingEdit = false;
1320  mArchive = false;
1321  mReminderAfterTime = DateTime();
1322  mExtraActionOptions = 0;
1323 #ifndef KALARMCAL_USE_KRESOURCES
1324  mCompatibility = KACalendar::Current;
1325  mReadOnly = false;
1326 #endif
1327  mCommandError = KAEvent::CMD_NO_ERROR;
1328  mChangeCount = changesPending ? 1 : 0;
1329  mTriggerChanged = true;
1330 }
1331 
1332 /******************************************************************************
1333 * Update an existing KCal::Event with the KAEventPrivate data.
1334 * If 'setCustomProperties' is true, all the KCal::Event's existing custom
1335 * properties are cleared and replaced with the KAEvent's custom properties. If
1336 * false, the KCal::Event's non-KAlarm custom properties are left untouched.
1337 */
1338 #ifndef KALARMCAL_USE_KRESOURCES
1339 bool KAEvent::updateKCalEvent(const KCalCore::Event::Ptr& e, UidAction u, bool setCustomProperties) const
1340 {
1341  return d->updateKCalEvent(e, u, setCustomProperties);
1342 }
1343 
1344 #else
1345 bool KAEvent::updateKCalEvent(KCal::Event* e, UidAction u) const
1346 {
1347  return d->updateKCalEvent(e, u);
1348 }
1349 #endif
1350 
1351 #ifndef KALARMCAL_USE_KRESOURCES
1352 bool KAEventPrivate::updateKCalEvent(const Event::Ptr& ev, KAEvent::UidAction uidact, bool setCustomProperties) const
1353 #else
1354 bool KAEventPrivate::updateKCalEvent(Event* ev, KAEvent::UidAction uidact) const
1355 #endif
1356 {
1357  // If it's an archived event, the event start date/time will be adjusted to its original
1358  // value instead of its next occurrence, and the expired main alarm will be reinstated.
1359  const bool archived = (mCategory == CalEvent::ARCHIVED);
1360 
1361  if (!ev
1362  || (uidact == KAEvent::UID_CHECK && !mEventID.isEmpty() && mEventID != ev->uid())
1363  || (!mAlarmCount && (!archived || !mMainExpired)))
1364  return false;
1365 
1366  ev->startUpdates(); // prevent multiple update notifications
1367  checkRecur(); // ensure recurrence/repetition data is consistent
1368  const bool readOnly = ev->isReadOnly();
1369  if (uidact == KAEvent::UID_SET)
1370  ev->setUid(mEventID);
1371 #ifndef KALARMCAL_USE_KRESOURCES
1372  ev->setReadOnly(mReadOnly);
1373 #else
1374  ev->setReadOnly(false);
1375 #endif
1376  ev->setTransparency(Event::Transparent);
1377 
1378  // Set up event-specific data
1379 
1380  // Set up custom properties.
1381 #ifndef KALARMCAL_USE_KRESOURCES
1382  if (setCustomProperties)
1383  ev->setCustomProperties(mCustomProperties);
1384 #endif
1385  ev->removeCustomProperty(KACalendar::APPNAME, FLAGS_PROPERTY);
1386  ev->removeCustomProperty(KACalendar::APPNAME, NEXT_RECUR_PROPERTY);
1387  ev->removeCustomProperty(KACalendar::APPNAME, REPEAT_PROPERTY);
1388  ev->removeCustomProperty(KACalendar::APPNAME, LOG_PROPERTY);
1389 
1390  QString param;
1391  if (mCategory == CalEvent::DISPLAYING)
1392  {
1393 #ifndef KALARMCAL_USE_KRESOURCES
1394  param = QString::number(mCollectionId); // original collection ID which contained the event
1395 #else
1396  param = mOriginalResourceId;
1397 #endif
1398  if (mDisplayingDefer)
1399  param += SC + DISP_DEFER;
1400  if (mDisplayingEdit)
1401  param += SC + DISP_EDIT;
1402  }
1403 #ifndef KALARMCAL_USE_KRESOURCES
1404  CalEvent::setStatus(ev, mCategory, param);
1405 #else
1406  CalEvent::setStatus(ev, mCategory, param);
1407 #endif
1408  QStringList flags;
1409  if (mStartDateTime.isDateOnly())
1410  flags += DATE_ONLY_FLAG;
1411  if (mConfirmAck)
1412  flags += CONFIRM_ACK_FLAG;
1413  if (mEmailBcc)
1414  flags += EMAIL_BCC_FLAG;
1415  if (mCopyToKOrganizer)
1416  flags += KORGANIZER_FLAG;
1417  if (mExcludeHolidays)
1418  flags += EXCLUDE_HOLIDAYS_FLAG;
1419  if (mWorkTimeOnly)
1420  flags += WORK_TIME_ONLY_FLAG;
1421  if (mLateCancel)
1422  (flags += (mAutoClose ? AUTO_CLOSE_FLAG : LATE_CANCEL_FLAG)) += QString::number(mLateCancel);
1423  if (mReminderMinutes)
1424  {
1425  flags += REMINDER_TYPE;
1426  if (mReminderOnceOnly)
1427  flags += REMINDER_ONCE_FLAG;
1428  flags += reminderToString(-mReminderMinutes);
1429  }
1430  if (mDeferDefaultMinutes)
1431  {
1432  QString param = QString::number(mDeferDefaultMinutes);
1433  if (mDeferDefaultDateOnly)
1434  param += QLatin1Char('D');
1435  (flags += DEFER_FLAG) += param;
1436  }
1437  if (!mTemplateName.isEmpty() && mTemplateAfterTime >= 0)
1438  (flags += TEMPL_AFTER_TIME_FLAG) += QString::number(mTemplateAfterTime);
1439  if (mKMailSerialNumber)
1440  (flags += KMAIL_SERNUM_FLAG) += QString::number(mKMailSerialNumber);
1441  if (mArchive && !archived)
1442  {
1443  flags += ARCHIVE_FLAG;
1444  if (mArchiveRepeatAtLogin)
1445  flags += AT_LOGIN_TYPE;
1446  }
1447  if (!flags.isEmpty())
1448  ev->setCustomProperty(KACalendar::APPNAME, FLAGS_PROPERTY, flags.join(SC));
1449 
1450  if (mCommandXterm)
1451  ev->setCustomProperty(KACalendar::APPNAME, LOG_PROPERTY, xtermURL);
1452  else if (mCommandDisplay)
1453  ev->setCustomProperty(KACalendar::APPNAME, LOG_PROPERTY, displayURL);
1454  else if (!mLogFile.isEmpty())
1455  ev->setCustomProperty(KACalendar::APPNAME, LOG_PROPERTY, mLogFile);
1456 
1457  ev->setCustomStatus(mEnabled ? QString() : DISABLED_STATUS);
1458  ev->setRevision(mRevision);
1459  ev->clearAlarms();
1460 
1461  /* Always set DTSTART as date/time, and use the category "DATE" to indicate
1462  * a date-only event, instead of calling setAllDay(). This is necessary to
1463  * allow a time zone to be specified for a date-only event. Also, KAlarm
1464  * allows the alarm to float within the 24-hour period defined by the
1465  * start-of-day time (which is user-dependent and therefore can't be
1466  * written into the calendar) rather than midnight to midnight, and there
1467  * is no RFC2445 conformant way to specify this.
1468  * RFC2445 states that alarm trigger times specified in absolute terms
1469  * (rather than relative to DTSTART or DTEND) can only be specified as a
1470  * UTC DATE-TIME value. So always use a time relative to DTSTART instead of
1471  * an absolute time.
1472  */
1473  ev->setDtStart(mStartDateTime.calendarKDateTime());
1474  ev->setAllDay(false);
1475  ev->setDtEnd(KDateTime());
1476 
1477  const DateTime dtMain = archived ? mStartDateTime : mNextMainDateTime;
1478  int ancillaryType = 0; // 0 = invalid, 1 = time, 2 = offset
1479  DateTime ancillaryTime; // time for ancillary alarms (pre-action, extra audio, etc)
1480  int ancillaryOffset = 0; // start offset for ancillary alarms
1481  if (!mMainExpired || archived)
1482  {
1483  /* The alarm offset must always be zero for the main alarm. To determine
1484  * which recurrence is due, the property X-KDE-KALARM_NEXTRECUR is used.
1485  * If the alarm offset was non-zero, exception dates and rules would not
1486  * work since they apply to the event time, not the alarm time.
1487  */
1488  if (!archived && checkRecur() != KARecurrence::NO_RECUR)
1489  {
1490  QDateTime dt = mNextMainDateTime.kDateTime().toTimeSpec(mStartDateTime.timeSpec()).dateTime();
1491  ev->setCustomProperty(KACalendar::APPNAME, NEXT_RECUR_PROPERTY,
1492  dt.toString(mNextMainDateTime.isDateOnly() ? QLatin1String("yyyyMMdd") : QLatin1String("yyyyMMddThhmmss")));
1493  }
1494  // Add the main alarm
1495  initKCalAlarm(ev, 0, QStringList(), MAIN_ALARM);
1496  ancillaryOffset = 0;
1497  ancillaryType = dtMain.isValid() ? 2 : 0;
1498  }
1499  else if (mRepetition)
1500  {
1501  // Alarm repetition is normally held in the main alarm, but since
1502  // the main alarm has expired, store in a custom property.
1503  const QString param = QString::fromLatin1("%1:%2").arg(mRepetition.intervalMinutes()).arg(mRepetition.count());
1504  ev->setCustomProperty(KACalendar::APPNAME, REPEAT_PROPERTY, param);
1505  }
1506 
1507  // Add subsidiary alarms
1508  if (mRepeatAtLogin || (mArchiveRepeatAtLogin && archived))
1509  {
1510  DateTime dtl;
1511  if (mArchiveRepeatAtLogin)
1512  dtl = mStartDateTime.calendarKDateTime().addDays(-1);
1513  else if (mAtLoginDateTime.isValid())
1514  dtl = mAtLoginDateTime;
1515  else if (mStartDateTime.isDateOnly())
1516  dtl = DateTime(KDateTime::currentLocalDate().addDays(-1), mStartDateTime.timeSpec());
1517  else
1518  dtl = KDateTime::currentUtcDateTime();
1519  initKCalAlarm(ev, dtl, QStringList(AT_LOGIN_TYPE));
1520  if (!ancillaryType && dtl.isValid())
1521  {
1522  ancillaryTime = dtl;
1523  ancillaryType = 1;
1524  }
1525  }
1526 
1527  // Find the base date/time for calculating alarm offsets
1528  DateTime nextDateTime = mNextMainDateTime;
1529  if (mMainExpired)
1530  {
1531  if (checkRecur() == KARecurrence::NO_RECUR)
1532  nextDateTime = mStartDateTime;
1533  else if (!archived)
1534  {
1535  // It's a deferral of an expired recurrence.
1536  // Need to ensure that the alarm offset is to an occurrence
1537  // which isn't excluded by an exception - otherwise, it will
1538  // never be triggered. So choose the first recurrence which
1539  // isn't an exception.
1540  KDateTime dt = mRecurrence->getNextDateTime(mStartDateTime.addDays(-1).kDateTime());
1541  dt.setDateOnly(mStartDateTime.isDateOnly());
1542  nextDateTime = dt;
1543  }
1544  }
1545 
1546  if (mReminderMinutes && (mReminderActive != NO_REMINDER || archived))
1547  {
1548  int startOffset;
1549  if (mReminderMinutes < 0 && mReminderActive != NO_REMINDER)
1550  {
1551  // A reminder AFTER the main alarm is active or disabled
1552  startOffset = nextDateTime.calendarKDateTime().secsTo(mReminderAfterTime.calendarKDateTime());
1553  }
1554  else
1555  {
1556  // A reminder BEFORE the main alarm is active
1557  startOffset = -mReminderMinutes * 60;
1558  }
1559  initKCalAlarm(ev, startOffset, QStringList(REMINDER_TYPE));
1560  // Don't set ancillary time if the reminder AFTER is hidden by a deferral
1561  if (!ancillaryType && (mReminderActive == ACTIVE_REMINDER || archived))
1562  {
1563  ancillaryOffset = startOffset;
1564  ancillaryType = 2;
1565  }
1566  }
1567  if (mDeferral != NO_DEFERRAL)
1568  {
1569  int startOffset;
1570  QStringList list;
1571  if (mDeferralTime.isDateOnly())
1572  {
1573  startOffset = nextDateTime.secsTo(mDeferralTime.calendarKDateTime());
1574  list += DATE_DEFERRAL_TYPE;
1575  }
1576  else
1577  {
1578  startOffset = nextDateTime.calendarKDateTime().secsTo(mDeferralTime.calendarKDateTime());
1579  list += TIME_DEFERRAL_TYPE;
1580  }
1581  if (mDeferral == REMINDER_DEFERRAL)
1582  list += REMINDER_TYPE;
1583  initKCalAlarm(ev, startOffset, list);
1584  if (!ancillaryType && mDeferralTime.isValid())
1585  {
1586  ancillaryOffset = startOffset;
1587  ancillaryType = 2;
1588  }
1589  }
1590  if (!mTemplateName.isEmpty())
1591  ev->setSummary(mTemplateName);
1592  else if (mDisplaying)
1593  {
1594  QStringList list(DISPLAYING_TYPE);
1595  if (mDisplayingFlags & KAEvent::REPEAT_AT_LOGIN)
1596  list += AT_LOGIN_TYPE;
1597  else if (mDisplayingFlags & DEFERRAL)
1598  {
1599  if (mDisplayingFlags & TIMED_FLAG)
1600  list += TIME_DEFERRAL_TYPE;
1601  else
1602  list += DATE_DEFERRAL_TYPE;
1603  }
1604  if (mDisplayingFlags & REMINDER)
1605  list += REMINDER_TYPE;
1606  initKCalAlarm(ev, mDisplayingTime, list);
1607  if (!ancillaryType && mDisplayingTime.isValid())
1608  {
1609  ancillaryTime = mDisplayingTime;
1610  ancillaryType = 1;
1611  }
1612  }
1613  if ((mBeep || mSpeak || !mAudioFile.isEmpty()) && mActionSubType != KAEvent::AUDIO)
1614  {
1615  // A sound is specified
1616  if (ancillaryType == 2)
1617  initKCalAlarm(ev, ancillaryOffset, QStringList(), AUDIO_ALARM);
1618  else
1619  initKCalAlarm(ev, ancillaryTime, QStringList(), AUDIO_ALARM);
1620  }
1621  if (!mPreAction.isEmpty())
1622  {
1623  // A pre-display action is specified
1624  if (ancillaryType == 2)
1625  initKCalAlarm(ev, ancillaryOffset, QStringList(PRE_ACTION_TYPE), PRE_ACTION_ALARM);
1626  else
1627  initKCalAlarm(ev, ancillaryTime, QStringList(PRE_ACTION_TYPE), PRE_ACTION_ALARM);
1628  }
1629  if (!mPostAction.isEmpty())
1630  {
1631  // A post-display action is specified
1632  if (ancillaryType == 2)
1633  initKCalAlarm(ev, ancillaryOffset, QStringList(POST_ACTION_TYPE), POST_ACTION_ALARM);
1634  else
1635  initKCalAlarm(ev, ancillaryTime, QStringList(POST_ACTION_TYPE), POST_ACTION_ALARM);
1636  }
1637 
1638  if (mRecurrence)
1639  mRecurrence->writeRecurrence(*ev->recurrence());
1640  else
1641  ev->clearRecurrence();
1642  if (mCreatedDateTime.isValid())
1643  ev->setCreated(mCreatedDateTime);
1644  ev->setReadOnly(readOnly);
1645  ev->endUpdates(); // finally issue an update notification
1646  return true;
1647 }
1648 
1649 /******************************************************************************
1650 * Create a new alarm for a libkcal event, and initialise it according to the
1651 * alarm action. If 'types' is non-null, it is appended to the X-KDE-KALARM-TYPE
1652 * property value list.
1653 * NOTE: The variant taking a DateTime calculates the offset from mStartDateTime,
1654 * which is not suitable for an alarm in a recurring event.
1655 */
1656 #ifndef KALARMCAL_USE_KRESOURCES
1657 Alarm::Ptr KAEventPrivate::initKCalAlarm(const Event::Ptr& event, const DateTime& dt, const QStringList& types, AlarmType type) const
1658 #else
1659 Alarm* KAEventPrivate::initKCalAlarm(Event* event, const DateTime& dt, const QStringList& types, AlarmType type) const
1660 #endif
1661 {
1662  const int startOffset = dt.isDateOnly() ? mStartDateTime.secsTo(dt)
1663  : mStartDateTime.calendarKDateTime().secsTo(dt.calendarKDateTime());
1664  return initKCalAlarm(event, startOffset, types, type);
1665 }
1666 
1667 #ifndef KALARMCAL_USE_KRESOURCES
1668 Alarm::Ptr KAEventPrivate::initKCalAlarm(const Event::Ptr& event, int startOffsetSecs, const QStringList& types, AlarmType type) const
1669 #else
1670 Alarm* KAEventPrivate::initKCalAlarm(Event* event, int startOffsetSecs, const QStringList& types, AlarmType type) const
1671 #endif
1672 {
1673  QStringList alltypes;
1674  QStringList flags;
1675 #ifndef KALARMCAL_USE_KRESOURCES
1676  Alarm::Ptr alarm = event->newAlarm();
1677 #else
1678  Alarm* alarm = event->newAlarm();
1679 #endif
1680  alarm->setEnabled(true);
1681  if (type != MAIN_ALARM)
1682  {
1683  // RFC2445 specifies that absolute alarm times must be stored as a UTC DATE-TIME value.
1684  // Set the alarm time as an offset to DTSTART for the reasons described in updateKCalEvent().
1685  alarm->setStartOffset(startOffsetSecs);
1686  }
1687 
1688  switch (type)
1689  {
1690  case AUDIO_ALARM:
1691  setAudioAlarm(alarm);
1692  if (mSpeak)
1693  flags << KAEventPrivate::SPEAK_FLAG;
1694  if (mRepeatSoundPause >= 0)
1695  {
1696  // Alarm::setSnoozeTime() sets 5 seconds if duration parameter is zero,
1697  // so repeat count = -1 represents 0 pause, -2 represents non-zero pause.
1698  alarm->setRepeatCount(mRepeatSoundPause ? -2 : -1);
1699  alarm->setSnoozeTime(Duration(mRepeatSoundPause, Duration::Seconds));
1700  }
1701  break;
1702  case PRE_ACTION_ALARM:
1703  setProcedureAlarm(alarm, mPreAction);
1704  if (mExtraActionOptions & KAEvent::ExecPreActOnDeferral)
1705  flags << KAEventPrivate::EXEC_ON_DEFERRAL_FLAG;
1706  if (mExtraActionOptions & KAEvent::CancelOnPreActError)
1707  flags << KAEventPrivate::CANCEL_ON_ERROR_FLAG;
1708  if (mExtraActionOptions & KAEvent::DontShowPreActError)
1709  flags << KAEventPrivate::DONT_SHOW_ERROR_FLAG;
1710  break;
1711  case POST_ACTION_ALARM:
1712  setProcedureAlarm(alarm, mPostAction);
1713  break;
1714  case MAIN_ALARM:
1715  alarm->setSnoozeTime(mRepetition.interval());
1716  alarm->setRepeatCount(mRepetition.count());
1717  if (mRepetition)
1718  alarm->setCustomProperty(KACalendar::APPNAME, NEXT_REPEAT_PROPERTY,
1719  QString::number(mNextRepeat));
1720  // fall through to INVALID_ALARM
1721  case REMINDER_ALARM:
1722  case INVALID_ALARM:
1723  {
1724  if (types == QStringList(REMINDER_TYPE)
1725  && mReminderMinutes < 0 && mReminderActive == HIDDEN_REMINDER)
1726  {
1727  // It's a reminder AFTER the alarm which is currently disabled
1728  // due to the main alarm being deferred past it.
1729  flags << HIDDEN_REMINDER_FLAG;
1730  }
1731  bool display = false;
1732  switch (mActionSubType)
1733  {
1734  case KAEvent::FILE:
1735  alltypes += FILE_TYPE;
1736  // fall through to MESSAGE
1737  case KAEvent::MESSAGE:
1738  alarm->setDisplayAlarm(AlarmText::toCalendarText(mText));
1739  display = true;
1740  break;
1741  case KAEvent::COMMAND:
1742  if (mCommandScript)
1743  alarm->setProcedureAlarm(QString(), mText);
1744  else
1745  setProcedureAlarm(alarm, mText);
1746  display = mCommandDisplay;
1747  break;
1748  case KAEvent::EMAIL:
1749  alarm->setEmailAlarm(mEmailSubject, mText, mEmailAddresses, mEmailAttachments);
1750  if (mEmailFromIdentity)
1751  flags << KAEventPrivate::EMAIL_ID_FLAG << QString::number(mEmailFromIdentity);
1752  break;
1753  case KAEvent::AUDIO:
1754  setAudioAlarm(alarm);
1755  if (mRepeatSoundPause >= 0)
1756  {
1757  alltypes += SOUND_REPEAT_TYPE;
1758  if (type == MAIN_ALARM)
1759  alltypes += QString::number(mRepeatSoundPause);
1760  }
1761  break;
1762  }
1763  if (display)
1764  alarm->setCustomProperty(KACalendar::APPNAME, FONT_COLOUR_PROPERTY,
1765  QString::fromLatin1("%1;%2;%3").arg(mBgColour.name())
1766  .arg(mFgColour.name())
1767  .arg(mUseDefaultFont ? QString() : mFont.toString()));
1768  break;
1769  }
1770  case DEFERRED_ALARM:
1771  case DEFERRED_REMINDER_ALARM:
1772  case AT_LOGIN_ALARM:
1773  case DISPLAYING_ALARM:
1774  break;
1775  }
1776  alltypes += types;
1777  if (!alltypes.isEmpty())
1778  alarm->setCustomProperty(KACalendar::APPNAME, TYPE_PROPERTY, alltypes.join(QLatin1String(",")));
1779  if (!flags.isEmpty())
1780  alarm->setCustomProperty(KACalendar::APPNAME, FLAGS_PROPERTY, flags.join(SC));
1781  return alarm;
1782 }
1783 
1784 bool KAEvent::isValid() const
1785 {
1786  return d->mAlarmCount && (d->mAlarmCount != 1 || !d->mRepeatAtLogin);
1787 }
1788 
1789 void KAEvent::setEnabled(bool enable)
1790 {
1791  d->mEnabled = enable;
1792 }
1793 
1794 bool KAEvent::enabled() const
1795 {
1796  return d->mEnabled;
1797 }
1798 
1799 #ifndef KALARMCAL_USE_KRESOURCES
1800 void KAEvent::setReadOnly(bool ro)
1801 {
1802  d->mReadOnly = ro;
1803 }
1804 
1805 bool KAEvent::isReadOnly() const
1806 {
1807  return d->mReadOnly;
1808 }
1809 #endif
1810 
1811 void KAEvent::setArchive()
1812 {
1813  d->mArchive = true;
1814 }
1815 
1816 bool KAEvent::toBeArchived() const
1817 {
1818  return d->mArchive;
1819 }
1820 
1821 bool KAEvent::mainExpired() const
1822 {
1823  return d->mMainExpired;
1824 }
1825 
1826 bool KAEvent::expired() const
1827 {
1828  return (d->mDisplaying && d->mMainExpired) || d->mCategory == CalEvent::ARCHIVED;
1829 }
1830 
1831 KAEvent::Flags KAEvent::flags() const
1832 {
1833  return d->flags();
1834 }
1835 
1836 KAEvent::Flags KAEventPrivate::flags() const
1837 {
1838  KAEvent::Flags result(0);
1839  if (mBeep) result |= KAEvent::BEEP;
1840  if (mRepeatSoundPause >= 0) result |= KAEvent::REPEAT_SOUND;
1841  if (mEmailBcc) result |= KAEvent::EMAIL_BCC;
1842  if (mStartDateTime.isDateOnly()) result |= KAEvent::ANY_TIME;
1843  if (mSpeak) result |= KAEvent::SPEAK;
1844  if (mRepeatAtLogin) result |= KAEvent::REPEAT_AT_LOGIN;
1845  if (mConfirmAck) result |= KAEvent::CONFIRM_ACK;
1846  if (mUseDefaultFont) result |= KAEvent::DEFAULT_FONT;
1847  if (mCommandScript) result |= KAEvent::SCRIPT;
1848  if (mCommandXterm) result |= KAEvent::EXEC_IN_XTERM;
1849  if (mCommandDisplay) result |= KAEvent::DISPLAY_COMMAND;
1850  if (mCopyToKOrganizer) result |= KAEvent::COPY_KORGANIZER;
1851  if (mExcludeHolidays) result |= KAEvent::EXCL_HOLIDAYS;
1852  if (mWorkTimeOnly) result |= KAEvent::WORK_TIME_ONLY;
1853  if (mReminderOnceOnly) result |= KAEvent::REMINDER_ONCE;
1854  if (mAutoClose) result |= KAEvent::AUTO_CLOSE;
1855  if (!mEnabled) result |= KAEvent::DISABLED;
1856  return result;
1857 }
1858 
1859 /******************************************************************************
1860 * Change the type of an event.
1861 * If it is being set to archived, set the archived indication in the event ID;
1862 * otherwise, remove the archived indication from the event ID.
1863 */
1864 void KAEvent::setCategory(CalEvent::Type s)
1865 {
1866  d->setCategory(s);
1867 }
1868 
1869 void KAEventPrivate::setCategory(CalEvent::Type s)
1870 {
1871  if (s == mCategory)
1872  return;
1873  mEventID = CalEvent::uid(mEventID, s);
1874  mCategory = s;
1875  mTriggerChanged = true; // templates and archived don't have trigger times
1876 }
1877 
1878 CalEvent::Type KAEvent::category() const
1879 {
1880  return d->mCategory;
1881 }
1882 
1883 void KAEvent::setEventId(const QString& id)
1884 {
1885  d->mEventID = id;
1886 }
1887 
1888 QString KAEvent::id() const
1889 {
1890  return d->mEventID;
1891 }
1892 
1893 void KAEvent::incrementRevision()
1894 {
1895  ++d->mRevision;
1896 }
1897 
1898 int KAEvent::revision() const
1899 {
1900  return d->mRevision;
1901 }
1902 
1903 #ifndef KALARMCAL_USE_KRESOURCES
1904 void KAEvent::setCollectionId(Akonadi::Collection::Id id)
1905 {
1906  d->mCollectionId = id;
1907 }
1908 
1909 void KAEvent::setCollectionId_const(Akonadi::Collection::Id id) const
1910 {
1911  d->mCollectionId = id;
1912 }
1913 
1914 Akonadi::Collection::Id KAEvent::collectionId() const
1915 {
1916  // A displaying alarm contains the event's original collection ID
1917  return d->mDisplaying ? -1 : d->mCollectionId;
1918 }
1919 
1920 void KAEvent::setItemId(Akonadi::Item::Id id)
1921 {
1922  d->mItemId = id;
1923 }
1924 
1925 Akonadi::Item::Id KAEvent::itemId() const
1926 {
1927  return d->mItemId;
1928 }
1929 
1930 /******************************************************************************
1931 * Initialise an Item with the event.
1932 * Note that the event is not updated with the Item ID.
1933 * Reply = true if successful,
1934 * false if event's category does not match collection's mime types.
1935 */
1936 bool KAEvent::setItemPayload(Akonadi::Item& item, const QStringList& collectionMimeTypes) const
1937 {
1938  QString mimetype;
1939  switch (d->mCategory)
1940  {
1941  case CalEvent::ACTIVE: mimetype = MIME_ACTIVE; break;
1942  case CalEvent::ARCHIVED: mimetype = MIME_ARCHIVED; break;
1943  case CalEvent::TEMPLATE: mimetype = MIME_TEMPLATE; break;
1944  default: Q_ASSERT(0); return false;
1945  }
1946  if (!collectionMimeTypes.contains(mimetype))
1947  return false;
1948  item.setMimeType(mimetype);
1949  item.setPayload<KAEvent>(*this);
1950  return true;
1951 }
1952 
1953 void KAEvent::setCompatibility(KACalendar::Compat c)
1954 {
1955  d->mCompatibility = c;
1956 }
1957 
1958 KACalendar::Compat KAEvent::compatibility() const
1959 {
1960  return d->mCompatibility;
1961 }
1962 
1963 QMap<QByteArray, QString> KAEvent::customProperties() const
1964 {
1965  return d->mCustomProperties;
1966 }
1967 
1968 #else
1969 void KAEvent::setResource(AlarmResource* r)
1970 {
1971  d->mResource = r;
1972 }
1973 
1974 AlarmResource* KAEvent::resource() const
1975 {
1976  return d->mResource;
1977 }
1978 #endif
1979 
1980 KAEvent::SubAction KAEvent::actionSubType() const
1981 {
1982  return d->mActionSubType;
1983 }
1984 
1985 KAEvent::Actions KAEvent::actionTypes() const
1986 {
1987  switch (d->mActionSubType)
1988  {
1989  case MESSAGE:
1990  case FILE: return ACT_DISPLAY;
1991  case COMMAND: return d->mCommandDisplay ? ACT_DISPLAY_COMMAND : ACT_COMMAND;
1992  case EMAIL: return ACT_EMAIL;
1993  case AUDIO: return ACT_AUDIO;
1994  default: return ACT_NONE;
1995  }
1996 }
1997 
1998 void KAEvent::setLateCancel(int minutes)
1999 {
2000  if (d->mRepeatAtLogin)
2001  minutes = 0;
2002  d->mLateCancel = minutes;
2003  if (!minutes)
2004  d->mAutoClose = false;
2005 }
2006 
2007 int KAEvent::lateCancel() const
2008 {
2009  return d->mLateCancel;
2010 }
2011 
2012 void KAEvent::setAutoClose(bool ac)
2013 {
2014  d->mAutoClose = ac;
2015 }
2016 
2017 bool KAEvent::autoClose() const
2018 {
2019  return d->mAutoClose;
2020 }
2021 
2022 void KAEvent::setKMailSerialNumber(unsigned long n)
2023 {
2024  d->mKMailSerialNumber = n;
2025 }
2026 
2027 unsigned long KAEvent::kmailSerialNumber() const
2028 {
2029  return d->mKMailSerialNumber;
2030 }
2031 
2032 QString KAEvent::cleanText() const
2033 {
2034  return d->mText;
2035 }
2036 
2037 QString KAEvent::message() const
2038 {
2039  return (d->mActionSubType == MESSAGE
2040  || d->mActionSubType == EMAIL) ? d->mText : QString();
2041 }
2042 
2043 QString KAEvent::displayMessage() const
2044 {
2045  return (d->mActionSubType == MESSAGE) ? d->mText : QString();
2046 }
2047 
2048 QString KAEvent::fileName() const
2049 {
2050  return (d->mActionSubType == FILE) ? d->mText : QString();
2051 }
2052 
2053 QColor KAEvent::bgColour() const
2054 {
2055  return d->mBgColour;
2056 }
2057 
2058 QColor KAEvent::fgColour() const
2059 {
2060  return d->mFgColour;
2061 }
2062 
2063 void KAEvent::setDefaultFont(const QFont& f)
2064 {
2065  KAEventPrivate::mDefaultFont = f;
2066 }
2067 
2068 bool KAEvent::useDefaultFont() const
2069 {
2070  return d->mUseDefaultFont;
2071 }
2072 
2073 QFont KAEvent::font() const
2074 {
2075  return d->mUseDefaultFont ? KAEventPrivate::mDefaultFont : d->mFont;
2076 }
2077 
2078 QString KAEvent::command() const
2079 {
2080  return (d->mActionSubType == COMMAND) ? d->mText : QString();
2081 }
2082 
2083 bool KAEvent::commandScript() const
2084 {
2085  return d->mCommandScript;
2086 }
2087 
2088 bool KAEvent::commandXterm() const
2089 {
2090  return d->mCommandXterm;
2091 }
2092 
2093 bool KAEvent::commandDisplay() const
2094 {
2095  return d->mCommandDisplay;
2096 }
2097 
2098 #ifndef KALARMCAL_USE_KRESOURCES
2099 void KAEvent::setCommandError(CmdErrType t) const
2100 {
2101  d->mCommandError = t;
2102 }
2103 
2104 #else
2105 /******************************************************************************
2106 * Set the command last error status.
2107 * If 'writeConfig' is true, the status is written to the config file.
2108 */
2109 void KAEvent::setCommandError(CmdErrType t, bool writeConfig) const
2110 {
2111  d->setCommandError(t, writeConfig);
2112 }
2113 
2114 void KAEventPrivate::setCommandError(KAEvent::CmdErrType error, bool writeConfig) const
2115 {
2116  kDebug() << mEventID << "," << error;
2117  if (error == mCommandError)
2118  return;
2119  mCommandError = error;
2120  if (writeConfig)
2121  {
2122  KConfigGroup config(KGlobal::config(), mCmdErrConfigGroup);
2123  if (mCommandError == KAEvent::CMD_NO_ERROR)
2124  config.deleteEntry(mEventID);
2125  else
2126  {
2127  QString errtext;
2128  switch (mCommandError)
2129  {
2130  case KAEvent::CMD_ERROR: errtext = CMD_ERROR_VALUE; break;
2131  case KAEvent::CMD_ERROR_PRE: errtext = CMD_ERROR_PRE_VALUE; break;
2132  case KAEvent::CMD_ERROR_POST: errtext = CMD_ERROR_POST_VALUE; break;
2133  case KAEvent::CMD_ERROR_PRE_POST:
2134  errtext = CMD_ERROR_PRE_VALUE + ',' + CMD_ERROR_POST_VALUE;
2135  break;
2136  default:
2137  break;
2138  }
2139  config.writeEntry(mEventID, errtext);
2140  }
2141  config.sync();
2142  }
2143 }
2144 
2145 /******************************************************************************
2146 * Initialise the command last error status of the alarm from the config file.
2147 */
2148 void KAEvent::setCommandError(const QString& configString)
2149 {
2150  d->setCommandError(configString);
2151 }
2152 
2153 void KAEventPrivate::setCommandError(const QString& configString)
2154 {
2155  mCommandError = KAEvent::CMD_NO_ERROR;
2156  const QStringList errs = configString.split(',');
2157  if (errs.indexOf(CMD_ERROR_VALUE) >= 0)
2158  mCommandError = KAEvent::CMD_ERROR;
2159  else
2160  {
2161  if (errs.indexOf(CMD_ERROR_PRE_VALUE) >= 0)
2162  mCommandError = KAEvent::CMD_ERROR_PRE;
2163  if (errs.indexOf(CMD_ERROR_POST_VALUE) >= 0)
2164  mCommandError = static_cast<KAEvent::CmdErrType>(mCommandError | KAEvent::CMD_ERROR_POST);
2165  }
2166 }
2167 
2168 QString KAEvent::commandErrorConfigGroup()
2169 {
2170  return KAEventPrivate::mCmdErrConfigGroup;
2171 }
2172 #endif
2173 
2174 KAEvent::CmdErrType KAEvent::commandError() const
2175 {
2176  return d->mCommandError;
2177 }
2178 
2179 void KAEvent::setLogFile(const QString& logfile)
2180 {
2181  d->mLogFile = logfile;
2182  if (!logfile.isEmpty())
2183  d->mCommandDisplay = d->mCommandXterm = false;
2184 }
2185 
2186 QString KAEvent::logFile() const
2187 {
2188  return d->mLogFile;
2189 }
2190 
2191 bool KAEvent::confirmAck() const
2192 {
2193  return d->mConfirmAck;
2194 }
2195 
2196 bool KAEvent::copyToKOrganizer() const
2197 {
2198  return d->mCopyToKOrganizer;
2199 }
2200 
2201 #ifndef KALARMCAL_USE_KRESOURCES
2202 void KAEvent::setEmail(uint from, const KCalCore::Person::List& addresses, const QString& subject,
2203  const QStringList& attachments)
2204 #else
2205 void KAEvent::setEmail(uint from, const QList<KCal::Person>& addresses, const QString& subject,
2206  const QStringList& attachments)
2207 #endif
2208 {
2209  d->mEmailFromIdentity = from;
2210  d->mEmailAddresses = addresses;
2211  d->mEmailSubject = subject;
2212  d->mEmailAttachments = attachments;
2213 }
2214 
2215 QString KAEvent::emailMessage() const
2216 {
2217  return (d->mActionSubType == EMAIL) ? d->mText : QString();
2218 }
2219 
2220 uint KAEvent::emailFromId() const
2221 {
2222  return d->mEmailFromIdentity;
2223 }
2224 
2225 #ifndef KALARMCAL_USE_KRESOURCES
2226 KCalCore::Person::List KAEvent::emailAddressees() const
2227 #else
2228 QList<KCal::Person> KAEvent::emailAddressees() const
2229 #endif
2230 {
2231  return d->mEmailAddresses;
2232 }
2233 
2234 QStringList KAEvent::emailAddresses() const
2235 {
2236  return static_cast<QStringList>(d->mEmailAddresses);
2237 }
2238 
2239 QString KAEvent::emailAddresses(const QString& sep) const
2240 {
2241  return d->mEmailAddresses.join(sep);
2242 }
2243 
2244 #ifndef KALARMCAL_USE_KRESOURCES
2245 QString KAEvent::joinEmailAddresses(const KCalCore::Person::List& addresses, const QString& separator)
2246 #else
2247 QString KAEvent::joinEmailAddresses(const QList<KCal::Person>& addresses, const QString& separator)
2248 #endif
2249 {
2250  return EmailAddressList(addresses).join(separator);
2251 }
2252 
2253 QStringList KAEvent::emailPureAddresses() const
2254 {
2255  return d->mEmailAddresses.pureAddresses();
2256 }
2257 
2258 QString KAEvent::emailPureAddresses(const QString& sep) const
2259 {
2260  return d->mEmailAddresses.pureAddresses(sep);
2261 }
2262 
2263 QString KAEvent::emailSubject() const
2264 {
2265  return d->mEmailSubject;
2266 }
2267 
2268 QStringList KAEvent::emailAttachments() const
2269 {
2270  return d->mEmailAttachments;
2271 }
2272 
2273 QString KAEvent::emailAttachments(const QString& sep) const
2274 {
2275  return d->mEmailAttachments.join(sep);
2276 }
2277 
2278 bool KAEvent::emailBcc() const
2279 {
2280  return d->mEmailBcc;
2281 }
2282 
2283 void KAEvent::setAudioFile(const QString& filename, float volume, float fadeVolume, int fadeSeconds, int repeatPause, bool allowEmptyFile)
2284 {
2285  d->setAudioFile(filename, volume, fadeVolume, fadeSeconds, repeatPause, allowEmptyFile);
2286 }
2287 
2288 void KAEventPrivate::setAudioFile(const QString& filename, float volume, float fadeVolume, int fadeSeconds, int repeatPause, bool allowEmptyFile)
2289 {
2290  mAudioFile = filename;
2291  mSoundVolume = (!allowEmptyFile && filename.isEmpty()) ? -1 : volume;
2292  if (mSoundVolume >= 0)
2293  {
2294  mFadeVolume = (fadeSeconds > 0) ? fadeVolume : -1;
2295  mFadeSeconds = (mFadeVolume >= 0) ? fadeSeconds : 0;
2296  }
2297  else
2298  {
2299  mFadeVolume = -1;
2300  mFadeSeconds = 0;
2301  }
2302  mRepeatSoundPause = repeatPause;
2303 }
2304 
2305 QString KAEvent::audioFile() const
2306 {
2307  return d->mAudioFile;
2308 }
2309 
2310 float KAEvent::soundVolume() const
2311 {
2312  return d->mSoundVolume;
2313 }
2314 
2315 float KAEvent::fadeVolume() const
2316 {
2317  return d->mSoundVolume >= 0 && d->mFadeSeconds ? d->mFadeVolume : -1;
2318 }
2319 
2320 int KAEvent::fadeSeconds() const
2321 {
2322  return d->mSoundVolume >= 0 && d->mFadeVolume >= 0 ? d->mFadeSeconds : 0;
2323 }
2324 
2325 bool KAEvent::repeatSound() const
2326 {
2327  return d->mRepeatSoundPause >= 0;
2328 }
2329 
2330 int KAEvent::repeatSoundPause() const
2331 {
2332  return d->mRepeatSoundPause;
2333 }
2334 
2335 bool KAEvent::beep() const
2336 {
2337  return d->mBeep;
2338 }
2339 
2340 bool KAEvent::speak() const
2341 {
2342  return (d->mActionSubType == MESSAGE
2343  || (d->mActionSubType == COMMAND && d->mCommandDisplay))
2344  && d->mSpeak;
2345 }
2346 
2347 /******************************************************************************
2348 * Set the event to be an alarm template.
2349 */
2350 void KAEvent::setTemplate(const QString& name, int afterTime)
2351 {
2352  d->setCategory(CalEvent::TEMPLATE);
2353  d->mTemplateName = name;
2354  d->mTemplateAfterTime = afterTime;
2355  d->mTriggerChanged = true; // templates and archived don't have trigger times
2356 }
2357 
2358 bool KAEvent::isTemplate() const
2359 {
2360  return !d->mTemplateName.isEmpty();
2361 }
2362 
2363 QString KAEvent::templateName() const
2364 {
2365  return d->mTemplateName;
2366 }
2367 
2368 bool KAEvent::usingDefaultTime() const
2369 {
2370  return d->mTemplateAfterTime == 0;
2371 }
2372 
2373 int KAEvent::templateAfterTime() const
2374 {
2375  return d->mTemplateAfterTime;
2376 }
2377 
2378 void KAEvent::setActions(const QString& pre, const QString& post, ExtraActionOptions options)
2379 {
2380  d->mPreAction = pre;
2381  d->mPostAction = post;
2382  d->mExtraActionOptions = options;
2383 }
2384 
2385 void KAEvent::setActions(const QString& pre, const QString& post, bool cancelOnError, bool dontShowError)
2386 {
2387  ExtraActionOptions opts(0);
2388  if (cancelOnError)
2389  opts |= CancelOnPreActError;
2390  if (dontShowError)
2391  opts |= DontShowPreActError;
2392  setActions(pre, post, opts);
2393 }
2394 
2395 QString KAEvent::preAction() const
2396 {
2397  return d->mPreAction;
2398 }
2399 
2400 QString KAEvent::postAction() const
2401 {
2402  return d->mPostAction;
2403 }
2404 
2405 KAEvent::ExtraActionOptions KAEvent::extraActionOptions() const
2406 {
2407  return d->mExtraActionOptions;
2408 }
2409 
2410 bool KAEvent::cancelOnPreActionError() const
2411 {
2412  return d->mExtraActionOptions & CancelOnPreActError;
2413 }
2414 
2415 bool KAEvent::dontShowPreActionError() const
2416 {
2417  return d->mExtraActionOptions & DontShowPreActError;
2418 }
2419 
2420 /******************************************************************************
2421 * Set a reminder.
2422 * 'minutes' = number of minutes BEFORE the main alarm.
2423 */
2424 void KAEvent::setReminder(int minutes, bool onceOnly)
2425 {
2426  d->setReminder(minutes, onceOnly);
2427 }
2428 
2429 void KAEventPrivate::setReminder(int minutes, bool onceOnly)
2430 {
2431  if (minutes > 0 && mRepeatAtLogin)
2432  minutes = 0;
2433  if (minutes != mReminderMinutes || (minutes && mReminderActive != ACTIVE_REMINDER))
2434  {
2435  if (minutes && mReminderActive == NO_REMINDER)
2436  ++mAlarmCount;
2437  else if (!minutes && mReminderActive != NO_REMINDER)
2438  --mAlarmCount;
2439  mReminderMinutes = minutes;
2440  mReminderActive = minutes ? ACTIVE_REMINDER : NO_REMINDER;
2441  mReminderOnceOnly = onceOnly;
2442  mReminderAfterTime = DateTime();
2443  mTriggerChanged = true;
2444  }
2445 }
2446 
2447 /******************************************************************************
2448 * Activate the event's reminder which occurs AFTER the given main alarm time.
2449 * Reply = true if successful (i.e. reminder falls before the next main alarm).
2450 */
2451 void KAEvent::activateReminderAfter(const DateTime& mainAlarmTime)
2452 {
2453  d->activateReminderAfter(mainAlarmTime);
2454 }
2455 
2456 void KAEventPrivate::activateReminderAfter(const DateTime& mainAlarmTime)
2457 {
2458  if (mReminderMinutes >= 0 || mReminderActive == ACTIVE_REMINDER || !mainAlarmTime.isValid())
2459  return;
2460  // There is a reminder AFTER the main alarm.
2461  if (checkRecur() != KARecurrence::NO_RECUR)
2462  {
2463  // For a recurring alarm, the given alarm time must be a recurrence, not a sub-repetition.
2464  DateTime next;
2465  //???? For some unknown reason, addSecs(-1) returns the recurrence after the next,
2466  //???? so addSecs(-60) is used instead.
2467  if (nextRecurrence(mainAlarmTime.addSecs(-60).effectiveKDateTime(), next) == KAEvent::NO_OCCURRENCE
2468  || mainAlarmTime != next)
2469  return;
2470  }
2471  else if (!mRepeatAtLogin)
2472  {
2473  // For a non-recurring alarm, the given alarm time must be the main alarm time.
2474  if (mainAlarmTime != mStartDateTime)
2475  return;
2476  }
2477 
2478  const DateTime reminderTime = mainAlarmTime.addMins(-mReminderMinutes);
2479  DateTime next;
2480  if (nextOccurrence(mainAlarmTime.effectiveKDateTime(), next, KAEvent::RETURN_REPETITION) != KAEvent::NO_OCCURRENCE
2481  && reminderTime >= next)
2482  return; // the reminder time is after the next occurrence of the main alarm
2483 
2484  kDebug() << "Setting reminder at" << reminderTime.effectiveKDateTime().dateTime();
2485  activate_reminder(true);
2486  mReminderAfterTime = reminderTime;
2487 }
2488 
2489 int KAEvent::reminderMinutes() const
2490 {
2491  return d->mReminderMinutes;
2492 }
2493 
2494 bool KAEvent::reminderActive() const
2495 {
2496  return d->mReminderActive == KAEventPrivate::ACTIVE_REMINDER;
2497 }
2498 
2499 bool KAEvent::reminderOnceOnly() const
2500 {
2501  return d->mReminderOnceOnly;
2502 }
2503 
2504 bool KAEvent::reminderDeferral() const
2505 {
2506  return d->mDeferral == KAEventPrivate::REMINDER_DEFERRAL;
2507 }
2508 
2509 /******************************************************************************
2510 * Defer the event to the specified time.
2511 * If the main alarm time has passed, the main alarm is marked as expired.
2512 * If 'adjustRecurrence' is true, ensure that the next scheduled recurrence is
2513 * after the current time.
2514 */
2515 void KAEvent::defer(const DateTime& dt, bool reminder, bool adjustRecurrence)
2516 {
2517  return d->defer(dt, reminder, adjustRecurrence);
2518 }
2519 
2520 void KAEventPrivate::defer(const DateTime& dateTime, bool reminder, bool adjustRecurrence)
2521 {
2522  startChanges(); // prevent multiple trigger time evaluation here
2523  bool setNextRepetition = false;
2524  bool checkRepetition = false;
2525  bool checkReminderAfter = false;
2526  if (checkRecur() == KARecurrence::NO_RECUR)
2527  {
2528  // Deferring a non-recurring alarm
2529  if (mReminderMinutes)
2530  {
2531  bool deferReminder = false;
2532  if (mReminderMinutes > 0)
2533  {
2534  // There's a reminder BEFORE the main alarm
2535  if (dateTime < mNextMainDateTime.effectiveKDateTime())
2536  deferReminder = true;
2537  else if (mReminderActive == ACTIVE_REMINDER || mDeferral == REMINDER_DEFERRAL)
2538  {
2539  // Deferring past the main alarm time, so adjust any existing deferral
2540  set_deferral(NO_DEFERRAL);
2541  mTriggerChanged = true;
2542  }
2543  }
2544  else if (mReminderMinutes < 0 && reminder)
2545  deferReminder = true; // deferring a reminder AFTER the main alarm
2546  if (deferReminder)
2547  {
2548  set_deferral(REMINDER_DEFERRAL); // defer reminder alarm
2549  mDeferralTime = dateTime;
2550  mTriggerChanged = true;
2551  }
2552  if (mReminderActive == ACTIVE_REMINDER)
2553  {
2554  activate_reminder(false);
2555  mTriggerChanged = true;
2556  }
2557  }
2558  if (mDeferral != REMINDER_DEFERRAL)
2559  {
2560  // We're deferring the main alarm.
2561  // Main alarm has now expired.
2562  mNextMainDateTime = mDeferralTime = dateTime;
2563  set_deferral(NORMAL_DEFERRAL);
2564  mTriggerChanged = true;
2565  checkReminderAfter = true;
2566  if (!mMainExpired)
2567  {
2568  // Mark the alarm as expired now
2569  mMainExpired = true;
2570  --mAlarmCount;
2571  if (mRepeatAtLogin)
2572  {
2573  // Remove the repeat-at-login alarm, but keep a note of it for archiving purposes
2574  mArchiveRepeatAtLogin = true;
2575  mRepeatAtLogin = false;
2576  --mAlarmCount;
2577  }
2578  }
2579  }
2580  }
2581  else if (reminder)
2582  {
2583  // Deferring a reminder for a recurring alarm
2584  if (dateTime >= mNextMainDateTime.effectiveKDateTime())
2585  {
2586  // Trying to defer it past the next main alarm (regardless of whether
2587  // the reminder triggered before or after the main alarm).
2588  set_deferral(NO_DEFERRAL); // (error)
2589  }
2590  else
2591  {
2592  set_deferral(REMINDER_DEFERRAL);
2593  mDeferralTime = dateTime;
2594  checkRepetition = true;
2595  }
2596  mTriggerChanged = true;
2597  }
2598  else
2599  {
2600  // Deferring a recurring alarm
2601  mDeferralTime = dateTime;
2602  if (mDeferral == NO_DEFERRAL)
2603  set_deferral(NORMAL_DEFERRAL);
2604  mTriggerChanged = true;
2605  checkReminderAfter = true;
2606  if (adjustRecurrence)
2607  {
2608  const KDateTime now = KDateTime::currentUtcDateTime();
2609  if (mainEndRepeatTime() < now)
2610  {
2611  // The last repetition (if any) of the current recurrence has already passed.
2612  // Adjust to the next scheduled recurrence after now.
2613  if (!mMainExpired && setNextOccurrence(now) == KAEvent::NO_OCCURRENCE)
2614  {
2615  mMainExpired = true;
2616  --mAlarmCount;
2617  }
2618  }
2619  else
2620  setNextRepetition = mRepetition;
2621  }
2622  else
2623  checkRepetition = true;
2624  }
2625  if (checkReminderAfter && mReminderMinutes < 0 && mReminderActive != NO_REMINDER)
2626  {
2627  // Enable/disable the active reminder AFTER the main alarm,
2628  // depending on whether the deferral is before or after the reminder.
2629  mReminderActive = (mDeferralTime < mReminderAfterTime) ? ACTIVE_REMINDER : HIDDEN_REMINDER;
2630  }
2631  if (checkRepetition)
2632  setNextRepetition = (mRepetition && mDeferralTime < mainEndRepeatTime());
2633  if (setNextRepetition)
2634  {
2635  // The alarm is repeated, and we're deferring to a time before the last repetition.
2636  // Set the next scheduled repetition to the one after the deferral.
2637  if (mNextMainDateTime >= mDeferralTime)
2638  mNextRepeat = 0;
2639  else
2640  mNextRepeat = mRepetition.nextRepeatCount(mNextMainDateTime.kDateTime(), mDeferralTime.kDateTime());
2641  mTriggerChanged = true;
2642  }
2643  endChanges();
2644 }
2645 
2646 /******************************************************************************
2647 * Cancel any deferral alarm.
2648 */
2649 void KAEvent::cancelDefer()
2650 {
2651  d->cancelDefer();
2652 }
2653 
2654 void KAEventPrivate::cancelDefer()
2655 {
2656  if (mDeferral != NO_DEFERRAL)
2657  {
2658  mDeferralTime = DateTime();
2659  set_deferral(NO_DEFERRAL);
2660  mTriggerChanged = true;
2661  }
2662 }
2663 
2664 void KAEvent::setDeferDefaultMinutes(int minutes, bool dateOnly)
2665 {
2666  d->mDeferDefaultMinutes = minutes;
2667  d->mDeferDefaultDateOnly = dateOnly;
2668 }
2669 
2670 bool KAEvent::deferred() const
2671 {
2672  return d->mDeferral > 0;
2673 }
2674 
2675 DateTime KAEvent::deferDateTime() const
2676 {
2677  return d->mDeferralTime;
2678 }
2679 
2680 /******************************************************************************
2681 * Find the latest time which the alarm can currently be deferred to.
2682 */
2683 DateTime KAEvent::deferralLimit(DeferLimitType* limitType) const
2684 {
2685  return d->deferralLimit(limitType);
2686 }
2687 
2688 DateTime KAEventPrivate::deferralLimit(KAEvent::DeferLimitType* limitType) const
2689 {
2690  KAEvent::DeferLimitType ltype = KAEvent::LIMIT_NONE;
2691  DateTime endTime;
2692  if (checkRecur() != KARecurrence::NO_RECUR)
2693  {
2694  // It's a recurring alarm. Find the latest time it can be deferred to:
2695  // it cannot be deferred past its next occurrence or sub-repetition,
2696  // or any advance reminder before that.
2697  DateTime reminderTime;
2698  const KDateTime now = KDateTime::currentUtcDateTime();
2699  const KAEvent::OccurType type = nextOccurrence(now, endTime, KAEvent::RETURN_REPETITION);
2700  if (type & KAEvent::OCCURRENCE_REPEAT)
2701  ltype = KAEvent::LIMIT_REPETITION;
2702  else if (type == KAEvent::NO_OCCURRENCE)
2703  ltype = KAEvent::LIMIT_NONE;
2704  else if (mReminderActive == ACTIVE_REMINDER && mReminderMinutes > 0
2705  && (now < (reminderTime = endTime.addMins(-mReminderMinutes))))
2706  {
2707  endTime = reminderTime;
2708  ltype = KAEvent::LIMIT_REMINDER;
2709  }
2710  else
2711  ltype = KAEvent::LIMIT_RECURRENCE;
2712  }
2713  else if (mReminderMinutes < 0)
2714  {
2715  // There is a reminder alarm which occurs AFTER the main alarm.
2716  // Don't allow the reminder to be deferred past the next main alarm time.
2717  if (KDateTime::currentUtcDateTime() < mNextMainDateTime.effectiveKDateTime())
2718  {
2719  endTime = mNextMainDateTime;
2720  ltype = KAEvent::LIMIT_MAIN;
2721  }
2722  }
2723  else if (mReminderMinutes > 0
2724  && KDateTime::currentUtcDateTime() < mNextMainDateTime.effectiveKDateTime())
2725  {
2726  // It's a reminder BEFORE the main alarm.
2727  // Don't allow it to be deferred past its main alarm time.
2728  endTime = mNextMainDateTime;
2729  ltype = KAEvent::LIMIT_MAIN;
2730  }
2731  if (ltype != KAEvent::LIMIT_NONE)
2732  endTime = endTime.addMins(-1);
2733  if (limitType)
2734  *limitType = ltype;
2735  return endTime;
2736 }
2737 
2738 int KAEvent::deferDefaultMinutes() const
2739 {
2740  return d->mDeferDefaultMinutes;
2741 }
2742 
2743 bool KAEvent::deferDefaultDateOnly() const
2744 {
2745  return d->mDeferDefaultDateOnly;
2746 }
2747 
2748 DateTime KAEvent::startDateTime() const
2749 {
2750  return d->mStartDateTime;
2751 }
2752 
2753 void KAEvent::setTime(const KDateTime& dt)
2754 {
2755  d->mNextMainDateTime = dt;
2756  d->mTriggerChanged = true;
2757 }
2758 
2759 DateTime KAEvent::mainDateTime(bool withRepeats) const
2760 {
2761  return d->mainDateTime(withRepeats);
2762 }
2763 
2764 QTime KAEvent::mainTime() const
2765 {
2766  return d->mNextMainDateTime.effectiveTime();
2767 }
2768 
2769 DateTime KAEvent::mainEndRepeatTime() const
2770 {
2771  return d->mainEndRepeatTime();
2772 }
2773 
2774 /******************************************************************************
2775 * Set the start-of-day time for date-only alarms.
2776 */
2777 void KAEvent::setStartOfDay(const QTime& startOfDay)
2778 {
2779  DateTime::setStartOfDay(startOfDay);
2780 #ifdef __GNUC__
2781 #warning Does this need all trigger times for date-only alarms to be recalculated?
2782 #endif
2783 }
2784 
2785 /******************************************************************************
2786 * Called when the user changes the start-of-day time.
2787 * Adjust the start time of the recurrence to match, for each date-only event in
2788 * a list.
2789 */
2790 void KAEvent::adjustStartOfDay(const KAEvent::List& events)
2791 {
2792  for (int i = 0, end = events.count(); i < end; ++i)
2793  {
2794  KAEventPrivate* const p = events[i]->d;
2795  if (p->mStartDateTime.isDateOnly() && p->checkRecur() != KARecurrence::NO_RECUR)
2796  p->mRecurrence->setStartDateTime(p->mStartDateTime.effectiveKDateTime(), true);
2797  }
2798 }
2799 
2800 DateTime KAEvent::nextTrigger(TriggerType type) const
2801 {
2802  d->calcTriggerTimes();
2803  switch (type)
2804  {
2805  case ALL_TRIGGER: return d->mAllTrigger;
2806  case MAIN_TRIGGER: return d->mMainTrigger;
2807  case ALL_WORK_TRIGGER: return d->mAllWorkTrigger;
2808  case WORK_TRIGGER: return d->mMainWorkTrigger;
2809  case DISPLAY_TRIGGER:
2810  {
2811  const bool reminderAfter = d->mMainExpired && d->mReminderActive && d->mReminderMinutes < 0;
2812  return d->checkRecur() != KARecurrence::NO_RECUR && (d->mWorkTimeOnly || d->mExcludeHolidays)
2813  ? (reminderAfter ? d->mAllWorkTrigger : d->mMainWorkTrigger)
2814  : (reminderAfter ? d->mAllTrigger : d->mMainTrigger);
2815  }
2816  default: return DateTime();
2817  }
2818 }
2819 
2820 void KAEvent::setCreatedDateTime(const KDateTime& dt)
2821 {
2822  d->mCreatedDateTime = dt;
2823 }
2824 
2825 KDateTime KAEvent::createdDateTime() const
2826 {
2827  return d->mCreatedDateTime;
2828 }
2829 
2830 /******************************************************************************
2831 * Set or clear repeat-at-login.
2832 */
2833 void KAEvent::setRepeatAtLogin(bool rl)
2834 {
2835  d->setRepeatAtLogin(rl);
2836 }
2837 
2838 void KAEventPrivate::setRepeatAtLogin(bool rl)
2839 {
2840  if (rl && !mRepeatAtLogin)
2841  {
2842  setRepeatAtLoginTrue(true); // clear incompatible statuses
2843  ++mAlarmCount;
2844  }
2845  else if (!rl && mRepeatAtLogin)
2846  --mAlarmCount;
2847  mRepeatAtLogin = rl;
2848  mTriggerChanged = true;
2849 }
2850 
2851 /******************************************************************************
2852 * Clear incompatible statuses when repeat-at-login is set.
2853 */
2854 void KAEventPrivate::setRepeatAtLoginTrue(bool clearReminder)
2855 {
2856  clearRecur(); // clear recurrences
2857  if (mReminderMinutes >= 0 && clearReminder)
2858  setReminder(0, false); // clear pre-alarm reminder
2859  mLateCancel = 0;
2860  mAutoClose = false;
2861  mCopyToKOrganizer = false;
2862 }
2863 
2864 bool KAEvent::repeatAtLogin(bool includeArchived) const
2865 {
2866  return d->mRepeatAtLogin || (includeArchived && d->mArchiveRepeatAtLogin);
2867 }
2868 
2869 void KAEvent::setExcludeHolidays(bool ex)
2870 {
2871  d->mExcludeHolidays = ex ? KAEventPrivate::mHolidays : 0;
2872  // Option only affects recurring alarms
2873  d->mTriggerChanged = (d->checkRecur() != KARecurrence::NO_RECUR);
2874 }
2875 
2876 bool KAEvent::holidaysExcluded() const
2877 {
2878  return d->mExcludeHolidays;
2879 }
2880 
2881 /******************************************************************************
2882 * Set a new holiday region.
2883 * Alarms which exclude holidays record the pointer to the holiday definition
2884 * at the time their next trigger times were last calculated. The change in
2885 * holiday definition pointer will cause their next trigger times to be
2886 * recalculated.
2887 */
2888 void KAEvent::setHolidays(const HolidayRegion& h)
2889 {
2890  KAEventPrivate::mHolidays = &h;
2891 }
2892 
2893 void KAEvent::setWorkTimeOnly(bool wto)
2894 {
2895  d->mWorkTimeOnly = wto;
2896  // Option only affects recurring alarms
2897  d->mTriggerChanged = (d->checkRecur() != KARecurrence::NO_RECUR);
2898 }
2899 
2900 bool KAEvent::workTimeOnly() const
2901 {
2902  return d->mWorkTimeOnly;
2903 }
2904 
2905 /******************************************************************************
2906 * Check whether a date/time is during working hours and/or holidays, depending
2907 * on the flags set for the specified event.
2908 */
2909 bool KAEvent::isWorkingTime(const KDateTime& dt) const
2910 {
2911  return d->isWorkingTime(dt);
2912 }
2913 
2914 bool KAEventPrivate::isWorkingTime(const KDateTime& dt) const
2915 {
2916  if ((mWorkTimeOnly && !mWorkDays.testBit(dt.date().dayOfWeek() - 1))
2917  || (mExcludeHolidays && mHolidays && mHolidays->isHoliday(dt.date())))
2918  return false;
2919  if (!mWorkTimeOnly)
2920  return true;
2921  return dt.isDateOnly()
2922  || (dt.time() >= mWorkDayStart && dt.time() < mWorkDayEnd);
2923 }
2924 
2925 /******************************************************************************
2926 * Set new working days and times.
2927 * Increment a counter so that working-time-only alarms can detect that they
2928 * need to update their next trigger time.
2929 */
2930 void KAEvent::setWorkTime(const QBitArray& days, const QTime& start, const QTime& end)
2931 {
2932  if (days != KAEventPrivate::mWorkDays || start != KAEventPrivate::mWorkDayStart || end != KAEventPrivate::mWorkDayEnd)
2933  {
2934  KAEventPrivate::mWorkDays = days;
2935  KAEventPrivate::mWorkDayStart = start;
2936  KAEventPrivate::mWorkDayEnd = end;
2937  if (!++KAEventPrivate::mWorkTimeIndex)
2938  ++KAEventPrivate::mWorkTimeIndex;
2939  }
2940 }
2941 
2942 /******************************************************************************
2943 * Clear the event's recurrence and alarm repetition data.
2944 */
2945 void KAEvent::setNoRecur()
2946 {
2947  d->clearRecur();
2948 }
2949 
2950 void KAEventPrivate::clearRecur()
2951 {
2952  if (mRecurrence || mRepetition)
2953  {
2954  delete mRecurrence;
2955  mRecurrence = 0;
2956  mRepetition.set(0, 0);
2957  mTriggerChanged = true;
2958  }
2959  mNextRepeat = 0;
2960 }
2961 
2962 /******************************************************************************
2963 * Initialise the event's recurrence from a KCal::Recurrence.
2964 * The event's start date/time is not changed.
2965 */
2966 void KAEvent::setRecurrence(const KARecurrence& recurrence)
2967 {
2968  d->setRecurrence(recurrence);
2969 }
2970 
2971 void KAEventPrivate::setRecurrence(const KARecurrence& recurrence)
2972 {
2973  startChanges(); // prevent multiple trigger time evaluation here
2974  if (recurrence.recurs())
2975  {
2976  delete mRecurrence;
2977  mRecurrence = new KARecurrence(recurrence);
2978  mRecurrence->setStartDateTime(mStartDateTime.effectiveKDateTime(), mStartDateTime.isDateOnly());
2979  mTriggerChanged = true;
2980 
2981  // Adjust sub-repetition values to fit the recurrence.
2982  setRepetition(mRepetition);
2983  }
2984  else
2985  clearRecur();
2986 
2987  endChanges();
2988 }
2989 
2990 /******************************************************************************
2991 * Set the recurrence to recur at a minutes interval.
2992 * Parameters:
2993 * freq = how many minutes between recurrences.
2994 * count = number of occurrences, including first and last.
2995 * = -1 to recur indefinitely.
2996 * = 0 to use 'end' instead.
2997 * end = end date/time (invalid to use 'count' instead).
2998 * Reply = false if no recurrence was set up.
2999 */
3000 bool KAEvent::setRecurMinutely(int freq, int count, const KDateTime& end)
3001 {
3002  const bool success = d->setRecur(RecurrenceRule::rMinutely, freq, count, end);
3003  d->mTriggerChanged = true;
3004  return success;
3005 }
3006 
3007 /******************************************************************************
3008 * Set the recurrence to recur daily.
3009 * Parameters:
3010 * freq = how many days between recurrences.
3011 * days = which days of the week alarms are allowed to occur on.
3012 * count = number of occurrences, including first and last.
3013 * = -1 to recur indefinitely.
3014 * = 0 to use 'end' instead.
3015 * end = end date (invalid to use 'count' instead).
3016 * Reply = false if no recurrence was set up.
3017 */
3018 bool KAEvent::setRecurDaily(int freq, const QBitArray& days, int count, const QDate& end)
3019 {
3020  const bool success = d->setRecur(RecurrenceRule::rDaily, freq, count, end);
3021  if (success)
3022  {
3023  int n = 0;
3024  for (int i = 0; i < 7; ++i)
3025  {
3026  if (days.testBit(i))
3027  ++n;
3028  }
3029  if (n < 7)
3030  d->mRecurrence->addWeeklyDays(days);
3031  }
3032  d->mTriggerChanged = true;
3033  return success;
3034 }
3035 
3036 /******************************************************************************
3037 * Set the recurrence to recur weekly, on the specified weekdays.
3038 * Parameters:
3039 * freq = how many weeks between recurrences.
3040 * days = which days of the week alarms should occur on.
3041 * count = number of occurrences, including first and last.
3042 * = -1 to recur indefinitely.
3043 * = 0 to use 'end' instead.
3044 * end = end date (invalid to use 'count' instead).
3045 * Reply = false if no recurrence was set up.
3046 */
3047 bool KAEvent::setRecurWeekly(int freq, const QBitArray& days, int count, const QDate& end)
3048 {
3049  const bool success = d->setRecur(RecurrenceRule::rWeekly, freq, count, end);
3050  if (success)
3051  d->mRecurrence->addWeeklyDays(days);
3052  d->mTriggerChanged = true;
3053  return success;
3054 }
3055 
3056 /******************************************************************************
3057 * Set the recurrence to recur monthly, on the specified days within the month.
3058 * Parameters:
3059 * freq = how many months between recurrences.
3060 * days = which days of the month alarms should occur on.
3061 * count = number of occurrences, including first and last.
3062 * = -1 to recur indefinitely.
3063 * = 0 to use 'end' instead.
3064 * end = end date (invalid to use 'count' instead).
3065 * Reply = false if no recurrence was set up.
3066 */
3067 bool KAEvent::setRecurMonthlyByDate(int freq, const QVector<int>& days, int count, const QDate& end)
3068 {
3069  const bool success = d->setRecur(RecurrenceRule::rMonthly, freq, count, end);
3070  if (success)
3071  {
3072  for (int i = 0, end = days.count(); i < end; ++i)
3073  d->mRecurrence->addMonthlyDate(days[i]);
3074  }
3075  d->mTriggerChanged = true;
3076  return success;
3077 }
3078 
3079 /******************************************************************************
3080 * Set the recurrence to recur monthly, on the specified weekdays in the
3081 * specified weeks of the month.
3082 * Parameters:
3083 * freq = how many months between recurrences.
3084 * posns = which days of the week/weeks of the month alarms should occur on.
3085 * count = number of occurrences, including first and last.
3086 * = -1 to recur indefinitely.
3087 * = 0 to use 'end' instead.
3088 * end = end date (invalid to use 'count' instead).
3089 * Reply = false if no recurrence was set up.
3090 */
3091 bool KAEvent::setRecurMonthlyByPos(int freq, const QVector<MonthPos>& posns, int count, const QDate& end)
3092 {
3093  const bool success = d->setRecur(RecurrenceRule::rMonthly, freq, count, end);
3094  if (success)
3095  {
3096  for (int i = 0, end = posns.count(); i < end; ++i)
3097  d->mRecurrence->addMonthlyPos(posns[i].weeknum, posns[i].days);
3098  }
3099  d->mTriggerChanged = true;
3100  return success;
3101 }
3102 
3103 /******************************************************************************
3104 * Set the recurrence to recur annually, on the specified start date in each
3105 * of the specified months.
3106 * Parameters:
3107 * freq = how many years between recurrences.
3108 * months = which months of the year alarms should occur on.
3109 * day = day of month, or 0 to use start date
3110 * feb29 = when February 29th should recur in non-leap years.
3111 * count = number of occurrences, including first and last.
3112 * = -1 to recur indefinitely.
3113 * = 0 to use 'end' instead.
3114 * end = end date (invalid to use 'count' instead).
3115 * Reply = false if no recurrence was set up.
3116 */
3117 bool KAEvent::setRecurAnnualByDate(int freq, const QVector<int>& months, int day, KARecurrence::Feb29Type feb29, int count, const QDate& end)
3118 {
3119  const bool success = d->setRecur(RecurrenceRule::rYearly, freq, count, end, feb29);
3120  if (success)
3121  {
3122  for (int i = 0, end = months.count(); i < end; ++i)
3123  d->mRecurrence->addYearlyMonth(months[i]);
3124  if (day)
3125  d->mRecurrence->addMonthlyDate(day);
3126  }
3127  d->mTriggerChanged = true;
3128  return success;
3129 }
3130 
3131 /******************************************************************************
3132 * Set the recurrence to recur annually, on the specified weekdays in the
3133 * specified weeks of the specified months.
3134 * Parameters:
3135 * freq = how many years between recurrences.
3136 * posns = which days of the week/weeks of the month alarms should occur on.
3137 * months = which months of the year alarms should occur on.
3138 * count = number of occurrences, including first and last.
3139 * = -1 to recur indefinitely.
3140 * = 0 to use 'end' instead.
3141 * end = end date (invalid to use 'count' instead).
3142 * Reply = false if no recurrence was set up.
3143 */
3144 bool KAEvent::setRecurAnnualByPos(int freq, const QVector<MonthPos>& posns, const QVector<int>& months, int count, const QDate& end)
3145 {
3146  const bool success = d->setRecur(RecurrenceRule::rYearly, freq, count, end);
3147  if (success)
3148  {
3149  int i = 0;
3150  int iend;
3151  for (iend = months.count(); i < iend; ++i)
3152  d->mRecurrence->addYearlyMonth(months[i]);
3153  for (i = 0, iend = posns.count(); i < iend; ++i)
3154  d->mRecurrence->addYearlyPos(posns[i].weeknum, posns[i].days);
3155  }
3156  d->mTriggerChanged = true;
3157  return success;
3158 }
3159 
3160 /******************************************************************************
3161 * Initialise the event's recurrence data.
3162 * Parameters:
3163 * freq = how many intervals between recurrences.
3164 * count = number of occurrences, including first and last.
3165 * = -1 to recur indefinitely.
3166 * = 0 to use 'end' instead.
3167 * end = end date/time (invalid to use 'count' instead).
3168 * Reply = false if no recurrence was set up.
3169 */
3170 bool KAEventPrivate::setRecur(RecurrenceRule::PeriodType recurType, int freq, int count, const QDate& end, KARecurrence::Feb29Type feb29)
3171 {
3172  KDateTime edt = mNextMainDateTime.kDateTime();
3173  edt.setDate(end);
3174  return setRecur(recurType, freq, count, edt, feb29);
3175 }
3176 bool KAEventPrivate::setRecur(RecurrenceRule::PeriodType recurType, int freq, int count, const KDateTime& end, KARecurrence::Feb29Type feb29)
3177 {
3178  if (count >= -1 && (count || end.date().isValid()))
3179  {
3180  if (!mRecurrence)
3181  mRecurrence = new KARecurrence;
3182  if (mRecurrence->init(recurType, freq, count, mNextMainDateTime.kDateTime(), end, feb29))
3183  return true;
3184  }
3185  clearRecur();
3186  return false;
3187 }
3188 
3189 bool KAEvent::recurs() const
3190 {
3191  return d->checkRecur() != KARecurrence::NO_RECUR;
3192 }
3193 
3194 KARecurrence::Type KAEvent::recurType() const
3195 {
3196  return d->checkRecur();
3197 }
3198 
3199 KARecurrence* KAEvent::recurrence() const
3200 {
3201  return d->mRecurrence;
3202 }
3203 
3204 /******************************************************************************
3205 * Return the recurrence interval in units of the recurrence period type.
3206 */
3207 int KAEvent::recurInterval() const
3208 {
3209  if (d->mRecurrence)
3210  {
3211  switch (d->mRecurrence->type())
3212  {
3213  case KARecurrence::MINUTELY:
3214  case KARecurrence::DAILY:
3215  case KARecurrence::WEEKLY:
3216  case KARecurrence::MONTHLY_DAY:
3217  case KARecurrence::MONTHLY_POS:
3218  case KARecurrence::ANNUAL_DATE:
3219  case KARecurrence::ANNUAL_POS:
3220  return d->mRecurrence->frequency();
3221  default:
3222  break;
3223  }
3224  }
3225  return 0;
3226 }
3227 
3228 Duration KAEvent::longestRecurrenceInterval() const
3229 {
3230  return d->mRecurrence ? d->mRecurrence->longestInterval() : Duration(0);
3231 }
3232 
3233 /******************************************************************************
3234 * Adjust the event date/time to the first recurrence of the event, on or after
3235 * start date/time. The event start date may not be a recurrence date, in which
3236 * case a later date will be set.
3237 */
3238 void KAEvent::setFirstRecurrence()
3239 {
3240  d->setFirstRecurrence();
3241 }
3242 
3243 void KAEventPrivate::setFirstRecurrence()
3244 {
3245  switch (checkRecur())
3246  {
3247  case KARecurrence::NO_RECUR:
3248  case KARecurrence::MINUTELY:
3249  return;
3250  case KARecurrence::ANNUAL_DATE:
3251  case KARecurrence::ANNUAL_POS:
3252  if (mRecurrence->yearMonths().isEmpty())
3253  return; // (presumably it's a template)
3254  break;
3255  case KARecurrence::DAILY:
3256  case KARecurrence::WEEKLY:
3257  case KARecurrence::MONTHLY_POS:
3258  case KARecurrence::MONTHLY_DAY:
3259  break;
3260  }
3261  const KDateTime recurStart = mRecurrence->startDateTime();
3262  if (mRecurrence->recursOn(recurStart.date(), recurStart.timeSpec()))
3263  return; // it already recurs on the start date
3264 
3265  // Set the frequency to 1 to find the first possible occurrence
3266  const int frequency = mRecurrence->frequency();
3267  mRecurrence->setFrequency(1);
3268  DateTime next;
3269  nextRecurrence(mNextMainDateTime.effectiveKDateTime(), next);
3270  if (!next.isValid())
3271  mRecurrence->setStartDateTime(recurStart, mStartDateTime.isDateOnly()); // reinstate the old value
3272  else
3273  {
3274  mRecurrence->setStartDateTime(next.effectiveKDateTime(), next.isDateOnly());
3275  mStartDateTime = mNextMainDateTime = next;
3276  mTriggerChanged = true;
3277  }
3278  mRecurrence->setFrequency(frequency); // restore the frequency
3279 }
3280 
3281 /******************************************************************************
3282 * Return the recurrence interval as text suitable for display.
3283 */
3284 QString KAEvent::recurrenceText(bool brief) const
3285 {
3286  if (d->mRepeatAtLogin)
3287  return brief ? i18nc("@info/plain Brief form of 'At Login'", "Login") : i18nc("@info/plain", "At login");
3288  if (d->mRecurrence)
3289  {
3290  const int frequency = d->mRecurrence->frequency();
3291  switch (d->mRecurrence->defaultRRuleConst()->recurrenceType())
3292  {
3293  case RecurrenceRule::rMinutely:
3294  if (frequency < 60)
3295  return i18ncp("@info/plain", "1 Minute", "%1 Minutes", frequency);
3296  else if (frequency % 60 == 0)
3297  return i18ncp("@info/plain", "1 Hour", "%1 Hours", frequency/60);
3298  else
3299  {
3300  QString mins;
3301  return i18nc("@info/plain Hours and minutes", "%1h %2m", frequency/60, mins.sprintf("%02d", frequency%60));
3302  }
3303  case RecurrenceRule::rDaily:
3304  return i18ncp("@info/plain", "1 Day", "%1 Days", frequency);
3305  case RecurrenceRule::rWeekly:
3306  return i18ncp("@info/plain", "1 Week", "%1 Weeks", frequency);
3307  case RecurrenceRule::rMonthly:
3308  return i18ncp("@info/plain", "1 Month", "%1 Months", frequency);
3309  case RecurrenceRule::rYearly:
3310  return i18ncp("@info/plain", "1 Year", "%1 Years", frequency);
3311  case RecurrenceRule::rNone:
3312  default:
3313  break;
3314  }
3315  }
3316  return brief ? QString() : i18nc("@info/plain No recurrence", "None");
3317 }
3318 
3319 /******************************************************************************
3320 * Initialise the event's sub-repetition.
3321 * The repetition length is adjusted if necessary to fit the recurrence interval.
3322 * If the event doesn't recur, the sub-repetition is cleared.
3323 * Reply = false if a non-daily interval was specified for a date-only recurrence.
3324 */
3325 bool KAEvent::setRepetition(const Repetition& r)
3326 {
3327  return d->setRepetition(r);
3328 }
3329 
3330 bool KAEventPrivate::setRepetition(const Repetition& repetition)
3331 {
3332  // Don't set mRepetition to zero at the start of this function, in case the
3333  // 'repetition' parameter passed in is a reference to mRepetition.
3334  mNextRepeat = 0;
3335  if (repetition && !mRepeatAtLogin)
3336  {
3337  Q_ASSERT(checkRecur() != KARecurrence::NO_RECUR);
3338  if (!repetition.isDaily() && mStartDateTime.isDateOnly())
3339  {
3340  mRepetition.set(0, 0);
3341  return false; // interval must be in units of days for date-only alarms
3342  }
3343  Duration longestInterval = mRecurrence->longestInterval();
3344  if (repetition.duration() >= longestInterval)
3345  {
3346  const int count = mStartDateTime.isDateOnly()
3347  ? (longestInterval.asDays() - 1) / repetition.intervalDays()
3348  : (longestInterval.asSeconds() - 1) / repetition.intervalSeconds();
3349  mRepetition.set(repetition.interval(), count);
3350  }
3351  else
3352  mRepetition = repetition;
3353  mTriggerChanged = true;
3354  }
3355  else if (mRepetition)
3356  {
3357  mRepetition.set(0, 0);
3358  mTriggerChanged = true;
3359  }
3360  return true;
3361 }
3362 
3363 Repetition KAEvent::repetition() const
3364 {
3365  return d->mRepetition;
3366 }
3367 
3368 int KAEvent::nextRepetition() const
3369 {
3370  return d->mNextRepeat;
3371 }
3372 
3373 /******************************************************************************
3374 * Return the repetition interval as text suitable for display.
3375 */
3376 QString KAEvent::repetitionText(bool brief) const
3377 {
3378  if (d->mRepetition)
3379  {
3380  if (!d->mRepetition.isDaily())
3381  {
3382  const int minutes = d->mRepetition.intervalMinutes();
3383  if (minutes < 60)
3384  return i18ncp("@info/plain", "1 Minute", "%1 Minutes", minutes);
3385  if (minutes % 60 == 0)
3386  return i18ncp("@info/plain", "1 Hour", "%1 Hours", minutes/60);
3387  QString mins;
3388  return i18nc("@info/plain Hours and minutes", "%1h %2m", minutes/60, mins.sprintf("%02d", minutes%60));
3389  }
3390  const int days = d->mRepetition.intervalDays();
3391  if (days % 7)
3392  return i18ncp("@info/plain", "1 Day", "%1 Days", days);
3393  return i18ncp("@info/plain", "1 Week", "%1 Weeks", days / 7);
3394  }
3395  return brief ? QString() : i18nc("@info/plain No repetition", "None");
3396 }
3397 
3398 /******************************************************************************
3399 * Determine whether the event will occur after the specified date/time.
3400 * If 'includeRepetitions' is true and the alarm has a sub-repetition, it
3401 * returns true if any repetitions occur after the specified date/time.
3402 */
3403 bool KAEvent::occursAfter(const KDateTime& preDateTime, bool includeRepetitions) const
3404 {
3405  return d->occursAfter(preDateTime, includeRepetitions);
3406 }
3407 
3408 bool KAEventPrivate::occursAfter(const KDateTime& preDateTime, bool includeRepetitions) const
3409 {
3410  KDateTime dt;
3411  if (checkRecur() != KARecurrence::NO_RECUR)
3412  {
3413  if (mRecurrence->duration() < 0)
3414  return true; // infinite recurrence
3415  dt = mRecurrence->endDateTime();
3416  }
3417  else
3418  dt = mNextMainDateTime.effectiveKDateTime();
3419  if (mStartDateTime.isDateOnly())
3420  {
3421  QDate pre = preDateTime.date();
3422  if (preDateTime.toTimeSpec(mStartDateTime.timeSpec()).time() < DateTime::startOfDay())
3423  pre = pre.addDays(-1); // today's recurrence (if today recurs) is still to come
3424  if (pre < dt.date())
3425  return true;
3426  }
3427  else if (preDateTime < dt)
3428  return true;
3429 
3430  if (includeRepetitions && mRepetition)
3431  {
3432  if (preDateTime < mRepetition.duration().end(dt))
3433  return true;
3434  }
3435  return false;
3436 }
3437 
3438 /******************************************************************************
3439 * Set the date/time of the event to the next scheduled occurrence after the
3440 * specified date/time, provided that this is later than its current date/time.
3441 * Any reminder alarm is adjusted accordingly.
3442 * If the alarm has a sub-repetition, and a repetition of a previous recurrence
3443 * occurs after the specified date/time, that repetition is set as the next
3444 * occurrence.
3445 */
3446 KAEvent::OccurType KAEvent::setNextOccurrence(const KDateTime& preDateTime)
3447 {
3448  return d->setNextOccurrence(preDateTime);
3449 }
3450 
3451 KAEvent::OccurType KAEventPrivate::setNextOccurrence(const KDateTime& preDateTime)
3452 {
3453  if (preDateTime < mNextMainDateTime.effectiveKDateTime())
3454  return KAEvent::FIRST_OR_ONLY_OCCURRENCE; // it might not be the first recurrence - tant pis
3455  KDateTime pre = preDateTime;
3456  // If there are repetitions, adjust the comparison date/time so that
3457  // we find the earliest recurrence which has a repetition falling after
3458  // the specified preDateTime.
3459  if (mRepetition)
3460  pre = mRepetition.duration(-mRepetition.count()).end(preDateTime);
3461 
3462  DateTime afterPre; // next recurrence after 'pre'
3463  KAEvent::OccurType type;
3464  if (pre < mNextMainDateTime.effectiveKDateTime())
3465  {
3466  afterPre = mNextMainDateTime;
3467  type = KAEvent::FIRST_OR_ONLY_OCCURRENCE; // may not actually be the first occurrence
3468  }
3469  else if (checkRecur() != KARecurrence::NO_RECUR)
3470  {
3471  type = nextRecurrence(pre, afterPre);
3472  if (type == KAEvent::NO_OCCURRENCE)
3473  return KAEvent::NO_OCCURRENCE;
3474  if (type != KAEvent::FIRST_OR_ONLY_OCCURRENCE && afterPre != mNextMainDateTime)
3475  {
3476  // Need to reschedule the next trigger date/time
3477  mNextMainDateTime = afterPre;
3478  if (mReminderMinutes > 0 && (mDeferral == REMINDER_DEFERRAL || mReminderActive != ACTIVE_REMINDER))
3479  {
3480  // Reinstate the advance reminder for the rescheduled recurrence.
3481  // Note that a reminder AFTER the main alarm will be left active.
3482  activate_reminder(!mReminderOnceOnly);
3483  }
3484  if (mDeferral == REMINDER_DEFERRAL)
3485  set_deferral(NO_DEFERRAL);
3486  mTriggerChanged = true;
3487  }
3488  }
3489  else
3490  return KAEvent::NO_OCCURRENCE;
3491 
3492  if (mRepetition)
3493  {
3494  if (afterPre <= preDateTime)
3495  {
3496  // The next occurrence is a sub-repetition.
3497  type = static_cast<KAEvent::OccurType>(type | KAEvent::OCCURRENCE_REPEAT);
3498  mNextRepeat = mRepetition.nextRepeatCount(afterPre.effectiveKDateTime(), preDateTime);
3499  // Repetitions can't have a reminder, so remove any.
3500  activate_reminder(false);
3501  if (mDeferral == REMINDER_DEFERRAL)
3502  set_deferral(NO_DEFERRAL);
3503  mTriggerChanged = true;
3504  }
3505  else if (mNextRepeat)
3506  {
3507  // The next occurrence is the main occurrence, not a repetition
3508  mNextRepeat = 0;
3509  mTriggerChanged = true;
3510  }
3511  }
3512  return type;
3513 }
3514 
3515 /******************************************************************************
3516 * Get the date/time of the next occurrence of the event, after the specified
3517 * date/time.
3518 * 'result' = date/time of next occurrence, or invalid date/time if none.
3519 */
3520 KAEvent::OccurType KAEvent::nextOccurrence(const KDateTime& preDateTime, DateTime& result, OccurOption o) const
3521 {
3522  return d->nextOccurrence(preDateTime, result, o);
3523 }
3524 
3525 KAEvent::OccurType KAEventPrivate::nextOccurrence(const KDateTime& preDateTime, DateTime& result,
3526  KAEvent::OccurOption includeRepetitions) const
3527 {
3528  KDateTime pre = preDateTime;
3529  if (includeRepetitions != KAEvent::IGNORE_REPETITION)
3530  { // RETURN_REPETITION or ALLOW_FOR_REPETITION
3531  if (!mRepetition)
3532  includeRepetitions = KAEvent::IGNORE_REPETITION;
3533  else
3534  pre = mRepetition.duration(-mRepetition.count()).end(preDateTime);
3535  }
3536 
3537  KAEvent::OccurType type;
3538  const bool recurs = (checkRecur() != KARecurrence::NO_RECUR);
3539  if (recurs)
3540  type = nextRecurrence(pre, result);
3541  else if (pre < mNextMainDateTime.effectiveKDateTime())
3542  {
3543  result = mNextMainDateTime;
3544  type = KAEvent::FIRST_OR_ONLY_OCCURRENCE;
3545  }
3546  else
3547  {
3548  result = DateTime();
3549  type = KAEvent::NO_OCCURRENCE;
3550  }
3551 
3552  if (type != KAEvent::NO_OCCURRENCE && result <= preDateTime && includeRepetitions != KAEvent::IGNORE_REPETITION)
3553  { // RETURN_REPETITION or ALLOW_FOR_REPETITION
3554  // The next occurrence is a sub-repetition
3555  int repetition = mRepetition.nextRepeatCount(result.kDateTime(), preDateTime);
3556  const DateTime repeatDT = mRepetition.duration(repetition).end(result.kDateTime());
3557  if (recurs)
3558  {
3559  // We've found a recurrence before the specified date/time, which has
3560  // a sub-repetition after the date/time.
3561  // However, if the intervals between recurrences vary, we could possibly
3562  // have missed a later recurrence which fits the criterion, so check again.
3563  DateTime dt;
3564  const KAEvent::OccurType newType = previousOccurrence(repeatDT.effectiveKDateTime(), dt, false);
3565  if (dt > result)
3566  {
3567  type = newType;
3568  result = dt;
3569  if (includeRepetitions == KAEvent::RETURN_REPETITION && result <= preDateTime)
3570  {
3571  // The next occurrence is a sub-repetition
3572  repetition = mRepetition.nextRepeatCount(result.kDateTime(), preDateTime);
3573  result = mRepetition.duration(repetition).end(result.kDateTime());
3574  type = static_cast<KAEvent::OccurType>(type | KAEvent::OCCURRENCE_REPEAT);
3575  }
3576  return type;
3577  }
3578  }
3579  if (includeRepetitions == KAEvent::RETURN_REPETITION)
3580  {
3581  // The next occurrence is a sub-repetition
3582  result = repeatDT;
3583  type = static_cast<KAEvent::OccurType>(type | KAEvent::OCCURRENCE_REPEAT);
3584  }
3585  }
3586  return type;
3587 }
3588 
3589 /******************************************************************************
3590 * Get the date/time of the last previous occurrence of the event, before the
3591 * specified date/time.
3592 * If 'includeRepetitions' is true and the alarm has a sub-repetition, the
3593 * last previous repetition is returned if appropriate.
3594 * 'result' = date/time of previous occurrence, or invalid date/time if none.
3595 */
3596 KAEvent::OccurType KAEvent::previousOccurrence(const KDateTime& afterDateTime, DateTime& result, bool includeRepetitions) const
3597 {
3598  return d->previousOccurrence(afterDateTime, result, includeRepetitions);
3599 }
3600 
3601 KAEvent::OccurType KAEventPrivate::previousOccurrence(const KDateTime& afterDateTime, DateTime& result,
3602  bool includeRepetitions) const
3603 {
3604  Q_ASSERT(!afterDateTime.isDateOnly());
3605  if (mStartDateTime >= afterDateTime)
3606  {
3607  result = KDateTime();
3608  return KAEvent::NO_OCCURRENCE; // the event starts after the specified date/time
3609  }
3610 
3611  // Find the latest recurrence of the event
3612  KAEvent::OccurType type;
3613  if (checkRecur() == KARecurrence::NO_RECUR)
3614  {
3615  result = mStartDateTime;
3616  type = KAEvent::FIRST_OR_ONLY_OCCURRENCE;
3617  }
3618  else
3619  {
3620  const KDateTime recurStart = mRecurrence->startDateTime();
3621  KDateTime after = afterDateTime.toTimeSpec(mStartDateTime.timeSpec());
3622  if (mStartDateTime.isDateOnly() && afterDateTime.time() > DateTime::startOfDay())
3623  after = after.addDays(1); // today's recurrence (if today recurs) has passed
3624  const KDateTime dt = mRecurrence->getPreviousDateTime(after);
3625  result = dt;
3626  result.setDateOnly(mStartDateTime.isDateOnly());
3627  if (!dt.isValid())
3628  return KAEvent::NO_OCCURRENCE;
3629  if (dt == recurStart)
3630  type = KAEvent::FIRST_OR_ONLY_OCCURRENCE;
3631  else if (mRecurrence->getNextDateTime(dt).isValid())
3632  type = result.isDateOnly() ? KAEvent::RECURRENCE_DATE : KAEvent::RECURRENCE_DATE_TIME;
3633  else
3634  type = KAEvent::LAST_RECURRENCE;
3635  }
3636 
3637  if (includeRepetitions && mRepetition)
3638  {
3639  // Find the latest repetition which is before the specified time.
3640  const int repetition = mRepetition.previousRepeatCount(result.effectiveKDateTime(), afterDateTime);
3641  if (repetition > 0)
3642  {
3643  result = mRepetition.duration(qMin(repetition, mRepetition.count())).end(result.kDateTime());
3644  return static_cast<KAEvent::OccurType>(type | KAEvent::OCCURRENCE_REPEAT);
3645  }
3646  }
3647  return type;
3648 }
3649 
3650 /******************************************************************************
3651 * Set the event to be a copy of the specified event, making the specified
3652 * alarm the 'displaying' alarm.
3653 * The purpose of setting up a 'displaying' alarm is to be able to reinstate
3654 * the alarm message in case of a crash, or to reinstate it should the user
3655 * choose to defer the alarm. Note that even repeat-at-login alarms need to be
3656 * saved in case their end time expires before the next login.
3657 * Reply = true if successful, false if alarm was not copied.
3658 */
3659 #ifndef KALARMCAL_USE_KRESOURCES
3660 bool KAEvent::setDisplaying(const KAEvent& e, KAAlarm::Type t, Akonadi::Collection::Id id, const KDateTime& dt, bool showEdit, bool showDefer)
3661 #else
3662 bool KAEvent::setDisplaying(const KAEvent& e, KAAlarm::Type t, const QString& id, const KDateTime& dt, bool showEdit, bool showDefer)
3663 #endif
3664 {
3665  return d->setDisplaying(*e.d, t, id, dt, showEdit, showDefer);
3666 }
3667 
3668 #ifndef KALARMCAL_USE_KRESOURCES
3669 bool KAEventPrivate::setDisplaying(const KAEventPrivate& event, KAAlarm::Type alarmType, Akonadi::Collection::Id collectionId,
3670  const KDateTime& repeatAtLoginTime, bool showEdit, bool showDefer)
3671 #else
3672 bool KAEventPrivate::setDisplaying(const KAEventPrivate& event, KAAlarm::Type alarmType, const QString& resourceID,
3673  const KDateTime& repeatAtLoginTime, bool showEdit, bool showDefer)
3674 #endif
3675 {
3676  if (!mDisplaying
3677  && (alarmType == KAAlarm::MAIN_ALARM
3678  || alarmType == KAAlarm::REMINDER_ALARM
3679  || alarmType == KAAlarm::DEFERRED_REMINDER_ALARM
3680  || alarmType == KAAlarm::DEFERRED_ALARM
3681  || alarmType == KAAlarm::AT_LOGIN_ALARM))
3682  {
3683 //kDebug()<<event.id()<<","<<(alarmType==KAAlarm::MAIN_ALARM?"MAIN":alarmType==KAAlarm::REMINDER_ALARM?"REMINDER":alarmType==KAAlarm::DEFERRED_REMINDER_ALARM?"REMINDER_DEFERRAL":alarmType==KAAlarm::DEFERRED_ALARM?"DEFERRAL":"LOGIN")<<"): time="<<repeatAtLoginTime.toString();
3684  KAAlarm al = event.alarm(alarmType);
3685  if (al.isValid())
3686  {
3687  *this = event;
3688  // Change the event ID to avoid duplicating the same unique ID as the original event
3689  setCategory(CalEvent::DISPLAYING);
3690 #ifndef KALARMCAL_USE_KRESOURCES
3691  mItemId = -1; // the display event doesn't have an associated Item
3692  mCollectionId = collectionId; // original collection ID which contained the event
3693 #else
3694  mOriginalResourceId = resourceID;
3695 #endif
3696  mDisplayingDefer = showDefer;
3697  mDisplayingEdit = showEdit;
3698  mDisplaying = true;
3699  mDisplayingTime = (alarmType == KAAlarm::AT_LOGIN_ALARM) ? repeatAtLoginTime : al.dateTime().kDateTime();
3700  switch (al.type())
3701  {
3702  case KAAlarm::AT_LOGIN_ALARM: mDisplayingFlags = KAEvent::REPEAT_AT_LOGIN; break;
3703  case KAAlarm::REMINDER_ALARM: mDisplayingFlags = REMINDER; break;
3704  case KAAlarm::DEFERRED_REMINDER_ALARM: mDisplayingFlags = al.timedDeferral() ? (REMINDER | TIME_DEFERRAL) : (REMINDER | DATE_DEFERRAL); break;
3705  case KAAlarm::DEFERRED_ALARM: mDisplayingFlags = al.timedDeferral() ? TIME_DEFERRAL : DATE_DEFERRAL; break;
3706  default: mDisplayingFlags = 0; break;
3707  }
3708  ++mAlarmCount;
3709  return true;
3710  }
3711  }
3712  return false;
3713 }
3714 
3715 /******************************************************************************
3716 * Reinstate the original event from the 'displaying' event.
3717 */
3718 #ifndef KALARMCAL_USE_KRESOURCES
3719 void KAEvent::reinstateFromDisplaying(const KCalCore::Event::Ptr& e, Akonadi::Collection::Id& id, bool& showEdit, bool& showDefer)
3720 #else
3721 void KAEvent::reinstateFromDisplaying(const KCal::Event* e, QString& id, bool& showEdit, bool& showDefer)
3722 #endif
3723 {
3724  d->reinstateFromDisplaying(e, id, showEdit, showDefer);
3725 }
3726 
3727 #ifndef KALARMCAL_USE_KRESOURCES
3728 void KAEventPrivate::reinstateFromDisplaying(const Event::Ptr& kcalEvent, Akonadi::Collection::Id& collectionId, bool& showEdit, bool& showDefer)
3729 #else
3730 void KAEventPrivate::reinstateFromDisplaying(const Event* kcalEvent, QString& resourceID, bool& showEdit, bool& showDefer)
3731 #endif
3732 {
3733  set(kcalEvent);
3734  if (mDisplaying)
3735  {
3736  // Retrieve the original event's unique ID
3737  setCategory(CalEvent::ACTIVE);
3738 #ifndef KALARMCAL_USE_KRESOURCES
3739  collectionId = mCollectionId;
3740  mCollectionId = -1;
3741 #else
3742  resourceID = mOriginalResourceId;
3743  mOriginalResourceId.clear();
3744 #endif
3745  showDefer = mDisplayingDefer;
3746  showEdit = mDisplayingEdit;
3747  mDisplaying = false;
3748  --mAlarmCount;
3749  }
3750 }
3751 
3752 /******************************************************************************
3753 * Return the original alarm which the displaying alarm refers to.
3754 * Note that the caller is responsible for ensuring that the event was a
3755 * displaying event, since this is normally called after
3756 * reinstateFromDisplaying(), which clears mDisplaying.
3757 */
3758 KAAlarm KAEvent::convertDisplayingAlarm() const
3759 {
3760  KAAlarm al = alarm(KAAlarm::DISPLAYING_ALARM);
3761  KAAlarm::Private* const al_d = al.d;
3762  const int displayingFlags = d->mDisplayingFlags;
3763  if (displayingFlags & REPEAT_AT_LOGIN)
3764  {
3765  al_d->mRepeatAtLogin = true;
3766  al_d->mType = KAAlarm::AT_LOGIN_ALARM;
3767  }
3768  else if (displayingFlags & KAEventPrivate::DEFERRAL)
3769  {
3770  al_d->mDeferred = true;
3771  al_d->mTimedDeferral = (displayingFlags & KAEventPrivate::TIMED_FLAG);
3772  al_d->mType = (displayingFlags & KAEventPrivate::REMINDER) ? KAAlarm::DEFERRED_REMINDER_ALARM : KAAlarm::DEFERRED_ALARM;
3773  }
3774  else if (displayingFlags & KAEventPrivate::REMINDER)
3775  al_d->mType = KAAlarm::REMINDER_ALARM;
3776  else
3777  al_d->mType = KAAlarm::MAIN_ALARM;
3778  return al;
3779 }
3780 
3781 bool KAEvent::displaying() const
3782 {
3783  return d->mDisplaying;
3784 }
3785 
3786 /******************************************************************************
3787 * Return the alarm of the specified type.
3788 */
3789 KAAlarm KAEvent::alarm(KAAlarm::Type t) const
3790 {
3791  return d->alarm(t);
3792 }
3793 
3794 KAAlarm KAEventPrivate::alarm(KAAlarm::Type type) const
3795 {
3796  checkRecur(); // ensure recurrence/repetition data is consistent
3797  KAAlarm al; // this sets type to INVALID_ALARM
3798  KAAlarm::Private* const al_d = al.d;
3799  if (mAlarmCount)
3800  {
3801  al_d->mActionType = static_cast<KAAlarm::Action>(mActionSubType);
3802  al_d->mRepeatAtLogin = false;
3803  al_d->mDeferred = false;
3804  switch (type)
3805  {
3806  case KAAlarm::MAIN_ALARM:
3807  if (!mMainExpired)
3808  {
3809  al_d->mType = KAAlarm::MAIN_ALARM;
3810  al_d->mNextMainDateTime = mNextMainDateTime;
3811  al_d->mRepetition = mRepetition;
3812  al_d->mNextRepeat = mNextRepeat;
3813  }
3814  break;
3815  case KAAlarm::REMINDER_ALARM:
3816  if (mReminderActive == ACTIVE_REMINDER)
3817  {
3818  al_d->mType = KAAlarm::REMINDER_ALARM;
3819  if (mReminderMinutes < 0)
3820  al_d->mNextMainDateTime = mReminderAfterTime;
3821  else if (mReminderOnceOnly)
3822  al_d->mNextMainDateTime = mStartDateTime.addMins(-mReminderMinutes);
3823  else
3824  al_d->mNextMainDateTime = mNextMainDateTime.addMins(-mReminderMinutes);
3825  }
3826  break;
3827  case KAAlarm::DEFERRED_REMINDER_ALARM:
3828  if (mDeferral != REMINDER_DEFERRAL)
3829  break;
3830  // fall through to DEFERRED_ALARM
3831  case KAAlarm::DEFERRED_ALARM:
3832  if (mDeferral != NO_DEFERRAL)
3833  {
3834  al_d->mType = (mDeferral == REMINDER_DEFERRAL) ? KAAlarm::DEFERRED_REMINDER_ALARM : KAAlarm::DEFERRED_ALARM;
3835  al_d->mNextMainDateTime = mDeferralTime;
3836  al_d->mDeferred = true;
3837  al_d->mTimedDeferral = !mDeferralTime.isDateOnly();
3838  }
3839  break;
3840  case KAAlarm::AT_LOGIN_ALARM:
3841  if (mRepeatAtLogin)
3842  {
3843  al_d->mType = KAAlarm::AT_LOGIN_ALARM;
3844  al_d->mNextMainDateTime = mAtLoginDateTime;
3845  al_d->mRepeatAtLogin = true;
3846  }
3847  break;
3848  case KAAlarm::DISPLAYING_ALARM:
3849  if (mDisplaying)
3850  {
3851  al_d->mType = KAAlarm::DISPLAYING_ALARM;
3852  al_d->mNextMainDateTime = mDisplayingTime;
3853  }
3854  break;
3855  case KAAlarm::INVALID_ALARM:
3856  default:
3857  break;
3858  }
3859  }
3860  return al;
3861 }
3862 
3863 /******************************************************************************
3864 * Return the main alarm for the event.
3865 * If the main alarm does not exist, one of the subsidiary ones is returned if
3866 * possible.
3867 * N.B. a repeat-at-login alarm can only be returned if it has been read from/
3868 * written to the calendar file.
3869 */
3870 KAAlarm KAEvent::firstAlarm() const
3871 {
3872  return d->firstAlarm();
3873 }
3874 
3875 KAAlarm KAEventPrivate::firstAlarm() const
3876 {
3877  if (mAlarmCount)
3878  {
3879  if (!mMainExpired)
3880  return alarm(KAAlarm::MAIN_ALARM);
3881  return nextAlarm(KAAlarm::MAIN_ALARM);
3882  }
3883  return KAAlarm();
3884 }
3885 
3886 /******************************************************************************
3887 * Return the next alarm for the event, after the specified alarm.
3888 * N.B. a repeat-at-login alarm can only be returned if it has been read from/
3889 * written to the calendar file.
3890 */
3891 KAAlarm KAEvent::nextAlarm(const KAAlarm& previousAlarm) const
3892 {
3893  return d->nextAlarm(previousAlarm.type());
3894 }
3895 
3896 KAAlarm KAEvent::nextAlarm(KAAlarm::Type previousType) const
3897 {
3898  return d->nextAlarm(previousType);
3899 }
3900 
3901 KAAlarm KAEventPrivate::nextAlarm(KAAlarm::Type previousType) const
3902 {
3903  switch (previousType)
3904  {
3905  case KAAlarm::MAIN_ALARM:
3906  if (mReminderActive == ACTIVE_REMINDER)
3907  return alarm(KAAlarm::REMINDER_ALARM);
3908  // fall through to REMINDER_ALARM
3909  case KAAlarm::REMINDER_ALARM:
3910  // There can only be one deferral alarm
3911  if (mDeferral == REMINDER_DEFERRAL)
3912  return alarm(KAAlarm::DEFERRED_REMINDER_ALARM);
3913  if (mDeferral == NORMAL_DEFERRAL)
3914  return alarm(KAAlarm::DEFERRED_ALARM);
3915  // fall through to DEFERRED_ALARM
3916  case KAAlarm::DEFERRED_REMINDER_ALARM:
3917  case KAAlarm::DEFERRED_ALARM:
3918  if (mRepeatAtLogin)
3919  return alarm(KAAlarm::AT_LOGIN_ALARM);
3920  // fall through to AT_LOGIN_ALARM
3921  case KAAlarm::AT_LOGIN_ALARM:
3922  if (mDisplaying)
3923  return alarm(KAAlarm::DISPLAYING_ALARM);
3924  // fall through to DISPLAYING_ALARM
3925  case KAAlarm::DISPLAYING_ALARM:
3926  // fall through to default
3927  case KAAlarm::INVALID_ALARM:
3928  default:
3929  break;
3930  }
3931  return KAAlarm();
3932 }
3933 
3934 int KAEvent::alarmCount() const
3935 {
3936  return d->mAlarmCount;
3937 }
3938 
3939 /******************************************************************************
3940 * Remove the alarm of the specified type from the event.
3941 * This must only be called to remove an alarm which has expired, not to
3942 * reconfigure the event.
3943 */
3944 void KAEvent::removeExpiredAlarm(KAAlarm::Type type)
3945 {
3946  d->removeExpiredAlarm(type);
3947 }
3948 
3949 void KAEventPrivate::removeExpiredAlarm(KAAlarm::Type type)
3950 {
3951  const int count = mAlarmCount;
3952  switch (type)
3953  {
3954  case KAAlarm::MAIN_ALARM:
3955  if (!mReminderActive || mReminderMinutes > 0)
3956  {
3957  mAlarmCount = 0; // removing main alarm - also remove subsidiary alarms
3958  break;
3959  }
3960  // There is a reminder after the main alarm - retain the
3961  // reminder and remove other subsidiary alarms.
3962  mMainExpired = true; // mark the alarm as expired now
3963  --mAlarmCount;
3964  set_deferral(NO_DEFERRAL);
3965  if (mDisplaying)
3966  {
3967  mDisplaying = false;
3968  --mAlarmCount;
3969  }
3970  // fall through to AT_LOGIN_ALARM
3971  case KAAlarm::AT_LOGIN_ALARM:
3972  if (mRepeatAtLogin)
3973  {
3974  // Remove the at-login alarm, but keep a note of it for archiving purposes
3975  mArchiveRepeatAtLogin = true;
3976  mRepeatAtLogin = false;
3977  --mAlarmCount;
3978  }
3979  break;
3980  case KAAlarm::REMINDER_ALARM:
3981  // Remove any reminder alarm, but keep a note of it for archiving purposes
3982  // and for restoration after the next recurrence.
3983  activate_reminder(false);
3984  break;
3985  case KAAlarm::DEFERRED_REMINDER_ALARM:
3986  case KAAlarm::DEFERRED_ALARM:
3987  set_deferral(NO_DEFERRAL);
3988  break;
3989  case KAAlarm::DISPLAYING_ALARM:
3990  if (mDisplaying)
3991  {
3992  mDisplaying = false;
3993  --mAlarmCount;
3994  }
3995  break;
3996  case KAAlarm::INVALID_ALARM:
3997  default:
3998  break;
3999  }
4000  if (mAlarmCount != count)
4001  mTriggerChanged = true;
4002 }
4003 
4004 void KAEvent::startChanges()
4005 {
4006  d->startChanges();
4007 }
4008 
4009 /******************************************************************************
4010 * Indicate that changes to the instance are complete.
4011 * This allows trigger times to be recalculated if any changes have occurred.
4012 */
4013 void KAEvent::endChanges()
4014 {
4015  d->endChanges();
4016 }
4017 
4018 void KAEventPrivate::endChanges()
4019 {
4020  if (mChangeCount > 0)
4021  --mChangeCount;
4022 }
4023 
4024 #ifndef KALARMCAL_USE_KRESOURCES
4025 /******************************************************************************
4026 * Return a list of pointers to KAEvent objects.
4027 */
4028 KAEvent::List KAEvent::ptrList(QVector<KAEvent>& objList)
4029 {
4030  KAEvent::List ptrs;
4031  for (int i = 0, count = objList.count(); i < count; ++i)
4032  ptrs += &objList[i];
4033  return ptrs;
4034 }
4035 #endif
4036 
4037 void KAEvent::dumpDebug() const
4038 {
4039 #ifndef KDE_NO_DEBUG_OUTPUT
4040  d->dumpDebug();
4041 #endif
4042 }
4043 
4044 #ifndef KDE_NO_DEBUG_OUTPUT
4045 void KAEventPrivate::dumpDebug() const
4046 {
4047  kDebug() << "KAEvent dump:";
4048 #ifdef KALARMCAL_USE_KRESOURCES
4049  if (mResource) { kDebug() << "-- mResource:" << (void*)mResource; }
4050 #endif
4051  kDebug() << "-- mEventID:" << mEventID;
4052  kDebug() << "-- mActionSubType:" << (mActionSubType == KAEvent::MESSAGE ? "MESSAGE" : mActionSubType == KAEvent::FILE ? "FILE" : mActionSubType == KAEvent::COMMAND ? "COMMAND" : mActionSubType == KAEvent::EMAIL ? "EMAIL" : mActionSubType == KAEvent::AUDIO ? "AUDIO" : "??");
4053  kDebug() << "-- mNextMainDateTime:" << mNextMainDateTime.toString();
4054  kDebug() << "-- mCommandError:" << mCommandError;
4055  kDebug() << "-- mAllTrigger:" << mAllTrigger.toString();
4056  kDebug() << "-- mMainTrigger:" << mMainTrigger.toString();
4057  kDebug() << "-- mAllWorkTrigger:" << mAllWorkTrigger.toString();
4058  kDebug() << "-- mMainWorkTrigger:" << mMainWorkTrigger.toString();
4059  kDebug() << "-- mCategory:" << mCategory;
4060  if (!mTemplateName.isEmpty())
4061  {
4062  kDebug() << "-- mTemplateName:" << mTemplateName;
4063  kDebug() << "-- mTemplateAfterTime:" << mTemplateAfterTime;
4064  }
4065  kDebug() << "-- mText:" << mText;
4066  if (mActionSubType == KAEvent::MESSAGE || mActionSubType == KAEvent::FILE)
4067  {
4068  kDebug() << "-- mBgColour:" << mBgColour.name();
4069  kDebug() << "-- mFgColour:" << mFgColour.name();
4070  kDebug() << "-- mUseDefaultFont:" << mUseDefaultFont;
4071  if (!mUseDefaultFont)
4072  kDebug() << "-- mFont:" << mFont.toString();
4073  kDebug() << "-- mSpeak:" << mSpeak;
4074  kDebug() << "-- mAudioFile:" << mAudioFile;
4075  kDebug() << "-- mPreAction:" << mPreAction;
4076  kDebug() << "-- mExecPreActOnDeferral:" << (mExtraActionOptions & KAEvent::ExecPreActOnDeferral);
4077  kDebug() << "-- mCancelOnPreActErr:" << (mExtraActionOptions & KAEvent::CancelOnPreActError);
4078  kDebug() << "-- mDontShowPreActErr:" << (mExtraActionOptions & KAEvent::DontShowPreActError);
4079  kDebug() << "-- mPostAction:" << mPostAction;
4080  kDebug() << "-- mLateCancel:" << mLateCancel;
4081  kDebug() << "-- mAutoClose:" << mAutoClose;
4082  }
4083  else if (mActionSubType == KAEvent::COMMAND)
4084  {
4085  kDebug() << "-- mCommandScript:" << mCommandScript;
4086  kDebug() << "-- mCommandXterm:" << mCommandXterm;
4087  kDebug() << "-- mCommandDisplay:" << mCommandDisplay;
4088  kDebug() << "-- mLogFile:" << mLogFile;
4089  }
4090  else if (mActionSubType == KAEvent::EMAIL)
4091  {
4092  kDebug() << "-- mEmail: FromKMail:" << mEmailFromIdentity;
4093  kDebug() << "-- Addresses:" << mEmailAddresses.join(QLatin1String(","));
4094  kDebug() << "-- Subject:" << mEmailSubject;
4095  kDebug() << "-- Attachments:" << mEmailAttachments.join(QLatin1String(","));
4096  kDebug() << "-- Bcc:" << mEmailBcc;
4097  }
4098  else if (mActionSubType == KAEvent::AUDIO)
4099  kDebug() << "-- mAudioFile:" << mAudioFile;
4100  kDebug() << "-- mBeep:" << mBeep;
4101  if (mActionSubType == KAEvent::AUDIO || !mAudioFile.isEmpty())
4102  {
4103  if (mSoundVolume >= 0)
4104  {
4105  kDebug() << "-- mSoundVolume:" << mSoundVolume;
4106  if (mFadeVolume >= 0)
4107  {
4108  kDebug() << "-- mFadeVolume:" << mFadeVolume;
4109  kDebug() << "-- mFadeSeconds:" << mFadeSeconds;
4110  }
4111  else
4112  kDebug() << "-- mFadeVolume:-:";
4113  }
4114  else
4115  kDebug() << "-- mSoundVolume:-:";
4116  kDebug() << "-- mRepeatSoundPause:" << mRepeatSoundPause;
4117  }
4118  kDebug() << "-- mKMailSerialNumber:" << mKMailSerialNumber;
4119  kDebug() << "-- mCopyToKOrganizer:" << mCopyToKOrganizer;
4120  kDebug() << "-- mExcludeHolidays:" << (bool)mExcludeHolidays;
4121  kDebug() << "-- mWorkTimeOnly:" << mWorkTimeOnly;
4122  kDebug() << "-- mStartDateTime:" << mStartDateTime.toString();
4123  kDebug() << "-- mCreatedDateTime:" << mCreatedDateTime;
4124  kDebug() << "-- mRepeatAtLogin:" << mRepeatAtLogin;
4125  if (mRepeatAtLogin)
4126  kDebug() << "-- mAtLoginDateTime:" << mAtLoginDateTime;
4127  kDebug() << "-- mArchiveRepeatAtLogin:" << mArchiveRepeatAtLogin;
4128  kDebug() << "-- mConfirmAck:" << mConfirmAck;
4129  kDebug() << "-- mEnabled:" << mEnabled;
4130 #ifndef KALARMCAL_USE_KRESOURCES
4131  kDebug() << "-- mItemId:" << mItemId;
4132  kDebug() << "-- mCollectionId:" << mCollectionId;
4133  kDebug() << "-- mCompatibility:" << mCompatibility;
4134  kDebug() << "-- mReadOnly:" << mReadOnly;
4135 #endif
4136  if (mReminderMinutes)
4137  {
4138  kDebug() << "-- mReminderMinutes:" << mReminderMinutes;
4139  kDebug() << "-- mReminderActive:" << (mReminderActive == ACTIVE_REMINDER ? "active" : mReminderActive == HIDDEN_REMINDER ? "hidden" : "no");
4140  kDebug() << "-- mReminderOnceOnly:" << mReminderOnceOnly;
4141  }
4142  else if (mDeferral > 0)
4143  {
4144  kDebug() << "-- mDeferral:" << (mDeferral == NORMAL_DEFERRAL ? "normal" : "reminder");
4145  kDebug() << "-- mDeferralTime:" << mDeferralTime.toString();
4146  }
4147  kDebug() << "-- mDeferDefaultMinutes:" << mDeferDefaultMinutes;
4148  if (mDeferDefaultMinutes)
4149  kDebug() << "-- mDeferDefaultDateOnly:" << mDeferDefaultDateOnly;
4150  if (mDisplaying)
4151  {
4152  kDebug() << "-- mDisplayingTime:" << mDisplayingTime.toString();
4153  kDebug() << "-- mDisplayingFlags:" << mDisplayingFlags;
4154  kDebug() << "-- mDisplayingDefer:" << mDisplayingDefer;
4155  kDebug() << "-- mDisplayingEdit:" << mDisplayingEdit;
4156  }
4157  kDebug() << "-- mRevision:" << mRevision;
4158  kDebug() << "-- mRecurrence:" << mRecurrence;
4159  if (!mRepetition)
4160  kDebug() << "-- mRepetition: 0";
4161  else if (mRepetition.isDaily())
4162  kDebug() << "-- mRepetition: count:" << mRepetition.count() << ", interval:" << mRepetition.intervalDays() << "days";
4163  else
4164  kDebug() << "-- mRepetition: count:" << mRepetition.count() << ", interval:" << mRepetition.intervalMinutes() << "minutes";
4165  kDebug() << "-- mNextRepeat:" << mNextRepeat;
4166  kDebug() << "-- mAlarmCount:" << mAlarmCount;
4167  kDebug() << "-- mMainExpired:" << mMainExpired;
4168  kDebug() << "-- mDisplaying:" << mDisplaying;
4169  kDebug() << "KAEvent dump end";
4170 }
4171 #endif
4172 
4173 /******************************************************************************
4174 * Fetch the start and next date/time for a KCal::Event.
4175 * Reply = next main date/time.
4176 */
4177 #ifndef KALARMCAL_USE_KRESOURCES
4178 DateTime KAEventPrivate::readDateTime(const Event::Ptr& event, bool dateOnly, DateTime& start)
4179 #else
4180 DateTime KAEventPrivate::readDateTime(const Event* event, bool dateOnly, DateTime& start)
4181 #endif
4182 {
4183  start = event->dtStart();
4184  if (dateOnly)
4185  {
4186  // A date-only event is indicated by the X-KDE-KALARM-FLAGS:DATE property, not
4187  // by a date-only start date/time (for the reasons given in updateKCalEvent()).
4188  start.setDateOnly(true);
4189  }
4190  DateTime next = start;
4191  const int SZ_YEAR = 4; // number of digits in year value
4192  const int SZ_MONTH = 2; // number of digits in month value
4193  const int SZ_DAY = 2; // number of digits in day value
4194  const int SZ_DATE = SZ_YEAR + SZ_MONTH + SZ_DAY; // total size of date value
4195  const int IX_TIME = SZ_DATE + 1; // offset to time value
4196  const int SZ_HOUR = 2; // number of digits in hour value
4197  const int SZ_MIN = 2; // number of digits in minute value
4198  const int SZ_SEC = 2; // number of digits in second value
4199  const int SZ_TIME = SZ_HOUR + SZ_MIN + SZ_SEC; // total size of time value
4200  const QString prop = event->customProperty(KACalendar::APPNAME, KAEventPrivate::NEXT_RECUR_PROPERTY);
4201  if (prop.length() >= SZ_DATE)
4202  {
4203  // The next due recurrence time is specified
4204  const QDate d(prop.left(SZ_YEAR).toInt(),
4205  prop.mid(SZ_YEAR, SZ_MONTH).toInt(),
4206  prop.mid(SZ_YEAR + SZ_MONTH, SZ_DAY).toInt());
4207  if (d.isValid())
4208  {
4209  if (dateOnly && prop.length() == SZ_DATE)
4210  next.setDate(d);
4211  else if (!dateOnly && prop.length() == IX_TIME + SZ_TIME && prop[SZ_DATE] == QLatin1Char('T'))
4212  {
4213  const QTime t(prop.mid(IX_TIME, SZ_HOUR).toInt(),
4214  prop.mid(IX_TIME + SZ_HOUR, SZ_MIN).toInt(),
4215  prop.mid(IX_TIME + SZ_HOUR + SZ_MIN, SZ_SEC).toInt());
4216  if (t.isValid())
4217  {
4218  next.setDate(d);
4219  next.setTime(t);
4220  }
4221  }
4222  if (next < start)
4223  next = start; // ensure next recurrence time is valid
4224  }
4225  }
4226  return next;
4227 }
4228 
4229 /******************************************************************************
4230 * Parse the alarms for a KCal::Event.
4231 * Reply = map of alarm data, indexed by KAAlarm::Type
4232 */
4233 #ifndef KALARMCAL_USE_KRESOURCES
4234 void KAEventPrivate::readAlarms(const Event::Ptr& event, AlarmMap* alarmMap, bool cmdDisplay)
4235 #else
4236 void KAEventPrivate::readAlarms(const Event* event, AlarmMap* alarmMap, bool cmdDisplay)
4237 #endif
4238 {
4239  const Alarm::List alarms = event->alarms();
4240 
4241  // Check if it's an audio event with no display alarm
4242  bool audioOnly = false;
4243  for (int i = 0, end = alarms.count(); i < end; ++i)
4244  {
4245  switch (alarms[i]->type())
4246  {
4247  case Alarm::Display:
4248  case Alarm::Procedure:
4249  audioOnly = false;
4250  i = end; // exit from the 'for' loop
4251  break;
4252  case Alarm::Audio:
4253  audioOnly = true;
4254  break;
4255  default:
4256  break;
4257  }
4258  }
4259 
4260  for (int i = 0, end = alarms.count(); i < end; ++i)
4261  {
4262  // Parse the next alarm's text
4263  AlarmData data;
4264  readAlarm(alarms[i], data, audioOnly, cmdDisplay);
4265  if (data.type != INVALID_ALARM)
4266  alarmMap->insert(data.type, data);
4267  }
4268 }
4269 
4270 /******************************************************************************
4271 * Parse a KCal::Alarm.
4272 * If 'audioMain' is true, the event contains an audio alarm but no display alarm.
4273 * Reply = alarm ID (sequence number)
4274 */
4275 #ifndef KALARMCAL_USE_KRESOURCES
4276 void KAEventPrivate::readAlarm(const Alarm::Ptr& alarm, AlarmData& data, bool audioMain, bool cmdDisplay)
4277 #else
4278 void KAEventPrivate::readAlarm(const Alarm* alarm, AlarmData& data, bool audioMain, bool cmdDisplay)
4279 #endif
4280 {
4281  // Parse the next alarm's text
4282  data.alarm = alarm;
4283  data.displayingFlags = 0;
4284  data.isEmailText = false;
4285  data.speak = false;
4286  data.hiddenReminder = false;
4287  data.timedDeferral = false;
4288  data.nextRepeat = 0;
4289  data.repeatSoundPause = -1;
4290  if (alarm->repeatCount())
4291  {
4292  bool ok;
4293  const QString property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::NEXT_REPEAT_PROPERTY);
4294  int n = static_cast<int>(property.toUInt(&ok));
4295  if (ok)
4296  data.nextRepeat = n;
4297  }
4298  QString property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY);
4299  const QStringList flags = property.split(KAEventPrivate::SC, QString::SkipEmptyParts);
4300  switch (alarm->type())
4301  {
4302  case Alarm::Procedure:
4303  data.action = KAAlarm::COMMAND;
4304  data.cleanText = alarm->programFile();
4305  data.commandScript = data.cleanText.isEmpty(); // blank command indicates a script
4306  if (!alarm->programArguments().isEmpty())
4307  {
4308  if (!data.commandScript)
4309  data.cleanText += QLatin1Char(' ');
4310  data.cleanText += alarm->programArguments();
4311  }
4312  data.extraActionOptions = 0;
4313  if (flags.contains(KAEventPrivate::EXEC_ON_DEFERRAL_FLAG))
4314  data.extraActionOptions |= KAEvent::ExecPreActOnDeferral;
4315  if (flags.contains(KAEventPrivate::CANCEL_ON_ERROR_FLAG))
4316  data.extraActionOptions |= KAEvent::CancelOnPreActError;
4317  if (flags.contains(KAEventPrivate::DONT_SHOW_ERROR_FLAG))
4318  data.extraActionOptions |= KAEvent::DontShowPreActError;
4319  if (!cmdDisplay)
4320  break;
4321  // fall through to Display
4322  case Alarm::Display:
4323  {
4324  if (alarm->type() == Alarm::Display)
4325  {
4326  data.action = KAAlarm::MESSAGE;
4327  data.cleanText = AlarmText::fromCalendarText(alarm->text(), data.isEmailText);
4328  }
4329  const QString property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::FONT_COLOUR_PROPERTY);
4330  const QStringList list = property.split(QLatin1Char(';'), QString::KeepEmptyParts);
4331  data.bgColour = QColor(255, 255, 255); // white
4332  data.fgColour = QColor(0, 0, 0); // black
4333  const int n = list.count();
4334  if (n > 0)
4335  {
4336  if (!list[0].isEmpty())
4337  {
4338  QColor c(list[0]);
4339  if (c.isValid())
4340  data.bgColour = c;
4341  }
4342  if (n > 1 && !list[1].isEmpty())
4343  {
4344  QColor c(list[1]);
4345  if (c.isValid())
4346  data.fgColour = c;
4347  }
4348  }
4349  data.defaultFont = (n <= 2 || list[2].isEmpty());
4350  if (!data.defaultFont)
4351  data.font.fromString(list[2]);
4352  break;
4353  }
4354  case Alarm::Email:
4355  {
4356  data.action = KAAlarm::EMAIL;
4357  data.cleanText = alarm->mailText();
4358  const int i = flags.indexOf(KAEventPrivate::EMAIL_ID_FLAG);
4359  data.emailFromId = (i >= 0 && i + 1 < flags.count()) ? flags[i + 1].toUInt() : 0;
4360  break;
4361  }
4362  case Alarm::Audio:
4363  {
4364  data.action = KAAlarm::AUDIO;
4365  data.cleanText = alarm->audioFile();
4366  data.repeatSoundPause = (alarm->repeatCount() == -2) ? alarm->snoozeTime().asSeconds()
4367  : (alarm->repeatCount() == -1) ? 0 : -1;
4368  data.soundVolume = -1;
4369  data.fadeVolume = -1;
4370  data.fadeSeconds = 0;
4371  QString property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::VOLUME_PROPERTY);
4372  if (!property.isEmpty())
4373  {
4374  bool ok;
4375  float fadeVolume;
4376  int fadeSecs = 0;
4377  const QStringList list = property.split(QLatin1Char(';'), QString::KeepEmptyParts);
4378  data.soundVolume = list[0].toFloat(&ok);
4379  if (!ok || data.soundVolume > 1.0f)
4380  data.soundVolume = -1;
4381  if (data.soundVolume >= 0 && list.count() >= 3)
4382  {
4383  fadeVolume = list[1].toFloat(&ok);
4384  if (ok)
4385  fadeSecs = static_cast<int>(list[2].toUInt(&ok));
4386  if (ok && fadeVolume >= 0 && fadeVolume <= 1.0f && fadeSecs > 0)
4387  {
4388  data.fadeVolume = fadeVolume;
4389  data.fadeSeconds = fadeSecs;
4390  }
4391  }
4392  }
4393  if (!audioMain)
4394  {
4395  data.type = AUDIO_ALARM;
4396  data.speak = flags.contains(KAEventPrivate::SPEAK_FLAG);
4397  return;
4398  }
4399  break;
4400  }
4401  case Alarm::Invalid:
4402  data.type = INVALID_ALARM;
4403  return;
4404  }
4405 
4406  bool atLogin = false;
4407  bool reminder = false;
4408  bool deferral = false;
4409  bool dateDeferral = false;
4410  bool repeatSound = false;
4411  data.type = MAIN_ALARM;
4412  property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::TYPE_PROPERTY);
4413  const QStringList types = property.split(QLatin1Char(','), QString::SkipEmptyParts);
4414  for (int i = 0, end = types.count(); i < end; ++i)
4415  {
4416  const QString type = types[i];
4417  if (type == KAEventPrivate::AT_LOGIN_TYPE)
4418  atLogin = true;
4419  else if (type == KAEventPrivate::FILE_TYPE && data.action == KAAlarm::MESSAGE)
4420  data.action = KAAlarm::FILE;
4421  else if (type == KAEventPrivate::REMINDER_TYPE)
4422  reminder = true;
4423  else if (type == KAEventPrivate::TIME_DEFERRAL_TYPE)
4424  deferral = true;
4425  else if (type == KAEventPrivate::DATE_DEFERRAL_TYPE)
4426  dateDeferral = deferral = true;
4427  else if (type == KAEventPrivate::DISPLAYING_TYPE)
4428  data.type = DISPLAYING_ALARM;
4429  else if (type == KAEventPrivate::PRE_ACTION_TYPE && data.action == KAAlarm::COMMAND)
4430  data.type = PRE_ACTION_ALARM;
4431  else if (type == KAEventPrivate::POST_ACTION_TYPE && data.action == KAAlarm::COMMAND)
4432  data.type = POST_ACTION_ALARM;
4433  else if (type == KAEventPrivate::SOUND_REPEAT_TYPE && data.action == KAAlarm::AUDIO)
4434  {
4435  repeatSound = true;
4436  if (i + 1 < end)
4437  {
4438  bool ok;
4439  uint n = types[i + 1].toUInt(&ok);
4440  if (ok)
4441  {
4442  data.repeatSoundPause = n;
4443  ++i;
4444  }
4445  }
4446  }
4447  }
4448  if (repeatSound && data.repeatSoundPause < 0)
4449  data.repeatSoundPause = 0;
4450  else if (!repeatSound)
4451  data.repeatSoundPause = -1;
4452 
4453  if (reminder)
4454  {
4455  if (data.type == MAIN_ALARM)
4456  {
4457  data.type = deferral ? DEFERRED_REMINDER_ALARM : REMINDER_ALARM;
4458  data.timedDeferral = (deferral && !dateDeferral);
4459  }
4460  else if (data.type == DISPLAYING_ALARM)
4461  data.displayingFlags = dateDeferral ? REMINDER | DATE_DEFERRAL
4462  : deferral ? REMINDER | TIME_DEFERRAL : REMINDER;
4463  else if (data.type == REMINDER_ALARM
4464  && flags.contains(KAEventPrivate::HIDDEN_REMINDER_FLAG))
4465  data.hiddenReminder = true;
4466  }
4467  else if (deferral)
4468  {
4469  if (data.type == MAIN_ALARM)
4470  {
4471  data.type = DEFERRED_ALARM;
4472  data.timedDeferral = !dateDeferral;
4473  }
4474  else if (data.type == DISPLAYING_ALARM)
4475  data.displayingFlags = dateDeferral ? DATE_DEFERRAL : TIME_DEFERRAL;
4476  }
4477  if (atLogin)
4478  {
4479  if (data.type == MAIN_ALARM)
4480  data.type = AT_LOGIN_ALARM;
4481  else if (data.type == DISPLAYING_ALARM)
4482  data.displayingFlags = KAEvent::REPEAT_AT_LOGIN;
4483  }
4484 //kDebug()<<"text="<<alarm->text()<<", time="<<alarm->time().toString()<<", valid time="<<alarm->time().isValid();
4485 }
4486 
4487 /******************************************************************************
4488 * Calculate the next trigger times of the alarm.
4489 * This should only be called when changes have actually occurred which might
4490 * affect the event's trigger times.
4491 * mMainTrigger is set to the next scheduled recurrence/sub-repetition, or the
4492 * deferral time if a deferral is pending.
4493 * mAllTrigger is the same as mMainTrigger, but takes account of reminders.
4494 * mMainWorkTrigger is set to the next scheduled recurrence/sub-repetition
4495 * which occurs in working hours, if working-time-only is set.
4496 * mAllWorkTrigger is the same as mMainWorkTrigger, but takes account of reminders.
4497 */
4498 void KAEventPrivate::calcTriggerTimes() const
4499 {
4500  if (mChangeCount)
4501  return;
4502 #ifdef __GNUC__
4503 #warning May need to set date-only alarms to after start-of-day time in working-time checks
4504 #endif
4505  bool recurs = (checkRecur() != KARecurrence::NO_RECUR);
4506  if ((recurs && mWorkTimeOnly && mWorkTimeOnly != mWorkTimeIndex)
4507  || (recurs && mExcludeHolidays && mExcludeHolidays != mHolidays))
4508  {
4509  // It's a work time alarm, and work days/times have changed, or
4510  // it excludes holidays, and the holidays definition has changed.
4511  mTriggerChanged = true;
4512  }
4513  else if (!mTriggerChanged)
4514  return;
4515  mTriggerChanged = false;
4516  if (recurs && mWorkTimeOnly)
4517  mWorkTimeOnly = mWorkTimeIndex; // note which work time definition was used in calculation
4518  if (recurs && mExcludeHolidays)
4519  mExcludeHolidays = mHolidays; // note which holiday definition was used in calculation
4520 
4521  if (mCategory == CalEvent::ARCHIVED || mCategory == CalEvent::TEMPLATE)
4522  {
4523  // It's a template or archived
4524  mAllTrigger = mMainTrigger = mAllWorkTrigger = mMainWorkTrigger = KDateTime();
4525  }
4526  else if (mDeferral == NORMAL_DEFERRAL)
4527  {
4528  // For a deferred alarm, working time setting is ignored
4529  mAllTrigger = mMainTrigger = mAllWorkTrigger = mMainWorkTrigger = mDeferralTime;
4530  }
4531  else
4532  {
4533  mMainTrigger = mainDateTime(true); // next recurrence or sub-repetition
4534  mAllTrigger = (mDeferral == REMINDER_DEFERRAL) ? mDeferralTime
4535  : (mReminderActive != ACTIVE_REMINDER) ? mMainTrigger
4536  : (mReminderMinutes < 0) ? mReminderAfterTime
4537  : mMainTrigger.addMins(-mReminderMinutes);
4538  // It's not deferred.
4539  // If only-during-working-time is set and it recurs, it won't actually trigger
4540  // unless it falls during working hours.
4541  if ((!mWorkTimeOnly && !mExcludeHolidays)
4542  || !recurs
4543  || isWorkingTime(mMainTrigger.kDateTime()))
4544  {
4545  // It only occurs once, or it complies with any working hours/holiday
4546  // restrictions.
4547  mMainWorkTrigger = mMainTrigger;
4548  mAllWorkTrigger = mAllTrigger;
4549  }
4550  else if (mWorkTimeOnly)
4551  {
4552  // The alarm is restricted to working hours.
4553  // Finding the next occurrence during working hours can sometimes take a long time,
4554  // so mark the next actual trigger as invalid until the calculation completes.
4555  // Note that reminders are only triggered if the main alarm is during working time.
4556  if (!mExcludeHolidays)
4557  {
4558  // There are no holiday restrictions.
4559  calcNextWorkingTime(mMainTrigger);
4560  }
4561  else if (mHolidays)
4562  {
4563  // Holidays are excluded.
4564  DateTime nextTrigger = mMainTrigger;
4565  KDateTime kdt;
4566  for (int i = 0; i < 20; ++i)
4567  {
4568  calcNextWorkingTime(nextTrigger);
4569  if (!mHolidays->isHoliday(mMainWorkTrigger.date()))
4570  return; // found a non-holiday occurrence
4571  kdt = mMainWorkTrigger.effectiveKDateTime();
4572  kdt.setTime(QTime(23,59,59));
4573  const KAEvent::OccurType type = nextOccurrence(kdt, nextTrigger, KAEvent::RETURN_REPETITION);
4574  if (!nextTrigger.isValid())
4575  break;
4576  if (isWorkingTime(nextTrigger.kDateTime()))
4577  {
4578  const int reminder = (mReminderMinutes > 0) ? mReminderMinutes : 0; // only interested in reminders BEFORE the alarm
4579  mMainWorkTrigger = nextTrigger;
4580  mAllWorkTrigger = (type & KAEvent::OCCURRENCE_REPEAT) ? mMainWorkTrigger : mMainWorkTrigger.addMins(-reminder);
4581  return; // found a non-holiday occurrence
4582  }
4583  }
4584  mMainWorkTrigger = mAllWorkTrigger = DateTime();
4585  }
4586  }
4587  else if (mExcludeHolidays && mHolidays)
4588  {
4589  // Holidays are excluded.
4590  DateTime nextTrigger = mMainTrigger;
4591  KDateTime kdt;
4592  for (int i = 0; i < 20; ++i)
4593  {
4594  kdt = nextTrigger.effectiveKDateTime();
4595  kdt.setTime(QTime(23,59,59));
4596  const KAEvent::OccurType type = nextOccurrence(kdt, nextTrigger, KAEvent::RETURN_REPETITION);
4597  if (!nextTrigger.isValid())
4598  break;
4599  if (!mHolidays->isHoliday(nextTrigger.date()))
4600  {
4601  const int reminder = (mReminderMinutes > 0) ? mReminderMinutes : 0; // only interested in reminders BEFORE the alarm
4602  mMainWorkTrigger = nextTrigger;
4603  mAllWorkTrigger = (type & KAEvent::OCCURRENCE_REPEAT) ? mMainWorkTrigger : mMainWorkTrigger.addMins(-reminder);
4604  return; // found a non-holiday occurrence
4605  }
4606  }
4607  mMainWorkTrigger = mAllWorkTrigger = DateTime();
4608  }
4609  }
4610 }
4611 
4612 /******************************************************************************
4613 * Return the time of the next scheduled occurrence of the event during working
4614 * hours, for an alarm which is restricted to working hours.
4615 * On entry, 'nextTrigger' = the next recurrence or repetition (as returned by
4616 * mainDateTime(true) ).
4617 */
4618 void KAEventPrivate::calcNextWorkingTime(const DateTime& nextTrigger) const
4619 {
4620  kDebug() << "next=" << nextTrigger.kDateTime().dateTime();
4621  mMainWorkTrigger = mAllWorkTrigger = DateTime();
4622 
4623  for (int i = 0; ; ++i)
4624  {
4625  if (i >= 7)
4626  return; // no working days are defined
4627  if (mWorkDays.testBit(i))
4628  break;
4629  }
4630  const KARecurrence::Type recurType = checkRecur();
4631  KDateTime kdt = nextTrigger.effectiveKDateTime();
4632  const int reminder = (mReminderMinutes > 0) ? mReminderMinutes : 0; // only interested in reminders BEFORE the alarm
4633  // Check if it always falls on the same day(s) of the week.
4634  const RecurrenceRule* rrule = mRecurrence->defaultRRuleConst();
4635  if (!rrule)
4636  return; // no recurrence rule!
4637  unsigned allDaysMask = 0x7F; // mask bits for all days of week
4638  bool noWorkPos = false; // true if no recurrence day position is working day
4639  const QList<RecurrenceRule::WDayPos> pos = rrule->byDays();
4640  const int nDayPos = pos.count(); // number of day positions
4641  if (nDayPos)
4642  {
4643  noWorkPos = true;
4644  allDaysMask = 0;
4645  for (int i = 0; i < nDayPos; ++i)
4646  {
4647  const int day = pos[i].day() - 1; // Monday = 0
4648  if (mWorkDays.testBit(day))
4649  noWorkPos = false; // found a working day occurrence
4650  allDaysMask |= 1 << day;
4651  }
4652  if (noWorkPos && !mRepetition)
4653  return; // never occurs on a working day
4654  }
4655  DateTime newdt;
4656 
4657  if (mStartDateTime.isDateOnly())
4658  {
4659  // It's a date-only alarm.
4660  // Sub-repetitions also have to be date-only.
4661  const int repeatFreq = mRepetition.intervalDays();
4662  const bool weeklyRepeat = mRepetition && !(repeatFreq % 7);
4663  const Duration interval = mRecurrence->regularInterval();
4664  if ((interval && !(interval.asDays() % 7))
4665  || nDayPos == 1)
4666  {
4667  // It recurs on the same day each week
4668  if (!mRepetition || weeklyRepeat)
4669  return; // any repetitions are also weekly
4670 
4671  // It's a weekly recurrence with a non-weekly sub-repetition.
4672  // Check one cycle of repetitions for the next one that lands
4673  // on a working day.
4674  KDateTime dt(nextTrigger.kDateTime().addDays(1));
4675  dt.setTime(QTime(0,0,0));
4676  previousOccurrence(dt, newdt, false);
4677  if (!newdt.isValid())
4678  return; // this should never happen
4679  kdt = newdt.effectiveKDateTime();
4680  const int day = kdt.date().dayOfWeek() - 1; // Monday = 0
4681  for (int repeatNum = mNextRepeat + 1; ; ++repeatNum)
4682  {
4683  if (repeatNum > mRepetition.count())
4684  repeatNum = 0;
4685  if (repeatNum == mNextRepeat)
4686  break;
4687  if (!repeatNum)
4688  {
4689  nextOccurrence(newdt.kDateTime(), newdt, KAEvent::IGNORE_REPETITION);
4690  if (mWorkDays.testBit(day))
4691  {
4692  mMainWorkTrigger = newdt;
4693  mAllWorkTrigger = mMainWorkTrigger.addMins(-reminder);
4694  return;
4695  }
4696  kdt = newdt.effectiveKDateTime();
4697  }
4698  else
4699  {
4700  const int inc = repeatFreq * repeatNum;
4701  if (mWorkDays.testBit((day + inc) % 7))
4702  {
4703  kdt = kdt.addDays(inc);
4704  kdt.setDateOnly(true);
4705  mMainWorkTrigger = mAllWorkTrigger = kdt;
4706  return;
4707  }
4708  }
4709  }
4710  return;
4711  }
4712  if (!mRepetition || weeklyRepeat)
4713  {
4714  // It's a date-only alarm with either no sub-repetition or a
4715  // sub-repetition which always falls on the same day of the week
4716  // as the recurrence (if any).
4717  unsigned days = 0;
4718  for ( ; ; )
4719  {
4720  kdt.setTime(QTime(23,59,59));
4721  nextOccurrence(kdt, newdt, KAEvent::IGNORE_REPETITION);
4722  if (!newdt.isValid())
4723  return;
4724  kdt = newdt.effectiveKDateTime();
4725  const int day = kdt.date().dayOfWeek() - 1;
4726  if (mWorkDays.testBit(day))
4727  break; // found a working day occurrence
4728  // Prevent indefinite looping (which should never happen anyway)
4729  if ((days & allDaysMask) == allDaysMask)
4730  return; // found a recurrence on every possible day of the week!?!
4731  days |= 1 << day;
4732  }
4733  kdt.setDateOnly(true);
4734  mMainWorkTrigger = kdt;
4735  mAllWorkTrigger = kdt.addSecs(-60 * reminder);
4736  return;
4737  }
4738 
4739  // It's a date-only alarm which recurs on different days of the week,
4740  // as does the sub-repetition.
4741  // Find the previous recurrence (as opposed to sub-repetition)
4742  unsigned days = 1 << (kdt.date().dayOfWeek() - 1);
4743  KDateTime dt(nextTrigger.kDateTime().addDays(1));
4744  dt.setTime(QTime(0,0,0));
4745  previousOccurrence(dt, newdt, false);
4746  if (!newdt.isValid())
4747  return; // this should never happen
4748  kdt = newdt.effectiveKDateTime();
4749  int day = kdt.date().dayOfWeek() - 1; // Monday = 0
4750  for (int repeatNum = mNextRepeat; ; repeatNum = 0)
4751  {
4752  while (++repeatNum <= mRepetition.count())
4753  {
4754  const int inc = repeatFreq * repeatNum;
4755  if (mWorkDays.testBit((day + inc) % 7))
4756  {
4757  kdt = kdt.addDays(inc);
4758  kdt.setDateOnly(true);
4759  mMainWorkTrigger = mAllWorkTrigger = kdt;
4760  return;
4761  }
4762  if ((days & allDaysMask) == allDaysMask)
4763  return; // found an occurrence on every possible day of the week!?!
4764  days |= 1 << day;
4765  }
4766  nextOccurrence(kdt, newdt, KAEvent::IGNORE_REPETITION);
4767  if (!newdt.isValid())
4768  return;
4769  kdt = newdt.effectiveKDateTime();
4770  day = kdt.date().dayOfWeek() - 1;
4771  if (mWorkDays.testBit(day))
4772  {
4773  kdt.setDateOnly(true);
4774  mMainWorkTrigger = kdt;
4775  mAllWorkTrigger = kdt.addSecs(-60 * reminder);
4776  return;
4777  }
4778  if ((days & allDaysMask) == allDaysMask)
4779  return; // found an occurrence on every possible day of the week!?!
4780  days |= 1 << day;
4781  }
4782  return;
4783  }
4784 
4785  // It's a date-time alarm.
4786 
4787  /* Check whether the recurrence or sub-repetition occurs at the same time
4788  * every day. Note that because of seasonal time changes, a recurrence
4789  * defined in terms of minutes will vary its time of day even if its value
4790  * is a multiple of a day (24*60 minutes). Sub-repetitions are considered
4791  * to repeat at the same time of day regardless of time changes if they
4792  * are multiples of a day, which doesn't strictly conform to the iCalendar
4793  * format because this only allows their interval to be recorded in seconds.
4794  */
4795  const bool recurTimeVaries = (recurType == KARecurrence::MINUTELY);
4796  const bool repeatTimeVaries = (mRepetition && !mRepetition.isDaily());
4797 
4798  if (!recurTimeVaries && !repeatTimeVaries)
4799  {
4800  // The alarm always occurs at the same time of day.
4801  // Check whether it can ever occur during working hours.
4802  if (!mayOccurDailyDuringWork(kdt))
4803  return; // never occurs during working hours
4804 
4805  // Find the next working day it occurs on
4806  bool repetition = false;
4807  unsigned days = 0;
4808  for ( ; ; )
4809  {
4810  KAEvent::OccurType type = nextOccurrence(kdt, newdt, KAEvent::RETURN_REPETITION);
4811  if (!newdt.isValid())
4812  return;
4813  repetition = (type & KAEvent::OCCURRENCE_REPEAT);
4814  kdt = newdt.effectiveKDateTime();
4815  const int day = kdt.date().dayOfWeek() - 1;
4816  if (mWorkDays.testBit(day))
4817  break; // found a working day occurrence
4818  // Prevent indefinite looping (which should never happen anyway)
4819  if (!repetition)
4820  {
4821  if ((days & allDaysMask) == allDaysMask)
4822  return; // found a recurrence on every possible day of the week!?!
4823  days |= 1 << day;
4824  }
4825  }
4826  mMainWorkTrigger = nextTrigger;
4827  mMainWorkTrigger.setDate(kdt.date());
4828  mAllWorkTrigger = repetition ? mMainWorkTrigger : mMainWorkTrigger.addMins(-reminder);
4829  return;
4830  }
4831 
4832  // The alarm occurs at different times of day.
4833  // We may need to check for a full annual cycle of seasonal time changes, in
4834  // case it only occurs during working hours after a time change.
4835  KTimeZone tz = kdt.timeZone();
4836  if (tz.isValid() && tz.type() == "KSystemTimeZone")
4837  {
4838  // It's a system time zone, so fetch full transition information
4839  const KTimeZone ktz = KSystemTimeZones::readZone(tz.name());
4840  if (ktz.isValid())
4841  tz = ktz;
4842  }
4843  const QList<KTimeZone::Transition> tzTransitions = tz.transitions();
4844 
4845  if (recurTimeVaries)
4846  {
4847  /* The alarm recurs at regular clock intervals, at different times of day.
4848  * Note that for this type of recurrence, it's necessary to avoid the
4849  * performance overhead of Recurrence class calls since these can in the
4850  * worst case cause the program to hang for a significant length of time.
4851  * In this case, we can calculate the next recurrence by simply adding the
4852  * recurrence interval, since KAlarm offers no facility to regularly miss
4853  * recurrences. (But exception dates/times need to be taken into account.)
4854  */
4855  KDateTime kdtRecur;
4856  int repeatFreq = 0;
4857  int repeatNum = 0;
4858  if (mRepetition)
4859  {
4860  // It's a repetition inside a recurrence, each of which occurs
4861  // at different times of day (bearing in mind that the repetition
4862  // may occur at daily intervals after each recurrence).
4863  // Find the previous recurrence (as opposed to sub-repetition)
4864  repeatFreq = mRepetition.intervalSeconds();
4865  previousOccurrence(kdt.addSecs(1), newdt, false);
4866  if (!newdt.isValid())
4867  return; // this should never happen
4868  kdtRecur = newdt.effectiveKDateTime();
4869  repeatNum = kdtRecur.secsTo(kdt) / repeatFreq;
4870  kdt = kdtRecur.addSecs(repeatNum * repeatFreq);
4871  }
4872  else
4873  {
4874  // There is no sub-repetition.
4875  // (N.B. Sub-repetitions can't exist without a recurrence.)
4876  // Check until the original time wraps round, but ensure that
4877  // if there are seasonal time changes, that all other subsequent
4878  // time offsets within the next year are checked.
4879  // This does not guarantee to find the next working time,
4880  // particularly if there are exceptions, but it's a
4881  // reasonable try.
4882  kdtRecur = kdt;
4883  }
4884  QTime firstTime = kdtRecur.time();
4885  int firstOffset = kdtRecur.utcOffset();
4886  int currentOffset = firstOffset;
4887  int dayRecur = kdtRecur.date().dayOfWeek() - 1; // Monday = 0
4888  int firstDay = dayRecur;
4889  QDate finalDate;
4890  const bool subdaily = (repeatFreq < 24*3600);
4891 // int period = mRecurrence->frequency() % (24*60); // it is by definition a MINUTELY recurrence
4892 // int limit = (24*60 + period - 1) / period; // number of times until recurrence wraps round
4893  int transitionIndex = -1;
4894  for (int n = 0; n < 7*24*60; ++n)
4895  {
4896  if (mRepetition)
4897  {
4898  // Check the sub-repetitions for this recurrence
4899  for ( ; ; )
4900  {
4901  // Find the repeat count to the next start of the working day
4902  const int inc = subdaily ? nextWorkRepetition(kdt) : 1;
4903  repeatNum += inc;
4904  if (repeatNum > mRepetition.count())
4905  break;
4906  kdt = kdt.addSecs(inc * repeatFreq);
4907  const QTime t = kdt.time();
4908  if (t >= mWorkDayStart && t < mWorkDayEnd)
4909  {
4910  if (mWorkDays.testBit(kdt.date().dayOfWeek() - 1))
4911  {
4912  mMainWorkTrigger = mAllWorkTrigger = kdt;
4913  return;
4914  }
4915  }
4916  }
4917  repeatNum = 0;
4918  }
4919  nextOccurrence(kdtRecur, newdt, KAEvent::IGNORE_REPETITION);
4920  if (!newdt.isValid())
4921  return;
4922  kdtRecur = newdt.effectiveKDateTime();
4923  dayRecur = kdtRecur.date().dayOfWeek() - 1; // Monday = 0
4924  const QTime t = kdtRecur.time();
4925  if (t >= mWorkDayStart && t < mWorkDayEnd)
4926  {
4927  if (mWorkDays.testBit(dayRecur))
4928  {
4929  mMainWorkTrigger = kdtRecur;
4930  mAllWorkTrigger = kdtRecur.addSecs(-60 * reminder);
4931  return;
4932  }
4933  }
4934  if (kdtRecur.utcOffset() != currentOffset)
4935  currentOffset = kdtRecur.utcOffset();
4936  if (t == firstTime && dayRecur == firstDay && currentOffset == firstOffset)
4937  {
4938  // We've wrapped round to the starting day and time.
4939  // If there are seasonal time changes, check for up
4940  // to the next year in other time offsets in case the
4941  // alarm occurs inside working hours then.
4942  if (!finalDate.isValid())
4943  finalDate = kdtRecur.date();
4944  const int i = tz.transitionIndex(kdtRecur.toUtc().dateTime());
4945  if (i < 0)
4946  return;
4947  if (i > transitionIndex)
4948  transitionIndex = i;
4949  if (++transitionIndex >= static_cast<int>(tzTransitions.count()))
4950  return;
4951  previousOccurrence(KDateTime(tzTransitions[transitionIndex].time(), KDateTime::UTC), newdt, KAEvent::IGNORE_REPETITION);
4952  kdtRecur = newdt.effectiveKDateTime();
4953  if (finalDate.daysTo(kdtRecur.date()) > 365)
4954  return;
4955  firstTime = kdtRecur.time();
4956  firstOffset = kdtRecur.utcOffset();
4957  currentOffset = firstOffset;
4958  firstDay = kdtRecur.date().dayOfWeek() - 1;
4959  }
4960  kdt = kdtRecur;
4961  }
4962 //kDebug()<<"-----exit loop: count="<<limit<<endl;
4963  return; // too many iterations
4964  }
4965 
4966  if (repeatTimeVaries)
4967  {
4968  /* There's a sub-repetition which occurs at different times of
4969  * day, inside a recurrence which occurs at the same time of day.
4970  * We potentially need to check recurrences starting on each day.
4971  * Then, it is still possible that a working time sub-repetition
4972  * could occur immediately after a seasonal time change.
4973  */
4974  // Find the previous recurrence (as opposed to sub-repetition)
4975  const int repeatFreq = mRepetition.intervalSeconds();
4976  previousOccurrence(kdt.addSecs(1), newdt, false);
4977  if (!newdt.isValid())
4978  return; // this should never happen
4979  KDateTime kdtRecur = newdt.effectiveKDateTime();
4980  const bool recurDuringWork = (kdtRecur.time() >= mWorkDayStart && kdtRecur.time() < mWorkDayEnd);
4981 
4982  // Use the previous recurrence as a base for checking whether
4983  // our tests have wrapped round to the same time/day of week.
4984  const bool subdaily = (repeatFreq < 24*3600);
4985  unsigned days = 0;
4986  bool checkTimeChangeOnly = false;
4987  int transitionIndex = -1;
4988  for (int limit = 10; --limit >= 0; )
4989  {
4990  // Check the next seasonal time change (for an arbitrary 10 times,
4991  // even though that might not guarantee the correct result)
4992  QDate dateRecur = kdtRecur.date();
4993  int dayRecur = dateRecur.dayOfWeek() - 1; // Monday = 0
4994  int repeatNum = kdtRecur.secsTo(kdt) / repeatFreq;
4995  kdt = kdtRecur.addSecs(repeatNum * repeatFreq);
4996 
4997  // Find the next recurrence, which sets the limit on possible sub-repetitions.
4998  // Note that for a monthly recurrence, for example, a sub-repetition could
4999  // be defined which is longer than the recurrence interval in short months.
5000  // In these cases, the sub-repetition is truncated by the following
5001  // recurrence.
5002  nextOccurrence(kdtRecur, newdt, KAEvent::IGNORE_REPETITION);
5003  KDateTime kdtNextRecur = newdt.effectiveKDateTime();
5004 
5005  int repeatsToCheck = mRepetition.count();
5006  int repeatsDuringWork = 0; // 0=unknown, 1=does, -1=never
5007  for ( ; ; )
5008  {
5009  // Check the sub-repetitions for this recurrence
5010  if (repeatsDuringWork >= 0)
5011  {
5012  for ( ; ; )
5013  {
5014  // Find the repeat count to the next start of the working day
5015  int inc = subdaily ? nextWorkRepetition(kdt) : 1;
5016  repeatNum += inc;
5017  const bool pastEnd = (repeatNum > mRepetition.count());
5018  if (pastEnd)
5019  inc -= repeatNum - mRepetition.count();
5020  repeatsToCheck -= inc;
5021  kdt = kdt.addSecs(inc * repeatFreq);
5022  if (kdtNextRecur.isValid() && kdt >= kdtNextRecur)
5023  {
5024  // This sub-repetition is past the next recurrence,
5025  // so start the check again from the next recurrence.
5026  repeatsToCheck = mRepetition.count();
5027  break;
5028  }
5029  if (pastEnd)
5030  break;
5031  const QTime t = kdt.time();
5032  if (t >= mWorkDayStart && t < mWorkDayEnd)
5033  {
5034  if (mWorkDays.testBit(kdt.date().dayOfWeek() - 1))
5035  {
5036  mMainWorkTrigger = mAllWorkTrigger = kdt;
5037  return;
5038  }
5039  repeatsDuringWork = 1;
5040  }
5041  else if (!repeatsDuringWork && repeatsToCheck <= 0)
5042  {
5043  // Sub-repetitions never occur during working hours
5044  repeatsDuringWork = -1;
5045  break;
5046  }
5047  }
5048  }
5049  repeatNum = 0;
5050  if (repeatsDuringWork < 0 && !recurDuringWork)
5051  break; // it never occurs during working hours
5052 
5053  // Check the next recurrence
5054  if (!kdtNextRecur.isValid())
5055  return;
5056  if (checkTimeChangeOnly || (days & allDaysMask) == allDaysMask)
5057  break; // found a recurrence on every possible day of the week!?!
5058  kdtRecur = kdtNextRecur;
5059  nextOccurrence(kdtRecur, newdt, KAEvent::IGNORE_REPETITION);
5060  kdtNextRecur = newdt.effectiveKDateTime();
5061  dateRecur = kdtRecur.date();
5062  dayRecur = dateRecur.dayOfWeek() - 1;
5063  if (recurDuringWork && mWorkDays.testBit(dayRecur))
5064  {
5065  mMainWorkTrigger = kdtRecur;
5066  mAllWorkTrigger = kdtRecur.addSecs(-60 * reminder);
5067  return;
5068  }
5069  days |= 1 << dayRecur;
5070  kdt = kdtRecur;
5071  }
5072 
5073  // Find the next recurrence before a seasonal time change,
5074  // and ensure the time change is after the last one processed.
5075  checkTimeChangeOnly = true;
5076  const int i = tz.transitionIndex(kdtRecur.toUtc().dateTime());
5077  if (i < 0)
5078  return;
5079  if (i > transitionIndex)
5080  transitionIndex = i;
5081  if (++transitionIndex >= static_cast<int>(tzTransitions.count()))
5082  return;
5083  kdt = KDateTime(tzTransitions[transitionIndex].time(), KDateTime::UTC);
5084  previousOccurrence(kdt, newdt, KAEvent::IGNORE_REPETITION);
5085  kdtRecur = newdt.effectiveKDateTime();
5086  }
5087  return; // not found - give up
5088  }
5089 }
5090 
5091 /******************************************************************************
5092 * Find the repeat count to the next start of a working day.
5093 * This allows for possible daylight saving time changes during the repetition.
5094 * Use for repetitions which occur at different times of day.
5095 */
5096 int KAEventPrivate::nextWorkRepetition(const KDateTime& pre) const
5097 {
5098  KDateTime nextWork(pre);
5099  if (pre.time() < mWorkDayStart)
5100  nextWork.setTime(mWorkDayStart);
5101  else
5102  {
5103  const int preDay = pre.date().dayOfWeek() - 1; // Monday = 0
5104  for (int n = 1; ; ++n)
5105  {
5106  if (n >= 7)
5107  return mRepetition.count() + 1; // should never happen
5108  if (mWorkDays.testBit((preDay + n) % 7))
5109  {
5110  nextWork = nextWork.addDays(n);
5111  nextWork.setTime(mWorkDayStart);
5112  break;
5113  }
5114  }
5115  }
5116  return (pre.secsTo(nextWork) - 1) / mRepetition.intervalSeconds() + 1;
5117 }
5118 
5119 /******************************************************************************
5120 * Check whether an alarm which recurs at the same time of day can possibly
5121 * occur during working hours.
5122 * This does not determine whether it actually does, but rather whether it could
5123 * potentially given enough repetitions.
5124 * Reply = false if it can never occur during working hours, true if it might.
5125 */
5126 bool KAEventPrivate::mayOccurDailyDuringWork(const KDateTime& kdt) const
5127 {
5128  if (!kdt.isDateOnly()
5129  && (kdt.time() < mWorkDayStart || kdt.time() >= mWorkDayEnd))
5130  return false; // its time is outside working hours
5131  // Check if it always occurs on the same day of the week
5132  const Duration interval = mRecurrence->regularInterval();
5133  if (interval && interval.isDaily() && !(interval.asDays() % 7))
5134  {
5135  // It recurs weekly
5136  if (!mRepetition || (mRepetition.isDaily() && !(mRepetition.intervalDays() % 7)))
5137  return false; // any repetitions are also weekly
5138  // Repetitions are daily. Check if any occur on working days
5139  // by checking the first recurrence and up to 6 repetitions.
5140  int day = mRecurrence->startDateTime().date().dayOfWeek() - 1; // Monday = 0
5141  const int repeatDays = mRepetition.intervalDays();
5142  const int maxRepeat = (mRepetition.count() < 6) ? mRepetition.count() : 6;
5143  for (int i = 0; !mWorkDays.testBit(day); ++i, day = (day + repeatDays) % 7)
5144  {
5145  if (i >= maxRepeat)
5146  return false; // no working day occurrences
5147  }
5148  }
5149  return true;
5150 }
5151 
5152 /******************************************************************************
5153 * Set the specified alarm to be an audio alarm with the given file name.
5154 */
5155 #ifndef KALARMCAL_USE_KRESOURCES
5156 void KAEventPrivate::setAudioAlarm(const Alarm::Ptr& alarm) const
5157 #else
5158 void KAEventPrivate::setAudioAlarm(Alarm* alarm) const
5159 #endif
5160 {
5161  alarm->setAudioAlarm(mAudioFile); // empty for a beep or for speaking
5162  if (mSoundVolume >= 0)
5163  alarm->setCustomProperty(KACalendar::APPNAME, VOLUME_PROPERTY,
5164  QString::fromLatin1("%1;%2;%3;%4").arg(QString::number(mSoundVolume, 'f', 2))
5165  .arg(QString::number(mFadeVolume, 'f', 2))
5166  .arg(mFadeSeconds));
5167 }
5168 
5169 /******************************************************************************
5170 * Get the date/time of the next recurrence of the event, after the specified
5171 * date/time.
5172 * 'result' = date/time of next occurrence, or invalid date/time if none.
5173 */
5174 KAEvent::OccurType KAEventPrivate::nextRecurrence(const KDateTime& preDateTime, DateTime& result) const
5175 {
5176  const KDateTime recurStart = mRecurrence->startDateTime();
5177  KDateTime pre = preDateTime.toTimeSpec(mStartDateTime.timeSpec());
5178  if (mStartDateTime.isDateOnly() && !pre.isDateOnly() && pre.time() < DateTime::startOfDay())
5179  {
5180  pre = pre.addDays(-1); // today's recurrence (if today recurs) is still to come
5181  pre.setTime(DateTime::startOfDay());
5182  }
5183  const KDateTime dt = mRecurrence->getNextDateTime(pre);
5184  result = dt;
5185  result.setDateOnly(mStartDateTime.isDateOnly());
5186  if (!dt.isValid())
5187  return KAEvent::NO_OCCURRENCE;
5188  if (dt == recurStart)
5189  return KAEvent::FIRST_OR_ONLY_OCCURRENCE;
5190  if (mRecurrence->duration() >= 0 && dt == mRecurrence->endDateTime())
5191  return KAEvent::LAST_RECURRENCE;
5192  return result.isDateOnly() ? KAEvent::RECURRENCE_DATE : KAEvent::RECURRENCE_DATE_TIME;
5193 }
5194 
5195 /******************************************************************************
5196 * Validate the event's recurrence data, correcting any inconsistencies (which
5197 * should never occur!).
5198 * Reply = recurrence period type.
5199 */
5200 KARecurrence::Type KAEventPrivate::checkRecur() const
5201 {
5202  if (mRecurrence)
5203  {
5204  KARecurrence::Type type = mRecurrence->type();
5205  switch (type)
5206  {
5207  case KARecurrence::MINUTELY: // hourly
5208  case KARecurrence::DAILY: // daily
5209  case KARecurrence::WEEKLY: // weekly on multiple days of week
5210  case KARecurrence::MONTHLY_DAY: // monthly on multiple dates in month
5211  case KARecurrence::MONTHLY_POS: // monthly on multiple nth day of week
5212  case KARecurrence::ANNUAL_DATE: // annually on multiple months (day of month = start date)
5213  case KARecurrence::ANNUAL_POS: // annually on multiple nth day of week in multiple months
5214  return type;
5215  default:
5216  if (mRecurrence)
5217  const_cast<KAEventPrivate*>(this)->clearRecur(); // this shouldn't ever be necessary!!
5218  break;
5219  }
5220  }
5221  if (mRepetition) // can't have a repetition without a recurrence
5222  const_cast<KAEventPrivate*>(this)->clearRecur(); // this shouldn't ever be necessary!!
5223  return KARecurrence::NO_RECUR;
5224 }
5225 
5226 /******************************************************************************
5227 * If the calendar was written by a previous version of KAlarm, do any
5228 * necessary format conversions on the events to ensure that when the calendar
5229 * is saved, no information is lost or corrupted.
5230 * Reply = true if any conversions were done.
5231 */
5232 #ifndef KALARMCAL_USE_KRESOURCES
5233 bool KAEvent::convertKCalEvents(const Calendar::Ptr& calendar, int calendarVersion)
5234 #else
5235 bool KAEvent::convertKCalEvents(CalendarLocal& calendar, int calendarVersion)
5236 #endif
5237 {
5238  // KAlarm pre-0.9 codes held in the alarm's DESCRIPTION property
5239  static const QChar SEPARATOR = QLatin1Char(';');
5240  static const QChar LATE_CANCEL_CODE = QLatin1Char('C');
5241  static const QChar AT_LOGIN_CODE = QLatin1Char('L'); // subsidiary alarm at every login
5242  static const QChar DEFERRAL_CODE = QLatin1Char('D'); // extra deferred alarm
5243  static const QString TEXT_PREFIX = QLatin1String("TEXT:");
5244  static const QString FILE_PREFIX = QLatin1String("FILE:");
5245  static const QString COMMAND_PREFIX = QLatin1String("CMD:");
5246 
5247  // KAlarm pre-0.9.2 codes held in the event's CATEGORY property
5248  static const QString BEEP_CATEGORY = QLatin1String("BEEP");
5249 
5250  // KAlarm pre-1.1.1 LATECANCEL category with no parameter
5251  static const QString LATE_CANCEL_CAT = QLatin1String("LATECANCEL");
5252 
5253  // KAlarm pre-1.3.0 TMPLDEFTIME category with no parameter
5254  static const QString TEMPL_DEF_TIME_CAT = QLatin1String("TMPLDEFTIME");
5255 
5256  // KAlarm pre-1.3.1 XTERM category
5257  static const QString EXEC_IN_XTERM_CAT = QLatin1String("XTERM");
5258 
5259  // KAlarm pre-1.9.0 categories
5260  static const QString DATE_ONLY_CATEGORY = QLatin1String("DATE");
5261  static const QString EMAIL_BCC_CATEGORY = QLatin1String("BCC");
5262  static const QString CONFIRM_ACK_CATEGORY = QLatin1String("ACKCONF");
5263  static const QString KORGANIZER_CATEGORY = QLatin1String("KORG");
5264  static const QString DEFER_CATEGORY = QLatin1String("DEFER;");
5265  static const QString ARCHIVE_CATEGORY = QLatin1String("SAVE");
5266  static const QString ARCHIVE_CATEGORIES = QLatin1String("SAVE:");
5267  static const QString LATE_CANCEL_CATEGORY = QLatin1String("LATECANCEL;");
5268  static const QString AUTO_CLOSE_CATEGORY = QLatin1String("LATECLOSE;");
5269  static const QString TEMPL_AFTER_TIME_CATEGORY = QLatin1String("TMPLAFTTIME;");
5270  static const QString KMAIL_SERNUM_CATEGORY = QLatin1String("KMAIL:");
5271  static const QString LOG_CATEGORY = QLatin1String("LOG:");
5272 
5273  // KAlarm pre-1.5.0/1.9.9 properties
5274  static const QByteArray KMAIL_ID_PROPERTY("KMAILID"); // X-KDE-KALARM-KMAILID property
5275 
5276  // KAlarm pre-2.6.0 properties
5277  static const QByteArray ARCHIVE_PROPERTY("ARCHIVE"); // X-KDE-KALARM-ARCHIVE property
5278  static const QString ARCHIVE_REMINDER_ONCE_TYPE = QLatin1String("ONCE");
5279  static const QString REMINDER_ONCE_TYPE = QLatin1String("REMINDER_ONCE");
5280  static const QByteArray EMAIL_ID_PROPERTY("EMAILID"); // X-KDE-KALARM-EMAILID property
5281  static const QByteArray SPEAK_PROPERTY("SPEAK"); // X-KDE-KALARM-SPEAK property
5282  static const QByteArray CANCEL_ON_ERROR_PROPERTY("ERRCANCEL");// X-KDE-KALARM-ERRCANCEL property
5283  static const QByteArray DONT_SHOW_ERROR_PROPERTY("ERRNOSHOW");// X-KDE-KALARM-ERRNOSHOW property
5284 
5285  bool adjustSummerTime = false;
5286  if (calendarVersion == -Version(0,5,7))
5287  {
5288  // The calendar file was written by the KDE 3.0.0 version of KAlarm 0.5.7.
5289  // Summer time was ignored when converting to UTC.
5290  calendarVersion = -calendarVersion;
5291  adjustSummerTime = true;
5292  }
5293 
5294  if (calendarVersion >= currentCalendarVersion())
5295  return false;
5296 
5297  kDebug() << "Adjusting version" << calendarVersion;
5298  const bool pre_0_7 = (calendarVersion < Version(0,7,0));
5299  const bool pre_0_9 = (calendarVersion < Version(0,9,0));
5300  const bool pre_0_9_2 = (calendarVersion < Version(0,9,2));
5301  const bool pre_1_1_1 = (calendarVersion < Version(1,1,1));
5302  const bool pre_1_2_1 = (calendarVersion < Version(1,2,1));
5303  const bool pre_1_3_0 = (calendarVersion < Version(1,3,0));
5304  const bool pre_1_3_1 = (calendarVersion < Version(1,3,1));
5305  const bool pre_1_4_14 = (calendarVersion < Version(1,4,14));
5306  const bool pre_1_5_0 = (calendarVersion < Version(1,5,0));
5307  const bool pre_1_9_0 = (calendarVersion < Version(1,9,0));
5308  const bool pre_1_9_2 = (calendarVersion < Version(1,9,2));
5309  const bool pre_1_9_7 = (calendarVersion < Version(1,9,7));
5310  const bool pre_1_9_9 = (calendarVersion < Version(1,9,9));
5311  const bool pre_1_9_10 = (calendarVersion < Version(1,9,10));
5312  const bool pre_2_2_9 = (calendarVersion < Version(2,2,9));
5313  const bool pre_2_3_0 = (calendarVersion < Version(2,3,0));
5314  const bool pre_2_3_2 = (calendarVersion < Version(2,3,2));
5315  const bool pre_2_7_0 = (calendarVersion < Version(2,7,0));
5316  Q_ASSERT(currentCalendarVersion() == Version(2,7,0));
5317 
5318  KTimeZone localZone;
5319  if (pre_1_9_2)
5320  localZone = KSystemTimeZones::local();
5321 
5322  bool converted = false;
5323 #ifndef KALARMCAL_USE_KRESOURCES
5324  const Event::List events = calendar->rawEvents();
5325 #else
5326  const Event::List events = calendar.rawEvents();
5327 #endif
5328  for (int ei = 0, eend = events.count(); ei < eend; ++ei)
5329  {
5330 #ifndef KALARMCAL_USE_KRESOURCES
5331  Event::Ptr event = events[ei];
5332 #else
5333  Event* event = events[ei];
5334 #endif
5335  const Alarm::List alarms = event->alarms();
5336  if (alarms.isEmpty())
5337  continue; // KAlarm isn't interested in events without alarms
5338  event->startUpdates(); // prevent multiple update notifications
5339  const bool readOnly = event->isReadOnly();
5340  if (readOnly)
5341  event->setReadOnly(false);
5342  QStringList cats = event->categories();
5343  bool addLateCancel = false;
5344  QStringList flags;
5345 
5346  if (pre_0_7 && event->allDay())
5347  {
5348  // It's a KAlarm pre-0.7 calendar file.
5349  // Ensure that when the calendar is saved, the alarm time isn't lost.
5350  event->setAllDay(false);
5351  }
5352 
5353  if (pre_0_9)
5354  {
5355  /*
5356  * It's a KAlarm pre-0.9 calendar file.
5357  * All alarms were of type DISPLAY. Instead of the X-KDE-KALARM-TYPE
5358  * alarm property, characteristics were stored as a prefix to the
5359  * alarm DESCRIPTION property, as follows:
5360  * SEQNO;[FLAGS];TYPE:TEXT
5361  * where
5362  * SEQNO = sequence number of alarm within the event
5363  * FLAGS = C for late-cancel, L for repeat-at-login, D for deferral
5364  * TYPE = TEXT or FILE or CMD
5365  * TEXT = message text, file name/URL or command
5366  */
5367  for (int ai = 0, aend = alarms.count(); ai < aend; ++ai)
5368  {
5369 #ifndef KALARMCAL_USE_KRESOURCES
5370  Alarm::Ptr alarm = alarms[ai];
5371 #else
5372  Alarm* alarm = alarms[ai];
5373 #endif
5374  bool atLogin = false;
5375  bool deferral = false;
5376  bool lateCancel = false;
5377  KAAlarm::Action action = KAAlarm::MESSAGE;
5378  const QString txt = alarm->text();
5379  const int length = txt.length();
5380  int i = 0;
5381  if (txt[0].isDigit())
5382  {
5383  while (++i < length && txt[i].isDigit()) ;
5384  if (i < length && txt[i++] == SEPARATOR)
5385  {
5386  while (i < length)
5387  {
5388  const QChar ch = txt[i++];
5389  if (ch == SEPARATOR)
5390  break;
5391  if (ch == LATE_CANCEL_CODE)
5392  lateCancel = true;
5393  else if (ch == AT_LOGIN_CODE)
5394  atLogin = true;
5395  else if (ch == DEFERRAL_CODE)
5396  deferral = true;
5397  }
5398  }
5399  else
5400  i = 0; // invalid prefix
5401  }
5402  if (txt.indexOf(TEXT_PREFIX, i) == i)
5403  i += TEXT_PREFIX.length();
5404  else if (txt.indexOf(FILE_PREFIX, i) == i)
5405  {
5406  action = KAAlarm::FILE;
5407  i += FILE_PREFIX.length();
5408  }
5409  else if (txt.indexOf(COMMAND_PREFIX, i) == i)
5410  {
5411  action = KAAlarm::COMMAND;
5412  i += COMMAND_PREFIX.length();
5413  }
5414  else
5415  i = 0;
5416  const QString altxt = txt.mid(i);
5417 
5418  QStringList types;
5419  switch (action)
5420  {
5421  case KAAlarm::FILE:
5422  types += KAEventPrivate::FILE_TYPE;
5423  // fall through to MESSAGE
5424  case KAAlarm::MESSAGE:
5425  alarm->setDisplayAlarm(altxt);
5426  break;
5427  case KAAlarm::COMMAND:
5428  setProcedureAlarm(alarm, altxt);
5429  break;
5430  case KAAlarm::EMAIL: // email alarms were introduced in KAlarm 0.9
5431  case KAAlarm::AUDIO: // audio alarms (with no display) were introduced in KAlarm 2.3.2
5432  break;
5433  }
5434  if (atLogin)
5435  {
5436  types += KAEventPrivate::AT_LOGIN_TYPE;
5437  lateCancel = false;
5438  }
5439  else if (deferral)
5440  types += KAEventPrivate::TIME_DEFERRAL_TYPE;
5441  if (lateCancel)
5442  addLateCancel = true;
5443  if (types.count() > 0)
5444  alarm->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::TYPE_PROPERTY, types.join(QLatin1String(",")));
5445 
5446  if (pre_0_7 && alarm->repeatCount() > 0 && alarm->snoozeTime().value() > 0)
5447  {
5448  // It's a KAlarm pre-0.7 calendar file.
5449  // Minutely recurrences were stored differently.
5450  Recurrence* recur = event->recurrence();
5451  if (recur && recur->recurs())
5452  {
5453  recur->setMinutely(alarm->snoozeTime().asSeconds() / 60);
5454  recur->setDuration(alarm->repeatCount() + 1);
5455  alarm->setRepeatCount(0);
5456  alarm->setSnoozeTime(0);
5457  }
5458  }
5459 
5460  if (adjustSummerTime)
5461  {
5462  // The calendar file was written by the KDE 3.0.0 version of KAlarm 0.5.7.
5463  // Summer time was ignored when converting to UTC.
5464  KDateTime dt = alarm->time();
5465  const time_t t = dt.toTime_t();
5466  const struct tm* dtm = localtime(&t);
5467  if (dtm->tm_isdst)
5468  {
5469  dt = dt.addSecs(-3600);
5470  alarm->setTime(dt);
5471  }
5472  }
5473  }
5474  }
5475 
5476  if (pre_0_9_2)
5477  {
5478  /*
5479  * It's a KAlarm pre-0.9.2 calendar file.
5480  * For the archive calendar, set the CREATED time to the DTEND value.
5481  * Convert date-only DTSTART to date/time, and add category "DATE".
5482  * Set the DTEND time to the DTSTART time.
5483  * Convert all alarm times to DTSTART offsets.
5484  * For display alarms, convert the first unlabelled category to an
5485  * X-KDE-KALARM-FONTCOLOUR property.
5486  * Convert BEEP category into an audio alarm with no audio file.
5487  */
5488  if (CalEvent::status(event) == CalEvent::ARCHIVED)
5489  event->setCreated(event->dtEnd());
5490  KDateTime start = event->dtStart();
5491  if (event->allDay())
5492  {
5493  event->setAllDay(false);
5494  start.setTime(QTime(0, 0));
5495  flags += KAEventPrivate::DATE_ONLY_FLAG;
5496  }
5497  event->setDtEnd(KDateTime());
5498 
5499  for (int ai = 0, aend = alarms.count(); ai < aend; ++ai)
5500  {
5501 #ifndef KALARMCAL_USE_KRESOURCES
5502  Alarm::Ptr alarm = alarms[ai];
5503 #else
5504  Alarm* alarm = alarms[ai];
5505 #endif
5506  alarm->setStartOffset(start.secsTo(alarm->time()));
5507  }
5508 
5509  if (!cats.isEmpty())
5510  {
5511  for (int ai = 0, aend = alarms.count(); ai < aend; ++ai)
5512  {
5513 #ifndef KALARMCAL_USE_KRESOURCES
5514  Alarm::Ptr alarm = alarms[ai];
5515 #else
5516  Alarm* alarm = alarms[ai];
5517 #endif
5518  if (alarm->type() == Alarm::Display)
5519  alarm->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FONT_COLOUR_PROPERTY,
5520  QString::fromLatin1("%1;;").arg(cats.at(0)));
5521  }
5522  cats.removeAt(0);
5523  }
5524 
5525  for (int i = 0, end = cats.count(); i < end; ++i)
5526  {
5527  if (cats.at(i) == BEEP_CATEGORY)
5528  {
5529  cats.removeAt(i);
5530 
5531 #ifndef KALARMCAL_USE_KRESOURCES
5532  Alarm::Ptr alarm = event->newAlarm();
5533 #else
5534  Alarm* alarm = event->newAlarm();
5535 #endif
5536  alarm->setEnabled(true);
5537  alarm->setAudioAlarm();
5538  KDateTime dt = event->dtStart(); // default
5539 
5540  // Parse and order the alarms to know which one's date/time to use
5541  KAEventPrivate::AlarmMap alarmMap;
5542  KAEventPrivate::readAlarms(event, &alarmMap);
5543  KAEventPrivate::AlarmMap::ConstIterator it = alarmMap.constBegin();
5544  if (it != alarmMap.constEnd())
5545  {
5546  dt = it.value().alarm->time();
5547  break;
5548  }
5549  alarm->setStartOffset(start.secsTo(dt));
5550  break;
5551  }
5552  }
5553  }
5554 
5555  if (pre_1_1_1)
5556  {
5557  /*
5558  * It's a KAlarm pre-1.1.1 calendar file.
5559  * Convert simple LATECANCEL category to LATECANCEL:n where n = minutes late.
5560  */
5561  int i;
5562  while ((i = cats.indexOf(LATE_CANCEL_CAT)) >= 0)
5563  {
5564  cats.removeAt(i);
5565  addLateCancel = true;
5566  }
5567  }
5568 
5569  if (pre_1_2_1)
5570  {
5571  /*
5572  * It's a KAlarm pre-1.2.1 calendar file.
5573  * Convert email display alarms from translated to untranslated header prefixes.
5574  */
5575  for (int ai = 0, aend = alarms.count(); ai < aend; ++ai)
5576  {
5577 #ifndef KALARMCAL_USE_KRESOURCES
5578  Alarm::Ptr alarm = alarms[ai];
5579 #else
5580  Alarm* alarm = alarms[ai];
5581 #endif
5582  if (alarm->type() == Alarm::Display)
5583  {
5584  const QString oldtext = alarm->text();
5585  const QString newtext = AlarmText::toCalendarText(oldtext);
5586  if (oldtext != newtext)
5587  alarm->setDisplayAlarm(newtext);
5588  }
5589  }
5590  }
5591 
5592  if (pre_1_3_0)
5593  {
5594  /*
5595  * It's a KAlarm pre-1.3.0 calendar file.
5596  * Convert simple TMPLDEFTIME category to TMPLAFTTIME:n where n = minutes after.
5597  */
5598  int i;
5599  while ((i = cats.indexOf(TEMPL_DEF_TIME_CAT)) >= 0)
5600  {
5601  cats.removeAt(i);
5602  (flags += KAEventPrivate::TEMPL_AFTER_TIME_FLAG) += QLatin1String("0");
5603  }
5604  }
5605 
5606  if (pre_1_3_1)
5607  {
5608  /*
5609  * It's a KAlarm pre-1.3.1 calendar file.
5610  * Convert simple XTERM category to LOG:xterm:
5611  */
5612  int i;
5613  while ((i = cats.indexOf(EXEC_IN_XTERM_CAT)) >= 0)
5614  {
5615  cats.removeAt(i);
5616  event->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::LOG_PROPERTY, KAEventPrivate::xtermURL);
5617  }
5618  }
5619 
5620  if (pre_1_9_0)
5621  {
5622  /*
5623  * It's a KAlarm pre-1.9 calendar file.
5624  * Add the X-KDE-KALARM-STATUS custom property.
5625  * Convert KAlarm categories to custom fields.
5626  */
5627  CalEvent::setStatus(event, CalEvent::status(event));
5628  for (int i = 0; i < cats.count(); )
5629  {
5630  const QString cat = cats.at(i);
5631  if (cat == DATE_ONLY_CATEGORY)
5632  flags += KAEventPrivate::DATE_ONLY_FLAG;
5633  else if (cat == CONFIRM_ACK_CATEGORY)
5634  flags += KAEventPrivate::CONFIRM_ACK_FLAG;
5635  else if (cat == EMAIL_BCC_CATEGORY)
5636  flags += KAEventPrivate::EMAIL_BCC_FLAG;
5637  else if (cat == KORGANIZER_CATEGORY)
5638  flags += KAEventPrivate::KORGANIZER_FLAG;
5639  else if (cat.startsWith(DEFER_CATEGORY))
5640  (flags += KAEventPrivate::DEFER_FLAG) += cat.mid(DEFER_CATEGORY.length());
5641  else if (cat.startsWith(TEMPL_AFTER_TIME_CATEGORY))
5642  (flags += KAEventPrivate::TEMPL_AFTER_TIME_FLAG) += cat.mid(TEMPL_AFTER_TIME_CATEGORY.length());
5643  else if (cat.startsWith(LATE_CANCEL_CATEGORY))
5644  (flags += KAEventPrivate::LATE_CANCEL_FLAG) += cat.mid(LATE_CANCEL_CATEGORY.length());
5645  else if (cat.startsWith(AUTO_CLOSE_CATEGORY))
5646  (flags += KAEventPrivate::AUTO_CLOSE_FLAG) += cat.mid(AUTO_CLOSE_CATEGORY.length());
5647  else if (cat.startsWith(KMAIL_SERNUM_CATEGORY))
5648  (flags += KAEventPrivate::KMAIL_SERNUM_FLAG) += cat.mid(KMAIL_SERNUM_CATEGORY.length());
5649  else if (cat == ARCHIVE_CATEGORY)
5650  event->setCustomProperty(KACalendar::APPNAME, ARCHIVE_PROPERTY, QLatin1String("0"));
5651  else if (cat.startsWith(ARCHIVE_CATEGORIES))
5652  event->setCustomProperty(KACalendar::APPNAME, ARCHIVE_PROPERTY, cat.mid(ARCHIVE_CATEGORIES.length()));
5653  else if (cat.startsWith(LOG_CATEGORY))
5654  event->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::LOG_PROPERTY, cat.mid(LOG_CATEGORY.length()));
5655  else
5656  {
5657  ++i; // Not a KAlarm category, so leave it
5658  continue;
5659  }
5660  cats.removeAt(i);
5661  }
5662  }
5663 
5664  if (pre_1_9_2)
5665  {
5666  /*
5667  * It's a KAlarm pre-1.9.2 calendar file.
5668  * Convert from clock time to the local system time zone.
5669  */
5670  event->shiftTimes(KDateTime::ClockTime, localZone);
5671  converted = true;
5672  }
5673 
5674  if (addLateCancel)
5675  (flags += KAEventPrivate::LATE_CANCEL_FLAG) += QLatin1String("1");
5676  if (!flags.isEmpty())
5677  event->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY, flags.join(KAEventPrivate::SC));
5678  event->setCategories(cats);
5679 
5680  if ((pre_1_4_14 || (pre_1_9_7 && !pre_1_9_0))
5681  && event->recurrence() && event->recurrence()->recurs())
5682  {
5683  /*
5684  * It's a KAlarm pre-1.4.14 or KAlarm 1.9 series pre-1.9.7 calendar file.
5685  * For recurring events, convert the main alarm offset to an absolute
5686  * time in the X-KDE-KALARM-NEXTRECUR property, and set main alarm
5687  * offsets to zero, and convert deferral alarm offsets to be relative to
5688  * the next recurrence.
5689  */
5690  const QStringList flags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, QString::SkipEmptyParts);
5691  const bool dateOnly = flags.contains(KAEventPrivate::DATE_ONLY_FLAG);
5692  KDateTime startDateTime = event->dtStart();
5693  if (dateOnly)
5694  startDateTime.setDateOnly(true);
5695  // Convert the main alarm and get the next main trigger time from it
5696  KDateTime nextMainDateTime;
5697  bool mainExpired = true;
5698  for (int i = 0, alend = alarms.count(); i < alend; ++i)
5699  {
5700 #ifndef KALARMCAL_USE_KRESOURCES
5701  Alarm::Ptr alarm = alarms[i];
5702 #else
5703  Alarm* alarm = alarms[i];
5704 #endif
5705  if (!alarm->hasStartOffset())
5706  continue;
5707  // Find whether the alarm triggers at the same time as the main
5708  // alarm, in which case its offset needs to be set to 0. The
5709  // following trigger with the main alarm:
5710  // - Additional audio alarm
5711  // - PRE_ACTION_TYPE
5712  // - POST_ACTION_TYPE
5713  // - DISPLAYING_TYPE
5714  bool mainAlarm = true;
5715  QString property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::TYPE_PROPERTY);
5716  const QStringList types = property.split(QLatin1Char(','), QString::SkipEmptyParts);
5717  for (int t = 0; t < types.count(); ++t)
5718  {
5719  QString type = types[t];
5720  if (type == KAEventPrivate::AT_LOGIN_TYPE
5721  || type == KAEventPrivate::TIME_DEFERRAL_TYPE
5722  || type == KAEventPrivate::DATE_DEFERRAL_TYPE
5723  || type == KAEventPrivate::REMINDER_TYPE
5724  || type == REMINDER_ONCE_TYPE)
5725  {
5726  mainAlarm = false;
5727  break;
5728  }
5729  }
5730  if (mainAlarm)
5731  {
5732  if (mainExpired)
5733  {
5734  // All main alarms are supposed to be at the same time, so
5735  // don't readjust the event's time for subsequent main alarms.
5736  mainExpired = false;
5737  nextMainDateTime = alarm->time();
5738  nextMainDateTime.setDateOnly(dateOnly);
5739  nextMainDateTime = nextMainDateTime.toTimeSpec(startDateTime);
5740  if (nextMainDateTime != startDateTime)
5741  {
5742  QDateTime dt = nextMainDateTime.dateTime();
5743  event->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::NEXT_RECUR_PROPERTY,
5744  dt.toString(dateOnly ? QLatin1String("yyyyMMdd") : QLatin1String("yyyyMMddThhmmss")));
5745  }
5746  }
5747  alarm->setStartOffset(0);
5748  converted = true;
5749  }
5750  }
5751  int adjustment;
5752  if (mainExpired)
5753  {
5754  // It's an expired recurrence.
5755  // Set the alarm offset relative to the first actual occurrence
5756  // (taking account of possible exceptions).
5757  KDateTime dt = event->recurrence()->getNextDateTime(startDateTime.addDays(-1));
5758  dt.setDateOnly(dateOnly);
5759  adjustment = startDateTime.secsTo(dt);
5760  }
5761  else
5762  adjustment = startDateTime.secsTo(nextMainDateTime);
5763  if (adjustment)
5764  {
5765  // Convert deferred alarms
5766  for (int i = 0, alend = alarms.count(); i < alend; ++i)
5767  {
5768 #ifndef KALARMCAL_USE_KRESOURCES
5769  Alarm::Ptr alarm = alarms[i];
5770 #else
5771  Alarm* alarm = alarms[i];
5772 #endif
5773  if (!alarm->hasStartOffset())
5774  continue;
5775  const QString property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::TYPE_PROPERTY);
5776  const QStringList types = property.split(QLatin1Char(','), QString::SkipEmptyParts);
5777  for (int t = 0; t < types.count(); ++t)
5778  {
5779  const QString type = types[t];
5780  if (type == KAEventPrivate::TIME_DEFERRAL_TYPE
5781  || type == KAEventPrivate::DATE_DEFERRAL_TYPE)
5782  {
5783  alarm->setStartOffset(alarm->startOffset().asSeconds() - adjustment);
5784  converted = true;
5785  break;
5786  }
5787  }
5788  }
5789  }
5790  }
5791 
5792  if (pre_1_5_0 || (pre_1_9_9 && !pre_1_9_0))
5793  {
5794  /*
5795  * It's a KAlarm pre-1.5.0 or KAlarm 1.9 series pre-1.9.9 calendar file.
5796  * Convert email identity names to uoids.
5797  */
5798  for (int i = 0, alend = alarms.count(); i < alend; ++i)
5799  {
5800 #ifndef KALARMCAL_USE_KRESOURCES
5801  Alarm::Ptr alarm = alarms[i];
5802 #else
5803  Alarm* alarm = alarms[i];
5804 #endif
5805  const QString name = alarm->customProperty(KACalendar::APPNAME, KMAIL_ID_PROPERTY);
5806  if (name.isEmpty())
5807  continue;
5808  const uint id = Identities::identityUoid(name);
5809  if (id)
5810  alarm->setCustomProperty(KACalendar::APPNAME, EMAIL_ID_PROPERTY, QString::number(id));
5811  alarm->removeCustomProperty(KACalendar::APPNAME, KMAIL_ID_PROPERTY);
5812  converted = true;
5813  }
5814  }
5815 
5816  if (pre_1_9_10)
5817  {
5818  /*
5819  * It's a KAlarm pre-1.9.10 calendar file.
5820  * Convert simple repetitions without a recurrence, to a recurrence.
5821  */
5822  if (KAEventPrivate::convertRepetition(event))
5823  converted = true;
5824  }
5825 
5826  if (pre_2_2_9 || (pre_2_3_2 && !pre_2_3_0))
5827  {
5828  /*
5829  * It's a KAlarm pre-2.2.9 or KAlarm 2.3 series pre-2.3.2 calendar file.
5830  * Set the time in the calendar for all date-only alarms to 00:00.
5831  */
5832  if (KAEventPrivate::convertStartOfDay(event))
5833  converted = true;
5834  }
5835 
5836  if (pre_2_7_0)
5837  {
5838  /*
5839  * It's a KAlarm pre-2.7.0 calendar file.
5840  * Archive and at-login flags were stored in event's ARCHIVE property when the main alarm had expired.
5841  * Reminder parameters were stored in event's ARCHIVE property when no reminder was pending.
5842  * Negative reminder periods (i.e. alarm offset > 0) were invalid, so convert to 0.
5843  * Now store reminder information in FLAGS property, whether reminder is pending or not.
5844  * Move EMAILID, SPEAK, ERRCANCEL and ERRNOSHOW alarm properties into new FLAGS property.
5845  */
5846  bool flagsValid = false;
5847  QStringList flags;
5848  QString reminder;
5849  bool reminderOnce = false;
5850  const QString prop = event->customProperty(KACalendar::APPNAME, ARCHIVE_PROPERTY);
5851  if (!prop.isEmpty())
5852  {
5853  // Convert the event's ARCHIVE property to parameters in the FLAGS property
5854  flags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, QString::SkipEmptyParts);
5855  flags << KAEventPrivate::ARCHIVE_FLAG;
5856  flagsValid = true;
5857  if (prop != QLatin1String("0")) // "0" was a dummy parameter if no others were present
5858  {
5859  // It's the archive property containing a reminder time and/or repeat-at-login flag.
5860  // This was present when no reminder/at-login alarm was pending.
5861  const QStringList list = prop.split(KAEventPrivate::SC, QString::SkipEmptyParts);
5862  for (int i = 0; i < list.count(); ++i)
5863  {
5864  if (list[i] == KAEventPrivate::AT_LOGIN_TYPE)
5865  flags << KAEventPrivate::AT_LOGIN_TYPE;
5866  else if (list[i] == ARCHIVE_REMINDER_ONCE_TYPE)
5867  reminderOnce = true;
5868  else if (!list[i].isEmpty() && !list[i].startsWith(QChar::fromLatin1('-')))
5869  reminder = list[i];
5870  }
5871  }
5872  event->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY, flags.join(KAEventPrivate::SC));
5873  event->removeCustomProperty(KACalendar::APPNAME, ARCHIVE_PROPERTY);
5874  }
5875 
5876  for (int i = 0, alend = alarms.count(); i < alend; ++i)
5877  {
5878 #ifndef KALARMCAL_USE_KRESOURCES
5879  Alarm::Ptr alarm = alarms[i];
5880 #else
5881  Alarm* alarm = alarms[i];
5882 #endif
5883  // Convert EMAILID, SPEAK, ERRCANCEL, ERRNOSHOW properties
5884  QStringList flags;
5885  QString property = alarm->customProperty(KACalendar::APPNAME, EMAIL_ID_PROPERTY);
5886  if (!property.isEmpty())
5887  {
5888  flags << KAEventPrivate::EMAIL_ID_FLAG << property;
5889  alarm->removeCustomProperty(KACalendar::APPNAME, EMAIL_ID_PROPERTY);
5890  }
5891  if (!alarm->customProperty(KACalendar::APPNAME, SPEAK_PROPERTY).isEmpty())
5892  {
5893  flags << KAEventPrivate::SPEAK_FLAG;
5894  alarm->removeCustomProperty(KACalendar::APPNAME, SPEAK_PROPERTY);
5895  }
5896  if (!alarm->customProperty(KACalendar::APPNAME, CANCEL_ON_ERROR_PROPERTY).isEmpty())
5897  {
5898  flags << KAEventPrivate::CANCEL_ON_ERROR_FLAG;
5899  alarm->removeCustomProperty(KACalendar::APPNAME, CANCEL_ON_ERROR_PROPERTY);
5900  }
5901  if (!alarm->customProperty(KACalendar::APPNAME, DONT_SHOW_ERROR_PROPERTY).isEmpty())
5902  {
5903  flags << KAEventPrivate::DONT_SHOW_ERROR_FLAG;
5904  alarm->removeCustomProperty(KACalendar::APPNAME, DONT_SHOW_ERROR_PROPERTY);
5905  }
5906  if (!flags.isEmpty())
5907  alarm->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY, flags.join(KAEventPrivate::SC));
5908 
5909  // Invalidate negative reminder periods in alarms
5910  if (!alarm->hasStartOffset())
5911  continue;
5912  property = alarm->customProperty(KACalendar::APPNAME, KAEventPrivate::TYPE_PROPERTY);
5913  QStringList types = property.split(QChar::fromLatin1(','), QString::SkipEmptyParts);
5914  const int r = types.indexOf(REMINDER_ONCE_TYPE);
5915  if (r >= 0)
5916  {
5917  // Move reminder-once indicator from the alarm to the event's FLAGS property
5918  types[r] = KAEventPrivate::REMINDER_TYPE;
5919  alarm->setCustomProperty(KACalendar::APPNAME, KAEventPrivate::TYPE_PROPERTY, types.join(QChar::fromLatin1(',')));
5920  reminderOnce = true;
5921  }
5922  if (r >= 0 || types.contains(KAEventPrivate::REMINDER_TYPE))
5923  {
5924  // The alarm is a reminder alarm
5925  const int offset = alarm->startOffset().asSeconds();
5926  if (offset > 0)
5927  {
5928  alarm->setStartOffset(0);
5929  converted = true;
5930  }
5931  else if (offset < 0)
5932  reminder = reminderToString(offset / 60);
5933  }
5934  }
5935  if (!reminder.isEmpty())
5936  {
5937  // Write reminder parameters into the event's FLAGS property
5938  if (!flagsValid)
5939  flags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, QString::SkipEmptyParts);
5940  if (flags.indexOf(KAEventPrivate::REMINDER_TYPE) < 0)
5941  {
5942  flags += KAEventPrivate::REMINDER_TYPE;
5943  if (reminderOnce)
5944  flags += KAEventPrivate::REMINDER_ONCE_FLAG;
5945  flags += reminder;
5946  }
5947  }
5948  }
5949 
5950  if (readOnly)
5951  event->setReadOnly(true);
5952  event->endUpdates(); // finally issue an update notification
5953  }
5954  return converted;
5955 }
5956 
5957 /******************************************************************************
5958 * Set the time for a date-only event to 00:00.
5959 * Reply = true if the event was updated.
5960 */
5961 #ifndef KALARMCAL_USE_KRESOURCES
5962 bool KAEventPrivate::convertStartOfDay(const Event::Ptr& event)
5963 #else
5964 bool KAEventPrivate::convertStartOfDay(Event* event)
5965 #endif
5966 {
5967  bool changed = false;
5968  const QTime midnight(0, 0);
5969  const QStringList flags = event->customProperty(KACalendar::APPNAME, KAEventPrivate::FLAGS_PROPERTY).split(KAEventPrivate::SC, QString::SkipEmptyParts);
5970  if (flags.indexOf(KAEventPrivate::DATE_ONLY_FLAG) >= 0)
5971  {
5972  // It's an untimed event, so fix it
5973  const KDateTime oldDt = event->dtStart();
5974  const int adjustment = oldDt.time().secsTo(midnight);
5975  if (adjustment)
5976  {
5977  event->setDtStart(KDateTime(oldDt.date(), midnight, oldDt.timeSpec()));
5978  int deferralOffset = 0;
5979  AlarmMap alarmMap;
5980  readAlarms(event, &alarmMap);
5981  for (AlarmMap::ConstIterator it = alarmMap.constBegin(); it != alarmMap.constEnd(); ++it)
5982  {
5983  const AlarmData& data = it.value();
5984  if (!data.alarm->hasStartOffset())
5985  continue;
5986  if (data.timedDeferral)
5987  {
5988  // Found a timed deferral alarm, so adjust the offset
5989  deferralOffset = data.alarm->startOffset().asSeconds();
5990 #ifndef KALARMCAL_USE_KRESOURCES
5991  const_cast<Alarm*>(data.alarm.data())->setStartOffset(deferralOffset - adjustment);
5992 #else
5993  const_cast<Alarm*>(data.alarm)->setStartOffset(deferralOffset - adjustment);
5994 #endif
5995  }
5996  else if (data.type == AUDIO_ALARM
5997  && data.alarm->startOffset().asSeconds() == deferralOffset)
5998  {
5999  // Audio alarm is set for the same time as the above deferral alarm
6000 #ifndef KALARMCAL_USE_KRESOURCES
6001  const_cast<Alarm*>(data.alarm.data())->setStartOffset(deferralOffset - adjustment);
6002 #else
6003  const_cast<Alarm*>(data.alarm)->setStartOffset(deferralOffset - adjustment);
6004 #endif
6005  }
6006  }
6007  changed = true;
6008  }
6009  }
6010  else
6011  {
6012  // It's a timed event. Fix any untimed alarms.
6013  bool foundDeferral = false;
6014  int deferralOffset = 0;
6015  int newDeferralOffset = 0;
6016  DateTime start;
6017  const KDateTime nextMainDateTime = readDateTime(event, false, start).kDateTime();
6018  AlarmMap alarmMap;
6019  readAlarms(event, &alarmMap);
6020  for (AlarmMap::ConstIterator it = alarmMap.constBegin(); it != alarmMap.constEnd(); ++it)
6021  {
6022  const AlarmData& data = it.value();
6023  if (!data.alarm->hasStartOffset())
6024  continue;
6025  if ((data.type & DEFERRED_ALARM) && !data.timedDeferral)
6026  {
6027  // Found a date-only deferral alarm, so adjust its time
6028  KDateTime altime = data.alarm->startOffset().end(nextMainDateTime);
6029  altime.setTime(midnight);
6030  deferralOffset = data.alarm->startOffset().asSeconds();
6031  newDeferralOffset = event->dtStart().secsTo(altime);
6032 #ifndef KALARMCAL_USE_KRESOURCES
6033  const_cast<Alarm*>(data.alarm.data())->setStartOffset(newDeferralOffset);
6034 #else
6035  const_cast<Alarm*>(data.alarm)->setStartOffset(newDeferralOffset);
6036 #endif
6037  foundDeferral = true;
6038  changed = true;
6039  }
6040  else if (foundDeferral
6041  && data.type == AUDIO_ALARM
6042  && data.alarm->startOffset().asSeconds() == deferralOffset)
6043  {
6044  // Audio alarm is set for the same time as the above deferral alarm
6045 #ifndef KALARMCAL_USE_KRESOURCES
6046  const_cast<Alarm*>(data.alarm.data())->setStartOffset(newDeferralOffset);
6047 #else
6048  const_cast<Alarm*>(data.alarm)->setStartOffset(newDeferralOffset);
6049 #endif
6050  changed = true;
6051  }
6052  }
6053  }
6054  return changed;
6055 }
6056 
6057 /******************************************************************************
6058 * Convert simple repetitions in an event without a recurrence, to a
6059 * recurrence. Repetitions which are an exact multiple of 24 hours are converted
6060 * to daily recurrences; else they are converted to minutely recurrences. Note
6061 * that daily and minutely recurrences produce different results when they span
6062 * a daylight saving time change.
6063 * Reply = true if any conversions were done.
6064 */
6065 #ifndef KALARMCAL_USE_KRESOURCES
6066 bool KAEventPrivate::convertRepetition(const Event::Ptr& event)
6067 #else
6068 bool KAEventPrivate::convertRepetition(Event* event)
6069 #endif
6070 {
6071  const Alarm::List alarms = event->alarms();
6072  if (alarms.isEmpty())
6073  return false;
6074  Recurrence* recur = event->recurrence(); // guaranteed to return non-null
6075  if (recur->recurs())
6076  return false;
6077  bool converted = false;
6078  const bool readOnly = event->isReadOnly();
6079  for (int ai = 0, aend = alarms.count(); ai < aend; ++ai)
6080  {
6081 #ifndef KALARMCAL_USE_KRESOURCES
6082  Alarm::Ptr alarm = alarms[ai];
6083 #else
6084  Alarm* alarm = alarms[ai];
6085 #endif
6086  if (alarm->repeatCount() > 0 && alarm->snoozeTime().value() > 0)
6087  {
6088  if (!converted)
6089  {
6090  event->startUpdates(); // prevent multiple update notifications
6091  if (readOnly)
6092  event->setReadOnly(false);
6093  if ((alarm->snoozeTime().asSeconds() % (24*3600)) != 0)
6094  recur->setMinutely(alarm->snoozeTime().asSeconds() / 60);
6095  else
6096  recur->setDaily(alarm->snoozeTime().asDays());
6097  recur->setDuration(alarm->repeatCount() + 1);
6098  converted = true;
6099  }
6100  alarm->setRepeatCount(0);
6101  alarm->setSnoozeTime(0);
6102  }
6103  }
6104  if (converted)
6105  {
6106  if (readOnly)
6107  event->setReadOnly(true);
6108  event->endUpdates(); // finally issue an update notification
6109  }
6110  return converted;
6111 }
6112 
6113 /*=============================================================================
6114 = Class KAAlarm
6115 = Corresponds to a single KCal::Alarm instance.
6116 =============================================================================*/
6117 
6118 KAAlarm::KAAlarm()
6119  : d(new Private)
6120 {
6121 }
6122 
6123 KAAlarm::Private::Private()
6124  : mType(INVALID_ALARM),
6125  mNextRepeat(0),
6126  mRepeatAtLogin(false),
6127  mDeferred(false)
6128 {
6129 }
6130 
6131 KAAlarm::KAAlarm(const KAAlarm& other)
6132  : d(new Private(*other.d))
6133 {
6134 }
6135 
6136 KAAlarm::~KAAlarm()
6137 {
6138  delete d;
6139 }
6140 
6141 KAAlarm& KAAlarm::operator=(const KAAlarm& other)
6142 {
6143  if (&other != this)
6144  *d = *other.d;
6145  return *this;
6146 }
6147 
6148 KAAlarm::Action KAAlarm::action() const
6149 {
6150  return d->mActionType;
6151 }
6152 
6153 bool KAAlarm::isValid() const
6154 {
6155  return d->mType != INVALID_ALARM;
6156 }
6157 
6158 KAAlarm::Type KAAlarm::type() const
6159 {
6160  return d->mType;
6161 }
6162 
6163 DateTime KAAlarm::dateTime(bool withRepeats) const
6164 {
6165  return (withRepeats && d->mNextRepeat && d->mRepetition)
6166  ? d->mRepetition.duration(d->mNextRepeat).end(d->mNextMainDateTime.kDateTime())
6167  : d->mNextMainDateTime;
6168 }
6169 
6170 QDate KAAlarm::date() const
6171 {
6172  return d->mNextMainDateTime.date();
6173 }
6174 
6175 QTime KAAlarm::time() const
6176 {
6177  return d->mNextMainDateTime.effectiveTime();
6178 }
6179 
6180 bool KAAlarm::repeatAtLogin() const
6181 {
6182  return d->mRepeatAtLogin;
6183 }
6184 
6185 bool KAAlarm::isReminder() const
6186 {
6187  return d->mType == REMINDER_ALARM;
6188 }
6189 
6190 bool KAAlarm::deferred() const
6191 {
6192  return d->mDeferred;
6193 }
6194 
6195 bool KAAlarm::timedDeferral() const
6196 {
6197  return d->mDeferred && d->mTimedDeferral;
6198 }
6199 
6200 void KAAlarm::setTime(const DateTime& dt)
6201 {
6202  d->mNextMainDateTime = dt;
6203 }
6204 
6205 void KAAlarm::setTime(const KDateTime& dt)
6206 {
6207  d->mNextMainDateTime = dt;
6208 }
6209 
6210 #ifdef KDE_NO_DEBUG_OUTPUT
6211 const char* KAAlarm::debugType(Type) { return ""; }
6212 #else
6213 const char* KAAlarm::debugType(Type type)
6214 {
6215  switch (type)
6216  {
6217  case MAIN_ALARM: return "MAIN";
6218  case REMINDER_ALARM: return "REMINDER";
6219  case DEFERRED_ALARM: return "DEFERRED";
6220  case DEFERRED_REMINDER_ALARM: return "DEFERRED_REMINDER";
6221  case AT_LOGIN_ALARM: return "LOGIN";
6222  case DISPLAYING_ALARM: return "DISPLAYING";
6223  default: return "INVALID";
6224  }
6225 }
6226 #endif
6227 
6228 /*=============================================================================
6229 = Class EmailAddressList
6230 =============================================================================*/
6231 
6232 /******************************************************************************
6233 * Sets the list of email addresses, removing any empty addresses.
6234 * Reply = false if empty addresses were found.
6235 */
6236 #ifndef KALARMCAL_USE_KRESOURCES
6237 EmailAddressList& EmailAddressList::operator=(const Person::List& addresses)
6238 #else
6239 EmailAddressList& EmailAddressList::operator=(const QList<Person>& addresses)
6240 #endif
6241 {
6242  clear();
6243  for (int p = 0, end = addresses.count(); p < end; ++p)
6244  {
6245 #ifndef KALARMCAL_USE_KRESOURCES
6246  if (!addresses[p]->email().isEmpty())
6247 #else
6248  if (!addresses[p].email().isEmpty())
6249 #endif
6250  append(addresses[p]);
6251  }
6252  return *this;
6253 }
6254 
6255 /******************************************************************************
6256 * Return the email address list as a string list of email addresses.
6257 */
6258 EmailAddressList::operator QStringList() const
6259 {
6260  QStringList list;
6261  for (int p = 0, end = count(); p < end; ++p)
6262  list += address(p);
6263  return list;
6264 }
6265 
6266 /******************************************************************************
6267 * Return the email address list as a string, each address being delimited by
6268 * the specified separator string.
6269 */
6270 QString EmailAddressList::join(const QString& separator) const
6271 {
6272  QString result;
6273  bool first = true;
6274  for (int p = 0, end = count(); p < end; ++p)
6275  {
6276  if (first)
6277  first = false;
6278  else
6279  result += separator;
6280  result += address(p);
6281  }
6282  return result;
6283 }
6284 
6285 /******************************************************************************
6286 * Convert one item into an email address, including name.
6287 */
6288 QString EmailAddressList::address(int index) const
6289 {
6290  if (index < 0 || index > count())
6291  return QString();
6292  QString result;
6293  bool quote = false;
6294 #ifndef KALARMCAL_USE_KRESOURCES
6295  const Person::Ptr person = (*this)[index];
6296  const QString name = person->name();
6297 #else
6298  const Person person = (*this)[index];
6299  const QString name = person.name();
6300 #endif
6301  if (!name.isEmpty())
6302  {
6303  // Need to enclose the name in quotes if it has any special characters
6304  for (int i = 0, len = name.length(); i < len; ++i)
6305  {
6306  const QChar ch = name[i];
6307  if (!ch.isLetterOrNumber())
6308  {
6309  quote = true;
6310  result += QLatin1Char('\"');
6311  break;
6312  }
6313  }
6314 #ifndef KALARMCAL_USE_KRESOURCES
6315  result += (*this)[index]->name();
6316 #else
6317  result += (*this)[index].name();
6318 #endif
6319  result += (quote ? QLatin1String("\" <") : QLatin1String(" <"));
6320  quote = true; // need angle brackets round email address
6321  }
6322 
6323 #ifndef KALARMCAL_USE_KRESOURCES
6324  result += person->email();
6325 #else
6326  result += person.email();
6327 #endif
6328  if (quote)
6329  result += QLatin1Char('>');
6330  return result;
6331 }
6332 
6333 /******************************************************************************
6334 * Return a list of the pure email addresses, excluding names.
6335 */
6336 QStringList EmailAddressList::pureAddresses() const
6337 {
6338  QStringList list;
6339  for (int p = 0, end = count(); p < end; ++p)
6340 #ifndef KALARMCAL_USE_KRESOURCES
6341  list += at(p)->email();
6342 #else
6343  list += at(p).email();
6344 #endif
6345  return list;
6346 }
6347 
6348 /******************************************************************************
6349 * Return a list of the pure email addresses, excluding names, as a string.
6350 */
6351 QString EmailAddressList::pureAddresses(const QString& separator) const
6352 {
6353  QString result;
6354  bool first = true;
6355  for (int p = 0, end = count(); p < end; ++p)
6356  {
6357  if (first)
6358  first = false;
6359  else
6360  result += separator;
6361 #ifndef KALARMCAL_USE_KRESOURCES
6362  result += at(p)->email();
6363 #else
6364  result += at(p).email();
6365 #endif
6366  }
6367  return result;
6368 }
6369 
6370 /*=============================================================================
6371 = Static functions
6372 =============================================================================*/
6373 
6374 /******************************************************************************
6375 * Set the specified alarm to be a procedure alarm with the given command line.
6376 * The command line is first split into its program file and arguments before
6377 * initialising the alarm.
6378 */
6379 #ifndef KALARMCAL_USE_KRESOURCES
6380 static void setProcedureAlarm(const Alarm::Ptr& alarm, const QString& commandLine)
6381 #else
6382 static void setProcedureAlarm(Alarm* alarm, const QString& commandLine)
6383 #endif
6384 {
6385  QString command;
6386  QString arguments;
6387  QChar quoteChar;
6388  bool quoted = false;
6389  const uint posMax = commandLine.length();
6390  uint pos;
6391  for (pos = 0; pos < posMax; ++pos)
6392  {
6393  const QChar ch = commandLine[pos];
6394  if (quoted)
6395  {
6396  if (ch == quoteChar)
6397  {
6398  ++pos; // omit the quote character
6399  break;
6400  }
6401  command += ch;
6402  }
6403  else
6404  {
6405  bool done = false;
6406  switch (ch.toLatin1())
6407  {
6408  case ' ':
6409  case ';':
6410  case '|':
6411  case '<':
6412  case '>':
6413  done = !command.isEmpty();
6414  break;
6415  case '\'':
6416  case '"':
6417  if (command.isEmpty())
6418  {
6419  // Start of a quoted string. Omit the quote character.
6420  quoted = true;
6421  quoteChar = ch;
6422  break;
6423  }
6424  // fall through to default
6425  default:
6426  command += ch;
6427  break;
6428  }
6429  if (done)
6430  break;
6431  }
6432  }
6433 
6434  // Skip any spaces after the command
6435  for ( ; pos < posMax && commandLine[pos] == QLatin1Char(' '); ++pos) ;
6436  arguments = commandLine.mid(pos);
6437 
6438  alarm->setProcedureAlarm(command, arguments);
6439 }
6440 
6441 /******************************************************************************
6442 * Converts a reminder interval into a parameter string for the
6443 * X-KDE-KALARM-FLAGS property.
6444 */
6445 QString reminderToString(int minutes)
6446 {
6447  char unit = 'M';
6448  int count = abs(minutes);
6449  if (count % 1440 == 0)
6450  {
6451  unit = 'D';
6452  count /= 1440;
6453  }
6454  else if (count % 60 == 0)
6455  {
6456  unit = 'H';
6457  count /= 60;
6458  }
6459  if (minutes < 0)
6460  count = -count;
6461  return QString::fromLatin1("%1%2").arg(count).arg(unit);
6462 }
6463 
6464 } // namespace KAlarmCal
6465 
6466 // vim: et sw=4:
KCalCore::Alarm::setEnabled
void setEnabled(bool enable)
KCalCore
KAlarmCal::KAEvent::ACT_DISPLAY
the alarm displays something
Definition: kaevent.h:247
KAlarmCal::KAEvent::cancelDefer
void cancelDefer()
Cancel any deferral alarm which is pending.
Definition: kaevent.cpp:2649
KAlarmCal::KAEvent::setReminder
void setReminder(int minutes, bool onceOnly)
Set an additional reminder alarm.
Definition: kaevent.cpp:2424
KAlarmCal::KAEvent::emailAddressees
KCalCore::Person::List emailAddressees() const
Return the list of email addressees, including names, for an email alarm.
Definition: kaevent.cpp:2226
KAlarmCal::KAEvent::ACT_DISPLAY_COMMAND
the alarm displays command output
Definition: kaevent.h:251
KAlarmCal::KAEvent::LIMIT_REMINDER
a reminder
Definition: kaevent.h:295
KAlarmCal::KAEvent::setRecurMinutely
bool setRecurMinutely(int freq, int count, const KDateTime &end)
Set the recurrence to recur at a minutes interval.
Definition: kaevent.cpp:3000
KAlarmCal::KARecurrence::ANNUAL_DATE
yearly, on a specified date in each of the specified months
Definition: karecurrence.h:75
KCalCore::Alarm::setRepeatCount
void setRepeatCount(int alarmRepeatCount)
KAlarmCal::KAEvent::repeatSound
bool repeatSound() const
Return whether the sound file will be repeated indefinitely.
Definition: kaevent.cpp:2325
KAlarmCal::CalEvent::type
Type type(const QString &mimeType)
Return the alarm Type for a mime type string.
Definition: kacalendar.cpp:469
KAlarmCal::KAAlarm::Type
Type
Alarm types.
Definition: kaevent.h:94
KAlarmCal::KAEvent::setNextOccurrence
OccurType setNextOccurrence(const KDateTime &preDateTime)
Set the date/time of the event to the next scheduled occurrence after a specified date/time...
Definition: kaevent.cpp:3446
KAlarmCal::KAEvent::recurrence
KARecurrence * recurrence() const
Return the full recurrence data for the event.
Definition: kaevent.cpp:3199
KAlarmCal::KAEvent::recurs
bool recurs() const
Return whether the event recurs.
Definition: kaevent.cpp:3189
KAlarmCal::KAAlarm::time
QTime time() const
Return the trigger time-of-day for the alarm.
Definition: kaevent.cpp:6175
KAlarmCal::KAEvent::setRecurrence
void setRecurrence(const KARecurrence &r)
Initialise the event's recurrence from a KARecurrence.
Definition: kaevent.cpp:2966
KAlarmCal::KARecurrence::WEEKLY
weekly, on specified weekdays
Definition: karecurrence.h:72
KAlarmCal::KAEvent::font
QFont font() const
Return the font to use for alarm message texts.
Definition: kaevent.cpp:2073
KAlarmCal::KAEvent::flags
Flags flags() const
Return the OR of various Flag enum status values.
Definition: kaevent.cpp:1831
KCalCore::Alarm::startOffset
Duration startOffset() const
KAlarmCal::KAEvent::repetitionText
QString repetitionText(bool brief=false) const
Return the repetition interval as text suitable for display.
Definition: kaevent.cpp:3376
KAlarmCal::KAEvent::cancelOnPreActionError
bool cancelOnPreActionError() const
Return whether the alarm is to be cancelled if the pre-alarm action fails.
Definition: kaevent.cpp:2410
KAlarmCal::KAEvent::setRecurMonthlyByDate
bool setRecurMonthlyByDate(int freq, const QVector< int > &days, int count, const QDate &end)
Set the recurrence to recur monthly, on the specified days within the month.
Definition: kaevent.cpp:3067
KAlarmCal::KAAlarm::REMINDER_ALARM
Reminder in advance of/after the main alarm.
Definition: kaevent.h:98
KCalCore::Alarm::setEmailAlarm
void setEmailAlarm(const QString &subject, const QString &text, const Person::List &addressees, const QStringList &attachments=QStringList())
KAlarmCal::KAEvent::dumpDebug
void dumpDebug() const
Output the event's data as debug output.
Definition: kaevent.cpp:4037
KAlarmCal::KAEvent::confirmAck
bool confirmAck() const
Return whether alarm acknowledgement must be confirmed by the user, for a display alarm...
Definition: kaevent.cpp:2191
KAlarmCal::KAAlarm::MAIN_ALARM
THE real alarm. Must be the first in the enumeration.
Definition: kaevent.h:97
KAlarmCal::CalEvent::TEMPLATE
the event is an alarm template
Definition: kacalendar.h:160
KAlarmCal::Repetition::interval
KCalCore::Duration interval() const
Return the interval between repetitions.
Definition: repetition.cpp:119
KAlarmCal::KAEvent::lateCancel
int lateCancel() const
Get the late cancellation period.
Definition: kaevent.cpp:2007
KAlarmCal::KAEvent::setRepeatAtLogin
void setRepeatAtLogin(bool repeat)
Enable or disable repeat-at-login.
Definition: kaevent.cpp:2833
KAlarmCal::KARecurrence::Type
Type
The recurrence's period type.
Definition: karecurrence.h:67
KCalCore::Person
KAlarmCal::DateTime::addMins
DateTime addMins(qint64 n) const
Returns a DateTime value mins minutes later than the value of this object.
Definition: datetime.cpp:290
KCalCore::Duration
KCalCore::Alarm::Ptr
QSharedPointer< Alarm > Ptr
KAlarmCal::KAEvent::alarm
KAAlarm alarm(KAAlarm::Type type) const
Return the alarm of a specified type.
Definition: kaevent.cpp:3789
KCalCore::CustomProperties::customProperty
QString customProperty(const QByteArray &app, const QByteArray &key) const
KAlarmCal::KAAlarm
KAAlarm represents individual alarms within a KAEvent.
Definition: kaevent.h:77
KAlarmCal::KAEvent::mainEndRepeatTime
DateTime mainEndRepeatTime() const
Return the time at which the last sub-repetition of the main alarm will occur.
Definition: kaevent.cpp:2769
KAlarmCal::Repetition::intervalSeconds
int intervalSeconds() const
Return the repetition interval in terms of seconds.
Definition: repetition.cpp:149
memorycalendar.h
KAlarmCal::KAEvent::ACT_NONE
invalid
Definition: kaevent.h:246
KCalCore::Incidence::customStatus
QString customStatus() const
KAlarmCal::DateTime::addSecs
DateTime addSecs(qint64 n) const
Returns a DateTime value secs seconds later than the value of this object.
Definition: datetime.cpp:285
KAlarmCal::KAEvent::setExcludeHolidays
void setExcludeHolidays(bool exclude)
Enable or disable the alarm on holiday dates.
Definition: kaevent.cpp:2869
KCalCore::Alarm::setSnoozeTime
void setSnoozeTime(const Duration &alarmSnoozeTime)
KCalCore::Recurrence::setDuration
void setDuration(int duration)
KCalCore::Event::Ptr
QSharedPointer< Event > Ptr
KAlarmCal::KAEvent::longestRecurrenceInterval
KCalCore::Duration longestRecurrenceInterval() const
Return the longest interval which can occur between consecutive recurrences.
Definition: kaevent.cpp:3228
KAlarmCal::KAEvent::speak
bool speak() const
Return whether the displayed alarm text should be spoken.
Definition: kaevent.cpp:2340
KAlarmCal::KAEvent::previousOccurrence
OccurType previousOccurrence(const KDateTime &afterDateTime, DateTime &result, bool includeRepetitions=false) const
Get the date/time of the last previous occurrence of the event, before the specified date/time...
Definition: kaevent.cpp:3596
KAlarmCal::KAEvent::EMAIL_BCC
blind copy the email to the user
Definition: kaevent.h:223
KCalCore::Person::name
QString name() const
KAlarmCal::KAEvent::setRecurDaily
bool setRecurDaily(int freq, const QBitArray &days, int count, const QDate &end)
Set the recurrence to recur daily.
Definition: kaevent.cpp:3018
KAlarmCal::DateTime::startOfDay
static QTime startOfDay()
Returns the start-of-day time.
Definition: datetime.cpp:361
KCalCore::Duration::isDaily
bool isDaily() const
KAlarmCal::Repetition
Represents a sub-repetition, defined by interval and repeat count.
Definition: repetition.h:47
KAlarmCal::KAEvent::setWorkTime
static void setWorkTime(const QBitArray &days, const QTime &start, const QTime &end)
Set working days and times, to be used by all KAEvent instances.
Definition: kaevent.cpp:2930
KCalCore::Alarm::hasStartOffset
bool hasStartOffset() const
Akonadi::Entity::Id
qint64 Id
KCalCore::Incidence::recurrence
Recurrence * recurrence() const
KAlarmCal::KAEvent::AUTO_CLOSE
auto-close the alarm window after the late-cancel period
Definition: kaevent.h:227
KAlarmCal::KAEvent::recurInterval
int recurInterval() const
Return the recurrence interval in units of the recurrence period type (minutes, days, etc).
Definition: kaevent.cpp:3207
KAlarmCal::DateTime::setStartOfDay
static void setStartOfDay(const QTime &sod)
Sets the start-of-day time.
Definition: datetime.cpp:351
KAlarmCal::KAEvent::setLateCancel
void setLateCancel(int minutes)
Set or clear the late-cancel option.
Definition: kaevent.cpp:1998
KAlarmCal::KAAlarm::INVALID_ALARM
Not an alarm.
Definition: kaevent.h:96
KAlarmCal::Repetition::duration
KCalCore::Duration duration() const
Return the overall duration of the repetition.
Definition: repetition.cpp:124
KAlarmCal::KAEvent::ACT_EMAIL
the alarm sends an email
Definition: kaevent.h:249
KAlarmCal::KAAlarm::DEFERRED_REMINDER_ALARM
Deferred reminder alarm.
Definition: kaevent.h:100
KAlarmCal::KAAlarm::isValid
bool isValid() const
Return whether the alarm is valid, i.e.
Definition: kaevent.cpp:6153
KAlarmCal::KAEvent::startChanges
void startChanges()
Call before making a group of changes to the event, to avoid unnecessary calculation intensive recalc...
Definition: kaevent.cpp:4004
KAlarmCal::KAEvent::emailBcc
bool emailBcc() const
Return whether to send a blind copy of the email to the sender, for an email alarm.
Definition: kaevent.cpp:2278
KCalCore::Alarm
KAlarmCal::KAEvent::CMD_ERROR_POST
post-alarm command execution failed
Definition: kaevent.h:314
KAlarmCal::KAAlarm::deferred
bool deferred() const
Return whether this is a deferred alarm.
Definition: kaevent.cpp:6190
KAlarmCal::AlarmText::fromCalendarText
static QString fromCalendarText(const QString &text, bool &email)
Translate an alarm calendar text to a display text.
Definition: alarmtext.cpp:422
KAlarmCal::KAEvent::setAudioFile
void setAudioFile(const QString &filename, float volume, float fadeVolume, int fadeSeconds, int repeatPause=-1, bool allowEmptyFile=false)
Set the audio file related data for the event.
Definition: kaevent.cpp:2283
KAlarmCal::KAEvent::set
void set(const KCalCore::Event::Ptr &)
Initialise the instance from a KCalCore::Event.
Definition: kaevent.cpp:757
KAlarmCal::KAEvent::setDefaultFont
static void setDefaultFont(const QFont &font)
Set the global default font for alarm message texts.
Definition: kaevent.cpp:2063
KAlarmCal::KAEvent::setHolidays
static void setHolidays(const KHolidays::HolidayRegion &region)
Set the holiday region to be used by all KAEvent instances.
Definition: kaevent.cpp:2888
KAlarmCal::KAEvent::DISPLAY_TRIGGER
next trigger time for display purposes (i.e. excluding reminders)
Definition: kaevent.h:305
KAlarmCal::KAEvent::compatibility
KACalendar::Compat compatibility() const
Return the event's storage format compatibility compared to the current KAlarm calendar format...
Definition: kaevent.cpp:1958
KAlarmCal::KAEvent::setRecurAnnualByDate
bool setRecurAnnualByDate(int freq, const QVector< int > &months, int day, KARecurrence::Feb29Type, int count, const QDate &end)
Set the recurrence to recur annually, on the specified day in each of the specified months...
Definition: kaevent.cpp:3117
KAlarmCal::KAEvent::fgColour
QColor fgColour() const
Return the message window foreground color, for a display alarm.
Definition: kaevent.cpp:2058
KAlarmCal::KAEvent::setEventId
void setEventId(const QString &id)
Set the event's unique identifier.
Definition: kaevent.cpp:1883
KAlarmCal::KARecurrence::DAILY
daily
Definition: karecurrence.h:71
KAlarmCal::KAEvent::deferDefaultDateOnly
bool deferDefaultDateOnly() const
Return the default date-only setting used in the deferral dialog.
Definition: kaevent.cpp:2743
KCalCore::Person::List
QVector< Ptr > List
KAlarmCal::KAAlarm::type
Type type() const
Return the alarm's type (main, reminder, etc.).
Definition: kaevent.cpp:6158
KAlarmCal::KAEvent::actionTypes
Actions actionTypes() const
Return the OR of the basic action types of the event's main alarm (display, command, email, audio).
Definition: kaevent.cpp:1985
KCalCore::Alarm::List
QVector< Ptr > List
KAlarmCal::KAEvent::LIMIT_NONE
there is no limit
Definition: kaevent.h:291
KAlarmCal::KARecurrence::ANNUAL_POS
yearly, on specified weekdays in the specified weeks of the specified months
Definition: karecurrence.h:76
KCalCore::Alarm::setProcedureAlarm
void setProcedureAlarm(const QString &programFile, const QString &arguments=QString())
KAlarmCal::KARecurrence::Feb29Type
Feb29Type
When annual February 29th recurrences should occur in non-leap years.
Definition: karecurrence.h:79
KAlarmCal::KAEvent::setRepetition
bool setRepetition(const Repetition &r)
Initialise the event's sub-repetition.
Definition: kaevent.cpp:3325
KAlarmCal::KAEvent::alarmCount
int alarmCount() const
Return the number of alarms in the event, i.e.
Definition: kaevent.cpp:3934
KAlarmCal::KAEvent::COMMAND
execute a command
Definition: kaevent.h:260
KAlarmCal::KAEvent::setDisplaying
bool setDisplaying(const KAEvent &event, KAAlarm::Type type, Akonadi::Collection::Id colId, const KDateTime &repeatAtLoginTime, bool showEdit, bool showDefer)
Set the event to be a copy of the specified event, making the specified alarm the 'displaying' alarm...
Definition: kaevent.cpp:3660
KAlarmCal::KAEvent::postAction
QString postAction() const
Return the shell command to execute after the display alarm is acknowledged.
Definition: kaevent.cpp:2400
KAlarmCal::KAEvent::fadeSeconds
int fadeSeconds() const
Return the fade period in seconds, or 0 if no fade is specified.
Definition: kaevent.cpp:2320
KAlarmCal::KAAlarm::DEFERRED_ALARM
Deferred alarm.
Definition: kaevent.h:99
KAlarmCal::KARecurrence::NO_RECUR
does not recur
Definition: karecurrence.h:69
KAlarmCal::KAEvent::emailAttachments
QStringList emailAttachments() const
Return the list of file paths of the attachments, for an email alarm.
Definition: kaevent.cpp:2268
KAlarmCal::KAEvent::deferDateTime
DateTime deferDateTime() const
Return the time at which the currently pending deferred alarm should trigger.
Definition: kaevent.cpp:2675
KAlarmCal::KAEvent::holidaysExcluded
bool holidaysExcluded() const
Return whether the alarm is disabled on holiday dates.
Definition: kaevent.cpp:2876
KAlarmCal::KAEvent::itemId
Akonadi::Item::Id itemId() const
Return the ID of the Akonadi Item which contains the event.
Definition: kaevent.cpp:1925
KAlarmCal::KAEvent::LIMIT_RECURRENCE
a recurrence
Definition: kaevent.h:293
KAlarmCal::KAEvent::isTemplate
bool isTemplate() const
Return whether the event is an alarm template.
Definition: kaevent.cpp:2358
KAlarmCal::KAEvent::dontShowPreActionError
bool dontShowPreActionError() const
Return whether the user should not be notified if the pre-alarm action fails.
Definition: kaevent.cpp:2415
KAlarmCal::KAEvent::List
QVector< KAEvent * > List
A list of pointers to KAEvent objects.
Definition: kaevent.h:214
KCalCore::Duration::end
KDateTime end(const KDateTime &start) const
KAlarmCal::CalEvent::Type
Type
The category of an event, indicated by the middle part of its UID.
Definition: kacalendar.h:155
KAlarmCal::KAEvent::REPEAT_SOUND
repeat the sound file while the alarm is displayed
Definition: kaevent.h:225
KAlarmCal::KAEvent::mainDateTime
DateTime mainDateTime(bool withRepeats=false) const
Return the next time the main alarm will trigger.
Definition: kaevent.cpp:2759
KAlarmCal::KACalendar::APPNAME
const QByteArray APPNAME
The application name ("KALARM") used in calendar properties.
KAlarmCal::KAEvent::IGNORE_REPETITION
check for recurrences only, ignore sub-repetitions
Definition: kaevent.h:283
KAlarmCal::KAEvent::isWorkingTime
bool isWorkingTime(const KDateTime &dt) const
Check whether a date/time is during working hours and/or holidays, depending on the flags set for the...
Definition: kaevent.cpp:2909
KAlarmCal::KAAlarm::dateTime
DateTime dateTime(bool withRepeats=false) const
Return the trigger time for the alarm.
Definition: kaevent.cpp:6163
KCalCore::Event::List
QVector< Ptr > List
KAlarmCal::KAEvent::templateName
QString templateName() const
Return the alarm template's name.
Definition: kaevent.cpp:2363
KAlarmCal::KARecurrence
Represents recurrences for KAlarm.
Definition: karecurrence.h:61
KAlarmCal::AlarmText::toCalendarText
static QString toCalendarText(const QString &text)
Return the text for an alarm message text, in alarm calendar format.
Definition: alarmtext.cpp:462
KCalCore::Incidence::alarms
Alarm::List alarms() const
KAlarmCal::KAEvent::setCreatedDateTime
void setCreatedDateTime(const KDateTime &dt)
Set the date/time the event was created, or saved in the archive calendar.
Definition: kaevent.cpp:2820
KCalCore::Alarm::snoozeTime
Duration snoozeTime() const
KAlarmCal::KAEvent::endChanges
void endChanges()
Call when a group of changes preceded by startChanges() is complete, to allow resultant updates to oc...
Definition: kaevent.cpp:4013
KAlarmCal::KAEvent::revision
int revision() const
Return the revision number of the event (SEQUENCE property in iCalendar).
Definition: kaevent.cpp:1898
KAlarmCal::KAAlarm::MESSAGE
KCal::Alarm::Display type: display a text message.
Definition: kaevent.h:83
KAlarmCal::KAEvent::setLogFile
void setLogFile(const QString &logfile)
Set the log file to write command alarm output to.
Definition: kaevent.cpp:2179
KAlarmCal::KAEvent::toBeArchived
bool toBeArchived() const
Return whether the event should be archived when it expires or is deleted.
Definition: kaevent.cpp:1816
KAlarmCal::KAAlarm::Action
Action
The basic KAAlarm action types.
Definition: kaevent.h:81
KCalCore::Alarm::text
QString text() const
KAlarmCal::KAEvent::emailSubject
QString emailSubject() const
Return the email subject line, for an email alarm.
Definition: kaevent.cpp:2263
KAlarmCal::CalEvent::DISPLAYING
the event is currently being displayed
Definition: kacalendar.h:161
KCalCore::Recurrence
KAlarmCal::KAAlarm::isReminder
bool isReminder() const
Return whether this is a reminder alarm.
Definition: kaevent.cpp:6185
KAlarmCal::KAEvent::logFile
QString logFile() const
Return the log file which command alarm output should be written to.
Definition: kaevent.cpp:2186
KAlarmCal::KAEvent::mainTime
QTime mainTime() const
Return the time at which the main alarm will next trigger.
Definition: kaevent.cpp:2764
KAlarmCal::KAEvent::KAEvent
KAEvent()
Default constructor which creates an invalid event.
KAlarmCal::CalEvent::ACTIVE
the event is currently active
Definition: kacalendar.h:158
KAlarmCal::KAAlarm::operator=
KAAlarm & operator=(const KAAlarm &other)
Assignment operator.
Definition: kaevent.cpp:6141
KAlarmCal::KAEvent::isValid
bool isValid() const
Return whether the instance represents a valid event.
Definition: kaevent.cpp:1784
KAlarmCal::KAEvent::CMD_NO_ERROR
no error
Definition: kaevent.h:311
KCalCore::Event::dtEnd
virtual KDateTime dtEnd() const
KCalCore::CustomProperties::removeCustomProperty
void removeCustomProperty(const QByteArray &app, const QByteArray &key)
holidays.h
KAlarmCal::KAEvent::firstAlarm
KAAlarm firstAlarm() const
Return the main alarm for the event.
Definition: kaevent.cpp:3870
KAlarmCal::KAEvent::WORK_TIME_ONLY
trigger the alarm only during working hours
Definition: kaevent.h:233
KAlarmCal::KAEvent::nextTrigger
DateTime nextTrigger(TriggerType type) const
Return the next time the alarm will trigger.
Definition: kaevent.cpp:2800
KAlarmCal::KAEvent::ACT_AUDIO
the alarm plays an audio file (without any display)
Definition: kaevent.h:250
KAlarmCal::KAEvent::CMD_ERROR_PRE
pre-alarm command execution failed
Definition: kaevent.h:313
KAlarmCal::KAAlarm::debugType
static const char * debugType(Type)
Return an alarm type as a string.
Definition: kaevent.cpp:6213
KAlarmCal::KAAlarm::action
Action action() const
Return the action type for the alarm.
Definition: kaevent.cpp:6148
KAlarmCal::KAEvent::SCRIPT
the command is a script, not a shell command line
Definition: kaevent.h:228
KAlarmCal::KAEvent::message
QString message() const
Return the message text for a display alarm, or the email body for an email alarm.
Definition: kaevent.cpp:2037
KAlarmCal::KAEvent::commandError
CmdErrType commandError() const
Return the command execution error for the last time the alarm triggered.
Definition: kaevent.cpp:2174
KAlarmCal::KAEvent::EXCL_HOLIDAYS
don't trigger the alarm on holidays
Definition: kaevent.h:232
KAlarmCal::KAEvent::beep
bool beep() const
Return whether a beep should sound when the alarm is displayed.
Definition: kaevent.cpp:2335
KAlarmCal::KAEvent::nextOccurrence
OccurType nextOccurrence(const KDateTime &preDateTime, DateTime &result, OccurOption option=IGNORE_REPETITION) const
Get the date/time of the next occurrence of the event, after the specified date/time.
Definition: kaevent.cpp:3520
KAlarmCal::KAEvent::setDeferDefaultMinutes
void setDeferDefaultMinutes(int minutes, bool dateOnly=false)
Set defaults for the deferral dialog.
Definition: kaevent.cpp:2664
KAlarmCal::KARecurrence::recurs
bool recurs() const
Returns whether the event recurs at all.
Definition: karecurrence.cpp:725
KAlarmCal::KAEvent::DISABLED
the alarm is currently disabled
Definition: kaevent.h:226
KAlarmCal::KAEvent::convertDisplayingAlarm
KAAlarm convertDisplayingAlarm() const
Return the original alarm which the displaying alarm refers to.
Definition: kaevent.cpp:3758
KAlarmCal::KAEvent::setNoRecur
void setNoRecur()
Clear the event's recurrence and sub-repetition data.
Definition: kaevent.cpp:2945
KAlarmCal::DateTime::effectiveKDateTime
KDateTime effectiveKDateTime() const
Returns the date and time of the value.
Definition: datetime.cpp:163
KAlarmCal::KAEvent::DeferLimitType
DeferLimitType
What type of occurrence currently limits how long the alarm can be deferred.
Definition: kaevent.h:289
KAlarmCal::KAEvent::setCommandError
void setCommandError(CmdErrType error) const
Set or clear the command execution error for the last time the alarm triggered.
Definition: kaevent.cpp:2099
KAlarmCal::KAEvent::REMINDER_ONCE
only trigger the reminder on the first recurrence
Definition: kaevent.h:235
KAlarmCal::KAEvent::setRecurMonthlyByPos
bool setRecurMonthlyByPos(int freq, const QVector< MonthPos > &pos, int count, const QDate &end)
Set the recurrence to recur monthly, on the specified weekdays in the specified weeks of the month...
Definition: kaevent.cpp:3091
KCalCore::IncidenceBase::allDay
bool allDay() const
KAlarmCal::KAEvent::setReadOnly
void setReadOnly(bool ro)
Set the read-only status of the alarm.
Definition: kaevent.cpp:1800
KAlarmCal::KAEvent::CancelOnPreActError
cancel alarm on pre-alarm action error
Definition: kaevent.h:323
KCalCore::CustomProperties::setCustomProperty
void setCustomProperty(const QByteArray &app, const QByteArray &key, const QString &value)
KAlarmCal::KAEvent::fadeVolume
float fadeVolume() const
Return the initial volume which will fade to the final volume.
Definition: kaevent.cpp:2315
KAlarmCal::KAEvent::AUDIO
play an audio file
Definition: kaevent.h:262
KAlarmCal::KAEvent::NO_OCCURRENCE
no occurrence is due
Definition: kaevent.h:268
KAlarmCal::KAEvent::ExecPreActOnDeferral
execute pre-alarm action also for deferred alarms
Definition: kaevent.h:325
KAlarmCal::KAEvent::CmdErrType
CmdErrType
Command execution error type for last time the alarm was triggered.
Definition: kaevent.h:309
KAlarmCal::KAEvent::setFirstRecurrence
void setFirstRecurrence()
Adjust the event date/time to the first recurrence of the event, on or after the event start date/tim...
Definition: kaevent.cpp:3238
KAlarmCal::KAEvent::WORK_TRIGGER
next main working time trigger, excluding reminders
Definition: kaevent.h:303
KAlarmCal::KAAlarm::setTime
void setTime(const DateTime &dt)
Set the alarm's trigger time.
Definition: kaevent.cpp:6200
KAlarmCal::DateTime::isValid
bool isValid() const
Returns true if the date is valid and, if it is a date-time value, the time is also valid...
Definition: datetime.cpp:102
KAlarmCal::KAEvent::RECURRENCE_DATE
a recurrence with only a date, not a time
Definition: kaevent.h:270
KAlarmCal::KAEvent::setAutoClose
void setAutoClose(bool autoclose)
Enable or disable auto-close for a display alarm, i.e.
Definition: kaevent.cpp:2012
KAlarmCal::KAEvent::reminderOnceOnly
bool reminderOnceOnly() const
Return whether the reminder alarm is triggered only for the first recurrence.
Definition: kaevent.cpp:2499
KAlarmCal::KAEvent::displaying
bool displaying() const
Return whether the alarm is currently being displayed, i.e.
Definition: kaevent.cpp:3781
KAlarmCal::KAEvent::SPEAK
speak the message when the alarm is displayed
Definition: kaevent.h:230
KAlarmCal::KAEvent::deferDefaultMinutes
int deferDefaultMinutes() const
Return the default deferral interval used in the deferral dialog.
Definition: kaevent.cpp:2738
KAlarmCal::KAEvent::commandScript
bool commandScript() const
Return whether a command script is specified, for a command alarm.
Definition: kaevent.cpp:2083
KAlarmCal::KAAlarm::AUDIO
KCal::Alarm::Audio type: play a sound file.
Definition: kaevent.h:87
KAlarmCal::KAEvent::ACT_COMMAND
the alarm executes a command
Definition: kaevent.h:248
KAlarmCal::KAEvent::enabled
bool enabled() const
Return the enabled status of the alarm.
Definition: kaevent.cpp:1794
KCalCore::Person::email
QString email() const
KAlarmCal::KAEvent::id
QString id() const
Return the event's unique identifier.
Definition: kaevent.cpp:1888
KAlarmCal::KAEvent::BEEP
sound an audible beep when the alarm is displayed
Definition: kaevent.h:219
KAlarmCal::KAEvent::occursAfter
bool occursAfter(const KDateTime &preDateTime, bool includeRepetitions) const
Determine whether the event will occur after the specified date/time.
Definition: kaevent.cpp:3403
KAlarmCal::KAEvent::setArchive
void setArchive()
Set the event to be archived when it expires or is deleted.
Definition: kaevent.cpp:1811
KAlarmCal::KAEvent::repeatAtLogin
bool repeatAtLogin(bool includeArchived=false) const
Return whether the alarm repeats at login.
Definition: kaevent.cpp:2864
KAlarmCal::KAEvent::TriggerType
TriggerType
Alarm trigger type.
Definition: kaevent.h:299
KAlarmCal::KAEvent::ANY_TIME
only a date is specified for the alarm, not a time
Definition: kaevent.h:221
KAlarmCal::KAEvent::reminderMinutes
int reminderMinutes() const
Return the number of minutes BEFORE the main alarm when a reminder alarm is set.
Definition: kaevent.cpp:2489
KAlarmCal::KAEvent::RECURRENCE_DATE_TIME
a recurrence with a date and time
Definition: kaevent.h:271
KAlarmCal::KAEvent::useDefaultFont
bool useDefaultFont() const
Return whether to use the default font (as set by setDefaultFont()) for alarm message texts...
Definition: kaevent.cpp:2068
KAlarmCal::KAEvent::incrementRevision
void incrementRevision()
Increment the revision number of the event (SEQUENCE property in iCalendar).
Definition: kaevent.cpp:1893
KAlarmCal::KAEvent::startDateTime
DateTime startDateTime() const
Return the start time for the event.
Definition: kaevent.cpp:2748
KAlarmCal::KAEvent::CONFIRM_ACK
closing the alarm message window requires a confirmation prompt
Definition: kaevent.h:222
KAlarmCal::DateTime::isDateOnly
bool isDateOnly() const
Returns true if it is date-only value.
Definition: datetime.cpp:107
KCalCore::Alarm::setTime
void setTime(const KDateTime &alarmTime)
KAlarmCal::KAEvent::setCompatibility
void setCompatibility(KACalendar::Compat c)
Note the event's storage format compatibility compared to the current KAlarm calendar format...
Definition: kaevent.cpp:1953
KAlarmCal::KAAlarm::repeatAtLogin
bool repeatAtLogin() const
Return whether this is a repeat-at-login alarm.
Definition: kaevent.cpp:6180
KHolidays
KAlarmCal
Definition: alarmtext.cpp:43
KAlarmCal::KAEvent::audioFile
QString audioFile() const
Return the audio file path.
Definition: kaevent.cpp:2305
KAlarmCal::KAEvent::convertKCalEvents
static bool convertKCalEvents(const KCalCore::Calendar::Ptr &, int calendarVersion)
If a calendar was written by a previous version of KAlarm, do any necessary format conversions on the...
Definition: kaevent.cpp:5233
KCalCore::Alarm::setStartOffset
void setStartOffset(const Duration &offset)
KAlarmCal::KAAlarm::timedDeferral
bool timedDeferral() const
Return whether in the case of a deferred alarm, it is timed (as opposed to date-only).
Definition: kaevent.cpp:6195
KCalCore::RecurrenceRule::PeriodType
PeriodType
KAlarmCal::KAEvent::extraActionOptions
ExtraActionOptions extraActionOptions() const
Return the pre- and post-alarm action options.
Definition: kaevent.cpp:2405
KAlarmCal::KAEvent::FIRST_OR_ONLY_OCCURRENCE
the first occurrence (takes precedence over LAST_RECURRENCE)
Definition: kaevent.h:269
KAlarmCal::KAAlarm::KAAlarm
KAAlarm()
Default constructor, which creates an invalid instance.
Definition: kaevent.cpp:6118
KAlarmCal::KAAlarm::FILE
KCal::Alarm::Display type: display a file (URL given by the alarm text)
Definition: kaevent.h:84
KAlarmCal::KAEvent::UID_CHECK
verify that the KCal::Event UID is already the same as the KAEvent ID, if the latter is non-empty ...
Definition: kaevent.h:333
KAlarmCal::KAEvent::REPEAT_AT_LOGIN
repeat the alarm at every login
Definition: kaevent.h:220
KCalCore::Calendar::Ptr
QSharedPointer< Calendar > Ptr
KAlarmCal::KAEvent::ALL_WORK_TRIGGER
next actual working time trigger, including reminders
Definition: kaevent.h:304
KAlarmCal::KAEvent::soundVolume
float soundVolume() const
Return the sound volume (the final volume if fade is specified).
Definition: kaevent.cpp:2310
KCalCore::Duration::value
int value() const
KAlarmCal::KAEvent::removeExpiredAlarm
void removeExpiredAlarm(KAAlarm::Type type)
Remove the alarm of the specified type from the event.
Definition: kaevent.cpp:3944
KAlarmCal::KAEvent::activateReminderAfter
void activateReminderAfter(const DateTime &mainAlarmTime)
If there is a reminder which occurs AFTER the main alarm, activate the event's reminder which occurs ...
Definition: kaevent.cpp:2451
if
if(recurs()&&!first)
KAlarmCal::KAEvent::setCollectionId
void setCollectionId(Akonadi::Collection::Id id)
Set the ID of the Akonadi Collection which contains the event.
Definition: kaevent.cpp:1904
KAlarmCal::KAAlarm::date
QDate date() const
Return the trigger date for the alarm.
Definition: kaevent.cpp:6170
KAlarmCal::KAEvent::defer
void defer(const DateTime &dt, bool reminder, bool adjustRecurrence=false)
Defer the event to the specified time.
Definition: kaevent.cpp:2515
KAlarmCal::KAEvent::joinEmailAddresses
static QString joinEmailAddresses(const KCalCore::Person::List &addresses, const QString &sep)
Concatenate a list of email addresses into a string.
Definition: kaevent.cpp:2245
KAlarmCal::KAEvent::setItemId
void setItemId(Akonadi::Item::Id id)
Set the ID of the Akonadi Item which contains the event.
Definition: kaevent.cpp:1920
KAlarmCal::KAEvent::OccurOption
OccurOption
How to treat sub-repetitions in nextOccurrence().
Definition: kaevent.h:281
KAlarmCal::Repetition::nextRepeatCount
int nextRepeatCount(const KDateTime &from, const KDateTime &preDateTime) const
Find the repetition count for the next repetition after a specified time.
Definition: repetition.cpp:154
KAlarmCal::KAEvent::FILE
display the contents of a file
Definition: kaevent.h:259
KAlarmCal::KAEvent::setTemplate
void setTemplate(const QString &name, int afterTime=-1)
Set the event to be an alarm template.
Definition: kaevent.cpp:2350
KAlarmCal::KAEvent::setStartOfDay
static void setStartOfDay(const QTime &)
Set the start-of-day time used by all date-only alarms.
Definition: kaevent.cpp:2777
KCalCore::Alarm::setAudioAlarm
void setAudioAlarm(const QString &audioFile=QString())
KAlarmCal::KAAlarm::DISPLAYING_ALARM
Copy of the alarm currently being displayed.
Definition: kaevent.h:104
KAlarmCal::KAEvent::EMAIL
send an email
Definition: kaevent.h:261
KAlarmCal::KAEvent::UID_SET
set the KCal::Event UID to the KAEvent ID
Definition: kaevent.h:334
KAlarmCal::KACalendar::Current
in current KAlarm format
Definition: kacalendar.h:74
KCalCore::Recurrence::setMinutely
void setMinutely(int freq)
KCalCore::Person::Ptr
QSharedPointer< Person > Ptr
KAlarmCal::Identities::identityUoid
uint identityUoid(const QString &identityUoidOrName)
Fetch the uoid of an identity name or uoid string.
Definition: identities.cpp:54
KAlarmCal::KAAlarm::EMAIL
KCal::Alarm::Email type: send an email.
Definition: kaevent.h:86
KAlarmCal::KAEvent::CMD_ERROR
command alarm execution failed
Definition: kaevent.h:312
KCalCore::Alarm::type
Type type() const
KAlarmCal::KAEvent::isReadOnly
bool isReadOnly() const
Return the read-only status of the alarm.
Definition: kaevent.cpp:1805
KAlarmCal::KAEvent::emailPureAddresses
QStringList emailPureAddresses() const
Return the list of email addressees, excluding names, for an email alarm.
Definition: kaevent.cpp:2253
KAlarmCal::KAEvent::fileName
QString fileName() const
Return the path of the file whose contents are to be shown, for a display alarm.
Definition: kaevent.cpp:2048
KAlarmCal::CalEvent::EMPTY
the event has no alarms
Definition: kacalendar.h:157
KAlarmCal::KAEvent::nextAlarm
KAAlarm nextAlarm(const KAAlarm &previousAlarm) const
Return the next alarm for the event, after the specified alarm.
Definition: kaevent.cpp:3891
KAlarmCal::KAEvent::repetition
Repetition repetition() const
Return the event's sub-repetition data.
Definition: kaevent.cpp:3363
KAlarmCal::KAEvent::commandDisplay
bool commandDisplay() const
Return whether the command output is to be displayed in an alarm message window.
Definition: kaevent.cpp:2093
KAlarmCal::KAEvent::emailMessage
QString emailMessage() const
Return the email message body, for an email alarm.
Definition: kaevent.cpp:2215
KAlarmCal::KAEvent::OccurType
OccurType
What type of occurrence is due.
Definition: kaevent.h:266
KAlarmCal::DateTime::kDateTime
KDateTime kDateTime() const
Returns the date and time of the value as a KDateTime.
Definition: datetime.cpp:132
KAlarmCal::KAEvent
KAEvent represents a KAlarm event.
Definition: kaevent.h:210
KCalCore::Event
KAlarmCal::KAEvent::adjustStartOfDay
static void adjustStartOfDay(const KAEvent::List &events)
Call when the user changes the start-of-day time, to adjust the data for each date-only event in a li...
Definition: kaevent.cpp:2790
KAlarmCal::KAEvent::autoClose
bool autoClose() const
Return whether auto-close is enabled, i.e.
Definition: kaevent.cpp:2017
KAlarmCal::KAEvent::DEFAULT_FONT
use the default alarm message font
Definition: kaevent.h:224
KAlarmCal::KAEvent::setActions
void setActions(const QString &pre, const QString &post, ExtraActionOptions options)
Set the pre-alarm and post-alarm actions, and their options.
Definition: kaevent.cpp:2378
KAlarmCal::KAEvent::actionSubType
SubAction actionSubType() const
Return the action sub-type of the event's main alarm.
Definition: kaevent.cpp:1980
KAlarmCal::KAEvent::recurrenceText
QString recurrenceText(bool brief=false) const
Return the recurrence interval as text suitable for display.
Definition: kaevent.cpp:3284
KCalCore::Alarm::time
KDateTime time() const
KAlarmCal::KAEvent::LAST_RECURRENCE
the last recurrence
Definition: kaevent.h:272
KAlarmCal::KAEvent::LIMIT_MAIN
the main alarm
Definition: kaevent.h:292
KAlarmCal::KAEvent::UidAction
UidAction
How to deal with the event UID in updateKCalEvent().
Definition: kaevent.h:330
KAlarmCal::KAEvent::EXEC_IN_XTERM
execute the command in a terminal window
Definition: kaevent.h:229
KAlarmCal::KAEvent::emailAddresses
QStringList emailAddresses() const
Return a list of the email addresses, including names, for an email alarm.
Definition: kaevent.cpp:2234
KAlarmCal::KAEvent::setEmail
void setEmail(uint from, const KCalCore::Person::List &, const QString &subject, const QStringList &attachments)
Set the email related data for the event.
Definition: kaevent.cpp:2202
KAlarmCal::KAEvent::setRecurAnnualByPos
bool setRecurAnnualByPos(int freq, const QVector< MonthPos > &pos, const QVector< int > &months, int count, const QDate &end)
Set the recurrence to recur annually, on the specified weekdays in the specified weeks of the specifi...
Definition: kaevent.cpp:3144
KAlarmCal::KAEvent::mainExpired
bool mainExpired() const
Return whether the event's main alarm has expired.
Definition: kaevent.cpp:1821
KAlarmCal::KAEvent::Actions
Actions
The basic action type(s) for the event's main alarm.
Definition: kaevent.h:244
KAlarmCal::KAEvent::DISPLAY_COMMAND
display command output in the alarm window
Definition: kaevent.h:234
KAlarmCal::KAEvent::templateAfterTime
int templateAfterTime() const
Return the number of minutes (>= 0) after the default alarm time which is specified in the alarm temp...
Definition: kaevent.cpp:2373
KAlarmCal::Repetition::isDaily
bool isDaily() const
Check whether the repetition interval is in terms of days (as opposed to minutes).
Definition: repetition.cpp:134
KAlarmCal::KAEvent::category
CalEvent::Type category() const
Return the alarm category (active/archived/template, or displaying).
Definition: kaevent.cpp:1878
KAlarmCal::KAAlarm::AT_LOGIN_ALARM
Additional repeat-at-login trigger.
Definition: kaevent.h:103
KAlarmCal::KAEvent::setEnabled
void setEnabled(bool enable)
Enable or disable the alarm.
Definition: kaevent.cpp:1789
KAlarmCal::KAEvent::deferred
bool deferred() const
Return whether there is currently a deferred alarm pending.
Definition: kaevent.cpp:2670
KAlarmCal::KAEvent::copyToKOrganizer
bool copyToKOrganizer() const
Return whether KOrganizer should hold a copy of the event.
Definition: kaevent.cpp:2196
KAlarmCal::KARecurrence::MONTHLY_POS
monthly, on specified weekdays in a specified week of the month
Definition: karecurrence.h:73
KAlarmCal::KAEvent::workTimeOnly
bool workTimeOnly() const
Return whether the alarm is disabled on non-working days and outside working hours.
Definition: kaevent.cpp:2900
KAlarmCal::KAEvent::emailFromId
uint emailFromId() const
Return the email identity to be used as the sender, for an email alarm.
Definition: kaevent.cpp:2220
KAlarmCal::KAEvent::LIMIT_REPETITION
a sub-repetition
Definition: kaevent.h:294
KCalCore::Alarm::repeatCount
int repeatCount() const
KAlarmCal::KAEvent::command
QString command() const
Return the command or script to execute, for a command alarm.
Definition: kaevent.cpp:2078
KAlarmCal::KAEvent::setTime
void setTime(const KDateTime &dt)
Set the next time to trigger the alarm (excluding sub-repetitions).
Definition: kaevent.cpp:2753
KAlarmCal::KAEvent::usingDefaultTime
bool usingDefaultTime() const
Return whether the alarm template does not specify a time.
Definition: kaevent.cpp:2368
KAlarmCal::KAEvent::setItemPayload
bool setItemPayload(Akonadi::Item &, const QStringList &collectionMimeTypes) const
Initialise an Akonadi::Item with the event's data.
Definition: kaevent.cpp:1936
KCalCore::Duration::asDays
int asDays() const
KAlarmCal::KAAlarm::COMMAND
KCal::Alarm::Procedure type: execute a shell command.
Definition: kaevent.h:85
KCalCore::Alarm::setDisplayAlarm
void setDisplayAlarm(const QString &text=QString())
KAlarmCal::KAEvent::RETURN_REPETITION
return a sub-repetition if it's the next occurrence
Definition: kaevent.h:284
KAlarmCal::KAEvent::expired
bool expired() const
Return whether the event has expired.
Definition: kaevent.cpp:1826
KAlarmCal::KAEvent::setCategory
void setCategory(CalEvent::Type type)
Set the alarm category (active/archived/template, or displaying).
Definition: kaevent.cpp:1864
KAlarmCal::KAEvent::collectionId
Akonadi::Collection::Id collectionId() const
Return the ID of the Akonadi Collection which contains the event.
Definition: kaevent.cpp:1914
KAlarmCal::KAAlarm::~KAAlarm
~KAAlarm()
Destructor.
Definition: kaevent.cpp:6136
KAlarmCal::KAEvent::setCollectionId_const
void setCollectionId_const(Akonadi::Collection::Id id) const
Set the ID of the Akonadi Collection which contains the event.
Definition: kaevent.cpp:1909
KCalCore::Alarm::mailText
QString mailText() const
KAlarmCal::KAEvent::updateKCalEvent
bool updateKCalEvent(const KCalCore::Event::Ptr &event, UidAction u, bool setCustomProperties=true) const
Update an existing KCalCore::Event with the KAEvent data.
Definition: kaevent.cpp:1339
KAlarmCal::KAEvent::reminderActive
bool reminderActive() const
Return whether a reminder is currently due (before the next, or after the last, main alarm/recurrence...
Definition: kaevent.cpp:2494
KCalCore::Duration::asSeconds
int asSeconds() const
KAlarmCal::KAEvent::OCCURRENCE_REPEAT
(bitmask for a sub-repetition of an occurrence)
Definition: kaevent.h:273
KAlarmCal::KAEvent::setWorkTimeOnly
void setWorkTimeOnly(bool wto)
Enable or disable the alarm on non-working days and outside working hours.
Definition: kaevent.cpp:2893
KAlarmCal::KAEvent::customProperties
QMap< QByteArray, QString > customProperties() const
Return the original KCalCore::Event's custom properties in the source calendar.
Definition: kaevent.cpp:1963
KAlarmCal::KAEvent::nextRepetition
int nextRepetition() const
Return the count of the next sub-repetition which is due.
Definition: kaevent.cpp:3368
KAlarmCal::KARecurrence::MINUTELY
at an hours/minutes interval
Definition: karecurrence.h:70
KAlarmCal::CalEvent::ARCHIVED
the event is archived
Definition: kacalendar.h:159
KAlarmCal::KAEvent::setRecurWeekly
bool setRecurWeekly(int freq, const QBitArray &days, int count, const QDate &end)
Set the recurrence to recur weekly, on the specified weekdays.
Definition: kaevent.cpp:3047
KAlarmCal::KAEvent::createdDateTime
KDateTime createdDateTime() const
Return the date/time the event was created, or saved in the archive calendar.
Definition: kaevent.cpp:2825
KAlarmCal::DateTime::setDateOnly
void setDateOnly(bool d)
Sets the value to be either date-only or date-time.
Definition: datetime.cpp:112
KCalCore::Alarm::programArguments
QString programArguments() const
KAlarmCal::KAEvent::DontShowPreActError
do not notify pre-alarm action errors to user
Definition: kaevent.h:324
KAlarmCal::KAEvent::displayMessage
QString displayMessage() const
Return the message text for a display alarm.
Definition: kaevent.cpp:2043
KAlarmCal::KAEvent::commandXterm
bool commandXterm() const
Return whether to execute the command in a terminal window, for a command alarm.
Definition: kaevent.cpp:2088
KAlarmCal::KAEvent::SubAction
SubAction
The sub-action type for the event's main alarm.
Definition: kaevent.h:256
KAlarmCal::DateTime
As KDateTime, but with a configurable start-of-day time for date-only values.
Definition: datetime.h:42
KCalCore::Recurrence::recurs
bool recurs() const
KAlarmCal::KAEvent::ALL_TRIGGER
next trigger, including reminders, ignoring working hours & holidays
Definition: kaevent.h:301
KAlarmCal::Repetition::set
void set(const KCalCore::Duration &interval, int count)
Initialises the instance with the specified interval and count.
Definition: repetition.cpp:80
KAlarmCal::KARecurrence::MONTHLY_DAY
monthly, on a specified day of the month
Definition: karecurrence.h:74
KAlarmCal::Repetition::intervalDays
int intervalDays() const
Return the repetition interval in terms of days.
Definition: repetition.cpp:139
KAlarmCal::KAEvent::cleanText
QString cleanText() const
Return the alarm's text.
Definition: kaevent.cpp:2032
KCalCore::Alarm::audioFile
QString audioFile() const
KAlarmCal::KAEvent::reinstateFromDisplaying
void reinstateFromDisplaying(const KCalCore::Event::Ptr &event, Akonadi::Collection::Id &colId, bool &showEdit, bool &showDefer)
Reinstate the original event from the 'displaying' event.
Definition: kaevent.cpp:3719
KAlarmCal::KAEvent::MESSAGE
display a message text
Definition: kaevent.h:258
KAlarmCal::KAEvent::bgColour
QColor bgColour() const
Return the message window background color, for a display alarm.
Definition: kaevent.cpp:2053
KAlarmCal::KAEvent::deferralLimit
DateTime deferralLimit(DeferLimitType *limitType=0) const
Return the latest time which the alarm can currently be deferred to.
Definition: kaevent.cpp:2683
KAlarmCal::KAEvent::ptrList
static List ptrList(QVector< KAEvent > &events)
Return a list of pointers to a list of KAEvent objects.
Definition: kaevent.cpp:4028
KAlarmCal::KAEvent::preAction
QString preAction() const
Return the shell command to execute before the alarm is displayed.
Definition: kaevent.cpp:2395
KAlarmCal::KAEvent::recurType
KARecurrence::Type recurType() const
Return the recurrence period type for the event.
Definition: kaevent.cpp:3194
KAlarmCal::KAEvent::repeatSoundPause
int repeatSoundPause() const
Return how many seconds to pause between repetitions of the sound file.
Definition: kaevent.cpp:2330
KAlarmCal::CalEvent::types
Types types(const QStringList &mimeTypes)
Return the alarm Types for a list of mime type strings.
Definition: kacalendar.cpp:480
KAlarmCal::KAEvent::MAIN_TRIGGER
next trigger, excluding reminders, ignoring working hours & holidays
Definition: kaevent.h:302
KCalCore::Alarm::programFile
QString programFile() const
KCalCore::Recurrence::setDaily
void setDaily(int freq)
KAlarmCal::KAEvent::COPY_KORGANIZER
KOrganizer should hold a copy of the event.
Definition: kaevent.h:231
KCalCore::RecurrenceRule
KAlarmCal::KAEvent::reminderDeferral
bool reminderDeferral() const
Return whether there is currently a deferred reminder alarm pending.
Definition: kaevent.cpp:2504
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Sun Apr 26 2015 12:45:50 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KAlarm Library

Skip menu "KAlarm Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.14.7 API Reference

Skip menu "kdepimlibs-4.14.7 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal