MauiKit File Browsing

XMLHelper.cpp
1#include <QByteArray>
2#include <QDebug>
3#include <QList>
4#include <QtXml/QDomDocument>
5
6#include "../dto/WebDAVItem.hpp"
7#include "XMLHelper.hpp"
8
9QList<WebDAVItem> XMLHelper::parseListDirResponse(WebDAVClient *webdavClient, QByteArray xml)
10{
12 QString webdavNS = QStringLiteral("DAV:");
13 QDomDocument doc;
14 doc.setContent(xml, true);
15
16 QDomNodeList responses = doc.elementsByTagNameNS(webdavNS, QStringLiteral("response"));
17
18 for (int i = 0; i < responses.length(); i++) {
19 QDomElement response = responses.at(i).toElement();
20
21 QString href = response.elementsByTagNameNS(webdavNS, QStringLiteral("href")).at(0).toElement().text();
22 QString creationDate = response.elementsByTagNameNS(webdavNS, QStringLiteral("creationdate")).at(0).toElement().text();
23 QString lastModified = response.elementsByTagNameNS(webdavNS, QStringLiteral("getlastmodified")).at(0).toElement().text();
24 QString displayName = response.elementsByTagNameNS(webdavNS, QStringLiteral("displayname")).at(0).toElement().text();
25 QString contentType = response.elementsByTagNameNS(webdavNS, QStringLiteral("getcontenttype")).at(0).toElement().text();
26 QString contentLength = response.elementsByTagNameNS(webdavNS, QStringLiteral("getcontentlength")).at(0).toElement().text();
27 bool isCollection;
28
29 if (response.elementsByTagNameNS(webdavNS, QStringLiteral("resourcetype")).at(0).toElement().elementsByTagNameNS(webdavNS, QStringLiteral("collection")).size() == 1) {
30 isCollection = true;
31 } else {
32 isCollection = false;
33 }
34
35 items.append(WebDAVItem(webdavClient, href, creationDate, lastModified, displayName, contentType, contentLength, isCollection));
36 }
37
38 return items;
39}
Represents an item in a remote cloud location.
AKONADI_CALENDAR_EXPORT QString displayName(Akonadi::ETMCalendar *calendar, const Akonadi::Collection &collection)
QDomNodeList elementsByTagNameNS(const QString &nsURI, const QString &localName)
ParseResult setContent(QAnyStringView text, ParseOptions options)
QDomNodeList elementsByTagNameNS(const QString &nsURI, const QString &localName) const const
QString text() const const
QDomElement toElement() const const
QDomNode at(int index) const const
int length() const const
void append(QList< T > &&value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:32:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.