00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kalarm.h"
00022
00023 #include <stdlib.h>
00024 #include <ctype.h>
00025 #include <iostream>
00026
00027 #include <qobjectlist.h>
00028 #include <qtimer.h>
00029 #include <qregexp.h>
00030 #include <qfile.h>
00031
00032 #include <kcmdlineargs.h>
00033 #include <klocale.h>
00034 #include <kstandarddirs.h>
00035 #include <kconfig.h>
00036 #include <kaboutdata.h>
00037 #include <dcopclient.h>
00038 #include <kprocess.h>
00039 #include <ktempfile.h>
00040 #include <kfileitem.h>
00041 #include <kstdguiitem.h>
00042 #include <ktrader.h>
00043 #include <kstaticdeleter.h>
00044 #include <kdebug.h>
00045
00046 #include <libkcal/calformat.h>
00047
00048 #include <kalarmd/clientinfo.h>
00049
00050 #include "alarmcalendar.h"
00051 #include "alarmlistview.h"
00052 #include "birthdaydlg.h"
00053 #include "editdlg.h"
00054 #include "daemon.h"
00055 #include "dcophandler.h"
00056 #include "functions.h"
00057 #include "kamail.h"
00058 #include "karecurrence.h"
00059 #include "mainwindow.h"
00060 #include "messagebox.h"
00061 #include "messagewin.h"
00062 #include "preferences.h"
00063 #include "prefdlg.h"
00064 #include "shellprocess.h"
00065 #include "traywindow.h"
00066 #include "kalarmapp.moc"
00067
00068 #include <netwm.h>
00069
00070
00071 static bool convWakeTime(const QCString& timeParam, QDateTime&, bool& noTime);
00072 static bool convInterval(const QCString& timeParam, KARecurrence::Type&, int& timeInterval, bool allowMonthYear = false);
00073
00074
00075
00076
00077
00078
00079 static inline int maxLateness(int lateCancel)
00080 {
00081 static const int LATENESS_LEEWAY = 5;
00082 int lc = (lateCancel >= 1) ? (lateCancel - 1)*60 : 0;
00083 return Daemon::maxTimeSinceCheck() + LATENESS_LEEWAY + lc;
00084 }
00085
00086
00087 KAlarmApp* KAlarmApp::theInstance = 0;
00088 int KAlarmApp::mActiveCount = 0;
00089 int KAlarmApp::mFatalError = 0;
00090 QString KAlarmApp::mFatalMessage;
00091
00092
00093
00094
00095
00096 KAlarmApp::KAlarmApp()
00097 : KUniqueApplication(),
00098 mInitialised(false),
00099 mDcopHandler(new DcopHandler()),
00100 #ifdef OLD_DCOP
00101 mDcopHandlerOld(new DcopHandlerOld()),
00102 #endif
00103 mTrayWindow(0),
00104 mPendingQuit(false),
00105 mProcessingQueue(false),
00106 mCheckingSystemTray(false),
00107 mSessionClosingDown(false),
00108 mRefreshExpiredAlarms(false),
00109 mSpeechEnabled(false)
00110 {
00111 Preferences::initialise();
00112 Preferences::connect(SIGNAL(preferencesChanged()), this, SLOT(slotPreferencesChanged()));
00113 KCal::CalFormat::setApplication(aboutData()->programName(), AlarmCalendar::icalProductId());
00114 KARecurrence::setDefaultFeb29Type(Preferences::defaultFeb29Type());
00115
00116
00117 mHaveSystemTray = true;
00118
00119 if (AlarmCalendar::initialiseCalendars())
00120 {
00121 connect(AlarmCalendar::expiredCalendar(), SIGNAL(purged()), SLOT(slotExpiredPurged()));
00122
00123 KConfig* config = kapp->config();
00124 config->setGroup(QString::fromLatin1("General"));
00125 mNoSystemTray = config->readBoolEntry(QString::fromLatin1("NoSystemTray"), false);
00126 mSavedNoSystemTray = mNoSystemTray;
00127 mOldRunInSystemTray = wantRunInSystemTray();
00128 mDisableAlarmsIfStopped = mOldRunInSystemTray && !mNoSystemTray && Preferences::disableAlarmsIfStopped();
00129 mStartOfDay = Preferences::startOfDay();
00130 if (Preferences::hasStartOfDayChanged())
00131 mStartOfDay.setHMS(100,0,0);
00132 DateTime::setStartOfDay(mStartOfDay);
00133 mPrefsExpiredColour = Preferences::expiredColour();
00134 mPrefsExpiredKeepDays = Preferences::expiredKeepDays();
00135 }
00136
00137
00138 mSpeechEnabled = (KTrader::self()->query("DCOP/Text-to-Speech", "Name == 'KTTSD'").count() > 0);
00139 if (!mSpeechEnabled)
00140 kdDebug(5950) << "KAlarmApp::KAlarmApp(): speech synthesis disabled (KTTSD not found)" << endl;
00141
00142 QString korg = QString::fromLatin1("korganizer");
00143 mKOrganizerEnabled = !locate("exe", korg).isNull() || !KStandardDirs::findExe(korg).isNull();
00144 if (!mKOrganizerEnabled)
00145 kdDebug(5950) << "KAlarmApp::KAlarmApp(): KOrganizer options disabled (KOrganizer not found)" << endl;
00146 }
00147
00148
00149
00150 KAlarmApp::~KAlarmApp()
00151 {
00152 while (!mCommandProcesses.isEmpty())
00153 {
00154 ProcData* pd = mCommandProcesses.first();
00155 mCommandProcesses.pop_front();
00156 delete pd;
00157 }
00158 AlarmCalendar::terminateCalendars();
00159 }
00160
00161
00162
00163
00164
00165 KAlarmApp* KAlarmApp::getInstance()
00166 {
00167 if (!theInstance)
00168 {
00169 theInstance = new KAlarmApp;
00170
00171 if (mFatalError)
00172 theInstance->quitFatal();
00173 else
00174 {
00175
00176 Daemon::initialise();
00177 }
00178 }
00179 return theInstance;
00180 }
00181
00182
00183
00184
00185 bool KAlarmApp::restoreSession()
00186 {
00187 if (!isRestored())
00188 return false;
00189 if (mFatalError)
00190 {
00191 quitFatal();
00192 return false;
00193 }
00194
00195
00196 kdDebug(5950) << "KAlarmApp::restoreSession(): Restoring\n";
00197 ++mActiveCount;
00198 if (!initCheck(true))
00199 {
00200 --mActiveCount;
00201 quitIf(1, true);
00202 return true;
00203 }
00204 MainWindow* trayParent = 0;
00205 for (int i = 1; KMainWindow::canBeRestored(i); ++i)
00206 {
00207 QString type = KMainWindow::classNameOfToplevel(i);
00208 if (type == QString::fromLatin1("MainWindow"))
00209 {
00210 MainWindow* win = MainWindow::create(true);
00211 win->restore(i, false);
00212 if (win->isHiddenTrayParent())
00213 trayParent = win;
00214 else
00215 win->show();
00216 }
00217 else if (type == QString::fromLatin1("MessageWin"))
00218 {
00219 MessageWin* win = new MessageWin;
00220 win->restore(i, false);
00221 if (win->isValid())
00222 win->show();
00223 else
00224 delete win;
00225 }
00226 }
00227 initCheck();
00228
00229
00230
00231 if (Preferences::autostartTrayIcon()
00232 || MainWindow::count() && wantRunInSystemTray())
00233 {
00234 displayTrayIcon(true, trayParent);
00235
00236
00237 if (trayParent)
00238 trayParent->hide();
00239 }
00240
00241 --mActiveCount;
00242 quitIf(0);
00243 return true;
00244 }
00245
00246
00247
00248
00249
00250 int KAlarmApp::newInstance()
00251 {
00252 kdDebug(5950)<<"KAlarmApp::newInstance()\n";
00253 if (mFatalError)
00254 {
00255 quitFatal();
00256 return 1;
00257 }
00258 ++mActiveCount;
00259 int exitCode = 0;
00260 static bool firstInstance = true;
00261 bool dontRedisplay = false;
00262 if (!firstInstance || !isRestored())
00263 {
00264 QString usage;
00265 KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
00266
00267
00268
00269
00270
00271
00272
00273 do
00274 {
00275 #define USAGE(message) { usage = message; break; }
00276 if (args->isSet("stop"))
00277 {
00278
00279 kdDebug(5950)<<"KAlarmApp::newInstance(): stop\n";
00280 args->clear();
00281 if (!Daemon::stop())
00282 {
00283 exitCode = 1;
00284 break;
00285 }
00286 dontRedisplay = true;
00287 }
00288 else
00289 if (args->isSet("reset"))
00290 {
00291
00292
00293 kdDebug(5950)<<"KAlarmApp::newInstance(): reset\n";
00294 args->clear();
00295 Daemon::reset();
00296 dontRedisplay = true;
00297 }
00298 else
00299 if (args->isSet("tray"))
00300 {
00301
00302 kdDebug(5950)<<"KAlarmApp::newInstance(): tray\n";
00303 args->clear();
00304 if (!mHaveSystemTray)
00305 {
00306 exitCode = 1;
00307 break;
00308 }
00309 if (!initCheck())
00310 {
00311 exitCode = 1;
00312 break;
00313 }
00314 if (!displayTrayIcon(true))
00315 {
00316 exitCode = 1;
00317 break;
00318 }
00319 }
00320 else
00321 if (args->isSet("handleEvent") || args->isSet("triggerEvent") || args->isSet("cancelEvent") || args->isSet("calendarURL"))
00322 {
00323
00324 kdDebug(5950)<<"KAlarmApp::newInstance(): handle event\n";
00325 EventFunc function = EVENT_HANDLE;
00326 int count = 0;
00327 const char* option = 0;
00328 if (args->isSet("handleEvent")) { function = EVENT_HANDLE; option = "handleEvent"; ++count; }
00329 if (args->isSet("triggerEvent")) { function = EVENT_TRIGGER; option = "triggerEvent"; ++count; }
00330 if (args->isSet("cancelEvent")) { function = EVENT_CANCEL; option = "cancelEvent"; ++count; }
00331 if (!count)
00332 USAGE(i18n("%1 requires %2, %3 or %4").arg(QString::fromLatin1("--calendarURL")).arg(QString::fromLatin1("--handleEvent")).arg(QString::fromLatin1("--triggerEvent")).arg(QString::fromLatin1("--cancelEvent")))
00333 if (count > 1)
00334 USAGE(i18n("%1, %2, %3 mutually exclusive").arg(QString::fromLatin1("--handleEvent")).arg(QString::fromLatin1("--triggerEvent")).arg(QString::fromLatin1("--cancelEvent")));
00335 if (!initCheck(true))
00336 {
00337 exitCode = 1;
00338 break;
00339 }
00340 if (args->isSet("calendarURL"))
00341 {
00342 QString calendarUrl = args->getOption("calendarURL");
00343 if (KURL(calendarUrl).url() != AlarmCalendar::activeCalendar()->urlString())
00344 USAGE(i18n("%1: wrong calendar file").arg(QString::fromLatin1("--calendarURL")))
00345 }
00346 QString eventID = args->getOption(option);
00347 args->clear();
00348 if (eventID.startsWith(QString::fromLatin1("ad:")))
00349 {
00350
00351 eventID = eventID.mid(3);
00352 Daemon::queueEvent(eventID);
00353 }
00354 setUpDcop();
00355 if (!handleEvent(eventID, function))
00356 {
00357 exitCode = 1;
00358 break;
00359 }
00360 }
00361 else
00362 if (args->isSet("edit"))
00363 {
00364 QString eventID = args->getOption("edit");
00365 if (!initCheck())
00366 {
00367 exitCode = 1;
00368 break;
00369 }
00370 if (!KAlarm::edit(eventID))
00371 {
00372 USAGE(i18n("%1: Event %2 not found, or not editable").arg(QString::fromLatin1("--edit")).arg(eventID))
00373 exitCode = 1;
00374 break;
00375 }
00376 }
00377 else
00378 if (args->isSet("edit-new") || args->isSet("edit-new-preset"))
00379 {
00380 QString templ;
00381 if (args->isSet("edit-new-preset"))
00382 templ = args->getOption("edit-new-preset");
00383 if (!initCheck())
00384 {
00385 exitCode = 1;
00386 break;
00387 }
00388 KAlarm::editNew(templ);
00389 }
00390 else
00391 if (args->isSet("file") || args->isSet("exec") || args->isSet("mail") || args->count())
00392 {
00393
00394 KAEvent::Action action = KAEvent::MESSAGE;
00395 QCString alMessage;
00396 uint alFromID = 0;
00397 EmailAddressList alAddresses;
00398 QStringList alAttachments;
00399 QCString alSubject;
00400 if (args->isSet("file"))
00401 {
00402 kdDebug(5950)<<"KAlarmApp::newInstance(): file\n";
00403 if (args->isSet("exec"))
00404 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--exec")).arg(QString::fromLatin1("--file")))
00405 if (args->isSet("mail"))
00406 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--mail")).arg(QString::fromLatin1("--file")))
00407 if (args->count())
00408 USAGE(i18n("message incompatible with %1").arg(QString::fromLatin1("--file")))
00409 alMessage = args->getOption("file");
00410 action = KAEvent::FILE;
00411 }
00412 else if (args->isSet("exec"))
00413 {
00414 kdDebug(5950)<<"KAlarmApp::newInstance(): exec\n";
00415 if (args->isSet("mail"))
00416 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--mail")).arg(QString::fromLatin1("--exec")))
00417 alMessage = args->getOption("exec");
00418 int n = args->count();
00419 for (int i = 0; i < n; ++i)
00420 {
00421 alMessage += ' ';
00422 alMessage += args->arg(i);
00423 }
00424 action = KAEvent::COMMAND;
00425 }
00426 else if (args->isSet("mail"))
00427 {
00428 kdDebug(5950)<<"KAlarmApp::newInstance(): mail\n";
00429 if (args->isSet("subject"))
00430 alSubject = args->getOption("subject");
00431 if (args->isSet("from-id"))
00432 alFromID = KAMail::identityUoid(args->getOption("from-id"));
00433 QCStringList params = args->getOptionList("mail");
00434 for (QCStringList::Iterator i = params.begin(); i != params.end(); ++i)
00435 {
00436 QString addr = QString::fromLocal8Bit(*i);
00437 if (!KAMail::checkAddress(addr))
00438 USAGE(i18n("%1: invalid email address").arg(QString::fromLatin1("--mail")))
00439 alAddresses += KCal::Person(QString::null, addr);
00440 }
00441 params = args->getOptionList("attach");
00442 for (QCStringList::Iterator i = params.begin(); i != params.end(); ++i)
00443 alAttachments += QString::fromLocal8Bit(*i);
00444 alMessage = args->arg(0);
00445 action = KAEvent::EMAIL;
00446 }
00447 else
00448 {
00449 kdDebug(5950)<<"KAlarmApp::newInstance(): message\n";
00450 alMessage = args->arg(0);
00451 }
00452
00453 if (action != KAEvent::EMAIL)
00454 {
00455 if (args->isSet("subject"))
00456 USAGE(i18n("%1 requires %2").arg(QString::fromLatin1("--subject")).arg(QString::fromLatin1("--mail")))
00457 if (args->isSet("from-id"))
00458 USAGE(i18n("%1 requires %2").arg(QString::fromLatin1("--from-id")).arg(QString::fromLatin1("--mail")))
00459 if (args->isSet("attach"))
00460 USAGE(i18n("%1 requires %2").arg(QString::fromLatin1("--attach")).arg(QString::fromLatin1("--mail")))
00461 if (args->isSet("bcc"))
00462 USAGE(i18n("%1 requires %2").arg(QString::fromLatin1("--bcc")).arg(QString::fromLatin1("--mail")))
00463 }
00464
00465 bool alarmNoTime = false;
00466 QDateTime alarmTime, endTime;
00467 QColor bgColour = Preferences::defaultBgColour();
00468 QColor fgColour = Preferences::defaultFgColour();
00469 KARecurrence recurrence;
00470 int repeatCount = 0;
00471 int repeatInterval = 0;
00472 if (args->isSet("color"))
00473 {
00474
00475 QCString colourText = args->getOption("color");
00476 if (static_cast<const char*>(colourText)[0] == '0'
00477 && tolower(static_cast<const char*>(colourText)[1]) == 'x')
00478 colourText.replace(0, 2, "#");
00479 bgColour.setNamedColor(colourText);
00480 if (!bgColour.isValid())
00481 USAGE(i18n("Invalid %1 parameter").arg(QString::fromLatin1("--color")))
00482 }
00483 if (args->isSet("colorfg"))
00484 {
00485
00486 QCString colourText = args->getOption("colorfg");
00487 if (static_cast<const char*>(colourText)[0] == '0'
00488 && tolower(static_cast<const char*>(colourText)[1]) == 'x')
00489 colourText.replace(0, 2, "#");
00490 fgColour.setNamedColor(colourText);
00491 if (!fgColour.isValid())
00492 USAGE(i18n("Invalid %1 parameter").arg(QString::fromLatin1("--colorfg")))
00493 }
00494
00495 if (args->isSet("time"))
00496 {
00497 QCString dateTime = args->getOption("time");
00498 if (!convWakeTime(dateTime, alarmTime, alarmNoTime))
00499 USAGE(i18n("Invalid %1 parameter").arg(QString::fromLatin1("--time")))
00500 }
00501 else
00502 alarmTime = QDateTime::currentDateTime();
00503
00504 bool haveRecurrence = args->isSet("recurrence");
00505 if (haveRecurrence)
00506 {
00507 if (args->isSet("login"))
00508 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--login")).arg(QString::fromLatin1("--recurrence")))
00509 if (args->isSet("until"))
00510 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--until")).arg(QString::fromLatin1("--recurrence")))
00511 QCString rule = args->getOption("recurrence");
00512 recurrence.set(QString::fromLocal8Bit(static_cast<const char*>(rule)));
00513 }
00514 if (args->isSet("interval"))
00515 {
00516
00517 int count;
00518 if (args->isSet("login"))
00519 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--login")).arg(QString::fromLatin1("--interval")))
00520 bool ok;
00521 if (args->isSet("repeat"))
00522 {
00523 count = args->getOption("repeat").toInt(&ok);
00524 if (!ok || !count || count < -1 || (count < 0 && haveRecurrence))
00525 USAGE(i18n("Invalid %1 parameter").arg(QString::fromLatin1("--repeat")))
00526 }
00527 else if (haveRecurrence)
00528 USAGE(i18n("%1 requires %2").arg(QString::fromLatin1("--interval")).arg(QString::fromLatin1("--repeat")))
00529 else if (args->isSet("until"))
00530 {
00531 count = 0;
00532 QCString dateTime = args->getOption("until");
00533 if (!convWakeTime(dateTime, endTime, alarmNoTime))
00534 USAGE(i18n("Invalid %1 parameter").arg(QString::fromLatin1("--until")))
00535 if (endTime < alarmTime)
00536 USAGE(i18n("%1 earlier than %2").arg(QString::fromLatin1("--until")).arg(QString::fromLatin1("--time")))
00537 }
00538 else
00539 count = -1;
00540
00541
00542 int interval;
00543 KARecurrence::Type recurType;
00544 if (!convInterval(args->getOption("interval"), recurType, interval, !haveRecurrence)
00545 || interval < 0)
00546 USAGE(i18n("Invalid %1 parameter").arg(QString::fromLatin1("--interval")))
00547 if (alarmNoTime && recurType == KARecurrence::MINUTELY)
00548 USAGE(i18n("Invalid %1 parameter for date-only alarm").arg(QString::fromLatin1("--interval")))
00549
00550 if (haveRecurrence)
00551 {
00552
00553 int longestInterval = recurrence.longestInterval();
00554 if (count * interval > longestInterval)
00555 USAGE(i18n("Invalid %1 and %2 parameters: repetition is longer than %3 interval").arg(QString::fromLatin1("--interval")).arg(QString::fromLatin1("--repeat")).arg(QString::fromLatin1("--recurrence")));
00556 repeatCount = count;
00557 repeatInterval = interval;
00558 }
00559 else
00560 {
00561
00562
00563 recurrence.set(recurType, interval, count, DateTime(alarmTime, alarmNoTime), endTime);
00564 }
00565 }
00566 else
00567 {
00568 if (args->isSet("repeat"))
00569 USAGE(i18n("%1 requires %2").arg(QString::fromLatin1("--repeat")).arg(QString::fromLatin1("--interval")))
00570 if (args->isSet("until"))
00571 USAGE(i18n("%1 requires %2").arg(QString::fromLatin1("--until")).arg(QString::fromLatin1("--interval")))
00572 }
00573
00574 QCString audioFile;
00575 float audioVolume = -1;
00576 #ifdef WITHOUT_ARTS
00577 bool audioRepeat = false;
00578 #else
00579 bool audioRepeat = args->isSet("play-repeat");
00580 #endif
00581 if (audioRepeat || args->isSet("play"))
00582 {
00583
00584 if (audioRepeat && args->isSet("play"))
00585 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--play")).arg(QString::fromLatin1("--play-repeat")))
00586 if (args->isSet("beep"))
00587 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--beep")).arg(QString::fromLatin1(audioRepeat ? "--play-repeat" : "--play")))
00588 if (args->isSet("speak"))
00589 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--speak")).arg(QString::fromLatin1(audioRepeat ? "--play-repeat" : "--play")))
00590 audioFile = args->getOption(audioRepeat ? "play-repeat" : "play");
00591 #ifndef WITHOUT_ARTS
00592 if (args->isSet("volume"))
00593 {
00594 bool ok;
00595 int volumepc = args->getOption("volume").toInt(&ok);
00596 if (!ok || volumepc < 0 || volumepc > 100)
00597 USAGE(i18n("Invalid %1 parameter").arg(QString::fromLatin1("--volume")))
00598 audioVolume = static_cast<float>(volumepc) / 100;
00599 }
00600 #endif
00601 }
00602 #ifndef WITHOUT_ARTS
00603 else if (args->isSet("volume"))
00604 USAGE(i18n("%1 requires %2 or %3").arg(QString::fromLatin1("--volume")).arg(QString::fromLatin1("--play")).arg(QString::fromLatin1("--play-repeat")))
00605 #endif
00606 if (args->isSet("speak"))
00607 {
00608 if (args->isSet("beep"))
00609 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--beep")).arg(QString::fromLatin1("--speak")))
00610 if (!mSpeechEnabled)
00611 USAGE(i18n("%1 requires speech synthesis to be configured using KTTSD").arg(QString::fromLatin1("--speak")))
00612 }
00613 int reminderMinutes = 0;
00614 bool onceOnly = args->isSet("reminder-once");
00615 if (args->isSet("reminder") || onceOnly)
00616 {
00617
00618 if (onceOnly && args->isSet("reminder"))
00619 USAGE(i18n("%1 incompatible with %2").arg(QString::fromLatin1("--reminder")).arg(QString::fromLatin1("--reminder-once")))
00620 QString opt = onceOnly ? QString::fromLatin1("--reminder-once") : QString::fromLatin1("--reminder");
00621 if (args->isSet("exec"))
00622 USAGE(i18n("%1 incompatible with %2").arg(opt).arg(QString::fromLatin1("--exec")))
00623 if (args->isSet("mail"))
00624 USAGE(i18n("%1 incompatible with %2").arg(opt).arg(QString::fromLatin1("--mail")))
00625 KARecurrence::Type recurType;
00626 QString optval = args->getOption(onceOnly ? "reminder-once" : "reminder");
00627 if (!convInterval(args->getOption(onceOnly ? "reminder-once" : "reminder"), recurType, reminderMinutes))
00628 USAGE(i18n("Invalid %1 parameter").arg(opt))
00629 if (recurType == KARecurrence::MINUTELY && alarmNoTime)
00630 USAGE(i18n("Invalid %1 parameter for date-only alarm").arg(opt))
00631 }
00632
00633 int lateCancel = 0;
00634 if (args->isSet("late-cancel"))
00635 {
00636 KARecurrence::Type recurType;
00637 bool ok = convInterval(args->getOption("late-cancel"), recurType, lateCancel);
00638 if (!ok || lateCancel <= 0)
00639 USAGE(i18n("Invalid %1 parameter").arg(QString::fromLatin1("late-cancel")))
00640 }
00641 else if (args->isSet("auto-close"))
00642 USAGE(i18n("%1 requires %2").arg(QString::fromLatin1("--auto-close")).arg(QString::fromLatin1("--late-cancel")))
00643
00644 int flags = KAEvent::DEFAULT_FONT;
00645 if (args->isSet("ack-confirm"))
00646 flags |= KAEvent::CONFIRM_ACK;
00647 if (args->isSet("auto-close"))
00648 flags |= KAEvent::AUTO_CLOSE;
00649 if (args->isSet("beep"))
00650 flags |= KAEvent::BEEP;
00651 if (args->isSet("speak"))
00652 flags |= KAEvent::SPEAK;
00653 if (args->isSet("korganizer"))
00654 flags |= KAEvent::COPY_KORGANIZER;
00655 if (args->isSet("disable"))
00656 flags |= KAEvent::DISABLED;
00657 if (audioRepeat)
00658 flags |= KAEvent::REPEAT_SOUND;
00659 if (args->isSet("login"))
00660 flags |= KAEvent::REPEAT_AT_LOGIN;
00661 if (args->isSet("bcc"))
00662 flags |= KAEvent::EMAIL_BCC;
00663 if (alarmNoTime)
00664 flags |= KAEvent::ANY_TIME;
00665 args->clear();
00666
00667
00668 if (!initCheck())
00669 {
00670 exitCode = 1;
00671 break;
00672 }
00673 if (!scheduleEvent(action, alMessage, alarmTime, lateCancel, flags, bgColour, fgColour, QFont(), audioFile,
00674 audioVolume, reminderMinutes, recurrence, repeatInterval, repeatCount,
00675 alFromID, alAddresses, alSubject, alAttachments))
00676 {
00677 exitCode = 1;
00678 break;
00679 }
00680 }
00681 else
00682 {
00683
00684 kdDebug(5950)<<"KAlarmApp::newInstance(): interactive\n";
00685 if (args->isSet("ack-confirm"))
00686 usage += QString::fromLatin1("--ack-confirm ");
00687 if (args->isSet("attach"))
00688 usage += QString::fromLatin1("--attach ");
00689 if (args->isSet("auto-close"))
00690 usage += QString::fromLatin1("--auto-close ");
00691 if (args->isSet("bcc"))
00692 usage += QString::fromLatin1("--bcc ");
00693 if (args->isSet("beep"))
00694 usage += QString::fromLatin1("--beep ");
00695 if (args->isSet("color"))
00696 usage += QString::fromLatin1("--color ");
00697 if (args->isSet("colorfg"))
00698 usage += QString::fromLatin1("--colorfg ");
00699 if (args->isSet("disable"))
00700 usage += QString::fromLatin1("--disable ");
00701 if (args->isSet("from-id"))
00702 usage += QString::fromLatin1("--from-id ");
00703 if (args->isSet("korganizer"))
00704 usage += QString::fromLatin1("--korganizer ");
00705 if (args->isSet("late-cancel"))
00706 usage += QString::fromLatin1("--late-cancel ");
00707 if (args->isSet("login"))
00708 usage += QString::fromLatin1("--login ");
00709 if (args->isSet("play"))
00710 usage += QString::fromLatin1("--play ");
00711 #ifndef WITHOUT_ARTS
00712 if (args->isSet("play-repeat"))
00713 usage += QString::fromLatin1("--play-repeat ");
00714 #endif
00715 if (args->isSet("reminder"))
00716 usage += QString::fromLatin1("--reminder ");
00717 if (args->isSet("reminder-once"))
00718 usage += QString::fromLatin1("--reminder-once ");
00719 if (args->isSet("speak"))
00720 usage += QString::fromLatin1("--speak ");
00721 if (args->isSet("subject"))
00722 usage += QString::fromLatin1("--subject ");
00723 if (args->isSet("time"))
00724 usage += QString::fromLatin1("--time ");
00725 #ifndef WITHOUT_ARTS
00726 if (args->isSet("volume"))
00727 usage += QString::fromLatin1("--volume ");
00728 #endif
00729 if (!usage.isEmpty())
00730 {
00731 usage += i18n(": option(s) only valid with a message/%1/%2").arg(QString::fromLatin1("--file")).arg(QString::fromLatin1("--exec"));
00732 break;
00733 }
00734
00735 args->clear();
00736
00737
00738
00739
00740
00741 if (!initCheck(true))
00742 {
00743 exitCode = 1;
00744 break;
00745 }
00746
00747 (MainWindow::create())->show();
00748 }
00749 } while (0);
00750
00751 if (!usage.isEmpty())
00752 {
00753
00754
00755 std::cerr << usage.local8Bit().data()
00756 << i18n("\nUse --help to get a list of available command line options.\n").local8Bit().data();
00757 exitCode = 1;
00758 }
00759 }
00760 if (firstInstance && !dontRedisplay && !exitCode)
00761 redisplayAlarms();
00762
00763 --mActiveCount;
00764 firstInstance = false;
00765
00766
00767
00768
00769 quitIf(exitCode);
00770 return exitCode;
00771 }
00772
00773
00774
00775
00776 void KAlarmApp::quitIf(int exitCode, bool force)
00777 {
00778 if (force)
00779 {
00780
00781 MainWindow::closeAll();
00782 displayTrayIcon(false);
00783 if (MessageWin::instanceCount())
00784 return;
00785 }
00786 else
00787 {
00788
00789 mPendingQuit = false;
00790 if (mActiveCount > 0 || MessageWin::instanceCount())
00791 return;
00792 int mwcount = MainWindow::count();
00793 MainWindow* mw = mwcount ? MainWindow::firstWindow() : 0;
00794 if (mwcount > 1 || mwcount && (!mw->isHidden() || !mw->isTrayParent()))
00795 return;
00796
00797 if (mTrayWindow)
00798 {
00799
00800
00801 if (checkSystemTray())
00802 return;
00803 }
00804 if (!mDcopQueue.isEmpty() || !mCommandProcesses.isEmpty())
00805 {
00806
00807 mPendingQuit = true;
00808 mPendingQuitCode = exitCode;
00809 return;
00810 }
00811 }
00812
00813
00814 kdDebug(5950) << "KAlarmApp::quitIf(" << exitCode << "): quitting" << endl;
00815 BirthdayDlg::close();
00816 exit(exitCode);
00817 }
00818
00819
00820
00821
00822
00823
00824 void KAlarmApp::doQuit(QWidget* parent)
00825 {
00826 kdDebug(5950) << "KAlarmApp::doQuit()\n";
00827 if (mDisableAlarmsIfStopped
00828 && MessageBox::warningContinueCancel(parent, KMessageBox::Cancel,
00829 i18n("Quitting will disable alarms\n(once any alarm message windows are closed)."),
00830 QString::null, KStdGuiItem::quit(), Preferences::QUIT_WARN
00831 ) != KMessageBox::Yes)
00832 return;
00833 quitIf(0, true);
00834 }
00835
00836
00837
00838
00839 void KAlarmApp::commitData(QSessionManager& sm)
00840 {
00841 mSessionClosingDown = true;
00842 KUniqueApplication::commitData(sm);
00843 mSessionClosingDown = false;
00844 }
00845
00846
00847
00848
00849
00850 void KAlarmApp::displayFatalError(const QString& message)
00851 {
00852 if (!mFatalError)
00853 {
00854 mFatalError = 1;
00855 mFatalMessage = message;
00856 if (theInstance)
00857 QTimer::singleShot(0, theInstance, SLOT(quitFatal()));
00858 }
00859 }
00860
00861
00862
00863
00864 void KAlarmApp::quitFatal()
00865 {
00866 switch (mFatalError)
00867 {
00868 case 0:
00869 case 2:
00870 return;
00871 case 1:
00872 mFatalError = 2;
00873 KMessageBox::error(0, mFatalMessage);
00874 mFatalError = 3;
00875
00876 case 3:
00877 if (theInstance)
00878 theInstance->quitIf(1, true);
00879 break;
00880 }
00881 QTimer::singleShot(1000, this, SLOT(quitFatal()));
00882 }
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896 void KAlarmApp::processQueue()
00897 {
00898 if (mInitialised && !mProcessingQueue)
00899 {
00900 kdDebug(5950) << "KAlarmApp::processQueue()\n";
00901 mProcessingQueue = true;
00902
00903
00904 KAlarm::resetDaemonIfQueued();
00905
00906
00907 while (!mDcopQueue.isEmpty())
00908 {
00909 DcopQEntry& entry = mDcopQueue.first();
00910 if (entry.eventId.isEmpty())
00911 {
00912
00913 switch (entry.function)
00914 {
00915 case EVENT_TRIGGER:
00916 execAlarm(entry.event, entry.event.firstAlarm(), false);
00917 break;
00918 case EVENT_HANDLE:
00919 KAlarm::addEvent(entry.event, 0);
00920 break;
00921 case EVENT_CANCEL:
00922 break;
00923 }
00924 }
00925 else
00926 handleEvent(entry.eventId, entry.function);
00927 mDcopQueue.pop_front();
00928 }
00929
00930
00931 AlarmCalendar::expiredCalendar()->purgeIfQueued();
00932
00933
00934 if (mPendingQuit)
00935 quitIf(mPendingQuitCode);
00936
00937 mProcessingQueue = false;
00938 }
00939 }
00940
00941
00942
00943
00944
00945
00946
00947 void KAlarmApp::redisplayAlarms()
00948 {
00949 AlarmCalendar* cal = AlarmCalendar::displayCalendar();
00950 if (cal->isOpen())
00951 {
00952 KCal::Event::List events = cal->events();
00953 for (KCal::Event::List::ConstIterator it = events.begin(); it != events.end(); ++it)
00954 {
00955 KCal::Event* kcalEvent = *it;
00956 KAEvent event(*kcalEvent);
00957 event.setUid(KAEvent::ACTIVE);
00958 if (!MessageWin::findEvent(event.id()))
00959 {
00960
00961 kdDebug(5950) << "KAlarmApp::redisplayAlarms(): " << event.id() << endl;
00962 KAAlarm alarm = event.convertDisplayingAlarm();
00963 (new MessageWin(event, alarm, false, !alarm.repeatAtLogin()))->show();
00964 }
00965 }
00966 }
00967 }
00968
00969
00970
00971
00972 void KAlarmApp::removeWindow(TrayWindow*)
00973 {
00974 mTrayWindow = 0;
00975 quitIf();
00976 }
00977
00978
00979
00980
00981 bool KAlarmApp::displayTrayIcon(bool show, MainWindow* parent)
00982 {
00983 static bool creating = false;
00984 if (show)
00985 {
00986 if (!mTrayWindow && !creating)
00987 {
00988 if (!mHaveSystemTray)
00989 return false;
00990 if (!MainWindow::count() && wantRunInSystemTray())
00991 {
00992 creating = true;
00993 parent = MainWindow::create();
00994 creating = false;
00995 }
00996 mTrayWindow = new TrayWindow(parent ? parent : MainWindow::firstWindow());
00997 connect(mTrayWindow, SIGNAL(deleted()), SIGNAL(trayIconToggled()));
00998 mTrayWindow->show();
00999 emit trayIconToggled();
01000
01001
01002
01003 mCheckingSystemTray = true;
01004 mSavedNoSystemTray = mNoSystemTray;
01005 mNoSystemTray = false;
01006 QTimer::singleShot(0, this, SLOT(slotSystemTrayTimer()));
01007 }
01008 }
01009 else if (mTrayWindow)
01010 {
01011 delete mTrayWindow;
01012 mTrayWindow = 0;
01013 }
01014 return true;
01015 }
01016
01017
01018
01019
01020
01021
01022
01023
01024 void KAlarmApp::slotSystemTrayTimer()
01025 {
01026 mCheckingSystemTray = false;
01027 if (!checkSystemTray())
01028 quitIf(0);
01029 }
01030
01031
01032
01033
01034
01035
01036 bool KAlarmApp::checkSystemTray()
01037 {
01038 if (mCheckingSystemTray || !mTrayWindow)
01039 return true;
01040 if (mTrayWindow->inSystemTray() != !mSavedNoSystemTray)
01041 {
01042 kdDebug(5950) << "KAlarmApp::checkSystemTray(): changed -> " << mSavedNoSystemTray << endl;
01043 mNoSystemTray = mSavedNoSystemTray = !mSavedNoSystemTray;
01044
01045
01046
01047
01048
01049
01050 KConfig* config = kapp->config();
01051 config->setGroup(QString::fromLatin1("General"));
01052 config->writeEntry(QString::fromLatin1("NoSystemTray"), mNoSystemTray);
01053 config->sync();
01054
01055
01056 slotPreferencesChanged();
01057 }
01058 else
01059 {
01060 kdDebug(5950) << "KAlarmApp::checkSystemTray(): no change = " << !mSavedNoSystemTray << endl;
01061 mNoSystemTray = mSavedNoSystemTray;
01062 }
01063 return !mNoSystemTray;
01064 }
01065
01066
01067
01068
01069 MainWindow* KAlarmApp::trayMainWindow() const
01070 {
01071 return mTrayWindow ? mTrayWindow->assocMainWindow() : 0;
01072 }
01073
01074
01075
01076
01077 void KAlarmApp::slotPreferencesChanged()
01078 {
01079 bool newRunInSysTray = wantRunInSystemTray();
01080 if (newRunInSysTray != mOldRunInSystemTray)
01081 {
01082
01083 ++mActiveCount;
01084 MainWindow* win = mTrayWindow ? mTrayWindow->assocMainWindow() : 0;
01085 delete mTrayWindow;
01086 mTrayWindow = 0;
01087 mOldRunInSystemTray = newRunInSysTray;
01088 if (!newRunInSysTray)
01089 {
01090 if (win && win->isHidden())
01091 delete win;
01092 }
01093 displayTrayIcon(true);
01094 --mActiveCount;
01095 }
01096
01097 bool newDisableIfStopped = wantRunInSystemTray() && !mNoSystemTray && Preferences::disableAlarmsIfStopped();
01098 if (newDisableIfStopped != mDisableAlarmsIfStopped)
01099 {
01100 mDisableAlarmsIfStopped = newDisableIfStopped;
01101 Preferences::setQuitWarn(true);
01102 Daemon::reregister();
01103 }
01104
01105
01106 if (Preferences::startOfDay() != mStartOfDay)
01107 changeStartOfDay();
01108
01109
01110 KARecurrence::setDefaultFeb29Type(Preferences::defaultFeb29Type());
01111
01112 if (Preferences::expiredColour() != mPrefsExpiredColour)
01113 {
01114
01115 mRefreshExpiredAlarms = true;
01116 mPrefsExpiredColour = Preferences::expiredColour();
01117 }
01118
01119 if (Preferences::expiredKeepDays() != mPrefsExpiredKeepDays)
01120 {
01121
01122
01123 mPrefsExpiredKeepDays = Preferences::expiredKeepDays();
01124 AlarmCalendar::expiredCalendar()->setPurgeDays(mPrefsExpiredKeepDays);
01125 }
01126
01127 if (mRefreshExpiredAlarms)
01128 {
01129 mRefreshExpiredAlarms = false;
01130 MainWindow::updateExpired();
01131 }
01132 }
01133
01134
01135
01136
01137 void KAlarmApp::changeStartOfDay()
01138 {
01139 Daemon::notifyTimeChanged();
01140 QTime sod = Preferences::startOfDay();
01141 DateTime::setStartOfDay(sod);
01142 AlarmCalendar* cal = AlarmCalendar::activeCalendar();
01143 if (KAEvent::adjustStartOfDay(cal->events()))
01144 cal->save();
01145 Preferences::updateStartOfDayCheck();
01146 mStartOfDay = sod;
01147 }
01148
01149
01150
01151
01152
01153 void KAlarmApp::slotExpiredPurged()
01154 {
01155 mRefreshExpiredAlarms = false;
01156 MainWindow::updateExpired();
01157 }
01158
01159
01160
01161
01162 bool KAlarmApp::wantRunInSystemTray() const
01163 {
01164 return Preferences::runInSystemTray() && mHaveSystemTray;
01165 }
01166
01167
01168
01169
01170
01171
01172 bool KAlarmApp::scheduleEvent(KAEvent::Action action, const QString& text, const QDateTime& dateTime,
01173 int lateCancel, int flags, const QColor& bg, const QColor& fg, const QFont& font,
01174 const QString& audioFile, float audioVolume, int reminderMinutes,
01175 const KARecurrence& recurrence, int repeatInterval, int repeatCount,
01176 uint mailFromID, const EmailAddressList& mailAddresses,
01177 const QString& mailSubject, const QStringList& mailAttachments)
01178 {
01179 kdDebug(5950) << "KAlarmApp::scheduleEvent(): " << text << endl;
01180 if (!dateTime.isValid())
01181 return false;
01182 QDateTime now = QDateTime::currentDateTime();
01183 if (lateCancel && dateTime < now.addSecs(-maxLateness(lateCancel)))
01184 return true;
01185 QDateTime alarmTime = dateTime;
01186
01187 alarmTime.setTime(QTime(alarmTime.time().hour(), alarmTime.time().minute(), 0));
01188
01189 KAEvent event(alarmTime, text, bg, fg, font, action, lateCancel, flags);
01190 if (reminderMinutes)
01191 {
01192 bool onceOnly = (reminderMinutes < 0);
01193 event.setReminder((onceOnly ? -reminderMinutes : reminderMinutes), onceOnly);
01194 }
01195 if (!audioFile.isEmpty())
01196 event.setAudioFile(audioFile, audioVolume, -1, 0);
01197 if (!mailAddresses.isEmpty())
01198 event.setEmail(mailFromID, mailAddresses, mailSubject, mailAttachments);
01199 event.setRecurrence(recurrence);
01200 event.setFirstRecurrence();
01201 event.setRepetition(repeatInterval, repeatCount - 1);
01202 if (alarmTime <= now)
01203 {
01204
01205
01206 if (!mInitialised)
01207 mDcopQueue.append(DcopQEntry(event, EVENT_TRIGGER));
01208 else
01209 execAlarm(event, event.firstAlarm(), false);
01210
01211 if (!event.recurs()
01212 || event.setNextOccurrence(now) == KAEvent::NO_OCCURRENCE)
01213 return true;
01214
01215 }
01216
01217
01218 mDcopQueue.append(DcopQEntry(event));
01219 if (mInitialised)
01220 QTimer::singleShot(0, this, SLOT(processQueue()));
01221 return true;
01222 }
01223
01224
01225
01226
01227
01228
01229
01230 bool KAlarmApp::handleEvent(const QString& urlString, const QString& eventID, EventFunc function)
01231 {
01232 kdDebug(5950) << "KAlarmApp::handleEvent(DCOP): " << eventID << endl;
01233 AlarmCalendar* cal = AlarmCalendar::activeCalendar();
01234 if (cal && KURL(urlString).url() != cal->urlString())
01235 {
01236 kdError(5950) << "KAlarmApp::handleEvent(DCOP): wrong calendar file " << urlString << endl;
01237 Daemon::eventHandled(eventID, false);
01238 return false;
01239 }
01240 mDcopQueue.append(DcopQEntry(function, eventID));
01241 if (mInitialised)
01242 QTimer::singleShot(0, this, SLOT(processQueue()));
01243 return true;
01244 }
01245
01246
01247
01248
01249
01250
01251
01252
01253
01254 bool KAlarmApp::handleEvent(const QString& eventID, EventFunc function)
01255 {
01256 kdDebug(5950) << "KAlarmApp::handleEvent(): " << eventID << ", " << (function==EVENT_TRIGGER?"TRIGGER":function==EVENT_CANCEL?"CANCEL":function==EVENT_HANDLE?"HANDLE":"?") << endl;
01257 KCal::Event* kcalEvent = AlarmCalendar::activeCalendar()->event(eventID);
01258 if (!kcalEvent)
01259 {
01260 kdError(5950) << "KAlarmApp::handleEvent(): event ID not found: " << eventID << endl;
01261 Daemon::eventHandled(eventID, false);
01262 return false;
01263 }
01264 KAEvent event(*kcalEvent);
01265 switch (function)
01266 {
01267 case EVENT_CANCEL:
01268 KAlarm::deleteEvent(event, true);
01269 break;
01270
01271 case EVENT_TRIGGER:
01272 case EVENT_HANDLE:
01273 {
01274 QDateTime now = QDateTime::currentDateTime();
01275 bool updateCalAndDisplay = false;
01276 bool alarmToExecuteValid = false;
01277 KAAlarm alarmToExecute;
01278
01279
01280 for (KAAlarm alarm = event.firstAlarm(); alarm.valid(); alarm = event.nextAlarm(alarm))
01281 {
01282
01283 int secs = alarm.dateTime(true).dateTime().secsTo(now);
01284 if (secs < 0)
01285 {
01286
01287 kdDebug(5950) << "KAlarmApp::handleEvent(): alarm " << alarm.type() << ": not due\n";
01288 continue;
01289 }
01290 if (alarm.repeatAtLogin())
01291 {
01292
01293
01294
01295
01296 kdDebug(5950) << "KAlarmApp::handleEvent(): REPEAT_AT_LOGIN\n";
01297 if (secs < maxLateness(1))
01298 continue;
01299
01300
01301
01302 if (alarmToExecute.valid())
01303 continue;
01304
01305
01306 alarm.setTime(now);
01307 }
01308 if (alarm.lateCancel())
01309 {
01310
01311 kdDebug(5950) << "KAlarmApp::handleEvent(): LATE_CANCEL\n";
01312 bool late = false;
01313 bool cancel = false;
01314 if (alarm.dateTime().isDateOnly())
01315 {
01316
01317 int maxlate = alarm.lateCancel() / 1440;
01318 QDateTime limit(alarm.date().addDays(maxlate + 1), Preferences::startOfDay());
01319 if (now >= limit)
01320 {
01321
01322
01323 DateTime next;
01324 KAEvent::OccurType type = event.previousOccurrence(now, next, true);
01325 switch (type & ~KAEvent::OCCURRENCE_REPEAT)
01326 {
01327 case KAEvent::FIRST_OR_ONLY_OCCURRENCE:
01328 case KAEvent::RECURRENCE_DATE:
01329 case KAEvent::RECURRENCE_DATE_TIME:
01330 case KAEvent::LAST_RECURRENCE:
01331 limit.setDate(next.date().addDays(maxlate + 1));
01332 limit.setTime(Preferences::startOfDay());
01333 if (now >= limit)
01334 {
01335 if (type == KAEvent::LAST_RECURRENCE
01336 || type == KAEvent::FIRST_OR_ONLY_OCCURRENCE && !event.recurs())
01337 cancel = true;
01338 else
01339 late = true;
01340 }
01341 break;
01342 case KAEvent::NO_OCCURRENCE:
01343 default:
01344 late = true;
01345 break;
01346 }
01347 }
01348 }
01349 else
01350 {
01351
01352 int maxlate = maxLateness(alarm.lateCancel());
01353 if (secs > maxlate)
01354 {
01355
01356
01357 DateTime next;
01358 KAEvent::OccurType type = event.previousOccurrence(now, next, true);
01359 switch (type & ~KAEvent::OCCURRENCE_REPEAT)
01360 {
01361 case KAEvent::FIRST_OR_ONLY_OCCURRENCE:
01362 case KAEvent::RECURRENCE_DATE:
01363 case KAEvent::RECURRENCE_DATE_TIME:
01364 case KAEvent::LAST_RECURRENCE:
01365 if (next.dateTime().secsTo(now) > maxlate)
01366 {
01367 if (type == KAEvent::LAST_RECURRENCE
01368 || type == KAEvent::FIRST_OR_ONLY_OCCURRENCE && !event.recurs())
01369 cancel = true;
01370 else
01371 late = true;
01372 }
01373 break;
01374 case KAEvent::NO_OCCURRENCE:
01375 default:
01376 late = true;
01377 break;
01378 }
01379 }
01380 }
01381
01382 if (cancel)
01383 {
01384
01385 event.setArchive();
01386 cancelAlarm(event, alarm.type(), false);
01387 updateCalAndDisplay = true;
01388 continue;
01389 }
01390 if (late)
01391 {
01392
01393 rescheduleAlarm(event, alarm, false);
01394 updateCalAndDisplay = true;
01395 continue;
01396 }
01397 }
01398 if (!alarmToExecuteValid)
01399 {
01400 kdDebug(5950) << "KAlarmApp::handleEvent(): alarm " << alarm.type() << ": execute\n";
01401 alarmToExecute = alarm;
01402 alarmToExecuteValid = true;
01403 }
01404 else
01405 kdDebug(5950) << "KAlarmApp::handleEvent(): alarm " << alarm.type() << ": skip\n";
01406 }
01407
01408
01409
01410 if (alarmToExecute.valid())
01411 execAlarm(event, alarmToExecute, true, !alarmToExecute.repeatAtLogin());
01412 else
01413 {
01414 if (function == EVENT_TRIGGER)
01415 {
01416
01417
01418
01419 KAAlarm alarm = event.firstAlarm();
01420 if (alarm.valid())
01421 execAlarm(event, alarm, false);
01422 }
01423 if (updateCalAndDisplay)
01424 KAlarm::updateEvent(event, 0);
01425 else if (function != EVENT_TRIGGER)
01426 {
01427 kdDebug(5950) << "KAlarmApp::handleEvent(): no action\n";
01428 Daemon::eventHandled(eventID, false);
01429 }
01430 }
01431 break;
01432 }
01433 }
01434 return true;
01435 }
01436
01437
01438
01439
01440
01441
01442 void KAlarmApp::alarmShowing(KAEvent& event, KAAlarm::Type alarmType, const DateTime& alarmTime)
01443 {
01444 kdDebug(5950) << "KAlarmApp::alarmShowing(" << event.id() << ", " << KAAlarm::debugType(alarmType) << ")\n";
01445 KCal::Event* kcalEvent = AlarmCalendar::activeCalendar()->event(event.id());
01446 if (!kcalEvent)
01447 kdError(5950) << "KAlarmApp::alarmShowing(): event ID not found: " << event.id() << endl;
01448 else
01449 {
01450 KAAlarm alarm = event.alarm(alarmType);
01451 if (!alarm.valid())
01452 kdError(5950) << "KAlarmApp::alarmShowing(): alarm type not found: " << event.id() << ":" << alarmType << endl;
01453 else
01454 {
01455
01456 KAEvent dispEvent;
01457 dispEvent.setDisplaying(event, alarmType, alarmTime.dateTime());
01458 AlarmCalendar* cal = AlarmCalendar::displayCalendarOpen();
01459 if (cal)
01460 {
01461 cal->deleteEvent(dispEvent.id());
01462 cal->addEvent(dispEvent);
01463 cal->save();
01464 }
01465
01466 rescheduleAlarm(event, alarm, true);
01467 return;
01468 }
01469 }
01470 Daemon::eventHandled(event.id(), false);
01471 }
01472
01473
01474
01475
01476 void KAlarmApp::alarmCompleted(const KAEvent& event)
01477 {
01478 if (!event.postAction().isEmpty() && ShellProcess::authorised())
01479 {
01480 QString command = event.postAction();
01481 kdDebug(5950) << "KAlarmApp::alarmCompleted(" << event.id() << "): " << command << endl;
01482 doShellCommand(command, event, 0, ProcData::POST_ACTION);
01483 }
01484 }
01485
01486
01487
01488
01489
01490
01491 void KAlarmApp::rescheduleAlarm(KAEvent& event, const KAAlarm& alarm, bool updateCalAndDisplay)
01492 {
01493 kdDebug(5950) << "KAlarmApp::rescheduleAlarm()" << endl;
01494 bool update = false;
01495 if (alarm.reminder() || alarm.deferred())
01496 {
01497
01498 event.removeExpiredAlarm(alarm.type());
01499 update = true;
01500 }
01501 else if (alarm.repeatAtLogin())
01502 {
01503
01504 if (updateCalAndDisplay && event.updated())
01505 update = true;
01506 }
01507 else
01508 {
01509
01510 KAEvent::OccurType type = event.setNextOccurrence(QDateTime::currentDateTime());
01511 switch (type)
01512 {
01513 case KAEvent::NO_OCCURRENCE:
01514
01515 cancelAlarm(event, alarm.type(), updateCalAndDisplay);
01516 break;
01517 default:
01518 if (!(type & KAEvent::OCCURRENCE_REPEAT))
01519 break;
01520
01521 case KAEvent::RECURRENCE_DATE:
01522 case KAEvent::RECURRENCE_DATE_TIME:
01523 case KAEvent::LAST_RECURRENCE:
01524
01525 if (updateCalAndDisplay)
01526 update = true;
01527 else
01528 {
01529 event.cancelCancelledDeferral();
01530 event.setUpdated();
01531 }
01532 break;
01533 case KAEvent::FIRST_OR_ONLY_OCCURRENCE:
01534
01535 break;
01536 }
01537 if (event.deferred())
01538 {
01539
01540 event.removeExpiredAlarm(KAAlarm::DEFERRED_ALARM);
01541 update = true;
01542 }
01543 }
01544 if (update)
01545 {
01546 event.cancelCancelledDeferral();
01547 KAlarm::updateEvent(event, 0);
01548 }
01549 }
01550
01551
01552
01553
01554
01555 void KAlarmApp::cancelAlarm(KAEvent& event, KAAlarm::Type alarmType, bool updateCalAndDisplay)
01556 {
01557 kdDebug(5950) << "KAlarmApp::cancelAlarm()" << endl;
01558 event.cancelCancelledDeferral();
01559 if (alarmType == KAAlarm::MAIN_ALARM && !event.displaying() && event.toBeArchived())
01560 {
01561
01562 QString id = event.id();
01563 KAlarm::addExpiredEvent(event);
01564 event.setEventID(id);
01565 }
01566 event.removeExpiredAlarm(alarmType);
01567 if (!event.alarmCount())
01568 KAlarm::deleteEvent(event, false);
01569 else if (updateCalAndDisplay)
01570 KAlarm::updateEvent(event, 0);
01571 }
01572
01573
01574
01575
01576
01577
01578
01579 void* KAlarmApp::execAlarm(KAEvent& event, const KAAlarm& alarm, bool reschedule, bool allowDefer, bool noPreAction)
01580 {
01581 if (!event.enabled())
01582 {
01583
01584 if (reschedule)
01585 rescheduleAlarm(event, alarm, true);
01586 return 0;
01587 }
01588
01589 void* result = (void*)1;
01590 event.setArchive();
01591 switch (alarm.action())
01592 {
01593 case KAAlarm::MESSAGE:
01594 case KAAlarm::FILE:
01595 {
01596
01597 MessageWin* win = MessageWin::findEvent(event.id());
01598
01599 bool reminder = (alarm.type() & KAAlarm::REMINDER_ALARM);
01600 bool replaceReminder = !reminder && win && (win->alarmType() & KAAlarm::REMINDER_ALARM);
01601 if (!reminder && !event.deferred()
01602 && (replaceReminder || !win) && !noPreAction
01603 && !event.preAction().isEmpty() && ShellProcess::authorised())
01604 {
01605
01606
01607
01608
01609 for (QValueList<ProcData*>::Iterator it = mCommandProcesses.begin(); it != mCommandProcesses.end(); ++it)
01610 {
01611 ProcData* pd = *it;
01612 if (pd->event->id() == event.id() && (pd->flags & ProcData::PRE_ACTION))
01613 {
01614 kdDebug(5950) << "KAlarmApp::execAlarm(): already executing pre-DISPLAY command" << endl;
01615 return pd->process;
01616 }
01617 }
01618
01619 QString command = event.preAction();
01620 kdDebug(5950) << "KAlarmApp::execAlarm(): pre-DISPLAY command: " << command << endl;
01621 int flags = (reschedule ? ProcData::RESCHEDULE : 0) | (allowDefer ? ProcData::ALLOW_DEFER : 0);
01622 if (doShellCommand(command, event, &alarm, (flags | ProcData::PRE_ACTION)))
01623 return result;
01624
01625 }
01626 if (!event.enabled())
01627 delete win;
01628 else if (!win
01629 || !win->hasDefer() && !alarm.repeatAtLogin()
01630 || replaceReminder)
01631 {
01632
01633
01634
01635
01636 if (win)
01637 win->setRecreating();
01638 delete win;
01639 (new MessageWin(event, alarm, reschedule, allowDefer))->show();
01640 }
01641 else
01642 {
01643
01644 win->repeat(alarm);
01645 }
01646 break;
01647 }
01648 case KAAlarm::COMMAND:
01649 {
01650 int flags = event.commandXterm() ? ProcData::EXEC_IN_XTERM : 0;
01651 QString command = event.cleanText();
01652 if (event.commandScript())
01653 {
01654
01655 kdDebug(5950) << "KAlarmApp::execAlarm(): COMMAND: (script)" << endl;
01656 QString tmpfile = createTempScriptFile(command, false, event, alarm);
01657 if (tmpfile.isEmpty())
01658 result = 0;
01659 else
01660 result = doShellCommand(tmpfile, event, &alarm, (flags | ProcData::TEMP_FILE));
01661 }
01662 else
01663 {
01664 kdDebug(5950) << "KAlarmApp::execAlarm(): COMMAND: " << command << endl;
01665 result = doShellCommand(command, event, &alarm, flags);
01666 }
01667 if (reschedule)
01668 rescheduleAlarm(event, alarm, true);
01669 break;
01670 }
01671 case KAAlarm::EMAIL:
01672 {
01673 kdDebug(5950) << "KAlarmApp::execAlarm(): EMAIL to: " << event.emailAddresses(", ") << endl;
01674 QStringList errmsgs;
01675 if (!KAMail::send(event, errmsgs, (reschedule || allowDefer)))
01676 result = 0;
01677 if (!errmsgs.isEmpty())
01678 {
01679
01680 if (result)
01681 kdDebug(5950) << "KAlarmApp::execAlarm(): copy error: " << errmsgs[1] << endl;
01682 else
01683 kdDebug(5950) << "KAlarmApp::execAlarm(): failed: " << errmsgs[1] << endl;
01684 (new MessageWin(event, alarm.dateTime(), errmsgs))->show();
01685 }
01686 if (reschedule)
01687 rescheduleAlarm(event, alarm, true);
01688 break;
01689 }
01690 default:
01691 return 0;
01692 }
01693 return result;
01694 }
01695
01696
01697
01698
01699
01700
01701
01702 ShellProcess* KAlarmApp::doShellCommand(const QString& command, const KAEvent& event, const KAAlarm* alarm, int flags)
01703 {
01704 kdDebug(5950) << "KAlarmApp::doShellCommand(" << command << ", " << event.id() << ")" << endl;
01705 KProcess::Communication comms = KProcess::NoCommunication;
01706 QString cmd;
01707 QString tmpXtermFile;
01708 if (flags & ProcData::EXEC_IN_XTERM)
01709 {
01710
01711 cmd = Preferences::cmdXTermCommand();
01712 cmd.replace("%t", aboutData()->programName());
01713 if (cmd.find("%C") >= 0)
01714 {
01715
01716 if (flags & ProcData::TEMP_FILE)
01717 cmd.replace("%C", command);
01718 else
01719 {
01720 tmpXtermFile = createTempScriptFile(command, true, event, *alarm);
01721 if (tmpXtermFile.isEmpty())
01722 return 0;
01723 cmd.replace("%C", tmpXtermFile);
01724 }
01725 }
01726 else if (cmd.find("%W") >= 0)
01727 {
01728
01729
01730 tmpXtermFile = createTempScriptFile(command + QString::fromLatin1("\nsleep 86400\n"), true, event, *alarm);
01731 if (tmpXtermFile.isEmpty())
01732 return 0;
01733 cmd.replace("%W", tmpXtermFile);
01734 }
01735 else if (cmd.find("%w") >= 0)
01736 {
01737
01738
01739 QString exec = KShellProcess::quote(command + QString::fromLatin1("; sleep 86400"));
01740 cmd.replace("%w", exec);
01741 }
01742 else
01743 {
01744
01745
01746 QString exec = KShellProcess::quote(command);
01747 if (cmd.find("%c") >= 0)
01748 cmd.replace("%c", exec);
01749 else
01750 cmd.append(exec);
01751 }
01752 }
01753 else
01754 {
01755 cmd = command;
01756 comms = KProcess::AllOutput;
01757 }
01758 ShellProcess* proc = new ShellProcess(cmd);
01759 connect(proc, SIGNAL(shellExited(ShellProcess*)), SLOT(slotCommandExited(ShellProcess*)));
01760 QGuardedPtr<ShellProcess> logproc = 0;
01761 if (comms == KProcess::AllOutput && !event.logFile().isEmpty())
01762 {
01763
01764
01765 connect(proc, SIGNAL(receivedStdout(KProcess*,char*,int)), SLOT(slotCommandOutput(KProcess*,char*,int)));
01766 connect(proc, SIGNAL(receivedStderr(KProcess*,char*,int)), SLOT(slotCommandOutput(KProcess*,char*,int)));
01767 logproc = new ShellProcess(QString::fromLatin1("cat >>%1").arg(event.logFile()));
01768 connect(logproc, SIGNAL(shellExited(ShellProcess*)), SLOT(slotLogProcExited(ShellProcess*)));
01769 logproc->start(KProcess::Stdin);
01770 QCString heading;
01771 if (alarm && alarm->dateTime().isValid())
01772 {
01773 QString dateTime = alarm->dateTime().isDateOnly()
01774 ? KGlobal::locale()->formatDate(alarm->dateTime().date(), true)
01775 : KGlobal::locale()->formatDateTime(alarm->dateTime().dateTime());
01776 heading.sprintf("\n******* KAlarm %s *******\n", dateTime.latin1());
01777 }
01778 else
01779 heading = "\n******* KAlarm *******\n";
01780 logproc->writeStdin(heading, heading.length()+1);
01781 }
01782 ProcData* pd = new ProcData(proc, logproc, new KAEvent(event), (alarm ? new KAAlarm(*alarm) : 0), flags);
01783 if (flags & ProcData::TEMP_FILE)
01784 pd->tempFiles += command;
01785 if (!tmpXtermFile.isEmpty())
01786 pd->tempFiles += tmpXtermFile;
01787 mCommandProcesses.append(pd);
01788 if (proc->start(comms))
01789 return proc;
01790
01791
01792 kdError(5950) << "KAlarmApp::doShellCommand(): command failed to start\n";
01793 commandErrorMsg(proc, event, alarm, flags);
01794 mCommandProcesses.remove(pd);
01795 delete pd;
01796 return 0;
01797 }
01798
01799
01800
01801
01802
01803 QString KAlarmApp::createTempScriptFile(const QString& command, bool insertShell, const KAEvent& event, const KAAlarm& alarm)
01804 {
01805 KTempFile tmpFile(QString::null, QString::null, 0700);
01806 tmpFile.setAutoDelete(false);
01807 QTextStream* stream = tmpFile.textStream();
01808 if (!stream)
01809 kdError(5950) << "KAlarmApp::createTempScript(): Unable to create a temporary script file" << endl;
01810 else
01811 {
01812 if (insertShell)
01813 *stream << "#!" << ShellProcess::shellPath() << "\n";
01814 *stream << command;
01815 tmpFile.close();
01816 if (tmpFile.status())
01817 kdError(5950) << "KAlarmApp::createTempScript(): Error " << tmpFile.status() << " writing to temporary script file" << endl;
01818 else
01819 return tmpFile.name();
01820 }
01821
01822 QStringList errmsgs(i18n("Error creating temporary script file"));
01823 (new MessageWin(event, alarm.dateTime(), errmsgs))->show();
01824 return QString::null;
01825 }
01826
01827
01828
01829
01830 void KAlarmApp::slotCommandOutput(KProcess* proc, char* buffer, int bufflen)
01831 {
01832
01833
01834 for (QValueList<ProcData*>::Iterator it = mCommandProcesses.begin(); it != mCommandProcesses.end(); ++it)
01835 {
01836 ProcData* pd = *it;
01837 if (pd->process == proc && pd->logProcess)
01838 {
01839 pd->logProcess->writeStdin(buffer, bufflen);
01840 break;
01841 }
01842 }
01843 }
01844
01845
01846
01847
01848 void KAlarmApp::slotLogProcExited(ShellProcess* proc)
01849 {
01850
01851
01852 delete proc;
01853 }
01854
01855
01856
01857
01858 void KAlarmApp::slotCommandExited(ShellProcess* proc)
01859 {
01860 kdDebug(5950) << "KAlarmApp::slotCommandExited()\n";
01861
01862 for (QValueList<ProcData*>::Iterator it = mCommandProcesses.begin(); it != mCommandProcesses.end(); ++it)
01863 {
01864 ProcData* pd = *it;
01865 if (pd->process == proc)
01866 {
01867
01868 if (pd->logProcess)
01869 pd->logProcess->stdinExit();
01870
01871
01872 if (!proc->normalExit())
01873 {
01874 QString errmsg = proc->errorMessage();
01875 kdWarning(5950) << "KAlarmApp::slotCommandExited(" << pd->event->cleanText() << "): " << errmsg << endl;
01876 if (pd->messageBoxParent)
01877 {
01878
01879 QObjectList* dialogs = pd->messageBoxParent->queryList("KDialogBase", 0, false, true);
01880 KDialogBase* dialog = (KDialogBase*)dialogs->getFirst();
01881 delete dialog;
01882 delete dialogs;
01883 if (!pd->tempFile())
01884 {
01885 errmsg += '\n';
01886 errmsg += proc->command();
01887 }
01888 KMessageBox::error(pd->messageBoxParent, errmsg);
01889 }
01890 else
01891 commandErrorMsg(proc, *pd->event, pd->alarm, pd->flags);
01892 }
01893 if (pd->preAction())
01894 execAlarm(*pd->event, *pd->alarm, pd->reschedule(), pd->allowDefer(), true);
01895 mCommandProcesses.remove(it);
01896 delete pd;
01897 break;
01898 }
01899 }
01900
01901
01902 if (mPendingQuit && mCommandProcesses.isEmpty())
01903 quitIf(mPendingQuitCode);
01904 }
01905
01906
01907
01908
01909 void KAlarmApp::commandErrorMsg(const ShellProcess* proc, const KAEvent& event, const KAAlarm* alarm, int flags)
01910 {
01911 QStringList errmsgs;
01912 if (flags & ProcData::PRE_ACTION)
01913 errmsgs += i18n("Pre-alarm action:");
01914 else if (flags & ProcData::POST_ACTION)
01915 errmsgs += i18n("Post-alarm action:");
01916 errmsgs += proc->errorMessage();
01917 if (!(flags & ProcData::TEMP_FILE))
01918 errmsgs += proc->command();
01919 (new MessageWin(event, (alarm ? alarm->dateTime() : DateTime()), errmsgs))->show();
01920 }
01921
01922
01923
01924
01925 void KAlarmApp::commandMessage(ShellProcess* proc, QWidget* parent)
01926 {
01927
01928 for (QValueList<ProcData*>::Iterator it = mCommandProcesses.begin(); it != mCommandProcesses.end(); ++it)
01929 {
01930 ProcData* pd = *it;
01931 if (pd->process == proc)
01932 {
01933 pd->messageBoxParent = parent;
01934 break;
01935 }
01936 }
01937 }
01938
01939
01940
01941
01942 void KAlarmApp::setUpDcop()
01943 {
01944 if (!mInitialised)
01945 {
01946 mInitialised = true;
01947 Daemon::createDcopHandler();
01948 QTimer::singleShot(0, this, SLOT(processQueue()));
01949 }
01950 }
01951
01952
01953
01954
01955
01956 bool KAlarmApp::initCheck(bool calendarOnly)
01957 {
01958 bool startdaemon;
01959 AlarmCalendar* cal = AlarmCalendar::activeCalendar();
01960 if (!cal->isOpen())
01961 {
01962 kdDebug(5950) << "KAlarmApp::initCheck(): opening active calendar\n";
01963
01964
01965 if (!cal->open())
01966 return false;
01967
01968 if (!mStartOfDay.isValid())
01969 changeStartOfDay();
01970
01971
01972
01973
01974
01975
01976 AlarmCalendar::displayCalendar()->open();
01977
01978
01979
01980
01981
01982
01983 AlarmCalendar::expiredCalendar()->open();
01984 AlarmCalendar::expiredCalendar()->setPurgeDays(theInstance->mPrefsExpiredKeepDays);
01985
01986 startdaemon = true;
01987 }
01988 else
01989 startdaemon = !Daemon::isRegistered();
01990
01991 if (!calendarOnly)
01992 {
01993 setUpDcop();
01994 if (startdaemon)
01995 Daemon::start();
01996 }
01997 return true;
01998 }
01999
02000
02001
02002
02003
02004
02005 static bool convWakeTime(const QCString& timeParam, QDateTime& dateTime, bool& noTime)
02006 {
02007 if (timeParam.length() > 19)
02008 return false;
02009 char timeStr[20];
02010 strcpy(timeStr, timeParam);
02011 int dt[5] = { -1, -1, -1, -1, -1 };
02012 char* s;
02013 char* end;
02014
02015 if ((s = strchr(timeStr, ':')) == 0)
02016 noTime = true;
02017 else
02018 {
02019 noTime = false;
02020 *s++ = 0;
02021 dt[4] = strtoul(s, &end, 10);
02022 if (end == s || *end || dt[4] >= 60)
02023 return false;
02024
02025 if ((s = strrchr(timeStr, '-')) == 0)
02026 s = timeStr;
02027 else
02028 *s++ = 0;
02029 dt[3] = strtoul(s, &end, 10);
02030 if (end == s || *end || dt[3] >= 24)
02031 return false;
02032 }
02033 bool dateSet = false;
02034 if (s != timeStr)
02035 {
02036 dateSet = true;
02037
02038 if ((s = strrchr(timeStr, '-')) == 0)
02039 s = timeStr;
02040 else
02041 *s++ = 0;
02042 dt[2] = strtoul(s, &end, 10);
02043 if (end == s || *end || dt[2] == 0 || dt[2] > 31)
02044 return false;
02045 if (s != timeStr)
02046 {
02047
02048 if ((s = strrchr(timeStr, '-')) == 0)
02049 s = timeStr;
02050 else
02051 *s++ = 0;
02052 dt[1] = strtoul(s, &end, 10);
02053 if (end == s || *end || dt[1] == 0 || dt[1] > 12)
02054 return false;
02055 if (s != timeStr)
02056 {
02057
02058 dt[0] = strtoul(timeStr, &end, 10);
02059 if (end == timeStr || *end)
02060 return false;
02061 }
02062 }
02063 }
02064
02065 QDate date(dt[0], dt[1], dt[2]);
02066 QTime time(0, 0, 0);
02067 if (noTime)
02068 {
02069
02070 if (dt[0] < 0)
02071 return false;
02072 }
02073 else
02074 {
02075
02076 QDateTime now = QDateTime::currentDateTime();
02077 if (dt[0] < 0)
02078 date.setYMD(now.date().year(),
02079 (dt[1] < 0 ? now.date().month() : dt[1]),
02080 (dt[2] < 0 ? now.date().day() : dt[2]));
02081 time.setHMS(dt[3], dt[4], 0);
02082 if (!dateSet && time < now.time())
02083 date = date.addDays(1);
02084 }
02085 if (!date.isValid())
02086 return false;
02087 dateTime.setDate(date);
02088 dateTime.setTime(time);
02089 return true;
02090 }
02091
02092
02093
02094
02095
02096
02097
02098 static bool convInterval(const QCString& timeParam, KARecurrence::Type& recurType, int& timeInterval, bool allowMonthYear)
02099 {
02100 QCString timeString = timeParam;
02101
02102 bool ok = true;
02103 uint interval = 0;
02104 bool negative = (timeString[0] == '-');
02105 if (negative)
02106 timeString = timeString.right(1);
02107 uint length = timeString.length();
02108 switch (timeString[length - 1])
02109 {
02110 case 'Y':
02111 if (!allowMonthYear)
02112 ok = false;
02113 recurType = KARecurrence::ANNUAL_DATE;
02114 timeString = timeString.left(length - 1);
02115 break;
02116 case 'W':
02117 recurType = KARecurrence::WEEKLY;
02118 timeString = timeString.left(length - 1);
02119 break;
02120 case 'D':
02121 recurType = KARecurrence::DAILY;
02122 timeString = timeString.left(length - 1);
02123 break;
02124 case 'M':
02125 {
02126 int i = timeString.find('H');
02127 if (i < 0)
02128 {
02129 if (!allowMonthYear)
02130 ok = false;
02131 recurType = KARecurrence::MONTHLY_DAY;
02132 timeString = timeString.left(length - 1);
02133 }
02134 else
02135 {
02136 recurType = KARecurrence::MINUTELY;
02137 interval = timeString.left(i).toUInt(&ok) * 60;
02138 timeString = timeString.mid(i + 1, length - i - 2);
02139 }
02140 break;
02141 }
02142 default:
02143 recurType = KARecurrence::MINUTELY;
02144 break;
02145 }
02146 if (ok)
02147 interval += timeString.toUInt(&ok);
02148 if (!allowMonthYear)
02149 {
02150
02151 switch (recurType)
02152 {
02153 case KARecurrence::WEEKLY:
02154 interval *= 7;
02155
02156 case KARecurrence::DAILY:
02157 interval *= 24*60;
02158 break;
02159 default:
02160 break;
02161 }
02162 }
02163 timeInterval = static_cast<int>(interval);
02164 if (negative)
02165 timeInterval = -timeInterval;
02166 return ok;
02167 }
02168
02169 KAlarmApp::ProcData::ProcData(ShellProcess* p, ShellProcess* logp, KAEvent* e, KAAlarm* a, int f)
02170 : process(p),
02171 logProcess(logp),
02172 event(e),
02173 alarm(a),
02174 messageBoxParent(0),
02175 flags(f)
02176 { }
02177
02178 KAlarmApp::ProcData::~ProcData()
02179 {
02180 while (!tempFiles.isEmpty())
02181 {
02182
02183 QFile f(tempFiles.first());
02184 f.remove();
02185 tempFiles.remove(tempFiles.begin());
02186 }
02187 delete process;
02188 delete event;
02189 delete alarm;
02190 }