home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / libkcal / resourcecached.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-01  |  9.2 KB  |  359 lines

  1. /*
  2.     This file is part of libkcal.
  3.  
  4.     Copyright (c) 2003,2004 Cornelius Schumacher <schumacher@kde.org>
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.     Boston, MA 02110-1301, USA.
  20. */
  21. #ifndef KCAL_RESOURCECACHED_H
  22. #define KCAL_RESOURCECACHED_H
  23.  
  24. #include "resourcecalendar.h"
  25.  
  26. #include "libemailfunctions/idmapper.h"
  27. #include "incidence.h"
  28. #include "calendarlocal.h"
  29.  
  30. #include <kconfig.h>
  31.  
  32. #include <qptrlist.h>
  33. #include <qstring.h>
  34. #include <qdatetime.h>
  35. #include <qtimer.h>
  36.  
  37. #include <kdepimmacros.h>
  38.  
  39. namespace KCal {
  40.  
  41. /**
  42.   This class provides a calendar resource using a local CalendarLocal object to
  43.   cache the calendar data.
  44. */
  45. class KDE_EXPORT ResourceCached : public ResourceCalendar,
  46.                        public KCal::Calendar::Observer
  47. {
  48.     Q_OBJECT
  49.   public:
  50.     /**
  51.       Reload policy.
  52.  
  53.       @see setReloadPolicy(), reloadPolicy()
  54.     */
  55.     enum { ReloadNever, ReloadOnStartup, ReloadInterval };
  56.     /**
  57.       Save policy.
  58.  
  59.       @see setSavePolicy(), savePolicy()
  60.     */
  61.     enum { SaveNever, SaveOnExit, SaveInterval, SaveDelayed, SaveAlways };
  62.  
  63.     ResourceCached( const KConfig * );
  64.     virtual ~ResourceCached();
  65.  
  66.     void readConfig( const KConfig *config );
  67.     void writeConfig( KConfig *config );
  68.  
  69.     /**
  70.       Set reload policy. This controls when the cache is refreshed.
  71.  
  72.       ReloadNever     never reload
  73.       ReloadOnStartup reload when resource is started
  74.       ReloadInterval  reload regularly after given interval
  75.     */
  76.     void setReloadPolicy( int policy );
  77.     /**
  78.       Return reload policy.
  79.  
  80.       @see setReloadPolicy()
  81.     */
  82.     int reloadPolicy() const;
  83.  
  84.     /**
  85.       Set reload interval in minutes which is used when reload policy is
  86.       ReloadInterval.
  87.     */
  88.     void setReloadInterval( int minutes );
  89.  
  90.     /**
  91.       Return reload interval in minutes.
  92.     */
  93.     int reloadInterval() const;
  94.  
  95.     /**
  96.       Set save policy. This controls when the cache is refreshed.
  97.  
  98.       SaveNever     never save
  99.       SaveOnExit    save when resource is exited
  100.       SaveInterval  save regularly after given interval
  101.       SaveDelayed   save after small delay
  102.       SaveAlways    save on every change
  103.     */
  104.     void setSavePolicy( int policy );
  105.     /**
  106.       Return save policy.
  107.  
  108.       @see setsavePolicy()
  109.     */
  110.     int savePolicy() const;
  111.  
  112.     /**
  113.       Set save interval in minutes which is used when save policy is
  114.       SaveInterval.
  115.     */
  116.     void setSaveInterval( int minutes );
  117.  
  118.     /**
  119.       Return save interval in minutes.
  120.     */
  121.     int saveInterval() const;
  122.  
  123.     /**
  124.       Return time of last load.
  125.     */
  126.     QDateTime lastLoad() const;
  127.  
  128.     /**
  129.       Return time of last save.
  130.     */
  131.     QDateTime lastSave() const;
  132.  
  133.     /**
  134.       Add event to calendar.
  135.     */
  136.     bool addEvent(Event *anEvent);
  137.     /**
  138.       Deletes an event from this calendar.
  139.     */
  140.     bool deleteEvent(Event *);
  141.  
  142.     /**
  143.       Retrieves an event on the basis of the unique string ID.
  144.     */
  145.     Event *event(const QString &UniqueStr);
  146.     /**
  147.       Return filtered list of all events in calendar.
  148.     */
  149.     Event::List events();
  150.     /**
  151.       Return unfiltered list of all events in calendar.
  152.     */
  153.     Event::List rawEvents( EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
  154.     /**
  155.       Builds and then returns a list of all events that match for the
  156.       date specified. useful for dayView, etc. etc.
  157.     */
  158.     Event::List rawEventsForDate( const QDate &date, EventSortField sortField = EventSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
  159.  
  160.     /**
  161.       Get unfiltered events for date \a qdt.
  162.     */
  163.     Event::List rawEventsForDate( const QDateTime &qdt );
  164.     /**
  165.       Get unfiltered events in a range of dates. If inclusive is set to true,
  166.       only events are returned, which are completely included in the range.
  167.     */
  168.     Event::List rawEvents( const QDate &start, const QDate &end,
  169.                                bool inclusive = false );
  170.  
  171.     /**
  172.       Add a todo to the todolist.
  173.     */
  174.     bool addTodo( Todo *todo );
  175.     /**
  176.       Remove a todo from the todolist.
  177.     */
  178.     bool deleteTodo( Todo * );
  179.     /**
  180.       Searches todolist for an event with this unique string identifier,
  181.       returns a pointer or null.
  182.     */
  183.     Todo *todo( const QString &uid );
  184.     /**
  185.       Return list of all todos.
  186.     */
  187.     Todo::List rawTodos( TodoSortField sortField = TodoSortUnsorted, SortDirection sortDirection = SortDirectionAscending );
  188.     /**
  189.       Returns list of todos due on the specified date.
  190.     */
  191.     Todo::List rawTodosForDate( const QDate &date );
  192.     /**
  193.       Add a Journal entry to calendar
  194.     */
  195.     virtual bool addJournal( Journal * );
  196.     /**
  197.       Remove a Journal from the calendar
  198.     */
  199.     virtual bool deleteJournal( Journal * );
  200.     /**
  201.       Return Journal with given unique id.
  202.     */
  203.     virtual Journal *journal( const QString &uid );
  204.     /**
  205.       Return list of all journals.
  206.     */
  207.     Journal::List rawJournals( JournalSortField sortField = JournalSortUnsorted,SortDirection sortDirection = SortDirectionAscending );
  208.     /**
  209.       Return list of journals for the given date.
  210.     */
  211.     Journal::List rawJournalsForDate( const QDate &date );
  212.  
  213.     /**
  214.       Return all alarms, which ocur in the given time interval.
  215.     */
  216.     Alarm::List alarms( const QDateTime &from, const QDateTime &to );
  217.  
  218.     /**
  219.       Return all alarms, which ocur before given date.
  220.     */
  221.     Alarm::List alarmsTo( const QDateTime &to );
  222.  
  223.     /**
  224.       Set id of timezone, e.g. "Europe/Berlin"
  225.     */
  226.     void setTimeZoneId( const QString &timeZoneId );
  227.  
  228.     QString timeZoneId() const;
  229.  
  230.     /**
  231.       Return the owner of the calendar's full name.
  232.     */
  233.     const Person &getOwner() const;
  234.     /**
  235.       Set the owner of the calendar. Should be owner's full name.
  236.     */
  237.     void setOwner( const Person &owner );
  238.  
  239.     void enableChangeNotification();
  240.     void disableChangeNotification();
  241.  
  242.     void clearChange( Incidence * );
  243.     void clearChange( const QString &uid );
  244.  
  245.     void clearChanges();
  246.  
  247.     bool hasChanges() const;
  248.  
  249.     Incidence::List allChanges() const;
  250.  
  251.     Incidence::List addedIncidences() const;
  252.     Incidence::List changedIncidences() const;
  253.     Incidence::List deletedIncidences() const;
  254.  
  255.     /**
  256.       Loads the cache, this method should be called on load.
  257.      */
  258.     void loadCache();
  259.  
  260.     /**
  261.       Saves the cache back.
  262.      */
  263.     void saveCache();
  264.  
  265.     /**
  266.       Clear cache.
  267.     */
  268.     void clearCache();
  269.  
  270.     void cleanUpEventCache( const KCal::Event::List &eventList );
  271.     void cleanUpTodoCache( const KCal::Todo::List &todoList );
  272.  
  273.     /**
  274.       Returns a reference to the id mapper.
  275.      */
  276.     KPIM::IdMapper& idMapper();
  277.  
  278.   protected:
  279.     // From Calendar::Observer
  280.     void calendarIncidenceAdded( KCal::Incidence *incidence );
  281.     void calendarIncidenceChanged( KCal::Incidence *incidence );
  282.     void calendarIncidenceDeleted( KCal::Incidence *incidence );
  283.  
  284.     CalendarLocal mCalendar;
  285.  
  286.     /**
  287.       Virtual method from KRES::Resource, called when the last instace of the
  288.       resource is closed
  289.      */
  290.     virtual void doClose();
  291.     /**
  292.       Opens the resource. Dummy implementation, so child classes don't have to
  293.       reimplement this method. By default, this does not do anything, but can be reimplemented in child classes
  294.      */
  295.     virtual bool doOpen();
  296.     /**
  297.       Check if reload required according to reload policy.
  298.     */
  299.     bool checkForReload();
  300.     /**
  301.       Check if save required according to save policy.
  302.     */
  303.     bool checkForSave();
  304.  
  305.     void checkForAutomaticSave();
  306.  
  307.     void addInfoText( QString & ) const;
  308.  
  309.     void setupSaveTimer();
  310.     void setupReloadTimer();
  311.  
  312.     /**
  313.       This method is used by loadCache() and saveCache(), reimplement
  314.       it to change the location of the cache.
  315.      */
  316.     virtual QString cacheFile() const;
  317.  
  318.     /**
  319.       Functions for keeping the changes persistent.
  320.      */
  321.     virtual QString changesCacheFile( const QString& ) const;
  322.     void loadChangesCache( QMap<Incidence*, bool>&, const QString& );
  323.     void loadChangesCache();
  324.     void saveChangesCache( const QMap<Incidence*, bool>&, const QString& );
  325.     void saveChangesCache();
  326.  
  327.   protected slots:
  328.     void slotReload();
  329.     void slotSave();
  330.  
  331.     void setIdMapperIdentifier();
  332.  
  333.   private:
  334.     int mReloadPolicy;
  335.     int mReloadInterval;
  336.     QTimer mReloadTimer;
  337.     bool mReloaded;
  338.  
  339.     int mSavePolicy;
  340.     int mSaveInterval;
  341.     QTimer mSaveTimer;
  342.  
  343.     QDateTime mLastLoad;
  344.     QDateTime mLastSave;
  345.  
  346.     QMap<KCal::Incidence *,bool> mAddedIncidences;
  347.     QMap<KCal::Incidence *,bool> mChangedIncidences;
  348.     QMap<KCal::Incidence *,bool> mDeletedIncidences;
  349.  
  350.     KPIM::IdMapper mIdMapper;
  351.  
  352.     class Private;
  353.     Private *d;
  354. };
  355.  
  356. }
  357.  
  358. #endif
  359.