kalarm

dcophandler.cpp

00001 /*
00002  *  dcophandler.cpp  -  handler for DCOP calls by other applications
00003  *  Program:  kalarm
00004  *  Copyright © 2002-2006,2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kalarm.h"
00022 
00023 #include <stdlib.h>
00024 
00025 #include <kdebug.h>
00026 
00027 #include "alarmcalendar.h"
00028 #include "daemon.h"
00029 #include "functions.h"
00030 #include "kalarmapp.h"
00031 #include "kamail.h"
00032 #include "karecurrence.h"
00033 #include "mainwindow.h"
00034 #include "preferences.h"
00035 #include "dcophandler.moc"
00036 
00037 static const char*  DCOP_OBJECT_NAME = "request";   // DCOP name of KAlarm's request interface
00038 #ifdef OLD_DCOP
00039 static const char*  DCOP_OLD_OBJECT_NAME = "display";
00040 #endif
00041 
00042 
00043 /*=============================================================================
00044 = DcopHandler
00045 = This class's function is to handle DCOP requests by other applications.
00046 =============================================================================*/
00047 DcopHandler::DcopHandler()
00048     : DCOPObject(DCOP_OBJECT_NAME),
00049       QWidget()
00050 {
00051     kdDebug(5950) << "DcopHandler::DcopHandler()\n";
00052 }
00053 
00054 
00055 bool DcopHandler::cancelEvent(const QString& url,const QString& eventId)
00056 {
00057     return theApp()->deleteEvent(url, eventId);
00058 }
00059 
00060 bool DcopHandler::triggerEvent(const QString& url,const QString& eventId)
00061 {
00062     return theApp()->triggerEvent(url, eventId);
00063 }
00064 
00065 bool DcopHandler::scheduleMessage(const QString& message, const QString& startDateTime, int lateCancel, unsigned flags,
00066                                   const QString& bgColor, const QString& fgColor, const QString& font,
00067                                   const KURL& audioFile, int reminderMins, const QString& recurrence,
00068                                   int subRepeatInterval, int subRepeatCount)
00069 {
00070     DateTime start;
00071     KARecurrence recur;
00072     if (!convertRecurrence(start, recur, startDateTime, recurrence, subRepeatInterval))
00073         return false;
00074     return scheduleMessage(message, start, lateCancel, flags, bgColor, fgColor, font, audioFile, reminderMins, recur, subRepeatInterval, subRepeatCount);
00075 }
00076 
00077 bool DcopHandler::scheduleMessage(const QString& message, const QString& startDateTime, int lateCancel, unsigned flags,
00078                                   const QString& bgColor, const QString& fgColor, const QString& font,
00079                                   const KURL& audioFile, int reminderMins,
00080                                   int recurType, int recurInterval, int recurCount)
00081 {
00082     DateTime start;
00083     KARecurrence recur;
00084     if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, recurCount))
00085         return false;
00086     return scheduleMessage(message, start, lateCancel, flags, bgColor, fgColor, font, audioFile, reminderMins, recur);
00087 }
00088 
00089 bool DcopHandler::scheduleMessage(const QString& message, const QString& startDateTime, int lateCancel, unsigned flags,
00090                                   const QString& bgColor, const QString& fgColor, const QString& font,
00091                                   const KURL& audioFile, int reminderMins,
00092                                   int recurType, int recurInterval, const QString& endDateTime)
00093 {
00094     DateTime start;
00095     KARecurrence recur;
00096     if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, endDateTime))
00097         return false;
00098     return scheduleMessage(message, start, lateCancel, flags, bgColor, fgColor, font, audioFile, reminderMins, recur);
00099 }
00100 
00101 bool DcopHandler::scheduleFile(const KURL& file, const QString& startDateTime, int lateCancel, unsigned flags, const QString& bgColor,
00102                                const KURL& audioFile, int reminderMins, const QString& recurrence,
00103                                int subRepeatInterval, int subRepeatCount)
00104 {
00105     DateTime start;
00106     KARecurrence recur;
00107     if (!convertRecurrence(start, recur, startDateTime, recurrence, subRepeatInterval))
00108         return false;
00109     return scheduleFile(file, start, lateCancel, flags, bgColor, audioFile, reminderMins, recur, subRepeatInterval, subRepeatCount);
00110 }
00111 
00112 bool DcopHandler::scheduleFile(const KURL& file, const QString& startDateTime, int lateCancel, unsigned flags, const QString& bgColor,
00113                                const KURL& audioFile, int reminderMins, int recurType, int recurInterval, int recurCount)
00114 {
00115     DateTime start;
00116     KARecurrence recur;
00117     if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, recurCount))
00118         return false;
00119     return scheduleFile(file, start, lateCancel, flags, bgColor, audioFile, reminderMins, recur);
00120 }
00121 
00122 bool DcopHandler::scheduleFile(const KURL& file, const QString& startDateTime, int lateCancel, unsigned flags, const QString& bgColor,
00123                                const KURL& audioFile, int reminderMins, int recurType, int recurInterval, const QString& endDateTime)
00124 {
00125     DateTime start;
00126     KARecurrence recur;
00127     if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, endDateTime))
00128         return false;
00129     return scheduleFile(file, start, lateCancel, flags, bgColor, audioFile, reminderMins, recur);
00130 }
00131 
00132 bool DcopHandler::scheduleCommand(const QString& commandLine, const QString& startDateTime, int lateCancel, unsigned flags,
00133                                   const QString& recurrence, int subRepeatInterval, int subRepeatCount)
00134 {
00135     DateTime start;
00136     KARecurrence recur;
00137     if (!convertRecurrence(start, recur, startDateTime, recurrence, subRepeatInterval))
00138         return false;
00139     return scheduleCommand(commandLine, start, lateCancel, flags, recur, subRepeatInterval, subRepeatCount);
00140 }
00141 
00142 bool DcopHandler::scheduleCommand(const QString& commandLine, const QString& startDateTime, int lateCancel, unsigned flags,
00143                                   int recurType, int recurInterval, int recurCount)
00144 {
00145     DateTime start = convertStartDateTime(startDateTime);
00146     if (!start.isValid())
00147         return false;
00148     KARecurrence recur;
00149     if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, recurCount))
00150         return false;
00151     return scheduleCommand(commandLine, start, lateCancel, flags, recur);
00152 }
00153 
00154 bool DcopHandler::scheduleCommand(const QString& commandLine, const QString& startDateTime, int lateCancel, unsigned flags,
00155                                   int recurType, int recurInterval, const QString& endDateTime)
00156 {
00157     DateTime start;
00158     KARecurrence recur;
00159     if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, endDateTime))
00160         return false;
00161     return scheduleCommand(commandLine, start, lateCancel, flags, recur);
00162 }
00163 
00164 bool DcopHandler::scheduleEmail(const QString& fromID, const QString& addresses, const QString& subject, const QString& message,
00165                                 const QString& attachments, const QString& startDateTime, int lateCancel, unsigned flags,
00166                                 const QString& recurrence, int subRepeatInterval, int subRepeatCount)
00167 {
00168     DateTime start;
00169     KARecurrence recur;
00170     if (!convertRecurrence(start, recur, startDateTime, recurrence, subRepeatInterval))
00171         return false;
00172     return scheduleEmail(fromID, addresses, subject, message, attachments, start, lateCancel, flags, recur, subRepeatInterval, subRepeatCount);
00173 }
00174 
00175 bool DcopHandler::scheduleEmail(const QString& fromID, const QString& addresses, const QString& subject, const QString& message,
00176                                 const QString& attachments, const QString& startDateTime, int lateCancel, unsigned flags,
00177                                 int recurType, int recurInterval, int recurCount)
00178 {
00179     DateTime start;
00180     KARecurrence recur;
00181     if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, recurCount))
00182         return false;
00183     return scheduleEmail(fromID, addresses, subject, message, attachments, start, lateCancel, flags, recur);
00184 }
00185 
00186 bool DcopHandler::scheduleEmail(const QString& fromID, const QString& addresses, const QString& subject, const QString& message,
00187                                 const QString& attachments, const QString& startDateTime, int lateCancel, unsigned flags,
00188                                 int recurType, int recurInterval, const QString& endDateTime)
00189 {
00190     DateTime start;
00191     KARecurrence recur;
00192     if (!convertRecurrence(start, recur, startDateTime, recurType, recurInterval, endDateTime))
00193         return false;
00194     return scheduleEmail(fromID, addresses, subject, message, attachments, start, lateCancel, flags, recur);
00195 }
00196 
00197 bool DcopHandler::edit(const QString& eventID)
00198 {
00199     return KAlarm::edit(eventID);
00200 }
00201 
00202 bool DcopHandler::editNew(const QString& templateName)
00203 {
00204     return KAlarm::editNew(templateName);
00205 }
00206 
00207 
00208 /******************************************************************************
00209 * Schedule a message alarm, after converting the parameters from strings.
00210 */
00211 bool DcopHandler::scheduleMessage(const QString& message, const DateTime& start, int lateCancel, unsigned flags,
00212                                   const QString& bgColor, const QString& fgColor, const QString& fontStr,
00213                                   const KURL& audioFile, int reminderMins, const KARecurrence& recurrence,
00214                                   int subRepeatInterval, int subRepeatCount)
00215 {
00216     unsigned kaEventFlags = convertStartFlags(start, flags);
00217     QColor bg = convertBgColour(bgColor);
00218     if (!bg.isValid())
00219         return false;
00220     QColor fg;
00221     if (fgColor.isEmpty())
00222         fg = Preferences::defaultFgColour();
00223     else
00224     {
00225         fg.setNamedColor(fgColor);
00226         if (!fg.isValid())
00227         {
00228             kdError(5950) << "DCOP call: invalid foreground color: " << fgColor << endl;
00229             return false;
00230         }
00231     }
00232     QFont font;
00233     if (fontStr.isEmpty())
00234         kaEventFlags |= KAEvent::DEFAULT_FONT;
00235     else
00236     {
00237         if (!font.fromString(fontStr))    // N.B. this doesn't do good validation
00238         {
00239             kdError(5950) << "DCOP call: invalid font: " << fontStr << endl;
00240             return false;
00241         }
00242     }
00243     return theApp()->scheduleEvent(KAEvent::MESSAGE, message, start.dateTime(), lateCancel, kaEventFlags, bg, fg, font,
00244                                    audioFile.url(), -1, reminderMins, recurrence, subRepeatInterval, subRepeatCount);
00245 }
00246 
00247 /******************************************************************************
00248 * Schedule a file alarm, after converting the parameters from strings.
00249 */
00250 bool DcopHandler::scheduleFile(const KURL& file,
00251                                const DateTime& start, int lateCancel, unsigned flags, const QString& bgColor,
00252                                const KURL& audioFile, int reminderMins, const KARecurrence& recurrence,
00253                                int subRepeatInterval, int subRepeatCount)
00254 {
00255     unsigned kaEventFlags = convertStartFlags(start, flags);
00256     QColor bg = convertBgColour(bgColor);
00257     if (!bg.isValid())
00258         return false;
00259     return theApp()->scheduleEvent(KAEvent::FILE, file.url(), start.dateTime(), lateCancel, kaEventFlags, bg, Qt::black, QFont(),
00260                                    audioFile.url(), -1, reminderMins, recurrence, subRepeatInterval, subRepeatCount);
00261 }
00262 
00263 /******************************************************************************
00264 * Schedule a command alarm, after converting the parameters from strings.
00265 */
00266 bool DcopHandler::scheduleCommand(const QString& commandLine,
00267                                   const DateTime& start, int lateCancel, unsigned flags,
00268                                   const KARecurrence& recurrence, int subRepeatInterval, int subRepeatCount)
00269 {
00270     unsigned kaEventFlags = convertStartFlags(start, flags);
00271     return theApp()->scheduleEvent(KAEvent::COMMAND, commandLine, start.dateTime(), lateCancel, kaEventFlags, Qt::black, Qt::black, QFont(),
00272                                    QString::null, -1, 0, recurrence, subRepeatInterval, subRepeatCount);
00273 }
00274 
00275 /******************************************************************************
00276 * Schedule an email alarm, after validating the addresses and attachments.
00277 */
00278 bool DcopHandler::scheduleEmail(const QString& fromID, const QString& addresses, const QString& subject,
00279                                 const QString& message, const QString& attachments,
00280                                 const DateTime& start, int lateCancel, unsigned flags,
00281                                 const KARecurrence& recurrence, int subRepeatInterval, int subRepeatCount)
00282 {
00283     unsigned kaEventFlags = convertStartFlags(start, flags);
00284     uint senderId = 0;
00285     if (!fromID.isEmpty())
00286     {
00287         senderId = KAMail::identityUoid(fromID);
00288         if (!senderId)
00289         {
00290             kdError(5950) << "DCOP call scheduleEmail(): unknown sender ID: " << fromID << endl;
00291             return false;
00292         }
00293     }
00294     EmailAddressList addrs;
00295     QString bad = KAMail::convertAddresses(addresses, addrs);
00296     if (!bad.isEmpty())
00297     {
00298         kdError(5950) << "DCOP call scheduleEmail(): invalid email addresses: " << bad << endl;
00299         return false;
00300     }
00301     if (addrs.isEmpty())
00302     {
00303         kdError(5950) << "DCOP call scheduleEmail(): no email address\n";
00304         return false;
00305     }
00306     QStringList atts;
00307     bad = KAMail::convertAttachments(attachments, atts);
00308     if (!bad.isEmpty())
00309     {
00310         kdError(5950) << "DCOP call scheduleEmail(): invalid email attachment: " << bad << endl;
00311         return false;
00312     }
00313     return theApp()->scheduleEvent(KAEvent::EMAIL, message, start.dateTime(), lateCancel, kaEventFlags, Qt::black, Qt::black, QFont(),
00314                                    QString::null, -1, 0, recurrence, subRepeatInterval, subRepeatCount, senderId, addrs, subject, atts);
00315 }
00316 
00317 
00318 /******************************************************************************
00319 * Convert the start date/time string to a DateTime. The date/time string is in
00320 * the format YYYY-MM-DD[THH:MM[:SS]] or [T]HH:MM[:SS]
00321 */
00322 DateTime DcopHandler::convertStartDateTime(const QString& startDateTime)
00323 {
00324     DateTime start;
00325     if (startDateTime.length() > 10)
00326     {
00327         // Both a date and a time are specified
00328         start = QDateTime::fromString(startDateTime, Qt::ISODate);
00329     }
00330     else
00331     {
00332         // Check whether a time is specified
00333         QString t;
00334         if (startDateTime[0] == 'T')
00335             t = startDateTime.mid(1);     // it's a time: remove the leading 'T'
00336         else if (!startDateTime[2].isDigit())
00337             t = startDateTime;            // it's a time with no leading 'T'
00338 
00339         if (t.isEmpty())
00340         {
00341             // It's a date
00342             start = QDate::fromString(startDateTime, Qt::ISODate);
00343         }
00344         else
00345         {
00346             // It's a time, so use today as the date
00347             start.set(QDate::currentDate(), QTime::fromString(t, Qt::ISODate));
00348         }
00349     }
00350     if (!start.isValid())
00351         kdError(5950) << "DCOP call: invalid start date/time: " << startDateTime << endl;
00352     return start;
00353 }
00354 
00355 /******************************************************************************
00356 * Convert the flag bits to KAEvent flag bits.
00357 */
00358 unsigned DcopHandler::convertStartFlags(const DateTime& start, unsigned flags)
00359 {
00360     unsigned kaEventFlags = 0;
00361     if (flags & REPEAT_AT_LOGIN) kaEventFlags |= KAEvent::REPEAT_AT_LOGIN;
00362     if (flags & BEEP)            kaEventFlags |= KAEvent::BEEP;
00363     if (flags & SPEAK)           kaEventFlags |= KAEvent::SPEAK;
00364     if (flags & CONFIRM_ACK)     kaEventFlags |= KAEvent::CONFIRM_ACK;
00365     if (flags & REPEAT_SOUND)    kaEventFlags |= KAEvent::REPEAT_SOUND;
00366     if (flags & AUTO_CLOSE)      kaEventFlags |= KAEvent::AUTO_CLOSE;
00367     if (flags & EMAIL_BCC)       kaEventFlags |= KAEvent::EMAIL_BCC;
00368     if (flags & SCRIPT)          kaEventFlags |= KAEvent::SCRIPT;
00369     if (flags & EXEC_IN_XTERM)   kaEventFlags |= KAEvent::EXEC_IN_XTERM;
00370     if (flags & SHOW_IN_KORG)    kaEventFlags |= KAEvent::COPY_KORGANIZER;
00371     if (flags & DISABLED)        kaEventFlags |= KAEvent::DISABLED;
00372     if (start.isDateOnly())      kaEventFlags |= KAEvent::ANY_TIME;
00373     return kaEventFlags;
00374 }
00375 
00376 /******************************************************************************
00377 * Convert the background colour string to a QColor.
00378 */
00379 QColor DcopHandler::convertBgColour(const QString& bgColor)
00380 {
00381     if (bgColor.isEmpty())
00382         return Preferences::defaultBgColour();
00383     QColor bg(bgColor);
00384     if (!bg.isValid())
00385             kdError(5950) << "DCOP call: invalid background color: " << bgColor << endl;
00386     return bg;
00387 }
00388 
00389 bool DcopHandler::convertRecurrence(DateTime& start, KARecurrence& recurrence, 
00390                                     const QString& startDateTime, const QString& icalRecurrence,
00391                                     int& subRepeatInterval)
00392 {
00393     start = convertStartDateTime(startDateTime);
00394     if (!start.isValid())
00395         return false;
00396     if (!recurrence.set(icalRecurrence))
00397         return false;
00398     if (subRepeatInterval  &&  recurrence.type() == KARecurrence::NO_RECUR)
00399     {
00400         subRepeatInterval = 0;
00401         kdWarning(5950) << "DCOP call: no recurrence specified, so sub-repetition ignored" << endl;
00402     }
00403     return true;
00404 }
00405 
00406 bool DcopHandler::convertRecurrence(DateTime& start, KARecurrence& recurrence, const QString& startDateTime,
00407                                     int recurType, int recurInterval, int recurCount)
00408 {
00409     start = convertStartDateTime(startDateTime);
00410     if (!start.isValid())
00411         return false;
00412     return convertRecurrence(recurrence, start, recurType, recurInterval, recurCount, QDateTime());
00413 }
00414 
00415 bool DcopHandler::convertRecurrence(DateTime& start, KARecurrence& recurrence, const QString& startDateTime,
00416                                     int recurType, int recurInterval, const QString& endDateTime)
00417 {
00418     start = convertStartDateTime(startDateTime);
00419     if (!start.isValid())
00420         return false;
00421     QDateTime end;
00422     if (endDateTime.find('T') < 0)
00423     {
00424         if (!start.isDateOnly())
00425         {
00426             kdError(5950) << "DCOP call: alarm is date-only, but recurrence end is date/time" << endl;
00427             return false;
00428         }
00429         end.setDate(QDate::fromString(endDateTime, Qt::ISODate));
00430     }
00431     else
00432     {
00433         if (start.isDateOnly())
00434         {
00435             kdError(5950) << "DCOP call: alarm is timed, but recurrence end is date-only" << endl;
00436             return false;
00437         }
00438         end = QDateTime::fromString(endDateTime, Qt::ISODate);
00439     }
00440     if (!end.isValid())
00441     {
00442         kdError(5950) << "DCOP call: invalid recurrence end date/time: " << endDateTime << endl;
00443         return false;
00444     }
00445     return convertRecurrence(recurrence, start, recurType, recurInterval, 0, end);
00446 }
00447 
00448 bool DcopHandler::convertRecurrence(KARecurrence& recurrence, const DateTime& start, int recurType,
00449                                     int recurInterval, int recurCount, const QDateTime& end)
00450 {
00451     KARecurrence::Type type;
00452     switch (recurType)
00453     {
00454         case MINUTELY:  type = KARecurrence::MINUTELY;  break;
00455         case DAILY:     type = KARecurrence::DAILY;  break;
00456         case WEEKLY:    type = KARecurrence::WEEKLY;  break;
00457         case MONTHLY:   type = KARecurrence::MONTHLY_DAY;  break;
00458         case YEARLY:    type = KARecurrence::ANNUAL_DATE;  break;
00459             break;
00460         default:
00461             kdError(5950) << "DCOP call: invalid recurrence type: " << recurType << endl;
00462             return false;
00463     }
00464     recurrence.set(type, recurInterval, recurCount, start, end);
00465     return true;
00466 }
00467 
00468 
00469 #ifdef OLD_DCOP
00470 /*=============================================================================
00471 = DcopHandlerOld
00472 = This class's function is simply to act as a receiver for DCOP requests.
00473 =============================================================================*/
00474 DcopHandlerOld::DcopHandlerOld()
00475     : QWidget(),
00476       DCOPObject(DCOP_OLD_OBJECT_NAME)
00477 {
00478     kdDebug(5950) << "DcopHandlerOld::DcopHandlerOld()\n";
00479 }
00480 
00481 /******************************************************************************
00482 * Process a DCOP request.
00483 */
00484 bool DcopHandlerOld::process(const QCString& func, const QByteArray& data, QCString& replyType, QByteArray&)
00485 {
00486     kdDebug(5950) << "DcopHandlerOld::process(): " << func << endl;
00487     enum
00488     {
00489         OPERATION      = 0x0007,    // mask for main operation
00490           HANDLE       = 0x0001,
00491           CANCEL       = 0x0002,
00492           TRIGGER      = 0x0003,
00493           SCHEDULE     = 0x0004,
00494         ALARM_TYPE     = 0x00F0,    // mask for SCHEDULE alarm type
00495           MESSAGE      = 0x0010,
00496           FILE         = 0x0020,
00497           COMMAND      = 0x0030,
00498           EMAIL        = 0x0040,
00499         SCH_FLAGS      = 0x0F00,    // mask for SCHEDULE flags
00500           REP_COUNT    = 0x0100,
00501           REP_END      = 0x0200,
00502           FONT         = 0x0400,
00503         PRE_096        = 0x1000,           // old-style pre-0.9.6 deprecated method
00504         PRE_091        = 0x2000 | PRE_096  // old-style pre-0.9.1 deprecated method
00505     };
00506     replyType = "void";
00507     int function;
00508     if (func == "handleEvent(const QString&,const QString&)"
00509     ||       func == "handleEvent(QString,QString)")
00510         function = HANDLE;
00511     else if (func == "cancelEvent(const QString&,const QString&)"
00512     ||       func == "cancelEvent(QString,QString)")
00513         function = CANCEL;
00514     else if (func == "triggerEvent(const QString&,const QString&)"
00515     ||       func == "triggerEvent(QString,QString)")
00516         function = TRIGGER;
00517 
00518     //                scheduleMessage(message, dateTime, colour, colourfg, flags, audioURL, reminder, recurrence)
00519     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,const QColor&,Q_UINT32,const QString&,Q_INT32,const QString&)"
00520     ||       func == "scheduleMessage(QString,QDateTime,QColor,QColor,Q_UINT32,QString,Q_UINT32,QString)")
00521         function = SCHEDULE | MESSAGE;
00522     //                scheduleMessage(message, dateTime, colour, colourfg, font, flags, audioURL, reminder, recurrence)
00523     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,const QColor&,const QFont&,Q_UINT32,const QString&,Q_INT32,const QString&)"
00524     ||       func == "scheduleMessage(QString,QDateTime,QColor,QColor,QFont,Q_UINT32,QString,Q_UINT32,QString)")
00525         function = SCHEDULE | MESSAGE | FONT;
00526     //                scheduleFile(URL, dateTime, colour, flags, audioURL, reminder, recurrence)
00527     else if (func == "scheduleFile(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,const QString&)"
00528     ||       func == "scheduleFile(QString,QDateTime,QColor,Q_UINT32,QString,Q_UINT32,QString)")
00529         function = SCHEDULE | FILE;
00530     //                scheduleCommand(commandLine, dateTime, flags, recurrence)
00531     else if (func == "scheduleCommand(const QString&,const QDateTime&,Q_UINT32,const QString&)"
00532     ||       func == "scheduleCommand(QString,QDateTime,Q_UINT32,QString)")
00533         function = SCHEDULE | COMMAND;
00534     //                scheduleEmail(addresses, subject, message, attachments, dateTime, flags, recurrence)
00535     else if (func == "scheduleEmail(const QString&,const QString&,const QString&,const QString&,const QDateTime&,Q_UINT32,const QString&)"
00536     ||       func == "scheduleEmail(QString,QString,QString,QString,QDateTime,Q_UINT32,QString)")
00537         function = SCHEDULE | EMAIL;
00538 
00539     //                scheduleMessage(message, dateTime, colour, colourfg, flags, audioURL, reminder, recurType, interval, recurCount)
00540     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,Q_INT32,Q_INT32)"
00541     ||       func == "scheduleMessage(QString,QDateTime,QColor,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,Q_INT32,Q_INT32)")
00542         function = SCHEDULE | MESSAGE | REP_COUNT;
00543     //                scheduleFile(URL, dateTime, colour, flags, audioURL, reminder, recurType, interval, recurCount)
00544     else if (func == "scheduleFile(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,Q_INT32,Q_INT32)"
00545     ||       func == "scheduleFile(QString,QDateTime,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,Q_INT32,Q_INT32)")
00546         function = SCHEDULE | FILE | REP_COUNT;
00547     //                scheduleCommand(commandLine, dateTime, flags, recurType, interval, recurCount)
00548     else if (func == "scheduleCommand(const QString&,const QDateTime&,Q_UINT32,Q_INT32,Q_INT32,Q_INT32)"
00549     ||       func == "scheduleCommand(QString,QDateTime,Q_UINT32,Q_INT32,Q_INT32,Q_INT32)")
00550         function = SCHEDULE | COMMAND | REP_COUNT;
00551     //                scheduleEmail(addresses, subject, message, attachments, dateTime, flags, recurType, interval, recurCount)
00552     else if (func == "scheduleEmail(const QString&,const QString&,const QString&,const QString&,const QDateTime&,Q_UINT32,Q_INT32,Q_INT32,Q_INT32)"
00553     ||       func == "scheduleEmail(QString,QString,QString,QString,QDateTime,Q_UINT32,Q_INT32,Q_INT32,Q_INT32)")
00554         function = SCHEDULE | EMAIL | REP_COUNT;
00555 
00556     //                scheduleMessage(message, dateTime, colour, colourfg, flags, audioURL, reminder, recurType, interval, endTime)
00557     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,Q_INT32,const QDateTime&)"
00558     ||       func == "scheduleMessage(QString,QDateTime,QColor,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,Q_INT32,QDateTime)")
00559         function = SCHEDULE | MESSAGE | REP_END;
00560     //                scheduleFile(URL, dateTime, colour, flags, audioURL, reminder, recurType, interval, endTime)
00561     else if (func == "scheduleFile(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,Q_INT32,const QDateTime&)"
00562     ||       func == "scheduleFile(QString,QDateTime,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,Q_INT32,QDateTime)")
00563         function = SCHEDULE | FILE | REP_END;
00564     //                scheduleCommand(commandLine, dateTime, flags, recurType, interval, endTime)
00565     else if (func == "scheduleCommand(const QString&,const QDateTime&,Q_UINT32,Q_INT32,Q_INT32,const QDateTime&)"
00566     ||       func == "scheduleCommand(QString,QDateTime,Q_UINT32,Q_INT32,Q_INT32,QDateTime)")
00567         function = SCHEDULE | COMMAND | REP_END;
00568     //                scheduleEmail(addresses, subject, message, attachments, dateTime, flags, recurType, interval, endTime)
00569     else if (func == "scheduleEmail(const QString&,const QString&,const QString&,const QString&,const QDateTime&,Q_UINT32,Q_INT32,Q_INT32,const QDateTime&)"
00570     ||       func == "scheduleEmail(QString,QString,QString,QString,QDateTime,Q_UINT32,Q_INT32,Q_INT32,QDateTime)")
00571         function = SCHEDULE | EMAIL | REP_END;
00572 
00573     // Deprecated methods: backwards compatibility with KAlarm pre-0.9.6
00574     //                scheduleMessage(message, dateTime, colour, flags, audioURL, reminder, recurrence)
00575     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,const QString&)"
00576     ||       func == "scheduleMessage(QString,QDateTime,QColor,Q_UINT32,QString,Q_UINT32,QString)")
00577         function = SCHEDULE | MESSAGE | PRE_096;
00578     //                scheduleMessage(message, dateTime, colour, font, flags, audioURL, reminder, recurrence)
00579     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,const QFont&,Q_UINT32,const QString&,Q_INT32,const QString&)"
00580     ||       func == "scheduleMessage(QString,QDateTime,QColor,QFont,Q_UINT32,QString,Q_UINT32,QString)")
00581         function = SCHEDULE | MESSAGE | FONT | PRE_096;
00582     //                scheduleMessage(message, dateTime, colour, flags, audioURL, reminder, recurType, interval, recurCount)
00583     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,Q_INT32,Q_INT32)"
00584     ||       func == "scheduleMessage(QString,QDateTime,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,Q_INT32,Q_INT32)")
00585         function = SCHEDULE | MESSAGE | REP_COUNT | PRE_096;
00586     //                scheduleMessage(message, dateTime, colour, flags, audioURL, reminder, recurType, interval, endTime)
00587     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,Q_INT32,const QDateTime&)"
00588     ||       func == "scheduleMessage(QString,QDateTime,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,Q_INT32,QDateTime)")
00589         function = SCHEDULE | MESSAGE | REP_END | PRE_096;
00590 
00591     // Deprecated methods: backwards compatibility with KAlarm pre-0.9.1
00592     //                scheduleMessage(message, dateTime, colour, flags, audioURL)
00593     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&)"
00594     ||       func == "scheduleMessage(QString,QDateTime,QColor,Q_UINT32,QString)")
00595         function = SCHEDULE | MESSAGE | PRE_091;
00596     //                scheduleFile(URL, dateTime, colour, flags, audioURL)
00597     else if (func == "scheduleFile(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&)"
00598     ||       func == "scheduleFile(QString,QDateTime,QColor,Q_UINT32,QString)")
00599         function = SCHEDULE | FILE | PRE_091;
00600     //                scheduleMessage(message, dateTime, colour, flags, audioURL, recurType, interval, recurCount)
00601     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,Q_INT32)"
00602     ||       func == "scheduleMessage(QString,QDateTime,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,Q_INT32)")
00603         function = SCHEDULE | MESSAGE | REP_COUNT | PRE_091;
00604     //                scheduleFile(URL, dateTime, colour, flags, audioURL, recurType, interval, recurCount)
00605     else if (func == "scheduleFile(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,Q_INT32)"
00606     ||       func == "scheduleFile(QString,QDateTime,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,Q_INT32)")
00607         function = SCHEDULE | FILE | REP_COUNT | PRE_091;
00608     //                scheduleMessage(message, dateTime, colour, flags, audioURL, recurType, interval, endTime)
00609     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,const QDateTime&)"
00610     ||       func == "scheduleMessage(QString,QDateTime,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,QDateTime)")
00611         function = SCHEDULE | MESSAGE | REP_END | PRE_091;
00612     //                scheduleFile(URL, dateTime, colour, flags, audioURL, recurType, interval, endTime)
00613     else if (func == "scheduleFile(const QString&,const QDateTime&,const QColor&,Q_UINT32,const QString&,Q_INT32,Q_INT32,const QDateTime&)"
00614     ||       func == "scheduleFile(QString,QDateTime,QColor,Q_UINT32,QString,Q_INT32,Q_INT32,QDateTime)")
00615         function = SCHEDULE | FILE | REP_END | PRE_091;
00616 
00617     // Obsolete methods: backwards compatibility with KAlarm pre-0.7
00618     else if (func == "scheduleMessage(const QString&,const QDateTime&,const QColor&,Q_UINT32,Q_INT32,Q_INT32)"
00619     ||       func == "scheduleMessage(QString,QDateTime,QColor,Q_UINT32,Q_INT32,Q_INT32)"
00620     ||       func == "scheduleFile(const QString&,const QDateTime&,const QColor&,Q_UINT32,Q_INT32,Q_INT32)"
00621     ||       func == "scheduleFile(QString,QDateTime,QColor,Q_UINT32,Q_INT32,Q_INT32)"
00622     ||       func == "scheduleCommand(const QString&,const QDateTime&,Q_UINT32,Q_INT32,Q_INT32)"
00623     ||       func == "scheduleCommand(QString,QDateTime,Q_UINT32,Q_INT32,Q_INT32)"
00624     // Obsolete methods: backwards compatibility with KAlarm pre-0.6
00625     ||       func == "cancelMessage(const QString&,const QString&)"
00626     ||       func == "cancelMessage(QString,QString)"
00627     ||       func == "displayMessage(const QString&,const QString&)"
00628     ||       func == "displayMessage(QString,QString)")
00629     {
00630         kdError(5950) << "DcopHandlerOld::process(): obsolete DCOP function call: '" << func << "'" << endl;
00631         return false;
00632     }
00633     else
00634     {
00635         kdError(5950) << "DcopHandlerOld::process(): unknown DCOP function" << endl;
00636         return false;
00637     }
00638 
00639     switch (function & OPERATION)
00640     {
00641         case HANDLE:        // trigger or cancel event with specified ID from calendar file
00642         case CANCEL:        // cancel event with specified ID from calendar file
00643         case TRIGGER:       // trigger event with specified ID in calendar file
00644         {
00645 
00646             QDataStream arg(data, IO_ReadOnly);
00647             QString urlString, vuid;
00648             arg >> urlString >> vuid;
00649             switch (function)
00650             {
00651                 case HANDLE:
00652                     return theApp()->handleEvent(urlString, vuid);
00653                 case CANCEL:
00654                     return theApp()->deleteEvent(urlString, vuid);
00655                 case TRIGGER:
00656                     return theApp()->triggerEvent(urlString, vuid);
00657             }
00658             break;
00659         }
00660         case SCHEDULE:      // schedule a new event
00661         {
00662             KAEvent::Action action;
00663             switch (function & ALARM_TYPE)
00664             {
00665                 case MESSAGE:  action = KAEvent::MESSAGE;  break;
00666                 case FILE:     action = KAEvent::FILE;     break;
00667                 case COMMAND:  action = KAEvent::COMMAND;  break;
00668                 case EMAIL:    action = KAEvent::EMAIL;    break;
00669                 default:  return false;
00670             }
00671             QDataStream  arg(data, IO_ReadOnly);
00672             QString      text, audioFile, mailSubject;
00673             float        audioVolume = -1;
00674             EmailAddressList mailAddresses;
00675             QStringList  mailAttachments;
00676             QDateTime    dateTime, endTime;
00677             QColor       bgColour;
00678             QColor       fgColour(Qt::black);
00679             QFont        font;
00680             Q_UINT32     flags;
00681             int          lateCancel = 0;
00682             KARecurrence recurrence;
00683             Q_INT32      reminderMinutes = 0;
00684             if (action == KAEvent::EMAIL)
00685             {
00686                 QString addresses, attachments;
00687                 arg >> addresses >> mailSubject >> text >> attachments;
00688                 QString bad = KAMail::convertAddresses(addresses, mailAddresses);
00689                 if (!bad.isEmpty())
00690                 {
00691                     kdError(5950) << "DcopHandlerOld::process(): invalid email addresses: " << bad << endl;
00692                     return false;
00693                 }
00694                 if (mailAddresses.isEmpty())
00695                 {
00696                     kdError(5950) << "DcopHandlerOld::process(): no email address\n";
00697                     return false;
00698                 }
00699                 bad = KAMail::convertAttachments(attachments, mailAttachments);
00700                 if (!bad.isEmpty())
00701                 {
00702                     kdError(5950) << "DcopHandlerOld::process(): invalid email attachment: " << bad << endl;
00703                     return false;
00704                 }
00705             }
00706             else
00707                 arg >> text;
00708             arg.readRawBytes((char*)&dateTime, sizeof(dateTime));
00709             if (action != KAEvent::COMMAND)
00710                 arg.readRawBytes((char*)&bgColour, sizeof(bgColour));
00711             if (action == KAEvent::MESSAGE  &&  !(function & PRE_096))
00712                 arg.readRawBytes((char*)&fgColour, sizeof(fgColour));
00713             if (function & FONT)
00714             {
00715                 arg.readRawBytes((char*)&font, sizeof(font));
00716                 arg >> flags;
00717             }
00718             else
00719             {
00720                 arg >> flags;
00721                 flags |= KAEvent::DEFAULT_FONT;
00722             }
00723             if (flags & KAEvent::LATE_CANCEL)
00724                 lateCancel = 1;
00725             if (action == KAEvent::MESSAGE  ||  action == KAEvent::FILE)
00726             {
00727                 arg >> audioFile;
00728                 if (!(function & PRE_091))
00729                     arg >> reminderMinutes;
00730             }
00731             if (function & (REP_COUNT | REP_END))
00732             {           
00733                 KARecurrence::Type recurType;
00734                 Q_INT32 recurCount = 0;
00735                 Q_INT32 recurInterval;
00736                 Q_INT32 type;
00737                 arg >> type >> recurInterval;
00738                 switch (type)
00739                 {
00740                     case 1:  recurType = KARecurrence::MINUTELY;     break;
00741                     case 3:  recurType = KARecurrence::DAILY;        break;
00742                     case 4:  recurType = KARecurrence::WEEKLY;       break;
00743                     case 6:  recurType = KARecurrence::MONTHLY_DAY;  break;
00744                     case 7:  recurType = KARecurrence::ANNUAL_DATE;  break;
00745                     default:
00746                         kdError(5950) << "DcopHandlerOld::process(): invalid simple repetition type: " << type << endl;
00747                         return false;
00748                 }
00749                 if (function & REP_COUNT)
00750                     arg >> recurCount;
00751                 else
00752                     arg.readRawBytes((char*)&endTime, sizeof(endTime));
00753                 recurrence.set(recurType, recurInterval, recurCount,
00754                                DateTime(dateTime, flags & KAEvent::ANY_TIME), endTime);
00755             }
00756             else if (!(function & PRE_091))
00757             {
00758                 QString rule;
00759                 arg >> rule;
00760                 recurrence.set(rule);
00761             }
00762             return theApp()->scheduleEvent(action, text, dateTime, lateCancel, flags, bgColour, fgColour, font, audioFile,
00763                                            audioVolume, reminderMinutes, recurrence, 0, 0, 0, mailAddresses, mailSubject, mailAttachments);
00764         }
00765     }
00766     return false;
00767 }
00768 #endif // OLD_DCOP
KDE Home | KDE Accessibility Home | Description of Access Keys