summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/davresource/davresource.cpp21
1 files changed, 19 insertions, 2 deletions
diff --git a/examples/davresource/davresource.cpp b/examples/davresource/davresource.cpp
index fa5e612..c8fd097 100644
--- a/examples/davresource/davresource.cpp
+++ b/examples/davresource/davresource.cpp
@@ -31,12 +31,14 @@
31 31
32#include "contactpreprocessor.h" 32#include "contactpreprocessor.h"
33 33
34#include <QNetworkReply>
34#include <KDAV2/DavCollection> 35#include <KDAV2/DavCollection>
35#include <KDAV2/DavCollectionsFetchJob> 36#include <KDAV2/DavCollectionsFetchJob>
36#include <KDAV2/DavItem> 37#include <KDAV2/DavItem>
37#include <KDAV2/DavItemsListJob> 38#include <KDAV2/DavItemsListJob>
38#include <KDAV2/DavItemFetchJob> 39#include <KDAV2/DavItemFetchJob>
39#include <KDAV2/EtagCache> 40#include <KDAV2/EtagCache>
41#include <KDAV2/DavJobBase>
40 42
41//This is the resources entity type, and not the domain type 43//This is the resources entity type, and not the domain type
42#define ENTITY_TYPE_CONTACT "contact" 44#define ENTITY_TYPE_CONTACT "contact"
@@ -44,14 +46,29 @@
44 46
45using namespace Sink; 47using namespace Sink;
46 48
49static int translateDavError(KJob *job)
50{
51 const int error = job->error();
52 const int responseCode = static_cast<KDAV2::DavJobBase*>(job)->latestResponseCode();
53
54 switch (responseCode) {
55 case QNetworkReply::HostNotFoundError:
56 return ApplicationDomain::NoServerError;
57 //Since we don't login we will just not have the necessary permissions ot view the object
58 case QNetworkReply::OperationCanceledError:
59 return ApplicationDomain::LoginError;
60 }
61 return ApplicationDomain::UnknownError;
62}
63
47static KAsync::Job<void> runJob(KJob *job) 64static KAsync::Job<void> runJob(KJob *job)
48{ 65{
49 return KAsync::start<void>([job](KAsync::Future<void> &future) { 66 return KAsync::start<void>([job](KAsync::Future<void> &future) {
50 QObject::connect(job, &KJob::result, [&future](KJob *job) { 67 QObject::connect(job, &KJob::result, [&future](KJob *job) {
51 SinkTrace() << "Job done: " << job->metaObject()->className(); 68 SinkTrace() << "Job done: " << job->metaObject()->className();
52 if (job->error()) { 69 if (job->error()) {
53 SinkWarning() << "Job failed: " << job->errorString(); 70 SinkWarning() << "Job failed: " << job->errorString() << job->metaObject()->className() << job->error() << static_cast<KDAV2::DavJobBase*>(job)->latestResponseCode();
54 future.setError(job->error(), job->errorString()); 71 future.setError(translateDavError(job), job->errorString());
55 } else { 72 } else {
56 future.setFinished(); 73 future.setFinished();
57 } 74 }