File indexing completed on 2024-04-21 03:53:53

0001 /*
0002     SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "davurl.h"
0008 
0009 
0010 using namespace KDAV;
0011 
0012 namespace KDAV
0013 {
0014 class DavUrlPrivate : public QSharedData
0015 {
0016 public:
0017     Protocol mProtocol = KDAV::CalDav;
0018     QUrl mUrl;
0019 };
0020 }
0021 
0022 DavUrl::DavUrl()
0023     : d(new DavUrlPrivate)
0024 {
0025 }
0026 
0027 DavUrl::DavUrl(const QUrl &url, Protocol protocol)
0028     : d(new DavUrlPrivate)
0029 {
0030     d->mUrl = url;
0031     d->mProtocol = protocol;
0032 }
0033 
0034 DavUrl::DavUrl(const DavUrl &) = default;
0035 DavUrl::DavUrl(DavUrl &&) = default;
0036 DavUrl::~DavUrl() = default;
0037 DavUrl &DavUrl::operator=(const DavUrl &) = default;
0038 DavUrl &DavUrl::operator=(DavUrl &&) = default;
0039 
0040 void DavUrl::setUrl(const QUrl &url)
0041 {
0042     d->mUrl = url;
0043 }
0044 
0045 QUrl DavUrl::url() const
0046 {
0047     return d->mUrl;
0048 }
0049 
0050 void DavUrl::setProtocol(Protocol protocol)
0051 {
0052     d->mProtocol = protocol;
0053 }
0054 
0055 Protocol DavUrl::protocol() const
0056 {
0057     return d->mProtocol;
0058 }
0059 
0060 QString DavUrl::toDisplayString() const
0061 {
0062     auto url = d->mUrl;
0063     url.setUserInfo(QString());
0064     return url.toDisplayString();
0065 }
0066 
0067 QDataStream &KDAV::operator<<(QDataStream &stream, const DavUrl &url)
0068 {
0069     stream << QString::number(url.protocol());
0070     stream << url.url();
0071 
0072     return stream;
0073 }
0074 
0075 QDataStream &KDAV::operator>>(QDataStream &stream, DavUrl &davUrl)
0076 {
0077     QUrl url;
0078     QString p;
0079 
0080     stream >> p;
0081     stream >> url;
0082 
0083     davUrl = DavUrl(url, static_cast<Protocol>(p.toInt()));
0084 
0085     return stream;
0086 }