From 4f6c584bacc8c3c694228f36ada3de77a76614a6 Mon Sep 17 00:00:00 2001
From: tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>
Date: Mon, 30 Aug 2010 07:52:23 +0000
Subject: * Fixed CalDAV tasks loading when event loading fails * Added
 calendar control functions to allow for a partial cache clear of only events,
 todos, or journals

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1169887 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
---
 kresources/caldav/resource.cpp |  5 ++++-
 libkcal/calendar.h             | 15 ++++++++++++++
 libkcal/calendarlocal.cpp      | 39 ++++++++++++++++++++++++++++++++++++
 libkcal/calendarlocal.h        | 15 ++++++++++++++
 libkcal/calendarnull.h         | 15 ++++++++++++++
 libkcal/calendarresources.cpp  | 45 ++++++++++++++++++++++++++++++++++++++++++
 libkcal/calendarresources.h    | 15 ++++++++++++++
 libkcal/resourcecached.cpp     | 15 ++++++++++++++
 libkcal/resourcecached.h       | 15 ++++++++++++++
 9 files changed, 178 insertions(+), 1 deletion(-)

diff --git a/kresources/caldav/resource.cpp b/kresources/caldav/resource.cpp
index 59865f41..c0bbf115 100644
--- a/kresources/caldav/resource.cpp
+++ b/kresources/caldav/resource.cpp
@@ -501,7 +501,7 @@ bool ResourceCalDav::parseData(const TQString& data) {
     }
 
     log("clearing cache");
-    clearCache();
+    clearEventsCache();
 
     disableChangeNotification();
 
@@ -557,6 +557,9 @@ bool ResourceCalDav::parseTasksData(const TQString& data) {
         return false;
     }
 
+    log("clearing cache");
+    clearTodosCache();
+
     disableChangeNotification();
 
     log("actually parsing the data");
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 4c6c0f98..a53ef5a0 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -284,6 +284,21 @@ class LIBKCAL_EXPORT Calendar : public TQObject, public CustomProperties,
     */
     virtual void close() = 0;
 
+    /**
+       Clears out the current Calendar, freeing all used memory etc.
+    */
+    virtual void closeEvents() = 0;
+
+    /**
+       Clears out the current Calendar, freeing all used memory etc.
+    */
+    virtual void closeTodos() = 0;
+
+    /**
+       Clears out the current Calendar, freeing all used memory etc.
+    */
+    virtual void closeJournals() = 0;
+
     /**
        Sync changes in memory to persistant storage.
     */
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 716fa5e9..27b27e0e 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -104,6 +104,45 @@ void CalendarLocal::close()
   setObserversEnabled( true );
 }
 
+void CalendarLocal::closeEvents()
+{
+  setObserversEnabled( false );
+  mFileName = TQString::null;
+
+  deleteAllEvents();
+
+  mDeletedIncidences.clear();
+  setModified( false );
+
+  setObserversEnabled( true );
+}
+
+void CalendarLocal::closeTodos()
+{
+  setObserversEnabled( false );
+  mFileName = TQString::null;
+
+  deleteAllTodos();
+
+  mDeletedIncidences.clear();
+  setModified( false );
+
+  setObserversEnabled( true );
+}
+
+void CalendarLocal::closeJournals()
+{
+  setObserversEnabled( false );
+  mFileName = TQString::null;
+
+  deleteAllJournals();
+
+  mDeletedIncidences.clear();
+  setModified( false );
+
+  setObserversEnabled( true );
+}
+
 
 bool CalendarLocal::addEvent( Event *event )
 {
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 7326a234..5a8e3cd7 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -78,6 +78,21 @@ class LIBKCAL_EXPORT CalendarLocal : public Calendar
     */
     void close();
 
+    /**
+      Clears out the current calendar, freeing all used memory etc. etc.
+    */
+    void closeEvents();
+
+    /**
+      Clears out the current calendar, freeing all used memory etc. etc.
+    */
+    void closeTodos();
+
+    /**
+      Clears out the current calendar, freeing all used memory etc. etc.
+    */
+    void closeJournals();
+
     void save() {}
 
     /**
diff --git a/libkcal/calendarnull.h b/libkcal/calendarnull.h
index d6c75844..8ea0afa9 100644
--- a/libkcal/calendarnull.h
+++ b/libkcal/calendarnull.h
@@ -71,6 +71,21 @@ class LIBKCAL_EXPORT CalendarNull : public Calendar
     */
     void close() {}
 
+    /**
+       Clears out the current Calendar, freeing all used memory etc.
+    */
+    void closeEvents() {}
+
+    /**
+       Clears out the current Calendar, freeing all used memory etc.
+    */
+    void closeTodos() {}
+
+    /**
+       Clears out the current Calendar, freeing all used memory etc.
+    */
+    void closeJournals() {}
+
     /**
        Sync changes in memory to persistant storage.
     */
diff --git a/libkcal/calendarresources.cpp b/libkcal/calendarresources.cpp
index 94ce0ca3..42f618dc 100644
--- a/libkcal/calendarresources.cpp
+++ b/libkcal/calendarresources.cpp
@@ -204,6 +204,51 @@ void CalendarResources::close()
   }
 }
 
+void CalendarResources::closeEvents()
+{
+  kdDebug(5800) << "CalendarResources::close" << endl;
+
+  if ( mOpen ) {
+    CalendarResourceManager::ActiveIterator it;
+    for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
+      (*it)->close();
+    }
+
+    setModified( false );
+    mOpen = false;
+  }
+}
+
+void CalendarResources::closeTodos()
+{
+  kdDebug(5800) << "CalendarResources::close" << endl;
+
+  if ( mOpen ) {
+    CalendarResourceManager::ActiveIterator it;
+    for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
+      (*it)->close();
+    }
+
+    setModified( false );
+    mOpen = false;
+  }
+}
+
+void CalendarResources::closeJournals()
+{
+  kdDebug(5800) << "CalendarResources::close" << endl;
+
+  if ( mOpen ) {
+    CalendarResourceManager::ActiveIterator it;
+    for ( it = mManager->activeBegin(); it != mManager->activeEnd(); ++it ) {
+      (*it)->close();
+    }
+
+    setModified( false );
+    mOpen = false;
+  }
+}
+
 void CalendarResources::save()
 {
   kdDebug(5800) << "CalendarResources::save()" << endl;
diff --git a/libkcal/calendarresources.h b/libkcal/calendarresources.h
index 9d343634..32c48ba4 100644
--- a/libkcal/calendarresources.h
+++ b/libkcal/calendarresources.h
@@ -187,6 +187,21 @@ class LIBKCAL_EXPORT CalendarResources :
     */
     void close();
 
+    /**
+       Clear out the current Calendar, freeing all used memory etc.
+    */
+    void closeEvents();
+
+    /**
+       Clear out the current Calendar, freeing all used memory etc.
+    */
+    void closeTodos();
+
+    /**
+       Clear out the current Calendar, freeing all used memory etc.
+    */
+    void closeJournals();
+
     /**
        Save this Calendar.
        If the save is successfull, the Ticket is deleted.  Otherwise, the
diff --git a/libkcal/resourcecached.cpp b/libkcal/resourcecached.cpp
index 155d24a0..1a4e8b19 100644
--- a/libkcal/resourcecached.cpp
+++ b/libkcal/resourcecached.cpp
@@ -321,6 +321,21 @@ void ResourceCached::clearCache()
   mCalendar.close();
 }
 
+void ResourceCached::clearEventsCache()
+{
+  mCalendar.closeEvents();
+}
+
+void ResourceCached::clearTodosCache()
+{
+  mCalendar.closeTodos();
+}
+
+void ResourceCached::clearJournalsCache()
+{
+  mCalendar.closeJournals();
+}
+
 void ResourceCached::cleanUpEventCache( const Event::List &eventList )
 {
   CalendarLocal calendar ( TQString::fromLatin1( "UTC" ) );
diff --git a/libkcal/resourcecached.h b/libkcal/resourcecached.h
index 42212272..60976698 100644
--- a/libkcal/resourcecached.h
+++ b/libkcal/resourcecached.h
@@ -270,6 +270,21 @@ class KDE_EXPORT ResourceCached : public ResourceCalendar,
     */
     void clearCache();
 
+    /**
+      Clear events cache.
+    */
+    void clearEventsCache();
+
+    /**
+      Clear todos cache.
+    */
+    void clearTodosCache();
+
+    /**
+      Clear journals cache.
+    */
+    void clearJournalsCache();
+
     void cleanUpEventCache( const KCal::Event::List &eventList );
     void cleanUpTodoCache( const KCal::Todo::List &todoList );
 
-- 
cgit v1.2.3

