kalarm

kalarmapp.h
Go to the documentation of this file.
1 /*
2  * kalarmapp.h - the KAlarm application object
3  * Program: kalarm
4  * Copyright © 2001-2008 by David Jarvie <djarvie@kde.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef KALARMAPP_H
22 #define KALARMAPP_H
23 
26 #include <tqguardedptr.h>
27 class TQTimer;
28 class TQDateTime;
29 
30 #include <tdeuniqueapplication.h>
31 #include <kurl.h>
32 class TDEProcess;
33 namespace KCal { class Event; }
34 
35 #include "alarmevent.h"
36 class DcopHandler;
37 #ifdef OLD_DCOP
38 class DcopHandlerOld;
39 #endif
40 class AlarmCalendar;
41 class MainWindow;
42 class AlarmListView;
43 class MessageWin;
44 class TrayWindow;
45 class ShellProcess;
46 
47 
48 class KAlarmApp : public TDEUniqueApplication
49 {
50  TQ_OBJECT
51 
52  public:
53  ~KAlarmApp();
54  virtual int newInstance();
55  static KAlarmApp* getInstance();
56  bool checkCalendarDaemon() { return initCheck(); }
57  bool haveSystemTray() const { return mHaveSystemTray; }
58  bool wantRunInSystemTray() const;
59  bool alarmsDisabledIfStopped() const { return mDisableAlarmsIfStopped; }
60  bool speechEnabled() const { return mSpeechEnabled; }
61  bool korganizerEnabled() const { return mKOrganizerEnabled; }
62  bool restoreSession();
63  bool sessionClosingDown() const { return mSessionClosingDown; }
64  void quitIf() { quitIf(0); }
65  void doQuit(TQWidget* parent);
66  static void displayFatalError(const TQString& message);
67  void addWindow(TrayWindow* w) { mTrayWindow = w; }
68  void removeWindow(TrayWindow*);
69  TrayWindow* trayWindow() const { return mTrayWindow; }
70  MainWindow* trayMainWindow() const;
71  bool displayTrayIcon(bool show, MainWindow* = 0);
72  bool trayIconDisplayed() const { return !!mTrayWindow; }
73  bool editNewAlarm(MainWindow* = 0);
74  virtual void commitData(TQSessionManager&);
75 
76  void* execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
77  void alarmShowing(KAEvent&, KAAlarm::Type, const DateTime&);
78  void alarmCompleted(const KAEvent&);
79  bool deleteEvent(const TQString& eventID) { return handleEvent(eventID, EVENT_CANCEL); }
80  void commandMessage(ShellProcess*, TQWidget* parent);
81  // Methods called indirectly by the DCOP interface
82  bool scheduleEvent(KAEvent::Action, const TQString& text, const TQDateTime&,
83  int lateCancel, int flags, const TQColor& bg, const TQColor& fg,
84  const TQFont&, const TQString& audioFile, float audioVolume,
85  int reminderMinutes, const KARecurrence& recurrence,
86  int repeatInterval, int repeatCount,
87  uint mailFromID = 0, const EmailAddressList& mailAddresses = EmailAddressList(),
88  const TQString& mailSubject = TQString(),
89  const TQStringList& mailAttachments = TQStringList());
90  bool handleEvent(const TQString& calendarFile, const TQString& eventID) { return handleEvent(calendarFile, eventID, EVENT_HANDLE); }
91  bool triggerEvent(const TQString& calendarFile, const TQString& eventID) { return handleEvent(calendarFile, eventID, EVENT_TRIGGER); }
92  bool deleteEvent(const TQString& calendarFile, const TQString& eventID) { return handleEvent(calendarFile, eventID, EVENT_CANCEL); }
93  public slots:
94  void processQueue();
95  signals:
96  void trayIconToggled();
97  protected:
98  KAlarmApp();
99  private slots:
100  void quitFatal();
101  void slotPreferencesChanged();
102  void slotCommandOutput(TDEProcess*, char* buffer, int bufflen);
103  void slotLogProcExited(ShellProcess*);
104  void slotCommandExited(ShellProcess*);
105  void slotSystemTrayTimer();
106  void slotExpiredPurged();
107  private:
108  enum EventFunc
109  {
110  EVENT_HANDLE, // if the alarm is due, execute it and then reschedule it
111  EVENT_TRIGGER, // execute the alarm regardless, and then reschedule it if it already due
112  EVENT_CANCEL // delete the alarm
113  };
114  struct ProcData
115  {
116  ProcData(ShellProcess* p, ShellProcess* logp, KAEvent* e, KAAlarm* a, int f = 0);
117  ~ProcData();
118  enum { PRE_ACTION = 0x01, POST_ACTION = 0x02, RESCHEDULE = 0x04, ALLOW_DEFER = 0x08,
119  TEMP_FILE = 0x10, EXEC_IN_XTERM = 0x20 };
120  bool preAction() const { return flags & PRE_ACTION; }
121  bool postAction() const { return flags & POST_ACTION; }
122  bool reschedule() const { return flags & RESCHEDULE; }
123  bool allowDefer() const { return flags & ALLOW_DEFER; }
124  bool tempFile() const { return flags & TEMP_FILE; }
125  bool execInXterm() const { return flags & EXEC_IN_XTERM; }
126  ShellProcess* process;
127  TQGuardedPtr<ShellProcess> logProcess;
128  KAEvent* event;
129  KAAlarm* alarm;
130  TQGuardedPtr<TQWidget> messageBoxParent;
131  TQStringList tempFiles;
132  int flags;
133  };
134  struct DcopTQEntry
135  {
136  DcopTQEntry(EventFunc f, const TQString& id) : function(f), eventId(id) { }
137  DcopTQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
138  DcopTQEntry() { }
139  EventFunc function;
140  TQString eventId;
141  KAEvent event;
142  };
143 
144  bool initCheck(bool calendarOnly = false);
145  void quitIf(int exitCode, bool force = false);
146  void redisplayAlarms();
147  bool checkSystemTray();
148  void changeStartOfDay();
149  void setUpDcop();
150  bool handleEvent(const TQString& calendarFile, const TQString& eventID, EventFunc);
151  bool handleEvent(const TQString& eventID, EventFunc);
152  void rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay);
153  void cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
154  ShellProcess* doShellCommand(const TQString& command, const KAEvent&, const KAAlarm*, int flags = 0);
155  TQString createTempScriptFile(const TQString& command, bool insertShell, const KAEvent&, const KAAlarm&);
156  void commandErrorMsg(const ShellProcess*, const KAEvent&, const KAAlarm*, int flags = 0);
157 
158  static KAlarmApp* theInstance; // the one and only KAlarmApp instance
159  static int mActiveCount; // number of active instances without main windows
160  static int mFatalError; // a fatal error has occurred - just wait to exit
161  static TQString mFatalMessage; // fatal error message to output
162  bool mInitialised; // initialisation complete: ready to handle DCOP calls
163  DcopHandler* mDcopHandler; // the parent of the main DCOP receiver object
164 #ifdef OLD_DCOP
165  DcopHandlerOld* mDcopHandlerOld; // the parent of the old main DCOP receiver object
166 #endif
167  TrayWindow* mTrayWindow; // active system tray icon
168  TQTime mStartOfDay; // start-of-day time currently in use
169  TQColor mPrefsExpiredColour; // expired alarms text colour
170  int mPrefsExpiredKeepDays;// how long expired alarms are being kept
171  TQValueList<ProcData*> mCommandProcesses; // currently active command alarm processes
172  TQValueList<DcopTQEntry> mDcopQueue; // DCOP command queue
173  int mPendingQuitCode; // exit code for a pending quit
174  bool mPendingQuit; // quit once the DCOP command and shell command queues have been processed
175  bool mProcessingQueue; // a mDcopQueue entry is currently being processed
176  bool mHaveSystemTray; // whether there is a system tray
177  bool mNoSystemTray; // no KDE system tray exists
178  bool mSavedNoSystemTray; // mNoSystemTray before mCheckingSystemTray was true
179  bool mCheckingSystemTray; // the existence of the system tray is being checked
180  bool mSessionClosingDown; // session manager is closing the application
181  bool mOldRunInSystemTray; // running continuously in system tray was selected
182  bool mDisableAlarmsIfStopped; // disable alarms whenever KAlarm is not running
183  bool mRefreshExpiredAlarms; // need to refresh the expired alarms display
184  bool mSpeechEnabled; // speech synthesis is enabled (kttsd exists)
185  bool mKOrganizerEnabled; // KOrganizer options are enabled (korganizer exists)
186 };
187 
188 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
189 
190 #endif // KALARMAPP_H
represents calendar alarms and events
Provides read and write access to calendar files.
Definition: alarmcalendar.h:37
KAEvent corresponds to a KCal::Event instance.
Definition: alarmevent.h:232
MessageWin: A window to display an alarm message.
Definition: messagewin.h:45