KCal Library
resourcecached.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KCAL_RESOURCECACHED_H
00023 #define KCAL_RESOURCECACHED_H
00024
00025 #include "resourcecalendar.h"
00026 #include "incidence.h"
00027
00028 #include <kdatetime.h>
00029
00030 #include <QtCore/QString>
00031
00032 class KConfigGroup;
00033 namespace KRES { class IdMapper; }
00034
00035 namespace KCal {
00036
00037 class CalendarLocal;
00038
00043 class KCAL_EXPORT ResourceCached : public ResourceCalendar,
00044 public KCal::Calendar::CalendarObserver
00045 {
00046 Q_OBJECT
00047 public:
00052 enum {
00053 ReloadNever,
00054 ReloadOnStartup,
00055 ReloadInterval
00056 };
00057
00062 enum {
00063 SaveNever,
00064 SaveOnExit,
00065 SaveInterval,
00066 SaveDelayed,
00067 SaveAlways
00068 };
00069
00075 enum CacheAction {
00076 DefaultCache,
00077 NoSyncCache,
00078 SyncCache
00079 };
00080
00081 ResourceCached();
00082 explicit ResourceCached( const KConfigGroup &group );
00083 virtual ~ResourceCached();
00084
00085 void readConfig( const KConfigGroup &group );
00086 void writeConfig( KConfigGroup &group );
00087
00095 void setReloadPolicy( int policy );
00101 int reloadPolicy() const;
00102
00107 void setReloadInterval( int minutes );
00108
00112 int reloadInterval() const;
00113
00122 bool inhibitDefaultReload( bool inhibit );
00123 bool defaultReloadInhibited() const;
00124
00128 bool reloaded() const;
00129
00139 void setSavePolicy( int policy );
00145 int savePolicy() const;
00146
00151 void setSaveInterval( int minutes );
00152
00156 int saveInterval() const;
00157
00161 KDateTime lastLoad() const;
00162
00166 KDateTime lastSave() const;
00167
00172 bool load( CacheAction );
00173
00177 virtual bool load();
00178
00188 bool save( CacheAction, Incidence *incidence = 0 );
00189
00193 virtual bool save( Incidence *incidence = 0 );
00194
00198 bool addEvent( Event *event );
00199
00203 bool deleteEvent( Event *event );
00204
00208 void deleteAllEvents();
00209
00213 Event *event( const QString &UniqueStr );
00214
00218 Event::List events();
00219
00223 Event::List rawEvents( EventSortField sortField = EventSortUnsorted,
00224 SortDirection sortDirection = SortDirectionAscending );
00225
00235 Event::List rawEventsForDate( const QDate &date,
00236 const KDateTime::Spec ×pec = KDateTime::Spec(),
00237 EventSortField sortField = EventSortUnsorted,
00238 SortDirection sortDirection = SortDirectionAscending );
00239
00243 Event::List rawEventsForDate( const KDateTime &dt );
00244
00255 Event::List rawEvents( const QDate &start, const QDate &end,
00256 const KDateTime::Spec ×pec = KDateTime::Spec(),
00257 bool inclusive = false );
00258
00262 bool addTodo( Todo *todo );
00266 bool deleteTodo( Todo * );
00267
00271 void deleteAllTodos();
00272
00277 Todo *todo( const QString &uid );
00278
00282 Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
00283 SortDirection sortDirection = SortDirectionAscending );
00284
00288 Todo::List rawTodosForDate( const QDate &date );
00289
00293 virtual bool addJournal( Journal * );
00294
00298 virtual bool deleteJournal( Journal * );
00299
00303 virtual void deleteAllJournals();
00304
00308 virtual Journal *journal( const QString &uid );
00309
00313 Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted,
00314 SortDirection sortDirection = SortDirectionAscending );
00315
00319 Journal::List rawJournalsForDate( const QDate &date );
00320
00324 Alarm::List alarms( const KDateTime &from, const KDateTime &to );
00325
00329 Alarm::List alarmsTo( const KDateTime &to );
00330
00337 void setTimeSpec( const KDateTime::Spec &timeSpec );
00338
00344 KDateTime::Spec timeSpec() const;
00345
00352 void setTimeZoneId( const QString &timeZoneId );
00353
00360 QString timeZoneId() const;
00361
00366 virtual void shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec );
00367
00371 Person owner() const;
00372
00377 void setOwner( const Person &owner );
00378
00379 void enableChangeNotification();
00380 void disableChangeNotification();
00381
00382 void clearChange( Incidence *incidence );
00383 void clearChange( const QString &uid );
00384
00385 void clearChanges();
00386
00387 bool hasChanges() const;
00388
00389 Incidence::List allChanges() const;
00390
00391 Incidence::List addedIncidences() const;
00392 Incidence::List changedIncidences() const;
00393 Incidence::List deletedIncidences() const;
00394
00399 bool loadFromCache();
00400
00404 void saveToCache();
00405
00409 void clearCache();
00410
00411 void cleanUpEventCache( const KCal::Event::List &eventList );
00412 void cleanUpTodoCache( const KCal::Todo::List &todoList );
00413
00417 KRES::IdMapper &idMapper();
00418
00419 using QObject::event;
00420
00421 protected:
00422 CalendarLocal *calendar() const;
00423
00424
00425 void calendarIncidenceAdded( KCal::Incidence *incidence );
00426 void calendarIncidenceChanged( KCal::Incidence *incidence );
00427 void calendarIncidenceDeleted( KCal::Incidence *incidence );
00428
00433 virtual void doClose();
00434
00440 virtual bool doOpen();
00441
00445 virtual bool doLoad( bool syncCache ) = 0;
00446
00453 void setReloaded( bool done );
00454
00463 virtual bool doSave( bool syncCache ) = 0;
00464
00473 virtual bool doSave( bool syncCache, Incidence * );
00474
00478 bool checkForReload();
00479
00483 bool checkForSave();
00484
00485 void checkForAutomaticSave();
00486
00487 void addInfoText( QString & ) const;
00488
00489 void setupSaveTimer();
00490 void setupReloadTimer();
00491
00496 virtual QString cacheFile() const;
00497
00501 virtual QString changesCacheFile( const QString &type ) const;
00502 void loadChangesCache( QMap<Incidence *, bool> &map, const QString &type );
00503 void loadChangesCache();
00504 void saveChangesCache( const QMap<Incidence *, bool> &map, const QString &type );
00505 void saveChangesCache();
00506
00507 protected Q_SLOTS:
00508 void slotReload();
00509 void slotSave();
00510
00511 void setIdMapperIdentifier();
00512
00513 private:
00514
00515 Q_DISABLE_COPY( ResourceCached )
00516 class Private;
00517 Private *const d;
00518
00519 };
00520
00521 }
00522
00523 #endif