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

List:       kde-pim
Subject:    [Kde-pim] [PATCH] Facility to group incidence change notifications
From:       David Jarvie <lists () astrojar ! org ! uk>
Date:       2007-11-11 17:35:48
Message-ID: 200711111735.49598.lists () astrojar ! org ! uk
[Download RAW message or body]

I've noticed that KAlarm frequently makes changes to Events which result in as 
many as 20 incidence change notifications being generated in quick 
succession. I propose the attached patch to enable applications to suppress 
individual change notifications when they know they are going to make 
multiple changes to an Incidence, by calling startUpdates(). The change 
notification would finally be called when endUpdates() is called to indicate 
the end of the group of updates.

OK to commit?

-- 
David Jarvie.
KAlarm author and maintainer.
http://www.astrojar.org.uk/kalarm

["update.diff" (text/x-diff)]

Index: incidencebase.h
===================================================================
--- incidencebase.h	(revision 730871)
+++ incidencebase.h	(working copy)
@@ -520,6 +520,20 @@
     */
     void updated();
 
+    /**
+      Call this when a group of updates is going to be made. This suppresses
+      change notifications until endUpdates() is called, at which point
+      updated() will automatically be called.
+    */
+    void startUpdates();
+
+    /**
+      Call this when a group of updates is complete, to notify observers that
+      the instance has changed. This should be called in conjunction with
+      startUpdates().
+    */
+    void endUpdates();
+
   protected:
     /**
       @copydoc
Index: incidencebase.cpp
===================================================================
--- incidencebase.cpp	(revision 730871)
+++ incidencebase.cpp	(working copy)
@@ -52,7 +52,7 @@
 class KCal::IncidenceBase::Private
 {
   public:
-    Private() : mAllDay( true ), mHasDuration( false )
+    Private(): mUpdateGroupLevel( 0 ), mAllDay( true ), mHasDuration( false )
     { mAttendees.setAutoDelete( true ); }
 
     Private( const Private &other )
@@ -61,6 +61,7 @@
         mOrganizer( other.mOrganizer ),
         mUid( other.mUid ),
         mDuration( other.mDuration ),
+	mUpdateGroupLevel( 0 ),
         mAllDay( other.mAllDay ),
         mHasDuration( other.mHasDuration )
         //????? mComments
@@ -73,6 +74,7 @@
     Person mOrganizer;           // incidence person (owner)
     QString mUid;                // incidence unique id
     Duration mDuration;          // incidence duration
+    int mUpdateGroupLevel;       // if non-zero, suppresses update() calls
     bool mAllDay;                // true if the incidence is all-day
     bool mHasDuration;           // true if the incidence has a duration
 
@@ -434,11 +436,27 @@
 
 void IncidenceBase::updated()
 {
-  foreach ( IncidenceObserver *o, d->mObservers ) {
-    o->incidenceUpdated( this );
+  if ( !d->mUpdateGroupLevel ) {
+    foreach ( IncidenceObserver *o, d->mObservers ) {
+      o->incidenceUpdated( this );
+    }
   }
 }
 
+void IncidenceBase::startUpdates()
+{
+  ++d->mUpdateGroupLevel;
+}
+
+void IncidenceBase::endUpdates()
+{
+  if ( d->mUpdateGroupLevel > 0 ) {
+    if ( --d->mUpdateGroupLevel == 0 ) {
+      updated();
+    }
+  }
+}
+
 void IncidenceBase::customPropertyUpdated()
 {
   updated();


_______________________________________________
KDE PIM mailing list kde-pim@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