libkcal

resourcecached.h

00001 /*
00002     This file is part of libkcal.
00003 
00004     Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 */
00021 #ifndef KCAL_RESOURCECACHED_H
00022 #define KCAL_RESOURCECACHED_H
00023 
00024 #include "resourcecalendar.h"
00025 
00026 #include "libemailfunctions/idmapper.h"
00027 #include "incidence.h"
00028 #include "calendarlocal.h"
00029 
00030 #include <kconfig.h>
00031 
00032 #include <qptrlist.h>
00033 #include <qstring.h>
00034 #include <qdatetime.h>
00035 #include <qtimer.h>
00036 
00037 #include <kdepimmacros.h>
00038 
00039 namespace KCal {
00040 
00045 class KDE_EXPORT ResourceCached : public ResourceCalendar,
00046                        public KCal::Calendar::Observer
00047 {
00048     Q_OBJECT
00049   public:
00055     enum { ReloadNever, ReloadOnStartup, ReloadInterval };
00061     enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways };
00062 
00063     ResourceCached( const KConfig * );
00064     virtual ~ResourceCached();
00065 
00066     void readConfig( const KConfig *config );
00067     void writeConfig( KConfig *config );
00068 
00076     void setReloadPolicy( int policy );
00082     int reloadPolicy() const;
00083 
00088     void setReloadInterval( int minutes );
00089 
00093     int reloadInterval() const;
00094 
00104     void setSavePolicy( int policy );
00110     int savePolicy() const;
00111 
00116     void setSaveInterval( int minutes );
00117 
00121     int saveInterval() const;
00122 
00126     void setLastLoad( const QDateTime & );
00130     QDateTime lastLoad() const;
00131 
00135     void setLastSave( const QDateTime & );
00139     QDateTime lastSave() const;
00140 
00144     bool addEvent(Event *anEvent);
00148     bool deleteEvent(Event *);
00149 
00153     Event *event(const QString &UniqueStr);
00157     Event::List events();
00161     Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00166     Event::List rawEventsForDate( const QDate &date, EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00167 
00171     Event::List rawEventsForDate( const QDateTime &qdt );
00176     Event::List rawEvents( const QDate &start, const QDate &end,
00177                                bool inclusive = false );
00178 
00182     bool addTodo( Todo *todo );
00186     bool deleteTodo( Todo * );
00191     Todo *todo( const QString &uid );
00195     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00199     Todo::List rawTodosForDate( const QDate &date );
00203     virtual bool addJournal( Journal * );
00207     virtual bool deleteJournal( Journal * );
00211     virtual Journal *journal( const QString &uid );
00215     Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted,SortDirection sortDirection = SortDirectionAscending );
00219     Journal::List rawJournalsForDate( const QDate &date );
00220 
00224     Alarm::List alarms( const QDateTime &from, const QDateTime &to );
00225 
00229     Alarm::List alarmsTo( const QDateTime &to );
00230 
00234     void setTimeZoneId( const QString &timeZoneId );
00235 
00236     QString timeZoneId() const;
00237 
00241     const Person &getOwner() const;
00245     void setOwner( const Person &owner );
00246 
00247     void enableChangeNotification();
00248     void disableChangeNotification();
00249 
00250     void clearChange( Incidence * );
00251     void clearChange( const QString &uid );
00252 
00253     void clearChanges();
00254 
00255     bool hasChanges() const;
00256 
00257     Incidence::List allChanges() const;
00258 
00259     Incidence::List addedIncidences() const;
00260     Incidence::List changedIncidences() const;
00261     Incidence::List deletedIncidences() const;
00262 
00266     void loadCache();
00267 
00271     void saveCache();
00272 
00276     void clearCache();
00277 
00278     void cleanUpEventCache( const KCal::Event::List &eventList );
00279     void cleanUpTodoCache( const KCal::Todo::List &todoList );
00280 
00284     KPIM::IdMapper& idMapper();
00285 
00286   protected:
00287     // From Calendar::Observer
00288     void calendarIncidenceAdded( KCal::Incidence *incidence );
00289     void calendarIncidenceChanged( KCal::Incidence *incidence );
00290     void calendarIncidenceDeleted( KCal::Incidence *incidence );
00291 
00292     CalendarLocal mCalendar;
00293 
00298     virtual void doClose();
00303     virtual bool doOpen();
00307     bool checkForReload();
00311     bool checkForSave();
00312 
00313     void checkForAutomaticSave();
00314 
00315     void addInfoText( QString & ) const;
00316 
00317     void setupSaveTimer();
00318     void setupReloadTimer();
00319 
00324     virtual QString cacheFile() const;
00325 
00329     virtual QString changesCacheFile( const QString& ) const;
00330     void loadChangesCache( QMap<Incidence*, bool>&, const QString& );
00331     void loadChangesCache();
00332     void saveChangesCache( const QMap<Incidence*, bool>&, const QString& );
00333     void saveChangesCache();
00334 
00335   protected slots:
00336     void slotReload();
00337     void slotSave();
00338 
00339     void setIdMapperIdentifier();
00340 
00341   private:
00342     int mReloadPolicy;
00343     int mReloadInterval;
00344     QTimer mReloadTimer;
00345     bool mReloaded;
00346 
00347     int mSavePolicy;
00348     int mSaveInterval;
00349     QTimer mSaveTimer;
00350 
00351     QDateTime mLastLoad;
00352     QDateTime mLastSave;
00353 
00354     QMap<KCal::Incidence *,bool> mAddedIncidences;
00355     QMap<KCal::Incidence *,bool> mChangedIncidences;
00356     QMap<KCal::Incidence *,bool> mDeletedIncidences;
00357 
00358     KPIM::IdMapper mIdMapper;
00359 
00360     class Private;
00361     Private *d;
00362 };
00363 
00364 }
00365 
00366 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys