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 <tqptrlist.h>
00033 #include <tqstring.h>
00034 #include <tqdatetime.h>
00035 #include <tqtimer.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 
00069     static bool editorWindowOpen();
00070     static void setEditorWindowOpen(bool open);
00071 
00079     void setReloadPolicy( int policy );
00085     int reloadPolicy() const;
00086 
00091     void setReloadInterval( int minutes );
00092 
00096     int reloadInterval() const;
00097 
00107     void setSavePolicy( int policy );
00113     int savePolicy() const;
00114 
00119     void setSaveInterval( int minutes );
00120 
00124     int saveInterval() const;
00125 
00129     TQDateTime lastLoad() const;
00130 
00134     TQDateTime lastSave() const;
00135 
00139     KDE_DEPRECATED bool addEvent( Event *event );
00140     bool addEvent( Event *event, const TQString &subresource );
00141 
00145     bool deleteEvent(Event *);
00146 
00150     Event *event(const TQString &UniqueStr);
00154     Event::List events();
00158     Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00163     Event::List rawEventsForDate( const TQDate &date, EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00164 
00168     Event::List rawEventsForDate( const TQDateTime &qdt );
00173     Event::List rawEvents( const TQDate &start, const TQDate &end,
00174                                bool inclusive = false );
00175 
00179     KDE_DEPRECATED bool addTodo( Todo *todo );
00180     bool addTodo( Todo *todo, const TQString &subresource );
00181 
00185     bool deleteTodo( Todo * );
00190     Todo *todo( const TQString &uid );
00194     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
00198     Todo::List rawTodosForDate( const TQDate &date );
00202     KDE_DEPRECATED bool addJournal( Journal *journal );
00203     bool addJournal( Journal *journal, const TQString &subresource );
00204 
00208     bool deleteJournal( Journal * );
00212     Journal *journal( const TQString &uid );
00216     Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted,SortDirection sortDirection = SortDirectionAscending );
00220     Journal::List rawJournalsForDate( const TQDate &date );
00221 
00225     Alarm::List alarms( const TQDateTime &from, const TQDateTime &to );
00226 
00230     Alarm::List alarmsTo( const TQDateTime &to );
00231 
00235     void setTimeZoneId( const TQString &timeZoneId );
00236 
00237     TQString timeZoneId() const;
00238 
00242     const Person &getOwner() const;
00246     void setOwner( const Person &owner );
00247 
00248     void enableChangeNotification();
00249     void disableChangeNotification();
00250 
00251     void clearChange( Incidence * );
00252     void clearChange( const TQString &uid );
00253 
00254     void clearChanges();
00255 
00256     bool hasChanges() const;
00257 
00258     Incidence::List allChanges() const;
00259 
00260     Incidence::List addedIncidences() const;
00261     Incidence::List changedIncidences() const;
00262     Incidence::List deletedIncidences() const;
00263 
00267     void loadCache();
00268 
00272     void saveCache();
00273 
00277     void clearCache();
00278 
00282     void clearEventsCache();
00283 
00287     void clearTodosCache();
00288 
00292     void clearJournalsCache();
00293 
00294     void cleanUpEventCache( const KCal::Event::List &eventList );
00295     void cleanUpTodoCache( const KCal::Todo::List &todoList );
00296 
00300     KPIM::IdMapper& idMapper();
00301 
00302   protected:
00303     // From Calendar::Observer
00304     void calendarIncidenceAdded( KCal::Incidence *incidence );
00305     void calendarIncidenceChanged( KCal::Incidence *incidence );
00306     void calendarIncidenceDeleted( KCal::Incidence *incidence );
00307 
00308     CalendarLocal mCalendar;
00309 
00314     virtual void doClose();
00319     virtual bool doOpen();
00323     bool checkForReload();
00327     bool checkForSave();
00328 
00329     void checkForAutomaticSave();
00330 
00331     void addInfoText( TQString & ) const;
00332 
00333     void setupSaveTimer();
00334     void setupReloadTimer();
00335 
00340     virtual TQString cacheFile() const;
00341 
00345     virtual TQString changesCacheFile( const TQString& ) const;
00346     void loadChangesCache( TQMap<Incidence*, bool>&, const TQString& );
00347     void loadChangesCache();
00348     void saveChangesCache( const TQMap<Incidence*, bool>&, const TQString& );
00349     void saveChangesCache();
00350 
00351   protected slots:
00352     void slotReload();
00353     void slotSave();
00354 
00355     void setIdMapperIdentifier();
00356 
00357   private:
00358     int mReloadPolicy;
00359     int mReloadInterval;
00360     TQTimer mReloadTimer;
00361     bool mReloaded;
00362 
00363     int mSavePolicy;
00364     int mSaveInterval;
00365     TQTimer mSaveTimer;
00366 
00367     TQDateTime mLastLoad;
00368     TQDateTime mLastSave;
00369 
00370     TQMap<KCal::Incidence *,bool> mAddedIncidences;
00371     TQMap<KCal::Incidence *,bool> mChangedIncidences;
00372     TQMap<KCal::Incidence *,bool> mDeletedIncidences;
00373 
00374     KPIM::IdMapper mIdMapper;
00375 
00376     class Private;
00377     Private *d;
00378 };
00379 
00380 }
00381 
00382 #endif