summaryrefslogtreecommitdiffstats
path: root/kresources/caldav/job.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-24 17:21:58 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-24 17:21:58 +0000
commita71c4476a79950040c9007f84af25cef4e28b351 (patch)
tree20d54bfeb827604e6b1c4ca01e9702346ddcc068 /kresources/caldav/job.cpp
parent45c9a75f1220817f57304df51e018f8cc66aaea4 (diff)
downloadtdepim-a71c4476a79950040c9007f84af25cef4e28b351.tar.gz
tdepim-a71c4476a79950040c9007f84af25cef4e28b351.zip
Initial CalDAV support
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1130194 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kresources/caldav/job.cpp')
-rw-r--r--kresources/caldav/job.cpp105
1 files changed, 105 insertions, 0 deletions
diff --git a/kresources/caldav/job.cpp b/kresources/caldav/job.cpp
new file mode 100644
index 000000000..f9fbb94c1
--- /dev/null
+++ b/kresources/caldav/job.cpp
@@ -0,0 +1,105 @@
+/*=========================================================================
+| KCalDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+| (c) 2009 Kumaran Santhanam (initial KDE4 version)
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Job class for accessing remote calendars.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "job.h"
+#include <kdebug.h>
+
+#include <qmutex.h>
+
+#define log(s) kdDebug() << s;
+
+/*=========================================================================
+| NAMESPACE
+ ========================================================================*/
+
+using namespace KCal;
+
+/*=========================================================================
+| STATIC
+ ========================================================================*/
+
+/*=========================================================================
+| CONSTRUCTOR AND DESTRUCTOR
+ ========================================================================*/
+
+CalDavJob::CalDavJob(const QString& url) {
+ cleanJob();
+ setUrl(url);
+}
+
+CalDavJob::~CalDavJob() {
+}
+
+
+/*=========================================================================
+| METHODS
+ ========================================================================*/
+
+void CalDavJob::enableCaldavDebug(runtime_info* rt) {
+ if (rt && rt->options) {
+ rt->options->debug = 0; // if debug = 1, it causes major CPU overhead
+ rt->options->verify_ssl_certificate = FALSE;
+ }
+}
+
+void CalDavJob::setErrorString(const QString& err, const long number) {
+ mError = true;
+ mErrorString = err;
+ mErrorNumber = number;
+}
+
+void CalDavJob::processError(const caldav_error* err) {
+ QString error_string;
+
+ long code = err->code;
+
+ if (-401 == code) { // unauthorized
+ error_string = i18n("Unauthorized. Username or password incorrect.");
+ } else if (-599 <= code && code <= -300) {
+ error_string = i18n("HTTP error %1. Maybe, URL is not a CalDAV resource.").arg(-code);
+ } else {
+ error_string = err->str;
+ }
+
+ setErrorString(error_string, code);
+}
+
+
+void CalDavJob::run() {
+ log("cleaning job");
+ cleanJob();
+
+ int res = OK;
+
+ runtime_info* caldav_runtime = caldav_get_runtime_info();
+
+#ifdef KCALDAV_DEBUG
+ log("setting debug caldav options");
+ enableCaldavDebug(caldav_runtime);
+#endif // KCALDAV_DEBUG
+
+ log("running job");
+ res = runJob(caldav_runtime);
+
+ if (OK != res) {
+ log("job failed");
+ processError(caldav_runtime->error);
+ }
+
+ caldav_free_runtime_info(&caldav_runtime);
+}
+
+// EOF ========================================================================