41
41
/** Base class for a KAlarm alarm calendar resource. */
42
42
class KALARM_RESOURCES_EXPORT AlarmResource : public KCal::ResourceCached
46
/** Type of alarms held in this calendar resource. */
49
ACTIVE = 0x01, // active alarms
50
ARCHIVED = 0x02, // archived alarms
51
TEMPLATE = 0x04 // alarm templates
53
/** Whether the fix function should convert old format KAlarm calendars. */
54
enum FixFunc { PROMPT, PROMPT_PART, CONVERT, NO_CONVERT };
57
explicit AlarmResource(const KConfigGroup&);
58
explicit AlarmResource(Type);
60
virtual void writeConfig(KConfigGroup&);
61
virtual QString infoText() const;
62
KABC::Lock* lock() { return mLock; }
64
/** Return which type of alarms the resource can contain. */
65
Type alarmType() const { return mType; }
67
/** Return which type of alarms the resource can contain. */
68
KCalEvent::Status kcalEventType() const;
70
/** Set the type of alarms which the resource can contain. */
71
void setAlarmType(Type type) { mType = type; }
73
/** Return whether the resource contains only alarms of the wrong type. */
74
bool isWrongAlarmType() const { return mWrongAlarmType; }
76
/** Check whether the alarm types in a calendar correspond with
77
* the resource's alarm type.
78
* Reply = true if at least 1 alarm is the right type.
80
bool checkAlarmTypes(KCal::CalendarLocal&) const;
82
/** Set whether the application has a GUI. This determines whether error or
83
* progress messages are displayed. */
84
static void setNoGui(bool noGui) { mNoGui = noGui; }
85
static bool hasGui() { return !mNoGui; }
87
/** Return the location(s) of the resource (URL, file path, etc.) */
88
virtual QStringList location() const = 0;
90
/** Return the type of the resource (URL, file, etc.)
91
* for display purposes. */
92
virtual QString displayType() const = 0;
94
/** Return the location of the resource (URL, file path, etc.)
95
* for display purposes. */
96
virtual QString displayLocation() const = 0;
98
/** Change the resource's location. The resource will be reloaded if active. */
99
virtual bool setLocation(const QString& locn, const QString& locn2 = QString()) = 0;
100
/** Return whether the resource is the standard resource for its alarm type. */
101
bool standardResource() const { return mStandard; }
103
/** Set or clear the resource as the standard resource for its alarm type. */
104
void setStandardResource(bool std) { mStandard = std; }
106
void setEnabled(bool enable);
107
bool isEnabled() const { return !mWrongAlarmType && isActive(); }
109
/** Return whether the resource can be written to now,
110
* i.e. it's active, read-write and in the current KAlarm format. */
111
bool writable() const { return isEnabled() && !readOnly(); }
113
/** Return whether the event can be written to now, i.e. the resource is
114
* active and read-write, and the event is in the current KAlarm format. */
115
bool writable(const KCal::Event*) const;
117
/** Return whether the resource is cached, i.e. whether it is downloaded
118
* and stored locally in a cache file. */
119
virtual bool cached() const { return false; }
121
/** Return whether the resource is read-only, either because it's marked as
122
* read-only, or because it's active but not in the current KAlarm format. */
123
virtual bool readOnly() const;
124
virtual void setReadOnly(bool);
126
/** Return the colour used to display alarms belonging to this resource.
127
* @return display colour, or invalid if none specified */
128
QColor colour() const { return mColour; }
130
/** Set the colour used to display alarms belonging to this resource.
131
* @param color display colour, or invalid to use the default colour */
132
void setColour(const QColor& color);
133
/** Start a batch of configuration changes.
134
* The changes will be stored up until applyReconfig() is called. */
135
virtual void startReconfig();
137
/** Apply the batch of configuration changes since startReconfig() was called. */
138
virtual void applyReconfig();
140
/** Load the resource.
141
* If it's a cached resource, load() uses the default action to either refresh
142
* the cache file first or not.
143
* If loading succeeds, the loaded() signal is emitted on completion (but is
144
* not emitted if false is returned). This allows AlarmResources to process
146
* Loading is not performed if the resource is disabled.
147
* @return true if loading succeeded at least partially, false if it failed
150
bool load(CacheAction a) { return KCal::ResourceCached::load(a); }
152
/** Return whether the resource has fully loaded. */
153
bool isLoaded() const { return mLoaded; }
155
/** Return whether the resource is in the process of loading. */
156
bool isLoading() const { return mLoading; }
158
/** Save the resource and then close it.
159
* It will be closed even if saving fails. */
160
bool saveAndClose(CacheAction, KCal::Incidence* = 0);
161
bool saveAndClose(KCal::Incidence* incidence = 0) { return saveAndClose(DefaultCache, incidence); }
163
/** Set a function to write the application ID into a calendar. */
164
static void setCalIDFunction(void (*f)(CalendarLocal&)) { mCalIDFunction = f; }
165
/** Set a function to create KAlarm event instances.
166
* When the function is called, the CalendarLocal parameter is
167
* set to null to indicate that the resource is about to be reloaded. */
168
static void setCustomEventFunction(void (*f)(AlarmResource*, CalendarLocal*)) { mCustomEventFunction = f; }
169
/** Set a function to fix the calendar once it has been loaded. */
170
static void setFixFunction(KCalendar::Status (*f)(CalendarLocal&, const QString&, AlarmResource*, FixFunc, bool* wrongType))
171
{ mFixFunction = f; }
172
/** Return whether the resource is in a different format from the
173
* current KAlarm format, in which case it cannot be written to.
174
* Note that readOnly() takes account of both incompatible() and
175
* KCal::ResourceCached::readOnly().
177
KCalendar::Status compatibility() const { return mCompatibility; }
178
KCalendar::Status compatibility(const KCal::Event*) const;
180
virtual void showProgress(bool) {}
182
static int debugArea() { return mDebugArea; }
183
static void setDebugArea(int area) { mDebugArea = area; }
46
/** Whether the fix function should convert old format KAlarm calendars. */
47
enum FixFunc { PROMPT, PROMPT_PART, CONVERT, NO_CONVERT };
50
explicit AlarmResource(const KConfigGroup&);
51
explicit AlarmResource(KAlarm::CalEvent::Type);
53
virtual void writeConfig(KConfigGroup&);
54
virtual QString infoText() const;
55
KABC::Lock* lock() { return mLock; }
57
/** Return which type of alarms the resource can contain. */
58
KAlarm::CalEvent::Type alarmType() const { return mType; }
60
/** Set the type of alarms which the resource can contain. */
61
void setAlarmType(KAlarm::CalEvent::Type type) { mType = type; }
63
/** Return whether the resource contains only alarms of the wrong type. */
64
bool isWrongAlarmType() const { return mWrongAlarmType; }
66
/** Check whether the alarm types in a calendar correspond with
67
* the resource's alarm type.
68
* Reply = true if at least 1 alarm is the right type.
70
bool checkAlarmTypes(KCal::CalendarLocal&) const;
72
/** Set whether the application has a GUI. This determines whether error or
73
* progress messages are displayed. */
74
static void setNoGui(bool noGui) { mNoGui = noGui; }
75
static bool hasGui() { return !mNoGui; }
77
/** Return the location(s) of the resource (URL, file path, etc.) */
78
virtual QStringList location() const = 0;
80
/** Return the type of the resource (URL, file, etc.)
81
* for display purposes. */
82
virtual QString displayType() const = 0;
84
/** Return the location of the resource (URL, file path, etc.)
85
* for display purposes. */
86
virtual QString displayLocation() const = 0;
88
/** Change the resource's location. The resource will be reloaded if active. */
89
virtual bool setLocation(const QString& locn, const QString& locn2 = QString()) = 0;
90
/** Return whether the resource is the standard resource for its alarm type. */
91
bool standardResource() const { return mStandard; }
93
/** Set or clear the resource as the standard resource for its alarm type. */
94
void setStandardResource(bool std) { mStandard = std; }
96
void setEnabled(bool enable);
97
bool isEnabled() const { return !mWrongAlarmType && isActive(); }
99
/** Return whether the resource can be written to now,
100
* i.e. it's active, read-write and in the current KAlarm format. */
101
bool writable() const { return isEnabled() && !readOnly(); }
103
/** Return whether the event can be written to now, i.e. the resource is
104
* active and read-write, and the event is in the current KAlarm format. */
105
bool writable(const KCal::Event*) const;
107
/** Return whether the resource is cached, i.e. whether it is downloaded
108
* and stored locally in a cache file. */
109
virtual bool cached() const { return false; }
111
/** Return whether the resource is read-only, either because it's marked as
112
* read-only, or because it's active but not in the current KAlarm format. */
113
virtual bool readOnly() const;
114
virtual void setReadOnly(bool);
116
/** Return the colour used to display alarms belonging to this resource.
117
* @return display colour, or invalid if none specified */
118
QColor colour() const { return mColour; }
120
/** Set the colour used to display alarms belonging to this resource.
121
* @param color display colour, or invalid to use the default colour */
122
void setColour(const QColor& color);
123
/** Start a batch of configuration changes.
124
* The changes will be stored up until applyReconfig() is called. */
125
virtual void startReconfig();
127
/** Apply the batch of configuration changes since startReconfig() was called. */
128
virtual void applyReconfig();
130
/** Load the resource.
131
* If it's a cached resource, load() uses the default action to either refresh
132
* the cache file first or not.
133
* If loading succeeds, the loaded() signal is emitted on completion (but is
134
* not emitted if false is returned). This allows AlarmResources to process
136
* Loading is not performed if the resource is disabled.
137
* @return true if loading succeeded at least partially, false if it failed
140
bool load(CacheAction a) { return KCal::ResourceCached::load(a); }
142
/** Return whether the resource has fully loaded. */
143
bool isLoaded() const { return mLoaded; }
145
/** Return whether the resource is in the process of loading. */
146
bool isLoading() const { return mLoading; }
148
/** Save the resource and then close it.
149
* It will be closed even if saving fails. */
150
bool saveAndClose(CacheAction, KCal::Incidence* = 0);
151
bool saveAndClose(KCal::Incidence* incidence = 0) { return saveAndClose(DefaultCache, incidence); }
153
/** Set a function to write the application ID into a calendar. */
154
static void setCalIDFunction(void (*f)(CalendarLocal&)) { mCalIDFunction = f; }
155
/** Set a function to create KAlarm event instances.
156
* When the function is called, the CalendarLocal parameter is
157
* set to null to indicate that the resource is about to be reloaded. */
158
static void setCustomEventFunction(void (*f)(AlarmResource*, CalendarLocal*)) { mCustomEventFunction = f; }
159
/** Set a function to fix the calendar once it has been loaded. */
160
static void setFixFunction(KAlarm::Calendar::Compat (*f)(CalendarLocal&, const QString&, AlarmResource*, FixFunc, bool* wrongType))
161
{ mFixFunction = f; }
162
/** Return whether the resource is in a different format from the
163
* current KAlarm format, in which case it cannot be written to.
164
* Note that readOnly() takes account of both incompatible() and
165
* KCal::ResourceCached::readOnly().
167
KAlarm::Calendar::Compat compatibility() const { return mCompatibility; }
168
KAlarm::Calendar::Compat compatibility(const KCal::Event*) const;
170
virtual void showProgress(bool) {}
172
static int debugArea() { return mDebugArea; }
173
static void setDebugArea(int area) { mDebugArea = area; }
186
QByteArray typeName() const;
176
QByteArray typeName() const;
190
virtual void cancelDownload(bool /*disable*/ = false) {}
193
/** Signal that the resource is about to close or reload.
194
* This signal warns that all events are about to be deleted. */
195
void invalidate(AlarmResource*);
196
/** Signal that loading of the resource has completed, whether
197
* successfully or not.
198
* This signal is always emitted after a resource is loaded. */
199
void loaded(AlarmResource*);
200
/** Emitted after attempting to save the resource, whether successfully or not.
201
* Not emitted if no attempt was made to save it (e.g. if the resource
202
* is closed or read-only or there is nothing to save, or if save()
205
void resourceSaved(AlarmResource*);
206
/** Emitted during download for remote resources. */
207
void downloading(AlarmResource*, unsigned long percent);
208
/** Signal that a remote resource download has completed, and the cache file has been updated. */
209
void cacheDownloaded(AlarmResource*);
210
/** Signal that the resource's read-only status has changed. */
211
void readOnlyChanged(AlarmResource*);
212
/** Signal that the resource's wrong alarm type status has changed. */
213
void wrongAlarmTypeChanged(AlarmResource*);
214
/** Signal that the resource's active status has changed. */
215
void enabledChanged(AlarmResource*);
216
/** Signal that the resource's location has changed. */
217
void locationChanged(AlarmResource*);
218
/** Signal that the resource cannot be set read-write since its format is incompatible. */
219
void notWritable(AlarmResource*);
220
/** Signal that the display colour has changed. */
221
void colourChanged(AlarmResource*);
224
virtual void doClose();
225
bool closeAfterSave() const { return mCloseAfterSave; }
226
void setCompatibility(KCalendar::Status c) { mCompatibility = c; }
227
void checkCompatibility(const QString&);
228
KCalendar::Status checkCompatibility(KCal::CalendarLocal&, const QString& filename, FixFunc, bool* wrongType = 0);
229
void setWrongAlarmType(bool wrongType, bool emitSignal = true);
230
void updateCustomEvents(bool useCalendar = true);
231
virtual void enableResource(bool enable) = 0;
232
void lock(const QString& path);
234
static void (*mCalIDFunction)(CalendarLocal&);
235
static KCalendar::Status (*mFixFunction)(CalendarLocal&, const QString&, AlarmResource*, FixFunc, bool* wrongType);
240
static int mDebugArea; // area for kDebug() output
241
static bool mNoGui; // application has no GUI, so don't display messages
242
static void (*mCustomEventFunction)(AlarmResource*, CalendarLocal*);
245
Type mType; // type of alarm held in this resource
246
QColor mColour; // background colour for displaying this resource
247
bool mStandard; // this is the standard resource for this mWriteType
248
bool mNewReadOnly; // new read-only status (while mReconfiguring = 1)
249
bool mOldReadOnly; // old read-only status (when startReconfig() called)
250
bool mCloseAfterSave; // resource is to be closed once save() is complete
251
bool mWrongAlarmType; // calendar contains only alarms of the wrong type
252
KCalendar::Status mCompatibility; // whether resource is in compatible format
254
typedef QMap<const KCal::Event*, KCalendar::Status> CompatibilityMap;
255
CompatibilityMap mCompatibilityMap; // whether individual events are in compatible format
256
short mReconfiguring; // a batch of config changes is in progress
257
bool mLoaded; // true if resource has finished loading
258
bool mLoading; // true if resource is currently loading
261
using KCal::ResourceCached::load; // prevent "hidden" warning
180
virtual void cancelDownload(bool /*disable*/ = false) {}
183
/** Signal that the resource is about to close or reload.
184
* This signal warns that all events are about to be deleted. */
185
void invalidate(AlarmResource*);
186
/** Signal that loading of the resource has completed, whether
187
* successfully or not.
188
* This signal is always emitted after a resource is loaded. */
189
void loaded(AlarmResource*);
190
/** Emitted after attempting to save the resource, whether successfully or not.
191
* Not emitted if no attempt was made to save it (e.g. if the resource
192
* is closed or read-only or there is nothing to save, or if save()
195
void resourceSaved(AlarmResource*);
196
/** Emitted during download for remote resources. */
197
void downloading(AlarmResource*, unsigned long percent);
198
/** Signal that a remote resource download has completed, and the cache file has been updated. */
199
void cacheDownloaded(AlarmResource*);
200
/** Signal that the resource's read-only status has changed. */
201
void readOnlyChanged(AlarmResource*);
202
/** Signal that the resource's wrong alarm type status has changed. */
203
void wrongAlarmTypeChanged(AlarmResource*);
204
/** Signal that the resource's active status has changed. */
205
void enabledChanged(AlarmResource*);
206
/** Signal that the resource's location has changed. */
207
void locationChanged(AlarmResource*);
208
/** Signal that the resource cannot be set read-write since its format is incompatible. */
209
void notWritable(AlarmResource*);
210
/** Signal that the display colour has changed. */
211
void colourChanged(AlarmResource*);
214
virtual void doClose();
215
bool closeAfterSave() const { return mCloseAfterSave; }
216
void setCompatibility(KAlarm::Calendar::Compat c) { mCompatibility = c; }
217
void checkCompatibility(const QString&);
218
KAlarm::Calendar::Compat checkCompatibility(KCal::CalendarLocal&, const QString& filename, FixFunc, bool* wrongType = 0);
219
void setWrongAlarmType(bool wrongType, bool emitSignal = true);
220
void updateCustomEvents(bool useCalendar = true);
221
virtual void enableResource(bool enable) = 0;
222
void lock(const QString& path);
224
static void (*mCalIDFunction)(CalendarLocal&);
225
static KAlarm::Calendar::Compat (*mFixFunction)(CalendarLocal&, const QString&, AlarmResource*, FixFunc, bool* wrongType);
230
static int mDebugArea; // area for kDebug() output
231
static bool mNoGui; // application has no GUI, so don't display messages
232
static void (*mCustomEventFunction)(AlarmResource*, CalendarLocal*);
235
KAlarm::CalEvent::Type mType; // type of alarm held in this resource
236
QColor mColour; // background colour for displaying this resource
237
bool mStandard; // this is the standard resource for this mWriteType
238
bool mNewReadOnly; // new read-only status (while mReconfiguring = 1)
239
bool mOldReadOnly; // old read-only status (when startReconfig() called)
240
bool mCloseAfterSave; // resource is to be closed once save() is complete
241
bool mWrongAlarmType; // calendar contains only alarms of the wrong type
242
KAlarm::Calendar::Compat mCompatibility; // whether resource is in compatible format
245
typedef QMap<const KCal::Event*, KAlarm::Calendar::Compat> CompatibilityMap;
246
CompatibilityMap mCompatibilityMap; // whether individual events are in compatible format
247
short mReconfiguring; // a batch of config changes is in progress
248
bool mLoaded; // true if resource has finished loading
249
bool mLoading; // true if resource is currently loading
252
using KCal::ResourceCached::load; // prevent "hidden" warning
264
255
typedef KRES::Manager<AlarmResource> AlarmResourceManager;