1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "davurl.h" |
8 | |
9 | |
10 | using namespace KDAV; |
11 | |
12 | namespace KDAV |
13 | { |
14 | class DavUrlPrivate : public QSharedData |
15 | { |
16 | public: |
17 | Protocol mProtocol = KDAV::CalDav; |
18 | QUrl mUrl; |
19 | }; |
20 | } |
21 | |
22 | DavUrl::DavUrl() |
23 | : d(new DavUrlPrivate) |
24 | { |
25 | } |
26 | |
27 | DavUrl::DavUrl(const QUrl &url, Protocol protocol) |
28 | : d(new DavUrlPrivate) |
29 | { |
30 | d->mUrl = url; |
31 | d->mProtocol = protocol; |
32 | } |
33 | |
34 | DavUrl::DavUrl(const DavUrl &) = default; |
35 | DavUrl::DavUrl(DavUrl &&) = default; |
36 | DavUrl::~DavUrl() = default; |
37 | DavUrl &DavUrl::operator=(const DavUrl &) = default; |
38 | DavUrl &DavUrl::operator=(DavUrl &&) = default; |
39 | |
40 | void DavUrl::setUrl(const QUrl &url) |
41 | { |
42 | d->mUrl = url; |
43 | } |
44 | |
45 | QUrl DavUrl::url() const |
46 | { |
47 | return d->mUrl; |
48 | } |
49 | |
50 | void DavUrl::setProtocol(Protocol protocol) |
51 | { |
52 | d->mProtocol = protocol; |
53 | } |
54 | |
55 | Protocol DavUrl::protocol() const |
56 | { |
57 | return d->mProtocol; |
58 | } |
59 | |
60 | QString DavUrl::toDisplayString() const |
61 | { |
62 | auto url = d->mUrl; |
63 | url.setUserInfo(userInfo: QString()); |
64 | return url.toDisplayString(); |
65 | } |
66 | |
67 | QDataStream &KDAV::operator<<(QDataStream &stream, const DavUrl &url) |
68 | { |
69 | stream << QString::number(url.protocol()); |
70 | stream << url.url(); |
71 | |
72 | return stream; |
73 | } |
74 | |
75 | QDataStream &KDAV::operator>>(QDataStream &stream, DavUrl &davUrl) |
76 | { |
77 | QUrl url; |
78 | QString p; |
79 | |
80 | stream >> p; |
81 | stream >> url; |
82 | |
83 | davUrl = DavUrl(url, static_cast<Protocol>(p.toInt())); |
84 | |
85 | return stream; |
86 | } |
87 |