summaryrefslogtreecommitdiffstats
path: root/examples/davresource/davresource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/davresource/davresource.cpp')
-rw-r--r--examples/davresource/davresource.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/examples/davresource/davresource.cpp b/examples/davresource/davresource.cpp
index 22c502f..fa5e612 100644
--- a/examples/davresource/davresource.cpp
+++ b/examples/davresource/davresource.cpp
@@ -132,8 +132,8 @@ public:
132 KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE 132 KAsync::Job<void> synchronizeWithSource(const Sink::QueryBase &query) Q_DECL_OVERRIDE
133 { 133 {
134 if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Addressbook>()) { 134 if (query.type() == ApplicationDomain::getTypeName<ApplicationDomain::Addressbook>()) {
135 SinkLogCtx(mLogCtx) << "Synchronizing addressbooks:" << mResourceUrl.url(); 135 SinkLogCtx(mLogCtx) << "Synchronizing addressbooks:" << resourceUrl().url();
136 auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(mResourceUrl); 136 auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(resourceUrl());
137 auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] (const KAsync::Error &error) { 137 auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] (const KAsync::Error &error) {
138 if (error) { 138 if (error) {
139 SinkWarningCtx(mLogCtx) << "Failed to synchronize addressbooks." << collectionsFetchJob->errorString(); 139 SinkWarningCtx(mLogCtx) << "Failed to synchronize addressbooks." << collectionsFetchJob->errorString();
@@ -147,7 +147,7 @@ public:
147 auto ridList = QSharedPointer<QByteArrayList>::create(); 147 auto ridList = QSharedPointer<QByteArrayList>::create();
148 auto total = QSharedPointer<int>::create(0); 148 auto total = QSharedPointer<int>::create(0);
149 auto progress = QSharedPointer<int>::create(0); 149 auto progress = QSharedPointer<int>::create(0);
150 auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(mResourceUrl); 150 auto collectionsFetchJob = new KDAV2::DavCollectionsFetchJob(resourceUrl());
151 auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] { 151 auto job = runJob(collectionsFetchJob).then([this, collectionsFetchJob] {
152 synchronizeAddressbooks(collectionsFetchJob ->collections()); 152 synchronizeAddressbooks(collectionsFetchJob ->collections());
153 return collectionsFetchJob->collections(); 153 return collectionsFetchJob->collections();
@@ -233,8 +233,20 @@ KAsync::Job<QByteArray> replay(const ApplicationDomain::Contact &contact, Sink::
233 return KAsync::null<QByteArray>(); 233 return KAsync::null<QByteArray>();
234 } 234 }
235 235
236 KDAV2::DavUrl resourceUrl() const
237 {
238 if (secret().isEmpty()) {
239 return {};
240 }
241 auto resourceUrl = mServer;
242 resourceUrl.setUserName(mUsername);
243 resourceUrl.setPassword(secret());
244 return KDAV2::DavUrl{resourceUrl, KDAV2::CardDav};
245 }
246
236public: 247public:
237 KDAV2::DavUrl mResourceUrl; 248 QUrl mServer;
249 QString mUsername;
238}; 250};
239 251
240 252
@@ -242,14 +254,12 @@ DavResource::DavResource(const Sink::ResourceContext &resourceContext)
242 : Sink::GenericResource(resourceContext) 254 : Sink::GenericResource(resourceContext)
243{ 255{
244 auto config = ResourceConfig::getConfiguration(resourceContext.instanceId()); 256 auto config = ResourceConfig::getConfiguration(resourceContext.instanceId());
245 auto resourceUrl = QUrl::fromUserInput(config.value("server").toString()); 257 auto server = QUrl::fromUserInput(config.value("server").toString());
246 resourceUrl.setUserName(config.value("username").toString()); 258 auto username = config.value("username").toString();
247 resourceUrl.setPassword(config.value("password").toString());
248
249 mResourceUrl = KDAV2::DavUrl(resourceUrl, KDAV2::CardDav);
250 259
251 auto synchronizer = QSharedPointer<ContactSynchronizer>::create(resourceContext); 260 auto synchronizer = QSharedPointer<ContactSynchronizer>::create(resourceContext);
252 synchronizer->mResourceUrl = mResourceUrl; 261 synchronizer->mServer = server;
262 synchronizer->mUsername = username;
253 setupSynchronizer(synchronizer); 263 setupSynchronizer(synchronizer);
254 264
255 setupPreprocessors(ENTITY_TYPE_CONTACT, QVector<Sink::Preprocessor*>() << new ContactPropertyExtractor); 265 setupPreprocessors(ENTITY_TYPE_CONTACT, QVector<Sink::Preprocessor*>() << new ContactPropertyExtractor);