SVN_SILENT made messages (after extraction)
[kdepim.git] / kalarm / alarmcalendar.h
bloba0e10d093a05c4284bc9d1dc3f660407f1162d85
1 /*
2 * alarmcalendar.h - KAlarm calendar file access
3 * Program: kalarm
4 * Copyright © 2001-2012 by David Jarvie <djarvie@kde.org>
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.
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.
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.
21 #ifndef ALARMCALENDAR_H
22 #define ALARMCALENDAR_H
24 #include "akonadimodel.h"
25 #include "eventid.h"
27 #include <kalarmcal/kaevent.h>
29 #include <AkonadiCore/collection.h>
30 #include <KCalCore/FileStorage>
31 #include <KCalCore/Event>
33 #include <QHash>
34 #include <QObject>
35 #include <QUrl>
38 using namespace KAlarmCal;
41 /** Provides read and write access to calendar files and resources.
42 * Either vCalendar or iCalendar files may be read, but the calendar is saved
43 * only in iCalendar format to avoid information loss.
45 class AlarmCalendar : public QObject
47 Q_OBJECT
48 public:
49 virtual ~AlarmCalendar();
50 bool valid() const { return (mCalType == RESOURCES) || mUrl.isValid(); }
51 CalEvent::Type type() const { return (mCalType == RESOURCES) ? CalEvent::EMPTY : mEventType; }
52 bool open();
53 int load();
54 bool reload();
55 bool save();
56 void close();
57 void startUpdate();
58 bool endUpdate();
59 KAEvent* earliestAlarm() const;
60 void setAlarmPending(KAEvent*, bool pending = true);
61 bool haveDisabledAlarms() const { return mHaveDisabledAlarms; }
62 void disabledChanged(const KAEvent*);
63 KAEvent::List atLoginAlarms() const;
64 KCalCore::Event::Ptr kcalEvent(const QString& uniqueID); // if Akonadi, display calendar only
65 KAEvent* event(const EventId& uniqueId, bool checkDuplicates = false);
66 KAEvent* templateEvent(const QString& templateName);
67 KAEvent::List events(const QString& uniqueId) const;
68 KAEvent::List events(CalEvent::Types s = CalEvent::EMPTY) const { return events(Akonadi::Collection(), s); }
69 KAEvent::List events(const Akonadi::Collection&, CalEvent::Types = CalEvent::EMPTY) const;
70 KCalCore::Event::List kcalEvents(CalEvent::Type s = CalEvent::EMPTY); // display calendar only
71 bool eventReadOnly(Akonadi::Item::Id) const;
72 Akonadi::Collection collectionForEvent(Akonadi::Item::Id) const;
73 bool addEvent(KAEvent&, QWidget* promptparent = Q_NULLPTR, bool useEventID = false, Akonadi::Collection* = Q_NULLPTR, bool noPrompt = false, bool* cancelled = Q_NULLPTR);
74 bool modifyEvent(const EventId& oldEventId, KAEvent& newEvent);
75 KAEvent* updateEvent(const KAEvent&);
76 KAEvent* updateEvent(const KAEvent*);
77 bool deleteEvent(const KAEvent&, bool save = false);
78 bool deleteDisplayEvent(const QString& eventID, bool save = false);
79 void purgeEvents(const KAEvent::List&);
80 bool isOpen();
81 QString path() const { return (mCalType == RESOURCES) ? QString() : mUrl.toDisplayString(); }
82 QString urlString() const { return (mCalType == RESOURCES) ? QString() : mUrl.toString(); }
83 void adjustStartOfDay();
85 static bool initialiseCalendars();
86 static void terminateCalendars();
87 static AlarmCalendar* resources() { return mResourcesCalendar; }
88 static AlarmCalendar* displayCalendar() { return mDisplayCalendar; }
89 static AlarmCalendar* displayCalendarOpen();
90 static KAEvent* getEvent(const EventId&);
91 static bool importAlarms(QWidget*, Akonadi::Collection* = Q_NULLPTR);
92 static bool exportAlarms(const KAEvent::List&, QWidget* parent);
94 Q_SIGNALS:
95 void earliestAlarmChanged();
96 void haveDisabledAlarmsChanged(bool haveDisabled);
97 void atLoginEventAdded(const KAEvent&);
98 void calendarSaved(AlarmCalendar*);
100 private Q_SLOTS:
101 void setAskResource(bool ask);
102 void slotCollectionStatusChanged(const Akonadi::Collection&, AkonadiModel::Change,
103 const QVariant& value, bool inserted);
104 void slotEventsAdded(const AkonadiModel::EventList&);
105 void slotEventsToBeRemoved(const AkonadiModel::EventList&);
106 void slotEventChanged(const AkonadiModel::Event&);
107 private:
108 enum CalType { RESOURCES, LOCAL_ICAL, LOCAL_VCAL };
109 typedef QMap<Akonadi::Collection::Id, KAEvent::List> ResourceMap; // id = invalid for display calendar
110 typedef QMap<Akonadi::Collection::Id, KAEvent*> EarliestMap;
111 typedef QHash<EventId, KAEvent*> KAEventMap; // indexed by collection and event UID
113 AlarmCalendar();
114 AlarmCalendar(const QString& file, CalEvent::Type);
115 bool saveCal(const QString& newFile = QString());
116 bool isValid() const { return mCalType == RESOURCES || mCalendarStorage; }
117 void addNewEvent(const Akonadi::Collection&, KAEvent*, bool replace = false);
118 CalEvent::Type deleteEventInternal(const KAEvent&, bool deleteFromAkonadi = true);
119 CalEvent::Type deleteEventInternal(const KAEvent&, const Akonadi::Collection&,
120 bool deleteFromAkonadi = true);
121 CalEvent::Type deleteEventInternal(const QString& eventID, const KAEvent& = KAEvent(),
122 const Akonadi::Collection& = Akonadi::Collection(), bool deleteFromAkonadi = true);
123 void updateDisplayKAEvents();
124 void removeKAEvents(Akonadi::Collection::Id, bool closing = false, CalEvent::Types = CalEvent::ACTIVE | CalEvent::ARCHIVED | CalEvent::TEMPLATE);
125 void findEarliestAlarm(const Akonadi::Collection&);
126 void findEarliestAlarm(Akonadi::Collection::Id); //deprecated
127 void checkForDisabledAlarms();
128 void checkForDisabledAlarms(bool oldEnabled, bool newEnabled);
130 static AlarmCalendar* mResourcesCalendar; // the calendar resources
131 static AlarmCalendar* mDisplayCalendar; // the display calendar
133 KCalCore::FileStorage::Ptr mCalendarStorage; // null pointer for Akonadi
134 ResourceMap mResourceMap;
135 KAEventMap mEventMap; // lookup of all events by UID
136 EarliestMap mEarliestAlarm; // alarm with earliest trigger time, by resource
137 QList<QString> mPendingAlarms; // IDs of alarms which are currently being processed after triggering
138 QUrl mUrl; // URL of current calendar file
139 QUrl mICalUrl; // URL of iCalendar file
140 QString mLocalFile; // calendar file, or local copy if it's a remote file
141 CalType mCalType; // what type of calendar mCalendar is (resources/ical/vcal)
142 CalEvent::Type mEventType; // what type of events the calendar file is for
143 bool mOpen; // true if the calendar file is open
144 int mUpdateCount; // nesting level of group of calendar update calls
145 bool mUpdateSave; // save() was called while mUpdateCount > 0
146 bool mHaveDisabledAlarms; // there is at least one individually disabled alarm
148 using QObject::event; // prevent "hidden" warning
151 #endif // ALARMCALENDAR_H
153 // vim: et sw=4: