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