diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-09-01 00:37:02 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-09-01 00:37:02 +0000 |
commit | cc29364f06178f8f6b457384f2ec37a042bd9d43 (patch) | |
tree | 7c77a3184c698bbf9d98cef09fb1ba8124daceba /kresources/caldav/resource.cpp | |
parent | 4f6c584bacc8c3c694228f36ada3de77a76614a6 (diff) | |
download | tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.tar.gz tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.zip |
* Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch
* Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed
* Added journal read support to the CalDAV resource
* Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kresources/caldav/resource.cpp')
-rw-r--r-- | kresources/caldav/resource.cpp | 142 |
1 files changed, 135 insertions, 7 deletions
diff --git a/kresources/caldav/resource.cpp b/kresources/caldav/resource.cpp index c0bbf1159..003633a40 100644 --- a/kresources/caldav/resource.cpp +++ b/kresources/caldav/resource.cpp @@ -160,7 +160,7 @@ bool ResourceCalDav::doLoad() { emit resourceLoaded(this); log("starting download job"); - startLoading(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl()); + startLoading(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl(), mPrefs->getFullJournalsUrl()); return true; } @@ -189,7 +189,7 @@ bool ResourceCalDav::doSave() { } log("start writing job"); - if (startWriting(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl()) == true) { + if (startWriting(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl(), mPrefs->getFullJournalsUrl()) == true) { log("clearing changes"); // FIXME: Calling clearChanges() here is not the ideal way since the // upload might fail, but there is no other place to call it... @@ -334,6 +334,7 @@ void ResourceCalDav::loadingQueuePop() { mLoader->setUrl(t->url); mLoader->setTasksUrl(t->tasksUrl); + mLoader->setJournalsUrl(t->journalsUrl); mLoader->setParent(this); mLoader->setType(0); @@ -353,10 +354,11 @@ void ResourceCalDav::loadingQueuePop() { delete t; } -void ResourceCalDav::startLoading(const TQString& url, const TQString& tasksUrl) { +void ResourceCalDav::startLoading(const TQString& url, const TQString& tasksUrl, const TQString& journalsUrl) { LoadingTask *t = new LoadingTask; t->url = url; t->tasksUrl = tasksUrl; + t->journalsUrl = journalsUrl; loadingQueuePush(t); } @@ -381,7 +383,7 @@ void ResourceCalDav::loadFinished() { else { // Set new password and try again mPrefs->setPassword(TQString(newpass)); - startLoading(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl()); + startLoading(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl(), mPrefs->getFullJournalsUrl()); } } else { @@ -429,7 +431,7 @@ void ResourceCalDav::loadFinished() { // else { // // Set new password and try again // mPrefs->setPassword(TQString(newpass)); -// startLoading(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl()); +// startLoading(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl(), mPrefs->getFullJournalsUrl()); // } } else { @@ -466,6 +468,54 @@ void ResourceCalDav::loadFinished() { } } + if (loader->journalsError()) { + if (loader->journalsErrorNumber() == -401) { + if (NULL != mPrefs) { +// TQCString newpass; +// if (KPasswordDialog::getPassword (newpass, TQString("<b>") + i18n("Remote authorization required") + TQString("</b><p>") + i18n("Please input the password for") + TQString(" ") + mPrefs->getusername(), NULL) != 1) { +// log("load error: " + loader->journalsErrorString() ); +// loadError(TQString("[%1] ").arg(abs(loader->journalsErrorNumber())) + loader->journalsErrorString()); +// } +// else { +// // Set new password and try again +// mPrefs->setPassword(TQString(newpass)); +// startLoading(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl(), mPrefs->getFullJournalsUrl()); +// } + } + else { + log("load error: " + loader->journalsErrorString() ); + loadError(TQString("[%1] ").arg(abs(loader->journalsErrorNumber())) + loader->journalsErrorString()); + } + } + else { + log("load error: " + loader->journalsErrorString() ); + loadError(TQString("[%1] ").arg(abs(loader->journalsErrorNumber())) + loader->journalsErrorString()); + } + } else { + log("successful journals load"); + TQString journalsData = loader->journalsData(); + + if (!journalsData.isNull() && !journalsData.isEmpty()) { + // TODO: I don't know why, but some schedules on http://caldav-test.ioda.net/ (I used it for testing) + // have some lines separated by single \r rather than \n or \r\n. + // ICalFormat fails to parse that. + journalsData.replace("\r\n", "\n"); // to avoid \r\n becomes \n\n after the next line + journalsData.replace('\r', '\n'); + + log("trying to parse..."); + if (parseJournalsData(journalsData)) { + // FIXME: The agenda view can crash when a change is + // made on a remote server and a reload is requested! + log("... parsing is ok"); + log("clearing changes"); + enableChangeNotification(); + clearChanges(); + emit resourceChanged(this); + emit resourceLoaded(this); + } + } + } + // Loading queue and mLoadingQueueReady flag are not shared resources, i.e. only one thread has an access to them. // That's why no mutexes are required. mLoader->terminate(); @@ -602,6 +652,63 @@ bool ResourceCalDav::parseTasksData(const TQString& data) { return ret; } +bool ResourceCalDav::parseJournalsData(const TQString& data) { + log("parseJournalsData()"); + + bool ret = true; + + // check if the data is OK + // May be it's not efficient (parsing is done twice), but it should be safe + if (!checkData(data)) { + loadError(i18n("Parsing calendar data failed.")); + return false; + } + + log("clearing cache"); + clearJournalsCache(); + + disableChangeNotification(); + + log("actually parsing the data"); + + ICalFormat ical; + if ( !ical.fromString( &mCalendar, data ) ) { + // this should never happen, but... + ret = false; + } + + // debug code here ------------------------------------------------------- +#ifdef KCALDAV_DEBUG + const TQString fout_path = "/tmp/kcaldav_download_" + identifier() + ".tmp"; + + TQFile fout(fout_path); + if (fout.open(IO_WriteOnly | IO_Append)) { + TQTextStream sout(&fout); + sout << "---------- " << resourceName() << ": --------------------------------\n"; + sout << data << "\n"; + fout.close(); + } else { + loadError(i18n("can't open file")); + } +#endif // KCALDAV_DEBUG + // end of debug code ---------------------------------------------------- + + enableChangeNotification(); + + if (ret) { + log("parsing is ok"); + //if ( !noReadOnlyOnLoad() && readOnly() ) { + if ( readOnly() ) { + log("ensuring read only flag honored"); + ensureReadOnlyFlagHonored(); + } + log("saving to cache"); + saveCache(); + } + + return ret; +} + /*========================================================================= | WRITING METHODS ========================================================================*/ @@ -662,6 +769,7 @@ void ResourceCalDav::writingQueuePop() { mWriter->setUrl(t->url); mWriter->setTasksUrl(t->tasksUrl); + mWriter->setJournalsUrl(t->journalsUrl); mWriter->setParent(this); mWriter->setType(1); @@ -689,6 +797,10 @@ void ResourceCalDav::writingQueuePop() { mWriter->setChangedTasksObjects(t->tasksChanged); mWriter->setDeletedTasksObjects(t->tasksDeleted); + mWriter->setAddedJournalsObjects(t->journalsAdded); + mWriter->setChangedJournalsObjects(t->journalsChanged); + mWriter->setDeletedJournalsObjects(t->journalsDeleted); + mWritingQueueReady = false; log("starting actual write job"); @@ -719,7 +831,7 @@ void ResourceCalDav::releaseReadLockout() { readLockout = false; } -bool ResourceCalDav::startWriting(const TQString& url, const TQString& tasksUrl) { +bool ResourceCalDav::startWriting(const TQString& url, const TQString& tasksUrl, const TQString& journalsUrl) { log("startWriting: url = " + url); // WARNING: This will segfault if a separate read or write thread @@ -757,16 +869,22 @@ bool ResourceCalDav::startWriting(const TQString& url, const TQString& tasksUrl) t->url = url; t->tasksUrl = tasksUrl; + t->journalsUrl = journalsUrl; t->added = ""; t->changed = ""; t->deleted = ""; t->tasksAdded = ""; t->tasksChanged = ""; t->tasksDeleted = ""; + t->journalsAdded = ""; + t->journalsChanged = ""; + t->journalsDeleted = ""; if (getICalString(currentIncidence).contains("BEGIN:VEVENT") > 0) t->added = getICalString(currentIncidence); else if (getICalString(currentIncidence).contains("BEGIN:VTODO") > 0) t->tasksAdded = getICalString(currentIncidence); + else if (getICalString(currentIncidence).contains("BEGIN:VJOURNAL") > 0) + t->journalsAdded = getICalString(currentIncidence); writingQueuePush(t); } @@ -785,11 +903,16 @@ bool ResourceCalDav::startWriting(const TQString& url, const TQString& tasksUrl) t->tasksAdded = ""; t->tasksChanged = ""; t->tasksDeleted = ""; + t->journalsAdded = ""; + t->journalsChanged = ""; + t->journalsDeleted = ""; if (getICalString(currentIncidence).contains("BEGIN:VEVENT") > 0) t->changed = getICalString(currentIncidence); else if (getICalString(currentIncidence).contains("BEGIN:VTODO") > 0) t->tasksChanged = getICalString(currentIncidence); + else if (getICalString(currentIncidence).contains("BEGIN:VJOURNAL") > 0) + t->journalsChanged = getICalString(currentIncidence); writingQueuePush(t); } @@ -808,11 +931,16 @@ bool ResourceCalDav::startWriting(const TQString& url, const TQString& tasksUrl) t->tasksAdded = ""; t->tasksChanged = ""; t->tasksDeleted = ""; + t->journalsAdded = ""; + t->journalsChanged = ""; + t->journalsDeleted = ""; if (getICalString(currentIncidence).contains("BEGIN:VEVENT") > 0) t->deleted = getICalString(currentIncidence); else if (getICalString(currentIncidence).contains("BEGIN:VTODO") > 0) t->tasksDeleted = getICalString(currentIncidence); + else if (getICalString(currentIncidence).contains("BEGIN:VJOURNALS") > 0) + t->journalsDeleted = getICalString(currentIncidence); writingQueuePush(t); } @@ -839,7 +967,7 @@ void ResourceCalDav::writingFinished() { else { // Set new password and try again mPrefs->setPassword(TQString(newpass)); - startWriting(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl()); + startWriting(mPrefs->getFullUrl(), mPrefs->getFullTasksUrl(), mPrefs->getFullJournalsUrl()); } } else { |