1 | /* |
2 | SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "davmanager_p.h" |
8 | |
9 | #include "protocols/caldavprotocol_p.h" |
10 | #include "protocols/carddavprotocol_p.h" |
11 | #include "protocols/groupdavprotocol_p.h" |
12 | |
13 | #include <KIO/DavJob> |
14 | |
15 | #include "libkdav_debug.h" |
16 | |
17 | #include <QUrl> |
18 | |
19 | using namespace KDAV; |
20 | |
21 | DavManager::DavManager() = default; |
22 | DavManager::~DavManager() = default; |
23 | |
24 | DavManager *DavManager::self() |
25 | { |
26 | static DavManager sSelf; |
27 | return &sSelf; |
28 | } |
29 | |
30 | KIO::DavJob *DavManager::createPropFindJob(const QUrl &url, const QString &document, const QString &depth) const |
31 | { |
32 | KIO::DavJob *job = KIO::davPropFind(url, properties: document, depth, flags: KIO::HideProgressInfo | KIO::DefaultFlags); |
33 | |
34 | job->addMetaData(QStringLiteral("cookies" ), QStringLiteral("none" )); |
35 | job->addMetaData(QStringLiteral("no-auth-prompt" ), QStringLiteral("true" )); |
36 | job->setProperty(name: "davDepth" , value: QVariant::fromValue(value: depth)); |
37 | |
38 | return job; |
39 | } |
40 | |
41 | KIO::DavJob *DavManager::createReportJob(const QUrl &url, const QString &document, const QString &depth) const |
42 | { |
43 | KIO::DavJob *job = KIO::davReport(url, report: document, depth, flags: KIO::HideProgressInfo | KIO::DefaultFlags); |
44 | |
45 | job->addMetaData(QStringLiteral("cookies" ), QStringLiteral("none" )); |
46 | job->addMetaData(QStringLiteral("no-auth-prompt" ), QStringLiteral("true" )); |
47 | job->setProperty(name: "davDepth" , value: QVariant::fromValue(value: depth)); |
48 | |
49 | return job; |
50 | } |
51 | |
52 | KIO::DavJob *DavManager::createPropPatchJob(const QUrl &url, const QString &document) const |
53 | { |
54 | KIO::DavJob *job = KIO::davPropPatch(url, properties: document, flags: KIO::HideProgressInfo | KIO::DefaultFlags); |
55 | const QString = QStringLiteral("Content-Type: text/xml" ); |
56 | job->addMetaData(QStringLiteral("customHTTPHeader" ), value: header); |
57 | job->addMetaData(QStringLiteral("cookies" ), QStringLiteral("none" )); |
58 | job->addMetaData(QStringLiteral("no-auth-prompt" ), QStringLiteral("true" )); |
59 | return job; |
60 | } |
61 | |
62 | const DavProtocolBase *DavManager::davProtocol(Protocol protocol) |
63 | { |
64 | const auto d = DavManager::self(); |
65 | if (!d->mProtocols[protocol]) { |
66 | switch (protocol) { |
67 | case KDAV::CalDav: |
68 | d->mProtocols[KDAV::CalDav].reset(p: new CaldavProtocol()); |
69 | break; |
70 | case KDAV::CardDav: |
71 | d->mProtocols[KDAV::CardDav].reset(p: new CarddavProtocol()); |
72 | break; |
73 | case KDAV::GroupDav: |
74 | d->mProtocols[KDAV::GroupDav].reset(p: new GroupdavProtocol()); |
75 | break; |
76 | default: |
77 | qCCritical(KDAV_LOG) << "Unknown protocol: " << static_cast<int>(protocol); |
78 | return nullptr; |
79 | } |
80 | } |
81 | |
82 | return d->mProtocols[protocol].get(); |
83 | } |
84 | |