1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
|
/*
This file is part of libkcal.
Copyright (c) 1998 Preston Brown <pbrown@kde.org>
Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KCAL_RESOURCECALENDAR_H
#define KCAL_RESOURCECALENDAR_H
#include <tqstring.h>
#include <tqdatetime.h>
#include <tqptrlist.h>
#include <tdeconfig.h>
#include "alarm.h"
#include "todo.h"
#include "event.h"
#include "journal.h"
#include "calendar.h"
#include "exceptions.h"
#include <tderesources/resource.h>
#include <tderesources/manager.h>
#include <kabc/lock.h>
#include <tdepimmacros.h>
namespace KCal {
class CalFormat;
/**
This class provides the interfaces for a calendar resource. It makes use of
the tderesources framework.
\warning This code is still under heavy development. Don't expect source or
binary compatibility in future versions.
*/
class LIBKCAL_EXPORT ResourceCalendar : public KRES::Resource
{
Q_OBJECT
public:
ResourceCalendar( const TDEConfig * );
virtual ~ResourceCalendar();
/**
Clears the exception status.
*/
void clearException();
/**
Set exception for this object. This is used by the functions of this
class to report errors.
*/
void setException( ErrorFormat *error );
/**
Returns an exception, if there is any, containing information about the
last error that occurred.
*/
ErrorFormat *exception();
void setResolveConflict( bool b);
virtual void writeConfig( TDEConfig* config );
/**
Return rich text with info about the resource. Adds standard info and
then calls addInfoText() to add info about concrete resources.
*/
virtual TQString infoText() const;
/**
Load resource data. After calling this function all data is accessible by
calling the incidence/event/todo/etc. accessor functions.
Whether data is actually loaded within this function or the loading is delayed
until it is accessed by another function depends on the implementation of
the resource.
If loading the data takes significant time, the resource should return
cached values if available, and return the results via the resourceChanged
signal. When the resource has finished loading, the resourceLoaded() signal
is emitted.
Calling this function multiple times should have the same effect as
calling it once, given that the data isn't changed between calls.
This function calls doLoad() which has to be reimplented by the resource
to do the actual loading.
*/
bool load();
/**
Save resource data. After calling this function it is safe to close the
resource without losing data.
Whether data is actually saved within this function or saving is delayed
depends on the implementation of the resource.
If saving the data takes significant time, the resource should return from
the function, do the saving in the background and notify the end of the
save by emitting the signal resourceSaved().
This function calls doSave() which has to be reimplented by the resource
to do the actual saving.
@param incidence if given as 0, doSave() is called to save all incidences,
else doSave(incidence) is called to save only the given one
*/
bool save( Incidence *incidence = 0 );
/**
Return true if a save operation is still in progress, otherwise return
false.
*/
virtual bool isSaving() { return false; }
/**
Return object for locking the resource.
*/
virtual KABC::Lock *lock() = 0;
/**
Add incidence to resource.
@deprecated use addIncidence(Incidence *,const TQString &) instead.
*/
virtual KDE_DEPRECATED bool addIncidence( Incidence * );
/**
Add incidence to resource and subresource.
*/
virtual bool addIncidence( Incidence *, const TQString &subresource );
/**
Delete incidence from resource.
*/
virtual bool deleteIncidence( Incidence * );
/**
Return incidence with given unique id. If there is no incidence with that
uid, return 0.
*/
Incidence *incidence( const TQString &uid );
/**
Add event to resource.
@deprecated use addEvent(Event *,const TQString&) instead.
*/
virtual KDE_DEPRECATED bool addEvent( Event *event ) = 0;
virtual bool addEvent( Event *event, const TQString &subresource ) = 0;
/**
Delete event from this resource.
*/
virtual bool deleteEvent( Event * ) = 0;
/**
Retrieves an event on the basis of the unique string ID.
*/
virtual Event *event( const TQString &uid ) = 0;
/**
Return unfiltered list of all events in calendar. Use with care,
this can be a bad idea for server-based calendars.
*/
virtual Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending ) = 0;
/**
Builds and then returns a list of all events that match the
date specified. Useful for dayView, etc. etc.
*/
virtual Event::List rawEventsForDate( const TQDate &date, EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending ) = 0;
/**
Get unfiltered events for date \a qdt.
*/
virtual Event::List rawEventsForDate( const TQDateTime &qdt ) = 0;
/**
Get unfiltered events in a range of dates. If inclusive is set to true,
only events which are completely included in the range are returned.
*/
virtual Event::List rawEvents( const TQDate &start, const TQDate &end,
bool inclusive = false ) = 0;
/**
Sets a particular value of the resource's configuration. The possible
keys are resource specific.
This method is provided to make it possible
to set resource-type specific settings without actually linking to
the resource's library. Its use is discouraged, but in
some situations the only possibility to avoid unwanted compiling and
linking dependencies. E.g. if you don't want to link to the remote
resource, but need to create a remote resource at the URL given in
yourURL, you can use code like the following:
KCal::ResourceCalendar *res = manager->createResource( "remote" );
if ( res ) {
res->setTimeZoneId( timezone );
res->setResourceName( i18n("Test resource") );
res->setValue( "DownloadURL", yourURL );
manager->add( res );
}
*/
virtual bool setValue( const TQString &key, const TQString &value );
signals:
/**
This signal is emitted when the data in the resource has changed. The
resource has to make sure that this signal is emitted whenever any
pointers to incidences which the resource has previously given to the
calling code, become invalid.
*/
void resourceChanged( ResourceCalendar * );
/**
This signal is emitted when loading data into the resource has been
finished.
*/
void resourceLoaded( ResourceCalendar * );
/**
This signal is emitted when saving the data of the resource has been
finished.
*/
void resourceSaved( ResourceCalendar * );
/**
This signal is emitted when an error occurs during loading.
*/
void resourceLoadError( ResourceCalendar *, const TQString &error );
/**
This signal is emitted when an error occurs during saving.
*/
void resourceSaveError( ResourceCalendar *, const TQString &error );
/**
This signal is emitted when a subresource is added.
*/
void signalSubresourceAdded( ResourceCalendar *, const TQString& type,
const TQString& subresource, const TQString& label );
/**
This signal is emitted when a subresource is removed.
*/
void signalSubresourceRemoved( ResourceCalendar *, const TQString &,
const TQString & );
public:
/**
Add a todo to the todolist.
@deprecated use addTodo(Todo *,const TQString &) instead.
*/
virtual KDE_DEPRECATED bool addTodo( Todo *todo ) = 0;
virtual bool addTodo( Todo *todo, const TQString &subresource ) = 0;
/**
Remove a todo from the todolist.
*/
virtual bool deleteTodo( Todo * ) = 0;
/**
Searches todolist for an event with this unique id.
@return pointer to todo or 0 if todo wasn't found
*/
virtual Todo *todo( const TQString &uid ) = 0;
/**
Return list of all todos.
*/
virtual Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending ) = 0;
/**
Returns list of todos due on the specified date.
*/
virtual Todo::List rawTodosForDate( const TQDate &date ) = 0;
/**
Add a Journal entry to the resource.
@deprecated use addJournal(Journal *,const TQString &) instead.
*/
virtual KDE_DEPRECATED bool addJournal( Journal * ) = 0;
virtual bool addJournal( Journal *journal, const TQString &subresource ) = 0;
/**
Remove a Journal entry from calendar.
*/
virtual bool deleteJournal( Journal * ) = 0;
/**
Return Journal with given unique id.
*/
virtual Journal *journal( const TQString &uid ) = 0;
/**
Return list of all journals.
*/
virtual Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted, SortDirection sortDirection = SortDirectionAscending ) = 0;
/**
Returns list of journals for the given date.
*/
virtual Journal::List rawJournalsForDate( const TQDate &date ) = 0;
/**
Return all alarms which occur in the given time interval.
*/
virtual Alarm::List alarms( const TQDateTime &from,
const TQDateTime &to ) = 0;
/**
Return all alarms which occur before given date.
*/
virtual Alarm::List alarmsTo( const TQDateTime &to ) = 0;
/** Returns a list of all incideces */
Incidence::List rawIncidences();
/**
Set time zone id used by this resource, e.g. "Europe/Berlin".
*/
virtual void setTimeZoneId( const TQString &timeZoneId ) = 0;
/**
If this resource has subresources, return a TQStringList of them.
In most cases, resources do not have subresources, so this is
by default just empty.
*/
virtual TQStringList subresources() const { return TQStringList(); }
/**
Is this subresource capable of having subresources or not?
*/
virtual bool canHaveSubresources() const { return false; }
/**
Is this subresource active or not?
*/
virtual bool subresourceActive( const TQString& ) const { return true; }
/**
Is this subresource writable or not?
*/
virtual bool subresourceWritable( const TQString& ) const;
/**
What is the label for this subresource?
*/
virtual const TQString labelForSubresource( const TQString& resource ) const
{
// the resource identifier is a sane fallback
return resource;
};
/**
Get the identifier of the subresource associated with a specified
incidence.
@return the identifier of the subresource or an empty string.
*/
virtual TQString subresourceIdentifier( Incidence *incidence )
{ Q_UNUSED( incidence ); return TQString(); }
/**
* Remove a subresource with the id @param resource
*/
virtual bool removeSubresource( const TQString& resource );
/**
* Add a subresource with the name @param resource and the parent
* id @param parent.
*/
virtual bool addSubresource( const TQString& resource, const TQString& parent );
/**
* Returns the type of the subresource: "event", "todo" or "journal",
* TQString() if unknown/mixed.
*/
virtual TQString subresourceType( const TQString &resource );
/**
* Called when we starting adding a batch of incidences.
* So we don't show the same warnings for each incidence.
*/
virtual void beginAddingIncidences();
/**
* Called when we finish adding a batch of incidences.
* @see beginAddingIncidences()
*/
virtual void endAddingIncidences();
public slots:
/**
(De-)activate a subresource.
*/
virtual void setSubresourceActive( const TQString &, bool active );
protected:
bool mResolveConflict;
/**
Do the actual loading of the resource data. Called by load().
*/
virtual bool doLoad() = 0;
/**
Do the actual saving of the resource data. Called by save().
*/
virtual bool doSave() = 0;
/**
Do the actual saving of the resource data. Called by save().
Save one Incidence. The default implementation calls doSave() to save everything
*/
virtual bool doSave( Incidence * );
/**
Add info text for concrete resources. Called by infoText().
*/
virtual void addInfoText( TQString & ) const {};
/**
A resource should call this function if a load error happens.
*/
void loadError( const TQString &errorMessage = TQString() );
/**
A resource should call this function if a save error happens.
*/
void saveError( const TQString &errorMessage = TQString() );
private:
bool mReceivedLoadError;
bool mReceivedSaveError;
ErrorFormat *mException;
class Private;
Private *d;
};
typedef KRES::Manager<ResourceCalendar> CalendarResourceManager;
}
#endif
|