• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kalarm

  • sources
  • kde-4.12
  • kdepim
  • kalarm
kalarmapp.h
Go to the documentation of this file.
1 /*
2  * kalarmapp.h - the KAlarm application object
3  * Program: kalarm
4  * Copyright © 2001-2014 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 #ifdef USE_AKONADI
27 #include "eventid.h"
28 #endif
29 #include "kamail.h"
30 #include "preferences.h"
31 
32 #include <kalarmcal/kaevent.h>
33 
34 #include <kuniqueapplication.h>
35 
36 #include <QPointer>
37 #include <QQueue>
38 #include <QList>
39 
40 class KDateTime;
41 namespace KCal { class Event; }
42 #ifdef USE_AKONADI
43 namespace Akonadi { class Collection; }
44 #endif
45 class DBusHandler;
46 class MainWindow;
47 class TrayWindow;
48 class ShellProcess;
49 class OrgKdeKSpeechInterface;
50 
51 using namespace KAlarmCal;
52 
53 
54 class KAlarmApp : public KUniqueApplication
55 {
56  Q_OBJECT
57  public:
58  ~KAlarmApp();
59  virtual int newInstance();
60  static KAlarmApp* getInstance();
61  bool checkCalendar() { return initCheck(); }
62  bool wantShowInSystemTray() const;
63  bool alarmsEnabled() const { return mAlarmsEnabled; }
64  bool speechEnabled() const { return mSpeechEnabled; }
65  OrgKdeKSpeechInterface* kspeechInterface(QString& error) const;
66  bool korganizerEnabled() const { return mKOrganizerEnabled; }
67  bool restoreSession();
68  bool sessionClosingDown() const { return mSessionClosingDown; }
69  bool quitIf() { return quitIf(0); }
70  void doQuit(QWidget* parent);
71  static void displayFatalError(const QString& message);
72  void addWindow(TrayWindow* w) { mTrayWindow = w; }
73  void removeWindow(TrayWindow*);
74  TrayWindow* trayWindow() const { return mTrayWindow; }
75  MainWindow* trayMainWindow() const;
76  bool displayTrayIcon(bool show, MainWindow* = 0);
77  bool trayIconDisplayed() const { return mTrayWindow; }
78  bool editNewAlarm(MainWindow* = 0);
79  virtual void commitData(QSessionManager&);
80 
81  void* execAlarm(KAEvent&, const KAAlarm&, bool reschedule, bool allowDefer = true, bool noPreAction = false);
82  ShellProcess* execCommandAlarm(const KAEvent&, const KAAlarm&, const QObject* receiver = 0, const char* slot = 0);
83  void alarmCompleted(const KAEvent&);
84  void rescheduleAlarm(KAEvent& e, const KAAlarm& a) { rescheduleAlarm(e, a, true); }
85  void purgeAll() { purge(0); }
86  void commandMessage(ShellProcess*, QWidget* parent);
87  void notifyAudioPlaying(bool playing);
88  void setSpreadWindowsState(bool spread);
89  // Methods called indirectly by the DCOP interface
90  bool scheduleEvent(KAEvent::SubAction, const QString& text, const KDateTime&,
91  int lateCancel, KAEvent::Flags flags, const QColor& bg, const QColor& fg,
92  const QFont&, const QString& audioFile, float audioVolume,
93  int reminderMinutes, const KARecurrence& recurrence,
94  int repeatInterval, int repeatCount,
95 #ifdef USE_AKONADI
96  uint mailFromID = 0, const KCalCore::Person::List& mailAddresses = KCalCore::Person::List(),
97 #else
98  uint mailFromID = 0, const QList<KCal::Person>& mailAddresses = QList<KCal::Person>(),
99 #endif
100  const QString& mailSubject = QString(),
101  const QStringList& mailAttachments = QStringList());
102 #ifdef USE_AKONADI
103  bool dbusTriggerEvent(const EventId& eventID) { return dbusHandleEvent(eventID, EVENT_TRIGGER); }
104  bool dbusDeleteEvent(const EventId& eventID) { return dbusHandleEvent(eventID, EVENT_CANCEL); }
105 #else
106  bool dbusTriggerEvent(const QString& eventID) { return dbusHandleEvent(eventID, EVENT_TRIGGER); }
107  bool dbusDeleteEvent(const QString& eventID) { return dbusHandleEvent(eventID, EVENT_CANCEL); }
108 #endif
109  QString dbusList();
110 
111  public slots:
112  void processQueue();
113  void setAlarmsEnabled(bool);
114 #ifdef USE_AKONADI
115  void purgeNewArchivedDefault(const Akonadi::Collection&);
116  void atLoginEventAdded(const KAEvent&);
117 #endif
118  void notifyAudioStopped() { notifyAudioPlaying(false); }
119  void stopAudio();
120  void spreadWindows(bool);
121  void emailSent(KAMail::JobData&, const QStringList& errmsgs, bool copyerr = false);
122 
123  signals:
124  void trayIconToggled();
125  void alarmEnabledToggled(bool);
126  void audioPlaying(bool);
127  void spreadWindowsToggled(bool);
128  void execAlarmSuccess();
129 
130  protected:
131  KAlarmApp();
132 
133  private:
134  typedef Preferences::Feb29Type Feb29Type; // allow it to be used in SIGNAL mechanism
135 
136  private slots:
137  void quitFatal();
138  void checkNextDueAlarm();
139  void checkKtimezoned();
140  void slotShowInSystemTrayChanged();
141  void changeStartOfDay();
142  void slotWorkTimeChanged(const QTime& start, const QTime& end, const QBitArray& days);
143  void slotHolidaysChanged(const KHolidays::HolidayRegion&);
144  void slotFeb29TypeChanged(Feb29Type);
145  void checkWritableCalendar();
146  void slotMessageFontChanged(const QFont&);
147  void setArchivePurgeDays();
148  void slotPurge() { purge(mArchivedPurgeDays); }
149 #ifdef USE_AKONADI
150  void purgeAfterDelay();
151 #endif
152  void slotCommandExited(ShellProcess*);
153  void slotDBusServiceUnregistered(const QString& serviceName);
154 
155  private:
156  enum EventFunc
157  {
158  EVENT_HANDLE, // if the alarm is due, execute it and then reschedule it
159  EVENT_TRIGGER, // execute the alarm regardless, and then reschedule it if it already due
160  EVENT_CANCEL // delete the alarm
161  };
162  struct ProcData
163  {
164  ProcData(ShellProcess*, KAEvent*, KAAlarm*, int flags = 0);
165  ~ProcData();
166  enum { PRE_ACTION = 0x01, POST_ACTION = 0x02, RESCHEDULE = 0x04, ALLOW_DEFER = 0x08,
167  TEMP_FILE = 0x10, EXEC_IN_XTERM = 0x20, DISP_OUTPUT = 0x40 };
168  bool preAction() const { return flags & PRE_ACTION; }
169  bool postAction() const { return flags & POST_ACTION; }
170  bool reschedule() const { return flags & RESCHEDULE; }
171  bool allowDefer() const { return flags & ALLOW_DEFER; }
172  bool tempFile() const { return flags & TEMP_FILE; }
173  bool execInXterm() const { return flags & EXEC_IN_XTERM; }
174  bool dispOutput() const { return flags & DISP_OUTPUT; }
175  ShellProcess* process;
176  KAEvent* event;
177  KAAlarm* alarm;
178  QPointer<QWidget> messageBoxParent;
179  QStringList tempFiles;
180  int flags;
181  };
182  struct ActionQEntry
183  {
184 #ifdef USE_AKONADI
185  ActionQEntry(EventFunc f, const EventId& id) : function(f), eventId(id) { }
186 #else
187  ActionQEntry(EventFunc f, const QString& id) : function(f), eventId(id) { }
188 #endif
189  ActionQEntry(const KAEvent& e, EventFunc f = EVENT_HANDLE) : function(f), event(e) { }
190  ActionQEntry() { }
191  EventFunc function;
192 #ifdef USE_AKONADI
193  EventId eventId;
194 #else
195  QString eventId;
196 #endif
197  KAEvent event;
198  };
199 
200  bool initialise();
201 #ifdef USE_AKONADI
202  bool initCheck(bool calendarOnly = false, bool waitForCollection = false, Akonadi::Collection::Id = -1);
203 #else
204  bool initCheck(bool calendarOnly = false);
205 #endif
206  bool quitIf(int exitCode, bool force = false);
207  bool checkSystemTray();
208  void startProcessQueue();
209  void queueAlarmId(const KAEvent&);
210 #ifdef USE_AKONADI
211  bool dbusHandleEvent(const EventId&, EventFunc);
212  bool handleEvent(const EventId&, EventFunc, bool checkDuplicates = false);
213 #else
214  bool dbusHandleEvent(const QString& eventID, EventFunc);
215  bool handleEvent(const QString& eventID, EventFunc);
216 #endif
217  int rescheduleAlarm(KAEvent&, const KAAlarm&, bool updateCalAndDisplay,
218  const KDateTime& nextDt = KDateTime());
219  bool cancelAlarm(KAEvent&, KAAlarm::Type, bool updateCalAndDisplay);
220  bool cancelReminderAndDeferral(KAEvent&);
221  ShellProcess* doShellCommand(const QString& command, const KAEvent&, const KAAlarm*,
222  int flags = 0, const QObject* receiver = 0, const char* slot = 0);
223  QString composeXTermCommand(const QString& command, const KAEvent&, const KAAlarm*,
224  int flags, QString& tempScriptFile) const;
225  QString createTempScriptFile(const QString& command, bool insertShell, const KAEvent&, const KAAlarm&) const;
226  void commandErrorMsg(const ShellProcess*, const KAEvent&, const KAAlarm*, int flags = 0);
227  void purge(int daysToKeep);
228  QStringList scheduledAlarmList();
229 
230  static KAlarmApp* theInstance; // the one and only KAlarmApp instance
231  static int mActiveCount; // number of active instances without main windows
232  static int mFatalError; // a fatal error has occurred - just wait to exit
233  static QString mFatalMessage; // fatal error message to output
234  bool mInitialised; // initialisation complete: ready to process execution queue
235  bool mQuitting; // a forced quit is in progress
236  bool mReadOnly; // only read-only access to calendars is needed
237  bool mLoginAlarmsDone; // alarms repeated at login have been processed
238  DBusHandler* mDBusHandler; // the parent of the main DCOP receiver object
239  TrayWindow* mTrayWindow; // active system tray icon
240  QTimer* mAlarmTimer; // activates KAlarm when next alarm is due
241  QColor mPrefsArchivedColour; // archived alarms text colour
242  int mArchivedPurgeDays; // how long to keep archived alarms, 0 = don't keep, -1 = keep indefinitely
243  int mPurgeDaysQueued; // >= 0 to purge the archive calendar from KAlarmApp::processLoop()
244  QList<ProcData*> mCommandProcesses; // currently active command alarm processes
245  QQueue<ActionQEntry> mActionQueue; // queued commands and actions
246  mutable OrgKdeKSpeechInterface* mKSpeech;// KSpeech D-Bus interface object
247  int mPendingQuitCode; // exit code for a pending quit
248  bool mPendingQuit; // quit once the DCOP command and shell command queues have been processed
249  bool mCancelRtcWake; // cancel RTC wake on quitting
250  bool mProcessingQueue; // a mActionQueue entry is currently being processed
251  bool mNoSystemTray; // no system tray exists
252  bool mSessionClosingDown; // session manager is closing the application
253  bool mOldShowInSystemTray; // showing in system tray was selected
254  bool mAlarmsEnabled; // alarms are enabled
255  bool mSpeechEnabled; // speech synthesis is enabled (kttsd exists)
256  bool mKOrganizerEnabled; // KOrganizer options are enabled (korganizer exists)
257 };
258 
259 inline KAlarmApp* theApp() { return KAlarmApp::getInstance(); }
260 
261 #endif // KALARMAPP_H
262 
263 // vim: et sw=4:
KAlarmApp::rescheduleAlarm
void rescheduleAlarm(KAEvent &e, const KAAlarm &a)
Definition: kalarmapp.h:84
DBusHandler
Definition: dbushandler.h:40
KAlarmApp::alarmsEnabled
bool alarmsEnabled() const
Definition: kalarmapp.h:63
text
virtual QByteArray text(quint32 serialNumber) const =0
QWidget
eventid.h
KAlarmApp::dbusDeleteEvent
bool dbusDeleteEvent(const QString &eventID)
Definition: kalarmapp.h:107
QObject
TrayWindow
Definition: traywindow.h:45
PreferencesBase::Feb29Type
Feb29Type
Definition: kalarmconfig.h:25
QPointer< QWidget >
KAlarmApp::quitIf
bool quitIf()
Definition: kalarmapp.h:69
KAlarmApp::trayIconDisplayed
bool trayIconDisplayed() const
Definition: kalarmapp.h:77
KAlarmApp::getInstance
static KAlarmApp * getInstance()
Definition: kalarmapp.cpp:206
KAlarmApp::dbusTriggerEvent
bool dbusTriggerEvent(const QString &eventID)
Definition: kalarmapp.h:106
KAlarmApp::korganizerEnabled
bool korganizerEnabled() const
Definition: kalarmapp.h:66
KAlarmApp::checkCalendar
bool checkCalendar()
Definition: kalarmapp.h:61
KAlarmApp::notifyAudioStopped
void notifyAudioStopped()
Definition: kalarmapp.h:118
KAlarmApp::addWindow
void addWindow(TrayWindow *w)
Definition: kalarmapp.h:72
theApp
KAlarmApp * theApp()
Definition: kalarmapp.h:259
preferences.h
KAlarmApp
Definition: kalarmapp.h:54
kamail.h
EventId
Unique event identifier for Akonadi.
Definition: eventid.h:38
KAlarmApp::purgeAll
void purgeAll()
Definition: kalarmapp.h:85
KAlarmApp::sessionClosingDown
bool sessionClosingDown() const
Definition: kalarmapp.h:68
KAlarmApp::trayWindow
TrayWindow * trayWindow() const
Definition: kalarmapp.h:74
KAMail::JobData
Definition: kamail.h:56
KUniqueApplication
MainWindow
Definition: mainwindow.h:71
ShellProcess
QList< KCal::Person >
KAlarmApp::speechEnabled
bool speechEnabled() const
Definition: kalarmapp.h:64
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:59:10 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kalarm

Skip menu "kalarm"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal