kalarm

kalarmapp.h

Go to the documentation of this file.
00001 /*
00002  *  kalarmapp.h  -  the KAlarm application object
00003  *  Program:  kalarm
00004  *  Copyright © 2001-2006 by David Jarvie <software@astrojar.org.uk>
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 <qguardedptr.h>
00027 class QTimer;
00028 class QDateTime;
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     public:
00052         ~KAlarmApp();
00053         virtual int        newInstance();
00054         static KAlarmApp*  getInstance();
00055         bool               checkCalendarDaemon()           { return initCheck(); }
00056         bool               haveSystemTray() const          { return mHaveSystemTray; }
00057         bool               wantRunInSystemTray() const;
00058         bool               alarmsDisabledIfStopped() const { return mDisableAlarmsIfStopped; }
00059         bool               speechEnabled() const           { return mSpeechEnabled; }
00060         bool               korganizerEnabled() const       { return mKOrganizerEnabled; }
00061         bool               restoreSession();
00062         bool               sessionClosingDown() const      { return mSessionClosingDown; }
00063         void               quitIf()                        { quitIf(0); }
00064         void               doQuit(QWidget* parent);
00065         static void        displayFatalError(const QString& message);
00066         void               addWindow(TrayWindow* w)        { mTrayWindow = w; }
00067         void               removeWindow(TrayWindow*);
00068         TrayWindow*        trayWindow() const              { return mTrayWindow; }
00069         MainWindow*        trayMainWindow() const;
00070         bool               displayTrayIcon(bool show, MainWindow* = 0);
00071         bool               trayIconDisplayed() const       { return !!mTrayWindow; }
00072         bool               editNewAlarm(MainWindow* = 0);
00073         virtual void       commitData(QSessionManager&);
00074 
00075         void*              execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
00076         void               alarmShowing(KAEvent&, KAAlarm::Type, const DateTime&);
00077         void               alarmCompleted(const KAEvent&);
00078         bool               deleteEvent(const QString& eventID)         { return handleEvent(eventID, EVENT_CANCEL); }
00079         void               commandMessage(ShellProcess*, QWidget* parent);
00080         // Methods called indirectly by the DCOP interface
00081         bool               scheduleEvent(KAEvent::Action, const QString& text, const QDateTime&,
00082                                          int lateCancel, int flags, const QColor& bg, const QColor& fg,
00083                                          const QFont&, const QString& audioFile, float audioVolume,
00084                                          int reminderMinutes, const KARecurrence& recurrence,
00085                          int repeatInterval, int repeatCount,
00086                                          const QString& mailFromID = QString::null,
00087                                          const EmailAddressList& mailAddresses = EmailAddressList(),
00088                                          const QString& mailSubject = QString::null,
00089                                          const QStringList& mailAttachments = QStringList());
00090         bool               handleEvent(const QString& calendarFile, const QString& eventID)    { return handleEvent(calendarFile, eventID, EVENT_HANDLE); }
00091         bool               triggerEvent(const QString& calendarFile, const QString& eventID)   { return handleEvent(calendarFile, eventID, EVENT_TRIGGER); }
00092         bool               deleteEvent(const QString& calendarFile, const QString& 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             QGuardedPtr<ShellProcess> logProcess;
00128             KAEvent*                  event;
00129             KAAlarm*                  alarm;
00130             QGuardedPtr<QWidget>      messageBoxParent;
00131             QStringList               tempFiles;
00132             int                       flags;
00133         };
00134         struct DcopQEntry
00135         {
00136             DcopQEntry(EventFunc f, const QString& id) : function(f), eventId(id) { }
00137             DcopQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
00138             DcopQEntry() { }
00139             EventFunc  function;
00140             QString    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 QString& calendarFile, const QString& eventID, EventFunc);
00151         bool               handleEvent(const QString& eventID, EventFunc);
00152         void               rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay);
00153         void               cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
00154         ShellProcess*      doShellCommand(const QString& command, const KAEvent&, const KAAlarm*, int flags = 0);
00155         QString            createTempScriptFile(const QString& 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 QString        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         QTime                 mStartOfDay;          // start-of-day time currently in use
00169         QColor                mPrefsExpiredColour;  // expired alarms text colour
00170         int                   mPrefsExpiredKeepDays;// how long expired alarms are being kept
00171         QValueList<ProcData*> mCommandProcesses;    // currently active command alarm processes
00172         QValueList<DcopQEntry> 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         bool                  mPrefsShowTime;       // Preferences setting for show alarm times in alarm list
00187         bool                  mPrefsShowTimeTo;     // Preferences setting for show time-to-alarms in alarm list
00188 };
00189 
00190 inline KAlarmApp* theApp()  { return KAlarmApp::getInstance(); }
00191 
00192 #endif // KALARMAPP_H
KDE Home | KDE Accessibility Home | Description of Access Keys