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

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

On vrijdag 12 december 2003 00:22, Cornelius Schumacher wrote:
> Have a look at the beginChange() and endChange() methods in Calendar. 
> They are intended to do the same, but with proper locking of the 
> resources or whatever else is needed. Would that also fit your needs?

We could update the changed resource in endChange(), but it would be nicer
to store information on which incidences have been changed in the save Ticket,
and then update all changed incidences in one go.

That would amount to my previous patch on this, on keeping information
about which incidences are changed in the save-ticket. I'm attaching it again.
Can I apply this?

> One problem is that currently KOrganizer doesn't always calls these 
> methods when events are changed. This has to be improved.

I looked at this last time. The first problem seems to be in CalendarView::editEvent(),
where beginChange() is called. Is there is an editor dialog still hanging around
for the event (closed or open), beginChange() isn't called. This may be because 
How can we differentiate between an event still being edited, and an event having 
been edited, but the event editor dialog still hanging around? 

There might be other instances like this, maybe related to DnD, I'll do some
experimenting later.

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