From kde-pim Sun Nov 11 17:35:48 2007 From: David Jarvie Date: Sun, 11 Nov 2007 17:35:48 +0000 To: kde-pim Subject: [Kde-pim] [PATCH] Facility to group incidence change notifications Message-Id: <200711111735.49598.lists () astrojar ! org ! uk> X-MARC-Message: https://marc.info/?l=kde-pim&m=119480255123991 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--Boundary-00=_11zNHgzeGgAMgev" --Boundary-00=_11zNHgzeGgAMgev Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 --Boundary-00=_11zNHgzeGgAMgev Content-Type: text/x-diff; charset="us-ascii"; name="update.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="update.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(); --Boundary-00=_11zNHgzeGgAMgev Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ 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/ --Boundary-00=_11zNHgzeGgAMgev--