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
00174 bool load( CacheAction action );
00175
00179 virtual bool load();
00180
00191 bool save( CacheAction action, Incidence *incidence = 0 );
00192
00196 virtual bool save( Incidence *incidence = 0 );
00197
00201 bool addEvent( Event *event );
00202
00206 bool deleteEvent( Event *event );
00207
00211 void deleteAllEvents();
00212
00216 Event *event( const QString &UniqueStr );
00217
00221 Event::List events();
00222
00226 Event::List rawEvents( EventSortField sortField = EventSortUnsorted,
00227 SortDirection sortDirection = SortDirectionAscending );
00228
00238 Event::List rawEventsForDate( const QDate &date,
00239 const KDateTime::Spec &timeSpec = KDateTime::Spec(),
00240 EventSortField sortField = EventSortUnsorted,
00241 SortDirection sortDirection = SortDirectionAscending );
00242
00246 Event::List rawEventsForDate( const KDateTime &dt );
00247
00258 Event::List rawEvents( const QDate &start, const QDate &end,
00259 const KDateTime::Spec &timeSpec = KDateTime::Spec(),
00260 bool inclusive = false );
00261
00265 bool addTodo( Todo *todo );
00269 bool deleteTodo( Todo * );
00270
00274 void deleteAllTodos();
00275
00280 Todo *todo( const QString &uid );
00281
00285 Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted,
00286 SortDirection sortDirection = SortDirectionAscending );
00287
00291 Todo::List rawTodosForDate( const QDate &date );
00292
00296 virtual bool addJournal( Journal * );
00297
00301 virtual bool deleteJournal( Journal * );
00302
00306 virtual void deleteAllJournals();
00307
00311 virtual Journal *journal( const QString &uid );
00312
00316 Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted,
00317 SortDirection sortDirection = SortDirectionAscending );
00318
00322 Journal::List rawJournalsForDate( const QDate &date );
00323
00327 Alarm::List alarms( const KDateTime &from, const KDateTime &to );
00328
00332 Alarm::List alarmsTo( const KDateTime &to );
00333
00340 void setTimeSpec( const KDateTime::Spec &timeSpec );
00341
00347 KDateTime::Spec timeSpec() const;
00348
00355 void setTimeZoneId( const QString &timeZoneId );
00356
00363 QString timeZoneId() const;
00364
00369 virtual void shiftTimes( const KDateTime::Spec &oldSpec, const KDateTime::Spec &newSpec );
00370
00374 Person owner() const;
00375
00380 void setOwner( const Person &owner );
00381
00382 void enableChangeNotification();
00383 void disableChangeNotification();
00384
00385 void clearChange( Incidence *incidence );
00386 void clearChange( const QString &uid );
00387
00388 void clearChanges();
00389
00390 bool hasChanges() const;
00391
00392 Incidence::List allChanges() const;
00393
00394 Incidence::List addedIncidences() const;
00395 Incidence::List changedIncidences() const;
00396 Incidence::List deletedIncidences() const;
00397
00402 bool loadFromCache();
00403
00407 void saveToCache();
00408
00412 void clearCache();
00413
00414 void cleanUpEventCache( const KCal::Event::List &eventList );
00415 void cleanUpTodoCache( const KCal::Todo::List &todoList );
00416
00420 KRES::IdMapper &idMapper();
00421
00422 using QObject::event;
00423
00424 protected:
00425 CalendarLocal *calendar() const;
00426
00427
00428 void calendarIncidenceAdded( KCal::Incidence *incidence );
00429 void calendarIncidenceChanged( KCal::Incidence *incidence );
00430 void calendarIncidenceDeleted( KCal::Incidence *incidence );
00431
00436 virtual void doClose();
00437
00443 virtual bool doOpen();
00444
00448 virtual bool doLoad( bool syncCache ) = 0;
00449
00456 void setReloaded( bool done );
00457
00466 virtual bool doSave( bool syncCache ) = 0;
00467
00477 virtual bool doSave( bool syncCache, Incidence *incidence );
00478
00482 bool checkForReload();
00483
00487 bool checkForSave();
00488
00489 void checkForAutomaticSave();
00490
00491 void addInfoText( QString & ) const;
00492
00493 void setupSaveTimer();
00494 void setupReloadTimer();
00495
00500 virtual QString cacheFile() const;
00501
00505 virtual QString changesCacheFile( const QString &type ) const;
00506 void loadChangesCache( QMap<Incidence *, bool> &map, const QString &type );
00507 void loadChangesCache();
00508 void saveChangesCache( const QMap<Incidence *, bool> &map, const QString &type );
00509 void saveChangesCache();
00510
00511 protected Q_SLOTS:
00512 void slotReload();
00513 void slotSave();
00514
00515 void setIdMapperIdentifier();
00516
00517 private:
00518
00519 Q_DISABLE_COPY( ResourceCached )
00520 class Private;
00521 Private *const d;
00522
00523 };
00524
00525 }
00526
00527 #endif