[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    RE: [Kde-pim] Server-based resources and editing events
From:       "Best, Jan-Pascal van" <j.p.vanbest () tbm ! tudelft ! nl>
Date:       2003-12-08 10:26:16
[Download RAW message or body]

Hi all,

I wrote earlier:
> The save() method is called from 
> CalendarResources::endChange(), which together
> with beginChange() should know which incidences are 
> being/have been edited. Is it 
> possible to add this information to the save ticket and pass 
> it on to the resource,
> so that the resource can choose to save only the modified incidences?
> 
> It would mean changing the signature of 
> ResourceCalendar::save() to add an
> (optional) QPtrList<KCal::Incidence> parameter. Resource 
> implementations based
> on files (local or remote) can ignore this parameter and just 
> save the whole lot,
> but ldap/database/exchange resources can just save the 
> modified incidences.

Attached is a patch for libkcal which implements this. It is completely
source compatible, though I'm not sure about binary compatibility.
It adds a
	virtual bool ResourceCalendar::save( QPtrList<Incidence> )
which by default just calls ResourceCalendar::save() to ignore the
incidence list and just save the entire calendar. I've modified
the ExchangeResource to make use of this mechanism.

The new save() method is called from the CalendarResources, which
keeps track of the changed Incidences in the save Ticket. The Ticket
class is updated with a flag hasIncidences (true means that the changed 
incidences are kept track of) and a QPtrList<Incidences>, which lists the
changes. The CalendarResources::beginChange(), ::save() and 
requestSaveTicket() are modified to store the changes in the Ticket.

It works for me, but not completely. The problem is that this mechanism depends
on Calendar::beginChange() and endChange() being called pairwise (not 
necessarily nested). The current CalendarView is KOrganizer doesn't do that
properly:
- If you edit an event, then click OK, everything works nicely. But then the 
KOEventDialog is kept, and the next time you edit the dialog, 
KOrg::CalendarView::editEvent() doesn't call beginChange() because it assumes the
kept editors hasn't been closed yet.
- If you cancel an editor dialog, endChange() is not called
- If you move an event around, only endChange() is called, not beginChange().

I'll try and look more closely into making sure that KOrganizer calls beginChange()
and endChange() properly. Meanwhile, what do you think of this patch? Of course, I'll 
only think about committing when I have the other issues resolved.

Cheers
Jan-Pascal

["tickets.patch" (application/octet-stream)]

Index: calendarresources.cpp
===================================================================
RCS file: /home/kde/kdepim/libkcal/calendarresources.cpp,v
retrieving revision 1.35
diff -u -3 -p -r1.35 calendarresources.cpp
--- calendarresources.cpp	9 Nov 2003 23:23:26 -0000	1.35
+++ calendarresources.cpp	8 Dec 2003 09:04:06 -0000
@@ -641,13 +641,13 @@ void CalendarResources::doSetTimeZoneId(
   }
 }
 
-CalendarResources::Ticket *CalendarResources::requestSaveTicket( ResourceCalendar \
*resource ) +CalendarResources::Ticket *CalendarResources::requestSaveTicket( \
ResourceCalendar *resource, bool hasIncidences )  {
   kdDebug(5800) << "CalendarResources::requestSaveTicket()" << endl;
 
   KABC::Lock *lock = resource->lock();
   if ( !lock ) return 0;
-  if ( lock->lock() ) return new Ticket( resource );
+  if ( lock->lock() ) return new Ticket( resource, hasIncidences );
   else return 0;
 }
 
@@ -655,7 +655,13 @@ bool CalendarResources::save( Ticket *ti
 {
   if ( !ticket || !ticket->resource() ) return false;
 
-  if ( ticket->resource()->save() ) {
+  bool success;
+  if ( ticket->hasIncidences() )
+    success = ticket->resource()->save( ticket->incidences() );
+  else
+    success = ticket->resource()->save();
+
+  if ( success ) {
     releaseSaveTicket( ticket );
     return true;
   }
@@ -684,8 +690,11 @@ bool CalendarResources::beginChange( Inc
   }
     
   int count = incrementChangeCount( r );
-  if ( count == 1 ) {
-    Ticket *ticket = requestSaveTicket( r );
+  if ( count != 1 ) {
+      Ticket *ticket = mTickets[ r ];
+      ticket->addIncidence( incidence );
+  } else {
+    Ticket *ticket = requestSaveTicket( r, true );
     if ( !ticket ) {
       kdDebug(5800) << "CalendarResources::beginChange(): unable to get ticket."
                     << endl;
@@ -693,6 +702,7 @@ bool CalendarResources::beginChange( Inc
       return false;
     } else {
       mTickets[ r ] = ticket;
+      ticket->addIncidence( incidence );
     }
   }
 
Index: calendarresources.h
===================================================================
RCS file: /home/kde/kdepim/libkcal/calendarresources.h,v
retrieving revision 1.26
diff -u -3 -p -r1.26 calendarresources.h
--- calendarresources.h	9 Nov 2003 23:23:26 -0000	1.26
+++ calendarresources.h	8 Dec 2003 09:04:06 -0000
@@ -85,11 +85,17 @@ class CalendarResources : public Calenda
         friend class CalendarResources;
       public:
         ResourceCalendar *resource() const { return mResource; }
+        bool hasIncidences() { return mHasIncidences; }
+        QPtrList<Incidence> const incidences() const { return mIncidences; }
         
       private:
-        Ticket( ResourceCalendar *r ) : mResource( r ) {}
+        Ticket( ResourceCalendar *r, bool hasIncidences=false ) : mResource( r ), \
mHasIncidences( hasIncidences ), mIncidences() {} +        void addIncidence( \
Incidence *incidence ) { if ( mHasIncidences ) mIncidences.append( incidence ); } +   \
void clearIncidences() { if ( mHasIncidences ) { mIncidences.clear(); mHasIncidences \
= false; } }  
         ResourceCalendar *mResource;
+        bool mHasIncidences; // true if all modified Incidences are in mIncidences
+        QPtrList<Incidence> mIncidences;
     };
 
     /** constructs a new calendar that uses the ResourceManager for "calendar" */
@@ -123,7 +129,7 @@ class CalendarResources : public Calenda
       calendar is locked for write access until save() or releaseSaveTicket() is
       called.
     */
-    Ticket *requestSaveTicket( ResourceCalendar * );
+    Ticket *requestSaveTicket( ResourceCalendar *, bool hasIncidences=false );
     /**
       Save calendar. If save is successfull, the ticket is deleted.
     */
Index: resourcecalendar.cpp
===================================================================
RCS file: /home/kde/kdepim/libkcal/resourcecalendar.cpp,v
retrieving revision 1.9
diff -u -3 -p -r1.9 resourcecalendar.cpp
--- resourcecalendar.cpp	22 Jul 2003 18:56:46 -0000	1.9
+++ resourcecalendar.cpp	8 Dec 2003 09:04:06 -0000
@@ -45,6 +45,11 @@ void ResourceCalendar::writeConfig( KCon
   KRES::Resource::writeConfig( config );
 }
 
+bool ResourceCalendar::save( QPtrList<Incidence> )
+{
+  return save();
+}
+
 bool ResourceCalendar::addIncidence( Incidence *incidence )
 {
   Incidence::AddVisitor<ResourceCalendar> v( this );
Index: resourcecalendar.h
===================================================================
RCS file: /home/kde/kdepim/libkcal/resourcecalendar.h,v
retrieving revision 1.18
diff -u -3 -p -r1.18 resourcecalendar.h
--- resourcecalendar.h	30 Oct 2003 09:44:04 -0000	1.18
+++ resourcecalendar.h	8 Dec 2003 09:04:06 -0000
@@ -73,7 +73,7 @@ class ResourceCalendar : public KRES::Re
     virtual bool load() = 0;
 
     /**
-      Save resource data. After calling this function it is save to close the
+      Save resource data. After calling this function it is safe to close the
       resource without losing data.
       
       If data is actually saved within this function or saving is delayed
@@ -85,6 +85,14 @@ class ResourceCalendar : public KRES::Re
     */
     virtual bool save() = 0;
 
+    /**
+     As save(), but with the added hint that only the incidences in the list
+     have changes. The resource can choose either to save the entire dataset,
+     or only the incidences listed.
+     The default implementation just calls save().
+    */
+    virtual bool save( QPtrList<Incidence> );
+
     virtual bool isSaving() { return false; }
 
     virtual KABC::Lock *lock() = 0;



_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic