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

kalarm

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

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