File indexing completed on 2025-03-09 04:23:15

0001 #include <QDateTime>
0002 #include <QDebug>
0003 #include <QIODevice>
0004 #include <QString>
0005 #include <QTextStream>
0006 
0007 #include "../WebDAVClient.hpp"
0008 #include "../utils/WebDAVReply.hpp"
0009 #include "WebDAVItem.hpp"
0010 
0011 WebDAVItem::WebDAVItem(WebDAVClient *webdavClient, QString href, QString creationDate, QString lastModified, QString displayName, QString contentType, QString contentLength, bool isCollection)
0012 {
0013     this->webdavClient = webdavClient;
0014     this->href = href;
0015     this->creationDate = QDateTime::fromString(creationDate, Qt::DateFormat::ISODate);
0016     this->lastModified = lastModified;
0017     this->displayName = displayName;
0018     this->contentType = contentType;
0019     this->contentLength = contentLength.toInt();
0020     this->flagIsCollection = isCollection;
0021 }
0022 
0023 bool WebDAVItem::isCollection()
0024 {
0025     return this->flagIsCollection;
0026 }
0027 
0028 bool WebDAVItem::isFile()
0029 {
0030     return !this->flagIsCollection;
0031 }
0032 
0033 WebDAVReply *WebDAVItem::download()
0034 {
0035     return this->webdavClient->downloadFrom(this->href);
0036 }
0037 
0038 WebDAVReply *WebDAVItem::upload(QString filename, QIODevice *file)
0039 {
0040     return this->webdavClient->uploadTo(this->href, filename, file);
0041 }
0042 
0043 WebDAVReply *WebDAVItem::createDir(QString dirName)
0044 {
0045     return this->webdavClient->createDir(this->href, dirName);
0046 }
0047 
0048 WebDAVReply *WebDAVItem::copy(QString destination)
0049 {
0050     return this->webdavClient->copy(this->href, destination);
0051 }
0052 
0053 WebDAVReply *WebDAVItem::move(QString destination, bool overwrite)
0054 {
0055     return this->webdavClient->move(this->href, destination, overwrite);
0056 }
0057 
0058 WebDAVReply *WebDAVItem::remove()
0059 {
0060     return this->webdavClient->remove(this->href);
0061 }
0062 
0063 WebDAVReply *WebDAVItem::listDir()
0064 {
0065     return this->webdavClient->listDir(this->href);
0066 }
0067 
0068 QString WebDAVItem::toString()
0069 {
0070     QString s;
0071     QTextStream out(&s);
0072 
0073     out << "HREF            : " << this->href << "," << Qt::endl
0074     << "CREATION_DATE   : " << this->creationDate.toString() << "," << Qt::endl
0075     << "LAST_MODIFIED   : " << this->lastModified << "," << Qt::endl
0076     << "DISPLAY_NAME    : " << this->displayName << "," << Qt::endl
0077     << "CONTENT_TYPE    : " << this->contentType << "," << Qt::endl
0078     << "CONTENT_LENGTH  : " << this->contentLength << "," << Qt::endl
0079         << "IS_COLLECTION   : " << this->flagIsCollection;
0080 
0081     return s;
0082 }
0083 
0084 QString WebDAVItem::getHref()
0085 {
0086     return this->href;
0087 }
0088 
0089 QDateTime WebDAVItem::getCreationDate()
0090 {
0091     return this->creationDate;
0092 }
0093 
0094 QString WebDAVItem::getLastModified()
0095 {
0096     return this->lastModified;
0097 }
0098 
0099 QString WebDAVItem::getDisplayName()
0100 {
0101     return this->displayName;
0102 }
0103 
0104 QString WebDAVItem::getContentType()
0105 {
0106     return this->contentType;
0107 }
0108 
0109 int WebDAVItem::getContentLength()
0110 {
0111     return this->contentLength;
0112 }