From b4d7e65ac0fe08b3b408bd3a0209d0fcd4c084fd Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 31 May 2010 21:22:53 +0000 Subject: Multi-save on exit fix git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1133001 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kresources/caldav/resource.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'kresources/caldav/resource.cpp') diff --git a/kresources/caldav/resource.cpp b/kresources/caldav/resource.cpp index 3ab1d358f..2562a8376 100644 --- a/kresources/caldav/resource.cpp +++ b/kresources/caldav/resource.cpp @@ -70,6 +70,7 @@ const int ResourceCalDav::DEFAULT_SAVE_POLICY = ResourceCached::SaveDelaye ResourceCalDav::ResourceCalDav( const KConfig *config ) : ResourceCached(config) , readLockout(false) + , mAllWritesComplete(false) , mLock(true) , mPrefs(NULL) , mLoader(NULL) @@ -77,6 +78,7 @@ ResourceCalDav::ResourceCalDav( const KConfig *config ) : , mProgress(NULL) , mLoadingQueueReady(true) , mWritingQueueReady(true) + , mWriteRetryTimer(NULL) { log("ResourceCalDav(config)"); init(); @@ -89,11 +91,14 @@ ResourceCalDav::ResourceCalDav( const KConfig *config ) : ResourceCalDav::~ResourceCalDav() { log("jobs termination"); - // This must save the users data before termination below to prevent data loss... - doSave(); + if (mWriteRetryTimer != NULL) { + mWriteRetryTimer->stop(); // Unfortunately we cannot do anything at this point; if this timer is still running something is seriously wrong + } + while ((mWriter->running() == true) || (mWritingQueue.isEmpty() == false) || !mWritingQueueReady) { - sleep(1); - qApp->processEvents(QEventLoop::ExcludeUserInput); + readLockout = true; + sleep(1); + qApp->processEvents(QEventLoop::ExcludeUserInput); } if (mLoader) { @@ -122,6 +127,10 @@ ResourceCalDav::~ResourceCalDav() { delete mPrefs; } +bool ResourceCalDav::isSaving() { + return (((mWriteRetryTimer != NULL) ? mWriteRetryTimer->isActive() : 0) || (mWriter->running() == true) || (mWritingQueue.isEmpty() == false) || !mWritingQueueReady); +} + /*========================================================================= | GENERAL METHODS ========================================================================*/ @@ -129,7 +138,7 @@ ResourceCalDav::~ResourceCalDav() { bool ResourceCalDav::doLoad() { bool syncCache = true; - if ((mLoadingQueueReady == false) || (mLoadingQueue.isEmpty() == false) || (mLoader->running() == true)) { + if ((mLoadingQueueReady == false) || (mLoadingQueue.isEmpty() == false) || (mLoader->running() == true) || (readLockout == true)) { return true; // Silently fail; the user has obviously not responded to a dialog and we don't need to pop up more of them! } @@ -587,7 +596,11 @@ bool ResourceCalDav::startWriting(const QString& url) { // modifies the calendar with clearChanges() or similar // Before these calls are made any existing read (and maybe write) threads should be finished if ((mLoader->running() == true) || (mLoadingQueue.isEmpty() == false) || (mWriter->running() == true) || (mWritingQueue.isEmpty() == false)) { - QTimer::singleShot( 100, this, SLOT(doSave()) ); + if (mWriteRetryTimer == NULL) { + mWriteRetryTimer = new QTimer(this); + connect( mWriteRetryTimer, SIGNAL(timeout()), SLOT(doSave()) ); + } + mWriteRetryTimer->start(1000, TRUE); return false; } -- cgit v1.2.1