You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
174 lines
5.0 KiB
174 lines
5.0 KiB
15 years ago
|
/*=========================================================================
|
||
|
| 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>
|
||
15 years ago
|
#include <klocale.h>
|
||
15 years ago
|
|
||
15 years ago
|
#include <tqmutex.h>
|
||
15 years ago
|
|
||
13 years ago
|
#define log(s) kdDebug() << s << '\n';
|
||
15 years ago
|
|
||
|
/*=========================================================================
|
||
|
| NAMESPACE
|
||
|
========================================================================*/
|
||
|
|
||
|
using namespace KCal;
|
||
|
|
||
|
/*=========================================================================
|
||
|
| STATIC
|
||
|
========================================================================*/
|
||
|
|
||
|
/*=========================================================================
|
||
|
| CONSTRUCTOR AND DESTRUCTOR
|
||
|
========================================================================*/
|
||
|
|
||
15 years ago
|
CalDavJob::CalDavJob(const TQString& url) {
|
||
15 years ago
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void CalDavJob::setErrorString(const TQString& err, const long number) {
|
||
15 years ago
|
mError = true;
|
||
|
mErrorString = err;
|
||
|
mErrorNumber = number;
|
||
|
}
|
||
|
|
||
14 years ago
|
void CalDavJob::setTasksErrorString(const TQString& err, const long number) {
|
||
|
mTasksError = true;
|
||
|
mTasksErrorString = err;
|
||
|
mTasksErrorNumber = number;
|
||
|
}
|
||
|
|
||
14 years ago
|
void CalDavJob::setJournalsErrorString(const TQString& err, const long number) {
|
||
|
mJournalsError = true;
|
||
|
mJournalsErrorString = err;
|
||
|
mJournalsErrorNumber = number;
|
||
|
}
|
||
|
|
||
15 years ago
|
void CalDavJob::processError(const caldav_error* err) {
|
||
15 years ago
|
TQString error_string;
|
||
15 years ago
|
|
||
|
long code = err->code;
|
||
|
|
||
|
if (-401 == code) { // unauthorized
|
||
|
error_string = i18n("Unauthorized. Username or password incorrect.");
|
||
|
} else if (-599 <= code && code <= -300) {
|
||
13 years ago
|
error_string = i18n("HTTP error %1. Please ensure that the URL is a valid CalDAV resource.").arg(-code);
|
||
15 years ago
|
} else {
|
||
|
error_string = err->str;
|
||
|
}
|
||
|
|
||
|
setErrorString(error_string, code);
|
||
|
}
|
||
|
|
||
14 years ago
|
void CalDavJob::processTasksError(const caldav_error* err) {
|
||
|
TQString error_string;
|
||
|
|
||
|
long code = err->code;
|
||
|
|
||
|
if (-401 == code) { // unauthorized
|
||
|
error_string = i18n("Unauthorized. Username or password incorrect.");
|
||
|
} else if (-599 <= code && code <= -300) {
|
||
13 years ago
|
error_string = i18n("HTTP error %1. Please ensure that the URL is a valid CalDAV resource.").arg(-code);
|
||
14 years ago
|
} else {
|
||
|
error_string = err->str;
|
||
|
}
|
||
|
|
||
|
setTasksErrorString(error_string, code);
|
||
|
}
|
||
|
|
||
14 years ago
|
void CalDavJob::processJournalsError(const caldav_error* err) {
|
||
|
TQString error_string;
|
||
|
|
||
|
long code = err->code;
|
||
|
|
||
|
if (-401 == code) { // unauthorized
|
||
|
error_string = i18n("Unauthorized. Username or password incorrect.");
|
||
|
} else if (-599 <= code && code <= -300) {
|
||
13 years ago
|
error_string = i18n("HTTP error %1. Please ensure that the URL is a valid CalDAV resource.").arg(-code);
|
||
14 years ago
|
} else {
|
||
|
error_string = err->str;
|
||
|
}
|
||
|
|
||
|
setJournalsErrorString(error_string, code);
|
||
|
}
|
||
|
|
||
15 years ago
|
|
||
|
void CalDavJob::run() {
|
||
|
log("cleaning job");
|
||
|
cleanJob();
|
||
|
|
||
|
int res = OK;
|
||
14 years ago
|
int tasksres = OK;
|
||
14 years ago
|
int journalsres = OK;
|
||
15 years ago
|
|
||
|
runtime_info* caldav_runtime = caldav_get_runtime_info();
|
||
|
|
||
|
#ifdef KCALDAV_DEBUG
|
||
|
log("setting debug caldav options");
|
||
|
enableCaldavDebug(caldav_runtime);
|
||
|
#endif // KCALDAV_DEBUG
|
||
|
|
||
14 years ago
|
log("running event job");
|
||
15 years ago
|
res = runJob(caldav_runtime);
|
||
|
|
||
|
if (OK != res) {
|
||
14 years ago
|
log("event job failed");
|
||
15 years ago
|
processError(caldav_runtime->error);
|
||
|
}
|
||
|
|
||
14 years ago
|
log("running tasks job");
|
||
|
tasksres = runTasksJob(caldav_runtime);
|
||
|
|
||
|
if (OK != tasksres) {
|
||
|
log("tasks job failed");
|
||
|
processTasksError(caldav_runtime->error);
|
||
|
}
|
||
|
|
||
14 years ago
|
log("running journals job");
|
||
|
journalsres = runJournalsJob(caldav_runtime);
|
||
|
|
||
|
if (OK != journalsres) {
|
||
|
log("journals job failed");
|
||
|
processJournalsError(caldav_runtime->error);
|
||
|
}
|
||
|
|
||
15 years ago
|
caldav_free_runtime_info(&caldav_runtime);
|
||
15 years ago
|
|
||
|
// Signal done
|
||
|
// 1000 is read, 1001 is write
|
||
13 years ago
|
if (type() == 0) TQApplication::postEvent ( parent(), new TQEvent( static_cast<TQEvent::Type>(1000) ) );
|
||
|
if (type() == 1) TQApplication::postEvent ( parent(), new TQEvent( static_cast<TQEvent::Type>(1001) ) );
|
||
15 years ago
|
}
|
||
|
|
||
|
// EOF ========================================================================
|