kalarm

kalarmapp.h
Go to the documentation of this file.
00001 /*
00002  *  kalarmapp.h  -  the KAlarm application object
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2008 by David Jarvie <djarvie@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #ifndef KALARMAPP_H
00022 #define KALARMAPP_H
00023 
00026 #include <tqguardedptr.h>
00027 class TQTimer;
00028 class TQDateTime;
00029 
00030 #include <kuniqueapplication.h>
00031 #include <kurl.h>
00032 class KProcess;
00033 namespace KCal { class Event; }
00034 
00035 #include "alarmevent.h"
00036 class DcopHandler;
00037 #ifdef OLD_DCOP
00038 class DcopHandlerOld;
00039 #endif
00040 class AlarmCalendar;
00041 class MainWindow;
00042 class AlarmListView;
00043 class MessageWin;
00044 class TrayWindow;
00045 class ShellProcess;
00046 
00047 
00048 class KAlarmApp : public KUniqueApplication
00049 {
00050         Q_OBJECT
00051   TQ_OBJECT
00052     public:
00053         ~KAlarmApp();
00054         virtual int        newInstance();
00055         static KAlarmApp*  getInstance();
00056         bool               checkCalendarDaemon()           { return initCheck(); }
00057         bool               haveSystemTray() const          { return mHaveSystemTray; }
00058         bool               wantRunInSystemTray() const;
00059         bool               alarmsDisabledIfStopped() const { return mDisableAlarmsIfStopped; }
00060         bool               speechEnabled() const           { return mSpeechEnabled; }
00061         bool               korganizerEnabled() const       { return mKOrganizerEnabled; }
00062         bool               restoreSession();
00063         bool               sessionClosingDown() const      { return mSessionClosingDown; }
00064         void               quitIf()                        { quitIf(0); }
00065         void               doQuit(TQWidget* parent);
00066         static void        displayFatalError(const TQString& message);
00067         void               addWindow(TrayWindow* w)        { mTrayWindow = w; }
00068         void               removeWindow(TrayWindow*);
00069         TrayWindow*        trayWindow() const              { return mTrayWindow; }
00070         MainWindow*        trayMainWindow() const;
00071         bool               displayTrayIcon(bool show, MainWindow* = 0);
00072         bool               trayIconDisplayed() const       { return !!mTrayWindow; }
00073         bool               editNewAlarm(MainWindow* = 0);
00074         virtual void       commitData(TQSessionManager&);
00075 
00076         void*              execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
00077         void               alarmShowing(KAEvent&, KAAlarm::Type, const DateTime&);
00078         void               alarmCompleted(const KAEvent&);
00079         bool               deleteEvent(const TQString& eventID)         { return handleEvent(eventID, EVENT_CANCEL); }
00080         void               commandMessage(ShellProcess*, TQWidget* parent);
00081         // Methods called indirectly by the DCOP interface
00082         bool               scheduleEvent(KAEvent::Action, const TQString& text, const TQDateTime&,
00083                                          int lateCancel, int flags, const TQColor& bg, const TQColor& fg,
00084                                          const TQFont&, const TQString& audioFile, float audioVolume,
00085                                          int reminderMinutes, const KARecurrence& recurrence,
00086                          int repeatInterval, int repeatCount,
00087                                          uint mailFromID = 0, const EmailAddressList& mailAddresses = EmailAddressList(),
00088                                          const TQString& mailSubject = TQString(),
00089                                          const TQStringList& mailAttachments = TQStringList());
00090         bool               handleEvent(const TQString& calendarFile, const TQString& eventID)    { return handleEvent(calendarFile, eventID, EVENT_HANDLE); }
00091         bool               triggerEvent(const TQString& calendarFile, const TQString& eventID)   { return handleEvent(calendarFile, eventID, EVENT_TRIGGER); }
00092         bool               deleteEvent(const TQString& calendarFile, const TQString& eventID)    { return handleEvent(calendarFile, eventID, EVENT_CANCEL); }
00093     public slots:
00094         void               processQueue();
00095     signals:
00096         void               trayIconToggled();
00097     protected:
00098         KAlarmApp();
00099     private slots:
00100         void               quitFatal();
00101         void               slotPreferencesChanged();
00102         void               slotCommandOutput(KProcess*, char* buffer, int bufflen);
00103         void               slotLogProcExited(ShellProcess*);
00104         void               slotCommandExited(ShellProcess*);
00105         void               slotSystemTrayTimer();
00106         void               slotExpiredPurged();
00107     private:
00108         enum EventFunc
00109         {
00110             EVENT_HANDLE,    // if the alarm is due, execute it and then reschedule it
00111             EVENT_TRIGGER,   // execute the alarm regardless, and then reschedule it if it already due
00112             EVENT_CANCEL     // delete the alarm
00113         };
00114         struct ProcData
00115         {
00116             ProcData(ShellProcess* p, ShellProcess* logp, KAEvent* e, KAAlarm* a, int f = 0);
00117             ~ProcData();
00118             enum { PRE_ACTION = 0x01, POST_ACTION = 0x02, RESCHEDULE = 0x04, ALLOW_DEFER = 0x08,
00119                    TEMP_FILE = 0x10, EXEC_IN_XTERM = 0x20 };
00120             bool                 preAction() const   { return flags & PRE_ACTION; }
00121             bool                 postAction() const  { return flags & POST_ACTION; }
00122             bool                 reschedule() const  { return flags & RESCHEDULE; }
00123             bool                 allowDefer() const  { return flags & ALLOW_DEFER; }
00124             bool                 tempFile() const    { return flags & TEMP_FILE; }
00125             bool                 execInXterm() const { return flags & EXEC_IN_XTERM; }
00126             ShellProcess*             process;
00127             TQGuardedPtr<ShellProcess> logProcess;
00128             KAEvent*                  event;
00129             KAAlarm*                  alarm;
00130             TQGuardedPtr<TQWidget>      messageBoxParent;
00131             TQStringList               tempFiles;
00132             int                       flags;
00133         };
00134         struct DcopTQEntry
00135         {
00136             DcopTQEntry(EventFunc f, const TQString& id) : function(f), eventId(id) { }
00137             DcopTQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
00138             DcopTQEntry() { }
00139             EventFunc  function;
00140             TQString    eventId;
00141             KAEvent    event;
00142         };
00143 
00144         bool               initCheck(bool calendarOnly = false);
00145         void               quitIf(int exitCode, bool force = false);
00146         void               redisplayAlarms();
00147         bool               checkSystemTray();
00148         void               changeStartOfDay();
00149         void               setUpDcop();
00150         bool               handleEvent(const TQString& calendarFile, const TQString& eventID, EventFunc);
00151         bool               handleEvent(const TQString& eventID, EventFunc);
00152         void               rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay);
00153         void               cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
00154         ShellProcess*      doShellCommand(const TQString& command, const KAEvent&, const KAAlarm*, int flags = 0);
00155         TQString            createTempScriptFile(const TQString& command, bool insertShell, const KAEvent&, const KAAlarm&);
00156         void               commandErrorMsg(const ShellProcess*, const KAEvent&, const KAAlarm*, int flags = 0);
00157 
00158         static KAlarmApp*     theInstance;          // the one and only KAlarmApp instance
00159         static int            mActiveCount;         // number of active instances without main windows
00160         static int            mFatalError;          // a fatal error has occurred - just wait to exit
00161         static TQString        mFatalMessage;        // fatal error message to output
00162         bool                  mInitialised;         // initialisation complete: ready to handle DCOP calls
00163         DcopHandler*          mDcopHandler;         // the parent of the main DCOP receiver object
00164 #ifdef OLD_DCOP
00165         DcopHandlerOld*       mDcopHandlerOld;      // the parent of the old main DCOP receiver object
00166 #endif
00167         TrayWindow*           mTrayWindow;          // active system tray icon
00168         TQTime                 mStartOfDay;          // start-of-day time currently in use
00169         TQColor                mPrefsExpiredColour;  // expired alarms text colour
00170         int                   mPrefsExpiredKeepDays;// how long expired alarms are being kept
00171         TQValueList<ProcData*> mCommandProcesses;    // currently active command alarm processes
00172         TQValueList<DcopTQEntry> mDcopQueue;          // DCOP command queue
00173         int                   mPendingQuitCode;     // exit code for a pending quit
00174         bool                  mPendingQuit;         // quit once the DCOP command and shell command queues have been processed
00175         bool                  mProcessingQueue;     // a mDcopQueue entry is currently being processed
00176         bool                  mHaveSystemTray;      // whether there is a system tray
00177         bool                  mNoSystemTray;        // no KDE system tray exists
00178         bool                  mSavedNoSystemTray;   // mNoSystemTray before mCheckingSystemTray was true
00179         bool                  mCheckingSystemTray;  // the existence of the system tray is being checked
00180         bool                  mSessionClosingDown;  // session manager is closing the application
00181         bool                  mOldRunInSystemTray;  // running continuously in system tray was selected
00182         bool                  mDisableAlarmsIfStopped; // disable alarms whenever KAlarm is not running
00183         bool                  mRefreshExpiredAlarms; // need to refresh the expired alarms display
00184         bool                  mSpeechEnabled;       // speech synthesis is enabled (kttsd exists)
00185         bool                  mKOrganizerEnabled;   // KOrganizer options are enabled (korganizer exists)
00186 };
00187 
00188 inline KAlarmApp* theApp()  { return KAlarmApp::getInstance(); }
00189 
00190 #endif // KALARMAPP_H