27 #include "alarmcalendar.h"
32 #include "karecurrence.h"
34 #include "preferences.h"
35 #include "dcophandler.h"
36 #include "dcophandler.moc"
38 static const char* DCOP_OBJECT_NAME = "request";
45 DcopHandler::DcopHandler()
46 : DCOPObject(DCOP_OBJECT_NAME),
49 kdDebug(5950) << "DcopHandler::DcopHandler()\n";
53 bool DcopHandler::cancelEvent( const TQString& url, const TQString& eventId)
55 return theApp()->deleteEvent(url, eventId);
58 bool DcopHandler::triggerEvent( const TQString& url, const TQString& eventId)
60 return theApp()->triggerEvent(url, eventId);
63 bool DcopHandler::scheduleMessage( const TQString& message, const TQString& startDateTime, int lateCancel, unsigned flags,
64 const TQString& bgColor, const TQString& fgColor, const TQString& font,
65 const KURL& audioFile, int reminderMins, const TQString& recurrence,
66 int subRepeatInterval, int subRepeatCount)
70 if (!convertRecurrence(start, recur, startDateTime, recurrence, subRepeatInterval))
72 return scheduleMessage(message, start, lateCancel, flags, bgColor, fgColor, font, audioFile, reminderMins, recur, subRepeatInterval, subRepeatCount);
75 bool DcopHandler::scheduleMessage( const TQString& message, const TQString& startDateTime, int lateCancel, unsigned flags,
76 const TQString& bgColor, const TQString& fgColor, const TQString& font,
77 const KURL& audioFile, int reminderMins,
78 int recurType, int recurInterval, int recurCount)
82 if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, recurCount))
84 return scheduleMessage(message, start, lateCancel, flags, bgColor, fgColor, font, audioFile, reminderMins, recur);
87 bool DcopHandler::scheduleMessage( const TQString& message, const TQString& startDateTime, int lateCancel, unsigned flags,
88 const TQString& bgColor, const TQString& fgColor, const TQString& font,
89 const KURL& audioFile, int reminderMins,
90 int recurType, int recurInterval, const TQString& endDateTime)
94 if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, endDateTime))
96 return scheduleMessage(message, start, lateCancel, flags, bgColor, fgColor, font, audioFile, reminderMins, recur);
99 bool DcopHandler::scheduleFile( const KURL& file, const TQString& startDateTime, int lateCancel, unsigned flags, const TQString& bgColor,
100 const KURL& audioFile, int reminderMins, const TQString& recurrence,
101 int subRepeatInterval, int subRepeatCount)
105 if (!convertRecurrence(start, recur, startDateTime, recurrence, subRepeatInterval))
107 return scheduleFile(file, start, lateCancel, flags, bgColor, audioFile, reminderMins, recur, subRepeatInterval, subRepeatCount);
110 bool DcopHandler::scheduleFile( const KURL& file, const TQString& startDateTime, int lateCancel, unsigned flags, const TQString& bgColor,
111 const KURL& audioFile, int reminderMins, int recurType, int recurInterval, int recurCount)
115 if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, recurCount))
117 return scheduleFile(file, start, lateCancel, flags, bgColor, audioFile, reminderMins, recur);
120 bool DcopHandler::scheduleFile( const KURL& file, const TQString& startDateTime, int lateCancel, unsigned flags, const TQString& bgColor,
121 const KURL& audioFile, int reminderMins, int recurType, int recurInterval, const TQString& endDateTime)
125 if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, endDateTime))
127 return scheduleFile(file, start, lateCancel, flags, bgColor, audioFile, reminderMins, recur);
130 bool DcopHandler::scheduleCommand( const TQString& commandLine, const TQString& startDateTime, int lateCancel, unsigned flags,
131 const TQString& recurrence, int subRepeatInterval, int subRepeatCount)
135 if (!convertRecurrence(start, recur, startDateTime, recurrence, subRepeatInterval))
137 return scheduleCommand(commandLine, start, lateCancel, flags, recur, subRepeatInterval, subRepeatCount);
140 bool DcopHandler::scheduleCommand( const TQString& commandLine, const TQString& startDateTime, int lateCancel, unsigned flags,
141 int recurType, int recurInterval, int recurCount)
143 DateTime start = convertStartDateTime(startDateTime);
144 if (!start.isValid())
147 if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, recurCount))
149 return scheduleCommand(commandLine, start, lateCancel, flags, recur);
152 bool DcopHandler::scheduleCommand( const TQString& commandLine, const TQString& startDateTime, int lateCancel, unsigned flags,
153 int recurType, int recurInterval, const TQString& endDateTime)
157 if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, endDateTime))
159 return scheduleCommand(commandLine, start, lateCancel, flags, recur);
162 bool DcopHandler::scheduleEmail( const TQString& fromID, const TQString& addresses, const TQString& subject, const TQString& message,
163 const TQString& attachments, const TQString& startDateTime, int lateCancel, unsigned flags,
164 const TQString& recurrence, int subRepeatInterval, int subRepeatCount)
168 if (!convertRecurrence(start, recur, startDateTime, recurrence, subRepeatInterval))
170 return scheduleEmail(fromID, addresses, subject, message, attachments, start, lateCancel, flags, recur, subRepeatInterval, subRepeatCount);
173 bool DcopHandler::scheduleEmail( const TQString& fromID, const TQString& addresses, const TQString& subject, const TQString& message,
174 const TQString& attachments, const TQString& startDateTime, int lateCancel, unsigned flags,
175 int recurType, int recurInterval, int recurCount)
179 if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, recurCount))
181 return scheduleEmail(fromID, addresses, subject, message, attachments, start, lateCancel, flags, recur);
184 bool DcopHandler::scheduleEmail( const TQString& fromID, const TQString& addresses, const TQString& subject, const TQString& message,
185 const TQString& attachments, const TQString& startDateTime, int lateCancel, unsigned flags,
186 int recurType, int recurInterval, const TQString& endDateTime)
190 if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, endDateTime))
192 return scheduleEmail(fromID, addresses, subject, message, attachments, start, lateCancel, flags, recur);
195 bool DcopHandler::edit( const TQString& eventID)
197 return KAlarm::edit(eventID);
200 bool DcopHandler::editNew( const TQString& templateName)
202 return KAlarm::editNew(templateName);
209 bool DcopHandler::scheduleMessage( const TQString& message, const DateTime& start, int lateCancel, unsigned flags,
210 const TQString& bgColor, const TQString& fgColor, const TQString& fontStr,
211 const KURL& audioFile, int reminderMins, const KARecurrence& recurrence,
212 int subRepeatInterval, int subRepeatCount)
214 unsigned kaEventFlags = convertStartFlags(start, flags);
215 TQColor bg = convertBgColour(bgColor);
219 if (fgColor.isEmpty())
220 fg = Preferences::defaultFgColour();
223 fg.setNamedColor(fgColor);
226 kdError(5950) << "DCOP call: invalid foreground color: " << fgColor << endl;
231 if (fontStr.isEmpty())
232 kaEventFlags |= KAEvent::DEFAULT_FONT;
235 if (!font.fromString(fontStr))
237 kdError(5950) << "DCOP call: invalid font: " << fontStr << endl;
241 return theApp()->scheduleEvent(KAEvent::MESSAGE, message, start.dateTime(), lateCancel, kaEventFlags, bg, fg, font,
242 audioFile.url(), -1, reminderMins, recurrence, subRepeatInterval, subRepeatCount);
248 bool DcopHandler::scheduleFile( const KURL& file,
249 const DateTime& start, int lateCancel, unsigned flags, const TQString& bgColor,
250 const KURL& audioFile, int reminderMins, const KARecurrence& recurrence,
251 int subRepeatInterval, int subRepeatCount)
253 unsigned kaEventFlags = convertStartFlags(start, flags);
254 TQColor bg = convertBgColour(bgColor);
257 return theApp()->scheduleEvent(KAEvent::FILE, file.url(), start.dateTime(), lateCancel, kaEventFlags, bg, TQt::black, TQFont(),
258 audioFile.url(), -1, reminderMins, recurrence, subRepeatInterval, subRepeatCount);
264 bool DcopHandler::scheduleCommand( const TQString& commandLine,
265 const DateTime& start, int lateCancel, unsigned flags,
266 const KARecurrence& recurrence, int subRepeatInterval, int subRepeatCount)
268 unsigned kaEventFlags = convertStartFlags(start, flags);
269 return theApp()->scheduleEvent(KAEvent::COMMAND, commandLine, start.dateTime(), lateCancel, kaEventFlags, TQt::black, TQt::black, TQFont(),
270 TQString(), -1, 0, recurrence, subRepeatInterval, subRepeatCount);
276 bool DcopHandler::scheduleEmail( const TQString& fromID, const TQString& addresses, const TQString& subject,
277 const TQString& message, const TQString& attachments,
278 const DateTime& start, int lateCancel, unsigned flags,
279 const KARecurrence& recurrence, int subRepeatInterval, int subRepeatCount)
281 unsigned kaEventFlags = convertStartFlags(start, flags);
283 if (!fromID.isEmpty())
285 senderId = KAMail::identityUoid(fromID);
288 kdError(5950) << "DCOP call scheduleEmail(): unknown sender ID: " << fromID << endl;
292 EmailAddressList addrs;
293 TQString bad = KAMail::convertAddresses(addresses, addrs);
296 kdError(5950) << "DCOP call scheduleEmail(): invalid email addresses: " << bad << endl;
301 kdError(5950) << "DCOP call scheduleEmail(): no email address\n";
305 bad = KAMail::convertAttachments(attachments, atts);
308 kdError(5950) << "DCOP call scheduleEmail(): invalid email attachment: " << bad << endl;
311 return theApp()->scheduleEvent(KAEvent::EMAIL, message, start.dateTime(), lateCancel, kaEventFlags, TQt::black, TQt::black, TQFont(),
312 TQString(), -1, 0, recurrence, subRepeatInterval, subRepeatCount, senderId, addrs, subject, atts);
320 DateTime DcopHandler::convertStartDateTime( const TQString& startDateTime)
323 if (startDateTime.length() > 10)
326 start = TQDateTime::fromString(startDateTime, TQt::ISODate);
332 if (startDateTime[0] == 'T')
333 t = startDateTime.mid(1);
334 else if (!startDateTime[2].isDigit())
340 start = TQDate::fromString(startDateTime, TQt::ISODate);
345 start.set(TQDate::currentDate(), TQTime::fromString(t, TQt::ISODate));
348 if (!start.isValid())
349 kdError(5950) << "DCOP call: invalid start date/time: " << startDateTime << endl;
356 unsigned DcopHandler::convertStartFlags( const DateTime& start, unsigned flags)
358 unsigned kaEventFlags = 0;
359 if (flags & REPEAT_AT_LOGIN) kaEventFlags |= KAEvent::REPEAT_AT_LOGIN;
360 if (flags & BEEP) kaEventFlags |= KAEvent::BEEP;
361 if (flags & SPEAK) kaEventFlags |= KAEvent::SPEAK;
362 if (flags & CONFIRM_ACK) kaEventFlags |= KAEvent::CONFIRM_ACK;
363 if (flags & REPEAT_SOUND) kaEventFlags |= KAEvent::REPEAT_SOUND;
364 if (flags & AUTO_CLOSE) kaEventFlags |= KAEvent::AUTO_CLOSE;
365 if (flags & EMAIL_BCC) kaEventFlags |= KAEvent::EMAIL_BCC;
366 if (flags & SCRIPT) kaEventFlags |= KAEvent::SCRIPT;
367 if (flags & EXEC_IN_XTERM) kaEventFlags |= KAEvent::EXEC_IN_XTERM;
368 if (flags & SHOW_IN_KORG) kaEventFlags |= KAEvent::COPY_KORGANIZER;
369 if (flags & DISABLED) kaEventFlags |= KAEvent::DISABLED;
370 if (start.isDateOnly()) kaEventFlags |= KAEvent::ANY_TIME;
377 TQColor DcopHandler::convertBgColour( const TQString& bgColor)
379 if (bgColor.isEmpty())
380 return Preferences::defaultBgColour();
383 kdError(5950) << "DCOP call: invalid background color: " << bgColor << endl;
387 bool DcopHandler::convertRecurrence(DateTime& start, KARecurrence& recurrence,
388 const TQString& startDateTime, const TQString& icalRecurrence,
389 int& subRepeatInterval)
391 start = convertStartDateTime(startDateTime);
392 if (!start.isValid())
394 if (!recurrence.set(icalRecurrence))
396 if (subRepeatInterval && recurrence.type() == KARecurrence::NO_RECUR)
398 subRepeatInterval = 0;
399 kdWarning(5950) << "DCOP call: no recurrence specified, so sub-repetition ignored" << endl;
404 bool DcopHandler::convertRecurrence(DateTime& start, KARecurrence& recurrence, const TQString& startDateTime,
405 int recurType, int recurInterval, int recurCount)
407 start = convertStartDateTime(startDateTime);
408 if (!start.isValid())
410 return convertRecurrence(recurrence, start, recurType, recurInterval, recurCount, TQDateTime());
413 bool DcopHandler::convertRecurrence(DateTime& start, KARecurrence& recurrence, const TQString& startDateTime,
414 int recurType, int recurInterval, const TQString& endDateTime)
416 start = convertStartDateTime(startDateTime);
417 if (!start.isValid())
420 if (endDateTime.find( 'T') < 0)
422 if (!start.isDateOnly())
424 kdError(5950) << "DCOP call: alarm is date-only, but recurrence end is date/time" << endl;
427 end.setDate(TQDate::fromString(endDateTime, TQt::ISODate));
431 if (start.isDateOnly())
433 kdError(5950) << "DCOP call: alarm is timed, but recurrence end is date-only" << endl;
436 end = TQDateTime::fromString(endDateTime, TQt::ISODate);
440 kdError(5950) << "DCOP call: invalid recurrence end date/time: " << endDateTime << endl;
443 return convertRecurrence(recurrence, start, recurType, recurInterval, 0, end);
446 bool DcopHandler::convertRecurrence(KARecurrence& recurrence, const DateTime& start, int recurType,
447 int recurInterval, int recurCount, const TQDateTime& end)
449 KARecurrence::Type type;
452 case MINUTELY: type = KARecurrence::MINUTELY; break;
453 case DAILY: type = KARecurrence::DAILY; break;
454 case WEEKLY: type = KARecurrence::WEEKLY; break;
455 case MONTHLY: type = KARecurrence::MONTHLY_DAY; break;
456 case YEARLY: type = KARecurrence::ANNUAL_DATE; break;
459 kdError(5950) << "DCOP call: invalid recurrence type: " << recurType << endl;
462 recurrence.set(type, recurInterval, recurCount, start, end);
the KAlarm application object
|