libkcal

resourcecached.h
1/*
2 This file is part of libkcal.
3
4 Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library 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 GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20*/
21#ifndef KCAL_RESOURCECACHED_H
22#define KCAL_RESOURCECACHED_H
23
24#include "resourcecalendar.h"
25
26#include "libemailfunctions/idmapper.h"
27#include "incidence.h"
28#include "calendarlocal.h"
29
30#include <tdeconfig.h>
31
32#include <tqptrlist.h>
33#include <tqstring.h>
34#include <tqdatetime.h>
35#include <tqtimer.h>
36
37#include <tdemacros.h>
38
39namespace KCal {
40
45class TDE_EXPORT ResourceCached : public ResourceCalendar,
47{
48 TQ_OBJECT
49
50 public:
56 enum { ReloadNever, ReloadOnStartup, ReloadInterval };
62 enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways };
63
64 ResourceCached( const TDEConfig * );
65 virtual ~ResourceCached();
66
67 void readConfig( const TDEConfig *config );
68 void writeConfig( TDEConfig *config );
69
70 static bool editorWindowOpen();
71 static void setEditorWindowOpen(bool open);
72
80 void setReloadPolicy( int policy );
86 int reloadPolicy() const;
87
92 void setReloadInterval( int minutes );
93
97 int reloadInterval() const;
98
108 void setSavePolicy( int policy );
114 int savePolicy() const;
115
120 void setSaveInterval( int minutes );
121
125 int saveInterval() const;
126
130 TQDateTime lastLoad() const;
131
135 TQDateTime lastSave() const;
136
140 TDE_DEPRECATED bool addEvent( Event *event );
141 bool addEvent( Event *event, const TQString &subresource );
142
146 bool deleteEvent(Event *);
147
151 Event *event(const TQString &UniqueStr);
155 Event::List events();
159 Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
164 Event::List rawEventsForDate( const TQDate &date, EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
165
169 Event::List rawEventsForDate( const TQDateTime &qdt );
174 Event::List rawEvents( const TQDate &start, const TQDate &end,
175 bool inclusive = false );
176
180 TDE_DEPRECATED bool addTodo( Todo *todo );
181 bool addTodo( Todo *todo, const TQString &subresource );
182
186 bool deleteTodo( Todo * );
191 Todo *todo( const TQString &uid );
195 Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
199 Todo::List rawTodosForDate( const TQDate &date );
203 TDE_DEPRECATED bool addJournal( Journal *journal );
204 bool addJournal( Journal *journal, const TQString &subresource );
205
209 bool deleteJournal( Journal * );
213 Journal *journal( const TQString &uid );
217 Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted,SortDirection sortDirection = SortDirectionAscending );
221 Journal::List rawJournalsForDate( const TQDate &date );
222
226 Alarm::List alarms( const TQDateTime &from, const TQDateTime &to );
227
231 Alarm::List alarmsTo( const TQDateTime &to );
232
236 void setTimeZoneId( const TQString &timeZoneId );
237
238 TQString timeZoneId() const;
239
243 const Person &getOwner() const;
247 void setOwner( const Person &owner );
248
249 void enableChangeNotification();
250 void disableChangeNotification();
251
252 void clearChange( Incidence * );
253 void clearChange( const TQString &uid );
254
255 void clearChanges();
256
257 bool hasChanges() const;
258
259 Incidence::List allChanges() const;
260
261 Incidence::List addedIncidences() const;
262 Incidence::List changedIncidences() const;
263 Incidence::List deletedIncidences() const;
264
268 void loadCache();
269
273 void saveCache();
274
278 void clearCache();
279
283 void clearEventsCache();
284
288 void clearTodosCache();
289
293 void clearJournalsCache();
294
295 void cleanUpEventCache( const KCal::Event::List &eventList );
296 void cleanUpTodoCache( const KCal::Todo::List &todoList );
297
301 KPIM::IdMapper& idMapper();
302
303 protected:
304 // From Calendar::Observer
308
309 CalendarLocal mCalendar;
310
315 virtual void doClose();
320 virtual bool doOpen();
324 bool checkForReload();
328 bool checkForSave();
329
330 void checkForAutomaticSave();
331
332 void addInfoText( TQString & ) const;
333
334 void setupSaveTimer();
335 void setupReloadTimer();
336
341 virtual TQString cacheFile() const;
342
346 virtual TQString changesCacheFile( const TQString& ) const;
347 void loadChangesCache( TQMap<Incidence*, bool>&, const TQString& );
348 void loadChangesCache();
349 void saveChangesCache( const TQMap<Incidence*, bool>&, const TQString& );
350 void saveChangesCache();
351
352 protected slots:
353 void slotReload();
354 void slotSave();
355
356 void setIdMapperIdentifier();
357
358 private:
359 int mReloadPolicy;
360 int mReloadInterval;
361 TQTimer mReloadTimer;
362 bool mReloaded;
363
364 int mSavePolicy;
365 int mSaveInterval;
366 TQTimer mSaveTimer;
367
368 TQDateTime mLastLoad;
369 TQDateTime mLastSave;
370
371 TQMap<KCal::Incidence *,bool> mAddedIncidences;
372 TQMap<KCal::Incidence *,bool> mChangedIncidences;
373 TQMap<KCal::Incidence *,bool> mDeletedIncidences;
374
375 KPIM::IdMapper mIdMapper;
376
377 class Private;
378 Private *d;
379};
380
381}
382
383#endif
This class provides a calendar stored as a local file.
The Observer class.
Definition calendar.h:869
This class provides an Event in the sense of RFC2445.
Definition event.h:33
This class provides the base class common to all calendar components.
Definition incidence.h:48
This class provides a Journal in the sense of RFC2445.
Definition journal.h:34
This class represents a person.
Definition person.h:35
void setSavePolicy(int policy)
Set save policy.
void clearTodosCache()
Clear todos cache.
void loadCache()
Loads the cache, this method should be called on load.
Alarm::List alarms(const TQDateTime &from, const TQDateTime &to)
Return all alarms, which ocur in the given time interval.
virtual bool doOpen()
Opens the resource.
virtual TQString cacheFile() const
This method is used by loadCache() and saveCache(), reimplement it to change the location of the cach...
bool deleteJournal(Journal *)
Remove a Journal from the calendar.
int reloadInterval() const
Return reload interval in minutes.
int reloadPolicy() const
Return reload policy.
void setSaveInterval(int minutes)
Set save interval in minutes which is used when save policy is SaveInterval.
void clearJournalsCache()
Clear journals cache.
Event::List rawEventsForDate(const TQDate &date, EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Builds and then returns a list of all events that match for the date specified.
int savePolicy() const
Return save policy.
KPIM::IdMapper & idMapper()
Returns a reference to the id mapper.
virtual TQString changesCacheFile(const TQString &) const
Functions for keeping the changes persistent.
void calendarIncidenceChanged(KCal::Incidence *incidence)
Notify the Observer that an Incidence has been modified.
Todo::List rawTodosForDate(const TQDate &date)
Returns list of todos due on the specified date.
void addInfoText(TQString &) const
Add info text for concrete resources.
void setOwner(const Person &owner)
Set the owner of the calendar.
void calendarIncidenceAdded(KCal::Incidence *incidence)
Notify the Observer that an Incidence has been inserted.
const Person & getOwner() const
Return the owner of the calendar's full name.
TQDateTime lastLoad() const
Return time of last load.
void saveCache()
Saves the cache back.
void setTimeZoneId(const TQString &timeZoneId)
Set id of timezone, e.g.
Event::List rawEvents(EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return unfiltered list of all events in calendar.
Journal * journal(const TQString &uid)
Return Journal with given unique id.
Journal::List rawJournals(JournalSortField sortField=JournalSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return list of all journals.
Event::List events()
Return filtered list of all events in calendar.
void setReloadInterval(int minutes)
Set reload interval in minutes which is used when reload policy is ReloadInterval.
virtual void doClose()
Virtual method from KRES::Resource, called when the last instace of the resource is closed.
bool deleteEvent(Event *)
Deletes an event from this calendar.
Journal::List rawJournalsForDate(const TQDate &date)
Return list of journals for the given date.
bool deleteTodo(Todo *)
Remove a todo from the todolist.
TQDateTime lastSave() const
Return time of last save.
void calendarIncidenceDeleted(KCal::Incidence *incidence)
Notify the Observer that an Incidence has been removed.
Todo * todo(const TQString &uid)
Searches todolist for an event with this unique string identifier, returns a pointer or null.
void setReloadPolicy(int policy)
Set reload policy.
TDE_DEPRECATED bool addJournal(Journal *journal)
Add a Journal entry to calendar.
Alarm::List alarmsTo(const TQDateTime &to)
Return all alarms, which ocur before given date.
TDE_DEPRECATED bool addEvent(Event *event)
Add event to calendar.
void clearEventsCache()
Clear events cache.
bool checkForSave()
Check if save required according to save policy.
bool checkForReload()
Check if reload required according to reload policy.
int saveInterval() const
Return save interval in minutes.
TDE_DEPRECATED bool addTodo(Todo *todo)
Add a todo to the todolist.
Todo::List rawTodos(TodoSortField sortField=TodoSortUnsorted, SortDirection sortDirection=SortDirectionAscending)
Return list of all todos.
Event * event(const TQString &UniqueStr)
Retrieves an event on the basis of the unique string ID.
void clearCache()
Clear cache.
Incidence * incidence(const TQString &uid)
Return incidence with given unique id.
This class provides a Todo in the sense of RFC2445.
Definition todo.h:32
Namespace KCal is for global classes, objects and/or functions in libkcal.
Definition alarm.h:38
TodoSortField
How Todos are to be sorted.
Definition calendar.h:91
@ TodoSortUnsorted
Todos are to be unsorted.
Definition calendar.h:93
JournalSortField
How Journals are to be sorted.
Definition calendar.h:111
@ JournalSortUnsorted
Journals are to be unsorted.
Definition calendar.h:113
EventSortField
How Events are to be sorted.
Definition calendar.h:75
@ EventSortUnsorted
Events are to be unsorted.
Definition calendar.h:77
SortDirection
Sort direction.
Definition calendar.h:63
@ SortDirectionAscending
Sort in ascending order (first to last).
Definition calendar.h:65