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     QDateTime lastLoad() const;
00127 
00131     QDateTime lastSave() const;
00132 
00136     KDE_DEPRECATED bool addEvent( Event *event );
00137     bool addEvent( Event *event, const QString &subresource );
00138 
00142     bool deleteEvent(Event *);
00143 
00147     Event *event(const QString &UniqueStr);
00151     Event::List events();
00155     Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00160     Event::List rawEventsForDate( const QDate &date, EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00161 
00165     Event::List rawEventsForDate( const QDateTime &qdt );
00170     Event::List rawEvents( const QDate &start, const QDate &end,
00171                                bool inclusive = false );
00172 
00176     KDE_DEPRECATED bool addTodo( Todo *todo );
00177     bool addTodo( Todo *todo, const QString &subresource );
00178 
00182     bool deleteTodo( Todo * );
00187     Todo *todo( const QString &uid );
00191     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00195     Todo::List rawTodosForDate( const QDate &date );
00199     KDE_DEPRECATED bool addJournal( Journal *journal );
00200     bool addJournal( Journal *journal, const QString &subresource );
00201 
00205     bool deleteJournal( Journal * );
00209     Journal *journal( const QString &uid );
00213     Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted,SortDirection sortDirection = SortDirectionAscending );
00217     Journal::List rawJournalsForDate( const QDate &date );
00218 
00222     Alarm::List alarms( const QDateTime &from, const QDateTime &to );
00223 
00227     Alarm::List alarmsTo( const QDateTime &to );
00228 
00232     void setTimeZoneId( const QString &timeZoneId );
00233 
00234     QString timeZoneId() const;
00235 
00239     const Person &getOwner() const;
00243     void setOwner( const Person &owner );
00244 
00245     void enableChangeNotification();
00246     void disableChangeNotification();
00247 
00248     void clearChange( Incidence * );
00249     void clearChange( const QString &uid );
00250 
00251     void clearChanges();
00252 
00253     bool hasChanges() const;
00254 
00255     Incidence::List allChanges() const;
00256 
00257     Incidence::List addedIncidences() const;
00258     Incidence::List changedIncidences() const;
00259     Incidence::List deletedIncidences() const;
00260 
00264     void loadCache();
00265 
00269     void saveCache();
00270 
00274     void clearCache();
00275 
00276     void cleanUpEventCache( const KCal::Event::List &eventList );
00277     void cleanUpTodoCache( const KCal::Todo::List &todoList );
00278 
00282     KPIM::IdMapper& idMapper();
00283 
00284   protected:
00285     // From Calendar::Observer
00286     void calendarIncidenceAdded( KCal::Incidence *incidence );
00287     void calendarIncidenceChanged( KCal::Incidence *incidence );
00288     void calendarIncidenceDeleted( KCal::Incidence *incidence );
00289 
00290     CalendarLocal mCalendar;
00291 
00296     virtual void doClose();
00301     virtual bool doOpen();
00305     bool checkForReload();
00309     bool checkForSave();
00310 
00311     void checkForAutomaticSave();
00312 
00313     void addInfoText( QString & ) const;
00314 
00315     void setupSaveTimer();
00316     void setupReloadTimer();
00317 
00322     virtual QString cacheFile() const;
00323 
00327     virtual QString changesCacheFile( const QString& ) const;
00328     void loadChangesCache( QMap<Incidence*, bool>&, const QString& );
00329     void loadChangesCache();
00330     void saveChangesCache( const QMap<Incidence*, bool>&, const QString& );
00331     void saveChangesCache();
00332 
00333   protected slots:
00334     void slotReload();
00335     void slotSave();
00336 
00337     void setIdMapperIdentifier();
00338 
00339   private:
00340     int mReloadPolicy;
00341     int mReloadInterval;
00342     QTimer mReloadTimer;
00343     bool mReloaded;
00344 
00345     int mSavePolicy;
00346     int mSaveInterval;
00347     QTimer mSaveTimer;
00348 
00349     QDateTime mLastLoad;
00350     QDateTime mLastSave;
00351 
00352     QMap<KCal::Incidence *,bool> mAddedIncidences;
00353     QMap<KCal::Incidence *,bool> mChangedIncidences;
00354     QMap<KCal::Incidence *,bool> mDeletedIncidences;
00355 
00356     KPIM::IdMapper mIdMapper;
00357 
00358     class Private;
00359     Private *d;
00360 };
00361 
00362 }
00363 
00364 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys