File indexing completed on 2024-11-17 04:44:02

0001 /*
0002     Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify
0005     it under the terms of the GNU General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or
0007     (at your option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program; if not, write to the Free Software
0016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #include "davurl.h"
0020 
0021 #include "enums.h"
0022 #include <QDebug>
0023 
0024 using namespace KDAV2;
0025 
0026 DavUrl::DavUrl()
0027     : mProtocol(KDAV2::CalDav)
0028 {
0029 }
0030 
0031 DavUrl::DavUrl(const QUrl &url, Protocol protocol)
0032     : mUrl(url), mProtocol(protocol)
0033 {
0034 }
0035 
0036 void DavUrl::setUrl(const QUrl &url)
0037 {
0038     mUrl = url;
0039 }
0040 
0041 QUrl DavUrl::url() const
0042 {
0043     return mUrl;
0044 }
0045 
0046 void DavUrl::setProtocol(Protocol protocol)
0047 {
0048     mProtocol = protocol;
0049 }
0050 
0051 Protocol DavUrl::protocol() const
0052 {
0053     return mProtocol;
0054 }
0055 
0056 QString DavUrl::toDisplayString() const
0057 {
0058     auto url = mUrl;
0059     url.setUserInfo(QString());
0060     return url.toDisplayString();
0061 }
0062 
0063 QDataStream &KDAV2::operator<<(QDataStream &stream, const DavUrl &url)
0064 {
0065     stream << QString::number(url.protocol());
0066     stream << url.url();
0067 
0068     return stream;
0069 }
0070 
0071 QDataStream &KDAV2::operator>>(QDataStream &stream, DavUrl &davUrl)
0072 {
0073     QUrl url;
0074     QString p;
0075 
0076     stream >> p;
0077     stream >> url;
0078 
0079     davUrl = DavUrl(url, (Protocol) p.toInt());
0080 
0081     return stream;
0082 }
0083 
0084 QDebug &KDAV2::operator<<(QDebug &debug, const DavUrl &url)
0085 {
0086     debug << url.toDisplayString();
0087     return debug;
0088 }