Multi-save on exit fix

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1133001 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 14 years ago
parent 7ef3b0e2a5
commit b4d7e65ac0

@ -70,6 +70,7 @@ const int ResourceCalDav::DEFAULT_SAVE_POLICY = ResourceCached::SaveDelaye
ResourceCalDav::ResourceCalDav( const KConfig *config ) : ResourceCalDav::ResourceCalDav( const KConfig *config ) :
ResourceCached(config) ResourceCached(config)
, readLockout(false) , readLockout(false)
, mAllWritesComplete(false)
, mLock(true) , mLock(true)
, mPrefs(NULL) , mPrefs(NULL)
, mLoader(NULL) , mLoader(NULL)
@ -77,6 +78,7 @@ ResourceCalDav::ResourceCalDav( const KConfig *config ) :
, mProgress(NULL) , mProgress(NULL)
, mLoadingQueueReady(true) , mLoadingQueueReady(true)
, mWritingQueueReady(true) , mWritingQueueReady(true)
, mWriteRetryTimer(NULL)
{ {
log("ResourceCalDav(config)"); log("ResourceCalDav(config)");
init(); init();
@ -89,9 +91,12 @@ ResourceCalDav::ResourceCalDav( const KConfig *config ) :
ResourceCalDav::~ResourceCalDav() { ResourceCalDav::~ResourceCalDav() {
log("jobs termination"); log("jobs termination");
// This must save the users data before termination below to prevent data loss... if (mWriteRetryTimer != NULL) {
doSave(); 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) { while ((mWriter->running() == true) || (mWritingQueue.isEmpty() == false) || !mWritingQueueReady) {
readLockout = true;
sleep(1); sleep(1);
qApp->processEvents(QEventLoop::ExcludeUserInput); qApp->processEvents(QEventLoop::ExcludeUserInput);
} }
@ -122,6 +127,10 @@ ResourceCalDav::~ResourceCalDav() {
delete mPrefs; delete mPrefs;
} }
bool ResourceCalDav::isSaving() {
return (((mWriteRetryTimer != NULL) ? mWriteRetryTimer->isActive() : 0) || (mWriter->running() == true) || (mWritingQueue.isEmpty() == false) || !mWritingQueueReady);
}
/*========================================================================= /*=========================================================================
| GENERAL METHODS | GENERAL METHODS
========================================================================*/ ========================================================================*/
@ -129,7 +138,7 @@ ResourceCalDav::~ResourceCalDav() {
bool ResourceCalDav::doLoad() { bool ResourceCalDav::doLoad() {
bool syncCache = true; 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! 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 // modifies the calendar with clearChanges() or similar
// Before these calls are made any existing read (and maybe write) threads should be finished // 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)) { 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; return false;
} }

@ -69,6 +69,8 @@ public:
virtual void setReadOnly(bool v); virtual void setReadOnly(bool v);
bool isSaving();
protected slots: protected slots:
void loadFinished(); void loadFinished();
@ -211,6 +213,7 @@ private:
static const int DEFAULT_SAVE_POLICY; static const int DEFAULT_SAVE_POLICY;
bool readLockout; bool readLockout;
bool mAllWritesComplete;
// members: =============================================================== // members: ===============================================================
@ -226,6 +229,8 @@ private:
bool mWritingQueueReady; bool mWritingQueueReady;
QPtrQueue<WritingTask> mWritingQueue; QPtrQueue<WritingTask> mWritingQueue;
QTimer *mWriteRetryTimer;
}; };

@ -70,12 +70,15 @@ const int ResourceCardDav::DEFAULT_SAVE_INTERVAL = 10;
ResourceCardDav::ResourceCardDav( const KConfig *config ) : ResourceCardDav::ResourceCardDav( const KConfig *config ) :
ResourceCached(config) ResourceCached(config)
, mLock(true) , mLock(true)
, readLockout(false)
, mAllWritesComplete(false)
, mPrefs(NULL) , mPrefs(NULL)
, mLoader(NULL) , mLoader(NULL)
, mWriter(NULL) , mWriter(NULL)
, mProgress(NULL) , mProgress(NULL)
, mLoadingQueueReady(true) , mLoadingQueueReady(true)
, mWritingQueueReady(true) , mWritingQueueReady(true)
, mWriteRetryTimer(NULL)
{ {
log("ResourceCardDav(config)"); log("ResourceCardDav(config)");
init(); init();
@ -88,9 +91,12 @@ ResourceCardDav::ResourceCardDav( const KConfig *config ) :
ResourceCardDav::~ResourceCardDav() { ResourceCardDav::~ResourceCardDav() {
log("jobs termination"); log("jobs termination");
// This must save the users data before termination below to prevent data loss... if (mWriteRetryTimer != NULL) {
doSave(); 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) { while ((mWriter->running() == true) || (mWritingQueue.isEmpty() == false) || !mWritingQueueReady) {
readLockout = true;
sleep(1); sleep(1);
qApp->processEvents(QEventLoop::ExcludeUserInput); qApp->processEvents(QEventLoop::ExcludeUserInput);
} }
@ -121,6 +127,10 @@ ResourceCardDav::~ResourceCardDav() {
delete mPrefs; delete mPrefs;
} }
bool ResourceCardDav::isSaving() {
return (((mWriteRetryTimer != NULL) ? mWriteRetryTimer->isActive() : 0) || (mWriter->running() == true) || (mWritingQueue.isEmpty() == false) || !mWritingQueueReady);
}
/*========================================================================= /*=========================================================================
| GENERAL METHODS | GENERAL METHODS
========================================================================*/ ========================================================================*/
@ -128,7 +138,7 @@ ResourceCardDav::~ResourceCardDav() {
bool ResourceCardDav::load() { bool ResourceCardDav::load() {
bool syncCache = true; 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! return true; // Silently fail; the user has obviously not responded to a dialog and we don't need to pop up more of them!
} }
@ -361,7 +371,7 @@ void ResourceCardDav::loadFinished() {
data.replace('\r', '\n'); data.replace('\r', '\n');
log("trying to parse..."); log("trying to parse...");
//printf("PARSING:\n\r%s\n\r", data.ascii()); printf("PARSING:\n\r%s\n\r", data.ascii());
if (parseData(data)) { if (parseData(data)) {
// FIXME: The agenda view can crash when a change is // FIXME: The agenda view can crash when a change is
// made on a remote server and a reload is requested! // made on a remote server and a reload is requested!
@ -566,7 +576,11 @@ bool ResourceCardDav::startWriting(const QString& url) {
// modifies the calendar with clearChanges() or similar // modifies the calendar with clearChanges() or similar
// Before these calls are made any existing read (and maybe write) threads should be finished // 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)) { 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; return false;
} }

@ -71,6 +71,8 @@ public:
virtual void setReadOnly(bool v); virtual void setReadOnly(bool v);
bool isSaving();
protected slots: protected slots:
void loadFinished(); void loadFinished();
@ -190,6 +192,9 @@ private:
static const int DEFAULT_RELOAD_POLICY; static const int DEFAULT_RELOAD_POLICY;
static const int DEFAULT_SAVE_POLICY; static const int DEFAULT_SAVE_POLICY;
bool readLockout;
bool mAllWritesComplete;
// members: =============================================================== // members: ===============================================================
KABC::LockNull mLock; KABC::LockNull mLock;
@ -204,6 +209,8 @@ private:
bool mWritingQueueReady; bool mWritingQueueReady;
QPtrQueue<WritingTask> mWritingQueue; QPtrQueue<WritingTask> mWritingQueue;
QTimer *mWriteRetryTimer;
}; };

Loading…
Cancel
Save