File indexing completed on 2024-06-16 04:52:27
0001 /* 0002 Copyright (c) 2009 Grégory Oestreicher <greg@kamago.net> 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 "davitem.h" 0020 0021 #include "davurl.h" 0022 0023 using namespace KDAV2; 0024 0025 class DavItemPrivate 0026 { 0027 public: 0028 DavItemPrivate(DavItem *qPtr) : q(qPtr) {} 0029 0030 void fillFrom(const DavItemPrivate &other); 0031 0032 DavItem *q; 0033 0034 DavUrl mUrl; 0035 QString mContentType; 0036 QByteArray mData; 0037 QString mEtag; 0038 }; 0039 0040 void DavItemPrivate::fillFrom(const DavItemPrivate& other) 0041 { 0042 mUrl = other.mUrl; 0043 mContentType = other.mContentType; 0044 mData = other.mData; 0045 mEtag = other.mEtag; 0046 } 0047 0048 0049 DavItem::DavItem() 0050 : d(std::unique_ptr<DavItemPrivate>(new DavItemPrivate(this))) 0051 { 0052 } 0053 0054 DavItem::DavItem(const DavUrl &url, const QString &contentType, const QByteArray &data, const QString &etag) 0055 : d(std::unique_ptr<DavItemPrivate>(new DavItemPrivate(this))) 0056 { 0057 d->mUrl = url; 0058 d->mContentType = contentType; 0059 d->mData = data; 0060 d->mEtag = etag; 0061 } 0062 0063 DavItem::DavItem(const DavItem &other) 0064 : d(std::unique_ptr<DavItemPrivate>(new DavItemPrivate(this))) 0065 { 0066 d->fillFrom(*other.d.get()); 0067 } 0068 0069 DavItem &DavItem::operator=(const DavItem &other) 0070 { 0071 d->fillFrom(*other.d.get()); 0072 return *this; 0073 } 0074 0075 DavItem::~DavItem() 0076 { 0077 } 0078 0079 void DavItem::setUrl(const DavUrl &url) 0080 { 0081 d->mUrl = url; 0082 } 0083 0084 DavUrl DavItem::url() const 0085 { 0086 return d->mUrl; 0087 } 0088 0089 void DavItem::setContentType(const QString &contentType) 0090 { 0091 d->mContentType = contentType; 0092 } 0093 0094 QString DavItem::contentType() const 0095 { 0096 return d->mContentType; 0097 } 0098 0099 void DavItem::setData(const QByteArray &data) 0100 { 0101 d->mData = data; 0102 } 0103 0104 QByteArray DavItem::data() const 0105 { 0106 return d->mData; 0107 } 0108 0109 void DavItem::setEtag(const QString &etag) 0110 { 0111 d->mEtag = etag; 0112 } 0113 0114 QString DavItem::etag() const 0115 { 0116 return d->mEtag; 0117 } 0118 0119 QDataStream &KDAV2::operator<<(QDataStream &stream, const DavItem &item) 0120 { 0121 stream << item.url(); 0122 stream << item.contentType(); 0123 stream << item.data(); 0124 stream << item.etag(); 0125 0126 return stream; 0127 } 0128 0129 QDataStream &KDAV2::operator>>(QDataStream &stream, DavItem &item) 0130 { 0131 QString contentType, etag; 0132 DavUrl url; 0133 QByteArray data; 0134 0135 stream >> url; 0136 stream >> contentType; 0137 stream >> data; 0138 stream >> etag; 0139 0140 item = DavItem(url, contentType, data, etag); 0141 0142 return stream; 0143 }