summaryrefslogtreecommitdiffstats
path: root/kresources/carddav/job.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-31 07:49:08 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-31 07:49:08 +0000
commit7ef3b0e2a5e5bc9bf928e989e4f66932be096824 (patch)
treed1b924b843f78b9d9de26becb36bb8e12f7fef44 /kresources/carddav/job.cpp
parentf4a40d0495ff26b8767cf321fa8039e5ac633c12 (diff)
downloadtdepim-7ef3b0e2a5e5bc9bf928e989e4f66932be096824.tar.gz
tdepim-7ef3b0e2a5e5bc9bf928e989e4f66932be096824.zip
Added new carddav resource for kaddressbook
Lots of bugfixes for korganizer caldav resource git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1132701 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kresources/carddav/job.cpp')
-rw-r--r--kresources/carddav/job.cpp110
1 files changed, 110 insertions, 0 deletions
diff --git a/kresources/carddav/job.cpp b/kresources/carddav/job.cpp
new file mode 100644
index 00000000..e82645f2
--- /dev/null
+++ b/kresources/carddav/job.cpp
@@ -0,0 +1,110 @@
+/*=========================================================================
+| KCardDAV
+|--------------------------------------------------------------------------
+| (c) 2010 Timothy Pearson
+|
+| This project is released under the GNU General Public License.
+| Please see the file COPYING for more details.
+|--------------------------------------------------------------------------
+| Job class for accessing remote address books.
+ ========================================================================*/
+
+/*=========================================================================
+| INCLUDES
+ ========================================================================*/
+
+#include "job.h"
+#include <kdebug.h>
+#include <klocale.h>
+
+#include <qmutex.h>
+
+#define log(s) kdDebug() << s;
+
+/*=========================================================================
+| NAMESPACE
+ ========================================================================*/
+
+using namespace KABC;
+
+/*=========================================================================
+| STATIC
+ ========================================================================*/
+
+/*=========================================================================
+| CONSTRUCTOR AND DESTRUCTOR
+ ========================================================================*/
+
+CardDavJob::CardDavJob(const QString& url) {
+ cleanJob();
+ setUrl(url);
+}
+
+CardDavJob::~CardDavJob() {
+}
+
+
+/*=========================================================================
+| METHODS
+ ========================================================================*/
+
+void CardDavJob::enableCarddavDebug(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 CardDavJob::setErrorString(const QString& err, const long number) {
+ mError = true;
+ mErrorString = err;
+ mErrorNumber = number;
+}
+
+void CardDavJob::processError(const carddav_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 CardDAV resource.").arg(-code);
+ } else {
+ error_string = err->str;
+ }
+
+ setErrorString(error_string, code);
+}
+
+
+void CardDavJob::run() {
+ log("cleaning job");
+ cleanJob();
+
+ int res = OK;
+
+ runtime_info* carddav_runtime = carddav_get_runtime_info();
+
+#ifdef KABCDAV_DEBUG
+ log("setting debug carddav options");
+ enableCarddavDebug(carddav_runtime);
+#endif // KABCDAV_DEBUG
+
+ log("running job");
+ res = runJob(carddav_runtime);
+
+ if (OK != res) {
+ log("job failed");
+ processError(carddav_runtime->error);
+ }
+
+ carddav_free_runtime_info(&carddav_runtime);
+
+ // Signal done
+ // 1000 is read, 1001 is write
+ if (type() == 0) QApplication::postEvent ( parent(), new QEvent( static_cast<QEvent::Type>(1000) ) );
+ if (type() == 1) QApplication::postEvent ( parent(), new QEvent( static_cast<QEvent::Type>(1001) ) );
+}
+
+// EOF ========================================================================